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/pci_ids.h>
20 #include <net/mac80211.h>
35 #include "wlc_types.h"
41 #include "wlc_bsscfg.h"
42 #include "phy/wlc_phy_hal.h"
43 #include "wlc_channel.h"
46 #include "wlc_phy_hal.h"
47 #include "wlc_phy_shim.h"
48 #include "wlc_antsel.h"
50 #include "wlc_ampdu.h"
51 #include "wl_export.h"
52 #include "wlc_alloc.h"
55 #include "wl_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 * Indication for txflowcontrol that all priority bits in
75 * TXQ_STOP_FOR_PRIOFC_MASK are to be considered.
80 * buffer length needed for wlc_format_ssid
81 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
83 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
85 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
86 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
88 #ifndef WLC_MPC_MAX_DELAYCNT
89 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
91 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
92 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
94 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
95 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
97 /* Scale down delays to accommodate QT slow speed */
98 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
99 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
101 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
104 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
105 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
106 * this low resolution driver tick can be used for maintenance tasks such as phy
107 * calibration and scb update
110 /* watchdog trigger mode: OSL timer or TBTT */
111 #define WLC_WATCHDOG_TBTT(wlc) \
112 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
114 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
115 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
117 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
118 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
128 /* Find basic rate for a given rate */
129 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
130 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
131 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
133 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
135 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
137 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
139 #define SCAN_IN_PROGRESS(x) 0
141 #define EPI_VERSION_NUM 0x054b0b00
144 /* pointer to most recently allocated wl/wlc */
145 static struct wlc_info *wlc_info_dbg = (struct wlc_info *) (NULL);
150 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
151 * table and by the wlc_doiovar() function. No ordering is imposed:
152 * the table is keyed by name, and the function uses a switch.
158 IOV_BCN_LI_BCN, /* Beacon listen interval in # of beacons */
159 IOV_LAST /* In case of a need to check max ID number */
162 const bcm_iovar_t wlc_iovars[] = {
163 {"mpc", IOV_MPC, (0), IOVT_BOOL, 0},
164 {"rtsthresh", IOV_RTSTHRESH, (IOVF_WHL), IOVT_UINT16, 0},
165 {"qtxpower", IOV_QTXPOWER, (IOVF_WHL), IOVT_UINT32, 0},
166 {"bcn_li_bcn", IOV_BCN_LI_BCN, (0), IOVT_UINT8, 0},
170 const u8 prio2fifo[NUMPRIO] = {
171 TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */
172 TX_AC_BK_FIFO, /* 1 BK AC_BK Background */
173 TX_AC_BK_FIFO, /* 2 -- AC_BK Background */
174 TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */
175 TX_AC_VI_FIFO, /* 4 CL AC_VI Video */
176 TX_AC_VI_FIFO, /* 5 VI AC_VI Video */
177 TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */
178 TX_AC_VO_FIFO /* 7 NC AC_VO Voice */
181 /* precedences numbers for wlc queues. These are twice as may levels as
183 * Odd numbers are used for HI priority traffic at same precedence levels
184 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
186 #define _WLC_PREC_NONE 0 /* None = - */
187 #define _WLC_PREC_BK 2 /* BK - Background */
188 #define _WLC_PREC_BE 4 /* BE - Best-effort */
189 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
190 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
191 #define _WLC_PREC_VI 10 /* Vi - Video */
192 #define _WLC_PREC_VO 12 /* Vo - Voice */
193 #define _WLC_PREC_NC 14 /* NC - Network Control */
195 /* 802.1D Priority to precedence queue mapping */
196 const u8 wlc_prio2prec_map[] = {
197 _WLC_PREC_BE, /* 0 BE - Best-effort */
198 _WLC_PREC_BK, /* 1 BK - Background */
199 _WLC_PREC_NONE, /* 2 None = - */
200 _WLC_PREC_EE, /* 3 EE - Excellent-effort */
201 _WLC_PREC_CL, /* 4 CL - Controlled Load */
202 _WLC_PREC_VI, /* 5 Vi - Video */
203 _WLC_PREC_VO, /* 6 Vo - Voice */
204 _WLC_PREC_NC, /* 7 NC - Network Control */
207 /* Sanity check for tx_prec_map and fifo synchup
208 * Either there are some packets pending for the fifo, else if fifo is empty then
209 * all the corresponding precmap bits should be set
211 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
212 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
213 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
214 (wlc)->fifo2prec_map[(fifo)]))
216 /* TX FIFO number to WME/802.1E Access Category */
217 const u8 wme_fifo2ac[] = { AC_BK, AC_BE, AC_VI, AC_VO, AC_BE, AC_BE };
219 /* WME/802.1E Access Category to TX FIFO number */
220 static const u8 wme_ac2fifo[] = { 1, 0, 2, 3 };
222 static bool in_send_q = false;
224 /* Shared memory location index for various AC params */
225 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
228 static const char *fifo_names[] = {
229 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
231 static const char fifo_names[6][0];
234 static const u8 acbitmap2maxprio[] = {
235 PRIO_8021D_BE, PRIO_8021D_BE, PRIO_8021D_BK, PRIO_8021D_BK,
236 PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI,
237 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO,
238 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO
241 /* currently the best mechanism for determining SIFS is the band in use */
242 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
244 /* value for # replay counters currently supported */
245 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
247 /* local prototypes */
248 static u16 BCMFASTPATH wlc_d11hdrs_mac80211(struct wlc_info *wlc,
249 struct ieee80211_hw *hw,
251 struct scb *scb, uint frag,
252 uint nfrags, uint queue,
255 ratespec_t rspec_override);
257 static void wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat);
258 static void wlc_bss_default_init(struct wlc_info *wlc);
259 static void wlc_ucode_mac_upd(struct wlc_info *wlc);
260 static ratespec_t mac80211_wlc_set_nrate(struct wlc_info *wlc,
261 struct wlcband *cur_band, u32 int_val);
262 static void wlc_tx_prec_map_init(struct wlc_info *wlc);
263 static void wlc_watchdog(void *arg);
264 static void wlc_watchdog_by_timer(void *arg);
265 static u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate);
266 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg);
267 static int wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val,
268 const bcm_iovar_t *vi);
269 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc);
271 /* send and receive */
272 static struct wlc_txq_info *wlc_txq_alloc(struct wlc_info *wlc);
273 static void wlc_txq_free(struct wlc_info *wlc,
274 struct wlc_txq_info *qi);
275 static void wlc_txflowcontrol_signal(struct wlc_info *wlc,
276 struct wlc_txq_info *qi,
278 static void wlc_txflowcontrol_reset(struct wlc_info *wlc);
279 static u16 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec,
281 static void wlc_compute_cck_plcp(struct wlc_info *wlc, ratespec_t rate,
282 uint length, u8 *plcp);
283 static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp);
284 static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp);
285 static u16 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate,
286 u8 preamble_type, uint next_frag_len);
287 static void wlc_recvctl(struct wlc_info *wlc,
288 d11rxhdr_t *rxh, struct sk_buff *p);
289 static uint wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t rate,
290 u8 preamble_type, uint dur);
291 static uint wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rate,
293 static uint wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rate,
295 /* interrupt, up/down, band */
296 static void wlc_setband(struct wlc_info *wlc, uint bandunit);
297 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc);
298 static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec);
299 static void wlc_bsinit(struct wlc_info *wlc);
300 static int wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
302 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc);
303 static bool wlc_radio_monitor_start(struct wlc_info *wlc);
304 static void wlc_radio_timer(void *arg);
305 static void wlc_radio_enable(struct wlc_info *wlc);
306 static void wlc_radio_upd(struct wlc_info *wlc);
308 /* scan, association, BSS */
309 static uint wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rate,
311 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap);
312 static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val);
313 static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val);
314 static void wlc_war16165(struct wlc_info *wlc, bool tx);
316 static void wlc_wme_retries_write(struct wlc_info *wlc);
317 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc);
318 static uint wlc_attach_module(struct wlc_info *wlc);
319 static void wlc_detach_module(struct wlc_info *wlc);
320 static void wlc_timers_deinit(struct wlc_info *wlc);
321 static void wlc_down_led_upd(struct wlc_info *wlc);
322 static uint wlc_down_del_timer(struct wlc_info *wlc);
323 static void wlc_ofdm_rateset_war(struct wlc_info *wlc);
324 static int _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
325 struct wlc_if *wlcif);
328 void wlc_get_rcmta(struct wlc_info *wlc, int idx, u8 *addr)
330 d11regs_t *regs = wlc->regs;
333 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc), __func__);
335 W_REG(®s->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2)));
336 (void)R_REG(®s->objaddr);
337 v32 = R_REG(®s->objdata);
339 addr[1] = (u8) (v32 >> 8);
340 addr[2] = (u8) (v32 >> 16);
341 addr[3] = (u8) (v32 >> 24);
342 W_REG(®s->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1)));
343 (void)R_REG(®s->objaddr);
344 v32 = R_REG(®s->objdata);
346 addr[5] = (u8) (v32 >> 8);
348 #endif /* defined(BCMDBG) */
350 /* keep the chip awake if needed */
351 bool wlc_stay_awake(struct wlc_info *wlc)
356 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
358 bool wlc_ps_allowed(struct wlc_info *wlc)
361 struct wlc_bsscfg *cfg;
363 /* disallow PS when one of the following global conditions meets */
364 if (!wlc->pub->associated || !wlc->PMenabled || wlc->PM_override)
367 /* disallow PS when one of these meets when not scanning */
368 if (!wlc->PMblocked) {
369 if (AP_ACTIVE(wlc) || wlc->monitor)
373 FOREACH_AS_STA(wlc, idx, cfg) {
374 /* disallow PS when one of the following bsscfg specific conditions meets */
375 if (!cfg->BSS || !WLC_PORTOPEN(cfg))
378 if (!cfg->dtim_programmed)
385 void wlc_reset(struct wlc_info *wlc)
387 WL_TRACE("wl%d: wlc_reset\n", wlc->pub->unit);
389 wlc->check_for_unaligned_tbtt = false;
391 /* slurp up hw mac counters before core reset */
394 /* reset our snapshot of macstat counters */
395 memset((char *)wlc->core->macstat_snapshot, 0,
398 wlc_bmac_reset(wlc->hw);
399 wlc_ampdu_reset(wlc->ampdu);
404 void wlc_fatal_error(struct wlc_info *wlc)
406 wiphy_err(wlc->wiphy, "wl%d: fatal error, reinitializing\n",
411 /* Return the channel the driver should initialize during wlc_init.
412 * the channel may have to be changed from the currently configured channel
413 * if other configurations are in conflict (bandlocked, 11n mode disabled,
414 * invalid channel for current country, etc.)
416 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc)
418 chanspec_t chanspec =
419 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE |
422 /* make sure the channel is on the supported band if we are band-restricted */
423 if (wlc->bandlocked || NBANDS(wlc) == 1) {
424 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
426 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
430 struct scb global_scb;
432 static void wlc_init_scb(struct wlc_info *wlc, struct scb *scb)
435 scb->flags = SCB_WMECAP | SCB_HTCAP;
436 for (i = 0; i < NUMPRIO; i++)
440 void wlc_init(struct wlc_info *wlc)
445 struct wlc_bsscfg *bsscfg;
448 WL_TRACE("wl%d: wlc_init\n", wlc->pub->unit);
452 /* This will happen if a big-hammer was executed. In that case, we want to go back
453 * to the channel that we were on and not new channel
455 if (wlc->pub->associated)
456 chanspec = wlc->home_chanspec;
458 chanspec = wlc_init_chanspec(wlc);
460 wlc_bmac_init(wlc->hw, chanspec, mute);
462 wlc->seckeys = wlc_bmac_read_shm(wlc->hw, M_SECRXKEYS_PTR) * 2;
463 if (wlc->machwcap & MCAP_TKIPMIC)
465 wlc_bmac_read_shm(wlc->hw, M_TKMICKEYS_PTR) * 2;
467 /* update beacon listen interval */
470 (u8) (wlc_bmac_read_shm(wlc->hw, M_NOSLPZNATDTIM) >> 10);
471 ASSERT(wlc->bcn_wait_prd > 0);
473 /* the world is new again, so is our reported rate */
474 wlc_reprate_init(wlc);
476 /* write ethernet address to core */
477 FOREACH_BSS(wlc, i, bsscfg) {
479 wlc_set_bssid(bsscfg);
482 /* Update tsf_cfprep if associated and up */
483 if (wlc->pub->associated) {
484 FOREACH_BSS(wlc, i, bsscfg) {
488 /* get beacon period and convert to uS */
489 bi = bsscfg->current_bss->beacon_period << 10;
491 * update since init path would reset
494 W_REG(®s->tsf_cfprep,
495 (bi << CFPREP_CBI_SHIFT));
497 /* Update maccontrol PM related bits */
498 wlc_set_ps_ctrl(wlc);
505 wlc_key_hw_init_all(wlc);
507 wlc_bandinit_ordered(wlc, chanspec);
509 wlc_init_scb(wlc, &global_scb);
511 /* init probe response timeout */
512 wlc_write_shm(wlc, M_PRS_MAXTIME, wlc->prb_resp_timeout);
514 /* init max burst txop (framebursting) */
515 wlc_write_shm(wlc, M_MBURST_TXOP,
517 _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP));
519 /* initialize maximum allowed duty cycle */
520 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true);
521 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true);
523 /* Update some shared memory locations related to max AMPDU size allowed to received */
524 wlc_ampdu_shm_upd(wlc->ampdu);
526 /* band-specific inits */
529 /* Enable EDCF mode (while the MAC is suspended) */
530 if (EDCF_ENAB(wlc->pub)) {
531 OR_REG(®s->ifs_ctl, IFS_USEEDCF);
532 wlc_edcf_setparams(wlc, false);
535 /* Init precedence maps for empty FIFOs */
536 wlc_tx_prec_map_init(wlc);
538 /* read the ucode version if we have not yet done so */
539 if (wlc->ucode_rev == 0) {
541 wlc_read_shm(wlc, M_BOM_REV_MAJOR) << NBITS(u16);
542 wlc->ucode_rev |= wlc_read_shm(wlc, M_BOM_REV_MINOR);
545 /* ..now really unleash hell (allow the MAC out of suspend) */
548 /* clear tx flow control */
549 wlc_txflowcontrol_reset(wlc);
551 /* clear tx data fifo suspends */
552 wlc->tx_suspended = false;
554 /* enable the RF Disable Delay timer */
555 W_REG(&wlc->regs->rfdisabledly, RFDISABLE_DEFAULT);
557 /* initialize mpc delay */
558 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
561 * Initialize WME parameters; if they haven't been set by some other
562 * mechanism (IOVar, etc) then read them from the hardware.
564 if (WLC_WME_RETRY_SHORT_GET(wlc, 0) == 0) { /* Uninitialized; read from HW */
568 for (ac = 0; ac < AC_COUNT; ac++) {
569 wlc->wme_retries[ac] =
570 wlc_read_shm(wlc, M_AC_TXLMT_ADDR(ac));
575 void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc)
577 wlc->bcnmisc_monitor = promisc;
578 wlc_mac_bcn_promisc(wlc);
581 void wlc_mac_bcn_promisc(struct wlc_info *wlc)
583 if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) ||
584 wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor)
585 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, MCTL_BCNS_PROMISC);
587 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, 0);
590 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
591 void wlc_mac_promisc(struct wlc_info *wlc)
593 u32 promisc_bits = 0;
595 /* promiscuous mode just sets MCTL_PROMISC
596 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
597 * since all BSS data traffic is directed at the AP
599 if (PROMISC_ENAB(wlc->pub) && !AP_ENAB(wlc->pub) && !wlc->wet)
600 promisc_bits |= MCTL_PROMISC;
602 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
603 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
604 * handled in wlc_mac_bcn_promisc()
606 if (MONITOR_ENAB(wlc))
607 promisc_bits |= MCTL_PROMISC | MCTL_KEEPCONTROL;
609 wlc_mctrl(wlc, MCTL_PROMISC | MCTL_KEEPCONTROL, promisc_bits);
612 /* check if hps and wake states of sw and hw are in sync */
613 bool wlc_ps_check(struct wlc_info *wlc)
619 if (!AP_ACTIVE(wlc)) {
621 tmp = R_REG(&wlc->regs->maccontrol);
624 * If deviceremoved is detected, then don't take any action as
625 * this can be called in any context. Assume that caller will
626 * take care of the condition. This is just to avoid assert
628 if (tmp == 0xffffffff) {
629 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n",
630 wlc->pub->unit, __func__);
631 return DEVICEREMOVED(wlc);
634 hps = PS_ALLOWED(wlc);
636 if (hps != ((tmp & MCTL_HPS) != 0)) {
638 struct wlc_bsscfg *cfg;
639 wiphy_err(wlc->wiphy, "wl%d: hps not sync, sw %d, "
641 wlc->pub->unit, hps, tmp);
642 FOREACH_BSS(wlc, idx, cfg) {
643 if (!BSSCFG_STA(cfg))
649 /* For a monolithic build the wake check can be exact since it looks at wake
650 * override bits. The MCTL_WAKE bit should match the 'wake' value.
652 wake = STAY_AWAKE(wlc) || wlc->hw->wake_override;
653 wake_ok = (wake == ((tmp & MCTL_WAKE) != 0));
654 if (hps && !wake_ok) {
655 wiphy_err(wlc->wiphy, "wl%d: wake not sync, sw %d "
657 wlc->pub->unit, wake, tmp);
665 /* push sw hps and wake state through hardware */
666 void wlc_set_ps_ctrl(struct wlc_info *wlc)
672 hps = PS_ALLOWED(wlc);
673 wake = hps ? (STAY_AWAKE(wlc)) : true;
675 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
676 wlc->pub->unit, hps, wake);
678 v1 = R_REG(&wlc->regs->maccontrol);
685 wlc_mctrl(wlc, MCTL_WAKE | MCTL_HPS, v2);
687 awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0));
689 if (wake && !awake_before)
690 wlc_bmac_wait_for_wake(wlc->hw);
695 * Write this BSS config's MAC address to core.
696 * Updates RXE match engine.
698 int wlc_set_mac(struct wlc_bsscfg *cfg)
701 struct wlc_info *wlc = cfg->wlc;
703 if (cfg == wlc->cfg) {
704 /* enter the MAC addr into the RXE match registers */
705 wlc_set_addrmatch(wlc, RCM_MAC_OFFSET, cfg->cur_etheraddr);
708 wlc_ampdu_macaddr_upd(wlc);
713 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
714 * Updates RXE match engine.
716 void wlc_set_bssid(struct wlc_bsscfg *cfg)
718 struct wlc_info *wlc = cfg->wlc;
720 /* if primary config, we need to update BSSID in RXE match registers */
721 if (cfg == wlc->cfg) {
722 wlc_set_addrmatch(wlc, RCM_BSSID_OFFSET, cfg->BSSID);
724 #ifdef SUPPORT_HWKEYS
725 else if (BSSCFG_STA(cfg) && cfg->BSS) {
726 wlc_rcmta_add_bssid(wlc, cfg);
732 * Suspend the the MAC and update the slot timing
733 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
735 void wlc_switch_shortslot(struct wlc_info *wlc, bool shortslot)
738 struct wlc_bsscfg *cfg;
740 ASSERT(wlc->band->gmode);
742 /* use the override if it is set */
743 if (wlc->shortslot_override != WLC_SHORTSLOT_AUTO)
744 shortslot = (wlc->shortslot_override == WLC_SHORTSLOT_ON);
746 if (wlc->shortslot == shortslot)
749 wlc->shortslot = shortslot;
751 /* update the capability based on current shortslot mode */
752 FOREACH_BSS(wlc, idx, cfg) {
753 if (!cfg->associated)
755 cfg->current_bss->capability &=
756 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
758 cfg->current_bss->capability |=
759 WLAN_CAPABILITY_SHORT_SLOT_TIME;
762 wlc_bmac_set_shortslot(wlc->hw, shortslot);
765 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc)
770 local = WLC_TXPWR_MAX;
771 if (wlc->pub->associated &&
772 (wf_chspec_ctlchan(wlc->chanspec) ==
773 wf_chspec_ctlchan(wlc->home_chanspec))) {
775 /* get the local power constraint if we are on the AP's
776 * channel [802.11h, 7.3.2.13]
778 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
780 (wlc->txpwr_local_max -
781 wlc->txpwr_local_constraint) * WLC_TXPWR_DB_FACTOR;
782 if (local_max > 0 && local_max < WLC_TXPWR_MAX)
783 return (u8) local_max;
791 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
792 void wlc_set_home_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
794 if (wlc->home_chanspec != chanspec) {
796 struct wlc_bsscfg *cfg;
798 wlc->home_chanspec = chanspec;
800 FOREACH_BSS(wlc, idx, cfg) {
801 if (!cfg->associated)
804 cfg->current_bss->chanspec = chanspec;
810 static void wlc_set_phy_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
812 /* Save our copy of the chanspec */
813 wlc->chanspec = chanspec;
815 /* Set the chanspec and power limits for this locale after computing
816 * any 11h local tx power constraints.
818 wlc_channel_set_chanspec(wlc->cmi, chanspec,
819 wlc_local_constraint_qdbm(wlc));
821 if (wlc->stf->ss_algosel_auto)
822 wlc_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel,
825 wlc_stf_ss_update(wlc, wlc->band);
829 void wlc_set_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
832 bool switchband = false;
833 chanspec_t old_chanspec = wlc->chanspec;
835 if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) {
836 wiphy_err(wlc->wiphy, "wl%d: %s: Bad channel %d\n",
837 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec));
838 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
842 /* Switch bands if necessary */
843 if (NBANDS(wlc) > 1) {
844 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
845 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) {
847 if (wlc->bandlocked) {
848 wiphy_err(wlc->wiphy, "wl%d: %s: chspec %d "
850 wlc->pub->unit, __func__,
851 CHSPEC_CHANNEL(chanspec));
854 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
855 * if the setband updates (wlc_bsinit) use low level calls to inspect and
856 * set state, the state inspected may be from the wrong band, or the
857 * following wlc_bmac_set_chanspec() may undo the work.
859 wlc_setband(wlc, bandunit);
863 ASSERT(N_ENAB(wlc->pub) || !CHSPEC_IS40(chanspec));
865 /* sync up phy/radio chanspec */
866 wlc_set_phy_chanspec(wlc, chanspec);
868 /* init antenna selection */
869 if (CHSPEC_WLC_BW(old_chanspec) != CHSPEC_WLC_BW(chanspec)) {
870 wlc_antsel_init(wlc->asi);
872 /* Fix the hardware rateset based on bw.
873 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
875 wlc_rateset_bw_mcs_filter(&wlc->band->hw_rateset,
877 mimo_cap_40 ? CHSPEC_WLC_BW(chanspec)
881 /* update some mac configuration since chanspec changed */
882 wlc_ucode_mac_upd(wlc);
886 static int wlc_get_current_txpwr(struct wlc_info *wlc, void *pwr, uint len)
888 txpwr_limits_t txpwr;
890 tx_power_legacy_t *old_power = NULL;
895 if (len == sizeof(tx_power_legacy_t))
896 old_power = (tx_power_legacy_t *) pwr;
897 else if (len < sizeof(tx_power_t))
898 return -BCME_BUFTOOSHORT;
900 memset(&power, 0, sizeof(tx_power_t));
902 power.chanspec = WLC_BAND_PI_RADIO_CHANSPEC;
903 if (wlc->pub->associated)
904 power.local_chanspec = wlc->home_chanspec;
906 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
907 * public interface only implements getting and setting a single value for all of
908 * rates, so we need to fill the array ourselves.
910 wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override);
911 for (r = 0; r < WL_TX_POWER_RATES; r++) {
912 power.user_limit[r] = (u8) qdbm;
915 power.local_max = wlc->txpwr_local_max * WLC_TXPWR_DB_FACTOR;
916 power.local_constraint =
917 wlc->txpwr_local_constraint * WLC_TXPWR_DB_FACTOR;
919 power.antgain[0] = wlc->bandstate[BAND_2G_INDEX]->antgain;
920 power.antgain[1] = wlc->bandstate[BAND_5G_INDEX]->antgain;
922 wlc_channel_reg_limits(wlc->cmi, power.chanspec, &txpwr);
924 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
925 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
928 /* CCK tx power limits */
929 for (c = 0, r = WL_TX_POWER_CCK_FIRST; c < WL_TX_POWER_CCK_NUM;
931 power.reg_limit[r] = txpwr.cck[c];
933 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
934 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
937 /* 20 MHz OFDM SISO tx power limits */
938 for (c = 0, r = WL_TX_POWER_OFDM_FIRST; c < WL_TX_POWER_OFDM_NUM;
940 power.reg_limit[r] = txpwr.ofdm[c];
942 if (WLC_PHY_11N_CAP(wlc->band)) {
944 /* 20 MHz OFDM CDD tx power limits */
945 for (c = 0, r = WL_TX_POWER_OFDM20_CDD_FIRST;
946 c < WL_TX_POWER_OFDM_NUM; c++, r++)
947 power.reg_limit[r] = txpwr.ofdm_cdd[c];
949 /* 40 MHz OFDM SISO tx power limits */
950 for (c = 0, r = WL_TX_POWER_OFDM40_SISO_FIRST;
951 c < WL_TX_POWER_OFDM_NUM; c++, r++)
952 power.reg_limit[r] = txpwr.ofdm_40_siso[c];
954 /* 40 MHz OFDM CDD tx power limits */
955 for (c = 0, r = WL_TX_POWER_OFDM40_CDD_FIRST;
956 c < WL_TX_POWER_OFDM_NUM; c++, r++)
957 power.reg_limit[r] = txpwr.ofdm_40_cdd[c];
959 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
960 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
963 /* 20MHz MCS0-7 SISO tx power limits */
964 for (c = 0, r = WL_TX_POWER_MCS20_SISO_FIRST;
965 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
966 power.reg_limit[r] = txpwr.mcs_20_siso[c];
968 /* 20MHz MCS0-7 CDD tx power limits */
969 for (c = 0, r = WL_TX_POWER_MCS20_CDD_FIRST;
970 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
971 power.reg_limit[r] = txpwr.mcs_20_cdd[c];
973 /* 20MHz MCS0-7 STBC tx power limits */
974 for (c = 0, r = WL_TX_POWER_MCS20_STBC_FIRST;
975 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
976 power.reg_limit[r] = txpwr.mcs_20_stbc[c];
978 /* 40MHz MCS0-7 SISO tx power limits */
979 for (c = 0, r = WL_TX_POWER_MCS40_SISO_FIRST;
980 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
981 power.reg_limit[r] = txpwr.mcs_40_siso[c];
983 /* 40MHz MCS0-7 CDD tx power limits */
984 for (c = 0, r = WL_TX_POWER_MCS40_CDD_FIRST;
985 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
986 power.reg_limit[r] = txpwr.mcs_40_cdd[c];
988 /* 40MHz MCS0-7 STBC tx power limits */
989 for (c = 0, r = WL_TX_POWER_MCS40_STBC_FIRST;
990 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
991 power.reg_limit[r] = txpwr.mcs_40_stbc[c];
993 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
994 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
997 /* 20MHz MCS8-15 SDM tx power limits */
998 for (c = 0, r = WL_TX_POWER_MCS20_SDM_FIRST;
999 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
1000 power.reg_limit[r] = txpwr.mcs_20_mimo[c];
1002 /* 40MHz MCS8-15 SDM tx power limits */
1003 for (c = 0, r = WL_TX_POWER_MCS40_SDM_FIRST;
1004 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
1005 power.reg_limit[r] = txpwr.mcs_40_mimo[c];
1008 power.reg_limit[WL_TX_POWER_MCS_32] = txpwr.mcs32;
1011 wlc_phy_txpower_get_current(wlc->band->pi, &power,
1012 CHSPEC_CHANNEL(power.chanspec));
1014 /* copy the tx_power_t struct to the return buffer,
1015 * or convert to a tx_power_legacy_t struct
1018 memcpy(pwr, &power, sizeof(tx_power_t));
1020 int band_idx = CHSPEC_IS2G(power.chanspec) ? 0 : 1;
1022 memset(old_power, 0, sizeof(tx_power_legacy_t));
1024 old_power->txpwr_local_max = power.local_max;
1025 old_power->txpwr_local_constraint = power.local_constraint;
1026 if (CHSPEC_IS2G(power.chanspec)) {
1027 old_power->txpwr_chan_reg_max = txpwr.cck[0];
1028 old_power->txpwr_est_Pout[band_idx] =
1030 old_power->txpwr_est_Pout_gofdm = power.est_Pout[0];
1032 old_power->txpwr_chan_reg_max = txpwr.ofdm[0];
1033 old_power->txpwr_est_Pout[band_idx] = power.est_Pout[0];
1035 old_power->txpwr_antgain[0] = power.antgain[0];
1036 old_power->txpwr_antgain[1] = power.antgain[1];
1038 for (r = 0; r < NUM_PWRCTRL_RATES; r++) {
1039 old_power->txpwr_band_max[r] = power.user_limit[r];
1040 old_power->txpwr_limit[r] = power.reg_limit[r];
1041 old_power->txpwr_target[band_idx][r] = power.target[r];
1042 if (CHSPEC_IS2G(power.chanspec))
1043 old_power->txpwr_bphy_cck_max[r] =
1044 power.board_limit[r];
1046 old_power->txpwr_aphy_max[r] =
1047 power.board_limit[r];
1053 #endif /* defined(BCMDBG) */
1055 static u32 wlc_watchdog_backup_bi(struct wlc_info *wlc)
1058 bi = 2 * wlc->cfg->current_bss->dtim_period *
1059 wlc->cfg->current_bss->beacon_period;
1060 if (wlc->bcn_li_dtim)
1061 bi *= wlc->bcn_li_dtim;
1062 else if (wlc->bcn_li_bcn)
1063 /* recalculate bi based on bcn_li_bcn */
1064 bi = 2 * wlc->bcn_li_bcn * wlc->cfg->current_bss->beacon_period;
1066 if (bi < 2 * TIMER_INTERVAL_WATCHDOG)
1067 bi = 2 * TIMER_INTERVAL_WATCHDOG;
1071 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1072 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1074 void wlc_watchdog_upd(struct wlc_info *wlc, bool tbtt)
1076 /* make sure changing watchdog driver is allowed */
1077 if (!wlc->pub->up || !wlc->pub->align_wd_tbtt)
1079 if (!tbtt && wlc->WDarmed) {
1080 wl_del_timer(wlc->wl, wlc->wdtimer);
1081 wlc->WDarmed = false;
1084 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1085 if (tbtt && wlc->WDarmed) {
1086 wl_del_timer(wlc->wl, wlc->wdtimer);
1087 wlc->WDarmed = false;
1088 wlc->WDlast = OSL_SYSUPTIME();
1090 /* arm watchdog timer and drive the watchdog there */
1091 else if (!tbtt && !wlc->WDarmed) {
1092 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
1094 wlc->WDarmed = true;
1096 if (tbtt && !wlc->WDarmed) {
1097 wl_add_timer(wlc->wl, wlc->wdtimer, wlc_watchdog_backup_bi(wlc),
1099 wlc->WDarmed = true;
1103 ratespec_t wlc_lowest_basic_rspec(struct wlc_info *wlc, wlc_rateset_t *rs)
1105 ratespec_t lowest_basic_rspec;
1108 /* Use the lowest basic rate */
1109 lowest_basic_rspec = rs->rates[0] & WLC_RATE_MASK;
1110 for (i = 0; i < rs->count; i++) {
1111 if (rs->rates[i] & WLC_RATE_FLAG) {
1112 lowest_basic_rspec = rs->rates[i] & WLC_RATE_MASK;
1117 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1118 if (IS_OFDM(lowest_basic_rspec)) {
1119 lowest_basic_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
1123 return lowest_basic_rspec;
1126 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1127 * setting as per this table:
1128 * ratespec CCK ant = wlc->stf->txant
1131 void wlc_beacon_phytxctl_txant_upd(struct wlc_info *wlc, ratespec_t bcn_rspec)
1134 u16 phytxant = wlc->stf->phytxant;
1135 u16 mask = PHY_TXC_ANT_MASK;
1137 /* for non-siso rates or default setting, use the available chains */
1138 if (WLC_PHY_11N_CAP(wlc->band)) {
1139 phytxant = wlc_stf_phytxchain_sel(wlc, bcn_rspec);
1142 phyctl = wlc_read_shm(wlc, M_BCN_PCTLWD);
1143 phyctl = (phyctl & ~mask) | phytxant;
1144 wlc_write_shm(wlc, M_BCN_PCTLWD, phyctl);
1147 /* centralized protection config change function to simplify debugging, no consistency checking
1148 * this should be called only on changes to avoid overhead in periodic function
1150 void wlc_protection_upd(struct wlc_info *wlc, uint idx, int val)
1152 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx, val);
1155 case WLC_PROT_G_SPEC:
1156 wlc->protection->_g = (bool) val;
1158 case WLC_PROT_G_OVR:
1159 wlc->protection->g_override = (s8) val;
1161 case WLC_PROT_G_USER:
1162 wlc->protection->gmode_user = (u8) val;
1164 case WLC_PROT_OVERLAP:
1165 wlc->protection->overlap = (s8) val;
1167 case WLC_PROT_N_USER:
1168 wlc->protection->nmode_user = (s8) val;
1170 case WLC_PROT_N_CFG:
1171 wlc->protection->n_cfg = (s8) val;
1173 case WLC_PROT_N_CFG_OVR:
1174 wlc->protection->n_cfg_override = (s8) val;
1176 case WLC_PROT_N_NONGF:
1177 wlc->protection->nongf = (bool) val;
1179 case WLC_PROT_N_NONGF_OVR:
1180 wlc->protection->nongf_override = (s8) val;
1182 case WLC_PROT_N_PAM_OVR:
1183 wlc->protection->n_pam_override = (s8) val;
1185 case WLC_PROT_N_OBSS:
1186 wlc->protection->n_obss = (bool) val;
1196 static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val)
1198 wlc->ht_cap.cap_info &= ~(IEEE80211_HT_CAP_SGI_20 |
1199 IEEE80211_HT_CAP_SGI_40);
1200 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_20) ?
1201 IEEE80211_HT_CAP_SGI_20 : 0;
1202 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_40) ?
1203 IEEE80211_HT_CAP_SGI_40 : 0;
1206 wlc_update_beacon(wlc);
1207 wlc_update_probe_resp(wlc, true);
1211 static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val)
1213 wlc->stf->ldpc = val;
1215 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_LDPC_CODING;
1216 if (wlc->stf->ldpc != OFF)
1217 wlc->ht_cap.cap_info |= IEEE80211_HT_CAP_LDPC_CODING;
1220 wlc_update_beacon(wlc);
1221 wlc_update_probe_resp(wlc, true);
1222 wlc_phy_ldpc_override_set(wlc->band->pi, (val ? true : false));
1227 * ucode, hwmac update
1228 * Channel dependent updates for ucode and hw
1230 static void wlc_ucode_mac_upd(struct wlc_info *wlc)
1232 /* enable or disable any active IBSSs depending on whether or not
1233 * we are on the home channel
1235 if (wlc->home_chanspec == WLC_BAND_PI_RADIO_CHANSPEC) {
1236 if (wlc->pub->associated) {
1237 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1238 * I think that the ucode inits set up the bcn templates and shm values
1239 * with a bogus beacon. This should not be done in the inits. If ucode needs
1240 * to set up a beacon for testing, the test routines should write it down,
1241 * not expect the inits to populate a bogus beacon.
1243 if (WLC_PHY_11N_CAP(wlc->band)) {
1244 wlc_write_shm(wlc, M_BCN_TXTSF_OFFSET,
1245 wlc->band->bcntsfoff);
1249 /* disable an active IBSS if we are not on the home channel */
1252 /* update the various promisc bits */
1253 wlc_mac_bcn_promisc(wlc);
1254 wlc_mac_promisc(wlc);
1257 static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec)
1259 wlc_rateset_t default_rateset;
1261 uint i, band_order[2];
1263 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc->pub->unit);
1265 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1266 * figure out the right band to park on
1268 if (wlc->bandlocked || NBANDS(wlc) == 1) {
1269 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
1271 parkband = wlc->band->bandunit; /* updated in wlc_bandlock() */
1272 band_order[0] = band_order[1] = parkband;
1274 /* park on the band of the specified chanspec */
1275 parkband = CHSPEC_WLCBANDUNIT(chanspec);
1277 /* order so that parkband initialize last */
1278 band_order[0] = parkband ^ 1;
1279 band_order[1] = parkband;
1282 /* make each band operational, software state init */
1283 for (i = 0; i < NBANDS(wlc); i++) {
1284 uint j = band_order[i];
1286 wlc->band = wlc->bandstate[j];
1288 wlc_default_rateset(wlc, &default_rateset);
1290 /* fill in hw_rate */
1291 wlc_rateset_filter(&default_rateset, &wlc->band->hw_rateset,
1292 false, WLC_RATES_CCK_OFDM, WLC_RATE_MASK,
1293 (bool) N_ENAB(wlc->pub));
1295 /* init basic rate lookup */
1296 wlc_rate_lookup_init(wlc, &default_rateset);
1299 /* sync up phy/radio chanspec */
1300 wlc_set_phy_chanspec(wlc, chanspec);
1303 /* band-specific init */
1304 static void WLBANDINITFN(wlc_bsinit) (struct wlc_info *wlc)
1306 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1307 wlc->pub->unit, wlc->band->bandunit);
1309 /* write ucode ACK/CTS rate table */
1310 wlc_set_ratetable(wlc);
1312 /* update some band specific mac configuration */
1313 wlc_ucode_mac_upd(wlc);
1315 /* init antenna selection */
1316 wlc_antsel_init(wlc->asi);
1320 /* switch to and initialize new band */
1321 static void WLBANDINITFN(wlc_setband) (struct wlc_info *wlc, uint bandunit)
1324 struct wlc_bsscfg *cfg;
1326 ASSERT(NBANDS(wlc) > 1);
1327 ASSERT(!wlc->bandlocked);
1328 ASSERT(bandunit != wlc->band->bandunit || wlc->bandinit_pending);
1330 wlc->band = wlc->bandstate[bandunit];
1335 /* wait for at least one beacon before entering sleeping state */
1336 wlc->PMawakebcn = true;
1337 FOREACH_AS_STA(wlc, idx, cfg)
1338 cfg->PMawakebcn = true;
1339 wlc_set_ps_ctrl(wlc);
1341 /* band-specific initializations */
1345 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1346 void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe)
1348 static const wme_param_ie_t stadef = {
1351 WME_SUBTYPE_PARAM_IE,
1356 {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA,
1357 cpu_to_le16(EDCF_AC_BE_TXOP_STA)},
1358 {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA,
1359 cpu_to_le16(EDCF_AC_BK_TXOP_STA)},
1360 {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA,
1361 cpu_to_le16(EDCF_AC_VI_TXOP_STA)},
1362 {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA,
1363 cpu_to_le16(EDCF_AC_VO_TXOP_STA)}
1366 memcpy(pe, &stadef, sizeof(*pe));
1369 void wlc_wme_setparams(struct wlc_info *wlc, u16 aci,
1370 const struct ieee80211_tx_queue_params *params,
1374 shm_acparams_t acp_shm;
1379 /* Only apply params if the core is out of reset and has clocks */
1381 wiphy_err(wlc->wiphy, "wl%d: %s : no-clock\n", wlc->pub->unit,
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);
1393 /* fill in shm ac params struct */
1394 acp_shm.txop = le16_to_cpu(params->txop);
1395 /* convert from units of 32us to us for ucode */
1396 wlc->edcf_txop[aci & 0x3] = acp_shm.txop =
1397 EDCF_TXOP2USEC(acp_shm.txop);
1398 acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK);
1400 if (aci == AC_VI && acp_shm.txop == 0
1401 && acp_shm.aifs < EDCF_AIFSN_MAX)
1404 if (acp_shm.aifs < EDCF_AIFSN_MIN
1405 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1406 wiphy_err(wlc->wiphy, "wl%d: wlc_edcf_setparams: bad "
1407 "aifs %d\n", wlc->pub->unit, acp_shm.aifs);
1411 acp_shm.cwmin = params->cw_min;
1412 acp_shm.cwmax = params->cw_max;
1413 acp_shm.cwcur = acp_shm.cwmin;
1415 R_REG(&wlc->regs->tsf_random) & acp_shm.cwcur;
1416 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1417 /* Indicate the new params to the ucode */
1418 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1419 wme_shmemacindex(aci) *
1421 M_EDCF_STATUS_OFF));
1422 acp_shm.status |= WME_STATUS_NEWAC;
1424 /* Fill in shm acparam table */
1425 shm_entry = (u16 *) &acp_shm;
1426 for (i = 0; i < (int)sizeof(shm_acparams_t); i += 2)
1429 wme_shmemacindex(aci) * M_EDCF_QLEN + i,
1435 wlc_suspend_mac_and_wait(wlc);
1438 wlc_enable_mac(wlc);
1442 void wlc_edcf_setparams(struct wlc_info *wlc, bool suspend)
1446 edcf_acparam_t *edcf_acp;
1448 struct ieee80211_tx_queue_params txq_pars;
1449 struct ieee80211_tx_queue_params *params = &txq_pars;
1454 * AP uses AC params from wme_param_ie_ap.
1455 * AP advertises AC params from wme_param_ie.
1456 * STA uses AC params from wme_param_ie.
1459 edcf_acp = (edcf_acparam_t *) &wlc->wme_param_ie.acparam[0];
1461 for (i_ac = 0; i_ac < AC_COUNT; i_ac++, edcf_acp++) {
1462 /* find out which ac this set of params applies to */
1463 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
1464 ASSERT(aci < AC_COUNT);
1465 /* set the admission control policy for this AC */
1466 if (edcf_acp->ACI & EDCF_ACM_MASK) {
1467 wlc->wme_admctl |= 1 << aci;
1470 /* fill in shm ac params struct */
1471 params->txop = edcf_acp->TXOP;
1472 params->aifs = edcf_acp->ACI;
1474 /* CWmin = 2^(ECWmin) - 1 */
1475 params->cw_min = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK);
1476 /* CWmax = 2^(ECWmax) - 1 */
1477 params->cw_max = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK)
1478 >> EDCF_ECWMAX_SHIFT);
1479 wlc_wme_setparams(wlc, aci, params, suspend);
1483 wlc_suspend_mac_and_wait(wlc);
1485 if (AP_ENAB(wlc->pub) && WME_ENAB(wlc->pub)) {
1486 wlc_update_beacon(wlc);
1487 wlc_update_probe_resp(wlc, false);
1491 wlc_enable_mac(wlc);
1495 bool wlc_timers_init(struct wlc_info *wlc, int unit)
1497 wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer,
1499 if (!wlc->wdtimer) {
1500 wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for wdtimer "
1505 wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer,
1507 if (!wlc->radio_timer) {
1508 wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for radio_timer "
1520 * Initialize wlc_info default values ...
1521 * may get overrides later in this function
1523 void wlc_info_init(struct wlc_info *wlc, int unit)
1526 /* Assume the device is there until proven otherwise */
1527 wlc->device_present = true;
1529 /* set default power output percentage to 100 percent */
1530 wlc->txpwr_percent = 100;
1532 /* Save our copy of the chanspec */
1533 wlc->chanspec = CH20MHZ_CHSPEC(1);
1535 /* initialize CCK preamble mode to unassociated state */
1536 wlc->shortpreamble = false;
1538 wlc->legacy_probe = true;
1540 /* various 802.11g modes */
1541 wlc->shortslot = false;
1542 wlc->shortslot_override = WLC_SHORTSLOT_AUTO;
1544 wlc->barker_overlap_control = true;
1545 wlc->barker_preamble = WLC_BARKER_SHORT_ALLOWED;
1546 wlc->txburst_limit_override = AUTO;
1548 wlc_protection_upd(wlc, WLC_PROT_G_OVR, WLC_PROTECTION_AUTO);
1549 wlc_protection_upd(wlc, WLC_PROT_G_SPEC, false);
1551 wlc_protection_upd(wlc, WLC_PROT_N_CFG_OVR, WLC_PROTECTION_AUTO);
1552 wlc_protection_upd(wlc, WLC_PROT_N_CFG, WLC_N_PROTECTION_OFF);
1553 wlc_protection_upd(wlc, WLC_PROT_N_NONGF_OVR, WLC_PROTECTION_AUTO);
1554 wlc_protection_upd(wlc, WLC_PROT_N_NONGF, false);
1555 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR, AUTO);
1557 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, WLC_PROTECTION_CTL_OVERLAP);
1559 /* 802.11g draft 4.0 NonERP elt advertisement */
1560 wlc->include_legacy_erp = true;
1562 wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF;
1563 wlc->stf->txant = ANT_TX_DEF;
1565 wlc->prb_resp_timeout = WLC_PRB_RESP_TIMEOUT;
1567 wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN;
1568 for (i = 0; i < NFIFO; i++)
1569 wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN;
1570 wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN;
1572 /* default rate fallback retry limits */
1573 wlc->SFBL = RETRY_SHORT_FB;
1574 wlc->LFBL = RETRY_LONG_FB;
1576 /* default mac retry limits */
1577 wlc->SRL = RETRY_SHORT_DEF;
1578 wlc->LRL = RETRY_LONG_DEF;
1581 wlc->PM = PM_OFF; /* User's setting of PM mode through IOCTL */
1582 wlc->PM_override = false; /* Prevents from going to PM if our AP is 'ill' */
1583 wlc->PMenabled = false; /* Current PM state */
1584 wlc->PMpending = false; /* Tracks whether STA indicated PM in the last attempt */
1585 wlc->PMblocked = false; /* To allow blocking going into PM during RM and scans */
1587 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1588 wlc->WME_PM_blocked = false;
1590 /* Init wme queuing method */
1591 wlc->wme_prec_queuing = false;
1593 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1595 /* Are we waiting for a response to PS-Poll that we sent */
1596 wlc->PSpoll = false;
1599 wlc->wme_apsd = true;
1600 wlc->apsd_sta_usp = false;
1601 wlc->apsd_trigger_timeout = 0; /* disable the trigger timer */
1602 wlc->apsd_trigger_ac = AC_BITMAP_ALL;
1604 /* Set flag to indicate that hw keys should be used when available. */
1605 wlc->wsec_swkeys = false;
1607 /* init the 4 static WEP default keys */
1608 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
1609 wlc->wsec_keys[i] = wlc->wsec_def_keys[i];
1610 wlc->wsec_keys[i]->idx = (u8) i;
1613 wlc->_regulatory_domain = false; /* 802.11d */
1615 /* WME QoS mode is Auto by default */
1616 wlc->pub->_wme = AUTO;
1618 #ifdef BCMSDIODEV_ENABLED
1619 wlc->pub->_priofc = true; /* enable priority flow control for sdio dongle */
1622 wlc->pub->_ampdu = AMPDU_AGG_HOST;
1623 wlc->pub->bcmerror = 0;
1624 wlc->ibss_allowed = true;
1625 wlc->ibss_coalesce_allowed = true;
1626 wlc->pub->_coex = ON;
1628 /* initialize mpc delay */
1629 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
1631 wlc->pr80838_war = true;
1634 static bool wlc_state_bmac_sync(struct wlc_info *wlc)
1636 wlc_bmac_state_t state_bmac;
1638 if (wlc_bmac_state_get(wlc->hw, &state_bmac) != 0)
1641 wlc->machwcap = state_bmac.machwcap;
1642 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR,
1643 (s8) state_bmac.preamble_ovr);
1648 static uint wlc_attach_module(struct wlc_info *wlc)
1652 unit = wlc->pub->unit;
1654 wlc->asi = wlc_antsel_attach(wlc);
1655 if (wlc->asi == NULL) {
1656 wiphy_err(wlc->wiphy, "wl%d: wlc_attach: wlc_antsel_attach "
1662 wlc->ampdu = wlc_ampdu_attach(wlc);
1663 if (wlc->ampdu == NULL) {
1664 wiphy_err(wlc->wiphy, "wl%d: wlc_attach: wlc_ampdu_attach "
1670 if ((wlc_stf_attach(wlc) != 0)) {
1671 wiphy_err(wlc->wiphy, "wl%d: wlc_attach: wlc_stf_attach "
1680 struct wlc_pub *wlc_pub(void *wlc)
1682 return ((struct wlc_info *) wlc)->pub;
1685 #define CHIP_SUPPORTS_11N(wlc) 1
1688 * The common driver entry routine. Error codes should be unique
1690 void *wlc_attach(struct wl_info *wl, u16 vendor, u16 device, uint unit,
1691 bool piomode, void *regsva, uint bustype, void *btparam,
1694 struct wlc_info *wlc;
1697 struct wlc_pub *pub;
1698 struct wlc_txq_info *qi;
1701 /* allocate struct wlc_info state and its substructures */
1702 wlc = (struct wlc_info *) wlc_attach_malloc(unit, &err, device);
1705 wlc->wiphy = wl->wiphy;
1712 wlc->band = wlc->bandstate[0];
1713 wlc->core = wlc->corestate;
1716 wlc->btparam = btparam;
1717 pub->_piomode = piomode;
1718 wlc->bandinit_pending = false;
1719 /* By default restrict TKIP associations from 11n STA's */
1720 wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT;
1722 /* populate struct wlc_info with default values */
1723 wlc_info_init(wlc, unit);
1725 /* update sta/ap related parameters */
1728 /* 11n_disable nvram */
1729 n_disabled = getintvar(pub->vars, "11n_disable");
1731 /* register a module (to handle iovars) */
1732 wlc_module_register(wlc->pub, wlc_iovars, "wlc_iovars", wlc,
1733 wlc_doiovar, NULL, NULL);
1736 * low level attach steps(all hw accesses go
1737 * inside, no more in rest of the attach)
1739 err = wlc_bmac_attach(wlc, vendor, device, unit, piomode, regsva,
1744 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1745 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1747 if (!wlc_state_bmac_sync(wlc)) {
1752 pub->phy_11ncapable = WLC_PHY_11N_CAP(wlc->band);
1754 /* propagate *vars* from BMAC driver to high driver */
1755 wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size);
1758 /* set maximum allowed duty cycle */
1759 wlc->tx_duty_cycle_ofdm =
1760 (u16) getintvar(pub->vars, "tx_duty_cycle_ofdm");
1761 wlc->tx_duty_cycle_cck =
1762 (u16) getintvar(pub->vars, "tx_duty_cycle_cck");
1764 wlc_stf_phy_chain_calc(wlc);
1766 /* txchain 1: txant 0, txchain 2: txant 1 */
1767 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
1768 wlc->stf->txant = wlc->stf->hw_txchain - 1;
1770 /* push to BMAC driver */
1771 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain,
1772 wlc->stf->hw_rxchain);
1774 /* pull up some info resulting from the low attach */
1777 for (i = 0; i < NFIFO; i++)
1778 wlc->core->txavail[i] = wlc->hw->txavail[i];
1781 wlc_bmac_hw_etheraddr(wlc->hw, wlc->perm_etheraddr);
1783 memcpy(&pub->cur_etheraddr, &wlc->perm_etheraddr, ETH_ALEN);
1785 for (j = 0; j < NBANDS(wlc); j++) {
1786 /* Use band 1 for single band 11a */
1787 if (IS_SINGLEBAND_5G(wlc->deviceid))
1790 wlc->band = wlc->bandstate[j];
1792 if (!wlc_attach_stf_ant_init(wlc)) {
1797 /* default contention windows size limits */
1798 wlc->band->CWmin = APHY_CWMIN;
1799 wlc->band->CWmax = PHY_CWMAX;
1801 /* init gmode value */
1802 if (BAND_2G(wlc->band->bandtype)) {
1803 wlc->band->gmode = GMODE_AUTO;
1804 wlc_protection_upd(wlc, WLC_PROT_G_USER,
1808 /* init _n_enab supported mode */
1809 if (WLC_PHY_11N_CAP(wlc->band) && CHIP_SUPPORTS_11N(wlc)) {
1810 if (n_disabled & WLFEATURE_DISABLE_11N) {
1812 wlc_protection_upd(wlc, WLC_PROT_N_USER, OFF);
1814 pub->_n_enab = SUPPORT_11N;
1815 wlc_protection_upd(wlc, WLC_PROT_N_USER,
1817 SUPPORT_11N) ? WL_11N_2x2 :
1822 /* init per-band default rateset, depend on band->gmode */
1823 wlc_default_rateset(wlc, &wlc->band->defrateset);
1825 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1826 wlc_rateset_filter(&wlc->band->defrateset,
1827 &wlc->band->hw_rateset, false,
1828 WLC_RATES_CCK_OFDM, WLC_RATE_MASK,
1829 (bool) N_ENAB(wlc->pub));
1832 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1833 wlc_stf_phy_txant_upd(wlc);
1835 /* attach each modules */
1836 err = wlc_attach_module(wlc);
1840 if (!wlc_timers_init(wlc, unit)) {
1841 wiphy_err(wl->wiphy, "wl%d: %s: wlc_init_timer failed\n", unit,
1847 /* depend on rateset, gmode */
1848 wlc->cmi = wlc_channel_mgr_attach(wlc);
1850 wiphy_err(wl->wiphy, "wl%d: %s: wlc_channel_mgr_attach failed"
1851 "\n", unit, __func__);
1856 /* init default when all parameters are ready, i.e. ->rateset */
1857 wlc_bss_default_init(wlc);
1860 * Complete the wlc default state initializations..
1863 /* allocate our initial queue */
1864 qi = wlc_txq_alloc(wlc);
1866 wiphy_err(wl->wiphy, "wl%d: %s: failed to malloc tx queue\n",
1871 wlc->active_queue = qi;
1873 wlc->bsscfg[0] = wlc->cfg;
1875 wlc->cfg->wlc = wlc;
1876 pub->txmaxpkts = MAXTXPKTS;
1878 pub->_cnt->version = WL_CNT_T_VERSION;
1879 pub->_cnt->length = sizeof(struct wl_cnt);
1881 WLCNTSET(pub->_wme_cnt->version, WL_WME_CNT_VERSION);
1882 WLCNTSET(pub->_wme_cnt->length, sizeof(wl_wme_cnt_t));
1884 wlc_wme_initparams_sta(wlc, &wlc->wme_param_ie);
1886 wlc->mimoft = FT_HT;
1887 wlc->ht_cap.cap_info = HT_CAP;
1888 if (HT_ENAB(wlc->pub))
1889 wlc->stf->ldpc = AUTO;
1891 wlc->mimo_40txbw = AUTO;
1892 wlc->ofdm_40txbw = AUTO;
1893 wlc->cck_40txbw = AUTO;
1894 wlc_update_mimo_band_bwcap(wlc, WLC_N_BW_20IN2G_40IN5G);
1896 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1897 wlc->rifs_advert = AUTO;
1899 /* Set default values of SGI */
1900 if (WLC_SGI_CAP_PHY(wlc)) {
1901 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1903 } else if (WLCISSSLPNPHY(wlc->band)) {
1904 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1907 wlc_ht_update_sgi_rx(wlc, 0);
1911 /* *******nvram 11n config overrides Start ********* */
1913 /* apply the sgi override from nvram conf */
1914 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_TX)
1917 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_RX)
1918 wlc_ht_update_sgi_rx(wlc, 0);
1920 /* apply the stbc override from nvram conf */
1921 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_TX) {
1922 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
1923 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
1924 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_TX_STBC;
1926 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_RX)
1927 wlc_stf_stbc_rx_set(wlc, HT_CAP_RX_STBC_NO);
1929 /* apply the GF override from nvram conf */
1930 if (n_disabled & WLFEATURE_DISABLE_11N_GF)
1931 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_GRN_FLD;
1933 /* initialize radio_mpc_disable according to wlc->mpc */
1934 wlc_radio_mpc_upd(wlc);
1936 if ((wlc->pub->sih->chip) == BCM43235_CHIP_ID) {
1937 if ((getintvar(wlc->pub->vars, "aa2g") == 7) ||
1938 (getintvar(wlc->pub->vars, "aa5g") == 7)) {
1939 wlc_bmac_antsel_set(wlc->hw, 1);
1942 wlc_bmac_antsel_set(wlc->hw, wlc->asi->antsel_avail);
1951 wiphy_err(wl->wiphy, "wl%d: %s: failed with err %d\n",
1952 unit, __func__, err);
1961 static void wlc_attach_antgain_init(struct wlc_info *wlc)
1964 unit = wlc->pub->unit;
1966 if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) {
1967 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
1968 wlc->band->antgain = 8;
1969 } else if (wlc->band->antgain == -1) {
1970 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in"
1971 " srom, using 2dB\n", unit, __func__);
1972 wlc->band->antgain = 8;
1975 /* Older sroms specified gain in whole dbm only. In order
1976 * be able to specify qdbm granularity and remain backward compatible
1977 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
1978 * are encoded in the hi 2 bits. 6 bit signed number ranges from
1979 * -32 - 31. Examples: 0x1 = 1 db,
1980 * 0xc1 = 1.75 db (1 + 3 quarters),
1981 * 0x3f = -1 (-1 + 0 quarters),
1982 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
1983 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
1985 gain = wlc->band->antgain & 0x3f;
1986 gain <<= 2; /* Sign extend */
1988 fract = (wlc->band->antgain & 0xc0) >> 6;
1989 wlc->band->antgain = 4 * gain + fract;
1993 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc)
2000 unit = wlc->pub->unit;
2001 vars = wlc->pub->vars;
2002 bandtype = wlc->band->bandtype;
2004 /* get antennas available */
2005 aa = (s8) getintvar(vars, (BAND_5G(bandtype) ? "aa5g" : "aa2g"));
2007 aa = (s8) getintvar(vars,
2008 (BAND_5G(bandtype) ? "aa1" : "aa0"));
2009 if ((aa < 1) || (aa > 15)) {
2010 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in"
2011 " srom (0x%x), using 3\n", unit, __func__, aa);
2015 /* reset the defaults if we have a single antenna */
2017 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0;
2018 wlc->stf->txant = ANT_TX_FORCE_0;
2019 } else if (aa == 2) {
2020 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1;
2021 wlc->stf->txant = ANT_TX_FORCE_1;
2025 /* Compute Antenna Gain */
2026 wlc->band->antgain =
2027 (s8) getintvar(vars, (BAND_5G(bandtype) ? "ag1" : "ag0"));
2028 wlc_attach_antgain_init(wlc);
2034 static void wlc_timers_deinit(struct wlc_info *wlc)
2036 /* free timer state */
2038 wl_free_timer(wlc->wl, wlc->wdtimer);
2039 wlc->wdtimer = NULL;
2041 if (wlc->radio_timer) {
2042 wl_free_timer(wlc->wl, wlc->radio_timer);
2043 wlc->radio_timer = NULL;
2047 static void wlc_detach_module(struct wlc_info *wlc)
2050 wlc_antsel_detach(wlc->asi);
2055 wlc_ampdu_detach(wlc->ampdu);
2059 wlc_stf_detach(wlc);
2063 * Return a count of the number of driver callbacks still pending.
2065 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2066 * touch hardware registers since the d11core may be in reset and clock may not be available.
2067 * One exception is sb register access, which is possible if crystal is turned on
2068 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2070 uint wlc_detach(struct wlc_info *wlc)
2078 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
2080 ASSERT(!wlc->pub->up);
2082 callbacks += wlc_bmac_detach(wlc);
2084 /* delete software timers */
2085 if (!wlc_radio_monitor_stop(wlc))
2088 wlc_channel_mgr_detach(wlc->cmi);
2090 wlc_timers_deinit(wlc);
2092 wlc_detach_module(wlc);
2094 /* free other state */
2098 kfree(wlc->country_ie_override);
2099 wlc->country_ie_override = NULL;
2103 /* free dumpcb list */
2104 struct dumpcb_s *prev, *ptr;
2105 prev = ptr = wlc->dumpcb_head;
2111 wlc->dumpcb_head = NULL;
2114 /* Detach from iovar manager */
2115 wlc_module_unregister(wlc->pub, "wlc_iovars", wlc);
2117 while (wlc->tx_queues != NULL)
2118 wlc_txq_free(wlc, wlc->tx_queues);
2121 * consistency check: wlc_module_register/wlc_module_unregister calls
2122 * should match therefore nothing should be left here.
2124 for (i = 0; i < WLC_MAXMODULES; i++)
2125 ASSERT(wlc->modulecb[i].name[0] == '\0');
2127 wlc_detach_mfree(wlc);
2131 /* update state that depends on the current value of "ap" */
2132 void wlc_ap_upd(struct wlc_info *wlc)
2134 if (AP_ENAB(wlc->pub))
2135 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */
2137 wlc->PLCPHdr_override = WLC_PLCP_SHORT; /* STA-BSS; short capable */
2139 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2140 wlc->vlan_mode = AP_ENAB(wlc->pub) ? OFF : AUTO;
2146 /* read hwdisable state and propagate to wlc flag */
2147 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc)
2149 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off)
2152 if (wlc_bmac_radio_read_hwdisabled(wlc->hw)) {
2153 mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2155 mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2159 /* return true if Minimum Power Consumption should be entered, false otherwise */
2160 bool wlc_is_non_delay_mpc(struct wlc_info *wlc)
2165 bool wlc_ismpc(struct wlc_info *wlc)
2167 return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc));
2170 void wlc_radio_mpc_upd(struct wlc_info *wlc)
2172 bool mpc_radio, radio_state;
2175 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2176 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2177 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2178 * the radio is going down.
2181 if (!wlc->pub->radio_disabled)
2183 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2185 if (!wlc->pub->radio_disabled)
2186 wlc_radio_monitor_stop(wlc);
2191 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2192 * to go ON, always call radio_upd synchronously
2193 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2196 (mboolisset(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE) ? OFF :
2198 mpc_radio = (wlc_ismpc(wlc) == true) ? OFF : ON;
2200 if (radio_state == ON && mpc_radio == OFF)
2201 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2202 else if (radio_state == OFF && mpc_radio == ON) {
2203 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2205 if (wlc->mpc_offcnt < WLC_MPC_THRESHOLD) {
2206 wlc->mpc_dlycnt = WLC_MPC_MAX_DELAYCNT;
2208 wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
2209 wlc->mpc_dur += OSL_SYSUPTIME() - wlc->mpc_laston_ts;
2211 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2212 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2213 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2215 if ((wlc->prev_non_delay_mpc == false) &&
2216 (wlc_is_non_delay_mpc(wlc) == true) && wlc->mpc_delay_off) {
2217 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2219 wlc->prev_non_delay_mpc = wlc_is_non_delay_mpc(wlc);
2223 * centralized radio disable/enable function,
2224 * invoke radio enable/disable after updating hwradio status
2226 static void wlc_radio_upd(struct wlc_info *wlc)
2228 if (wlc->pub->radio_disabled) {
2229 wlc_radio_disable(wlc);
2231 wlc_radio_enable(wlc);
2235 /* maintain LED behavior in down state */
2236 static void wlc_down_led_upd(struct wlc_info *wlc)
2238 ASSERT(!wlc->pub->up);
2240 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2241 /* turn on sbclk if necessary */
2242 if (!AP_ENAB(wlc->pub)) {
2243 wlc_pllreq(wlc, true, WLC_PLLREQ_FLIP);
2245 wlc_pllreq(wlc, false, WLC_PLLREQ_FLIP);
2249 /* update hwradio status and return it */
2250 bool wlc_check_radio_disabled(struct wlc_info *wlc)
2252 wlc_radio_hwdisable_upd(wlc);
2254 return mboolisset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE) ? true : false;
2257 void wlc_radio_disable(struct wlc_info *wlc)
2259 if (!wlc->pub->up) {
2260 wlc_down_led_upd(wlc);
2264 wlc_radio_monitor_start(wlc);
2268 static void wlc_radio_enable(struct wlc_info *wlc)
2273 if (DEVICEREMOVED(wlc))
2276 if (!wlc->down_override) { /* imposed by wl down/out ioctl */
2281 /* periodical query hw radio button while driver is "down" */
2282 static void wlc_radio_timer(void *arg)
2284 struct wlc_info *wlc = (struct wlc_info *) arg;
2286 if (DEVICEREMOVED(wlc)) {
2287 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit,
2293 /* cap mpc off count */
2294 if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT)
2297 /* validate all the reasons driver could be down and running this radio_timer */
2298 ASSERT(wlc->pub->radio_disabled || wlc->down_override);
2299 wlc_radio_hwdisable_upd(wlc);
2303 static bool wlc_radio_monitor_start(struct wlc_info *wlc)
2305 /* Don't start the timer if HWRADIO feature is disabled */
2306 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
2309 wlc->radio_monitor = true;
2310 wlc_pllreq(wlc, true, WLC_PLLREQ_RADIO_MON);
2311 wl_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true);
2315 bool wlc_radio_monitor_stop(struct wlc_info *wlc)
2317 if (!wlc->radio_monitor)
2320 ASSERT((wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO) !=
2323 wlc->radio_monitor = false;
2324 wlc_pllreq(wlc, false, WLC_PLLREQ_RADIO_MON);
2325 return wl_del_timer(wlc->wl, wlc->radio_timer);
2328 /* bring the driver down, but don't reset hardware */
2329 void wlc_out(struct wlc_info *wlc)
2331 wlc_bmac_set_noreset(wlc->hw, true);
2334 wlc_bmac_set_noreset(wlc->hw, false);
2336 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2339 /* This will make sure that when 'up' is done
2340 * after 'out' it'll restore hardware (especially gpios)
2342 wlc->pub->hw_up = false;
2346 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2347 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2348 * in prec_map. Of course, ignore this rule when block_datafifo is set
2350 static bool wlc_tx_prec_map_verify(struct wlc_info *wlc)
2352 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2355 if (!EDCF_ENAB(wlc->pub)) {
2356 if (!(WLC_TX_FIFO_CHECK(wlc, TX_DATA_FIFO) ||
2357 WLC_TX_FIFO_CHECK(wlc, TX_CTL_FIFO)))
2363 return WLC_TX_FIFO_CHECK(wlc, TX_AC_BK_FIFO)
2364 && WLC_TX_FIFO_CHECK(wlc, TX_AC_BE_FIFO)
2365 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VI_FIFO)
2366 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VO_FIFO);
2370 static void wlc_watchdog_by_timer(void *arg)
2372 struct wlc_info *wlc = (struct wlc_info *) arg;
2374 if (WLC_WATCHDOG_TBTT(wlc)) {
2375 /* set to normal osl watchdog period */
2376 wl_del_timer(wlc->wl, wlc->wdtimer);
2377 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
2382 /* common watchdog code */
2383 static void wlc_watchdog(void *arg)
2385 struct wlc_info *wlc = (struct wlc_info *) arg;
2387 struct wlc_bsscfg *cfg;
2389 WL_TRACE("wl%d: wlc_watchdog\n", wlc->pub->unit);
2394 if (DEVICEREMOVED(wlc)) {
2395 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit,
2401 /* increment second count */
2404 /* delay radio disable */
2405 if (wlc->mpc_delay_off) {
2406 if (--wlc->mpc_delay_off == 0) {
2407 mboolset(wlc->pub->radio_disabled,
2408 WL_RADIO_MPC_DISABLE);
2409 if (wlc->mpc && wlc_ismpc(wlc))
2410 wlc->mpc_offcnt = 0;
2411 wlc->mpc_laston_ts = OSL_SYSUPTIME();
2416 wlc_radio_mpc_upd(wlc);
2417 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2418 wlc_radio_hwdisable_upd(wlc);
2420 /* if ismpc, driver should be in down state if up/down is allowed */
2421 if (wlc->mpc && wlc_ismpc(wlc))
2422 ASSERT(!wlc->pub->up);
2423 /* if radio is disable, driver may be down, quit here */
2424 if (wlc->pub->radio_disabled)
2427 wlc_bmac_watchdog(wlc);
2429 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2430 if ((wlc->pub->now % SW_TIMER_MAC_STAT_UPD) == 0)
2433 /* Manage TKIP countermeasures timers */
2434 FOREACH_BSS(wlc, i, cfg) {
2435 if (cfg->tk_cm_dt) {
2438 if (cfg->tk_cm_bt) {
2443 /* Call any registered watchdog handlers */
2444 for (i = 0; i < WLC_MAXMODULES; i++) {
2445 if (wlc->modulecb[i].watchdog_fn)
2446 wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl);
2449 if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable &&
2450 ((wlc->pub->now - wlc->tempsense_lasttime) >=
2451 WLC_TEMPSENSE_PERIOD)) {
2452 wlc->tempsense_lasttime = wlc->pub->now;
2453 wlc_tempsense_upd(wlc);
2455 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2456 ASSERT(wlc_bmac_taclear(wlc->hw, true));
2458 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2459 ASSERT(wlc_tx_prec_map_verify(wlc));
2461 ASSERT(wlc_ps_check(wlc));
2464 /* make interface operational */
2465 int wlc_up(struct wlc_info *wlc)
2467 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2469 /* HW is turned off so don't try to access it */
2470 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
2471 return -BCME_RADIOOFF;
2473 if (!wlc->pub->hw_up) {
2474 wlc_bmac_hw_up(wlc->hw);
2475 wlc->pub->hw_up = true;
2478 if ((wlc->pub->boardflags & BFL_FEM)
2479 && (wlc->pub->sih->chip == BCM4313_CHIP_ID)) {
2480 if (wlc->pub->boardrev >= 0x1250
2481 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2482 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
2483 MHF5_4313_GPIOCTRL, WLC_BAND_ALL);
2485 wlc_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE, MHF4_EXTPA_ENABLE,
2491 * Need to read the hwradio status here to cover the case where the system
2492 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2493 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2494 * don't call radio_update to avoid looping wlc_up.
2496 * wlc_bmac_up_prep() returns either 0 or -BCME_RADIOOFF only
2498 if (!wlc->pub->radio_disabled) {
2499 int status = wlc_bmac_up_prep(wlc->hw);
2500 if (status == -BCME_RADIOOFF) {
2502 (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) {
2504 struct wlc_bsscfg *bsscfg;
2505 mboolset(wlc->pub->radio_disabled,
2506 WL_RADIO_HW_DISABLE);
2508 FOREACH_BSS(wlc, idx, bsscfg) {
2509 if (!BSSCFG_STA(bsscfg)
2510 || !bsscfg->enable || !bsscfg->BSS)
2512 wiphy_err(wlc->wiphy, "wl%d.%d: wlc_up"
2514 "wlc_bsscfg_disable()\n",
2515 wlc->pub->unit, idx);
2522 if (wlc->pub->radio_disabled) {
2523 wlc_radio_monitor_start(wlc);
2527 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2530 wlc_radio_monitor_stop(wlc);
2532 /* Set EDCF hostflags */
2533 if (EDCF_ENAB(wlc->pub)) {
2534 wlc_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL);
2536 wlc_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL);
2539 if (WLC_WAR16165(wlc))
2540 wlc_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR,
2544 wlc->pub->up = true;
2546 if (wlc->bandinit_pending) {
2547 wlc_suspend_mac_and_wait(wlc);
2548 wlc_set_chanspec(wlc, wlc->default_bss->chanspec);
2549 wlc->bandinit_pending = false;
2550 wlc_enable_mac(wlc);
2553 wlc_bmac_up_finish(wlc->hw);
2555 /* other software states up after ISR is running */
2556 /* start APs that were to be brought up but are not up yet */
2557 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2559 /* Program the TX wme params with the current settings */
2560 wlc_wme_retries_write(wlc);
2562 /* start one second watchdog timer */
2563 ASSERT(!wlc->WDarmed);
2564 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true);
2565 wlc->WDarmed = true;
2567 /* ensure antenna config is up to date */
2568 wlc_stf_phy_txant_upd(wlc);
2569 /* ensure LDPC config is in sync */
2570 wlc_ht_update_ldpc(wlc, wlc->stf->ldpc);
2575 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2576 static void wlc_tx_prec_map_init(struct wlc_info *wlc)
2578 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2579 memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16));
2581 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2582 * if either is full.
2584 if (!EDCF_ENAB(wlc->pub)) {
2585 wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL;
2586 wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL;
2588 wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK;
2589 wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE;
2590 wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI;
2591 wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO;
2595 static uint wlc_down_del_timer(struct wlc_info *wlc)
2603 * Mark the interface nonoperational, stop the software mechanisms,
2604 * disable the hardware, free any transient buffer state.
2605 * Return a count of the number of driver callbacks still pending.
2607 uint wlc_down(struct wlc_info *wlc)
2612 bool dev_gone = false;
2613 struct wlc_txq_info *qi;
2615 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2617 /* check if we are already in the going down path */
2618 if (wlc->going_down) {
2619 wiphy_err(wlc->wiphy, "wl%d: %s: Driver going down so return"
2620 "\n", wlc->pub->unit, __func__);
2626 /* in between, mpc could try to bring down again.. */
2627 wlc->going_down = true;
2629 callbacks += wlc_bmac_down_prep(wlc->hw);
2631 dev_gone = DEVICEREMOVED(wlc);
2633 /* Call any registered down handlers */
2634 for (i = 0; i < WLC_MAXMODULES; i++) {
2635 if (wlc->modulecb[i].down_fn)
2637 wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
2640 /* cancel the watchdog timer */
2642 if (!wl_del_timer(wlc->wl, wlc->wdtimer))
2644 wlc->WDarmed = false;
2646 /* cancel all other timers */
2647 callbacks += wlc_down_del_timer(wlc);
2649 /* interrupt must have been blocked */
2650 ASSERT((wlc->macintmask == 0) || !wlc->pub->up);
2652 wlc->pub->up = false;
2654 wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL);
2656 /* clear txq flow control */
2657 wlc_txflowcontrol_reset(wlc);
2659 /* flush tx queues */
2660 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
2661 pktq_flush(&qi->q, true, NULL, 0);
2662 ASSERT(pktq_empty(&qi->q));
2665 callbacks += wlc_bmac_down_finish(wlc->hw);
2667 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2671 /* Since all the packets should have been freed,
2672 * all callbacks should have been called
2674 for (i = 1; i <= wlc->pub->tunables->maxpktcb; i++)
2675 ASSERT(wlc->pkt_callback[i].fn == NULL);
2677 wlc->going_down = false;
2681 /* Set the current gmode configuration */
2682 int wlc_set_gmode(struct wlc_info *wlc, u8 gmode, bool config)
2687 /* Default to 54g Auto */
2688 s8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2689 bool shortslot_restrict = false; /* Restrict association to stations that support shortslot
2691 bool ignore_bcns = true; /* Ignore legacy beacons on the same channel */
2692 bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */
2693 int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2694 bool preamble_restrict = false; /* Restrict association to stations that support short
2697 struct wlcband *band;
2699 /* if N-support is enabled, allow Gmode set as long as requested
2700 * Gmode is not GMODE_LEGACY_B
2702 if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B)
2703 return -BCME_UNSUPPORTED;
2705 /* verify that we are dealing with 2G band and grab the band pointer */
2706 if (wlc->band->bandtype == WLC_BAND_2G)
2708 else if ((NBANDS(wlc) > 1) &&
2709 (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G))
2710 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
2712 return -BCME_BADBAND;
2714 /* Legacy or bust when no OFDM is supported by regulatory */
2715 if ((wlc_channel_locale_flags_in_band(wlc->cmi, band->bandunit) &
2716 WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B))
2719 /* update configuration value */
2721 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode);
2723 /* Clear supported rates filter */
2724 memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t));
2726 /* Clear rateset override */
2727 memset(&rs, 0, sizeof(wlc_rateset_t));
2730 case GMODE_LEGACY_B:
2731 shortslot = WLC_SHORTSLOT_OFF;
2732 wlc_rateset_copy(&gphy_legacy_rates, &rs);
2737 if (AP_ENAB(wlc->pub))
2738 wlc_rateset_copy(&cck_rates, &wlc->sup_rates_override);
2742 /* Accept defaults */
2747 preamble = WLC_PLCP_SHORT;
2748 preamble_restrict = true;
2751 case GMODE_PERFORMANCE:
2752 if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */
2753 wlc_rateset_copy(&cck_ofdm_rates,
2754 &wlc->sup_rates_override);
2756 shortslot = WLC_SHORTSLOT_ON;
2757 shortslot_restrict = true;
2759 preamble = WLC_PLCP_SHORT;
2760 preamble_restrict = true;
2765 wiphy_err(wlc->wiphy, "wl%d: %s: invalid gmode %d\n",
2766 wlc->pub->unit, __func__, gmode);
2767 return -BCME_UNSUPPORTED;
2771 * If we are switching to gmode == GMODE_LEGACY_B,
2772 * clean up rate info that may refer to OFDM rates.
2774 if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) {
2775 band->gmode = gmode;
2776 if (band->rspec_override && !IS_CCK(band->rspec_override)) {
2777 band->rspec_override = 0;
2778 wlc_reprate_init(wlc);
2780 if (band->mrspec_override && !IS_CCK(band->mrspec_override)) {
2781 band->mrspec_override = 0;
2785 band->gmode = gmode;
2787 wlc->ignore_bcns = ignore_bcns;
2789 wlc->shortslot_override = shortslot;
2791 if (AP_ENAB(wlc->pub)) {
2792 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2793 wlc->PLCPHdr_override =
2795 WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO;
2798 if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG)
2799 || preamble == WLC_PLCP_SHORT)
2800 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2802 wlc->default_bss->capability &= ~WLAN_CAPABILITY_SHORT_PREAMBLE;
2804 /* Update shortslot capability bit for AP and IBSS */
2805 if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) ||
2806 shortslot == WLC_SHORTSLOT_ON)
2807 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2809 wlc->default_bss->capability &=
2810 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
2812 /* Use the default 11g rateset */
2814 wlc_rateset_copy(&cck_ofdm_rates, &rs);
2817 for (i = 0; i < rs.count; i++) {
2818 if (rs.rates[i] == WLC_RATE_6M
2819 || rs.rates[i] == WLC_RATE_12M
2820 || rs.rates[i] == WLC_RATE_24M)
2821 rs.rates[i] |= WLC_RATE_FLAG;
2825 /* Set default bss rateset */
2826 wlc->default_bss->rateset.count = rs.count;
2827 memcpy(wlc->default_bss->rateset.rates, rs.rates,
2828 sizeof(wlc->default_bss->rateset.rates));
2833 static int wlc_nmode_validate(struct wlc_info *wlc, s32 nmode)
2845 if (!(WLC_PHY_11N_CAP(wlc->band)))
2846 err = -BCME_BADBAND;
2857 int wlc_set_nmode(struct wlc_info *wlc, s32 nmode)
2862 err = wlc_nmode_validate(wlc, nmode);
2869 wlc->pub->_n_enab = OFF;
2870 wlc->default_bss->flags &= ~WLC_BSS_HT;
2871 /* delete the mcs rates from the default and hw ratesets */
2872 wlc_rateset_mcs_clear(&wlc->default_bss->rateset);
2873 for (i = 0; i < NBANDS(wlc); i++) {
2874 memset(wlc->bandstate[i]->hw_rateset.mcs, 0,
2876 if (IS_MCS(wlc->band->rspec_override)) {
2877 wlc->bandstate[i]->rspec_override = 0;
2878 wlc_reprate_init(wlc);
2880 if (IS_MCS(wlc->band->mrspec_override))
2881 wlc->bandstate[i]->mrspec_override = 0;
2886 if (wlc->stf->txstreams == WL_11N_3x3)
2892 ASSERT(WLC_PHY_11N_CAP(wlc->band));
2893 /* force GMODE_AUTO if NMODE is ON */
2894 wlc_set_gmode(wlc, GMODE_AUTO, true);
2895 if (nmode == WL_11N_3x3)
2896 wlc->pub->_n_enab = SUPPORT_HT;
2898 wlc->pub->_n_enab = SUPPORT_11N;
2899 wlc->default_bss->flags |= WLC_BSS_HT;
2900 /* add the mcs rates to the default and hw ratesets */
2901 wlc_rateset_mcs_build(&wlc->default_bss->rateset,
2902 wlc->stf->txstreams);
2903 for (i = 0; i < NBANDS(wlc); i++)
2904 memcpy(wlc->bandstate[i]->hw_rateset.mcs,
2905 wlc->default_bss->rateset.mcs, MCSSET_LEN);
2916 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg)
2918 wlc_rateset_t rs, new;
2921 memcpy(&rs, rs_arg, sizeof(wlc_rateset_t));
2923 /* check for bad count value */
2924 if ((rs.count == 0) || (rs.count > WLC_NUMRATES))
2925 return -BCME_BADRATESET;
2927 /* try the current band */
2928 bandunit = wlc->band->bandunit;
2929 memcpy(&new, &rs, sizeof(wlc_rateset_t));
2930 if (wlc_rate_hwrs_filter_sort_validate
2931 (&new, &wlc->bandstate[bandunit]->hw_rateset, true,
2932 wlc->stf->txstreams))
2935 /* try the other band */
2936 if (IS_MBAND_UNLOCKED(wlc)) {
2937 bandunit = OTHERBANDUNIT(wlc);
2938 memcpy(&new, &rs, sizeof(wlc_rateset_t));
2939 if (wlc_rate_hwrs_filter_sort_validate(&new,
2941 bandstate[bandunit]->
2943 wlc->stf->txstreams))
2950 /* apply new rateset */
2951 memcpy(&wlc->default_bss->rateset, &new, sizeof(wlc_rateset_t));
2952 memcpy(&wlc->bandstate[bandunit]->defrateset, &new,
2953 sizeof(wlc_rateset_t));
2957 /* simplified integer set interface for common ioctl handler */
2958 int wlc_set(struct wlc_info *wlc, int cmd, int arg)
2960 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
2963 /* simplified integer get interface for common ioctl handler */
2964 int wlc_get(struct wlc_info *wlc, int cmd, int *arg)
2966 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL);
2969 static void wlc_ofdm_rateset_war(struct wlc_info *wlc)
2974 if (wlc->cfg->associated)
2975 r = wlc->cfg->current_bss->rateset.rates[0];
2977 r = wlc->default_bss->rateset.rates[0];
2979 wlc_phy_ofdm_rateset_war(wlc->band->pi, war);
2985 wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
2986 struct wlc_if *wlcif)
2988 return _wlc_ioctl(wlc, cmd, arg, len, wlcif);
2991 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
2993 _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
2994 struct wlc_if *wlcif)
3001 struct scb *nextscb;
3005 struct wlc_bsscfg *bsscfg;
3006 wlc_bss_info_t *current_bss;
3008 /* update bsscfg pointer */
3010 current_bss = bsscfg->current_bss;
3012 /* initialize the following to get rid of compiler warning */
3018 /* If the device is turned off, then it's not "removed" */
3019 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
3020 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit,
3026 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
3028 /* default argument is generic integer */
3029 pval = arg ? (int *)arg:NULL;
3031 /* This will prevent the misaligned access */
3032 if (pval && (u32) len >= sizeof(val))
3033 memcpy(&val, pval, sizeof(val));
3037 /* bool conversion to avoid duplication below */
3038 bool_val = val != 0;
3042 /* A few commands don't need any arguments; all the others do. */
3050 case WLC_START_CHANNEL_QA:
3055 if ((arg == NULL) || (len <= 0)) {
3056 wiphy_err(wlc->wiphy, "wl%d: %s: Command %d needs "
3058 wlc->pub->unit, __func__, cmd);
3059 bcmerror = -BCME_BADARG;
3067 case WLC_GET_MSGLEVEL:
3068 *pval = wl_msg_level;
3071 case WLC_SET_MSGLEVEL:
3076 case WLC_GET_INSTANCE:
3077 *pval = wlc->pub->unit;
3080 case WLC_GET_CHANNEL:{
3081 channel_info_t *ci = (channel_info_t *) arg;
3083 ASSERT(len > (int)sizeof(ci));
3086 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC);
3087 ci->target_channel =
3088 CHSPEC_CHANNEL(wlc->default_bss->chanspec);
3089 ci->scan_channel = 0;
3094 case WLC_SET_CHANNEL:{
3095 chanspec_t chspec = CH20MHZ_CHSPEC(val);
3097 if (val < 0 || val > MAXCHANNEL) {
3098 bcmerror = -BCME_OUTOFRANGECHAN;
3102 if (!wlc_valid_chanspec_db(wlc->cmi, chspec)) {
3103 bcmerror = -BCME_BADCHAN;
3107 if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) {
3108 if (wlc->band->bandunit !=
3109 CHSPEC_WLCBANDUNIT(chspec))
3110 wlc->bandinit_pending = true;
3112 wlc->bandinit_pending = false;
3115 wlc->default_bss->chanspec = chspec;
3116 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3118 (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) {
3119 wlc_set_home_chanspec(wlc, chspec);
3120 wlc_suspend_mac_and_wait(wlc);
3121 wlc_set_chanspec(wlc, chspec);
3122 wlc_enable_mac(wlc);
3128 case WLC_GET_UCFLAGS:
3129 if (!wlc->pub->up) {
3130 bcmerror = -BCME_NOTUP;
3134 /* optional band is stored in the second integer of incoming buffer */
3137 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3139 /* bcmerror checking */
3140 bcmerror = wlc_iocregchk(wlc, band);
3144 if (val >= MHFMAX) {
3145 bcmerror = -BCME_RANGE;
3149 *pval = wlc_bmac_mhf_get(wlc->hw, (u8) val, WLC_BAND_AUTO);
3152 case WLC_SET_UCFLAGS:
3153 if (!wlc->pub->up) {
3154 bcmerror = -BCME_NOTUP;
3158 /* optional band is stored in the second integer of incoming buffer */
3161 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3163 /* bcmerror checking */
3164 bcmerror = wlc_iocregchk(wlc, band);
3170 bcmerror = -BCME_RANGE;
3174 wlc_mhf(wlc, (u8) i, 0xffff, (u16) (val >> NBITS(u16)),
3181 /* optional band is stored in the second integer of incoming buffer */
3184 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3186 /* bcmerror checking */
3187 bcmerror = wlc_iocregchk(wlc, band);
3192 bcmerror = -BCME_BADADDR;
3196 *pval = wlc_read_shm(wlc, (u16) val);
3202 /* optional band is stored in the second integer of incoming buffer */
3205 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3207 /* bcmerror checking */
3208 bcmerror = wlc_iocregchk(wlc, band);
3213 bcmerror = -BCME_BADADDR;
3217 wlc_write_shm(wlc, (u16) val,
3218 (u16) (val >> NBITS(u16)));
3221 case WLC_R_REG: /* MAC registers */
3223 r = (rw_reg_t *) arg;
3224 band = WLC_BAND_AUTO;
3226 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3227 bcmerror = -BCME_BUFTOOSHORT;
3231 if (len >= (int)sizeof(rw_reg_t))
3234 /* bcmerror checking */
3235 bcmerror = wlc_iocregchk(wlc, band);
3239 if ((r->byteoff + r->size) > sizeof(d11regs_t)) {
3240 bcmerror = -BCME_BADADDR;
3243 if (r->size == sizeof(u32))
3245 R_REG((u32 *)((unsigned char *)(unsigned long)regs +
3247 else if (r->size == sizeof(u16))
3249 R_REG((u16 *)((unsigned char *)(unsigned long)regs +
3252 bcmerror = -BCME_BADADDR;
3257 r = (rw_reg_t *) arg;
3258 band = WLC_BAND_AUTO;
3260 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3261 bcmerror = -BCME_BUFTOOSHORT;
3265 if (len >= (int)sizeof(rw_reg_t))
3268 /* bcmerror checking */
3269 bcmerror = wlc_iocregchk(wlc, band);
3273 if (r->byteoff + r->size > sizeof(d11regs_t)) {
3274 bcmerror = -BCME_BADADDR;
3277 if (r->size == sizeof(u32))
3278 W_REG((u32 *)((unsigned char *)(unsigned long) regs +
3279 r->byteoff), r->val);
3280 else if (r->size == sizeof(u16))
3281 W_REG((u16 *)((unsigned char *)(unsigned long) regs +
3282 r->byteoff), r->val);
3284 bcmerror = -BCME_BADADDR;
3289 *pval = wlc->stf->txant;
3293 bcmerror = wlc_stf_ant_txant_validate(wlc, (s8) val);
3297 wlc->stf->txant = (s8) val;
3299 /* if down, we are done */
3303 wlc_suspend_mac_and_wait(wlc);
3305 wlc_stf_phy_txant_upd(wlc);
3306 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
3308 wlc_enable_mac(wlc);
3312 case WLC_GET_ANTDIV:{
3315 /* return configured value if core is down */
3316 if (!wlc->pub->up) {
3317 *pval = wlc->stf->ant_rx_ovr;
3320 if (wlc_phy_ant_rxdiv_get
3321 (wlc->band->pi, &phy_antdiv))
3322 *pval = (int)phy_antdiv;
3324 *pval = (int)wlc->stf->ant_rx_ovr;
3329 case WLC_SET_ANTDIV:
3330 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3331 if ((val < -1) || (val > 3)) {
3332 bcmerror = -BCME_RANGE;
3337 val = ANT_RX_DIV_DEF;
3339 wlc->stf->ant_rx_ovr = (u8) val;
3340 wlc_phy_ant_rxdiv_set(wlc->band->pi, (u8) val);
3343 case WLC_GET_RX_ANT:{ /* get latest used rx antenna */
3346 if (!wlc->pub->up) {
3347 bcmerror = -BCME_NOTUP;
3351 rxstatus = R_REG(&wlc->regs->phyrxstatus0);
3352 if (rxstatus == 0xdead || rxstatus == (u16) -1) {
3353 bcmerror = -BCME_ERROR;
3356 *pval = (rxstatus & PRXS0_RXANT_UPSUBBAND) ? 1 : 0;
3361 case WLC_GET_UCANTDIV:
3363 bcmerror = -BCME_NOCLK;
3368 (wlc_bmac_mhf_get(wlc->hw, MHF1, WLC_BAND_AUTO) &
3372 case WLC_SET_UCANTDIV:{
3373 if (!wlc->pub->up) {
3374 bcmerror = -BCME_NOTUP;
3378 /* if multiband, band must be locked */
3379 if (IS_MBAND_UNLOCKED(wlc)) {
3380 bcmerror = -BCME_NOTBANDLOCKED;
3384 wlc_mhf(wlc, MHF1, MHF1_ANTDIV,
3385 (val ? MHF1_ANTDIV : 0), WLC_BAND_AUTO);
3388 #endif /* defined(BCMDBG) */
3395 if (val >= 1 && val <= RETRY_SHORT_MAX) {
3397 wlc->SRL = (u16) val;
3399 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3401 for (ac = 0; ac < AC_COUNT; ac++) {
3402 WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL);
3404 wlc_wme_retries_write(wlc);
3406 bcmerror = -BCME_RANGE;
3414 if (val >= 1 && val <= 255) {
3416 wlc->LRL = (u16) val;
3418 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3420 for (ac = 0; ac < AC_COUNT; ac++) {
3421 WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL);
3423 wlc_wme_retries_write(wlc);
3425 bcmerror = -BCME_RANGE;
3429 *pval = wlc->band->CWmin;
3434 bcmerror = -BCME_NOCLK;
3438 if (val >= 1 && val <= 255) {
3439 wlc_set_cwmin(wlc, (u16) val);
3441 bcmerror = -BCME_RANGE;
3445 *pval = wlc->band->CWmax;
3450 bcmerror = -BCME_NOCLK;
3454 if (val >= 255 && val <= 2047) {
3455 wlc_set_cwmax(wlc, (u16) val);
3457 bcmerror = -BCME_RANGE;
3460 case WLC_GET_RADIO: /* use mask if don't want to expose some internal bits */
3461 *pval = wlc->pub->radio_disabled;
3464 case WLC_SET_RADIO:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3467 u16 radiomask, radioval;
3469 WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE;
3472 radiomask = (val & 0xffff0000) >> 16;
3473 radioval = val & 0x0000ffff;
3475 if ((radiomask == 0) || (radiomask & ~validbits)
3476 || (radioval & ~validbits)
3477 || ((radioval & ~radiomask) != 0)) {
3478 wiphy_err(wlc->wiphy, "SET_RADIO with wrong "
3479 "bits 0x%x\n", val);
3480 bcmerror = -BCME_RANGE;
3485 (wlc->pub->radio_disabled & ~radiomask) | radioval;
3486 wlc->pub->radio_disabled = new;
3488 wlc_radio_hwdisable_upd(wlc);
3493 case WLC_GET_PHYTYPE:
3494 *pval = WLC_PHYTYPE(wlc->band->phytype);
3499 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc))) {
3502 wsec_key_t *src_key = wlc->wsec_keys[val];
3504 if (len < (int)sizeof(key)) {
3505 bcmerror = -BCME_BUFTOOSHORT;
3509 memset((char *)&key, 0, sizeof(key));
3511 key.index = src_key->id;
3512 key.len = src_key->len;
3513 memcpy(key.data, src_key->data, key.len);
3514 key.algo = src_key->algo;
3515 if (WSEC_SOFTKEY(wlc, src_key, bsscfg))
3516 key.flags |= WL_SOFT_KEY;
3517 if (src_key->flags & WSEC_PRIMARY_KEY)
3518 key.flags |= WL_PRIMARY_KEY;
3520 memcpy(key.ea, src_key->ea, ETH_ALEN);
3523 memcpy(arg, &key, sizeof(key));
3525 bcmerror = -BCME_BADKEYIDX;
3527 #endif /* defined(BCMDBG) */
3531 wlc_iovar_op(wlc, "wsec_key", NULL, 0, arg, len, IOV_SET,
3535 case WLC_GET_KEY_SEQ:{
3538 if (len < DOT11_WPA_KEY_RSC_LEN) {
3539 bcmerror = -BCME_BUFTOOSHORT;
3543 /* Return the key's tx iv as an EAPOL sequence counter.
3544 * This will be used to supply the RSC value to a supplicant.
3545 * The format is 8 bytes, with least significant in seq[0].
3548 key = WSEC_KEY(wlc, val);
3549 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc)) &&
3551 u8 seq[DOT11_WPA_KEY_RSC_LEN];
3554 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3555 if ((bsscfg->WPA_auth & WPA_AUTH_NONE) &&
3556 is_zero_ether_addr(key->ea)) {
3557 lo = bsscfg->wpa_none_txiv.lo;
3558 hi = bsscfg->wpa_none_txiv.hi;
3564 /* format the buffer, low to high */
3566 seq[1] = (lo >> 8) & 0xff;
3568 seq[3] = (hi >> 8) & 0xff;
3569 seq[4] = (hi >> 16) & 0xff;
3570 seq[5] = (hi >> 24) & 0xff;
3574 memcpy(arg, seq, sizeof(seq));
3576 bcmerror = -BCME_BADKEYIDX;
3581 case WLC_GET_CURR_RATESET:{
3582 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3585 if (wlc->pub->associated)
3586 rs = ¤t_bss->rateset;
3588 rs = &wlc->default_bss->rateset;
3590 if (len < (int)(rs->count + sizeof(rs->count))) {
3591 bcmerror = -BCME_BUFTOOSHORT;
3595 /* Copy only legacy rateset section */
3596 ret_rs->count = rs->count;
3597 memcpy(&ret_rs->rates, &rs->rates, rs->count);
3601 case WLC_GET_RATESET:{
3603 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3605 memset(&rs, 0, sizeof(wlc_rateset_t));
3606 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs);
3608 if (len < (int)(rs.count + sizeof(rs.count))) {
3609 bcmerror = -BCME_BUFTOOSHORT;
3613 /* Copy only legacy rateset section */
3614 ret_rs->count = rs.count;
3615 memcpy(&ret_rs->rates, &rs.rates, rs.count);
3619 case WLC_SET_RATESET:{
3621 wl_rateset_t *in_rs = (wl_rateset_t *) arg;
3623 if (len < (int)(in_rs->count + sizeof(in_rs->count))) {
3624 bcmerror = -BCME_BUFTOOSHORT;
3628 if (in_rs->count > WLC_NUMRATES) {
3629 bcmerror = -BCME_BUFTOOLONG;
3633 memset(&rs, 0, sizeof(wlc_rateset_t));
3635 /* Copy only legacy rateset section */
3636 rs.count = in_rs->count;
3637 memcpy(&rs.rates, &in_rs->rates, rs.count);
3639 /* merge rateset coming in with the current mcsset */
3640 if (N_ENAB(wlc->pub)) {
3641 if (bsscfg->associated)
3643 ¤t_bss->rateset.mcs[0],
3647 &wlc->default_bss->rateset.mcs[0],
3651 bcmerror = wlc_set_rateset(wlc, &rs);
3654 wlc_ofdm_rateset_war(wlc);
3659 case WLC_GET_BCNPRD:
3660 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3661 *pval = current_bss->beacon_period;
3663 *pval = wlc->default_bss->beacon_period;
3666 case WLC_SET_BCNPRD:
3667 /* range [1, 0xffff] */
3668 if (val >= DOT11_MIN_BEACON_PERIOD
3669 && val <= DOT11_MAX_BEACON_PERIOD) {
3670 wlc->default_bss->beacon_period = (u16) val;
3672 bcmerror = -BCME_RANGE;
3675 case WLC_GET_DTIMPRD:
3676 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3677 *pval = current_bss->dtim_period;
3679 *pval = wlc->default_bss->dtim_period;
3682 case WLC_SET_DTIMPRD:
3683 /* range [1, 0xff] */
3684 if (val >= DOT11_MIN_DTIM_PERIOD
3685 && val <= DOT11_MAX_DTIM_PERIOD) {
3686 wlc->default_bss->dtim_period = (u8) val;
3688 bcmerror = -BCME_RANGE;
3697 if ((val >= PM_OFF) && (val <= PM_MAX)) {
3701 /* Change watchdog driver to align watchdog with tbtt if possible */
3702 wlc_watchdog_upd(wlc, PS_ALLOWED(wlc));
3704 bcmerror = -BCME_ERROR;
3706 #endif /* SUPPORT_PS */
3711 if (AP_ENAB(wlc->pub)) {
3712 bcmerror = -BCME_NOTSTA;
3719 if (AP_ENAB(wlc->pub)) {
3720 bcmerror = -BCME_NOTSTA;
3724 wlc->wake = val ? true : false;
3726 /* if down, we're done */
3730 /* apply to the mac */
3731 wlc_set_ps_ctrl(wlc);
3734 #endif /* SUPPORT_PS */
3736 case WLC_GET_REVINFO:
3737 bcmerror = wlc_get_revision_info(wlc, arg, (uint) len);
3741 *pval = (int)AP_ENAB(wlc->pub);
3745 if (bsscfg->associated)
3746 *pval = (int)current_bss->atim_window;
3748 *pval = (int)wlc->default_bss->atim_window;
3752 wlc->default_bss->atim_window = (u32) val;
3755 case WLC_GET_PKTCNTS:{
3756 get_pktcnt_t *pktcnt = (get_pktcnt_t *) pval;
3758 pktcnt->rx_good_pkt = wlc->pub->_cnt->rxframe;
3759 pktcnt->rx_bad_pkt = wlc->pub->_cnt->rxerror;
3760 pktcnt->tx_good_pkt =
3761 wlc->pub->_cnt->txfrmsnt;
3762 pktcnt->tx_bad_pkt =
3763 wlc->pub->_cnt->txerror +
3764 wlc->pub->_cnt->txfail;
3765 if (len >= (int)sizeof(get_pktcnt_t)) {
3766 /* Be backward compatible - only if buffer is large enough */
3767 pktcnt->rx_ocast_good_pkt =
3768 wlc->pub->_cnt->rxmfrmocast;
3773 #ifdef SUPPORT_HWKEY
3776 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_GET,
3782 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_SET,
3786 case WLC_GET_WPA_AUTH:
3787 *pval = (int)bsscfg->WPA_auth;
3790 case WLC_SET_WPA_AUTH:
3791 /* change of WPA_Auth modifies the PS_ALLOWED state */
3792 if (BSSCFG_STA(bsscfg)) {
3793 bsscfg->WPA_auth = (u16) val;
3795 bsscfg->WPA_auth = (u16) val;
3797 #endif /* SUPPORT_HWKEY */
3799 case WLC_GET_BANDLIST:
3800 /* count of number of bands, followed by each band type */
3801 *pval++ = NBANDS(wlc);
3802 *pval++ = wlc->band->bandtype;
3803 if (NBANDS(wlc) > 1)
3804 *pval++ = wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype;
3808 *pval = wlc->bandlocked ? wlc->band->bandtype : WLC_BAND_AUTO;
3811 case WLC_GET_PHYLIST:
3813 unsigned char *cp = arg;
3815 bcmerror = -BCME_BUFTOOSHORT;
3819 if (WLCISNPHY(wlc->band)) {
3821 } else if (WLCISLCNPHY(wlc->band)) {
3823 } else if (WLCISSSLPNPHY(wlc->band)) {
3830 case WLC_GET_SHORTSLOT:
3831 *pval = wlc->shortslot;
3834 case WLC_GET_SHORTSLOT_OVERRIDE:
3835 *pval = wlc->shortslot_override;
3838 case WLC_SET_SHORTSLOT_OVERRIDE:
3839 if ((val != WLC_SHORTSLOT_AUTO) &&
3840 (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) {
3841 bcmerror = -BCME_RANGE;
3845 wlc->shortslot_override = (s8) val;
3847 /* shortslot is an 11g feature, so no more work if we are
3848 * currently on the 5G band
3850 if (BAND_5G(wlc->band->bandtype))
3853 if (wlc->pub->up && wlc->pub->associated) {
3854 /* let watchdog or beacon processing update shortslot */
3855 } else if (wlc->pub->up) {
3856 /* unassociated shortslot is off */
3857 wlc_switch_shortslot(wlc, false);
3859 /* driver is down, so just update the wlc_info value */
3860 if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) {
3861 wlc->shortslot = false;
3864 (wlc->shortslot_override ==
3871 case WLC_GET_LEGACY_ERP:
3872 *pval = wlc->include_legacy_erp;
3875 case WLC_SET_LEGACY_ERP:
3876 if (wlc->include_legacy_erp == bool_val)
3879 wlc->include_legacy_erp = bool_val;
3881 if (AP_ENAB(wlc->pub) && wlc->clk) {
3882 wlc_update_beacon(wlc);
3883 wlc_update_probe_resp(wlc, true);
3888 if (wlc->band->bandtype == WLC_BAND_2G)
3889 *pval = wlc->band->gmode;
3890 else if (NBANDS(wlc) > 1)
3891 *pval = wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode;
3895 if (!wlc->pub->associated)
3896 bcmerror = wlc_set_gmode(wlc, (u8) val, true);
3898 bcmerror = -BCME_ASSOCIATED;
3903 case WLC_GET_GMODE_PROTECTION:
3904 *pval = wlc->protection->_g;
3907 case WLC_GET_PROTECTION_CONTROL:
3908 *pval = wlc->protection->overlap;
3911 case WLC_SET_PROTECTION_CONTROL:
3912 if ((val != WLC_PROTECTION_CTL_OFF) &&
3913 (val != WLC_PROTECTION_CTL_LOCAL) &&
3914 (val != WLC_PROTECTION_CTL_OVERLAP)) {
3915 bcmerror = -BCME_RANGE;
3919 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, (s8) val);
3921 /* Current g_protection will sync up to the specified control alg in watchdog
3922 * if the driver is up and associated.
3923 * If the driver is down or not associated, the control setting has no effect.
3927 case WLC_GET_GMODE_PROTECTION_OVERRIDE:
3928 *pval = wlc->protection->g_override;
3931 case WLC_SET_GMODE_PROTECTION_OVERRIDE:
3932 if ((val != WLC_PROTECTION_AUTO) &&
3933 (val != WLC_PROTECTION_OFF) && (val != WLC_PROTECTION_ON)) {
3934 bcmerror = -BCME_RANGE;
3938 wlc_protection_upd(wlc, WLC_PROT_G_OVR, (s8) val);
3942 case WLC_SET_SUP_RATESET_OVERRIDE:{
3943 wlc_rateset_t rs, new;
3946 if (len < (int)sizeof(wlc_rateset_t)) {
3947 bcmerror = -BCME_BUFTOOSHORT;
3950 memcpy(&rs, arg, sizeof(wlc_rateset_t));
3952 /* check for bad count value */
3953 if (rs.count > WLC_NUMRATES) {
3954 bcmerror = -BCME_BADRATESET;
3958 /* this command is only appropriate for gmode operation */
3959 if (!(wlc->band->gmode ||
3961 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
3962 /* gmode only command when not in gmode */
3963 bcmerror = -BCME_BADBAND;
3967 /* check for an empty rateset to clear the override */
3968 if (rs.count == 0) {
3969 memset(&wlc->sup_rates_override, 0,
3970 sizeof(wlc_rateset_t));
3975 * validate rateset by comparing pre and
3976 * post sorted against 11g hw rates
3978 wlc_rateset_filter(&rs, &new, false,
3979 WLC_RATES_CCK_OFDM, WLC_RATE_MASK,
3980 BSS_N_ENAB(wlc, bsscfg));
3981 wlc_rate_hwrs_filter_sort_validate(&new,
3984 wlc->stf->txstreams);
3985 if (rs.count != new.count) {
3986 bcmerror = -BCME_BADRATESET;
3990 /* apply new rateset to the override */
3991 memcpy(&wlc->sup_rates_override, &new,
3992 sizeof(wlc_rateset_t));
3994 /* update bcn and probe resp if needed */
3995 if (wlc->pub->up && AP_ENAB(wlc->pub)
3996 && wlc->pub->associated) {
3997 wlc_update_beacon(wlc);
3998 wlc_update_probe_resp(wlc, true);
4003 case WLC_GET_SUP_RATESET_OVERRIDE:
4004 /* this command is only appropriate for gmode operation */
4005 if (!(wlc->band->gmode ||
4007 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4008 /* gmode only command when not in gmode */
4009 bcmerror = -BCME_BADBAND;
4012 if (len < (int)sizeof(wlc_rateset_t)) {
4013 bcmerror = -BCME_BUFTOOSHORT;
4016 memcpy(arg, &wlc->sup_rates_override, sizeof(wlc_rateset_t));
4020 case WLC_GET_PRB_RESP_TIMEOUT:
4021 *pval = wlc->prb_resp_timeout;
4024 case WLC_SET_PRB_RESP_TIMEOUT:
4026 bcmerror = -BCME_NOTDOWN;
4029 if (val < 0 || val >= 0xFFFF) {
4030 bcmerror = -BCME_RANGE; /* bad value */
4033 wlc->prb_resp_timeout = (u16) val;
4036 case WLC_GET_KEY_PRIMARY:{
4039 /* treat the 'val' parm as the key id */
4040 key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4042 *pval = key->id == val ? true : false;
4044 bcmerror = -BCME_BADKEYIDX;
4049 case WLC_SET_KEY_PRIMARY:{
4050 wsec_key_t *key, *old_key;
4052 bcmerror = -BCME_BADKEYIDX;
4054 /* treat the 'val' parm as the key id */
4055 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
4056 key = bsscfg->bss_def_keys[i];
4057 if (key != NULL && key->id == val) {
4058 old_key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4059 if (old_key != NULL)
4062 key->flags |= WSEC_PRIMARY_KEY;
4063 bsscfg->wsec_index = i;
4079 /* validate the name value */
4081 for (i = 0; i < (uint) len && *name != '\0';
4085 if (i == (uint) len) {
4086 bcmerror = -BCME_BUFTOOSHORT;
4089 i++; /* include the null in the string length */
4091 if (cmd == WLC_GET_VAR) {
4093 wlc_iovar_op(wlc, arg,
4094 (void *)((s8 *) arg + i),
4095 len - i, arg, len, IOV_GET,
4099 wlc_iovar_op(wlc, arg, NULL, 0,
4100 (void *)((s8 *) arg + i),
4101 len - i, IOV_SET, wlcif);
4106 case WLC_SET_WSEC_PMK:
4107 bcmerror = -BCME_UNSUPPORTED;
4111 case WLC_CURRENT_PWR:
4113 bcmerror = -BCME_NOTUP;
4115 bcmerror = wlc_get_current_txpwr(wlc, arg, len);
4120 wiphy_err(wlc->wiphy, "%s: WLC_LAST\n", __func__);
4125 if (VALID_BCMERROR(bcmerror))
4126 wlc->pub->bcmerror = bcmerror;
4132 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4133 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4134 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4136 if (!(wlc->pub->hw_off))
4137 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok);
4143 /* consolidated register access ioctl error checking */
4144 int wlc_iocregchk(struct wlc_info *wlc, uint band)
4146 /* if band is specified, it must be the current band */
4147 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype))
4148 return -BCME_BADBAND;
4150 /* if multiband and band is not specified, band must be locked */
4151 if ((band == WLC_BAND_AUTO) && IS_MBAND_UNLOCKED(wlc))
4152 return -BCME_NOTBANDLOCKED;
4154 /* must have core clocks */
4160 #endif /* defined(BCMDBG) */
4163 /* For some ioctls, make sure that the pi pointer matches the current phy */
4164 int wlc_iocpichk(struct wlc_info *wlc, uint phytype)
4166 if (wlc->band->phytype != phytype)
4167 return -BCME_BADBAND;
4172 /* Look up the given var name in the given table */
4173 static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table,
4176 const bcm_iovar_t *vi;
4177 const char *lookup_name;
4179 /* skip any ':' delimited option prefixes */
4180 lookup_name = strrchr(name, ':');
4181 if (lookup_name != NULL)
4186 ASSERT(table != NULL);
4188 for (vi = table; vi->name; vi++) {
4189 if (!strcmp(vi->name, lookup_name))
4192 /* ran to end of table */
4194 return NULL; /* var name not found */
4197 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4198 int wlc_iovar_getint(struct wlc_info *wlc, const char *name, int *arg)
4200 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET,
4204 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4205 int wlc_iovar_setint(struct wlc_info *wlc, const char *name, int arg)
4207 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg),
4211 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4212 int wlc_iovar_gets8(struct wlc_info *wlc, const char *name, s8 *arg)
4218 wlc_iovar_op(wlc, name, NULL, 0, &iovar_int, sizeof(iovar_int),
4221 *arg = (s8) iovar_int;
4227 * register iovar table, watchdog and down handlers.
4228 * calling function must keep 'iovars' until wlc_module_unregister is called.
4229 * 'iovar' must have the last entry's name field being NULL as terminator.
4231 int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
4232 const char *name, void *hdl, iovar_fn_t i_fn,
4233 watchdog_fn_t w_fn, down_fn_t d_fn)
4235 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4238 ASSERT(name != NULL);
4239 ASSERT(i_fn != NULL || w_fn != NULL || d_fn != NULL);
4241 /* find an empty entry and just add, no duplication check! */
4242 for (i = 0; i < WLC_MAXMODULES; i++) {
4243 if (wlc->modulecb[i].name[0] == '\0') {
4244 strncpy(wlc->modulecb[i].name, name,
4245 sizeof(wlc->modulecb[i].name) - 1);
4246 wlc->modulecb[i].iovars = iovars;
4247 wlc->modulecb[i].hdl = hdl;
4248 wlc->modulecb[i].iovar_fn = i_fn;
4249 wlc->modulecb[i].watchdog_fn = w_fn;
4250 wlc->modulecb[i].down_fn = d_fn;
4255 /* it is time to increase the capacity */
4256 ASSERT(i < WLC_MAXMODULES);
4257 return -BCME_NORESOURCE;
4260 /* unregister module callbacks */
4261 int wlc_module_unregister(struct wlc_pub *pub, const char *name, void *hdl)
4263 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4267 return -BCME_NOTFOUND;
4269 ASSERT(name != NULL);
4271 for (i = 0; i < WLC_MAXMODULES; i++) {
4272 if (!strcmp(wlc->modulecb[i].name, name) &&
4273 (wlc->modulecb[i].hdl == hdl)) {
4274 memset(&wlc->modulecb[i], 0, sizeof(struct modulecb));
4279 /* table not found! */
4280 return -BCME_NOTFOUND;
4283 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4284 static void wlc_wme_retries_write(struct wlc_info *wlc)
4288 /* Need clock to do this */
4292 for (ac = 0; ac < AC_COUNT; ac++) {
4293 wlc_write_shm(wlc, M_AC_TXLMT_ADDR(ac), wlc->wme_retries[ac]);
4297 /* Get or set an iovar. The params/p_len pair specifies any additional
4298 * qualifying parameters (e.g. an "element index") for a get, while the
4299 * arg/len pair is the buffer for the value to be set or retrieved.
4300 * Operation (get/set) is specified by the last argument.
4301 * interface context provided by wlcif
4303 * All pointers may point into the same buffer.
4306 wlc_iovar_op(struct wlc_info *wlc, const char *name,
4307 void *params, int p_len, void *arg, int len,
4308 bool set, struct wlc_if *wlcif)
4312 const bcm_iovar_t *vi = NULL;
4316 ASSERT(name != NULL);
4320 /* Get MUST have return space */
4321 ASSERT(set || (arg && len));
4323 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
4325 /* Set does NOT take qualifiers */
4326 ASSERT(!set || (!params && !p_len));
4328 if (!set && (len == sizeof(int)) &&
4329 !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) {
4330 wiphy_err(wlc->wiphy, "wl%d: %s unaligned get ptr for %s\n",
4331 wlc->pub->unit, __func__, name);
4335 /* find the given iovar name */
4336 for (i = 0; i < WLC_MAXMODULES; i++) {
4337 if (!wlc->modulecb[i].iovars)
4339 vi = wlc_iovar_lookup(wlc->modulecb[i].iovars, name);
4343 /* iovar name not found */
4344 if (i >= WLC_MAXMODULES) {
4345 err = -BCME_UNSUPPORTED;
4349 /* set up 'params' pointer in case this is a set command so that
4350 * the convenience int and bool code can be common to set and get
4352 if (params == NULL) {
4357 if (vi->type == IOVT_VOID)
4359 else if (vi->type == IOVT_BUFFER)
4362 /* all other types are integer sized */
4363 val_size = sizeof(int);
4365 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
4367 /* Do the actual parameter implementation */
4368 err = wlc->modulecb[i].iovar_fn(wlc->modulecb[i].hdl, vi, actionid,
4369 name, params, p_len, arg, len, val_size,
4377 wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi, void *arg, int len,
4380 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4384 /* check generic condition flags */
4386 if (((vi->flags & IOVF_SET_DOWN) && wlc->pub->up) ||
4387 ((vi->flags & IOVF_SET_UP) && !wlc->pub->up)) {
4388 err = (wlc->pub->up ? -BCME_NOTDOWN : -BCME_NOTUP);
4389 } else if ((vi->flags & IOVF_SET_BAND)
4390 && IS_MBAND_UNLOCKED(wlc)) {
4391 err = -BCME_NOTBANDLOCKED;
4392 } else if ((vi->flags & IOVF_SET_CLK) && !wlc->clk) {
4396 if (((vi->flags & IOVF_GET_DOWN) && wlc->pub->up) ||
4397 ((vi->flags & IOVF_GET_UP) && !wlc->pub->up)) {
4398 err = (wlc->pub->up ? -BCME_NOTDOWN : -BCME_NOTUP);
4399 } else if ((vi->flags & IOVF_GET_BAND)
4400 && IS_MBAND_UNLOCKED(wlc)) {
4401 err = -BCME_NOTBANDLOCKED;
4402 } else if ((vi->flags & IOVF_GET_CLK) && !wlc->clk) {
4410 /* length check on io buf */
4411 err = bcm_iovar_lencheck(vi, arg, len, set);
4415 /* On set, check value ranges for integer types */
4425 memcpy(&int_val, arg, sizeof(int));
4426 err = wlc_iovar_rangecheck(wlc, int_val, vi);
4434 /* handler for iovar table wlc_iovars */
4436 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4437 * iovar case, the switch statement maps the iovar id into separate get
4438 * and set values. If you add a new iovar to the switch you MUST use
4439 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4441 * Please use params for additional qualifying parameters.
4444 wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4445 const char *name, void *params, uint p_len, void *arg, int len,
4446 int val_size, struct wlc_if *wlcif)
4448 struct wlc_info *wlc = hdl;
4449 struct wlc_bsscfg *bsscfg;
4456 wlc_bss_info_t *current_bss;
4458 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
4463 err = wlc_iovar_check(wlc->pub, vi, arg, len, IOV_ISSET(actionid));
4467 /* convenience int and bool vals for first 8 bytes of buffer */
4468 if (p_len >= (int)sizeof(int_val))
4469 memcpy(&int_val, params, sizeof(int_val));
4471 if (p_len >= (int)sizeof(int_val) * 2)
4473 (void *)((unsigned long)params + sizeof(int_val)),
4476 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4477 ret_int_ptr = (s32 *) arg;
4479 bool_val = (int_val != 0) ? true : false;
4480 bool_val2 = (int_val2 != 0) ? true : false;
4482 WL_TRACE("wl%d: %s: id %d\n",
4483 wlc->pub->unit, __func__, IOV_ID(actionid));
4484 /* Do the actual parameter implementation */
4486 case IOV_SVAL(IOV_RTSTHRESH):
4487 wlc->RTSThresh = int_val;
4490 case IOV_GVAL(IOV_QTXPOWER):{
4494 err = wlc_phy_txpower_get(wlc->band->pi, &qdbm,
4499 /* Return qdbm units */
4501 qdbm | (override ? WL_TXPWR_OVERRIDE : 0);
4505 /* As long as override is false, this only sets the *user* targets.
4506 User can twiddle this all he wants with no harm.
4507 wlc_phy_txpower_set() explicitly sets override to false if
4508 not internal or test.
4510 case IOV_SVAL(IOV_QTXPOWER):{
4514 /* Remove override bit and clip to max qdbm value */
4515 qdbm = (u8)min_t(u32, (int_val & ~WL_TXPWR_OVERRIDE), 0xff);
4516 /* Extract override setting */
4517 override = (int_val & WL_TXPWR_OVERRIDE) ? true : false;
4519 wlc_phy_txpower_set(wlc->band->pi, qdbm, override);
4523 case IOV_GVAL(IOV_MPC):
4524 *ret_int_ptr = (s32) wlc->mpc;
4527 case IOV_SVAL(IOV_MPC):
4528 wlc->mpc = bool_val;
4529 wlc_radio_mpc_upd(wlc);
4533 case IOV_GVAL(IOV_BCN_LI_BCN):
4534 *ret_int_ptr = wlc->bcn_li_bcn;
4537 case IOV_SVAL(IOV_BCN_LI_BCN):
4538 wlc->bcn_li_bcn = (u8) int_val;
4540 wlc_bcn_li_upd(wlc);
4544 wiphy_err(wlc->wiphy, "wl%d: %s: unsupported\n",
4545 wlc->pub->unit, __func__);
4546 err = -BCME_UNSUPPORTED;
4550 goto exit; /* avoid unused label warning */
4557 wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val, const bcm_iovar_t *vi)
4563 /* Only ranged integers are checked */
4566 max_val |= 0x7fffffff;
4569 max_val |= 0x00007fff;
4572 max_val |= 0x0000007f;
4574 if (vi->flags & IOVF_NTRL)
4576 else if (vi->flags & IOVF_WHL)
4578 /* Signed values are checked against max_val and min_val */
4579 if ((s32) val < (s32) min_val
4580 || (s32) val > (s32) max_val)
4585 max_val |= 0xffffffff;
4588 max_val |= 0x0000ffff;
4591 max_val |= 0x000000ff;
4592 if (vi->flags & IOVF_NTRL)
4594 if ((val < min_val) || (val > max_val))
4603 static const char *supr_reason[] = {
4604 "None", "PMQ Entry", "Flush request",
4605 "Previous frag failure", "Channel mismatch",
4606 "Lifetime Expiry", "Underflow"
4609 static void wlc_print_txs_status(u16 s)
4611 printk(KERN_DEBUG "[15:12] %d frame attempts\n",
4612 (s & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT);
4613 printk(KERN_DEBUG " [11:8] %d rts attempts\n",
4614 (s & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT);
4615 printk(KERN_DEBUG " [7] %d PM mode indicated\n",
4616 ((s & TX_STATUS_PMINDCTD) ? 1 : 0));
4617 printk(KERN_DEBUG " [6] %d intermediate status\n",
4618 ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0));
4619 printk(KERN_DEBUG " [5] %d AMPDU\n",
4620 (s & TX_STATUS_AMPDU) ? 1 : 0);
4621 printk(KERN_DEBUG " [4:2] %d Frame Suppressed Reason (%s)\n",
4622 ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT),
4623 supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]);
4624 printk(KERN_DEBUG " [1] %d acked\n",
4625 ((s & TX_STATUS_ACK_RCV) ? 1 : 0));
4629 void wlc_print_txstatus(tx_status_t *txs)
4632 u16 s = txs->status;
4633 u16 ackphyrxsh = txs->ackphyrxsh;
4635 printk(KERN_DEBUG "\ntxpkt (MPDU) Complete\n");
4637 printk(KERN_DEBUG "FrameID: %04x ", txs->frameid);
4638 printk(KERN_DEBUG "TxStatus: %04x", s);
4639 printk(KERN_DEBUG "\n");
4641 wlc_print_txs_status(s);
4643 printk(KERN_DEBUG "LastTxTime: %04x ", txs->lasttxtime);
4644 printk(KERN_DEBUG "Seq: %04x ", txs->sequence);
4645 printk(KERN_DEBUG "PHYTxStatus: %04x ", txs->phyerr);
4646 printk(KERN_DEBUG "RxAckRSSI: %04x ",
4647 (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT);
4648 printk(KERN_DEBUG "RxAckSQ: %04x",
4649 (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
4650 printk(KERN_DEBUG "\n");
4651 #endif /* defined(BCMDBG) */
4655 wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat)
4660 v = le16_to_cpu(cur_stat);
4661 delta = (u16)(v - *macstat_snapshot);
4665 *macstat_snapshot = v;
4669 #define MACSTATUPD(name) \
4670 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4672 void wlc_statsupd(struct wlc_info *wlc)
4682 /* if driver down, make no sense to update stats */
4687 /* save last rx fifo 0 overflow count */
4688 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl;
4690 /* save last tx fifo underflow count */
4691 for (i = 0; i < NFIFO; i++)
4692 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i];
4695 /* Read mac stats from contiguous shared memory */
4696 wlc_bmac_copyfrom_shm(wlc->hw, M_UCODE_MACSTAT,
4697 &macstats, sizeof(macstat_t));
4699 /* update mac stats */
4700 MACSTATUPD(txallfrm);
4701 MACSTATUPD(txrtsfrm);
4702 MACSTATUPD(txctsfrm);
4703 MACSTATUPD(txackfrm);
4704 MACSTATUPD(txdnlfrm);
4705 MACSTATUPD(txbcnfrm);
4706 for (i = 0; i < NFIFO; i++)
4707 MACSTATUPD(txfunfl[i]);
4708 MACSTATUPD(txtplunfl);
4709 MACSTATUPD(txphyerr);
4710 MACSTATUPD(rxfrmtoolong);
4711 MACSTATUPD(rxfrmtooshrt);
4712 MACSTATUPD(rxinvmachdr);
4713 MACSTATUPD(rxbadfcs);
4714 MACSTATUPD(rxbadplcp);
4715 MACSTATUPD(rxcrsglitch);
4717 MACSTATUPD(rxdfrmucastmbss);
4718 MACSTATUPD(rxmfrmucastmbss);
4719 MACSTATUPD(rxcfrmucast);
4720 MACSTATUPD(rxrtsucast);
4721 MACSTATUPD(rxctsucast);
4722 MACSTATUPD(rxackucast);
4723 MACSTATUPD(rxdfrmocast);
4724 MACSTATUPD(rxmfrmocast);
4725 MACSTATUPD(rxcfrmocast);
4726 MACSTATUPD(rxrtsocast);
4727 MACSTATUPD(rxctsocast);
4728 MACSTATUPD(rxdfrmmcast);
4729 MACSTATUPD(rxmfrmmcast);
4730 MACSTATUPD(rxcfrmmcast);
4731 MACSTATUPD(rxbeaconmbss);
4732 MACSTATUPD(rxdfrmucastobss);
4733 MACSTATUPD(rxbeaconobss);
4734 MACSTATUPD(rxrsptmout);
4735 MACSTATUPD(bcntxcancl);
4736 MACSTATUPD(rxf0ovfl);
4737 MACSTATUPD(rxf1ovfl);
4738 MACSTATUPD(rxf2ovfl);
4739 MACSTATUPD(txsfovfl);
4740 MACSTATUPD(pmqovfl);
4741 MACSTATUPD(rxcgprqfrm);
4742 MACSTATUPD(rxcgprsqovfl);
4743 MACSTATUPD(txcgprsfail);
4744 MACSTATUPD(txcgprssuc);
4745 MACSTATUPD(prs_timeout);
4747 MACSTATUPD(frmscons);
4749 MACSTATUPD(txglitch_nack);
4750 MACSTATUPD(txburst);
4751 MACSTATUPD(phywatchdog);
4752 MACSTATUPD(pktengrxducast);
4753 MACSTATUPD(pktengrxdmcast);
4756 /* check for rx fifo 0 overflow */
4757 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
4759 wiphy_err(wlc->wiphy, "wl%d: %u rx fifo 0 overflows!\n",
4760 wlc->pub->unit, delta);
4762 /* check for tx fifo underflows */
4763 for (i = 0; i < NFIFO; i++) {
4765 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
4768 wiphy_err(wlc->wiphy, "wl%d: %u tx fifo %d underflows!"
4769 "\n", wlc->pub->unit, delta, i);
4773 /* dot11 counter update */
4775 WLCNTSET(wlc->pub->_cnt->txrts,
4776 (wlc->pub->_cnt->rxctsucast -
4777 wlc->pub->_cnt->d11cnt_txrts_off));
4778 WLCNTSET(wlc->pub->_cnt->rxcrc,
4779 (wlc->pub->_cnt->rxbadfcs - wlc->pub->_cnt->d11cnt_rxcrc_off));
4780 WLCNTSET(wlc->pub->_cnt->txnocts,
4781 ((wlc->pub->_cnt->txrtsfrm - wlc->pub->_cnt->rxctsucast) -
4782 wlc->pub->_cnt->d11cnt_txnocts_off));
4784 /* merge counters from dma module */
4785 for (i = 0; i < NFIFO; i++) {
4786 if (wlc->hw->di[i]) {
4787 WLCNTADD(wlc->pub->_cnt->txnobuf,
4788 (wlc->hw->di[i])->txnobuf);
4789 WLCNTADD(wlc->pub->_cnt->rxnobuf,
4790 (wlc->hw->di[i])->rxnobuf);
4791 WLCNTADD(wlc->pub->_cnt->rxgiant,
4792 (wlc->hw->di[i])->rxgiants);
4793 dma_counterreset(wlc->hw->di[i]);
4798 * Aggregate transmit and receive errors that probably resulted
4799 * in the loss of a frame are computed on the fly.
4801 WLCNTSET(wlc->pub->_cnt->txerror,
4802 wlc->pub->_cnt->txnobuf + wlc->pub->_cnt->txnoassoc +
4803 wlc->pub->_cnt->txuflo + wlc->pub->_cnt->txrunt +
4804 wlc->pub->_cnt->dmade + wlc->pub->_cnt->dmada +
4805 wlc->pub->_cnt->dmape);
4806 WLCNTSET(wlc->pub->_cnt->rxerror,
4807 wlc->pub->_cnt->rxoflo + wlc->pub->_cnt->rxnobuf +
4808 wlc->pub->_cnt->rxfragerr + wlc->pub->_cnt->rxrunt +
4809 wlc->pub->_cnt->rxgiant + wlc->pub->_cnt->rxnoscb +
4810 wlc->pub->_cnt->rxbadsrcmac);
4811 for (i = 0; i < NFIFO; i++)
4812 wlc->pub->_cnt->rxerror += wlc->pub->_cnt->rxuflo[i];
4815 bool wlc_chipmatch(u16 vendor, u16 device)
4817 if (vendor != PCI_VENDOR_ID_BROADCOM) {
4818 pr_err("wlc_chipmatch: unknown vendor id %04x\n", vendor);
4822 if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID))
4825 if (device == BCM4313_D11N2G_ID)
4827 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
4830 pr_err("wlc_chipmatch: unknown device id %04x\n", device);
4835 void wlc_print_txdesc(d11txh_t *txh)
4837 u16 mtcl = le16_to_cpu(txh->MacTxControlLow);
4838 u16 mtch = le16_to_cpu(txh->MacTxControlHigh);
4839 u16 mfc = le16_to_cpu(txh->MacFrameControl);
4840 u16 tfest = le16_to_cpu(txh->TxFesTimeNormal);
4841 u16 ptcw = le16_to_cpu(txh->PhyTxControlWord);
4842 u16 ptcw_1 = le16_to_cpu(txh->PhyTxControlWord_1);
4843 u16 ptcw_1_Fbr = le16_to_cpu(txh->PhyTxControlWord_1_Fbr);
4844 u16 ptcw_1_Rts = le16_to_cpu(txh->PhyTxControlWord_1_Rts);
4845 u16 ptcw_1_FbrRts = le16_to_cpu(txh->PhyTxControlWord_1_FbrRts);
4846 u16 mainrates = le16_to_cpu(txh->MainRates);
4847 u16 xtraft = le16_to_cpu(txh->XtraFrameTypes);
4849 u8 *ra = txh->TxFrameRA;
4850 u16 tfestfb = le16_to_cpu(txh->TxFesTimeFallback);
4851 u8 *rtspfb = txh->RTSPLCPFallback;
4852 u16 rtsdfb = le16_to_cpu(txh->RTSDurFallback);
4853 u8 *fragpfb = txh->FragPLCPFallback;
4854 u16 fragdfb = le16_to_cpu(txh->FragDurFallback);
4855 u16 mmodelen = le16_to_cpu(txh->MModeLen);
4856 u16 mmodefbrlen = le16_to_cpu(txh->MModeFbrLen);
4857 u16 tfid = le16_to_cpu(txh->TxFrameID);
4858 u16 txs = le16_to_cpu(txh->TxStatus);
4859 u16 mnmpdu = le16_to_cpu(txh->MaxNMpdus);
4860 u16 mabyte = le16_to_cpu(txh->MaxABytes_MRT);
4861 u16 mabyte_f = le16_to_cpu(txh->MaxABytes_FBR);
4862 u16 mmbyte = le16_to_cpu(txh->MinMBytes);
4864 u8 *rtsph = txh->RTSPhyHeader;
4865 struct ieee80211_rts rts = txh->rts_frame;
4868 /* add plcp header along with txh descriptor */
4869 prhex("Raw TxDesc + plcp header", (unsigned char *) txh, sizeof(d11txh_t) + 48);
4871 printk(KERN_DEBUG "TxCtlLow: %04x ", mtcl);
4872 printk(KERN_DEBUG "TxCtlHigh: %04x ", mtch);
4873 printk(KERN_DEBUG "FC: %04x ", mfc);
4874 printk(KERN_DEBUG "FES Time: %04x\n", tfest);
4875 printk(KERN_DEBUG "PhyCtl: %04x%s ", ptcw,
4876 (ptcw & PHY_TXC_SHORT_HDR) ? " short" : "");
4877 printk(KERN_DEBUG "PhyCtl_1: %04x ", ptcw_1);
4878 printk(KERN_DEBUG "PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr);
4879 printk(KERN_DEBUG "PhyCtl_1_Rts: %04x ", ptcw_1_Rts);
4880 printk(KERN_DEBUG "PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts);
4881 printk(KERN_DEBUG "MainRates: %04x ", mainrates);
4882 printk(KERN_DEBUG "XtraFrameTypes: %04x ", xtraft);
4883 printk(KERN_DEBUG "\n");
4885 bcm_format_hex(hexbuf, iv, sizeof(txh->IV));
4886 printk(KERN_DEBUG "SecIV: %s\n", hexbuf);
4887 bcm_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA));
4888 printk(KERN_DEBUG "RA: %s\n", hexbuf);
4890 printk(KERN_DEBUG "Fb FES Time: %04x ", tfestfb);
4891 bcm_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback));
4892 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
4893 printk(KERN_DEBUG "RTS DUR: %04x ", rtsdfb);
4894 bcm_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback));
4895 printk(KERN_DEBUG "PLCP: %s ", hexbuf);
4896 printk(KERN_DEBUG "DUR: %04x", fragdfb);
4897 printk(KERN_DEBUG "\n");
4899 printk(KERN_DEBUG "MModeLen: %04x ", mmodelen);
4900 printk(KERN_DEBUG "MModeFbrLen: %04x\n", mmodefbrlen);
4902 printk(KERN_DEBUG "FrameID: %04x\n", tfid);
4903 printk(KERN_DEBUG "TxStatus: %04x\n", txs);
4905 printk(KERN_DEBUG "MaxNumMpdu: %04x\n", mnmpdu);
4906 printk(KERN_DEBUG "MaxAggbyte: %04x\n", mabyte);
4907 printk(KERN_DEBUG "MaxAggbyte_fb: %04x\n", mabyte_f);
4908 printk(KERN_DEBUG "MinByte: %04x\n", mmbyte);
4910 bcm_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader));
4911 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
4912 bcm_format_hex(hexbuf, (u8 *) &rts, sizeof(txh->rts_frame));
4913 printk(KERN_DEBUG "RTS Frame: %s", hexbuf);
4914 printk(KERN_DEBUG "\n");
4916 #endif /* defined(BCMDBG) */
4919 void wlc_print_rxh(d11rxhdr_t *rxh)
4921 u16 len = rxh->RxFrameSize;
4922 u16 phystatus_0 = rxh->PhyRxStatus_0;
4923 u16 phystatus_1 = rxh->PhyRxStatus_1;
4924 u16 phystatus_2 = rxh->PhyRxStatus_2;
4925 u16 phystatus_3 = rxh->PhyRxStatus_3;
4926 u16 macstatus1 = rxh->RxStatus1;
4927 u16 macstatus2 = rxh->RxStatus2;
4930 static const bcm_bit_desc_t macstat_flags[] = {
4931 {RXS_FCSERR, "FCSErr"},
4932 {RXS_RESPFRAMETX, "Reply"},
4933 {RXS_PBPRES, "PADDING"},
4934 {RXS_DECATMPT, "DeCr"},
4935 {RXS_DECERR, "DeCrErr"},
4936 {RXS_BCNSENT, "Bcn"},
4940 prhex("Raw RxDesc", (unsigned char *) rxh, sizeof(d11rxhdr_t));
4942 bcm_format_flags(macstat_flags, macstatus1, flagstr, 64);
4944 snprintf(lenbuf, sizeof(lenbuf), "0x%x", len);
4946 printk(KERN_DEBUG "RxFrameSize: %6s (%d)%s\n", lenbuf, len,
4947 (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : "");
4948 printk(KERN_DEBUG "RxPHYStatus: %04x %04x %04x %04x\n",
4949 phystatus_0, phystatus_1, phystatus_2, phystatus_3);
4950 printk(KERN_DEBUG "RxMACStatus: %x %s\n", macstatus1, flagstr);
4951 printk(KERN_DEBUG "RXMACaggtype: %x\n",
4952 (macstatus2 & RXS_AGGTYPE_MASK));
4953 printk(KERN_DEBUG "RxTSFTime: %04x\n", rxh->RxTSFTime);
4955 #endif /* defined(BCMDBG) */
4958 int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len)
4962 char *endp = buf + SSID_FMT_BUF_LEN;
4964 if (ssid_len > IEEE80211_MAX_SSID_LEN)
4965 ssid_len = IEEE80211_MAX_SSID_LEN;
4967 for (i = 0; i < ssid_len; i++) {
4972 } else if (isprint((unsigned char) c)) {
4975 p += snprintf(p, (endp - p), "\\x%02X", c);
4981 return (int)(p - buf);
4983 #endif /* defined(BCMDBG) */
4985 static u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate)
4987 return wlc_bmac_rate_shm_offset(wlc->hw, rate);
4990 /* Callback for device removed */
4993 * Attempts to queue a packet onto a multiple-precedence queue,
4994 * if necessary evicting a lower precedence packet from the queue.
4996 * 'prec' is the precedence number that has already been mapped
4997 * from the packet priority.
4999 * Returns true if packet consumed (queued), false if not.
5002 wlc_prec_enq(struct wlc_info *wlc, struct pktq *q, void *pkt, int prec)
5004 return wlc_prec_enq_head(wlc, q, pkt, prec, false);
5008 wlc_prec_enq_head(struct wlc_info *wlc, struct pktq *q, struct sk_buff *pkt,
5009 int prec, bool head)
5012 int eprec = -1; /* precedence to evict from */
5014 /* Determine precedence from which to evict packet, if any */
5015 if (pktq_pfull(q, prec))
5017 else if (pktq_full(q)) {
5018 p = pktq_peek_tail(q, &eprec);
5021 wiphy_err(wlc->wiphy, "%s: Failing: eprec %d > prec %d"
5022 "\n", __func__, eprec, prec);
5027 /* Evict if needed */
5029 bool discard_oldest;
5031 /* Detect queueing to unconfigured precedence */
5032 ASSERT(!pktq_pempty(q, eprec));
5034 discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec);
5036 /* Refuse newer packet unless configured to discard oldest */
5037 if (eprec == prec && !discard_oldest) {
5038 wiphy_err(wlc->wiphy, "%s: No where to go, prec == %d"
5039 "\n", __func__, prec);
5043 /* Evict packet according to discard policy */
5044 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
5048 /* Increment wme stats */
5049 if (WME_ENAB(wlc->pub)) {
5050 WLCNTINCR(wlc->pub->_wme_cnt->
5051 tx_failed[WME_PRIO2AC(p->priority)].packets);
5052 WLCNTADD(wlc->pub->_wme_cnt->
5053 tx_failed[WME_PRIO2AC(p->priority)].bytes,
5056 pkt_buf_free_skb(p);
5057 wlc->pub->_cnt->txnobuf++;
5062 p = pktq_penq_head(q, prec, pkt);
5064 p = pktq_penq(q, prec, pkt);
5070 void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
5073 struct wlc_info *wlc = (struct wlc_info *) ctx;
5074 struct wlc_txq_info *qi = wlc->active_queue; /* Check me */
5075 struct pktq *q = &qi->q;
5078 prio = sdu->priority;
5080 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat);
5082 if (!wlc_prec_enq(wlc, q, sdu, prec)) {
5083 if (!EDCF_ENAB(wlc->pub)
5084 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
5085 wiphy_err(wlc->wiphy, "wl%d: wlc_txq_enq: txq overflow"
5086 "\n", wlc->pub->unit);
5089 * XXX we might hit this condtion in case
5090 * packet flooding from mac80211 stack
5092 pkt_buf_free_skb(sdu);
5093 wlc->pub->_cnt->txnobuf++;
5096 /* Check if flow control needs to be turned on after enqueuing the packet
5097 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5098 * to drop instead of relying on stack to make the right decision
5100 if (!EDCF_ENAB(wlc->pub)
5101 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5102 if (pktq_len(q) >= wlc->pub->tunables->datahiwat) {
5103 wlc_txflowcontrol(wlc, qi, ON, ALLPRIO);
5105 } else if (wlc->pub->_priofc) {
5106 if (pktq_plen(q, wlc_prio2prec_map[prio]) >=
5107 wlc->pub->tunables->datahiwat) {
5108 wlc_txflowcontrol(wlc, qi, ON, prio);
5114 wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
5115 struct ieee80211_hw *hw)
5120 struct scb *scb = &global_scb;
5121 struct ieee80211_hdr *d11_header = (struct ieee80211_hdr *)(sdu->data);
5125 /* 802.11 standard requires management traffic to go at highest priority */
5126 prio = ieee80211_is_data(d11_header->frame_control) ? sdu->priority :
5128 fifo = prio2fifo[prio];
5130 ASSERT((uint) skb_headroom(sdu) >= TXOFF);
5131 ASSERT(!(sdu->next));
5132 ASSERT(!(sdu->prev));
5133 ASSERT(fifo < NFIFO);
5137 (wlc_d11hdrs_mac80211(wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0)))
5139 wlc_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio));
5140 wlc_send_q(wlc, wlc->active_queue);
5142 wlc->pub->_cnt->ieee_tx++;
5146 void BCMFASTPATH wlc_send_q(struct wlc_info *wlc, struct wlc_txq_info *qi)
5148 struct sk_buff *pkt[DOT11_MAXNUMFRAGS];
5151 int err = 0, i, count;
5153 struct pktq *q = &qi->q;
5154 struct ieee80211_tx_info *tx_info;
5156 /* only do work for the active queue */
5157 if (qi != wlc->active_queue)
5165 prec_map = wlc->tx_prec_map;
5167 /* Send all the enq'd pkts that we can.
5168 * Dequeue packets with precedence with empty HW fifo only
5170 while (prec_map && (pkt[0] = pktq_mdeq(q, prec_map, &prec))) {
5171 tx_info = IEEE80211_SKB_CB(pkt[0]);
5172 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
5173 err = wlc_sendampdu(wlc->ampdu, qi, pkt, prec);
5176 err = wlc_prep_pdu(wlc, pkt[0], &fifo);
5178 for (i = 0; i < count; i++) {
5179 wlc_txfifo(wlc, fifo, pkt[i], true, 1);
5184 if (err == -BCME_BUSY) {
5185 pktq_penq_head(q, prec, pkt[0]);
5186 /* If send failed due to any other reason than a change in
5187 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5189 if (prec_map == wlc->tx_prec_map)
5191 prec_map = wlc->tx_prec_map;
5195 /* Check if flow control needs to be turned off after sending the packet */
5196 if (!EDCF_ENAB(wlc->pub)
5197 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5198 if (wlc_txflowcontrol_prio_isset(wlc, qi, ALLPRIO)
5199 && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) {
5200 wlc_txflowcontrol(wlc, qi, OFF, ALLPRIO);
5202 } else if (wlc->pub->_priofc) {
5204 for (prio = MAXPRIO; prio >= 0; prio--) {
5205 if (wlc_txflowcontrol_prio_isset(wlc, qi, prio) &&
5206 (pktq_plen(q, wlc_prio2prec_map[prio]) <
5207 wlc->pub->tunables->datahiwat / 2)) {
5208 wlc_txflowcontrol(wlc, qi, OFF, prio);
5216 * bcmc_fid_generate:
5217 * Generate frame ID for a BCMC packet. The frag field is not used
5218 * for MC frames so is used as part of the sequence number.
5221 bcmc_fid_generate(struct wlc_info *wlc, struct wlc_bsscfg *bsscfg,
5226 frameid = le16_to_cpu(txh->TxFrameID) & ~(TXFID_SEQ_MASK |
5230 mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5237 wlc_txfifo(struct wlc_info *wlc, uint fifo, struct sk_buff *p, bool commit,
5240 u16 frameid = INVALIDFID;
5243 ASSERT(fifo < NFIFO);
5244 txh = (d11txh_t *) (p->data);
5246 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5247 * ucode or BSS info as appropriate.
5249 if (fifo == TX_BCMC_FIFO) {
5250 frameid = le16_to_cpu(txh->TxFrameID);
5254 if (WLC_WAR16165(wlc))
5255 wlc_war16165(wlc, true);
5258 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5259 * in wlc_bmac_txfifo()
5262 TXPKTPENDINC(wlc, fifo, txpktpend);
5263 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5264 txpktpend, TXPKTPENDGET(wlc, fifo));
5267 /* Commit BCMC sequence number in the SHM frame ID location */
5268 if (frameid != INVALIDFID)
5269 BCMCFID(wlc, frameid);
5271 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
5272 wiphy_err(wlc->wiphy, "wlc_txfifo: fatal, toss frames !!!\n");
5277 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec, uint length)
5280 uint mac_rate = RSPEC2RATE(rspec);
5283 if (IS_MCS(rspec)) {
5284 /* not supported yet */
5286 } else if (IS_OFDM(rspec)) {
5287 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5289 * Nbits = length * 8
5290 * Nbits/sym = Mbps * 4 = mac_rate * 2
5292 nsyms = CEIL((length * 8), (mac_rate * 2));
5294 /* usec = symbols * usec/symbol */
5295 usec = (u16) (nsyms * APHY_SYMBOL_TIME);
5306 usec = (length << 4) / 11;
5309 usec = (length << 3) / 11;
5312 wiphy_err(wlc->wiphy, "wl%d: wlc_compute_airtime: "
5313 "unsupported rspec 0x%x\n",
5314 wlc->pub->unit, rspec);
5315 ASSERT((const char *)"Bad phy_rate" == NULL);
5324 wlc_compute_plcp(struct wlc_info *wlc, ratespec_t rspec, uint length, u8 *plcp)
5326 if (IS_MCS(rspec)) {
5327 wlc_compute_mimo_plcp(rspec, length, plcp);
5328 } else if (IS_OFDM(rspec)) {
5329 wlc_compute_ofdm_plcp(rspec, length, plcp);
5331 wlc_compute_cck_plcp(wlc, rspec, length, plcp);
5336 /* Rate: 802.11 rate code, length: PSDU length in octets */
5337 static void wlc_compute_mimo_plcp(ratespec_t rspec, uint length, u8 *plcp)
5339 u8 mcs = (u8) (rspec & RSPEC_RATE_MASK);
5340 ASSERT(IS_MCS(rspec));
5342 if (RSPEC_IS40MHZ(rspec) || (mcs == 32))
5343 plcp[0] |= MIMO_PLCP_40MHZ;
5344 WLC_SET_MIMO_PLCP_LEN(plcp, length);
5345 plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */
5346 plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5347 plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5351 /* Rate: 802.11 rate code, length: PSDU length in octets */
5352 static void BCMFASTPATH
5353 wlc_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp)
5357 int rate = RSPEC2RATE(rspec);
5359 ASSERT(IS_OFDM(rspec));
5361 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5362 rate_signal = rate_info[rate] & WLC_RATE_MASK;
5363 ASSERT(rate_signal != 0);
5365 memset(plcp, 0, D11_PHY_HDR_LEN);
5366 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal);
5368 tmp = (length & 0xfff) << 5;
5369 plcp[2] |= (tmp >> 16) & 0xff;
5370 plcp[1] |= (tmp >> 8) & 0xff;
5371 plcp[0] |= tmp & 0xff;
5377 * Compute PLCP, but only requires actual rate and length of pkt.
5378 * Rate is given in the driver standard multiple of 500 kbps.
5379 * le is set for 11 Mbps rate if necessary.
5380 * Broken out for PRQ.
5383 static void wlc_cck_plcp_set(struct wlc_info *wlc, int rate_500, uint length,
5397 usec = (length << 4) / 11;
5398 if ((length << 4) - (usec * 11) > 0)
5402 usec = (length << 3) / 11;
5403 if ((length << 3) - (usec * 11) > 0) {
5405 if ((usec * 11) - (length << 3) >= 8)
5406 le = D11B_PLCP_SIGNAL_LE;
5411 wiphy_err(wlc->wiphy, "wlc_cck_plcp_set: unsupported rate %d"
5413 rate_500 = WLC_RATE_1M;
5417 /* PLCP signal byte */
5418 plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */
5419 /* PLCP service byte */
5420 plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED);
5421 /* PLCP length u16, little endian */
5422 plcp[2] = usec & 0xff;
5423 plcp[3] = (usec >> 8) & 0xff;
5429 /* Rate: 802.11 rate code, length: PSDU length in octets */
5430 static void wlc_compute_cck_plcp(struct wlc_info *wlc, ratespec_t rspec,
5431 uint length, u8 *plcp)
5433 int rate = RSPEC2RATE(rspec);
5435 ASSERT(IS_CCK(rspec));
5437 wlc_cck_plcp_set(wlc, rate, length, plcp);
5440 /* wlc_compute_frame_dur()
5442 * Calculate the 802.11 MAC header DUR field for MPDU
5443 * DUR for a single frame = 1 SIFS + 1 ACK
5444 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5446 * rate MPDU rate in unit of 500kbps
5447 * next_frag_len next MPDU length in bytes
5448 * preamble_type use short/GF or long/MM PLCP header
5450 static u16 BCMFASTPATH
5451 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate, u8 preamble_type,
5456 sifs = SIFS(wlc->band);
5459 dur += (u16) wlc_calc_ack_time(wlc, rate, preamble_type);
5461 if (next_frag_len) {
5462 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5464 /* add another SIFS and the frag time */
5467 (u16) wlc_calc_frame_time(wlc, rate, preamble_type,
5473 /* wlc_compute_rtscts_dur()
5475 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5476 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5477 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5479 * cts cts-to-self or rts/cts
5480 * rts_rate rts or cts rate in unit of 500kbps
5481 * rate next MPDU rate in unit of 500kbps
5482 * frame_len next MPDU frame length in bytes
5485 wlc_compute_rtscts_dur(struct wlc_info *wlc, bool cts_only, ratespec_t rts_rate,
5486 ratespec_t frame_rate, u8 rts_preamble_type,
5487 u8 frame_preamble_type, uint frame_len, bool ba)
5491 sifs = SIFS(wlc->band);
5493 if (!cts_only) { /* RTS/CTS */
5496 (u16) wlc_calc_cts_time(wlc, rts_rate,
5498 } else { /* CTS-TO-SELF */
5503 (u16) wlc_calc_frame_time(wlc, frame_rate, frame_preamble_type,
5507 (u16) wlc_calc_ba_time(wlc, frame_rate,
5508 WLC_SHORT_PREAMBLE);
5511 (u16) wlc_calc_ack_time(wlc, frame_rate,
5512 frame_preamble_type);
5516 static bool wlc_phy_rspec_check(struct wlc_info *wlc, u16 bw, ratespec_t rspec)
5518 if (IS_MCS(rspec)) {
5519 uint mcs = rspec & RSPEC_RATE_MASK;
5522 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5523 } else if ((mcs >= 8) && (mcs <= 23)) {
5524 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SDM);
5525 } else if (mcs == 32) {
5526 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5527 ASSERT(bw == PHY_TXC1_BW_40MHZ_DUP);
5529 } else if (IS_OFDM(rspec)) {
5530 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_STBC);
5532 ASSERT(IS_CCK(rspec));
5534 ASSERT((bw == PHY_TXC1_BW_20MHZ)
5535 || (bw == PHY_TXC1_BW_20MHZ_UP));
5536 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SISO);
5542 u16 BCMFASTPATH wlc_phytxctl1_calc(struct wlc_info *wlc, ratespec_t rspec)
5547 if (WLCISLCNPHY(wlc->band)) {
5548 bw = PHY_TXC1_BW_20MHZ;
5550 bw = RSPEC_GET_BW(rspec);
5551 /* 10Mhz is not supported yet */
5552 if (bw < PHY_TXC1_BW_20MHZ) {
5553 wiphy_err(wlc->wiphy, "wlc_phytxctl1_calc: bw %d is "
5554 "not supported yet, set to 20L\n", bw);
5555 bw = PHY_TXC1_BW_20MHZ;
5558 wlc_phy_rspec_check(wlc, bw, rspec);
5561 if (IS_MCS(rspec)) {
5562 uint mcs = rspec & RSPEC_RATE_MASK;
5564 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5565 phyctl1 = RSPEC_PHYTXBYTE2(rspec);
5566 /* set the upper byte of phyctl1 */
5567 phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8);
5568 } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band)
5569 && !WLCISSSLPNPHY(wlc->band)) {
5570 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5571 /* Eventually MIMOPHY would also be converted to this format */
5572 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5573 phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5574 } else { /* legacy OFDM/CCK */
5576 /* get the phyctl byte from rate phycfg table */
5577 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec));
5579 wiphy_err(wlc->wiphy, "wlc_phytxctl1_calc: wrong "
5580 "legacy OFDM/CCK rate\n");
5584 /* set the upper byte of phyctl1 */
5586 (bw | (phycfg << 8) |
5587 (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5591 /* phy clock must support 40Mhz if tx descriptor uses it */
5592 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) {
5593 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ);
5594 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi));
5600 ratespec_t BCMFASTPATH
5601 wlc_rspec_to_rts_rspec(struct wlc_info *wlc, ratespec_t rspec, bool use_rspec,
5604 ratespec_t rts_rspec = 0;
5607 /* use frame rate as rts rate */
5610 } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) {
5611 /* Use 11Mbps as the g protection RTS target rate and fallback.
5612 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5613 * target in case 11 Mbps is not Basic.
5614 * 6 and 9 Mbps are not usually selected by rate selection, but even
5615 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5617 rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M);
5619 /* calculate RTS rate and fallback rate based on the frame rate
5620 * RTS must be sent at a basic rate since it is a
5621 * control frame, sec 9.6 of 802.11 spec
5623 rts_rspec = WLC_BASIC_RATE(wlc, rspec);
5626 if (WLC_PHY_11N_CAP(wlc->band)) {
5627 /* set rts txbw to correct side band */
5628 rts_rspec &= ~RSPEC_BW_MASK;
5630 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5631 * (DUP), otherwise send RTS on control channel
5633 if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec))
5634 rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT);
5636 rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5638 /* pick siso/cdd as default for ofdm */
5639 if (IS_OFDM(rts_rspec)) {
5640 rts_rspec &= ~RSPEC_STF_MASK;
5641 rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
5648 * Add d11txh_t, cck_phy_hdr_t.
5650 * 'p' data must start with 802.11 MAC header
5651 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5653 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5656 static u16 BCMFASTPATH
5657 wlc_d11hdrs_mac80211(struct wlc_info *wlc, struct ieee80211_hw *hw,
5658 struct sk_buff *p, struct scb *scb, uint frag,
5659 uint nfrags, uint queue, uint next_frag_len,
5660 wsec_key_t *key, ratespec_t rspec_override)
5662 struct ieee80211_hdr *h;
5664 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
5665 int len, phylen, rts_phylen;
5666 u16 mch, phyctl, xfts, mainrates;
5667 u16 seq = 0, mcl = 0, status = 0, frameid = 0;
5668 ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = {
5669 WLC_RATE_1M, WLC_RATE_1M};
5670 bool use_rts = false;
5671 bool use_cts = false;
5672 bool use_rifs = false;
5673 bool short_preamble[2] = { false, false };
5674 u8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5675 u8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5676 u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN];
5677 struct ieee80211_rts *rts = NULL;
5681 bool hwtkmic = false;
5682 u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
5683 #define ANTCFG_NONE 0xFF
5684 u8 antcfg = ANTCFG_NONE;
5685 u8 fbantcfg = ANTCFG_NONE;
5686 uint phyctl1_stf = 0;
5688 struct ieee80211_tx_rate *txrate[2];
5690 struct ieee80211_tx_info *tx_info;
5693 u8 mimo_preamble_type;
5695 ASSERT(queue < NFIFO);
5697 /* locate 802.11 MAC header */
5698 h = (struct ieee80211_hdr *)(p->data);
5699 qos = ieee80211_is_data_qos(h->frame_control);
5701 /* compute length of frame in bytes for use in PLCP computations */
5703 phylen = len + FCS_LEN;
5705 /* If WEP enabled, add room in phylen for the additional bytes of
5706 * ICV which MAC generates. We do NOT add the additional bytes to
5707 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5711 phylen += key->icv_len;
5715 tx_info = IEEE80211_SKB_CB(p);
5719 plcp = skb_push(p, D11_PHY_HDR_LEN);
5721 /* add Broadcom tx descriptor header */
5722 txh = (d11txh_t *) skb_push(p, D11_TXH_LEN);
5723 memset(txh, 0, D11_TXH_LEN);
5726 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
5727 /* non-AP STA should never use BCMC queue */
5728 ASSERT(queue != TX_BCMC_FIFO);
5729 if (queue == TX_BCMC_FIFO) {
5730 wiphy_err(wlc->wiphy, "wl%d: %s: ASSERT queue == "
5731 "TX_BCMC!\n", WLCWLUNIT(wlc), __func__);
5732 frameid = bcmc_fid_generate(wlc, NULL, txh);
5734 /* Increment the counter for first fragment */
5735 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
5736 SCB_SEQNUM(scb, p->priority)++;
5739 /* extract fragment number from frame first */
5740 seq = le16_to_cpu(seq) & FRAGNUM_MASK;
5741 seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT);
5742 h->seq_ctrl = cpu_to_le16(seq);
5744 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5745 (queue & TXFID_QUEUE_MASK);
5748 frameid |= queue & TXFID_QUEUE_MASK;
5750 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5751 if (SCB_PS(scb) || ieee80211_is_beacon(h->frame_control))
5752 mcl |= TXC_IGNOREPMQ;
5754 ASSERT(hw->max_rates <= IEEE80211_TX_MAX_RATES);
5755 ASSERT(hw->max_rates == 2);
5757 txrate[0] = tx_info->control.rates;
5758 txrate[1] = txrate[0] + 1;
5760 ASSERT(txrate[0]->idx >= 0);
5761 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5762 if (txrate[1]->idx < 0) {
5763 txrate[1] = txrate[0];
5766 for (k = 0; k < hw->max_rates; k++) {
5768 txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false;
5770 ASSERT(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU));
5771 if ((txrate[k]->idx >= 0)
5772 && (txrate[k]->idx <
5773 hw->wiphy->bands[tx_info->band]->n_bitrates)) {
5775 hw->wiphy->bands[tx_info->band]->
5776 bitrates[txrate[k]->idx].hw_value;
5779 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ?
5782 ASSERT((txrate[k]->idx >= 0) &&
5784 hw->wiphy->bands[tx_info->band]->
5786 rate_val[k] = WLC_RATE_1M;
5789 rate_val[k] = txrate[k]->idx;
5791 /* Currently only support same setting for primay and fallback rates.
5792 * Unify flags for each rate into a single value for the frame
5796 flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false;
5799 flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false;
5802 rate_val[k] |= NRATE_MCS_INUSE;
5804 rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]);
5806 /* (1) RATE: determine and validate primary rate and fallback rates */
5807 if (!RSPEC_ACTIVE(rspec[k])) {
5808 ASSERT(RSPEC_ACTIVE(rspec[k]));
5809 rspec[k] = WLC_RATE_1M;
5811 if (!is_multicast_ether_addr(h->addr1)) {
5812 /* set tx antenna config */
5813 wlc_antsel_antcfg_get(wlc->asi, false, false, 0,
5814 0, &antcfg, &fbantcfg);
5819 phyctl1_stf = wlc->stf->ss_opmode;
5821 if (N_ENAB(wlc->pub)) {
5822 for (k = 0; k < hw->max_rates; k++) {
5823 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5824 if (((IS_MCS(rspec[k]) &&
5825 IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) ||
5827 && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
5828 || !(rspec[k] & RSPEC_OVERRIDE))) {
5829 rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
5831 /* For SISO MCS use STBC if possible */
5832 if (IS_MCS(rspec[k])
5833 && WLC_STF_SS_STBC_TX(wlc, scb)) {
5836 ASSERT(WLC_STBC_CAP_PHY(wlc));
5837 stc = 1; /* Nss for single stream is always 1 */
5839 (PHY_TXC1_MODE_STBC <<
5840 RSPEC_STF_SHIFT) | (stc <<
5844 (phyctl1_stf << RSPEC_STF_SHIFT);
5847 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5848 if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) {
5849 /* default txbw is 20in40 SB */
5850 mimo_ctlchbw = mimo_txbw =
5851 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
5852 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
5854 if (IS_MCS(rspec[k])) {
5855 /* mcs 32 must be 40b/w DUP */
5856 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5858 PHY_TXC1_BW_40MHZ_DUP;
5860 } else if (wlc->mimo_40txbw != AUTO)
5861 mimo_txbw = wlc->mimo_40txbw;
5862 /* else check if dst is using 40 Mhz */
5863 else if (scb->flags & SCB_IS40)
5864 mimo_txbw = PHY_TXC1_BW_40MHZ;
5865 } else if (IS_OFDM(rspec[k])) {
5866 if (wlc->ofdm_40txbw != AUTO)
5867 mimo_txbw = wlc->ofdm_40txbw;
5869 ASSERT(IS_CCK(rspec[k]));
5870 if (wlc->cck_40txbw != AUTO)
5871 mimo_txbw = wlc->cck_40txbw;
5874 /* mcs32 is 40 b/w only.
5875 * This is possible for probe packets on a STA during SCAN
5877 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5879 rspec[k] = RSPEC_MIMORATE;
5881 mimo_txbw = PHY_TXC1_BW_20MHZ;
5884 /* Set channel width */
5885 rspec[k] &= ~RSPEC_BW_MASK;
5886 if ((k == 0) || ((k > 0) && IS_MCS(rspec[k])))
5887 rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT);
5889 rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5893 if (IS_MCS(rspec[k])
5894 && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5895 rspec[k] |= RSPEC_SHORT_GI;
5896 else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5897 rspec[k] &= ~RSPEC_SHORT_GI;
5899 rspec[k] &= ~RSPEC_SHORT_GI;
5902 mimo_preamble_type = WLC_MM_PREAMBLE;
5903 if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD)
5904 mimo_preamble_type = WLC_GF_PREAMBLE;
5906 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
5907 && (!IS_MCS(rspec[k]))) {
5908 wiphy_err(wlc->wiphy, "wl%d: %s: IEEE80211_TX_"
5909 "RC_MCS != IS_MCS(rspec)\n",
5910 WLCWLUNIT(wlc), __func__);
5911 ASSERT(0 && "Rate mismatch");
5914 if (IS_MCS(rspec[k])) {
5915 preamble_type[k] = mimo_preamble_type;
5917 /* if SGI is selected, then forced mm for single stream */
5918 if ((rspec[k] & RSPEC_SHORT_GI)
5919 && IS_SINGLE_STREAM(rspec[k] &
5921 preamble_type[k] = WLC_MM_PREAMBLE;
5925 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
5926 ASSERT(VALID_RATE_DBG(wlc, rspec[0]));
5928 /* should be better conditionalized */
5929 if (!IS_MCS(rspec[0])
5930 && (tx_info->control.rates[0].
5931 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
5932 preamble_type[k] = WLC_SHORT_PREAMBLE;
5934 ASSERT(!IS_MCS(rspec[0])
5935 || WLC_IS_MIMO_PREAMBLE(preamble_type[k]));
5938 for (k = 0; k < hw->max_rates; k++) {
5939 /* Set ctrlchbw as 20Mhz */
5940 ASSERT(!IS_MCS(rspec[k]));
5941 rspec[k] &= ~RSPEC_BW_MASK;
5942 rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
5944 /* for nphy, stf of ofdm frames must follow policies */
5945 if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) {
5946 rspec[k] &= ~RSPEC_STF_MASK;
5947 rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
5952 /* Reset these for use with AMPDU's */
5953 txrate[0]->count = 0;
5954 txrate[1]->count = 0;
5956 /* (2) PROTECTION, may change rspec */
5957 if ((ieee80211_is_data(h->frame_control) ||
5958 ieee80211_is_mgmt(h->frame_control)) &&
5959 (phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1))
5962 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
5963 wlc_compute_plcp(wlc, rspec[0], phylen, plcp);
5964 wlc_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
5965 memcpy(&txh->FragPLCPFallback,
5966 plcp_fallback, sizeof(txh->FragPLCPFallback));
5968 /* Length field now put in CCK FBR CRC field */
5969 if (IS_CCK(rspec[1])) {
5970 txh->FragPLCPFallback[4] = phylen & 0xff;
5971 txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
5974 /* MIMO-RATE: need validation ?? */
5976 IS_OFDM(rspec[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) plcp) :
5979 /* DUR field for main rate */
5980 if (!ieee80211_is_pspoll(h->frame_control) &&
5981 !is_multicast_ether_addr(h->addr1) && !use_rifs) {
5983 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0],
5985 h->duration_id = cpu_to_le16(durid);
5986 } else if (use_rifs) {
5987 /* NAV protect to end of next max packet size */
5989 (u16) wlc_calc_frame_time(wlc, rspec[0],
5991 DOT11_MAX_FRAG_LEN);
5992 durid += RIFS_11N_TIME;
5993 h->duration_id = cpu_to_le16(durid);
5996 /* DUR field for fallback rate */
5997 if (ieee80211_is_pspoll(h->frame_control))
5998 txh->FragDurFallback = h->duration_id;
5999 else if (is_multicast_ether_addr(h->addr1) || use_rifs)
6000 txh->FragDurFallback = 0;
6002 durid = wlc_compute_frame_dur(wlc, rspec[1],
6003 preamble_type[1], next_frag_len);
6004 txh->FragDurFallback = cpu_to_le16(durid);
6007 /* (4) MAC-HDR: MacTxControlLow */
6009 mcl |= TXC_STARTMSDU;
6011 if (!is_multicast_ether_addr(h->addr1))
6012 mcl |= TXC_IMMEDACK;
6014 if (BAND_5G(wlc->band->bandtype))
6015 mcl |= TXC_FREQBAND_5G;
6017 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC))
6020 /* set AMIC bit if using hardware TKIP MIC */
6024 txh->MacTxControlLow = cpu_to_le16(mcl);
6026 /* MacTxControlHigh */
6029 /* Set fallback rate preamble type */
6030 if ((preamble_type[1] == WLC_SHORT_PREAMBLE) ||
6031 (preamble_type[1] == WLC_GF_PREAMBLE)) {
6032 ASSERT((preamble_type[1] == WLC_GF_PREAMBLE) ||
6033 (!IS_MCS(rspec[1])));
6034 if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M)
6035 mch |= TXC_PREAMBLE_DATA_FB_SHORT;
6038 /* MacFrameControl */
6039 memcpy(&txh->MacFrameControl, &h->frame_control, sizeof(u16));
6040 txh->TxFesTimeNormal = cpu_to_le16(0);
6042 txh->TxFesTimeFallback = cpu_to_le16(0);
6045 memcpy(&txh->TxFrameRA, &h->addr1, ETH_ALEN);
6048 txh->TxFrameID = cpu_to_le16(frameid);
6050 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6051 * then we may need to reset the retry cnt's via the status reg
6053 txh->TxStatus = cpu_to_le16(status);
6055 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6056 * the END of previous structure so that it's compatible in driver.
6058 txh->MaxNMpdus = cpu_to_le16(0);
6059 txh->MaxABytes_MRT = cpu_to_le16(0);
6060 txh->MaxABytes_FBR = cpu_to_le16(0);
6061 txh->MinMBytes = cpu_to_le16(0);
6063 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6064 /* RTS PLCP header and RTS frame */
6065 if (use_rts || use_cts) {
6066 if (use_rts && use_cts)
6069 for (k = 0; k < 2; k++) {
6070 rts_rspec[k] = wlc_rspec_to_rts_rspec(wlc, rspec[k],
6075 if (!IS_OFDM(rts_rspec[0]) &&
6076 !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) ||
6077 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6078 rts_preamble_type[0] = WLC_SHORT_PREAMBLE;
6079 mch |= TXC_PREAMBLE_RTS_MAIN_SHORT;
6082 if (!IS_OFDM(rts_rspec[1]) &&
6083 !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) ||
6084 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6085 rts_preamble_type[1] = WLC_SHORT_PREAMBLE;
6086 mch |= TXC_PREAMBLE_RTS_FB_SHORT;
6089 /* RTS/CTS additions to MacTxControlLow */
6091 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDCTS);
6093 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDRTS);
6094 txh->MacTxControlLow |= cpu_to_le16(TXC_LONGFRAME);
6097 /* RTS PLCP header */
6098 ASSERT(IS_ALIGNED((unsigned long)txh->RTSPhyHeader, sizeof(u16)));
6099 rts_plcp = txh->RTSPhyHeader;
6101 rts_phylen = DOT11_CTS_LEN + FCS_LEN;
6103 rts_phylen = DOT11_RTS_LEN + FCS_LEN;
6105 wlc_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp);
6107 /* fallback rate version of RTS PLCP header */
6108 wlc_compute_plcp(wlc, rts_rspec[1], rts_phylen,
6110 memcpy(&txh->RTSPLCPFallback, rts_plcp_fallback,
6111 sizeof(txh->RTSPLCPFallback));
6113 /* RTS frame fields... */
6114 rts = (struct ieee80211_rts *)&txh->rts_frame;
6116 durid = wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec[0],
6117 rspec[0], rts_preamble_type[0],
6118 preamble_type[0], phylen, false);
6119 rts->duration = cpu_to_le16(durid);
6120 /* fallback rate version of RTS DUR field */
6121 durid = wlc_compute_rtscts_dur(wlc, use_cts,
6122 rts_rspec[1], rspec[1],
6123 rts_preamble_type[1],
6124 preamble_type[1], phylen, false);
6125 txh->RTSDurFallback = cpu_to_le16(durid);
6128 rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
6129 IEEE80211_STYPE_CTS);
6131 memcpy(&rts->ra, &h->addr2, ETH_ALEN);
6133 rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
6134 IEEE80211_STYPE_RTS);
6136 memcpy(&rts->ra, &h->addr1, 2 * ETH_ALEN);
6140 * low 8 bits: main frag rate/mcs,
6141 * high 8 bits: rts/cts rate/mcs
6143 mainrates |= (IS_OFDM(rts_rspec[0]) ?
6144 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) :
6147 memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN);
6148 memset((char *)&txh->rts_frame, 0,
6149 sizeof(struct ieee80211_rts));
6150 memset((char *)txh->RTSPLCPFallback, 0,
6151 sizeof(txh->RTSPLCPFallback));
6152 txh->RTSDurFallback = 0;
6155 #ifdef SUPPORT_40MHZ
6156 /* add null delimiter count */
6157 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) {
6158 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] =
6159 wlc_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen);
6163 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6164 txh->MacTxControlHigh = cpu_to_le16(mch);
6166 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6167 txh->MainRates = cpu_to_le16(mainrates);
6169 /* XtraFrameTypes */
6170 xfts = FRAMETYPE(rspec[1], wlc->mimoft);
6171 xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT);
6172 xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT);
6174 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT;
6175 txh->XtraFrameTypes = cpu_to_le16(xfts);
6177 /* PhyTxControlWord */
6178 phyctl = FRAMETYPE(rspec[0], wlc->mimoft);
6179 if ((preamble_type[0] == WLC_SHORT_PREAMBLE) ||
6180 (preamble_type[0] == WLC_GF_PREAMBLE)) {
6181 ASSERT((preamble_type[0] == WLC_GF_PREAMBLE)
6182 || !IS_MCS(rspec[0]));
6183 if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M)
6184 phyctl |= PHY_TXC_SHORT_HDR;
6185 wlc->pub->_cnt->txprshort++;
6188 /* phytxant is properly bit shifted */
6189 phyctl |= wlc_stf_d11hdrs_phyctl_txant(wlc, rspec[0]);
6190 txh->PhyTxControlWord = cpu_to_le16(phyctl);
6192 /* PhyTxControlWord_1 */
6193 if (WLC_PHY_11N_CAP(wlc->band)) {
6196 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[0]);
6197 txh->PhyTxControlWord_1 = cpu_to_le16(phyctl1);
6198 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[1]);
6199 txh->PhyTxControlWord_1_Fbr = cpu_to_le16(phyctl1);
6201 if (use_rts || use_cts) {
6202 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[0]);
6203 txh->PhyTxControlWord_1_Rts = cpu_to_le16(phyctl1);
6204 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[1]);
6205 txh->PhyTxControlWord_1_FbrRts = cpu_to_le16(phyctl1);
6209 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6210 * fill in non-zero MModeLen and/or MModeFbrLen
6211 * it will be unnecessary if they are separated
6213 if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) {
6215 wlc_calc_lsig_len(wlc, rspec[0], phylen);
6216 txh->MModeLen = cpu_to_le16(mmodelen);
6219 if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) {
6221 wlc_calc_lsig_len(wlc, rspec[1], phylen);
6222 txh->MModeFbrLen = cpu_to_le16(mmodefbrlen);
6226 if (IS_MCS(rspec[0]))
6227 ASSERT(IS_MCS(rspec[1]));
6229 ASSERT(!IS_MCS(rspec[0]) ||
6230 ((preamble_type[0] == WLC_MM_PREAMBLE) == (txh->MModeLen != 0)));
6231 ASSERT(!IS_MCS(rspec[1]) ||
6232 ((preamble_type[1] == WLC_MM_PREAMBLE) ==
6233 (txh->MModeFbrLen != 0)));
6235 ac = skb_get_queue_mapping(p);
6236 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
6237 uint frag_dur, dur, dur_fallback;
6239 ASSERT(!is_multicast_ether_addr(h->addr1));
6241 /* WME: Update TXOP threshold */
6242 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
6244 wlc_calc_frame_time(wlc, rspec[0], preamble_type[0],
6248 /* 1 RTS or CTS-to-self frame */
6250 wlc_calc_cts_time(wlc, rts_rspec[0],
6251 rts_preamble_type[0]);
6253 wlc_calc_cts_time(wlc, rts_rspec[1],
6254 rts_preamble_type[1]);
6255 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6256 dur += le16_to_cpu(rts->duration);
6258 le16_to_cpu(txh->RTSDurFallback);
6259 } else if (use_rifs) {
6263 /* frame + SIFS + ACK */
6266 wlc_compute_frame_dur(wlc, rspec[0],
6267 preamble_type[0], 0);
6270 wlc_calc_frame_time(wlc, rspec[1],
6274 wlc_compute_frame_dur(wlc, rspec[1],
6275 preamble_type[1], 0);
6277 /* NEED to set TxFesTimeNormal (hard) */
6278 txh->TxFesTimeNormal = cpu_to_le16((u16) dur);
6279 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6280 txh->TxFesTimeFallback =
6281 cpu_to_le16((u16) dur_fallback);
6283 /* update txop byte threshold (txop minus intraframe overhead) */
6284 if (wlc->edcf_txop[ac] >= (dur - frag_dur)) {
6289 wlc_calc_frame_len(wlc, rspec[0],
6295 /* range bound the fragthreshold */
6296 if (newfragthresh < DOT11_MIN_FRAG_LEN)
6299 else if (newfragthresh >
6300 wlc->usr_fragthresh)
6302 wlc->usr_fragthresh;
6303 /* update the fragthresh and do txc update */
6304 if (wlc->fragthresh[queue] !=
6305 (u16) newfragthresh) {
6306 wlc->fragthresh[queue] =
6307 (u16) newfragthresh;
6311 wiphy_err(wlc->wiphy, "wl%d: %s txop invalid "
6313 wlc->pub->unit, fifo_names[queue],
6314 RSPEC2RATE(rspec[0]));
6316 if (dur > wlc->edcf_txop[ac])
6317 wiphy_err(wlc->wiphy, "wl%d: %s: %s txop "
6318 "exceeded phylen %d/%d dur %d/%d\n",
6319 wlc->pub->unit, __func__,
6321 phylen, wlc->fragthresh[queue],
6322 dur, wlc->edcf_txop[ac]);
6329 void wlc_tbtt(struct wlc_info *wlc, d11regs_t *regs)
6331 struct wlc_bsscfg *cfg = wlc->cfg;
6333 wlc->pub->_cnt->tbtt++;
6335 if (BSSCFG_STA(cfg)) {
6336 /* run watchdog here if the watchdog timer is not armed */
6337 if (WLC_WATCHDOG_TBTT(wlc)) {
6340 wl_del_timer(wlc->wl, wlc->wdtimer);
6341 wlc->WDarmed = false;
6344 cur = OSL_SYSUPTIME();
6345 delta = cur > wlc->WDlast ? cur - wlc->WDlast :
6346 (u32) ~0 - wlc->WDlast + cur + 1;
6347 if (delta >= TIMER_INTERVAL_WATCHDOG) {
6348 wlc_watchdog((void *)wlc);
6352 wl_add_timer(wlc->wl, wlc->wdtimer,
6353 wlc_watchdog_backup_bi(wlc), true);
6354 wlc->WDarmed = true;
6359 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6360 wlc->qvalid |= MCMD_DIRFRMQVAL;
6364 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6365 void wlc_hwtimer_gptimer_set(struct wlc_info *wlc, uint us)
6367 W_REG(&wlc->regs->gptimer, us);
6370 void wlc_hwtimer_gptimer_abort(struct wlc_info *wlc)
6372 W_REG(&wlc->regs->gptimer, 0);
6375 static void wlc_hwtimer_gptimer_cb(struct wlc_info *wlc)
6377 /* when interrupt is generated, the counter is loaded with last value
6378 * written and continue to decrement. So it has to be cleaned first
6380 W_REG(&wlc->regs->gptimer, 0);
6384 * This fn has all the high level dpc processing from wlc_dpc.
6385 * POLICY: no macinstatus change, no bounding loop.
6386 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6388 void wlc_high_dpc(struct wlc_info *wlc, u32 macintstatus)
6390 d11regs_t *regs = wlc->regs;
6393 static const bcm_bit_desc_t int_flags[] = {
6394 {MI_MACSSPNDD, "MACSSPNDD"},
6395 {MI_BCNTPL, "BCNTPL"},
6397 {MI_BCNSUCCESS, "BCNSUCCESS"},
6398 {MI_BCNCANCLD, "BCNCANCLD"},
6399 {MI_ATIMWINEND, "ATIMWINEND"},
6401 {MI_NSPECGEN_0, "NSPECGEN_0"},
6402 {MI_NSPECGEN_1, "NSPECGEN_1"},
6403 {MI_MACTXERR, "MACTXERR"},
6404 {MI_NSPECGEN_3, "NSPECGEN_3"},
6405 {MI_PHYTXERR, "PHYTXERR"},
6409 {MI_DMAINT, "DMAINT"},
6410 {MI_TXSTOP, "TXSTOP"},
6412 {MI_BG_NOISE, "BG_NOISE"},
6413 {MI_DTIM_TBTT, "DTIM_TBTT"},
6415 {MI_PWRUP, "PWRUP"},
6416 {MI_RFDISABLE, "RFDISABLE"},
6418 {MI_PHYCHANGED, "PHYCHANGED"},
6423 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) {
6424 bcm_format_flags(int_flags, macintstatus, flagstr,
6426 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6427 wlc->pub->unit, macintstatus, flagstr);
6431 if (macintstatus & MI_PRQ) {
6432 /* Process probe request FIFO */
6433 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6436 /* TBTT indication */
6437 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6438 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
6439 wlc_tbtt(wlc, regs);
6441 if (macintstatus & MI_GP0) {
6442 wiphy_err(wlc->wiphy, "wl%d: PSM microcode watchdog fired at "
6443 "%d (seconds). Resetting.\n",
6444 wlc->pub->unit, wlc->pub->now);
6446 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6447 __func__, wlc->pub->sih->chip,
6448 wlc->pub->sih->chiprev);
6450 wlc->pub->_cnt->psmwds++;
6456 /* gptimer timeout */
6457 if (macintstatus & MI_TO) {
6458 wlc_hwtimer_gptimer_cb(wlc);
6461 if (macintstatus & MI_RFDISABLE) {
6462 wiphy_err(wlc->wiphy, "wl%d: MAC Detected a change on the RF "
6463 "Disable Input 0x%x\n", wlc->pub->unit,
6464 R_REG(®s->phydebug) & PDBG_RFD);
6465 /* delay the cleanup to wl_down in IBSS case */
6466 if ((R_REG(®s->phydebug) & PDBG_RFD)) {
6468 struct wlc_bsscfg *bsscfg;
6469 FOREACH_BSS(wlc, idx, bsscfg) {
6470 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable
6473 wiphy_err(wlc->wiphy, "wl%d: wlc_dpc: "
6474 "rfdisable -> wlc_bsscfg_disable()"
6475 "\n", wlc->pub->unit);
6480 /* send any enq'd tx packets. Just makes sure to jump start tx */
6481 if (!pktq_empty(&wlc->active_queue->q))
6482 wlc_send_q(wlc, wlc->active_queue);
6484 ASSERT(wlc_ps_check(wlc));
6487 static void wlc_war16165(struct wlc_info *wlc, bool tx)
6490 /* the post-increment is used in STAY_AWAKE macro */
6491 if (wlc->txpend16165war++ == 0)
6492 wlc_set_ps_ctrl(wlc);
6494 wlc->txpend16165war--;
6495 if (wlc->txpend16165war == 0)
6496 wlc_set_ps_ctrl(wlc);
6500 /* process an individual tx_status_t */
6503 wlc_dotxstatus(struct wlc_info *wlc, tx_status_t *txs, u32 frm_tx2)
6508 struct scb *scb = NULL;
6510 int tx_rts, tx_frame_count, tx_rts_count;
6511 uint totlen, supr_status;
6513 struct ieee80211_hdr *h;
6515 struct ieee80211_tx_info *tx_info;
6516 struct ieee80211_tx_rate *txrate;
6519 (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */
6521 /* discard intermediate indications for ucode with one legitimate case:
6522 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6523 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6524 * transmission count)
6526 if (!(txs->status & TX_STATUS_AMPDU)
6527 && (txs->status & TX_STATUS_INTERMEDIATE)) {
6528 WLCNTADD(wlc->pub->_cnt->txnoack,
6530 status & TX_STATUS_FRM_RTX_MASK) >>
6531 TX_STATUS_FRM_RTX_SHIFT));
6532 wiphy_err(wlc->wiphy, "%s: INTERMEDIATE but not AMPDU\n",
6537 queue = txs->frameid & TXFID_QUEUE_MASK;
6538 ASSERT(queue < NFIFO);
6539 if (queue >= NFIFO) {
6544 p = GETNEXTTXP(wlc, queue);
6545 if (WLC_WAR16165(wlc))
6546 wlc_war16165(wlc, false);
6550 txh = (d11txh_t *) (p->data);
6551 mcl = le16_to_cpu(txh->MacTxControlLow);
6554 if (WL_ERROR_ON()) {
6555 wiphy_err(wlc->wiphy, "phyerr 0x%x, rate 0x%x\n",
6556 txs->phyerr, txh->MainRates);
6557 wlc_print_txdesc(txh);
6559 wlc_print_txstatus(txs);
6562 ASSERT(txs->frameid == cpu_to_le16(txh->TxFrameID));
6563 if (txs->frameid != cpu_to_le16(txh->TxFrameID))
6566 tx_info = IEEE80211_SKB_CB(p);
6567 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
6569 if (tx_info->control.sta)
6570 scb = (struct scb *)tx_info->control.sta->drv_priv;
6572 if (N_ENAB(wlc->pub)) {
6573 u8 *plcp = (u8 *) (txh + 1);
6574 if (PLCP3_ISSGI(plcp[3]))
6575 wlc->pub->_cnt->txmpdu_sgi++;
6576 if (PLCP3_ISSTBC(plcp[3]))
6577 wlc->pub->_cnt->txmpdu_stbc++;
6580 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
6581 ASSERT((mcl & TXC_AMPDU_MASK) != TXC_AMPDU_NONE);
6582 wlc_ampdu_dotxstatus(wlc->ampdu, scb, p, txs);
6586 supr_status = txs->status & TX_STATUS_SUPR_MASK;
6587 if (supr_status == TX_STATUS_SUPR_BADCH)
6588 WL_TRACE("%s: Pkt tx suppressed, possibly channel %d\n",
6589 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec));
6591 tx_rts = cpu_to_le16(txh->MacTxControlLow) & TXC_SENDRTS;
6593 (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT;
6595 (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT;
6597 lastframe = !ieee80211_has_morefrags(h->frame_control);
6600 wiphy_err(wlc->wiphy, "Not last frame!\n");
6603 ieee80211_tx_info_clear_status(tx_info);
6604 if (queue < AC_COUNT) {
6605 sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]);
6606 lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]);
6612 txrate = tx_info->status.rates;
6613 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6614 if ((tx_frame_count > sfbl) && (txrate[1].idx >= 0)) {
6615 /* rate selection requested a fallback rate and we used it */
6616 txrate->count = lfbl;
6617 txrate[1].count = tx_frame_count - lfbl;
6619 /* rate selection did not request fallback rate, or we didn't need it */
6620 txrate->count = tx_frame_count;
6621 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6623 txrate[1].count = 0;
6626 /* clear the rest of the rates */
6627 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
6629 txrate[i].count = 0;
6632 if (txs->status & TX_STATUS_ACK_RCV)
6633 tx_info->flags |= IEEE80211_TX_STAT_ACK;
6636 totlen = pkttotlen(p);
6639 wlc_txfifo_complete(wlc, queue, 1);
6645 /* remove PLCP & Broadcom tx descriptor header */
6646 skb_pull(p, D11_PHY_HDR_LEN);
6647 skb_pull(p, D11_TXH_LEN);
6648 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
6649 wlc->pub->_cnt->ieee_tx_status++;
6651 wiphy_err(wlc->wiphy, "%s: Not last frame => not calling "
6652 "tx_status\n", __func__);
6660 pkt_buf_free_skb(p);
6667 wlc_txfifo_complete(struct wlc_info *wlc, uint fifo, s8 txpktpend)
6669 TXPKTPENDDEC(wlc, fifo, txpktpend);
6670 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6671 txpktpend, TXPKTPENDGET(wlc, fifo));
6673 /* There is more room; mark precedences related to this FIFO sendable */
6674 WLC_TX_FIFO_ENAB(wlc, fifo);
6675 ASSERT(TXPKTPENDGET(wlc, fifo) >= 0);
6677 if (!TXPKTPENDTOT(wlc)) {
6678 if (wlc->block_datafifo & DATA_BLOCK_TX_SUPR)
6679 wlc_bsscfg_tx_check(wlc);
6682 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6683 if (AP_ENAB(wlc->pub) &&
6684 wlc->bcmcfifo_drain && !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) {
6685 wlc->bcmcfifo_drain = false;
6686 wlc_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO);
6689 /* figure out which bsscfg is being worked on... */
6692 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6693 * return the offset (in us) of the TSF from the last TBTT
6695 u32 wlc_calc_tbtt_offset(u32 bp, u32 tsf_h, u32 tsf_l)
6697 u32 k, btklo, btkhi, offset;
6699 /* TBTT is always an even multiple of the beacon_interval,
6700 * so the TBTT less than or equal to the beacon timestamp is
6701 * the beacon timestamp minus the beacon timestamp modulo
6702 * the beacon interval.
6704 * TBTT = BT - (BT % BIu)
6705 * = (BTk - (BTk % BP)) * 2^10
6707 * BT = beacon timestamp (usec, 64bits)
6708 * BTk = beacon timestamp (Kusec, 54bits)
6709 * BP = beacon interval (Kusec, 16bits)
6710 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6712 * To keep the calculations in u32s, the modulo operation
6713 * on the high part of BT needs to be done in parts using the
6715 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6717 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6719 * So, if BTk[n] = u16 n [0,3] of BTk.
6720 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6721 * and the SUM term can be broken down:
6722 * (BTk[n] * 2^16n) % BP
6723 * (BTk[n] * (2^16n % BP)) % BP
6725 * Create a set of power of 2 mod BP constants:
6726 * K[n] = 2^(16n) % BP
6727 * = (K[n-1] * 2^16) % BP
6728 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6730 * BTk % BP = BTk[0-1] % BP +
6731 * (BTk[2] * K[2]) % BP +
6732 * (BTk[3] * K[3]) % BP
6734 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6737 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6738 btklo = (tsf_h << 22) | (tsf_l >> 10);
6739 btkhi = tsf_h >> 10;
6741 /* offset = BTk % BP */
6742 offset = btklo % bp;
6744 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6745 k = (u32) (1 << 16) % bp;
6746 k = (u32) (k * 1 << 16) % (u32) bp;
6748 /* offset += (BTk[2] * K[2]) % BP */
6749 offset += ((btkhi & 0xffff) * k) % bp;
6752 btkhi = btkhi >> 16;
6754 /* k[3] = (K[2] * 2^16) % BP */
6757 /* offset += (BTk[3] * K[3]) % BP */
6758 offset += ((btkhi & 0xffff) * k) % bp;
6760 offset = offset % bp;
6762 /* convert offset from kus to us by shifting up 10 bits and
6763 * add in the low 10 bits of tsf that we ignored
6765 offset = (offset << 10) + (tsf_l & 0x3FF);
6770 /* Update beacon listen interval in shared memory */
6771 void wlc_bcn_li_upd(struct wlc_info *wlc)
6773 if (AP_ENAB(wlc->pub))
6776 /* wake up every DTIM is the default */
6777 if (wlc->bcn_li_dtim == 1)
6778 wlc_write_shm(wlc, M_BCN_LI, 0);
6780 wlc_write_shm(wlc, M_BCN_LI,
6781 (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
6785 prep_mac80211_status(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p,
6786 struct ieee80211_rx_status *rx_status)
6789 wlc_d11rxhdr_t *wlc_rxh = (wlc_d11rxhdr_t *) rxh;
6793 unsigned char *plcp;
6796 /* Clearly, this is bogus -- reading the TSF now is wrong */
6797 wlc_read_tsf(wlc, &tsf_l, &tsf_h); /* mactime */
6798 rx_status->mactime = tsf_h;
6799 rx_status->mactime <<= 32;
6800 rx_status->mactime |= tsf_l;
6801 rx_status->flag |= RX_FLAG_MACTIME_MPDU; /* clearly wrong */
6804 channel = WLC_CHAN_CHANNEL(rxh->RxChan);
6807 rx_status->band = IEEE80211_BAND_5GHZ;
6808 rx_status->freq = ieee80211_ofdm_chan_to_freq(
6809 WF_CHAN_FACTOR_5_G/2, channel);
6812 rx_status->band = IEEE80211_BAND_2GHZ;
6813 rx_status->freq = ieee80211_dsss_chan_to_freq(channel);
6816 rx_status->signal = wlc_rxh->rssi; /* signal */
6820 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
6824 rspec = wlc_compute_rspec(rxh, plcp);
6825 if (IS_MCS(rspec)) {
6826 rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
6827 rx_status->flag |= RX_FLAG_HT;
6828 if (RSPEC_IS40MHZ(rspec))
6829 rx_status->flag |= RX_FLAG_40MHZ;
6831 switch (RSPEC2RATE(rspec)) {
6833 rx_status->rate_idx = 0;
6836 rx_status->rate_idx = 1;
6839 rx_status->rate_idx = 2;
6842 rx_status->rate_idx = 3;
6845 rx_status->rate_idx = 4;
6848 rx_status->rate_idx = 5;
6851 rx_status->rate_idx = 6;
6854 rx_status->rate_idx = 7;
6857 rx_status->rate_idx = 8;
6860 rx_status->rate_idx = 9;
6863 rx_status->rate_idx = 10;
6866 rx_status->rate_idx = 11;
6869 wiphy_err(wlc->wiphy, "%s: Unknown rate\n", __func__);
6872 /* Determine short preamble and rate_idx */
6874 if (IS_CCK(rspec)) {
6875 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
6876 rx_status->flag |= RX_FLAG_SHORTPRE;
6877 } else if (IS_OFDM(rspec)) {
6878 rx_status->flag |= RX_FLAG_SHORTPRE;
6880 wiphy_err(wlc->wiphy, "%s: Unknown modulation\n",
6885 if (PLCP3_ISSGI(plcp[3]))
6886 rx_status->flag |= RX_FLAG_SHORT_GI;
6888 if (rxh->RxStatus1 & RXS_DECERR) {
6889 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
6890 wiphy_err(wlc->wiphy, "%s: RX_FLAG_FAILED_PLCP_CRC\n",
6893 if (rxh->RxStatus1 & RXS_FCSERR) {
6894 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
6895 wiphy_err(wlc->wiphy, "%s: RX_FLAG_FAILED_FCS_CRC\n",
6901 wlc_recvctl(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p)
6904 struct ieee80211_rx_status rx_status;
6906 struct sk_buff *skb = p;
6909 memset(&rx_status, 0, sizeof(rx_status));
6910 prep_mac80211_status(wlc, rxh, p, &rx_status);
6912 /* mac header+body length, exclude CRC and plcp header */
6913 len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN;
6914 skb_pull(p, D11_PHY_HDR_LEN);
6915 __skb_trim(p, len_mpdu);
6920 ASSERT(IS_ALIGNED((unsigned long)skb->data, 2));
6922 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
6923 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
6925 wlc->pub->_cnt->ieee_rx++;
6929 void wlc_bss_list_free(struct wlc_info *wlc, struct wlc_bss_list *bss_list)
6934 wiphy_err(wlc->wiphy, "%s: Attempting to free NULL list\n",
6938 /* inspect all BSS descriptor */
6939 for (index = 0; index < bss_list->count; index++) {
6940 kfree(bss_list->ptrs[index]);
6941 bss_list->ptrs[index] = NULL;
6943 bss_list->count = 0;
6946 /* Process received frames */
6948 * Return true if more frames need to be processed. false otherwise.
6949 * Param 'bound' indicates max. # frames to process before break out.
6952 void BCMFASTPATH wlc_recv(struct wlc_info *wlc, struct sk_buff *p)
6955 struct ieee80211_hdr *h;
6959 WL_TRACE("wl%d: wlc_recv\n", wlc->pub->unit);
6961 /* frame starts with rxhdr */
6962 rxh = (d11rxhdr_t *) (p->data);
6964 /* strip off rxhdr */
6965 skb_pull(p, wlc->hwrxoff);
6967 /* fixup rx header endianness */
6968 rxh->RxFrameSize = le16_to_cpu(rxh->RxFrameSize);
6969 rxh->PhyRxStatus_0 = le16_to_cpu(rxh->PhyRxStatus_0);
6970 rxh->PhyRxStatus_1 = le16_to_cpu(rxh->PhyRxStatus_1);
6971 rxh->PhyRxStatus_2 = le16_to_cpu(rxh->PhyRxStatus_2);
6972 rxh->PhyRxStatus_3 = le16_to_cpu(rxh->PhyRxStatus_3);
6973 rxh->PhyRxStatus_4 = le16_to_cpu(rxh->PhyRxStatus_4);
6974 rxh->PhyRxStatus_5 = le16_to_cpu(rxh->PhyRxStatus_5);
6975 rxh->RxStatus1 = le16_to_cpu(rxh->RxStatus1);
6976 rxh->RxStatus2 = le16_to_cpu(rxh->RxStatus2);
6977 rxh->RxTSFTime = le16_to_cpu(rxh->RxTSFTime);
6978 rxh->RxChan = le16_to_cpu(rxh->RxChan);
6980 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
6981 if (rxh->RxStatus1 & RXS_PBPRES) {
6983 wlc->pub->_cnt->rxrunt++;
6984 wiphy_err(wlc->wiphy, "wl%d: wlc_recv: rcvd runt of "
6985 "len %d\n", wlc->pub->unit, p->len);
6991 h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN);
6994 if (rxh->RxStatus1 & RXS_FCSERR) {
6995 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
6996 wiphy_err(wlc->wiphy, "FCSERR while scanning******* -"
7000 wiphy_err(wlc->wiphy, "RCSERR!!!\n");
7005 /* check received pkt has at least frame control field */
7006 if (len < D11_PHY_HDR_LEN + sizeof(h->frame_control)) {
7007 wlc->pub->_cnt->rxrunt++;
7011 is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK;
7013 /* explicitly test bad src address to avoid sending bad deauth */
7015 /* CTS and ACK CTL frames are w/o a2 */
7017 if (ieee80211_is_data(h->frame_control) ||
7018 ieee80211_is_mgmt(h->frame_control)) {
7019 if ((is_zero_ether_addr(h->addr2) ||
7020 is_multicast_ether_addr(h->addr2))) {
7021 wiphy_err(wlc->wiphy, "wl%d: %s: dropping a "
7022 "frame with invalid src mac address,"
7024 wlc->pub->unit, __func__, h->addr2);
7025 wlc->pub->_cnt->rxbadsrcmac++;
7028 wlc->pub->_cnt->rxfrag++;
7032 /* due to sheer numbers, toss out probe reqs for now */
7033 if (ieee80211_is_probe_req(h->frame_control))
7039 wlc_recvctl(wlc, rxh, p);
7043 pkt_buf_free_skb(p);
7046 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7047 * number of bytes goes in the length field
7049 * Formula given by HT PHY Spec v 1.13
7050 * len = 3(nsyms + nstream + 3) - 3
7053 wlc_calc_lsig_len(struct wlc_info *wlc, ratespec_t ratespec, uint mac_len)
7055 uint nsyms, len = 0, kNdps;
7057 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7058 wlc->pub->unit, RSPEC2RATE(ratespec), mac_len);
7060 if (IS_MCS(ratespec)) {
7061 uint mcs = ratespec & RSPEC_RATE_MASK;
7062 /* MCS_TXS(mcs) returns num tx streams - 1 */
7063 int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec);
7065 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7066 /* the payload duration calculation matches that of regular ofdm */
7067 /* 1000Ndbps = kbps * 4 */
7069 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7070 RSPEC_ISSGI(ratespec)) * 4;
7072 if (RSPEC_STC(ratespec) == 0)
7073 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7075 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7076 APHY_TAIL_NBITS) * 1000, kNdps);
7078 /* STBC needs to have even number of symbols */
7081 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7082 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7084 nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7085 /* 3 bytes/symbol @ legacy 6Mbps rate */
7086 len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */
7092 /* calculate frame duration of a given rate and length, return time in usec unit */
7094 wlc_calc_frame_time(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7097 uint nsyms, dur = 0, Ndps, kNdps;
7098 uint rate = RSPEC2RATE(ratespec);
7102 wiphy_err(wlc->wiphy, "wl%d: WAR: using rate of 1 mbps\n",
7107 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7108 wlc->pub->unit, ratespec, preamble_type, mac_len);
7110 if (IS_MCS(ratespec)) {
7111 uint mcs = ratespec & RSPEC_RATE_MASK;
7112 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7113 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7114 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type));
7116 dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7117 if (preamble_type == WLC_MM_PREAMBLE)
7119 /* 1000Ndbps = kbps * 4 */
7121 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7122 RSPEC_ISSGI(ratespec)) * 4;
7124 if (RSPEC_STC(ratespec) == 0)
7125 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7127 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7128 APHY_TAIL_NBITS) * 1000, kNdps);
7130 /* STBC needs to have even number of symbols */
7133 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7134 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7136 dur += APHY_SYMBOL_TIME * nsyms;
7137 if (BAND_2G(wlc->band->bandtype))
7138 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7139 } else if (IS_OFDM(rate)) {
7140 dur = APHY_PREAMBLE_TIME;
7141 dur += APHY_SIGNAL_TIME;
7142 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7144 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7146 CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS),
7148 dur += APHY_SYMBOL_TIME * nsyms;
7149 if (BAND_2G(wlc->band->bandtype))
7150 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7152 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7153 mac_len = mac_len * 8 * 2;
7154 /* calc ceiling of bits/rate = microseconds of air time */
7155 dur = (mac_len + rate - 1) / rate;
7156 if (preamble_type & WLC_SHORT_PREAMBLE)
7157 dur += BPHY_PLCP_SHORT_TIME;
7159 dur += BPHY_PLCP_TIME;
7164 /* The opposite of wlc_calc_frame_time */
7166 wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7169 uint nsyms, mac_len, Ndps, kNdps;
7170 uint rate = RSPEC2RATE(ratespec);
7172 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7173 wlc->pub->unit, ratespec, preamble_type, dur);
7175 if (IS_MCS(ratespec)) {
7176 uint mcs = ratespec & RSPEC_RATE_MASK;
7177 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7178 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7179 dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7180 /* payload calculation matches that of regular ofdm */
7181 if (BAND_2G(wlc->band->bandtype))
7182 dur -= DOT11_OFDM_SIGNAL_EXTENSION;
7183 /* kNdbps = kbps * 4 */
7185 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7186 RSPEC_ISSGI(ratespec)) * 4;
7187 nsyms = dur / APHY_SYMBOL_TIME;
7190 ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000;
7191 } else if (IS_OFDM(ratespec)) {
7192 dur -= APHY_PREAMBLE_TIME;
7193 dur -= APHY_SIGNAL_TIME;
7194 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7196 nsyms = dur / APHY_SYMBOL_TIME;
7199 (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8;
7201 if (preamble_type & WLC_SHORT_PREAMBLE)
7202 dur -= BPHY_PLCP_SHORT_TIME;
7204 dur -= BPHY_PLCP_TIME;
7205 mac_len = dur * rate;
7206 /* divide out factor of 2 in rate (1/2 mbps) */
7207 mac_len = mac_len / 8 / 2;
7213 wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7215 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7216 wlc->pub->unit, rspec, preamble_type);
7217 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7218 * or equal to the rate of the immediately previous frame in the FES
7220 rspec = WLC_BASIC_RATE(wlc, rspec);
7221 ASSERT(VALID_RATE_DBG(wlc, rspec));
7223 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7224 return wlc_calc_frame_time(wlc, rspec, preamble_type,
7225 (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
7229 static uint BCMFASTPATH
7230 wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7234 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7235 wlc->pub->unit, rspec, preamble_type);
7236 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7237 * or equal to the rate of the immediately previous frame in the FES
7239 rspec = WLC_BASIC_RATE(wlc, rspec);
7240 ASSERT(VALID_RATE_DBG(wlc, rspec));
7242 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7244 wlc_calc_frame_time(wlc, rspec, preamble_type,
7245 (DOT11_ACK_LEN + FCS_LEN));
7250 wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7252 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7253 wlc->pub->unit, rspec, preamble_type);
7254 return wlc_calc_ack_time(wlc, rspec, preamble_type);
7257 /* derive wlc->band->basic_rate[] table from 'rateset' */
7258 void wlc_rate_lookup_init(struct wlc_info *wlc, wlc_rateset_t *rateset)
7264 u8 *br = wlc->band->basic_rate;
7267 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7268 memset(br, 0, WLC_MAXRATE + 1);
7270 /* For each basic rate in the rates list, make an entry in the
7271 * best basic lookup.
7273 for (i = 0; i < rateset->count; i++) {
7274 /* only make an entry for a basic rate */
7275 if (!(rateset->rates[i] & WLC_RATE_FLAG))
7278 /* mask off basic bit */
7279 rate = (rateset->rates[i] & WLC_RATE_MASK);
7281 if (rate > WLC_MAXRATE) {
7282 wiphy_err(wlc->wiphy, "wlc_rate_lookup_init: invalid "
7283 "rate 0x%X in rate set\n",
7291 /* The rate lookup table now has non-zero entries for each
7292 * basic rate, equal to the basic rate: br[basicN] = basicN
7294 * To look up the best basic rate corresponding to any
7295 * particular rate, code can use the basic_rate table
7298 * basic_rate = wlc->band->basic_rate[tx_rate]
7300 * Make sure there is a best basic rate entry for
7301 * every rate by walking up the table from low rates
7302 * to high, filling in holes in the lookup table
7305 for (i = 0; i < wlc->band->hw_rateset.count; i++) {
7306 rate = wlc->band->hw_rateset.rates[i];
7307 ASSERT(rate <= WLC_MAXRATE);
7309 if (br[rate] != 0) {
7310 /* This rate is a basic rate.
7311 * Keep track of the best basic rate so far by
7322 /* This rate is not a basic rate so figure out the
7323 * best basic rate less than this rate and fill in
7324 * the hole in the table
7327 br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic;
7332 if (IS_OFDM(rate)) {
7333 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7334 if (rate >= WLC_RATE_24M)
7335 mandatory = WLC_RATE_24M;
7336 else if (rate >= WLC_RATE_12M)
7337 mandatory = WLC_RATE_12M;
7339 mandatory = WLC_RATE_6M;
7341 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7345 br[rate] = mandatory;
7349 static void wlc_write_rate_shm(struct wlc_info *wlc, u8 rate, u8 basic_rate)
7352 u8 basic_phy_rate, basic_index;
7353 u16 dir_table, basic_table;
7356 /* Shared memory address for the table we are reading */
7357 dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
7359 /* Shared memory address for the table we are writing */
7360 basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
7363 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7364 * the index into the rate table.
7366 phy_rate = rate_info[rate] & WLC_RATE_MASK;
7367 basic_phy_rate = rate_info[basic_rate] & WLC_RATE_MASK;
7368 index = phy_rate & 0xf;
7369 basic_index = basic_phy_rate & 0xf;
7371 /* Find the SHM pointer to the ACK rate entry by looking in the
7374 basic_ptr = wlc_read_shm(wlc, (dir_table + basic_index * 2));
7376 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7377 * to the correct basic rate for the given incoming rate
7379 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr);
7382 static const wlc_rateset_t *wlc_rateset_get_hwrs(struct wlc_info *wlc)
7384 const wlc_rateset_t *rs_dflt;
7386 if (WLC_PHY_11N_CAP(wlc->band)) {
7387 if (BAND_5G(wlc->band->bandtype))
7388 rs_dflt = &ofdm_mimo_rates;
7390 rs_dflt = &cck_ofdm_mimo_rates;
7391 } else if (wlc->band->gmode)
7392 rs_dflt = &cck_ofdm_rates;
7394 rs_dflt = &cck_rates;
7399 void wlc_set_ratetable(struct wlc_info *wlc)
7401 const wlc_rateset_t *rs_dflt;
7403 u8 rate, basic_rate;
7406 rs_dflt = wlc_rateset_get_hwrs(wlc);
7407 ASSERT(rs_dflt != NULL);
7409 wlc_rateset_copy(rs_dflt, &rs);
7410 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7412 /* walk the phy rate table and update SHM basic rate lookup table */
7413 for (i = 0; i < rs.count; i++) {
7414 rate = rs.rates[i] & WLC_RATE_MASK;
7416 /* for a given rate WLC_BASIC_RATE returns the rate at
7417 * which a response ACK/CTS should be sent.
7419 basic_rate = WLC_BASIC_RATE(wlc, rate);
7420 if (basic_rate == 0) {
7421 /* This should only happen if we are using a
7422 * restricted rateset.
7424 basic_rate = rs.rates[0] & WLC_RATE_MASK;
7427 wlc_write_rate_shm(wlc, rate, basic_rate);
7432 * Return true if the specified rate is supported by the specified band.
7433 * WLC_BAND_AUTO indicates the current band.
7435 bool wlc_valid_rate(struct wlc_info *wlc, ratespec_t rspec, int band,
7438 wlc_rateset_t *hw_rateset;
7441 if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) {
7442 hw_rateset = &wlc->band->hw_rateset;
7443 } else if (NBANDS(wlc) > 1) {
7444 hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset;
7446 /* other band specified and we are a single band device */
7450 /* check if this is a mimo rate */
7451 if (IS_MCS(rspec)) {
7452 if (!VALID_MCS((rspec & RSPEC_RATE_MASK)))
7455 return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK));
7458 for (i = 0; i < hw_rateset->count; i++)
7459 if (hw_rateset->rates[i] == RSPEC2RATE(rspec))
7463 wiphy_err(wlc->wiphy, "wl%d: wlc_valid_rate: rate spec 0x%x "
7464 "not in hw_rateset\n", wlc->pub->unit, rspec);
7470 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap)
7473 struct wlcband *band;
7475 for (i = 0; i < NBANDS(wlc); i++) {
7476 if (IS_SINGLEBAND_5G(wlc->deviceid))
7478 band = wlc->bandstate[i];
7479 if (band->bandtype == WLC_BAND_5G) {
7480 if ((bwcap == WLC_N_BW_40ALL)
7481 || (bwcap == WLC_N_BW_20IN2G_40IN5G))
7482 band->mimo_cap_40 = true;
7484 band->mimo_cap_40 = false;
7486 ASSERT(band->bandtype == WLC_BAND_2G);
7487 if (bwcap == WLC_N_BW_40ALL)
7488 band->mimo_cap_40 = true;
7490 band->mimo_cap_40 = false;
7494 wlc->mimo_band_bwcap = bwcap;
7497 void wlc_mod_prb_rsp_rate_table(struct wlc_info *wlc, uint frame_len)
7499 const wlc_rateset_t *rs_dflt;
7503 u8 plcp[D11_PHY_HDR_LEN];
7507 sifs = SIFS(wlc->band);
7509 rs_dflt = wlc_rateset_get_hwrs(wlc);
7510 ASSERT(rs_dflt != NULL);
7512 wlc_rateset_copy(rs_dflt, &rs);
7513 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7515 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7516 for (i = 0; i < rs.count; i++) {
7517 rate = rs.rates[i] & WLC_RATE_MASK;
7519 entry_ptr = wlc_rate_shm_offset(wlc, rate);
7521 /* Calculate the Probe Response PLCP for the given rate */
7522 wlc_compute_plcp(wlc, rate, frame_len, plcp);
7524 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7526 (u16) wlc_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE,
7530 /* Update the SHM Rate Table entry Probe Response values */
7531 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS,
7532 (u16) (plcp[0] + (plcp[1] << 8)));
7533 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2,
7534 (u16) (plcp[2] + (plcp[3] << 8)));
7535 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur);
7540 wlc_compute_bcntsfoff(struct wlc_info *wlc, ratespec_t rspec,
7541 bool short_preamble, bool phydelay)
7545 if (IS_MCS(rspec)) {
7546 wiphy_err(wlc->wiphy, "wl%d: recd beacon with mcs rate; rspec "
7547 "0x%x\n", wlc->pub->unit, rspec);
7548 } else if (IS_OFDM(rspec)) {
7549 /* tx delay from MAC through phy to air (2.1 usec) +
7550 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7551 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7552 * bytes at beacon rate)
7554 bcntsfoff += phydelay ? D11A_PHY_TX_DELAY : 0;
7555 bcntsfoff += APHY_PREAMBLE_TIME + APHY_SIGNAL_TIME;
7557 wlc_compute_airtime(wlc, rspec,
7558 APHY_SERVICE_NBITS / 8 +
7561 /* tx delay from MAC through phy to air (3.4 usec) +
7562 * phy header time (long preamble + PLCP == 192 usec) +
7563 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7565 bcntsfoff += phydelay ? D11B_PHY_TX_DELAY : 0;
7567 short_preamble ? D11B_PHY_SPREHDR_TIME :
7568 D11B_PHY_LPREHDR_TIME;
7569 bcntsfoff += wlc_compute_airtime(wlc, rspec, DOT11_MAC_HDR_LEN);
7571 return (u16) (bcntsfoff);
7574 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7576 * PLCP header is 6 bytes.
7577 * 802.11 A3 header is 24 bytes.
7578 * Max beacon frame body template length is 112 bytes.
7579 * Max probe resp frame body template length is 110 bytes.
7581 * *len on input contains the max length of the packet available.
7583 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7584 * and included up to, but not including, the 4 byte FCS.
7587 wlc_bcn_prb_template(struct wlc_info *wlc, u16 type, ratespec_t bcn_rspec,
7588 struct wlc_bsscfg *cfg, u16 *buf, int *len)
7590 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
7591 cck_phy_hdr_t *plcp;
7592 struct ieee80211_mgmt *h;
7593 int hdr_len, body_len;
7595 ASSERT(*len >= 142);
7596 ASSERT(type == IEEE80211_STYPE_BEACON ||
7597 type == IEEE80211_STYPE_PROBE_RESP);
7599 if (MBSS_BCN_ENAB(cfg) && type == IEEE80211_STYPE_BEACON)
7600 hdr_len = DOT11_MAC_HDR_LEN;
7602 hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN;
7603 body_len = *len - hdr_len; /* calc buffer size provided for frame body */
7605 *len = hdr_len + body_len; /* return actual size */
7607 /* format PHY and MAC headers */
7608 memset((char *)buf, 0, hdr_len);
7610 plcp = (cck_phy_hdr_t *) buf;
7612 /* PLCP for Probe Response frames are filled in from core's rate table */
7613 if (type == IEEE80211_STYPE_BEACON && !MBSS_BCN_ENAB(cfg)) {
7615 wlc_compute_plcp(wlc, bcn_rspec,
7616 (DOT11_MAC_HDR_LEN + body_len + FCS_LEN),
7620 /* "Regular" and 16 MBSS but not for 4 MBSS */
7621 /* Update the phytxctl for the beacon based on the rspec */
7622 if (!SOFTBCN_ENAB(cfg))
7623 wlc_beacon_phytxctl_txant_upd(wlc, bcn_rspec);
7625 if (MBSS_BCN_ENAB(cfg) && type == IEEE80211_STYPE_BEACON)
7626 h = (struct ieee80211_mgmt *)&plcp[0];
7628 h = (struct ieee80211_mgmt *)&plcp[1];
7630 /* fill in 802.11 header */
7631 h->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | type);
7633 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7634 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7635 if (type == IEEE80211_STYPE_BEACON)
7636 memcpy(&h->da, ðer_bcast, ETH_ALEN);
7637 memcpy(&h->sa, &cfg->cur_etheraddr, ETH_ALEN);
7638 memcpy(&h->bssid, &cfg->BSSID, ETH_ALEN);
7640 /* SEQ filled in by MAC */
7645 int wlc_get_header_len()
7650 /* Update a beacon for a particular BSS
7651 * For MBSS, this updates the software template and sets "latest" to the index of the
7653 * Otherwise, it updates the hardware template.
7655 void wlc_bss_update_beacon(struct wlc_info *wlc, struct wlc_bsscfg *cfg)
7657 int len = BCN_TMPL_LEN;
7659 /* Clear the soft intmask */
7660 wlc->defmacintmask &= ~MI_BCNTPL;
7662 if (!cfg->up) { /* Only allow updates on an UP bss */
7666 /* Optimize: Some of if/else could be combined */
7667 if (!MBSS_BCN_ENAB(cfg) && HWBCN_ENAB(cfg)) {
7668 /* Hardware beaconing for this config */
7669 u16 bcn[BCN_TMPL_LEN / 2];
7670 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
7671 d11regs_t *regs = wlc->regs;
7673 /* Check if both templates are in use, if so sched. an interrupt
7674 * that will call back into this routine
7676 if ((R_REG(®s->maccommand) & both_valid) == both_valid) {
7677 /* clear any previous status */
7678 W_REG(®s->macintstatus, MI_BCNTPL);
7680 /* Check that after scheduling the interrupt both of the
7681 * templates are still busy. if not clear the int. & remask
7683 if ((R_REG(®s->maccommand) & both_valid) == both_valid) {
7684 wlc->defmacintmask |= MI_BCNTPL;
7689 wlc_lowest_basic_rspec(wlc, &cfg->current_bss->rateset);
7690 ASSERT(wlc_valid_rate
7691 (wlc, wlc->bcn_rspec,
7692 CHSPEC_IS2G(cfg->current_bss->
7693 chanspec) ? WLC_BAND_2G : WLC_BAND_5G,
7696 /* update the template and ucode shm */
7697 wlc_bcn_prb_template(wlc, IEEE80211_STYPE_BEACON,
7698 wlc->bcn_rspec, cfg, bcn, &len);
7699 wlc_write_hw_bcntemplates(wlc, bcn, len, false);
7704 * Update all beacons for the system.
7706 void wlc_update_beacon(struct wlc_info *wlc)
7709 struct wlc_bsscfg *bsscfg;
7711 /* update AP or IBSS beacons */
7712 FOREACH_BSS(wlc, idx, bsscfg) {
7713 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7714 wlc_bss_update_beacon(wlc, bsscfg);
7718 /* Write ssid into shared memory */
7719 void wlc_shm_ssid_upd(struct wlc_info *wlc, struct wlc_bsscfg *cfg)
7721 u8 *ssidptr = cfg->SSID;
7723 u8 ssidbuf[IEEE80211_MAX_SSID_LEN];
7725 /* padding the ssid with zero and copy it into shm */
7726 memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN);
7727 memcpy(ssidbuf, ssidptr, cfg->SSID_len);
7729 wlc_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN);
7731 if (!MBSS_BCN_ENAB(cfg))
7732 wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len);
7735 void wlc_update_probe_resp(struct wlc_info *wlc, bool suspend)
7738 struct wlc_bsscfg *bsscfg;
7740 /* update AP or IBSS probe responses */
7741 FOREACH_BSS(wlc, idx, bsscfg) {
7742 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7743 wlc_bss_update_probe_resp(wlc, bsscfg, suspend);
7748 wlc_bss_update_probe_resp(struct wlc_info *wlc, struct wlc_bsscfg *cfg,
7751 u16 prb_resp[BCN_TMPL_LEN / 2];
7752 int len = BCN_TMPL_LEN;
7754 /* write the probe response to hardware, or save in the config structure */
7755 if (!MBSS_PRB_ENAB(cfg)) {
7757 /* create the probe response template */
7758 wlc_bcn_prb_template(wlc, IEEE80211_STYPE_PROBE_RESP, 0, cfg,
7762 wlc_suspend_mac_and_wait(wlc);
7764 /* write the probe response into the template region */
7765 wlc_bmac_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
7766 (len + 3) & ~3, prb_resp);
7768 /* write the length of the probe response frame (+PLCP/-FCS) */
7769 wlc_write_shm(wlc, M_PRB_RESP_FRM_LEN, (u16) len);
7771 /* write the SSID and SSID length */
7772 wlc_shm_ssid_upd(wlc, cfg);
7775 * Write PLCP headers and durations for probe response frames at all rates.
7776 * Use the actual frame length covered by the PLCP header for the call to
7777 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7779 len += (-D11_PHY_HDR_LEN + FCS_LEN);
7780 wlc_mod_prb_rsp_rate_table(wlc, (u16) len);
7783 wlc_enable_mac(wlc);
7784 } else { /* Generating probe resp in sw; update local template */
7785 ASSERT(0 && "No software probe response support without MBSS");
7789 /* prepares pdu for transmission. returns BCM error codes */
7790 int wlc_prep_pdu(struct wlc_info *wlc, struct sk_buff *pdu, uint *fifop)
7794 struct ieee80211_hdr *h;
7798 txh = (d11txh_t *) (pdu->data);
7800 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
7803 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7804 fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
7810 /* return if insufficient dma resources */
7811 if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) {
7812 /* Mark precedences related to this FIFO, unsendable */
7813 WLC_TX_FIFO_CLEAR(wlc, fifo);
7817 if (!ieee80211_is_data(txh->MacFrameControl))
7818 wlc->pub->_cnt->txctl++;
7823 /* init tx reported rate mechanism */
7824 void wlc_reprate_init(struct wlc_info *wlc)
7827 struct wlc_bsscfg *bsscfg;
7829 FOREACH_BSS(wlc, i, bsscfg) {
7830 wlc_bsscfg_reprate_init(bsscfg);
7834 /* per bsscfg init tx reported rate mechanism */
7835 void wlc_bsscfg_reprate_init(struct wlc_bsscfg *bsscfg)
7837 bsscfg->txrspecidx = 0;
7838 memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec));
7841 /* Retrieve a consolidated set of revision information,
7842 * typically for the WLC_GET_REVINFO ioctl
7844 int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len)
7846 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf;
7848 if (len < WL_REV_INFO_LEGACY_LENGTH)
7849 return -BCME_BUFTOOSHORT;
7851 rinfo->vendorid = wlc->vendorid;
7852 rinfo->deviceid = wlc->deviceid;
7853 rinfo->radiorev = (wlc->band->radiorev << IDCODE_REV_SHIFT) |
7854 (wlc->band->radioid << IDCODE_ID_SHIFT);
7855 rinfo->chiprev = wlc->pub->sih->chiprev;
7856 rinfo->corerev = wlc->pub->corerev;
7857 rinfo->boardid = wlc->pub->sih->boardtype;
7858 rinfo->boardvendor = wlc->pub->sih->boardvendor;
7859 rinfo->boardrev = wlc->pub->boardrev;
7860 rinfo->ucoderev = wlc->ucode_rev;
7861 rinfo->driverrev = EPI_VERSION_NUM;
7862 rinfo->bus = wlc->pub->sih->bustype;
7863 rinfo->chipnum = wlc->pub->sih->chip;
7865 if (len >= (offsetof(wlc_rev_info_t, chippkg))) {
7866 rinfo->phytype = wlc->band->phytype;
7867 rinfo->phyrev = wlc->band->phyrev;
7868 rinfo->anarev = 0; /* obsolete stuff, suppress */
7871 if (len >= sizeof(*rinfo)) {
7872 rinfo->chippkg = wlc->pub->sih->chippkg;
7878 void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs)
7880 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype,
7881 false, WLC_RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7882 CHSPEC_WLC_BW(wlc->default_bss->chanspec),
7883 wlc->stf->txstreams);
7886 static void wlc_bss_default_init(struct wlc_info *wlc)
7888 chanspec_t chanspec;
7889 struct wlcband *band;
7890 wlc_bss_info_t *bi = wlc->default_bss;
7892 /* init default and target BSS with some sane initial values */
7893 memset((char *)(bi), 0, sizeof(wlc_bss_info_t));
7894 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT :
7895 BEACON_INTERVAL_DEFAULT;
7896 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT :
7897 DTIM_INTERVAL_DEFAULT;
7899 /* fill the default channel as the first valid channel
7900 * starting from the 2G channels
7902 chanspec = CH20MHZ_CHSPEC(1);
7903 ASSERT(chanspec != INVCHANSPEC);
7905 wlc->home_chanspec = bi->chanspec = chanspec;
7907 /* find the band of our default channel */
7909 if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec))
7910 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
7912 /* init bss rates to the band specific default rate set */
7913 wlc_rateset_default(&bi->rateset, NULL, band->phytype, band->bandtype,
7914 false, WLC_RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7915 CHSPEC_WLC_BW(chanspec), wlc->stf->txstreams);
7917 if (N_ENAB(wlc->pub))
7918 bi->flags |= WLC_BSS_HT;
7922 wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, u32 b_low)
7924 if (b_low > *a_low) {
7925 /* low half needs a carry */
7933 mac80211_wlc_set_nrate(struct wlc_info *wlc, struct wlcband *cur_band,
7936 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
7937 u8 rate = int_val & NRATE_RATE_MASK;
7939 bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE);
7940 bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT);
7941 bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY)
7942 == NRATE_OVERRIDE_MCS_ONLY);
7946 return (ratespec_t) rate;
7949 /* validate the combination of rate/mcs/stf is allowed */
7950 if (N_ENAB(wlc->pub) && ismcs) {
7951 /* mcs only allowed when nmode */
7952 if (stf > PHY_TXC1_MODE_SDM) {
7953 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid stf\n",
7954 WLCWLUNIT(wlc), __func__);
7955 bcmerror = -BCME_RANGE;
7959 /* mcs 32 is a special case, DUP mode 40 only */
7961 if (!CHSPEC_IS40(wlc->home_chanspec) ||
7962 ((stf != PHY_TXC1_MODE_SISO)
7963 && (stf != PHY_TXC1_MODE_CDD))) {
7964 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid mcs "
7965 "32\n", WLCWLUNIT(wlc), __func__);
7966 bcmerror = -BCME_RANGE;
7969 /* mcs > 7 must use stf SDM */
7970 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
7971 /* mcs > 7 must use stf SDM */
7972 if (stf != PHY_TXC1_MODE_SDM) {
7973 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
7974 WLCWLUNIT(wlc), __func__, rate);
7975 stf = PHY_TXC1_MODE_SDM;
7978 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
7979 if ((stf > PHY_TXC1_MODE_STBC) ||
7980 (!WLC_STBC_CAP_PHY(wlc)
7981 && (stf == PHY_TXC1_MODE_STBC))) {
7982 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid STBC"
7983 "\n", WLCWLUNIT(wlc), __func__);
7984 bcmerror = -BCME_RANGE;
7988 } else if (IS_OFDM(rate)) {
7989 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
7990 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid OFDM\n",
7991 WLCWLUNIT(wlc), __func__);
7992 bcmerror = -BCME_RANGE;
7995 } else if (IS_CCK(rate)) {
7996 if ((cur_band->bandtype != WLC_BAND_2G)
7997 || (stf != PHY_TXC1_MODE_SISO)) {
7998 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid CCK\n",
7999 WLCWLUNIT(wlc), __func__);
8000 bcmerror = -BCME_RANGE;
8004 wiphy_err(wlc->wiphy, "wl%d: %s: Unknown rate type\n",
8005 WLCWLUNIT(wlc), __func__);
8006 bcmerror = -BCME_RANGE;
8009 /* make sure multiple antennae are available for non-siso rates */
8010 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
8011 wiphy_err(wlc->wiphy, "wl%d: %s: SISO antenna but !SISO "
8012 "request\n", WLCWLUNIT(wlc), __func__);
8013 bcmerror = -BCME_RANGE;
8019 rspec |= RSPEC_MIMORATE;
8020 /* For STBC populate the STC field of the ratespec */
8021 if (stf == PHY_TXC1_MODE_STBC) {
8023 stc = 1; /* Nss for single stream is always 1 */
8024 rspec |= (stc << RSPEC_STC_SHIFT);
8028 rspec |= (stf << RSPEC_STF_SHIFT);
8030 if (override_mcs_only)
8031 rspec |= RSPEC_OVERRIDE_MCS_ONLY;
8034 rspec |= RSPEC_SHORT_GI;
8037 && !wlc_valid_rate(wlc, rspec, cur_band->bandtype, true)) {
8046 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8048 wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
8051 int idle_busy_ratio_x_16 = 0;
8053 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
8054 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
8055 if (duty_cycle > 100 || duty_cycle < 0) {
8056 wiphy_err(wlc->wiphy, "wl%d: duty cycle value off limit\n",
8061 idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle;
8062 /* Only write to shared memory when wl is up */
8064 wlc_write_shm(wlc, offset, (u16) idle_busy_ratio_x_16);
8067 wlc->tx_duty_cycle_ofdm = (u16) duty_cycle;
8069 wlc->tx_duty_cycle_cck = (u16) duty_cycle;
8074 /* Read a single u16 from shared memory.
8075 * SHM 'offset' needs to be an even address
8077 u16 wlc_read_shm(struct wlc_info *wlc, uint offset)
8079 return wlc_bmac_read_shm(wlc->hw, offset);
8082 /* Write a single u16 to shared memory.
8083 * SHM 'offset' needs to be an even address
8085 void wlc_write_shm(struct wlc_info *wlc, uint offset, u16 v)
8087 wlc_bmac_write_shm(wlc->hw, offset, v);
8090 /* Set a range of shared memory to a value.
8091 * SHM 'offset' needs to be an even address and
8092 * Range length 'len' must be an even number of bytes
8094 void wlc_set_shm(struct wlc_info *wlc, uint offset, u16 v, int len)
8096 /* offset and len need to be even */
8097 ASSERT((offset & 1) == 0);
8098 ASSERT((len & 1) == 0);
8103 wlc_bmac_set_shm(wlc->hw, offset, v, len);
8106 /* Copy a buffer to shared memory.
8107 * SHM 'offset' needs to be an even address and
8108 * Buffer length 'len' must be an even number of bytes
8110 void wlc_copyto_shm(struct wlc_info *wlc, uint offset, const void *buf, int len)
8112 /* offset and len need to be even */
8113 ASSERT((offset & 1) == 0);
8114 ASSERT((len & 1) == 0);
8118 wlc_bmac_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8122 /* Copy from shared memory to a buffer.
8123 * SHM 'offset' needs to be an even address and
8124 * Buffer length 'len' must be an even number of bytes
8126 void wlc_copyfrom_shm(struct wlc_info *wlc, uint offset, void *buf, int len)
8128 /* offset and len need to be even */
8129 ASSERT((offset & 1) == 0);
8130 ASSERT((len & 1) == 0);
8135 wlc_bmac_copyfrom_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8138 /* wrapper BMAC functions to for HIGH driver access */
8139 void wlc_mctrl(struct wlc_info *wlc, u32 mask, u32 val)
8141 wlc_bmac_mctrl(wlc->hw, mask, val);
8144 void wlc_corereset(struct wlc_info *wlc, u32 flags)
8146 wlc_bmac_corereset(wlc->hw, flags);
8149 void wlc_mhf(struct wlc_info *wlc, u8 idx, u16 mask, u16 val, int bands)
8151 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands);
8154 u16 wlc_mhf_get(struct wlc_info *wlc, u8 idx, int bands)
8156 return wlc_bmac_mhf_get(wlc->hw, idx, bands);
8159 int wlc_xmtfifo_sz_get(struct wlc_info *wlc, uint fifo, uint *blocks)
8161 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks);
8164 void wlc_write_template_ram(struct wlc_info *wlc, int offset, int len,
8167 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf);
8170 void wlc_write_hw_bcntemplates(struct wlc_info *wlc, void *bcn, int len,
8173 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both);
8177 wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
8180 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr);
8181 if (match_reg_offset == RCM_BSSID_OFFSET)
8182 memcpy(wlc->cfg->BSSID, addr, ETH_ALEN);
8185 void wlc_set_rcmta(struct wlc_info *wlc, int idx, const u8 *addr)
8187 wlc_bmac_set_rcmta(wlc->hw, idx, addr);
8190 void wlc_read_tsf(struct wlc_info *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr)
8192 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr);
8195 void wlc_set_cwmin(struct wlc_info *wlc, u16 newmin)
8197 wlc->band->CWmin = newmin;
8198 wlc_bmac_set_cwmin(wlc->hw, newmin);
8201 void wlc_set_cwmax(struct wlc_info *wlc, u16 newmax)
8203 wlc->band->CWmax = newmax;
8204 wlc_bmac_set_cwmax(wlc->hw, newmax);
8207 void wlc_fifoerrors(struct wlc_info *wlc)
8210 wlc_bmac_fifoerrors(wlc->hw);
8213 /* Search mem rw utilities */
8215 void wlc_pllreq(struct wlc_info *wlc, bool set, mbool req_bit)
8217 wlc_bmac_pllreq(wlc->hw, set, req_bit);
8220 void wlc_reset_bmac_done(struct wlc_info *wlc)
8224 void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode)
8226 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_SM_PS;
8227 wlc->ht_cap.cap_info |= (mimops_mode << IEEE80211_HT_CAP_SM_PS_SHIFT);
8229 if (AP_ENAB(wlc->pub) && wlc->clk) {
8230 wlc_update_beacon(wlc);
8231 wlc_update_probe_resp(wlc, true);
8235 /* check for the particular priority flow control bit being set */
8237 wlc_txflowcontrol_prio_isset(struct wlc_info *wlc, struct wlc_txq_info *q,
8242 if (prio == ALLPRIO) {
8243 prio_mask = TXQ_STOP_FOR_PRIOFC_MASK;
8245 ASSERT(prio >= 0 && prio <= MAXPRIO);
8246 prio_mask = NBITVAL(prio);
8249 return (q->stopped & prio_mask) == prio_mask;
8252 /* propagate the flow control to all interfaces using the given tx queue */
8253 void wlc_txflowcontrol(struct wlc_info *wlc, struct wlc_txq_info *qi,
8259 WL_TRACE("%s: flow control kicks in\n", __func__);
8261 if (prio == ALLPRIO) {
8262 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
8264 ASSERT(prio >= 0 && prio <= MAXPRIO);
8265 prio_bits = NBITVAL(prio);
8268 cur_bits = qi->stopped & prio_bits;
8270 /* Check for the case of no change and return early
8271 * Otherwise update the bit and continue
8274 if (cur_bits == prio_bits) {
8277 mboolset(qi->stopped, prio_bits);
8279 if (cur_bits == 0) {
8282 mboolclr(qi->stopped, prio_bits);
8285 /* If there is a flow control override we will not change the external
8286 * flow control state.
8288 if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) {
8292 wlc_txflowcontrol_signal(wlc, qi, on, prio);
8296 wlc_txflowcontrol_override(struct wlc_info *wlc, struct wlc_txq_info *qi,
8297 bool on, uint override)
8301 ASSERT(override != 0);
8302 ASSERT((override & TXQ_STOP_FOR_PRIOFC_MASK) == 0);
8304 prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK);
8306 /* Update the flow control bits and do an early return if there is
8307 * no change in the external flow control state.
8310 mboolset(qi->stopped, override);
8311 /* if there was a previous override bit on, then setting this
8312 * makes no difference.
8314 if (prev_override) {
8318 wlc_txflowcontrol_signal(wlc, qi, ON, ALLPRIO);
8320 mboolclr(qi->stopped, override);
8321 /* clearing an override bit will only make a difference for
8322 * flow control if it was the only bit set. For any other
8323 * override setting, just return
8325 if (prev_override != override) {
8329 if (qi->stopped == 0) {
8330 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8334 for (prio = MAXPRIO; prio >= 0; prio--) {
8335 if (!mboolisset(qi->stopped, NBITVAL(prio)))
8336 wlc_txflowcontrol_signal(wlc, qi, OFF,
8343 static void wlc_txflowcontrol_reset(struct wlc_info *wlc)
8345 struct wlc_txq_info *qi;
8347 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
8349 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8356 wlc_txflowcontrol_signal(struct wlc_info *wlc, struct wlc_txq_info *qi, bool on,
8359 struct wlc_if *wlcif;
8361 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
8362 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
8363 wl_txflowcontrol(wlc->wl, wlcif->wlif, on, prio);
8367 static struct wlc_txq_info *wlc_txq_alloc(struct wlc_info *wlc)
8369 struct wlc_txq_info *qi, *p;
8371 qi = wlc_calloc(wlc->pub->unit, sizeof(struct wlc_txq_info));
8374 * Have enough room for control packets along with HI watermark
8375 * Also, add room to txq for total psq packets if all the SCBs
8376 * leave PS mode. The watermark for flowcontrol to OS packets
8377 * will remain the same
8379 pktq_init(&qi->q, WLC_PREC_COUNT,
8380 (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT
8381 + wlc->pub->psq_pkts_total);
8383 /* add this queue to the the global list */
8386 wlc->tx_queues = qi;
8388 while (p->next != NULL)
8396 static void wlc_txq_free(struct wlc_info *wlc, struct wlc_txq_info *qi)
8398 struct wlc_txq_info *p;
8403 /* remove the queue from the linked list */
8406 wlc->tx_queues = p->next;
8408 while (p != NULL && p->next != qi)
8410 ASSERT(p->next == qi);
8412 p->next = p->next->next;
8419 * Flag 'scan in progress' to withhold dynamic phy calibration
8421 void wlc_scan_start(struct wlc_info *wlc)
8423 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, true);
8426 void wlc_scan_stop(struct wlc_info *wlc)
8428 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, false);
8431 void wlc_associate_upd(struct wlc_info *wlc, bool state)
8433 wlc->pub->associated = state;
8434 wlc->cfg->associated = state;
8438 * When a remote STA/AP is removed by Mac80211, or when it can no longer accept
8439 * AMPDU traffic, packets pending in hardware have to be invalidated so that
8440 * when later on hardware releases them, they can be handled appropriately.
8442 void wlc_inval_dma_pkts(struct wlc_hw_info *hw,
8443 struct ieee80211_sta *sta,
8444 void (*dma_callback_fn))
8446 struct hnddma_pub *dmah;
8448 for (i = 0; i < NFIFO; i++) {
8451 dma_walk_packets(dmah, dma_callback_fn, sta);
8455 int wlc_get_curband(struct wlc_info *wlc)
8457 return wlc->band->bandunit;