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.
144 IOV_BCN_LI_BCN
, /* Beacon listen interval in # of beacons */
145 IOV_LAST
/* In case of a need to check max ID number */
148 const bcm_iovar_t wlc_iovars
[] = {
149 {"mpc", IOV_MPC
, (IOVF_OPEN_ALLOW
), IOVT_BOOL
, 0},
150 {"qtxpower", IOV_QTXPOWER
, (IOVF_WHL
| IOVF_OPEN_ALLOW
), IOVT_UINT32
,
152 {"bcn_li_bcn", IOV_BCN_LI_BCN
, 0, IOVT_UINT8
, 0},
156 const u8 prio2fifo
[NUMPRIO
] = {
157 TX_AC_BE_FIFO
, /* 0 BE AC_BE Best Effort */
158 TX_AC_BK_FIFO
, /* 1 BK AC_BK Background */
159 TX_AC_BK_FIFO
, /* 2 -- AC_BK Background */
160 TX_AC_BE_FIFO
, /* 3 EE AC_BE Best Effort */
161 TX_AC_VI_FIFO
, /* 4 CL AC_VI Video */
162 TX_AC_VI_FIFO
, /* 5 VI AC_VI Video */
163 TX_AC_VO_FIFO
, /* 6 VO AC_VO Voice */
164 TX_AC_VO_FIFO
/* 7 NC AC_VO Voice */
167 /* precedences numbers for wlc queues. These are twice as may levels as
169 * Odd numbers are used for HI priority traffic at same precedence levels
170 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
172 #define _WLC_PREC_NONE 0 /* None = - */
173 #define _WLC_PREC_BK 2 /* BK - Background */
174 #define _WLC_PREC_BE 4 /* BE - Best-effort */
175 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
176 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
177 #define _WLC_PREC_VI 10 /* Vi - Video */
178 #define _WLC_PREC_VO 12 /* Vo - Voice */
179 #define _WLC_PREC_NC 14 /* NC - Network Control */
181 /* 802.1D Priority to precedence queue mapping */
182 const u8 wlc_prio2prec_map
[] = {
183 _WLC_PREC_BE
, /* 0 BE - Best-effort */
184 _WLC_PREC_BK
, /* 1 BK - Background */
185 _WLC_PREC_NONE
, /* 2 None = - */
186 _WLC_PREC_EE
, /* 3 EE - Excellent-effort */
187 _WLC_PREC_CL
, /* 4 CL - Controlled Load */
188 _WLC_PREC_VI
, /* 5 Vi - Video */
189 _WLC_PREC_VO
, /* 6 Vo - Voice */
190 _WLC_PREC_NC
, /* 7 NC - Network Control */
193 /* Sanity check for tx_prec_map and fifo synchup
194 * Either there are some packets pending for the fifo, else if fifo is empty then
195 * all the corresponding precmap bits should be set
197 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
198 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
199 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
200 (wlc)->fifo2prec_map[(fifo)]))
202 /* TX FIFO number to WME/802.1E Access Category */
203 const u8 wme_fifo2ac
[] = { AC_BK
, AC_BE
, AC_VI
, AC_VO
, AC_BE
, AC_BE
};
205 /* WME/802.1E Access Category to TX FIFO number */
206 static const u8 wme_ac2fifo
[] = { 1, 0, 2, 3 };
208 static bool in_send_q
= false;
210 /* Shared memory location index for various AC params */
211 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
214 static const char *fifo_names
[] = {
215 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
216 const char *aci_names
[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
219 static const u8 acbitmap2maxprio
[] = {
220 PRIO_8021D_BE
, PRIO_8021D_BE
, PRIO_8021D_BK
, PRIO_8021D_BK
,
221 PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
,
222 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
,
223 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
226 /* currently the best mechanism for determining SIFS is the band in use */
227 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
229 /* value for # replay counters currently supported */
230 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
232 /* local prototypes */
233 static u16 BCMFASTPATH
wlc_d11hdrs_mac80211(struct wlc_info
*wlc
,
234 struct ieee80211_hw
*hw
,
236 struct scb
*scb
, uint frag
,
237 uint nfrags
, uint queue
,
240 ratespec_t rspec_override
);
242 static void wlc_bss_default_init(struct wlc_info
*wlc
);
243 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
);
244 static ratespec_t
mac80211_wlc_set_nrate(struct wlc_info
*wlc
,
245 struct wlcband
*cur_band
, u32 int_val
);
246 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
);
247 static void wlc_watchdog(void *arg
);
248 static void wlc_watchdog_by_timer(void *arg
);
249 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
);
250 static int wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
,
251 const bcm_iovar_t
*vi
);
252 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
);
254 /* send and receive */
255 static wlc_txq_info_t
*wlc_txq_alloc(struct wlc_info
*wlc
,
256 struct osl_info
*osh
);
257 static void wlc_txq_free(struct wlc_info
*wlc
, struct osl_info
*osh
,
259 static void wlc_txflowcontrol_signal(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
,
261 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
);
262 static u16
wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
,
264 static void wlc_compute_cck_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
265 static void wlc_compute_ofdm_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
266 static void wlc_compute_mimo_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
267 static u16
wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
,
268 u8 preamble_type
, uint next_frag_len
);
269 static void wlc_recvctl(struct wlc_info
*wlc
, struct osl_info
*osh
,
270 d11rxhdr_t
*rxh
, struct sk_buff
*p
);
271 static uint
wlc_calc_frame_len(struct wlc_info
*wlc
, ratespec_t rate
,
272 u8 preamble_type
, uint dur
);
273 static uint
wlc_calc_ack_time(struct wlc_info
*wlc
, ratespec_t rate
,
275 static uint
wlc_calc_cts_time(struct wlc_info
*wlc
, ratespec_t rate
,
277 /* interrupt, up/down, band */
278 static void wlc_setband(struct wlc_info
*wlc
, uint bandunit
);
279 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
);
280 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
);
281 static void wlc_bsinit(struct wlc_info
*wlc
);
282 static int wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
284 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
);
285 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
);
286 static void wlc_radio_timer(void *arg
);
287 static void wlc_radio_enable(struct wlc_info
*wlc
);
288 static void wlc_radio_upd(struct wlc_info
*wlc
);
290 /* scan, association, BSS */
291 static uint
wlc_calc_ba_time(struct wlc_info
*wlc
, ratespec_t rate
,
293 static void wlc_update_mimo_band_bwcap(struct wlc_info
*wlc
, u8 bwcap
);
294 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
);
295 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
);
296 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
);
298 static void wlc_process_eventq(void *arg
);
299 static void wlc_wme_retries_write(struct wlc_info
*wlc
);
300 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
);
301 static uint
wlc_attach_module(struct wlc_info
*wlc
);
302 static void wlc_detach_module(struct wlc_info
*wlc
);
303 static void wlc_timers_deinit(struct wlc_info
*wlc
);
304 static void wlc_down_led_upd(struct wlc_info
*wlc
);
305 static uint
wlc_down_del_timer(struct wlc_info
*wlc
);
306 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
);
307 static int _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
308 struct wlc_if
*wlcif
);
311 void wlc_get_rcmta(struct wlc_info
*wlc
, int idx
, u8
*addr
)
313 d11regs_t
*regs
= wlc
->regs
;
315 struct osl_info
*osh
;
317 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc
), __func__
);
319 ASSERT(wlc
->pub
->corerev
> 4);
323 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| (idx
* 2)));
324 (void)R_REG(osh
, ®s
->objaddr
);
325 v32
= R_REG(osh
, ®s
->objdata
);
327 addr
[1] = (u8
) (v32
>> 8);
328 addr
[2] = (u8
) (v32
>> 16);
329 addr
[3] = (u8
) (v32
>> 24);
330 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| ((idx
* 2) + 1)));
331 (void)R_REG(osh
, ®s
->objaddr
);
332 v32
= R_REG(osh
, (volatile u16
*)®s
->objdata
);
334 addr
[5] = (u8
) (v32
>> 8);
336 #endif /* defined(BCMDBG) */
338 /* keep the chip awake if needed */
339 bool wlc_stay_awake(struct wlc_info
*wlc
)
344 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
346 bool wlc_ps_allowed(struct wlc_info
*wlc
)
351 /* disallow PS when one of the following global conditions meets */
352 if (!wlc
->pub
->associated
|| !wlc
->PMenabled
|| wlc
->PM_override
)
355 /* disallow PS when one of these meets when not scanning */
356 if (!wlc
->PMblocked
) {
357 if (AP_ACTIVE(wlc
) || wlc
->monitor
)
361 FOREACH_AS_STA(wlc
, idx
, cfg
) {
362 /* disallow PS when one of the following bsscfg specific conditions meets */
363 if (!cfg
->BSS
|| !WLC_PORTOPEN(cfg
))
366 if (!cfg
->dtim_programmed
)
373 void wlc_reset(struct wlc_info
*wlc
)
375 WL_TRACE("wl%d: wlc_reset\n", wlc
->pub
->unit
);
377 wlc
->check_for_unaligned_tbtt
= false;
379 /* slurp up hw mac counters before core reset */
380 if (WLC_UPDATE_STATS(wlc
)) {
383 /* reset our snapshot of macstat counters */
384 memset((char *)wlc
->core
->macstat_snapshot
, 0,
388 wlc_bmac_reset(wlc
->hw
);
389 wlc_ampdu_reset(wlc
->ampdu
);
394 void wlc_fatal_error(struct wlc_info
*wlc
)
396 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc
->pub
->unit
);
400 /* Return the channel the driver should initialize during wlc_init.
401 * the channel may have to be changed from the currently configured channel
402 * if other configurations are in conflict (bandlocked, 11n mode disabled,
403 * invalid channel for current country, etc.)
405 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
)
407 chanspec_t chanspec
=
408 1 | WL_CHANSPEC_BW_20
| WL_CHANSPEC_CTL_SB_NONE
|
411 /* make sure the channel is on the supported band if we are band-restricted */
412 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
413 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
415 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
419 struct scb global_scb
;
421 static void wlc_init_scb(struct wlc_info
*wlc
, struct scb
*scb
)
424 scb
->flags
= SCB_WMECAP
| SCB_HTCAP
;
425 for (i
= 0; i
< NUMPRIO
; i
++)
429 void wlc_init(struct wlc_info
*wlc
)
434 wlc_bsscfg_t
*bsscfg
;
437 WL_TRACE("wl%d: wlc_init\n", wlc
->pub
->unit
);
441 /* This will happen if a big-hammer was executed. In that case, we want to go back
442 * to the channel that we were on and not new channel
444 if (wlc
->pub
->associated
)
445 chanspec
= wlc
->home_chanspec
;
447 chanspec
= wlc_init_chanspec(wlc
);
449 wlc_bmac_init(wlc
->hw
, chanspec
, mute
);
451 wlc
->seckeys
= wlc_bmac_read_shm(wlc
->hw
, M_SECRXKEYS_PTR
) * 2;
452 if (D11REV_GE(wlc
->pub
->corerev
, 15) && (wlc
->machwcap
& MCAP_TKIPMIC
))
454 wlc_bmac_read_shm(wlc
->hw
, M_TKMICKEYS_PTR
) * 2;
456 /* update beacon listen interval */
459 (u8
) (wlc_bmac_read_shm(wlc
->hw
, M_NOSLPZNATDTIM
) >> 10);
460 ASSERT(wlc
->bcn_wait_prd
> 0);
462 /* the world is new again, so is our reported rate */
463 wlc_reprate_init(wlc
);
465 /* write ethernet address to core */
466 FOREACH_BSS(wlc
, i
, bsscfg
) {
468 wlc_set_bssid(bsscfg
);
471 /* Update tsf_cfprep if associated and up */
472 if (wlc
->pub
->associated
) {
473 FOREACH_BSS(wlc
, i
, bsscfg
) {
477 /* get beacon period from bsscfg and convert to uS */
478 bi
= bsscfg
->current_bss
->beacon_period
<< 10;
479 /* update the tsf_cfprep register */
480 /* since init path would reset to default value */
481 W_REG(wlc
->osh
, ®s
->tsf_cfprep
,
482 (bi
<< CFPREP_CBI_SHIFT
));
484 /* Update maccontrol PM related bits */
485 wlc_set_ps_ctrl(wlc
);
492 wlc_key_hw_init_all(wlc
);
494 wlc_bandinit_ordered(wlc
, chanspec
);
496 wlc_init_scb(wlc
, &global_scb
);
498 /* init probe response timeout */
499 wlc_write_shm(wlc
, M_PRS_MAXTIME
, wlc
->prb_resp_timeout
);
501 /* init max burst txop (framebursting) */
502 wlc_write_shm(wlc
, M_MBURST_TXOP
,
504 _rifs
? (EDCF_AC_VO_TXOP_AP
<< 5) : MAXFRAMEBURST_TXOP
));
506 /* initialize maximum allowed duty cycle */
507 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_ofdm
, true, true);
508 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_cck
, false, true);
510 /* Update some shared memory locations related to max AMPDU size allowed to received */
511 wlc_ampdu_shm_upd(wlc
->ampdu
);
513 /* band-specific inits */
516 /* Enable EDCF mode (while the MAC is suspended) */
517 if (EDCF_ENAB(wlc
->pub
)) {
518 OR_REG(wlc
->osh
, ®s
->ifs_ctl
, IFS_USEEDCF
);
519 wlc_edcf_setparams(wlc
->cfg
, false);
522 /* Init precedence maps for empty FIFOs */
523 wlc_tx_prec_map_init(wlc
);
525 /* read the ucode version if we have not yet done so */
526 if (wlc
->ucode_rev
== 0) {
528 wlc_read_shm(wlc
, M_BOM_REV_MAJOR
) << NBITS(u16
);
529 wlc
->ucode_rev
|= wlc_read_shm(wlc
, M_BOM_REV_MINOR
);
532 /* ..now really unleash hell (allow the MAC out of suspend) */
535 /* clear tx flow control */
536 wlc_txflowcontrol_reset(wlc
);
538 /* clear tx data fifo suspends */
539 wlc
->tx_suspended
= false;
541 /* enable the RF Disable Delay timer */
542 if (D11REV_GE(wlc
->pub
->corerev
, 10))
543 W_REG(wlc
->osh
, &wlc
->regs
->rfdisabledly
, RFDISABLE_DEFAULT
);
545 /* initialize mpc delay */
546 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
549 * Initialize WME parameters; if they haven't been set by some other
550 * mechanism (IOVar, etc) then read them from the hardware.
552 if (WLC_WME_RETRY_SHORT_GET(wlc
, 0) == 0) { /* Unintialized; read from HW */
556 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
557 wlc
->wme_retries
[ac
] =
558 wlc_read_shm(wlc
, M_AC_TXLMT_ADDR(ac
));
563 void wlc_mac_bcn_promisc_change(struct wlc_info
*wlc
, bool promisc
)
565 wlc
->bcnmisc_monitor
= promisc
;
566 wlc_mac_bcn_promisc(wlc
);
569 void wlc_mac_bcn_promisc(struct wlc_info
*wlc
)
571 if ((AP_ENAB(wlc
->pub
) && (N_ENAB(wlc
->pub
) || wlc
->band
->gmode
)) ||
572 wlc
->bcnmisc_ibss
|| wlc
->bcnmisc_scan
|| wlc
->bcnmisc_monitor
)
573 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, MCTL_BCNS_PROMISC
);
575 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, 0);
578 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
579 void wlc_mac_promisc(struct wlc_info
*wlc
)
581 u32 promisc_bits
= 0;
583 /* promiscuous mode just sets MCTL_PROMISC
584 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
585 * since all BSS data traffic is directed at the AP
587 if (PROMISC_ENAB(wlc
->pub
) && !AP_ENAB(wlc
->pub
) && !wlc
->wet
)
588 promisc_bits
|= MCTL_PROMISC
;
590 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
591 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
592 * handled in wlc_mac_bcn_promisc()
594 if (MONITOR_ENAB(wlc
))
595 promisc_bits
|= MCTL_PROMISC
| MCTL_KEEPCONTROL
;
597 wlc_mctrl(wlc
, MCTL_PROMISC
| MCTL_KEEPCONTROL
, promisc_bits
);
600 /* check if hps and wake states of sw and hw are in sync */
601 bool wlc_ps_check(struct wlc_info
*wlc
)
607 if (!AP_ACTIVE(wlc
)) {
609 tmp
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
611 /* If deviceremoved is detected, then don't take any action as this can be called
612 * in any context. Assume that caller will take care of the condition. This is just
615 if (tmp
== 0xffffffff) {
616 WL_ERROR("wl%d: %s: dead chip\n",
617 wlc
->pub
->unit
, __func__
);
618 return DEVICEREMOVED(wlc
);
621 hps
= PS_ALLOWED(wlc
);
623 if (hps
!= ((tmp
& MCTL_HPS
) != 0)) {
626 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
627 wlc
->pub
->unit
, hps
, tmp
);
628 FOREACH_BSS(wlc
, idx
, cfg
) {
629 if (!BSSCFG_STA(cfg
))
635 /* For a monolithic build the wake check can be exact since it looks at wake
636 * override bits. The MCTL_WAKE bit should match the 'wake' value.
638 wake
= STAY_AWAKE(wlc
) || wlc
->hw
->wake_override
;
639 wake_ok
= (wake
== ((tmp
& MCTL_WAKE
) != 0));
640 if (hps
&& !wake_ok
) {
641 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
642 wlc
->pub
->unit
, wake
, tmp
);
650 /* push sw hps and wake state through hardware */
651 void wlc_set_ps_ctrl(struct wlc_info
*wlc
)
657 hps
= PS_ALLOWED(wlc
);
658 wake
= hps
? (STAY_AWAKE(wlc
)) : true;
660 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
661 wlc
->pub
->unit
, hps
, wake
);
663 v1
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
670 wlc_mctrl(wlc
, MCTL_WAKE
| MCTL_HPS
, v2
);
672 awake_before
= ((v1
& MCTL_WAKE
) || ((v1
& MCTL_HPS
) == 0));
674 if (wake
&& !awake_before
)
675 wlc_bmac_wait_for_wake(wlc
->hw
);
680 * Write this BSS config's MAC address to core.
681 * Updates RXE match engine.
683 int wlc_set_mac(wlc_bsscfg_t
*cfg
)
686 struct wlc_info
*wlc
= cfg
->wlc
;
688 if (cfg
== wlc
->cfg
) {
689 /* enter the MAC addr into the RXE match registers */
690 wlc_set_addrmatch(wlc
, RCM_MAC_OFFSET
, cfg
->cur_etheraddr
);
693 wlc_ampdu_macaddr_upd(wlc
);
698 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
699 * Updates RXE match engine.
701 void wlc_set_bssid(wlc_bsscfg_t
*cfg
)
703 struct wlc_info
*wlc
= cfg
->wlc
;
705 /* if primary config, we need to update BSSID in RXE match registers */
706 if (cfg
== wlc
->cfg
) {
707 wlc_set_addrmatch(wlc
, RCM_BSSID_OFFSET
, cfg
->BSSID
);
709 #ifdef SUPPORT_HWKEYS
710 else if (BSSCFG_STA(cfg
) && cfg
->BSS
) {
711 wlc_rcmta_add_bssid(wlc
, cfg
);
717 * Suspend the the MAC and update the slot timing
718 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
720 void wlc_switch_shortslot(struct wlc_info
*wlc
, bool shortslot
)
725 ASSERT(wlc
->band
->gmode
);
727 /* use the override if it is set */
728 if (wlc
->shortslot_override
!= WLC_SHORTSLOT_AUTO
)
729 shortslot
= (wlc
->shortslot_override
== WLC_SHORTSLOT_ON
);
731 if (wlc
->shortslot
== shortslot
)
734 wlc
->shortslot
= shortslot
;
736 /* update the capability based on current shortslot mode */
737 FOREACH_BSS(wlc
, idx
, cfg
) {
738 if (!cfg
->associated
)
740 cfg
->current_bss
->capability
&=
741 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
743 cfg
->current_bss
->capability
|=
744 WLAN_CAPABILITY_SHORT_SLOT_TIME
;
747 wlc_bmac_set_shortslot(wlc
->hw
, shortslot
);
750 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
)
755 local
= WLC_TXPWR_MAX
;
756 if (wlc
->pub
->associated
&&
757 (wf_chspec_ctlchan(wlc
->chanspec
) ==
758 wf_chspec_ctlchan(wlc
->home_chanspec
))) {
760 /* get the local power constraint if we are on the AP's
761 * channel [802.11h, 7.3.2.13]
763 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
765 (wlc
->txpwr_local_max
-
766 wlc
->txpwr_local_constraint
) * WLC_TXPWR_DB_FACTOR
;
767 if (local_max
> 0 && local_max
< WLC_TXPWR_MAX
)
768 return (u8
) local_max
;
776 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
777 void wlc_set_home_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
779 if (wlc
->home_chanspec
!= chanspec
) {
783 wlc
->home_chanspec
= chanspec
;
785 FOREACH_BSS(wlc
, idx
, cfg
) {
786 if (!cfg
->associated
)
788 cfg
->target_bss
->chanspec
= chanspec
;
789 cfg
->current_bss
->chanspec
= chanspec
;
795 static void wlc_set_phy_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
797 /* Save our copy of the chanspec */
798 wlc
->chanspec
= chanspec
;
800 /* Set the chanspec and power limits for this locale after computing
801 * any 11h local tx power constraints.
803 wlc_channel_set_chanspec(wlc
->cmi
, chanspec
,
804 wlc_local_constraint_qdbm(wlc
));
806 if (wlc
->stf
->ss_algosel_auto
)
807 wlc_stf_ss_algo_channel_get(wlc
, &wlc
->stf
->ss_algo_channel
,
810 wlc_stf_ss_update(wlc
, wlc
->band
);
814 void wlc_set_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
817 bool switchband
= false;
818 chanspec_t old_chanspec
= wlc
->chanspec
;
820 if (!wlc_valid_chanspec_db(wlc
->cmi
, chanspec
)) {
821 WL_ERROR("wl%d: %s: Bad channel %d\n",
822 wlc
->pub
->unit
, __func__
, CHSPEC_CHANNEL(chanspec
));
823 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
827 /* Switch bands if necessary */
828 if (NBANDS(wlc
) > 1) {
829 bandunit
= CHSPEC_WLCBANDUNIT(chanspec
);
830 if (wlc
->band
->bandunit
!= bandunit
|| wlc
->bandinit_pending
) {
832 if (wlc
->bandlocked
) {
833 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
834 wlc
->pub
->unit
, __func__
,
835 CHSPEC_CHANNEL(chanspec
));
838 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
839 * if the setband updates (wlc_bsinit) use low level calls to inspect and
840 * set state, the state inspected may be from the wrong band, or the
841 * following wlc_bmac_set_chanspec() may undo the work.
843 wlc_setband(wlc
, bandunit
);
847 ASSERT(N_ENAB(wlc
->pub
) || !CHSPEC_IS40(chanspec
));
849 /* sync up phy/radio chanspec */
850 wlc_set_phy_chanspec(wlc
, chanspec
);
852 /* init antenna selection */
853 if (CHSPEC_WLC_BW(old_chanspec
) != CHSPEC_WLC_BW(chanspec
)) {
854 if (WLANTSEL_ENAB(wlc
))
855 wlc_antsel_init(wlc
->asi
);
857 /* Fix the hardware rateset based on bw.
858 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
860 wlc_rateset_bw_mcs_filter(&wlc
->band
->hw_rateset
,
862 mimo_cap_40
? CHSPEC_WLC_BW(chanspec
)
866 /* update some mac configuration since chanspec changed */
867 wlc_ucode_mac_upd(wlc
);
871 static int wlc_get_current_txpwr(struct wlc_info
*wlc
, void *pwr
, uint len
)
873 txpwr_limits_t txpwr
;
875 tx_power_legacy_t
*old_power
= NULL
;
880 if (len
== sizeof(tx_power_legacy_t
))
881 old_power
= (tx_power_legacy_t
*) pwr
;
882 else if (len
< sizeof(tx_power_t
))
883 return BCME_BUFTOOSHORT
;
885 memset(&power
, 0, sizeof(tx_power_t
));
887 power
.chanspec
= WLC_BAND_PI_RADIO_CHANSPEC
;
888 if (wlc
->pub
->associated
)
889 power
.local_chanspec
= wlc
->home_chanspec
;
891 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
892 * public interface only implements getting and setting a single value for all of
893 * rates, so we need to fill the array ourselves.
895 wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
, &override
);
896 for (r
= 0; r
< WL_TX_POWER_RATES
; r
++) {
897 power
.user_limit
[r
] = (u8
) qdbm
;
900 power
.local_max
= wlc
->txpwr_local_max
* WLC_TXPWR_DB_FACTOR
;
901 power
.local_constraint
=
902 wlc
->txpwr_local_constraint
* WLC_TXPWR_DB_FACTOR
;
904 power
.antgain
[0] = wlc
->bandstate
[BAND_2G_INDEX
]->antgain
;
905 power
.antgain
[1] = wlc
->bandstate
[BAND_5G_INDEX
]->antgain
;
907 wlc_channel_reg_limits(wlc
->cmi
, power
.chanspec
, &txpwr
);
909 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
910 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
913 /* CCK tx power limits */
914 for (c
= 0, r
= WL_TX_POWER_CCK_FIRST
; c
< WL_TX_POWER_CCK_NUM
;
916 power
.reg_limit
[r
] = txpwr
.cck
[c
];
918 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
919 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
922 /* 20 MHz OFDM SISO tx power limits */
923 for (c
= 0, r
= WL_TX_POWER_OFDM_FIRST
; c
< WL_TX_POWER_OFDM_NUM
;
925 power
.reg_limit
[r
] = txpwr
.ofdm
[c
];
927 if (WLC_PHY_11N_CAP(wlc
->band
)) {
929 /* 20 MHz OFDM CDD tx power limits */
930 for (c
= 0, r
= WL_TX_POWER_OFDM20_CDD_FIRST
;
931 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
932 power
.reg_limit
[r
] = txpwr
.ofdm_cdd
[c
];
934 /* 40 MHz OFDM SISO tx power limits */
935 for (c
= 0, r
= WL_TX_POWER_OFDM40_SISO_FIRST
;
936 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
937 power
.reg_limit
[r
] = txpwr
.ofdm_40_siso
[c
];
939 /* 40 MHz OFDM CDD tx power limits */
940 for (c
= 0, r
= WL_TX_POWER_OFDM40_CDD_FIRST
;
941 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
942 power
.reg_limit
[r
] = txpwr
.ofdm_40_cdd
[c
];
944 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
945 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
948 /* 20MHz MCS0-7 SISO tx power limits */
949 for (c
= 0, r
= WL_TX_POWER_MCS20_SISO_FIRST
;
950 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
951 power
.reg_limit
[r
] = txpwr
.mcs_20_siso
[c
];
953 /* 20MHz MCS0-7 CDD tx power limits */
954 for (c
= 0, r
= WL_TX_POWER_MCS20_CDD_FIRST
;
955 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
956 power
.reg_limit
[r
] = txpwr
.mcs_20_cdd
[c
];
958 /* 20MHz MCS0-7 STBC tx power limits */
959 for (c
= 0, r
= WL_TX_POWER_MCS20_STBC_FIRST
;
960 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
961 power
.reg_limit
[r
] = txpwr
.mcs_20_stbc
[c
];
963 /* 40MHz MCS0-7 SISO tx power limits */
964 for (c
= 0, r
= WL_TX_POWER_MCS40_SISO_FIRST
;
965 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
966 power
.reg_limit
[r
] = txpwr
.mcs_40_siso
[c
];
968 /* 40MHz MCS0-7 CDD tx power limits */
969 for (c
= 0, r
= WL_TX_POWER_MCS40_CDD_FIRST
;
970 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
971 power
.reg_limit
[r
] = txpwr
.mcs_40_cdd
[c
];
973 /* 40MHz MCS0-7 STBC tx power limits */
974 for (c
= 0, r
= WL_TX_POWER_MCS40_STBC_FIRST
;
975 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
976 power
.reg_limit
[r
] = txpwr
.mcs_40_stbc
[c
];
978 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
979 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
982 /* 20MHz MCS8-15 SDM tx power limits */
983 for (c
= 0, r
= WL_TX_POWER_MCS20_SDM_FIRST
;
984 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
985 power
.reg_limit
[r
] = txpwr
.mcs_20_mimo
[c
];
987 /* 40MHz MCS8-15 SDM tx power limits */
988 for (c
= 0, r
= WL_TX_POWER_MCS40_SDM_FIRST
;
989 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
990 power
.reg_limit
[r
] = txpwr
.mcs_40_mimo
[c
];
993 power
.reg_limit
[WL_TX_POWER_MCS_32
] = txpwr
.mcs32
;
996 wlc_phy_txpower_get_current(wlc
->band
->pi
, &power
,
997 CHSPEC_CHANNEL(power
.chanspec
));
999 /* copy the tx_power_t struct to the return buffer,
1000 * or convert to a tx_power_legacy_t struct
1003 bcopy(&power
, pwr
, sizeof(tx_power_t
));
1005 int band_idx
= CHSPEC_IS2G(power
.chanspec
) ? 0 : 1;
1007 memset(old_power
, 0, sizeof(tx_power_legacy_t
));
1009 old_power
->txpwr_local_max
= power
.local_max
;
1010 old_power
->txpwr_local_constraint
= power
.local_constraint
;
1011 if (CHSPEC_IS2G(power
.chanspec
)) {
1012 old_power
->txpwr_chan_reg_max
= txpwr
.cck
[0];
1013 old_power
->txpwr_est_Pout
[band_idx
] =
1015 old_power
->txpwr_est_Pout_gofdm
= power
.est_Pout
[0];
1017 old_power
->txpwr_chan_reg_max
= txpwr
.ofdm
[0];
1018 old_power
->txpwr_est_Pout
[band_idx
] = power
.est_Pout
[0];
1020 old_power
->txpwr_antgain
[0] = power
.antgain
[0];
1021 old_power
->txpwr_antgain
[1] = power
.antgain
[1];
1023 for (r
= 0; r
< NUM_PWRCTRL_RATES
; r
++) {
1024 old_power
->txpwr_band_max
[r
] = power
.user_limit
[r
];
1025 old_power
->txpwr_limit
[r
] = power
.reg_limit
[r
];
1026 old_power
->txpwr_target
[band_idx
][r
] = power
.target
[r
];
1027 if (CHSPEC_IS2G(power
.chanspec
))
1028 old_power
->txpwr_bphy_cck_max
[r
] =
1029 power
.board_limit
[r
];
1031 old_power
->txpwr_aphy_max
[r
] =
1032 power
.board_limit
[r
];
1038 #endif /* defined(BCMDBG) */
1040 static u32
wlc_watchdog_backup_bi(struct wlc_info
*wlc
)
1043 bi
= 2 * wlc
->cfg
->current_bss
->dtim_period
*
1044 wlc
->cfg
->current_bss
->beacon_period
;
1045 if (wlc
->bcn_li_dtim
)
1046 bi
*= wlc
->bcn_li_dtim
;
1047 else if (wlc
->bcn_li_bcn
)
1048 /* recalculate bi based on bcn_li_bcn */
1049 bi
= 2 * wlc
->bcn_li_bcn
* wlc
->cfg
->current_bss
->beacon_period
;
1051 if (bi
< 2 * TIMER_INTERVAL_WATCHDOG
)
1052 bi
= 2 * TIMER_INTERVAL_WATCHDOG
;
1056 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1057 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1059 void wlc_watchdog_upd(struct wlc_info
*wlc
, bool tbtt
)
1061 /* make sure changing watchdog driver is allowed */
1062 if (!wlc
->pub
->up
|| !wlc
->pub
->align_wd_tbtt
)
1064 if (!tbtt
&& wlc
->WDarmed
) {
1065 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1066 wlc
->WDarmed
= false;
1069 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1070 if (tbtt
&& wlc
->WDarmed
) {
1071 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1072 wlc
->WDarmed
= false;
1073 wlc
->WDlast
= OSL_SYSUPTIME();
1075 /* arm watchdog timer and drive the watchdog there */
1076 else if (!tbtt
&& !wlc
->WDarmed
) {
1077 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
1079 wlc
->WDarmed
= true;
1081 if (tbtt
&& !wlc
->WDarmed
) {
1082 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, wlc_watchdog_backup_bi(wlc
),
1084 wlc
->WDarmed
= true;
1088 ratespec_t
wlc_lowest_basic_rspec(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
1090 ratespec_t lowest_basic_rspec
;
1093 /* Use the lowest basic rate */
1094 lowest_basic_rspec
= rs
->rates
[0] & RATE_MASK
;
1095 for (i
= 0; i
< rs
->count
; i
++) {
1096 if (rs
->rates
[i
] & WLC_RATE_FLAG
) {
1097 lowest_basic_rspec
= rs
->rates
[i
] & RATE_MASK
;
1102 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1103 if (IS_OFDM(lowest_basic_rspec
)) {
1104 lowest_basic_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
1108 return lowest_basic_rspec
;
1111 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1112 * setting as per this table:
1113 * ratespec CCK ant = wlc->stf->txant
1116 void wlc_beacon_phytxctl_txant_upd(struct wlc_info
*wlc
, ratespec_t bcn_rspec
)
1119 u16 phytxant
= wlc
->stf
->phytxant
;
1120 u16 mask
= PHY_TXC_ANT_MASK
;
1122 /* for non-siso rates or default setting, use the available chains */
1123 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1124 phytxant
= wlc_stf_phytxchain_sel(wlc
, bcn_rspec
);
1127 phyctl
= wlc_read_shm(wlc
, M_BCN_PCTLWD
);
1128 phyctl
= (phyctl
& ~mask
) | phytxant
;
1129 wlc_write_shm(wlc
, M_BCN_PCTLWD
, phyctl
);
1132 /* centralized protection config change function to simplify debugging, no consistency checking
1133 * this should be called only on changes to avoid overhead in periodic function
1135 void wlc_protection_upd(struct wlc_info
*wlc
, uint idx
, int val
)
1137 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx
, val
);
1140 case WLC_PROT_G_SPEC
:
1141 wlc
->protection
->_g
= (bool) val
;
1143 case WLC_PROT_G_OVR
:
1144 wlc
->protection
->g_override
= (s8
) val
;
1146 case WLC_PROT_G_USER
:
1147 wlc
->protection
->gmode_user
= (u8
) val
;
1149 case WLC_PROT_OVERLAP
:
1150 wlc
->protection
->overlap
= (s8
) val
;
1152 case WLC_PROT_N_USER
:
1153 wlc
->protection
->nmode_user
= (s8
) val
;
1155 case WLC_PROT_N_CFG
:
1156 wlc
->protection
->n_cfg
= (s8
) val
;
1158 case WLC_PROT_N_CFG_OVR
:
1159 wlc
->protection
->n_cfg_override
= (s8
) val
;
1161 case WLC_PROT_N_NONGF
:
1162 wlc
->protection
->nongf
= (bool) val
;
1164 case WLC_PROT_N_NONGF_OVR
:
1165 wlc
->protection
->nongf_override
= (s8
) val
;
1167 case WLC_PROT_N_PAM_OVR
:
1168 wlc
->protection
->n_pam_override
= (s8
) val
;
1170 case WLC_PROT_N_OBSS
:
1171 wlc
->protection
->n_obss
= (bool) val
;
1181 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
)
1183 wlc
->ht_cap
.cap_info
&= ~(IEEE80211_HT_CAP_SGI_20
|
1184 IEEE80211_HT_CAP_SGI_40
);
1185 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_20
) ?
1186 IEEE80211_HT_CAP_SGI_20
: 0;
1187 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_40
) ?
1188 IEEE80211_HT_CAP_SGI_40
: 0;
1191 wlc_update_beacon(wlc
);
1192 wlc_update_probe_resp(wlc
, true);
1196 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
)
1198 wlc
->stf
->ldpc
= val
;
1200 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_LDPC_CODING
;
1201 if (wlc
->stf
->ldpc
!= OFF
)
1202 wlc
->ht_cap
.cap_info
|= IEEE80211_HT_CAP_LDPC_CODING
;
1205 wlc_update_beacon(wlc
);
1206 wlc_update_probe_resp(wlc
, true);
1207 wlc_phy_ldpc_override_set(wlc
->band
->pi
, (val
? true : false));
1212 * ucode, hwmac update
1213 * Channel dependent updates for ucode and hw
1215 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
)
1217 /* enable or disable any active IBSSs depending on whether or not
1218 * we are on the home channel
1220 if (wlc
->home_chanspec
== WLC_BAND_PI_RADIO_CHANSPEC
) {
1221 if (wlc
->pub
->associated
) {
1222 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1223 * I think that the ucode inits set up the bcn templates and shm values
1224 * with a bogus beacon. This should not be done in the inits. If ucode needs
1225 * to set up a beacon for testing, the test routines should write it down,
1226 * not expect the inits to populate a bogus beacon.
1228 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1229 wlc_write_shm(wlc
, M_BCN_TXTSF_OFFSET
,
1230 wlc
->band
->bcntsfoff
);
1234 /* disable an active IBSS if we are not on the home channel */
1237 /* update the various promisc bits */
1238 wlc_mac_bcn_promisc(wlc
);
1239 wlc_mac_promisc(wlc
);
1242 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
)
1244 wlc_rateset_t default_rateset
;
1246 uint i
, band_order
[2];
1248 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc
->pub
->unit
);
1250 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1251 * figure out the right band to park on
1253 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
1254 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
1256 parkband
= wlc
->band
->bandunit
; /* updated in wlc_bandlock() */
1257 band_order
[0] = band_order
[1] = parkband
;
1259 /* park on the band of the specified chanspec */
1260 parkband
= CHSPEC_WLCBANDUNIT(chanspec
);
1262 /* order so that parkband initialize last */
1263 band_order
[0] = parkband
^ 1;
1264 band_order
[1] = parkband
;
1267 /* make each band operational, software state init */
1268 for (i
= 0; i
< NBANDS(wlc
); i
++) {
1269 uint j
= band_order
[i
];
1271 wlc
->band
= wlc
->bandstate
[j
];
1273 wlc_default_rateset(wlc
, &default_rateset
);
1275 /* fill in hw_rate */
1276 wlc_rateset_filter(&default_rateset
, &wlc
->band
->hw_rateset
,
1277 false, WLC_RATES_CCK_OFDM
, RATE_MASK
,
1278 (bool) N_ENAB(wlc
->pub
));
1280 /* init basic rate lookup */
1281 wlc_rate_lookup_init(wlc
, &default_rateset
);
1284 /* sync up phy/radio chanspec */
1285 wlc_set_phy_chanspec(wlc
, chanspec
);
1288 /* band-specific init */
1289 static void WLBANDINITFN(wlc_bsinit
) (struct wlc_info
*wlc
)
1291 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1292 wlc
->pub
->unit
, wlc
->band
->bandunit
);
1294 /* write ucode ACK/CTS rate table */
1295 wlc_set_ratetable(wlc
);
1297 /* update some band specific mac configuration */
1298 wlc_ucode_mac_upd(wlc
);
1300 /* init antenna selection */
1301 if (WLANTSEL_ENAB(wlc
))
1302 wlc_antsel_init(wlc
->asi
);
1306 /* switch to and initialize new band */
1307 static void WLBANDINITFN(wlc_setband
) (struct wlc_info
*wlc
, uint bandunit
)
1312 ASSERT(NBANDS(wlc
) > 1);
1313 ASSERT(!wlc
->bandlocked
);
1314 ASSERT(bandunit
!= wlc
->band
->bandunit
|| wlc
->bandinit_pending
);
1316 wlc
->band
= wlc
->bandstate
[bandunit
];
1321 /* wait for at least one beacon before entering sleeping state */
1322 wlc
->PMawakebcn
= true;
1323 FOREACH_AS_STA(wlc
, idx
, cfg
)
1324 cfg
->PMawakebcn
= true;
1325 wlc_set_ps_ctrl(wlc
);
1327 /* band-specific initializations */
1331 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1332 void wlc_wme_initparams_sta(struct wlc_info
*wlc
, wme_param_ie_t
*pe
)
1334 static const wme_param_ie_t stadef
= {
1337 WME_SUBTYPE_PARAM_IE
,
1342 {EDCF_AC_BE_ACI_STA
, EDCF_AC_BE_ECW_STA
,
1343 HTOL16(EDCF_AC_BE_TXOP_STA
)},
1344 {EDCF_AC_BK_ACI_STA
, EDCF_AC_BK_ECW_STA
,
1345 HTOL16(EDCF_AC_BK_TXOP_STA
)},
1346 {EDCF_AC_VI_ACI_STA
, EDCF_AC_VI_ECW_STA
,
1347 HTOL16(EDCF_AC_VI_TXOP_STA
)},
1348 {EDCF_AC_VO_ACI_STA
, EDCF_AC_VO_ECW_STA
,
1349 HTOL16(EDCF_AC_VO_TXOP_STA
)}
1353 ASSERT(sizeof(*pe
) == WME_PARAM_IE_LEN
);
1354 memcpy(pe
, &stadef
, sizeof(*pe
));
1357 void wlc_wme_setparams(struct wlc_info
*wlc
, u16 aci
, void *arg
, bool suspend
)
1360 shm_acparams_t acp_shm
;
1362 struct ieee80211_tx_queue_params
*params
= arg
;
1366 /* Only apply params if the core is out of reset and has clocks */
1368 WL_ERROR("wl%d: %s : no-clock\n", wlc
->pub
->unit
, __func__
);
1373 * AP uses AC params from wme_param_ie_ap.
1374 * AP advertises AC params from wme_param_ie.
1375 * STA uses AC params from wme_param_ie.
1378 wlc
->wme_admctl
= 0;
1381 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1382 /* find out which ac this set of params applies to */
1383 ASSERT(aci
< AC_COUNT
);
1384 /* set the admission control policy for this AC */
1385 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1387 /* fill in shm ac params struct */
1388 acp_shm
.txop
= ltoh16(params
->txop
);
1389 /* convert from units of 32us to us for ucode */
1390 wlc
->edcf_txop
[aci
& 0x3] = acp_shm
.txop
=
1391 EDCF_TXOP2USEC(acp_shm
.txop
);
1392 acp_shm
.aifs
= (params
->aifs
& EDCF_AIFSN_MASK
);
1394 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1395 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1398 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1399 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1400 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1401 wlc
->pub
->unit
, acp_shm
.aifs
);
1405 acp_shm
.cwmin
= params
->cw_min
;
1406 acp_shm
.cwmax
= params
->cw_max
;
1407 acp_shm
.cwcur
= acp_shm
.cwmin
;
1409 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1410 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1411 /* Indicate the new params to the ucode */
1412 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1413 wme_shmemacindex(aci
) *
1415 M_EDCF_STATUS_OFF
));
1416 acp_shm
.status
|= WME_STATUS_NEWAC
;
1418 /* Fill in shm acparam table */
1419 shm_entry
= (u16
*) &acp_shm
;
1420 for (i
= 0; i
< (int)sizeof(shm_acparams_t
); i
+= 2)
1423 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ i
,
1429 wlc_suspend_mac_and_wait(wlc
);
1432 wlc_enable_mac(wlc
);
1436 void wlc_edcf_setparams(wlc_bsscfg_t
*cfg
, bool suspend
)
1438 struct wlc_info
*wlc
= cfg
->wlc
;
1440 edcf_acparam_t
*edcf_acp
;
1441 shm_acparams_t acp_shm
;
1447 /* Only apply params if the core is out of reset and has clocks */
1452 * AP uses AC params from wme_param_ie_ap.
1453 * AP advertises AC params from wme_param_ie.
1454 * STA uses AC params from wme_param_ie.
1457 edcf_acp
= (edcf_acparam_t
*) &wlc
->wme_param_ie
.acparam
[0];
1459 wlc
->wme_admctl
= 0;
1461 for (i
= 0; i
< AC_COUNT
; i
++, edcf_acp
++) {
1462 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1463 /* find out which ac this set of params applies to */
1464 aci
= (edcf_acp
->ACI
& EDCF_ACI_MASK
) >> EDCF_ACI_SHIFT
;
1465 ASSERT(aci
< AC_COUNT
);
1466 /* set the admission control policy for this AC */
1467 if (edcf_acp
->ACI
& EDCF_ACM_MASK
) {
1468 wlc
->wme_admctl
|= 1 << aci
;
1471 /* fill in shm ac params struct */
1472 acp_shm
.txop
= ltoh16(edcf_acp
->TXOP
);
1473 /* convert from units of 32us to us for ucode */
1474 wlc
->edcf_txop
[aci
] = acp_shm
.txop
=
1475 EDCF_TXOP2USEC(acp_shm
.txop
);
1476 acp_shm
.aifs
= (edcf_acp
->ACI
& EDCF_AIFSN_MASK
);
1478 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1479 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1482 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1483 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1484 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1485 wlc
->pub
->unit
, acp_shm
.aifs
);
1489 /* CWmin = 2^(ECWmin) - 1 */
1490 acp_shm
.cwmin
= EDCF_ECW2CW(edcf_acp
->ECW
& EDCF_ECWMIN_MASK
);
1491 /* CWmax = 2^(ECWmax) - 1 */
1492 acp_shm
.cwmax
= EDCF_ECW2CW((edcf_acp
->ECW
& EDCF_ECWMAX_MASK
)
1493 >> EDCF_ECWMAX_SHIFT
);
1494 acp_shm
.cwcur
= acp_shm
.cwmin
;
1496 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1497 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1498 /* Indicate the new params to the ucode */
1499 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1500 wme_shmemacindex(aci
) *
1502 M_EDCF_STATUS_OFF
));
1503 acp_shm
.status
|= WME_STATUS_NEWAC
;
1505 /* Fill in shm acparam table */
1506 shm_entry
= (u16
*) &acp_shm
;
1507 for (j
= 0; j
< (int)sizeof(shm_acparams_t
); j
+= 2)
1510 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ j
,
1515 wlc_suspend_mac_and_wait(wlc
);
1517 if (AP_ENAB(wlc
->pub
) && WME_ENAB(wlc
->pub
)) {
1518 wlc_update_beacon(wlc
);
1519 wlc_update_probe_resp(wlc
, false);
1523 wlc_enable_mac(wlc
);
1527 bool wlc_timers_init(struct wlc_info
*wlc
, int unit
)
1529 wlc
->wdtimer
= wl_init_timer(wlc
->wl
, wlc_watchdog_by_timer
,
1531 if (!wlc
->wdtimer
) {
1532 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit
);
1536 wlc
->radio_timer
= wl_init_timer(wlc
->wl
, wlc_radio_timer
,
1538 if (!wlc
->radio_timer
) {
1539 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit
);
1550 * Initialize wlc_info default values ...
1551 * may get overrides later in this function
1553 void wlc_info_init(struct wlc_info
*wlc
, int unit
)
1556 /* Assume the device is there until proven otherwise */
1557 wlc
->device_present
= true;
1559 /* set default power output percentage to 100 percent */
1560 wlc
->txpwr_percent
= 100;
1562 /* Save our copy of the chanspec */
1563 wlc
->chanspec
= CH20MHZ_CHSPEC(1);
1565 /* initialize CCK preamble mode to unassociated state */
1566 wlc
->shortpreamble
= false;
1568 wlc
->legacy_probe
= true;
1570 /* various 802.11g modes */
1571 wlc
->shortslot
= false;
1572 wlc
->shortslot_override
= WLC_SHORTSLOT_AUTO
;
1574 wlc
->barker_overlap_control
= true;
1575 wlc
->barker_preamble
= WLC_BARKER_SHORT_ALLOWED
;
1576 wlc
->txburst_limit_override
= AUTO
;
1578 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, WLC_PROTECTION_AUTO
);
1579 wlc_protection_upd(wlc
, WLC_PROT_G_SPEC
, false);
1581 wlc_protection_upd(wlc
, WLC_PROT_N_CFG_OVR
, WLC_PROTECTION_AUTO
);
1582 wlc_protection_upd(wlc
, WLC_PROT_N_CFG
, WLC_N_PROTECTION_OFF
);
1583 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF_OVR
, WLC_PROTECTION_AUTO
);
1584 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF
, false);
1585 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
, AUTO
);
1587 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, WLC_PROTECTION_CTL_OVERLAP
);
1589 /* 802.11g draft 4.0 NonERP elt advertisement */
1590 wlc
->include_legacy_erp
= true;
1592 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_DEF
;
1593 wlc
->stf
->txant
= ANT_TX_DEF
;
1595 wlc
->prb_resp_timeout
= WLC_PRB_RESP_TIMEOUT
;
1597 wlc
->usr_fragthresh
= DOT11_DEFAULT_FRAG_LEN
;
1598 for (i
= 0; i
< NFIFO
; i
++)
1599 wlc
->fragthresh
[i
] = DOT11_DEFAULT_FRAG_LEN
;
1600 wlc
->RTSThresh
= DOT11_DEFAULT_RTS_LEN
;
1602 /* default rate fallback retry limits */
1603 wlc
->SFBL
= RETRY_SHORT_FB
;
1604 wlc
->LFBL
= RETRY_LONG_FB
;
1606 /* default mac retry limits */
1607 wlc
->SRL
= RETRY_SHORT_DEF
;
1608 wlc
->LRL
= RETRY_LONG_DEF
;
1611 wlc
->PM
= PM_OFF
; /* User's setting of PM mode through IOCTL */
1612 wlc
->PM_override
= false; /* Prevents from going to PM if our AP is 'ill' */
1613 wlc
->PMenabled
= false; /* Current PM state */
1614 wlc
->PMpending
= false; /* Tracks whether STA indicated PM in the last attempt */
1615 wlc
->PMblocked
= false; /* To allow blocking going into PM during RM and scans */
1617 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1618 wlc
->WME_PM_blocked
= false;
1620 /* Init wme queuing method */
1621 wlc
->wme_prec_queuing
= false;
1623 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1625 /* Are we waiting for a response to PS-Poll that we sent */
1626 wlc
->PSpoll
= false;
1629 wlc
->wme_apsd
= true;
1630 wlc
->apsd_sta_usp
= false;
1631 wlc
->apsd_trigger_timeout
= 0; /* disable the trigger timer */
1632 wlc
->apsd_trigger_ac
= AC_BITMAP_ALL
;
1634 /* Set flag to indicate that hw keys should be used when available. */
1635 wlc
->wsec_swkeys
= false;
1637 /* init the 4 static WEP default keys */
1638 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
1639 wlc
->wsec_keys
[i
] = wlc
->wsec_def_keys
[i
];
1640 wlc
->wsec_keys
[i
]->idx
= (u8
) i
;
1643 wlc
->_regulatory_domain
= false; /* 802.11d */
1645 /* WME QoS mode is Auto by default */
1646 wlc
->pub
->_wme
= AUTO
;
1648 #ifdef BCMSDIODEV_ENABLED
1649 wlc
->pub
->_priofc
= true; /* enable priority flow control for sdio dongle */
1652 wlc
->pub
->_ampdu
= AMPDU_AGG_HOST
;
1653 wlc
->pub
->bcmerror
= 0;
1654 wlc
->ibss_allowed
= true;
1655 wlc
->ibss_coalesce_allowed
= true;
1656 wlc
->pub
->_coex
= ON
;
1658 /* intialize mpc delay */
1659 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
1661 wlc
->pr80838_war
= true;
1664 static bool wlc_state_bmac_sync(struct wlc_info
*wlc
)
1666 wlc_bmac_state_t state_bmac
;
1668 if (wlc_bmac_state_get(wlc
->hw
, &state_bmac
) != 0)
1671 wlc
->machwcap
= state_bmac
.machwcap
;
1672 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
,
1673 (s8
) state_bmac
.preamble_ovr
);
1678 static uint
wlc_attach_module(struct wlc_info
*wlc
)
1682 unit
= wlc
->pub
->unit
;
1684 wlc
->asi
= wlc_antsel_attach(wlc
, wlc
->osh
, wlc
->pub
, wlc
->hw
);
1685 if (wlc
->asi
== NULL
) {
1686 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit
);
1691 wlc
->ampdu
= wlc_ampdu_attach(wlc
);
1692 if (wlc
->ampdu
== NULL
) {
1693 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit
);
1698 /* Initialize event queue; needed before following calls */
1700 wlc_eventq_attach(wlc
->pub
, wlc
, wlc
->wl
, wlc_process_eventq
);
1701 if (wlc
->eventq
== NULL
) {
1702 WL_ERROR("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit
);
1707 if ((wlc_stf_attach(wlc
) != 0)) {
1708 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit
);
1716 struct wlc_pub
*wlc_pub(void *wlc
)
1718 return ((struct wlc_info
*) wlc
)->pub
;
1721 #define CHIP_SUPPORTS_11N(wlc) 1
1724 * The common driver entry routine. Error codes should be unique
1726 void *wlc_attach(void *wl
, u16 vendor
, u16 device
, uint unit
, bool piomode
,
1727 struct osl_info
*osh
, void *regsva
, uint bustype
,
1728 void *btparam
, uint
*perr
)
1730 struct wlc_info
*wlc
;
1733 struct wlc_pub
*pub
;
1737 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1738 unit
, __func__
, vendor
, device
);
1740 ASSERT(WSEC_MAX_RCMTA_KEYS
<= WSEC_MAX_KEYS
);
1741 ASSERT(WSEC_MAX_DEFAULT_KEYS
== WLC_DEFAULT_KEYS
);
1743 /* some code depends on packed structures */
1744 ASSERT(sizeof(struct ethhdr
) == ETH_HLEN
);
1745 ASSERT(sizeof(d11regs_t
) == SI_CORE_SIZE
);
1746 ASSERT(sizeof(ofdm_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1747 ASSERT(sizeof(cck_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1748 ASSERT(sizeof(d11txh_t
) == D11_TXH_LEN
);
1749 ASSERT(sizeof(d11rxhdr_t
) == RXHDR_LEN
);
1750 ASSERT(sizeof(struct ieee80211_hdr
) == DOT11_A4_HDR_LEN
);
1751 ASSERT(sizeof(struct ieee80211_rts
) == DOT11_RTS_LEN
);
1752 ASSERT(sizeof(tx_status_t
) == TXSTATUS_LEN
);
1753 ASSERT(sizeof(struct ieee80211_ht_cap
) == HT_CAP_IE_LEN
);
1755 ASSERT(offsetof(wl_scan_params_t
, channel_list
) ==
1756 WL_SCAN_PARAMS_FIXED_SIZE
);
1758 ASSERT(IS_ALIGNED(offsetof(wsec_key_t
, data
), sizeof(u32
)));
1759 ASSERT(ISPOWEROF2(MA_WINDOW_SZ
));
1761 ASSERT(sizeof(wlc_d11rxhdr_t
) <= WL_HWRXOFF
);
1764 * Number of replay counters value used in WPA IE must match # rxivs
1765 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1766 * 'RSN Information Element' figure 8 for this mapping.
1768 ASSERT((WPA_CAP_16_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1769 && 16 == WLC_NUMRXIVS
)
1770 || (WPA_CAP_4_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1771 && 4 == WLC_NUMRXIVS
));
1773 /* allocate struct wlc_info state and its substructures */
1774 wlc
= (struct wlc_info
*) wlc_attach_malloc(osh
, unit
, &err
, device
);
1784 wlc
->band
= wlc
->bandstate
[0];
1785 wlc
->core
= wlc
->corestate
;
1789 wlc
->btparam
= btparam
;
1790 pub
->_piomode
= piomode
;
1791 wlc
->bandinit_pending
= false;
1792 /* By default restrict TKIP associations from 11n STA's */
1793 wlc
->ht_wsec_restriction
= WLC_HT_TKIP_RESTRICT
;
1795 /* populate struct wlc_info with default values */
1796 wlc_info_init(wlc
, unit
);
1798 /* update sta/ap related parameters */
1801 /* 11n_disable nvram */
1802 n_disabled
= getintvar(pub
->vars
, "11n_disable");
1804 /* register a module (to handle iovars) */
1805 wlc_module_register(wlc
->pub
, wlc_iovars
, "wlc_iovars", wlc
,
1806 wlc_doiovar
, NULL
, NULL
);
1808 /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */
1809 err
= wlc_bmac_attach(wlc
, vendor
, device
, unit
, piomode
, osh
, regsva
,
1814 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1815 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1817 if (!wlc_state_bmac_sync(wlc
)) {
1822 pub
->phy_11ncapable
= WLC_PHY_11N_CAP(wlc
->band
);
1824 /* propagate *vars* from BMAC driver to high driver */
1825 wlc_bmac_copyfrom_vars(wlc
->hw
, &pub
->vars
, &wlc
->vars_size
);
1828 /* set maximum allowed duty cycle */
1829 wlc
->tx_duty_cycle_ofdm
=
1830 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_ofdm");
1831 wlc
->tx_duty_cycle_cck
=
1832 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_cck");
1834 wlc_stf_phy_chain_calc(wlc
);
1836 /* txchain 1: txant 0, txchain 2: txant 1 */
1837 if (WLCISNPHY(wlc
->band
) && (wlc
->stf
->txstreams
== 1))
1838 wlc
->stf
->txant
= wlc
->stf
->hw_txchain
- 1;
1840 /* push to BMAC driver */
1841 wlc_phy_stf_chain_init(wlc
->band
->pi
, wlc
->stf
->hw_txchain
,
1842 wlc
->stf
->hw_rxchain
);
1844 /* pull up some info resulting from the low attach */
1847 for (i
= 0; i
< NFIFO
; i
++)
1848 wlc
->core
->txavail
[i
] = wlc
->hw
->txavail
[i
];
1851 wlc_bmac_hw_etheraddr(wlc
->hw
, wlc
->perm_etheraddr
);
1853 bcopy((char *)&wlc
->perm_etheraddr
, (char *)&pub
->cur_etheraddr
,
1856 for (j
= 0; j
< NBANDS(wlc
); j
++) {
1857 /* Use band 1 for single band 11a */
1858 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
1861 wlc
->band
= wlc
->bandstate
[j
];
1863 if (!wlc_attach_stf_ant_init(wlc
)) {
1868 /* default contention windows size limits */
1869 wlc
->band
->CWmin
= APHY_CWMIN
;
1870 wlc
->band
->CWmax
= PHY_CWMAX
;
1872 /* init gmode value */
1873 if (BAND_2G(wlc
->band
->bandtype
)) {
1874 wlc
->band
->gmode
= GMODE_AUTO
;
1875 wlc_protection_upd(wlc
, WLC_PROT_G_USER
,
1879 /* init _n_enab supported mode */
1880 if (WLC_PHY_11N_CAP(wlc
->band
) && CHIP_SUPPORTS_11N(wlc
)) {
1881 if (n_disabled
& WLFEATURE_DISABLE_11N
) {
1883 wlc_protection_upd(wlc
, WLC_PROT_N_USER
, OFF
);
1885 pub
->_n_enab
= SUPPORT_11N
;
1886 wlc_protection_upd(wlc
, WLC_PROT_N_USER
,
1888 SUPPORT_11N
) ? WL_11N_2x2
:
1893 /* init per-band default rateset, depend on band->gmode */
1894 wlc_default_rateset(wlc
, &wlc
->band
->defrateset
);
1896 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1897 wlc_rateset_filter(&wlc
->band
->defrateset
,
1898 &wlc
->band
->hw_rateset
, false,
1899 WLC_RATES_CCK_OFDM
, RATE_MASK
,
1900 (bool) N_ENAB(wlc
->pub
));
1903 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1904 wlc_stf_phy_txant_upd(wlc
);
1906 /* attach each modules */
1907 err
= wlc_attach_module(wlc
);
1911 if (!wlc_timers_init(wlc
, unit
)) {
1912 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit
, __func__
);
1917 /* depend on rateset, gmode */
1918 wlc
->cmi
= wlc_channel_mgr_attach(wlc
);
1920 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1926 /* init default when all parameters are ready, i.e. ->rateset */
1927 wlc_bss_default_init(wlc
);
1930 * Complete the wlc default state initializations..
1933 /* allocate our initial queue */
1934 qi
= wlc_txq_alloc(wlc
, osh
);
1936 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1941 wlc
->active_queue
= qi
;
1943 wlc
->bsscfg
[0] = wlc
->cfg
;
1945 wlc
->cfg
->wlc
= wlc
;
1946 pub
->txmaxpkts
= MAXTXPKTS
;
1948 WLCNTSET(pub
->_cnt
->version
, WL_CNT_T_VERSION
);
1949 WLCNTSET(pub
->_cnt
->length
, sizeof(wl_cnt_t
));
1951 WLCNTSET(pub
->_wme_cnt
->version
, WL_WME_CNT_VERSION
);
1952 WLCNTSET(pub
->_wme_cnt
->length
, sizeof(wl_wme_cnt_t
));
1954 wlc_wme_initparams_sta(wlc
, &wlc
->wme_param_ie
);
1956 wlc
->mimoft
= FT_HT
;
1957 wlc
->ht_cap
.cap_info
= HT_CAP
;
1958 if (HT_ENAB(wlc
->pub
))
1959 wlc
->stf
->ldpc
= AUTO
;
1961 wlc
->mimo_40txbw
= AUTO
;
1962 wlc
->ofdm_40txbw
= AUTO
;
1963 wlc
->cck_40txbw
= AUTO
;
1964 wlc_update_mimo_band_bwcap(wlc
, WLC_N_BW_20IN2G_40IN5G
);
1966 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1967 wlc
->rifs_advert
= AUTO
;
1969 /* Set default values of SGI */
1970 if (WLC_SGI_CAP_PHY(wlc
)) {
1971 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1973 } else if (WLCISSSLPNPHY(wlc
->band
)) {
1974 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1977 wlc_ht_update_sgi_rx(wlc
, 0);
1981 /* *******nvram 11n config overrides Start ********* */
1983 /* apply the sgi override from nvram conf */
1984 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_TX
)
1987 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_RX
)
1988 wlc_ht_update_sgi_rx(wlc
, 0);
1990 /* apply the stbc override from nvram conf */
1991 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_TX
) {
1992 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= OFF
;
1993 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= OFF
;
1994 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_TX_STBC
;
1996 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_RX
)
1997 wlc_stf_stbc_rx_set(wlc
, HT_CAP_RX_STBC_NO
);
1999 /* apply the GF override from nvram conf */
2000 if (n_disabled
& WLFEATURE_DISABLE_11N_GF
)
2001 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_GRN_FLD
;
2003 /* initialize radio_mpc_disable according to wlc->mpc */
2004 wlc_radio_mpc_upd(wlc
);
2006 if (WLANTSEL_ENAB(wlc
)) {
2007 if ((wlc
->pub
->sih
->chip
) == BCM43235_CHIP_ID
) {
2008 if ((getintvar(wlc
->pub
->vars
, "aa2g") == 7) ||
2009 (getintvar(wlc
->pub
->vars
, "aa5g") == 7)) {
2010 wlc_bmac_antsel_set(wlc
->hw
, 1);
2013 wlc_bmac_antsel_set(wlc
->hw
, wlc
->asi
->antsel_avail
);
2023 WL_ERROR("wl%d: %s: failed with err %d\n", unit
, __func__
, err
);
2032 static void wlc_attach_antgain_init(struct wlc_info
*wlc
)
2035 unit
= wlc
->pub
->unit
;
2037 if ((wlc
->band
->antgain
== -1) && (wlc
->pub
->sromrev
== 1)) {
2038 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2039 wlc
->band
->antgain
= 8;
2040 } else if (wlc
->band
->antgain
== -1) {
2041 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2043 wlc
->band
->antgain
= 8;
2046 /* Older sroms specified gain in whole dbm only. In order
2047 * be able to specify qdbm granularity and remain backward compatible
2048 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2049 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2050 * -32 - 31. Examples: 0x1 = 1 db,
2051 * 0xc1 = 1.75 db (1 + 3 quarters),
2052 * 0x3f = -1 (-1 + 0 quarters),
2053 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2054 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2056 gain
= wlc
->band
->antgain
& 0x3f;
2057 gain
<<= 2; /* Sign extend */
2059 fract
= (wlc
->band
->antgain
& 0xc0) >> 6;
2060 wlc
->band
->antgain
= 4 * gain
+ fract
;
2064 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
)
2071 unit
= wlc
->pub
->unit
;
2072 vars
= wlc
->pub
->vars
;
2073 bandtype
= wlc
->band
->bandtype
;
2075 /* get antennas available */
2076 aa
= (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "aa5g" : "aa2g"));
2078 aa
= (s8
) getintvar(vars
,
2079 (BAND_5G(bandtype
) ? "aa1" : "aa0"));
2080 if ((aa
< 1) || (aa
> 15)) {
2081 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2082 unit
, __func__
, aa
);
2086 /* reset the defaults if we have a single antenna */
2088 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_0
;
2089 wlc
->stf
->txant
= ANT_TX_FORCE_0
;
2090 } else if (aa
== 2) {
2091 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_1
;
2092 wlc
->stf
->txant
= ANT_TX_FORCE_1
;
2096 /* Compute Antenna Gain */
2097 wlc
->band
->antgain
=
2098 (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "ag1" : "ag0"));
2099 wlc_attach_antgain_init(wlc
);
2105 static void wlc_timers_deinit(struct wlc_info
*wlc
)
2107 /* free timer state */
2109 wl_free_timer(wlc
->wl
, wlc
->wdtimer
);
2110 wlc
->wdtimer
= NULL
;
2112 if (wlc
->radio_timer
) {
2113 wl_free_timer(wlc
->wl
, wlc
->radio_timer
);
2114 wlc
->radio_timer
= NULL
;
2118 static void wlc_detach_module(struct wlc_info
*wlc
)
2121 wlc_antsel_detach(wlc
->asi
);
2126 wlc_ampdu_detach(wlc
->ampdu
);
2130 wlc_stf_detach(wlc
);
2134 * Return a count of the number of driver callbacks still pending.
2136 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2137 * touch hardware registers since the d11core may be in reset and clock may not be available.
2138 * One exception is sb register access, which is possible if crystal is turned on
2139 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2141 uint
wlc_detach(struct wlc_info
*wlc
)
2149 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
2151 ASSERT(!wlc
->pub
->up
);
2153 callbacks
+= wlc_bmac_detach(wlc
);
2155 /* delete software timers */
2156 if (!wlc_radio_monitor_stop(wlc
))
2160 wlc_eventq_detach(wlc
->eventq
);
2164 wlc_channel_mgr_detach(wlc
->cmi
);
2166 wlc_timers_deinit(wlc
);
2168 wlc_detach_module(wlc
);
2170 /* free other state */
2174 if (wlc
->country_ie_override
) {
2175 kfree(wlc
->country_ie_override
);
2176 wlc
->country_ie_override
= NULL
;
2181 /* free dumpcb list */
2182 dumpcb_t
*prev
, *ptr
;
2183 prev
= ptr
= wlc
->dumpcb_head
;
2189 wlc
->dumpcb_head
= NULL
;
2192 /* Detach from iovar manager */
2193 wlc_module_unregister(wlc
->pub
, "wlc_iovars", wlc
);
2195 while (wlc
->tx_queues
!= NULL
) {
2196 wlc_txq_free(wlc
, wlc
->osh
, wlc
->tx_queues
);
2200 * consistency check: wlc_module_register/wlc_module_unregister calls
2201 * should match therefore nothing should be left here.
2203 for (i
= 0; i
< WLC_MAXMODULES
; i
++)
2204 ASSERT(wlc
->modulecb
[i
].name
[0] == '\0');
2206 wlc_detach_mfree(wlc
, wlc
->osh
);
2210 /* update state that depends on the current value of "ap" */
2211 void wlc_ap_upd(struct wlc_info
*wlc
)
2213 if (AP_ENAB(wlc
->pub
))
2214 wlc
->PLCPHdr_override
= WLC_PLCP_AUTO
; /* AP: short not allowed, but not enforced */
2216 wlc
->PLCPHdr_override
= WLC_PLCP_SHORT
; /* STA-BSS; short capable */
2218 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2219 wlc
->vlan_mode
= AP_ENAB(wlc
->pub
) ? OFF
: AUTO
;
2225 /* read hwdisable state and propagate to wlc flag */
2226 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
)
2228 if (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
|| wlc
->pub
->hw_off
)
2231 if (wlc_bmac_radio_read_hwdisabled(wlc
->hw
)) {
2232 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2234 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2238 /* return true if Minimum Power Consumption should be entered, false otherwise */
2239 bool wlc_is_non_delay_mpc(struct wlc_info
*wlc
)
2244 bool wlc_ismpc(struct wlc_info
*wlc
)
2246 return (wlc
->mpc_delay_off
== 0) && (wlc_is_non_delay_mpc(wlc
));
2249 void wlc_radio_mpc_upd(struct wlc_info
*wlc
)
2251 bool mpc_radio
, radio_state
;
2254 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2255 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2256 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2257 * the radio is going down.
2260 if (!wlc
->pub
->radio_disabled
)
2262 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2264 if (!wlc
->pub
->radio_disabled
)
2265 wlc_radio_monitor_stop(wlc
);
2270 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2271 * to go ON, always call radio_upd synchronously
2272 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2275 (mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
) ? OFF
:
2277 mpc_radio
= (wlc_ismpc(wlc
) == true) ? OFF
: ON
;
2279 if (radio_state
== ON
&& mpc_radio
== OFF
)
2280 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2281 else if (radio_state
== OFF
&& mpc_radio
== ON
) {
2282 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2284 if (wlc
->mpc_offcnt
< WLC_MPC_THRESHOLD
) {
2285 wlc
->mpc_dlycnt
= WLC_MPC_MAX_DELAYCNT
;
2287 wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
2288 wlc
->mpc_dur
+= OSL_SYSUPTIME() - wlc
->mpc_laston_ts
;
2290 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2291 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2292 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2294 if ((wlc
->prev_non_delay_mpc
== false) &&
2295 (wlc_is_non_delay_mpc(wlc
) == true) && wlc
->mpc_delay_off
) {
2296 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2298 wlc
->prev_non_delay_mpc
= wlc_is_non_delay_mpc(wlc
);
2302 * centralized radio disable/enable function,
2303 * invoke radio enable/disable after updating hwradio status
2305 static void wlc_radio_upd(struct wlc_info
*wlc
)
2307 if (wlc
->pub
->radio_disabled
)
2308 wlc_radio_disable(wlc
);
2310 wlc_radio_enable(wlc
);
2313 /* maintain LED behavior in down state */
2314 static void wlc_down_led_upd(struct wlc_info
*wlc
)
2316 ASSERT(!wlc
->pub
->up
);
2318 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2319 /* turn on sbclk if necessary */
2320 if (!AP_ENAB(wlc
->pub
)) {
2321 wlc_pllreq(wlc
, true, WLC_PLLREQ_FLIP
);
2323 wlc_pllreq(wlc
, false, WLC_PLLREQ_FLIP
);
2327 void wlc_radio_disable(struct wlc_info
*wlc
)
2329 if (!wlc
->pub
->up
) {
2330 wlc_down_led_upd(wlc
);
2334 wlc_radio_monitor_start(wlc
);
2338 static void wlc_radio_enable(struct wlc_info
*wlc
)
2343 if (DEVICEREMOVED(wlc
))
2346 if (!wlc
->down_override
) { /* imposed by wl down/out ioctl */
2351 /* periodical query hw radio button while driver is "down" */
2352 static void wlc_radio_timer(void *arg
)
2354 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2356 if (DEVICEREMOVED(wlc
)) {
2357 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2362 /* cap mpc off count */
2363 if (wlc
->mpc_offcnt
< WLC_MPC_MAX_DELAYCNT
)
2366 /* validate all the reasons driver could be down and running this radio_timer */
2367 ASSERT(wlc
->pub
->radio_disabled
|| wlc
->down_override
);
2368 wlc_radio_hwdisable_upd(wlc
);
2372 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
)
2374 /* Don't start the timer if HWRADIO feature is disabled */
2375 if (wlc
->radio_monitor
|| (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
))
2378 wlc
->radio_monitor
= true;
2379 wlc_pllreq(wlc
, true, WLC_PLLREQ_RADIO_MON
);
2380 wl_add_timer(wlc
->wl
, wlc
->radio_timer
, TIMER_INTERVAL_RADIOCHK
, true);
2384 bool wlc_radio_monitor_stop(struct wlc_info
*wlc
)
2386 if (!wlc
->radio_monitor
)
2389 ASSERT((wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
) !=
2392 wlc
->radio_monitor
= false;
2393 wlc_pllreq(wlc
, false, WLC_PLLREQ_RADIO_MON
);
2394 return wl_del_timer(wlc
->wl
, wlc
->radio_timer
);
2397 /* bring the driver down, but don't reset hardware */
2398 void wlc_out(struct wlc_info
*wlc
)
2400 wlc_bmac_set_noreset(wlc
->hw
, true);
2403 wlc_bmac_set_noreset(wlc
->hw
, false);
2405 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2408 /* This will make sure that when 'up' is done
2409 * after 'out' it'll restore hardware (especially gpios)
2411 wlc
->pub
->hw_up
= false;
2415 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2416 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2417 * in prec_map. Of course, ignore this rule when block_datafifo is set
2419 static bool wlc_tx_prec_map_verify(struct wlc_info
*wlc
)
2421 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2424 if (!EDCF_ENAB(wlc
->pub
)) {
2425 if (!(WLC_TX_FIFO_CHECK(wlc
, TX_DATA_FIFO
) ||
2426 WLC_TX_FIFO_CHECK(wlc
, TX_CTL_FIFO
)))
2432 return WLC_TX_FIFO_CHECK(wlc
, TX_AC_BK_FIFO
)
2433 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_BE_FIFO
)
2434 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VI_FIFO
)
2435 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VO_FIFO
);
2439 static void wlc_watchdog_by_timer(void *arg
)
2441 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2443 if (WLC_WATCHDOG_TBTT(wlc
)) {
2444 /* set to normal osl watchdog period */
2445 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
2446 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
2451 /* common watchdog code */
2452 static void wlc_watchdog(void *arg
)
2454 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2458 WL_TRACE("wl%d: wlc_watchdog\n", wlc
->pub
->unit
);
2463 if (DEVICEREMOVED(wlc
)) {
2464 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2469 /* increment second count */
2472 /* delay radio disable */
2473 if (wlc
->mpc_delay_off
) {
2474 if (--wlc
->mpc_delay_off
== 0) {
2475 mboolset(wlc
->pub
->radio_disabled
,
2476 WL_RADIO_MPC_DISABLE
);
2477 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2478 wlc
->mpc_offcnt
= 0;
2479 wlc
->mpc_laston_ts
= OSL_SYSUPTIME();
2484 wlc_radio_mpc_upd(wlc
);
2485 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2486 wlc_radio_hwdisable_upd(wlc
);
2488 /* if ismpc, driver should be in down state if up/down is allowed */
2489 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2490 ASSERT(!wlc
->pub
->up
);
2491 /* if radio is disable, driver may be down, quit here */
2492 if (wlc
->pub
->radio_disabled
)
2495 wlc_bmac_watchdog(wlc
);
2497 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2498 if ((WLC_UPDATE_STATS(wlc
))
2499 && (!(wlc
->pub
->now
% SW_TIMER_MAC_STAT_UPD
)))
2502 /* Manage TKIP countermeasures timers */
2503 FOREACH_BSS(wlc
, i
, cfg
) {
2504 if (cfg
->tk_cm_dt
) {
2507 if (cfg
->tk_cm_bt
) {
2512 /* Call any registered watchdog handlers */
2513 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2514 if (wlc
->modulecb
[i
].watchdog_fn
)
2515 wlc
->modulecb
[i
].watchdog_fn(wlc
->modulecb
[i
].hdl
);
2518 if (WLCISNPHY(wlc
->band
) && !wlc
->pub
->tempsense_disable
&&
2519 ((wlc
->pub
->now
- wlc
->tempsense_lasttime
) >=
2520 WLC_TEMPSENSE_PERIOD
)) {
2521 wlc
->tempsense_lasttime
= wlc
->pub
->now
;
2522 wlc_tempsense_upd(wlc
);
2524 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2525 ASSERT(wlc_bmac_taclear(wlc
->hw
, true));
2527 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2528 ASSERT(wlc_tx_prec_map_verify(wlc
));
2530 ASSERT(wlc_ps_check(wlc
));
2533 /* make interface operational */
2534 int wlc_up(struct wlc_info
*wlc
)
2536 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2538 /* HW is turned off so don't try to access it */
2539 if (wlc
->pub
->hw_off
|| DEVICEREMOVED(wlc
))
2540 return BCME_RADIOOFF
;
2542 if (!wlc
->pub
->hw_up
) {
2543 wlc_bmac_hw_up(wlc
->hw
);
2544 wlc
->pub
->hw_up
= true;
2547 if ((wlc
->pub
->boardflags
& BFL_FEM
)
2548 && (wlc
->pub
->sih
->chip
== BCM4313_CHIP_ID
)) {
2549 if (wlc
->pub
->boardrev
>= 0x1250
2550 && (wlc
->pub
->boardflags
& BFL_FEM_BT
)) {
2551 wlc_mhf(wlc
, MHF5
, MHF5_4313_GPIOCTRL
,
2552 MHF5_4313_GPIOCTRL
, WLC_BAND_ALL
);
2554 wlc_mhf(wlc
, MHF4
, MHF4_EXTPA_ENABLE
, MHF4_EXTPA_ENABLE
,
2560 * Need to read the hwradio status here to cover the case where the system
2561 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2562 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2563 * don't call radio_update to avoid looping wlc_up.
2565 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2567 if (!wlc
->pub
->radio_disabled
) {
2568 int status
= wlc_bmac_up_prep(wlc
->hw
);
2569 if (status
== BCME_RADIOOFF
) {
2571 (wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
)) {
2573 wlc_bsscfg_t
*bsscfg
;
2574 mboolset(wlc
->pub
->radio_disabled
,
2575 WL_RADIO_HW_DISABLE
);
2577 FOREACH_BSS(wlc
, idx
, bsscfg
) {
2578 if (!BSSCFG_STA(bsscfg
)
2579 || !bsscfg
->enable
|| !bsscfg
->BSS
)
2581 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2582 wlc
->pub
->unit
, idx
);
2589 if (wlc
->pub
->radio_disabled
) {
2590 wlc_radio_monitor_start(wlc
);
2594 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2597 wlc_radio_monitor_stop(wlc
);
2599 /* Set EDCF hostflags */
2600 if (EDCF_ENAB(wlc
->pub
)) {
2601 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, MHF1_EDCF
, WLC_BAND_ALL
);
2603 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, 0, WLC_BAND_ALL
);
2606 if (WLC_WAR16165(wlc
))
2607 wlc_mhf(wlc
, MHF2
, MHF2_PCISLOWCLKWAR
, MHF2_PCISLOWCLKWAR
,
2611 wlc
->pub
->up
= true;
2613 if (wlc
->bandinit_pending
) {
2614 wlc_suspend_mac_and_wait(wlc
);
2615 wlc_set_chanspec(wlc
, wlc
->default_bss
->chanspec
);
2616 wlc
->bandinit_pending
= false;
2617 wlc_enable_mac(wlc
);
2620 wlc_bmac_up_finish(wlc
->hw
);
2622 /* other software states up after ISR is running */
2623 /* start APs that were to be brought up but are not up yet */
2624 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2626 /* Program the TX wme params with the current settings */
2627 wlc_wme_retries_write(wlc
);
2629 /* start one second watchdog timer */
2630 ASSERT(!wlc
->WDarmed
);
2631 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
, true);
2632 wlc
->WDarmed
= true;
2634 /* ensure antenna config is up to date */
2635 wlc_stf_phy_txant_upd(wlc
);
2636 /* ensure LDPC config is in sync */
2637 wlc_ht_update_ldpc(wlc
, wlc
->stf
->ldpc
);
2642 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2643 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
)
2645 wlc
->tx_prec_map
= WLC_PREC_BMP_ALL
;
2646 memset(wlc
->fifo2prec_map
, 0, NFIFO
* sizeof(u16
));
2648 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2649 * if either is full.
2651 if (!EDCF_ENAB(wlc
->pub
)) {
2652 wlc
->fifo2prec_map
[TX_DATA_FIFO
] = WLC_PREC_BMP_ALL
;
2653 wlc
->fifo2prec_map
[TX_CTL_FIFO
] = WLC_PREC_BMP_ALL
;
2655 wlc
->fifo2prec_map
[TX_AC_BK_FIFO
] = WLC_PREC_BMP_AC_BK
;
2656 wlc
->fifo2prec_map
[TX_AC_BE_FIFO
] = WLC_PREC_BMP_AC_BE
;
2657 wlc
->fifo2prec_map
[TX_AC_VI_FIFO
] = WLC_PREC_BMP_AC_VI
;
2658 wlc
->fifo2prec_map
[TX_AC_VO_FIFO
] = WLC_PREC_BMP_AC_VO
;
2662 static uint
wlc_down_del_timer(struct wlc_info
*wlc
)
2670 * Mark the interface nonoperational, stop the software mechanisms,
2671 * disable the hardware, free any transient buffer state.
2672 * Return a count of the number of driver callbacks still pending.
2674 uint
wlc_down(struct wlc_info
*wlc
)
2679 bool dev_gone
= false;
2682 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2684 /* check if we are already in the going down path */
2685 if (wlc
->going_down
) {
2686 WL_ERROR("wl%d: %s: Driver going down so return\n",
2687 wlc
->pub
->unit
, __func__
);
2693 /* in between, mpc could try to bring down again.. */
2694 wlc
->going_down
= true;
2696 callbacks
+= wlc_bmac_down_prep(wlc
->hw
);
2698 dev_gone
= DEVICEREMOVED(wlc
);
2700 /* Call any registered down handlers */
2701 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2702 if (wlc
->modulecb
[i
].down_fn
)
2704 wlc
->modulecb
[i
].down_fn(wlc
->modulecb
[i
].hdl
);
2707 /* cancel the watchdog timer */
2709 if (!wl_del_timer(wlc
->wl
, wlc
->wdtimer
))
2711 wlc
->WDarmed
= false;
2713 /* cancel all other timers */
2714 callbacks
+= wlc_down_del_timer(wlc
);
2716 /* interrupt must have been blocked */
2717 ASSERT((wlc
->macintmask
== 0) || !wlc
->pub
->up
);
2719 wlc
->pub
->up
= false;
2721 wlc_phy_mute_upd(wlc
->band
->pi
, false, PHY_MUTE_ALL
);
2723 /* clear txq flow control */
2724 wlc_txflowcontrol_reset(wlc
);
2726 /* flush tx queues */
2727 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
2728 pktq_flush(wlc
->osh
, &qi
->q
, true, NULL
, 0);
2729 ASSERT(pktq_empty(&qi
->q
));
2732 /* flush event queue.
2733 * Should be the last thing done after all the events are generated
2734 * Just delivers the events synchronously instead of waiting for a timer
2736 callbacks
+= wlc_eventq_down(wlc
->eventq
);
2738 callbacks
+= wlc_bmac_down_finish(wlc
->hw
);
2740 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2744 /* Verify all packets are flushed from the driver */
2745 if (wlc
->osh
->pktalloced
!= 0) {
2746 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2747 wlc
->osh
->pktalloced
);
2750 /* Since all the packets should have been freed,
2751 * all callbacks should have been called
2753 for (i
= 1; i
<= wlc
->pub
->tunables
->maxpktcb
; i
++)
2754 ASSERT(wlc
->pkt_callback
[i
].fn
== NULL
);
2756 wlc
->going_down
= false;
2760 /* Set the current gmode configuration */
2761 int wlc_set_gmode(struct wlc_info
*wlc
, u8 gmode
, bool config
)
2766 /* Default to 54g Auto */
2767 s8 shortslot
= WLC_SHORTSLOT_AUTO
; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2768 bool shortslot_restrict
= false; /* Restrict association to stations that support shortslot
2770 bool ignore_bcns
= true; /* Ignore legacy beacons on the same channel */
2771 bool ofdm_basic
= false; /* Make 6, 12, and 24 basic rates */
2772 int preamble
= WLC_PLCP_LONG
; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2773 bool preamble_restrict
= false; /* Restrict association to stations that support short
2776 struct wlcband
*band
;
2778 /* if N-support is enabled, allow Gmode set as long as requested
2779 * Gmode is not GMODE_LEGACY_B
2781 if (N_ENAB(wlc
->pub
) && gmode
== GMODE_LEGACY_B
)
2782 return BCME_UNSUPPORTED
;
2784 /* verify that we are dealing with 2G band and grab the band pointer */
2785 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
2787 else if ((NBANDS(wlc
) > 1) &&
2788 (wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
== WLC_BAND_2G
))
2789 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
2791 return BCME_BADBAND
;
2793 /* Legacy or bust when no OFDM is supported by regulatory */
2794 if ((wlc_channel_locale_flags_in_band(wlc
->cmi
, band
->bandunit
) &
2795 WLC_NO_OFDM
) && (gmode
!= GMODE_LEGACY_B
))
2798 /* update configuration value */
2800 wlc_protection_upd(wlc
, WLC_PROT_G_USER
, gmode
);
2802 /* Clear supported rates filter */
2803 memset(&wlc
->sup_rates_override
, 0, sizeof(wlc_rateset_t
));
2805 /* Clear rateset override */
2806 memset(&rs
, 0, sizeof(wlc_rateset_t
));
2809 case GMODE_LEGACY_B
:
2810 shortslot
= WLC_SHORTSLOT_OFF
;
2811 wlc_rateset_copy(&gphy_legacy_rates
, &rs
);
2816 if (AP_ENAB(wlc
->pub
))
2817 wlc_rateset_copy(&cck_rates
, &wlc
->sup_rates_override
);
2821 /* Accept defaults */
2826 preamble
= WLC_PLCP_SHORT
;
2827 preamble_restrict
= true;
2830 case GMODE_PERFORMANCE
:
2831 if (AP_ENAB(wlc
->pub
)) /* Put all rates into the Supported Rates element */
2832 wlc_rateset_copy(&cck_ofdm_rates
,
2833 &wlc
->sup_rates_override
);
2835 shortslot
= WLC_SHORTSLOT_ON
;
2836 shortslot_restrict
= true;
2838 preamble
= WLC_PLCP_SHORT
;
2839 preamble_restrict
= true;
2844 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2845 wlc
->pub
->unit
, __func__
, gmode
);
2846 return BCME_UNSUPPORTED
;
2850 * If we are switching to gmode == GMODE_LEGACY_B,
2851 * clean up rate info that may refer to OFDM rates.
2853 if ((gmode
== GMODE_LEGACY_B
) && (band
->gmode
!= GMODE_LEGACY_B
)) {
2854 band
->gmode
= gmode
;
2855 if (band
->rspec_override
&& !IS_CCK(band
->rspec_override
)) {
2856 band
->rspec_override
= 0;
2857 wlc_reprate_init(wlc
);
2859 if (band
->mrspec_override
&& !IS_CCK(band
->mrspec_override
)) {
2860 band
->mrspec_override
= 0;
2864 band
->gmode
= gmode
;
2866 wlc
->ignore_bcns
= ignore_bcns
;
2868 wlc
->shortslot_override
= shortslot
;
2870 if (AP_ENAB(wlc
->pub
)) {
2871 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2872 wlc
->PLCPHdr_override
=
2874 WLC_PLCP_LONG
) ? WLC_PLCP_SHORT
: WLC_PLCP_AUTO
;
2877 if ((AP_ENAB(wlc
->pub
) && preamble
!= WLC_PLCP_LONG
)
2878 || preamble
== WLC_PLCP_SHORT
)
2879 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
2881 wlc
->default_bss
->capability
&= ~WLAN_CAPABILITY_SHORT_PREAMBLE
;
2883 /* Update shortslot capability bit for AP and IBSS */
2884 if ((AP_ENAB(wlc
->pub
) && shortslot
== WLC_SHORTSLOT_AUTO
) ||
2885 shortslot
== WLC_SHORTSLOT_ON
)
2886 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2888 wlc
->default_bss
->capability
&=
2889 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2891 /* Use the default 11g rateset */
2893 wlc_rateset_copy(&cck_ofdm_rates
, &rs
);
2896 for (i
= 0; i
< rs
.count
; i
++) {
2897 if (rs
.rates
[i
] == WLC_RATE_6M
2898 || rs
.rates
[i
] == WLC_RATE_12M
2899 || rs
.rates
[i
] == WLC_RATE_24M
)
2900 rs
.rates
[i
] |= WLC_RATE_FLAG
;
2904 /* Set default bss rateset */
2905 wlc
->default_bss
->rateset
.count
= rs
.count
;
2906 bcopy((char *)rs
.rates
, (char *)wlc
->default_bss
->rateset
.rates
,
2907 sizeof(wlc
->default_bss
->rateset
.rates
));
2912 static int wlc_nmode_validate(struct wlc_info
*wlc
, s32 nmode
)
2924 if (!(WLC_PHY_11N_CAP(wlc
->band
)))
2936 int wlc_set_nmode(struct wlc_info
*wlc
, s32 nmode
)
2941 err
= wlc_nmode_validate(wlc
, nmode
);
2948 wlc
->pub
->_n_enab
= OFF
;
2949 wlc
->default_bss
->flags
&= ~WLC_BSS_HT
;
2950 /* delete the mcs rates from the default and hw ratesets */
2951 wlc_rateset_mcs_clear(&wlc
->default_bss
->rateset
);
2952 for (i
= 0; i
< NBANDS(wlc
); i
++) {
2953 memset(wlc
->bandstate
[i
]->hw_rateset
.mcs
, 0,
2955 if (IS_MCS(wlc
->band
->rspec_override
)) {
2956 wlc
->bandstate
[i
]->rspec_override
= 0;
2957 wlc_reprate_init(wlc
);
2959 if (IS_MCS(wlc
->band
->mrspec_override
))
2960 wlc
->bandstate
[i
]->mrspec_override
= 0;
2965 if (wlc
->stf
->txstreams
== WL_11N_3x3
)
2971 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
2972 /* force GMODE_AUTO if NMODE is ON */
2973 wlc_set_gmode(wlc
, GMODE_AUTO
, true);
2974 if (nmode
== WL_11N_3x3
)
2975 wlc
->pub
->_n_enab
= SUPPORT_HT
;
2977 wlc
->pub
->_n_enab
= SUPPORT_11N
;
2978 wlc
->default_bss
->flags
|= WLC_BSS_HT
;
2979 /* add the mcs rates to the default and hw ratesets */
2980 wlc_rateset_mcs_build(&wlc
->default_bss
->rateset
,
2981 wlc
->stf
->txstreams
);
2982 for (i
= 0; i
< NBANDS(wlc
); i
++)
2983 memcpy(wlc
->bandstate
[i
]->hw_rateset
.mcs
,
2984 wlc
->default_bss
->rateset
.mcs
, MCSSET_LEN
);
2995 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
)
2997 wlc_rateset_t rs
, new;
3000 bcopy((char *)rs_arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
3002 /* check for bad count value */
3003 if ((rs
.count
== 0) || (rs
.count
> WLC_NUMRATES
))
3004 return BCME_BADRATESET
;
3006 /* try the current band */
3007 bandunit
= wlc
->band
->bandunit
;
3008 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3009 if (wlc_rate_hwrs_filter_sort_validate
3010 (&new, &wlc
->bandstate
[bandunit
]->hw_rateset
, true,
3011 wlc
->stf
->txstreams
))
3014 /* try the other band */
3015 if (IS_MBAND_UNLOCKED(wlc
)) {
3016 bandunit
= OTHERBANDUNIT(wlc
);
3017 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3018 if (wlc_rate_hwrs_filter_sort_validate(&new,
3020 bandstate
[bandunit
]->
3022 wlc
->stf
->txstreams
))
3029 /* apply new rateset */
3030 bcopy((char *)&new, (char *)&wlc
->default_bss
->rateset
,
3031 sizeof(wlc_rateset_t
));
3032 bcopy((char *)&new, (char *)&wlc
->bandstate
[bandunit
]->defrateset
,
3033 sizeof(wlc_rateset_t
));
3037 /* simplified integer set interface for common ioctl handler */
3038 int wlc_set(struct wlc_info
*wlc
, int cmd
, int arg
)
3040 return wlc_ioctl(wlc
, cmd
, (void *)&arg
, sizeof(arg
), NULL
);
3043 /* simplified integer get interface for common ioctl handler */
3044 int wlc_get(struct wlc_info
*wlc
, int cmd
, int *arg
)
3046 return wlc_ioctl(wlc
, cmd
, arg
, sizeof(int), NULL
);
3049 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
)
3054 if (wlc
->cfg
->associated
)
3055 r
= wlc
->cfg
->current_bss
->rateset
.rates
[0];
3057 r
= wlc
->default_bss
->rateset
.rates
[0];
3059 wlc_phy_ofdm_rateset_war(wlc
->band
->pi
, war
);
3065 wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3066 struct wlc_if
*wlcif
)
3068 return _wlc_ioctl(wlc
, cmd
, arg
, len
, wlcif
);
3071 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3073 _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3074 struct wlc_if
*wlcif
)
3081 struct scb
*nextscb
;
3085 wlc_bsscfg_t
*bsscfg
;
3086 struct osl_info
*osh
;
3087 wlc_bss_info_t
*current_bss
;
3089 /* update bsscfg pointer */
3090 bsscfg
= NULL
; /* XXX: Hack bsscfg to be size one and use this globally */
3093 /* initialize the following to get rid of compiler warning */
3099 /* If the device is turned off, then it's not "removed" */
3100 if (!wlc
->pub
->hw_off
&& DEVICEREMOVED(wlc
)) {
3101 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
3106 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
3108 /* default argument is generic integer */
3109 pval
= arg
? (int *)arg
:NULL
;
3111 /* This will prevent the misaligned access */
3112 if (pval
&& (u32
) len
>= sizeof(val
))
3113 bcopy(pval
, &val
, sizeof(val
));
3117 /* bool conversion to avoid duplication below */
3118 bool_val
= val
!= 0;
3120 if (cmd
!= WLC_SET_CHANNEL
)
3121 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3122 cmd
, (uint
)val
, val
, len
);
3128 /* A few commands don't need any arguments; all the others do. */
3136 case WLC_START_CHANNEL_QA
:
3141 if ((arg
== NULL
) || (len
<= 0)) {
3142 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3143 wlc
->pub
->unit
, __func__
, cmd
);
3144 bcmerror
= BCME_BADARG
;
3152 case WLC_GET_MSGLEVEL
:
3153 *pval
= wl_msg_level
;
3156 case WLC_SET_MSGLEVEL
:
3161 case WLC_GET_INSTANCE
:
3162 *pval
= wlc
->pub
->unit
;
3165 case WLC_GET_CHANNEL
:{
3166 channel_info_t
*ci
= (channel_info_t
*) arg
;
3168 ASSERT(len
> (int)sizeof(ci
));
3171 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
);
3172 ci
->target_channel
=
3173 CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
);
3174 ci
->scan_channel
= 0;
3179 case WLC_SET_CHANNEL
:{
3180 chanspec_t chspec
= CH20MHZ_CHSPEC(val
);
3182 if (val
< 0 || val
> MAXCHANNEL
) {
3183 bcmerror
= BCME_OUTOFRANGECHAN
;
3187 if (!wlc_valid_chanspec_db(wlc
->cmi
, chspec
)) {
3188 bcmerror
= BCME_BADCHAN
;
3192 if (!wlc
->pub
->up
&& IS_MBAND_UNLOCKED(wlc
)) {
3193 if (wlc
->band
->bandunit
!=
3194 CHSPEC_WLCBANDUNIT(chspec
))
3195 wlc
->bandinit_pending
= true;
3197 wlc
->bandinit_pending
= false;
3200 wlc
->default_bss
->chanspec
= chspec
;
3201 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3202 if (wlc
->pub
->up
&& !wlc
->pub
->associated
&&
3203 (WLC_BAND_PI_RADIO_CHANSPEC
!= chspec
)) {
3204 wlc_set_home_chanspec(wlc
, chspec
);
3205 wlc_suspend_mac_and_wait(wlc
);
3206 wlc_set_chanspec(wlc
, chspec
);
3207 wlc_enable_mac(wlc
);
3213 case WLC_GET_UCFLAGS
:
3214 if (!wlc
->pub
->up
) {
3215 bcmerror
= BCME_NOTUP
;
3219 /* optional band is stored in the second integer of incoming buffer */
3222 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3224 /* bcmerror checking */
3225 bcmerror
= wlc_iocregchk(wlc
, band
);
3229 if (val
>= MHFMAX
) {
3230 bcmerror
= BCME_RANGE
;
3234 *pval
= wlc_bmac_mhf_get(wlc
->hw
, (u8
) val
, WLC_BAND_AUTO
);
3237 case WLC_SET_UCFLAGS
:
3238 if (!wlc
->pub
->up
) {
3239 bcmerror
= BCME_NOTUP
;
3243 /* optional band is stored in the second integer of incoming buffer */
3246 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3248 /* bcmerror checking */
3249 bcmerror
= wlc_iocregchk(wlc
, band
);
3255 bcmerror
= BCME_RANGE
;
3259 wlc_mhf(wlc
, (u8
) i
, 0xffff, (u16
) (val
>> NBITS(u16
)),
3266 /* optional band is stored in the second integer of incoming buffer */
3269 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3271 /* bcmerror checking */
3272 bcmerror
= wlc_iocregchk(wlc
, band
);
3277 bcmerror
= BCME_BADADDR
;
3281 *pval
= wlc_read_shm(wlc
, (u16
) val
);
3287 /* optional band is stored in the second integer of incoming buffer */
3290 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3292 /* bcmerror checking */
3293 bcmerror
= wlc_iocregchk(wlc
, band
);
3298 bcmerror
= BCME_BADADDR
;
3302 wlc_write_shm(wlc
, (u16
) val
,
3303 (u16
) (val
>> NBITS(u16
)));
3306 case WLC_R_REG
: /* MAC registers */
3308 r
= (rw_reg_t
*) arg
;
3309 band
= WLC_BAND_AUTO
;
3311 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3312 bcmerror
= BCME_BUFTOOSHORT
;
3316 if (len
>= (int)sizeof(rw_reg_t
))
3319 /* bcmerror checking */
3320 bcmerror
= wlc_iocregchk(wlc
, band
);
3324 if ((r
->byteoff
+ r
->size
) > sizeof(d11regs_t
)) {
3325 bcmerror
= BCME_BADADDR
;
3328 if (r
->size
== sizeof(u32
))
3331 (u32
*)((unsigned char *)(unsigned long)regs
+
3333 else if (r
->size
== sizeof(u16
))
3336 (u16
*)((unsigned char *)(unsigned long)regs
+
3339 bcmerror
= BCME_BADADDR
;
3344 r
= (rw_reg_t
*) arg
;
3345 band
= WLC_BAND_AUTO
;
3347 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3348 bcmerror
= BCME_BUFTOOSHORT
;
3352 if (len
>= (int)sizeof(rw_reg_t
))
3355 /* bcmerror checking */
3356 bcmerror
= wlc_iocregchk(wlc
, band
);
3360 if (r
->byteoff
+ r
->size
> sizeof(d11regs_t
)) {
3361 bcmerror
= BCME_BADADDR
;
3364 if (r
->size
== sizeof(u32
))
3366 (u32
*)((unsigned char *)(unsigned long) regs
+
3367 r
->byteoff
), r
->val
);
3368 else if (r
->size
== sizeof(u16
))
3370 (u16
*)((unsigned char *)(unsigned long) regs
+
3371 r
->byteoff
), r
->val
);
3373 bcmerror
= BCME_BADADDR
;
3378 *pval
= wlc
->stf
->txant
;
3382 bcmerror
= wlc_stf_ant_txant_validate(wlc
, (s8
) val
);
3386 wlc
->stf
->txant
= (s8
) val
;
3388 /* if down, we are done */
3392 wlc_suspend_mac_and_wait(wlc
);
3394 wlc_stf_phy_txant_upd(wlc
);
3395 wlc_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
3397 wlc_enable_mac(wlc
);
3401 case WLC_GET_ANTDIV
:{
3404 /* return configured value if core is down */
3405 if (!wlc
->pub
->up
) {
3406 *pval
= wlc
->stf
->ant_rx_ovr
;
3409 if (wlc_phy_ant_rxdiv_get
3410 (wlc
->band
->pi
, &phy_antdiv
))
3411 *pval
= (int)phy_antdiv
;
3413 *pval
= (int)wlc
->stf
->ant_rx_ovr
;
3418 case WLC_SET_ANTDIV
:
3419 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3420 if ((val
< -1) || (val
> 3)) {
3421 bcmerror
= BCME_RANGE
;
3426 val
= ANT_RX_DIV_DEF
;
3428 wlc
->stf
->ant_rx_ovr
= (u8
) val
;
3429 wlc_phy_ant_rxdiv_set(wlc
->band
->pi
, (u8
) val
);
3432 case WLC_GET_RX_ANT
:{ /* get latest used rx antenna */
3435 if (!wlc
->pub
->up
) {
3436 bcmerror
= BCME_NOTUP
;
3440 rxstatus
= R_REG(wlc
->osh
, &wlc
->regs
->phyrxstatus0
);
3441 if (rxstatus
== 0xdead || rxstatus
== (u16
) -1) {
3442 bcmerror
= BCME_ERROR
;
3445 *pval
= (rxstatus
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0;
3450 case WLC_GET_UCANTDIV
:
3452 bcmerror
= BCME_NOCLK
;
3457 (wlc_bmac_mhf_get(wlc
->hw
, MHF1
, WLC_BAND_AUTO
) &
3461 case WLC_SET_UCANTDIV
:{
3462 if (!wlc
->pub
->up
) {
3463 bcmerror
= BCME_NOTUP
;
3467 /* if multiband, band must be locked */
3468 if (IS_MBAND_UNLOCKED(wlc
)) {
3469 bcmerror
= BCME_NOTBANDLOCKED
;
3473 /* 4322 supports antdiv in phy, no need to set it to ucode */
3474 if (WLCISNPHY(wlc
->band
)
3475 && D11REV_IS(wlc
->pub
->corerev
, 16)) {
3476 WL_ERROR("wl%d: can't set ucantdiv for 4322\n",
3478 bcmerror
= BCME_UNSUPPORTED
;
3480 wlc_mhf(wlc
, MHF1
, MHF1_ANTDIV
,
3481 (val
? MHF1_ANTDIV
: 0), WLC_BAND_AUTO
);
3484 #endif /* defined(BCMDBG) */
3491 if (val
>= 1 && val
<= RETRY_SHORT_MAX
) {
3493 wlc
->SRL
= (u16
) val
;
3495 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3497 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3498 WLC_WME_RETRY_SHORT_SET(wlc
, ac
, wlc
->SRL
);
3500 wlc_wme_retries_write(wlc
);
3502 bcmerror
= BCME_RANGE
;
3510 if (val
>= 1 && val
<= 255) {
3512 wlc
->LRL
= (u16
) val
;
3514 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3516 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3517 WLC_WME_RETRY_LONG_SET(wlc
, ac
, wlc
->LRL
);
3519 wlc_wme_retries_write(wlc
);
3521 bcmerror
= BCME_RANGE
;
3525 *pval
= wlc
->band
->CWmin
;
3530 bcmerror
= BCME_NOCLK
;
3534 if (val
>= 1 && val
<= 255) {
3535 wlc_set_cwmin(wlc
, (u16
) val
);
3537 bcmerror
= BCME_RANGE
;
3541 *pval
= wlc
->band
->CWmax
;
3546 bcmerror
= BCME_NOCLK
;
3550 if (val
>= 255 && val
<= 2047) {
3551 wlc_set_cwmax(wlc
, (u16
) val
);
3553 bcmerror
= BCME_RANGE
;
3556 case WLC_GET_RADIO
: /* use mask if don't want to expose some internal bits */
3557 *pval
= wlc
->pub
->radio_disabled
;
3560 case WLC_SET_RADIO
:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3563 u16 radiomask
, radioval
;
3565 WL_RADIO_SW_DISABLE
| WL_RADIO_HW_DISABLE
;
3568 radiomask
= (val
& 0xffff0000) >> 16;
3569 radioval
= val
& 0x0000ffff;
3571 if ((radiomask
== 0) || (radiomask
& ~validbits
)
3572 || (radioval
& ~validbits
)
3573 || ((radioval
& ~radiomask
) != 0)) {
3574 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3576 bcmerror
= BCME_RANGE
;
3581 (wlc
->pub
->radio_disabled
& ~radiomask
) | radioval
;
3582 wlc
->pub
->radio_disabled
= new;
3584 wlc_radio_hwdisable_upd(wlc
);
3589 case WLC_GET_PHYTYPE
:
3590 *pval
= WLC_PHYTYPE(wlc
->band
->phytype
);
3595 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
))) {
3598 wsec_key_t
*src_key
= wlc
->wsec_keys
[val
];
3600 if (len
< (int)sizeof(key
)) {
3601 bcmerror
= BCME_BUFTOOSHORT
;
3605 memset((char *)&key
, 0, sizeof(key
));
3607 key
.index
= src_key
->id
;
3608 key
.len
= src_key
->len
;
3609 bcopy(src_key
->data
, key
.data
, key
.len
);
3610 key
.algo
= src_key
->algo
;
3611 if (WSEC_SOFTKEY(wlc
, src_key
, bsscfg
))
3612 key
.flags
|= WL_SOFT_KEY
;
3613 if (src_key
->flags
& WSEC_PRIMARY_KEY
)
3614 key
.flags
|= WL_PRIMARY_KEY
;
3616 bcopy(src_key
->ea
, key
.ea
,
3620 bcopy((char *)&key
, arg
, sizeof(key
));
3622 bcmerror
= BCME_BADKEYIDX
;
3624 #endif /* defined(BCMDBG) */
3628 wlc_iovar_op(wlc
, "wsec_key", NULL
, 0, arg
, len
, IOV_SET
,
3632 case WLC_GET_KEY_SEQ
:{
3635 if (len
< DOT11_WPA_KEY_RSC_LEN
) {
3636 bcmerror
= BCME_BUFTOOSHORT
;
3640 /* Return the key's tx iv as an EAPOL sequence counter.
3641 * This will be used to supply the RSC value to a supplicant.
3642 * The format is 8 bytes, with least significant in seq[0].
3645 key
= WSEC_KEY(wlc
, val
);
3646 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
)) &&
3648 u8 seq
[DOT11_WPA_KEY_RSC_LEN
];
3651 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3652 if ((bsscfg
->WPA_auth
& WPA_AUTH_NONE
) &&
3653 is_zero_ether_addr(key
->ea
)) {
3654 lo
= bsscfg
->wpa_none_txiv
.lo
;
3655 hi
= bsscfg
->wpa_none_txiv
.hi
;
3661 /* format the buffer, low to high */
3663 seq
[1] = (lo
>> 8) & 0xff;
3665 seq
[3] = (hi
>> 8) & 0xff;
3666 seq
[4] = (hi
>> 16) & 0xff;
3667 seq
[5] = (hi
>> 24) & 0xff;
3671 bcopy((char *)seq
, arg
, sizeof(seq
));
3673 bcmerror
= BCME_BADKEYIDX
;
3678 case WLC_GET_CURR_RATESET
:{
3679 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3682 if (bsscfg
->associated
)
3683 rs
= ¤t_bss
->rateset
;
3685 rs
= &wlc
->default_bss
->rateset
;
3687 if (len
< (int)(rs
->count
+ sizeof(rs
->count
))) {
3688 bcmerror
= BCME_BUFTOOSHORT
;
3692 /* Copy only legacy rateset section */
3693 ret_rs
->count
= rs
->count
;
3694 bcopy(&rs
->rates
, &ret_rs
->rates
, rs
->count
);
3698 case WLC_GET_RATESET
:{
3700 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3702 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3703 wlc_default_rateset(wlc
, (wlc_rateset_t
*) &rs
);
3705 if (len
< (int)(rs
.count
+ sizeof(rs
.count
))) {
3706 bcmerror
= BCME_BUFTOOSHORT
;
3710 /* Copy only legacy rateset section */
3711 ret_rs
->count
= rs
.count
;
3712 bcopy(&rs
.rates
, &ret_rs
->rates
, rs
.count
);
3716 case WLC_SET_RATESET
:{
3718 wl_rateset_t
*in_rs
= (wl_rateset_t
*) arg
;
3720 if (len
< (int)(in_rs
->count
+ sizeof(in_rs
->count
))) {
3721 bcmerror
= BCME_BUFTOOSHORT
;
3725 if (in_rs
->count
> WLC_NUMRATES
) {
3726 bcmerror
= BCME_BUFTOOLONG
;
3730 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3732 /* Copy only legacy rateset section */
3733 rs
.count
= in_rs
->count
;
3734 bcopy(&in_rs
->rates
, &rs
.rates
, rs
.count
);
3736 /* merge rateset coming in with the current mcsset */
3737 if (N_ENAB(wlc
->pub
)) {
3738 if (bsscfg
->associated
)
3739 bcopy(¤t_bss
->rateset
.mcs
[0],
3740 rs
.mcs
, MCSSET_LEN
);
3742 bcopy(&wlc
->default_bss
->rateset
.mcs
[0],
3743 rs
.mcs
, MCSSET_LEN
);
3746 bcmerror
= wlc_set_rateset(wlc
, &rs
);
3749 wlc_ofdm_rateset_war(wlc
);
3754 case WLC_GET_BCNPRD
:
3755 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3756 *pval
= current_bss
->beacon_period
;
3758 *pval
= wlc
->default_bss
->beacon_period
;
3761 case WLC_SET_BCNPRD
:
3762 /* range [1, 0xffff] */
3763 if (val
>= DOT11_MIN_BEACON_PERIOD
3764 && val
<= DOT11_MAX_BEACON_PERIOD
) {
3765 wlc
->default_bss
->beacon_period
= (u16
) val
;
3767 bcmerror
= BCME_RANGE
;
3770 case WLC_GET_DTIMPRD
:
3771 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3772 *pval
= current_bss
->dtim_period
;
3774 *pval
= wlc
->default_bss
->dtim_period
;
3777 case WLC_SET_DTIMPRD
:
3778 /* range [1, 0xff] */
3779 if (val
>= DOT11_MIN_DTIM_PERIOD
3780 && val
<= DOT11_MAX_DTIM_PERIOD
) {
3781 wlc
->default_bss
->dtim_period
= (u8
) val
;
3783 bcmerror
= BCME_RANGE
;
3792 if ((val
>= PM_OFF
) && (val
<= PM_MAX
)) {
3796 /* Change watchdog driver to align watchdog with tbtt if possible */
3797 wlc_watchdog_upd(wlc
, PS_ALLOWED(wlc
));
3799 bcmerror
= BCME_ERROR
;
3801 #endif /* SUPPORT_PS */
3806 if (AP_ENAB(wlc
->pub
)) {
3807 bcmerror
= BCME_NOTSTA
;
3814 if (AP_ENAB(wlc
->pub
)) {
3815 bcmerror
= BCME_NOTSTA
;
3819 wlc
->wake
= val
? true : false;
3821 /* if down, we're done */
3825 /* apply to the mac */
3826 wlc_set_ps_ctrl(wlc
);
3829 #endif /* SUPPORT_PS */
3831 case WLC_GET_REVINFO
:
3832 bcmerror
= wlc_get_revision_info(wlc
, arg
, (uint
) len
);
3836 *pval
= (int)AP_ENAB(wlc
->pub
);
3840 if (bsscfg
->associated
)
3841 *pval
= (int)current_bss
->atim_window
;
3843 *pval
= (int)wlc
->default_bss
->atim_window
;
3847 wlc
->default_bss
->atim_window
= (u32
) val
;
3850 case WLC_GET_PKTCNTS
:{
3851 get_pktcnt_t
*pktcnt
= (get_pktcnt_t
*) pval
;
3852 if (WLC_UPDATE_STATS(wlc
))
3854 pktcnt
->rx_good_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxframe
);
3855 pktcnt
->rx_bad_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxerror
);
3856 pktcnt
->tx_good_pkt
=
3857 WLCNTVAL(wlc
->pub
->_cnt
->txfrmsnt
);
3858 pktcnt
->tx_bad_pkt
=
3859 WLCNTVAL(wlc
->pub
->_cnt
->txerror
) +
3860 WLCNTVAL(wlc
->pub
->_cnt
->txfail
);
3861 if (len
>= (int)sizeof(get_pktcnt_t
)) {
3862 /* Be backward compatible - only if buffer is large enough */
3863 pktcnt
->rx_ocast_good_pkt
=
3864 WLCNTVAL(wlc
->pub
->_cnt
->rxmfrmocast
);
3869 #ifdef SUPPORT_HWKEY
3872 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_GET
,
3878 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_SET
,
3882 case WLC_GET_WPA_AUTH
:
3883 *pval
= (int)bsscfg
->WPA_auth
;
3886 case WLC_SET_WPA_AUTH
:
3887 /* change of WPA_Auth modifies the PS_ALLOWED state */
3888 if (BSSCFG_STA(bsscfg
)) {
3889 bsscfg
->WPA_auth
= (u16
) val
;
3891 bsscfg
->WPA_auth
= (u16
) val
;
3893 #endif /* SUPPORT_HWKEY */
3895 case WLC_GET_BANDLIST
:
3896 /* count of number of bands, followed by each band type */
3897 *pval
++ = NBANDS(wlc
);
3898 *pval
++ = wlc
->band
->bandtype
;
3899 if (NBANDS(wlc
) > 1)
3900 *pval
++ = wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
;
3904 *pval
= wlc
->bandlocked
? wlc
->band
->bandtype
: WLC_BAND_AUTO
;
3907 case WLC_GET_PHYLIST
:
3909 unsigned char *cp
= arg
;
3911 bcmerror
= BCME_BUFTOOSHORT
;
3915 if (WLCISNPHY(wlc
->band
)) {
3917 } else if (WLCISLCNPHY(wlc
->band
)) {
3919 } else if (WLCISSSLPNPHY(wlc
->band
)) {
3926 case WLC_GET_SHORTSLOT
:
3927 *pval
= wlc
->shortslot
;
3930 case WLC_GET_SHORTSLOT_OVERRIDE
:
3931 *pval
= wlc
->shortslot_override
;
3934 case WLC_SET_SHORTSLOT_OVERRIDE
:
3935 if ((val
!= WLC_SHORTSLOT_AUTO
) &&
3936 (val
!= WLC_SHORTSLOT_OFF
) && (val
!= WLC_SHORTSLOT_ON
)) {
3937 bcmerror
= BCME_RANGE
;
3941 wlc
->shortslot_override
= (s8
) val
;
3943 /* shortslot is an 11g feature, so no more work if we are
3944 * currently on the 5G band
3946 if (BAND_5G(wlc
->band
->bandtype
))
3949 if (wlc
->pub
->up
&& wlc
->pub
->associated
) {
3950 /* let watchdog or beacon processing update shortslot */
3951 } else if (wlc
->pub
->up
) {
3952 /* unassociated shortslot is off */
3953 wlc_switch_shortslot(wlc
, false);
3955 /* driver is down, so just update the wlc_info value */
3956 if (wlc
->shortslot_override
== WLC_SHORTSLOT_AUTO
) {
3957 wlc
->shortslot
= false;
3960 (wlc
->shortslot_override
==
3967 case WLC_GET_LEGACY_ERP
:
3968 *pval
= wlc
->include_legacy_erp
;
3971 case WLC_SET_LEGACY_ERP
:
3972 if (wlc
->include_legacy_erp
== bool_val
)
3975 wlc
->include_legacy_erp
= bool_val
;
3977 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
3978 wlc_update_beacon(wlc
);
3979 wlc_update_probe_resp(wlc
, true);
3984 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
3985 *pval
= wlc
->band
->gmode
;
3986 else if (NBANDS(wlc
) > 1)
3987 *pval
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
;
3991 if (!wlc
->pub
->associated
)
3992 bcmerror
= wlc_set_gmode(wlc
, (u8
) val
, true);
3994 bcmerror
= BCME_ASSOCIATED
;
3999 case WLC_GET_GMODE_PROTECTION
:
4000 *pval
= wlc
->protection
->_g
;
4003 case WLC_GET_PROTECTION_CONTROL
:
4004 *pval
= wlc
->protection
->overlap
;
4007 case WLC_SET_PROTECTION_CONTROL
:
4008 if ((val
!= WLC_PROTECTION_CTL_OFF
) &&
4009 (val
!= WLC_PROTECTION_CTL_LOCAL
) &&
4010 (val
!= WLC_PROTECTION_CTL_OVERLAP
)) {
4011 bcmerror
= BCME_RANGE
;
4015 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, (s8
) val
);
4017 /* Current g_protection will sync up to the specified control alg in watchdog
4018 * if the driver is up and associated.
4019 * If the driver is down or not associated, the control setting has no effect.
4023 case WLC_GET_GMODE_PROTECTION_OVERRIDE
:
4024 *pval
= wlc
->protection
->g_override
;
4027 case WLC_SET_GMODE_PROTECTION_OVERRIDE
:
4028 if ((val
!= WLC_PROTECTION_AUTO
) &&
4029 (val
!= WLC_PROTECTION_OFF
) && (val
!= WLC_PROTECTION_ON
)) {
4030 bcmerror
= BCME_RANGE
;
4034 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, (s8
) val
);
4038 case WLC_SET_SUP_RATESET_OVERRIDE
:{
4039 wlc_rateset_t rs
, new;
4042 if (len
< (int)sizeof(wlc_rateset_t
)) {
4043 bcmerror
= BCME_BUFTOOSHORT
;
4046 bcopy((char *)arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
4048 /* check for bad count value */
4049 if (rs
.count
> WLC_NUMRATES
) {
4050 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4054 /* this command is only appropriate for gmode operation */
4055 if (!(wlc
->band
->gmode
||
4057 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4058 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4062 /* check for an empty rateset to clear the override */
4063 if (rs
.count
== 0) {
4064 memset(&wlc
->sup_rates_override
, 0,
4065 sizeof(wlc_rateset_t
));
4069 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4070 wlc_rateset_filter(&rs
, &new, false, WLC_RATES_CCK_OFDM
,
4071 RATE_MASK
, BSS_N_ENAB(wlc
, bsscfg
));
4072 wlc_rate_hwrs_filter_sort_validate(&new,
4075 wlc
->stf
->txstreams
);
4076 if (rs
.count
!= new.count
) {
4077 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4081 /* apply new rateset to the override */
4082 bcopy((char *)&new, (char *)&wlc
->sup_rates_override
,
4083 sizeof(wlc_rateset_t
));
4085 /* update bcn and probe resp if needed */
4086 if (wlc
->pub
->up
&& AP_ENAB(wlc
->pub
)
4087 && wlc
->pub
->associated
) {
4088 wlc_update_beacon(wlc
);
4089 wlc_update_probe_resp(wlc
, true);
4094 case WLC_GET_SUP_RATESET_OVERRIDE
:
4095 /* this command is only appropriate for gmode operation */
4096 if (!(wlc
->band
->gmode
||
4098 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4099 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4102 if (len
< (int)sizeof(wlc_rateset_t
)) {
4103 bcmerror
= BCME_BUFTOOSHORT
;
4106 bcopy((char *)&wlc
->sup_rates_override
, (char *)arg
,
4107 sizeof(wlc_rateset_t
));
4111 case WLC_GET_PRB_RESP_TIMEOUT
:
4112 *pval
= wlc
->prb_resp_timeout
;
4115 case WLC_SET_PRB_RESP_TIMEOUT
:
4117 bcmerror
= BCME_NOTDOWN
;
4120 if (val
< 0 || val
>= 0xFFFF) {
4121 bcmerror
= BCME_RANGE
; /* bad value */
4124 wlc
->prb_resp_timeout
= (u16
) val
;
4127 case WLC_GET_KEY_PRIMARY
:{
4130 /* treat the 'val' parm as the key id */
4131 key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4133 *pval
= key
->id
== val
? true : false;
4135 bcmerror
= BCME_BADKEYIDX
;
4140 case WLC_SET_KEY_PRIMARY
:{
4141 wsec_key_t
*key
, *old_key
;
4143 bcmerror
= BCME_BADKEYIDX
;
4145 /* treat the 'val' parm as the key id */
4146 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
4147 key
= bsscfg
->bss_def_keys
[i
];
4148 if (key
!= NULL
&& key
->id
== val
) {
4149 old_key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4150 if (old_key
!= NULL
)
4153 key
->flags
|= WSEC_PRIMARY_KEY
;
4154 bsscfg
->wsec_index
= i
;
4170 /* validate the name value */
4172 for (i
= 0; i
< (uint
) len
&& *name
!= '\0';
4176 if (i
== (uint
) len
) {
4177 bcmerror
= BCME_BUFTOOSHORT
;
4180 i
++; /* include the null in the string length */
4182 if (cmd
== WLC_GET_VAR
) {
4184 wlc_iovar_op(wlc
, arg
,
4185 (void *)((s8
*) arg
+ i
),
4186 len
- i
, arg
, len
, IOV_GET
,
4190 wlc_iovar_op(wlc
, arg
, NULL
, 0,
4191 (void *)((s8
*) arg
+ i
),
4192 len
- i
, IOV_SET
, wlcif
);
4197 case WLC_SET_WSEC_PMK
:
4198 bcmerror
= BCME_UNSUPPORTED
;
4202 case WLC_CURRENT_PWR
:
4204 bcmerror
= BCME_NOTUP
;
4206 bcmerror
= wlc_get_current_txpwr(wlc
, arg
, len
);
4211 WL_ERROR("%s: WLC_LAST\n", __func__
);
4216 if (VALID_BCMERROR(bcmerror
))
4217 wlc
->pub
->bcmerror
= bcmerror
;
4223 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4224 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4225 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4227 if (!(wlc
->pub
->hw_off
))
4228 ASSERT(wlc_bmac_taclear(wlc
->hw
, ta_ok
) || !ta_ok
);
4234 /* consolidated register access ioctl error checking */
4235 int wlc_iocregchk(struct wlc_info
*wlc
, uint band
)
4237 /* if band is specified, it must be the current band */
4238 if ((band
!= WLC_BAND_AUTO
) && (band
!= (uint
) wlc
->band
->bandtype
))
4239 return BCME_BADBAND
;
4241 /* if multiband and band is not specified, band must be locked */
4242 if ((band
== WLC_BAND_AUTO
) && IS_MBAND_UNLOCKED(wlc
))
4243 return BCME_NOTBANDLOCKED
;
4245 /* must have core clocks */
4251 #endif /* defined(BCMDBG) */
4254 /* For some ioctls, make sure that the pi pointer matches the current phy */
4255 int wlc_iocpichk(struct wlc_info
*wlc
, uint phytype
)
4257 if (wlc
->band
->phytype
!= phytype
)
4258 return BCME_BADBAND
;
4263 /* Look up the given var name in the given table */
4264 static const bcm_iovar_t
*wlc_iovar_lookup(const bcm_iovar_t
*table
,
4267 const bcm_iovar_t
*vi
;
4268 const char *lookup_name
;
4270 /* skip any ':' delimited option prefixes */
4271 lookup_name
= strrchr(name
, ':');
4272 if (lookup_name
!= NULL
)
4277 ASSERT(table
!= NULL
);
4279 for (vi
= table
; vi
->name
; vi
++) {
4280 if (!strcmp(vi
->name
, lookup_name
))
4283 /* ran to end of table */
4285 return NULL
; /* var name not found */
4288 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4289 int wlc_iovar_getint(struct wlc_info
*wlc
, const char *name
, int *arg
)
4291 return wlc_iovar_op(wlc
, name
, NULL
, 0, arg
, sizeof(s32
), IOV_GET
,
4295 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4296 int wlc_iovar_setint(struct wlc_info
*wlc
, const char *name
, int arg
)
4298 return wlc_iovar_op(wlc
, name
, NULL
, 0, (void *)&arg
, sizeof(arg
),
4302 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4303 int wlc_iovar_gets8(struct wlc_info
*wlc
, const char *name
, s8
*arg
)
4309 wlc_iovar_op(wlc
, name
, NULL
, 0, &iovar_int
, sizeof(iovar_int
),
4312 *arg
= (s8
) iovar_int
;
4318 * register iovar table, watchdog and down handlers.
4319 * calling function must keep 'iovars' until wlc_module_unregister is called.
4320 * 'iovar' must have the last entry's name field being NULL as terminator.
4322 int wlc_module_register(struct wlc_pub
*pub
, const bcm_iovar_t
*iovars
,
4323 const char *name
, void *hdl
, iovar_fn_t i_fn
,
4324 watchdog_fn_t w_fn
, down_fn_t d_fn
)
4326 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4329 ASSERT(name
!= NULL
);
4330 ASSERT(i_fn
!= NULL
|| w_fn
!= NULL
|| d_fn
!= NULL
);
4332 /* find an empty entry and just add, no duplication check! */
4333 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4334 if (wlc
->modulecb
[i
].name
[0] == '\0') {
4335 strncpy(wlc
->modulecb
[i
].name
, name
,
4336 sizeof(wlc
->modulecb
[i
].name
) - 1);
4337 wlc
->modulecb
[i
].iovars
= iovars
;
4338 wlc
->modulecb
[i
].hdl
= hdl
;
4339 wlc
->modulecb
[i
].iovar_fn
= i_fn
;
4340 wlc
->modulecb
[i
].watchdog_fn
= w_fn
;
4341 wlc
->modulecb
[i
].down_fn
= d_fn
;
4346 /* it is time to increase the capacity */
4347 ASSERT(i
< WLC_MAXMODULES
);
4348 return BCME_NORESOURCE
;
4351 /* unregister module callbacks */
4352 int wlc_module_unregister(struct wlc_pub
*pub
, const char *name
, void *hdl
)
4354 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4358 return BCME_NOTFOUND
;
4360 ASSERT(name
!= NULL
);
4362 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4363 if (!strcmp(wlc
->modulecb
[i
].name
, name
) &&
4364 (wlc
->modulecb
[i
].hdl
== hdl
)) {
4365 memset(&wlc
->modulecb
[i
], 0, sizeof(modulecb_t
));
4370 /* table not found! */
4371 return BCME_NOTFOUND
;
4374 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4375 static void wlc_wme_retries_write(struct wlc_info
*wlc
)
4379 /* Need clock to do this */
4383 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
4384 wlc_write_shm(wlc
, M_AC_TXLMT_ADDR(ac
), wlc
->wme_retries
[ac
]);
4388 /* Get or set an iovar. The params/p_len pair specifies any additional
4389 * qualifying parameters (e.g. an "element index") for a get, while the
4390 * arg/len pair is the buffer for the value to be set or retrieved.
4391 * Operation (get/set) is specified by the last argument.
4392 * interface context provided by wlcif
4394 * All pointers may point into the same buffer.
4397 wlc_iovar_op(struct wlc_info
*wlc
, const char *name
,
4398 void *params
, int p_len
, void *arg
, int len
,
4399 bool set
, struct wlc_if
*wlcif
)
4403 const bcm_iovar_t
*vi
= NULL
;
4407 ASSERT(name
!= NULL
);
4411 /* Get MUST have return space */
4412 ASSERT(set
|| (arg
&& len
));
4414 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
4416 /* Set does NOT take qualifiers */
4417 ASSERT(!set
|| (!params
&& !p_len
));
4419 if (!set
&& (len
== sizeof(int)) &&
4420 !(IS_ALIGNED((unsigned long)(arg
), (uint
) sizeof(int)))) {
4421 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4422 wlc
->pub
->unit
, __func__
, name
);
4426 /* find the given iovar name */
4427 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4428 if (!wlc
->modulecb
[i
].iovars
)
4430 vi
= wlc_iovar_lookup(wlc
->modulecb
[i
].iovars
, name
);
4434 /* iovar name not found */
4435 if (i
>= WLC_MAXMODULES
) {
4436 err
= BCME_UNSUPPORTED
;
4440 /* set up 'params' pointer in case this is a set command so that
4441 * the convenience int and bool code can be common to set and get
4443 if (params
== NULL
) {
4448 if (vi
->type
== IOVT_VOID
)
4450 else if (vi
->type
== IOVT_BUFFER
)
4453 /* all other types are integer sized */
4454 val_size
= sizeof(int);
4456 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
4458 /* Do the actual parameter implementation */
4459 err
= wlc
->modulecb
[i
].iovar_fn(wlc
->modulecb
[i
].hdl
, vi
, actionid
,
4460 name
, params
, p_len
, arg
, len
, val_size
,
4468 wlc_iovar_check(struct wlc_pub
*pub
, const bcm_iovar_t
*vi
, void *arg
, int len
,
4471 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4475 /* check generic condition flags */
4477 if (((vi
->flags
& IOVF_SET_DOWN
) && wlc
->pub
->up
) ||
4478 ((vi
->flags
& IOVF_SET_UP
) && !wlc
->pub
->up
)) {
4479 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4480 } else if ((vi
->flags
& IOVF_SET_BAND
)
4481 && IS_MBAND_UNLOCKED(wlc
)) {
4482 err
= BCME_NOTBANDLOCKED
;
4483 } else if ((vi
->flags
& IOVF_SET_CLK
) && !wlc
->clk
) {
4487 if (((vi
->flags
& IOVF_GET_DOWN
) && wlc
->pub
->up
) ||
4488 ((vi
->flags
& IOVF_GET_UP
) && !wlc
->pub
->up
)) {
4489 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4490 } else if ((vi
->flags
& IOVF_GET_BAND
)
4491 && IS_MBAND_UNLOCKED(wlc
)) {
4492 err
= BCME_NOTBANDLOCKED
;
4493 } else if ((vi
->flags
& IOVF_GET_CLK
) && !wlc
->clk
) {
4501 /* length check on io buf */
4502 err
= bcm_iovar_lencheck(vi
, arg
, len
, set
);
4506 /* On set, check value ranges for integer types */
4516 bcopy(arg
, &int_val
, sizeof(int));
4517 err
= wlc_iovar_rangecheck(wlc
, int_val
, vi
);
4525 /* handler for iovar table wlc_iovars */
4527 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4528 * iovar case, the switch statement maps the iovar id into separate get
4529 * and set values. If you add a new iovar to the switch you MUST use
4530 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4532 * Please use params for additional qualifying parameters.
4535 wlc_doiovar(void *hdl
, const bcm_iovar_t
*vi
, u32 actionid
,
4536 const char *name
, void *params
, uint p_len
, void *arg
, int len
,
4537 int val_size
, struct wlc_if
*wlcif
)
4539 struct wlc_info
*wlc
= hdl
;
4540 wlc_bsscfg_t
*bsscfg
;
4547 wlc_bss_info_t
*current_bss
;
4549 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
4554 err
= wlc_iovar_check(wlc
->pub
, vi
, arg
, len
, IOV_ISSET(actionid
));
4558 /* convenience int and bool vals for first 8 bytes of buffer */
4559 if (p_len
>= (int)sizeof(int_val
))
4560 bcopy(params
, &int_val
, sizeof(int_val
));
4562 if (p_len
>= (int)sizeof(int_val
) * 2)
4563 bcopy((void *)((unsigned long)params
+ sizeof(int_val
)), &int_val2
,
4566 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4567 ret_int_ptr
= (s32
*) arg
;
4569 bool_val
= (int_val
!= 0) ? true : false;
4570 bool_val2
= (int_val2
!= 0) ? true : false;
4572 WL_TRACE("wl%d: %s: id %d\n",
4573 wlc
->pub
->unit
, __func__
, IOV_ID(actionid
));
4574 /* Do the actual parameter implementation */
4577 case IOV_GVAL(IOV_QTXPOWER
):{
4581 err
= wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
,
4586 /* Return qdbm units */
4588 qdbm
| (override
? WL_TXPWR_OVERRIDE
: 0);
4592 /* As long as override is false, this only sets the *user* targets.
4593 User can twiddle this all he wants with no harm.
4594 wlc_phy_txpower_set() explicitly sets override to false if
4595 not internal or test.
4597 case IOV_SVAL(IOV_QTXPOWER
):{
4601 /* Remove override bit and clip to max qdbm value */
4602 qdbm
= (u8
)min_t(u32
, (int_val
& ~WL_TXPWR_OVERRIDE
), 0xff);
4603 /* Extract override setting */
4604 override
= (int_val
& WL_TXPWR_OVERRIDE
) ? true : false;
4606 wlc_phy_txpower_set(wlc
->band
->pi
, qdbm
, override
);
4610 case IOV_GVAL(IOV_MPC
):
4611 *ret_int_ptr
= (s32
) wlc
->mpc
;
4614 case IOV_SVAL(IOV_MPC
):
4615 wlc
->mpc
= bool_val
;
4616 wlc_radio_mpc_upd(wlc
);
4620 case IOV_GVAL(IOV_BCN_LI_BCN
):
4621 *ret_int_ptr
= wlc
->bcn_li_bcn
;
4624 case IOV_SVAL(IOV_BCN_LI_BCN
):
4625 wlc
->bcn_li_bcn
= (u8
) int_val
;
4627 wlc_bcn_li_upd(wlc
);
4631 WL_ERROR("wl%d: %s: unsupported\n", wlc
->pub
->unit
, __func__
);
4632 err
= BCME_UNSUPPORTED
;
4636 goto exit
; /* avoid unused label warning */
4643 wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
, const bcm_iovar_t
*vi
)
4649 /* Only ranged integers are checked */
4652 max_val
|= 0x7fffffff;
4655 max_val
|= 0x00007fff;
4658 max_val
|= 0x0000007f;
4660 if (vi
->flags
& IOVF_NTRL
)
4662 else if (vi
->flags
& IOVF_WHL
)
4664 /* Signed values are checked against max_val and min_val */
4665 if ((s32
) val
< (s32
) min_val
4666 || (s32
) val
> (s32
) max_val
)
4671 max_val
|= 0xffffffff;
4674 max_val
|= 0x0000ffff;
4677 max_val
|= 0x000000ff;
4678 if (vi
->flags
& IOVF_NTRL
)
4680 if ((val
< min_val
) || (val
> max_val
))
4689 static const char *supr_reason
[] = {
4690 "None", "PMQ Entry", "Flush request",
4691 "Previous frag failure", "Channel mismatch",
4692 "Lifetime Expiry", "Underflow"
4695 static void wlc_print_txs_status(u16 s
)
4697 printf("[15:12] %d frame attempts\n", (s
& TX_STATUS_FRM_RTX_MASK
) >>
4698 TX_STATUS_FRM_RTX_SHIFT
);
4699 printf(" [11:8] %d rts attempts\n", (s
& TX_STATUS_RTS_RTX_MASK
) >>
4700 TX_STATUS_RTS_RTX_SHIFT
);
4701 printf(" [7] %d PM mode indicated\n",
4702 ((s
& TX_STATUS_PMINDCTD
) ? 1 : 0));
4703 printf(" [6] %d intermediate status\n",
4704 ((s
& TX_STATUS_INTERMEDIATE
) ? 1 : 0));
4705 printf(" [5] %d AMPDU\n", (s
& TX_STATUS_AMPDU
) ? 1 : 0);
4706 printf(" [4:2] %d Frame Suppressed Reason (%s)\n",
4707 ((s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
),
4708 supr_reason
[(s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
]);
4709 printf(" [1] %d acked\n", ((s
& TX_STATUS_ACK_RCV
) ? 1 : 0));
4713 void wlc_print_txstatus(tx_status_t
*txs
)
4716 u16 s
= txs
->status
;
4717 u16 ackphyrxsh
= txs
->ackphyrxsh
;
4719 printf("\ntxpkt (MPDU) Complete\n");
4721 printf("FrameID: %04x ", txs
->frameid
);
4722 printf("TxStatus: %04x", s
);
4725 wlc_print_txs_status(s
);
4727 printf("LastTxTime: %04x ", txs
->lasttxtime
);
4728 printf("Seq: %04x ", txs
->sequence
);
4729 printf("PHYTxStatus: %04x ", txs
->phyerr
);
4730 printf("RxAckRSSI: %04x ",
4731 (ackphyrxsh
& PRXS1_JSSI_MASK
) >> PRXS1_JSSI_SHIFT
);
4732 printf("RxAckSQ: %04x", (ackphyrxsh
& PRXS1_SQ_MASK
) >> PRXS1_SQ_SHIFT
);
4734 #endif /* defined(BCMDBG) */
4737 #define MACSTATUPD(name) \
4738 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4740 void wlc_statsupd(struct wlc_info
*wlc
)
4749 /* if driver down, make no sense to update stats */
4754 /* save last rx fifo 0 overflow count */
4755 rxf0ovfl
= wlc
->core
->macstat_snapshot
->rxf0ovfl
;
4757 /* save last tx fifo underflow count */
4758 for (i
= 0; i
< NFIFO
; i
++)
4759 txfunfl
[i
] = wlc
->core
->macstat_snapshot
->txfunfl
[i
];
4763 /* check for rx fifo 0 overflow */
4764 delta
= (u16
) (wlc
->core
->macstat_snapshot
->rxf0ovfl
- rxf0ovfl
);
4766 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4767 wlc
->pub
->unit
, delta
);
4769 /* check for tx fifo underflows */
4770 for (i
= 0; i
< NFIFO
; i
++) {
4772 (u16
) (wlc
->core
->macstat_snapshot
->txfunfl
[i
] -
4775 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4776 wlc
->pub
->unit
, delta
, i
);
4780 /* dot11 counter update */
4782 WLCNTSET(wlc
->pub
->_cnt
->txrts
,
4783 (wlc
->pub
->_cnt
->rxctsucast
-
4784 wlc
->pub
->_cnt
->d11cnt_txrts_off
));
4785 WLCNTSET(wlc
->pub
->_cnt
->rxcrc
,
4786 (wlc
->pub
->_cnt
->rxbadfcs
- wlc
->pub
->_cnt
->d11cnt_rxcrc_off
));
4787 WLCNTSET(wlc
->pub
->_cnt
->txnocts
,
4788 ((wlc
->pub
->_cnt
->txrtsfrm
- wlc
->pub
->_cnt
->rxctsucast
) -
4789 wlc
->pub
->_cnt
->d11cnt_txnocts_off
));
4791 /* merge counters from dma module */
4792 for (i
= 0; i
< NFIFO
; i
++) {
4793 if (wlc
->hw
->di
[i
]) {
4794 WLCNTADD(wlc
->pub
->_cnt
->txnobuf
,
4795 (wlc
->hw
->di
[i
])->txnobuf
);
4796 WLCNTADD(wlc
->pub
->_cnt
->rxnobuf
,
4797 (wlc
->hw
->di
[i
])->rxnobuf
);
4798 WLCNTADD(wlc
->pub
->_cnt
->rxgiant
,
4799 (wlc
->hw
->di
[i
])->rxgiants
);
4800 dma_counterreset(wlc
->hw
->di
[i
]);
4805 * Aggregate transmit and receive errors that probably resulted
4806 * in the loss of a frame are computed on the fly.
4808 WLCNTSET(wlc
->pub
->_cnt
->txerror
,
4809 wlc
->pub
->_cnt
->txnobuf
+ wlc
->pub
->_cnt
->txnoassoc
+
4810 wlc
->pub
->_cnt
->txuflo
+ wlc
->pub
->_cnt
->txrunt
+
4811 wlc
->pub
->_cnt
->dmade
+ wlc
->pub
->_cnt
->dmada
+
4812 wlc
->pub
->_cnt
->dmape
);
4813 WLCNTSET(wlc
->pub
->_cnt
->rxerror
,
4814 wlc
->pub
->_cnt
->rxoflo
+ wlc
->pub
->_cnt
->rxnobuf
+
4815 wlc
->pub
->_cnt
->rxfragerr
+ wlc
->pub
->_cnt
->rxrunt
+
4816 wlc
->pub
->_cnt
->rxgiant
+ wlc
->pub
->_cnt
->rxnoscb
+
4817 wlc
->pub
->_cnt
->rxbadsrcmac
);
4818 for (i
= 0; i
< NFIFO
; i
++)
4819 WLCNTADD(wlc
->pub
->_cnt
->rxerror
, wlc
->pub
->_cnt
->rxuflo
[i
]);
4822 bool wlc_chipmatch(u16 vendor
, u16 device
)
4824 if (vendor
!= VENDOR_BROADCOM
) {
4825 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor
);
4829 if ((device
== BCM43224_D11N_ID
) || (device
== BCM43225_D11N2G_ID
))
4832 if (device
== BCM4313_D11N2G_ID
)
4834 if ((device
== BCM43236_D11N_ID
) || (device
== BCM43236_D11N2G_ID
))
4837 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device
);
4842 void wlc_print_txdesc(d11txh_t
*txh
)
4844 u16 mtcl
= ltoh16(txh
->MacTxControlLow
);
4845 u16 mtch
= ltoh16(txh
->MacTxControlHigh
);
4846 u16 mfc
= ltoh16(txh
->MacFrameControl
);
4847 u16 tfest
= ltoh16(txh
->TxFesTimeNormal
);
4848 u16 ptcw
= ltoh16(txh
->PhyTxControlWord
);
4849 u16 ptcw_1
= ltoh16(txh
->PhyTxControlWord_1
);
4850 u16 ptcw_1_Fbr
= ltoh16(txh
->PhyTxControlWord_1_Fbr
);
4851 u16 ptcw_1_Rts
= ltoh16(txh
->PhyTxControlWord_1_Rts
);
4852 u16 ptcw_1_FbrRts
= ltoh16(txh
->PhyTxControlWord_1_FbrRts
);
4853 u16 mainrates
= ltoh16(txh
->MainRates
);
4854 u16 xtraft
= ltoh16(txh
->XtraFrameTypes
);
4856 u8
*ra
= txh
->TxFrameRA
;
4857 u16 tfestfb
= ltoh16(txh
->TxFesTimeFallback
);
4858 u8
*rtspfb
= txh
->RTSPLCPFallback
;
4859 u16 rtsdfb
= ltoh16(txh
->RTSDurFallback
);
4860 u8
*fragpfb
= txh
->FragPLCPFallback
;
4861 u16 fragdfb
= ltoh16(txh
->FragDurFallback
);
4862 u16 mmodelen
= ltoh16(txh
->MModeLen
);
4863 u16 mmodefbrlen
= ltoh16(txh
->MModeFbrLen
);
4864 u16 tfid
= ltoh16(txh
->TxFrameID
);
4865 u16 txs
= ltoh16(txh
->TxStatus
);
4866 u16 mnmpdu
= ltoh16(txh
->MaxNMpdus
);
4867 u16 mabyte
= ltoh16(txh
->MaxABytes_MRT
);
4868 u16 mabyte_f
= ltoh16(txh
->MaxABytes_FBR
);
4869 u16 mmbyte
= ltoh16(txh
->MinMBytes
);
4871 u8
*rtsph
= txh
->RTSPhyHeader
;
4872 struct ieee80211_rts rts
= txh
->rts_frame
;
4875 /* add plcp header along with txh descriptor */
4876 prhex("Raw TxDesc + plcp header", (unsigned char *) txh
, sizeof(d11txh_t
) + 48);
4878 printf("TxCtlLow: %04x ", mtcl
);
4879 printf("TxCtlHigh: %04x ", mtch
);
4880 printf("FC: %04x ", mfc
);
4881 printf("FES Time: %04x\n", tfest
);
4882 printf("PhyCtl: %04x%s ", ptcw
,
4883 (ptcw
& PHY_TXC_SHORT_HDR
) ? " short" : "");
4884 printf("PhyCtl_1: %04x ", ptcw_1
);
4885 printf("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr
);
4886 printf("PhyCtl_1_Rts: %04x ", ptcw_1_Rts
);
4887 printf("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts
);
4888 printf("MainRates: %04x ", mainrates
);
4889 printf("XtraFrameTypes: %04x ", xtraft
);
4892 bcm_format_hex(hexbuf
, iv
, sizeof(txh
->IV
));
4893 printf("SecIV: %s\n", hexbuf
);
4894 bcm_format_hex(hexbuf
, ra
, sizeof(txh
->TxFrameRA
));
4895 printf("RA: %s\n", hexbuf
);
4897 printf("Fb FES Time: %04x ", tfestfb
);
4898 bcm_format_hex(hexbuf
, rtspfb
, sizeof(txh
->RTSPLCPFallback
));
4899 printf("RTS PLCP: %s ", hexbuf
);
4900 printf("RTS DUR: %04x ", rtsdfb
);
4901 bcm_format_hex(hexbuf
, fragpfb
, sizeof(txh
->FragPLCPFallback
));
4902 printf("PLCP: %s ", hexbuf
);
4903 printf("DUR: %04x", fragdfb
);
4906 printf("MModeLen: %04x ", mmodelen
);
4907 printf("MModeFbrLen: %04x\n", mmodefbrlen
);
4909 printf("FrameID: %04x\n", tfid
);
4910 printf("TxStatus: %04x\n", txs
);
4912 printf("MaxNumMpdu: %04x\n", mnmpdu
);
4913 printf("MaxAggbyte: %04x\n", mabyte
);
4914 printf("MaxAggbyte_fb: %04x\n", mabyte_f
);
4915 printf("MinByte: %04x\n", mmbyte
);
4917 bcm_format_hex(hexbuf
, rtsph
, sizeof(txh
->RTSPhyHeader
));
4918 printf("RTS PLCP: %s ", hexbuf
);
4919 bcm_format_hex(hexbuf
, (u8
*) &rts
, sizeof(txh
->rts_frame
));
4920 printf("RTS Frame: %s", hexbuf
);
4924 #endif /* defined(BCMDBG) */
4927 void wlc_print_rxh(d11rxhdr_t
*rxh
)
4929 u16 len
= rxh
->RxFrameSize
;
4930 u16 phystatus_0
= rxh
->PhyRxStatus_0
;
4931 u16 phystatus_1
= rxh
->PhyRxStatus_1
;
4932 u16 phystatus_2
= rxh
->PhyRxStatus_2
;
4933 u16 phystatus_3
= rxh
->PhyRxStatus_3
;
4934 u16 macstatus1
= rxh
->RxStatus1
;
4935 u16 macstatus2
= rxh
->RxStatus2
;
4938 static const bcm_bit_desc_t macstat_flags
[] = {
4939 {RXS_FCSERR
, "FCSErr"},
4940 {RXS_RESPFRAMETX
, "Reply"},
4941 {RXS_PBPRES
, "PADDING"},
4942 {RXS_DECATMPT
, "DeCr"},
4943 {RXS_DECERR
, "DeCrErr"},
4944 {RXS_BCNSENT
, "Bcn"},
4948 prhex("Raw RxDesc", (unsigned char *) rxh
, sizeof(d11rxhdr_t
));
4950 bcm_format_flags(macstat_flags
, macstatus1
, flagstr
, 64);
4952 snprintf(lenbuf
, sizeof(lenbuf
), "0x%x", len
);
4954 printf("RxFrameSize: %6s (%d)%s\n", lenbuf
, len
,
4955 (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
) ? " short preamble" : "");
4956 printf("RxPHYStatus: %04x %04x %04x %04x\n",
4957 phystatus_0
, phystatus_1
, phystatus_2
, phystatus_3
);
4958 printf("RxMACStatus: %x %s\n", macstatus1
, flagstr
);
4959 printf("RXMACaggtype: %x\n", (macstatus2
& RXS_AGGTYPE_MASK
));
4960 printf("RxTSFTime: %04x\n", rxh
->RxTSFTime
);
4962 #endif /* defined(BCMDBG) */
4965 int wlc_format_ssid(char *buf
, const unsigned char ssid
[], uint ssid_len
)
4969 char *endp
= buf
+ SSID_FMT_BUF_LEN
;
4971 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
4972 ssid_len
= IEEE80211_MAX_SSID_LEN
;
4974 for (i
= 0; i
< ssid_len
; i
++) {
4979 } else if (isprint((unsigned char) c
)) {
4982 p
+= snprintf(p
, (endp
- p
), "\\x%02X", c
);
4988 return (int)(p
- buf
);
4990 #endif /* defined(BCMDBG) */
4992 u16
wlc_rate_shm_offset(struct wlc_info
*wlc
, u8 rate
)
4994 return wlc_bmac_rate_shm_offset(wlc
->hw
, rate
);
4997 /* Callback for device removed */
5000 * Attempts to queue a packet onto a multiple-precedence queue,
5001 * if necessary evicting a lower precedence packet from the queue.
5003 * 'prec' is the precedence number that has already been mapped
5004 * from the packet priority.
5006 * Returns true if packet consumed (queued), false if not.
5009 wlc_prec_enq(struct wlc_info
*wlc
, struct pktq
*q
, void *pkt
, int prec
)
5011 return wlc_prec_enq_head(wlc
, q
, pkt
, prec
, false);
5015 wlc_prec_enq_head(struct wlc_info
*wlc
, struct pktq
*q
, struct sk_buff
*pkt
,
5016 int prec
, bool head
)
5019 int eprec
= -1; /* precedence to evict from */
5021 /* Determine precedence from which to evict packet, if any */
5022 if (pktq_pfull(q
, prec
))
5024 else if (pktq_full(q
)) {
5025 p
= pktq_peek_tail(q
, &eprec
);
5028 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5029 __func__
, eprec
, prec
);
5034 /* Evict if needed */
5036 bool discard_oldest
;
5038 /* Detect queueing to unconfigured precedence */
5039 ASSERT(!pktq_pempty(q
, eprec
));
5041 discard_oldest
= AC_BITMAP_TST(wlc
->wme_dp
, eprec
);
5043 /* Refuse newer packet unless configured to discard oldest */
5044 if (eprec
== prec
&& !discard_oldest
) {
5045 WL_ERROR("%s: No where to go, prec == %d\n",
5050 /* Evict packet according to discard policy */
5051 p
= discard_oldest
? pktq_pdeq(q
, eprec
) : pktq_pdeq_tail(q
,
5055 /* Increment wme stats */
5056 if (WME_ENAB(wlc
->pub
)) {
5057 WLCNTINCR(wlc
->pub
->_wme_cnt
->
5058 tx_failed
[WME_PRIO2AC(p
->priority
)].packets
);
5059 WLCNTADD(wlc
->pub
->_wme_cnt
->
5060 tx_failed
[WME_PRIO2AC(p
->priority
)].bytes
,
5061 pkttotlen(wlc
->osh
, p
));
5065 pkt_buf_free_skb(wlc
->osh
, p
, true);
5066 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5071 p
= pktq_penq_head(q
, prec
, pkt
);
5073 p
= pktq_penq(q
, prec
, pkt
);
5079 void BCMFASTPATH
wlc_txq_enq(void *ctx
, struct scb
*scb
, struct sk_buff
*sdu
,
5082 struct wlc_info
*wlc
= (struct wlc_info
*) ctx
;
5083 wlc_txq_info_t
*qi
= wlc
->active_queue
; /* Check me */
5084 struct pktq
*q
= &qi
->q
;
5087 prio
= sdu
->priority
;
5089 ASSERT(pktq_max(q
) >= wlc
->pub
->tunables
->datahiwat
);
5091 if (!wlc_prec_enq(wlc
, q
, sdu
, prec
)) {
5092 if (!EDCF_ENAB(wlc
->pub
)
5093 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
))
5094 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5097 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5098 pkt_buf_free_skb(wlc
->osh
, sdu
, true);
5099 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5102 /* Check if flow control needs to be turned on after enqueuing the packet
5103 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5104 * to drop instead of relying on stack to make the right decision
5106 if (!EDCF_ENAB(wlc
->pub
)
5107 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5108 if (pktq_len(q
) >= wlc
->pub
->tunables
->datahiwat
) {
5109 wlc_txflowcontrol(wlc
, qi
, ON
, ALLPRIO
);
5111 } else if (wlc
->pub
->_priofc
) {
5112 if (pktq_plen(q
, wlc_prio2prec_map
[prio
]) >=
5113 wlc
->pub
->tunables
->datahiwat
) {
5114 wlc_txflowcontrol(wlc
, qi
, ON
, prio
);
5120 wlc_sendpkt_mac80211(struct wlc_info
*wlc
, struct sk_buff
*sdu
,
5121 struct ieee80211_hw
*hw
)
5126 struct scb
*scb
= &global_scb
;
5127 struct ieee80211_hdr
*d11_header
= (struct ieee80211_hdr
*)(sdu
->data
);
5132 fc
= ltoh16(d11_header
->frame_control
);
5133 type
= (fc
& IEEE80211_FCTL_FTYPE
);
5135 /* 802.11 standard requires management traffic to go at highest priority */
5136 prio
= (type
== IEEE80211_FTYPE_DATA
? sdu
->priority
: MAXPRIO
);
5137 fifo
= prio2fifo
[prio
];
5139 ASSERT((uint
) skb_headroom(sdu
) >= TXOFF
);
5140 ASSERT(!(sdu
->next
));
5141 ASSERT(!(sdu
->prev
));
5142 ASSERT(fifo
< NFIFO
);
5146 (wlc_d11hdrs_mac80211(wlc
, hw
, pkt
, scb
, 0, 1, fifo
, 0, NULL
, 0)))
5148 wlc_txq_enq(wlc
, scb
, pkt
, WLC_PRIO_TO_PREC(prio
));
5149 wlc_send_q(wlc
, wlc
->active_queue
);
5151 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx
);
5155 void BCMFASTPATH
wlc_send_q(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
)
5157 struct sk_buff
*pkt
[DOT11_MAXNUMFRAGS
];
5160 int err
= 0, i
, count
;
5162 struct pktq
*q
= &qi
->q
;
5163 struct ieee80211_tx_info
*tx_info
;
5165 /* only do work for the active queue */
5166 if (qi
!= wlc
->active_queue
)
5174 prec_map
= wlc
->tx_prec_map
;
5176 /* Send all the enq'd pkts that we can.
5177 * Dequeue packets with precedence with empty HW fifo only
5179 while (prec_map
&& (pkt
[0] = pktq_mdeq(q
, prec_map
, &prec
))) {
5180 tx_info
= IEEE80211_SKB_CB(pkt
[0]);
5181 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
5182 err
= wlc_sendampdu(wlc
->ampdu
, qi
, pkt
, prec
);
5185 err
= wlc_prep_pdu(wlc
, pkt
[0], &fifo
);
5187 for (i
= 0; i
< count
; i
++) {
5188 wlc_txfifo(wlc
, fifo
, pkt
[i
], true, 1);
5193 if (err
== BCME_BUSY
) {
5194 pktq_penq_head(q
, prec
, pkt
[0]);
5195 /* If send failed due to any other reason than a change in
5196 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5198 if (prec_map
== wlc
->tx_prec_map
)
5200 prec_map
= wlc
->tx_prec_map
;
5204 /* Check if flow control needs to be turned off after sending the packet */
5205 if (!EDCF_ENAB(wlc
->pub
)
5206 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5207 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, ALLPRIO
)
5208 && (pktq_len(q
) < wlc
->pub
->tunables
->datahiwat
/ 2)) {
5209 wlc_txflowcontrol(wlc
, qi
, OFF
, ALLPRIO
);
5211 } else if (wlc
->pub
->_priofc
) {
5213 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
5214 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, prio
) &&
5215 (pktq_plen(q
, wlc_prio2prec_map
[prio
]) <
5216 wlc
->pub
->tunables
->datahiwat
/ 2)) {
5217 wlc_txflowcontrol(wlc
, qi
, OFF
, prio
);
5225 * bcmc_fid_generate:
5226 * Generate frame ID for a BCMC packet. The frag field is not used
5227 * for MC frames so is used as part of the sequence number.
5230 bcmc_fid_generate(struct wlc_info
*wlc
, wlc_bsscfg_t
*bsscfg
, d11txh_t
*txh
)
5234 frameid
= ltoh16(txh
->TxFrameID
) & ~(TXFID_SEQ_MASK
| TXFID_QUEUE_MASK
);
5237 mc_fid_counter
++) << TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5244 wlc_txfifo(struct wlc_info
*wlc
, uint fifo
, struct sk_buff
*p
, bool commit
,
5247 u16 frameid
= INVALIDFID
;
5250 ASSERT(fifo
< NFIFO
);
5251 txh
= (d11txh_t
*) (p
->data
);
5253 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5254 * ucode or BSS info as appropriate.
5256 if (fifo
== TX_BCMC_FIFO
) {
5257 frameid
= ltoh16(txh
->TxFrameID
);
5261 if (WLC_WAR16165(wlc
))
5262 wlc_war16165(wlc
, true);
5265 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5266 * in wlc_bmac_txfifo()
5269 TXPKTPENDINC(wlc
, fifo
, txpktpend
);
5270 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5271 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
5274 /* Commit BCMC sequence number in the SHM frame ID location */
5275 if (frameid
!= INVALIDFID
)
5276 BCMCFID(wlc
, frameid
);
5278 if (dma_txfast(wlc
->hw
->di
[fifo
], p
, commit
) < 0) {
5279 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5284 wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
)
5287 uint mac_rate
= RSPEC2RATE(rspec
);
5290 if (IS_MCS(rspec
)) {
5291 /* not supported yet */
5293 } else if (IS_OFDM(rspec
)) {
5294 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5296 * Nbits = length * 8
5297 * Nbits/sym = Mbps * 4 = mac_rate * 2
5299 nsyms
= CEIL((length
* 8), (mac_rate
* 2));
5301 /* usec = symbols * usec/symbol */
5302 usec
= (u16
) (nsyms
* APHY_SYMBOL_TIME
);
5313 usec
= (length
<< 4) / 11;
5316 usec
= (length
<< 3) / 11;
5319 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5320 wlc
->pub
->unit
, rspec
);
5321 ASSERT((const char *)"Bad phy_rate" == NULL
);
5330 wlc_compute_plcp(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
, u8
*plcp
)
5332 if (IS_MCS(rspec
)) {
5333 wlc_compute_mimo_plcp(rspec
, length
, plcp
);
5334 } else if (IS_OFDM(rspec
)) {
5335 wlc_compute_ofdm_plcp(rspec
, length
, plcp
);
5337 wlc_compute_cck_plcp(rspec
, length
, plcp
);
5342 /* Rate: 802.11 rate code, length: PSDU length in octets */
5343 static void wlc_compute_mimo_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5345 u8 mcs
= (u8
) (rspec
& RSPEC_RATE_MASK
);
5346 ASSERT(IS_MCS(rspec
));
5348 if (RSPEC_IS40MHZ(rspec
) || (mcs
== 32))
5349 plcp
[0] |= MIMO_PLCP_40MHZ
;
5350 WLC_SET_MIMO_PLCP_LEN(plcp
, length
);
5351 plcp
[3] = RSPEC_MIMOPLCP3(rspec
); /* rspec already holds this byte */
5352 plcp
[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5353 plcp
[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5357 /* Rate: 802.11 rate code, length: PSDU length in octets */
5358 static void BCMFASTPATH
5359 wlc_compute_ofdm_plcp(ratespec_t rspec
, u32 length
, u8
*plcp
)
5363 int rate
= RSPEC2RATE(rspec
);
5365 ASSERT(IS_OFDM(rspec
));
5367 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5368 rate_signal
= rate_info
[rate
] & RATE_MASK
;
5369 ASSERT(rate_signal
!= 0);
5371 memset(plcp
, 0, D11_PHY_HDR_LEN
);
5372 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t
*) plcp
, rate_signal
);
5374 tmp
= (length
& 0xfff) << 5;
5375 plcp
[2] |= (tmp
>> 16) & 0xff;
5376 plcp
[1] |= (tmp
>> 8) & 0xff;
5377 plcp
[0] |= tmp
& 0xff;
5383 * Compute PLCP, but only requires actual rate and length of pkt.
5384 * Rate is given in the driver standard multiple of 500 kbps.
5385 * le is set for 11 Mbps rate if necessary.
5386 * Broken out for PRQ.
5389 static void wlc_cck_plcp_set(int rate_500
, uint length
, u8
*plcp
)
5402 usec
= (length
<< 4) / 11;
5403 if ((length
<< 4) - (usec
* 11) > 0)
5407 usec
= (length
<< 3) / 11;
5408 if ((length
<< 3) - (usec
* 11) > 0) {
5410 if ((usec
* 11) - (length
<< 3) >= 8)
5411 le
= D11B_PLCP_SIGNAL_LE
;
5416 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500
);
5417 rate_500
= WLC_RATE_1M
;
5421 /* PLCP signal byte */
5422 plcp
[0] = rate_500
* 5; /* r (500kbps) * 5 == r (100kbps) */
5423 /* PLCP service byte */
5424 plcp
[1] = (u8
) (le
| D11B_PLCP_SIGNAL_LOCKED
);
5425 /* PLCP length u16, little endian */
5426 plcp
[2] = usec
& 0xff;
5427 plcp
[3] = (usec
>> 8) & 0xff;
5433 /* Rate: 802.11 rate code, length: PSDU length in octets */
5434 static void wlc_compute_cck_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5436 int rate
= RSPEC2RATE(rspec
);
5438 ASSERT(IS_CCK(rspec
));
5440 wlc_cck_plcp_set(rate
, length
, plcp
);
5443 /* wlc_compute_frame_dur()
5445 * Calculate the 802.11 MAC header DUR field for MPDU
5446 * DUR for a single frame = 1 SIFS + 1 ACK
5447 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5449 * rate MPDU rate in unit of 500kbps
5450 * next_frag_len next MPDU length in bytes
5451 * preamble_type use short/GF or long/MM PLCP header
5453 static u16 BCMFASTPATH
5454 wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
, u8 preamble_type
,
5459 sifs
= SIFS(wlc
->band
);
5462 dur
+= (u16
) wlc_calc_ack_time(wlc
, rate
, preamble_type
);
5464 if (next_frag_len
) {
5465 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5467 /* add another SIFS and the frag time */
5470 (u16
) wlc_calc_frame_time(wlc
, rate
, preamble_type
,
5476 /* wlc_compute_rtscts_dur()
5478 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5479 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5480 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5482 * cts cts-to-self or rts/cts
5483 * rts_rate rts or cts rate in unit of 500kbps
5484 * rate next MPDU rate in unit of 500kbps
5485 * frame_len next MPDU frame length in bytes
5488 wlc_compute_rtscts_dur(struct wlc_info
*wlc
, bool cts_only
, ratespec_t rts_rate
,
5489 ratespec_t frame_rate
, u8 rts_preamble_type
,
5490 u8 frame_preamble_type
, uint frame_len
, bool ba
)
5494 sifs
= SIFS(wlc
->band
);
5496 if (!cts_only
) { /* RTS/CTS */
5499 (u16
) wlc_calc_cts_time(wlc
, rts_rate
,
5501 } else { /* CTS-TO-SELF */
5506 (u16
) wlc_calc_frame_time(wlc
, frame_rate
, frame_preamble_type
,
5510 (u16
) wlc_calc_ba_time(wlc
, frame_rate
,
5511 WLC_SHORT_PREAMBLE
);
5514 (u16
) wlc_calc_ack_time(wlc
, frame_rate
,
5515 frame_preamble_type
);
5519 static bool wlc_phy_rspec_check(struct wlc_info
*wlc
, u16 bw
, ratespec_t rspec
)
5521 if (IS_MCS(rspec
)) {
5522 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5525 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5526 } else if ((mcs
>= 8) && (mcs
<= 23)) {
5527 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SDM
);
5528 } else if (mcs
== 32) {
5529 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5530 ASSERT(bw
== PHY_TXC1_BW_40MHZ_DUP
);
5532 } else if (IS_OFDM(rspec
)) {
5533 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_STBC
);
5535 ASSERT(IS_CCK(rspec
));
5537 ASSERT((bw
== PHY_TXC1_BW_20MHZ
)
5538 || (bw
== PHY_TXC1_BW_20MHZ_UP
));
5539 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SISO
);
5545 u16 BCMFASTPATH
wlc_phytxctl1_calc(struct wlc_info
*wlc
, ratespec_t rspec
)
5550 if (WLCISLCNPHY(wlc
->band
)) {
5551 bw
= PHY_TXC1_BW_20MHZ
;
5553 bw
= RSPEC_GET_BW(rspec
);
5554 /* 10Mhz is not supported yet */
5555 if (bw
< PHY_TXC1_BW_20MHZ
) {
5556 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5558 bw
= PHY_TXC1_BW_20MHZ
;
5561 wlc_phy_rspec_check(wlc
, bw
, rspec
);
5564 if (IS_MCS(rspec
)) {
5565 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5567 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5568 phyctl1
= RSPEC_PHYTXBYTE2(rspec
);
5569 /* set the upper byte of phyctl1 */
5570 phyctl1
|= (mcs_table
[mcs
].tx_phy_ctl3
<< 8);
5571 } else if (IS_CCK(rspec
) && !WLCISLCNPHY(wlc
->band
)
5572 && !WLCISSSLPNPHY(wlc
->band
)) {
5573 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5574 /* Eventually MIMOPHY would also be converted to this format */
5575 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5576 phyctl1
= (bw
| (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5577 } else { /* legacy OFDM/CCK */
5579 /* get the phyctl byte from rate phycfg table */
5580 phycfg
= wlc_rate_legacy_phyctl(RSPEC2RATE(rspec
));
5582 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5586 /* set the upper byte of phyctl1 */
5588 (bw
| (phycfg
<< 8) |
5589 (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5593 /* phy clock must support 40Mhz if tx descriptor uses it */
5594 if ((phyctl1
& PHY_TXC1_BW_MASK
) >= PHY_TXC1_BW_40MHZ
) {
5595 ASSERT(CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
);
5596 ASSERT(wlc
->chanspec
== wlc_phy_chanspec_get(wlc
->band
->pi
));
5602 ratespec_t BCMFASTPATH
5603 wlc_rspec_to_rts_rspec(struct wlc_info
*wlc
, ratespec_t rspec
, bool use_rspec
,
5606 ratespec_t rts_rspec
= 0;
5609 /* use frame rate as rts rate */
5612 } else if (wlc
->band
->gmode
&& wlc
->protection
->_g
&& !IS_CCK(rspec
)) {
5613 /* Use 11Mbps as the g protection RTS target rate and fallback.
5614 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5615 * target in case 11 Mbps is not Basic.
5616 * 6 and 9 Mbps are not usually selected by rate selection, but even
5617 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5619 rts_rspec
= WLC_BASIC_RATE(wlc
, WLC_RATE_11M
);
5621 /* calculate RTS rate and fallback rate based on the frame rate
5622 * RTS must be sent at a basic rate since it is a
5623 * control frame, sec 9.6 of 802.11 spec
5625 rts_rspec
= WLC_BASIC_RATE(wlc
, rspec
);
5628 if (WLC_PHY_11N_CAP(wlc
->band
)) {
5629 /* set rts txbw to correct side band */
5630 rts_rspec
&= ~RSPEC_BW_MASK
;
5632 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5633 * (DUP), otherwise send RTS on control channel
5635 if (RSPEC_IS40MHZ(rspec
) && !IS_CCK(rts_rspec
))
5636 rts_rspec
|= (PHY_TXC1_BW_40MHZ_DUP
<< RSPEC_BW_SHIFT
);
5638 rts_rspec
|= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5640 /* pick siso/cdd as default for ofdm */
5641 if (IS_OFDM(rts_rspec
)) {
5642 rts_rspec
&= ~RSPEC_STF_MASK
;
5643 rts_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
5650 * Add d11txh_t, cck_phy_hdr_t.
5652 * 'p' data must start with 802.11 MAC header
5653 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5655 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5658 static u16 BCMFASTPATH
5659 wlc_d11hdrs_mac80211(struct wlc_info
*wlc
, struct ieee80211_hw
*hw
,
5660 struct sk_buff
*p
, struct scb
*scb
, uint frag
,
5661 uint nfrags
, uint queue
, uint next_frag_len
,
5662 wsec_key_t
*key
, ratespec_t rspec_override
)
5664 struct ieee80211_hdr
*h
;
5666 u8
*plcp
, plcp_fallback
[D11_PHY_HDR_LEN
];
5667 struct osl_info
*osh
;
5668 int len
, phylen
, rts_phylen
;
5669 u16 fc
, type
, frameid
, mch
, phyctl
, xfts
, mainrates
;
5670 u16 seq
= 0, mcl
= 0, status
= 0;
5671 ratespec_t rspec
[2] = { WLC_RATE_1M
, WLC_RATE_1M
}, rts_rspec
[2] = {
5672 WLC_RATE_1M
, WLC_RATE_1M
};
5673 bool use_rts
= false;
5674 bool use_cts
= false;
5675 bool use_rifs
= false;
5676 bool short_preamble
[2] = { false, false };
5677 u8 preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5678 u8 rts_preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5679 u8
*rts_plcp
, rts_plcp_fallback
[D11_PHY_HDR_LEN
];
5680 struct ieee80211_rts
*rts
= NULL
;
5684 bool hwtkmic
= false;
5685 u16 mimo_ctlchbw
= PHY_TXC1_BW_20MHZ
;
5687 #define ANTCFG_NONE 0xFF
5688 u8 antcfg
= ANTCFG_NONE
;
5689 u8 fbantcfg
= ANTCFG_NONE
;
5691 uint phyctl1_stf
= 0;
5693 struct ieee80211_tx_rate
*txrate
[2];
5695 struct ieee80211_tx_info
*tx_info
;
5698 u8 mimo_preamble_type
;
5702 ASSERT(queue
< NFIFO
);
5706 /* locate 802.11 MAC header */
5707 h
= (struct ieee80211_hdr
*)(p
->data
);
5708 fc
= ltoh16(h
->frame_control
);
5709 type
= (fc
& IEEE80211_FCTL_FTYPE
);
5711 qos
= (type
== IEEE80211_FTYPE_DATA
&&
5712 FC_SUBTYPE_ANY_QOS(fc
));
5714 /* compute length of frame in bytes for use in PLCP computations */
5715 len
= pkttotlen(osh
, p
);
5716 phylen
= len
+ FCS_LEN
;
5718 /* If WEP enabled, add room in phylen for the additional bytes of
5719 * ICV which MAC generates. We do NOT add the additional bytes to
5720 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5724 phylen
+= key
->icv_len
;
5728 tx_info
= IEEE80211_SKB_CB(p
);
5732 plcp
= skb_push(p
, D11_PHY_HDR_LEN
);
5734 /* add Broadcom tx descriptor header */
5735 txh
= (d11txh_t
*) skb_push(p
, D11_TXH_LEN
);
5736 memset((char *)txh
, 0, D11_TXH_LEN
);
5739 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
5740 /* non-AP STA should never use BCMC queue */
5741 ASSERT(queue
!= TX_BCMC_FIFO
);
5742 if (queue
== TX_BCMC_FIFO
) {
5743 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5744 WLCWLUNIT(wlc
), __func__
);
5745 frameid
= bcmc_fid_generate(wlc
, NULL
, txh
);
5747 /* Increment the counter for first fragment */
5748 if (tx_info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
) {
5749 SCB_SEQNUM(scb
, p
->priority
)++;
5752 /* extract fragment number from frame first */
5753 seq
= ltoh16(seq
) & FRAGNUM_MASK
;
5754 seq
|= (SCB_SEQNUM(scb
, p
->priority
) << SEQNUM_SHIFT
);
5755 h
->seq_ctrl
= htol16(seq
);
5757 frameid
= ((seq
<< TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5758 (queue
& TXFID_QUEUE_MASK
);
5761 frameid
|= queue
& TXFID_QUEUE_MASK
;
5763 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5764 if (SCB_PS(scb
) || ((fc
& FC_KIND_MASK
) == FC_BEACON
))
5765 mcl
|= TXC_IGNOREPMQ
;
5767 ASSERT(hw
->max_rates
<= IEEE80211_TX_MAX_RATES
);
5768 ASSERT(hw
->max_rates
== 2);
5770 txrate
[0] = tx_info
->control
.rates
;
5771 txrate
[1] = txrate
[0] + 1;
5773 ASSERT(txrate
[0]->idx
>= 0);
5774 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5775 if (txrate
[1]->idx
< 0) {
5776 txrate
[1] = txrate
[0];
5779 for (k
= 0; k
< hw
->max_rates
; k
++) {
5781 txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
? true : false;
5783 ASSERT(!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
));
5784 if ((txrate
[k
]->idx
>= 0)
5785 && (txrate
[k
]->idx
<
5786 hw
->wiphy
->bands
[tx_info
->band
]->n_bitrates
)) {
5788 hw
->wiphy
->bands
[tx_info
->band
]->
5789 bitrates
[txrate
[k
]->idx
].hw_value
;
5792 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
?
5795 ASSERT((txrate
[k
]->idx
>= 0) &&
5797 hw
->wiphy
->bands
[tx_info
->band
]->
5799 rate_val
[k
] = WLC_RATE_1M
;
5802 rate_val
[k
] = txrate
[k
]->idx
;
5804 /* Currently only support same setting for primay and fallback rates.
5805 * Unify flags for each rate into a single value for the frame
5809 flags
& IEEE80211_TX_RC_USE_RTS_CTS
? true : false;
5812 flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
? true : false;
5815 rate_val
[k
] |= NRATE_MCS_INUSE
;
5817 rspec
[k
] = mac80211_wlc_set_nrate(wlc
, wlc
->band
, rate_val
[k
]);
5819 /* (1) RATE: determine and validate primary rate and fallback rates */
5820 if (!RSPEC_ACTIVE(rspec
[k
])) {
5821 ASSERT(RSPEC_ACTIVE(rspec
[k
]));
5822 rspec
[k
] = WLC_RATE_1M
;
5824 if (WLANTSEL_ENAB(wlc
) &&
5825 !is_multicast_ether_addr(h
->addr1
)) {
5826 /* set tx antenna config */
5827 wlc_antsel_antcfg_get(wlc
->asi
, false, false, 0,
5828 0, &antcfg
, &fbantcfg
);
5833 phyctl1_stf
= wlc
->stf
->ss_opmode
;
5835 if (N_ENAB(wlc
->pub
)) {
5836 for (k
= 0; k
< hw
->max_rates
; k
++) {
5837 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5838 if (((IS_MCS(rspec
[k
]) &&
5839 IS_SINGLE_STREAM(rspec
[k
] & RSPEC_RATE_MASK
)) ||
5841 && ((rspec
[k
] & RSPEC_OVERRIDE_MCS_ONLY
)
5842 || !(rspec
[k
] & RSPEC_OVERRIDE
))) {
5843 rspec
[k
] &= ~(RSPEC_STF_MASK
| RSPEC_STC_MASK
);
5845 /* For SISO MCS use STBC if possible */
5846 if (IS_MCS(rspec
[k
])
5847 && WLC_STF_SS_STBC_TX(wlc
, scb
)) {
5850 ASSERT(WLC_STBC_CAP_PHY(wlc
));
5851 stc
= 1; /* Nss for single stream is always 1 */
5853 (PHY_TXC1_MODE_STBC
<<
5854 RSPEC_STF_SHIFT
) | (stc
<<
5858 (phyctl1_stf
<< RSPEC_STF_SHIFT
);
5861 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5862 if (CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
) {
5863 /* default txbw is 20in40 SB */
5864 mimo_ctlchbw
= mimo_txbw
=
5865 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC
)
5866 ? PHY_TXC1_BW_20MHZ_UP
: PHY_TXC1_BW_20MHZ
;
5868 if (IS_MCS(rspec
[k
])) {
5869 /* mcs 32 must be 40b/w DUP */
5870 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5872 PHY_TXC1_BW_40MHZ_DUP
;
5874 } else if (wlc
->mimo_40txbw
!= AUTO
)
5875 mimo_txbw
= wlc
->mimo_40txbw
;
5876 /* else check if dst is using 40 Mhz */
5877 else if (scb
->flags
& SCB_IS40
)
5878 mimo_txbw
= PHY_TXC1_BW_40MHZ
;
5879 } else if (IS_OFDM(rspec
[k
])) {
5880 if (wlc
->ofdm_40txbw
!= AUTO
)
5881 mimo_txbw
= wlc
->ofdm_40txbw
;
5883 ASSERT(IS_CCK(rspec
[k
]));
5884 if (wlc
->cck_40txbw
!= AUTO
)
5885 mimo_txbw
= wlc
->cck_40txbw
;
5888 /* mcs32 is 40 b/w only.
5889 * This is possible for probe packets on a STA during SCAN
5891 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5893 rspec
[k
] = RSPEC_MIMORATE
;
5895 mimo_txbw
= PHY_TXC1_BW_20MHZ
;
5898 /* Set channel width */
5899 rspec
[k
] &= ~RSPEC_BW_MASK
;
5900 if ((k
== 0) || ((k
> 0) && IS_MCS(rspec
[k
])))
5901 rspec
[k
] |= (mimo_txbw
<< RSPEC_BW_SHIFT
);
5903 rspec
[k
] |= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5907 if (IS_MCS(rspec
[k
])
5908 && (txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5909 rspec
[k
] |= RSPEC_SHORT_GI
;
5910 else if (!(txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5911 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5913 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5916 mimo_preamble_type
= WLC_MM_PREAMBLE
;
5917 if (txrate
[k
]->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
5918 mimo_preamble_type
= WLC_GF_PREAMBLE
;
5920 if ((txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
)
5921 && (!IS_MCS(rspec
[k
]))) {
5922 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5923 WLCWLUNIT(wlc
), __func__
);
5924 ASSERT(0 && "Rate mismatch");
5927 if (IS_MCS(rspec
[k
])) {
5928 preamble_type
[k
] = mimo_preamble_type
;
5930 /* if SGI is selected, then forced mm for single stream */
5931 if ((rspec
[k
] & RSPEC_SHORT_GI
)
5932 && IS_SINGLE_STREAM(rspec
[k
] &
5934 preamble_type
[k
] = WLC_MM_PREAMBLE
;
5938 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
5939 ASSERT(VALID_RATE_DBG(wlc
, rspec
[0]));
5941 /* should be better conditionalized */
5942 if (!IS_MCS(rspec
[0])
5943 && (tx_info
->control
.rates
[0].
5944 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
))
5945 preamble_type
[k
] = WLC_SHORT_PREAMBLE
;
5947 ASSERT(!IS_MCS(rspec
[0])
5948 || WLC_IS_MIMO_PREAMBLE(preamble_type
[k
]));
5951 for (k
= 0; k
< hw
->max_rates
; k
++) {
5952 /* Set ctrlchbw as 20Mhz */
5953 ASSERT(!IS_MCS(rspec
[k
]));
5954 rspec
[k
] &= ~RSPEC_BW_MASK
;
5955 rspec
[k
] |= (PHY_TXC1_BW_20MHZ
<< RSPEC_BW_SHIFT
);
5957 /* for nphy, stf of ofdm frames must follow policies */
5958 if (WLCISNPHY(wlc
->band
) && IS_OFDM(rspec
[k
])) {
5959 rspec
[k
] &= ~RSPEC_STF_MASK
;
5960 rspec
[k
] |= phyctl1_stf
<< RSPEC_STF_SHIFT
;
5965 /* Reset these for use with AMPDU's */
5966 txrate
[0]->count
= 0;
5967 txrate
[1]->count
= 0;
5969 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
5970 wlc_compute_plcp(wlc
, rspec
[0], phylen
, plcp
);
5971 wlc_compute_plcp(wlc
, rspec
[1], phylen
, plcp_fallback
);
5972 bcopy(plcp_fallback
, (char *)&txh
->FragPLCPFallback
,
5973 sizeof(txh
->FragPLCPFallback
));
5975 /* Length field now put in CCK FBR CRC field */
5976 if (IS_CCK(rspec
[1])) {
5977 txh
->FragPLCPFallback
[4] = phylen
& 0xff;
5978 txh
->FragPLCPFallback
[5] = (phylen
& 0xff00) >> 8;
5981 /* MIMO-RATE: need validation ?? */
5983 IS_OFDM(rspec
[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) plcp
) :
5986 /* DUR field for main rate */
5987 if ((fc
!= FC_PS_POLL
) &&
5988 !is_multicast_ether_addr(h
->addr1
) && !use_rifs
) {
5990 wlc_compute_frame_dur(wlc
, rspec
[0], preamble_type
[0],
5992 h
->duration_id
= htol16(durid
);
5993 } else if (use_rifs
) {
5994 /* NAV protect to end of next max packet size */
5996 (u16
) wlc_calc_frame_time(wlc
, rspec
[0],
5998 DOT11_MAX_FRAG_LEN
);
5999 durid
+= RIFS_11N_TIME
;
6000 h
->duration_id
= htol16(durid
);
6003 /* DUR field for fallback rate */
6004 if (fc
== FC_PS_POLL
)
6005 txh
->FragDurFallback
= h
->duration_id
;
6006 else if (is_multicast_ether_addr(h
->addr1
) || use_rifs
)
6007 txh
->FragDurFallback
= 0;
6009 durid
= wlc_compute_frame_dur(wlc
, rspec
[1],
6010 preamble_type
[1], next_frag_len
);
6011 txh
->FragDurFallback
= htol16(durid
);
6014 /* (4) MAC-HDR: MacTxControlLow */
6016 mcl
|= TXC_STARTMSDU
;
6018 if (!is_multicast_ether_addr(h
->addr1
))
6019 mcl
|= TXC_IMMEDACK
;
6021 if (BAND_5G(wlc
->band
->bandtype
))
6022 mcl
|= TXC_FREQBAND_5G
;
6024 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC
))
6027 /* set AMIC bit if using hardware TKIP MIC */
6031 txh
->MacTxControlLow
= htol16(mcl
);
6033 /* MacTxControlHigh */
6036 /* Set fallback rate preamble type */
6037 if ((preamble_type
[1] == WLC_SHORT_PREAMBLE
) ||
6038 (preamble_type
[1] == WLC_GF_PREAMBLE
)) {
6039 ASSERT((preamble_type
[1] == WLC_GF_PREAMBLE
) ||
6040 (!IS_MCS(rspec
[1])));
6041 if (RSPEC2RATE(rspec
[1]) != WLC_RATE_1M
)
6042 mch
|= TXC_PREAMBLE_DATA_FB_SHORT
;
6045 /* MacFrameControl */
6046 bcopy((char *)&h
->frame_control
, (char *)&txh
->MacFrameControl
,
6048 txh
->TxFesTimeNormal
= htol16(0);
6050 txh
->TxFesTimeFallback
= htol16(0);
6053 bcopy((char *)&h
->addr1
, (char *)&txh
->TxFrameRA
, ETH_ALEN
);
6056 txh
->TxFrameID
= htol16(frameid
);
6058 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6059 * then we may need to reset the retry cnt's via the status reg
6061 txh
->TxStatus
= htol16(status
);
6063 if (D11REV_GE(wlc
->pub
->corerev
, 16)) {
6064 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6065 * the END of previous structure so that it's compatible in driver.
6066 * In old rev ucode, these fields should be ignored
6068 txh
->MaxNMpdus
= htol16(0);
6069 txh
->MaxABytes_MRT
= htol16(0);
6070 txh
->MaxABytes_FBR
= htol16(0);
6071 txh
->MinMBytes
= htol16(0);
6074 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6075 /* RTS PLCP header and RTS frame */
6076 if (use_rts
|| use_cts
) {
6077 if (use_rts
&& use_cts
)
6080 for (k
= 0; k
< 2; k
++) {
6081 rts_rspec
[k
] = wlc_rspec_to_rts_rspec(wlc
, rspec
[k
],
6086 if (!IS_OFDM(rts_rspec
[0]) &&
6087 !((RSPEC2RATE(rts_rspec
[0]) == WLC_RATE_1M
) ||
6088 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6089 rts_preamble_type
[0] = WLC_SHORT_PREAMBLE
;
6090 mch
|= TXC_PREAMBLE_RTS_MAIN_SHORT
;
6093 if (!IS_OFDM(rts_rspec
[1]) &&
6094 !((RSPEC2RATE(rts_rspec
[1]) == WLC_RATE_1M
) ||
6095 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6096 rts_preamble_type
[1] = WLC_SHORT_PREAMBLE
;
6097 mch
|= TXC_PREAMBLE_RTS_FB_SHORT
;
6100 /* RTS/CTS additions to MacTxControlLow */
6102 txh
->MacTxControlLow
|= htol16(TXC_SENDCTS
);
6104 txh
->MacTxControlLow
|= htol16(TXC_SENDRTS
);
6105 txh
->MacTxControlLow
|= htol16(TXC_LONGFRAME
);
6108 /* RTS PLCP header */
6109 ASSERT(IS_ALIGNED((unsigned long)txh
->RTSPhyHeader
, sizeof(u16
)));
6110 rts_plcp
= txh
->RTSPhyHeader
;
6112 rts_phylen
= DOT11_CTS_LEN
+ FCS_LEN
;
6114 rts_phylen
= DOT11_RTS_LEN
+ FCS_LEN
;
6116 wlc_compute_plcp(wlc
, rts_rspec
[0], rts_phylen
, rts_plcp
);
6118 /* fallback rate version of RTS PLCP header */
6119 wlc_compute_plcp(wlc
, rts_rspec
[1], rts_phylen
,
6121 bcopy(rts_plcp_fallback
, (char *)&txh
->RTSPLCPFallback
,
6122 sizeof(txh
->RTSPLCPFallback
));
6124 /* RTS frame fields... */
6125 rts
= (struct ieee80211_rts
*)&txh
->rts_frame
;
6127 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
, rts_rspec
[0],
6128 rspec
[0], rts_preamble_type
[0],
6129 preamble_type
[0], phylen
, false);
6130 rts
->duration
= htol16(durid
);
6131 /* fallback rate version of RTS DUR field */
6132 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
,
6133 rts_rspec
[1], rspec
[1],
6134 rts_preamble_type
[1],
6135 preamble_type
[1], phylen
, false);
6136 txh
->RTSDurFallback
= htol16(durid
);
6139 rts
->frame_control
= htol16(FC_CTS
);
6140 bcopy((char *)&h
->addr2
, (char *)&rts
->ra
, ETH_ALEN
);
6142 rts
->frame_control
= htol16((u16
) FC_RTS
);
6143 bcopy((char *)&h
->addr1
, (char *)&rts
->ra
,
6148 * low 8 bits: main frag rate/mcs,
6149 * high 8 bits: rts/cts rate/mcs
6151 mainrates
|= (IS_OFDM(rts_rspec
[0]) ?
6152 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) rts_plcp
) :
6155 memset((char *)txh
->RTSPhyHeader
, 0, D11_PHY_HDR_LEN
);
6156 memset((char *)&txh
->rts_frame
, 0,
6157 sizeof(struct ieee80211_rts
));
6158 memset((char *)txh
->RTSPLCPFallback
, 0,
6159 sizeof(txh
->RTSPLCPFallback
));
6160 txh
->RTSDurFallback
= 0;
6163 #ifdef SUPPORT_40MHZ
6164 /* add null delimiter count */
6165 if ((tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) && IS_MCS(rspec
)) {
6166 txh
->RTSPLCPFallback
[AMPDU_FBR_NULL_DELIM
] =
6167 wlc_ampdu_null_delim_cnt(wlc
->ampdu
, scb
, rspec
, phylen
);
6171 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6172 txh
->MacTxControlHigh
= htol16(mch
);
6174 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6175 txh
->MainRates
= htol16(mainrates
);
6177 /* XtraFrameTypes */
6178 xfts
= FRAMETYPE(rspec
[1], wlc
->mimoft
);
6179 xfts
|= (FRAMETYPE(rts_rspec
[0], wlc
->mimoft
) << XFTS_RTS_FT_SHIFT
);
6180 xfts
|= (FRAMETYPE(rts_rspec
[1], wlc
->mimoft
) << XFTS_FBRRTS_FT_SHIFT
);
6182 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
) << XFTS_CHANNEL_SHIFT
;
6183 txh
->XtraFrameTypes
= htol16(xfts
);
6185 /* PhyTxControlWord */
6186 phyctl
= FRAMETYPE(rspec
[0], wlc
->mimoft
);
6187 if ((preamble_type
[0] == WLC_SHORT_PREAMBLE
) ||
6188 (preamble_type
[0] == WLC_GF_PREAMBLE
)) {
6189 ASSERT((preamble_type
[0] == WLC_GF_PREAMBLE
)
6190 || !IS_MCS(rspec
[0]));
6191 if (RSPEC2RATE(rspec
[0]) != WLC_RATE_1M
)
6192 phyctl
|= PHY_TXC_SHORT_HDR
;
6193 WLCNTINCR(wlc
->pub
->_cnt
->txprshort
);
6196 /* phytxant is properly bit shifted */
6197 phyctl
|= wlc_stf_d11hdrs_phyctl_txant(wlc
, rspec
[0]);
6198 txh
->PhyTxControlWord
= htol16(phyctl
);
6200 /* PhyTxControlWord_1 */
6201 if (WLC_PHY_11N_CAP(wlc
->band
)) {
6204 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[0]);
6205 txh
->PhyTxControlWord_1
= htol16(phyctl1
);
6206 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[1]);
6207 txh
->PhyTxControlWord_1_Fbr
= htol16(phyctl1
);
6209 if (use_rts
|| use_cts
) {
6210 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[0]);
6211 txh
->PhyTxControlWord_1_Rts
= htol16(phyctl1
);
6212 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[1]);
6213 txh
->PhyTxControlWord_1_FbrRts
= htol16(phyctl1
);
6217 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6218 * fill in non-zero MModeLen and/or MModeFbrLen
6219 * it will be unnecessary if they are separated
6221 if (IS_MCS(rspec
[0]) && (preamble_type
[0] == WLC_MM_PREAMBLE
)) {
6223 wlc_calc_lsig_len(wlc
, rspec
[0], phylen
);
6224 txh
->MModeLen
= htol16(mmodelen
);
6227 if (IS_MCS(rspec
[1]) && (preamble_type
[1] == WLC_MM_PREAMBLE
)) {
6229 wlc_calc_lsig_len(wlc
, rspec
[1], phylen
);
6230 txh
->MModeFbrLen
= htol16(mmodefbrlen
);
6234 if (IS_MCS(rspec
[0]))
6235 ASSERT(IS_MCS(rspec
[1]));
6237 ASSERT(!IS_MCS(rspec
[0]) ||
6238 ((preamble_type
[0] == WLC_MM_PREAMBLE
) == (txh
->MModeLen
!= 0)));
6239 ASSERT(!IS_MCS(rspec
[1]) ||
6240 ((preamble_type
[1] == WLC_MM_PREAMBLE
) ==
6241 (txh
->MModeFbrLen
!= 0)));
6243 ac
= wme_fifo2ac
[queue
];
6244 if (SCB_WME(scb
) && qos
&& wlc
->edcf_txop
[ac
]) {
6245 uint frag_dur
, dur
, dur_fallback
;
6247 ASSERT(!is_multicast_ether_addr(h
->addr1
));
6249 /* WME: Update TXOP threshold */
6250 if ((!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)) && (frag
== 0)) {
6252 wlc_calc_frame_time(wlc
, rspec
[0], preamble_type
[0],
6256 /* 1 RTS or CTS-to-self frame */
6258 wlc_calc_cts_time(wlc
, rts_rspec
[0],
6259 rts_preamble_type
[0]);
6261 wlc_calc_cts_time(wlc
, rts_rspec
[1],
6262 rts_preamble_type
[1]);
6263 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6264 dur
+= ltoh16(rts
->duration
);
6265 dur_fallback
+= ltoh16(txh
->RTSDurFallback
);
6266 } else if (use_rifs
) {
6270 /* frame + SIFS + ACK */
6273 wlc_compute_frame_dur(wlc
, rspec
[0],
6274 preamble_type
[0], 0);
6277 wlc_calc_frame_time(wlc
, rspec
[1],
6281 wlc_compute_frame_dur(wlc
, rspec
[1],
6282 preamble_type
[1], 0);
6284 /* NEED to set TxFesTimeNormal (hard) */
6285 txh
->TxFesTimeNormal
= htol16((u16
) dur
);
6286 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6287 txh
->TxFesTimeFallback
= htol16((u16
) dur_fallback
);
6289 /* update txop byte threshold (txop minus intraframe overhead) */
6290 if (wlc
->edcf_txop
[ac
] >= (dur
- frag_dur
)) {
6295 wlc_calc_frame_len(wlc
, rspec
[0],
6301 /* range bound the fragthreshold */
6302 if (newfragthresh
< DOT11_MIN_FRAG_LEN
)
6305 else if (newfragthresh
>
6306 wlc
->usr_fragthresh
)
6308 wlc
->usr_fragthresh
;
6309 /* update the fragthresh and do txc update */
6310 if (wlc
->fragthresh
[queue
] !=
6311 (u16
) newfragthresh
) {
6312 wlc
->fragthresh
[queue
] =
6313 (u16
) newfragthresh
;
6317 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6318 wlc
->pub
->unit
, fifo_names
[queue
],
6319 RSPEC2RATE(rspec
[0]));
6321 if (dur
> wlc
->edcf_txop
[ac
])
6322 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6323 wlc
->pub
->unit
, __func__
,
6325 phylen
, wlc
->fragthresh
[queue
],
6326 dur
, wlc
->edcf_txop
[ac
]);
6333 void wlc_tbtt(struct wlc_info
*wlc
, d11regs_t
*regs
)
6335 wlc_bsscfg_t
*cfg
= wlc
->cfg
;
6337 WLCNTINCR(wlc
->pub
->_cnt
->tbtt
);
6339 if (BSSCFG_STA(cfg
)) {
6340 /* run watchdog here if the watchdog timer is not armed */
6341 if (WLC_WATCHDOG_TBTT(wlc
)) {
6344 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
6345 wlc
->WDarmed
= false;
6348 cur
= OSL_SYSUPTIME();
6349 delta
= cur
> wlc
->WDlast
? cur
- wlc
->WDlast
:
6350 (u32
) ~0 - wlc
->WDlast
+ cur
+ 1;
6351 if (delta
>= TIMER_INTERVAL_WATCHDOG
) {
6352 wlc_watchdog((void *)wlc
);
6356 wl_add_timer(wlc
->wl
, wlc
->wdtimer
,
6357 wlc_watchdog_backup_bi(wlc
), true);
6358 wlc
->WDarmed
= true;
6363 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6364 wlc
->qvalid
|= MCMD_DIRFRMQVAL
;
6368 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6369 void wlc_hwtimer_gptimer_set(struct wlc_info
*wlc
, uint us
)
6371 ASSERT(wlc
->pub
->corerev
>= 3); /* no gptimer in earlier revs */
6372 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, us
);
6375 void wlc_hwtimer_gptimer_abort(struct wlc_info
*wlc
)
6377 ASSERT(wlc
->pub
->corerev
>= 3);
6378 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6381 static void wlc_hwtimer_gptimer_cb(struct wlc_info
*wlc
)
6383 /* when interrupt is generated, the counter is loaded with last value
6384 * written and continue to decrement. So it has to be cleaned first
6386 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6390 * This fn has all the high level dpc processing from wlc_dpc.
6391 * POLICY: no macinstatus change, no bounding loop.
6392 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6394 void wlc_high_dpc(struct wlc_info
*wlc
, u32 macintstatus
)
6396 d11regs_t
*regs
= wlc
->regs
;
6399 static const bcm_bit_desc_t int_flags
[] = {
6400 {MI_MACSSPNDD
, "MACSSPNDD"},
6401 {MI_BCNTPL
, "BCNTPL"},
6403 {MI_BCNSUCCESS
, "BCNSUCCESS"},
6404 {MI_BCNCANCLD
, "BCNCANCLD"},
6405 {MI_ATIMWINEND
, "ATIMWINEND"},
6407 {MI_NSPECGEN_0
, "NSPECGEN_0"},
6408 {MI_NSPECGEN_1
, "NSPECGEN_1"},
6409 {MI_MACTXERR
, "MACTXERR"},
6410 {MI_NSPECGEN_3
, "NSPECGEN_3"},
6411 {MI_PHYTXERR
, "PHYTXERR"},
6415 {MI_DMAINT
, "DMAINT"},
6416 {MI_TXSTOP
, "TXSTOP"},
6418 {MI_BG_NOISE
, "BG_NOISE"},
6419 {MI_DTIM_TBTT
, "DTIM_TBTT"},
6421 {MI_PWRUP
, "PWRUP"},
6422 {MI_RFDISABLE
, "RFDISABLE"},
6424 {MI_PHYCHANGED
, "PHYCHANGED"},
6429 if (macintstatus
& ~(MI_TBTT
| MI_TXSTOP
)) {
6430 bcm_format_flags(int_flags
, macintstatus
, flagstr
,
6432 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6433 wlc
->pub
->unit
, macintstatus
, flagstr
);
6437 if (macintstatus
& MI_PRQ
) {
6438 /* Process probe request FIFO */
6439 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6442 /* TBTT indication */
6443 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6444 if (macintstatus
& (MI_TBTT
| MI_DTIM_TBTT
))
6445 wlc_tbtt(wlc
, regs
);
6447 if (macintstatus
& MI_GP0
) {
6448 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6449 wlc
->pub
->unit
, wlc
->pub
->now
);
6451 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6452 __func__
, wlc
->pub
->sih
->chip
,
6453 wlc
->pub
->sih
->chiprev
);
6455 WLCNTINCR(wlc
->pub
->_cnt
->psmwds
);
6461 /* gptimer timeout */
6462 if (macintstatus
& MI_TO
) {
6463 wlc_hwtimer_gptimer_cb(wlc
);
6466 if (macintstatus
& MI_RFDISABLE
) {
6467 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6469 R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
);
6470 /* delay the cleanup to wl_down in IBSS case */
6471 if ((R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
)) {
6473 wlc_bsscfg_t
*bsscfg
;
6474 FOREACH_BSS(wlc
, idx
, bsscfg
) {
6475 if (!BSSCFG_STA(bsscfg
) || !bsscfg
->enable
6478 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6484 /* send any enq'd tx packets. Just makes sure to jump start tx */
6485 if (!pktq_empty(&wlc
->active_queue
->q
))
6486 wlc_send_q(wlc
, wlc
->active_queue
);
6488 ASSERT(wlc_ps_check(wlc
));
6491 static void *wlc_15420war(struct wlc_info
*wlc
, uint queue
)
6493 struct hnddma_pub
*di
;
6496 ASSERT(queue
< NFIFO
);
6498 if ((D11REV_IS(wlc
->pub
->corerev
, 4))
6499 || (D11REV_GT(wlc
->pub
->corerev
, 6)))
6502 di
= wlc
->hw
->di
[queue
];
6505 /* get next packet, ignoring XmtStatus.Curr */
6506 p
= dma_getnexttxp(di
, HNDDMA_RANGE_ALL
);
6508 /* sw block tx dma */
6511 /* if tx ring is now empty, reset and re-init the tx dma channel */
6512 if (dma_txactive(wlc
->hw
->di
[queue
]) == 0) {
6513 WLCNTINCR(wlc
->pub
->_cnt
->txdmawar
);
6514 if (!dma_txreset(di
))
6515 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
6516 wlc
->pub
->unit
, __func__
, queue
);
6522 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
)
6525 /* the post-increment is used in STAY_AWAKE macro */
6526 if (wlc
->txpend16165war
++ == 0)
6527 wlc_set_ps_ctrl(wlc
);
6529 wlc
->txpend16165war
--;
6530 if (wlc
->txpend16165war
== 0)
6531 wlc_set_ps_ctrl(wlc
);
6535 /* process an individual tx_status_t */
6538 wlc_dotxstatus(struct wlc_info
*wlc
, tx_status_t
*txs
, u32 frm_tx2
)
6543 struct scb
*scb
= NULL
;
6545 struct osl_info
*osh
;
6546 int tx_rts
, tx_frame_count
, tx_rts_count
;
6547 uint totlen
, supr_status
;
6549 struct ieee80211_hdr
*h
;
6552 struct ieee80211_tx_info
*tx_info
;
6553 struct ieee80211_tx_rate
*txrate
;
6556 (void)(frm_tx2
); /* Compiler reference to avoid unused variable warning */
6558 /* discard intermediate indications for ucode with one legitimate case:
6559 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6560 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6561 * transmission count)
6563 if (!(txs
->status
& TX_STATUS_AMPDU
)
6564 && (txs
->status
& TX_STATUS_INTERMEDIATE
)) {
6565 WLCNTADD(wlc
->pub
->_cnt
->txnoack
,
6567 status
& TX_STATUS_FRM_RTX_MASK
) >>
6568 TX_STATUS_FRM_RTX_SHIFT
));
6569 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__
);
6574 queue
= txs
->frameid
& TXFID_QUEUE_MASK
;
6575 ASSERT(queue
< NFIFO
);
6576 if (queue
>= NFIFO
) {
6581 p
= GETNEXTTXP(wlc
, queue
);
6582 if (WLC_WAR16165(wlc
))
6583 wlc_war16165(wlc
, false);
6585 p
= wlc_15420war(wlc
, queue
);
6590 txh
= (d11txh_t
*) (p
->data
);
6591 mcl
= ltoh16(txh
->MacTxControlLow
);
6594 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6595 txs
->phyerr
, txh
->MainRates
);
6596 wlc_print_txdesc(txh
);
6597 wlc_print_txstatus(txs
);
6600 ASSERT(txs
->frameid
== htol16(txh
->TxFrameID
));
6601 if (txs
->frameid
!= htol16(txh
->TxFrameID
))
6604 tx_info
= IEEE80211_SKB_CB(p
);
6605 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
6606 fc
= ltoh16(h
->frame_control
);
6608 scb
= (struct scb
*)tx_info
->control
.sta
->drv_priv
;
6610 if (N_ENAB(wlc
->pub
)) {
6611 u8
*plcp
= (u8
*) (txh
+ 1);
6612 if (PLCP3_ISSGI(plcp
[3]))
6613 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_sgi
);
6614 if (PLCP3_ISSTBC(plcp
[3]))
6615 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_stbc
);
6618 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
6619 ASSERT((mcl
& TXC_AMPDU_MASK
) != TXC_AMPDU_NONE
);
6620 wlc_ampdu_dotxstatus(wlc
->ampdu
, scb
, p
, txs
);
6624 supr_status
= txs
->status
& TX_STATUS_SUPR_MASK
;
6625 if (supr_status
== TX_STATUS_SUPR_BADCH
)
6626 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6627 __func__
, CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
));
6629 tx_rts
= htol16(txh
->MacTxControlLow
) & TXC_SENDRTS
;
6631 (txs
->status
& TX_STATUS_FRM_RTX_MASK
) >> TX_STATUS_FRM_RTX_SHIFT
;
6633 (txs
->status
& TX_STATUS_RTS_RTX_MASK
) >> TX_STATUS_RTS_RTX_SHIFT
;
6635 lastframe
= (fc
& IEEE80211_FCTL_MOREFRAGS
) == 0;
6638 WL_ERROR("Not last frame!\n");
6641 ieee80211_tx_info_clear_status(tx_info
);
6642 if (queue
< AC_COUNT
) {
6643 sfbl
= WLC_WME_RETRY_SFB_GET(wlc
, wme_fifo2ac
[queue
]);
6644 lfbl
= WLC_WME_RETRY_LFB_GET(wlc
, wme_fifo2ac
[queue
]);
6650 txrate
= tx_info
->status
.rates
;
6651 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6652 if ((tx_frame_count
> sfbl
) && (txrate
[1].idx
>= 0)) {
6653 /* rate selection requested a fallback rate and we used it */
6654 txrate
->count
= lfbl
;
6655 txrate
[1].count
= tx_frame_count
- lfbl
;
6657 /* rate selection did not request fallback rate, or we didn't need it */
6658 txrate
->count
= tx_frame_count
;
6659 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6661 txrate
[1].count
= 0;
6664 /* clear the rest of the rates */
6665 for (i
= 2; i
< IEEE80211_TX_MAX_RATES
; i
++) {
6667 txrate
[i
].count
= 0;
6670 if (txs
->status
& TX_STATUS_ACK_RCV
)
6671 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
6674 totlen
= pkttotlen(osh
, p
);
6677 wlc_txfifo_complete(wlc
, queue
, 1);
6683 /* remove PLCP & Broadcom tx descriptor header */
6684 skb_pull(p
, D11_PHY_HDR_LEN
);
6685 skb_pull(p
, D11_TXH_LEN
);
6686 ieee80211_tx_status_irqsafe(wlc
->pub
->ieee_hw
, p
);
6687 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx_status
);
6689 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6698 pkt_buf_free_skb(osh
, p
, true);
6705 wlc_txfifo_complete(struct wlc_info
*wlc
, uint fifo
, s8 txpktpend
)
6707 TXPKTPENDDEC(wlc
, fifo
, txpktpend
);
6708 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6709 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
6711 /* There is more room; mark precedences related to this FIFO sendable */
6712 WLC_TX_FIFO_ENAB(wlc
, fifo
);
6713 ASSERT(TXPKTPENDGET(wlc
, fifo
) >= 0);
6715 if (!TXPKTPENDTOT(wlc
)) {
6716 if (wlc
->block_datafifo
& DATA_BLOCK_TX_SUPR
)
6717 wlc_bsscfg_tx_check(wlc
);
6720 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6721 if (AP_ENAB(wlc
->pub
) &&
6722 wlc
->bcmcfifo_drain
&& !TXPKTPENDGET(wlc
, TX_BCMC_FIFO
)) {
6723 wlc
->bcmcfifo_drain
= false;
6724 wlc_mhf(wlc
, MHF2
, MHF2_TXBCMC_NOW
, 0, WLC_BAND_AUTO
);
6727 /* figure out which bsscfg is being worked on... */
6730 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6731 * return the offset (in us) of the TSF from the last TBTT
6733 u32
wlc_calc_tbtt_offset(u32 bp
, u32 tsf_h
, u32 tsf_l
)
6735 u32 k
, btklo
, btkhi
, offset
;
6737 /* TBTT is always an even multiple of the beacon_interval,
6738 * so the TBTT less than or equal to the beacon timestamp is
6739 * the beacon timestamp minus the beacon timestamp modulo
6740 * the beacon interval.
6742 * TBTT = BT - (BT % BIu)
6743 * = (BTk - (BTk % BP)) * 2^10
6745 * BT = beacon timestamp (usec, 64bits)
6746 * BTk = beacon timestamp (Kusec, 54bits)
6747 * BP = beacon interval (Kusec, 16bits)
6748 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6750 * To keep the calculations in u32s, the modulo operation
6751 * on the high part of BT needs to be done in parts using the
6753 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6755 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6757 * So, if BTk[n] = u16 n [0,3] of BTk.
6758 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6759 * and the SUM term can be broken down:
6760 * (BTk[n] * 2^16n) % BP
6761 * (BTk[n] * (2^16n % BP)) % BP
6763 * Create a set of power of 2 mod BP constants:
6764 * K[n] = 2^(16n) % BP
6765 * = (K[n-1] * 2^16) % BP
6766 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6768 * BTk % BP = BTk[0-1] % BP +
6769 * (BTk[2] * K[2]) % BP +
6770 * (BTk[3] * K[3]) % BP
6772 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6775 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6776 btklo
= (tsf_h
<< 22) | (tsf_l
>> 10);
6777 btkhi
= tsf_h
>> 10;
6779 /* offset = BTk % BP */
6780 offset
= btklo
% bp
;
6782 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6783 k
= (u32
) (1 << 16) % bp
;
6784 k
= (u32
) (k
* 1 << 16) % (u32
) bp
;
6786 /* offset += (BTk[2] * K[2]) % BP */
6787 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6790 btkhi
= btkhi
>> 16;
6792 /* k[3] = (K[2] * 2^16) % BP */
6795 /* offset += (BTk[3] * K[3]) % BP */
6796 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6798 offset
= offset
% bp
;
6800 /* convert offset from kus to us by shifting up 10 bits and
6801 * add in the low 10 bits of tsf that we ignored
6803 offset
= (offset
<< 10) + (tsf_l
& 0x3FF);
6808 /* Update beacon listen interval in shared memory */
6809 void wlc_bcn_li_upd(struct wlc_info
*wlc
)
6811 if (AP_ENAB(wlc
->pub
))
6814 /* wake up every DTIM is the default */
6815 if (wlc
->bcn_li_dtim
== 1)
6816 wlc_write_shm(wlc
, M_BCN_LI
, 0);
6818 wlc_write_shm(wlc
, M_BCN_LI
,
6819 (wlc
->bcn_li_dtim
<< 8) | wlc
->bcn_li_bcn
);
6823 prep_mac80211_status(struct wlc_info
*wlc
, d11rxhdr_t
*rxh
, struct sk_buff
*p
,
6824 struct ieee80211_rx_status
*rx_status
)
6827 wlc_d11rxhdr_t
*wlc_rxh
= (wlc_d11rxhdr_t
*) rxh
;
6831 unsigned char *plcp
;
6833 wlc_read_tsf(wlc
, &tsf_l
, &tsf_h
); /* mactime */
6834 rx_status
->mactime
= tsf_h
;
6835 rx_status
->mactime
<<= 32;
6836 rx_status
->mactime
|= tsf_l
;
6837 rx_status
->flag
|= RX_FLAG_TSFT
;
6839 channel
= WLC_CHAN_CHANNEL(rxh
->RxChan
);
6841 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
6843 rx_status
->band
= IEEE80211_BAND_5GHZ
;
6844 rx_status
->freq
= ieee80211_ofdm_chan_to_freq(
6845 WF_CHAN_FACTOR_5_G
/2, channel
);
6848 rx_status
->band
= IEEE80211_BAND_2GHZ
;
6849 rx_status
->freq
= ieee80211_dsss_chan_to_freq(channel
);
6852 rx_status
->signal
= wlc_rxh
->rssi
; /* signal */
6856 rx_status
->antenna
= (rxh
->PhyRxStatus_0
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0; /* ant */
6860 rspec
= wlc_compute_rspec(rxh
, plcp
);
6861 if (IS_MCS(rspec
)) {
6862 rx_status
->rate_idx
= rspec
& RSPEC_RATE_MASK
;
6863 rx_status
->flag
|= RX_FLAG_HT
;
6864 if (RSPEC_IS40MHZ(rspec
))
6865 rx_status
->flag
|= RX_FLAG_40MHZ
;
6867 switch (RSPEC2RATE(rspec
)) {
6869 rx_status
->rate_idx
= 0;
6872 rx_status
->rate_idx
= 1;
6875 rx_status
->rate_idx
= 2;
6878 rx_status
->rate_idx
= 3;
6881 rx_status
->rate_idx
= 4;
6884 rx_status
->rate_idx
= 5;
6887 rx_status
->rate_idx
= 6;
6890 rx_status
->rate_idx
= 7;
6893 rx_status
->rate_idx
= 8;
6896 rx_status
->rate_idx
= 9;
6899 rx_status
->rate_idx
= 10;
6902 rx_status
->rate_idx
= 11;
6905 WL_ERROR("%s: Unknown rate\n", __func__
);
6908 /* Determine short preamble and rate_idx */
6910 if (IS_CCK(rspec
)) {
6911 if (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
)
6912 WL_ERROR("Short CCK\n");
6913 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6914 } else if (IS_OFDM(rspec
)) {
6915 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6917 WL_ERROR("%s: Unknown modulation\n", __func__
);
6921 if (PLCP3_ISSGI(plcp
[3]))
6922 rx_status
->flag
|= RX_FLAG_SHORT_GI
;
6924 if (rxh
->RxStatus1
& RXS_DECERR
) {
6925 rx_status
->flag
|= RX_FLAG_FAILED_PLCP_CRC
;
6926 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__
);
6928 if (rxh
->RxStatus1
& RXS_FCSERR
) {
6929 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
6930 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__
);
6935 wlc_recvctl(struct wlc_info
*wlc
, struct osl_info
*osh
, d11rxhdr_t
*rxh
,
6939 struct ieee80211_rx_status rx_status
;
6941 struct sk_buff
*skb
= p
;
6944 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
6945 * Test for INTERMEDIATE like so:
6946 * if (!(plcp[0] | plcp[1] | plcp[2]))
6949 memset(&rx_status
, 0, sizeof(rx_status
));
6950 prep_mac80211_status(wlc
, rxh
, p
, &rx_status
);
6952 /* mac header+body length, exclude CRC and plcp header */
6953 len_mpdu
= p
->len
- D11_PHY_HDR_LEN
- FCS_LEN
;
6954 skb_pull(p
, D11_PHY_HDR_LEN
);
6955 __skb_trim(p
, len_mpdu
);
6960 ASSERT(IS_ALIGNED((unsigned long)skb
->data
, 2));
6962 memcpy(IEEE80211_SKB_RXCB(p
), &rx_status
, sizeof(rx_status
));
6963 ieee80211_rx_irqsafe(wlc
->pub
->ieee_hw
, p
);
6965 WLCNTINCR(wlc
->pub
->_cnt
->ieee_rx
);
6970 void wlc_bss_list_free(struct wlc_info
*wlc
, wlc_bss_list_t
*bss_list
)
6976 WL_ERROR("%s: Attempting to free NULL list\n", __func__
);
6979 /* inspect all BSS descriptor */
6980 for (index
= 0; index
< bss_list
->count
; index
++) {
6981 bi
= bss_list
->ptrs
[index
];
6984 bss_list
->ptrs
[index
] = NULL
;
6987 bss_list
->count
= 0;
6990 /* Process received frames */
6992 * Return true if more frames need to be processed. false otherwise.
6993 * Param 'bound' indicates max. # frames to process before break out.
6996 void BCMFASTPATH
wlc_recv(struct wlc_info
*wlc
, struct sk_buff
*p
)
6999 struct ieee80211_hdr
*h
;
7000 struct osl_info
*osh
;
7005 WL_TRACE("wl%d: wlc_recv\n", wlc
->pub
->unit
);
7009 /* frame starts with rxhdr */
7010 rxh
= (d11rxhdr_t
*) (p
->data
);
7012 /* strip off rxhdr */
7013 skb_pull(p
, wlc
->hwrxoff
);
7015 /* fixup rx header endianness */
7016 ltoh16_buf((void *)rxh
, sizeof(d11rxhdr_t
));
7018 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7019 if (rxh
->RxStatus1
& RXS_PBPRES
) {
7021 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7022 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7023 wlc
->pub
->unit
, p
->len
);
7029 h
= (struct ieee80211_hdr
*)(p
->data
+ D11_PHY_HDR_LEN
);
7032 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7033 if (wlc
->pub
->mac80211_state
& MAC80211_PROMISC_BCNS
) {
7034 WL_ERROR("FCSERR while scanning******* - tossing\n");
7037 WL_ERROR("RCSERR!!!\n");
7042 /* check received pkt has at least frame control field */
7043 if (len
>= D11_PHY_HDR_LEN
+ sizeof(h
->frame_control
)) {
7044 fc
= ltoh16(h
->frame_control
);
7046 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7050 is_amsdu
= rxh
->RxStatus2
& RXS_AMSDU_MASK
;
7052 /* explicitly test bad src address to avoid sending bad deauth */
7054 /* CTS and ACK CTL frames are w/o a2 */
7055 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
||
7056 (fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
7057 if ((is_zero_ether_addr(h
->addr2
) ||
7058 is_multicast_ether_addr(h
->addr2
))) {
7059 WL_ERROR("wl%d: %s: dropping a frame with "
7060 "invalid src mac address, a2: %pM\n",
7061 wlc
->pub
->unit
, __func__
, h
->addr2
);
7062 WLCNTINCR(wlc
->pub
->_cnt
->rxbadsrcmac
);
7065 WLCNTINCR(wlc
->pub
->_cnt
->rxfrag
);
7069 /* due to sheer numbers, toss out probe reqs for now */
7070 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
7071 if ((fc
& FC_KIND_MASK
) == FC_PROBE_REQ
)
7076 WL_ERROR("%s: is_amsdu causing toss\n", __func__
);
7080 wlc_recvctl(wlc
, osh
, rxh
, p
);
7084 pkt_buf_free_skb(osh
, p
, false);
7087 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7088 * number of bytes goes in the length field
7090 * Formula given by HT PHY Spec v 1.13
7091 * len = 3(nsyms + nstream + 3) - 3
7094 wlc_calc_lsig_len(struct wlc_info
*wlc
, ratespec_t ratespec
, uint mac_len
)
7096 uint nsyms
, len
= 0, kNdps
;
7098 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7099 wlc
->pub
->unit
, RSPEC2RATE(ratespec
), mac_len
);
7101 if (IS_MCS(ratespec
)) {
7102 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7103 /* MCS_TXS(mcs) returns num tx streams - 1 */
7104 int tot_streams
= (MCS_TXS(mcs
) + 1) + RSPEC_STC(ratespec
);
7106 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7107 /* the payload duration calculation matches that of regular ofdm */
7108 /* 1000Ndbps = kbps * 4 */
7110 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7111 RSPEC_ISSGI(ratespec
)) * 4;
7113 if (RSPEC_STC(ratespec
) == 0)
7114 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7116 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7117 APHY_TAIL_NBITS
) * 1000, kNdps
);
7119 /* STBC needs to have even number of symbols */
7122 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7123 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7125 nsyms
+= (tot_streams
+ 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7126 /* 3 bytes/symbol @ legacy 6Mbps rate */
7127 len
= (3 * nsyms
) - 3; /* (-3) excluding service bits and tail bits */
7133 /* calculate frame duration of a given rate and length, return time in usec unit */
7135 wlc_calc_frame_time(struct wlc_info
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7138 uint nsyms
, dur
= 0, Ndps
, kNdps
;
7139 uint rate
= RSPEC2RATE(ratespec
);
7143 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc
->pub
->unit
);
7147 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7148 wlc
->pub
->unit
, ratespec
, preamble_type
, mac_len
);
7150 if (IS_MCS(ratespec
)) {
7151 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7152 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7153 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7154 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type
));
7156 dur
= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7157 if (preamble_type
== WLC_MM_PREAMBLE
)
7159 /* 1000Ndbps = kbps * 4 */
7161 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7162 RSPEC_ISSGI(ratespec
)) * 4;
7164 if (RSPEC_STC(ratespec
) == 0)
7165 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7167 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7168 APHY_TAIL_NBITS
) * 1000, kNdps
);
7170 /* STBC needs to have even number of symbols */
7173 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7174 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7176 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7177 if (BAND_2G(wlc
->band
->bandtype
))
7178 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7179 } else if (IS_OFDM(rate
)) {
7180 dur
= APHY_PREAMBLE_TIME
;
7181 dur
+= APHY_SIGNAL_TIME
;
7182 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7184 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7186 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+ APHY_TAIL_NBITS
),
7188 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7189 if (BAND_2G(wlc
->band
->bandtype
))
7190 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7192 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7193 mac_len
= mac_len
* 8 * 2;
7194 /* calc ceiling of bits/rate = microseconds of air time */
7195 dur
= (mac_len
+ rate
- 1) / rate
;
7196 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7197 dur
+= BPHY_PLCP_SHORT_TIME
;
7199 dur
+= BPHY_PLCP_TIME
;
7204 /* The opposite of wlc_calc_frame_time */
7206 wlc_calc_frame_len(struct wlc_info
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7209 uint nsyms
, mac_len
, Ndps
, kNdps
;
7210 uint rate
= RSPEC2RATE(ratespec
);
7212 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7213 wlc
->pub
->unit
, ratespec
, preamble_type
, dur
);
7215 if (IS_MCS(ratespec
)) {
7216 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7217 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7218 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7219 dur
-= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7220 /* payload calculation matches that of regular ofdm */
7221 if (BAND_2G(wlc
->band
->bandtype
))
7222 dur
-= DOT11_OFDM_SIGNAL_EXTENSION
;
7223 /* kNdbps = kbps * 4 */
7225 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7226 RSPEC_ISSGI(ratespec
)) * 4;
7227 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7230 ((APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
) * 1000)) / 8000;
7231 } else if (IS_OFDM(ratespec
)) {
7232 dur
-= APHY_PREAMBLE_TIME
;
7233 dur
-= APHY_SIGNAL_TIME
;
7234 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7236 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7239 (APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
)) / 8;
7241 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7242 dur
-= BPHY_PLCP_SHORT_TIME
;
7244 dur
-= BPHY_PLCP_TIME
;
7245 mac_len
= dur
* rate
;
7246 /* divide out factor of 2 in rate (1/2 mbps) */
7247 mac_len
= mac_len
/ 8 / 2;
7253 wlc_calc_ba_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7255 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7256 wlc
->pub
->unit
, rspec
, preamble_type
);
7257 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7258 * or equal to the rate of the immediately previous frame in the FES
7260 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7261 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7263 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7264 return wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7265 (DOT11_BA_LEN
+ DOT11_BA_BITMAP_LEN
+
7269 static uint BCMFASTPATH
7270 wlc_calc_ack_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7274 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7275 wlc
->pub
->unit
, rspec
, preamble_type
);
7276 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7277 * or equal to the rate of the immediately previous frame in the FES
7279 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7280 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7282 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7284 wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7285 (DOT11_ACK_LEN
+ FCS_LEN
));
7290 wlc_calc_cts_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7292 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7293 wlc
->pub
->unit
, rspec
, preamble_type
);
7294 return wlc_calc_ack_time(wlc
, rspec
, preamble_type
);
7297 /* derive wlc->band->basic_rate[] table from 'rateset' */
7298 void wlc_rate_lookup_init(struct wlc_info
*wlc
, wlc_rateset_t
*rateset
)
7304 u8
*br
= wlc
->band
->basic_rate
;
7307 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7308 memset(br
, 0, WLC_MAXRATE
+ 1);
7310 /* For each basic rate in the rates list, make an entry in the
7311 * best basic lookup.
7313 for (i
= 0; i
< rateset
->count
; i
++) {
7314 /* only make an entry for a basic rate */
7315 if (!(rateset
->rates
[i
] & WLC_RATE_FLAG
))
7318 /* mask off basic bit */
7319 rate
= (rateset
->rates
[i
] & RATE_MASK
);
7321 if (rate
> WLC_MAXRATE
) {
7322 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7330 /* The rate lookup table now has non-zero entries for each
7331 * basic rate, equal to the basic rate: br[basicN] = basicN
7333 * To look up the best basic rate corresponding to any
7334 * particular rate, code can use the basic_rate table
7337 * basic_rate = wlc->band->basic_rate[tx_rate]
7339 * Make sure there is a best basic rate entry for
7340 * every rate by walking up the table from low rates
7341 * to high, filling in holes in the lookup table
7344 for (i
= 0; i
< wlc
->band
->hw_rateset
.count
; i
++) {
7345 rate
= wlc
->band
->hw_rateset
.rates
[i
];
7346 ASSERT(rate
<= WLC_MAXRATE
);
7348 if (br
[rate
] != 0) {
7349 /* This rate is a basic rate.
7350 * Keep track of the best basic rate so far by
7361 /* This rate is not a basic rate so figure out the
7362 * best basic rate less than this rate and fill in
7363 * the hole in the table
7366 br
[rate
] = IS_OFDM(rate
) ? ofdm_basic
: cck_basic
;
7371 if (IS_OFDM(rate
)) {
7372 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7373 if (rate
>= WLC_RATE_24M
)
7374 mandatory
= WLC_RATE_24M
;
7375 else if (rate
>= WLC_RATE_12M
)
7376 mandatory
= WLC_RATE_12M
;
7378 mandatory
= WLC_RATE_6M
;
7380 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7384 br
[rate
] = mandatory
;
7388 static void wlc_write_rate_shm(struct wlc_info
*wlc
, u8 rate
, u8 basic_rate
)
7391 u8 basic_phy_rate
, basic_index
;
7392 u16 dir_table
, basic_table
;
7395 /* Shared memory address for the table we are reading */
7396 dir_table
= IS_OFDM(basic_rate
) ? M_RT_DIRMAP_A
: M_RT_DIRMAP_B
;
7398 /* Shared memory address for the table we are writing */
7399 basic_table
= IS_OFDM(rate
) ? M_RT_BBRSMAP_A
: M_RT_BBRSMAP_B
;
7402 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7403 * the index into the rate table.
7405 phy_rate
= rate_info
[rate
] & RATE_MASK
;
7406 basic_phy_rate
= rate_info
[basic_rate
] & RATE_MASK
;
7407 index
= phy_rate
& 0xf;
7408 basic_index
= basic_phy_rate
& 0xf;
7410 /* Find the SHM pointer to the ACK rate entry by looking in the
7413 basic_ptr
= wlc_read_shm(wlc
, (dir_table
+ basic_index
* 2));
7415 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7416 * to the correct basic rate for the given incoming rate
7418 wlc_write_shm(wlc
, (basic_table
+ index
* 2), basic_ptr
);
7421 static const wlc_rateset_t
*wlc_rateset_get_hwrs(struct wlc_info
*wlc
)
7423 const wlc_rateset_t
*rs_dflt
;
7425 if (WLC_PHY_11N_CAP(wlc
->band
)) {
7426 if (BAND_5G(wlc
->band
->bandtype
))
7427 rs_dflt
= &ofdm_mimo_rates
;
7429 rs_dflt
= &cck_ofdm_mimo_rates
;
7430 } else if (wlc
->band
->gmode
)
7431 rs_dflt
= &cck_ofdm_rates
;
7433 rs_dflt
= &cck_rates
;
7438 void wlc_set_ratetable(struct wlc_info
*wlc
)
7440 const wlc_rateset_t
*rs_dflt
;
7442 u8 rate
, basic_rate
;
7445 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7446 ASSERT(rs_dflt
!= NULL
);
7448 wlc_rateset_copy(rs_dflt
, &rs
);
7449 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7451 /* walk the phy rate table and update SHM basic rate lookup table */
7452 for (i
= 0; i
< rs
.count
; i
++) {
7453 rate
= rs
.rates
[i
] & RATE_MASK
;
7455 /* for a given rate WLC_BASIC_RATE returns the rate at
7456 * which a response ACK/CTS should be sent.
7458 basic_rate
= WLC_BASIC_RATE(wlc
, rate
);
7459 if (basic_rate
== 0) {
7460 /* This should only happen if we are using a
7461 * restricted rateset.
7463 basic_rate
= rs
.rates
[0] & RATE_MASK
;
7466 wlc_write_rate_shm(wlc
, rate
, basic_rate
);
7471 * Return true if the specified rate is supported by the specified band.
7472 * WLC_BAND_AUTO indicates the current band.
7474 bool wlc_valid_rate(struct wlc_info
*wlc
, ratespec_t rspec
, int band
,
7477 wlc_rateset_t
*hw_rateset
;
7480 if ((band
== WLC_BAND_AUTO
) || (band
== wlc
->band
->bandtype
)) {
7481 hw_rateset
= &wlc
->band
->hw_rateset
;
7482 } else if (NBANDS(wlc
) > 1) {
7483 hw_rateset
= &wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->hw_rateset
;
7485 /* other band specified and we are a single band device */
7489 /* check if this is a mimo rate */
7490 if (IS_MCS(rspec
)) {
7491 if (!VALID_MCS((rspec
& RSPEC_RATE_MASK
)))
7494 return isset(hw_rateset
->mcs
, (rspec
& RSPEC_RATE_MASK
));
7497 for (i
= 0; i
< hw_rateset
->count
; i
++)
7498 if (hw_rateset
->rates
[i
] == RSPEC2RATE(rspec
))
7502 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7503 wlc
->pub
->unit
, rspec
);
7509 static void wlc_update_mimo_band_bwcap(struct wlc_info
*wlc
, u8 bwcap
)
7512 struct wlcband
*band
;
7514 for (i
= 0; i
< NBANDS(wlc
); i
++) {
7515 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
7517 band
= wlc
->bandstate
[i
];
7518 if (band
->bandtype
== WLC_BAND_5G
) {
7519 if ((bwcap
== WLC_N_BW_40ALL
)
7520 || (bwcap
== WLC_N_BW_20IN2G_40IN5G
))
7521 band
->mimo_cap_40
= true;
7523 band
->mimo_cap_40
= false;
7525 ASSERT(band
->bandtype
== WLC_BAND_2G
);
7526 if (bwcap
== WLC_N_BW_40ALL
)
7527 band
->mimo_cap_40
= true;
7529 band
->mimo_cap_40
= false;
7533 wlc
->mimo_band_bwcap
= bwcap
;
7536 void wlc_mod_prb_rsp_rate_table(struct wlc_info
*wlc
, uint frame_len
)
7538 const wlc_rateset_t
*rs_dflt
;
7542 u8 plcp
[D11_PHY_HDR_LEN
];
7546 sifs
= SIFS(wlc
->band
);
7548 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7549 ASSERT(rs_dflt
!= NULL
);
7551 wlc_rateset_copy(rs_dflt
, &rs
);
7552 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7554 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7555 for (i
= 0; i
< rs
.count
; i
++) {
7556 rate
= rs
.rates
[i
] & RATE_MASK
;
7558 entry_ptr
= wlc_rate_shm_offset(wlc
, rate
);
7560 /* Calculate the Probe Response PLCP for the given rate */
7561 wlc_compute_plcp(wlc
, rate
, frame_len
, plcp
);
7563 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7565 (u16
) wlc_calc_frame_time(wlc
, rate
, WLC_LONG_PREAMBLE
,
7569 /* Update the SHM Rate Table entry Probe Response values */
7570 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
,
7571 (u16
) (plcp
[0] + (plcp
[1] << 8)));
7572 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
+ 2,
7573 (u16
) (plcp
[2] + (plcp
[3] << 8)));
7574 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_DUR_POS
, dur
);
7579 wlc_compute_bcntsfoff(struct wlc_info
*wlc
, ratespec_t rspec
,
7580 bool short_preamble
, bool phydelay
)
7584 if (IS_MCS(rspec
)) {
7585 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7586 wlc
->pub
->unit
, rspec
);
7587 } else if (IS_OFDM(rspec
)) {
7588 /* tx delay from MAC through phy to air (2.1 usec) +
7589 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7590 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7591 * bytes at beacon rate)
7593 bcntsfoff
+= phydelay
? D11A_PHY_TX_DELAY
: 0;
7594 bcntsfoff
+= APHY_PREAMBLE_TIME
+ APHY_SIGNAL_TIME
;
7596 wlc_compute_airtime(wlc
, rspec
,
7597 APHY_SERVICE_NBITS
/ 8 +
7600 /* tx delay from MAC through phy to air (3.4 usec) +
7601 * phy header time (long preamble + PLCP == 192 usec) +
7602 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7604 bcntsfoff
+= phydelay
? D11B_PHY_TX_DELAY
: 0;
7606 short_preamble
? D11B_PHY_SPREHDR_TIME
:
7607 D11B_PHY_LPREHDR_TIME
;
7608 bcntsfoff
+= wlc_compute_airtime(wlc
, rspec
, DOT11_MAC_HDR_LEN
);
7610 return (u16
) (bcntsfoff
);
7613 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7615 * PLCP header is 6 bytes.
7616 * 802.11 A3 header is 24 bytes.
7617 * Max beacon frame body template length is 112 bytes.
7618 * Max probe resp frame body template length is 110 bytes.
7620 * *len on input contains the max length of the packet available.
7622 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7623 * and included up to, but not including, the 4 byte FCS.
7626 wlc_bcn_prb_template(struct wlc_info
*wlc
, uint type
, ratespec_t bcn_rspec
,
7627 wlc_bsscfg_t
*cfg
, u16
*buf
, int *len
)
7629 static const u8 ether_bcast
[ETH_ALEN
] = {255, 255, 255, 255, 255, 255};
7630 cck_phy_hdr_t
*plcp
;
7631 struct ieee80211_mgmt
*h
;
7632 int hdr_len
, body_len
;
7634 ASSERT(*len
>= 142);
7635 ASSERT(type
== FC_BEACON
|| type
== FC_PROBE_RESP
);
7637 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7638 hdr_len
= DOT11_MAC_HDR_LEN
;
7640 hdr_len
= D11_PHY_HDR_LEN
+ DOT11_MAC_HDR_LEN
;
7641 body_len
= *len
- hdr_len
; /* calc buffer size provided for frame body */
7643 *len
= hdr_len
+ body_len
; /* return actual size */
7645 /* format PHY and MAC headers */
7646 memset((char *)buf
, 0, hdr_len
);
7648 plcp
= (cck_phy_hdr_t
*) buf
;
7650 /* PLCP for Probe Response frames are filled in from core's rate table */
7651 if (type
== FC_BEACON
&& !MBSS_BCN_ENAB(cfg
)) {
7653 wlc_compute_plcp(wlc
, bcn_rspec
,
7654 (DOT11_MAC_HDR_LEN
+ body_len
+ FCS_LEN
),
7658 /* "Regular" and 16 MBSS but not for 4 MBSS */
7659 /* Update the phytxctl for the beacon based on the rspec */
7660 if (!SOFTBCN_ENAB(cfg
))
7661 wlc_beacon_phytxctl_txant_upd(wlc
, bcn_rspec
);
7663 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7664 h
= (struct ieee80211_mgmt
*)&plcp
[0];
7666 h
= (struct ieee80211_mgmt
*)&plcp
[1];
7668 /* fill in 802.11 header */
7669 h
->frame_control
= htol16((u16
) type
);
7671 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7672 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7673 if (type
== FC_BEACON
)
7674 bcopy((const char *)ðer_bcast
, (char *)&h
->da
,
7676 bcopy((char *)&cfg
->cur_etheraddr
, (char *)&h
->sa
, ETH_ALEN
);
7677 bcopy((char *)&cfg
->BSSID
, (char *)&h
->bssid
, ETH_ALEN
);
7679 /* SEQ filled in by MAC */
7684 int wlc_get_header_len()
7689 /* Update a beacon for a particular BSS
7690 * For MBSS, this updates the software template and sets "latest" to the index of the
7692 * Otherwise, it updates the hardware template.
7694 void wlc_bss_update_beacon(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
)
7696 int len
= BCN_TMPL_LEN
;
7698 /* Clear the soft intmask */
7699 wlc
->defmacintmask
&= ~MI_BCNTPL
;
7701 if (!cfg
->up
) { /* Only allow updates on an UP bss */
7705 if (MBSS_BCN_ENAB(cfg
)) { /* Optimize: Some of if/else could be combined */
7706 } else if (HWBCN_ENAB(cfg
)) { /* Hardware beaconing for this config */
7707 u16 bcn
[BCN_TMPL_LEN
/ 2];
7708 u32 both_valid
= MCMD_BCN0VLD
| MCMD_BCN1VLD
;
7709 d11regs_t
*regs
= wlc
->regs
;
7710 struct osl_info
*osh
= NULL
;
7714 /* Check if both templates are in use, if so sched. an interrupt
7715 * that will call back into this routine
7717 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7718 /* clear any previous status */
7719 W_REG(osh
, ®s
->macintstatus
, MI_BCNTPL
);
7721 /* Check that after scheduling the interrupt both of the
7722 * templates are still busy. if not clear the int. & remask
7724 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7725 wlc
->defmacintmask
|= MI_BCNTPL
;
7730 wlc_lowest_basic_rspec(wlc
, &cfg
->current_bss
->rateset
);
7731 ASSERT(wlc_valid_rate
7732 (wlc
, wlc
->bcn_rspec
,
7733 CHSPEC_IS2G(cfg
->current_bss
->
7734 chanspec
) ? WLC_BAND_2G
: WLC_BAND_5G
,
7737 /* update the template and ucode shm */
7738 wlc_bcn_prb_template(wlc
, FC_BEACON
, wlc
->bcn_rspec
, cfg
, bcn
,
7740 wlc_write_hw_bcntemplates(wlc
, bcn
, len
, false);
7745 * Update all beacons for the system.
7747 void wlc_update_beacon(struct wlc_info
*wlc
)
7750 wlc_bsscfg_t
*bsscfg
;
7752 /* update AP or IBSS beacons */
7753 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7754 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7755 wlc_bss_update_beacon(wlc
, bsscfg
);
7759 /* Write ssid into shared memory */
7760 void wlc_shm_ssid_upd(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
)
7762 u8
*ssidptr
= cfg
->SSID
;
7764 u8 ssidbuf
[IEEE80211_MAX_SSID_LEN
];
7766 /* padding the ssid with zero and copy it into shm */
7767 memset(ssidbuf
, 0, IEEE80211_MAX_SSID_LEN
);
7768 bcopy(ssidptr
, ssidbuf
, cfg
->SSID_len
);
7770 wlc_copyto_shm(wlc
, base
, ssidbuf
, IEEE80211_MAX_SSID_LEN
);
7772 if (!MBSS_BCN_ENAB(cfg
))
7773 wlc_write_shm(wlc
, M_SSIDLEN
, (u16
) cfg
->SSID_len
);
7776 void wlc_update_probe_resp(struct wlc_info
*wlc
, bool suspend
)
7779 wlc_bsscfg_t
*bsscfg
;
7781 /* update AP or IBSS probe responses */
7782 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7783 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7784 wlc_bss_update_probe_resp(wlc
, bsscfg
, suspend
);
7789 wlc_bss_update_probe_resp(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
, bool suspend
)
7791 u16 prb_resp
[BCN_TMPL_LEN
/ 2];
7792 int len
= BCN_TMPL_LEN
;
7794 /* write the probe response to hardware, or save in the config structure */
7795 if (!MBSS_PRB_ENAB(cfg
)) {
7797 /* create the probe response template */
7798 wlc_bcn_prb_template(wlc
, FC_PROBE_RESP
, 0, cfg
, prb_resp
,
7802 wlc_suspend_mac_and_wait(wlc
);
7804 /* write the probe response into the template region */
7805 wlc_bmac_write_template_ram(wlc
->hw
, T_PRS_TPL_BASE
,
7806 (len
+ 3) & ~3, prb_resp
);
7808 /* write the length of the probe response frame (+PLCP/-FCS) */
7809 wlc_write_shm(wlc
, M_PRB_RESP_FRM_LEN
, (u16
) len
);
7811 /* write the SSID and SSID length */
7812 wlc_shm_ssid_upd(wlc
, cfg
);
7815 * Write PLCP headers and durations for probe response frames at all rates.
7816 * Use the actual frame length covered by the PLCP header for the call to
7817 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7819 len
+= (-D11_PHY_HDR_LEN
+ FCS_LEN
);
7820 wlc_mod_prb_rsp_rate_table(wlc
, (u16
) len
);
7823 wlc_enable_mac(wlc
);
7824 } else { /* Generating probe resp in sw; update local template */
7825 ASSERT(0 && "No software probe response support without MBSS");
7829 /* prepares pdu for transmission. returns BCM error codes */
7830 int wlc_prep_pdu(struct wlc_info
*wlc
, struct sk_buff
*pdu
, uint
*fifop
)
7832 struct osl_info
*osh
;
7835 struct ieee80211_hdr
*h
;
7842 txh
= (d11txh_t
*) (pdu
->data
);
7844 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
7846 fc
= ltoh16(h
->frame_control
);
7848 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7849 fifo
= ltoh16(txh
->TxFrameID
) & TXFID_QUEUE_MASK
;
7855 /* return if insufficient dma resources */
7856 if (TXAVAIL(wlc
, fifo
) < MAX_DMA_SEGS
) {
7857 /* Mark precedences related to this FIFO, unsendable */
7858 WLC_TX_FIFO_CLEAR(wlc
, fifo
);
7862 if ((ltoh16(txh
->MacFrameControl
) & IEEE80211_FCTL_FTYPE
) !=
7863 IEEE80211_FTYPE_DATA
)
7864 WLCNTINCR(wlc
->pub
->_cnt
->txctl
);
7869 /* init tx reported rate mechanism */
7870 void wlc_reprate_init(struct wlc_info
*wlc
)
7873 wlc_bsscfg_t
*bsscfg
;
7875 FOREACH_BSS(wlc
, i
, bsscfg
) {
7876 wlc_bsscfg_reprate_init(bsscfg
);
7880 /* per bsscfg init tx reported rate mechanism */
7881 void wlc_bsscfg_reprate_init(wlc_bsscfg_t
*bsscfg
)
7883 bsscfg
->txrspecidx
= 0;
7884 memset((char *)bsscfg
->txrspec
, 0, sizeof(bsscfg
->txrspec
));
7887 /* Retrieve a consolidated set of revision information,
7888 * typically for the WLC_GET_REVINFO ioctl
7890 int wlc_get_revision_info(struct wlc_info
*wlc
, void *buf
, uint len
)
7892 wlc_rev_info_t
*rinfo
= (wlc_rev_info_t
*) buf
;
7894 if (len
< WL_REV_INFO_LEGACY_LENGTH
)
7895 return BCME_BUFTOOSHORT
;
7897 rinfo
->vendorid
= wlc
->vendorid
;
7898 rinfo
->deviceid
= wlc
->deviceid
;
7899 rinfo
->radiorev
= (wlc
->band
->radiorev
<< IDCODE_REV_SHIFT
) |
7900 (wlc
->band
->radioid
<< IDCODE_ID_SHIFT
);
7901 rinfo
->chiprev
= wlc
->pub
->sih
->chiprev
;
7902 rinfo
->corerev
= wlc
->pub
->corerev
;
7903 rinfo
->boardid
= wlc
->pub
->sih
->boardtype
;
7904 rinfo
->boardvendor
= wlc
->pub
->sih
->boardvendor
;
7905 rinfo
->boardrev
= wlc
->pub
->boardrev
;
7906 rinfo
->ucoderev
= wlc
->ucode_rev
;
7907 rinfo
->driverrev
= EPI_VERSION_NUM
;
7908 rinfo
->bus
= wlc
->pub
->sih
->bustype
;
7909 rinfo
->chipnum
= wlc
->pub
->sih
->chip
;
7911 if (len
>= (offsetof(wlc_rev_info_t
, chippkg
))) {
7912 rinfo
->phytype
= wlc
->band
->phytype
;
7913 rinfo
->phyrev
= wlc
->band
->phyrev
;
7914 rinfo
->anarev
= 0; /* obsolete stuff, suppress */
7917 if (len
>= sizeof(*rinfo
)) {
7918 rinfo
->chippkg
= wlc
->pub
->sih
->chippkg
;
7924 void wlc_default_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
7926 wlc_rateset_default(rs
, NULL
, wlc
->band
->phytype
, wlc
->band
->bandtype
,
7927 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7928 CHSPEC_WLC_BW(wlc
->default_bss
->chanspec
),
7929 wlc
->stf
->txstreams
);
7932 static void wlc_bss_default_init(struct wlc_info
*wlc
)
7934 chanspec_t chanspec
;
7935 struct wlcband
*band
;
7936 wlc_bss_info_t
*bi
= wlc
->default_bss
;
7938 /* init default and target BSS with some sane initial values */
7939 memset((char *)(bi
), 0, sizeof(wlc_bss_info_t
));
7940 bi
->beacon_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? BEACON_INTERVAL_DEF_QT
:
7941 BEACON_INTERVAL_DEFAULT
;
7942 bi
->dtim_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? DTIM_INTERVAL_DEF_QT
:
7943 DTIM_INTERVAL_DEFAULT
;
7945 /* fill the default channel as the first valid channel
7946 * starting from the 2G channels
7948 chanspec
= CH20MHZ_CHSPEC(1);
7949 ASSERT(chanspec
!= INVCHANSPEC
);
7951 wlc
->home_chanspec
= bi
->chanspec
= chanspec
;
7953 /* find the band of our default channel */
7955 if (NBANDS(wlc
) > 1 && band
->bandunit
!= CHSPEC_WLCBANDUNIT(chanspec
))
7956 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
7958 /* init bss rates to the band specific default rate set */
7959 wlc_rateset_default(&bi
->rateset
, NULL
, band
->phytype
, band
->bandtype
,
7960 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7961 CHSPEC_WLC_BW(chanspec
), wlc
->stf
->txstreams
);
7963 if (N_ENAB(wlc
->pub
))
7964 bi
->flags
|= WLC_BSS_HT
;
7967 /* Deferred event processing */
7968 static void wlc_process_eventq(void *arg
)
7970 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
7973 while ((etmp
= wlc_eventq_deq(wlc
->eventq
))) {
7974 /* Perform OS specific event processing */
7975 wl_event(wlc
->wl
, etmp
->event
.ifname
, etmp
);
7980 wlc_event_free(wlc
->eventq
, etmp
);
7985 wlc_uint64_sub(u32
*a_high
, u32
*a_low
, u32 b_high
, u32 b_low
)
7987 if (b_low
> *a_low
) {
7988 /* low half needs a carry */
7996 mac80211_wlc_set_nrate(struct wlc_info
*wlc
, struct wlcband
*cur_band
,
7999 u8 stf
= (int_val
& NRATE_STF_MASK
) >> NRATE_STF_SHIFT
;
8000 u8 rate
= int_val
& NRATE_RATE_MASK
;
8002 bool ismcs
= ((int_val
& NRATE_MCS_INUSE
) == NRATE_MCS_INUSE
);
8003 bool issgi
= ((int_val
& NRATE_SGI_MASK
) >> NRATE_SGI_SHIFT
);
8004 bool override_mcs_only
= ((int_val
& NRATE_OVERRIDE_MCS_ONLY
)
8005 == NRATE_OVERRIDE_MCS_ONLY
);
8009 return (ratespec_t
) rate
;
8012 /* validate the combination of rate/mcs/stf is allowed */
8013 if (N_ENAB(wlc
->pub
) && ismcs
) {
8014 /* mcs only allowed when nmode */
8015 if (stf
> PHY_TXC1_MODE_SDM
) {
8016 WL_ERROR("wl%d: %s: Invalid stf\n",
8017 WLCWLUNIT(wlc
), __func__
);
8018 bcmerror
= BCME_RANGE
;
8022 /* mcs 32 is a special case, DUP mode 40 only */
8024 if (!CHSPEC_IS40(wlc
->home_chanspec
) ||
8025 ((stf
!= PHY_TXC1_MODE_SISO
)
8026 && (stf
!= PHY_TXC1_MODE_CDD
))) {
8027 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8028 WLCWLUNIT(wlc
), __func__
);
8029 bcmerror
= BCME_RANGE
;
8032 /* mcs > 7 must use stf SDM */
8033 } else if (rate
> HIGHEST_SINGLE_STREAM_MCS
) {
8034 /* mcs > 7 must use stf SDM */
8035 if (stf
!= PHY_TXC1_MODE_SDM
) {
8036 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8037 WLCWLUNIT(wlc
), __func__
, rate
);
8038 stf
= PHY_TXC1_MODE_SDM
;
8041 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8042 if ((stf
> PHY_TXC1_MODE_STBC
) ||
8043 (!WLC_STBC_CAP_PHY(wlc
)
8044 && (stf
== PHY_TXC1_MODE_STBC
))) {
8045 WL_ERROR("wl%d: %s: Invalid STBC\n",
8046 WLCWLUNIT(wlc
), __func__
);
8047 bcmerror
= BCME_RANGE
;
8051 } else if (IS_OFDM(rate
)) {
8052 if ((stf
!= PHY_TXC1_MODE_CDD
) && (stf
!= PHY_TXC1_MODE_SISO
)) {
8053 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8054 WLCWLUNIT(wlc
), __func__
);
8055 bcmerror
= BCME_RANGE
;
8058 } else if (IS_CCK(rate
)) {
8059 if ((cur_band
->bandtype
!= WLC_BAND_2G
)
8060 || (stf
!= PHY_TXC1_MODE_SISO
)) {
8061 WL_ERROR("wl%d: %s: Invalid CCK\n",
8062 WLCWLUNIT(wlc
), __func__
);
8063 bcmerror
= BCME_RANGE
;
8067 WL_ERROR("wl%d: %s: Unknown rate type\n",
8068 WLCWLUNIT(wlc
), __func__
);
8069 bcmerror
= BCME_RANGE
;
8072 /* make sure multiple antennae are available for non-siso rates */
8073 if ((stf
!= PHY_TXC1_MODE_SISO
) && (wlc
->stf
->txstreams
== 1)) {
8074 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8075 WLCWLUNIT(wlc
), __func__
);
8076 bcmerror
= BCME_RANGE
;
8082 rspec
|= RSPEC_MIMORATE
;
8083 /* For STBC populate the STC field of the ratespec */
8084 if (stf
== PHY_TXC1_MODE_STBC
) {
8086 stc
= 1; /* Nss for single stream is always 1 */
8087 rspec
|= (stc
<< RSPEC_STC_SHIFT
);
8091 rspec
|= (stf
<< RSPEC_STF_SHIFT
);
8093 if (override_mcs_only
)
8094 rspec
|= RSPEC_OVERRIDE_MCS_ONLY
;
8097 rspec
|= RSPEC_SHORT_GI
;
8100 && !wlc_valid_rate(wlc
, rspec
, cur_band
->bandtype
, true)) {
8106 WL_ERROR("Hoark\n");
8110 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8112 wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
8115 int idle_busy_ratio_x_16
= 0;
8117 isOFDM
? M_TX_IDLE_BUSY_RATIO_X_16_OFDM
:
8118 M_TX_IDLE_BUSY_RATIO_X_16_CCK
;
8119 if (duty_cycle
> 100 || duty_cycle
< 0) {
8120 WL_ERROR("wl%d: duty cycle value off limit\n", wlc
->pub
->unit
);
8124 idle_busy_ratio_x_16
= (100 - duty_cycle
) * 16 / duty_cycle
;
8125 /* Only write to shared memory when wl is up */
8127 wlc_write_shm(wlc
, offset
, (u16
) idle_busy_ratio_x_16
);
8130 wlc
->tx_duty_cycle_ofdm
= (u16
) duty_cycle
;
8132 wlc
->tx_duty_cycle_cck
= (u16
) duty_cycle
;
8137 /* Read a single u16 from shared memory.
8138 * SHM 'offset' needs to be an even address
8140 u16
wlc_read_shm(struct wlc_info
*wlc
, uint offset
)
8142 return wlc_bmac_read_shm(wlc
->hw
, offset
);
8145 /* Write a single u16 to shared memory.
8146 * SHM 'offset' needs to be an even address
8148 void wlc_write_shm(struct wlc_info
*wlc
, uint offset
, u16 v
)
8150 wlc_bmac_write_shm(wlc
->hw
, offset
, v
);
8153 /* Set a range of shared memory to a value.
8154 * SHM 'offset' needs to be an even address and
8155 * Range length 'len' must be an even number of bytes
8157 void wlc_set_shm(struct wlc_info
*wlc
, uint offset
, u16 v
, int len
)
8159 /* offset and len need to be even */
8160 ASSERT((offset
& 1) == 0);
8161 ASSERT((len
& 1) == 0);
8166 wlc_bmac_set_shm(wlc
->hw
, offset
, v
, len
);
8169 /* Copy a buffer to shared memory.
8170 * SHM 'offset' needs to be an even address and
8171 * Buffer length 'len' must be an even number of bytes
8173 void wlc_copyto_shm(struct wlc_info
*wlc
, uint offset
, const void *buf
, int len
)
8175 /* offset and len need to be even */
8176 ASSERT((offset
& 1) == 0);
8177 ASSERT((len
& 1) == 0);
8181 wlc_bmac_copyto_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8185 /* Copy from shared memory to a buffer.
8186 * SHM 'offset' needs to be an even address and
8187 * Buffer length 'len' must be an even number of bytes
8189 void wlc_copyfrom_shm(struct wlc_info
*wlc
, uint offset
, void *buf
, int len
)
8191 /* offset and len need to be even */
8192 ASSERT((offset
& 1) == 0);
8193 ASSERT((len
& 1) == 0);
8198 wlc_bmac_copyfrom_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8201 /* wrapper BMAC functions to for HIGH driver access */
8202 void wlc_mctrl(struct wlc_info
*wlc
, u32 mask
, u32 val
)
8204 wlc_bmac_mctrl(wlc
->hw
, mask
, val
);
8207 void wlc_corereset(struct wlc_info
*wlc
, u32 flags
)
8209 wlc_bmac_corereset(wlc
->hw
, flags
);
8212 void wlc_mhf(struct wlc_info
*wlc
, u8 idx
, u16 mask
, u16 val
, int bands
)
8214 wlc_bmac_mhf(wlc
->hw
, idx
, mask
, val
, bands
);
8217 u16
wlc_mhf_get(struct wlc_info
*wlc
, u8 idx
, int bands
)
8219 return wlc_bmac_mhf_get(wlc
->hw
, idx
, bands
);
8222 int wlc_xmtfifo_sz_get(struct wlc_info
*wlc
, uint fifo
, uint
*blocks
)
8224 return wlc_bmac_xmtfifo_sz_get(wlc
->hw
, fifo
, blocks
);
8227 void wlc_write_template_ram(struct wlc_info
*wlc
, int offset
, int len
,
8230 wlc_bmac_write_template_ram(wlc
->hw
, offset
, len
, buf
);
8233 void wlc_write_hw_bcntemplates(struct wlc_info
*wlc
, void *bcn
, int len
,
8236 wlc_bmac_write_hw_bcntemplates(wlc
->hw
, bcn
, len
, both
);
8240 wlc_set_addrmatch(struct wlc_info
*wlc
, int match_reg_offset
,
8243 wlc_bmac_set_addrmatch(wlc
->hw
, match_reg_offset
, addr
);
8246 void wlc_set_rcmta(struct wlc_info
*wlc
, int idx
, const u8
*addr
)
8248 wlc_bmac_set_rcmta(wlc
->hw
, idx
, addr
);
8251 void wlc_read_tsf(struct wlc_info
*wlc
, u32
*tsf_l_ptr
, u32
*tsf_h_ptr
)
8253 wlc_bmac_read_tsf(wlc
->hw
, tsf_l_ptr
, tsf_h_ptr
);
8256 void wlc_set_cwmin(struct wlc_info
*wlc
, u16 newmin
)
8258 wlc
->band
->CWmin
= newmin
;
8259 wlc_bmac_set_cwmin(wlc
->hw
, newmin
);
8262 void wlc_set_cwmax(struct wlc_info
*wlc
, u16 newmax
)
8264 wlc
->band
->CWmax
= newmax
;
8265 wlc_bmac_set_cwmax(wlc
->hw
, newmax
);
8268 void wlc_fifoerrors(struct wlc_info
*wlc
)
8271 wlc_bmac_fifoerrors(wlc
->hw
);
8274 /* Search mem rw utilities */
8276 void wlc_pllreq(struct wlc_info
*wlc
, bool set
, mbool req_bit
)
8278 wlc_bmac_pllreq(wlc
->hw
, set
, req_bit
);
8281 void wlc_reset_bmac_done(struct wlc_info
*wlc
)
8285 void wlc_ht_mimops_cap_update(struct wlc_info
*wlc
, u8 mimops_mode
)
8287 wlc
->ht_cap
.cap_info
&= ~HT_CAP_MIMO_PS_MASK
;
8288 wlc
->ht_cap
.cap_info
|= (mimops_mode
<< IEEE80211_HT_CAP_SM_PS_SHIFT
);
8290 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
8291 wlc_update_beacon(wlc
);
8292 wlc_update_probe_resp(wlc
, true);
8296 /* check for the particular priority flow control bit being set */
8298 wlc_txflowcontrol_prio_isset(struct wlc_info
*wlc
, wlc_txq_info_t
*q
, int prio
)
8302 if (prio
== ALLPRIO
) {
8303 prio_mask
= TXQ_STOP_FOR_PRIOFC_MASK
;
8305 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8306 prio_mask
= NBITVAL(prio
);
8309 return (q
->stopped
& prio_mask
) == prio_mask
;
8312 /* propogate the flow control to all interfaces using the given tx queue */
8313 void wlc_txflowcontrol(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
,
8319 WL_ERROR("%s: flow control kicks in\n", __func__
);
8321 if (prio
== ALLPRIO
) {
8322 prio_bits
= TXQ_STOP_FOR_PRIOFC_MASK
;
8324 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8325 prio_bits
= NBITVAL(prio
);
8328 cur_bits
= qi
->stopped
& prio_bits
;
8330 /* Check for the case of no change and return early
8331 * Otherwise update the bit and continue
8334 if (cur_bits
== prio_bits
) {
8337 mboolset(qi
->stopped
, prio_bits
);
8339 if (cur_bits
== 0) {
8342 mboolclr(qi
->stopped
, prio_bits
);
8345 /* If there is a flow control override we will not change the external
8346 * flow control state.
8348 if (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
) {
8352 wlc_txflowcontrol_signal(wlc
, qi
, on
, prio
);
8356 wlc_txflowcontrol_override(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8361 ASSERT(override
!= 0);
8362 ASSERT((override
& TXQ_STOP_FOR_PRIOFC_MASK
) == 0);
8364 prev_override
= (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
);
8366 /* Update the flow control bits and do an early return if there is
8367 * no change in the external flow control state.
8370 mboolset(qi
->stopped
, override
);
8371 /* if there was a previous override bit on, then setting this
8372 * makes no difference.
8374 if (prev_override
) {
8378 wlc_txflowcontrol_signal(wlc
, qi
, ON
, ALLPRIO
);
8380 mboolclr(qi
->stopped
, override
);
8381 /* clearing an override bit will only make a difference for
8382 * flow control if it was the only bit set. For any other
8383 * override setting, just return
8385 if (prev_override
!= override
) {
8389 if (qi
->stopped
== 0) {
8390 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8394 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
8395 if (!mboolisset(qi
->stopped
, NBITVAL(prio
)))
8396 wlc_txflowcontrol_signal(wlc
, qi
, OFF
,
8403 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
)
8407 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
8409 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8416 wlc_txflowcontrol_signal(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8419 struct wlc_if
*wlcif
;
8421 for (wlcif
= wlc
->wlcif_list
; wlcif
!= NULL
; wlcif
= wlcif
->next
) {
8422 if (wlcif
->qi
== qi
&& wlcif
->flags
& WLC_IF_LINKED
)
8423 wl_txflowcontrol(wlc
->wl
, wlcif
->wlif
, on
, prio
);
8427 static wlc_txq_info_t
*wlc_txq_alloc(struct wlc_info
*wlc
, struct osl_info
*osh
)
8429 wlc_txq_info_t
*qi
, *p
;
8431 qi
= (wlc_txq_info_t
*) wlc_calloc(osh
, wlc
->pub
->unit
,
8432 sizeof(wlc_txq_info_t
));
8437 /* Have enough room for control packets along with HI watermark */
8438 /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */
8439 /* The watermark for flowcontrol to OS packets will remain the same */
8440 pktq_init(&qi
->q
, WLC_PREC_COUNT
,
8441 (2 * wlc
->pub
->tunables
->datahiwat
) + PKTQ_LEN_DEFAULT
+
8442 wlc
->pub
->psq_pkts_total
);
8444 /* add this queue to the the global list */
8447 wlc
->tx_queues
= qi
;
8449 while (p
->next
!= NULL
)
8457 static void wlc_txq_free(struct wlc_info
*wlc
, struct osl_info
*osh
,
8465 /* remove the queue from the linked list */
8468 wlc
->tx_queues
= p
->next
;
8470 while (p
!= NULL
&& p
->next
!= qi
)
8472 ASSERT(p
->next
== qi
);
8474 p
->next
= p
->next
->next
;