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>
26 #include <bcmendian.h>
38 #include <wlc_bsscfg.h>
39 #include <wlc_channel.h>
40 #include <wlc_event.h>
41 #include <wlc_mac80211.h>
44 #include <wlc_phy_hal.h>
45 #include <wlc_phy_shim.h>
46 #include <wlc_antsel.h>
48 #include <wlc_ampdu.h>
49 #include <wlc_event.h>
50 #include <wl_export.h>
51 #include "d11ucode_ext.h"
52 #include <wlc_alloc.h>
53 #include <net/mac80211.h>
60 #define RSN_CAP_4_REPLAY_CNTRS 2
61 #define RSN_CAP_16_REPLAY_CNTRS 3
63 #define WPA_CAP_4_REPLAY_CNTRS RSN_CAP_4_REPLAY_CNTRS
64 #define WPA_CAP_16_REPLAY_CNTRS RSN_CAP_16_REPLAY_CNTRS
67 * buffer length needed for wlc_format_ssid
68 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
70 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
72 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
73 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
75 #ifndef WLC_MPC_MAX_DELAYCNT
76 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
78 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
79 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
81 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
82 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
84 /* Scale down delays to accommodate QT slow speed */
85 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
86 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
88 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
91 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
92 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
93 * this low resolution driver tick can be used for maintenance tasks such as phy
94 * calibration and scb update
97 /* watchdog trigger mode: OSL timer or TBTT */
98 #define WLC_WATCHDOG_TBTT(wlc) \
99 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
101 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
102 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
104 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
105 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
115 /* Find basic rate for a given rate */
116 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
117 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
118 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
120 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
122 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
124 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
126 #define SCAN_IN_PROGRESS(x) 0
128 #define EPI_VERSION_NUM 0x054b0b00
131 /* pointer to most recently allocated wl/wlc */
132 static struct wlc_info
*wlc_info_dbg
= (struct wlc_info
*) (NULL
);
137 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
138 * table and by the wlc_doiovar() function. No ordering is imposed:
139 * the table is keyed by name, and the function uses a switch.
145 IOV_BCN_LI_BCN
, /* Beacon listen interval in # of beacons */
146 IOV_LAST
/* In case of a need to check max ID number */
149 const bcm_iovar_t wlc_iovars
[] = {
150 {"mpc", IOV_MPC
, (0), IOVT_BOOL
, 0},
151 {"rtsthresh", IOV_RTSTHRESH
, (IOVF_WHL
), IOVT_UINT16
, 0},
152 {"qtxpower", IOV_QTXPOWER
, (IOVF_WHL
), IOVT_UINT32
, 0},
153 {"bcn_li_bcn", IOV_BCN_LI_BCN
, (0), IOVT_UINT8
, 0},
157 const u8 prio2fifo
[NUMPRIO
] = {
158 TX_AC_BE_FIFO
, /* 0 BE AC_BE Best Effort */
159 TX_AC_BK_FIFO
, /* 1 BK AC_BK Background */
160 TX_AC_BK_FIFO
, /* 2 -- AC_BK Background */
161 TX_AC_BE_FIFO
, /* 3 EE AC_BE Best Effort */
162 TX_AC_VI_FIFO
, /* 4 CL AC_VI Video */
163 TX_AC_VI_FIFO
, /* 5 VI AC_VI Video */
164 TX_AC_VO_FIFO
, /* 6 VO AC_VO Voice */
165 TX_AC_VO_FIFO
/* 7 NC AC_VO Voice */
168 /* precedences numbers for wlc queues. These are twice as may levels as
170 * Odd numbers are used for HI priority traffic at same precedence levels
171 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
173 #define _WLC_PREC_NONE 0 /* None = - */
174 #define _WLC_PREC_BK 2 /* BK - Background */
175 #define _WLC_PREC_BE 4 /* BE - Best-effort */
176 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
177 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
178 #define _WLC_PREC_VI 10 /* Vi - Video */
179 #define _WLC_PREC_VO 12 /* Vo - Voice */
180 #define _WLC_PREC_NC 14 /* NC - Network Control */
182 /* 802.1D Priority to precedence queue mapping */
183 const u8 wlc_prio2prec_map
[] = {
184 _WLC_PREC_BE
, /* 0 BE - Best-effort */
185 _WLC_PREC_BK
, /* 1 BK - Background */
186 _WLC_PREC_NONE
, /* 2 None = - */
187 _WLC_PREC_EE
, /* 3 EE - Excellent-effort */
188 _WLC_PREC_CL
, /* 4 CL - Controlled Load */
189 _WLC_PREC_VI
, /* 5 Vi - Video */
190 _WLC_PREC_VO
, /* 6 Vo - Voice */
191 _WLC_PREC_NC
, /* 7 NC - Network Control */
194 /* Sanity check for tx_prec_map and fifo synchup
195 * Either there are some packets pending for the fifo, else if fifo is empty then
196 * all the corresponding precmap bits should be set
198 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
199 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
200 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
201 (wlc)->fifo2prec_map[(fifo)]))
203 /* TX FIFO number to WME/802.1E Access Category */
204 const u8 wme_fifo2ac
[] = { AC_BK
, AC_BE
, AC_VI
, AC_VO
, AC_BE
, AC_BE
};
206 /* WME/802.1E Access Category to TX FIFO number */
207 static const u8 wme_ac2fifo
[] = { 1, 0, 2, 3 };
209 static bool in_send_q
= false;
211 /* Shared memory location index for various AC params */
212 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
215 static const char *fifo_names
[] = {
216 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
217 const char *aci_names
[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
220 static const u8 acbitmap2maxprio
[] = {
221 PRIO_8021D_BE
, PRIO_8021D_BE
, PRIO_8021D_BK
, PRIO_8021D_BK
,
222 PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
,
223 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
,
224 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
227 /* currently the best mechanism for determining SIFS is the band in use */
228 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
230 /* value for # replay counters currently supported */
231 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
233 /* local prototypes */
234 static u16 BCMFASTPATH
wlc_d11hdrs_mac80211(struct wlc_info
*wlc
,
235 struct ieee80211_hw
*hw
,
237 struct scb
*scb
, uint frag
,
238 uint nfrags
, uint queue
,
241 ratespec_t rspec_override
);
243 static void wlc_ctrupd_cache(u16 cur_stat
, u16
*macstat_snapshot
, u32
*macstat
);
244 static void wlc_bss_default_init(struct wlc_info
*wlc
);
245 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
);
246 static ratespec_t
mac80211_wlc_set_nrate(struct wlc_info
*wlc
,
247 struct wlcband
*cur_band
, u32 int_val
);
248 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
);
249 static void wlc_watchdog(void *arg
);
250 static void wlc_watchdog_by_timer(void *arg
);
251 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
);
252 static int wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
,
253 const bcm_iovar_t
*vi
);
254 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
);
256 /* send and receive */
257 static wlc_txq_info_t
*wlc_txq_alloc(struct wlc_info
*wlc
,
258 struct osl_info
*osh
);
259 static void wlc_txq_free(struct wlc_info
*wlc
, struct osl_info
*osh
,
261 static void wlc_txflowcontrol_signal(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
,
263 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
);
264 static u16
wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
,
266 static void wlc_compute_cck_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
267 static void wlc_compute_ofdm_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
268 static void wlc_compute_mimo_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
269 static u16
wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
,
270 u8 preamble_type
, uint next_frag_len
);
271 static void wlc_recvctl(struct wlc_info
*wlc
, struct osl_info
*osh
,
272 d11rxhdr_t
*rxh
, struct sk_buff
*p
);
273 static uint
wlc_calc_frame_len(struct wlc_info
*wlc
, ratespec_t rate
,
274 u8 preamble_type
, uint dur
);
275 static uint
wlc_calc_ack_time(struct wlc_info
*wlc
, ratespec_t rate
,
277 static uint
wlc_calc_cts_time(struct wlc_info
*wlc
, ratespec_t rate
,
279 /* interrupt, up/down, band */
280 static void wlc_setband(struct wlc_info
*wlc
, uint bandunit
);
281 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
);
282 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
);
283 static void wlc_bsinit(struct wlc_info
*wlc
);
284 static int wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
286 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
);
287 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
);
288 static void wlc_radio_timer(void *arg
);
289 static void wlc_radio_enable(struct wlc_info
*wlc
);
290 static void wlc_radio_upd(struct wlc_info
*wlc
);
292 /* scan, association, BSS */
293 static uint
wlc_calc_ba_time(struct wlc_info
*wlc
, ratespec_t rate
,
295 static void wlc_update_mimo_band_bwcap(struct wlc_info
*wlc
, u8 bwcap
);
296 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
);
297 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
);
298 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
);
300 static void wlc_process_eventq(void *arg
);
301 static void wlc_wme_retries_write(struct wlc_info
*wlc
);
302 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
);
303 static uint
wlc_attach_module(struct wlc_info
*wlc
);
304 static void wlc_detach_module(struct wlc_info
*wlc
);
305 static void wlc_timers_deinit(struct wlc_info
*wlc
);
306 static void wlc_down_led_upd(struct wlc_info
*wlc
);
307 static uint
wlc_down_del_timer(struct wlc_info
*wlc
);
308 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
);
309 static int _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
310 struct wlc_if
*wlcif
);
313 void wlc_get_rcmta(struct wlc_info
*wlc
, int idx
, u8
*addr
)
315 d11regs_t
*regs
= wlc
->regs
;
317 struct osl_info
*osh
;
319 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc
), __func__
);
321 ASSERT(wlc
->pub
->corerev
> 4);
325 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| (idx
* 2)));
326 (void)R_REG(osh
, ®s
->objaddr
);
327 v32
= R_REG(osh
, ®s
->objdata
);
329 addr
[1] = (u8
) (v32
>> 8);
330 addr
[2] = (u8
) (v32
>> 16);
331 addr
[3] = (u8
) (v32
>> 24);
332 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| ((idx
* 2) + 1)));
333 (void)R_REG(osh
, ®s
->objaddr
);
334 v32
= R_REG(osh
, (volatile u16
*)®s
->objdata
);
336 addr
[5] = (u8
) (v32
>> 8);
338 #endif /* defined(BCMDBG) */
340 /* keep the chip awake if needed */
341 bool wlc_stay_awake(struct wlc_info
*wlc
)
346 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
348 bool wlc_ps_allowed(struct wlc_info
*wlc
)
353 /* disallow PS when one of the following global conditions meets */
354 if (!wlc
->pub
->associated
|| !wlc
->PMenabled
|| wlc
->PM_override
)
357 /* disallow PS when one of these meets when not scanning */
358 if (!wlc
->PMblocked
) {
359 if (AP_ACTIVE(wlc
) || wlc
->monitor
)
363 FOREACH_AS_STA(wlc
, idx
, cfg
) {
364 /* disallow PS when one of the following bsscfg specific conditions meets */
365 if (!cfg
->BSS
|| !WLC_PORTOPEN(cfg
))
368 if (!cfg
->dtim_programmed
)
375 void wlc_reset(struct wlc_info
*wlc
)
377 WL_TRACE("wl%d: wlc_reset\n", wlc
->pub
->unit
);
379 wlc
->check_for_unaligned_tbtt
= false;
381 /* slurp up hw mac counters before core reset */
382 if (WLC_UPDATE_STATS(wlc
)) {
385 /* reset our snapshot of macstat counters */
386 memset((char *)wlc
->core
->macstat_snapshot
, 0,
390 wlc_bmac_reset(wlc
->hw
);
391 wlc_ampdu_reset(wlc
->ampdu
);
396 void wlc_fatal_error(struct wlc_info
*wlc
)
398 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc
->pub
->unit
);
402 /* Return the channel the driver should initialize during wlc_init.
403 * the channel may have to be changed from the currently configured channel
404 * if other configurations are in conflict (bandlocked, 11n mode disabled,
405 * invalid channel for current country, etc.)
407 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
)
409 chanspec_t chanspec
=
410 1 | WL_CHANSPEC_BW_20
| WL_CHANSPEC_CTL_SB_NONE
|
413 /* make sure the channel is on the supported band if we are band-restricted */
414 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
415 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
417 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
421 struct scb global_scb
;
423 static void wlc_init_scb(struct wlc_info
*wlc
, struct scb
*scb
)
426 scb
->flags
= SCB_WMECAP
| SCB_HTCAP
;
427 for (i
= 0; i
< NUMPRIO
; i
++)
431 void wlc_init(struct wlc_info
*wlc
)
436 wlc_bsscfg_t
*bsscfg
;
439 WL_TRACE("wl%d: wlc_init\n", wlc
->pub
->unit
);
443 /* This will happen if a big-hammer was executed. In that case, we want to go back
444 * to the channel that we were on and not new channel
446 if (wlc
->pub
->associated
)
447 chanspec
= wlc
->home_chanspec
;
449 chanspec
= wlc_init_chanspec(wlc
);
451 wlc_bmac_init(wlc
->hw
, chanspec
, mute
);
453 wlc
->seckeys
= wlc_bmac_read_shm(wlc
->hw
, M_SECRXKEYS_PTR
) * 2;
454 if (D11REV_GE(wlc
->pub
->corerev
, 15) && (wlc
->machwcap
& MCAP_TKIPMIC
))
456 wlc_bmac_read_shm(wlc
->hw
, M_TKMICKEYS_PTR
) * 2;
458 /* update beacon listen interval */
461 (u8
) (wlc_bmac_read_shm(wlc
->hw
, M_NOSLPZNATDTIM
) >> 10);
462 ASSERT(wlc
->bcn_wait_prd
> 0);
464 /* the world is new again, so is our reported rate */
465 wlc_reprate_init(wlc
);
467 /* write ethernet address to core */
468 FOREACH_BSS(wlc
, i
, bsscfg
) {
470 wlc_set_bssid(bsscfg
);
473 /* Update tsf_cfprep if associated and up */
474 if (wlc
->pub
->associated
) {
475 FOREACH_BSS(wlc
, i
, bsscfg
) {
479 /* get beacon period from bsscfg and convert to uS */
480 bi
= bsscfg
->current_bss
->beacon_period
<< 10;
481 /* update the tsf_cfprep register */
482 /* since init path would reset to default value */
483 W_REG(wlc
->osh
, ®s
->tsf_cfprep
,
484 (bi
<< CFPREP_CBI_SHIFT
));
486 /* Update maccontrol PM related bits */
487 wlc_set_ps_ctrl(wlc
);
494 wlc_key_hw_init_all(wlc
);
496 wlc_bandinit_ordered(wlc
, chanspec
);
498 wlc_init_scb(wlc
, &global_scb
);
500 /* init probe response timeout */
501 wlc_write_shm(wlc
, M_PRS_MAXTIME
, wlc
->prb_resp_timeout
);
503 /* init max burst txop (framebursting) */
504 wlc_write_shm(wlc
, M_MBURST_TXOP
,
506 _rifs
? (EDCF_AC_VO_TXOP_AP
<< 5) : MAXFRAMEBURST_TXOP
));
508 /* initialize maximum allowed duty cycle */
509 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_ofdm
, true, true);
510 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_cck
, false, true);
512 /* Update some shared memory locations related to max AMPDU size allowed to received */
513 wlc_ampdu_shm_upd(wlc
->ampdu
);
515 /* band-specific inits */
518 /* Enable EDCF mode (while the MAC is suspended) */
519 if (EDCF_ENAB(wlc
->pub
)) {
520 OR_REG(wlc
->osh
, ®s
->ifs_ctl
, IFS_USEEDCF
);
521 wlc_edcf_setparams(wlc
->cfg
, false);
524 /* Init precedence maps for empty FIFOs */
525 wlc_tx_prec_map_init(wlc
);
527 /* read the ucode version if we have not yet done so */
528 if (wlc
->ucode_rev
== 0) {
530 wlc_read_shm(wlc
, M_BOM_REV_MAJOR
) << NBITS(u16
);
531 wlc
->ucode_rev
|= wlc_read_shm(wlc
, M_BOM_REV_MINOR
);
534 /* ..now really unleash hell (allow the MAC out of suspend) */
537 /* clear tx flow control */
538 wlc_txflowcontrol_reset(wlc
);
540 /* clear tx data fifo suspends */
541 wlc
->tx_suspended
= false;
543 /* enable the RF Disable Delay timer */
544 if (D11REV_GE(wlc
->pub
->corerev
, 10))
545 W_REG(wlc
->osh
, &wlc
->regs
->rfdisabledly
, RFDISABLE_DEFAULT
);
547 /* initialize mpc delay */
548 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
551 * Initialize WME parameters; if they haven't been set by some other
552 * mechanism (IOVar, etc) then read them from the hardware.
554 if (WLC_WME_RETRY_SHORT_GET(wlc
, 0) == 0) { /* Unintialized; read from HW */
558 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
559 wlc
->wme_retries
[ac
] =
560 wlc_read_shm(wlc
, M_AC_TXLMT_ADDR(ac
));
565 void wlc_mac_bcn_promisc_change(struct wlc_info
*wlc
, bool promisc
)
567 wlc
->bcnmisc_monitor
= promisc
;
568 wlc_mac_bcn_promisc(wlc
);
571 void wlc_mac_bcn_promisc(struct wlc_info
*wlc
)
573 if ((AP_ENAB(wlc
->pub
) && (N_ENAB(wlc
->pub
) || wlc
->band
->gmode
)) ||
574 wlc
->bcnmisc_ibss
|| wlc
->bcnmisc_scan
|| wlc
->bcnmisc_monitor
)
575 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, MCTL_BCNS_PROMISC
);
577 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, 0);
580 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
581 void wlc_mac_promisc(struct wlc_info
*wlc
)
583 u32 promisc_bits
= 0;
585 /* promiscuous mode just sets MCTL_PROMISC
586 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
587 * since all BSS data traffic is directed at the AP
589 if (PROMISC_ENAB(wlc
->pub
) && !AP_ENAB(wlc
->pub
) && !wlc
->wet
)
590 promisc_bits
|= MCTL_PROMISC
;
592 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
593 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
594 * handled in wlc_mac_bcn_promisc()
596 if (MONITOR_ENAB(wlc
))
597 promisc_bits
|= MCTL_PROMISC
| MCTL_KEEPCONTROL
;
599 wlc_mctrl(wlc
, MCTL_PROMISC
| MCTL_KEEPCONTROL
, promisc_bits
);
602 /* check if hps and wake states of sw and hw are in sync */
603 bool wlc_ps_check(struct wlc_info
*wlc
)
609 if (!AP_ACTIVE(wlc
)) {
611 tmp
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
613 /* If deviceremoved is detected, then don't take any action as this can be called
614 * in any context. Assume that caller will take care of the condition. This is just
617 if (tmp
== 0xffffffff) {
618 WL_ERROR("wl%d: %s: dead chip\n",
619 wlc
->pub
->unit
, __func__
);
620 return DEVICEREMOVED(wlc
);
623 hps
= PS_ALLOWED(wlc
);
625 if (hps
!= ((tmp
& MCTL_HPS
) != 0)) {
628 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
629 wlc
->pub
->unit
, hps
, tmp
);
630 FOREACH_BSS(wlc
, idx
, cfg
) {
631 if (!BSSCFG_STA(cfg
))
637 /* For a monolithic build the wake check can be exact since it looks at wake
638 * override bits. The MCTL_WAKE bit should match the 'wake' value.
640 wake
= STAY_AWAKE(wlc
) || wlc
->hw
->wake_override
;
641 wake_ok
= (wake
== ((tmp
& MCTL_WAKE
) != 0));
642 if (hps
&& !wake_ok
) {
643 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
644 wlc
->pub
->unit
, wake
, tmp
);
652 /* push sw hps and wake state through hardware */
653 void wlc_set_ps_ctrl(struct wlc_info
*wlc
)
659 hps
= PS_ALLOWED(wlc
);
660 wake
= hps
? (STAY_AWAKE(wlc
)) : true;
662 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
663 wlc
->pub
->unit
, hps
, wake
);
665 v1
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
672 wlc_mctrl(wlc
, MCTL_WAKE
| MCTL_HPS
, v2
);
674 awake_before
= ((v1
& MCTL_WAKE
) || ((v1
& MCTL_HPS
) == 0));
676 if (wake
&& !awake_before
)
677 wlc_bmac_wait_for_wake(wlc
->hw
);
682 * Write this BSS config's MAC address to core.
683 * Updates RXE match engine.
685 int wlc_set_mac(wlc_bsscfg_t
*cfg
)
688 struct wlc_info
*wlc
= cfg
->wlc
;
690 if (cfg
== wlc
->cfg
) {
691 /* enter the MAC addr into the RXE match registers */
692 wlc_set_addrmatch(wlc
, RCM_MAC_OFFSET
, cfg
->cur_etheraddr
);
695 wlc_ampdu_macaddr_upd(wlc
);
700 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
701 * Updates RXE match engine.
703 void wlc_set_bssid(wlc_bsscfg_t
*cfg
)
705 struct wlc_info
*wlc
= cfg
->wlc
;
707 /* if primary config, we need to update BSSID in RXE match registers */
708 if (cfg
== wlc
->cfg
) {
709 wlc_set_addrmatch(wlc
, RCM_BSSID_OFFSET
, cfg
->BSSID
);
711 #ifdef SUPPORT_HWKEYS
712 else if (BSSCFG_STA(cfg
) && cfg
->BSS
) {
713 wlc_rcmta_add_bssid(wlc
, cfg
);
719 * Suspend the the MAC and update the slot timing
720 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
722 void wlc_switch_shortslot(struct wlc_info
*wlc
, bool shortslot
)
727 ASSERT(wlc
->band
->gmode
);
729 /* use the override if it is set */
730 if (wlc
->shortslot_override
!= WLC_SHORTSLOT_AUTO
)
731 shortslot
= (wlc
->shortslot_override
== WLC_SHORTSLOT_ON
);
733 if (wlc
->shortslot
== shortslot
)
736 wlc
->shortslot
= shortslot
;
738 /* update the capability based on current shortslot mode */
739 FOREACH_BSS(wlc
, idx
, cfg
) {
740 if (!cfg
->associated
)
742 cfg
->current_bss
->capability
&=
743 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
745 cfg
->current_bss
->capability
|=
746 WLAN_CAPABILITY_SHORT_SLOT_TIME
;
749 wlc_bmac_set_shortslot(wlc
->hw
, shortslot
);
752 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
)
757 local
= WLC_TXPWR_MAX
;
758 if (wlc
->pub
->associated
&&
759 (wf_chspec_ctlchan(wlc
->chanspec
) ==
760 wf_chspec_ctlchan(wlc
->home_chanspec
))) {
762 /* get the local power constraint if we are on the AP's
763 * channel [802.11h, 7.3.2.13]
765 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
767 (wlc
->txpwr_local_max
-
768 wlc
->txpwr_local_constraint
) * WLC_TXPWR_DB_FACTOR
;
769 if (local_max
> 0 && local_max
< WLC_TXPWR_MAX
)
770 return (u8
) local_max
;
778 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
779 void wlc_set_home_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
781 if (wlc
->home_chanspec
!= chanspec
) {
785 wlc
->home_chanspec
= chanspec
;
787 FOREACH_BSS(wlc
, idx
, cfg
) {
788 if (!cfg
->associated
)
790 cfg
->target_bss
->chanspec
= chanspec
;
791 cfg
->current_bss
->chanspec
= chanspec
;
797 static void wlc_set_phy_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
799 /* Save our copy of the chanspec */
800 wlc
->chanspec
= chanspec
;
802 /* Set the chanspec and power limits for this locale after computing
803 * any 11h local tx power constraints.
805 wlc_channel_set_chanspec(wlc
->cmi
, chanspec
,
806 wlc_local_constraint_qdbm(wlc
));
808 if (wlc
->stf
->ss_algosel_auto
)
809 wlc_stf_ss_algo_channel_get(wlc
, &wlc
->stf
->ss_algo_channel
,
812 wlc_stf_ss_update(wlc
, wlc
->band
);
816 void wlc_set_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
819 bool switchband
= false;
820 chanspec_t old_chanspec
= wlc
->chanspec
;
822 if (!wlc_valid_chanspec_db(wlc
->cmi
, chanspec
)) {
823 WL_ERROR("wl%d: %s: Bad channel %d\n",
824 wlc
->pub
->unit
, __func__
, CHSPEC_CHANNEL(chanspec
));
825 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
829 /* Switch bands if necessary */
830 if (NBANDS(wlc
) > 1) {
831 bandunit
= CHSPEC_WLCBANDUNIT(chanspec
);
832 if (wlc
->band
->bandunit
!= bandunit
|| wlc
->bandinit_pending
) {
834 if (wlc
->bandlocked
) {
835 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
836 wlc
->pub
->unit
, __func__
,
837 CHSPEC_CHANNEL(chanspec
));
840 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
841 * if the setband updates (wlc_bsinit) use low level calls to inspect and
842 * set state, the state inspected may be from the wrong band, or the
843 * following wlc_bmac_set_chanspec() may undo the work.
845 wlc_setband(wlc
, bandunit
);
849 ASSERT(N_ENAB(wlc
->pub
) || !CHSPEC_IS40(chanspec
));
851 /* sync up phy/radio chanspec */
852 wlc_set_phy_chanspec(wlc
, chanspec
);
854 /* init antenna selection */
855 if (CHSPEC_WLC_BW(old_chanspec
) != CHSPEC_WLC_BW(chanspec
)) {
856 if (WLANTSEL_ENAB(wlc
))
857 wlc_antsel_init(wlc
->asi
);
859 /* Fix the hardware rateset based on bw.
860 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
862 wlc_rateset_bw_mcs_filter(&wlc
->band
->hw_rateset
,
864 mimo_cap_40
? CHSPEC_WLC_BW(chanspec
)
868 /* update some mac configuration since chanspec changed */
869 wlc_ucode_mac_upd(wlc
);
873 static int wlc_get_current_txpwr(struct wlc_info
*wlc
, void *pwr
, uint len
)
875 txpwr_limits_t txpwr
;
877 tx_power_legacy_t
*old_power
= NULL
;
882 if (len
== sizeof(tx_power_legacy_t
))
883 old_power
= (tx_power_legacy_t
*) pwr
;
884 else if (len
< sizeof(tx_power_t
))
885 return BCME_BUFTOOSHORT
;
887 memset(&power
, 0, sizeof(tx_power_t
));
889 power
.chanspec
= WLC_BAND_PI_RADIO_CHANSPEC
;
890 if (wlc
->pub
->associated
)
891 power
.local_chanspec
= wlc
->home_chanspec
;
893 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
894 * public interface only implements getting and setting a single value for all of
895 * rates, so we need to fill the array ourselves.
897 wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
, &override
);
898 for (r
= 0; r
< WL_TX_POWER_RATES
; r
++) {
899 power
.user_limit
[r
] = (u8
) qdbm
;
902 power
.local_max
= wlc
->txpwr_local_max
* WLC_TXPWR_DB_FACTOR
;
903 power
.local_constraint
=
904 wlc
->txpwr_local_constraint
* WLC_TXPWR_DB_FACTOR
;
906 power
.antgain
[0] = wlc
->bandstate
[BAND_2G_INDEX
]->antgain
;
907 power
.antgain
[1] = wlc
->bandstate
[BAND_5G_INDEX
]->antgain
;
909 wlc_channel_reg_limits(wlc
->cmi
, power
.chanspec
, &txpwr
);
911 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
912 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
915 /* CCK tx power limits */
916 for (c
= 0, r
= WL_TX_POWER_CCK_FIRST
; c
< WL_TX_POWER_CCK_NUM
;
918 power
.reg_limit
[r
] = txpwr
.cck
[c
];
920 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
921 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
924 /* 20 MHz OFDM SISO tx power limits */
925 for (c
= 0, r
= WL_TX_POWER_OFDM_FIRST
; c
< WL_TX_POWER_OFDM_NUM
;
927 power
.reg_limit
[r
] = txpwr
.ofdm
[c
];
929 if (WLC_PHY_11N_CAP(wlc
->band
)) {
931 /* 20 MHz OFDM CDD tx power limits */
932 for (c
= 0, r
= WL_TX_POWER_OFDM20_CDD_FIRST
;
933 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
934 power
.reg_limit
[r
] = txpwr
.ofdm_cdd
[c
];
936 /* 40 MHz OFDM SISO tx power limits */
937 for (c
= 0, r
= WL_TX_POWER_OFDM40_SISO_FIRST
;
938 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
939 power
.reg_limit
[r
] = txpwr
.ofdm_40_siso
[c
];
941 /* 40 MHz OFDM CDD tx power limits */
942 for (c
= 0, r
= WL_TX_POWER_OFDM40_CDD_FIRST
;
943 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
944 power
.reg_limit
[r
] = txpwr
.ofdm_40_cdd
[c
];
946 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
947 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
950 /* 20MHz MCS0-7 SISO tx power limits */
951 for (c
= 0, r
= WL_TX_POWER_MCS20_SISO_FIRST
;
952 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
953 power
.reg_limit
[r
] = txpwr
.mcs_20_siso
[c
];
955 /* 20MHz MCS0-7 CDD tx power limits */
956 for (c
= 0, r
= WL_TX_POWER_MCS20_CDD_FIRST
;
957 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
958 power
.reg_limit
[r
] = txpwr
.mcs_20_cdd
[c
];
960 /* 20MHz MCS0-7 STBC tx power limits */
961 for (c
= 0, r
= WL_TX_POWER_MCS20_STBC_FIRST
;
962 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
963 power
.reg_limit
[r
] = txpwr
.mcs_20_stbc
[c
];
965 /* 40MHz MCS0-7 SISO tx power limits */
966 for (c
= 0, r
= WL_TX_POWER_MCS40_SISO_FIRST
;
967 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
968 power
.reg_limit
[r
] = txpwr
.mcs_40_siso
[c
];
970 /* 40MHz MCS0-7 CDD tx power limits */
971 for (c
= 0, r
= WL_TX_POWER_MCS40_CDD_FIRST
;
972 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
973 power
.reg_limit
[r
] = txpwr
.mcs_40_cdd
[c
];
975 /* 40MHz MCS0-7 STBC tx power limits */
976 for (c
= 0, r
= WL_TX_POWER_MCS40_STBC_FIRST
;
977 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
978 power
.reg_limit
[r
] = txpwr
.mcs_40_stbc
[c
];
980 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
981 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
984 /* 20MHz MCS8-15 SDM tx power limits */
985 for (c
= 0, r
= WL_TX_POWER_MCS20_SDM_FIRST
;
986 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
987 power
.reg_limit
[r
] = txpwr
.mcs_20_mimo
[c
];
989 /* 40MHz MCS8-15 SDM tx power limits */
990 for (c
= 0, r
= WL_TX_POWER_MCS40_SDM_FIRST
;
991 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
992 power
.reg_limit
[r
] = txpwr
.mcs_40_mimo
[c
];
995 power
.reg_limit
[WL_TX_POWER_MCS_32
] = txpwr
.mcs32
;
998 wlc_phy_txpower_get_current(wlc
->band
->pi
, &power
,
999 CHSPEC_CHANNEL(power
.chanspec
));
1001 /* copy the tx_power_t struct to the return buffer,
1002 * or convert to a tx_power_legacy_t struct
1005 bcopy(&power
, pwr
, sizeof(tx_power_t
));
1007 int band_idx
= CHSPEC_IS2G(power
.chanspec
) ? 0 : 1;
1009 memset(old_power
, 0, sizeof(tx_power_legacy_t
));
1011 old_power
->txpwr_local_max
= power
.local_max
;
1012 old_power
->txpwr_local_constraint
= power
.local_constraint
;
1013 if (CHSPEC_IS2G(power
.chanspec
)) {
1014 old_power
->txpwr_chan_reg_max
= txpwr
.cck
[0];
1015 old_power
->txpwr_est_Pout
[band_idx
] =
1017 old_power
->txpwr_est_Pout_gofdm
= power
.est_Pout
[0];
1019 old_power
->txpwr_chan_reg_max
= txpwr
.ofdm
[0];
1020 old_power
->txpwr_est_Pout
[band_idx
] = power
.est_Pout
[0];
1022 old_power
->txpwr_antgain
[0] = power
.antgain
[0];
1023 old_power
->txpwr_antgain
[1] = power
.antgain
[1];
1025 for (r
= 0; r
< NUM_PWRCTRL_RATES
; r
++) {
1026 old_power
->txpwr_band_max
[r
] = power
.user_limit
[r
];
1027 old_power
->txpwr_limit
[r
] = power
.reg_limit
[r
];
1028 old_power
->txpwr_target
[band_idx
][r
] = power
.target
[r
];
1029 if (CHSPEC_IS2G(power
.chanspec
))
1030 old_power
->txpwr_bphy_cck_max
[r
] =
1031 power
.board_limit
[r
];
1033 old_power
->txpwr_aphy_max
[r
] =
1034 power
.board_limit
[r
];
1040 #endif /* defined(BCMDBG) */
1042 static u32
wlc_watchdog_backup_bi(struct wlc_info
*wlc
)
1045 bi
= 2 * wlc
->cfg
->current_bss
->dtim_period
*
1046 wlc
->cfg
->current_bss
->beacon_period
;
1047 if (wlc
->bcn_li_dtim
)
1048 bi
*= wlc
->bcn_li_dtim
;
1049 else if (wlc
->bcn_li_bcn
)
1050 /* recalculate bi based on bcn_li_bcn */
1051 bi
= 2 * wlc
->bcn_li_bcn
* wlc
->cfg
->current_bss
->beacon_period
;
1053 if (bi
< 2 * TIMER_INTERVAL_WATCHDOG
)
1054 bi
= 2 * TIMER_INTERVAL_WATCHDOG
;
1058 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1059 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1061 void wlc_watchdog_upd(struct wlc_info
*wlc
, bool tbtt
)
1063 /* make sure changing watchdog driver is allowed */
1064 if (!wlc
->pub
->up
|| !wlc
->pub
->align_wd_tbtt
)
1066 if (!tbtt
&& wlc
->WDarmed
) {
1067 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1068 wlc
->WDarmed
= false;
1071 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1072 if (tbtt
&& wlc
->WDarmed
) {
1073 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1074 wlc
->WDarmed
= false;
1075 wlc
->WDlast
= OSL_SYSUPTIME();
1077 /* arm watchdog timer and drive the watchdog there */
1078 else if (!tbtt
&& !wlc
->WDarmed
) {
1079 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
1081 wlc
->WDarmed
= true;
1083 if (tbtt
&& !wlc
->WDarmed
) {
1084 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, wlc_watchdog_backup_bi(wlc
),
1086 wlc
->WDarmed
= true;
1090 ratespec_t
wlc_lowest_basic_rspec(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
1092 ratespec_t lowest_basic_rspec
;
1095 /* Use the lowest basic rate */
1096 lowest_basic_rspec
= rs
->rates
[0] & RATE_MASK
;
1097 for (i
= 0; i
< rs
->count
; i
++) {
1098 if (rs
->rates
[i
] & WLC_RATE_FLAG
) {
1099 lowest_basic_rspec
= rs
->rates
[i
] & RATE_MASK
;
1104 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1105 if (IS_OFDM(lowest_basic_rspec
)) {
1106 lowest_basic_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
1110 return lowest_basic_rspec
;
1113 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1114 * setting as per this table:
1115 * ratespec CCK ant = wlc->stf->txant
1118 void wlc_beacon_phytxctl_txant_upd(struct wlc_info
*wlc
, ratespec_t bcn_rspec
)
1121 u16 phytxant
= wlc
->stf
->phytxant
;
1122 u16 mask
= PHY_TXC_ANT_MASK
;
1124 /* for non-siso rates or default setting, use the available chains */
1125 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1126 phytxant
= wlc_stf_phytxchain_sel(wlc
, bcn_rspec
);
1129 phyctl
= wlc_read_shm(wlc
, M_BCN_PCTLWD
);
1130 phyctl
= (phyctl
& ~mask
) | phytxant
;
1131 wlc_write_shm(wlc
, M_BCN_PCTLWD
, phyctl
);
1134 /* centralized protection config change function to simplify debugging, no consistency checking
1135 * this should be called only on changes to avoid overhead in periodic function
1137 void wlc_protection_upd(struct wlc_info
*wlc
, uint idx
, int val
)
1139 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx
, val
);
1142 case WLC_PROT_G_SPEC
:
1143 wlc
->protection
->_g
= (bool) val
;
1145 case WLC_PROT_G_OVR
:
1146 wlc
->protection
->g_override
= (s8
) val
;
1148 case WLC_PROT_G_USER
:
1149 wlc
->protection
->gmode_user
= (u8
) val
;
1151 case WLC_PROT_OVERLAP
:
1152 wlc
->protection
->overlap
= (s8
) val
;
1154 case WLC_PROT_N_USER
:
1155 wlc
->protection
->nmode_user
= (s8
) val
;
1157 case WLC_PROT_N_CFG
:
1158 wlc
->protection
->n_cfg
= (s8
) val
;
1160 case WLC_PROT_N_CFG_OVR
:
1161 wlc
->protection
->n_cfg_override
= (s8
) val
;
1163 case WLC_PROT_N_NONGF
:
1164 wlc
->protection
->nongf
= (bool) val
;
1166 case WLC_PROT_N_NONGF_OVR
:
1167 wlc
->protection
->nongf_override
= (s8
) val
;
1169 case WLC_PROT_N_PAM_OVR
:
1170 wlc
->protection
->n_pam_override
= (s8
) val
;
1172 case WLC_PROT_N_OBSS
:
1173 wlc
->protection
->n_obss
= (bool) val
;
1183 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
)
1185 wlc
->ht_cap
.cap_info
&= ~(IEEE80211_HT_CAP_SGI_20
|
1186 IEEE80211_HT_CAP_SGI_40
);
1187 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_20
) ?
1188 IEEE80211_HT_CAP_SGI_20
: 0;
1189 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_40
) ?
1190 IEEE80211_HT_CAP_SGI_40
: 0;
1193 wlc_update_beacon(wlc
);
1194 wlc_update_probe_resp(wlc
, true);
1198 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
)
1200 wlc
->stf
->ldpc
= val
;
1202 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_LDPC_CODING
;
1203 if (wlc
->stf
->ldpc
!= OFF
)
1204 wlc
->ht_cap
.cap_info
|= IEEE80211_HT_CAP_LDPC_CODING
;
1207 wlc_update_beacon(wlc
);
1208 wlc_update_probe_resp(wlc
, true);
1209 wlc_phy_ldpc_override_set(wlc
->band
->pi
, (val
? true : false));
1214 * ucode, hwmac update
1215 * Channel dependent updates for ucode and hw
1217 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
)
1219 /* enable or disable any active IBSSs depending on whether or not
1220 * we are on the home channel
1222 if (wlc
->home_chanspec
== WLC_BAND_PI_RADIO_CHANSPEC
) {
1223 if (wlc
->pub
->associated
) {
1224 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1225 * I think that the ucode inits set up the bcn templates and shm values
1226 * with a bogus beacon. This should not be done in the inits. If ucode needs
1227 * to set up a beacon for testing, the test routines should write it down,
1228 * not expect the inits to populate a bogus beacon.
1230 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1231 wlc_write_shm(wlc
, M_BCN_TXTSF_OFFSET
,
1232 wlc
->band
->bcntsfoff
);
1236 /* disable an active IBSS if we are not on the home channel */
1239 /* update the various promisc bits */
1240 wlc_mac_bcn_promisc(wlc
);
1241 wlc_mac_promisc(wlc
);
1244 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
)
1246 wlc_rateset_t default_rateset
;
1248 uint i
, band_order
[2];
1250 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc
->pub
->unit
);
1252 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1253 * figure out the right band to park on
1255 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
1256 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
1258 parkband
= wlc
->band
->bandunit
; /* updated in wlc_bandlock() */
1259 band_order
[0] = band_order
[1] = parkband
;
1261 /* park on the band of the specified chanspec */
1262 parkband
= CHSPEC_WLCBANDUNIT(chanspec
);
1264 /* order so that parkband initialize last */
1265 band_order
[0] = parkband
^ 1;
1266 band_order
[1] = parkband
;
1269 /* make each band operational, software state init */
1270 for (i
= 0; i
< NBANDS(wlc
); i
++) {
1271 uint j
= band_order
[i
];
1273 wlc
->band
= wlc
->bandstate
[j
];
1275 wlc_default_rateset(wlc
, &default_rateset
);
1277 /* fill in hw_rate */
1278 wlc_rateset_filter(&default_rateset
, &wlc
->band
->hw_rateset
,
1279 false, WLC_RATES_CCK_OFDM
, RATE_MASK
,
1280 (bool) N_ENAB(wlc
->pub
));
1282 /* init basic rate lookup */
1283 wlc_rate_lookup_init(wlc
, &default_rateset
);
1286 /* sync up phy/radio chanspec */
1287 wlc_set_phy_chanspec(wlc
, chanspec
);
1290 /* band-specific init */
1291 static void WLBANDINITFN(wlc_bsinit
) (struct wlc_info
*wlc
)
1293 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1294 wlc
->pub
->unit
, wlc
->band
->bandunit
);
1296 /* write ucode ACK/CTS rate table */
1297 wlc_set_ratetable(wlc
);
1299 /* update some band specific mac configuration */
1300 wlc_ucode_mac_upd(wlc
);
1302 /* init antenna selection */
1303 if (WLANTSEL_ENAB(wlc
))
1304 wlc_antsel_init(wlc
->asi
);
1308 /* switch to and initialize new band */
1309 static void WLBANDINITFN(wlc_setband
) (struct wlc_info
*wlc
, uint bandunit
)
1314 ASSERT(NBANDS(wlc
) > 1);
1315 ASSERT(!wlc
->bandlocked
);
1316 ASSERT(bandunit
!= wlc
->band
->bandunit
|| wlc
->bandinit_pending
);
1318 wlc
->band
= wlc
->bandstate
[bandunit
];
1323 /* wait for at least one beacon before entering sleeping state */
1324 wlc
->PMawakebcn
= true;
1325 FOREACH_AS_STA(wlc
, idx
, cfg
)
1326 cfg
->PMawakebcn
= true;
1327 wlc_set_ps_ctrl(wlc
);
1329 /* band-specific initializations */
1333 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1334 void wlc_wme_initparams_sta(struct wlc_info
*wlc
, wme_param_ie_t
*pe
)
1336 static const wme_param_ie_t stadef
= {
1339 WME_SUBTYPE_PARAM_IE
,
1344 {EDCF_AC_BE_ACI_STA
, EDCF_AC_BE_ECW_STA
,
1345 HTOL16(EDCF_AC_BE_TXOP_STA
)},
1346 {EDCF_AC_BK_ACI_STA
, EDCF_AC_BK_ECW_STA
,
1347 HTOL16(EDCF_AC_BK_TXOP_STA
)},
1348 {EDCF_AC_VI_ACI_STA
, EDCF_AC_VI_ECW_STA
,
1349 HTOL16(EDCF_AC_VI_TXOP_STA
)},
1350 {EDCF_AC_VO_ACI_STA
, EDCF_AC_VO_ECW_STA
,
1351 HTOL16(EDCF_AC_VO_TXOP_STA
)}
1355 ASSERT(sizeof(*pe
) == WME_PARAM_IE_LEN
);
1356 memcpy(pe
, &stadef
, sizeof(*pe
));
1359 void wlc_wme_setparams(struct wlc_info
*wlc
, u16 aci
, void *arg
, bool suspend
)
1362 shm_acparams_t acp_shm
;
1364 struct ieee80211_tx_queue_params
*params
= arg
;
1368 /* Only apply params if the core is out of reset and has clocks */
1370 WL_ERROR("wl%d: %s : no-clock\n", wlc
->pub
->unit
, __func__
);
1375 * AP uses AC params from wme_param_ie_ap.
1376 * AP advertises AC params from wme_param_ie.
1377 * STA uses AC params from wme_param_ie.
1380 wlc
->wme_admctl
= 0;
1383 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1384 /* find out which ac this set of params applies to */
1385 ASSERT(aci
< AC_COUNT
);
1386 /* set the admission control policy for this AC */
1387 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1389 /* fill in shm ac params struct */
1390 acp_shm
.txop
= ltoh16(params
->txop
);
1391 /* convert from units of 32us to us for ucode */
1392 wlc
->edcf_txop
[aci
& 0x3] = acp_shm
.txop
=
1393 EDCF_TXOP2USEC(acp_shm
.txop
);
1394 acp_shm
.aifs
= (params
->aifs
& EDCF_AIFSN_MASK
);
1396 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1397 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1400 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1401 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1402 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1403 wlc
->pub
->unit
, acp_shm
.aifs
);
1407 acp_shm
.cwmin
= params
->cw_min
;
1408 acp_shm
.cwmax
= params
->cw_max
;
1409 acp_shm
.cwcur
= acp_shm
.cwmin
;
1411 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1412 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1413 /* Indicate the new params to the ucode */
1414 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1415 wme_shmemacindex(aci
) *
1417 M_EDCF_STATUS_OFF
));
1418 acp_shm
.status
|= WME_STATUS_NEWAC
;
1420 /* Fill in shm acparam table */
1421 shm_entry
= (u16
*) &acp_shm
;
1422 for (i
= 0; i
< (int)sizeof(shm_acparams_t
); i
+= 2)
1425 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ i
,
1431 wlc_suspend_mac_and_wait(wlc
);
1434 wlc_enable_mac(wlc
);
1438 void wlc_edcf_setparams(wlc_bsscfg_t
*cfg
, bool suspend
)
1440 struct wlc_info
*wlc
= cfg
->wlc
;
1442 edcf_acparam_t
*edcf_acp
;
1443 shm_acparams_t acp_shm
;
1449 /* Only apply params if the core is out of reset and has clocks */
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 wlc
->wme_admctl
= 0;
1463 for (i
= 0; i
< AC_COUNT
; i
++, edcf_acp
++) {
1464 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1465 /* find out which ac this set of params applies to */
1466 aci
= (edcf_acp
->ACI
& EDCF_ACI_MASK
) >> EDCF_ACI_SHIFT
;
1467 ASSERT(aci
< AC_COUNT
);
1468 /* set the admission control policy for this AC */
1469 if (edcf_acp
->ACI
& EDCF_ACM_MASK
) {
1470 wlc
->wme_admctl
|= 1 << aci
;
1473 /* fill in shm ac params struct */
1474 acp_shm
.txop
= ltoh16(edcf_acp
->TXOP
);
1475 /* convert from units of 32us to us for ucode */
1476 wlc
->edcf_txop
[aci
] = acp_shm
.txop
=
1477 EDCF_TXOP2USEC(acp_shm
.txop
);
1478 acp_shm
.aifs
= (edcf_acp
->ACI
& EDCF_AIFSN_MASK
);
1480 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1481 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1484 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1485 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1486 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1487 wlc
->pub
->unit
, acp_shm
.aifs
);
1491 /* CWmin = 2^(ECWmin) - 1 */
1492 acp_shm
.cwmin
= EDCF_ECW2CW(edcf_acp
->ECW
& EDCF_ECWMIN_MASK
);
1493 /* CWmax = 2^(ECWmax) - 1 */
1494 acp_shm
.cwmax
= EDCF_ECW2CW((edcf_acp
->ECW
& EDCF_ECWMAX_MASK
)
1495 >> EDCF_ECWMAX_SHIFT
);
1496 acp_shm
.cwcur
= acp_shm
.cwmin
;
1498 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1499 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1500 /* Indicate the new params to the ucode */
1501 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1502 wme_shmemacindex(aci
) *
1504 M_EDCF_STATUS_OFF
));
1505 acp_shm
.status
|= WME_STATUS_NEWAC
;
1507 /* Fill in shm acparam table */
1508 shm_entry
= (u16
*) &acp_shm
;
1509 for (j
= 0; j
< (int)sizeof(shm_acparams_t
); j
+= 2)
1512 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ j
,
1517 wlc_suspend_mac_and_wait(wlc
);
1519 if (AP_ENAB(wlc
->pub
) && WME_ENAB(wlc
->pub
)) {
1520 wlc_update_beacon(wlc
);
1521 wlc_update_probe_resp(wlc
, false);
1525 wlc_enable_mac(wlc
);
1529 bool wlc_timers_init(struct wlc_info
*wlc
, int unit
)
1531 wlc
->wdtimer
= wl_init_timer(wlc
->wl
, wlc_watchdog_by_timer
,
1533 if (!wlc
->wdtimer
) {
1534 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit
);
1538 wlc
->radio_timer
= wl_init_timer(wlc
->wl
, wlc_radio_timer
,
1540 if (!wlc
->radio_timer
) {
1541 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit
);
1552 * Initialize wlc_info default values ...
1553 * may get overrides later in this function
1555 void wlc_info_init(struct wlc_info
*wlc
, int unit
)
1558 /* Assume the device is there until proven otherwise */
1559 wlc
->device_present
= true;
1561 /* set default power output percentage to 100 percent */
1562 wlc
->txpwr_percent
= 100;
1564 /* Save our copy of the chanspec */
1565 wlc
->chanspec
= CH20MHZ_CHSPEC(1);
1567 /* initialize CCK preamble mode to unassociated state */
1568 wlc
->shortpreamble
= false;
1570 wlc
->legacy_probe
= true;
1572 /* various 802.11g modes */
1573 wlc
->shortslot
= false;
1574 wlc
->shortslot_override
= WLC_SHORTSLOT_AUTO
;
1576 wlc
->barker_overlap_control
= true;
1577 wlc
->barker_preamble
= WLC_BARKER_SHORT_ALLOWED
;
1578 wlc
->txburst_limit_override
= AUTO
;
1580 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, WLC_PROTECTION_AUTO
);
1581 wlc_protection_upd(wlc
, WLC_PROT_G_SPEC
, false);
1583 wlc_protection_upd(wlc
, WLC_PROT_N_CFG_OVR
, WLC_PROTECTION_AUTO
);
1584 wlc_protection_upd(wlc
, WLC_PROT_N_CFG
, WLC_N_PROTECTION_OFF
);
1585 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF_OVR
, WLC_PROTECTION_AUTO
);
1586 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF
, false);
1587 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
, AUTO
);
1589 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, WLC_PROTECTION_CTL_OVERLAP
);
1591 /* 802.11g draft 4.0 NonERP elt advertisement */
1592 wlc
->include_legacy_erp
= true;
1594 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_DEF
;
1595 wlc
->stf
->txant
= ANT_TX_DEF
;
1597 wlc
->prb_resp_timeout
= WLC_PRB_RESP_TIMEOUT
;
1599 wlc
->usr_fragthresh
= DOT11_DEFAULT_FRAG_LEN
;
1600 for (i
= 0; i
< NFIFO
; i
++)
1601 wlc
->fragthresh
[i
] = DOT11_DEFAULT_FRAG_LEN
;
1602 wlc
->RTSThresh
= DOT11_DEFAULT_RTS_LEN
;
1604 /* default rate fallback retry limits */
1605 wlc
->SFBL
= RETRY_SHORT_FB
;
1606 wlc
->LFBL
= RETRY_LONG_FB
;
1608 /* default mac retry limits */
1609 wlc
->SRL
= RETRY_SHORT_DEF
;
1610 wlc
->LRL
= RETRY_LONG_DEF
;
1613 wlc
->PM
= PM_OFF
; /* User's setting of PM mode through IOCTL */
1614 wlc
->PM_override
= false; /* Prevents from going to PM if our AP is 'ill' */
1615 wlc
->PMenabled
= false; /* Current PM state */
1616 wlc
->PMpending
= false; /* Tracks whether STA indicated PM in the last attempt */
1617 wlc
->PMblocked
= false; /* To allow blocking going into PM during RM and scans */
1619 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1620 wlc
->WME_PM_blocked
= false;
1622 /* Init wme queuing method */
1623 wlc
->wme_prec_queuing
= false;
1625 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1627 /* Are we waiting for a response to PS-Poll that we sent */
1628 wlc
->PSpoll
= false;
1631 wlc
->wme_apsd
= true;
1632 wlc
->apsd_sta_usp
= false;
1633 wlc
->apsd_trigger_timeout
= 0; /* disable the trigger timer */
1634 wlc
->apsd_trigger_ac
= AC_BITMAP_ALL
;
1636 /* Set flag to indicate that hw keys should be used when available. */
1637 wlc
->wsec_swkeys
= false;
1639 /* init the 4 static WEP default keys */
1640 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
1641 wlc
->wsec_keys
[i
] = wlc
->wsec_def_keys
[i
];
1642 wlc
->wsec_keys
[i
]->idx
= (u8
) i
;
1645 wlc
->_regulatory_domain
= false; /* 802.11d */
1647 /* WME QoS mode is Auto by default */
1648 wlc
->pub
->_wme
= AUTO
;
1650 #ifdef BCMSDIODEV_ENABLED
1651 wlc
->pub
->_priofc
= true; /* enable priority flow control for sdio dongle */
1654 wlc
->pub
->_ampdu
= AMPDU_AGG_HOST
;
1655 wlc
->pub
->bcmerror
= 0;
1656 wlc
->ibss_allowed
= true;
1657 wlc
->ibss_coalesce_allowed
= true;
1658 wlc
->pub
->_coex
= ON
;
1660 /* intialize mpc delay */
1661 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
1663 wlc
->pr80838_war
= true;
1666 static bool wlc_state_bmac_sync(struct wlc_info
*wlc
)
1668 wlc_bmac_state_t state_bmac
;
1670 if (wlc_bmac_state_get(wlc
->hw
, &state_bmac
) != 0)
1673 wlc
->machwcap
= state_bmac
.machwcap
;
1674 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
,
1675 (s8
) state_bmac
.preamble_ovr
);
1680 static uint
wlc_attach_module(struct wlc_info
*wlc
)
1684 unit
= wlc
->pub
->unit
;
1686 wlc
->asi
= wlc_antsel_attach(wlc
, wlc
->osh
, wlc
->pub
, wlc
->hw
);
1687 if (wlc
->asi
== NULL
) {
1688 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit
);
1693 wlc
->ampdu
= wlc_ampdu_attach(wlc
);
1694 if (wlc
->ampdu
== NULL
) {
1695 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit
);
1700 /* Initialize event queue; needed before following calls */
1702 wlc_eventq_attach(wlc
->pub
, wlc
, wlc
->wl
, wlc_process_eventq
);
1703 if (wlc
->eventq
== NULL
) {
1704 WL_ERROR("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit
);
1709 if ((wlc_stf_attach(wlc
) != 0)) {
1710 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit
);
1718 struct wlc_pub
*wlc_pub(void *wlc
)
1720 return ((struct wlc_info
*) wlc
)->pub
;
1723 #define CHIP_SUPPORTS_11N(wlc) 1
1726 * The common driver entry routine. Error codes should be unique
1728 void *wlc_attach(void *wl
, u16 vendor
, u16 device
, uint unit
, bool piomode
,
1729 struct osl_info
*osh
, void *regsva
, uint bustype
,
1730 void *btparam
, uint
*perr
)
1732 struct wlc_info
*wlc
;
1735 struct wlc_pub
*pub
;
1739 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1740 unit
, __func__
, vendor
, device
);
1742 ASSERT(WSEC_MAX_RCMTA_KEYS
<= WSEC_MAX_KEYS
);
1743 ASSERT(WSEC_MAX_DEFAULT_KEYS
== WLC_DEFAULT_KEYS
);
1745 /* some code depends on packed structures */
1746 ASSERT(sizeof(struct ethhdr
) == ETH_HLEN
);
1747 ASSERT(sizeof(d11regs_t
) == SI_CORE_SIZE
);
1748 ASSERT(sizeof(ofdm_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1749 ASSERT(sizeof(cck_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1750 ASSERT(sizeof(d11txh_t
) == D11_TXH_LEN
);
1751 ASSERT(sizeof(d11rxhdr_t
) == RXHDR_LEN
);
1752 ASSERT(sizeof(struct ieee80211_hdr
) == DOT11_A4_HDR_LEN
);
1753 ASSERT(sizeof(struct ieee80211_rts
) == DOT11_RTS_LEN
);
1754 ASSERT(sizeof(tx_status_t
) == TXSTATUS_LEN
);
1755 ASSERT(sizeof(struct ieee80211_ht_cap
) == HT_CAP_IE_LEN
);
1757 ASSERT(offsetof(wl_scan_params_t
, channel_list
) ==
1758 WL_SCAN_PARAMS_FIXED_SIZE
);
1760 ASSERT(IS_ALIGNED(offsetof(wsec_key_t
, data
), sizeof(u32
)));
1761 ASSERT(ISPOWEROF2(MA_WINDOW_SZ
));
1763 ASSERT(sizeof(wlc_d11rxhdr_t
) <= WL_HWRXOFF
);
1766 * Number of replay counters value used in WPA IE must match # rxivs
1767 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1768 * 'RSN Information Element' figure 8 for this mapping.
1770 ASSERT((WPA_CAP_16_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1771 && 16 == WLC_NUMRXIVS
)
1772 || (WPA_CAP_4_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1773 && 4 == WLC_NUMRXIVS
));
1775 /* allocate struct wlc_info state and its substructures */
1776 wlc
= (struct wlc_info
*) wlc_attach_malloc(osh
, unit
, &err
, device
);
1786 wlc
->band
= wlc
->bandstate
[0];
1787 wlc
->core
= wlc
->corestate
;
1791 wlc
->btparam
= btparam
;
1792 pub
->_piomode
= piomode
;
1793 wlc
->bandinit_pending
= false;
1794 /* By default restrict TKIP associations from 11n STA's */
1795 wlc
->ht_wsec_restriction
= WLC_HT_TKIP_RESTRICT
;
1797 /* populate struct wlc_info with default values */
1798 wlc_info_init(wlc
, unit
);
1800 /* update sta/ap related parameters */
1803 /* 11n_disable nvram */
1804 n_disabled
= getintvar(pub
->vars
, "11n_disable");
1806 /* register a module (to handle iovars) */
1807 wlc_module_register(wlc
->pub
, wlc_iovars
, "wlc_iovars", wlc
,
1808 wlc_doiovar
, NULL
, NULL
);
1810 /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */
1811 err
= wlc_bmac_attach(wlc
, vendor
, device
, unit
, piomode
, osh
, regsva
,
1816 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1817 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1819 if (!wlc_state_bmac_sync(wlc
)) {
1824 pub
->phy_11ncapable
= WLC_PHY_11N_CAP(wlc
->band
);
1826 /* propagate *vars* from BMAC driver to high driver */
1827 wlc_bmac_copyfrom_vars(wlc
->hw
, &pub
->vars
, &wlc
->vars_size
);
1830 /* set maximum allowed duty cycle */
1831 wlc
->tx_duty_cycle_ofdm
=
1832 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_ofdm");
1833 wlc
->tx_duty_cycle_cck
=
1834 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_cck");
1836 wlc_stf_phy_chain_calc(wlc
);
1838 /* txchain 1: txant 0, txchain 2: txant 1 */
1839 if (WLCISNPHY(wlc
->band
) && (wlc
->stf
->txstreams
== 1))
1840 wlc
->stf
->txant
= wlc
->stf
->hw_txchain
- 1;
1842 /* push to BMAC driver */
1843 wlc_phy_stf_chain_init(wlc
->band
->pi
, wlc
->stf
->hw_txchain
,
1844 wlc
->stf
->hw_rxchain
);
1846 /* pull up some info resulting from the low attach */
1849 for (i
= 0; i
< NFIFO
; i
++)
1850 wlc
->core
->txavail
[i
] = wlc
->hw
->txavail
[i
];
1853 wlc_bmac_hw_etheraddr(wlc
->hw
, wlc
->perm_etheraddr
);
1855 bcopy((char *)&wlc
->perm_etheraddr
, (char *)&pub
->cur_etheraddr
,
1858 for (j
= 0; j
< NBANDS(wlc
); j
++) {
1859 /* Use band 1 for single band 11a */
1860 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
1863 wlc
->band
= wlc
->bandstate
[j
];
1865 if (!wlc_attach_stf_ant_init(wlc
)) {
1870 /* default contention windows size limits */
1871 wlc
->band
->CWmin
= APHY_CWMIN
;
1872 wlc
->band
->CWmax
= PHY_CWMAX
;
1874 /* init gmode value */
1875 if (BAND_2G(wlc
->band
->bandtype
)) {
1876 wlc
->band
->gmode
= GMODE_AUTO
;
1877 wlc_protection_upd(wlc
, WLC_PROT_G_USER
,
1881 /* init _n_enab supported mode */
1882 if (WLC_PHY_11N_CAP(wlc
->band
) && CHIP_SUPPORTS_11N(wlc
)) {
1883 if (n_disabled
& WLFEATURE_DISABLE_11N
) {
1885 wlc_protection_upd(wlc
, WLC_PROT_N_USER
, OFF
);
1887 pub
->_n_enab
= SUPPORT_11N
;
1888 wlc_protection_upd(wlc
, WLC_PROT_N_USER
,
1890 SUPPORT_11N
) ? WL_11N_2x2
:
1895 /* init per-band default rateset, depend on band->gmode */
1896 wlc_default_rateset(wlc
, &wlc
->band
->defrateset
);
1898 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1899 wlc_rateset_filter(&wlc
->band
->defrateset
,
1900 &wlc
->band
->hw_rateset
, false,
1901 WLC_RATES_CCK_OFDM
, RATE_MASK
,
1902 (bool) N_ENAB(wlc
->pub
));
1905 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1906 wlc_stf_phy_txant_upd(wlc
);
1908 /* attach each modules */
1909 err
= wlc_attach_module(wlc
);
1913 if (!wlc_timers_init(wlc
, unit
)) {
1914 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit
, __func__
);
1919 /* depend on rateset, gmode */
1920 wlc
->cmi
= wlc_channel_mgr_attach(wlc
);
1922 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1928 /* init default when all parameters are ready, i.e. ->rateset */
1929 wlc_bss_default_init(wlc
);
1932 * Complete the wlc default state initializations..
1935 /* allocate our initial queue */
1936 qi
= wlc_txq_alloc(wlc
, osh
);
1938 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1943 wlc
->active_queue
= qi
;
1945 wlc
->bsscfg
[0] = wlc
->cfg
;
1947 wlc
->cfg
->wlc
= wlc
;
1948 pub
->txmaxpkts
= MAXTXPKTS
;
1950 WLCNTSET(pub
->_cnt
->version
, WL_CNT_T_VERSION
);
1951 WLCNTSET(pub
->_cnt
->length
, sizeof(wl_cnt_t
));
1953 WLCNTSET(pub
->_wme_cnt
->version
, WL_WME_CNT_VERSION
);
1954 WLCNTSET(pub
->_wme_cnt
->length
, sizeof(wl_wme_cnt_t
));
1956 wlc_wme_initparams_sta(wlc
, &wlc
->wme_param_ie
);
1958 wlc
->mimoft
= FT_HT
;
1959 wlc
->ht_cap
.cap_info
= HT_CAP
;
1960 if (HT_ENAB(wlc
->pub
))
1961 wlc
->stf
->ldpc
= AUTO
;
1963 wlc
->mimo_40txbw
= AUTO
;
1964 wlc
->ofdm_40txbw
= AUTO
;
1965 wlc
->cck_40txbw
= AUTO
;
1966 wlc_update_mimo_band_bwcap(wlc
, WLC_N_BW_20IN2G_40IN5G
);
1968 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1969 wlc
->rifs_advert
= AUTO
;
1971 /* Set default values of SGI */
1972 if (WLC_SGI_CAP_PHY(wlc
)) {
1973 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1975 } else if (WLCISSSLPNPHY(wlc
->band
)) {
1976 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1979 wlc_ht_update_sgi_rx(wlc
, 0);
1983 /* *******nvram 11n config overrides Start ********* */
1985 /* apply the sgi override from nvram conf */
1986 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_TX
)
1989 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_RX
)
1990 wlc_ht_update_sgi_rx(wlc
, 0);
1992 /* apply the stbc override from nvram conf */
1993 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_TX
) {
1994 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= OFF
;
1995 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= OFF
;
1996 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_TX_STBC
;
1998 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_RX
)
1999 wlc_stf_stbc_rx_set(wlc
, HT_CAP_RX_STBC_NO
);
2001 /* apply the GF override from nvram conf */
2002 if (n_disabled
& WLFEATURE_DISABLE_11N_GF
)
2003 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_GRN_FLD
;
2005 /* initialize radio_mpc_disable according to wlc->mpc */
2006 wlc_radio_mpc_upd(wlc
);
2008 if (WLANTSEL_ENAB(wlc
)) {
2009 if ((wlc
->pub
->sih
->chip
) == BCM43235_CHIP_ID
) {
2010 if ((getintvar(wlc
->pub
->vars
, "aa2g") == 7) ||
2011 (getintvar(wlc
->pub
->vars
, "aa5g") == 7)) {
2012 wlc_bmac_antsel_set(wlc
->hw
, 1);
2015 wlc_bmac_antsel_set(wlc
->hw
, wlc
->asi
->antsel_avail
);
2025 WL_ERROR("wl%d: %s: failed with err %d\n", unit
, __func__
, err
);
2034 static void wlc_attach_antgain_init(struct wlc_info
*wlc
)
2037 unit
= wlc
->pub
->unit
;
2039 if ((wlc
->band
->antgain
== -1) && (wlc
->pub
->sromrev
== 1)) {
2040 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2041 wlc
->band
->antgain
= 8;
2042 } else if (wlc
->band
->antgain
== -1) {
2043 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2045 wlc
->band
->antgain
= 8;
2048 /* Older sroms specified gain in whole dbm only. In order
2049 * be able to specify qdbm granularity and remain backward compatible
2050 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2051 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2052 * -32 - 31. Examples: 0x1 = 1 db,
2053 * 0xc1 = 1.75 db (1 + 3 quarters),
2054 * 0x3f = -1 (-1 + 0 quarters),
2055 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2056 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2058 gain
= wlc
->band
->antgain
& 0x3f;
2059 gain
<<= 2; /* Sign extend */
2061 fract
= (wlc
->band
->antgain
& 0xc0) >> 6;
2062 wlc
->band
->antgain
= 4 * gain
+ fract
;
2066 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
)
2073 unit
= wlc
->pub
->unit
;
2074 vars
= wlc
->pub
->vars
;
2075 bandtype
= wlc
->band
->bandtype
;
2077 /* get antennas available */
2078 aa
= (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "aa5g" : "aa2g"));
2080 aa
= (s8
) getintvar(vars
,
2081 (BAND_5G(bandtype
) ? "aa1" : "aa0"));
2082 if ((aa
< 1) || (aa
> 15)) {
2083 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2084 unit
, __func__
, aa
);
2088 /* reset the defaults if we have a single antenna */
2090 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_0
;
2091 wlc
->stf
->txant
= ANT_TX_FORCE_0
;
2092 } else if (aa
== 2) {
2093 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_1
;
2094 wlc
->stf
->txant
= ANT_TX_FORCE_1
;
2098 /* Compute Antenna Gain */
2099 wlc
->band
->antgain
=
2100 (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "ag1" : "ag0"));
2101 wlc_attach_antgain_init(wlc
);
2107 static void wlc_timers_deinit(struct wlc_info
*wlc
)
2109 /* free timer state */
2111 wl_free_timer(wlc
->wl
, wlc
->wdtimer
);
2112 wlc
->wdtimer
= NULL
;
2114 if (wlc
->radio_timer
) {
2115 wl_free_timer(wlc
->wl
, wlc
->radio_timer
);
2116 wlc
->radio_timer
= NULL
;
2120 static void wlc_detach_module(struct wlc_info
*wlc
)
2123 wlc_antsel_detach(wlc
->asi
);
2128 wlc_ampdu_detach(wlc
->ampdu
);
2132 wlc_stf_detach(wlc
);
2136 * Return a count of the number of driver callbacks still pending.
2138 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2139 * touch hardware registers since the d11core may be in reset and clock may not be available.
2140 * One exception is sb register access, which is possible if crystal is turned on
2141 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2143 uint
wlc_detach(struct wlc_info
*wlc
)
2151 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
2153 ASSERT(!wlc
->pub
->up
);
2155 callbacks
+= wlc_bmac_detach(wlc
);
2157 /* delete software timers */
2158 if (!wlc_radio_monitor_stop(wlc
))
2162 wlc_eventq_detach(wlc
->eventq
);
2166 wlc_channel_mgr_detach(wlc
->cmi
);
2168 wlc_timers_deinit(wlc
);
2170 wlc_detach_module(wlc
);
2172 /* free other state */
2176 if (wlc
->country_ie_override
) {
2177 kfree(wlc
->country_ie_override
);
2178 wlc
->country_ie_override
= NULL
;
2183 /* free dumpcb list */
2184 dumpcb_t
*prev
, *ptr
;
2185 prev
= ptr
= wlc
->dumpcb_head
;
2191 wlc
->dumpcb_head
= NULL
;
2194 /* Detach from iovar manager */
2195 wlc_module_unregister(wlc
->pub
, "wlc_iovars", wlc
);
2197 while (wlc
->tx_queues
!= NULL
) {
2198 wlc_txq_free(wlc
, wlc
->osh
, wlc
->tx_queues
);
2202 * consistency check: wlc_module_register/wlc_module_unregister calls
2203 * should match therefore nothing should be left here.
2205 for (i
= 0; i
< WLC_MAXMODULES
; i
++)
2206 ASSERT(wlc
->modulecb
[i
].name
[0] == '\0');
2208 wlc_detach_mfree(wlc
, wlc
->osh
);
2212 /* update state that depends on the current value of "ap" */
2213 void wlc_ap_upd(struct wlc_info
*wlc
)
2215 if (AP_ENAB(wlc
->pub
))
2216 wlc
->PLCPHdr_override
= WLC_PLCP_AUTO
; /* AP: short not allowed, but not enforced */
2218 wlc
->PLCPHdr_override
= WLC_PLCP_SHORT
; /* STA-BSS; short capable */
2220 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2221 wlc
->vlan_mode
= AP_ENAB(wlc
->pub
) ? OFF
: AUTO
;
2227 /* read hwdisable state and propagate to wlc flag */
2228 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
)
2230 if (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
|| wlc
->pub
->hw_off
)
2233 if (wlc_bmac_radio_read_hwdisabled(wlc
->hw
)) {
2234 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2236 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2240 /* return true if Minimum Power Consumption should be entered, false otherwise */
2241 bool wlc_is_non_delay_mpc(struct wlc_info
*wlc
)
2246 bool wlc_ismpc(struct wlc_info
*wlc
)
2248 return (wlc
->mpc_delay_off
== 0) && (wlc_is_non_delay_mpc(wlc
));
2251 void wlc_radio_mpc_upd(struct wlc_info
*wlc
)
2253 bool mpc_radio
, radio_state
;
2256 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2257 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2258 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2259 * the radio is going down.
2262 if (!wlc
->pub
->radio_disabled
)
2264 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2266 if (!wlc
->pub
->radio_disabled
)
2267 wlc_radio_monitor_stop(wlc
);
2272 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2273 * to go ON, always call radio_upd synchronously
2274 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2277 (mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
) ? OFF
:
2279 mpc_radio
= (wlc_ismpc(wlc
) == true) ? OFF
: ON
;
2281 if (radio_state
== ON
&& mpc_radio
== OFF
)
2282 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2283 else if (radio_state
== OFF
&& mpc_radio
== ON
) {
2284 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2286 if (wlc
->mpc_offcnt
< WLC_MPC_THRESHOLD
) {
2287 wlc
->mpc_dlycnt
= WLC_MPC_MAX_DELAYCNT
;
2289 wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
2290 wlc
->mpc_dur
+= OSL_SYSUPTIME() - wlc
->mpc_laston_ts
;
2292 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2293 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2294 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2296 if ((wlc
->prev_non_delay_mpc
== false) &&
2297 (wlc_is_non_delay_mpc(wlc
) == true) && wlc
->mpc_delay_off
) {
2298 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2300 wlc
->prev_non_delay_mpc
= wlc_is_non_delay_mpc(wlc
);
2304 * centralized radio disable/enable function,
2305 * invoke radio enable/disable after updating hwradio status
2307 static void wlc_radio_upd(struct wlc_info
*wlc
)
2311 /* maintain LED behavior in down state */
2312 static void wlc_down_led_upd(struct wlc_info
*wlc
)
2314 ASSERT(!wlc
->pub
->up
);
2316 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2317 /* turn on sbclk if necessary */
2318 if (!AP_ENAB(wlc
->pub
)) {
2319 wlc_pllreq(wlc
, true, WLC_PLLREQ_FLIP
);
2321 wlc_pllreq(wlc
, false, WLC_PLLREQ_FLIP
);
2325 /* update hwradio status and return it */
2326 bool wlc_check_radio_disabled(struct wlc_info
*wlc
)
2328 wlc_radio_hwdisable_upd(wlc
);
2330 return mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
) ? true : false;
2333 void wlc_radio_disable(struct wlc_info
*wlc
)
2335 if (!wlc
->pub
->up
) {
2336 wlc_down_led_upd(wlc
);
2340 wlc_radio_monitor_start(wlc
);
2344 static void wlc_radio_enable(struct wlc_info
*wlc
)
2349 if (DEVICEREMOVED(wlc
))
2352 if (!wlc
->down_override
) { /* imposed by wl down/out ioctl */
2357 /* periodical query hw radio button while driver is "down" */
2358 static void wlc_radio_timer(void *arg
)
2360 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2362 if (DEVICEREMOVED(wlc
)) {
2363 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2368 /* cap mpc off count */
2369 if (wlc
->mpc_offcnt
< WLC_MPC_MAX_DELAYCNT
)
2372 /* validate all the reasons driver could be down and running this radio_timer */
2373 ASSERT(wlc
->pub
->radio_disabled
|| wlc
->down_override
);
2374 wlc_radio_hwdisable_upd(wlc
);
2378 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
)
2380 /* Don't start the timer if HWRADIO feature is disabled */
2381 if (wlc
->radio_monitor
|| (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
))
2384 wlc
->radio_monitor
= true;
2385 wlc_pllreq(wlc
, true, WLC_PLLREQ_RADIO_MON
);
2386 wl_add_timer(wlc
->wl
, wlc
->radio_timer
, TIMER_INTERVAL_RADIOCHK
, true);
2390 bool wlc_radio_monitor_stop(struct wlc_info
*wlc
)
2392 if (!wlc
->radio_monitor
)
2395 ASSERT((wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
) !=
2398 wlc
->radio_monitor
= false;
2399 wlc_pllreq(wlc
, false, WLC_PLLREQ_RADIO_MON
);
2400 return wl_del_timer(wlc
->wl
, wlc
->radio_timer
);
2403 /* bring the driver down, but don't reset hardware */
2404 void wlc_out(struct wlc_info
*wlc
)
2406 wlc_bmac_set_noreset(wlc
->hw
, true);
2409 wlc_bmac_set_noreset(wlc
->hw
, false);
2411 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2414 /* This will make sure that when 'up' is done
2415 * after 'out' it'll restore hardware (especially gpios)
2417 wlc
->pub
->hw_up
= false;
2421 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2422 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2423 * in prec_map. Of course, ignore this rule when block_datafifo is set
2425 static bool wlc_tx_prec_map_verify(struct wlc_info
*wlc
)
2427 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2430 if (!EDCF_ENAB(wlc
->pub
)) {
2431 if (!(WLC_TX_FIFO_CHECK(wlc
, TX_DATA_FIFO
) ||
2432 WLC_TX_FIFO_CHECK(wlc
, TX_CTL_FIFO
)))
2438 return WLC_TX_FIFO_CHECK(wlc
, TX_AC_BK_FIFO
)
2439 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_BE_FIFO
)
2440 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VI_FIFO
)
2441 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VO_FIFO
);
2445 static void wlc_watchdog_by_timer(void *arg
)
2447 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2449 if (WLC_WATCHDOG_TBTT(wlc
)) {
2450 /* set to normal osl watchdog period */
2451 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
2452 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
2457 /* common watchdog code */
2458 static void wlc_watchdog(void *arg
)
2460 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2464 WL_TRACE("wl%d: wlc_watchdog\n", wlc
->pub
->unit
);
2469 if (DEVICEREMOVED(wlc
)) {
2470 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2475 /* increment second count */
2478 /* delay radio disable */
2479 if (wlc
->mpc_delay_off
) {
2480 if (--wlc
->mpc_delay_off
== 0) {
2481 mboolset(wlc
->pub
->radio_disabled
,
2482 WL_RADIO_MPC_DISABLE
);
2483 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2484 wlc
->mpc_offcnt
= 0;
2485 wlc
->mpc_laston_ts
= OSL_SYSUPTIME();
2490 wlc_radio_mpc_upd(wlc
);
2491 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2492 wlc_radio_hwdisable_upd(wlc
);
2494 /* if ismpc, driver should be in down state if up/down is allowed */
2495 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2496 ASSERT(!wlc
->pub
->up
);
2497 /* if radio is disable, driver may be down, quit here */
2498 if (wlc
->pub
->radio_disabled
)
2501 wlc_bmac_watchdog(wlc
);
2503 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2504 if ((WLC_UPDATE_STATS(wlc
))
2505 && (!(wlc
->pub
->now
% SW_TIMER_MAC_STAT_UPD
)))
2508 /* Manage TKIP countermeasures timers */
2509 FOREACH_BSS(wlc
, i
, cfg
) {
2510 if (cfg
->tk_cm_dt
) {
2513 if (cfg
->tk_cm_bt
) {
2518 /* Call any registered watchdog handlers */
2519 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2520 if (wlc
->modulecb
[i
].watchdog_fn
)
2521 wlc
->modulecb
[i
].watchdog_fn(wlc
->modulecb
[i
].hdl
);
2524 if (WLCISNPHY(wlc
->band
) && !wlc
->pub
->tempsense_disable
&&
2525 ((wlc
->pub
->now
- wlc
->tempsense_lasttime
) >=
2526 WLC_TEMPSENSE_PERIOD
)) {
2527 wlc
->tempsense_lasttime
= wlc
->pub
->now
;
2528 wlc_tempsense_upd(wlc
);
2530 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2531 ASSERT(wlc_bmac_taclear(wlc
->hw
, true));
2533 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2534 ASSERT(wlc_tx_prec_map_verify(wlc
));
2536 ASSERT(wlc_ps_check(wlc
));
2539 /* make interface operational */
2540 int wlc_up(struct wlc_info
*wlc
)
2542 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2544 /* HW is turned off so don't try to access it */
2545 if (wlc
->pub
->hw_off
|| DEVICEREMOVED(wlc
))
2546 return BCME_RADIOOFF
;
2548 if (!wlc
->pub
->hw_up
) {
2549 wlc_bmac_hw_up(wlc
->hw
);
2550 wlc
->pub
->hw_up
= true;
2553 if ((wlc
->pub
->boardflags
& BFL_FEM
)
2554 && (wlc
->pub
->sih
->chip
== BCM4313_CHIP_ID
)) {
2555 if (wlc
->pub
->boardrev
>= 0x1250
2556 && (wlc
->pub
->boardflags
& BFL_FEM_BT
)) {
2557 wlc_mhf(wlc
, MHF5
, MHF5_4313_GPIOCTRL
,
2558 MHF5_4313_GPIOCTRL
, WLC_BAND_ALL
);
2560 wlc_mhf(wlc
, MHF4
, MHF4_EXTPA_ENABLE
, MHF4_EXTPA_ENABLE
,
2566 * Need to read the hwradio status here to cover the case where the system
2567 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2568 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2569 * don't call radio_update to avoid looping wlc_up.
2571 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2573 if (!wlc
->pub
->radio_disabled
) {
2574 int status
= wlc_bmac_up_prep(wlc
->hw
);
2575 if (status
== BCME_RADIOOFF
) {
2577 (wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
)) {
2579 wlc_bsscfg_t
*bsscfg
;
2580 mboolset(wlc
->pub
->radio_disabled
,
2581 WL_RADIO_HW_DISABLE
);
2583 FOREACH_BSS(wlc
, idx
, bsscfg
) {
2584 if (!BSSCFG_STA(bsscfg
)
2585 || !bsscfg
->enable
|| !bsscfg
->BSS
)
2587 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2588 wlc
->pub
->unit
, idx
);
2595 if (wlc
->pub
->radio_disabled
) {
2596 wlc_radio_monitor_start(wlc
);
2600 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2603 wlc_radio_monitor_stop(wlc
);
2605 /* Set EDCF hostflags */
2606 if (EDCF_ENAB(wlc
->pub
)) {
2607 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, MHF1_EDCF
, WLC_BAND_ALL
);
2609 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, 0, WLC_BAND_ALL
);
2612 if (WLC_WAR16165(wlc
))
2613 wlc_mhf(wlc
, MHF2
, MHF2_PCISLOWCLKWAR
, MHF2_PCISLOWCLKWAR
,
2617 wlc
->pub
->up
= true;
2619 if (wlc
->bandinit_pending
) {
2620 wlc_suspend_mac_and_wait(wlc
);
2621 wlc_set_chanspec(wlc
, wlc
->default_bss
->chanspec
);
2622 wlc
->bandinit_pending
= false;
2623 wlc_enable_mac(wlc
);
2626 wlc_bmac_up_finish(wlc
->hw
);
2628 /* other software states up after ISR is running */
2629 /* start APs that were to be brought up but are not up yet */
2630 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2632 /* Program the TX wme params with the current settings */
2633 wlc_wme_retries_write(wlc
);
2635 /* start one second watchdog timer */
2636 ASSERT(!wlc
->WDarmed
);
2637 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
, true);
2638 wlc
->WDarmed
= true;
2640 /* ensure antenna config is up to date */
2641 wlc_stf_phy_txant_upd(wlc
);
2642 /* ensure LDPC config is in sync */
2643 wlc_ht_update_ldpc(wlc
, wlc
->stf
->ldpc
);
2648 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2649 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
)
2651 wlc
->tx_prec_map
= WLC_PREC_BMP_ALL
;
2652 memset(wlc
->fifo2prec_map
, 0, NFIFO
* sizeof(u16
));
2654 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2655 * if either is full.
2657 if (!EDCF_ENAB(wlc
->pub
)) {
2658 wlc
->fifo2prec_map
[TX_DATA_FIFO
] = WLC_PREC_BMP_ALL
;
2659 wlc
->fifo2prec_map
[TX_CTL_FIFO
] = WLC_PREC_BMP_ALL
;
2661 wlc
->fifo2prec_map
[TX_AC_BK_FIFO
] = WLC_PREC_BMP_AC_BK
;
2662 wlc
->fifo2prec_map
[TX_AC_BE_FIFO
] = WLC_PREC_BMP_AC_BE
;
2663 wlc
->fifo2prec_map
[TX_AC_VI_FIFO
] = WLC_PREC_BMP_AC_VI
;
2664 wlc
->fifo2prec_map
[TX_AC_VO_FIFO
] = WLC_PREC_BMP_AC_VO
;
2668 static uint
wlc_down_del_timer(struct wlc_info
*wlc
)
2676 * Mark the interface nonoperational, stop the software mechanisms,
2677 * disable the hardware, free any transient buffer state.
2678 * Return a count of the number of driver callbacks still pending.
2680 uint
wlc_down(struct wlc_info
*wlc
)
2685 bool dev_gone
= false;
2688 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2690 /* check if we are already in the going down path */
2691 if (wlc
->going_down
) {
2692 WL_ERROR("wl%d: %s: Driver going down so return\n",
2693 wlc
->pub
->unit
, __func__
);
2699 /* in between, mpc could try to bring down again.. */
2700 wlc
->going_down
= true;
2702 callbacks
+= wlc_bmac_down_prep(wlc
->hw
);
2704 dev_gone
= DEVICEREMOVED(wlc
);
2706 /* Call any registered down handlers */
2707 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2708 if (wlc
->modulecb
[i
].down_fn
)
2710 wlc
->modulecb
[i
].down_fn(wlc
->modulecb
[i
].hdl
);
2713 /* cancel the watchdog timer */
2715 if (!wl_del_timer(wlc
->wl
, wlc
->wdtimer
))
2717 wlc
->WDarmed
= false;
2719 /* cancel all other timers */
2720 callbacks
+= wlc_down_del_timer(wlc
);
2722 /* interrupt must have been blocked */
2723 ASSERT((wlc
->macintmask
== 0) || !wlc
->pub
->up
);
2725 wlc
->pub
->up
= false;
2727 wlc_phy_mute_upd(wlc
->band
->pi
, false, PHY_MUTE_ALL
);
2729 /* clear txq flow control */
2730 wlc_txflowcontrol_reset(wlc
);
2732 /* flush tx queues */
2733 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
2734 pktq_flush(wlc
->osh
, &qi
->q
, true, NULL
, 0);
2735 ASSERT(pktq_empty(&qi
->q
));
2738 /* flush event queue.
2739 * Should be the last thing done after all the events are generated
2740 * Just delivers the events synchronously instead of waiting for a timer
2742 callbacks
+= wlc_eventq_down(wlc
->eventq
);
2744 callbacks
+= wlc_bmac_down_finish(wlc
->hw
);
2746 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2750 /* Verify all packets are flushed from the driver */
2751 if (wlc
->osh
->pktalloced
!= 0) {
2752 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2753 wlc
->osh
->pktalloced
);
2756 /* Since all the packets should have been freed,
2757 * all callbacks should have been called
2759 for (i
= 1; i
<= wlc
->pub
->tunables
->maxpktcb
; i
++)
2760 ASSERT(wlc
->pkt_callback
[i
].fn
== NULL
);
2762 wlc
->going_down
= false;
2766 /* Set the current gmode configuration */
2767 int wlc_set_gmode(struct wlc_info
*wlc
, u8 gmode
, bool config
)
2772 /* Default to 54g Auto */
2773 s8 shortslot
= WLC_SHORTSLOT_AUTO
; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2774 bool shortslot_restrict
= false; /* Restrict association to stations that support shortslot
2776 bool ignore_bcns
= true; /* Ignore legacy beacons on the same channel */
2777 bool ofdm_basic
= false; /* Make 6, 12, and 24 basic rates */
2778 int preamble
= WLC_PLCP_LONG
; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2779 bool preamble_restrict
= false; /* Restrict association to stations that support short
2782 struct wlcband
*band
;
2784 /* if N-support is enabled, allow Gmode set as long as requested
2785 * Gmode is not GMODE_LEGACY_B
2787 if (N_ENAB(wlc
->pub
) && gmode
== GMODE_LEGACY_B
)
2788 return BCME_UNSUPPORTED
;
2790 /* verify that we are dealing with 2G band and grab the band pointer */
2791 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
2793 else if ((NBANDS(wlc
) > 1) &&
2794 (wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
== WLC_BAND_2G
))
2795 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
2797 return BCME_BADBAND
;
2799 /* Legacy or bust when no OFDM is supported by regulatory */
2800 if ((wlc_channel_locale_flags_in_band(wlc
->cmi
, band
->bandunit
) &
2801 WLC_NO_OFDM
) && (gmode
!= GMODE_LEGACY_B
))
2804 /* update configuration value */
2806 wlc_protection_upd(wlc
, WLC_PROT_G_USER
, gmode
);
2808 /* Clear supported rates filter */
2809 memset(&wlc
->sup_rates_override
, 0, sizeof(wlc_rateset_t
));
2811 /* Clear rateset override */
2812 memset(&rs
, 0, sizeof(wlc_rateset_t
));
2815 case GMODE_LEGACY_B
:
2816 shortslot
= WLC_SHORTSLOT_OFF
;
2817 wlc_rateset_copy(&gphy_legacy_rates
, &rs
);
2822 if (AP_ENAB(wlc
->pub
))
2823 wlc_rateset_copy(&cck_rates
, &wlc
->sup_rates_override
);
2827 /* Accept defaults */
2832 preamble
= WLC_PLCP_SHORT
;
2833 preamble_restrict
= true;
2836 case GMODE_PERFORMANCE
:
2837 if (AP_ENAB(wlc
->pub
)) /* Put all rates into the Supported Rates element */
2838 wlc_rateset_copy(&cck_ofdm_rates
,
2839 &wlc
->sup_rates_override
);
2841 shortslot
= WLC_SHORTSLOT_ON
;
2842 shortslot_restrict
= true;
2844 preamble
= WLC_PLCP_SHORT
;
2845 preamble_restrict
= true;
2850 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2851 wlc
->pub
->unit
, __func__
, gmode
);
2852 return BCME_UNSUPPORTED
;
2856 * If we are switching to gmode == GMODE_LEGACY_B,
2857 * clean up rate info that may refer to OFDM rates.
2859 if ((gmode
== GMODE_LEGACY_B
) && (band
->gmode
!= GMODE_LEGACY_B
)) {
2860 band
->gmode
= gmode
;
2861 if (band
->rspec_override
&& !IS_CCK(band
->rspec_override
)) {
2862 band
->rspec_override
= 0;
2863 wlc_reprate_init(wlc
);
2865 if (band
->mrspec_override
&& !IS_CCK(band
->mrspec_override
)) {
2866 band
->mrspec_override
= 0;
2870 band
->gmode
= gmode
;
2872 wlc
->ignore_bcns
= ignore_bcns
;
2874 wlc
->shortslot_override
= shortslot
;
2876 if (AP_ENAB(wlc
->pub
)) {
2877 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2878 wlc
->PLCPHdr_override
=
2880 WLC_PLCP_LONG
) ? WLC_PLCP_SHORT
: WLC_PLCP_AUTO
;
2883 if ((AP_ENAB(wlc
->pub
) && preamble
!= WLC_PLCP_LONG
)
2884 || preamble
== WLC_PLCP_SHORT
)
2885 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
2887 wlc
->default_bss
->capability
&= ~WLAN_CAPABILITY_SHORT_PREAMBLE
;
2889 /* Update shortslot capability bit for AP and IBSS */
2890 if ((AP_ENAB(wlc
->pub
) && shortslot
== WLC_SHORTSLOT_AUTO
) ||
2891 shortslot
== WLC_SHORTSLOT_ON
)
2892 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2894 wlc
->default_bss
->capability
&=
2895 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2897 /* Use the default 11g rateset */
2899 wlc_rateset_copy(&cck_ofdm_rates
, &rs
);
2902 for (i
= 0; i
< rs
.count
; i
++) {
2903 if (rs
.rates
[i
] == WLC_RATE_6M
2904 || rs
.rates
[i
] == WLC_RATE_12M
2905 || rs
.rates
[i
] == WLC_RATE_24M
)
2906 rs
.rates
[i
] |= WLC_RATE_FLAG
;
2910 /* Set default bss rateset */
2911 wlc
->default_bss
->rateset
.count
= rs
.count
;
2912 bcopy((char *)rs
.rates
, (char *)wlc
->default_bss
->rateset
.rates
,
2913 sizeof(wlc
->default_bss
->rateset
.rates
));
2918 static int wlc_nmode_validate(struct wlc_info
*wlc
, s32 nmode
)
2930 if (!(WLC_PHY_11N_CAP(wlc
->band
)))
2942 int wlc_set_nmode(struct wlc_info
*wlc
, s32 nmode
)
2947 err
= wlc_nmode_validate(wlc
, nmode
);
2954 wlc
->pub
->_n_enab
= OFF
;
2955 wlc
->default_bss
->flags
&= ~WLC_BSS_HT
;
2956 /* delete the mcs rates from the default and hw ratesets */
2957 wlc_rateset_mcs_clear(&wlc
->default_bss
->rateset
);
2958 for (i
= 0; i
< NBANDS(wlc
); i
++) {
2959 memset(wlc
->bandstate
[i
]->hw_rateset
.mcs
, 0,
2961 if (IS_MCS(wlc
->band
->rspec_override
)) {
2962 wlc
->bandstate
[i
]->rspec_override
= 0;
2963 wlc_reprate_init(wlc
);
2965 if (IS_MCS(wlc
->band
->mrspec_override
))
2966 wlc
->bandstate
[i
]->mrspec_override
= 0;
2971 if (wlc
->stf
->txstreams
== WL_11N_3x3
)
2977 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
2978 /* force GMODE_AUTO if NMODE is ON */
2979 wlc_set_gmode(wlc
, GMODE_AUTO
, true);
2980 if (nmode
== WL_11N_3x3
)
2981 wlc
->pub
->_n_enab
= SUPPORT_HT
;
2983 wlc
->pub
->_n_enab
= SUPPORT_11N
;
2984 wlc
->default_bss
->flags
|= WLC_BSS_HT
;
2985 /* add the mcs rates to the default and hw ratesets */
2986 wlc_rateset_mcs_build(&wlc
->default_bss
->rateset
,
2987 wlc
->stf
->txstreams
);
2988 for (i
= 0; i
< NBANDS(wlc
); i
++)
2989 memcpy(wlc
->bandstate
[i
]->hw_rateset
.mcs
,
2990 wlc
->default_bss
->rateset
.mcs
, MCSSET_LEN
);
3001 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
)
3003 wlc_rateset_t rs
, new;
3006 bcopy((char *)rs_arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
3008 /* check for bad count value */
3009 if ((rs
.count
== 0) || (rs
.count
> WLC_NUMRATES
))
3010 return BCME_BADRATESET
;
3012 /* try the current band */
3013 bandunit
= wlc
->band
->bandunit
;
3014 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3015 if (wlc_rate_hwrs_filter_sort_validate
3016 (&new, &wlc
->bandstate
[bandunit
]->hw_rateset
, true,
3017 wlc
->stf
->txstreams
))
3020 /* try the other band */
3021 if (IS_MBAND_UNLOCKED(wlc
)) {
3022 bandunit
= OTHERBANDUNIT(wlc
);
3023 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3024 if (wlc_rate_hwrs_filter_sort_validate(&new,
3026 bandstate
[bandunit
]->
3028 wlc
->stf
->txstreams
))
3035 /* apply new rateset */
3036 bcopy((char *)&new, (char *)&wlc
->default_bss
->rateset
,
3037 sizeof(wlc_rateset_t
));
3038 bcopy((char *)&new, (char *)&wlc
->bandstate
[bandunit
]->defrateset
,
3039 sizeof(wlc_rateset_t
));
3043 /* simplified integer set interface for common ioctl handler */
3044 int wlc_set(struct wlc_info
*wlc
, int cmd
, int arg
)
3046 return wlc_ioctl(wlc
, cmd
, (void *)&arg
, sizeof(arg
), NULL
);
3049 /* simplified integer get interface for common ioctl handler */
3050 int wlc_get(struct wlc_info
*wlc
, int cmd
, int *arg
)
3052 return wlc_ioctl(wlc
, cmd
, arg
, sizeof(int), NULL
);
3055 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
)
3060 if (wlc
->cfg
->associated
)
3061 r
= wlc
->cfg
->current_bss
->rateset
.rates
[0];
3063 r
= wlc
->default_bss
->rateset
.rates
[0];
3065 wlc_phy_ofdm_rateset_war(wlc
->band
->pi
, war
);
3071 wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3072 struct wlc_if
*wlcif
)
3074 return _wlc_ioctl(wlc
, cmd
, arg
, len
, wlcif
);
3077 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3079 _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3080 struct wlc_if
*wlcif
)
3087 struct scb
*nextscb
;
3091 wlc_bsscfg_t
*bsscfg
;
3092 struct osl_info
*osh
;
3093 wlc_bss_info_t
*current_bss
;
3095 /* update bsscfg pointer */
3096 bsscfg
= NULL
; /* XXX: Hack bsscfg to be size one and use this globally */
3099 /* initialize the following to get rid of compiler warning */
3105 /* If the device is turned off, then it's not "removed" */
3106 if (!wlc
->pub
->hw_off
&& DEVICEREMOVED(wlc
)) {
3107 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
3112 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
3114 /* default argument is generic integer */
3115 pval
= arg
? (int *)arg
:NULL
;
3117 /* This will prevent the misaligned access */
3118 if (pval
&& (u32
) len
>= sizeof(val
))
3119 bcopy(pval
, &val
, sizeof(val
));
3123 /* bool conversion to avoid duplication below */
3124 bool_val
= val
!= 0;
3126 if (cmd
!= WLC_SET_CHANNEL
)
3127 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3128 cmd
, (uint
)val
, val
, len
);
3134 /* A few commands don't need any arguments; all the others do. */
3142 case WLC_START_CHANNEL_QA
:
3147 if ((arg
== NULL
) || (len
<= 0)) {
3148 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3149 wlc
->pub
->unit
, __func__
, cmd
);
3150 bcmerror
= BCME_BADARG
;
3158 case WLC_GET_MSGLEVEL
:
3159 *pval
= wl_msg_level
;
3162 case WLC_SET_MSGLEVEL
:
3167 case WLC_GET_INSTANCE
:
3168 *pval
= wlc
->pub
->unit
;
3171 case WLC_GET_CHANNEL
:{
3172 channel_info_t
*ci
= (channel_info_t
*) arg
;
3174 ASSERT(len
> (int)sizeof(ci
));
3177 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
);
3178 ci
->target_channel
=
3179 CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
);
3180 ci
->scan_channel
= 0;
3185 case WLC_SET_CHANNEL
:{
3186 chanspec_t chspec
= CH20MHZ_CHSPEC(val
);
3188 if (val
< 0 || val
> MAXCHANNEL
) {
3189 bcmerror
= BCME_OUTOFRANGECHAN
;
3193 if (!wlc_valid_chanspec_db(wlc
->cmi
, chspec
)) {
3194 bcmerror
= BCME_BADCHAN
;
3198 if (!wlc
->pub
->up
&& IS_MBAND_UNLOCKED(wlc
)) {
3199 if (wlc
->band
->bandunit
!=
3200 CHSPEC_WLCBANDUNIT(chspec
))
3201 wlc
->bandinit_pending
= true;
3203 wlc
->bandinit_pending
= false;
3206 wlc
->default_bss
->chanspec
= chspec
;
3207 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3208 if (wlc
->pub
->up
&& !wlc
->pub
->associated
&&
3209 (WLC_BAND_PI_RADIO_CHANSPEC
!= chspec
)) {
3210 wlc_set_home_chanspec(wlc
, chspec
);
3211 wlc_suspend_mac_and_wait(wlc
);
3212 wlc_set_chanspec(wlc
, chspec
);
3213 wlc_enable_mac(wlc
);
3219 case WLC_GET_UCFLAGS
:
3220 if (!wlc
->pub
->up
) {
3221 bcmerror
= BCME_NOTUP
;
3225 /* optional band is stored in the second integer of incoming buffer */
3228 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3230 /* bcmerror checking */
3231 bcmerror
= wlc_iocregchk(wlc
, band
);
3235 if (val
>= MHFMAX
) {
3236 bcmerror
= BCME_RANGE
;
3240 *pval
= wlc_bmac_mhf_get(wlc
->hw
, (u8
) val
, WLC_BAND_AUTO
);
3243 case WLC_SET_UCFLAGS
:
3244 if (!wlc
->pub
->up
) {
3245 bcmerror
= BCME_NOTUP
;
3249 /* optional band is stored in the second integer of incoming buffer */
3252 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3254 /* bcmerror checking */
3255 bcmerror
= wlc_iocregchk(wlc
, band
);
3261 bcmerror
= BCME_RANGE
;
3265 wlc_mhf(wlc
, (u8
) i
, 0xffff, (u16
) (val
>> NBITS(u16
)),
3272 /* optional band is stored in the second integer of incoming buffer */
3275 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3277 /* bcmerror checking */
3278 bcmerror
= wlc_iocregchk(wlc
, band
);
3283 bcmerror
= BCME_BADADDR
;
3287 *pval
= wlc_read_shm(wlc
, (u16
) val
);
3293 /* optional band is stored in the second integer of incoming buffer */
3296 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3298 /* bcmerror checking */
3299 bcmerror
= wlc_iocregchk(wlc
, band
);
3304 bcmerror
= BCME_BADADDR
;
3308 wlc_write_shm(wlc
, (u16
) val
,
3309 (u16
) (val
>> NBITS(u16
)));
3312 case WLC_R_REG
: /* MAC registers */
3314 r
= (rw_reg_t
*) arg
;
3315 band
= WLC_BAND_AUTO
;
3317 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3318 bcmerror
= BCME_BUFTOOSHORT
;
3322 if (len
>= (int)sizeof(rw_reg_t
))
3325 /* bcmerror checking */
3326 bcmerror
= wlc_iocregchk(wlc
, band
);
3330 if ((r
->byteoff
+ r
->size
) > sizeof(d11regs_t
)) {
3331 bcmerror
= BCME_BADADDR
;
3334 if (r
->size
== sizeof(u32
))
3337 (u32
*)((unsigned char *)(unsigned long)regs
+
3339 else if (r
->size
== sizeof(u16
))
3342 (u16
*)((unsigned char *)(unsigned long)regs
+
3345 bcmerror
= BCME_BADADDR
;
3350 r
= (rw_reg_t
*) arg
;
3351 band
= WLC_BAND_AUTO
;
3353 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3354 bcmerror
= BCME_BUFTOOSHORT
;
3358 if (len
>= (int)sizeof(rw_reg_t
))
3361 /* bcmerror checking */
3362 bcmerror
= wlc_iocregchk(wlc
, band
);
3366 if (r
->byteoff
+ r
->size
> sizeof(d11regs_t
)) {
3367 bcmerror
= BCME_BADADDR
;
3370 if (r
->size
== sizeof(u32
))
3372 (u32
*)((unsigned char *)(unsigned long) regs
+
3373 r
->byteoff
), r
->val
);
3374 else if (r
->size
== sizeof(u16
))
3376 (u16
*)((unsigned char *)(unsigned long) regs
+
3377 r
->byteoff
), r
->val
);
3379 bcmerror
= BCME_BADADDR
;
3384 *pval
= wlc
->stf
->txant
;
3388 bcmerror
= wlc_stf_ant_txant_validate(wlc
, (s8
) val
);
3392 wlc
->stf
->txant
= (s8
) val
;
3394 /* if down, we are done */
3398 wlc_suspend_mac_and_wait(wlc
);
3400 wlc_stf_phy_txant_upd(wlc
);
3401 wlc_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
3403 wlc_enable_mac(wlc
);
3407 case WLC_GET_ANTDIV
:{
3410 /* return configured value if core is down */
3411 if (!wlc
->pub
->up
) {
3412 *pval
= wlc
->stf
->ant_rx_ovr
;
3415 if (wlc_phy_ant_rxdiv_get
3416 (wlc
->band
->pi
, &phy_antdiv
))
3417 *pval
= (int)phy_antdiv
;
3419 *pval
= (int)wlc
->stf
->ant_rx_ovr
;
3424 case WLC_SET_ANTDIV
:
3425 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3426 if ((val
< -1) || (val
> 3)) {
3427 bcmerror
= BCME_RANGE
;
3432 val
= ANT_RX_DIV_DEF
;
3434 wlc
->stf
->ant_rx_ovr
= (u8
) val
;
3435 wlc_phy_ant_rxdiv_set(wlc
->band
->pi
, (u8
) val
);
3438 case WLC_GET_RX_ANT
:{ /* get latest used rx antenna */
3441 if (!wlc
->pub
->up
) {
3442 bcmerror
= BCME_NOTUP
;
3446 rxstatus
= R_REG(wlc
->osh
, &wlc
->regs
->phyrxstatus0
);
3447 if (rxstatus
== 0xdead || rxstatus
== (u16
) -1) {
3448 bcmerror
= BCME_ERROR
;
3451 *pval
= (rxstatus
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0;
3456 case WLC_GET_UCANTDIV
:
3458 bcmerror
= BCME_NOCLK
;
3463 (wlc_bmac_mhf_get(wlc
->hw
, MHF1
, WLC_BAND_AUTO
) &
3467 case WLC_SET_UCANTDIV
:{
3468 if (!wlc
->pub
->up
) {
3469 bcmerror
= BCME_NOTUP
;
3473 /* if multiband, band must be locked */
3474 if (IS_MBAND_UNLOCKED(wlc
)) {
3475 bcmerror
= BCME_NOTBANDLOCKED
;
3479 /* 4322 supports antdiv in phy, no need to set it to ucode */
3480 if (WLCISNPHY(wlc
->band
)
3481 && D11REV_IS(wlc
->pub
->corerev
, 16)) {
3482 WL_ERROR("wl%d: can't set ucantdiv for 4322\n",
3484 bcmerror
= BCME_UNSUPPORTED
;
3486 wlc_mhf(wlc
, MHF1
, MHF1_ANTDIV
,
3487 (val
? MHF1_ANTDIV
: 0), WLC_BAND_AUTO
);
3490 #endif /* defined(BCMDBG) */
3497 if (val
>= 1 && val
<= RETRY_SHORT_MAX
) {
3499 wlc
->SRL
= (u16
) val
;
3501 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3503 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3504 WLC_WME_RETRY_SHORT_SET(wlc
, ac
, wlc
->SRL
);
3506 wlc_wme_retries_write(wlc
);
3508 bcmerror
= BCME_RANGE
;
3516 if (val
>= 1 && val
<= 255) {
3518 wlc
->LRL
= (u16
) val
;
3520 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3522 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3523 WLC_WME_RETRY_LONG_SET(wlc
, ac
, wlc
->LRL
);
3525 wlc_wme_retries_write(wlc
);
3527 bcmerror
= BCME_RANGE
;
3531 *pval
= wlc
->band
->CWmin
;
3536 bcmerror
= BCME_NOCLK
;
3540 if (val
>= 1 && val
<= 255) {
3541 wlc_set_cwmin(wlc
, (u16
) val
);
3543 bcmerror
= BCME_RANGE
;
3547 *pval
= wlc
->band
->CWmax
;
3552 bcmerror
= BCME_NOCLK
;
3556 if (val
>= 255 && val
<= 2047) {
3557 wlc_set_cwmax(wlc
, (u16
) val
);
3559 bcmerror
= BCME_RANGE
;
3562 case WLC_GET_RADIO
: /* use mask if don't want to expose some internal bits */
3563 *pval
= wlc
->pub
->radio_disabled
;
3566 case WLC_SET_RADIO
:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3569 u16 radiomask
, radioval
;
3571 WL_RADIO_SW_DISABLE
| WL_RADIO_HW_DISABLE
;
3574 radiomask
= (val
& 0xffff0000) >> 16;
3575 radioval
= val
& 0x0000ffff;
3577 if ((radiomask
== 0) || (radiomask
& ~validbits
)
3578 || (radioval
& ~validbits
)
3579 || ((radioval
& ~radiomask
) != 0)) {
3580 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3582 bcmerror
= BCME_RANGE
;
3587 (wlc
->pub
->radio_disabled
& ~radiomask
) | radioval
;
3588 wlc
->pub
->radio_disabled
= new;
3590 wlc_radio_hwdisable_upd(wlc
);
3595 case WLC_GET_PHYTYPE
:
3596 *pval
= WLC_PHYTYPE(wlc
->band
->phytype
);
3601 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
))) {
3604 wsec_key_t
*src_key
= wlc
->wsec_keys
[val
];
3606 if (len
< (int)sizeof(key
)) {
3607 bcmerror
= BCME_BUFTOOSHORT
;
3611 memset((char *)&key
, 0, sizeof(key
));
3613 key
.index
= src_key
->id
;
3614 key
.len
= src_key
->len
;
3615 bcopy(src_key
->data
, key
.data
, key
.len
);
3616 key
.algo
= src_key
->algo
;
3617 if (WSEC_SOFTKEY(wlc
, src_key
, bsscfg
))
3618 key
.flags
|= WL_SOFT_KEY
;
3619 if (src_key
->flags
& WSEC_PRIMARY_KEY
)
3620 key
.flags
|= WL_PRIMARY_KEY
;
3622 bcopy(src_key
->ea
, key
.ea
,
3626 bcopy((char *)&key
, arg
, sizeof(key
));
3628 bcmerror
= BCME_BADKEYIDX
;
3630 #endif /* defined(BCMDBG) */
3634 wlc_iovar_op(wlc
, "wsec_key", NULL
, 0, arg
, len
, IOV_SET
,
3638 case WLC_GET_KEY_SEQ
:{
3641 if (len
< DOT11_WPA_KEY_RSC_LEN
) {
3642 bcmerror
= BCME_BUFTOOSHORT
;
3646 /* Return the key's tx iv as an EAPOL sequence counter.
3647 * This will be used to supply the RSC value to a supplicant.
3648 * The format is 8 bytes, with least significant in seq[0].
3651 key
= WSEC_KEY(wlc
, val
);
3652 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
)) &&
3654 u8 seq
[DOT11_WPA_KEY_RSC_LEN
];
3657 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3658 if ((bsscfg
->WPA_auth
& WPA_AUTH_NONE
) &&
3659 is_zero_ether_addr(key
->ea
)) {
3660 lo
= bsscfg
->wpa_none_txiv
.lo
;
3661 hi
= bsscfg
->wpa_none_txiv
.hi
;
3667 /* format the buffer, low to high */
3669 seq
[1] = (lo
>> 8) & 0xff;
3671 seq
[3] = (hi
>> 8) & 0xff;
3672 seq
[4] = (hi
>> 16) & 0xff;
3673 seq
[5] = (hi
>> 24) & 0xff;
3677 bcopy((char *)seq
, arg
, sizeof(seq
));
3679 bcmerror
= BCME_BADKEYIDX
;
3684 case WLC_GET_CURR_RATESET
:{
3685 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3688 if (bsscfg
->associated
)
3689 rs
= ¤t_bss
->rateset
;
3691 rs
= &wlc
->default_bss
->rateset
;
3693 if (len
< (int)(rs
->count
+ sizeof(rs
->count
))) {
3694 bcmerror
= BCME_BUFTOOSHORT
;
3698 /* Copy only legacy rateset section */
3699 ret_rs
->count
= rs
->count
;
3700 bcopy(&rs
->rates
, &ret_rs
->rates
, rs
->count
);
3704 case WLC_GET_RATESET
:{
3706 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3708 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3709 wlc_default_rateset(wlc
, (wlc_rateset_t
*) &rs
);
3711 if (len
< (int)(rs
.count
+ sizeof(rs
.count
))) {
3712 bcmerror
= BCME_BUFTOOSHORT
;
3716 /* Copy only legacy rateset section */
3717 ret_rs
->count
= rs
.count
;
3718 bcopy(&rs
.rates
, &ret_rs
->rates
, rs
.count
);
3722 case WLC_SET_RATESET
:{
3724 wl_rateset_t
*in_rs
= (wl_rateset_t
*) arg
;
3726 if (len
< (int)(in_rs
->count
+ sizeof(in_rs
->count
))) {
3727 bcmerror
= BCME_BUFTOOSHORT
;
3731 if (in_rs
->count
> WLC_NUMRATES
) {
3732 bcmerror
= BCME_BUFTOOLONG
;
3736 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3738 /* Copy only legacy rateset section */
3739 rs
.count
= in_rs
->count
;
3740 bcopy(&in_rs
->rates
, &rs
.rates
, rs
.count
);
3742 /* merge rateset coming in with the current mcsset */
3743 if (N_ENAB(wlc
->pub
)) {
3744 if (bsscfg
->associated
)
3745 bcopy(¤t_bss
->rateset
.mcs
[0],
3746 rs
.mcs
, MCSSET_LEN
);
3748 bcopy(&wlc
->default_bss
->rateset
.mcs
[0],
3749 rs
.mcs
, MCSSET_LEN
);
3752 bcmerror
= wlc_set_rateset(wlc
, &rs
);
3755 wlc_ofdm_rateset_war(wlc
);
3760 case WLC_GET_BCNPRD
:
3761 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3762 *pval
= current_bss
->beacon_period
;
3764 *pval
= wlc
->default_bss
->beacon_period
;
3767 case WLC_SET_BCNPRD
:
3768 /* range [1, 0xffff] */
3769 if (val
>= DOT11_MIN_BEACON_PERIOD
3770 && val
<= DOT11_MAX_BEACON_PERIOD
) {
3771 wlc
->default_bss
->beacon_period
= (u16
) val
;
3773 bcmerror
= BCME_RANGE
;
3776 case WLC_GET_DTIMPRD
:
3777 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3778 *pval
= current_bss
->dtim_period
;
3780 *pval
= wlc
->default_bss
->dtim_period
;
3783 case WLC_SET_DTIMPRD
:
3784 /* range [1, 0xff] */
3785 if (val
>= DOT11_MIN_DTIM_PERIOD
3786 && val
<= DOT11_MAX_DTIM_PERIOD
) {
3787 wlc
->default_bss
->dtim_period
= (u8
) val
;
3789 bcmerror
= BCME_RANGE
;
3798 if ((val
>= PM_OFF
) && (val
<= PM_MAX
)) {
3802 /* Change watchdog driver to align watchdog with tbtt if possible */
3803 wlc_watchdog_upd(wlc
, PS_ALLOWED(wlc
));
3805 bcmerror
= BCME_ERROR
;
3807 #endif /* SUPPORT_PS */
3812 if (AP_ENAB(wlc
->pub
)) {
3813 bcmerror
= BCME_NOTSTA
;
3820 if (AP_ENAB(wlc
->pub
)) {
3821 bcmerror
= BCME_NOTSTA
;
3825 wlc
->wake
= val
? true : false;
3827 /* if down, we're done */
3831 /* apply to the mac */
3832 wlc_set_ps_ctrl(wlc
);
3835 #endif /* SUPPORT_PS */
3837 case WLC_GET_REVINFO
:
3838 bcmerror
= wlc_get_revision_info(wlc
, arg
, (uint
) len
);
3842 *pval
= (int)AP_ENAB(wlc
->pub
);
3846 if (bsscfg
->associated
)
3847 *pval
= (int)current_bss
->atim_window
;
3849 *pval
= (int)wlc
->default_bss
->atim_window
;
3853 wlc
->default_bss
->atim_window
= (u32
) val
;
3856 case WLC_GET_PKTCNTS
:{
3857 get_pktcnt_t
*pktcnt
= (get_pktcnt_t
*) pval
;
3858 if (WLC_UPDATE_STATS(wlc
))
3860 pktcnt
->rx_good_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxframe
);
3861 pktcnt
->rx_bad_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxerror
);
3862 pktcnt
->tx_good_pkt
=
3863 WLCNTVAL(wlc
->pub
->_cnt
->txfrmsnt
);
3864 pktcnt
->tx_bad_pkt
=
3865 WLCNTVAL(wlc
->pub
->_cnt
->txerror
) +
3866 WLCNTVAL(wlc
->pub
->_cnt
->txfail
);
3867 if (len
>= (int)sizeof(get_pktcnt_t
)) {
3868 /* Be backward compatible - only if buffer is large enough */
3869 pktcnt
->rx_ocast_good_pkt
=
3870 WLCNTVAL(wlc
->pub
->_cnt
->rxmfrmocast
);
3875 #ifdef SUPPORT_HWKEY
3878 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_GET
,
3884 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_SET
,
3888 case WLC_GET_WPA_AUTH
:
3889 *pval
= (int)bsscfg
->WPA_auth
;
3892 case WLC_SET_WPA_AUTH
:
3893 /* change of WPA_Auth modifies the PS_ALLOWED state */
3894 if (BSSCFG_STA(bsscfg
)) {
3895 bsscfg
->WPA_auth
= (u16
) val
;
3897 bsscfg
->WPA_auth
= (u16
) val
;
3899 #endif /* SUPPORT_HWKEY */
3901 case WLC_GET_BANDLIST
:
3902 /* count of number of bands, followed by each band type */
3903 *pval
++ = NBANDS(wlc
);
3904 *pval
++ = wlc
->band
->bandtype
;
3905 if (NBANDS(wlc
) > 1)
3906 *pval
++ = wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
;
3910 *pval
= wlc
->bandlocked
? wlc
->band
->bandtype
: WLC_BAND_AUTO
;
3913 case WLC_GET_PHYLIST
:
3915 unsigned char *cp
= arg
;
3917 bcmerror
= BCME_BUFTOOSHORT
;
3921 if (WLCISNPHY(wlc
->band
)) {
3923 } else if (WLCISLCNPHY(wlc
->band
)) {
3925 } else if (WLCISSSLPNPHY(wlc
->band
)) {
3932 case WLC_GET_SHORTSLOT
:
3933 *pval
= wlc
->shortslot
;
3936 case WLC_GET_SHORTSLOT_OVERRIDE
:
3937 *pval
= wlc
->shortslot_override
;
3940 case WLC_SET_SHORTSLOT_OVERRIDE
:
3941 if ((val
!= WLC_SHORTSLOT_AUTO
) &&
3942 (val
!= WLC_SHORTSLOT_OFF
) && (val
!= WLC_SHORTSLOT_ON
)) {
3943 bcmerror
= BCME_RANGE
;
3947 wlc
->shortslot_override
= (s8
) val
;
3949 /* shortslot is an 11g feature, so no more work if we are
3950 * currently on the 5G band
3952 if (BAND_5G(wlc
->band
->bandtype
))
3955 if (wlc
->pub
->up
&& wlc
->pub
->associated
) {
3956 /* let watchdog or beacon processing update shortslot */
3957 } else if (wlc
->pub
->up
) {
3958 /* unassociated shortslot is off */
3959 wlc_switch_shortslot(wlc
, false);
3961 /* driver is down, so just update the wlc_info value */
3962 if (wlc
->shortslot_override
== WLC_SHORTSLOT_AUTO
) {
3963 wlc
->shortslot
= false;
3966 (wlc
->shortslot_override
==
3973 case WLC_GET_LEGACY_ERP
:
3974 *pval
= wlc
->include_legacy_erp
;
3977 case WLC_SET_LEGACY_ERP
:
3978 if (wlc
->include_legacy_erp
== bool_val
)
3981 wlc
->include_legacy_erp
= bool_val
;
3983 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
3984 wlc_update_beacon(wlc
);
3985 wlc_update_probe_resp(wlc
, true);
3990 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
3991 *pval
= wlc
->band
->gmode
;
3992 else if (NBANDS(wlc
) > 1)
3993 *pval
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
;
3997 if (!wlc
->pub
->associated
)
3998 bcmerror
= wlc_set_gmode(wlc
, (u8
) val
, true);
4000 bcmerror
= BCME_ASSOCIATED
;
4005 case WLC_GET_GMODE_PROTECTION
:
4006 *pval
= wlc
->protection
->_g
;
4009 case WLC_GET_PROTECTION_CONTROL
:
4010 *pval
= wlc
->protection
->overlap
;
4013 case WLC_SET_PROTECTION_CONTROL
:
4014 if ((val
!= WLC_PROTECTION_CTL_OFF
) &&
4015 (val
!= WLC_PROTECTION_CTL_LOCAL
) &&
4016 (val
!= WLC_PROTECTION_CTL_OVERLAP
)) {
4017 bcmerror
= BCME_RANGE
;
4021 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, (s8
) val
);
4023 /* Current g_protection will sync up to the specified control alg in watchdog
4024 * if the driver is up and associated.
4025 * If the driver is down or not associated, the control setting has no effect.
4029 case WLC_GET_GMODE_PROTECTION_OVERRIDE
:
4030 *pval
= wlc
->protection
->g_override
;
4033 case WLC_SET_GMODE_PROTECTION_OVERRIDE
:
4034 if ((val
!= WLC_PROTECTION_AUTO
) &&
4035 (val
!= WLC_PROTECTION_OFF
) && (val
!= WLC_PROTECTION_ON
)) {
4036 bcmerror
= BCME_RANGE
;
4040 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, (s8
) val
);
4044 case WLC_SET_SUP_RATESET_OVERRIDE
:{
4045 wlc_rateset_t rs
, new;
4048 if (len
< (int)sizeof(wlc_rateset_t
)) {
4049 bcmerror
= BCME_BUFTOOSHORT
;
4052 bcopy((char *)arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
4054 /* check for bad count value */
4055 if (rs
.count
> WLC_NUMRATES
) {
4056 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4060 /* this command is only appropriate for gmode operation */
4061 if (!(wlc
->band
->gmode
||
4063 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4064 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4068 /* check for an empty rateset to clear the override */
4069 if (rs
.count
== 0) {
4070 memset(&wlc
->sup_rates_override
, 0,
4071 sizeof(wlc_rateset_t
));
4075 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4076 wlc_rateset_filter(&rs
, &new, false, WLC_RATES_CCK_OFDM
,
4077 RATE_MASK
, BSS_N_ENAB(wlc
, bsscfg
));
4078 wlc_rate_hwrs_filter_sort_validate(&new,
4081 wlc
->stf
->txstreams
);
4082 if (rs
.count
!= new.count
) {
4083 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4087 /* apply new rateset to the override */
4088 bcopy((char *)&new, (char *)&wlc
->sup_rates_override
,
4089 sizeof(wlc_rateset_t
));
4091 /* update bcn and probe resp if needed */
4092 if (wlc
->pub
->up
&& AP_ENAB(wlc
->pub
)
4093 && wlc
->pub
->associated
) {
4094 wlc_update_beacon(wlc
);
4095 wlc_update_probe_resp(wlc
, true);
4100 case WLC_GET_SUP_RATESET_OVERRIDE
:
4101 /* this command is only appropriate for gmode operation */
4102 if (!(wlc
->band
->gmode
||
4104 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4105 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4108 if (len
< (int)sizeof(wlc_rateset_t
)) {
4109 bcmerror
= BCME_BUFTOOSHORT
;
4112 bcopy((char *)&wlc
->sup_rates_override
, (char *)arg
,
4113 sizeof(wlc_rateset_t
));
4117 case WLC_GET_PRB_RESP_TIMEOUT
:
4118 *pval
= wlc
->prb_resp_timeout
;
4121 case WLC_SET_PRB_RESP_TIMEOUT
:
4123 bcmerror
= BCME_NOTDOWN
;
4126 if (val
< 0 || val
>= 0xFFFF) {
4127 bcmerror
= BCME_RANGE
; /* bad value */
4130 wlc
->prb_resp_timeout
= (u16
) val
;
4133 case WLC_GET_KEY_PRIMARY
:{
4136 /* treat the 'val' parm as the key id */
4137 key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4139 *pval
= key
->id
== val
? true : false;
4141 bcmerror
= BCME_BADKEYIDX
;
4146 case WLC_SET_KEY_PRIMARY
:{
4147 wsec_key_t
*key
, *old_key
;
4149 bcmerror
= BCME_BADKEYIDX
;
4151 /* treat the 'val' parm as the key id */
4152 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
4153 key
= bsscfg
->bss_def_keys
[i
];
4154 if (key
!= NULL
&& key
->id
== val
) {
4155 old_key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4156 if (old_key
!= NULL
)
4159 key
->flags
|= WSEC_PRIMARY_KEY
;
4160 bsscfg
->wsec_index
= i
;
4176 /* validate the name value */
4178 for (i
= 0; i
< (uint
) len
&& *name
!= '\0';
4182 if (i
== (uint
) len
) {
4183 bcmerror
= BCME_BUFTOOSHORT
;
4186 i
++; /* include the null in the string length */
4188 if (cmd
== WLC_GET_VAR
) {
4190 wlc_iovar_op(wlc
, arg
,
4191 (void *)((s8
*) arg
+ i
),
4192 len
- i
, arg
, len
, IOV_GET
,
4196 wlc_iovar_op(wlc
, arg
, NULL
, 0,
4197 (void *)((s8
*) arg
+ i
),
4198 len
- i
, IOV_SET
, wlcif
);
4203 case WLC_SET_WSEC_PMK
:
4204 bcmerror
= BCME_UNSUPPORTED
;
4208 case WLC_CURRENT_PWR
:
4210 bcmerror
= BCME_NOTUP
;
4212 bcmerror
= wlc_get_current_txpwr(wlc
, arg
, len
);
4217 WL_ERROR("%s: WLC_LAST\n", __func__
);
4222 if (VALID_BCMERROR(bcmerror
))
4223 wlc
->pub
->bcmerror
= bcmerror
;
4229 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4230 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4231 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4233 if (!(wlc
->pub
->hw_off
))
4234 ASSERT(wlc_bmac_taclear(wlc
->hw
, ta_ok
) || !ta_ok
);
4240 /* consolidated register access ioctl error checking */
4241 int wlc_iocregchk(struct wlc_info
*wlc
, uint band
)
4243 /* if band is specified, it must be the current band */
4244 if ((band
!= WLC_BAND_AUTO
) && (band
!= (uint
) wlc
->band
->bandtype
))
4245 return BCME_BADBAND
;
4247 /* if multiband and band is not specified, band must be locked */
4248 if ((band
== WLC_BAND_AUTO
) && IS_MBAND_UNLOCKED(wlc
))
4249 return BCME_NOTBANDLOCKED
;
4251 /* must have core clocks */
4257 #endif /* defined(BCMDBG) */
4260 /* For some ioctls, make sure that the pi pointer matches the current phy */
4261 int wlc_iocpichk(struct wlc_info
*wlc
, uint phytype
)
4263 if (wlc
->band
->phytype
!= phytype
)
4264 return BCME_BADBAND
;
4269 /* Look up the given var name in the given table */
4270 static const bcm_iovar_t
*wlc_iovar_lookup(const bcm_iovar_t
*table
,
4273 const bcm_iovar_t
*vi
;
4274 const char *lookup_name
;
4276 /* skip any ':' delimited option prefixes */
4277 lookup_name
= strrchr(name
, ':');
4278 if (lookup_name
!= NULL
)
4283 ASSERT(table
!= NULL
);
4285 for (vi
= table
; vi
->name
; vi
++) {
4286 if (!strcmp(vi
->name
, lookup_name
))
4289 /* ran to end of table */
4291 return NULL
; /* var name not found */
4294 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4295 int wlc_iovar_getint(struct wlc_info
*wlc
, const char *name
, int *arg
)
4297 return wlc_iovar_op(wlc
, name
, NULL
, 0, arg
, sizeof(s32
), IOV_GET
,
4301 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4302 int wlc_iovar_setint(struct wlc_info
*wlc
, const char *name
, int arg
)
4304 return wlc_iovar_op(wlc
, name
, NULL
, 0, (void *)&arg
, sizeof(arg
),
4308 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4309 int wlc_iovar_gets8(struct wlc_info
*wlc
, const char *name
, s8
*arg
)
4315 wlc_iovar_op(wlc
, name
, NULL
, 0, &iovar_int
, sizeof(iovar_int
),
4318 *arg
= (s8
) iovar_int
;
4324 * register iovar table, watchdog and down handlers.
4325 * calling function must keep 'iovars' until wlc_module_unregister is called.
4326 * 'iovar' must have the last entry's name field being NULL as terminator.
4328 int wlc_module_register(struct wlc_pub
*pub
, const bcm_iovar_t
*iovars
,
4329 const char *name
, void *hdl
, iovar_fn_t i_fn
,
4330 watchdog_fn_t w_fn
, down_fn_t d_fn
)
4332 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4335 ASSERT(name
!= NULL
);
4336 ASSERT(i_fn
!= NULL
|| w_fn
!= NULL
|| d_fn
!= NULL
);
4338 /* find an empty entry and just add, no duplication check! */
4339 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4340 if (wlc
->modulecb
[i
].name
[0] == '\0') {
4341 strncpy(wlc
->modulecb
[i
].name
, name
,
4342 sizeof(wlc
->modulecb
[i
].name
) - 1);
4343 wlc
->modulecb
[i
].iovars
= iovars
;
4344 wlc
->modulecb
[i
].hdl
= hdl
;
4345 wlc
->modulecb
[i
].iovar_fn
= i_fn
;
4346 wlc
->modulecb
[i
].watchdog_fn
= w_fn
;
4347 wlc
->modulecb
[i
].down_fn
= d_fn
;
4352 /* it is time to increase the capacity */
4353 ASSERT(i
< WLC_MAXMODULES
);
4354 return BCME_NORESOURCE
;
4357 /* unregister module callbacks */
4358 int wlc_module_unregister(struct wlc_pub
*pub
, const char *name
, void *hdl
)
4360 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4364 return BCME_NOTFOUND
;
4366 ASSERT(name
!= NULL
);
4368 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4369 if (!strcmp(wlc
->modulecb
[i
].name
, name
) &&
4370 (wlc
->modulecb
[i
].hdl
== hdl
)) {
4371 memset(&wlc
->modulecb
[i
], 0, sizeof(modulecb_t
));
4376 /* table not found! */
4377 return BCME_NOTFOUND
;
4380 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4381 static void wlc_wme_retries_write(struct wlc_info
*wlc
)
4385 /* Need clock to do this */
4389 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
4390 wlc_write_shm(wlc
, M_AC_TXLMT_ADDR(ac
), wlc
->wme_retries
[ac
]);
4394 /* Get or set an iovar. The params/p_len pair specifies any additional
4395 * qualifying parameters (e.g. an "element index") for a get, while the
4396 * arg/len pair is the buffer for the value to be set or retrieved.
4397 * Operation (get/set) is specified by the last argument.
4398 * interface context provided by wlcif
4400 * All pointers may point into the same buffer.
4403 wlc_iovar_op(struct wlc_info
*wlc
, const char *name
,
4404 void *params
, int p_len
, void *arg
, int len
,
4405 bool set
, struct wlc_if
*wlcif
)
4409 const bcm_iovar_t
*vi
= NULL
;
4413 ASSERT(name
!= NULL
);
4417 /* Get MUST have return space */
4418 ASSERT(set
|| (arg
&& len
));
4420 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
4422 /* Set does NOT take qualifiers */
4423 ASSERT(!set
|| (!params
&& !p_len
));
4425 if (!set
&& (len
== sizeof(int)) &&
4426 !(IS_ALIGNED((unsigned long)(arg
), (uint
) sizeof(int)))) {
4427 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4428 wlc
->pub
->unit
, __func__
, name
);
4432 /* find the given iovar name */
4433 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4434 if (!wlc
->modulecb
[i
].iovars
)
4436 vi
= wlc_iovar_lookup(wlc
->modulecb
[i
].iovars
, name
);
4440 /* iovar name not found */
4441 if (i
>= WLC_MAXMODULES
) {
4442 err
= BCME_UNSUPPORTED
;
4446 /* set up 'params' pointer in case this is a set command so that
4447 * the convenience int and bool code can be common to set and get
4449 if (params
== NULL
) {
4454 if (vi
->type
== IOVT_VOID
)
4456 else if (vi
->type
== IOVT_BUFFER
)
4459 /* all other types are integer sized */
4460 val_size
= sizeof(int);
4462 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
4464 /* Do the actual parameter implementation */
4465 err
= wlc
->modulecb
[i
].iovar_fn(wlc
->modulecb
[i
].hdl
, vi
, actionid
,
4466 name
, params
, p_len
, arg
, len
, val_size
,
4474 wlc_iovar_check(struct wlc_pub
*pub
, const bcm_iovar_t
*vi
, void *arg
, int len
,
4477 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4481 /* check generic condition flags */
4483 if (((vi
->flags
& IOVF_SET_DOWN
) && wlc
->pub
->up
) ||
4484 ((vi
->flags
& IOVF_SET_UP
) && !wlc
->pub
->up
)) {
4485 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4486 } else if ((vi
->flags
& IOVF_SET_BAND
)
4487 && IS_MBAND_UNLOCKED(wlc
)) {
4488 err
= BCME_NOTBANDLOCKED
;
4489 } else if ((vi
->flags
& IOVF_SET_CLK
) && !wlc
->clk
) {
4493 if (((vi
->flags
& IOVF_GET_DOWN
) && wlc
->pub
->up
) ||
4494 ((vi
->flags
& IOVF_GET_UP
) && !wlc
->pub
->up
)) {
4495 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4496 } else if ((vi
->flags
& IOVF_GET_BAND
)
4497 && IS_MBAND_UNLOCKED(wlc
)) {
4498 err
= BCME_NOTBANDLOCKED
;
4499 } else if ((vi
->flags
& IOVF_GET_CLK
) && !wlc
->clk
) {
4507 /* length check on io buf */
4508 err
= bcm_iovar_lencheck(vi
, arg
, len
, set
);
4512 /* On set, check value ranges for integer types */
4522 bcopy(arg
, &int_val
, sizeof(int));
4523 err
= wlc_iovar_rangecheck(wlc
, int_val
, vi
);
4531 /* handler for iovar table wlc_iovars */
4533 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4534 * iovar case, the switch statement maps the iovar id into separate get
4535 * and set values. If you add a new iovar to the switch you MUST use
4536 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4538 * Please use params for additional qualifying parameters.
4541 wlc_doiovar(void *hdl
, const bcm_iovar_t
*vi
, u32 actionid
,
4542 const char *name
, void *params
, uint p_len
, void *arg
, int len
,
4543 int val_size
, struct wlc_if
*wlcif
)
4545 struct wlc_info
*wlc
= hdl
;
4546 wlc_bsscfg_t
*bsscfg
;
4553 wlc_bss_info_t
*current_bss
;
4555 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
4560 err
= wlc_iovar_check(wlc
->pub
, vi
, arg
, len
, IOV_ISSET(actionid
));
4564 /* convenience int and bool vals for first 8 bytes of buffer */
4565 if (p_len
>= (int)sizeof(int_val
))
4566 bcopy(params
, &int_val
, sizeof(int_val
));
4568 if (p_len
>= (int)sizeof(int_val
) * 2)
4569 bcopy((void *)((unsigned long)params
+ sizeof(int_val
)), &int_val2
,
4572 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4573 ret_int_ptr
= (s32
*) arg
;
4575 bool_val
= (int_val
!= 0) ? true : false;
4576 bool_val2
= (int_val2
!= 0) ? true : false;
4578 WL_TRACE("wl%d: %s: id %d\n",
4579 wlc
->pub
->unit
, __func__
, IOV_ID(actionid
));
4580 /* Do the actual parameter implementation */
4582 case IOV_SVAL(IOV_RTSTHRESH
):
4583 wlc
->RTSThresh
= int_val
;
4586 case IOV_GVAL(IOV_QTXPOWER
):{
4590 err
= wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
,
4595 /* Return qdbm units */
4597 qdbm
| (override
? WL_TXPWR_OVERRIDE
: 0);
4601 /* As long as override is false, this only sets the *user* targets.
4602 User can twiddle this all he wants with no harm.
4603 wlc_phy_txpower_set() explicitly sets override to false if
4604 not internal or test.
4606 case IOV_SVAL(IOV_QTXPOWER
):{
4610 /* Remove override bit and clip to max qdbm value */
4611 qdbm
= (u8
)min_t(u32
, (int_val
& ~WL_TXPWR_OVERRIDE
), 0xff);
4612 /* Extract override setting */
4613 override
= (int_val
& WL_TXPWR_OVERRIDE
) ? true : false;
4615 wlc_phy_txpower_set(wlc
->band
->pi
, qdbm
, override
);
4619 case IOV_GVAL(IOV_MPC
):
4620 *ret_int_ptr
= (s32
) wlc
->mpc
;
4623 case IOV_SVAL(IOV_MPC
):
4624 wlc
->mpc
= bool_val
;
4625 wlc_radio_mpc_upd(wlc
);
4629 case IOV_GVAL(IOV_BCN_LI_BCN
):
4630 *ret_int_ptr
= wlc
->bcn_li_bcn
;
4633 case IOV_SVAL(IOV_BCN_LI_BCN
):
4634 wlc
->bcn_li_bcn
= (u8
) int_val
;
4636 wlc_bcn_li_upd(wlc
);
4640 WL_ERROR("wl%d: %s: unsupported\n", wlc
->pub
->unit
, __func__
);
4641 err
= BCME_UNSUPPORTED
;
4645 goto exit
; /* avoid unused label warning */
4652 wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
, const bcm_iovar_t
*vi
)
4658 /* Only ranged integers are checked */
4661 max_val
|= 0x7fffffff;
4664 max_val
|= 0x00007fff;
4667 max_val
|= 0x0000007f;
4669 if (vi
->flags
& IOVF_NTRL
)
4671 else if (vi
->flags
& IOVF_WHL
)
4673 /* Signed values are checked against max_val and min_val */
4674 if ((s32
) val
< (s32
) min_val
4675 || (s32
) val
> (s32
) max_val
)
4680 max_val
|= 0xffffffff;
4683 max_val
|= 0x0000ffff;
4686 max_val
|= 0x000000ff;
4687 if (vi
->flags
& IOVF_NTRL
)
4689 if ((val
< min_val
) || (val
> max_val
))
4698 static const char *supr_reason
[] = {
4699 "None", "PMQ Entry", "Flush request",
4700 "Previous frag failure", "Channel mismatch",
4701 "Lifetime Expiry", "Underflow"
4704 static void wlc_print_txs_status(u16 s
)
4706 printf("[15:12] %d frame attempts\n", (s
& TX_STATUS_FRM_RTX_MASK
) >>
4707 TX_STATUS_FRM_RTX_SHIFT
);
4708 printf(" [11:8] %d rts attempts\n", (s
& TX_STATUS_RTS_RTX_MASK
) >>
4709 TX_STATUS_RTS_RTX_SHIFT
);
4710 printf(" [7] %d PM mode indicated\n",
4711 ((s
& TX_STATUS_PMINDCTD
) ? 1 : 0));
4712 printf(" [6] %d intermediate status\n",
4713 ((s
& TX_STATUS_INTERMEDIATE
) ? 1 : 0));
4714 printf(" [5] %d AMPDU\n", (s
& TX_STATUS_AMPDU
) ? 1 : 0);
4715 printf(" [4:2] %d Frame Suppressed Reason (%s)\n",
4716 ((s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
),
4717 supr_reason
[(s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
]);
4718 printf(" [1] %d acked\n", ((s
& TX_STATUS_ACK_RCV
) ? 1 : 0));
4722 void wlc_print_txstatus(tx_status_t
*txs
)
4725 u16 s
= txs
->status
;
4726 u16 ackphyrxsh
= txs
->ackphyrxsh
;
4728 printf("\ntxpkt (MPDU) Complete\n");
4730 printf("FrameID: %04x ", txs
->frameid
);
4731 printf("TxStatus: %04x", s
);
4734 wlc_print_txs_status(s
);
4736 printf("LastTxTime: %04x ", txs
->lasttxtime
);
4737 printf("Seq: %04x ", txs
->sequence
);
4738 printf("PHYTxStatus: %04x ", txs
->phyerr
);
4739 printf("RxAckRSSI: %04x ",
4740 (ackphyrxsh
& PRXS1_JSSI_MASK
) >> PRXS1_JSSI_SHIFT
);
4741 printf("RxAckSQ: %04x", (ackphyrxsh
& PRXS1_SQ_MASK
) >> PRXS1_SQ_SHIFT
);
4743 #endif /* defined(BCMDBG) */
4746 #define MACSTATUPD(name) \
4747 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4749 void wlc_statsupd(struct wlc_info
*wlc
)
4758 /* if driver down, make no sense to update stats */
4763 /* save last rx fifo 0 overflow count */
4764 rxf0ovfl
= wlc
->core
->macstat_snapshot
->rxf0ovfl
;
4766 /* save last tx fifo underflow count */
4767 for (i
= 0; i
< NFIFO
; i
++)
4768 txfunfl
[i
] = wlc
->core
->macstat_snapshot
->txfunfl
[i
];
4772 /* check for rx fifo 0 overflow */
4773 delta
= (u16
) (wlc
->core
->macstat_snapshot
->rxf0ovfl
- rxf0ovfl
);
4775 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4776 wlc
->pub
->unit
, delta
);
4778 /* check for tx fifo underflows */
4779 for (i
= 0; i
< NFIFO
; i
++) {
4781 (u16
) (wlc
->core
->macstat_snapshot
->txfunfl
[i
] -
4784 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4785 wlc
->pub
->unit
, delta
, i
);
4789 /* dot11 counter update */
4791 WLCNTSET(wlc
->pub
->_cnt
->txrts
,
4792 (wlc
->pub
->_cnt
->rxctsucast
-
4793 wlc
->pub
->_cnt
->d11cnt_txrts_off
));
4794 WLCNTSET(wlc
->pub
->_cnt
->rxcrc
,
4795 (wlc
->pub
->_cnt
->rxbadfcs
- wlc
->pub
->_cnt
->d11cnt_rxcrc_off
));
4796 WLCNTSET(wlc
->pub
->_cnt
->txnocts
,
4797 ((wlc
->pub
->_cnt
->txrtsfrm
- wlc
->pub
->_cnt
->rxctsucast
) -
4798 wlc
->pub
->_cnt
->d11cnt_txnocts_off
));
4800 /* merge counters from dma module */
4801 for (i
= 0; i
< NFIFO
; i
++) {
4802 if (wlc
->hw
->di
[i
]) {
4803 WLCNTADD(wlc
->pub
->_cnt
->txnobuf
,
4804 (wlc
->hw
->di
[i
])->txnobuf
);
4805 WLCNTADD(wlc
->pub
->_cnt
->rxnobuf
,
4806 (wlc
->hw
->di
[i
])->rxnobuf
);
4807 WLCNTADD(wlc
->pub
->_cnt
->rxgiant
,
4808 (wlc
->hw
->di
[i
])->rxgiants
);
4809 dma_counterreset(wlc
->hw
->di
[i
]);
4814 * Aggregate transmit and receive errors that probably resulted
4815 * in the loss of a frame are computed on the fly.
4817 WLCNTSET(wlc
->pub
->_cnt
->txerror
,
4818 wlc
->pub
->_cnt
->txnobuf
+ wlc
->pub
->_cnt
->txnoassoc
+
4819 wlc
->pub
->_cnt
->txuflo
+ wlc
->pub
->_cnt
->txrunt
+
4820 wlc
->pub
->_cnt
->dmade
+ wlc
->pub
->_cnt
->dmada
+
4821 wlc
->pub
->_cnt
->dmape
);
4822 WLCNTSET(wlc
->pub
->_cnt
->rxerror
,
4823 wlc
->pub
->_cnt
->rxoflo
+ wlc
->pub
->_cnt
->rxnobuf
+
4824 wlc
->pub
->_cnt
->rxfragerr
+ wlc
->pub
->_cnt
->rxrunt
+
4825 wlc
->pub
->_cnt
->rxgiant
+ wlc
->pub
->_cnt
->rxnoscb
+
4826 wlc
->pub
->_cnt
->rxbadsrcmac
);
4827 for (i
= 0; i
< NFIFO
; i
++)
4828 WLCNTADD(wlc
->pub
->_cnt
->rxerror
, wlc
->pub
->_cnt
->rxuflo
[i
]);
4831 bool wlc_chipmatch(u16 vendor
, u16 device
)
4833 if (vendor
!= VENDOR_BROADCOM
) {
4834 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor
);
4838 if ((device
== BCM43224_D11N_ID
) || (device
== BCM43225_D11N2G_ID
))
4841 if (device
== BCM4313_D11N2G_ID
)
4843 if ((device
== BCM43236_D11N_ID
) || (device
== BCM43236_D11N2G_ID
))
4846 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device
);
4851 void wlc_print_txdesc(d11txh_t
*txh
)
4853 u16 mtcl
= ltoh16(txh
->MacTxControlLow
);
4854 u16 mtch
= ltoh16(txh
->MacTxControlHigh
);
4855 u16 mfc
= ltoh16(txh
->MacFrameControl
);
4856 u16 tfest
= ltoh16(txh
->TxFesTimeNormal
);
4857 u16 ptcw
= ltoh16(txh
->PhyTxControlWord
);
4858 u16 ptcw_1
= ltoh16(txh
->PhyTxControlWord_1
);
4859 u16 ptcw_1_Fbr
= ltoh16(txh
->PhyTxControlWord_1_Fbr
);
4860 u16 ptcw_1_Rts
= ltoh16(txh
->PhyTxControlWord_1_Rts
);
4861 u16 ptcw_1_FbrRts
= ltoh16(txh
->PhyTxControlWord_1_FbrRts
);
4862 u16 mainrates
= ltoh16(txh
->MainRates
);
4863 u16 xtraft
= ltoh16(txh
->XtraFrameTypes
);
4865 u8
*ra
= txh
->TxFrameRA
;
4866 u16 tfestfb
= ltoh16(txh
->TxFesTimeFallback
);
4867 u8
*rtspfb
= txh
->RTSPLCPFallback
;
4868 u16 rtsdfb
= ltoh16(txh
->RTSDurFallback
);
4869 u8
*fragpfb
= txh
->FragPLCPFallback
;
4870 u16 fragdfb
= ltoh16(txh
->FragDurFallback
);
4871 u16 mmodelen
= ltoh16(txh
->MModeLen
);
4872 u16 mmodefbrlen
= ltoh16(txh
->MModeFbrLen
);
4873 u16 tfid
= ltoh16(txh
->TxFrameID
);
4874 u16 txs
= ltoh16(txh
->TxStatus
);
4875 u16 mnmpdu
= ltoh16(txh
->MaxNMpdus
);
4876 u16 mabyte
= ltoh16(txh
->MaxABytes_MRT
);
4877 u16 mabyte_f
= ltoh16(txh
->MaxABytes_FBR
);
4878 u16 mmbyte
= ltoh16(txh
->MinMBytes
);
4880 u8
*rtsph
= txh
->RTSPhyHeader
;
4881 struct ieee80211_rts rts
= txh
->rts_frame
;
4884 /* add plcp header along with txh descriptor */
4885 prhex("Raw TxDesc + plcp header", (unsigned char *) txh
, sizeof(d11txh_t
) + 48);
4887 printf("TxCtlLow: %04x ", mtcl
);
4888 printf("TxCtlHigh: %04x ", mtch
);
4889 printf("FC: %04x ", mfc
);
4890 printf("FES Time: %04x\n", tfest
);
4891 printf("PhyCtl: %04x%s ", ptcw
,
4892 (ptcw
& PHY_TXC_SHORT_HDR
) ? " short" : "");
4893 printf("PhyCtl_1: %04x ", ptcw_1
);
4894 printf("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr
);
4895 printf("PhyCtl_1_Rts: %04x ", ptcw_1_Rts
);
4896 printf("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts
);
4897 printf("MainRates: %04x ", mainrates
);
4898 printf("XtraFrameTypes: %04x ", xtraft
);
4901 bcm_format_hex(hexbuf
, iv
, sizeof(txh
->IV
));
4902 printf("SecIV: %s\n", hexbuf
);
4903 bcm_format_hex(hexbuf
, ra
, sizeof(txh
->TxFrameRA
));
4904 printf("RA: %s\n", hexbuf
);
4906 printf("Fb FES Time: %04x ", tfestfb
);
4907 bcm_format_hex(hexbuf
, rtspfb
, sizeof(txh
->RTSPLCPFallback
));
4908 printf("RTS PLCP: %s ", hexbuf
);
4909 printf("RTS DUR: %04x ", rtsdfb
);
4910 bcm_format_hex(hexbuf
, fragpfb
, sizeof(txh
->FragPLCPFallback
));
4911 printf("PLCP: %s ", hexbuf
);
4912 printf("DUR: %04x", fragdfb
);
4915 printf("MModeLen: %04x ", mmodelen
);
4916 printf("MModeFbrLen: %04x\n", mmodefbrlen
);
4918 printf("FrameID: %04x\n", tfid
);
4919 printf("TxStatus: %04x\n", txs
);
4921 printf("MaxNumMpdu: %04x\n", mnmpdu
);
4922 printf("MaxAggbyte: %04x\n", mabyte
);
4923 printf("MaxAggbyte_fb: %04x\n", mabyte_f
);
4924 printf("MinByte: %04x\n", mmbyte
);
4926 bcm_format_hex(hexbuf
, rtsph
, sizeof(txh
->RTSPhyHeader
));
4927 printf("RTS PLCP: %s ", hexbuf
);
4928 bcm_format_hex(hexbuf
, (u8
*) &rts
, sizeof(txh
->rts_frame
));
4929 printf("RTS Frame: %s", hexbuf
);
4933 #endif /* defined(BCMDBG) */
4936 void wlc_print_rxh(d11rxhdr_t
*rxh
)
4938 u16 len
= rxh
->RxFrameSize
;
4939 u16 phystatus_0
= rxh
->PhyRxStatus_0
;
4940 u16 phystatus_1
= rxh
->PhyRxStatus_1
;
4941 u16 phystatus_2
= rxh
->PhyRxStatus_2
;
4942 u16 phystatus_3
= rxh
->PhyRxStatus_3
;
4943 u16 macstatus1
= rxh
->RxStatus1
;
4944 u16 macstatus2
= rxh
->RxStatus2
;
4947 static const bcm_bit_desc_t macstat_flags
[] = {
4948 {RXS_FCSERR
, "FCSErr"},
4949 {RXS_RESPFRAMETX
, "Reply"},
4950 {RXS_PBPRES
, "PADDING"},
4951 {RXS_DECATMPT
, "DeCr"},
4952 {RXS_DECERR
, "DeCrErr"},
4953 {RXS_BCNSENT
, "Bcn"},
4957 prhex("Raw RxDesc", (unsigned char *) rxh
, sizeof(d11rxhdr_t
));
4959 bcm_format_flags(macstat_flags
, macstatus1
, flagstr
, 64);
4961 snprintf(lenbuf
, sizeof(lenbuf
), "0x%x", len
);
4963 printf("RxFrameSize: %6s (%d)%s\n", lenbuf
, len
,
4964 (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
) ? " short preamble" : "");
4965 printf("RxPHYStatus: %04x %04x %04x %04x\n",
4966 phystatus_0
, phystatus_1
, phystatus_2
, phystatus_3
);
4967 printf("RxMACStatus: %x %s\n", macstatus1
, flagstr
);
4968 printf("RXMACaggtype: %x\n", (macstatus2
& RXS_AGGTYPE_MASK
));
4969 printf("RxTSFTime: %04x\n", rxh
->RxTSFTime
);
4971 #endif /* defined(BCMDBG) */
4974 int wlc_format_ssid(char *buf
, const unsigned char ssid
[], uint ssid_len
)
4978 char *endp
= buf
+ SSID_FMT_BUF_LEN
;
4980 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
4981 ssid_len
= IEEE80211_MAX_SSID_LEN
;
4983 for (i
= 0; i
< ssid_len
; i
++) {
4988 } else if (isprint((unsigned char) c
)) {
4991 p
+= snprintf(p
, (endp
- p
), "\\x%02X", c
);
4997 return (int)(p
- buf
);
4999 #endif /* defined(BCMDBG) */
5001 u16
wlc_rate_shm_offset(struct wlc_info
*wlc
, u8 rate
)
5003 return wlc_bmac_rate_shm_offset(wlc
->hw
, rate
);
5006 /* Callback for device removed */
5009 * Attempts to queue a packet onto a multiple-precedence queue,
5010 * if necessary evicting a lower precedence packet from the queue.
5012 * 'prec' is the precedence number that has already been mapped
5013 * from the packet priority.
5015 * Returns true if packet consumed (queued), false if not.
5018 wlc_prec_enq(struct wlc_info
*wlc
, struct pktq
*q
, void *pkt
, int prec
)
5020 return wlc_prec_enq_head(wlc
, q
, pkt
, prec
, false);
5024 wlc_prec_enq_head(struct wlc_info
*wlc
, struct pktq
*q
, struct sk_buff
*pkt
,
5025 int prec
, bool head
)
5028 int eprec
= -1; /* precedence to evict from */
5030 /* Determine precedence from which to evict packet, if any */
5031 if (pktq_pfull(q
, prec
))
5033 else if (pktq_full(q
)) {
5034 p
= pktq_peek_tail(q
, &eprec
);
5037 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5038 __func__
, eprec
, prec
);
5043 /* Evict if needed */
5045 bool discard_oldest
;
5047 /* Detect queueing to unconfigured precedence */
5048 ASSERT(!pktq_pempty(q
, eprec
));
5050 discard_oldest
= AC_BITMAP_TST(wlc
->wme_dp
, eprec
);
5052 /* Refuse newer packet unless configured to discard oldest */
5053 if (eprec
== prec
&& !discard_oldest
) {
5054 WL_ERROR("%s: No where to go, prec == %d\n",
5059 /* Evict packet according to discard policy */
5060 p
= discard_oldest
? pktq_pdeq(q
, eprec
) : pktq_pdeq_tail(q
,
5064 /* Increment wme stats */
5065 if (WME_ENAB(wlc
->pub
)) {
5066 WLCNTINCR(wlc
->pub
->_wme_cnt
->
5067 tx_failed
[WME_PRIO2AC(p
->priority
)].packets
);
5068 WLCNTADD(wlc
->pub
->_wme_cnt
->
5069 tx_failed
[WME_PRIO2AC(p
->priority
)].bytes
,
5070 pkttotlen(wlc
->osh
, p
));
5074 pkt_buf_free_skb(wlc
->osh
, p
, true);
5075 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5080 p
= pktq_penq_head(q
, prec
, pkt
);
5082 p
= pktq_penq(q
, prec
, pkt
);
5088 void BCMFASTPATH
wlc_txq_enq(void *ctx
, struct scb
*scb
, struct sk_buff
*sdu
,
5091 struct wlc_info
*wlc
= (struct wlc_info
*) ctx
;
5092 wlc_txq_info_t
*qi
= wlc
->active_queue
; /* Check me */
5093 struct pktq
*q
= &qi
->q
;
5096 prio
= sdu
->priority
;
5098 ASSERT(pktq_max(q
) >= wlc
->pub
->tunables
->datahiwat
);
5100 if (!wlc_prec_enq(wlc
, q
, sdu
, prec
)) {
5101 if (!EDCF_ENAB(wlc
->pub
)
5102 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
))
5103 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5106 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5107 pkt_buf_free_skb(wlc
->osh
, sdu
, true);
5108 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5111 /* Check if flow control needs to be turned on after enqueuing the packet
5112 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5113 * to drop instead of relying on stack to make the right decision
5115 if (!EDCF_ENAB(wlc
->pub
)
5116 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5117 if (pktq_len(q
) >= wlc
->pub
->tunables
->datahiwat
) {
5118 wlc_txflowcontrol(wlc
, qi
, ON
, ALLPRIO
);
5120 } else if (wlc
->pub
->_priofc
) {
5121 if (pktq_plen(q
, wlc_prio2prec_map
[prio
]) >=
5122 wlc
->pub
->tunables
->datahiwat
) {
5123 wlc_txflowcontrol(wlc
, qi
, ON
, prio
);
5129 wlc_sendpkt_mac80211(struct wlc_info
*wlc
, struct sk_buff
*sdu
,
5130 struct ieee80211_hw
*hw
)
5135 struct scb
*scb
= &global_scb
;
5136 struct ieee80211_hdr
*d11_header
= (struct ieee80211_hdr
*)(sdu
->data
);
5141 fc
= ltoh16(d11_header
->frame_control
);
5142 type
= (fc
& IEEE80211_FCTL_FTYPE
);
5144 /* 802.11 standard requires management traffic to go at highest priority */
5145 prio
= (type
== IEEE80211_FTYPE_DATA
? sdu
->priority
: MAXPRIO
);
5146 fifo
= prio2fifo
[prio
];
5148 ASSERT((uint
) skb_headroom(sdu
) >= TXOFF
);
5149 ASSERT(!(sdu
->next
));
5150 ASSERT(!(sdu
->prev
));
5151 ASSERT(fifo
< NFIFO
);
5155 (wlc_d11hdrs_mac80211(wlc
, hw
, pkt
, scb
, 0, 1, fifo
, 0, NULL
, 0)))
5157 wlc_txq_enq(wlc
, scb
, pkt
, WLC_PRIO_TO_PREC(prio
));
5158 wlc_send_q(wlc
, wlc
->active_queue
);
5160 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx
);
5164 void BCMFASTPATH
wlc_send_q(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
)
5166 struct sk_buff
*pkt
[DOT11_MAXNUMFRAGS
];
5169 int err
= 0, i
, count
;
5171 struct pktq
*q
= &qi
->q
;
5172 struct ieee80211_tx_info
*tx_info
;
5174 /* only do work for the active queue */
5175 if (qi
!= wlc
->active_queue
)
5183 prec_map
= wlc
->tx_prec_map
;
5185 /* Send all the enq'd pkts that we can.
5186 * Dequeue packets with precedence with empty HW fifo only
5188 while (prec_map
&& (pkt
[0] = pktq_mdeq(q
, prec_map
, &prec
))) {
5189 tx_info
= IEEE80211_SKB_CB(pkt
[0]);
5190 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
5191 err
= wlc_sendampdu(wlc
->ampdu
, qi
, pkt
, prec
);
5194 err
= wlc_prep_pdu(wlc
, pkt
[0], &fifo
);
5196 for (i
= 0; i
< count
; i
++) {
5197 wlc_txfifo(wlc
, fifo
, pkt
[i
], true, 1);
5202 if (err
== BCME_BUSY
) {
5203 pktq_penq_head(q
, prec
, pkt
[0]);
5204 /* If send failed due to any other reason than a change in
5205 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5207 if (prec_map
== wlc
->tx_prec_map
)
5209 prec_map
= wlc
->tx_prec_map
;
5213 /* Check if flow control needs to be turned off after sending the packet */
5214 if (!EDCF_ENAB(wlc
->pub
)
5215 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5216 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, ALLPRIO
)
5217 && (pktq_len(q
) < wlc
->pub
->tunables
->datahiwat
/ 2)) {
5218 wlc_txflowcontrol(wlc
, qi
, OFF
, ALLPRIO
);
5220 } else if (wlc
->pub
->_priofc
) {
5222 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
5223 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, prio
) &&
5224 (pktq_plen(q
, wlc_prio2prec_map
[prio
]) <
5225 wlc
->pub
->tunables
->datahiwat
/ 2)) {
5226 wlc_txflowcontrol(wlc
, qi
, OFF
, prio
);
5234 * bcmc_fid_generate:
5235 * Generate frame ID for a BCMC packet. The frag field is not used
5236 * for MC frames so is used as part of the sequence number.
5239 bcmc_fid_generate(struct wlc_info
*wlc
, wlc_bsscfg_t
*bsscfg
, d11txh_t
*txh
)
5243 frameid
= ltoh16(txh
->TxFrameID
) & ~(TXFID_SEQ_MASK
| TXFID_QUEUE_MASK
);
5246 mc_fid_counter
++) << TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5253 wlc_txfifo(struct wlc_info
*wlc
, uint fifo
, struct sk_buff
*p
, bool commit
,
5256 u16 frameid
= INVALIDFID
;
5259 ASSERT(fifo
< NFIFO
);
5260 txh
= (d11txh_t
*) (p
->data
);
5262 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5263 * ucode or BSS info as appropriate.
5265 if (fifo
== TX_BCMC_FIFO
) {
5266 frameid
= ltoh16(txh
->TxFrameID
);
5270 if (WLC_WAR16165(wlc
))
5271 wlc_war16165(wlc
, true);
5274 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5275 * in wlc_bmac_txfifo()
5278 TXPKTPENDINC(wlc
, fifo
, txpktpend
);
5279 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5280 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
5283 /* Commit BCMC sequence number in the SHM frame ID location */
5284 if (frameid
!= INVALIDFID
)
5285 BCMCFID(wlc
, frameid
);
5287 if (dma_txfast(wlc
->hw
->di
[fifo
], p
, commit
) < 0) {
5288 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5293 wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
)
5296 uint mac_rate
= RSPEC2RATE(rspec
);
5299 if (IS_MCS(rspec
)) {
5300 /* not supported yet */
5302 } else if (IS_OFDM(rspec
)) {
5303 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5305 * Nbits = length * 8
5306 * Nbits/sym = Mbps * 4 = mac_rate * 2
5308 nsyms
= CEIL((length
* 8), (mac_rate
* 2));
5310 /* usec = symbols * usec/symbol */
5311 usec
= (u16
) (nsyms
* APHY_SYMBOL_TIME
);
5322 usec
= (length
<< 4) / 11;
5325 usec
= (length
<< 3) / 11;
5328 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5329 wlc
->pub
->unit
, rspec
);
5330 ASSERT((const char *)"Bad phy_rate" == NULL
);
5339 wlc_compute_plcp(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
, u8
*plcp
)
5341 if (IS_MCS(rspec
)) {
5342 wlc_compute_mimo_plcp(rspec
, length
, plcp
);
5343 } else if (IS_OFDM(rspec
)) {
5344 wlc_compute_ofdm_plcp(rspec
, length
, plcp
);
5346 wlc_compute_cck_plcp(rspec
, length
, plcp
);
5351 /* Rate: 802.11 rate code, length: PSDU length in octets */
5352 static void wlc_compute_mimo_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5354 u8 mcs
= (u8
) (rspec
& RSPEC_RATE_MASK
);
5355 ASSERT(IS_MCS(rspec
));
5357 if (RSPEC_IS40MHZ(rspec
) || (mcs
== 32))
5358 plcp
[0] |= MIMO_PLCP_40MHZ
;
5359 WLC_SET_MIMO_PLCP_LEN(plcp
, length
);
5360 plcp
[3] = RSPEC_MIMOPLCP3(rspec
); /* rspec already holds this byte */
5361 plcp
[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5362 plcp
[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5366 /* Rate: 802.11 rate code, length: PSDU length in octets */
5367 static void BCMFASTPATH
5368 wlc_compute_ofdm_plcp(ratespec_t rspec
, u32 length
, u8
*plcp
)
5372 int rate
= RSPEC2RATE(rspec
);
5374 ASSERT(IS_OFDM(rspec
));
5376 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5377 rate_signal
= rate_info
[rate
] & RATE_MASK
;
5378 ASSERT(rate_signal
!= 0);
5380 memset(plcp
, 0, D11_PHY_HDR_LEN
);
5381 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t
*) plcp
, rate_signal
);
5383 tmp
= (length
& 0xfff) << 5;
5384 plcp
[2] |= (tmp
>> 16) & 0xff;
5385 plcp
[1] |= (tmp
>> 8) & 0xff;
5386 plcp
[0] |= tmp
& 0xff;
5392 * Compute PLCP, but only requires actual rate and length of pkt.
5393 * Rate is given in the driver standard multiple of 500 kbps.
5394 * le is set for 11 Mbps rate if necessary.
5395 * Broken out for PRQ.
5398 static void wlc_cck_plcp_set(int rate_500
, uint length
, u8
*plcp
)
5411 usec
= (length
<< 4) / 11;
5412 if ((length
<< 4) - (usec
* 11) > 0)
5416 usec
= (length
<< 3) / 11;
5417 if ((length
<< 3) - (usec
* 11) > 0) {
5419 if ((usec
* 11) - (length
<< 3) >= 8)
5420 le
= D11B_PLCP_SIGNAL_LE
;
5425 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500
);
5426 rate_500
= WLC_RATE_1M
;
5430 /* PLCP signal byte */
5431 plcp
[0] = rate_500
* 5; /* r (500kbps) * 5 == r (100kbps) */
5432 /* PLCP service byte */
5433 plcp
[1] = (u8
) (le
| D11B_PLCP_SIGNAL_LOCKED
);
5434 /* PLCP length u16, little endian */
5435 plcp
[2] = usec
& 0xff;
5436 plcp
[3] = (usec
>> 8) & 0xff;
5442 /* Rate: 802.11 rate code, length: PSDU length in octets */
5443 static void wlc_compute_cck_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5445 int rate
= RSPEC2RATE(rspec
);
5447 ASSERT(IS_CCK(rspec
));
5449 wlc_cck_plcp_set(rate
, length
, plcp
);
5452 /* wlc_compute_frame_dur()
5454 * Calculate the 802.11 MAC header DUR field for MPDU
5455 * DUR for a single frame = 1 SIFS + 1 ACK
5456 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5458 * rate MPDU rate in unit of 500kbps
5459 * next_frag_len next MPDU length in bytes
5460 * preamble_type use short/GF or long/MM PLCP header
5462 static u16 BCMFASTPATH
5463 wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
, u8 preamble_type
,
5468 sifs
= SIFS(wlc
->band
);
5471 dur
+= (u16
) wlc_calc_ack_time(wlc
, rate
, preamble_type
);
5473 if (next_frag_len
) {
5474 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5476 /* add another SIFS and the frag time */
5479 (u16
) wlc_calc_frame_time(wlc
, rate
, preamble_type
,
5485 /* wlc_compute_rtscts_dur()
5487 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5488 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5489 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5491 * cts cts-to-self or rts/cts
5492 * rts_rate rts or cts rate in unit of 500kbps
5493 * rate next MPDU rate in unit of 500kbps
5494 * frame_len next MPDU frame length in bytes
5497 wlc_compute_rtscts_dur(struct wlc_info
*wlc
, bool cts_only
, ratespec_t rts_rate
,
5498 ratespec_t frame_rate
, u8 rts_preamble_type
,
5499 u8 frame_preamble_type
, uint frame_len
, bool ba
)
5503 sifs
= SIFS(wlc
->band
);
5505 if (!cts_only
) { /* RTS/CTS */
5508 (u16
) wlc_calc_cts_time(wlc
, rts_rate
,
5510 } else { /* CTS-TO-SELF */
5515 (u16
) wlc_calc_frame_time(wlc
, frame_rate
, frame_preamble_type
,
5519 (u16
) wlc_calc_ba_time(wlc
, frame_rate
,
5520 WLC_SHORT_PREAMBLE
);
5523 (u16
) wlc_calc_ack_time(wlc
, frame_rate
,
5524 frame_preamble_type
);
5528 static bool wlc_phy_rspec_check(struct wlc_info
*wlc
, u16 bw
, ratespec_t rspec
)
5530 if (IS_MCS(rspec
)) {
5531 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5534 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5535 } else if ((mcs
>= 8) && (mcs
<= 23)) {
5536 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SDM
);
5537 } else if (mcs
== 32) {
5538 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5539 ASSERT(bw
== PHY_TXC1_BW_40MHZ_DUP
);
5541 } else if (IS_OFDM(rspec
)) {
5542 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_STBC
);
5544 ASSERT(IS_CCK(rspec
));
5546 ASSERT((bw
== PHY_TXC1_BW_20MHZ
)
5547 || (bw
== PHY_TXC1_BW_20MHZ_UP
));
5548 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SISO
);
5554 u16 BCMFASTPATH
wlc_phytxctl1_calc(struct wlc_info
*wlc
, ratespec_t rspec
)
5559 if (WLCISLCNPHY(wlc
->band
)) {
5560 bw
= PHY_TXC1_BW_20MHZ
;
5562 bw
= RSPEC_GET_BW(rspec
);
5563 /* 10Mhz is not supported yet */
5564 if (bw
< PHY_TXC1_BW_20MHZ
) {
5565 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5567 bw
= PHY_TXC1_BW_20MHZ
;
5570 wlc_phy_rspec_check(wlc
, bw
, rspec
);
5573 if (IS_MCS(rspec
)) {
5574 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5576 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5577 phyctl1
= RSPEC_PHYTXBYTE2(rspec
);
5578 /* set the upper byte of phyctl1 */
5579 phyctl1
|= (mcs_table
[mcs
].tx_phy_ctl3
<< 8);
5580 } else if (IS_CCK(rspec
) && !WLCISLCNPHY(wlc
->band
)
5581 && !WLCISSSLPNPHY(wlc
->band
)) {
5582 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5583 /* Eventually MIMOPHY would also be converted to this format */
5584 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5585 phyctl1
= (bw
| (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5586 } else { /* legacy OFDM/CCK */
5588 /* get the phyctl byte from rate phycfg table */
5589 phycfg
= wlc_rate_legacy_phyctl(RSPEC2RATE(rspec
));
5591 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5595 /* set the upper byte of phyctl1 */
5597 (bw
| (phycfg
<< 8) |
5598 (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5602 /* phy clock must support 40Mhz if tx descriptor uses it */
5603 if ((phyctl1
& PHY_TXC1_BW_MASK
) >= PHY_TXC1_BW_40MHZ
) {
5604 ASSERT(CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
);
5605 ASSERT(wlc
->chanspec
== wlc_phy_chanspec_get(wlc
->band
->pi
));
5611 ratespec_t BCMFASTPATH
5612 wlc_rspec_to_rts_rspec(struct wlc_info
*wlc
, ratespec_t rspec
, bool use_rspec
,
5615 ratespec_t rts_rspec
= 0;
5618 /* use frame rate as rts rate */
5621 } else if (wlc
->band
->gmode
&& wlc
->protection
->_g
&& !IS_CCK(rspec
)) {
5622 /* Use 11Mbps as the g protection RTS target rate and fallback.
5623 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5624 * target in case 11 Mbps is not Basic.
5625 * 6 and 9 Mbps are not usually selected by rate selection, but even
5626 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5628 rts_rspec
= WLC_BASIC_RATE(wlc
, WLC_RATE_11M
);
5630 /* calculate RTS rate and fallback rate based on the frame rate
5631 * RTS must be sent at a basic rate since it is a
5632 * control frame, sec 9.6 of 802.11 spec
5634 rts_rspec
= WLC_BASIC_RATE(wlc
, rspec
);
5637 if (WLC_PHY_11N_CAP(wlc
->band
)) {
5638 /* set rts txbw to correct side band */
5639 rts_rspec
&= ~RSPEC_BW_MASK
;
5641 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5642 * (DUP), otherwise send RTS on control channel
5644 if (RSPEC_IS40MHZ(rspec
) && !IS_CCK(rts_rspec
))
5645 rts_rspec
|= (PHY_TXC1_BW_40MHZ_DUP
<< RSPEC_BW_SHIFT
);
5647 rts_rspec
|= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5649 /* pick siso/cdd as default for ofdm */
5650 if (IS_OFDM(rts_rspec
)) {
5651 rts_rspec
&= ~RSPEC_STF_MASK
;
5652 rts_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
5659 * Add d11txh_t, cck_phy_hdr_t.
5661 * 'p' data must start with 802.11 MAC header
5662 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5664 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5667 static u16 BCMFASTPATH
5668 wlc_d11hdrs_mac80211(struct wlc_info
*wlc
, struct ieee80211_hw
*hw
,
5669 struct sk_buff
*p
, struct scb
*scb
, uint frag
,
5670 uint nfrags
, uint queue
, uint next_frag_len
,
5671 wsec_key_t
*key
, ratespec_t rspec_override
)
5673 struct ieee80211_hdr
*h
;
5675 u8
*plcp
, plcp_fallback
[D11_PHY_HDR_LEN
];
5676 struct osl_info
*osh
;
5677 int len
, phylen
, rts_phylen
;
5678 u16 fc
, type
, frameid
, mch
, phyctl
, xfts
, mainrates
;
5679 u16 seq
= 0, mcl
= 0, status
= 0;
5680 ratespec_t rspec
[2] = { WLC_RATE_1M
, WLC_RATE_1M
}, rts_rspec
[2] = {
5681 WLC_RATE_1M
, WLC_RATE_1M
};
5682 bool use_rts
= false;
5683 bool use_cts
= false;
5684 bool use_rifs
= false;
5685 bool short_preamble
[2] = { false, false };
5686 u8 preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5687 u8 rts_preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5688 u8
*rts_plcp
, rts_plcp_fallback
[D11_PHY_HDR_LEN
];
5689 struct ieee80211_rts
*rts
= NULL
;
5693 bool hwtkmic
= false;
5694 u16 mimo_ctlchbw
= PHY_TXC1_BW_20MHZ
;
5696 #define ANTCFG_NONE 0xFF
5697 u8 antcfg
= ANTCFG_NONE
;
5698 u8 fbantcfg
= ANTCFG_NONE
;
5700 uint phyctl1_stf
= 0;
5702 struct ieee80211_tx_rate
*txrate
[2];
5704 struct ieee80211_tx_info
*tx_info
;
5707 u8 mimo_preamble_type
;
5711 ASSERT(queue
< NFIFO
);
5715 /* locate 802.11 MAC header */
5716 h
= (struct ieee80211_hdr
*)(p
->data
);
5717 fc
= ltoh16(h
->frame_control
);
5718 type
= (fc
& IEEE80211_FCTL_FTYPE
);
5720 qos
= (type
== IEEE80211_FTYPE_DATA
&&
5721 FC_SUBTYPE_ANY_QOS(fc
));
5723 /* compute length of frame in bytes for use in PLCP computations */
5724 len
= pkttotlen(osh
, p
);
5725 phylen
= len
+ FCS_LEN
;
5727 /* If WEP enabled, add room in phylen for the additional bytes of
5728 * ICV which MAC generates. We do NOT add the additional bytes to
5729 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5733 phylen
+= key
->icv_len
;
5737 tx_info
= IEEE80211_SKB_CB(p
);
5741 plcp
= skb_push(p
, D11_PHY_HDR_LEN
);
5743 /* add Broadcom tx descriptor header */
5744 txh
= (d11txh_t
*) skb_push(p
, D11_TXH_LEN
);
5745 memset((char *)txh
, 0, D11_TXH_LEN
);
5748 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
5749 /* non-AP STA should never use BCMC queue */
5750 ASSERT(queue
!= TX_BCMC_FIFO
);
5751 if (queue
== TX_BCMC_FIFO
) {
5752 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5753 WLCWLUNIT(wlc
), __func__
);
5754 frameid
= bcmc_fid_generate(wlc
, NULL
, txh
);
5756 /* Increment the counter for first fragment */
5757 if (tx_info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
) {
5758 SCB_SEQNUM(scb
, p
->priority
)++;
5761 /* extract fragment number from frame first */
5762 seq
= ltoh16(seq
) & FRAGNUM_MASK
;
5763 seq
|= (SCB_SEQNUM(scb
, p
->priority
) << SEQNUM_SHIFT
);
5764 h
->seq_ctrl
= htol16(seq
);
5766 frameid
= ((seq
<< TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5767 (queue
& TXFID_QUEUE_MASK
);
5770 frameid
|= queue
& TXFID_QUEUE_MASK
;
5772 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5773 if (SCB_PS(scb
) || ((fc
& FC_KIND_MASK
) == FC_BEACON
))
5774 mcl
|= TXC_IGNOREPMQ
;
5776 ASSERT(hw
->max_rates
<= IEEE80211_TX_MAX_RATES
);
5777 ASSERT(hw
->max_rates
== 2);
5779 txrate
[0] = tx_info
->control
.rates
;
5780 txrate
[1] = txrate
[0] + 1;
5782 ASSERT(txrate
[0]->idx
>= 0);
5783 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5784 if (txrate
[1]->idx
< 0) {
5785 txrate
[1] = txrate
[0];
5788 for (k
= 0; k
< hw
->max_rates
; k
++) {
5790 txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
? true : false;
5792 ASSERT(!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
));
5793 if ((txrate
[k
]->idx
>= 0)
5794 && (txrate
[k
]->idx
<
5795 hw
->wiphy
->bands
[tx_info
->band
]->n_bitrates
)) {
5797 hw
->wiphy
->bands
[tx_info
->band
]->
5798 bitrates
[txrate
[k
]->idx
].hw_value
;
5801 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
?
5804 ASSERT((txrate
[k
]->idx
>= 0) &&
5806 hw
->wiphy
->bands
[tx_info
->band
]->
5808 rate_val
[k
] = WLC_RATE_1M
;
5811 rate_val
[k
] = txrate
[k
]->idx
;
5813 /* Currently only support same setting for primay and fallback rates.
5814 * Unify flags for each rate into a single value for the frame
5818 flags
& IEEE80211_TX_RC_USE_RTS_CTS
? true : false;
5821 flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
? true : false;
5824 rate_val
[k
] |= NRATE_MCS_INUSE
;
5826 rspec
[k
] = mac80211_wlc_set_nrate(wlc
, wlc
->band
, rate_val
[k
]);
5828 /* (1) RATE: determine and validate primary rate and fallback rates */
5829 if (!RSPEC_ACTIVE(rspec
[k
])) {
5830 ASSERT(RSPEC_ACTIVE(rspec
[k
]));
5831 rspec
[k
] = WLC_RATE_1M
;
5833 if (WLANTSEL_ENAB(wlc
) &&
5834 !is_multicast_ether_addr(h
->addr1
)) {
5835 /* set tx antenna config */
5836 wlc_antsel_antcfg_get(wlc
->asi
, false, false, 0,
5837 0, &antcfg
, &fbantcfg
);
5842 phyctl1_stf
= wlc
->stf
->ss_opmode
;
5844 if (N_ENAB(wlc
->pub
)) {
5845 for (k
= 0; k
< hw
->max_rates
; k
++) {
5846 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5847 if (((IS_MCS(rspec
[k
]) &&
5848 IS_SINGLE_STREAM(rspec
[k
] & RSPEC_RATE_MASK
)) ||
5850 && ((rspec
[k
] & RSPEC_OVERRIDE_MCS_ONLY
)
5851 || !(rspec
[k
] & RSPEC_OVERRIDE
))) {
5852 rspec
[k
] &= ~(RSPEC_STF_MASK
| RSPEC_STC_MASK
);
5854 /* For SISO MCS use STBC if possible */
5855 if (IS_MCS(rspec
[k
])
5856 && WLC_STF_SS_STBC_TX(wlc
, scb
)) {
5859 ASSERT(WLC_STBC_CAP_PHY(wlc
));
5860 stc
= 1; /* Nss for single stream is always 1 */
5862 (PHY_TXC1_MODE_STBC
<<
5863 RSPEC_STF_SHIFT
) | (stc
<<
5867 (phyctl1_stf
<< RSPEC_STF_SHIFT
);
5870 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5871 if (CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
) {
5872 /* default txbw is 20in40 SB */
5873 mimo_ctlchbw
= mimo_txbw
=
5874 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC
)
5875 ? PHY_TXC1_BW_20MHZ_UP
: PHY_TXC1_BW_20MHZ
;
5877 if (IS_MCS(rspec
[k
])) {
5878 /* mcs 32 must be 40b/w DUP */
5879 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5881 PHY_TXC1_BW_40MHZ_DUP
;
5883 } else if (wlc
->mimo_40txbw
!= AUTO
)
5884 mimo_txbw
= wlc
->mimo_40txbw
;
5885 /* else check if dst is using 40 Mhz */
5886 else if (scb
->flags
& SCB_IS40
)
5887 mimo_txbw
= PHY_TXC1_BW_40MHZ
;
5888 } else if (IS_OFDM(rspec
[k
])) {
5889 if (wlc
->ofdm_40txbw
!= AUTO
)
5890 mimo_txbw
= wlc
->ofdm_40txbw
;
5892 ASSERT(IS_CCK(rspec
[k
]));
5893 if (wlc
->cck_40txbw
!= AUTO
)
5894 mimo_txbw
= wlc
->cck_40txbw
;
5897 /* mcs32 is 40 b/w only.
5898 * This is possible for probe packets on a STA during SCAN
5900 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5902 rspec
[k
] = RSPEC_MIMORATE
;
5904 mimo_txbw
= PHY_TXC1_BW_20MHZ
;
5907 /* Set channel width */
5908 rspec
[k
] &= ~RSPEC_BW_MASK
;
5909 if ((k
== 0) || ((k
> 0) && IS_MCS(rspec
[k
])))
5910 rspec
[k
] |= (mimo_txbw
<< RSPEC_BW_SHIFT
);
5912 rspec
[k
] |= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5916 if (IS_MCS(rspec
[k
])
5917 && (txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5918 rspec
[k
] |= RSPEC_SHORT_GI
;
5919 else if (!(txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5920 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5922 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5925 mimo_preamble_type
= WLC_MM_PREAMBLE
;
5926 if (txrate
[k
]->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
5927 mimo_preamble_type
= WLC_GF_PREAMBLE
;
5929 if ((txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
)
5930 && (!IS_MCS(rspec
[k
]))) {
5931 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5932 WLCWLUNIT(wlc
), __func__
);
5933 ASSERT(0 && "Rate mismatch");
5936 if (IS_MCS(rspec
[k
])) {
5937 preamble_type
[k
] = mimo_preamble_type
;
5939 /* if SGI is selected, then forced mm for single stream */
5940 if ((rspec
[k
] & RSPEC_SHORT_GI
)
5941 && IS_SINGLE_STREAM(rspec
[k
] &
5943 preamble_type
[k
] = WLC_MM_PREAMBLE
;
5947 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
5948 ASSERT(VALID_RATE_DBG(wlc
, rspec
[0]));
5950 /* should be better conditionalized */
5951 if (!IS_MCS(rspec
[0])
5952 && (tx_info
->control
.rates
[0].
5953 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
))
5954 preamble_type
[k
] = WLC_SHORT_PREAMBLE
;
5956 ASSERT(!IS_MCS(rspec
[0])
5957 || WLC_IS_MIMO_PREAMBLE(preamble_type
[k
]));
5960 for (k
= 0; k
< hw
->max_rates
; k
++) {
5961 /* Set ctrlchbw as 20Mhz */
5962 ASSERT(!IS_MCS(rspec
[k
]));
5963 rspec
[k
] &= ~RSPEC_BW_MASK
;
5964 rspec
[k
] |= (PHY_TXC1_BW_20MHZ
<< RSPEC_BW_SHIFT
);
5966 /* for nphy, stf of ofdm frames must follow policies */
5967 if (WLCISNPHY(wlc
->band
) && IS_OFDM(rspec
[k
])) {
5968 rspec
[k
] &= ~RSPEC_STF_MASK
;
5969 rspec
[k
] |= phyctl1_stf
<< RSPEC_STF_SHIFT
;
5974 /* Reset these for use with AMPDU's */
5975 txrate
[0]->count
= 0;
5976 txrate
[1]->count
= 0;
5978 /* (2) PROTECTION, may change rspec */
5979 if ((ieee80211_is_data(fc
) || ieee80211_is_mgmt(fc
)) &&
5980 (phylen
> wlc
->RTSThresh
) && !is_multicast_ether_addr(h
->addr1
))
5983 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
5984 wlc_compute_plcp(wlc
, rspec
[0], phylen
, plcp
);
5985 wlc_compute_plcp(wlc
, rspec
[1], phylen
, plcp_fallback
);
5986 bcopy(plcp_fallback
, (char *)&txh
->FragPLCPFallback
,
5987 sizeof(txh
->FragPLCPFallback
));
5989 /* Length field now put in CCK FBR CRC field */
5990 if (IS_CCK(rspec
[1])) {
5991 txh
->FragPLCPFallback
[4] = phylen
& 0xff;
5992 txh
->FragPLCPFallback
[5] = (phylen
& 0xff00) >> 8;
5995 /* MIMO-RATE: need validation ?? */
5997 IS_OFDM(rspec
[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) plcp
) :
6000 /* DUR field for main rate */
6001 if ((fc
!= FC_PS_POLL
) &&
6002 !is_multicast_ether_addr(h
->addr1
) && !use_rifs
) {
6004 wlc_compute_frame_dur(wlc
, rspec
[0], preamble_type
[0],
6006 h
->duration_id
= htol16(durid
);
6007 } else if (use_rifs
) {
6008 /* NAV protect to end of next max packet size */
6010 (u16
) wlc_calc_frame_time(wlc
, rspec
[0],
6012 DOT11_MAX_FRAG_LEN
);
6013 durid
+= RIFS_11N_TIME
;
6014 h
->duration_id
= htol16(durid
);
6017 /* DUR field for fallback rate */
6018 if (fc
== FC_PS_POLL
)
6019 txh
->FragDurFallback
= h
->duration_id
;
6020 else if (is_multicast_ether_addr(h
->addr1
) || use_rifs
)
6021 txh
->FragDurFallback
= 0;
6023 durid
= wlc_compute_frame_dur(wlc
, rspec
[1],
6024 preamble_type
[1], next_frag_len
);
6025 txh
->FragDurFallback
= htol16(durid
);
6028 /* (4) MAC-HDR: MacTxControlLow */
6030 mcl
|= TXC_STARTMSDU
;
6032 if (!is_multicast_ether_addr(h
->addr1
))
6033 mcl
|= TXC_IMMEDACK
;
6035 if (BAND_5G(wlc
->band
->bandtype
))
6036 mcl
|= TXC_FREQBAND_5G
;
6038 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC
))
6041 /* set AMIC bit if using hardware TKIP MIC */
6045 txh
->MacTxControlLow
= htol16(mcl
);
6047 /* MacTxControlHigh */
6050 /* Set fallback rate preamble type */
6051 if ((preamble_type
[1] == WLC_SHORT_PREAMBLE
) ||
6052 (preamble_type
[1] == WLC_GF_PREAMBLE
)) {
6053 ASSERT((preamble_type
[1] == WLC_GF_PREAMBLE
) ||
6054 (!IS_MCS(rspec
[1])));
6055 if (RSPEC2RATE(rspec
[1]) != WLC_RATE_1M
)
6056 mch
|= TXC_PREAMBLE_DATA_FB_SHORT
;
6059 /* MacFrameControl */
6060 bcopy((char *)&h
->frame_control
, (char *)&txh
->MacFrameControl
,
6062 txh
->TxFesTimeNormal
= htol16(0);
6064 txh
->TxFesTimeFallback
= htol16(0);
6067 bcopy((char *)&h
->addr1
, (char *)&txh
->TxFrameRA
, ETH_ALEN
);
6070 txh
->TxFrameID
= htol16(frameid
);
6072 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6073 * then we may need to reset the retry cnt's via the status reg
6075 txh
->TxStatus
= htol16(status
);
6077 if (D11REV_GE(wlc
->pub
->corerev
, 16)) {
6078 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6079 * the END of previous structure so that it's compatible in driver.
6080 * In old rev ucode, these fields should be ignored
6082 txh
->MaxNMpdus
= htol16(0);
6083 txh
->MaxABytes_MRT
= htol16(0);
6084 txh
->MaxABytes_FBR
= htol16(0);
6085 txh
->MinMBytes
= htol16(0);
6088 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6089 /* RTS PLCP header and RTS frame */
6090 if (use_rts
|| use_cts
) {
6091 if (use_rts
&& use_cts
)
6094 for (k
= 0; k
< 2; k
++) {
6095 rts_rspec
[k
] = wlc_rspec_to_rts_rspec(wlc
, rspec
[k
],
6100 if (!IS_OFDM(rts_rspec
[0]) &&
6101 !((RSPEC2RATE(rts_rspec
[0]) == WLC_RATE_1M
) ||
6102 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6103 rts_preamble_type
[0] = WLC_SHORT_PREAMBLE
;
6104 mch
|= TXC_PREAMBLE_RTS_MAIN_SHORT
;
6107 if (!IS_OFDM(rts_rspec
[1]) &&
6108 !((RSPEC2RATE(rts_rspec
[1]) == WLC_RATE_1M
) ||
6109 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6110 rts_preamble_type
[1] = WLC_SHORT_PREAMBLE
;
6111 mch
|= TXC_PREAMBLE_RTS_FB_SHORT
;
6114 /* RTS/CTS additions to MacTxControlLow */
6116 txh
->MacTxControlLow
|= htol16(TXC_SENDCTS
);
6118 txh
->MacTxControlLow
|= htol16(TXC_SENDRTS
);
6119 txh
->MacTxControlLow
|= htol16(TXC_LONGFRAME
);
6122 /* RTS PLCP header */
6123 ASSERT(IS_ALIGNED((unsigned long)txh
->RTSPhyHeader
, sizeof(u16
)));
6124 rts_plcp
= txh
->RTSPhyHeader
;
6126 rts_phylen
= DOT11_CTS_LEN
+ FCS_LEN
;
6128 rts_phylen
= DOT11_RTS_LEN
+ FCS_LEN
;
6130 wlc_compute_plcp(wlc
, rts_rspec
[0], rts_phylen
, rts_plcp
);
6132 /* fallback rate version of RTS PLCP header */
6133 wlc_compute_plcp(wlc
, rts_rspec
[1], rts_phylen
,
6135 bcopy(rts_plcp_fallback
, (char *)&txh
->RTSPLCPFallback
,
6136 sizeof(txh
->RTSPLCPFallback
));
6138 /* RTS frame fields... */
6139 rts
= (struct ieee80211_rts
*)&txh
->rts_frame
;
6141 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
, rts_rspec
[0],
6142 rspec
[0], rts_preamble_type
[0],
6143 preamble_type
[0], phylen
, false);
6144 rts
->duration
= htol16(durid
);
6145 /* fallback rate version of RTS DUR field */
6146 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
,
6147 rts_rspec
[1], rspec
[1],
6148 rts_preamble_type
[1],
6149 preamble_type
[1], phylen
, false);
6150 txh
->RTSDurFallback
= htol16(durid
);
6153 rts
->frame_control
= htol16(FC_CTS
);
6154 bcopy((char *)&h
->addr2
, (char *)&rts
->ra
, ETH_ALEN
);
6156 rts
->frame_control
= htol16((u16
) FC_RTS
);
6157 bcopy((char *)&h
->addr1
, (char *)&rts
->ra
,
6162 * low 8 bits: main frag rate/mcs,
6163 * high 8 bits: rts/cts rate/mcs
6165 mainrates
|= (IS_OFDM(rts_rspec
[0]) ?
6166 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) rts_plcp
) :
6169 memset((char *)txh
->RTSPhyHeader
, 0, D11_PHY_HDR_LEN
);
6170 memset((char *)&txh
->rts_frame
, 0,
6171 sizeof(struct ieee80211_rts
));
6172 memset((char *)txh
->RTSPLCPFallback
, 0,
6173 sizeof(txh
->RTSPLCPFallback
));
6174 txh
->RTSDurFallback
= 0;
6177 #ifdef SUPPORT_40MHZ
6178 /* add null delimiter count */
6179 if ((tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) && IS_MCS(rspec
)) {
6180 txh
->RTSPLCPFallback
[AMPDU_FBR_NULL_DELIM
] =
6181 wlc_ampdu_null_delim_cnt(wlc
->ampdu
, scb
, rspec
, phylen
);
6185 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6186 txh
->MacTxControlHigh
= htol16(mch
);
6188 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6189 txh
->MainRates
= htol16(mainrates
);
6191 /* XtraFrameTypes */
6192 xfts
= FRAMETYPE(rspec
[1], wlc
->mimoft
);
6193 xfts
|= (FRAMETYPE(rts_rspec
[0], wlc
->mimoft
) << XFTS_RTS_FT_SHIFT
);
6194 xfts
|= (FRAMETYPE(rts_rspec
[1], wlc
->mimoft
) << XFTS_FBRRTS_FT_SHIFT
);
6196 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
) << XFTS_CHANNEL_SHIFT
;
6197 txh
->XtraFrameTypes
= htol16(xfts
);
6199 /* PhyTxControlWord */
6200 phyctl
= FRAMETYPE(rspec
[0], wlc
->mimoft
);
6201 if ((preamble_type
[0] == WLC_SHORT_PREAMBLE
) ||
6202 (preamble_type
[0] == WLC_GF_PREAMBLE
)) {
6203 ASSERT((preamble_type
[0] == WLC_GF_PREAMBLE
)
6204 || !IS_MCS(rspec
[0]));
6205 if (RSPEC2RATE(rspec
[0]) != WLC_RATE_1M
)
6206 phyctl
|= PHY_TXC_SHORT_HDR
;
6207 WLCNTINCR(wlc
->pub
->_cnt
->txprshort
);
6210 /* phytxant is properly bit shifted */
6211 phyctl
|= wlc_stf_d11hdrs_phyctl_txant(wlc
, rspec
[0]);
6212 txh
->PhyTxControlWord
= htol16(phyctl
);
6214 /* PhyTxControlWord_1 */
6215 if (WLC_PHY_11N_CAP(wlc
->band
)) {
6218 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[0]);
6219 txh
->PhyTxControlWord_1
= htol16(phyctl1
);
6220 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[1]);
6221 txh
->PhyTxControlWord_1_Fbr
= htol16(phyctl1
);
6223 if (use_rts
|| use_cts
) {
6224 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[0]);
6225 txh
->PhyTxControlWord_1_Rts
= htol16(phyctl1
);
6226 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[1]);
6227 txh
->PhyTxControlWord_1_FbrRts
= htol16(phyctl1
);
6231 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6232 * fill in non-zero MModeLen and/or MModeFbrLen
6233 * it will be unnecessary if they are separated
6235 if (IS_MCS(rspec
[0]) && (preamble_type
[0] == WLC_MM_PREAMBLE
)) {
6237 wlc_calc_lsig_len(wlc
, rspec
[0], phylen
);
6238 txh
->MModeLen
= htol16(mmodelen
);
6241 if (IS_MCS(rspec
[1]) && (preamble_type
[1] == WLC_MM_PREAMBLE
)) {
6243 wlc_calc_lsig_len(wlc
, rspec
[1], phylen
);
6244 txh
->MModeFbrLen
= htol16(mmodefbrlen
);
6248 if (IS_MCS(rspec
[0]))
6249 ASSERT(IS_MCS(rspec
[1]));
6251 ASSERT(!IS_MCS(rspec
[0]) ||
6252 ((preamble_type
[0] == WLC_MM_PREAMBLE
) == (txh
->MModeLen
!= 0)));
6253 ASSERT(!IS_MCS(rspec
[1]) ||
6254 ((preamble_type
[1] == WLC_MM_PREAMBLE
) ==
6255 (txh
->MModeFbrLen
!= 0)));
6257 ac
= wme_fifo2ac
[queue
];
6258 if (SCB_WME(scb
) && qos
&& wlc
->edcf_txop
[ac
]) {
6259 uint frag_dur
, dur
, dur_fallback
;
6261 ASSERT(!is_multicast_ether_addr(h
->addr1
));
6263 /* WME: Update TXOP threshold */
6264 if ((!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)) && (frag
== 0)) {
6266 wlc_calc_frame_time(wlc
, rspec
[0], preamble_type
[0],
6270 /* 1 RTS or CTS-to-self frame */
6272 wlc_calc_cts_time(wlc
, rts_rspec
[0],
6273 rts_preamble_type
[0]);
6275 wlc_calc_cts_time(wlc
, rts_rspec
[1],
6276 rts_preamble_type
[1]);
6277 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6278 dur
+= ltoh16(rts
->duration
);
6279 dur_fallback
+= ltoh16(txh
->RTSDurFallback
);
6280 } else if (use_rifs
) {
6284 /* frame + SIFS + ACK */
6287 wlc_compute_frame_dur(wlc
, rspec
[0],
6288 preamble_type
[0], 0);
6291 wlc_calc_frame_time(wlc
, rspec
[1],
6295 wlc_compute_frame_dur(wlc
, rspec
[1],
6296 preamble_type
[1], 0);
6298 /* NEED to set TxFesTimeNormal (hard) */
6299 txh
->TxFesTimeNormal
= htol16((u16
) dur
);
6300 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6301 txh
->TxFesTimeFallback
= htol16((u16
) dur_fallback
);
6303 /* update txop byte threshold (txop minus intraframe overhead) */
6304 if (wlc
->edcf_txop
[ac
] >= (dur
- frag_dur
)) {
6309 wlc_calc_frame_len(wlc
, rspec
[0],
6315 /* range bound the fragthreshold */
6316 if (newfragthresh
< DOT11_MIN_FRAG_LEN
)
6319 else if (newfragthresh
>
6320 wlc
->usr_fragthresh
)
6322 wlc
->usr_fragthresh
;
6323 /* update the fragthresh and do txc update */
6324 if (wlc
->fragthresh
[queue
] !=
6325 (u16
) newfragthresh
) {
6326 wlc
->fragthresh
[queue
] =
6327 (u16
) newfragthresh
;
6332 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6333 wlc
->pub
->unit
, fifo_names
[queue
],
6334 RSPEC2RATE(rspec
[0]));
6336 if (dur
> wlc
->edcf_txop
[ac
])
6337 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6338 wlc
->pub
->unit
, __func__
,
6340 phylen
, wlc
->fragthresh
[queue
],
6341 dur
, wlc
->edcf_txop
[ac
]);
6351 void wlc_tbtt(struct wlc_info
*wlc
, d11regs_t
*regs
)
6353 wlc_bsscfg_t
*cfg
= wlc
->cfg
;
6355 WLCNTINCR(wlc
->pub
->_cnt
->tbtt
);
6357 if (BSSCFG_STA(cfg
)) {
6358 /* run watchdog here if the watchdog timer is not armed */
6359 if (WLC_WATCHDOG_TBTT(wlc
)) {
6362 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
6363 wlc
->WDarmed
= false;
6366 cur
= OSL_SYSUPTIME();
6367 delta
= cur
> wlc
->WDlast
? cur
- wlc
->WDlast
:
6368 (u32
) ~0 - wlc
->WDlast
+ cur
+ 1;
6369 if (delta
>= TIMER_INTERVAL_WATCHDOG
) {
6370 wlc_watchdog((void *)wlc
);
6374 wl_add_timer(wlc
->wl
, wlc
->wdtimer
,
6375 wlc_watchdog_backup_bi(wlc
), true);
6376 wlc
->WDarmed
= true;
6381 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6382 wlc
->qvalid
|= MCMD_DIRFRMQVAL
;
6386 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6387 void wlc_hwtimer_gptimer_set(struct wlc_info
*wlc
, uint us
)
6389 ASSERT(wlc
->pub
->corerev
>= 3); /* no gptimer in earlier revs */
6390 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, us
);
6393 void wlc_hwtimer_gptimer_abort(struct wlc_info
*wlc
)
6395 ASSERT(wlc
->pub
->corerev
>= 3);
6396 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6399 static void wlc_hwtimer_gptimer_cb(struct wlc_info
*wlc
)
6401 /* when interrupt is generated, the counter is loaded with last value
6402 * written and continue to decrement. So it has to be cleaned first
6404 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6408 * This fn has all the high level dpc processing from wlc_dpc.
6409 * POLICY: no macinstatus change, no bounding loop.
6410 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6412 void wlc_high_dpc(struct wlc_info
*wlc
, u32 macintstatus
)
6414 d11regs_t
*regs
= wlc
->regs
;
6417 static const bcm_bit_desc_t int_flags
[] = {
6418 {MI_MACSSPNDD
, "MACSSPNDD"},
6419 {MI_BCNTPL
, "BCNTPL"},
6421 {MI_BCNSUCCESS
, "BCNSUCCESS"},
6422 {MI_BCNCANCLD
, "BCNCANCLD"},
6423 {MI_ATIMWINEND
, "ATIMWINEND"},
6425 {MI_NSPECGEN_0
, "NSPECGEN_0"},
6426 {MI_NSPECGEN_1
, "NSPECGEN_1"},
6427 {MI_MACTXERR
, "MACTXERR"},
6428 {MI_NSPECGEN_3
, "NSPECGEN_3"},
6429 {MI_PHYTXERR
, "PHYTXERR"},
6433 {MI_DMAINT
, "DMAINT"},
6434 {MI_TXSTOP
, "TXSTOP"},
6436 {MI_BG_NOISE
, "BG_NOISE"},
6437 {MI_DTIM_TBTT
, "DTIM_TBTT"},
6439 {MI_PWRUP
, "PWRUP"},
6440 {MI_RFDISABLE
, "RFDISABLE"},
6442 {MI_PHYCHANGED
, "PHYCHANGED"},
6447 if (macintstatus
& ~(MI_TBTT
| MI_TXSTOP
)) {
6448 bcm_format_flags(int_flags
, macintstatus
, flagstr
,
6450 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6451 wlc
->pub
->unit
, macintstatus
, flagstr
);
6455 if (macintstatus
& MI_PRQ
) {
6456 /* Process probe request FIFO */
6457 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6460 /* TBTT indication */
6461 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6462 if (macintstatus
& (MI_TBTT
| MI_DTIM_TBTT
))
6463 wlc_tbtt(wlc
, regs
);
6465 if (macintstatus
& MI_GP0
) {
6466 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6467 wlc
->pub
->unit
, wlc
->pub
->now
);
6469 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6470 __func__
, wlc
->pub
->sih
->chip
,
6471 wlc
->pub
->sih
->chiprev
);
6473 WLCNTINCR(wlc
->pub
->_cnt
->psmwds
);
6479 /* gptimer timeout */
6480 if (macintstatus
& MI_TO
) {
6481 wlc_hwtimer_gptimer_cb(wlc
);
6484 if (macintstatus
& MI_RFDISABLE
) {
6485 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6487 R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
);
6488 /* delay the cleanup to wl_down in IBSS case */
6489 if ((R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
)) {
6491 wlc_bsscfg_t
*bsscfg
;
6492 FOREACH_BSS(wlc
, idx
, bsscfg
) {
6493 if (!BSSCFG_STA(bsscfg
) || !bsscfg
->enable
6496 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6502 /* send any enq'd tx packets. Just makes sure to jump start tx */
6503 if (!pktq_empty(&wlc
->active_queue
->q
))
6504 wlc_send_q(wlc
, wlc
->active_queue
);
6506 ASSERT(wlc_ps_check(wlc
));
6509 static void *wlc_15420war(struct wlc_info
*wlc
, uint queue
)
6511 struct hnddma_pub
*di
;
6514 ASSERT(queue
< NFIFO
);
6516 if ((D11REV_IS(wlc
->pub
->corerev
, 4))
6517 || (D11REV_GT(wlc
->pub
->corerev
, 6)))
6520 di
= wlc
->hw
->di
[queue
];
6523 /* get next packet, ignoring XmtStatus.Curr */
6524 p
= dma_getnexttxp(di
, HNDDMA_RANGE_ALL
);
6526 /* sw block tx dma */
6529 /* if tx ring is now empty, reset and re-init the tx dma channel */
6530 if (dma_txactive(wlc
->hw
->di
[queue
]) == 0) {
6531 WLCNTINCR(wlc
->pub
->_cnt
->txdmawar
);
6532 if (!dma_txreset(di
))
6533 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
6534 wlc
->pub
->unit
, __func__
, queue
);
6540 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
)
6543 /* the post-increment is used in STAY_AWAKE macro */
6544 if (wlc
->txpend16165war
++ == 0)
6545 wlc_set_ps_ctrl(wlc
);
6547 wlc
->txpend16165war
--;
6548 if (wlc
->txpend16165war
== 0)
6549 wlc_set_ps_ctrl(wlc
);
6553 /* process an individual tx_status_t */
6556 wlc_dotxstatus(struct wlc_info
*wlc
, tx_status_t
*txs
, u32 frm_tx2
)
6561 struct scb
*scb
= NULL
;
6563 struct osl_info
*osh
;
6564 int tx_rts
, tx_frame_count
, tx_rts_count
;
6565 uint totlen
, supr_status
;
6567 struct ieee80211_hdr
*h
;
6570 struct ieee80211_tx_info
*tx_info
;
6571 struct ieee80211_tx_rate
*txrate
;
6574 (void)(frm_tx2
); /* Compiler reference to avoid unused variable warning */
6576 /* discard intermediate indications for ucode with one legitimate case:
6577 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6578 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6579 * transmission count)
6581 if (!(txs
->status
& TX_STATUS_AMPDU
)
6582 && (txs
->status
& TX_STATUS_INTERMEDIATE
)) {
6583 WLCNTADD(wlc
->pub
->_cnt
->txnoack
,
6585 status
& TX_STATUS_FRM_RTX_MASK
) >>
6586 TX_STATUS_FRM_RTX_SHIFT
));
6587 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__
);
6592 queue
= txs
->frameid
& TXFID_QUEUE_MASK
;
6593 ASSERT(queue
< NFIFO
);
6594 if (queue
>= NFIFO
) {
6599 p
= GETNEXTTXP(wlc
, queue
);
6600 if (WLC_WAR16165(wlc
))
6601 wlc_war16165(wlc
, false);
6603 p
= wlc_15420war(wlc
, queue
);
6608 txh
= (d11txh_t
*) (p
->data
);
6609 mcl
= ltoh16(txh
->MacTxControlLow
);
6612 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6613 txs
->phyerr
, txh
->MainRates
);
6615 wlc_print_txdesc(txh
);
6617 wlc_print_txstatus(txs
);
6620 ASSERT(txs
->frameid
== htol16(txh
->TxFrameID
));
6621 if (txs
->frameid
!= htol16(txh
->TxFrameID
))
6624 tx_info
= IEEE80211_SKB_CB(p
);
6625 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
6626 fc
= ltoh16(h
->frame_control
);
6628 scb
= (struct scb
*)tx_info
->control
.sta
->drv_priv
;
6630 if (N_ENAB(wlc
->pub
)) {
6631 u8
*plcp
= (u8
*) (txh
+ 1);
6632 if (PLCP3_ISSGI(plcp
[3]))
6633 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_sgi
);
6634 if (PLCP3_ISSTBC(plcp
[3]))
6635 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_stbc
);
6638 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
6639 ASSERT((mcl
& TXC_AMPDU_MASK
) != TXC_AMPDU_NONE
);
6640 wlc_ampdu_dotxstatus(wlc
->ampdu
, scb
, p
, txs
);
6644 supr_status
= txs
->status
& TX_STATUS_SUPR_MASK
;
6645 if (supr_status
== TX_STATUS_SUPR_BADCH
)
6646 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6647 __func__
, CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
));
6649 tx_rts
= htol16(txh
->MacTxControlLow
) & TXC_SENDRTS
;
6651 (txs
->status
& TX_STATUS_FRM_RTX_MASK
) >> TX_STATUS_FRM_RTX_SHIFT
;
6653 (txs
->status
& TX_STATUS_RTS_RTX_MASK
) >> TX_STATUS_RTS_RTX_SHIFT
;
6655 lastframe
= (fc
& IEEE80211_FCTL_MOREFRAGS
) == 0;
6658 WL_ERROR("Not last frame!\n");
6661 ieee80211_tx_info_clear_status(tx_info
);
6662 if (queue
< AC_COUNT
) {
6663 sfbl
= WLC_WME_RETRY_SFB_GET(wlc
, wme_fifo2ac
[queue
]);
6664 lfbl
= WLC_WME_RETRY_LFB_GET(wlc
, wme_fifo2ac
[queue
]);
6670 txrate
= tx_info
->status
.rates
;
6671 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6672 if ((tx_frame_count
> sfbl
) && (txrate
[1].idx
>= 0)) {
6673 /* rate selection requested a fallback rate and we used it */
6674 txrate
->count
= lfbl
;
6675 txrate
[1].count
= tx_frame_count
- lfbl
;
6677 /* rate selection did not request fallback rate, or we didn't need it */
6678 txrate
->count
= tx_frame_count
;
6679 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6681 txrate
[1].count
= 0;
6684 /* clear the rest of the rates */
6685 for (i
= 2; i
< IEEE80211_TX_MAX_RATES
; i
++) {
6687 txrate
[i
].count
= 0;
6690 if (txs
->status
& TX_STATUS_ACK_RCV
)
6691 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
6694 totlen
= pkttotlen(osh
, p
);
6697 wlc_txfifo_complete(wlc
, queue
, 1);
6703 /* remove PLCP & Broadcom tx descriptor header */
6704 skb_pull(p
, D11_PHY_HDR_LEN
);
6705 skb_pull(p
, D11_TXH_LEN
);
6706 ieee80211_tx_status_irqsafe(wlc
->pub
->ieee_hw
, p
);
6707 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx_status
);
6709 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6718 pkt_buf_free_skb(osh
, p
, true);
6725 wlc_txfifo_complete(struct wlc_info
*wlc
, uint fifo
, s8 txpktpend
)
6727 TXPKTPENDDEC(wlc
, fifo
, txpktpend
);
6728 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6729 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
6731 /* There is more room; mark precedences related to this FIFO sendable */
6732 WLC_TX_FIFO_ENAB(wlc
, fifo
);
6733 ASSERT(TXPKTPENDGET(wlc
, fifo
) >= 0);
6735 if (!TXPKTPENDTOT(wlc
)) {
6736 if (wlc
->block_datafifo
& DATA_BLOCK_TX_SUPR
)
6737 wlc_bsscfg_tx_check(wlc
);
6740 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6741 if (AP_ENAB(wlc
->pub
) &&
6742 wlc
->bcmcfifo_drain
&& !TXPKTPENDGET(wlc
, TX_BCMC_FIFO
)) {
6743 wlc
->bcmcfifo_drain
= false;
6744 wlc_mhf(wlc
, MHF2
, MHF2_TXBCMC_NOW
, 0, WLC_BAND_AUTO
);
6747 /* figure out which bsscfg is being worked on... */
6750 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6751 * return the offset (in us) of the TSF from the last TBTT
6753 u32
wlc_calc_tbtt_offset(u32 bp
, u32 tsf_h
, u32 tsf_l
)
6755 u32 k
, btklo
, btkhi
, offset
;
6757 /* TBTT is always an even multiple of the beacon_interval,
6758 * so the TBTT less than or equal to the beacon timestamp is
6759 * the beacon timestamp minus the beacon timestamp modulo
6760 * the beacon interval.
6762 * TBTT = BT - (BT % BIu)
6763 * = (BTk - (BTk % BP)) * 2^10
6765 * BT = beacon timestamp (usec, 64bits)
6766 * BTk = beacon timestamp (Kusec, 54bits)
6767 * BP = beacon interval (Kusec, 16bits)
6768 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6770 * To keep the calculations in u32s, the modulo operation
6771 * on the high part of BT needs to be done in parts using the
6773 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6775 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6777 * So, if BTk[n] = u16 n [0,3] of BTk.
6778 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6779 * and the SUM term can be broken down:
6780 * (BTk[n] * 2^16n) % BP
6781 * (BTk[n] * (2^16n % BP)) % BP
6783 * Create a set of power of 2 mod BP constants:
6784 * K[n] = 2^(16n) % BP
6785 * = (K[n-1] * 2^16) % BP
6786 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6788 * BTk % BP = BTk[0-1] % BP +
6789 * (BTk[2] * K[2]) % BP +
6790 * (BTk[3] * K[3]) % BP
6792 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6795 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6796 btklo
= (tsf_h
<< 22) | (tsf_l
>> 10);
6797 btkhi
= tsf_h
>> 10;
6799 /* offset = BTk % BP */
6800 offset
= btklo
% bp
;
6802 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6803 k
= (u32
) (1 << 16) % bp
;
6804 k
= (u32
) (k
* 1 << 16) % (u32
) bp
;
6806 /* offset += (BTk[2] * K[2]) % BP */
6807 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6810 btkhi
= btkhi
>> 16;
6812 /* k[3] = (K[2] * 2^16) % BP */
6815 /* offset += (BTk[3] * K[3]) % BP */
6816 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6818 offset
= offset
% bp
;
6820 /* convert offset from kus to us by shifting up 10 bits and
6821 * add in the low 10 bits of tsf that we ignored
6823 offset
= (offset
<< 10) + (tsf_l
& 0x3FF);
6828 /* Update beacon listen interval in shared memory */
6829 void wlc_bcn_li_upd(struct wlc_info
*wlc
)
6831 if (AP_ENAB(wlc
->pub
))
6834 /* wake up every DTIM is the default */
6835 if (wlc
->bcn_li_dtim
== 1)
6836 wlc_write_shm(wlc
, M_BCN_LI
, 0);
6838 wlc_write_shm(wlc
, M_BCN_LI
,
6839 (wlc
->bcn_li_dtim
<< 8) | wlc
->bcn_li_bcn
);
6843 prep_mac80211_status(struct wlc_info
*wlc
, d11rxhdr_t
*rxh
, struct sk_buff
*p
,
6844 struct ieee80211_rx_status
*rx_status
)
6847 wlc_d11rxhdr_t
*wlc_rxh
= (wlc_d11rxhdr_t
*) rxh
;
6851 unsigned char *plcp
;
6853 wlc_read_tsf(wlc
, &tsf_l
, &tsf_h
); /* mactime */
6854 rx_status
->mactime
= tsf_h
;
6855 rx_status
->mactime
<<= 32;
6856 rx_status
->mactime
|= tsf_l
;
6857 rx_status
->flag
|= RX_FLAG_TSFT
;
6859 channel
= WLC_CHAN_CHANNEL(rxh
->RxChan
);
6861 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
6863 rx_status
->band
= IEEE80211_BAND_5GHZ
;
6864 rx_status
->freq
= ieee80211_ofdm_chan_to_freq(
6865 WF_CHAN_FACTOR_5_G
/2, channel
);
6868 rx_status
->band
= IEEE80211_BAND_2GHZ
;
6869 rx_status
->freq
= ieee80211_dsss_chan_to_freq(channel
);
6872 rx_status
->signal
= wlc_rxh
->rssi
; /* signal */
6876 rx_status
->antenna
= (rxh
->PhyRxStatus_0
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0; /* ant */
6880 rspec
= wlc_compute_rspec(rxh
, plcp
);
6881 if (IS_MCS(rspec
)) {
6882 rx_status
->rate_idx
= rspec
& RSPEC_RATE_MASK
;
6883 rx_status
->flag
|= RX_FLAG_HT
;
6884 if (RSPEC_IS40MHZ(rspec
))
6885 rx_status
->flag
|= RX_FLAG_40MHZ
;
6887 switch (RSPEC2RATE(rspec
)) {
6889 rx_status
->rate_idx
= 0;
6892 rx_status
->rate_idx
= 1;
6895 rx_status
->rate_idx
= 2;
6898 rx_status
->rate_idx
= 3;
6901 rx_status
->rate_idx
= 4;
6904 rx_status
->rate_idx
= 5;
6907 rx_status
->rate_idx
= 6;
6910 rx_status
->rate_idx
= 7;
6913 rx_status
->rate_idx
= 8;
6916 rx_status
->rate_idx
= 9;
6919 rx_status
->rate_idx
= 10;
6922 rx_status
->rate_idx
= 11;
6925 WL_ERROR("%s: Unknown rate\n", __func__
);
6928 /* Determine short preamble and rate_idx */
6930 if (IS_CCK(rspec
)) {
6931 if (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
)
6932 WL_ERROR("Short CCK\n");
6933 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6934 } else if (IS_OFDM(rspec
)) {
6935 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6937 WL_ERROR("%s: Unknown modulation\n", __func__
);
6941 if (PLCP3_ISSGI(plcp
[3]))
6942 rx_status
->flag
|= RX_FLAG_SHORT_GI
;
6944 if (rxh
->RxStatus1
& RXS_DECERR
) {
6945 rx_status
->flag
|= RX_FLAG_FAILED_PLCP_CRC
;
6946 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__
);
6948 if (rxh
->RxStatus1
& RXS_FCSERR
) {
6949 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
6950 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__
);
6955 wlc_recvctl(struct wlc_info
*wlc
, struct osl_info
*osh
, d11rxhdr_t
*rxh
,
6959 struct ieee80211_rx_status rx_status
;
6961 struct sk_buff
*skb
= p
;
6964 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
6965 * Test for INTERMEDIATE like so:
6966 * if (!(plcp[0] | plcp[1] | plcp[2]))
6969 memset(&rx_status
, 0, sizeof(rx_status
));
6970 prep_mac80211_status(wlc
, rxh
, p
, &rx_status
);
6972 /* mac header+body length, exclude CRC and plcp header */
6973 len_mpdu
= p
->len
- D11_PHY_HDR_LEN
- FCS_LEN
;
6974 skb_pull(p
, D11_PHY_HDR_LEN
);
6975 __skb_trim(p
, len_mpdu
);
6980 ASSERT(IS_ALIGNED((unsigned long)skb
->data
, 2));
6982 memcpy(IEEE80211_SKB_RXCB(p
), &rx_status
, sizeof(rx_status
));
6983 ieee80211_rx_irqsafe(wlc
->pub
->ieee_hw
, p
);
6985 WLCNTINCR(wlc
->pub
->_cnt
->ieee_rx
);
6990 void wlc_bss_list_free(struct wlc_info
*wlc
, wlc_bss_list_t
*bss_list
)
6996 WL_ERROR("%s: Attempting to free NULL list\n", __func__
);
6999 /* inspect all BSS descriptor */
7000 for (index
= 0; index
< bss_list
->count
; index
++) {
7001 bi
= bss_list
->ptrs
[index
];
7004 bss_list
->ptrs
[index
] = NULL
;
7007 bss_list
->count
= 0;
7010 /* Process received frames */
7012 * Return true if more frames need to be processed. false otherwise.
7013 * Param 'bound' indicates max. # frames to process before break out.
7016 void BCMFASTPATH
wlc_recv(struct wlc_info
*wlc
, struct sk_buff
*p
)
7019 struct ieee80211_hdr
*h
;
7020 struct osl_info
*osh
;
7025 WL_TRACE("wl%d: wlc_recv\n", wlc
->pub
->unit
);
7029 /* frame starts with rxhdr */
7030 rxh
= (d11rxhdr_t
*) (p
->data
);
7032 /* strip off rxhdr */
7033 skb_pull(p
, wlc
->hwrxoff
);
7035 /* fixup rx header endianness */
7036 ltoh16_buf((void *)rxh
, sizeof(d11rxhdr_t
));
7038 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7039 if (rxh
->RxStatus1
& RXS_PBPRES
) {
7041 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7042 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7043 wlc
->pub
->unit
, p
->len
);
7049 h
= (struct ieee80211_hdr
*)(p
->data
+ D11_PHY_HDR_LEN
);
7052 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7053 if (wlc
->pub
->mac80211_state
& MAC80211_PROMISC_BCNS
) {
7054 WL_ERROR("FCSERR while scanning******* - tossing\n");
7057 WL_ERROR("RCSERR!!!\n");
7062 /* check received pkt has at least frame control field */
7063 if (len
>= D11_PHY_HDR_LEN
+ sizeof(h
->frame_control
)) {
7064 fc
= ltoh16(h
->frame_control
);
7066 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7070 is_amsdu
= rxh
->RxStatus2
& RXS_AMSDU_MASK
;
7072 /* explicitly test bad src address to avoid sending bad deauth */
7074 /* CTS and ACK CTL frames are w/o a2 */
7075 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
||
7076 (fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
7077 if ((is_zero_ether_addr(h
->addr2
) ||
7078 is_multicast_ether_addr(h
->addr2
))) {
7079 WL_ERROR("wl%d: %s: dropping a frame with "
7080 "invalid src mac address, a2: %pM\n",
7081 wlc
->pub
->unit
, __func__
, h
->addr2
);
7082 WLCNTINCR(wlc
->pub
->_cnt
->rxbadsrcmac
);
7085 WLCNTINCR(wlc
->pub
->_cnt
->rxfrag
);
7089 /* due to sheer numbers, toss out probe reqs for now */
7090 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
7091 if ((fc
& FC_KIND_MASK
) == FC_PROBE_REQ
)
7096 WL_ERROR("%s: is_amsdu causing toss\n", __func__
);
7100 wlc_recvctl(wlc
, osh
, rxh
, p
);
7104 pkt_buf_free_skb(osh
, p
, false);
7107 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7108 * number of bytes goes in the length field
7110 * Formula given by HT PHY Spec v 1.13
7111 * len = 3(nsyms + nstream + 3) - 3
7114 wlc_calc_lsig_len(struct wlc_info
*wlc
, ratespec_t ratespec
, uint mac_len
)
7116 uint nsyms
, len
= 0, kNdps
;
7118 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7119 wlc
->pub
->unit
, RSPEC2RATE(ratespec
), mac_len
);
7121 if (IS_MCS(ratespec
)) {
7122 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7123 /* MCS_TXS(mcs) returns num tx streams - 1 */
7124 int tot_streams
= (MCS_TXS(mcs
) + 1) + RSPEC_STC(ratespec
);
7126 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7127 /* the payload duration calculation matches that of regular ofdm */
7128 /* 1000Ndbps = kbps * 4 */
7130 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7131 RSPEC_ISSGI(ratespec
)) * 4;
7133 if (RSPEC_STC(ratespec
) == 0)
7134 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7136 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7137 APHY_TAIL_NBITS
) * 1000, kNdps
);
7139 /* STBC needs to have even number of symbols */
7142 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7143 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7145 nsyms
+= (tot_streams
+ 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7146 /* 3 bytes/symbol @ legacy 6Mbps rate */
7147 len
= (3 * nsyms
) - 3; /* (-3) excluding service bits and tail bits */
7153 /* calculate frame duration of a given rate and length, return time in usec unit */
7155 wlc_calc_frame_time(struct wlc_info
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7158 uint nsyms
, dur
= 0, Ndps
, kNdps
;
7159 uint rate
= RSPEC2RATE(ratespec
);
7163 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc
->pub
->unit
);
7167 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7168 wlc
->pub
->unit
, ratespec
, preamble_type
, mac_len
);
7170 if (IS_MCS(ratespec
)) {
7171 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7172 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7173 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7174 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type
));
7176 dur
= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7177 if (preamble_type
== WLC_MM_PREAMBLE
)
7179 /* 1000Ndbps = kbps * 4 */
7181 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7182 RSPEC_ISSGI(ratespec
)) * 4;
7184 if (RSPEC_STC(ratespec
) == 0)
7185 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7187 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7188 APHY_TAIL_NBITS
) * 1000, kNdps
);
7190 /* STBC needs to have even number of symbols */
7193 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7194 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7196 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7197 if (BAND_2G(wlc
->band
->bandtype
))
7198 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7199 } else if (IS_OFDM(rate
)) {
7200 dur
= APHY_PREAMBLE_TIME
;
7201 dur
+= APHY_SIGNAL_TIME
;
7202 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7204 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7206 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+ APHY_TAIL_NBITS
),
7208 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7209 if (BAND_2G(wlc
->band
->bandtype
))
7210 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7212 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7213 mac_len
= mac_len
* 8 * 2;
7214 /* calc ceiling of bits/rate = microseconds of air time */
7215 dur
= (mac_len
+ rate
- 1) / rate
;
7216 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7217 dur
+= BPHY_PLCP_SHORT_TIME
;
7219 dur
+= BPHY_PLCP_TIME
;
7224 /* The opposite of wlc_calc_frame_time */
7226 wlc_calc_frame_len(struct wlc_info
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7229 uint nsyms
, mac_len
, Ndps
, kNdps
;
7230 uint rate
= RSPEC2RATE(ratespec
);
7232 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7233 wlc
->pub
->unit
, ratespec
, preamble_type
, dur
);
7235 if (IS_MCS(ratespec
)) {
7236 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7237 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7238 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7239 dur
-= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7240 /* payload calculation matches that of regular ofdm */
7241 if (BAND_2G(wlc
->band
->bandtype
))
7242 dur
-= DOT11_OFDM_SIGNAL_EXTENSION
;
7243 /* kNdbps = kbps * 4 */
7245 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7246 RSPEC_ISSGI(ratespec
)) * 4;
7247 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7250 ((APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
) * 1000)) / 8000;
7251 } else if (IS_OFDM(ratespec
)) {
7252 dur
-= APHY_PREAMBLE_TIME
;
7253 dur
-= APHY_SIGNAL_TIME
;
7254 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7256 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7259 (APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
)) / 8;
7261 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7262 dur
-= BPHY_PLCP_SHORT_TIME
;
7264 dur
-= BPHY_PLCP_TIME
;
7265 mac_len
= dur
* rate
;
7266 /* divide out factor of 2 in rate (1/2 mbps) */
7267 mac_len
= mac_len
/ 8 / 2;
7273 wlc_calc_ba_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7275 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7276 wlc
->pub
->unit
, rspec
, preamble_type
);
7277 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7278 * or equal to the rate of the immediately previous frame in the FES
7280 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7281 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7283 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7284 return wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7285 (DOT11_BA_LEN
+ DOT11_BA_BITMAP_LEN
+
7289 static uint BCMFASTPATH
7290 wlc_calc_ack_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7294 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7295 wlc
->pub
->unit
, rspec
, preamble_type
);
7296 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7297 * or equal to the rate of the immediately previous frame in the FES
7299 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7300 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7302 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7304 wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7305 (DOT11_ACK_LEN
+ FCS_LEN
));
7310 wlc_calc_cts_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7312 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7313 wlc
->pub
->unit
, rspec
, preamble_type
);
7314 return wlc_calc_ack_time(wlc
, rspec
, preamble_type
);
7317 /* derive wlc->band->basic_rate[] table from 'rateset' */
7318 void wlc_rate_lookup_init(struct wlc_info
*wlc
, wlc_rateset_t
*rateset
)
7324 u8
*br
= wlc
->band
->basic_rate
;
7327 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7328 memset(br
, 0, WLC_MAXRATE
+ 1);
7330 /* For each basic rate in the rates list, make an entry in the
7331 * best basic lookup.
7333 for (i
= 0; i
< rateset
->count
; i
++) {
7334 /* only make an entry for a basic rate */
7335 if (!(rateset
->rates
[i
] & WLC_RATE_FLAG
))
7338 /* mask off basic bit */
7339 rate
= (rateset
->rates
[i
] & RATE_MASK
);
7341 if (rate
> WLC_MAXRATE
) {
7342 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7350 /* The rate lookup table now has non-zero entries for each
7351 * basic rate, equal to the basic rate: br[basicN] = basicN
7353 * To look up the best basic rate corresponding to any
7354 * particular rate, code can use the basic_rate table
7357 * basic_rate = wlc->band->basic_rate[tx_rate]
7359 * Make sure there is a best basic rate entry for
7360 * every rate by walking up the table from low rates
7361 * to high, filling in holes in the lookup table
7364 for (i
= 0; i
< wlc
->band
->hw_rateset
.count
; i
++) {
7365 rate
= wlc
->band
->hw_rateset
.rates
[i
];
7366 ASSERT(rate
<= WLC_MAXRATE
);
7368 if (br
[rate
] != 0) {
7369 /* This rate is a basic rate.
7370 * Keep track of the best basic rate so far by
7381 /* This rate is not a basic rate so figure out the
7382 * best basic rate less than this rate and fill in
7383 * the hole in the table
7386 br
[rate
] = IS_OFDM(rate
) ? ofdm_basic
: cck_basic
;
7391 if (IS_OFDM(rate
)) {
7392 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7393 if (rate
>= WLC_RATE_24M
)
7394 mandatory
= WLC_RATE_24M
;
7395 else if (rate
>= WLC_RATE_12M
)
7396 mandatory
= WLC_RATE_12M
;
7398 mandatory
= WLC_RATE_6M
;
7400 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7404 br
[rate
] = mandatory
;
7408 static void wlc_write_rate_shm(struct wlc_info
*wlc
, u8 rate
, u8 basic_rate
)
7411 u8 basic_phy_rate
, basic_index
;
7412 u16 dir_table
, basic_table
;
7415 /* Shared memory address for the table we are reading */
7416 dir_table
= IS_OFDM(basic_rate
) ? M_RT_DIRMAP_A
: M_RT_DIRMAP_B
;
7418 /* Shared memory address for the table we are writing */
7419 basic_table
= IS_OFDM(rate
) ? M_RT_BBRSMAP_A
: M_RT_BBRSMAP_B
;
7422 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7423 * the index into the rate table.
7425 phy_rate
= rate_info
[rate
] & RATE_MASK
;
7426 basic_phy_rate
= rate_info
[basic_rate
] & RATE_MASK
;
7427 index
= phy_rate
& 0xf;
7428 basic_index
= basic_phy_rate
& 0xf;
7430 /* Find the SHM pointer to the ACK rate entry by looking in the
7433 basic_ptr
= wlc_read_shm(wlc
, (dir_table
+ basic_index
* 2));
7435 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7436 * to the correct basic rate for the given incoming rate
7438 wlc_write_shm(wlc
, (basic_table
+ index
* 2), basic_ptr
);
7441 static const wlc_rateset_t
*wlc_rateset_get_hwrs(struct wlc_info
*wlc
)
7443 const wlc_rateset_t
*rs_dflt
;
7445 if (WLC_PHY_11N_CAP(wlc
->band
)) {
7446 if (BAND_5G(wlc
->band
->bandtype
))
7447 rs_dflt
= &ofdm_mimo_rates
;
7449 rs_dflt
= &cck_ofdm_mimo_rates
;
7450 } else if (wlc
->band
->gmode
)
7451 rs_dflt
= &cck_ofdm_rates
;
7453 rs_dflt
= &cck_rates
;
7458 void wlc_set_ratetable(struct wlc_info
*wlc
)
7460 const wlc_rateset_t
*rs_dflt
;
7462 u8 rate
, basic_rate
;
7465 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7466 ASSERT(rs_dflt
!= NULL
);
7468 wlc_rateset_copy(rs_dflt
, &rs
);
7469 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7471 /* walk the phy rate table and update SHM basic rate lookup table */
7472 for (i
= 0; i
< rs
.count
; i
++) {
7473 rate
= rs
.rates
[i
] & RATE_MASK
;
7475 /* for a given rate WLC_BASIC_RATE returns the rate at
7476 * which a response ACK/CTS should be sent.
7478 basic_rate
= WLC_BASIC_RATE(wlc
, rate
);
7479 if (basic_rate
== 0) {
7480 /* This should only happen if we are using a
7481 * restricted rateset.
7483 basic_rate
= rs
.rates
[0] & RATE_MASK
;
7486 wlc_write_rate_shm(wlc
, rate
, basic_rate
);
7491 * Return true if the specified rate is supported by the specified band.
7492 * WLC_BAND_AUTO indicates the current band.
7494 bool wlc_valid_rate(struct wlc_info
*wlc
, ratespec_t rspec
, int band
,
7497 wlc_rateset_t
*hw_rateset
;
7500 if ((band
== WLC_BAND_AUTO
) || (band
== wlc
->band
->bandtype
)) {
7501 hw_rateset
= &wlc
->band
->hw_rateset
;
7502 } else if (NBANDS(wlc
) > 1) {
7503 hw_rateset
= &wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->hw_rateset
;
7505 /* other band specified and we are a single band device */
7509 /* check if this is a mimo rate */
7510 if (IS_MCS(rspec
)) {
7511 if (!VALID_MCS((rspec
& RSPEC_RATE_MASK
)))
7514 return isset(hw_rateset
->mcs
, (rspec
& RSPEC_RATE_MASK
));
7517 for (i
= 0; i
< hw_rateset
->count
; i
++)
7518 if (hw_rateset
->rates
[i
] == RSPEC2RATE(rspec
))
7522 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7523 wlc
->pub
->unit
, rspec
);
7529 static void wlc_update_mimo_band_bwcap(struct wlc_info
*wlc
, u8 bwcap
)
7532 struct wlcband
*band
;
7534 for (i
= 0; i
< NBANDS(wlc
); i
++) {
7535 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
7537 band
= wlc
->bandstate
[i
];
7538 if (band
->bandtype
== WLC_BAND_5G
) {
7539 if ((bwcap
== WLC_N_BW_40ALL
)
7540 || (bwcap
== WLC_N_BW_20IN2G_40IN5G
))
7541 band
->mimo_cap_40
= true;
7543 band
->mimo_cap_40
= false;
7545 ASSERT(band
->bandtype
== WLC_BAND_2G
);
7546 if (bwcap
== WLC_N_BW_40ALL
)
7547 band
->mimo_cap_40
= true;
7549 band
->mimo_cap_40
= false;
7553 wlc
->mimo_band_bwcap
= bwcap
;
7556 void wlc_mod_prb_rsp_rate_table(struct wlc_info
*wlc
, uint frame_len
)
7558 const wlc_rateset_t
*rs_dflt
;
7562 u8 plcp
[D11_PHY_HDR_LEN
];
7566 sifs
= SIFS(wlc
->band
);
7568 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7569 ASSERT(rs_dflt
!= NULL
);
7571 wlc_rateset_copy(rs_dflt
, &rs
);
7572 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7574 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7575 for (i
= 0; i
< rs
.count
; i
++) {
7576 rate
= rs
.rates
[i
] & RATE_MASK
;
7578 entry_ptr
= wlc_rate_shm_offset(wlc
, rate
);
7580 /* Calculate the Probe Response PLCP for the given rate */
7581 wlc_compute_plcp(wlc
, rate
, frame_len
, plcp
);
7583 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7585 (u16
) wlc_calc_frame_time(wlc
, rate
, WLC_LONG_PREAMBLE
,
7589 /* Update the SHM Rate Table entry Probe Response values */
7590 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
,
7591 (u16
) (plcp
[0] + (plcp
[1] << 8)));
7592 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
+ 2,
7593 (u16
) (plcp
[2] + (plcp
[3] << 8)));
7594 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_DUR_POS
, dur
);
7599 wlc_compute_bcntsfoff(struct wlc_info
*wlc
, ratespec_t rspec
,
7600 bool short_preamble
, bool phydelay
)
7604 if (IS_MCS(rspec
)) {
7605 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7606 wlc
->pub
->unit
, rspec
);
7607 } else if (IS_OFDM(rspec
)) {
7608 /* tx delay from MAC through phy to air (2.1 usec) +
7609 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7610 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7611 * bytes at beacon rate)
7613 bcntsfoff
+= phydelay
? D11A_PHY_TX_DELAY
: 0;
7614 bcntsfoff
+= APHY_PREAMBLE_TIME
+ APHY_SIGNAL_TIME
;
7616 wlc_compute_airtime(wlc
, rspec
,
7617 APHY_SERVICE_NBITS
/ 8 +
7620 /* tx delay from MAC through phy to air (3.4 usec) +
7621 * phy header time (long preamble + PLCP == 192 usec) +
7622 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7624 bcntsfoff
+= phydelay
? D11B_PHY_TX_DELAY
: 0;
7626 short_preamble
? D11B_PHY_SPREHDR_TIME
:
7627 D11B_PHY_LPREHDR_TIME
;
7628 bcntsfoff
+= wlc_compute_airtime(wlc
, rspec
, DOT11_MAC_HDR_LEN
);
7630 return (u16
) (bcntsfoff
);
7633 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7635 * PLCP header is 6 bytes.
7636 * 802.11 A3 header is 24 bytes.
7637 * Max beacon frame body template length is 112 bytes.
7638 * Max probe resp frame body template length is 110 bytes.
7640 * *len on input contains the max length of the packet available.
7642 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7643 * and included up to, but not including, the 4 byte FCS.
7646 wlc_bcn_prb_template(struct wlc_info
*wlc
, uint type
, ratespec_t bcn_rspec
,
7647 wlc_bsscfg_t
*cfg
, u16
*buf
, int *len
)
7649 static const u8 ether_bcast
[ETH_ALEN
] = {255, 255, 255, 255, 255, 255};
7650 cck_phy_hdr_t
*plcp
;
7651 struct ieee80211_mgmt
*h
;
7652 int hdr_len
, body_len
;
7654 ASSERT(*len
>= 142);
7655 ASSERT(type
== FC_BEACON
|| type
== FC_PROBE_RESP
);
7657 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7658 hdr_len
= DOT11_MAC_HDR_LEN
;
7660 hdr_len
= D11_PHY_HDR_LEN
+ DOT11_MAC_HDR_LEN
;
7661 body_len
= *len
- hdr_len
; /* calc buffer size provided for frame body */
7663 *len
= hdr_len
+ body_len
; /* return actual size */
7665 /* format PHY and MAC headers */
7666 memset((char *)buf
, 0, hdr_len
);
7668 plcp
= (cck_phy_hdr_t
*) buf
;
7670 /* PLCP for Probe Response frames are filled in from core's rate table */
7671 if (type
== FC_BEACON
&& !MBSS_BCN_ENAB(cfg
)) {
7673 wlc_compute_plcp(wlc
, bcn_rspec
,
7674 (DOT11_MAC_HDR_LEN
+ body_len
+ FCS_LEN
),
7678 /* "Regular" and 16 MBSS but not for 4 MBSS */
7679 /* Update the phytxctl for the beacon based on the rspec */
7680 if (!SOFTBCN_ENAB(cfg
))
7681 wlc_beacon_phytxctl_txant_upd(wlc
, bcn_rspec
);
7683 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7684 h
= (struct ieee80211_mgmt
*)&plcp
[0];
7686 h
= (struct ieee80211_mgmt
*)&plcp
[1];
7688 /* fill in 802.11 header */
7689 h
->frame_control
= htol16((u16
) type
);
7691 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7692 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7693 if (type
== FC_BEACON
)
7694 bcopy((const char *)ðer_bcast
, (char *)&h
->da
,
7696 bcopy((char *)&cfg
->cur_etheraddr
, (char *)&h
->sa
, ETH_ALEN
);
7697 bcopy((char *)&cfg
->BSSID
, (char *)&h
->bssid
, ETH_ALEN
);
7699 /* SEQ filled in by MAC */
7704 int wlc_get_header_len()
7709 /* Update a beacon for a particular BSS
7710 * For MBSS, this updates the software template and sets "latest" to the index of the
7712 * Otherwise, it updates the hardware template.
7714 void wlc_bss_update_beacon(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
)
7716 int len
= BCN_TMPL_LEN
;
7718 /* Clear the soft intmask */
7719 wlc
->defmacintmask
&= ~MI_BCNTPL
;
7721 if (!cfg
->up
) { /* Only allow updates on an UP bss */
7725 if (MBSS_BCN_ENAB(cfg
)) { /* Optimize: Some of if/else could be combined */
7726 } else if (HWBCN_ENAB(cfg
)) { /* Hardware beaconing for this config */
7727 u16 bcn
[BCN_TMPL_LEN
/ 2];
7728 u32 both_valid
= MCMD_BCN0VLD
| MCMD_BCN1VLD
;
7729 d11regs_t
*regs
= wlc
->regs
;
7730 struct osl_info
*osh
= NULL
;
7734 /* Check if both templates are in use, if so sched. an interrupt
7735 * that will call back into this routine
7737 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7738 /* clear any previous status */
7739 W_REG(osh
, ®s
->macintstatus
, MI_BCNTPL
);
7741 /* Check that after scheduling the interrupt both of the
7742 * templates are still busy. if not clear the int. & remask
7744 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7745 wlc
->defmacintmask
|= MI_BCNTPL
;
7750 wlc_lowest_basic_rspec(wlc
, &cfg
->current_bss
->rateset
);
7751 ASSERT(wlc_valid_rate
7752 (wlc
, wlc
->bcn_rspec
,
7753 CHSPEC_IS2G(cfg
->current_bss
->
7754 chanspec
) ? WLC_BAND_2G
: WLC_BAND_5G
,
7757 /* update the template and ucode shm */
7758 wlc_bcn_prb_template(wlc
, FC_BEACON
, wlc
->bcn_rspec
, cfg
, bcn
,
7760 wlc_write_hw_bcntemplates(wlc
, bcn
, len
, false);
7765 * Update all beacons for the system.
7767 void wlc_update_beacon(struct wlc_info
*wlc
)
7770 wlc_bsscfg_t
*bsscfg
;
7772 /* update AP or IBSS beacons */
7773 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7774 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7775 wlc_bss_update_beacon(wlc
, bsscfg
);
7779 /* Write ssid into shared memory */
7780 void wlc_shm_ssid_upd(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
)
7782 u8
*ssidptr
= cfg
->SSID
;
7784 u8 ssidbuf
[IEEE80211_MAX_SSID_LEN
];
7786 /* padding the ssid with zero and copy it into shm */
7787 memset(ssidbuf
, 0, IEEE80211_MAX_SSID_LEN
);
7788 bcopy(ssidptr
, ssidbuf
, cfg
->SSID_len
);
7790 wlc_copyto_shm(wlc
, base
, ssidbuf
, IEEE80211_MAX_SSID_LEN
);
7792 if (!MBSS_BCN_ENAB(cfg
))
7793 wlc_write_shm(wlc
, M_SSIDLEN
, (u16
) cfg
->SSID_len
);
7796 void wlc_update_probe_resp(struct wlc_info
*wlc
, bool suspend
)
7799 wlc_bsscfg_t
*bsscfg
;
7801 /* update AP or IBSS probe responses */
7802 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7803 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7804 wlc_bss_update_probe_resp(wlc
, bsscfg
, suspend
);
7809 wlc_bss_update_probe_resp(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
, bool suspend
)
7811 u16 prb_resp
[BCN_TMPL_LEN
/ 2];
7812 int len
= BCN_TMPL_LEN
;
7814 /* write the probe response to hardware, or save in the config structure */
7815 if (!MBSS_PRB_ENAB(cfg
)) {
7817 /* create the probe response template */
7818 wlc_bcn_prb_template(wlc
, FC_PROBE_RESP
, 0, cfg
, prb_resp
,
7822 wlc_suspend_mac_and_wait(wlc
);
7824 /* write the probe response into the template region */
7825 wlc_bmac_write_template_ram(wlc
->hw
, T_PRS_TPL_BASE
,
7826 (len
+ 3) & ~3, prb_resp
);
7828 /* write the length of the probe response frame (+PLCP/-FCS) */
7829 wlc_write_shm(wlc
, M_PRB_RESP_FRM_LEN
, (u16
) len
);
7831 /* write the SSID and SSID length */
7832 wlc_shm_ssid_upd(wlc
, cfg
);
7835 * Write PLCP headers and durations for probe response frames at all rates.
7836 * Use the actual frame length covered by the PLCP header for the call to
7837 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7839 len
+= (-D11_PHY_HDR_LEN
+ FCS_LEN
);
7840 wlc_mod_prb_rsp_rate_table(wlc
, (u16
) len
);
7843 wlc_enable_mac(wlc
);
7844 } else { /* Generating probe resp in sw; update local template */
7845 ASSERT(0 && "No software probe response support without MBSS");
7849 /* prepares pdu for transmission. returns BCM error codes */
7850 int wlc_prep_pdu(struct wlc_info
*wlc
, struct sk_buff
*pdu
, uint
*fifop
)
7852 struct osl_info
*osh
;
7855 struct ieee80211_hdr
*h
;
7862 txh
= (d11txh_t
*) (pdu
->data
);
7864 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
7866 fc
= ltoh16(h
->frame_control
);
7868 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7869 fifo
= ltoh16(txh
->TxFrameID
) & TXFID_QUEUE_MASK
;
7875 /* return if insufficient dma resources */
7876 if (TXAVAIL(wlc
, fifo
) < MAX_DMA_SEGS
) {
7877 /* Mark precedences related to this FIFO, unsendable */
7878 WLC_TX_FIFO_CLEAR(wlc
, fifo
);
7882 if ((ltoh16(txh
->MacFrameControl
) & IEEE80211_FCTL_FTYPE
) !=
7883 IEEE80211_FTYPE_DATA
)
7884 WLCNTINCR(wlc
->pub
->_cnt
->txctl
);
7889 /* init tx reported rate mechanism */
7890 void wlc_reprate_init(struct wlc_info
*wlc
)
7893 wlc_bsscfg_t
*bsscfg
;
7895 FOREACH_BSS(wlc
, i
, bsscfg
) {
7896 wlc_bsscfg_reprate_init(bsscfg
);
7900 /* per bsscfg init tx reported rate mechanism */
7901 void wlc_bsscfg_reprate_init(wlc_bsscfg_t
*bsscfg
)
7903 bsscfg
->txrspecidx
= 0;
7904 memset((char *)bsscfg
->txrspec
, 0, sizeof(bsscfg
->txrspec
));
7907 /* Retrieve a consolidated set of revision information,
7908 * typically for the WLC_GET_REVINFO ioctl
7910 int wlc_get_revision_info(struct wlc_info
*wlc
, void *buf
, uint len
)
7912 wlc_rev_info_t
*rinfo
= (wlc_rev_info_t
*) buf
;
7914 if (len
< WL_REV_INFO_LEGACY_LENGTH
)
7915 return BCME_BUFTOOSHORT
;
7917 rinfo
->vendorid
= wlc
->vendorid
;
7918 rinfo
->deviceid
= wlc
->deviceid
;
7919 rinfo
->radiorev
= (wlc
->band
->radiorev
<< IDCODE_REV_SHIFT
) |
7920 (wlc
->band
->radioid
<< IDCODE_ID_SHIFT
);
7921 rinfo
->chiprev
= wlc
->pub
->sih
->chiprev
;
7922 rinfo
->corerev
= wlc
->pub
->corerev
;
7923 rinfo
->boardid
= wlc
->pub
->sih
->boardtype
;
7924 rinfo
->boardvendor
= wlc
->pub
->sih
->boardvendor
;
7925 rinfo
->boardrev
= wlc
->pub
->boardrev
;
7926 rinfo
->ucoderev
= wlc
->ucode_rev
;
7927 rinfo
->driverrev
= EPI_VERSION_NUM
;
7928 rinfo
->bus
= wlc
->pub
->sih
->bustype
;
7929 rinfo
->chipnum
= wlc
->pub
->sih
->chip
;
7931 if (len
>= (offsetof(wlc_rev_info_t
, chippkg
))) {
7932 rinfo
->phytype
= wlc
->band
->phytype
;
7933 rinfo
->phyrev
= wlc
->band
->phyrev
;
7934 rinfo
->anarev
= 0; /* obsolete stuff, suppress */
7937 if (len
>= sizeof(*rinfo
)) {
7938 rinfo
->chippkg
= wlc
->pub
->sih
->chippkg
;
7944 void wlc_default_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
7946 wlc_rateset_default(rs
, NULL
, wlc
->band
->phytype
, wlc
->band
->bandtype
,
7947 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7948 CHSPEC_WLC_BW(wlc
->default_bss
->chanspec
),
7949 wlc
->stf
->txstreams
);
7952 static void wlc_bss_default_init(struct wlc_info
*wlc
)
7954 chanspec_t chanspec
;
7955 struct wlcband
*band
;
7956 wlc_bss_info_t
*bi
= wlc
->default_bss
;
7958 /* init default and target BSS with some sane initial values */
7959 memset((char *)(bi
), 0, sizeof(wlc_bss_info_t
));
7960 bi
->beacon_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? BEACON_INTERVAL_DEF_QT
:
7961 BEACON_INTERVAL_DEFAULT
;
7962 bi
->dtim_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? DTIM_INTERVAL_DEF_QT
:
7963 DTIM_INTERVAL_DEFAULT
;
7965 /* fill the default channel as the first valid channel
7966 * starting from the 2G channels
7968 chanspec
= CH20MHZ_CHSPEC(1);
7969 ASSERT(chanspec
!= INVCHANSPEC
);
7971 wlc
->home_chanspec
= bi
->chanspec
= chanspec
;
7973 /* find the band of our default channel */
7975 if (NBANDS(wlc
) > 1 && band
->bandunit
!= CHSPEC_WLCBANDUNIT(chanspec
))
7976 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
7978 /* init bss rates to the band specific default rate set */
7979 wlc_rateset_default(&bi
->rateset
, NULL
, band
->phytype
, band
->bandtype
,
7980 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7981 CHSPEC_WLC_BW(chanspec
), wlc
->stf
->txstreams
);
7983 if (N_ENAB(wlc
->pub
))
7984 bi
->flags
|= WLC_BSS_HT
;
7987 /* Deferred event processing */
7988 static void wlc_process_eventq(void *arg
)
7990 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
7993 while ((etmp
= wlc_eventq_deq(wlc
->eventq
))) {
7994 /* Perform OS specific event processing */
7995 wl_event(wlc
->wl
, etmp
->event
.ifname
, etmp
);
8000 wlc_event_free(wlc
->eventq
, etmp
);
8005 wlc_uint64_sub(u32
*a_high
, u32
*a_low
, u32 b_high
, u32 b_low
)
8007 if (b_low
> *a_low
) {
8008 /* low half needs a carry */
8016 mac80211_wlc_set_nrate(struct wlc_info
*wlc
, struct wlcband
*cur_band
,
8019 u8 stf
= (int_val
& NRATE_STF_MASK
) >> NRATE_STF_SHIFT
;
8020 u8 rate
= int_val
& NRATE_RATE_MASK
;
8022 bool ismcs
= ((int_val
& NRATE_MCS_INUSE
) == NRATE_MCS_INUSE
);
8023 bool issgi
= ((int_val
& NRATE_SGI_MASK
) >> NRATE_SGI_SHIFT
);
8024 bool override_mcs_only
= ((int_val
& NRATE_OVERRIDE_MCS_ONLY
)
8025 == NRATE_OVERRIDE_MCS_ONLY
);
8029 return (ratespec_t
) rate
;
8032 /* validate the combination of rate/mcs/stf is allowed */
8033 if (N_ENAB(wlc
->pub
) && ismcs
) {
8034 /* mcs only allowed when nmode */
8035 if (stf
> PHY_TXC1_MODE_SDM
) {
8036 WL_ERROR("wl%d: %s: Invalid stf\n",
8037 WLCWLUNIT(wlc
), __func__
);
8038 bcmerror
= BCME_RANGE
;
8042 /* mcs 32 is a special case, DUP mode 40 only */
8044 if (!CHSPEC_IS40(wlc
->home_chanspec
) ||
8045 ((stf
!= PHY_TXC1_MODE_SISO
)
8046 && (stf
!= PHY_TXC1_MODE_CDD
))) {
8047 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8048 WLCWLUNIT(wlc
), __func__
);
8049 bcmerror
= BCME_RANGE
;
8052 /* mcs > 7 must use stf SDM */
8053 } else if (rate
> HIGHEST_SINGLE_STREAM_MCS
) {
8054 /* mcs > 7 must use stf SDM */
8055 if (stf
!= PHY_TXC1_MODE_SDM
) {
8056 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8057 WLCWLUNIT(wlc
), __func__
, rate
);
8058 stf
= PHY_TXC1_MODE_SDM
;
8061 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8062 if ((stf
> PHY_TXC1_MODE_STBC
) ||
8063 (!WLC_STBC_CAP_PHY(wlc
)
8064 && (stf
== PHY_TXC1_MODE_STBC
))) {
8065 WL_ERROR("wl%d: %s: Invalid STBC\n",
8066 WLCWLUNIT(wlc
), __func__
);
8067 bcmerror
= BCME_RANGE
;
8071 } else if (IS_OFDM(rate
)) {
8072 if ((stf
!= PHY_TXC1_MODE_CDD
) && (stf
!= PHY_TXC1_MODE_SISO
)) {
8073 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8074 WLCWLUNIT(wlc
), __func__
);
8075 bcmerror
= BCME_RANGE
;
8078 } else if (IS_CCK(rate
)) {
8079 if ((cur_band
->bandtype
!= WLC_BAND_2G
)
8080 || (stf
!= PHY_TXC1_MODE_SISO
)) {
8081 WL_ERROR("wl%d: %s: Invalid CCK\n",
8082 WLCWLUNIT(wlc
), __func__
);
8083 bcmerror
= BCME_RANGE
;
8087 WL_ERROR("wl%d: %s: Unknown rate type\n",
8088 WLCWLUNIT(wlc
), __func__
);
8089 bcmerror
= BCME_RANGE
;
8092 /* make sure multiple antennae are available for non-siso rates */
8093 if ((stf
!= PHY_TXC1_MODE_SISO
) && (wlc
->stf
->txstreams
== 1)) {
8094 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8095 WLCWLUNIT(wlc
), __func__
);
8096 bcmerror
= BCME_RANGE
;
8102 rspec
|= RSPEC_MIMORATE
;
8103 /* For STBC populate the STC field of the ratespec */
8104 if (stf
== PHY_TXC1_MODE_STBC
) {
8106 stc
= 1; /* Nss for single stream is always 1 */
8107 rspec
|= (stc
<< RSPEC_STC_SHIFT
);
8111 rspec
|= (stf
<< RSPEC_STF_SHIFT
);
8113 if (override_mcs_only
)
8114 rspec
|= RSPEC_OVERRIDE_MCS_ONLY
;
8117 rspec
|= RSPEC_SHORT_GI
;
8120 && !wlc_valid_rate(wlc
, rspec
, cur_band
->bandtype
, true)) {
8126 WL_ERROR("Hoark\n");
8130 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8132 wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
8135 int idle_busy_ratio_x_16
= 0;
8137 isOFDM
? M_TX_IDLE_BUSY_RATIO_X_16_OFDM
:
8138 M_TX_IDLE_BUSY_RATIO_X_16_CCK
;
8139 if (duty_cycle
> 100 || duty_cycle
< 0) {
8140 WL_ERROR("wl%d: duty cycle value off limit\n", wlc
->pub
->unit
);
8144 idle_busy_ratio_x_16
= (100 - duty_cycle
) * 16 / duty_cycle
;
8145 /* Only write to shared memory when wl is up */
8147 wlc_write_shm(wlc
, offset
, (u16
) idle_busy_ratio_x_16
);
8150 wlc
->tx_duty_cycle_ofdm
= (u16
) duty_cycle
;
8152 wlc
->tx_duty_cycle_cck
= (u16
) duty_cycle
;
8157 /* Read a single u16 from shared memory.
8158 * SHM 'offset' needs to be an even address
8160 u16
wlc_read_shm(struct wlc_info
*wlc
, uint offset
)
8162 return wlc_bmac_read_shm(wlc
->hw
, offset
);
8165 /* Write a single u16 to shared memory.
8166 * SHM 'offset' needs to be an even address
8168 void wlc_write_shm(struct wlc_info
*wlc
, uint offset
, u16 v
)
8170 wlc_bmac_write_shm(wlc
->hw
, offset
, v
);
8173 /* Set a range of shared memory to a value.
8174 * SHM 'offset' needs to be an even address and
8175 * Range length 'len' must be an even number of bytes
8177 void wlc_set_shm(struct wlc_info
*wlc
, uint offset
, u16 v
, int len
)
8179 /* offset and len need to be even */
8180 ASSERT((offset
& 1) == 0);
8181 ASSERT((len
& 1) == 0);
8186 wlc_bmac_set_shm(wlc
->hw
, offset
, v
, len
);
8189 /* Copy a buffer to shared memory.
8190 * SHM 'offset' needs to be an even address and
8191 * Buffer length 'len' must be an even number of bytes
8193 void wlc_copyto_shm(struct wlc_info
*wlc
, uint offset
, const void *buf
, int len
)
8195 /* offset and len need to be even */
8196 ASSERT((offset
& 1) == 0);
8197 ASSERT((len
& 1) == 0);
8201 wlc_bmac_copyto_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8205 /* Copy from shared memory to a buffer.
8206 * SHM 'offset' needs to be an even address and
8207 * Buffer length 'len' must be an even number of bytes
8209 void wlc_copyfrom_shm(struct wlc_info
*wlc
, uint offset
, void *buf
, int len
)
8211 /* offset and len need to be even */
8212 ASSERT((offset
& 1) == 0);
8213 ASSERT((len
& 1) == 0);
8218 wlc_bmac_copyfrom_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8221 /* wrapper BMAC functions to for HIGH driver access */
8222 void wlc_mctrl(struct wlc_info
*wlc
, u32 mask
, u32 val
)
8224 wlc_bmac_mctrl(wlc
->hw
, mask
, val
);
8227 void wlc_corereset(struct wlc_info
*wlc
, u32 flags
)
8229 wlc_bmac_corereset(wlc
->hw
, flags
);
8232 void wlc_mhf(struct wlc_info
*wlc
, u8 idx
, u16 mask
, u16 val
, int bands
)
8234 wlc_bmac_mhf(wlc
->hw
, idx
, mask
, val
, bands
);
8237 u16
wlc_mhf_get(struct wlc_info
*wlc
, u8 idx
, int bands
)
8239 return wlc_bmac_mhf_get(wlc
->hw
, idx
, bands
);
8242 int wlc_xmtfifo_sz_get(struct wlc_info
*wlc
, uint fifo
, uint
*blocks
)
8244 return wlc_bmac_xmtfifo_sz_get(wlc
->hw
, fifo
, blocks
);
8247 void wlc_write_template_ram(struct wlc_info
*wlc
, int offset
, int len
,
8250 wlc_bmac_write_template_ram(wlc
->hw
, offset
, len
, buf
);
8253 void wlc_write_hw_bcntemplates(struct wlc_info
*wlc
, void *bcn
, int len
,
8256 wlc_bmac_write_hw_bcntemplates(wlc
->hw
, bcn
, len
, both
);
8260 wlc_set_addrmatch(struct wlc_info
*wlc
, int match_reg_offset
,
8263 wlc_bmac_set_addrmatch(wlc
->hw
, match_reg_offset
, addr
);
8266 void wlc_set_rcmta(struct wlc_info
*wlc
, int idx
, const u8
*addr
)
8268 wlc_bmac_set_rcmta(wlc
->hw
, idx
, addr
);
8271 void wlc_read_tsf(struct wlc_info
*wlc
, u32
*tsf_l_ptr
, u32
*tsf_h_ptr
)
8273 wlc_bmac_read_tsf(wlc
->hw
, tsf_l_ptr
, tsf_h_ptr
);
8276 void wlc_set_cwmin(struct wlc_info
*wlc
, u16 newmin
)
8278 wlc
->band
->CWmin
= newmin
;
8279 wlc_bmac_set_cwmin(wlc
->hw
, newmin
);
8282 void wlc_set_cwmax(struct wlc_info
*wlc
, u16 newmax
)
8284 wlc
->band
->CWmax
= newmax
;
8285 wlc_bmac_set_cwmax(wlc
->hw
, newmax
);
8288 void wlc_fifoerrors(struct wlc_info
*wlc
)
8291 wlc_bmac_fifoerrors(wlc
->hw
);
8294 /* Search mem rw utilities */
8296 void wlc_pllreq(struct wlc_info
*wlc
, bool set
, mbool req_bit
)
8298 wlc_bmac_pllreq(wlc
->hw
, set
, req_bit
);
8301 void wlc_reset_bmac_done(struct wlc_info
*wlc
)
8305 void wlc_ht_mimops_cap_update(struct wlc_info
*wlc
, u8 mimops_mode
)
8307 wlc
->ht_cap
.cap_info
&= ~HT_CAP_MIMO_PS_MASK
;
8308 wlc
->ht_cap
.cap_info
|= (mimops_mode
<< IEEE80211_HT_CAP_SM_PS_SHIFT
);
8310 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
8311 wlc_update_beacon(wlc
);
8312 wlc_update_probe_resp(wlc
, true);
8316 /* check for the particular priority flow control bit being set */
8318 wlc_txflowcontrol_prio_isset(struct wlc_info
*wlc
, wlc_txq_info_t
*q
, int prio
)
8322 if (prio
== ALLPRIO
) {
8323 prio_mask
= TXQ_STOP_FOR_PRIOFC_MASK
;
8325 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8326 prio_mask
= NBITVAL(prio
);
8329 return (q
->stopped
& prio_mask
) == prio_mask
;
8332 /* propogate the flow control to all interfaces using the given tx queue */
8333 void wlc_txflowcontrol(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
,
8339 WL_ERROR("%s: flow control kicks in\n", __func__
);
8341 if (prio
== ALLPRIO
) {
8342 prio_bits
= TXQ_STOP_FOR_PRIOFC_MASK
;
8344 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8345 prio_bits
= NBITVAL(prio
);
8348 cur_bits
= qi
->stopped
& prio_bits
;
8350 /* Check for the case of no change and return early
8351 * Otherwise update the bit and continue
8354 if (cur_bits
== prio_bits
) {
8357 mboolset(qi
->stopped
, prio_bits
);
8359 if (cur_bits
== 0) {
8362 mboolclr(qi
->stopped
, prio_bits
);
8365 /* If there is a flow control override we will not change the external
8366 * flow control state.
8368 if (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
) {
8372 wlc_txflowcontrol_signal(wlc
, qi
, on
, prio
);
8376 wlc_txflowcontrol_override(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8381 ASSERT(override
!= 0);
8382 ASSERT((override
& TXQ_STOP_FOR_PRIOFC_MASK
) == 0);
8384 prev_override
= (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
);
8386 /* Update the flow control bits and do an early return if there is
8387 * no change in the external flow control state.
8390 mboolset(qi
->stopped
, override
);
8391 /* if there was a previous override bit on, then setting this
8392 * makes no difference.
8394 if (prev_override
) {
8398 wlc_txflowcontrol_signal(wlc
, qi
, ON
, ALLPRIO
);
8400 mboolclr(qi
->stopped
, override
);
8401 /* clearing an override bit will only make a difference for
8402 * flow control if it was the only bit set. For any other
8403 * override setting, just return
8405 if (prev_override
!= override
) {
8409 if (qi
->stopped
== 0) {
8410 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8414 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
8415 if (!mboolisset(qi
->stopped
, NBITVAL(prio
)))
8416 wlc_txflowcontrol_signal(wlc
, qi
, OFF
,
8423 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
)
8427 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
8429 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8436 wlc_txflowcontrol_signal(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8439 struct wlc_if
*wlcif
;
8441 for (wlcif
= wlc
->wlcif_list
; wlcif
!= NULL
; wlcif
= wlcif
->next
) {
8442 if (wlcif
->qi
== qi
&& wlcif
->flags
& WLC_IF_LINKED
)
8443 wl_txflowcontrol(wlc
->wl
, wlcif
->wlif
, on
, prio
);
8447 static wlc_txq_info_t
*wlc_txq_alloc(struct wlc_info
*wlc
, struct osl_info
*osh
)
8449 wlc_txq_info_t
*qi
, *p
;
8451 qi
= (wlc_txq_info_t
*) wlc_calloc(osh
, wlc
->pub
->unit
,
8452 sizeof(wlc_txq_info_t
));
8457 /* Have enough room for control packets along with HI watermark */
8458 /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */
8459 /* The watermark for flowcontrol to OS packets will remain the same */
8460 pktq_init(&qi
->q
, WLC_PREC_COUNT
,
8461 (2 * wlc
->pub
->tunables
->datahiwat
) + PKTQ_LEN_DEFAULT
+
8462 wlc
->pub
->psq_pkts_total
);
8464 /* add this queue to the the global list */
8467 wlc
->tx_queues
= qi
;
8469 while (p
->next
!= NULL
)
8477 static void wlc_txq_free(struct wlc_info
*wlc
, struct osl_info
*osh
,
8485 /* remove the queue from the linked list */
8488 wlc
->tx_queues
= p
->next
;
8490 while (p
!= NULL
&& p
->next
!= qi
)
8492 ASSERT(p
->next
== qi
);
8494 p
->next
= p
->next
->next
;