2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include <linux/kernel.h>
17 #include <linux/ctype.h>
18 #include <linux/etherdevice.h>
19 #include <linux/pci_ids.h>
20 #include <net/mac80211.h>
35 #include "wlc_types.h"
41 #include "wlc_bsscfg.h"
42 #include "phy/wlc_phy_hal.h"
43 #include "wlc_channel.h"
46 #include "wlc_phy_hal.h"
47 #include "wlc_phy_shim.h"
48 #include "wlc_antsel.h"
50 #include "wlc_ampdu.h"
51 #include "wl_export.h"
52 #include "wlc_alloc.h"
56 * Disable statistics counting for WME
58 #define WLCNTSET(a, b)
60 #define WLCNTADD(a, b)
65 #define RSN_CAP_4_REPLAY_CNTRS 2
66 #define RSN_CAP_16_REPLAY_CNTRS 3
68 #define WPA_CAP_4_REPLAY_CNTRS RSN_CAP_4_REPLAY_CNTRS
69 #define WPA_CAP_16_REPLAY_CNTRS RSN_CAP_16_REPLAY_CNTRS
72 * Indication for txflowcontrol that all priority bits in
73 * TXQ_STOP_FOR_PRIOFC_MASK are to be considered.
78 * buffer length needed for wlc_format_ssid
79 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
81 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
83 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
84 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
86 #ifndef WLC_MPC_MAX_DELAYCNT
87 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
89 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
90 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
92 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
93 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
95 /* Scale down delays to accommodate QT slow speed */
96 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
97 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
99 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
102 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
103 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
104 * this low resolution driver tick can be used for maintenance tasks such as phy
105 * calibration and scb update
108 /* watchdog trigger mode: OSL timer or TBTT */
109 #define WLC_WATCHDOG_TBTT(wlc) \
110 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
112 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
113 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
115 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
116 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
126 /* Find basic rate for a given rate */
127 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
128 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
129 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
131 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
133 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
135 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
137 #define SCAN_IN_PROGRESS(x) 0
139 #define EPI_VERSION_NUM 0x054b0b00
142 /* pointer to most recently allocated wl/wlc */
143 static struct wlc_info
*wlc_info_dbg
= (struct wlc_info
*) (NULL
);
148 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
149 * table and by the wlc_doiovar() function. No ordering is imposed:
150 * the table is keyed by name, and the function uses a switch.
156 IOV_BCN_LI_BCN
, /* Beacon listen interval in # of beacons */
157 IOV_LAST
/* In case of a need to check max ID number */
160 const bcm_iovar_t wlc_iovars
[] = {
161 {"mpc", IOV_MPC
, (0), IOVT_BOOL
, 0},
162 {"rtsthresh", IOV_RTSTHRESH
, (IOVF_WHL
), IOVT_UINT16
, 0},
163 {"qtxpower", IOV_QTXPOWER
, (IOVF_WHL
), IOVT_UINT32
, 0},
164 {"bcn_li_bcn", IOV_BCN_LI_BCN
, (0), IOVT_UINT8
, 0},
168 const u8 prio2fifo
[NUMPRIO
] = {
169 TX_AC_BE_FIFO
, /* 0 BE AC_BE Best Effort */
170 TX_AC_BK_FIFO
, /* 1 BK AC_BK Background */
171 TX_AC_BK_FIFO
, /* 2 -- AC_BK Background */
172 TX_AC_BE_FIFO
, /* 3 EE AC_BE Best Effort */
173 TX_AC_VI_FIFO
, /* 4 CL AC_VI Video */
174 TX_AC_VI_FIFO
, /* 5 VI AC_VI Video */
175 TX_AC_VO_FIFO
, /* 6 VO AC_VO Voice */
176 TX_AC_VO_FIFO
/* 7 NC AC_VO Voice */
179 /* precedences numbers for wlc queues. These are twice as may levels as
181 * Odd numbers are used for HI priority traffic at same precedence levels
182 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
184 #define _WLC_PREC_NONE 0 /* None = - */
185 #define _WLC_PREC_BK 2 /* BK - Background */
186 #define _WLC_PREC_BE 4 /* BE - Best-effort */
187 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
188 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
189 #define _WLC_PREC_VI 10 /* Vi - Video */
190 #define _WLC_PREC_VO 12 /* Vo - Voice */
191 #define _WLC_PREC_NC 14 /* NC - Network Control */
193 /* 802.1D Priority to precedence queue mapping */
194 const u8 wlc_prio2prec_map
[] = {
195 _WLC_PREC_BE
, /* 0 BE - Best-effort */
196 _WLC_PREC_BK
, /* 1 BK - Background */
197 _WLC_PREC_NONE
, /* 2 None = - */
198 _WLC_PREC_EE
, /* 3 EE - Excellent-effort */
199 _WLC_PREC_CL
, /* 4 CL - Controlled Load */
200 _WLC_PREC_VI
, /* 5 Vi - Video */
201 _WLC_PREC_VO
, /* 6 Vo - Voice */
202 _WLC_PREC_NC
, /* 7 NC - Network Control */
205 /* Sanity check for tx_prec_map and fifo synchup
206 * Either there are some packets pending for the fifo, else if fifo is empty then
207 * all the corresponding precmap bits should be set
209 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
210 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
211 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
212 (wlc)->fifo2prec_map[(fifo)]))
214 /* TX FIFO number to WME/802.1E Access Category */
215 const u8 wme_fifo2ac
[] = { AC_BK
, AC_BE
, AC_VI
, AC_VO
, AC_BE
, AC_BE
};
217 /* WME/802.1E Access Category to TX FIFO number */
218 static const u8 wme_ac2fifo
[] = { 1, 0, 2, 3 };
220 static bool in_send_q
= false;
222 /* Shared memory location index for various AC params */
223 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
226 static const char *fifo_names
[] = {
227 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
229 static const char fifo_names
[6][0];
232 static const u8 acbitmap2maxprio
[] = {
233 PRIO_8021D_BE
, PRIO_8021D_BE
, PRIO_8021D_BK
, PRIO_8021D_BK
,
234 PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
,
235 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
,
236 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
239 /* currently the best mechanism for determining SIFS is the band in use */
240 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
242 /* value for # replay counters currently supported */
243 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
245 /* local prototypes */
246 static u16 BCMFASTPATH
wlc_d11hdrs_mac80211(struct wlc_info
*wlc
,
247 struct ieee80211_hw
*hw
,
249 struct scb
*scb
, uint frag
,
250 uint nfrags
, uint queue
,
253 ratespec_t rspec_override
);
255 static void wlc_ctrupd_cache(u16 cur_stat
, u16
*macstat_snapshot
, u32
*macstat
);
256 static void wlc_bss_default_init(struct wlc_info
*wlc
);
257 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
);
258 static ratespec_t
mac80211_wlc_set_nrate(struct wlc_info
*wlc
,
259 struct wlcband
*cur_band
, u32 int_val
);
260 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
);
261 static void wlc_watchdog(void *arg
);
262 static void wlc_watchdog_by_timer(void *arg
);
263 static u16
wlc_rate_shm_offset(struct wlc_info
*wlc
, u8 rate
);
264 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
);
265 static int wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
,
266 const bcm_iovar_t
*vi
);
267 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
);
269 /* send and receive */
270 static struct wlc_txq_info
*wlc_txq_alloc(struct wlc_info
*wlc
);
271 static void wlc_txq_free(struct wlc_info
*wlc
,
272 struct wlc_txq_info
*qi
);
273 static void wlc_txflowcontrol_signal(struct wlc_info
*wlc
,
274 struct wlc_txq_info
*qi
,
276 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
);
277 static u16
wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
,
279 static void wlc_compute_cck_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
280 static void wlc_compute_ofdm_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
281 static void wlc_compute_mimo_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
282 static u16
wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
,
283 u8 preamble_type
, uint next_frag_len
);
284 static void wlc_recvctl(struct wlc_info
*wlc
,
285 d11rxhdr_t
*rxh
, struct sk_buff
*p
);
286 static uint
wlc_calc_frame_len(struct wlc_info
*wlc
, ratespec_t rate
,
287 u8 preamble_type
, uint dur
);
288 static uint
wlc_calc_ack_time(struct wlc_info
*wlc
, ratespec_t rate
,
290 static uint
wlc_calc_cts_time(struct wlc_info
*wlc
, ratespec_t rate
,
292 /* interrupt, up/down, band */
293 static void wlc_setband(struct wlc_info
*wlc
, uint bandunit
);
294 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
);
295 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
);
296 static void wlc_bsinit(struct wlc_info
*wlc
);
297 static int wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
299 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
);
300 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
);
301 static void wlc_radio_timer(void *arg
);
302 static void wlc_radio_enable(struct wlc_info
*wlc
);
303 static void wlc_radio_upd(struct wlc_info
*wlc
);
305 /* scan, association, BSS */
306 static uint
wlc_calc_ba_time(struct wlc_info
*wlc
, ratespec_t rate
,
308 static void wlc_update_mimo_band_bwcap(struct wlc_info
*wlc
, u8 bwcap
);
309 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
);
310 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
);
311 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
);
313 static void wlc_wme_retries_write(struct wlc_info
*wlc
);
314 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
);
315 static uint
wlc_attach_module(struct wlc_info
*wlc
);
316 static void wlc_detach_module(struct wlc_info
*wlc
);
317 static void wlc_timers_deinit(struct wlc_info
*wlc
);
318 static void wlc_down_led_upd(struct wlc_info
*wlc
);
319 static uint
wlc_down_del_timer(struct wlc_info
*wlc
);
320 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
);
321 static int _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
322 struct wlc_if
*wlcif
);
325 void wlc_get_rcmta(struct wlc_info
*wlc
, int idx
, u8
*addr
)
327 d11regs_t
*regs
= wlc
->regs
;
330 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc
), __func__
);
332 W_REG(®s
->objaddr
, (OBJADDR_RCMTA_SEL
| (idx
* 2)));
333 (void)R_REG(®s
->objaddr
);
334 v32
= R_REG(®s
->objdata
);
336 addr
[1] = (u8
) (v32
>> 8);
337 addr
[2] = (u8
) (v32
>> 16);
338 addr
[3] = (u8
) (v32
>> 24);
339 W_REG(®s
->objaddr
, (OBJADDR_RCMTA_SEL
| ((idx
* 2) + 1)));
340 (void)R_REG(®s
->objaddr
);
341 v32
= R_REG(®s
->objdata
);
343 addr
[5] = (u8
) (v32
>> 8);
345 #endif /* defined(BCMDBG) */
347 /* keep the chip awake if needed */
348 bool wlc_stay_awake(struct wlc_info
*wlc
)
353 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
355 bool wlc_ps_allowed(struct wlc_info
*wlc
)
358 struct wlc_bsscfg
*cfg
;
360 /* disallow PS when one of the following global conditions meets */
361 if (!wlc
->pub
->associated
|| !wlc
->PMenabled
|| wlc
->PM_override
)
364 /* disallow PS when one of these meets when not scanning */
365 if (!wlc
->PMblocked
) {
366 if (AP_ACTIVE(wlc
) || wlc
->monitor
)
370 FOREACH_AS_STA(wlc
, idx
, cfg
) {
371 /* disallow PS when one of the following bsscfg specific conditions meets */
372 if (!cfg
->BSS
|| !WLC_PORTOPEN(cfg
))
375 if (!cfg
->dtim_programmed
)
382 void wlc_reset(struct wlc_info
*wlc
)
384 WL_TRACE("wl%d: wlc_reset\n", wlc
->pub
->unit
);
386 wlc
->check_for_unaligned_tbtt
= false;
388 /* slurp up hw mac counters before core reset */
391 /* reset our snapshot of macstat counters */
392 memset((char *)wlc
->core
->macstat_snapshot
, 0,
395 wlc_bmac_reset(wlc
->hw
);
396 wlc_ampdu_reset(wlc
->ampdu
);
401 void wlc_fatal_error(struct wlc_info
*wlc
)
403 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc
->pub
->unit
);
407 /* Return the channel the driver should initialize during wlc_init.
408 * the channel may have to be changed from the currently configured channel
409 * if other configurations are in conflict (bandlocked, 11n mode disabled,
410 * invalid channel for current country, etc.)
412 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
)
414 chanspec_t chanspec
=
415 1 | WL_CHANSPEC_BW_20
| WL_CHANSPEC_CTL_SB_NONE
|
418 /* make sure the channel is on the supported band if we are band-restricted */
419 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
420 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
422 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
426 struct scb global_scb
;
428 static void wlc_init_scb(struct wlc_info
*wlc
, struct scb
*scb
)
431 scb
->flags
= SCB_WMECAP
| SCB_HTCAP
;
432 for (i
= 0; i
< NUMPRIO
; i
++)
436 void wlc_init(struct wlc_info
*wlc
)
441 struct wlc_bsscfg
*bsscfg
;
444 WL_TRACE("wl%d: wlc_init\n", wlc
->pub
->unit
);
448 /* This will happen if a big-hammer was executed. In that case, we want to go back
449 * to the channel that we were on and not new channel
451 if (wlc
->pub
->associated
)
452 chanspec
= wlc
->home_chanspec
;
454 chanspec
= wlc_init_chanspec(wlc
);
456 wlc_bmac_init(wlc
->hw
, chanspec
, mute
);
458 wlc
->seckeys
= wlc_bmac_read_shm(wlc
->hw
, M_SECRXKEYS_PTR
) * 2;
459 if (wlc
->machwcap
& MCAP_TKIPMIC
)
461 wlc_bmac_read_shm(wlc
->hw
, M_TKMICKEYS_PTR
) * 2;
463 /* update beacon listen interval */
466 (u8
) (wlc_bmac_read_shm(wlc
->hw
, M_NOSLPZNATDTIM
) >> 10);
467 ASSERT(wlc
->bcn_wait_prd
> 0);
469 /* the world is new again, so is our reported rate */
470 wlc_reprate_init(wlc
);
472 /* write ethernet address to core */
473 FOREACH_BSS(wlc
, i
, bsscfg
) {
475 wlc_set_bssid(bsscfg
);
478 /* Update tsf_cfprep if associated and up */
479 if (wlc
->pub
->associated
) {
480 FOREACH_BSS(wlc
, i
, bsscfg
) {
484 /* get beacon period and convert to uS */
485 bi
= bsscfg
->current_bss
->beacon_period
<< 10;
487 * update since init path would reset
490 W_REG(®s
->tsf_cfprep
,
491 (bi
<< CFPREP_CBI_SHIFT
));
493 /* Update maccontrol PM related bits */
494 wlc_set_ps_ctrl(wlc
);
501 wlc_key_hw_init_all(wlc
);
503 wlc_bandinit_ordered(wlc
, chanspec
);
505 wlc_init_scb(wlc
, &global_scb
);
507 /* init probe response timeout */
508 wlc_write_shm(wlc
, M_PRS_MAXTIME
, wlc
->prb_resp_timeout
);
510 /* init max burst txop (framebursting) */
511 wlc_write_shm(wlc
, M_MBURST_TXOP
,
513 _rifs
? (EDCF_AC_VO_TXOP_AP
<< 5) : MAXFRAMEBURST_TXOP
));
515 /* initialize maximum allowed duty cycle */
516 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_ofdm
, true, true);
517 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_cck
, false, true);
519 /* Update some shared memory locations related to max AMPDU size allowed to received */
520 wlc_ampdu_shm_upd(wlc
->ampdu
);
522 /* band-specific inits */
525 /* Enable EDCF mode (while the MAC is suspended) */
526 if (EDCF_ENAB(wlc
->pub
)) {
527 OR_REG(®s
->ifs_ctl
, IFS_USEEDCF
);
528 wlc_edcf_setparams(wlc
->cfg
, false);
531 /* Init precedence maps for empty FIFOs */
532 wlc_tx_prec_map_init(wlc
);
534 /* read the ucode version if we have not yet done so */
535 if (wlc
->ucode_rev
== 0) {
537 wlc_read_shm(wlc
, M_BOM_REV_MAJOR
) << NBITS(u16
);
538 wlc
->ucode_rev
|= wlc_read_shm(wlc
, M_BOM_REV_MINOR
);
541 /* ..now really unleash hell (allow the MAC out of suspend) */
544 /* clear tx flow control */
545 wlc_txflowcontrol_reset(wlc
);
547 /* clear tx data fifo suspends */
548 wlc
->tx_suspended
= false;
550 /* enable the RF Disable Delay timer */
551 W_REG(&wlc
->regs
->rfdisabledly
, RFDISABLE_DEFAULT
);
553 /* initialize mpc delay */
554 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
557 * Initialize WME parameters; if they haven't been set by some other
558 * mechanism (IOVar, etc) then read them from the hardware.
560 if (WLC_WME_RETRY_SHORT_GET(wlc
, 0) == 0) { /* Uninitialized; read from HW */
564 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
565 wlc
->wme_retries
[ac
] =
566 wlc_read_shm(wlc
, M_AC_TXLMT_ADDR(ac
));
571 void wlc_mac_bcn_promisc_change(struct wlc_info
*wlc
, bool promisc
)
573 wlc
->bcnmisc_monitor
= promisc
;
574 wlc_mac_bcn_promisc(wlc
);
577 void wlc_mac_bcn_promisc(struct wlc_info
*wlc
)
579 if ((AP_ENAB(wlc
->pub
) && (N_ENAB(wlc
->pub
) || wlc
->band
->gmode
)) ||
580 wlc
->bcnmisc_ibss
|| wlc
->bcnmisc_scan
|| wlc
->bcnmisc_monitor
)
581 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, MCTL_BCNS_PROMISC
);
583 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, 0);
586 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
587 void wlc_mac_promisc(struct wlc_info
*wlc
)
589 u32 promisc_bits
= 0;
591 /* promiscuous mode just sets MCTL_PROMISC
592 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
593 * since all BSS data traffic is directed at the AP
595 if (PROMISC_ENAB(wlc
->pub
) && !AP_ENAB(wlc
->pub
) && !wlc
->wet
)
596 promisc_bits
|= MCTL_PROMISC
;
598 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
599 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
600 * handled in wlc_mac_bcn_promisc()
602 if (MONITOR_ENAB(wlc
))
603 promisc_bits
|= MCTL_PROMISC
| MCTL_KEEPCONTROL
;
605 wlc_mctrl(wlc
, MCTL_PROMISC
| MCTL_KEEPCONTROL
, promisc_bits
);
608 /* check if hps and wake states of sw and hw are in sync */
609 bool wlc_ps_check(struct wlc_info
*wlc
)
615 if (!AP_ACTIVE(wlc
)) {
617 tmp
= R_REG(&wlc
->regs
->maccontrol
);
620 * If deviceremoved is detected, then don't take any action as
621 * this can be called in any context. Assume that caller will
622 * take care of the condition. This is just to avoid assert
624 if (tmp
== 0xffffffff) {
625 WL_ERROR("wl%d: %s: dead chip\n",
626 wlc
->pub
->unit
, __func__
);
627 return DEVICEREMOVED(wlc
);
630 hps
= PS_ALLOWED(wlc
);
632 if (hps
!= ((tmp
& MCTL_HPS
) != 0)) {
634 struct wlc_bsscfg
*cfg
;
635 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
636 wlc
->pub
->unit
, hps
, tmp
);
637 FOREACH_BSS(wlc
, idx
, cfg
) {
638 if (!BSSCFG_STA(cfg
))
644 /* For a monolithic build the wake check can be exact since it looks at wake
645 * override bits. The MCTL_WAKE bit should match the 'wake' value.
647 wake
= STAY_AWAKE(wlc
) || wlc
->hw
->wake_override
;
648 wake_ok
= (wake
== ((tmp
& MCTL_WAKE
) != 0));
649 if (hps
&& !wake_ok
) {
650 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
651 wlc
->pub
->unit
, wake
, tmp
);
659 /* push sw hps and wake state through hardware */
660 void wlc_set_ps_ctrl(struct wlc_info
*wlc
)
666 hps
= PS_ALLOWED(wlc
);
667 wake
= hps
? (STAY_AWAKE(wlc
)) : true;
669 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
670 wlc
->pub
->unit
, hps
, wake
);
672 v1
= R_REG(&wlc
->regs
->maccontrol
);
679 wlc_mctrl(wlc
, MCTL_WAKE
| MCTL_HPS
, v2
);
681 awake_before
= ((v1
& MCTL_WAKE
) || ((v1
& MCTL_HPS
) == 0));
683 if (wake
&& !awake_before
)
684 wlc_bmac_wait_for_wake(wlc
->hw
);
689 * Write this BSS config's MAC address to core.
690 * Updates RXE match engine.
692 int wlc_set_mac(struct wlc_bsscfg
*cfg
)
695 struct wlc_info
*wlc
= cfg
->wlc
;
697 if (cfg
== wlc
->cfg
) {
698 /* enter the MAC addr into the RXE match registers */
699 wlc_set_addrmatch(wlc
, RCM_MAC_OFFSET
, cfg
->cur_etheraddr
);
702 wlc_ampdu_macaddr_upd(wlc
);
707 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
708 * Updates RXE match engine.
710 void wlc_set_bssid(struct wlc_bsscfg
*cfg
)
712 struct wlc_info
*wlc
= cfg
->wlc
;
714 /* if primary config, we need to update BSSID in RXE match registers */
715 if (cfg
== wlc
->cfg
) {
716 wlc_set_addrmatch(wlc
, RCM_BSSID_OFFSET
, cfg
->BSSID
);
718 #ifdef SUPPORT_HWKEYS
719 else if (BSSCFG_STA(cfg
) && cfg
->BSS
) {
720 wlc_rcmta_add_bssid(wlc
, cfg
);
726 * Suspend the the MAC and update the slot timing
727 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
729 void wlc_switch_shortslot(struct wlc_info
*wlc
, bool shortslot
)
732 struct wlc_bsscfg
*cfg
;
734 ASSERT(wlc
->band
->gmode
);
736 /* use the override if it is set */
737 if (wlc
->shortslot_override
!= WLC_SHORTSLOT_AUTO
)
738 shortslot
= (wlc
->shortslot_override
== WLC_SHORTSLOT_ON
);
740 if (wlc
->shortslot
== shortslot
)
743 wlc
->shortslot
= shortslot
;
745 /* update the capability based on current shortslot mode */
746 FOREACH_BSS(wlc
, idx
, cfg
) {
747 if (!cfg
->associated
)
749 cfg
->current_bss
->capability
&=
750 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
752 cfg
->current_bss
->capability
|=
753 WLAN_CAPABILITY_SHORT_SLOT_TIME
;
756 wlc_bmac_set_shortslot(wlc
->hw
, shortslot
);
759 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
)
764 local
= WLC_TXPWR_MAX
;
765 if (wlc
->pub
->associated
&&
766 (wf_chspec_ctlchan(wlc
->chanspec
) ==
767 wf_chspec_ctlchan(wlc
->home_chanspec
))) {
769 /* get the local power constraint if we are on the AP's
770 * channel [802.11h, 7.3.2.13]
772 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
774 (wlc
->txpwr_local_max
-
775 wlc
->txpwr_local_constraint
) * WLC_TXPWR_DB_FACTOR
;
776 if (local_max
> 0 && local_max
< WLC_TXPWR_MAX
)
777 return (u8
) local_max
;
785 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
786 void wlc_set_home_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
788 if (wlc
->home_chanspec
!= chanspec
) {
790 struct wlc_bsscfg
*cfg
;
792 wlc
->home_chanspec
= chanspec
;
794 FOREACH_BSS(wlc
, idx
, cfg
) {
795 if (!cfg
->associated
)
798 cfg
->current_bss
->chanspec
= chanspec
;
804 static void wlc_set_phy_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
806 /* Save our copy of the chanspec */
807 wlc
->chanspec
= chanspec
;
809 /* Set the chanspec and power limits for this locale after computing
810 * any 11h local tx power constraints.
812 wlc_channel_set_chanspec(wlc
->cmi
, chanspec
,
813 wlc_local_constraint_qdbm(wlc
));
815 if (wlc
->stf
->ss_algosel_auto
)
816 wlc_stf_ss_algo_channel_get(wlc
, &wlc
->stf
->ss_algo_channel
,
819 wlc_stf_ss_update(wlc
, wlc
->band
);
823 void wlc_set_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
826 bool switchband
= false;
827 chanspec_t old_chanspec
= wlc
->chanspec
;
829 if (!wlc_valid_chanspec_db(wlc
->cmi
, chanspec
)) {
830 WL_ERROR("wl%d: %s: Bad channel %d\n",
831 wlc
->pub
->unit
, __func__
, CHSPEC_CHANNEL(chanspec
));
832 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
836 /* Switch bands if necessary */
837 if (NBANDS(wlc
) > 1) {
838 bandunit
= CHSPEC_WLCBANDUNIT(chanspec
);
839 if (wlc
->band
->bandunit
!= bandunit
|| wlc
->bandinit_pending
) {
841 if (wlc
->bandlocked
) {
842 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
843 wlc
->pub
->unit
, __func__
,
844 CHSPEC_CHANNEL(chanspec
));
847 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
848 * if the setband updates (wlc_bsinit) use low level calls to inspect and
849 * set state, the state inspected may be from the wrong band, or the
850 * following wlc_bmac_set_chanspec() may undo the work.
852 wlc_setband(wlc
, bandunit
);
856 ASSERT(N_ENAB(wlc
->pub
) || !CHSPEC_IS40(chanspec
));
858 /* sync up phy/radio chanspec */
859 wlc_set_phy_chanspec(wlc
, chanspec
);
861 /* init antenna selection */
862 if (CHSPEC_WLC_BW(old_chanspec
) != CHSPEC_WLC_BW(chanspec
)) {
863 wlc_antsel_init(wlc
->asi
);
865 /* Fix the hardware rateset based on bw.
866 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
868 wlc_rateset_bw_mcs_filter(&wlc
->band
->hw_rateset
,
870 mimo_cap_40
? CHSPEC_WLC_BW(chanspec
)
874 /* update some mac configuration since chanspec changed */
875 wlc_ucode_mac_upd(wlc
);
879 static int wlc_get_current_txpwr(struct wlc_info
*wlc
, void *pwr
, uint len
)
881 txpwr_limits_t txpwr
;
883 tx_power_legacy_t
*old_power
= NULL
;
888 if (len
== sizeof(tx_power_legacy_t
))
889 old_power
= (tx_power_legacy_t
*) pwr
;
890 else if (len
< sizeof(tx_power_t
))
891 return BCME_BUFTOOSHORT
;
893 memset(&power
, 0, sizeof(tx_power_t
));
895 power
.chanspec
= WLC_BAND_PI_RADIO_CHANSPEC
;
896 if (wlc
->pub
->associated
)
897 power
.local_chanspec
= wlc
->home_chanspec
;
899 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
900 * public interface only implements getting and setting a single value for all of
901 * rates, so we need to fill the array ourselves.
903 wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
, &override
);
904 for (r
= 0; r
< WL_TX_POWER_RATES
; r
++) {
905 power
.user_limit
[r
] = (u8
) qdbm
;
908 power
.local_max
= wlc
->txpwr_local_max
* WLC_TXPWR_DB_FACTOR
;
909 power
.local_constraint
=
910 wlc
->txpwr_local_constraint
* WLC_TXPWR_DB_FACTOR
;
912 power
.antgain
[0] = wlc
->bandstate
[BAND_2G_INDEX
]->antgain
;
913 power
.antgain
[1] = wlc
->bandstate
[BAND_5G_INDEX
]->antgain
;
915 wlc_channel_reg_limits(wlc
->cmi
, power
.chanspec
, &txpwr
);
917 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
918 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
921 /* CCK tx power limits */
922 for (c
= 0, r
= WL_TX_POWER_CCK_FIRST
; c
< WL_TX_POWER_CCK_NUM
;
924 power
.reg_limit
[r
] = txpwr
.cck
[c
];
926 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
927 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
930 /* 20 MHz OFDM SISO tx power limits */
931 for (c
= 0, r
= WL_TX_POWER_OFDM_FIRST
; c
< WL_TX_POWER_OFDM_NUM
;
933 power
.reg_limit
[r
] = txpwr
.ofdm
[c
];
935 if (WLC_PHY_11N_CAP(wlc
->band
)) {
937 /* 20 MHz OFDM CDD tx power limits */
938 for (c
= 0, r
= WL_TX_POWER_OFDM20_CDD_FIRST
;
939 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
940 power
.reg_limit
[r
] = txpwr
.ofdm_cdd
[c
];
942 /* 40 MHz OFDM SISO tx power limits */
943 for (c
= 0, r
= WL_TX_POWER_OFDM40_SISO_FIRST
;
944 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
945 power
.reg_limit
[r
] = txpwr
.ofdm_40_siso
[c
];
947 /* 40 MHz OFDM CDD tx power limits */
948 for (c
= 0, r
= WL_TX_POWER_OFDM40_CDD_FIRST
;
949 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
950 power
.reg_limit
[r
] = txpwr
.ofdm_40_cdd
[c
];
952 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
953 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
956 /* 20MHz MCS0-7 SISO tx power limits */
957 for (c
= 0, r
= WL_TX_POWER_MCS20_SISO_FIRST
;
958 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
959 power
.reg_limit
[r
] = txpwr
.mcs_20_siso
[c
];
961 /* 20MHz MCS0-7 CDD tx power limits */
962 for (c
= 0, r
= WL_TX_POWER_MCS20_CDD_FIRST
;
963 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
964 power
.reg_limit
[r
] = txpwr
.mcs_20_cdd
[c
];
966 /* 20MHz MCS0-7 STBC tx power limits */
967 for (c
= 0, r
= WL_TX_POWER_MCS20_STBC_FIRST
;
968 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
969 power
.reg_limit
[r
] = txpwr
.mcs_20_stbc
[c
];
971 /* 40MHz MCS0-7 SISO tx power limits */
972 for (c
= 0, r
= WL_TX_POWER_MCS40_SISO_FIRST
;
973 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
974 power
.reg_limit
[r
] = txpwr
.mcs_40_siso
[c
];
976 /* 40MHz MCS0-7 CDD tx power limits */
977 for (c
= 0, r
= WL_TX_POWER_MCS40_CDD_FIRST
;
978 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
979 power
.reg_limit
[r
] = txpwr
.mcs_40_cdd
[c
];
981 /* 40MHz MCS0-7 STBC tx power limits */
982 for (c
= 0, r
= WL_TX_POWER_MCS40_STBC_FIRST
;
983 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
984 power
.reg_limit
[r
] = txpwr
.mcs_40_stbc
[c
];
986 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
987 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
990 /* 20MHz MCS8-15 SDM tx power limits */
991 for (c
= 0, r
= WL_TX_POWER_MCS20_SDM_FIRST
;
992 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
993 power
.reg_limit
[r
] = txpwr
.mcs_20_mimo
[c
];
995 /* 40MHz MCS8-15 SDM tx power limits */
996 for (c
= 0, r
= WL_TX_POWER_MCS40_SDM_FIRST
;
997 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
998 power
.reg_limit
[r
] = txpwr
.mcs_40_mimo
[c
];
1001 power
.reg_limit
[WL_TX_POWER_MCS_32
] = txpwr
.mcs32
;
1004 wlc_phy_txpower_get_current(wlc
->band
->pi
, &power
,
1005 CHSPEC_CHANNEL(power
.chanspec
));
1007 /* copy the tx_power_t struct to the return buffer,
1008 * or convert to a tx_power_legacy_t struct
1011 memcpy(pwr
, &power
, sizeof(tx_power_t
));
1013 int band_idx
= CHSPEC_IS2G(power
.chanspec
) ? 0 : 1;
1015 memset(old_power
, 0, sizeof(tx_power_legacy_t
));
1017 old_power
->txpwr_local_max
= power
.local_max
;
1018 old_power
->txpwr_local_constraint
= power
.local_constraint
;
1019 if (CHSPEC_IS2G(power
.chanspec
)) {
1020 old_power
->txpwr_chan_reg_max
= txpwr
.cck
[0];
1021 old_power
->txpwr_est_Pout
[band_idx
] =
1023 old_power
->txpwr_est_Pout_gofdm
= power
.est_Pout
[0];
1025 old_power
->txpwr_chan_reg_max
= txpwr
.ofdm
[0];
1026 old_power
->txpwr_est_Pout
[band_idx
] = power
.est_Pout
[0];
1028 old_power
->txpwr_antgain
[0] = power
.antgain
[0];
1029 old_power
->txpwr_antgain
[1] = power
.antgain
[1];
1031 for (r
= 0; r
< NUM_PWRCTRL_RATES
; r
++) {
1032 old_power
->txpwr_band_max
[r
] = power
.user_limit
[r
];
1033 old_power
->txpwr_limit
[r
] = power
.reg_limit
[r
];
1034 old_power
->txpwr_target
[band_idx
][r
] = power
.target
[r
];
1035 if (CHSPEC_IS2G(power
.chanspec
))
1036 old_power
->txpwr_bphy_cck_max
[r
] =
1037 power
.board_limit
[r
];
1039 old_power
->txpwr_aphy_max
[r
] =
1040 power
.board_limit
[r
];
1046 #endif /* defined(BCMDBG) */
1048 static u32
wlc_watchdog_backup_bi(struct wlc_info
*wlc
)
1051 bi
= 2 * wlc
->cfg
->current_bss
->dtim_period
*
1052 wlc
->cfg
->current_bss
->beacon_period
;
1053 if (wlc
->bcn_li_dtim
)
1054 bi
*= wlc
->bcn_li_dtim
;
1055 else if (wlc
->bcn_li_bcn
)
1056 /* recalculate bi based on bcn_li_bcn */
1057 bi
= 2 * wlc
->bcn_li_bcn
* wlc
->cfg
->current_bss
->beacon_period
;
1059 if (bi
< 2 * TIMER_INTERVAL_WATCHDOG
)
1060 bi
= 2 * TIMER_INTERVAL_WATCHDOG
;
1064 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1065 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1067 void wlc_watchdog_upd(struct wlc_info
*wlc
, bool tbtt
)
1069 /* make sure changing watchdog driver is allowed */
1070 if (!wlc
->pub
->up
|| !wlc
->pub
->align_wd_tbtt
)
1072 if (!tbtt
&& wlc
->WDarmed
) {
1073 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1074 wlc
->WDarmed
= false;
1077 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1078 if (tbtt
&& wlc
->WDarmed
) {
1079 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1080 wlc
->WDarmed
= false;
1081 wlc
->WDlast
= OSL_SYSUPTIME();
1083 /* arm watchdog timer and drive the watchdog there */
1084 else if (!tbtt
&& !wlc
->WDarmed
) {
1085 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
1087 wlc
->WDarmed
= true;
1089 if (tbtt
&& !wlc
->WDarmed
) {
1090 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, wlc_watchdog_backup_bi(wlc
),
1092 wlc
->WDarmed
= true;
1096 ratespec_t
wlc_lowest_basic_rspec(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
1098 ratespec_t lowest_basic_rspec
;
1101 /* Use the lowest basic rate */
1102 lowest_basic_rspec
= rs
->rates
[0] & RATE_MASK
;
1103 for (i
= 0; i
< rs
->count
; i
++) {
1104 if (rs
->rates
[i
] & WLC_RATE_FLAG
) {
1105 lowest_basic_rspec
= rs
->rates
[i
] & RATE_MASK
;
1110 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1111 if (IS_OFDM(lowest_basic_rspec
)) {
1112 lowest_basic_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
1116 return lowest_basic_rspec
;
1119 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1120 * setting as per this table:
1121 * ratespec CCK ant = wlc->stf->txant
1124 void wlc_beacon_phytxctl_txant_upd(struct wlc_info
*wlc
, ratespec_t bcn_rspec
)
1127 u16 phytxant
= wlc
->stf
->phytxant
;
1128 u16 mask
= PHY_TXC_ANT_MASK
;
1130 /* for non-siso rates or default setting, use the available chains */
1131 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1132 phytxant
= wlc_stf_phytxchain_sel(wlc
, bcn_rspec
);
1135 phyctl
= wlc_read_shm(wlc
, M_BCN_PCTLWD
);
1136 phyctl
= (phyctl
& ~mask
) | phytxant
;
1137 wlc_write_shm(wlc
, M_BCN_PCTLWD
, phyctl
);
1140 /* centralized protection config change function to simplify debugging, no consistency checking
1141 * this should be called only on changes to avoid overhead in periodic function
1143 void wlc_protection_upd(struct wlc_info
*wlc
, uint idx
, int val
)
1145 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx
, val
);
1148 case WLC_PROT_G_SPEC
:
1149 wlc
->protection
->_g
= (bool) val
;
1151 case WLC_PROT_G_OVR
:
1152 wlc
->protection
->g_override
= (s8
) val
;
1154 case WLC_PROT_G_USER
:
1155 wlc
->protection
->gmode_user
= (u8
) val
;
1157 case WLC_PROT_OVERLAP
:
1158 wlc
->protection
->overlap
= (s8
) val
;
1160 case WLC_PROT_N_USER
:
1161 wlc
->protection
->nmode_user
= (s8
) val
;
1163 case WLC_PROT_N_CFG
:
1164 wlc
->protection
->n_cfg
= (s8
) val
;
1166 case WLC_PROT_N_CFG_OVR
:
1167 wlc
->protection
->n_cfg_override
= (s8
) val
;
1169 case WLC_PROT_N_NONGF
:
1170 wlc
->protection
->nongf
= (bool) val
;
1172 case WLC_PROT_N_NONGF_OVR
:
1173 wlc
->protection
->nongf_override
= (s8
) val
;
1175 case WLC_PROT_N_PAM_OVR
:
1176 wlc
->protection
->n_pam_override
= (s8
) val
;
1178 case WLC_PROT_N_OBSS
:
1179 wlc
->protection
->n_obss
= (bool) val
;
1189 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
)
1191 wlc
->ht_cap
.cap_info
&= ~(IEEE80211_HT_CAP_SGI_20
|
1192 IEEE80211_HT_CAP_SGI_40
);
1193 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_20
) ?
1194 IEEE80211_HT_CAP_SGI_20
: 0;
1195 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_40
) ?
1196 IEEE80211_HT_CAP_SGI_40
: 0;
1199 wlc_update_beacon(wlc
);
1200 wlc_update_probe_resp(wlc
, true);
1204 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
)
1206 wlc
->stf
->ldpc
= val
;
1208 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_LDPC_CODING
;
1209 if (wlc
->stf
->ldpc
!= OFF
)
1210 wlc
->ht_cap
.cap_info
|= IEEE80211_HT_CAP_LDPC_CODING
;
1213 wlc_update_beacon(wlc
);
1214 wlc_update_probe_resp(wlc
, true);
1215 wlc_phy_ldpc_override_set(wlc
->band
->pi
, (val
? true : false));
1220 * ucode, hwmac update
1221 * Channel dependent updates for ucode and hw
1223 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
)
1225 /* enable or disable any active IBSSs depending on whether or not
1226 * we are on the home channel
1228 if (wlc
->home_chanspec
== WLC_BAND_PI_RADIO_CHANSPEC
) {
1229 if (wlc
->pub
->associated
) {
1230 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1231 * I think that the ucode inits set up the bcn templates and shm values
1232 * with a bogus beacon. This should not be done in the inits. If ucode needs
1233 * to set up a beacon for testing, the test routines should write it down,
1234 * not expect the inits to populate a bogus beacon.
1236 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1237 wlc_write_shm(wlc
, M_BCN_TXTSF_OFFSET
,
1238 wlc
->band
->bcntsfoff
);
1242 /* disable an active IBSS if we are not on the home channel */
1245 /* update the various promisc bits */
1246 wlc_mac_bcn_promisc(wlc
);
1247 wlc_mac_promisc(wlc
);
1250 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
)
1252 wlc_rateset_t default_rateset
;
1254 uint i
, band_order
[2];
1256 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc
->pub
->unit
);
1258 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1259 * figure out the right band to park on
1261 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
1262 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
1264 parkband
= wlc
->band
->bandunit
; /* updated in wlc_bandlock() */
1265 band_order
[0] = band_order
[1] = parkband
;
1267 /* park on the band of the specified chanspec */
1268 parkband
= CHSPEC_WLCBANDUNIT(chanspec
);
1270 /* order so that parkband initialize last */
1271 band_order
[0] = parkband
^ 1;
1272 band_order
[1] = parkband
;
1275 /* make each band operational, software state init */
1276 for (i
= 0; i
< NBANDS(wlc
); i
++) {
1277 uint j
= band_order
[i
];
1279 wlc
->band
= wlc
->bandstate
[j
];
1281 wlc_default_rateset(wlc
, &default_rateset
);
1283 /* fill in hw_rate */
1284 wlc_rateset_filter(&default_rateset
, &wlc
->band
->hw_rateset
,
1285 false, WLC_RATES_CCK_OFDM
, RATE_MASK
,
1286 (bool) N_ENAB(wlc
->pub
));
1288 /* init basic rate lookup */
1289 wlc_rate_lookup_init(wlc
, &default_rateset
);
1292 /* sync up phy/radio chanspec */
1293 wlc_set_phy_chanspec(wlc
, chanspec
);
1296 /* band-specific init */
1297 static void WLBANDINITFN(wlc_bsinit
) (struct wlc_info
*wlc
)
1299 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1300 wlc
->pub
->unit
, wlc
->band
->bandunit
);
1302 /* write ucode ACK/CTS rate table */
1303 wlc_set_ratetable(wlc
);
1305 /* update some band specific mac configuration */
1306 wlc_ucode_mac_upd(wlc
);
1308 /* init antenna selection */
1309 wlc_antsel_init(wlc
->asi
);
1313 /* switch to and initialize new band */
1314 static void WLBANDINITFN(wlc_setband
) (struct wlc_info
*wlc
, uint bandunit
)
1317 struct wlc_bsscfg
*cfg
;
1319 ASSERT(NBANDS(wlc
) > 1);
1320 ASSERT(!wlc
->bandlocked
);
1321 ASSERT(bandunit
!= wlc
->band
->bandunit
|| wlc
->bandinit_pending
);
1323 wlc
->band
= wlc
->bandstate
[bandunit
];
1328 /* wait for at least one beacon before entering sleeping state */
1329 wlc
->PMawakebcn
= true;
1330 FOREACH_AS_STA(wlc
, idx
, cfg
)
1331 cfg
->PMawakebcn
= true;
1332 wlc_set_ps_ctrl(wlc
);
1334 /* band-specific initializations */
1338 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1339 void wlc_wme_initparams_sta(struct wlc_info
*wlc
, wme_param_ie_t
*pe
)
1341 static const wme_param_ie_t stadef
= {
1344 WME_SUBTYPE_PARAM_IE
,
1349 {EDCF_AC_BE_ACI_STA
, EDCF_AC_BE_ECW_STA
,
1350 cpu_to_le16(EDCF_AC_BE_TXOP_STA
)},
1351 {EDCF_AC_BK_ACI_STA
, EDCF_AC_BK_ECW_STA
,
1352 cpu_to_le16(EDCF_AC_BK_TXOP_STA
)},
1353 {EDCF_AC_VI_ACI_STA
, EDCF_AC_VI_ECW_STA
,
1354 cpu_to_le16(EDCF_AC_VI_TXOP_STA
)},
1355 {EDCF_AC_VO_ACI_STA
, EDCF_AC_VO_ECW_STA
,
1356 cpu_to_le16(EDCF_AC_VO_TXOP_STA
)}
1360 ASSERT(sizeof(*pe
) == WME_PARAM_IE_LEN
);
1361 memcpy(pe
, &stadef
, sizeof(*pe
));
1364 void wlc_wme_setparams(struct wlc_info
*wlc
, u16 aci
, void *arg
, bool suspend
)
1367 shm_acparams_t acp_shm
;
1369 struct ieee80211_tx_queue_params
*params
= arg
;
1373 /* Only apply params if the core is out of reset and has clocks */
1375 WL_ERROR("wl%d: %s : no-clock\n", wlc
->pub
->unit
, __func__
);
1380 * AP uses AC params from wme_param_ie_ap.
1381 * AP advertises AC params from wme_param_ie.
1382 * STA uses AC params from wme_param_ie.
1385 wlc
->wme_admctl
= 0;
1388 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1389 /* find out which ac this set of params applies to */
1390 ASSERT(aci
< AC_COUNT
);
1391 /* set the admission control policy for this AC */
1392 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1394 /* fill in shm ac params struct */
1395 acp_shm
.txop
= le16_to_cpu(params
->txop
);
1396 /* convert from units of 32us to us for ucode */
1397 wlc
->edcf_txop
[aci
& 0x3] = acp_shm
.txop
=
1398 EDCF_TXOP2USEC(acp_shm
.txop
);
1399 acp_shm
.aifs
= (params
->aifs
& EDCF_AIFSN_MASK
);
1401 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1402 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1405 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1406 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1407 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1408 wlc
->pub
->unit
, acp_shm
.aifs
);
1412 acp_shm
.cwmin
= params
->cw_min
;
1413 acp_shm
.cwmax
= params
->cw_max
;
1414 acp_shm
.cwcur
= acp_shm
.cwmin
;
1416 R_REG(&wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1417 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1418 /* Indicate the new params to the ucode */
1419 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1420 wme_shmemacindex(aci
) *
1422 M_EDCF_STATUS_OFF
));
1423 acp_shm
.status
|= WME_STATUS_NEWAC
;
1425 /* Fill in shm acparam table */
1426 shm_entry
= (u16
*) &acp_shm
;
1427 for (i
= 0; i
< (int)sizeof(shm_acparams_t
); i
+= 2)
1430 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ i
,
1436 wlc_suspend_mac_and_wait(wlc
);
1439 wlc_enable_mac(wlc
);
1443 void wlc_edcf_setparams(struct wlc_bsscfg
*cfg
, bool suspend
)
1445 struct wlc_info
*wlc
= cfg
->wlc
;
1447 edcf_acparam_t
*edcf_acp
;
1448 shm_acparams_t acp_shm
;
1454 /* Only apply params if the core is out of reset and has clocks */
1459 * AP uses AC params from wme_param_ie_ap.
1460 * AP advertises AC params from wme_param_ie.
1461 * STA uses AC params from wme_param_ie.
1464 edcf_acp
= (edcf_acparam_t
*) &wlc
->wme_param_ie
.acparam
[0];
1466 wlc
->wme_admctl
= 0;
1468 for (i
= 0; i
< AC_COUNT
; i
++, edcf_acp
++) {
1469 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1470 /* find out which ac this set of params applies to */
1471 aci
= (edcf_acp
->ACI
& EDCF_ACI_MASK
) >> EDCF_ACI_SHIFT
;
1472 ASSERT(aci
< AC_COUNT
);
1473 /* set the admission control policy for this AC */
1474 if (edcf_acp
->ACI
& EDCF_ACM_MASK
) {
1475 wlc
->wme_admctl
|= 1 << aci
;
1478 /* fill in shm ac params struct */
1479 acp_shm
.txop
= le16_to_cpu(edcf_acp
->TXOP
);
1480 /* convert from units of 32us to us for ucode */
1481 wlc
->edcf_txop
[aci
] = acp_shm
.txop
=
1482 EDCF_TXOP2USEC(acp_shm
.txop
);
1483 acp_shm
.aifs
= (edcf_acp
->ACI
& EDCF_AIFSN_MASK
);
1485 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1486 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1489 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1490 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1491 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1492 wlc
->pub
->unit
, acp_shm
.aifs
);
1496 /* CWmin = 2^(ECWmin) - 1 */
1497 acp_shm
.cwmin
= EDCF_ECW2CW(edcf_acp
->ECW
& EDCF_ECWMIN_MASK
);
1498 /* CWmax = 2^(ECWmax) - 1 */
1499 acp_shm
.cwmax
= EDCF_ECW2CW((edcf_acp
->ECW
& EDCF_ECWMAX_MASK
)
1500 >> EDCF_ECWMAX_SHIFT
);
1501 acp_shm
.cwcur
= acp_shm
.cwmin
;
1503 R_REG(&wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1504 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1505 /* Indicate the new params to the ucode */
1506 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1507 wme_shmemacindex(aci
) *
1509 M_EDCF_STATUS_OFF
));
1510 acp_shm
.status
|= WME_STATUS_NEWAC
;
1512 /* Fill in shm acparam table */
1513 shm_entry
= (u16
*) &acp_shm
;
1514 for (j
= 0; j
< (int)sizeof(shm_acparams_t
); j
+= 2)
1517 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ j
,
1522 wlc_suspend_mac_and_wait(wlc
);
1524 if (AP_ENAB(wlc
->pub
) && WME_ENAB(wlc
->pub
)) {
1525 wlc_update_beacon(wlc
);
1526 wlc_update_probe_resp(wlc
, false);
1530 wlc_enable_mac(wlc
);
1534 bool wlc_timers_init(struct wlc_info
*wlc
, int unit
)
1536 wlc
->wdtimer
= wl_init_timer(wlc
->wl
, wlc_watchdog_by_timer
,
1538 if (!wlc
->wdtimer
) {
1539 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit
);
1543 wlc
->radio_timer
= wl_init_timer(wlc
->wl
, wlc_radio_timer
,
1545 if (!wlc
->radio_timer
) {
1546 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit
);
1557 * Initialize wlc_info default values ...
1558 * may get overrides later in this function
1560 void wlc_info_init(struct wlc_info
*wlc
, int unit
)
1563 /* Assume the device is there until proven otherwise */
1564 wlc
->device_present
= true;
1566 /* set default power output percentage to 100 percent */
1567 wlc
->txpwr_percent
= 100;
1569 /* Save our copy of the chanspec */
1570 wlc
->chanspec
= CH20MHZ_CHSPEC(1);
1572 /* initialize CCK preamble mode to unassociated state */
1573 wlc
->shortpreamble
= false;
1575 wlc
->legacy_probe
= true;
1577 /* various 802.11g modes */
1578 wlc
->shortslot
= false;
1579 wlc
->shortslot_override
= WLC_SHORTSLOT_AUTO
;
1581 wlc
->barker_overlap_control
= true;
1582 wlc
->barker_preamble
= WLC_BARKER_SHORT_ALLOWED
;
1583 wlc
->txburst_limit_override
= AUTO
;
1585 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, WLC_PROTECTION_AUTO
);
1586 wlc_protection_upd(wlc
, WLC_PROT_G_SPEC
, false);
1588 wlc_protection_upd(wlc
, WLC_PROT_N_CFG_OVR
, WLC_PROTECTION_AUTO
);
1589 wlc_protection_upd(wlc
, WLC_PROT_N_CFG
, WLC_N_PROTECTION_OFF
);
1590 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF_OVR
, WLC_PROTECTION_AUTO
);
1591 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF
, false);
1592 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
, AUTO
);
1594 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, WLC_PROTECTION_CTL_OVERLAP
);
1596 /* 802.11g draft 4.0 NonERP elt advertisement */
1597 wlc
->include_legacy_erp
= true;
1599 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_DEF
;
1600 wlc
->stf
->txant
= ANT_TX_DEF
;
1602 wlc
->prb_resp_timeout
= WLC_PRB_RESP_TIMEOUT
;
1604 wlc
->usr_fragthresh
= DOT11_DEFAULT_FRAG_LEN
;
1605 for (i
= 0; i
< NFIFO
; i
++)
1606 wlc
->fragthresh
[i
] = DOT11_DEFAULT_FRAG_LEN
;
1607 wlc
->RTSThresh
= DOT11_DEFAULT_RTS_LEN
;
1609 /* default rate fallback retry limits */
1610 wlc
->SFBL
= RETRY_SHORT_FB
;
1611 wlc
->LFBL
= RETRY_LONG_FB
;
1613 /* default mac retry limits */
1614 wlc
->SRL
= RETRY_SHORT_DEF
;
1615 wlc
->LRL
= RETRY_LONG_DEF
;
1618 wlc
->PM
= PM_OFF
; /* User's setting of PM mode through IOCTL */
1619 wlc
->PM_override
= false; /* Prevents from going to PM if our AP is 'ill' */
1620 wlc
->PMenabled
= false; /* Current PM state */
1621 wlc
->PMpending
= false; /* Tracks whether STA indicated PM in the last attempt */
1622 wlc
->PMblocked
= false; /* To allow blocking going into PM during RM and scans */
1624 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1625 wlc
->WME_PM_blocked
= false;
1627 /* Init wme queuing method */
1628 wlc
->wme_prec_queuing
= false;
1630 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1632 /* Are we waiting for a response to PS-Poll that we sent */
1633 wlc
->PSpoll
= false;
1636 wlc
->wme_apsd
= true;
1637 wlc
->apsd_sta_usp
= false;
1638 wlc
->apsd_trigger_timeout
= 0; /* disable the trigger timer */
1639 wlc
->apsd_trigger_ac
= AC_BITMAP_ALL
;
1641 /* Set flag to indicate that hw keys should be used when available. */
1642 wlc
->wsec_swkeys
= false;
1644 /* init the 4 static WEP default keys */
1645 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
1646 wlc
->wsec_keys
[i
] = wlc
->wsec_def_keys
[i
];
1647 wlc
->wsec_keys
[i
]->idx
= (u8
) i
;
1650 wlc
->_regulatory_domain
= false; /* 802.11d */
1652 /* WME QoS mode is Auto by default */
1653 wlc
->pub
->_wme
= AUTO
;
1655 #ifdef BCMSDIODEV_ENABLED
1656 wlc
->pub
->_priofc
= true; /* enable priority flow control for sdio dongle */
1659 wlc
->pub
->_ampdu
= AMPDU_AGG_HOST
;
1660 wlc
->pub
->bcmerror
= 0;
1661 wlc
->ibss_allowed
= true;
1662 wlc
->ibss_coalesce_allowed
= true;
1663 wlc
->pub
->_coex
= ON
;
1665 /* initialize mpc delay */
1666 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
1668 wlc
->pr80838_war
= true;
1671 static bool wlc_state_bmac_sync(struct wlc_info
*wlc
)
1673 wlc_bmac_state_t state_bmac
;
1675 if (wlc_bmac_state_get(wlc
->hw
, &state_bmac
) != 0)
1678 wlc
->machwcap
= state_bmac
.machwcap
;
1679 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
,
1680 (s8
) state_bmac
.preamble_ovr
);
1685 static uint
wlc_attach_module(struct wlc_info
*wlc
)
1689 unit
= wlc
->pub
->unit
;
1691 wlc
->asi
= wlc_antsel_attach(wlc
);
1692 if (wlc
->asi
== NULL
) {
1693 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit
);
1698 wlc
->ampdu
= wlc_ampdu_attach(wlc
);
1699 if (wlc
->ampdu
== NULL
) {
1700 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit
);
1705 if ((wlc_stf_attach(wlc
) != 0)) {
1706 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit
);
1714 struct wlc_pub
*wlc_pub(void *wlc
)
1716 return ((struct wlc_info
*) wlc
)->pub
;
1719 #define CHIP_SUPPORTS_11N(wlc) 1
1722 * The common driver entry routine. Error codes should be unique
1724 void *wlc_attach(void *wl
, u16 vendor
, u16 device
, uint unit
, bool piomode
,
1725 void *regsva
, uint bustype
, void *btparam
, uint
*perr
)
1727 struct wlc_info
*wlc
;
1730 struct wlc_pub
*pub
;
1731 struct wlc_txq_info
*qi
;
1734 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1735 unit
, __func__
, vendor
, device
);
1737 ASSERT(WSEC_MAX_RCMTA_KEYS
<= WSEC_MAX_KEYS
);
1738 ASSERT(WSEC_MAX_DEFAULT_KEYS
== WLC_DEFAULT_KEYS
);
1740 /* some code depends on packed structures */
1741 ASSERT(sizeof(struct ethhdr
) == ETH_HLEN
);
1742 ASSERT(sizeof(d11regs_t
) == SI_CORE_SIZE
);
1743 ASSERT(sizeof(ofdm_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1744 ASSERT(sizeof(cck_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1745 ASSERT(sizeof(d11txh_t
) == D11_TXH_LEN
);
1746 ASSERT(sizeof(d11rxhdr_t
) == RXHDR_LEN
);
1747 ASSERT(sizeof(struct ieee80211_hdr
) == DOT11_A4_HDR_LEN
);
1748 ASSERT(sizeof(struct ieee80211_rts
) == DOT11_RTS_LEN
);
1749 ASSERT(sizeof(tx_status_t
) == TXSTATUS_LEN
);
1750 ASSERT(sizeof(struct ieee80211_ht_cap
) == HT_CAP_IE_LEN
);
1752 ASSERT(offsetof(wl_scan_params_t
, channel_list
) ==
1753 WL_SCAN_PARAMS_FIXED_SIZE
);
1755 ASSERT(IS_ALIGNED(offsetof(wsec_key_t
, data
), sizeof(u32
)));
1756 ASSERT(ISPOWEROF2(MA_WINDOW_SZ
));
1758 ASSERT(sizeof(wlc_d11rxhdr_t
) <= WL_HWRXOFF
);
1761 * Number of replay counters value used in WPA IE must match # rxivs
1762 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1763 * 'RSN Information Element' figure 8 for this mapping.
1765 ASSERT((WPA_CAP_16_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1766 && 16 == WLC_NUMRXIVS
)
1767 || (WPA_CAP_4_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1768 && 4 == WLC_NUMRXIVS
));
1770 /* allocate struct wlc_info state and its substructures */
1771 wlc
= (struct wlc_info
*) wlc_attach_malloc(unit
, &err
, device
);
1780 wlc
->band
= wlc
->bandstate
[0];
1781 wlc
->core
= wlc
->corestate
;
1784 wlc
->btparam
= btparam
;
1785 pub
->_piomode
= piomode
;
1786 wlc
->bandinit_pending
= false;
1787 /* By default restrict TKIP associations from 11n STA's */
1788 wlc
->ht_wsec_restriction
= WLC_HT_TKIP_RESTRICT
;
1790 /* populate struct wlc_info with default values */
1791 wlc_info_init(wlc
, unit
);
1793 /* update sta/ap related parameters */
1796 /* 11n_disable nvram */
1797 n_disabled
= getintvar(pub
->vars
, "11n_disable");
1799 /* register a module (to handle iovars) */
1800 wlc_module_register(wlc
->pub
, wlc_iovars
, "wlc_iovars", wlc
,
1801 wlc_doiovar
, NULL
, NULL
);
1804 * low level attach steps(all hw accesses go
1805 * inside, no more in rest of the attach)
1807 err
= wlc_bmac_attach(wlc
, vendor
, device
, unit
, piomode
, regsva
,
1812 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1813 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1815 if (!wlc_state_bmac_sync(wlc
)) {
1820 pub
->phy_11ncapable
= WLC_PHY_11N_CAP(wlc
->band
);
1822 /* propagate *vars* from BMAC driver to high driver */
1823 wlc_bmac_copyfrom_vars(wlc
->hw
, &pub
->vars
, &wlc
->vars_size
);
1826 /* set maximum allowed duty cycle */
1827 wlc
->tx_duty_cycle_ofdm
=
1828 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_ofdm");
1829 wlc
->tx_duty_cycle_cck
=
1830 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_cck");
1832 wlc_stf_phy_chain_calc(wlc
);
1834 /* txchain 1: txant 0, txchain 2: txant 1 */
1835 if (WLCISNPHY(wlc
->band
) && (wlc
->stf
->txstreams
== 1))
1836 wlc
->stf
->txant
= wlc
->stf
->hw_txchain
- 1;
1838 /* push to BMAC driver */
1839 wlc_phy_stf_chain_init(wlc
->band
->pi
, wlc
->stf
->hw_txchain
,
1840 wlc
->stf
->hw_rxchain
);
1842 /* pull up some info resulting from the low attach */
1845 for (i
= 0; i
< NFIFO
; i
++)
1846 wlc
->core
->txavail
[i
] = wlc
->hw
->txavail
[i
];
1849 wlc_bmac_hw_etheraddr(wlc
->hw
, wlc
->perm_etheraddr
);
1851 memcpy(&pub
->cur_etheraddr
, &wlc
->perm_etheraddr
, ETH_ALEN
);
1853 for (j
= 0; j
< NBANDS(wlc
); j
++) {
1854 /* Use band 1 for single band 11a */
1855 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
1858 wlc
->band
= wlc
->bandstate
[j
];
1860 if (!wlc_attach_stf_ant_init(wlc
)) {
1865 /* default contention windows size limits */
1866 wlc
->band
->CWmin
= APHY_CWMIN
;
1867 wlc
->band
->CWmax
= PHY_CWMAX
;
1869 /* init gmode value */
1870 if (BAND_2G(wlc
->band
->bandtype
)) {
1871 wlc
->band
->gmode
= GMODE_AUTO
;
1872 wlc_protection_upd(wlc
, WLC_PROT_G_USER
,
1876 /* init _n_enab supported mode */
1877 if (WLC_PHY_11N_CAP(wlc
->band
) && CHIP_SUPPORTS_11N(wlc
)) {
1878 if (n_disabled
& WLFEATURE_DISABLE_11N
) {
1880 wlc_protection_upd(wlc
, WLC_PROT_N_USER
, OFF
);
1882 pub
->_n_enab
= SUPPORT_11N
;
1883 wlc_protection_upd(wlc
, WLC_PROT_N_USER
,
1885 SUPPORT_11N
) ? WL_11N_2x2
:
1890 /* init per-band default rateset, depend on band->gmode */
1891 wlc_default_rateset(wlc
, &wlc
->band
->defrateset
);
1893 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1894 wlc_rateset_filter(&wlc
->band
->defrateset
,
1895 &wlc
->band
->hw_rateset
, false,
1896 WLC_RATES_CCK_OFDM
, RATE_MASK
,
1897 (bool) N_ENAB(wlc
->pub
));
1900 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1901 wlc_stf_phy_txant_upd(wlc
);
1903 /* attach each modules */
1904 err
= wlc_attach_module(wlc
);
1908 if (!wlc_timers_init(wlc
, unit
)) {
1909 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit
, __func__
);
1914 /* depend on rateset, gmode */
1915 wlc
->cmi
= wlc_channel_mgr_attach(wlc
);
1917 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1923 /* init default when all parameters are ready, i.e. ->rateset */
1924 wlc_bss_default_init(wlc
);
1927 * Complete the wlc default state initializations..
1930 /* allocate our initial queue */
1931 qi
= wlc_txq_alloc(wlc
);
1933 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1938 wlc
->active_queue
= qi
;
1940 wlc
->bsscfg
[0] = wlc
->cfg
;
1942 wlc
->cfg
->wlc
= wlc
;
1943 pub
->txmaxpkts
= MAXTXPKTS
;
1945 pub
->_cnt
->version
= WL_CNT_T_VERSION
;
1946 pub
->_cnt
->length
= sizeof(struct wl_cnt
);
1948 WLCNTSET(pub
->_wme_cnt
->version
, WL_WME_CNT_VERSION
);
1949 WLCNTSET(pub
->_wme_cnt
->length
, sizeof(wl_wme_cnt_t
));
1951 wlc_wme_initparams_sta(wlc
, &wlc
->wme_param_ie
);
1953 wlc
->mimoft
= FT_HT
;
1954 wlc
->ht_cap
.cap_info
= HT_CAP
;
1955 if (HT_ENAB(wlc
->pub
))
1956 wlc
->stf
->ldpc
= AUTO
;
1958 wlc
->mimo_40txbw
= AUTO
;
1959 wlc
->ofdm_40txbw
= AUTO
;
1960 wlc
->cck_40txbw
= AUTO
;
1961 wlc_update_mimo_band_bwcap(wlc
, WLC_N_BW_20IN2G_40IN5G
);
1963 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1964 wlc
->rifs_advert
= AUTO
;
1966 /* Set default values of SGI */
1967 if (WLC_SGI_CAP_PHY(wlc
)) {
1968 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1970 } else if (WLCISSSLPNPHY(wlc
->band
)) {
1971 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1974 wlc_ht_update_sgi_rx(wlc
, 0);
1978 /* *******nvram 11n config overrides Start ********* */
1980 /* apply the sgi override from nvram conf */
1981 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_TX
)
1984 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_RX
)
1985 wlc_ht_update_sgi_rx(wlc
, 0);
1987 /* apply the stbc override from nvram conf */
1988 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_TX
) {
1989 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= OFF
;
1990 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= OFF
;
1991 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_TX_STBC
;
1993 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_RX
)
1994 wlc_stf_stbc_rx_set(wlc
, HT_CAP_RX_STBC_NO
);
1996 /* apply the GF override from nvram conf */
1997 if (n_disabled
& WLFEATURE_DISABLE_11N_GF
)
1998 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_GRN_FLD
;
2000 /* initialize radio_mpc_disable according to wlc->mpc */
2001 wlc_radio_mpc_upd(wlc
);
2003 if ((wlc
->pub
->sih
->chip
) == BCM43235_CHIP_ID
) {
2004 if ((getintvar(wlc
->pub
->vars
, "aa2g") == 7) ||
2005 (getintvar(wlc
->pub
->vars
, "aa5g") == 7)) {
2006 wlc_bmac_antsel_set(wlc
->hw
, 1);
2009 wlc_bmac_antsel_set(wlc
->hw
, wlc
->asi
->antsel_avail
);
2018 WL_ERROR("wl%d: %s: failed with err %d\n", unit
, __func__
, err
);
2027 static void wlc_attach_antgain_init(struct wlc_info
*wlc
)
2030 unit
= wlc
->pub
->unit
;
2032 if ((wlc
->band
->antgain
== -1) && (wlc
->pub
->sromrev
== 1)) {
2033 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2034 wlc
->band
->antgain
= 8;
2035 } else if (wlc
->band
->antgain
== -1) {
2036 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2038 wlc
->band
->antgain
= 8;
2041 /* Older sroms specified gain in whole dbm only. In order
2042 * be able to specify qdbm granularity and remain backward compatible
2043 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2044 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2045 * -32 - 31. Examples: 0x1 = 1 db,
2046 * 0xc1 = 1.75 db (1 + 3 quarters),
2047 * 0x3f = -1 (-1 + 0 quarters),
2048 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2049 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2051 gain
= wlc
->band
->antgain
& 0x3f;
2052 gain
<<= 2; /* Sign extend */
2054 fract
= (wlc
->band
->antgain
& 0xc0) >> 6;
2055 wlc
->band
->antgain
= 4 * gain
+ fract
;
2059 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
)
2066 unit
= wlc
->pub
->unit
;
2067 vars
= wlc
->pub
->vars
;
2068 bandtype
= wlc
->band
->bandtype
;
2070 /* get antennas available */
2071 aa
= (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "aa5g" : "aa2g"));
2073 aa
= (s8
) getintvar(vars
,
2074 (BAND_5G(bandtype
) ? "aa1" : "aa0"));
2075 if ((aa
< 1) || (aa
> 15)) {
2076 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2077 unit
, __func__
, aa
);
2081 /* reset the defaults if we have a single antenna */
2083 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_0
;
2084 wlc
->stf
->txant
= ANT_TX_FORCE_0
;
2085 } else if (aa
== 2) {
2086 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_1
;
2087 wlc
->stf
->txant
= ANT_TX_FORCE_1
;
2091 /* Compute Antenna Gain */
2092 wlc
->band
->antgain
=
2093 (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "ag1" : "ag0"));
2094 wlc_attach_antgain_init(wlc
);
2100 static void wlc_timers_deinit(struct wlc_info
*wlc
)
2102 /* free timer state */
2104 wl_free_timer(wlc
->wl
, wlc
->wdtimer
);
2105 wlc
->wdtimer
= NULL
;
2107 if (wlc
->radio_timer
) {
2108 wl_free_timer(wlc
->wl
, wlc
->radio_timer
);
2109 wlc
->radio_timer
= NULL
;
2113 static void wlc_detach_module(struct wlc_info
*wlc
)
2116 wlc_antsel_detach(wlc
->asi
);
2121 wlc_ampdu_detach(wlc
->ampdu
);
2125 wlc_stf_detach(wlc
);
2129 * Return a count of the number of driver callbacks still pending.
2131 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2132 * touch hardware registers since the d11core may be in reset and clock may not be available.
2133 * One exception is sb register access, which is possible if crystal is turned on
2134 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2136 uint
wlc_detach(struct wlc_info
*wlc
)
2144 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
2146 ASSERT(!wlc
->pub
->up
);
2148 callbacks
+= wlc_bmac_detach(wlc
);
2150 /* delete software timers */
2151 if (!wlc_radio_monitor_stop(wlc
))
2154 wlc_channel_mgr_detach(wlc
->cmi
);
2156 wlc_timers_deinit(wlc
);
2158 wlc_detach_module(wlc
);
2160 /* free other state */
2164 kfree(wlc
->country_ie_override
);
2165 wlc
->country_ie_override
= NULL
;
2169 /* free dumpcb list */
2170 struct dumpcb_s
*prev
, *ptr
;
2171 prev
= ptr
= wlc
->dumpcb_head
;
2177 wlc
->dumpcb_head
= NULL
;
2180 /* Detach from iovar manager */
2181 wlc_module_unregister(wlc
->pub
, "wlc_iovars", wlc
);
2183 while (wlc
->tx_queues
!= NULL
)
2184 wlc_txq_free(wlc
, wlc
->tx_queues
);
2187 * consistency check: wlc_module_register/wlc_module_unregister calls
2188 * should match therefore nothing should be left here.
2190 for (i
= 0; i
< WLC_MAXMODULES
; i
++)
2191 ASSERT(wlc
->modulecb
[i
].name
[0] == '\0');
2193 wlc_detach_mfree(wlc
);
2197 /* update state that depends on the current value of "ap" */
2198 void wlc_ap_upd(struct wlc_info
*wlc
)
2200 if (AP_ENAB(wlc
->pub
))
2201 wlc
->PLCPHdr_override
= WLC_PLCP_AUTO
; /* AP: short not allowed, but not enforced */
2203 wlc
->PLCPHdr_override
= WLC_PLCP_SHORT
; /* STA-BSS; short capable */
2205 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2206 wlc
->vlan_mode
= AP_ENAB(wlc
->pub
) ? OFF
: AUTO
;
2212 /* read hwdisable state and propagate to wlc flag */
2213 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
)
2215 if (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
|| wlc
->pub
->hw_off
)
2218 if (wlc_bmac_radio_read_hwdisabled(wlc
->hw
)) {
2219 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2221 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2225 /* return true if Minimum Power Consumption should be entered, false otherwise */
2226 bool wlc_is_non_delay_mpc(struct wlc_info
*wlc
)
2231 bool wlc_ismpc(struct wlc_info
*wlc
)
2233 return (wlc
->mpc_delay_off
== 0) && (wlc_is_non_delay_mpc(wlc
));
2236 void wlc_radio_mpc_upd(struct wlc_info
*wlc
)
2238 bool mpc_radio
, radio_state
;
2241 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2242 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2243 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2244 * the radio is going down.
2247 if (!wlc
->pub
->radio_disabled
)
2249 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2251 if (!wlc
->pub
->radio_disabled
)
2252 wlc_radio_monitor_stop(wlc
);
2257 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2258 * to go ON, always call radio_upd synchronously
2259 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2262 (mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
) ? OFF
:
2264 mpc_radio
= (wlc_ismpc(wlc
) == true) ? OFF
: ON
;
2266 if (radio_state
== ON
&& mpc_radio
== OFF
)
2267 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2268 else if (radio_state
== OFF
&& mpc_radio
== ON
) {
2269 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2271 if (wlc
->mpc_offcnt
< WLC_MPC_THRESHOLD
) {
2272 wlc
->mpc_dlycnt
= WLC_MPC_MAX_DELAYCNT
;
2274 wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
2275 wlc
->mpc_dur
+= OSL_SYSUPTIME() - wlc
->mpc_laston_ts
;
2277 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2278 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2279 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2281 if ((wlc
->prev_non_delay_mpc
== false) &&
2282 (wlc_is_non_delay_mpc(wlc
) == true) && wlc
->mpc_delay_off
) {
2283 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2285 wlc
->prev_non_delay_mpc
= wlc_is_non_delay_mpc(wlc
);
2289 * centralized radio disable/enable function,
2290 * invoke radio enable/disable after updating hwradio status
2292 static void wlc_radio_upd(struct wlc_info
*wlc
)
2294 if (wlc
->pub
->radio_disabled
) {
2295 wlc_radio_disable(wlc
);
2297 wlc_radio_enable(wlc
);
2301 /* maintain LED behavior in down state */
2302 static void wlc_down_led_upd(struct wlc_info
*wlc
)
2304 ASSERT(!wlc
->pub
->up
);
2306 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2307 /* turn on sbclk if necessary */
2308 if (!AP_ENAB(wlc
->pub
)) {
2309 wlc_pllreq(wlc
, true, WLC_PLLREQ_FLIP
);
2311 wlc_pllreq(wlc
, false, WLC_PLLREQ_FLIP
);
2315 /* update hwradio status and return it */
2316 bool wlc_check_radio_disabled(struct wlc_info
*wlc
)
2318 wlc_radio_hwdisable_upd(wlc
);
2320 return mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
) ? true : false;
2323 void wlc_radio_disable(struct wlc_info
*wlc
)
2325 if (!wlc
->pub
->up
) {
2326 wlc_down_led_upd(wlc
);
2330 wlc_radio_monitor_start(wlc
);
2334 static void wlc_radio_enable(struct wlc_info
*wlc
)
2339 if (DEVICEREMOVED(wlc
))
2342 if (!wlc
->down_override
) { /* imposed by wl down/out ioctl */
2347 /* periodical query hw radio button while driver is "down" */
2348 static void wlc_radio_timer(void *arg
)
2350 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2352 if (DEVICEREMOVED(wlc
)) {
2353 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2358 /* cap mpc off count */
2359 if (wlc
->mpc_offcnt
< WLC_MPC_MAX_DELAYCNT
)
2362 /* validate all the reasons driver could be down and running this radio_timer */
2363 ASSERT(wlc
->pub
->radio_disabled
|| wlc
->down_override
);
2364 wlc_radio_hwdisable_upd(wlc
);
2368 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
)
2370 /* Don't start the timer if HWRADIO feature is disabled */
2371 if (wlc
->radio_monitor
|| (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
))
2374 wlc
->radio_monitor
= true;
2375 wlc_pllreq(wlc
, true, WLC_PLLREQ_RADIO_MON
);
2376 wl_add_timer(wlc
->wl
, wlc
->radio_timer
, TIMER_INTERVAL_RADIOCHK
, true);
2380 bool wlc_radio_monitor_stop(struct wlc_info
*wlc
)
2382 if (!wlc
->radio_monitor
)
2385 ASSERT((wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
) !=
2388 wlc
->radio_monitor
= false;
2389 wlc_pllreq(wlc
, false, WLC_PLLREQ_RADIO_MON
);
2390 return wl_del_timer(wlc
->wl
, wlc
->radio_timer
);
2393 /* bring the driver down, but don't reset hardware */
2394 void wlc_out(struct wlc_info
*wlc
)
2396 wlc_bmac_set_noreset(wlc
->hw
, true);
2399 wlc_bmac_set_noreset(wlc
->hw
, false);
2401 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2404 /* This will make sure that when 'up' is done
2405 * after 'out' it'll restore hardware (especially gpios)
2407 wlc
->pub
->hw_up
= false;
2411 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2412 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2413 * in prec_map. Of course, ignore this rule when block_datafifo is set
2415 static bool wlc_tx_prec_map_verify(struct wlc_info
*wlc
)
2417 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2420 if (!EDCF_ENAB(wlc
->pub
)) {
2421 if (!(WLC_TX_FIFO_CHECK(wlc
, TX_DATA_FIFO
) ||
2422 WLC_TX_FIFO_CHECK(wlc
, TX_CTL_FIFO
)))
2428 return WLC_TX_FIFO_CHECK(wlc
, TX_AC_BK_FIFO
)
2429 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_BE_FIFO
)
2430 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VI_FIFO
)
2431 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VO_FIFO
);
2435 static void wlc_watchdog_by_timer(void *arg
)
2437 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2439 if (WLC_WATCHDOG_TBTT(wlc
)) {
2440 /* set to normal osl watchdog period */
2441 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
2442 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
2447 /* common watchdog code */
2448 static void wlc_watchdog(void *arg
)
2450 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2452 struct wlc_bsscfg
*cfg
;
2454 WL_TRACE("wl%d: wlc_watchdog\n", wlc
->pub
->unit
);
2459 if (DEVICEREMOVED(wlc
)) {
2460 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2465 /* increment second count */
2468 /* delay radio disable */
2469 if (wlc
->mpc_delay_off
) {
2470 if (--wlc
->mpc_delay_off
== 0) {
2471 mboolset(wlc
->pub
->radio_disabled
,
2472 WL_RADIO_MPC_DISABLE
);
2473 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2474 wlc
->mpc_offcnt
= 0;
2475 wlc
->mpc_laston_ts
= OSL_SYSUPTIME();
2480 wlc_radio_mpc_upd(wlc
);
2481 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2482 wlc_radio_hwdisable_upd(wlc
);
2484 /* if ismpc, driver should be in down state if up/down is allowed */
2485 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2486 ASSERT(!wlc
->pub
->up
);
2487 /* if radio is disable, driver may be down, quit here */
2488 if (wlc
->pub
->radio_disabled
)
2491 wlc_bmac_watchdog(wlc
);
2493 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2494 if ((wlc
->pub
->now
% SW_TIMER_MAC_STAT_UPD
) == 0)
2497 /* Manage TKIP countermeasures timers */
2498 FOREACH_BSS(wlc
, i
, cfg
) {
2499 if (cfg
->tk_cm_dt
) {
2502 if (cfg
->tk_cm_bt
) {
2507 /* Call any registered watchdog handlers */
2508 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2509 if (wlc
->modulecb
[i
].watchdog_fn
)
2510 wlc
->modulecb
[i
].watchdog_fn(wlc
->modulecb
[i
].hdl
);
2513 if (WLCISNPHY(wlc
->band
) && !wlc
->pub
->tempsense_disable
&&
2514 ((wlc
->pub
->now
- wlc
->tempsense_lasttime
) >=
2515 WLC_TEMPSENSE_PERIOD
)) {
2516 wlc
->tempsense_lasttime
= wlc
->pub
->now
;
2517 wlc_tempsense_upd(wlc
);
2519 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2520 ASSERT(wlc_bmac_taclear(wlc
->hw
, true));
2522 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2523 ASSERT(wlc_tx_prec_map_verify(wlc
));
2525 ASSERT(wlc_ps_check(wlc
));
2528 /* make interface operational */
2529 int wlc_up(struct wlc_info
*wlc
)
2531 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2533 /* HW is turned off so don't try to access it */
2534 if (wlc
->pub
->hw_off
|| DEVICEREMOVED(wlc
))
2535 return BCME_RADIOOFF
;
2537 if (!wlc
->pub
->hw_up
) {
2538 wlc_bmac_hw_up(wlc
->hw
);
2539 wlc
->pub
->hw_up
= true;
2542 if ((wlc
->pub
->boardflags
& BFL_FEM
)
2543 && (wlc
->pub
->sih
->chip
== BCM4313_CHIP_ID
)) {
2544 if (wlc
->pub
->boardrev
>= 0x1250
2545 && (wlc
->pub
->boardflags
& BFL_FEM_BT
)) {
2546 wlc_mhf(wlc
, MHF5
, MHF5_4313_GPIOCTRL
,
2547 MHF5_4313_GPIOCTRL
, WLC_BAND_ALL
);
2549 wlc_mhf(wlc
, MHF4
, MHF4_EXTPA_ENABLE
, MHF4_EXTPA_ENABLE
,
2555 * Need to read the hwradio status here to cover the case where the system
2556 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2557 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2558 * don't call radio_update to avoid looping wlc_up.
2560 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2562 if (!wlc
->pub
->radio_disabled
) {
2563 int status
= wlc_bmac_up_prep(wlc
->hw
);
2564 if (status
== BCME_RADIOOFF
) {
2566 (wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
)) {
2568 struct wlc_bsscfg
*bsscfg
;
2569 mboolset(wlc
->pub
->radio_disabled
,
2570 WL_RADIO_HW_DISABLE
);
2572 FOREACH_BSS(wlc
, idx
, bsscfg
) {
2573 if (!BSSCFG_STA(bsscfg
)
2574 || !bsscfg
->enable
|| !bsscfg
->BSS
)
2576 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2577 wlc
->pub
->unit
, idx
);
2584 if (wlc
->pub
->radio_disabled
) {
2585 wlc_radio_monitor_start(wlc
);
2589 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2592 wlc_radio_monitor_stop(wlc
);
2594 /* Set EDCF hostflags */
2595 if (EDCF_ENAB(wlc
->pub
)) {
2596 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, MHF1_EDCF
, WLC_BAND_ALL
);
2598 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, 0, WLC_BAND_ALL
);
2601 if (WLC_WAR16165(wlc
))
2602 wlc_mhf(wlc
, MHF2
, MHF2_PCISLOWCLKWAR
, MHF2_PCISLOWCLKWAR
,
2606 wlc
->pub
->up
= true;
2608 if (wlc
->bandinit_pending
) {
2609 wlc_suspend_mac_and_wait(wlc
);
2610 wlc_set_chanspec(wlc
, wlc
->default_bss
->chanspec
);
2611 wlc
->bandinit_pending
= false;
2612 wlc_enable_mac(wlc
);
2615 wlc_bmac_up_finish(wlc
->hw
);
2617 /* other software states up after ISR is running */
2618 /* start APs that were to be brought up but are not up yet */
2619 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2621 /* Program the TX wme params with the current settings */
2622 wlc_wme_retries_write(wlc
);
2624 /* start one second watchdog timer */
2625 ASSERT(!wlc
->WDarmed
);
2626 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
, true);
2627 wlc
->WDarmed
= true;
2629 /* ensure antenna config is up to date */
2630 wlc_stf_phy_txant_upd(wlc
);
2631 /* ensure LDPC config is in sync */
2632 wlc_ht_update_ldpc(wlc
, wlc
->stf
->ldpc
);
2637 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2638 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
)
2640 wlc
->tx_prec_map
= WLC_PREC_BMP_ALL
;
2641 memset(wlc
->fifo2prec_map
, 0, NFIFO
* sizeof(u16
));
2643 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2644 * if either is full.
2646 if (!EDCF_ENAB(wlc
->pub
)) {
2647 wlc
->fifo2prec_map
[TX_DATA_FIFO
] = WLC_PREC_BMP_ALL
;
2648 wlc
->fifo2prec_map
[TX_CTL_FIFO
] = WLC_PREC_BMP_ALL
;
2650 wlc
->fifo2prec_map
[TX_AC_BK_FIFO
] = WLC_PREC_BMP_AC_BK
;
2651 wlc
->fifo2prec_map
[TX_AC_BE_FIFO
] = WLC_PREC_BMP_AC_BE
;
2652 wlc
->fifo2prec_map
[TX_AC_VI_FIFO
] = WLC_PREC_BMP_AC_VI
;
2653 wlc
->fifo2prec_map
[TX_AC_VO_FIFO
] = WLC_PREC_BMP_AC_VO
;
2657 static uint
wlc_down_del_timer(struct wlc_info
*wlc
)
2665 * Mark the interface nonoperational, stop the software mechanisms,
2666 * disable the hardware, free any transient buffer state.
2667 * Return a count of the number of driver callbacks still pending.
2669 uint
wlc_down(struct wlc_info
*wlc
)
2674 bool dev_gone
= false;
2675 struct wlc_txq_info
*qi
;
2677 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2679 /* check if we are already in the going down path */
2680 if (wlc
->going_down
) {
2681 WL_ERROR("wl%d: %s: Driver going down so return\n",
2682 wlc
->pub
->unit
, __func__
);
2688 /* in between, mpc could try to bring down again.. */
2689 wlc
->going_down
= true;
2691 callbacks
+= wlc_bmac_down_prep(wlc
->hw
);
2693 dev_gone
= DEVICEREMOVED(wlc
);
2695 /* Call any registered down handlers */
2696 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2697 if (wlc
->modulecb
[i
].down_fn
)
2699 wlc
->modulecb
[i
].down_fn(wlc
->modulecb
[i
].hdl
);
2702 /* cancel the watchdog timer */
2704 if (!wl_del_timer(wlc
->wl
, wlc
->wdtimer
))
2706 wlc
->WDarmed
= false;
2708 /* cancel all other timers */
2709 callbacks
+= wlc_down_del_timer(wlc
);
2711 /* interrupt must have been blocked */
2712 ASSERT((wlc
->macintmask
== 0) || !wlc
->pub
->up
);
2714 wlc
->pub
->up
= false;
2716 wlc_phy_mute_upd(wlc
->band
->pi
, false, PHY_MUTE_ALL
);
2718 /* clear txq flow control */
2719 wlc_txflowcontrol_reset(wlc
);
2721 /* flush tx queues */
2722 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
2723 pktq_flush(&qi
->q
, true, NULL
, 0);
2724 ASSERT(pktq_empty(&qi
->q
));
2727 callbacks
+= wlc_bmac_down_finish(wlc
->hw
);
2729 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2733 /* Since all the packets should have been freed,
2734 * all callbacks should have been called
2736 for (i
= 1; i
<= wlc
->pub
->tunables
->maxpktcb
; i
++)
2737 ASSERT(wlc
->pkt_callback
[i
].fn
== NULL
);
2739 wlc
->going_down
= false;
2743 /* Set the current gmode configuration */
2744 int wlc_set_gmode(struct wlc_info
*wlc
, u8 gmode
, bool config
)
2749 /* Default to 54g Auto */
2750 s8 shortslot
= WLC_SHORTSLOT_AUTO
; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2751 bool shortslot_restrict
= false; /* Restrict association to stations that support shortslot
2753 bool ignore_bcns
= true; /* Ignore legacy beacons on the same channel */
2754 bool ofdm_basic
= false; /* Make 6, 12, and 24 basic rates */
2755 int preamble
= WLC_PLCP_LONG
; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2756 bool preamble_restrict
= false; /* Restrict association to stations that support short
2759 struct wlcband
*band
;
2761 /* if N-support is enabled, allow Gmode set as long as requested
2762 * Gmode is not GMODE_LEGACY_B
2764 if (N_ENAB(wlc
->pub
) && gmode
== GMODE_LEGACY_B
)
2765 return BCME_UNSUPPORTED
;
2767 /* verify that we are dealing with 2G band and grab the band pointer */
2768 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
2770 else if ((NBANDS(wlc
) > 1) &&
2771 (wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
== WLC_BAND_2G
))
2772 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
2774 return BCME_BADBAND
;
2776 /* Legacy or bust when no OFDM is supported by regulatory */
2777 if ((wlc_channel_locale_flags_in_band(wlc
->cmi
, band
->bandunit
) &
2778 WLC_NO_OFDM
) && (gmode
!= GMODE_LEGACY_B
))
2781 /* update configuration value */
2783 wlc_protection_upd(wlc
, WLC_PROT_G_USER
, gmode
);
2785 /* Clear supported rates filter */
2786 memset(&wlc
->sup_rates_override
, 0, sizeof(wlc_rateset_t
));
2788 /* Clear rateset override */
2789 memset(&rs
, 0, sizeof(wlc_rateset_t
));
2792 case GMODE_LEGACY_B
:
2793 shortslot
= WLC_SHORTSLOT_OFF
;
2794 wlc_rateset_copy(&gphy_legacy_rates
, &rs
);
2799 if (AP_ENAB(wlc
->pub
))
2800 wlc_rateset_copy(&cck_rates
, &wlc
->sup_rates_override
);
2804 /* Accept defaults */
2809 preamble
= WLC_PLCP_SHORT
;
2810 preamble_restrict
= true;
2813 case GMODE_PERFORMANCE
:
2814 if (AP_ENAB(wlc
->pub
)) /* Put all rates into the Supported Rates element */
2815 wlc_rateset_copy(&cck_ofdm_rates
,
2816 &wlc
->sup_rates_override
);
2818 shortslot
= WLC_SHORTSLOT_ON
;
2819 shortslot_restrict
= true;
2821 preamble
= WLC_PLCP_SHORT
;
2822 preamble_restrict
= true;
2827 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2828 wlc
->pub
->unit
, __func__
, gmode
);
2829 return BCME_UNSUPPORTED
;
2833 * If we are switching to gmode == GMODE_LEGACY_B,
2834 * clean up rate info that may refer to OFDM rates.
2836 if ((gmode
== GMODE_LEGACY_B
) && (band
->gmode
!= GMODE_LEGACY_B
)) {
2837 band
->gmode
= gmode
;
2838 if (band
->rspec_override
&& !IS_CCK(band
->rspec_override
)) {
2839 band
->rspec_override
= 0;
2840 wlc_reprate_init(wlc
);
2842 if (band
->mrspec_override
&& !IS_CCK(band
->mrspec_override
)) {
2843 band
->mrspec_override
= 0;
2847 band
->gmode
= gmode
;
2849 wlc
->ignore_bcns
= ignore_bcns
;
2851 wlc
->shortslot_override
= shortslot
;
2853 if (AP_ENAB(wlc
->pub
)) {
2854 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2855 wlc
->PLCPHdr_override
=
2857 WLC_PLCP_LONG
) ? WLC_PLCP_SHORT
: WLC_PLCP_AUTO
;
2860 if ((AP_ENAB(wlc
->pub
) && preamble
!= WLC_PLCP_LONG
)
2861 || preamble
== WLC_PLCP_SHORT
)
2862 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
2864 wlc
->default_bss
->capability
&= ~WLAN_CAPABILITY_SHORT_PREAMBLE
;
2866 /* Update shortslot capability bit for AP and IBSS */
2867 if ((AP_ENAB(wlc
->pub
) && shortslot
== WLC_SHORTSLOT_AUTO
) ||
2868 shortslot
== WLC_SHORTSLOT_ON
)
2869 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2871 wlc
->default_bss
->capability
&=
2872 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2874 /* Use the default 11g rateset */
2876 wlc_rateset_copy(&cck_ofdm_rates
, &rs
);
2879 for (i
= 0; i
< rs
.count
; i
++) {
2880 if (rs
.rates
[i
] == WLC_RATE_6M
2881 || rs
.rates
[i
] == WLC_RATE_12M
2882 || rs
.rates
[i
] == WLC_RATE_24M
)
2883 rs
.rates
[i
] |= WLC_RATE_FLAG
;
2887 /* Set default bss rateset */
2888 wlc
->default_bss
->rateset
.count
= rs
.count
;
2889 memcpy(wlc
->default_bss
->rateset
.rates
, rs
.rates
,
2890 sizeof(wlc
->default_bss
->rateset
.rates
));
2895 static int wlc_nmode_validate(struct wlc_info
*wlc
, s32 nmode
)
2907 if (!(WLC_PHY_11N_CAP(wlc
->band
)))
2919 int wlc_set_nmode(struct wlc_info
*wlc
, s32 nmode
)
2924 err
= wlc_nmode_validate(wlc
, nmode
);
2931 wlc
->pub
->_n_enab
= OFF
;
2932 wlc
->default_bss
->flags
&= ~WLC_BSS_HT
;
2933 /* delete the mcs rates from the default and hw ratesets */
2934 wlc_rateset_mcs_clear(&wlc
->default_bss
->rateset
);
2935 for (i
= 0; i
< NBANDS(wlc
); i
++) {
2936 memset(wlc
->bandstate
[i
]->hw_rateset
.mcs
, 0,
2938 if (IS_MCS(wlc
->band
->rspec_override
)) {
2939 wlc
->bandstate
[i
]->rspec_override
= 0;
2940 wlc_reprate_init(wlc
);
2942 if (IS_MCS(wlc
->band
->mrspec_override
))
2943 wlc
->bandstate
[i
]->mrspec_override
= 0;
2948 if (wlc
->stf
->txstreams
== WL_11N_3x3
)
2954 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
2955 /* force GMODE_AUTO if NMODE is ON */
2956 wlc_set_gmode(wlc
, GMODE_AUTO
, true);
2957 if (nmode
== WL_11N_3x3
)
2958 wlc
->pub
->_n_enab
= SUPPORT_HT
;
2960 wlc
->pub
->_n_enab
= SUPPORT_11N
;
2961 wlc
->default_bss
->flags
|= WLC_BSS_HT
;
2962 /* add the mcs rates to the default and hw ratesets */
2963 wlc_rateset_mcs_build(&wlc
->default_bss
->rateset
,
2964 wlc
->stf
->txstreams
);
2965 for (i
= 0; i
< NBANDS(wlc
); i
++)
2966 memcpy(wlc
->bandstate
[i
]->hw_rateset
.mcs
,
2967 wlc
->default_bss
->rateset
.mcs
, MCSSET_LEN
);
2978 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
)
2980 wlc_rateset_t rs
, new;
2983 memcpy(&rs
, rs_arg
, sizeof(wlc_rateset_t
));
2985 /* check for bad count value */
2986 if ((rs
.count
== 0) || (rs
.count
> WLC_NUMRATES
))
2987 return BCME_BADRATESET
;
2989 /* try the current band */
2990 bandunit
= wlc
->band
->bandunit
;
2991 memcpy(&new, &rs
, sizeof(wlc_rateset_t
));
2992 if (wlc_rate_hwrs_filter_sort_validate
2993 (&new, &wlc
->bandstate
[bandunit
]->hw_rateset
, true,
2994 wlc
->stf
->txstreams
))
2997 /* try the other band */
2998 if (IS_MBAND_UNLOCKED(wlc
)) {
2999 bandunit
= OTHERBANDUNIT(wlc
);
3000 memcpy(&new, &rs
, sizeof(wlc_rateset_t
));
3001 if (wlc_rate_hwrs_filter_sort_validate(&new,
3003 bandstate
[bandunit
]->
3005 wlc
->stf
->txstreams
))
3012 /* apply new rateset */
3013 memcpy(&wlc
->default_bss
->rateset
, &new, sizeof(wlc_rateset_t
));
3014 memcpy(&wlc
->bandstate
[bandunit
]->defrateset
, &new,
3015 sizeof(wlc_rateset_t
));
3019 /* simplified integer set interface for common ioctl handler */
3020 int wlc_set(struct wlc_info
*wlc
, int cmd
, int arg
)
3022 return wlc_ioctl(wlc
, cmd
, (void *)&arg
, sizeof(arg
), NULL
);
3025 /* simplified integer get interface for common ioctl handler */
3026 int wlc_get(struct wlc_info
*wlc
, int cmd
, int *arg
)
3028 return wlc_ioctl(wlc
, cmd
, arg
, sizeof(int), NULL
);
3031 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
)
3036 if (wlc
->cfg
->associated
)
3037 r
= wlc
->cfg
->current_bss
->rateset
.rates
[0];
3039 r
= wlc
->default_bss
->rateset
.rates
[0];
3041 wlc_phy_ofdm_rateset_war(wlc
->band
->pi
, war
);
3047 wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3048 struct wlc_if
*wlcif
)
3050 return _wlc_ioctl(wlc
, cmd
, arg
, len
, wlcif
);
3053 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3055 _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3056 struct wlc_if
*wlcif
)
3063 struct scb
*nextscb
;
3067 struct wlc_bsscfg
*bsscfg
;
3068 wlc_bss_info_t
*current_bss
;
3070 /* update bsscfg pointer */
3071 bsscfg
= NULL
; /* XXX: Hack bsscfg to be size one and use this globally */
3074 /* initialize the following to get rid of compiler warning */
3080 /* If the device is turned off, then it's not "removed" */
3081 if (!wlc
->pub
->hw_off
&& DEVICEREMOVED(wlc
)) {
3082 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
3087 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
3089 /* default argument is generic integer */
3090 pval
= arg
? (int *)arg
:NULL
;
3092 /* This will prevent the misaligned access */
3093 if (pval
&& (u32
) len
>= sizeof(val
))
3094 memcpy(&val
, pval
, sizeof(val
));
3098 /* bool conversion to avoid duplication below */
3099 bool_val
= val
!= 0;
3101 if (cmd
!= WLC_SET_CHANNEL
)
3102 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3103 cmd
, (uint
)val
, val
, len
);
3108 /* A few commands don't need any arguments; all the others do. */
3116 case WLC_START_CHANNEL_QA
:
3121 if ((arg
== NULL
) || (len
<= 0)) {
3122 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3123 wlc
->pub
->unit
, __func__
, cmd
);
3124 bcmerror
= BCME_BADARG
;
3132 case WLC_GET_MSGLEVEL
:
3133 *pval
= wl_msg_level
;
3136 case WLC_SET_MSGLEVEL
:
3141 case WLC_GET_INSTANCE
:
3142 *pval
= wlc
->pub
->unit
;
3145 case WLC_GET_CHANNEL
:{
3146 channel_info_t
*ci
= (channel_info_t
*) arg
;
3148 ASSERT(len
> (int)sizeof(ci
));
3151 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
);
3152 ci
->target_channel
=
3153 CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
);
3154 ci
->scan_channel
= 0;
3159 case WLC_SET_CHANNEL
:{
3160 chanspec_t chspec
= CH20MHZ_CHSPEC(val
);
3162 if (val
< 0 || val
> MAXCHANNEL
) {
3163 bcmerror
= BCME_OUTOFRANGECHAN
;
3167 if (!wlc_valid_chanspec_db(wlc
->cmi
, chspec
)) {
3168 bcmerror
= BCME_BADCHAN
;
3172 if (!wlc
->pub
->up
&& IS_MBAND_UNLOCKED(wlc
)) {
3173 if (wlc
->band
->bandunit
!=
3174 CHSPEC_WLCBANDUNIT(chspec
))
3175 wlc
->bandinit_pending
= true;
3177 wlc
->bandinit_pending
= false;
3180 wlc
->default_bss
->chanspec
= chspec
;
3181 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3183 (WLC_BAND_PI_RADIO_CHANSPEC
!= chspec
)) {
3184 wlc_set_home_chanspec(wlc
, chspec
);
3185 wlc_suspend_mac_and_wait(wlc
);
3186 wlc_set_chanspec(wlc
, chspec
);
3187 wlc_enable_mac(wlc
);
3193 case WLC_GET_UCFLAGS
:
3194 if (!wlc
->pub
->up
) {
3195 bcmerror
= BCME_NOTUP
;
3199 /* optional band is stored in the second integer of incoming buffer */
3202 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3204 /* bcmerror checking */
3205 bcmerror
= wlc_iocregchk(wlc
, band
);
3209 if (val
>= MHFMAX
) {
3210 bcmerror
= BCME_RANGE
;
3214 *pval
= wlc_bmac_mhf_get(wlc
->hw
, (u8
) val
, WLC_BAND_AUTO
);
3217 case WLC_SET_UCFLAGS
:
3218 if (!wlc
->pub
->up
) {
3219 bcmerror
= BCME_NOTUP
;
3223 /* optional band is stored in the second integer of incoming buffer */
3226 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3228 /* bcmerror checking */
3229 bcmerror
= wlc_iocregchk(wlc
, band
);
3235 bcmerror
= BCME_RANGE
;
3239 wlc_mhf(wlc
, (u8
) i
, 0xffff, (u16
) (val
>> NBITS(u16
)),
3246 /* optional band is stored in the second integer of incoming buffer */
3249 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3251 /* bcmerror checking */
3252 bcmerror
= wlc_iocregchk(wlc
, band
);
3257 bcmerror
= BCME_BADADDR
;
3261 *pval
= wlc_read_shm(wlc
, (u16
) val
);
3267 /* optional band is stored in the second integer of incoming buffer */
3270 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3272 /* bcmerror checking */
3273 bcmerror
= wlc_iocregchk(wlc
, band
);
3278 bcmerror
= BCME_BADADDR
;
3282 wlc_write_shm(wlc
, (u16
) val
,
3283 (u16
) (val
>> NBITS(u16
)));
3286 case WLC_R_REG
: /* MAC registers */
3288 r
= (rw_reg_t
*) arg
;
3289 band
= WLC_BAND_AUTO
;
3291 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3292 bcmerror
= BCME_BUFTOOSHORT
;
3296 if (len
>= (int)sizeof(rw_reg_t
))
3299 /* bcmerror checking */
3300 bcmerror
= wlc_iocregchk(wlc
, band
);
3304 if ((r
->byteoff
+ r
->size
) > sizeof(d11regs_t
)) {
3305 bcmerror
= BCME_BADADDR
;
3308 if (r
->size
== sizeof(u32
))
3310 R_REG((u32
*)((unsigned char *)(unsigned long)regs
+
3312 else if (r
->size
== sizeof(u16
))
3314 R_REG((u16
*)((unsigned char *)(unsigned long)regs
+
3317 bcmerror
= BCME_BADADDR
;
3322 r
= (rw_reg_t
*) arg
;
3323 band
= WLC_BAND_AUTO
;
3325 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3326 bcmerror
= BCME_BUFTOOSHORT
;
3330 if (len
>= (int)sizeof(rw_reg_t
))
3333 /* bcmerror checking */
3334 bcmerror
= wlc_iocregchk(wlc
, band
);
3338 if (r
->byteoff
+ r
->size
> sizeof(d11regs_t
)) {
3339 bcmerror
= BCME_BADADDR
;
3342 if (r
->size
== sizeof(u32
))
3343 W_REG((u32
*)((unsigned char *)(unsigned long) regs
+
3344 r
->byteoff
), r
->val
);
3345 else if (r
->size
== sizeof(u16
))
3346 W_REG((u16
*)((unsigned char *)(unsigned long) regs
+
3347 r
->byteoff
), r
->val
);
3349 bcmerror
= BCME_BADADDR
;
3354 *pval
= wlc
->stf
->txant
;
3358 bcmerror
= wlc_stf_ant_txant_validate(wlc
, (s8
) val
);
3362 wlc
->stf
->txant
= (s8
) val
;
3364 /* if down, we are done */
3368 wlc_suspend_mac_and_wait(wlc
);
3370 wlc_stf_phy_txant_upd(wlc
);
3371 wlc_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
3373 wlc_enable_mac(wlc
);
3377 case WLC_GET_ANTDIV
:{
3380 /* return configured value if core is down */
3381 if (!wlc
->pub
->up
) {
3382 *pval
= wlc
->stf
->ant_rx_ovr
;
3385 if (wlc_phy_ant_rxdiv_get
3386 (wlc
->band
->pi
, &phy_antdiv
))
3387 *pval
= (int)phy_antdiv
;
3389 *pval
= (int)wlc
->stf
->ant_rx_ovr
;
3394 case WLC_SET_ANTDIV
:
3395 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3396 if ((val
< -1) || (val
> 3)) {
3397 bcmerror
= BCME_RANGE
;
3402 val
= ANT_RX_DIV_DEF
;
3404 wlc
->stf
->ant_rx_ovr
= (u8
) val
;
3405 wlc_phy_ant_rxdiv_set(wlc
->band
->pi
, (u8
) val
);
3408 case WLC_GET_RX_ANT
:{ /* get latest used rx antenna */
3411 if (!wlc
->pub
->up
) {
3412 bcmerror
= BCME_NOTUP
;
3416 rxstatus
= R_REG(&wlc
->regs
->phyrxstatus0
);
3417 if (rxstatus
== 0xdead || rxstatus
== (u16
) -1) {
3418 bcmerror
= BCME_ERROR
;
3421 *pval
= (rxstatus
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0;
3426 case WLC_GET_UCANTDIV
:
3428 bcmerror
= BCME_NOCLK
;
3433 (wlc_bmac_mhf_get(wlc
->hw
, MHF1
, WLC_BAND_AUTO
) &
3437 case WLC_SET_UCANTDIV
:{
3438 if (!wlc
->pub
->up
) {
3439 bcmerror
= BCME_NOTUP
;
3443 /* if multiband, band must be locked */
3444 if (IS_MBAND_UNLOCKED(wlc
)) {
3445 bcmerror
= BCME_NOTBANDLOCKED
;
3449 wlc_mhf(wlc
, MHF1
, MHF1_ANTDIV
,
3450 (val
? MHF1_ANTDIV
: 0), WLC_BAND_AUTO
);
3453 #endif /* defined(BCMDBG) */
3460 if (val
>= 1 && val
<= RETRY_SHORT_MAX
) {
3462 wlc
->SRL
= (u16
) val
;
3464 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3466 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3467 WLC_WME_RETRY_SHORT_SET(wlc
, ac
, wlc
->SRL
);
3469 wlc_wme_retries_write(wlc
);
3471 bcmerror
= BCME_RANGE
;
3479 if (val
>= 1 && val
<= 255) {
3481 wlc
->LRL
= (u16
) val
;
3483 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3485 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3486 WLC_WME_RETRY_LONG_SET(wlc
, ac
, wlc
->LRL
);
3488 wlc_wme_retries_write(wlc
);
3490 bcmerror
= BCME_RANGE
;
3494 *pval
= wlc
->band
->CWmin
;
3499 bcmerror
= BCME_NOCLK
;
3503 if (val
>= 1 && val
<= 255) {
3504 wlc_set_cwmin(wlc
, (u16
) val
);
3506 bcmerror
= BCME_RANGE
;
3510 *pval
= wlc
->band
->CWmax
;
3515 bcmerror
= BCME_NOCLK
;
3519 if (val
>= 255 && val
<= 2047) {
3520 wlc_set_cwmax(wlc
, (u16
) val
);
3522 bcmerror
= BCME_RANGE
;
3525 case WLC_GET_RADIO
: /* use mask if don't want to expose some internal bits */
3526 *pval
= wlc
->pub
->radio_disabled
;
3529 case WLC_SET_RADIO
:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3532 u16 radiomask
, radioval
;
3534 WL_RADIO_SW_DISABLE
| WL_RADIO_HW_DISABLE
;
3537 radiomask
= (val
& 0xffff0000) >> 16;
3538 radioval
= val
& 0x0000ffff;
3540 if ((radiomask
== 0) || (radiomask
& ~validbits
)
3541 || (radioval
& ~validbits
)
3542 || ((radioval
& ~radiomask
) != 0)) {
3543 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3545 bcmerror
= BCME_RANGE
;
3550 (wlc
->pub
->radio_disabled
& ~radiomask
) | radioval
;
3551 wlc
->pub
->radio_disabled
= new;
3553 wlc_radio_hwdisable_upd(wlc
);
3558 case WLC_GET_PHYTYPE
:
3559 *pval
= WLC_PHYTYPE(wlc
->band
->phytype
);
3564 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
))) {
3567 wsec_key_t
*src_key
= wlc
->wsec_keys
[val
];
3569 if (len
< (int)sizeof(key
)) {
3570 bcmerror
= BCME_BUFTOOSHORT
;
3574 memset((char *)&key
, 0, sizeof(key
));
3576 key
.index
= src_key
->id
;
3577 key
.len
= src_key
->len
;
3578 memcpy(key
.data
, src_key
->data
, key
.len
);
3579 key
.algo
= src_key
->algo
;
3580 if (WSEC_SOFTKEY(wlc
, src_key
, bsscfg
))
3581 key
.flags
|= WL_SOFT_KEY
;
3582 if (src_key
->flags
& WSEC_PRIMARY_KEY
)
3583 key
.flags
|= WL_PRIMARY_KEY
;
3585 memcpy(key
.ea
, src_key
->ea
, ETH_ALEN
);
3588 memcpy(arg
, &key
, sizeof(key
));
3590 bcmerror
= BCME_BADKEYIDX
;
3592 #endif /* defined(BCMDBG) */
3596 wlc_iovar_op(wlc
, "wsec_key", NULL
, 0, arg
, len
, IOV_SET
,
3600 case WLC_GET_KEY_SEQ
:{
3603 if (len
< DOT11_WPA_KEY_RSC_LEN
) {
3604 bcmerror
= BCME_BUFTOOSHORT
;
3608 /* Return the key's tx iv as an EAPOL sequence counter.
3609 * This will be used to supply the RSC value to a supplicant.
3610 * The format is 8 bytes, with least significant in seq[0].
3613 key
= WSEC_KEY(wlc
, val
);
3614 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
)) &&
3616 u8 seq
[DOT11_WPA_KEY_RSC_LEN
];
3619 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3620 if ((bsscfg
->WPA_auth
& WPA_AUTH_NONE
) &&
3621 is_zero_ether_addr(key
->ea
)) {
3622 lo
= bsscfg
->wpa_none_txiv
.lo
;
3623 hi
= bsscfg
->wpa_none_txiv
.hi
;
3629 /* format the buffer, low to high */
3631 seq
[1] = (lo
>> 8) & 0xff;
3633 seq
[3] = (hi
>> 8) & 0xff;
3634 seq
[4] = (hi
>> 16) & 0xff;
3635 seq
[5] = (hi
>> 24) & 0xff;
3639 memcpy(arg
, seq
, sizeof(seq
));
3641 bcmerror
= BCME_BADKEYIDX
;
3646 case WLC_GET_CURR_RATESET
:{
3647 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3650 if (bsscfg
->associated
)
3651 rs
= ¤t_bss
->rateset
;
3653 rs
= &wlc
->default_bss
->rateset
;
3655 if (len
< (int)(rs
->count
+ sizeof(rs
->count
))) {
3656 bcmerror
= BCME_BUFTOOSHORT
;
3660 /* Copy only legacy rateset section */
3661 ret_rs
->count
= rs
->count
;
3662 memcpy(&ret_rs
->rates
, &rs
->rates
, rs
->count
);
3666 case WLC_GET_RATESET
:{
3668 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3670 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3671 wlc_default_rateset(wlc
, (wlc_rateset_t
*) &rs
);
3673 if (len
< (int)(rs
.count
+ sizeof(rs
.count
))) {
3674 bcmerror
= BCME_BUFTOOSHORT
;
3678 /* Copy only legacy rateset section */
3679 ret_rs
->count
= rs
.count
;
3680 memcpy(&ret_rs
->rates
, &rs
.rates
, rs
.count
);
3684 case WLC_SET_RATESET
:{
3686 wl_rateset_t
*in_rs
= (wl_rateset_t
*) arg
;
3688 if (len
< (int)(in_rs
->count
+ sizeof(in_rs
->count
))) {
3689 bcmerror
= BCME_BUFTOOSHORT
;
3693 if (in_rs
->count
> WLC_NUMRATES
) {
3694 bcmerror
= BCME_BUFTOOLONG
;
3698 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3700 /* Copy only legacy rateset section */
3701 rs
.count
= in_rs
->count
;
3702 memcpy(&rs
.rates
, &in_rs
->rates
, rs
.count
);
3704 /* merge rateset coming in with the current mcsset */
3705 if (N_ENAB(wlc
->pub
)) {
3706 if (bsscfg
->associated
)
3708 ¤t_bss
->rateset
.mcs
[0],
3712 &wlc
->default_bss
->rateset
.mcs
[0],
3716 bcmerror
= wlc_set_rateset(wlc
, &rs
);
3719 wlc_ofdm_rateset_war(wlc
);
3724 case WLC_GET_BCNPRD
:
3725 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3726 *pval
= current_bss
->beacon_period
;
3728 *pval
= wlc
->default_bss
->beacon_period
;
3731 case WLC_SET_BCNPRD
:
3732 /* range [1, 0xffff] */
3733 if (val
>= DOT11_MIN_BEACON_PERIOD
3734 && val
<= DOT11_MAX_BEACON_PERIOD
) {
3735 wlc
->default_bss
->beacon_period
= (u16
) val
;
3737 bcmerror
= BCME_RANGE
;
3740 case WLC_GET_DTIMPRD
:
3741 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3742 *pval
= current_bss
->dtim_period
;
3744 *pval
= wlc
->default_bss
->dtim_period
;
3747 case WLC_SET_DTIMPRD
:
3748 /* range [1, 0xff] */
3749 if (val
>= DOT11_MIN_DTIM_PERIOD
3750 && val
<= DOT11_MAX_DTIM_PERIOD
) {
3751 wlc
->default_bss
->dtim_period
= (u8
) val
;
3753 bcmerror
= BCME_RANGE
;
3762 if ((val
>= PM_OFF
) && (val
<= PM_MAX
)) {
3766 /* Change watchdog driver to align watchdog with tbtt if possible */
3767 wlc_watchdog_upd(wlc
, PS_ALLOWED(wlc
));
3769 bcmerror
= BCME_ERROR
;
3771 #endif /* SUPPORT_PS */
3776 if (AP_ENAB(wlc
->pub
)) {
3777 bcmerror
= BCME_NOTSTA
;
3784 if (AP_ENAB(wlc
->pub
)) {
3785 bcmerror
= BCME_NOTSTA
;
3789 wlc
->wake
= val
? true : false;
3791 /* if down, we're done */
3795 /* apply to the mac */
3796 wlc_set_ps_ctrl(wlc
);
3799 #endif /* SUPPORT_PS */
3801 case WLC_GET_REVINFO
:
3802 bcmerror
= wlc_get_revision_info(wlc
, arg
, (uint
) len
);
3806 *pval
= (int)AP_ENAB(wlc
->pub
);
3810 if (bsscfg
->associated
)
3811 *pval
= (int)current_bss
->atim_window
;
3813 *pval
= (int)wlc
->default_bss
->atim_window
;
3817 wlc
->default_bss
->atim_window
= (u32
) val
;
3820 case WLC_GET_PKTCNTS
:{
3821 get_pktcnt_t
*pktcnt
= (get_pktcnt_t
*) pval
;
3823 pktcnt
->rx_good_pkt
= wlc
->pub
->_cnt
->rxframe
;
3824 pktcnt
->rx_bad_pkt
= wlc
->pub
->_cnt
->rxerror
;
3825 pktcnt
->tx_good_pkt
=
3826 wlc
->pub
->_cnt
->txfrmsnt
;
3827 pktcnt
->tx_bad_pkt
=
3828 wlc
->pub
->_cnt
->txerror
+
3829 wlc
->pub
->_cnt
->txfail
;
3830 if (len
>= (int)sizeof(get_pktcnt_t
)) {
3831 /* Be backward compatible - only if buffer is large enough */
3832 pktcnt
->rx_ocast_good_pkt
=
3833 wlc
->pub
->_cnt
->rxmfrmocast
;
3838 #ifdef SUPPORT_HWKEY
3841 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_GET
,
3847 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_SET
,
3851 case WLC_GET_WPA_AUTH
:
3852 *pval
= (int)bsscfg
->WPA_auth
;
3855 case WLC_SET_WPA_AUTH
:
3856 /* change of WPA_Auth modifies the PS_ALLOWED state */
3857 if (BSSCFG_STA(bsscfg
)) {
3858 bsscfg
->WPA_auth
= (u16
) val
;
3860 bsscfg
->WPA_auth
= (u16
) val
;
3862 #endif /* SUPPORT_HWKEY */
3864 case WLC_GET_BANDLIST
:
3865 /* count of number of bands, followed by each band type */
3866 *pval
++ = NBANDS(wlc
);
3867 *pval
++ = wlc
->band
->bandtype
;
3868 if (NBANDS(wlc
) > 1)
3869 *pval
++ = wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
;
3873 *pval
= wlc
->bandlocked
? wlc
->band
->bandtype
: WLC_BAND_AUTO
;
3876 case WLC_GET_PHYLIST
:
3878 unsigned char *cp
= arg
;
3880 bcmerror
= BCME_BUFTOOSHORT
;
3884 if (WLCISNPHY(wlc
->band
)) {
3886 } else if (WLCISLCNPHY(wlc
->band
)) {
3888 } else if (WLCISSSLPNPHY(wlc
->band
)) {
3895 case WLC_GET_SHORTSLOT
:
3896 *pval
= wlc
->shortslot
;
3899 case WLC_GET_SHORTSLOT_OVERRIDE
:
3900 *pval
= wlc
->shortslot_override
;
3903 case WLC_SET_SHORTSLOT_OVERRIDE
:
3904 if ((val
!= WLC_SHORTSLOT_AUTO
) &&
3905 (val
!= WLC_SHORTSLOT_OFF
) && (val
!= WLC_SHORTSLOT_ON
)) {
3906 bcmerror
= BCME_RANGE
;
3910 wlc
->shortslot_override
= (s8
) val
;
3912 /* shortslot is an 11g feature, so no more work if we are
3913 * currently on the 5G band
3915 if (BAND_5G(wlc
->band
->bandtype
))
3918 if (wlc
->pub
->up
&& wlc
->pub
->associated
) {
3919 /* let watchdog or beacon processing update shortslot */
3920 } else if (wlc
->pub
->up
) {
3921 /* unassociated shortslot is off */
3922 wlc_switch_shortslot(wlc
, false);
3924 /* driver is down, so just update the wlc_info value */
3925 if (wlc
->shortslot_override
== WLC_SHORTSLOT_AUTO
) {
3926 wlc
->shortslot
= false;
3929 (wlc
->shortslot_override
==
3936 case WLC_GET_LEGACY_ERP
:
3937 *pval
= wlc
->include_legacy_erp
;
3940 case WLC_SET_LEGACY_ERP
:
3941 if (wlc
->include_legacy_erp
== bool_val
)
3944 wlc
->include_legacy_erp
= bool_val
;
3946 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
3947 wlc_update_beacon(wlc
);
3948 wlc_update_probe_resp(wlc
, true);
3953 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
3954 *pval
= wlc
->band
->gmode
;
3955 else if (NBANDS(wlc
) > 1)
3956 *pval
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
;
3960 if (!wlc
->pub
->associated
)
3961 bcmerror
= wlc_set_gmode(wlc
, (u8
) val
, true);
3963 bcmerror
= BCME_ASSOCIATED
;
3968 case WLC_GET_GMODE_PROTECTION
:
3969 *pval
= wlc
->protection
->_g
;
3972 case WLC_GET_PROTECTION_CONTROL
:
3973 *pval
= wlc
->protection
->overlap
;
3976 case WLC_SET_PROTECTION_CONTROL
:
3977 if ((val
!= WLC_PROTECTION_CTL_OFF
) &&
3978 (val
!= WLC_PROTECTION_CTL_LOCAL
) &&
3979 (val
!= WLC_PROTECTION_CTL_OVERLAP
)) {
3980 bcmerror
= BCME_RANGE
;
3984 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, (s8
) val
);
3986 /* Current g_protection will sync up to the specified control alg in watchdog
3987 * if the driver is up and associated.
3988 * If the driver is down or not associated, the control setting has no effect.
3992 case WLC_GET_GMODE_PROTECTION_OVERRIDE
:
3993 *pval
= wlc
->protection
->g_override
;
3996 case WLC_SET_GMODE_PROTECTION_OVERRIDE
:
3997 if ((val
!= WLC_PROTECTION_AUTO
) &&
3998 (val
!= WLC_PROTECTION_OFF
) && (val
!= WLC_PROTECTION_ON
)) {
3999 bcmerror
= BCME_RANGE
;
4003 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, (s8
) val
);
4007 case WLC_SET_SUP_RATESET_OVERRIDE
:{
4008 wlc_rateset_t rs
, new;
4011 if (len
< (int)sizeof(wlc_rateset_t
)) {
4012 bcmerror
= BCME_BUFTOOSHORT
;
4015 memcpy(&rs
, arg
, sizeof(wlc_rateset_t
));
4017 /* check for bad count value */
4018 if (rs
.count
> WLC_NUMRATES
) {
4019 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4023 /* this command is only appropriate for gmode operation */
4024 if (!(wlc
->band
->gmode
||
4026 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4027 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4031 /* check for an empty rateset to clear the override */
4032 if (rs
.count
== 0) {
4033 memset(&wlc
->sup_rates_override
, 0,
4034 sizeof(wlc_rateset_t
));
4038 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4039 wlc_rateset_filter(&rs
, &new, false, WLC_RATES_CCK_OFDM
,
4040 RATE_MASK
, BSS_N_ENAB(wlc
, bsscfg
));
4041 wlc_rate_hwrs_filter_sort_validate(&new,
4044 wlc
->stf
->txstreams
);
4045 if (rs
.count
!= new.count
) {
4046 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4050 /* apply new rateset to the override */
4051 memcpy(&wlc
->sup_rates_override
, &new,
4052 sizeof(wlc_rateset_t
));
4054 /* update bcn and probe resp if needed */
4055 if (wlc
->pub
->up
&& AP_ENAB(wlc
->pub
)
4056 && wlc
->pub
->associated
) {
4057 wlc_update_beacon(wlc
);
4058 wlc_update_probe_resp(wlc
, true);
4063 case WLC_GET_SUP_RATESET_OVERRIDE
:
4064 /* this command is only appropriate for gmode operation */
4065 if (!(wlc
->band
->gmode
||
4067 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4068 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4071 if (len
< (int)sizeof(wlc_rateset_t
)) {
4072 bcmerror
= BCME_BUFTOOSHORT
;
4075 memcpy(arg
, &wlc
->sup_rates_override
, sizeof(wlc_rateset_t
));
4079 case WLC_GET_PRB_RESP_TIMEOUT
:
4080 *pval
= wlc
->prb_resp_timeout
;
4083 case WLC_SET_PRB_RESP_TIMEOUT
:
4085 bcmerror
= BCME_NOTDOWN
;
4088 if (val
< 0 || val
>= 0xFFFF) {
4089 bcmerror
= BCME_RANGE
; /* bad value */
4092 wlc
->prb_resp_timeout
= (u16
) val
;
4095 case WLC_GET_KEY_PRIMARY
:{
4098 /* treat the 'val' parm as the key id */
4099 key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4101 *pval
= key
->id
== val
? true : false;
4103 bcmerror
= BCME_BADKEYIDX
;
4108 case WLC_SET_KEY_PRIMARY
:{
4109 wsec_key_t
*key
, *old_key
;
4111 bcmerror
= BCME_BADKEYIDX
;
4113 /* treat the 'val' parm as the key id */
4114 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
4115 key
= bsscfg
->bss_def_keys
[i
];
4116 if (key
!= NULL
&& key
->id
== val
) {
4117 old_key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4118 if (old_key
!= NULL
)
4121 key
->flags
|= WSEC_PRIMARY_KEY
;
4122 bsscfg
->wsec_index
= i
;
4138 /* validate the name value */
4140 for (i
= 0; i
< (uint
) len
&& *name
!= '\0';
4144 if (i
== (uint
) len
) {
4145 bcmerror
= BCME_BUFTOOSHORT
;
4148 i
++; /* include the null in the string length */
4150 if (cmd
== WLC_GET_VAR
) {
4152 wlc_iovar_op(wlc
, arg
,
4153 (void *)((s8
*) arg
+ i
),
4154 len
- i
, arg
, len
, IOV_GET
,
4158 wlc_iovar_op(wlc
, arg
, NULL
, 0,
4159 (void *)((s8
*) arg
+ i
),
4160 len
- i
, IOV_SET
, wlcif
);
4165 case WLC_SET_WSEC_PMK
:
4166 bcmerror
= BCME_UNSUPPORTED
;
4170 case WLC_CURRENT_PWR
:
4172 bcmerror
= BCME_NOTUP
;
4174 bcmerror
= wlc_get_current_txpwr(wlc
, arg
, len
);
4179 WL_ERROR("%s: WLC_LAST\n", __func__
);
4184 if (VALID_BCMERROR(bcmerror
))
4185 wlc
->pub
->bcmerror
= bcmerror
;
4191 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4192 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4193 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4195 if (!(wlc
->pub
->hw_off
))
4196 ASSERT(wlc_bmac_taclear(wlc
->hw
, ta_ok
) || !ta_ok
);
4202 /* consolidated register access ioctl error checking */
4203 int wlc_iocregchk(struct wlc_info
*wlc
, uint band
)
4205 /* if band is specified, it must be the current band */
4206 if ((band
!= WLC_BAND_AUTO
) && (band
!= (uint
) wlc
->band
->bandtype
))
4207 return BCME_BADBAND
;
4209 /* if multiband and band is not specified, band must be locked */
4210 if ((band
== WLC_BAND_AUTO
) && IS_MBAND_UNLOCKED(wlc
))
4211 return BCME_NOTBANDLOCKED
;
4213 /* must have core clocks */
4219 #endif /* defined(BCMDBG) */
4222 /* For some ioctls, make sure that the pi pointer matches the current phy */
4223 int wlc_iocpichk(struct wlc_info
*wlc
, uint phytype
)
4225 if (wlc
->band
->phytype
!= phytype
)
4226 return BCME_BADBAND
;
4231 /* Look up the given var name in the given table */
4232 static const bcm_iovar_t
*wlc_iovar_lookup(const bcm_iovar_t
*table
,
4235 const bcm_iovar_t
*vi
;
4236 const char *lookup_name
;
4238 /* skip any ':' delimited option prefixes */
4239 lookup_name
= strrchr(name
, ':');
4240 if (lookup_name
!= NULL
)
4245 ASSERT(table
!= NULL
);
4247 for (vi
= table
; vi
->name
; vi
++) {
4248 if (!strcmp(vi
->name
, lookup_name
))
4251 /* ran to end of table */
4253 return NULL
; /* var name not found */
4256 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4257 int wlc_iovar_getint(struct wlc_info
*wlc
, const char *name
, int *arg
)
4259 return wlc_iovar_op(wlc
, name
, NULL
, 0, arg
, sizeof(s32
), IOV_GET
,
4263 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4264 int wlc_iovar_setint(struct wlc_info
*wlc
, const char *name
, int arg
)
4266 return wlc_iovar_op(wlc
, name
, NULL
, 0, (void *)&arg
, sizeof(arg
),
4270 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4271 int wlc_iovar_gets8(struct wlc_info
*wlc
, const char *name
, s8
*arg
)
4277 wlc_iovar_op(wlc
, name
, NULL
, 0, &iovar_int
, sizeof(iovar_int
),
4280 *arg
= (s8
) iovar_int
;
4286 * register iovar table, watchdog and down handlers.
4287 * calling function must keep 'iovars' until wlc_module_unregister is called.
4288 * 'iovar' must have the last entry's name field being NULL as terminator.
4290 int wlc_module_register(struct wlc_pub
*pub
, const bcm_iovar_t
*iovars
,
4291 const char *name
, void *hdl
, iovar_fn_t i_fn
,
4292 watchdog_fn_t w_fn
, down_fn_t d_fn
)
4294 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4297 ASSERT(name
!= NULL
);
4298 ASSERT(i_fn
!= NULL
|| w_fn
!= NULL
|| d_fn
!= NULL
);
4300 /* find an empty entry and just add, no duplication check! */
4301 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4302 if (wlc
->modulecb
[i
].name
[0] == '\0') {
4303 strncpy(wlc
->modulecb
[i
].name
, name
,
4304 sizeof(wlc
->modulecb
[i
].name
) - 1);
4305 wlc
->modulecb
[i
].iovars
= iovars
;
4306 wlc
->modulecb
[i
].hdl
= hdl
;
4307 wlc
->modulecb
[i
].iovar_fn
= i_fn
;
4308 wlc
->modulecb
[i
].watchdog_fn
= w_fn
;
4309 wlc
->modulecb
[i
].down_fn
= d_fn
;
4314 /* it is time to increase the capacity */
4315 ASSERT(i
< WLC_MAXMODULES
);
4316 return BCME_NORESOURCE
;
4319 /* unregister module callbacks */
4320 int wlc_module_unregister(struct wlc_pub
*pub
, const char *name
, void *hdl
)
4322 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4326 return BCME_NOTFOUND
;
4328 ASSERT(name
!= NULL
);
4330 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4331 if (!strcmp(wlc
->modulecb
[i
].name
, name
) &&
4332 (wlc
->modulecb
[i
].hdl
== hdl
)) {
4333 memset(&wlc
->modulecb
[i
], 0, sizeof(struct modulecb
));
4338 /* table not found! */
4339 return BCME_NOTFOUND
;
4342 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4343 static void wlc_wme_retries_write(struct wlc_info
*wlc
)
4347 /* Need clock to do this */
4351 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
4352 wlc_write_shm(wlc
, M_AC_TXLMT_ADDR(ac
), wlc
->wme_retries
[ac
]);
4356 /* Get or set an iovar. The params/p_len pair specifies any additional
4357 * qualifying parameters (e.g. an "element index") for a get, while the
4358 * arg/len pair is the buffer for the value to be set or retrieved.
4359 * Operation (get/set) is specified by the last argument.
4360 * interface context provided by wlcif
4362 * All pointers may point into the same buffer.
4365 wlc_iovar_op(struct wlc_info
*wlc
, const char *name
,
4366 void *params
, int p_len
, void *arg
, int len
,
4367 bool set
, struct wlc_if
*wlcif
)
4371 const bcm_iovar_t
*vi
= NULL
;
4375 ASSERT(name
!= NULL
);
4379 /* Get MUST have return space */
4380 ASSERT(set
|| (arg
&& len
));
4382 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
4384 /* Set does NOT take qualifiers */
4385 ASSERT(!set
|| (!params
&& !p_len
));
4387 if (!set
&& (len
== sizeof(int)) &&
4388 !(IS_ALIGNED((unsigned long)(arg
), (uint
) sizeof(int)))) {
4389 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4390 wlc
->pub
->unit
, __func__
, name
);
4394 /* find the given iovar name */
4395 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4396 if (!wlc
->modulecb
[i
].iovars
)
4398 vi
= wlc_iovar_lookup(wlc
->modulecb
[i
].iovars
, name
);
4402 /* iovar name not found */
4403 if (i
>= WLC_MAXMODULES
) {
4404 err
= BCME_UNSUPPORTED
;
4408 /* set up 'params' pointer in case this is a set command so that
4409 * the convenience int and bool code can be common to set and get
4411 if (params
== NULL
) {
4416 if (vi
->type
== IOVT_VOID
)
4418 else if (vi
->type
== IOVT_BUFFER
)
4421 /* all other types are integer sized */
4422 val_size
= sizeof(int);
4424 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
4426 /* Do the actual parameter implementation */
4427 err
= wlc
->modulecb
[i
].iovar_fn(wlc
->modulecb
[i
].hdl
, vi
, actionid
,
4428 name
, params
, p_len
, arg
, len
, val_size
,
4436 wlc_iovar_check(struct wlc_pub
*pub
, const bcm_iovar_t
*vi
, void *arg
, int len
,
4439 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4443 /* check generic condition flags */
4445 if (((vi
->flags
& IOVF_SET_DOWN
) && wlc
->pub
->up
) ||
4446 ((vi
->flags
& IOVF_SET_UP
) && !wlc
->pub
->up
)) {
4447 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4448 } else if ((vi
->flags
& IOVF_SET_BAND
)
4449 && IS_MBAND_UNLOCKED(wlc
)) {
4450 err
= BCME_NOTBANDLOCKED
;
4451 } else if ((vi
->flags
& IOVF_SET_CLK
) && !wlc
->clk
) {
4455 if (((vi
->flags
& IOVF_GET_DOWN
) && wlc
->pub
->up
) ||
4456 ((vi
->flags
& IOVF_GET_UP
) && !wlc
->pub
->up
)) {
4457 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4458 } else if ((vi
->flags
& IOVF_GET_BAND
)
4459 && IS_MBAND_UNLOCKED(wlc
)) {
4460 err
= BCME_NOTBANDLOCKED
;
4461 } else if ((vi
->flags
& IOVF_GET_CLK
) && !wlc
->clk
) {
4469 /* length check on io buf */
4470 err
= bcm_iovar_lencheck(vi
, arg
, len
, set
);
4474 /* On set, check value ranges for integer types */
4484 memcpy(&int_val
, arg
, sizeof(int));
4485 err
= wlc_iovar_rangecheck(wlc
, int_val
, vi
);
4493 /* handler for iovar table wlc_iovars */
4495 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4496 * iovar case, the switch statement maps the iovar id into separate get
4497 * and set values. If you add a new iovar to the switch you MUST use
4498 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4500 * Please use params for additional qualifying parameters.
4503 wlc_doiovar(void *hdl
, const bcm_iovar_t
*vi
, u32 actionid
,
4504 const char *name
, void *params
, uint p_len
, void *arg
, int len
,
4505 int val_size
, struct wlc_if
*wlcif
)
4507 struct wlc_info
*wlc
= hdl
;
4508 struct wlc_bsscfg
*bsscfg
;
4515 wlc_bss_info_t
*current_bss
;
4517 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
4522 err
= wlc_iovar_check(wlc
->pub
, vi
, arg
, len
, IOV_ISSET(actionid
));
4526 /* convenience int and bool vals for first 8 bytes of buffer */
4527 if (p_len
>= (int)sizeof(int_val
))
4528 memcpy(&int_val
, params
, sizeof(int_val
));
4530 if (p_len
>= (int)sizeof(int_val
) * 2)
4532 (void *)((unsigned long)params
+ sizeof(int_val
)),
4535 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4536 ret_int_ptr
= (s32
*) arg
;
4538 bool_val
= (int_val
!= 0) ? true : false;
4539 bool_val2
= (int_val2
!= 0) ? true : false;
4541 WL_TRACE("wl%d: %s: id %d\n",
4542 wlc
->pub
->unit
, __func__
, IOV_ID(actionid
));
4543 /* Do the actual parameter implementation */
4545 case IOV_SVAL(IOV_RTSTHRESH
):
4546 wlc
->RTSThresh
= int_val
;
4549 case IOV_GVAL(IOV_QTXPOWER
):{
4553 err
= wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
,
4558 /* Return qdbm units */
4560 qdbm
| (override
? WL_TXPWR_OVERRIDE
: 0);
4564 /* As long as override is false, this only sets the *user* targets.
4565 User can twiddle this all he wants with no harm.
4566 wlc_phy_txpower_set() explicitly sets override to false if
4567 not internal or test.
4569 case IOV_SVAL(IOV_QTXPOWER
):{
4573 /* Remove override bit and clip to max qdbm value */
4574 qdbm
= (u8
)min_t(u32
, (int_val
& ~WL_TXPWR_OVERRIDE
), 0xff);
4575 /* Extract override setting */
4576 override
= (int_val
& WL_TXPWR_OVERRIDE
) ? true : false;
4578 wlc_phy_txpower_set(wlc
->band
->pi
, qdbm
, override
);
4582 case IOV_GVAL(IOV_MPC
):
4583 *ret_int_ptr
= (s32
) wlc
->mpc
;
4586 case IOV_SVAL(IOV_MPC
):
4587 wlc
->mpc
= bool_val
;
4588 wlc_radio_mpc_upd(wlc
);
4592 case IOV_GVAL(IOV_BCN_LI_BCN
):
4593 *ret_int_ptr
= wlc
->bcn_li_bcn
;
4596 case IOV_SVAL(IOV_BCN_LI_BCN
):
4597 wlc
->bcn_li_bcn
= (u8
) int_val
;
4599 wlc_bcn_li_upd(wlc
);
4603 WL_ERROR("wl%d: %s: unsupported\n", wlc
->pub
->unit
, __func__
);
4604 err
= BCME_UNSUPPORTED
;
4608 goto exit
; /* avoid unused label warning */
4615 wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
, const bcm_iovar_t
*vi
)
4621 /* Only ranged integers are checked */
4624 max_val
|= 0x7fffffff;
4627 max_val
|= 0x00007fff;
4630 max_val
|= 0x0000007f;
4632 if (vi
->flags
& IOVF_NTRL
)
4634 else if (vi
->flags
& IOVF_WHL
)
4636 /* Signed values are checked against max_val and min_val */
4637 if ((s32
) val
< (s32
) min_val
4638 || (s32
) val
> (s32
) max_val
)
4643 max_val
|= 0xffffffff;
4646 max_val
|= 0x0000ffff;
4649 max_val
|= 0x000000ff;
4650 if (vi
->flags
& IOVF_NTRL
)
4652 if ((val
< min_val
) || (val
> max_val
))
4661 static const char *supr_reason
[] = {
4662 "None", "PMQ Entry", "Flush request",
4663 "Previous frag failure", "Channel mismatch",
4664 "Lifetime Expiry", "Underflow"
4667 static void wlc_print_txs_status(u16 s
)
4669 printk(KERN_DEBUG
"[15:12] %d frame attempts\n",
4670 (s
& TX_STATUS_FRM_RTX_MASK
) >> TX_STATUS_FRM_RTX_SHIFT
);
4671 printk(KERN_DEBUG
" [11:8] %d rts attempts\n",
4672 (s
& TX_STATUS_RTS_RTX_MASK
) >> TX_STATUS_RTS_RTX_SHIFT
);
4673 printk(KERN_DEBUG
" [7] %d PM mode indicated\n",
4674 ((s
& TX_STATUS_PMINDCTD
) ? 1 : 0));
4675 printk(KERN_DEBUG
" [6] %d intermediate status\n",
4676 ((s
& TX_STATUS_INTERMEDIATE
) ? 1 : 0));
4677 printk(KERN_DEBUG
" [5] %d AMPDU\n",
4678 (s
& TX_STATUS_AMPDU
) ? 1 : 0);
4679 printk(KERN_DEBUG
" [4:2] %d Frame Suppressed Reason (%s)\n",
4680 ((s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
),
4681 supr_reason
[(s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
]);
4682 printk(KERN_DEBUG
" [1] %d acked\n",
4683 ((s
& TX_STATUS_ACK_RCV
) ? 1 : 0));
4687 void wlc_print_txstatus(tx_status_t
*txs
)
4690 u16 s
= txs
->status
;
4691 u16 ackphyrxsh
= txs
->ackphyrxsh
;
4693 printk(KERN_DEBUG
"\ntxpkt (MPDU) Complete\n");
4695 printk(KERN_DEBUG
"FrameID: %04x ", txs
->frameid
);
4696 printk(KERN_DEBUG
"TxStatus: %04x", s
);
4697 printk(KERN_DEBUG
"\n");
4699 wlc_print_txs_status(s
);
4701 printk(KERN_DEBUG
"LastTxTime: %04x ", txs
->lasttxtime
);
4702 printk(KERN_DEBUG
"Seq: %04x ", txs
->sequence
);
4703 printk(KERN_DEBUG
"PHYTxStatus: %04x ", txs
->phyerr
);
4704 printk(KERN_DEBUG
"RxAckRSSI: %04x ",
4705 (ackphyrxsh
& PRXS1_JSSI_MASK
) >> PRXS1_JSSI_SHIFT
);
4706 printk(KERN_DEBUG
"RxAckSQ: %04x",
4707 (ackphyrxsh
& PRXS1_SQ_MASK
) >> PRXS1_SQ_SHIFT
);
4708 printk(KERN_DEBUG
"\n");
4709 #endif /* defined(BCMDBG) */
4713 wlc_ctrupd_cache(u16 cur_stat
, u16
*macstat_snapshot
, u32
*macstat
)
4718 v
= le16_to_cpu(cur_stat
);
4719 delta
= (u16
)(v
- *macstat_snapshot
);
4723 *macstat_snapshot
= v
;
4727 #define MACSTATUPD(name) \
4728 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4730 void wlc_statsupd(struct wlc_info
*wlc
)
4740 /* if driver down, make no sense to update stats */
4745 /* save last rx fifo 0 overflow count */
4746 rxf0ovfl
= wlc
->core
->macstat_snapshot
->rxf0ovfl
;
4748 /* save last tx fifo underflow count */
4749 for (i
= 0; i
< NFIFO
; i
++)
4750 txfunfl
[i
] = wlc
->core
->macstat_snapshot
->txfunfl
[i
];
4753 /* Read mac stats from contiguous shared memory */
4754 wlc_bmac_copyfrom_shm(wlc
->hw
, M_UCODE_MACSTAT
,
4755 &macstats
, sizeof(macstat_t
));
4757 /* update mac stats */
4758 MACSTATUPD(txallfrm
);
4759 MACSTATUPD(txrtsfrm
);
4760 MACSTATUPD(txctsfrm
);
4761 MACSTATUPD(txackfrm
);
4762 MACSTATUPD(txdnlfrm
);
4763 MACSTATUPD(txbcnfrm
);
4764 for (i
= 0; i
< NFIFO
; i
++)
4765 MACSTATUPD(txfunfl
[i
]);
4766 MACSTATUPD(txtplunfl
);
4767 MACSTATUPD(txphyerr
);
4768 MACSTATUPD(rxfrmtoolong
);
4769 MACSTATUPD(rxfrmtooshrt
);
4770 MACSTATUPD(rxinvmachdr
);
4771 MACSTATUPD(rxbadfcs
);
4772 MACSTATUPD(rxbadplcp
);
4773 MACSTATUPD(rxcrsglitch
);
4775 MACSTATUPD(rxdfrmucastmbss
);
4776 MACSTATUPD(rxmfrmucastmbss
);
4777 MACSTATUPD(rxcfrmucast
);
4778 MACSTATUPD(rxrtsucast
);
4779 MACSTATUPD(rxctsucast
);
4780 MACSTATUPD(rxackucast
);
4781 MACSTATUPD(rxdfrmocast
);
4782 MACSTATUPD(rxmfrmocast
);
4783 MACSTATUPD(rxcfrmocast
);
4784 MACSTATUPD(rxrtsocast
);
4785 MACSTATUPD(rxctsocast
);
4786 MACSTATUPD(rxdfrmmcast
);
4787 MACSTATUPD(rxmfrmmcast
);
4788 MACSTATUPD(rxcfrmmcast
);
4789 MACSTATUPD(rxbeaconmbss
);
4790 MACSTATUPD(rxdfrmucastobss
);
4791 MACSTATUPD(rxbeaconobss
);
4792 MACSTATUPD(rxrsptmout
);
4793 MACSTATUPD(bcntxcancl
);
4794 MACSTATUPD(rxf0ovfl
);
4795 MACSTATUPD(rxf1ovfl
);
4796 MACSTATUPD(rxf2ovfl
);
4797 MACSTATUPD(txsfovfl
);
4798 MACSTATUPD(pmqovfl
);
4799 MACSTATUPD(rxcgprqfrm
);
4800 MACSTATUPD(rxcgprsqovfl
);
4801 MACSTATUPD(txcgprsfail
);
4802 MACSTATUPD(txcgprssuc
);
4803 MACSTATUPD(prs_timeout
);
4805 MACSTATUPD(frmscons
);
4807 MACSTATUPD(txglitch_nack
);
4808 MACSTATUPD(txburst
);
4809 MACSTATUPD(phywatchdog
);
4810 MACSTATUPD(pktengrxducast
);
4811 MACSTATUPD(pktengrxdmcast
);
4814 /* check for rx fifo 0 overflow */
4815 delta
= (u16
) (wlc
->core
->macstat_snapshot
->rxf0ovfl
- rxf0ovfl
);
4817 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4818 wlc
->pub
->unit
, delta
);
4820 /* check for tx fifo underflows */
4821 for (i
= 0; i
< NFIFO
; i
++) {
4823 (u16
) (wlc
->core
->macstat_snapshot
->txfunfl
[i
] -
4826 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4827 wlc
->pub
->unit
, delta
, i
);
4831 /* dot11 counter update */
4833 WLCNTSET(wlc
->pub
->_cnt
->txrts
,
4834 (wlc
->pub
->_cnt
->rxctsucast
-
4835 wlc
->pub
->_cnt
->d11cnt_txrts_off
));
4836 WLCNTSET(wlc
->pub
->_cnt
->rxcrc
,
4837 (wlc
->pub
->_cnt
->rxbadfcs
- wlc
->pub
->_cnt
->d11cnt_rxcrc_off
));
4838 WLCNTSET(wlc
->pub
->_cnt
->txnocts
,
4839 ((wlc
->pub
->_cnt
->txrtsfrm
- wlc
->pub
->_cnt
->rxctsucast
) -
4840 wlc
->pub
->_cnt
->d11cnt_txnocts_off
));
4842 /* merge counters from dma module */
4843 for (i
= 0; i
< NFIFO
; i
++) {
4844 if (wlc
->hw
->di
[i
]) {
4845 WLCNTADD(wlc
->pub
->_cnt
->txnobuf
,
4846 (wlc
->hw
->di
[i
])->txnobuf
);
4847 WLCNTADD(wlc
->pub
->_cnt
->rxnobuf
,
4848 (wlc
->hw
->di
[i
])->rxnobuf
);
4849 WLCNTADD(wlc
->pub
->_cnt
->rxgiant
,
4850 (wlc
->hw
->di
[i
])->rxgiants
);
4851 dma_counterreset(wlc
->hw
->di
[i
]);
4856 * Aggregate transmit and receive errors that probably resulted
4857 * in the loss of a frame are computed on the fly.
4859 WLCNTSET(wlc
->pub
->_cnt
->txerror
,
4860 wlc
->pub
->_cnt
->txnobuf
+ wlc
->pub
->_cnt
->txnoassoc
+
4861 wlc
->pub
->_cnt
->txuflo
+ wlc
->pub
->_cnt
->txrunt
+
4862 wlc
->pub
->_cnt
->dmade
+ wlc
->pub
->_cnt
->dmada
+
4863 wlc
->pub
->_cnt
->dmape
);
4864 WLCNTSET(wlc
->pub
->_cnt
->rxerror
,
4865 wlc
->pub
->_cnt
->rxoflo
+ wlc
->pub
->_cnt
->rxnobuf
+
4866 wlc
->pub
->_cnt
->rxfragerr
+ wlc
->pub
->_cnt
->rxrunt
+
4867 wlc
->pub
->_cnt
->rxgiant
+ wlc
->pub
->_cnt
->rxnoscb
+
4868 wlc
->pub
->_cnt
->rxbadsrcmac
);
4869 for (i
= 0; i
< NFIFO
; i
++)
4870 wlc
->pub
->_cnt
->rxerror
+= wlc
->pub
->_cnt
->rxuflo
[i
];
4873 bool wlc_chipmatch(u16 vendor
, u16 device
)
4875 if (vendor
!= PCI_VENDOR_ID_BROADCOM
) {
4876 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor
);
4880 if ((device
== BCM43224_D11N_ID
) || (device
== BCM43225_D11N2G_ID
))
4883 if (device
== BCM4313_D11N2G_ID
)
4885 if ((device
== BCM43236_D11N_ID
) || (device
== BCM43236_D11N2G_ID
))
4888 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device
);
4893 void wlc_print_txdesc(d11txh_t
*txh
)
4895 u16 mtcl
= le16_to_cpu(txh
->MacTxControlLow
);
4896 u16 mtch
= le16_to_cpu(txh
->MacTxControlHigh
);
4897 u16 mfc
= le16_to_cpu(txh
->MacFrameControl
);
4898 u16 tfest
= le16_to_cpu(txh
->TxFesTimeNormal
);
4899 u16 ptcw
= le16_to_cpu(txh
->PhyTxControlWord
);
4900 u16 ptcw_1
= le16_to_cpu(txh
->PhyTxControlWord_1
);
4901 u16 ptcw_1_Fbr
= le16_to_cpu(txh
->PhyTxControlWord_1_Fbr
);
4902 u16 ptcw_1_Rts
= le16_to_cpu(txh
->PhyTxControlWord_1_Rts
);
4903 u16 ptcw_1_FbrRts
= le16_to_cpu(txh
->PhyTxControlWord_1_FbrRts
);
4904 u16 mainrates
= le16_to_cpu(txh
->MainRates
);
4905 u16 xtraft
= le16_to_cpu(txh
->XtraFrameTypes
);
4907 u8
*ra
= txh
->TxFrameRA
;
4908 u16 tfestfb
= le16_to_cpu(txh
->TxFesTimeFallback
);
4909 u8
*rtspfb
= txh
->RTSPLCPFallback
;
4910 u16 rtsdfb
= le16_to_cpu(txh
->RTSDurFallback
);
4911 u8
*fragpfb
= txh
->FragPLCPFallback
;
4912 u16 fragdfb
= le16_to_cpu(txh
->FragDurFallback
);
4913 u16 mmodelen
= le16_to_cpu(txh
->MModeLen
);
4914 u16 mmodefbrlen
= le16_to_cpu(txh
->MModeFbrLen
);
4915 u16 tfid
= le16_to_cpu(txh
->TxFrameID
);
4916 u16 txs
= le16_to_cpu(txh
->TxStatus
);
4917 u16 mnmpdu
= le16_to_cpu(txh
->MaxNMpdus
);
4918 u16 mabyte
= le16_to_cpu(txh
->MaxABytes_MRT
);
4919 u16 mabyte_f
= le16_to_cpu(txh
->MaxABytes_FBR
);
4920 u16 mmbyte
= le16_to_cpu(txh
->MinMBytes
);
4922 u8
*rtsph
= txh
->RTSPhyHeader
;
4923 struct ieee80211_rts rts
= txh
->rts_frame
;
4926 /* add plcp header along with txh descriptor */
4927 prhex("Raw TxDesc + plcp header", (unsigned char *) txh
, sizeof(d11txh_t
) + 48);
4929 printk(KERN_DEBUG
"TxCtlLow: %04x ", mtcl
);
4930 printk(KERN_DEBUG
"TxCtlHigh: %04x ", mtch
);
4931 printk(KERN_DEBUG
"FC: %04x ", mfc
);
4932 printk(KERN_DEBUG
"FES Time: %04x\n", tfest
);
4933 printk(KERN_DEBUG
"PhyCtl: %04x%s ", ptcw
,
4934 (ptcw
& PHY_TXC_SHORT_HDR
) ? " short" : "");
4935 printk(KERN_DEBUG
"PhyCtl_1: %04x ", ptcw_1
);
4936 printk(KERN_DEBUG
"PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr
);
4937 printk(KERN_DEBUG
"PhyCtl_1_Rts: %04x ", ptcw_1_Rts
);
4938 printk(KERN_DEBUG
"PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts
);
4939 printk(KERN_DEBUG
"MainRates: %04x ", mainrates
);
4940 printk(KERN_DEBUG
"XtraFrameTypes: %04x ", xtraft
);
4941 printk(KERN_DEBUG
"\n");
4943 bcm_format_hex(hexbuf
, iv
, sizeof(txh
->IV
));
4944 printk(KERN_DEBUG
"SecIV: %s\n", hexbuf
);
4945 bcm_format_hex(hexbuf
, ra
, sizeof(txh
->TxFrameRA
));
4946 printk(KERN_DEBUG
"RA: %s\n", hexbuf
);
4948 printk(KERN_DEBUG
"Fb FES Time: %04x ", tfestfb
);
4949 bcm_format_hex(hexbuf
, rtspfb
, sizeof(txh
->RTSPLCPFallback
));
4950 printk(KERN_DEBUG
"RTS PLCP: %s ", hexbuf
);
4951 printk(KERN_DEBUG
"RTS DUR: %04x ", rtsdfb
);
4952 bcm_format_hex(hexbuf
, fragpfb
, sizeof(txh
->FragPLCPFallback
));
4953 printk(KERN_DEBUG
"PLCP: %s ", hexbuf
);
4954 printk(KERN_DEBUG
"DUR: %04x", fragdfb
);
4955 printk(KERN_DEBUG
"\n");
4957 printk(KERN_DEBUG
"MModeLen: %04x ", mmodelen
);
4958 printk(KERN_DEBUG
"MModeFbrLen: %04x\n", mmodefbrlen
);
4960 printk(KERN_DEBUG
"FrameID: %04x\n", tfid
);
4961 printk(KERN_DEBUG
"TxStatus: %04x\n", txs
);
4963 printk(KERN_DEBUG
"MaxNumMpdu: %04x\n", mnmpdu
);
4964 printk(KERN_DEBUG
"MaxAggbyte: %04x\n", mabyte
);
4965 printk(KERN_DEBUG
"MaxAggbyte_fb: %04x\n", mabyte_f
);
4966 printk(KERN_DEBUG
"MinByte: %04x\n", mmbyte
);
4968 bcm_format_hex(hexbuf
, rtsph
, sizeof(txh
->RTSPhyHeader
));
4969 printk(KERN_DEBUG
"RTS PLCP: %s ", hexbuf
);
4970 bcm_format_hex(hexbuf
, (u8
*) &rts
, sizeof(txh
->rts_frame
));
4971 printk(KERN_DEBUG
"RTS Frame: %s", hexbuf
);
4972 printk(KERN_DEBUG
"\n");
4974 #endif /* defined(BCMDBG) */
4977 void wlc_print_rxh(d11rxhdr_t
*rxh
)
4979 u16 len
= rxh
->RxFrameSize
;
4980 u16 phystatus_0
= rxh
->PhyRxStatus_0
;
4981 u16 phystatus_1
= rxh
->PhyRxStatus_1
;
4982 u16 phystatus_2
= rxh
->PhyRxStatus_2
;
4983 u16 phystatus_3
= rxh
->PhyRxStatus_3
;
4984 u16 macstatus1
= rxh
->RxStatus1
;
4985 u16 macstatus2
= rxh
->RxStatus2
;
4988 static const bcm_bit_desc_t macstat_flags
[] = {
4989 {RXS_FCSERR
, "FCSErr"},
4990 {RXS_RESPFRAMETX
, "Reply"},
4991 {RXS_PBPRES
, "PADDING"},
4992 {RXS_DECATMPT
, "DeCr"},
4993 {RXS_DECERR
, "DeCrErr"},
4994 {RXS_BCNSENT
, "Bcn"},
4998 prhex("Raw RxDesc", (unsigned char *) rxh
, sizeof(d11rxhdr_t
));
5000 bcm_format_flags(macstat_flags
, macstatus1
, flagstr
, 64);
5002 snprintf(lenbuf
, sizeof(lenbuf
), "0x%x", len
);
5004 printk(KERN_DEBUG
"RxFrameSize: %6s (%d)%s\n", lenbuf
, len
,
5005 (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
) ? " short preamble" : "");
5006 printk(KERN_DEBUG
"RxPHYStatus: %04x %04x %04x %04x\n",
5007 phystatus_0
, phystatus_1
, phystatus_2
, phystatus_3
);
5008 printk(KERN_DEBUG
"RxMACStatus: %x %s\n", macstatus1
, flagstr
);
5009 printk(KERN_DEBUG
"RXMACaggtype: %x\n",
5010 (macstatus2
& RXS_AGGTYPE_MASK
));
5011 printk(KERN_DEBUG
"RxTSFTime: %04x\n", rxh
->RxTSFTime
);
5013 #endif /* defined(BCMDBG) */
5016 int wlc_format_ssid(char *buf
, const unsigned char ssid
[], uint ssid_len
)
5020 char *endp
= buf
+ SSID_FMT_BUF_LEN
;
5022 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
5023 ssid_len
= IEEE80211_MAX_SSID_LEN
;
5025 for (i
= 0; i
< ssid_len
; i
++) {
5030 } else if (isprint((unsigned char) c
)) {
5033 p
+= snprintf(p
, (endp
- p
), "\\x%02X", c
);
5039 return (int)(p
- buf
);
5041 #endif /* defined(BCMDBG) */
5043 static u16
wlc_rate_shm_offset(struct wlc_info
*wlc
, u8 rate
)
5045 return wlc_bmac_rate_shm_offset(wlc
->hw
, rate
);
5048 /* Callback for device removed */
5051 * Attempts to queue a packet onto a multiple-precedence queue,
5052 * if necessary evicting a lower precedence packet from the queue.
5054 * 'prec' is the precedence number that has already been mapped
5055 * from the packet priority.
5057 * Returns true if packet consumed (queued), false if not.
5060 wlc_prec_enq(struct wlc_info
*wlc
, struct pktq
*q
, void *pkt
, int prec
)
5062 return wlc_prec_enq_head(wlc
, q
, pkt
, prec
, false);
5066 wlc_prec_enq_head(struct wlc_info
*wlc
, struct pktq
*q
, struct sk_buff
*pkt
,
5067 int prec
, bool head
)
5070 int eprec
= -1; /* precedence to evict from */
5072 /* Determine precedence from which to evict packet, if any */
5073 if (pktq_pfull(q
, prec
))
5075 else if (pktq_full(q
)) {
5076 p
= pktq_peek_tail(q
, &eprec
);
5079 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5080 __func__
, eprec
, prec
);
5085 /* Evict if needed */
5087 bool discard_oldest
;
5089 /* Detect queueing to unconfigured precedence */
5090 ASSERT(!pktq_pempty(q
, eprec
));
5092 discard_oldest
= AC_BITMAP_TST(wlc
->wme_dp
, eprec
);
5094 /* Refuse newer packet unless configured to discard oldest */
5095 if (eprec
== prec
&& !discard_oldest
) {
5096 WL_ERROR("%s: No where to go, prec == %d\n",
5101 /* Evict packet according to discard policy */
5102 p
= discard_oldest
? pktq_pdeq(q
, eprec
) : pktq_pdeq_tail(q
,
5106 /* Increment wme stats */
5107 if (WME_ENAB(wlc
->pub
)) {
5108 WLCNTINCR(wlc
->pub
->_wme_cnt
->
5109 tx_failed
[WME_PRIO2AC(p
->priority
)].packets
);
5110 WLCNTADD(wlc
->pub
->_wme_cnt
->
5111 tx_failed
[WME_PRIO2AC(p
->priority
)].bytes
,
5114 pkt_buf_free_skb(p
);
5115 wlc
->pub
->_cnt
->txnobuf
++;
5120 p
= pktq_penq_head(q
, prec
, pkt
);
5122 p
= pktq_penq(q
, prec
, pkt
);
5128 void BCMFASTPATH
wlc_txq_enq(void *ctx
, struct scb
*scb
, struct sk_buff
*sdu
,
5131 struct wlc_info
*wlc
= (struct wlc_info
*) ctx
;
5132 struct wlc_txq_info
*qi
= wlc
->active_queue
; /* Check me */
5133 struct pktq
*q
= &qi
->q
;
5136 prio
= sdu
->priority
;
5138 ASSERT(pktq_max(q
) >= wlc
->pub
->tunables
->datahiwat
);
5140 if (!wlc_prec_enq(wlc
, q
, sdu
, prec
)) {
5141 if (!EDCF_ENAB(wlc
->pub
)
5142 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
))
5143 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5147 * XXX we might hit this condtion in case
5148 * packet flooding from mac80211 stack
5150 pkt_buf_free_skb(sdu
);
5151 wlc
->pub
->_cnt
->txnobuf
++;
5154 /* Check if flow control needs to be turned on after enqueuing the packet
5155 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5156 * to drop instead of relying on stack to make the right decision
5158 if (!EDCF_ENAB(wlc
->pub
)
5159 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5160 if (pktq_len(q
) >= wlc
->pub
->tunables
->datahiwat
) {
5161 wlc_txflowcontrol(wlc
, qi
, ON
, ALLPRIO
);
5163 } else if (wlc
->pub
->_priofc
) {
5164 if (pktq_plen(q
, wlc_prio2prec_map
[prio
]) >=
5165 wlc
->pub
->tunables
->datahiwat
) {
5166 wlc_txflowcontrol(wlc
, qi
, ON
, prio
);
5172 wlc_sendpkt_mac80211(struct wlc_info
*wlc
, struct sk_buff
*sdu
,
5173 struct ieee80211_hw
*hw
)
5178 struct scb
*scb
= &global_scb
;
5179 struct ieee80211_hdr
*d11_header
= (struct ieee80211_hdr
*)(sdu
->data
);
5183 /* 802.11 standard requires management traffic to go at highest priority */
5184 prio
= ieee80211_is_data(d11_header
->frame_control
) ? sdu
->priority
:
5186 fifo
= prio2fifo
[prio
];
5188 ASSERT((uint
) skb_headroom(sdu
) >= TXOFF
);
5189 ASSERT(!(sdu
->next
));
5190 ASSERT(!(sdu
->prev
));
5191 ASSERT(fifo
< NFIFO
);
5195 (wlc_d11hdrs_mac80211(wlc
, hw
, pkt
, scb
, 0, 1, fifo
, 0, NULL
, 0)))
5197 wlc_txq_enq(wlc
, scb
, pkt
, WLC_PRIO_TO_PREC(prio
));
5198 wlc_send_q(wlc
, wlc
->active_queue
);
5200 wlc
->pub
->_cnt
->ieee_tx
++;
5204 void BCMFASTPATH
wlc_send_q(struct wlc_info
*wlc
, struct wlc_txq_info
*qi
)
5206 struct sk_buff
*pkt
[DOT11_MAXNUMFRAGS
];
5209 int err
= 0, i
, count
;
5211 struct pktq
*q
= &qi
->q
;
5212 struct ieee80211_tx_info
*tx_info
;
5214 /* only do work for the active queue */
5215 if (qi
!= wlc
->active_queue
)
5223 prec_map
= wlc
->tx_prec_map
;
5225 /* Send all the enq'd pkts that we can.
5226 * Dequeue packets with precedence with empty HW fifo only
5228 while (prec_map
&& (pkt
[0] = pktq_mdeq(q
, prec_map
, &prec
))) {
5229 tx_info
= IEEE80211_SKB_CB(pkt
[0]);
5230 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
5231 err
= wlc_sendampdu(wlc
->ampdu
, qi
, pkt
, prec
);
5234 err
= wlc_prep_pdu(wlc
, pkt
[0], &fifo
);
5236 for (i
= 0; i
< count
; i
++) {
5237 wlc_txfifo(wlc
, fifo
, pkt
[i
], true, 1);
5242 if (err
== BCME_BUSY
) {
5243 pktq_penq_head(q
, prec
, pkt
[0]);
5244 /* If send failed due to any other reason than a change in
5245 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5247 if (prec_map
== wlc
->tx_prec_map
)
5249 prec_map
= wlc
->tx_prec_map
;
5253 /* Check if flow control needs to be turned off after sending the packet */
5254 if (!EDCF_ENAB(wlc
->pub
)
5255 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5256 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, ALLPRIO
)
5257 && (pktq_len(q
) < wlc
->pub
->tunables
->datahiwat
/ 2)) {
5258 wlc_txflowcontrol(wlc
, qi
, OFF
, ALLPRIO
);
5260 } else if (wlc
->pub
->_priofc
) {
5262 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
5263 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, prio
) &&
5264 (pktq_plen(q
, wlc_prio2prec_map
[prio
]) <
5265 wlc
->pub
->tunables
->datahiwat
/ 2)) {
5266 wlc_txflowcontrol(wlc
, qi
, OFF
, prio
);
5274 * bcmc_fid_generate:
5275 * Generate frame ID for a BCMC packet. The frag field is not used
5276 * for MC frames so is used as part of the sequence number.
5279 bcmc_fid_generate(struct wlc_info
*wlc
, struct wlc_bsscfg
*bsscfg
,
5284 frameid
= le16_to_cpu(txh
->TxFrameID
) & ~(TXFID_SEQ_MASK
|
5288 mc_fid_counter
++) << TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5295 wlc_txfifo(struct wlc_info
*wlc
, uint fifo
, struct sk_buff
*p
, bool commit
,
5298 u16 frameid
= INVALIDFID
;
5301 ASSERT(fifo
< NFIFO
);
5302 txh
= (d11txh_t
*) (p
->data
);
5304 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5305 * ucode or BSS info as appropriate.
5307 if (fifo
== TX_BCMC_FIFO
) {
5308 frameid
= le16_to_cpu(txh
->TxFrameID
);
5312 if (WLC_WAR16165(wlc
))
5313 wlc_war16165(wlc
, true);
5316 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5317 * in wlc_bmac_txfifo()
5320 TXPKTPENDINC(wlc
, fifo
, txpktpend
);
5321 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5322 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
5325 /* Commit BCMC sequence number in the SHM frame ID location */
5326 if (frameid
!= INVALIDFID
)
5327 BCMCFID(wlc
, frameid
);
5329 if (dma_txfast(wlc
->hw
->di
[fifo
], p
, commit
) < 0) {
5330 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5335 wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
)
5338 uint mac_rate
= RSPEC2RATE(rspec
);
5341 if (IS_MCS(rspec
)) {
5342 /* not supported yet */
5344 } else if (IS_OFDM(rspec
)) {
5345 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5347 * Nbits = length * 8
5348 * Nbits/sym = Mbps * 4 = mac_rate * 2
5350 nsyms
= CEIL((length
* 8), (mac_rate
* 2));
5352 /* usec = symbols * usec/symbol */
5353 usec
= (u16
) (nsyms
* APHY_SYMBOL_TIME
);
5364 usec
= (length
<< 4) / 11;
5367 usec
= (length
<< 3) / 11;
5370 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5371 wlc
->pub
->unit
, rspec
);
5372 ASSERT((const char *)"Bad phy_rate" == NULL
);
5381 wlc_compute_plcp(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
, u8
*plcp
)
5383 if (IS_MCS(rspec
)) {
5384 wlc_compute_mimo_plcp(rspec
, length
, plcp
);
5385 } else if (IS_OFDM(rspec
)) {
5386 wlc_compute_ofdm_plcp(rspec
, length
, plcp
);
5388 wlc_compute_cck_plcp(rspec
, length
, plcp
);
5393 /* Rate: 802.11 rate code, length: PSDU length in octets */
5394 static void wlc_compute_mimo_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5396 u8 mcs
= (u8
) (rspec
& RSPEC_RATE_MASK
);
5397 ASSERT(IS_MCS(rspec
));
5399 if (RSPEC_IS40MHZ(rspec
) || (mcs
== 32))
5400 plcp
[0] |= MIMO_PLCP_40MHZ
;
5401 WLC_SET_MIMO_PLCP_LEN(plcp
, length
);
5402 plcp
[3] = RSPEC_MIMOPLCP3(rspec
); /* rspec already holds this byte */
5403 plcp
[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5404 plcp
[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5408 /* Rate: 802.11 rate code, length: PSDU length in octets */
5409 static void BCMFASTPATH
5410 wlc_compute_ofdm_plcp(ratespec_t rspec
, u32 length
, u8
*plcp
)
5414 int rate
= RSPEC2RATE(rspec
);
5416 ASSERT(IS_OFDM(rspec
));
5418 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5419 rate_signal
= rate_info
[rate
] & RATE_MASK
;
5420 ASSERT(rate_signal
!= 0);
5422 memset(plcp
, 0, D11_PHY_HDR_LEN
);
5423 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t
*) plcp
, rate_signal
);
5425 tmp
= (length
& 0xfff) << 5;
5426 plcp
[2] |= (tmp
>> 16) & 0xff;
5427 plcp
[1] |= (tmp
>> 8) & 0xff;
5428 plcp
[0] |= tmp
& 0xff;
5434 * Compute PLCP, but only requires actual rate and length of pkt.
5435 * Rate is given in the driver standard multiple of 500 kbps.
5436 * le is set for 11 Mbps rate if necessary.
5437 * Broken out for PRQ.
5440 static void wlc_cck_plcp_set(int rate_500
, uint length
, u8
*plcp
)
5453 usec
= (length
<< 4) / 11;
5454 if ((length
<< 4) - (usec
* 11) > 0)
5458 usec
= (length
<< 3) / 11;
5459 if ((length
<< 3) - (usec
* 11) > 0) {
5461 if ((usec
* 11) - (length
<< 3) >= 8)
5462 le
= D11B_PLCP_SIGNAL_LE
;
5467 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500
);
5468 rate_500
= WLC_RATE_1M
;
5472 /* PLCP signal byte */
5473 plcp
[0] = rate_500
* 5; /* r (500kbps) * 5 == r (100kbps) */
5474 /* PLCP service byte */
5475 plcp
[1] = (u8
) (le
| D11B_PLCP_SIGNAL_LOCKED
);
5476 /* PLCP length u16, little endian */
5477 plcp
[2] = usec
& 0xff;
5478 plcp
[3] = (usec
>> 8) & 0xff;
5484 /* Rate: 802.11 rate code, length: PSDU length in octets */
5485 static void wlc_compute_cck_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5487 int rate
= RSPEC2RATE(rspec
);
5489 ASSERT(IS_CCK(rspec
));
5491 wlc_cck_plcp_set(rate
, length
, plcp
);
5494 /* wlc_compute_frame_dur()
5496 * Calculate the 802.11 MAC header DUR field for MPDU
5497 * DUR for a single frame = 1 SIFS + 1 ACK
5498 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5500 * rate MPDU rate in unit of 500kbps
5501 * next_frag_len next MPDU length in bytes
5502 * preamble_type use short/GF or long/MM PLCP header
5504 static u16 BCMFASTPATH
5505 wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
, u8 preamble_type
,
5510 sifs
= SIFS(wlc
->band
);
5513 dur
+= (u16
) wlc_calc_ack_time(wlc
, rate
, preamble_type
);
5515 if (next_frag_len
) {
5516 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5518 /* add another SIFS and the frag time */
5521 (u16
) wlc_calc_frame_time(wlc
, rate
, preamble_type
,
5527 /* wlc_compute_rtscts_dur()
5529 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5530 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5531 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5533 * cts cts-to-self or rts/cts
5534 * rts_rate rts or cts rate in unit of 500kbps
5535 * rate next MPDU rate in unit of 500kbps
5536 * frame_len next MPDU frame length in bytes
5539 wlc_compute_rtscts_dur(struct wlc_info
*wlc
, bool cts_only
, ratespec_t rts_rate
,
5540 ratespec_t frame_rate
, u8 rts_preamble_type
,
5541 u8 frame_preamble_type
, uint frame_len
, bool ba
)
5545 sifs
= SIFS(wlc
->band
);
5547 if (!cts_only
) { /* RTS/CTS */
5550 (u16
) wlc_calc_cts_time(wlc
, rts_rate
,
5552 } else { /* CTS-TO-SELF */
5557 (u16
) wlc_calc_frame_time(wlc
, frame_rate
, frame_preamble_type
,
5561 (u16
) wlc_calc_ba_time(wlc
, frame_rate
,
5562 WLC_SHORT_PREAMBLE
);
5565 (u16
) wlc_calc_ack_time(wlc
, frame_rate
,
5566 frame_preamble_type
);
5570 static bool wlc_phy_rspec_check(struct wlc_info
*wlc
, u16 bw
, ratespec_t rspec
)
5572 if (IS_MCS(rspec
)) {
5573 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5576 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5577 } else if ((mcs
>= 8) && (mcs
<= 23)) {
5578 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SDM
);
5579 } else if (mcs
== 32) {
5580 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5581 ASSERT(bw
== PHY_TXC1_BW_40MHZ_DUP
);
5583 } else if (IS_OFDM(rspec
)) {
5584 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_STBC
);
5586 ASSERT(IS_CCK(rspec
));
5588 ASSERT((bw
== PHY_TXC1_BW_20MHZ
)
5589 || (bw
== PHY_TXC1_BW_20MHZ_UP
));
5590 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SISO
);
5596 u16 BCMFASTPATH
wlc_phytxctl1_calc(struct wlc_info
*wlc
, ratespec_t rspec
)
5601 if (WLCISLCNPHY(wlc
->band
)) {
5602 bw
= PHY_TXC1_BW_20MHZ
;
5604 bw
= RSPEC_GET_BW(rspec
);
5605 /* 10Mhz is not supported yet */
5606 if (bw
< PHY_TXC1_BW_20MHZ
) {
5607 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5609 bw
= PHY_TXC1_BW_20MHZ
;
5612 wlc_phy_rspec_check(wlc
, bw
, rspec
);
5615 if (IS_MCS(rspec
)) {
5616 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5618 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5619 phyctl1
= RSPEC_PHYTXBYTE2(rspec
);
5620 /* set the upper byte of phyctl1 */
5621 phyctl1
|= (mcs_table
[mcs
].tx_phy_ctl3
<< 8);
5622 } else if (IS_CCK(rspec
) && !WLCISLCNPHY(wlc
->band
)
5623 && !WLCISSSLPNPHY(wlc
->band
)) {
5624 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5625 /* Eventually MIMOPHY would also be converted to this format */
5626 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5627 phyctl1
= (bw
| (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5628 } else { /* legacy OFDM/CCK */
5630 /* get the phyctl byte from rate phycfg table */
5631 phycfg
= wlc_rate_legacy_phyctl(RSPEC2RATE(rspec
));
5633 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5637 /* set the upper byte of phyctl1 */
5639 (bw
| (phycfg
<< 8) |
5640 (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5644 /* phy clock must support 40Mhz if tx descriptor uses it */
5645 if ((phyctl1
& PHY_TXC1_BW_MASK
) >= PHY_TXC1_BW_40MHZ
) {
5646 ASSERT(CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
);
5647 ASSERT(wlc
->chanspec
== wlc_phy_chanspec_get(wlc
->band
->pi
));
5653 ratespec_t BCMFASTPATH
5654 wlc_rspec_to_rts_rspec(struct wlc_info
*wlc
, ratespec_t rspec
, bool use_rspec
,
5657 ratespec_t rts_rspec
= 0;
5660 /* use frame rate as rts rate */
5663 } else if (wlc
->band
->gmode
&& wlc
->protection
->_g
&& !IS_CCK(rspec
)) {
5664 /* Use 11Mbps as the g protection RTS target rate and fallback.
5665 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5666 * target in case 11 Mbps is not Basic.
5667 * 6 and 9 Mbps are not usually selected by rate selection, but even
5668 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5670 rts_rspec
= WLC_BASIC_RATE(wlc
, WLC_RATE_11M
);
5672 /* calculate RTS rate and fallback rate based on the frame rate
5673 * RTS must be sent at a basic rate since it is a
5674 * control frame, sec 9.6 of 802.11 spec
5676 rts_rspec
= WLC_BASIC_RATE(wlc
, rspec
);
5679 if (WLC_PHY_11N_CAP(wlc
->band
)) {
5680 /* set rts txbw to correct side band */
5681 rts_rspec
&= ~RSPEC_BW_MASK
;
5683 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5684 * (DUP), otherwise send RTS on control channel
5686 if (RSPEC_IS40MHZ(rspec
) && !IS_CCK(rts_rspec
))
5687 rts_rspec
|= (PHY_TXC1_BW_40MHZ_DUP
<< RSPEC_BW_SHIFT
);
5689 rts_rspec
|= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5691 /* pick siso/cdd as default for ofdm */
5692 if (IS_OFDM(rts_rspec
)) {
5693 rts_rspec
&= ~RSPEC_STF_MASK
;
5694 rts_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
5701 * Add d11txh_t, cck_phy_hdr_t.
5703 * 'p' data must start with 802.11 MAC header
5704 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5706 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5709 static u16 BCMFASTPATH
5710 wlc_d11hdrs_mac80211(struct wlc_info
*wlc
, struct ieee80211_hw
*hw
,
5711 struct sk_buff
*p
, struct scb
*scb
, uint frag
,
5712 uint nfrags
, uint queue
, uint next_frag_len
,
5713 wsec_key_t
*key
, ratespec_t rspec_override
)
5715 struct ieee80211_hdr
*h
;
5717 u8
*plcp
, plcp_fallback
[D11_PHY_HDR_LEN
];
5718 int len
, phylen
, rts_phylen
;
5719 u16 mch
, phyctl
, xfts
, mainrates
;
5720 u16 seq
= 0, mcl
= 0, status
= 0, frameid
= 0;
5721 ratespec_t rspec
[2] = { WLC_RATE_1M
, WLC_RATE_1M
}, rts_rspec
[2] = {
5722 WLC_RATE_1M
, WLC_RATE_1M
};
5723 bool use_rts
= false;
5724 bool use_cts
= false;
5725 bool use_rifs
= false;
5726 bool short_preamble
[2] = { false, false };
5727 u8 preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5728 u8 rts_preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5729 u8
*rts_plcp
, rts_plcp_fallback
[D11_PHY_HDR_LEN
];
5730 struct ieee80211_rts
*rts
= NULL
;
5734 bool hwtkmic
= false;
5735 u16 mimo_ctlchbw
= PHY_TXC1_BW_20MHZ
;
5736 #define ANTCFG_NONE 0xFF
5737 u8 antcfg
= ANTCFG_NONE
;
5738 u8 fbantcfg
= ANTCFG_NONE
;
5739 uint phyctl1_stf
= 0;
5741 struct ieee80211_tx_rate
*txrate
[2];
5743 struct ieee80211_tx_info
*tx_info
;
5746 u8 mimo_preamble_type
;
5748 ASSERT(queue
< NFIFO
);
5750 /* locate 802.11 MAC header */
5751 h
= (struct ieee80211_hdr
*)(p
->data
);
5752 qos
= ieee80211_is_data_qos(h
->frame_control
);
5754 /* compute length of frame in bytes for use in PLCP computations */
5756 phylen
= len
+ FCS_LEN
;
5758 /* If WEP enabled, add room in phylen for the additional bytes of
5759 * ICV which MAC generates. We do NOT add the additional bytes to
5760 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5764 phylen
+= key
->icv_len
;
5768 tx_info
= IEEE80211_SKB_CB(p
);
5772 plcp
= skb_push(p
, D11_PHY_HDR_LEN
);
5774 /* add Broadcom tx descriptor header */
5775 txh
= (d11txh_t
*) skb_push(p
, D11_TXH_LEN
);
5776 memset(txh
, 0, D11_TXH_LEN
);
5779 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
5780 /* non-AP STA should never use BCMC queue */
5781 ASSERT(queue
!= TX_BCMC_FIFO
);
5782 if (queue
== TX_BCMC_FIFO
) {
5783 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5784 WLCWLUNIT(wlc
), __func__
);
5785 frameid
= bcmc_fid_generate(wlc
, NULL
, txh
);
5787 /* Increment the counter for first fragment */
5788 if (tx_info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
) {
5789 SCB_SEQNUM(scb
, p
->priority
)++;
5792 /* extract fragment number from frame first */
5793 seq
= le16_to_cpu(seq
) & FRAGNUM_MASK
;
5794 seq
|= (SCB_SEQNUM(scb
, p
->priority
) << SEQNUM_SHIFT
);
5795 h
->seq_ctrl
= cpu_to_le16(seq
);
5797 frameid
= ((seq
<< TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5798 (queue
& TXFID_QUEUE_MASK
);
5801 frameid
|= queue
& TXFID_QUEUE_MASK
;
5803 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5804 if (SCB_PS(scb
) || ieee80211_is_beacon(h
->frame_control
))
5805 mcl
|= TXC_IGNOREPMQ
;
5807 ASSERT(hw
->max_rates
<= IEEE80211_TX_MAX_RATES
);
5808 ASSERT(hw
->max_rates
== 2);
5810 txrate
[0] = tx_info
->control
.rates
;
5811 txrate
[1] = txrate
[0] + 1;
5813 ASSERT(txrate
[0]->idx
>= 0);
5814 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5815 if (txrate
[1]->idx
< 0) {
5816 txrate
[1] = txrate
[0];
5819 for (k
= 0; k
< hw
->max_rates
; k
++) {
5821 txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
? true : false;
5823 ASSERT(!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
));
5824 if ((txrate
[k
]->idx
>= 0)
5825 && (txrate
[k
]->idx
<
5826 hw
->wiphy
->bands
[tx_info
->band
]->n_bitrates
)) {
5828 hw
->wiphy
->bands
[tx_info
->band
]->
5829 bitrates
[txrate
[k
]->idx
].hw_value
;
5832 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
?
5835 ASSERT((txrate
[k
]->idx
>= 0) &&
5837 hw
->wiphy
->bands
[tx_info
->band
]->
5839 rate_val
[k
] = WLC_RATE_1M
;
5842 rate_val
[k
] = txrate
[k
]->idx
;
5844 /* Currently only support same setting for primay and fallback rates.
5845 * Unify flags for each rate into a single value for the frame
5849 flags
& IEEE80211_TX_RC_USE_RTS_CTS
? true : false;
5852 flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
? true : false;
5855 rate_val
[k
] |= NRATE_MCS_INUSE
;
5857 rspec
[k
] = mac80211_wlc_set_nrate(wlc
, wlc
->band
, rate_val
[k
]);
5859 /* (1) RATE: determine and validate primary rate and fallback rates */
5860 if (!RSPEC_ACTIVE(rspec
[k
])) {
5861 ASSERT(RSPEC_ACTIVE(rspec
[k
]));
5862 rspec
[k
] = WLC_RATE_1M
;
5864 if (!is_multicast_ether_addr(h
->addr1
)) {
5865 /* set tx antenna config */
5866 wlc_antsel_antcfg_get(wlc
->asi
, false, false, 0,
5867 0, &antcfg
, &fbantcfg
);
5872 phyctl1_stf
= wlc
->stf
->ss_opmode
;
5874 if (N_ENAB(wlc
->pub
)) {
5875 for (k
= 0; k
< hw
->max_rates
; k
++) {
5876 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5877 if (((IS_MCS(rspec
[k
]) &&
5878 IS_SINGLE_STREAM(rspec
[k
] & RSPEC_RATE_MASK
)) ||
5880 && ((rspec
[k
] & RSPEC_OVERRIDE_MCS_ONLY
)
5881 || !(rspec
[k
] & RSPEC_OVERRIDE
))) {
5882 rspec
[k
] &= ~(RSPEC_STF_MASK
| RSPEC_STC_MASK
);
5884 /* For SISO MCS use STBC if possible */
5885 if (IS_MCS(rspec
[k
])
5886 && WLC_STF_SS_STBC_TX(wlc
, scb
)) {
5889 ASSERT(WLC_STBC_CAP_PHY(wlc
));
5890 stc
= 1; /* Nss for single stream is always 1 */
5892 (PHY_TXC1_MODE_STBC
<<
5893 RSPEC_STF_SHIFT
) | (stc
<<
5897 (phyctl1_stf
<< RSPEC_STF_SHIFT
);
5900 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5901 if (CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
) {
5902 /* default txbw is 20in40 SB */
5903 mimo_ctlchbw
= mimo_txbw
=
5904 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC
)
5905 ? PHY_TXC1_BW_20MHZ_UP
: PHY_TXC1_BW_20MHZ
;
5907 if (IS_MCS(rspec
[k
])) {
5908 /* mcs 32 must be 40b/w DUP */
5909 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5911 PHY_TXC1_BW_40MHZ_DUP
;
5913 } else if (wlc
->mimo_40txbw
!= AUTO
)
5914 mimo_txbw
= wlc
->mimo_40txbw
;
5915 /* else check if dst is using 40 Mhz */
5916 else if (scb
->flags
& SCB_IS40
)
5917 mimo_txbw
= PHY_TXC1_BW_40MHZ
;
5918 } else if (IS_OFDM(rspec
[k
])) {
5919 if (wlc
->ofdm_40txbw
!= AUTO
)
5920 mimo_txbw
= wlc
->ofdm_40txbw
;
5922 ASSERT(IS_CCK(rspec
[k
]));
5923 if (wlc
->cck_40txbw
!= AUTO
)
5924 mimo_txbw
= wlc
->cck_40txbw
;
5927 /* mcs32 is 40 b/w only.
5928 * This is possible for probe packets on a STA during SCAN
5930 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5932 rspec
[k
] = RSPEC_MIMORATE
;
5934 mimo_txbw
= PHY_TXC1_BW_20MHZ
;
5937 /* Set channel width */
5938 rspec
[k
] &= ~RSPEC_BW_MASK
;
5939 if ((k
== 0) || ((k
> 0) && IS_MCS(rspec
[k
])))
5940 rspec
[k
] |= (mimo_txbw
<< RSPEC_BW_SHIFT
);
5942 rspec
[k
] |= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5946 if (IS_MCS(rspec
[k
])
5947 && (txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5948 rspec
[k
] |= RSPEC_SHORT_GI
;
5949 else if (!(txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5950 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5952 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5955 mimo_preamble_type
= WLC_MM_PREAMBLE
;
5956 if (txrate
[k
]->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
5957 mimo_preamble_type
= WLC_GF_PREAMBLE
;
5959 if ((txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
)
5960 && (!IS_MCS(rspec
[k
]))) {
5961 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5962 WLCWLUNIT(wlc
), __func__
);
5963 ASSERT(0 && "Rate mismatch");
5966 if (IS_MCS(rspec
[k
])) {
5967 preamble_type
[k
] = mimo_preamble_type
;
5969 /* if SGI is selected, then forced mm for single stream */
5970 if ((rspec
[k
] & RSPEC_SHORT_GI
)
5971 && IS_SINGLE_STREAM(rspec
[k
] &
5973 preamble_type
[k
] = WLC_MM_PREAMBLE
;
5977 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
5978 ASSERT(VALID_RATE_DBG(wlc
, rspec
[0]));
5980 /* should be better conditionalized */
5981 if (!IS_MCS(rspec
[0])
5982 && (tx_info
->control
.rates
[0].
5983 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
))
5984 preamble_type
[k
] = WLC_SHORT_PREAMBLE
;
5986 ASSERT(!IS_MCS(rspec
[0])
5987 || WLC_IS_MIMO_PREAMBLE(preamble_type
[k
]));
5990 for (k
= 0; k
< hw
->max_rates
; k
++) {
5991 /* Set ctrlchbw as 20Mhz */
5992 ASSERT(!IS_MCS(rspec
[k
]));
5993 rspec
[k
] &= ~RSPEC_BW_MASK
;
5994 rspec
[k
] |= (PHY_TXC1_BW_20MHZ
<< RSPEC_BW_SHIFT
);
5996 /* for nphy, stf of ofdm frames must follow policies */
5997 if (WLCISNPHY(wlc
->band
) && IS_OFDM(rspec
[k
])) {
5998 rspec
[k
] &= ~RSPEC_STF_MASK
;
5999 rspec
[k
] |= phyctl1_stf
<< RSPEC_STF_SHIFT
;
6004 /* Reset these for use with AMPDU's */
6005 txrate
[0]->count
= 0;
6006 txrate
[1]->count
= 0;
6008 /* (2) PROTECTION, may change rspec */
6009 if ((ieee80211_is_data(h
->frame_control
) ||
6010 ieee80211_is_mgmt(h
->frame_control
)) &&
6011 (phylen
> wlc
->RTSThresh
) && !is_multicast_ether_addr(h
->addr1
))
6014 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
6015 wlc_compute_plcp(wlc
, rspec
[0], phylen
, plcp
);
6016 wlc_compute_plcp(wlc
, rspec
[1], phylen
, plcp_fallback
);
6017 memcpy(&txh
->FragPLCPFallback
,
6018 plcp_fallback
, sizeof(txh
->FragPLCPFallback
));
6020 /* Length field now put in CCK FBR CRC field */
6021 if (IS_CCK(rspec
[1])) {
6022 txh
->FragPLCPFallback
[4] = phylen
& 0xff;
6023 txh
->FragPLCPFallback
[5] = (phylen
& 0xff00) >> 8;
6026 /* MIMO-RATE: need validation ?? */
6028 IS_OFDM(rspec
[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) plcp
) :
6031 /* DUR field for main rate */
6032 if (!ieee80211_is_pspoll(h
->frame_control
) &&
6033 !is_multicast_ether_addr(h
->addr1
) && !use_rifs
) {
6035 wlc_compute_frame_dur(wlc
, rspec
[0], preamble_type
[0],
6037 h
->duration_id
= cpu_to_le16(durid
);
6038 } else if (use_rifs
) {
6039 /* NAV protect to end of next max packet size */
6041 (u16
) wlc_calc_frame_time(wlc
, rspec
[0],
6043 DOT11_MAX_FRAG_LEN
);
6044 durid
+= RIFS_11N_TIME
;
6045 h
->duration_id
= cpu_to_le16(durid
);
6048 /* DUR field for fallback rate */
6049 if (ieee80211_is_pspoll(h
->frame_control
))
6050 txh
->FragDurFallback
= h
->duration_id
;
6051 else if (is_multicast_ether_addr(h
->addr1
) || use_rifs
)
6052 txh
->FragDurFallback
= 0;
6054 durid
= wlc_compute_frame_dur(wlc
, rspec
[1],
6055 preamble_type
[1], next_frag_len
);
6056 txh
->FragDurFallback
= cpu_to_le16(durid
);
6059 /* (4) MAC-HDR: MacTxControlLow */
6061 mcl
|= TXC_STARTMSDU
;
6063 if (!is_multicast_ether_addr(h
->addr1
))
6064 mcl
|= TXC_IMMEDACK
;
6066 if (BAND_5G(wlc
->band
->bandtype
))
6067 mcl
|= TXC_FREQBAND_5G
;
6069 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC
))
6072 /* set AMIC bit if using hardware TKIP MIC */
6076 txh
->MacTxControlLow
= cpu_to_le16(mcl
);
6078 /* MacTxControlHigh */
6081 /* Set fallback rate preamble type */
6082 if ((preamble_type
[1] == WLC_SHORT_PREAMBLE
) ||
6083 (preamble_type
[1] == WLC_GF_PREAMBLE
)) {
6084 ASSERT((preamble_type
[1] == WLC_GF_PREAMBLE
) ||
6085 (!IS_MCS(rspec
[1])));
6086 if (RSPEC2RATE(rspec
[1]) != WLC_RATE_1M
)
6087 mch
|= TXC_PREAMBLE_DATA_FB_SHORT
;
6090 /* MacFrameControl */
6091 memcpy(&txh
->MacFrameControl
, &h
->frame_control
, sizeof(u16
));
6092 txh
->TxFesTimeNormal
= cpu_to_le16(0);
6094 txh
->TxFesTimeFallback
= cpu_to_le16(0);
6097 memcpy(&txh
->TxFrameRA
, &h
->addr1
, ETH_ALEN
);
6100 txh
->TxFrameID
= cpu_to_le16(frameid
);
6102 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6103 * then we may need to reset the retry cnt's via the status reg
6105 txh
->TxStatus
= cpu_to_le16(status
);
6107 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6108 * the END of previous structure so that it's compatible in driver.
6110 txh
->MaxNMpdus
= cpu_to_le16(0);
6111 txh
->MaxABytes_MRT
= cpu_to_le16(0);
6112 txh
->MaxABytes_FBR
= cpu_to_le16(0);
6113 txh
->MinMBytes
= cpu_to_le16(0);
6115 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6116 /* RTS PLCP header and RTS frame */
6117 if (use_rts
|| use_cts
) {
6118 if (use_rts
&& use_cts
)
6121 for (k
= 0; k
< 2; k
++) {
6122 rts_rspec
[k
] = wlc_rspec_to_rts_rspec(wlc
, rspec
[k
],
6127 if (!IS_OFDM(rts_rspec
[0]) &&
6128 !((RSPEC2RATE(rts_rspec
[0]) == WLC_RATE_1M
) ||
6129 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6130 rts_preamble_type
[0] = WLC_SHORT_PREAMBLE
;
6131 mch
|= TXC_PREAMBLE_RTS_MAIN_SHORT
;
6134 if (!IS_OFDM(rts_rspec
[1]) &&
6135 !((RSPEC2RATE(rts_rspec
[1]) == WLC_RATE_1M
) ||
6136 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6137 rts_preamble_type
[1] = WLC_SHORT_PREAMBLE
;
6138 mch
|= TXC_PREAMBLE_RTS_FB_SHORT
;
6141 /* RTS/CTS additions to MacTxControlLow */
6143 txh
->MacTxControlLow
|= cpu_to_le16(TXC_SENDCTS
);
6145 txh
->MacTxControlLow
|= cpu_to_le16(TXC_SENDRTS
);
6146 txh
->MacTxControlLow
|= cpu_to_le16(TXC_LONGFRAME
);
6149 /* RTS PLCP header */
6150 ASSERT(IS_ALIGNED((unsigned long)txh
->RTSPhyHeader
, sizeof(u16
)));
6151 rts_plcp
= txh
->RTSPhyHeader
;
6153 rts_phylen
= DOT11_CTS_LEN
+ FCS_LEN
;
6155 rts_phylen
= DOT11_RTS_LEN
+ FCS_LEN
;
6157 wlc_compute_plcp(wlc
, rts_rspec
[0], rts_phylen
, rts_plcp
);
6159 /* fallback rate version of RTS PLCP header */
6160 wlc_compute_plcp(wlc
, rts_rspec
[1], rts_phylen
,
6162 memcpy(&txh
->RTSPLCPFallback
, rts_plcp_fallback
,
6163 sizeof(txh
->RTSPLCPFallback
));
6165 /* RTS frame fields... */
6166 rts
= (struct ieee80211_rts
*)&txh
->rts_frame
;
6168 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
, rts_rspec
[0],
6169 rspec
[0], rts_preamble_type
[0],
6170 preamble_type
[0], phylen
, false);
6171 rts
->duration
= cpu_to_le16(durid
);
6172 /* fallback rate version of RTS DUR field */
6173 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
,
6174 rts_rspec
[1], rspec
[1],
6175 rts_preamble_type
[1],
6176 preamble_type
[1], phylen
, false);
6177 txh
->RTSDurFallback
= cpu_to_le16(durid
);
6180 rts
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
6181 IEEE80211_STYPE_CTS
);
6183 memcpy(&rts
->ra
, &h
->addr2
, ETH_ALEN
);
6185 rts
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
6186 IEEE80211_STYPE_RTS
);
6188 memcpy(&rts
->ra
, &h
->addr1
, 2 * ETH_ALEN
);
6192 * low 8 bits: main frag rate/mcs,
6193 * high 8 bits: rts/cts rate/mcs
6195 mainrates
|= (IS_OFDM(rts_rspec
[0]) ?
6196 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) rts_plcp
) :
6199 memset((char *)txh
->RTSPhyHeader
, 0, D11_PHY_HDR_LEN
);
6200 memset((char *)&txh
->rts_frame
, 0,
6201 sizeof(struct ieee80211_rts
));
6202 memset((char *)txh
->RTSPLCPFallback
, 0,
6203 sizeof(txh
->RTSPLCPFallback
));
6204 txh
->RTSDurFallback
= 0;
6207 #ifdef SUPPORT_40MHZ
6208 /* add null delimiter count */
6209 if ((tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) && IS_MCS(rspec
)) {
6210 txh
->RTSPLCPFallback
[AMPDU_FBR_NULL_DELIM
] =
6211 wlc_ampdu_null_delim_cnt(wlc
->ampdu
, scb
, rspec
, phylen
);
6215 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6216 txh
->MacTxControlHigh
= cpu_to_le16(mch
);
6218 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6219 txh
->MainRates
= cpu_to_le16(mainrates
);
6221 /* XtraFrameTypes */
6222 xfts
= FRAMETYPE(rspec
[1], wlc
->mimoft
);
6223 xfts
|= (FRAMETYPE(rts_rspec
[0], wlc
->mimoft
) << XFTS_RTS_FT_SHIFT
);
6224 xfts
|= (FRAMETYPE(rts_rspec
[1], wlc
->mimoft
) << XFTS_FBRRTS_FT_SHIFT
);
6226 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
) << XFTS_CHANNEL_SHIFT
;
6227 txh
->XtraFrameTypes
= cpu_to_le16(xfts
);
6229 /* PhyTxControlWord */
6230 phyctl
= FRAMETYPE(rspec
[0], wlc
->mimoft
);
6231 if ((preamble_type
[0] == WLC_SHORT_PREAMBLE
) ||
6232 (preamble_type
[0] == WLC_GF_PREAMBLE
)) {
6233 ASSERT((preamble_type
[0] == WLC_GF_PREAMBLE
)
6234 || !IS_MCS(rspec
[0]));
6235 if (RSPEC2RATE(rspec
[0]) != WLC_RATE_1M
)
6236 phyctl
|= PHY_TXC_SHORT_HDR
;
6237 wlc
->pub
->_cnt
->txprshort
++;
6240 /* phytxant is properly bit shifted */
6241 phyctl
|= wlc_stf_d11hdrs_phyctl_txant(wlc
, rspec
[0]);
6242 txh
->PhyTxControlWord
= cpu_to_le16(phyctl
);
6244 /* PhyTxControlWord_1 */
6245 if (WLC_PHY_11N_CAP(wlc
->band
)) {
6248 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[0]);
6249 txh
->PhyTxControlWord_1
= cpu_to_le16(phyctl1
);
6250 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[1]);
6251 txh
->PhyTxControlWord_1_Fbr
= cpu_to_le16(phyctl1
);
6253 if (use_rts
|| use_cts
) {
6254 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[0]);
6255 txh
->PhyTxControlWord_1_Rts
= cpu_to_le16(phyctl1
);
6256 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[1]);
6257 txh
->PhyTxControlWord_1_FbrRts
= cpu_to_le16(phyctl1
);
6261 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6262 * fill in non-zero MModeLen and/or MModeFbrLen
6263 * it will be unnecessary if they are separated
6265 if (IS_MCS(rspec
[0]) && (preamble_type
[0] == WLC_MM_PREAMBLE
)) {
6267 wlc_calc_lsig_len(wlc
, rspec
[0], phylen
);
6268 txh
->MModeLen
= cpu_to_le16(mmodelen
);
6271 if (IS_MCS(rspec
[1]) && (preamble_type
[1] == WLC_MM_PREAMBLE
)) {
6273 wlc_calc_lsig_len(wlc
, rspec
[1], phylen
);
6274 txh
->MModeFbrLen
= cpu_to_le16(mmodefbrlen
);
6278 if (IS_MCS(rspec
[0]))
6279 ASSERT(IS_MCS(rspec
[1]));
6281 ASSERT(!IS_MCS(rspec
[0]) ||
6282 ((preamble_type
[0] == WLC_MM_PREAMBLE
) == (txh
->MModeLen
!= 0)));
6283 ASSERT(!IS_MCS(rspec
[1]) ||
6284 ((preamble_type
[1] == WLC_MM_PREAMBLE
) ==
6285 (txh
->MModeFbrLen
!= 0)));
6287 ac
= skb_get_queue_mapping(p
);
6288 if (SCB_WME(scb
) && qos
&& wlc
->edcf_txop
[ac
]) {
6289 uint frag_dur
, dur
, dur_fallback
;
6291 ASSERT(!is_multicast_ether_addr(h
->addr1
));
6293 /* WME: Update TXOP threshold */
6294 if ((!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)) && (frag
== 0)) {
6296 wlc_calc_frame_time(wlc
, rspec
[0], preamble_type
[0],
6300 /* 1 RTS or CTS-to-self frame */
6302 wlc_calc_cts_time(wlc
, rts_rspec
[0],
6303 rts_preamble_type
[0]);
6305 wlc_calc_cts_time(wlc
, rts_rspec
[1],
6306 rts_preamble_type
[1]);
6307 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6308 dur
+= le16_to_cpu(rts
->duration
);
6310 le16_to_cpu(txh
->RTSDurFallback
);
6311 } else if (use_rifs
) {
6315 /* frame + SIFS + ACK */
6318 wlc_compute_frame_dur(wlc
, rspec
[0],
6319 preamble_type
[0], 0);
6322 wlc_calc_frame_time(wlc
, rspec
[1],
6326 wlc_compute_frame_dur(wlc
, rspec
[1],
6327 preamble_type
[1], 0);
6329 /* NEED to set TxFesTimeNormal (hard) */
6330 txh
->TxFesTimeNormal
= cpu_to_le16((u16
) dur
);
6331 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6332 txh
->TxFesTimeFallback
=
6333 cpu_to_le16((u16
) dur_fallback
);
6335 /* update txop byte threshold (txop minus intraframe overhead) */
6336 if (wlc
->edcf_txop
[ac
] >= (dur
- frag_dur
)) {
6341 wlc_calc_frame_len(wlc
, rspec
[0],
6347 /* range bound the fragthreshold */
6348 if (newfragthresh
< DOT11_MIN_FRAG_LEN
)
6351 else if (newfragthresh
>
6352 wlc
->usr_fragthresh
)
6354 wlc
->usr_fragthresh
;
6355 /* update the fragthresh and do txc update */
6356 if (wlc
->fragthresh
[queue
] !=
6357 (u16
) newfragthresh
) {
6358 wlc
->fragthresh
[queue
] =
6359 (u16
) newfragthresh
;
6363 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6364 wlc
->pub
->unit
, fifo_names
[queue
],
6365 RSPEC2RATE(rspec
[0]));
6367 if (dur
> wlc
->edcf_txop
[ac
])
6368 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6369 wlc
->pub
->unit
, __func__
,
6371 phylen
, wlc
->fragthresh
[queue
],
6372 dur
, wlc
->edcf_txop
[ac
]);
6379 void wlc_tbtt(struct wlc_info
*wlc
, d11regs_t
*regs
)
6381 struct wlc_bsscfg
*cfg
= wlc
->cfg
;
6383 wlc
->pub
->_cnt
->tbtt
++;
6385 if (BSSCFG_STA(cfg
)) {
6386 /* run watchdog here if the watchdog timer is not armed */
6387 if (WLC_WATCHDOG_TBTT(wlc
)) {
6390 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
6391 wlc
->WDarmed
= false;
6394 cur
= OSL_SYSUPTIME();
6395 delta
= cur
> wlc
->WDlast
? cur
- wlc
->WDlast
:
6396 (u32
) ~0 - wlc
->WDlast
+ cur
+ 1;
6397 if (delta
>= TIMER_INTERVAL_WATCHDOG
) {
6398 wlc_watchdog((void *)wlc
);
6402 wl_add_timer(wlc
->wl
, wlc
->wdtimer
,
6403 wlc_watchdog_backup_bi(wlc
), true);
6404 wlc
->WDarmed
= true;
6409 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6410 wlc
->qvalid
|= MCMD_DIRFRMQVAL
;
6414 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6415 void wlc_hwtimer_gptimer_set(struct wlc_info
*wlc
, uint us
)
6417 W_REG(&wlc
->regs
->gptimer
, us
);
6420 void wlc_hwtimer_gptimer_abort(struct wlc_info
*wlc
)
6422 W_REG(&wlc
->regs
->gptimer
, 0);
6425 static void wlc_hwtimer_gptimer_cb(struct wlc_info
*wlc
)
6427 /* when interrupt is generated, the counter is loaded with last value
6428 * written and continue to decrement. So it has to be cleaned first
6430 W_REG(&wlc
->regs
->gptimer
, 0);
6434 * This fn has all the high level dpc processing from wlc_dpc.
6435 * POLICY: no macinstatus change, no bounding loop.
6436 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6438 void wlc_high_dpc(struct wlc_info
*wlc
, u32 macintstatus
)
6440 d11regs_t
*regs
= wlc
->regs
;
6443 static const bcm_bit_desc_t int_flags
[] = {
6444 {MI_MACSSPNDD
, "MACSSPNDD"},
6445 {MI_BCNTPL
, "BCNTPL"},
6447 {MI_BCNSUCCESS
, "BCNSUCCESS"},
6448 {MI_BCNCANCLD
, "BCNCANCLD"},
6449 {MI_ATIMWINEND
, "ATIMWINEND"},
6451 {MI_NSPECGEN_0
, "NSPECGEN_0"},
6452 {MI_NSPECGEN_1
, "NSPECGEN_1"},
6453 {MI_MACTXERR
, "MACTXERR"},
6454 {MI_NSPECGEN_3
, "NSPECGEN_3"},
6455 {MI_PHYTXERR
, "PHYTXERR"},
6459 {MI_DMAINT
, "DMAINT"},
6460 {MI_TXSTOP
, "TXSTOP"},
6462 {MI_BG_NOISE
, "BG_NOISE"},
6463 {MI_DTIM_TBTT
, "DTIM_TBTT"},
6465 {MI_PWRUP
, "PWRUP"},
6466 {MI_RFDISABLE
, "RFDISABLE"},
6468 {MI_PHYCHANGED
, "PHYCHANGED"},
6473 if (macintstatus
& ~(MI_TBTT
| MI_TXSTOP
)) {
6474 bcm_format_flags(int_flags
, macintstatus
, flagstr
,
6476 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6477 wlc
->pub
->unit
, macintstatus
, flagstr
);
6481 if (macintstatus
& MI_PRQ
) {
6482 /* Process probe request FIFO */
6483 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6486 /* TBTT indication */
6487 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6488 if (macintstatus
& (MI_TBTT
| MI_DTIM_TBTT
))
6489 wlc_tbtt(wlc
, regs
);
6491 if (macintstatus
& MI_GP0
) {
6492 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6493 wlc
->pub
->unit
, wlc
->pub
->now
);
6495 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6496 __func__
, wlc
->pub
->sih
->chip
,
6497 wlc
->pub
->sih
->chiprev
);
6499 wlc
->pub
->_cnt
->psmwds
++;
6505 /* gptimer timeout */
6506 if (macintstatus
& MI_TO
) {
6507 wlc_hwtimer_gptimer_cb(wlc
);
6510 if (macintstatus
& MI_RFDISABLE
) {
6511 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6513 R_REG(®s
->phydebug
) & PDBG_RFD
);
6514 /* delay the cleanup to wl_down in IBSS case */
6515 if ((R_REG(®s
->phydebug
) & PDBG_RFD
)) {
6517 struct wlc_bsscfg
*bsscfg
;
6518 FOREACH_BSS(wlc
, idx
, bsscfg
) {
6519 if (!BSSCFG_STA(bsscfg
) || !bsscfg
->enable
6522 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6528 /* send any enq'd tx packets. Just makes sure to jump start tx */
6529 if (!pktq_empty(&wlc
->active_queue
->q
))
6530 wlc_send_q(wlc
, wlc
->active_queue
);
6532 ASSERT(wlc_ps_check(wlc
));
6535 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
)
6538 /* the post-increment is used in STAY_AWAKE macro */
6539 if (wlc
->txpend16165war
++ == 0)
6540 wlc_set_ps_ctrl(wlc
);
6542 wlc
->txpend16165war
--;
6543 if (wlc
->txpend16165war
== 0)
6544 wlc_set_ps_ctrl(wlc
);
6548 /* process an individual tx_status_t */
6551 wlc_dotxstatus(struct wlc_info
*wlc
, tx_status_t
*txs
, u32 frm_tx2
)
6556 struct scb
*scb
= NULL
;
6558 int tx_rts
, tx_frame_count
, tx_rts_count
;
6559 uint totlen
, supr_status
;
6561 struct ieee80211_hdr
*h
;
6563 struct ieee80211_tx_info
*tx_info
;
6564 struct ieee80211_tx_rate
*txrate
;
6567 (void)(frm_tx2
); /* Compiler reference to avoid unused variable warning */
6569 /* discard intermediate indications for ucode with one legitimate case:
6570 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6571 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6572 * transmission count)
6574 if (!(txs
->status
& TX_STATUS_AMPDU
)
6575 && (txs
->status
& TX_STATUS_INTERMEDIATE
)) {
6576 WLCNTADD(wlc
->pub
->_cnt
->txnoack
,
6578 status
& TX_STATUS_FRM_RTX_MASK
) >>
6579 TX_STATUS_FRM_RTX_SHIFT
));
6580 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__
);
6584 queue
= txs
->frameid
& TXFID_QUEUE_MASK
;
6585 ASSERT(queue
< NFIFO
);
6586 if (queue
>= NFIFO
) {
6591 p
= GETNEXTTXP(wlc
, queue
);
6592 if (WLC_WAR16165(wlc
))
6593 wlc_war16165(wlc
, false);
6597 txh
= (d11txh_t
*) (p
->data
);
6598 mcl
= le16_to_cpu(txh
->MacTxControlLow
);
6601 if (WL_ERROR_ON()) {
6602 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6603 txs
->phyerr
, txh
->MainRates
);
6604 wlc_print_txdesc(txh
);
6606 wlc_print_txstatus(txs
);
6609 ASSERT(txs
->frameid
== cpu_to_le16(txh
->TxFrameID
));
6610 if (txs
->frameid
!= cpu_to_le16(txh
->TxFrameID
))
6613 tx_info
= IEEE80211_SKB_CB(p
);
6614 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
6616 if (tx_info
->control
.sta
)
6617 scb
= (struct scb
*)tx_info
->control
.sta
->drv_priv
;
6619 if (N_ENAB(wlc
->pub
)) {
6620 u8
*plcp
= (u8
*) (txh
+ 1);
6621 if (PLCP3_ISSGI(plcp
[3]))
6622 wlc
->pub
->_cnt
->txmpdu_sgi
++;
6623 if (PLCP3_ISSTBC(plcp
[3]))
6624 wlc
->pub
->_cnt
->txmpdu_stbc
++;
6627 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
6628 ASSERT((mcl
& TXC_AMPDU_MASK
) != TXC_AMPDU_NONE
);
6629 wlc_ampdu_dotxstatus(wlc
->ampdu
, scb
, p
, txs
);
6633 supr_status
= txs
->status
& TX_STATUS_SUPR_MASK
;
6634 if (supr_status
== TX_STATUS_SUPR_BADCH
)
6635 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6636 __func__
, CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
));
6638 tx_rts
= cpu_to_le16(txh
->MacTxControlLow
) & TXC_SENDRTS
;
6640 (txs
->status
& TX_STATUS_FRM_RTX_MASK
) >> TX_STATUS_FRM_RTX_SHIFT
;
6642 (txs
->status
& TX_STATUS_RTS_RTX_MASK
) >> TX_STATUS_RTS_RTX_SHIFT
;
6644 lastframe
= !ieee80211_has_morefrags(h
->frame_control
);
6647 WL_ERROR("Not last frame!\n");
6650 ieee80211_tx_info_clear_status(tx_info
);
6651 if (queue
< AC_COUNT
) {
6652 sfbl
= WLC_WME_RETRY_SFB_GET(wlc
, wme_fifo2ac
[queue
]);
6653 lfbl
= WLC_WME_RETRY_LFB_GET(wlc
, wme_fifo2ac
[queue
]);
6659 txrate
= tx_info
->status
.rates
;
6660 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6661 if ((tx_frame_count
> sfbl
) && (txrate
[1].idx
>= 0)) {
6662 /* rate selection requested a fallback rate and we used it */
6663 txrate
->count
= lfbl
;
6664 txrate
[1].count
= tx_frame_count
- lfbl
;
6666 /* rate selection did not request fallback rate, or we didn't need it */
6667 txrate
->count
= tx_frame_count
;
6668 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6670 txrate
[1].count
= 0;
6673 /* clear the rest of the rates */
6674 for (i
= 2; i
< IEEE80211_TX_MAX_RATES
; i
++) {
6676 txrate
[i
].count
= 0;
6679 if (txs
->status
& TX_STATUS_ACK_RCV
)
6680 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
6683 totlen
= pkttotlen(p
);
6686 wlc_txfifo_complete(wlc
, queue
, 1);
6692 /* remove PLCP & Broadcom tx descriptor header */
6693 skb_pull(p
, D11_PHY_HDR_LEN
);
6694 skb_pull(p
, D11_TXH_LEN
);
6695 ieee80211_tx_status_irqsafe(wlc
->pub
->ieee_hw
, p
);
6696 wlc
->pub
->_cnt
->ieee_tx_status
++;
6698 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6707 pkt_buf_free_skb(p
);
6714 wlc_txfifo_complete(struct wlc_info
*wlc
, uint fifo
, s8 txpktpend
)
6716 TXPKTPENDDEC(wlc
, fifo
, txpktpend
);
6717 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6718 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
6720 /* There is more room; mark precedences related to this FIFO sendable */
6721 WLC_TX_FIFO_ENAB(wlc
, fifo
);
6722 ASSERT(TXPKTPENDGET(wlc
, fifo
) >= 0);
6724 if (!TXPKTPENDTOT(wlc
)) {
6725 if (wlc
->block_datafifo
& DATA_BLOCK_TX_SUPR
)
6726 wlc_bsscfg_tx_check(wlc
);
6729 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6730 if (AP_ENAB(wlc
->pub
) &&
6731 wlc
->bcmcfifo_drain
&& !TXPKTPENDGET(wlc
, TX_BCMC_FIFO
)) {
6732 wlc
->bcmcfifo_drain
= false;
6733 wlc_mhf(wlc
, MHF2
, MHF2_TXBCMC_NOW
, 0, WLC_BAND_AUTO
);
6736 /* figure out which bsscfg is being worked on... */
6739 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6740 * return the offset (in us) of the TSF from the last TBTT
6742 u32
wlc_calc_tbtt_offset(u32 bp
, u32 tsf_h
, u32 tsf_l
)
6744 u32 k
, btklo
, btkhi
, offset
;
6746 /* TBTT is always an even multiple of the beacon_interval,
6747 * so the TBTT less than or equal to the beacon timestamp is
6748 * the beacon timestamp minus the beacon timestamp modulo
6749 * the beacon interval.
6751 * TBTT = BT - (BT % BIu)
6752 * = (BTk - (BTk % BP)) * 2^10
6754 * BT = beacon timestamp (usec, 64bits)
6755 * BTk = beacon timestamp (Kusec, 54bits)
6756 * BP = beacon interval (Kusec, 16bits)
6757 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6759 * To keep the calculations in u32s, the modulo operation
6760 * on the high part of BT needs to be done in parts using the
6762 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6764 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6766 * So, if BTk[n] = u16 n [0,3] of BTk.
6767 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6768 * and the SUM term can be broken down:
6769 * (BTk[n] * 2^16n) % BP
6770 * (BTk[n] * (2^16n % BP)) % BP
6772 * Create a set of power of 2 mod BP constants:
6773 * K[n] = 2^(16n) % BP
6774 * = (K[n-1] * 2^16) % BP
6775 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6777 * BTk % BP = BTk[0-1] % BP +
6778 * (BTk[2] * K[2]) % BP +
6779 * (BTk[3] * K[3]) % BP
6781 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6784 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6785 btklo
= (tsf_h
<< 22) | (tsf_l
>> 10);
6786 btkhi
= tsf_h
>> 10;
6788 /* offset = BTk % BP */
6789 offset
= btklo
% bp
;
6791 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6792 k
= (u32
) (1 << 16) % bp
;
6793 k
= (u32
) (k
* 1 << 16) % (u32
) bp
;
6795 /* offset += (BTk[2] * K[2]) % BP */
6796 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6799 btkhi
= btkhi
>> 16;
6801 /* k[3] = (K[2] * 2^16) % BP */
6804 /* offset += (BTk[3] * K[3]) % BP */
6805 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6807 offset
= offset
% bp
;
6809 /* convert offset from kus to us by shifting up 10 bits and
6810 * add in the low 10 bits of tsf that we ignored
6812 offset
= (offset
<< 10) + (tsf_l
& 0x3FF);
6817 /* Update beacon listen interval in shared memory */
6818 void wlc_bcn_li_upd(struct wlc_info
*wlc
)
6820 if (AP_ENAB(wlc
->pub
))
6823 /* wake up every DTIM is the default */
6824 if (wlc
->bcn_li_dtim
== 1)
6825 wlc_write_shm(wlc
, M_BCN_LI
, 0);
6827 wlc_write_shm(wlc
, M_BCN_LI
,
6828 (wlc
->bcn_li_dtim
<< 8) | wlc
->bcn_li_bcn
);
6832 prep_mac80211_status(struct wlc_info
*wlc
, d11rxhdr_t
*rxh
, struct sk_buff
*p
,
6833 struct ieee80211_rx_status
*rx_status
)
6836 wlc_d11rxhdr_t
*wlc_rxh
= (wlc_d11rxhdr_t
*) rxh
;
6840 unsigned char *plcp
;
6843 /* Clearly, this is bogus -- reading the TSF now is wrong */
6844 wlc_read_tsf(wlc
, &tsf_l
, &tsf_h
); /* mactime */
6845 rx_status
->mactime
= tsf_h
;
6846 rx_status
->mactime
<<= 32;
6847 rx_status
->mactime
|= tsf_l
;
6848 rx_status
->flag
|= RX_FLAG_MACTIME_MPDU
; /* clearly wrong */
6851 channel
= WLC_CHAN_CHANNEL(rxh
->RxChan
);
6854 rx_status
->band
= IEEE80211_BAND_5GHZ
;
6855 rx_status
->freq
= ieee80211_ofdm_chan_to_freq(
6856 WF_CHAN_FACTOR_5_G
/2, channel
);
6859 rx_status
->band
= IEEE80211_BAND_2GHZ
;
6860 rx_status
->freq
= ieee80211_dsss_chan_to_freq(channel
);
6863 rx_status
->signal
= wlc_rxh
->rssi
; /* signal */
6867 rx_status
->antenna
= (rxh
->PhyRxStatus_0
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0; /* ant */
6871 rspec
= wlc_compute_rspec(rxh
, plcp
);
6872 if (IS_MCS(rspec
)) {
6873 rx_status
->rate_idx
= rspec
& RSPEC_RATE_MASK
;
6874 rx_status
->flag
|= RX_FLAG_HT
;
6875 if (RSPEC_IS40MHZ(rspec
))
6876 rx_status
->flag
|= RX_FLAG_40MHZ
;
6878 switch (RSPEC2RATE(rspec
)) {
6880 rx_status
->rate_idx
= 0;
6883 rx_status
->rate_idx
= 1;
6886 rx_status
->rate_idx
= 2;
6889 rx_status
->rate_idx
= 3;
6892 rx_status
->rate_idx
= 4;
6895 rx_status
->rate_idx
= 5;
6898 rx_status
->rate_idx
= 6;
6901 rx_status
->rate_idx
= 7;
6904 rx_status
->rate_idx
= 8;
6907 rx_status
->rate_idx
= 9;
6910 rx_status
->rate_idx
= 10;
6913 rx_status
->rate_idx
= 11;
6916 WL_ERROR("%s: Unknown rate\n", __func__
);
6919 /* Determine short preamble and rate_idx */
6921 if (IS_CCK(rspec
)) {
6922 if (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
)
6923 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6924 } else if (IS_OFDM(rspec
)) {
6925 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6927 WL_ERROR("%s: Unknown modulation\n", __func__
);
6931 if (PLCP3_ISSGI(plcp
[3]))
6932 rx_status
->flag
|= RX_FLAG_SHORT_GI
;
6934 if (rxh
->RxStatus1
& RXS_DECERR
) {
6935 rx_status
->flag
|= RX_FLAG_FAILED_PLCP_CRC
;
6936 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__
);
6938 if (rxh
->RxStatus1
& RXS_FCSERR
) {
6939 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
6940 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__
);
6945 wlc_recvctl(struct wlc_info
*wlc
, d11rxhdr_t
*rxh
, struct sk_buff
*p
)
6948 struct ieee80211_rx_status rx_status
;
6950 struct sk_buff
*skb
= p
;
6953 memset(&rx_status
, 0, sizeof(rx_status
));
6954 prep_mac80211_status(wlc
, rxh
, p
, &rx_status
);
6956 /* mac header+body length, exclude CRC and plcp header */
6957 len_mpdu
= p
->len
- D11_PHY_HDR_LEN
- FCS_LEN
;
6958 skb_pull(p
, D11_PHY_HDR_LEN
);
6959 __skb_trim(p
, len_mpdu
);
6964 ASSERT(IS_ALIGNED((unsigned long)skb
->data
, 2));
6966 memcpy(IEEE80211_SKB_RXCB(p
), &rx_status
, sizeof(rx_status
));
6967 ieee80211_rx_irqsafe(wlc
->pub
->ieee_hw
, p
);
6969 wlc
->pub
->_cnt
->ieee_rx
++;
6973 void wlc_bss_list_free(struct wlc_info
*wlc
, struct wlc_bss_list
*bss_list
)
6978 WL_ERROR("%s: Attempting to free NULL list\n", __func__
);
6981 /* inspect all BSS descriptor */
6982 for (index
= 0; index
< bss_list
->count
; index
++) {
6983 kfree(bss_list
->ptrs
[index
]);
6984 bss_list
->ptrs
[index
] = NULL
;
6986 bss_list
->count
= 0;
6989 /* Process received frames */
6991 * Return true if more frames need to be processed. false otherwise.
6992 * Param 'bound' indicates max. # frames to process before break out.
6995 void BCMFASTPATH
wlc_recv(struct wlc_info
*wlc
, struct sk_buff
*p
)
6998 struct ieee80211_hdr
*h
;
7002 WL_TRACE("wl%d: wlc_recv\n", wlc
->pub
->unit
);
7004 /* frame starts with rxhdr */
7005 rxh
= (d11rxhdr_t
*) (p
->data
);
7007 /* strip off rxhdr */
7008 skb_pull(p
, wlc
->hwrxoff
);
7010 /* fixup rx header endianness */
7011 rxh
->RxFrameSize
= le16_to_cpu(rxh
->RxFrameSize
);
7012 rxh
->PhyRxStatus_0
= le16_to_cpu(rxh
->PhyRxStatus_0
);
7013 rxh
->PhyRxStatus_1
= le16_to_cpu(rxh
->PhyRxStatus_1
);
7014 rxh
->PhyRxStatus_2
= le16_to_cpu(rxh
->PhyRxStatus_2
);
7015 rxh
->PhyRxStatus_3
= le16_to_cpu(rxh
->PhyRxStatus_3
);
7016 rxh
->PhyRxStatus_4
= le16_to_cpu(rxh
->PhyRxStatus_4
);
7017 rxh
->PhyRxStatus_5
= le16_to_cpu(rxh
->PhyRxStatus_5
);
7018 rxh
->RxStatus1
= le16_to_cpu(rxh
->RxStatus1
);
7019 rxh
->RxStatus2
= le16_to_cpu(rxh
->RxStatus2
);
7020 rxh
->RxTSFTime
= le16_to_cpu(rxh
->RxTSFTime
);
7021 rxh
->RxChan
= le16_to_cpu(rxh
->RxChan
);
7023 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7024 if (rxh
->RxStatus1
& RXS_PBPRES
) {
7026 wlc
->pub
->_cnt
->rxrunt
++;
7027 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7028 wlc
->pub
->unit
, p
->len
);
7034 h
= (struct ieee80211_hdr
*)(p
->data
+ D11_PHY_HDR_LEN
);
7037 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7038 if (wlc
->pub
->mac80211_state
& MAC80211_PROMISC_BCNS
) {
7039 WL_ERROR("FCSERR while scanning******* - tossing\n");
7042 WL_ERROR("RCSERR!!!\n");
7047 /* check received pkt has at least frame control field */
7048 if (len
< D11_PHY_HDR_LEN
+ sizeof(h
->frame_control
)) {
7049 wlc
->pub
->_cnt
->rxrunt
++;
7053 is_amsdu
= rxh
->RxStatus2
& RXS_AMSDU_MASK
;
7055 /* explicitly test bad src address to avoid sending bad deauth */
7057 /* CTS and ACK CTL frames are w/o a2 */
7059 if (ieee80211_is_data(h
->frame_control
) ||
7060 ieee80211_is_mgmt(h
->frame_control
)) {
7061 if ((is_zero_ether_addr(h
->addr2
) ||
7062 is_multicast_ether_addr(h
->addr2
))) {
7063 WL_ERROR("wl%d: %s: dropping a frame with "
7064 "invalid src mac address, a2: %pM\n",
7065 wlc
->pub
->unit
, __func__
, h
->addr2
);
7066 wlc
->pub
->_cnt
->rxbadsrcmac
++;
7069 wlc
->pub
->_cnt
->rxfrag
++;
7073 /* due to sheer numbers, toss out probe reqs for now */
7074 if (ieee80211_is_probe_req(h
->frame_control
))
7080 wlc_recvctl(wlc
, rxh
, p
);
7084 pkt_buf_free_skb(p
);
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
, u16 type
, ratespec_t bcn_rspec
,
7627 struct wlc_bsscfg
*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
== IEEE80211_STYPE_BEACON
||
7636 type
== IEEE80211_STYPE_PROBE_RESP
);
7638 if (MBSS_BCN_ENAB(cfg
) && type
== IEEE80211_STYPE_BEACON
)
7639 hdr_len
= DOT11_MAC_HDR_LEN
;
7641 hdr_len
= D11_PHY_HDR_LEN
+ DOT11_MAC_HDR_LEN
;
7642 body_len
= *len
- hdr_len
; /* calc buffer size provided for frame body */
7644 *len
= hdr_len
+ body_len
; /* return actual size */
7646 /* format PHY and MAC headers */
7647 memset((char *)buf
, 0, hdr_len
);
7649 plcp
= (cck_phy_hdr_t
*) buf
;
7651 /* PLCP for Probe Response frames are filled in from core's rate table */
7652 if (type
== IEEE80211_STYPE_BEACON
&& !MBSS_BCN_ENAB(cfg
)) {
7654 wlc_compute_plcp(wlc
, bcn_rspec
,
7655 (DOT11_MAC_HDR_LEN
+ body_len
+ FCS_LEN
),
7659 /* "Regular" and 16 MBSS but not for 4 MBSS */
7660 /* Update the phytxctl for the beacon based on the rspec */
7661 if (!SOFTBCN_ENAB(cfg
))
7662 wlc_beacon_phytxctl_txant_upd(wlc
, bcn_rspec
);
7664 if (MBSS_BCN_ENAB(cfg
) && type
== IEEE80211_STYPE_BEACON
)
7665 h
= (struct ieee80211_mgmt
*)&plcp
[0];
7667 h
= (struct ieee80211_mgmt
*)&plcp
[1];
7669 /* fill in 802.11 header */
7670 h
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
| type
);
7672 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7673 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7674 if (type
== IEEE80211_STYPE_BEACON
)
7675 memcpy(&h
->da
, ðer_bcast
, ETH_ALEN
);
7676 memcpy(&h
->sa
, &cfg
->cur_etheraddr
, ETH_ALEN
);
7677 memcpy(&h
->bssid
, &cfg
->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
, struct wlc_bsscfg
*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 /* Optimize: Some of if/else could be combined */
7706 if (!MBSS_BCN_ENAB(cfg
) && HWBCN_ENAB(cfg
)) {
7707 /* Hardware beaconing for this config */
7708 u16 bcn
[BCN_TMPL_LEN
/ 2];
7709 u32 both_valid
= MCMD_BCN0VLD
| MCMD_BCN1VLD
;
7710 d11regs_t
*regs
= wlc
->regs
;
7712 /* Check if both templates are in use, if so sched. an interrupt
7713 * that will call back into this routine
7715 if ((R_REG(®s
->maccommand
) & both_valid
) == both_valid
) {
7716 /* clear any previous status */
7717 W_REG(®s
->macintstatus
, MI_BCNTPL
);
7719 /* Check that after scheduling the interrupt both of the
7720 * templates are still busy. if not clear the int. & remask
7722 if ((R_REG(®s
->maccommand
) & both_valid
) == both_valid
) {
7723 wlc
->defmacintmask
|= MI_BCNTPL
;
7728 wlc_lowest_basic_rspec(wlc
, &cfg
->current_bss
->rateset
);
7729 ASSERT(wlc_valid_rate
7730 (wlc
, wlc
->bcn_rspec
,
7731 CHSPEC_IS2G(cfg
->current_bss
->
7732 chanspec
) ? WLC_BAND_2G
: WLC_BAND_5G
,
7735 /* update the template and ucode shm */
7736 wlc_bcn_prb_template(wlc
, IEEE80211_STYPE_BEACON
,
7737 wlc
->bcn_rspec
, cfg
, bcn
, &len
);
7738 wlc_write_hw_bcntemplates(wlc
, bcn
, len
, false);
7743 * Update all beacons for the system.
7745 void wlc_update_beacon(struct wlc_info
*wlc
)
7748 struct wlc_bsscfg
*bsscfg
;
7750 /* update AP or IBSS beacons */
7751 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7752 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7753 wlc_bss_update_beacon(wlc
, bsscfg
);
7757 /* Write ssid into shared memory */
7758 void wlc_shm_ssid_upd(struct wlc_info
*wlc
, struct wlc_bsscfg
*cfg
)
7760 u8
*ssidptr
= cfg
->SSID
;
7762 u8 ssidbuf
[IEEE80211_MAX_SSID_LEN
];
7764 /* padding the ssid with zero and copy it into shm */
7765 memset(ssidbuf
, 0, IEEE80211_MAX_SSID_LEN
);
7766 memcpy(ssidbuf
, ssidptr
, cfg
->SSID_len
);
7768 wlc_copyto_shm(wlc
, base
, ssidbuf
, IEEE80211_MAX_SSID_LEN
);
7770 if (!MBSS_BCN_ENAB(cfg
))
7771 wlc_write_shm(wlc
, M_SSIDLEN
, (u16
) cfg
->SSID_len
);
7774 void wlc_update_probe_resp(struct wlc_info
*wlc
, bool suspend
)
7777 struct wlc_bsscfg
*bsscfg
;
7779 /* update AP or IBSS probe responses */
7780 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7781 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7782 wlc_bss_update_probe_resp(wlc
, bsscfg
, suspend
);
7787 wlc_bss_update_probe_resp(struct wlc_info
*wlc
, struct wlc_bsscfg
*cfg
,
7790 u16 prb_resp
[BCN_TMPL_LEN
/ 2];
7791 int len
= BCN_TMPL_LEN
;
7793 /* write the probe response to hardware, or save in the config structure */
7794 if (!MBSS_PRB_ENAB(cfg
)) {
7796 /* create the probe response template */
7797 wlc_bcn_prb_template(wlc
, IEEE80211_STYPE_PROBE_RESP
, 0, cfg
,
7801 wlc_suspend_mac_and_wait(wlc
);
7803 /* write the probe response into the template region */
7804 wlc_bmac_write_template_ram(wlc
->hw
, T_PRS_TPL_BASE
,
7805 (len
+ 3) & ~3, prb_resp
);
7807 /* write the length of the probe response frame (+PLCP/-FCS) */
7808 wlc_write_shm(wlc
, M_PRB_RESP_FRM_LEN
, (u16
) len
);
7810 /* write the SSID and SSID length */
7811 wlc_shm_ssid_upd(wlc
, cfg
);
7814 * Write PLCP headers and durations for probe response frames at all rates.
7815 * Use the actual frame length covered by the PLCP header for the call to
7816 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7818 len
+= (-D11_PHY_HDR_LEN
+ FCS_LEN
);
7819 wlc_mod_prb_rsp_rate_table(wlc
, (u16
) len
);
7822 wlc_enable_mac(wlc
);
7823 } else { /* Generating probe resp in sw; update local template */
7824 ASSERT(0 && "No software probe response support without MBSS");
7828 /* prepares pdu for transmission. returns BCM error codes */
7829 int wlc_prep_pdu(struct wlc_info
*wlc
, struct sk_buff
*pdu
, uint
*fifop
)
7833 struct ieee80211_hdr
*h
;
7837 txh
= (d11txh_t
*) (pdu
->data
);
7839 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
7842 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7843 fifo
= le16_to_cpu(txh
->TxFrameID
) & TXFID_QUEUE_MASK
;
7849 /* return if insufficient dma resources */
7850 if (TXAVAIL(wlc
, fifo
) < MAX_DMA_SEGS
) {
7851 /* Mark precedences related to this FIFO, unsendable */
7852 WLC_TX_FIFO_CLEAR(wlc
, fifo
);
7856 if (!ieee80211_is_data(txh
->MacFrameControl
))
7857 wlc
->pub
->_cnt
->txctl
++;
7862 /* init tx reported rate mechanism */
7863 void wlc_reprate_init(struct wlc_info
*wlc
)
7866 struct wlc_bsscfg
*bsscfg
;
7868 FOREACH_BSS(wlc
, i
, bsscfg
) {
7869 wlc_bsscfg_reprate_init(bsscfg
);
7873 /* per bsscfg init tx reported rate mechanism */
7874 void wlc_bsscfg_reprate_init(struct wlc_bsscfg
*bsscfg
)
7876 bsscfg
->txrspecidx
= 0;
7877 memset((char *)bsscfg
->txrspec
, 0, sizeof(bsscfg
->txrspec
));
7880 /* Retrieve a consolidated set of revision information,
7881 * typically for the WLC_GET_REVINFO ioctl
7883 int wlc_get_revision_info(struct wlc_info
*wlc
, void *buf
, uint len
)
7885 wlc_rev_info_t
*rinfo
= (wlc_rev_info_t
*) buf
;
7887 if (len
< WL_REV_INFO_LEGACY_LENGTH
)
7888 return BCME_BUFTOOSHORT
;
7890 rinfo
->vendorid
= wlc
->vendorid
;
7891 rinfo
->deviceid
= wlc
->deviceid
;
7892 rinfo
->radiorev
= (wlc
->band
->radiorev
<< IDCODE_REV_SHIFT
) |
7893 (wlc
->band
->radioid
<< IDCODE_ID_SHIFT
);
7894 rinfo
->chiprev
= wlc
->pub
->sih
->chiprev
;
7895 rinfo
->corerev
= wlc
->pub
->corerev
;
7896 rinfo
->boardid
= wlc
->pub
->sih
->boardtype
;
7897 rinfo
->boardvendor
= wlc
->pub
->sih
->boardvendor
;
7898 rinfo
->boardrev
= wlc
->pub
->boardrev
;
7899 rinfo
->ucoderev
= wlc
->ucode_rev
;
7900 rinfo
->driverrev
= EPI_VERSION_NUM
;
7901 rinfo
->bus
= wlc
->pub
->sih
->bustype
;
7902 rinfo
->chipnum
= wlc
->pub
->sih
->chip
;
7904 if (len
>= (offsetof(wlc_rev_info_t
, chippkg
))) {
7905 rinfo
->phytype
= wlc
->band
->phytype
;
7906 rinfo
->phyrev
= wlc
->band
->phyrev
;
7907 rinfo
->anarev
= 0; /* obsolete stuff, suppress */
7910 if (len
>= sizeof(*rinfo
)) {
7911 rinfo
->chippkg
= wlc
->pub
->sih
->chippkg
;
7917 void wlc_default_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
7919 wlc_rateset_default(rs
, NULL
, wlc
->band
->phytype
, wlc
->band
->bandtype
,
7920 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7921 CHSPEC_WLC_BW(wlc
->default_bss
->chanspec
),
7922 wlc
->stf
->txstreams
);
7925 static void wlc_bss_default_init(struct wlc_info
*wlc
)
7927 chanspec_t chanspec
;
7928 struct wlcband
*band
;
7929 wlc_bss_info_t
*bi
= wlc
->default_bss
;
7931 /* init default and target BSS with some sane initial values */
7932 memset((char *)(bi
), 0, sizeof(wlc_bss_info_t
));
7933 bi
->beacon_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? BEACON_INTERVAL_DEF_QT
:
7934 BEACON_INTERVAL_DEFAULT
;
7935 bi
->dtim_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? DTIM_INTERVAL_DEF_QT
:
7936 DTIM_INTERVAL_DEFAULT
;
7938 /* fill the default channel as the first valid channel
7939 * starting from the 2G channels
7941 chanspec
= CH20MHZ_CHSPEC(1);
7942 ASSERT(chanspec
!= INVCHANSPEC
);
7944 wlc
->home_chanspec
= bi
->chanspec
= chanspec
;
7946 /* find the band of our default channel */
7948 if (NBANDS(wlc
) > 1 && band
->bandunit
!= CHSPEC_WLCBANDUNIT(chanspec
))
7949 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
7951 /* init bss rates to the band specific default rate set */
7952 wlc_rateset_default(&bi
->rateset
, NULL
, band
->phytype
, band
->bandtype
,
7953 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7954 CHSPEC_WLC_BW(chanspec
), wlc
->stf
->txstreams
);
7956 if (N_ENAB(wlc
->pub
))
7957 bi
->flags
|= WLC_BSS_HT
;
7961 wlc_uint64_sub(u32
*a_high
, u32
*a_low
, u32 b_high
, u32 b_low
)
7963 if (b_low
> *a_low
) {
7964 /* low half needs a carry */
7972 mac80211_wlc_set_nrate(struct wlc_info
*wlc
, struct wlcband
*cur_band
,
7975 u8 stf
= (int_val
& NRATE_STF_MASK
) >> NRATE_STF_SHIFT
;
7976 u8 rate
= int_val
& NRATE_RATE_MASK
;
7978 bool ismcs
= ((int_val
& NRATE_MCS_INUSE
) == NRATE_MCS_INUSE
);
7979 bool issgi
= ((int_val
& NRATE_SGI_MASK
) >> NRATE_SGI_SHIFT
);
7980 bool override_mcs_only
= ((int_val
& NRATE_OVERRIDE_MCS_ONLY
)
7981 == NRATE_OVERRIDE_MCS_ONLY
);
7985 return (ratespec_t
) rate
;
7988 /* validate the combination of rate/mcs/stf is allowed */
7989 if (N_ENAB(wlc
->pub
) && ismcs
) {
7990 /* mcs only allowed when nmode */
7991 if (stf
> PHY_TXC1_MODE_SDM
) {
7992 WL_ERROR("wl%d: %s: Invalid stf\n",
7993 WLCWLUNIT(wlc
), __func__
);
7994 bcmerror
= BCME_RANGE
;
7998 /* mcs 32 is a special case, DUP mode 40 only */
8000 if (!CHSPEC_IS40(wlc
->home_chanspec
) ||
8001 ((stf
!= PHY_TXC1_MODE_SISO
)
8002 && (stf
!= PHY_TXC1_MODE_CDD
))) {
8003 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8004 WLCWLUNIT(wlc
), __func__
);
8005 bcmerror
= BCME_RANGE
;
8008 /* mcs > 7 must use stf SDM */
8009 } else if (rate
> HIGHEST_SINGLE_STREAM_MCS
) {
8010 /* mcs > 7 must use stf SDM */
8011 if (stf
!= PHY_TXC1_MODE_SDM
) {
8012 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8013 WLCWLUNIT(wlc
), __func__
, rate
);
8014 stf
= PHY_TXC1_MODE_SDM
;
8017 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8018 if ((stf
> PHY_TXC1_MODE_STBC
) ||
8019 (!WLC_STBC_CAP_PHY(wlc
)
8020 && (stf
== PHY_TXC1_MODE_STBC
))) {
8021 WL_ERROR("wl%d: %s: Invalid STBC\n",
8022 WLCWLUNIT(wlc
), __func__
);
8023 bcmerror
= BCME_RANGE
;
8027 } else if (IS_OFDM(rate
)) {
8028 if ((stf
!= PHY_TXC1_MODE_CDD
) && (stf
!= PHY_TXC1_MODE_SISO
)) {
8029 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8030 WLCWLUNIT(wlc
), __func__
);
8031 bcmerror
= BCME_RANGE
;
8034 } else if (IS_CCK(rate
)) {
8035 if ((cur_band
->bandtype
!= WLC_BAND_2G
)
8036 || (stf
!= PHY_TXC1_MODE_SISO
)) {
8037 WL_ERROR("wl%d: %s: Invalid CCK\n",
8038 WLCWLUNIT(wlc
), __func__
);
8039 bcmerror
= BCME_RANGE
;
8043 WL_ERROR("wl%d: %s: Unknown rate type\n",
8044 WLCWLUNIT(wlc
), __func__
);
8045 bcmerror
= BCME_RANGE
;
8048 /* make sure multiple antennae are available for non-siso rates */
8049 if ((stf
!= PHY_TXC1_MODE_SISO
) && (wlc
->stf
->txstreams
== 1)) {
8050 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8051 WLCWLUNIT(wlc
), __func__
);
8052 bcmerror
= BCME_RANGE
;
8058 rspec
|= RSPEC_MIMORATE
;
8059 /* For STBC populate the STC field of the ratespec */
8060 if (stf
== PHY_TXC1_MODE_STBC
) {
8062 stc
= 1; /* Nss for single stream is always 1 */
8063 rspec
|= (stc
<< RSPEC_STC_SHIFT
);
8067 rspec
|= (stf
<< RSPEC_STF_SHIFT
);
8069 if (override_mcs_only
)
8070 rspec
|= RSPEC_OVERRIDE_MCS_ONLY
;
8073 rspec
|= RSPEC_SHORT_GI
;
8076 && !wlc_valid_rate(wlc
, rspec
, cur_band
->bandtype
, true)) {
8082 WL_ERROR("Hoark\n");
8086 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8088 wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
8091 int idle_busy_ratio_x_16
= 0;
8093 isOFDM
? M_TX_IDLE_BUSY_RATIO_X_16_OFDM
:
8094 M_TX_IDLE_BUSY_RATIO_X_16_CCK
;
8095 if (duty_cycle
> 100 || duty_cycle
< 0) {
8096 WL_ERROR("wl%d: duty cycle value off limit\n", wlc
->pub
->unit
);
8100 idle_busy_ratio_x_16
= (100 - duty_cycle
) * 16 / duty_cycle
;
8101 /* Only write to shared memory when wl is up */
8103 wlc_write_shm(wlc
, offset
, (u16
) idle_busy_ratio_x_16
);
8106 wlc
->tx_duty_cycle_ofdm
= (u16
) duty_cycle
;
8108 wlc
->tx_duty_cycle_cck
= (u16
) duty_cycle
;
8113 /* Read a single u16 from shared memory.
8114 * SHM 'offset' needs to be an even address
8116 u16
wlc_read_shm(struct wlc_info
*wlc
, uint offset
)
8118 return wlc_bmac_read_shm(wlc
->hw
, offset
);
8121 /* Write a single u16 to shared memory.
8122 * SHM 'offset' needs to be an even address
8124 void wlc_write_shm(struct wlc_info
*wlc
, uint offset
, u16 v
)
8126 wlc_bmac_write_shm(wlc
->hw
, offset
, v
);
8129 /* Set a range of shared memory to a value.
8130 * SHM 'offset' needs to be an even address and
8131 * Range length 'len' must be an even number of bytes
8133 void wlc_set_shm(struct wlc_info
*wlc
, uint offset
, u16 v
, int len
)
8135 /* offset and len need to be even */
8136 ASSERT((offset
& 1) == 0);
8137 ASSERT((len
& 1) == 0);
8142 wlc_bmac_set_shm(wlc
->hw
, offset
, v
, len
);
8145 /* Copy a buffer to shared memory.
8146 * SHM 'offset' needs to be an even address and
8147 * Buffer length 'len' must be an even number of bytes
8149 void wlc_copyto_shm(struct wlc_info
*wlc
, uint offset
, const void *buf
, int len
)
8151 /* offset and len need to be even */
8152 ASSERT((offset
& 1) == 0);
8153 ASSERT((len
& 1) == 0);
8157 wlc_bmac_copyto_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8161 /* Copy from shared memory to a buffer.
8162 * SHM 'offset' needs to be an even address and
8163 * Buffer length 'len' must be an even number of bytes
8165 void wlc_copyfrom_shm(struct wlc_info
*wlc
, uint offset
, void *buf
, int len
)
8167 /* offset and len need to be even */
8168 ASSERT((offset
& 1) == 0);
8169 ASSERT((len
& 1) == 0);
8174 wlc_bmac_copyfrom_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8177 /* wrapper BMAC functions to for HIGH driver access */
8178 void wlc_mctrl(struct wlc_info
*wlc
, u32 mask
, u32 val
)
8180 wlc_bmac_mctrl(wlc
->hw
, mask
, val
);
8183 void wlc_corereset(struct wlc_info
*wlc
, u32 flags
)
8185 wlc_bmac_corereset(wlc
->hw
, flags
);
8188 void wlc_mhf(struct wlc_info
*wlc
, u8 idx
, u16 mask
, u16 val
, int bands
)
8190 wlc_bmac_mhf(wlc
->hw
, idx
, mask
, val
, bands
);
8193 u16
wlc_mhf_get(struct wlc_info
*wlc
, u8 idx
, int bands
)
8195 return wlc_bmac_mhf_get(wlc
->hw
, idx
, bands
);
8198 int wlc_xmtfifo_sz_get(struct wlc_info
*wlc
, uint fifo
, uint
*blocks
)
8200 return wlc_bmac_xmtfifo_sz_get(wlc
->hw
, fifo
, blocks
);
8203 void wlc_write_template_ram(struct wlc_info
*wlc
, int offset
, int len
,
8206 wlc_bmac_write_template_ram(wlc
->hw
, offset
, len
, buf
);
8209 void wlc_write_hw_bcntemplates(struct wlc_info
*wlc
, void *bcn
, int len
,
8212 wlc_bmac_write_hw_bcntemplates(wlc
->hw
, bcn
, len
, both
);
8216 wlc_set_addrmatch(struct wlc_info
*wlc
, int match_reg_offset
,
8219 wlc_bmac_set_addrmatch(wlc
->hw
, match_reg_offset
, addr
);
8220 if (match_reg_offset
== RCM_BSSID_OFFSET
)
8221 memcpy(wlc
->cfg
->BSSID
, addr
, ETH_ALEN
);
8224 void wlc_set_rcmta(struct wlc_info
*wlc
, int idx
, const u8
*addr
)
8226 wlc_bmac_set_rcmta(wlc
->hw
, idx
, addr
);
8229 void wlc_read_tsf(struct wlc_info
*wlc
, u32
*tsf_l_ptr
, u32
*tsf_h_ptr
)
8231 wlc_bmac_read_tsf(wlc
->hw
, tsf_l_ptr
, tsf_h_ptr
);
8234 void wlc_set_cwmin(struct wlc_info
*wlc
, u16 newmin
)
8236 wlc
->band
->CWmin
= newmin
;
8237 wlc_bmac_set_cwmin(wlc
->hw
, newmin
);
8240 void wlc_set_cwmax(struct wlc_info
*wlc
, u16 newmax
)
8242 wlc
->band
->CWmax
= newmax
;
8243 wlc_bmac_set_cwmax(wlc
->hw
, newmax
);
8246 void wlc_fifoerrors(struct wlc_info
*wlc
)
8249 wlc_bmac_fifoerrors(wlc
->hw
);
8252 /* Search mem rw utilities */
8254 void wlc_pllreq(struct wlc_info
*wlc
, bool set
, mbool req_bit
)
8256 wlc_bmac_pllreq(wlc
->hw
, set
, req_bit
);
8259 void wlc_reset_bmac_done(struct wlc_info
*wlc
)
8263 void wlc_ht_mimops_cap_update(struct wlc_info
*wlc
, u8 mimops_mode
)
8265 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_SM_PS
;
8266 wlc
->ht_cap
.cap_info
|= (mimops_mode
<< IEEE80211_HT_CAP_SM_PS_SHIFT
);
8268 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
8269 wlc_update_beacon(wlc
);
8270 wlc_update_probe_resp(wlc
, true);
8274 /* check for the particular priority flow control bit being set */
8276 wlc_txflowcontrol_prio_isset(struct wlc_info
*wlc
, struct wlc_txq_info
*q
,
8281 if (prio
== ALLPRIO
) {
8282 prio_mask
= TXQ_STOP_FOR_PRIOFC_MASK
;
8284 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8285 prio_mask
= NBITVAL(prio
);
8288 return (q
->stopped
& prio_mask
) == prio_mask
;
8291 /* propagate the flow control to all interfaces using the given tx queue */
8292 void wlc_txflowcontrol(struct wlc_info
*wlc
, struct wlc_txq_info
*qi
,
8298 WL_TRACE("%s: flow control kicks in\n", __func__
);
8300 if (prio
== ALLPRIO
) {
8301 prio_bits
= TXQ_STOP_FOR_PRIOFC_MASK
;
8303 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8304 prio_bits
= NBITVAL(prio
);
8307 cur_bits
= qi
->stopped
& prio_bits
;
8309 /* Check for the case of no change and return early
8310 * Otherwise update the bit and continue
8313 if (cur_bits
== prio_bits
) {
8316 mboolset(qi
->stopped
, prio_bits
);
8318 if (cur_bits
== 0) {
8321 mboolclr(qi
->stopped
, prio_bits
);
8324 /* If there is a flow control override we will not change the external
8325 * flow control state.
8327 if (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
) {
8331 wlc_txflowcontrol_signal(wlc
, qi
, on
, prio
);
8335 wlc_txflowcontrol_override(struct wlc_info
*wlc
, struct wlc_txq_info
*qi
,
8336 bool on
, uint override
)
8340 ASSERT(override
!= 0);
8341 ASSERT((override
& TXQ_STOP_FOR_PRIOFC_MASK
) == 0);
8343 prev_override
= (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
);
8345 /* Update the flow control bits and do an early return if there is
8346 * no change in the external flow control state.
8349 mboolset(qi
->stopped
, override
);
8350 /* if there was a previous override bit on, then setting this
8351 * makes no difference.
8353 if (prev_override
) {
8357 wlc_txflowcontrol_signal(wlc
, qi
, ON
, ALLPRIO
);
8359 mboolclr(qi
->stopped
, override
);
8360 /* clearing an override bit will only make a difference for
8361 * flow control if it was the only bit set. For any other
8362 * override setting, just return
8364 if (prev_override
!= override
) {
8368 if (qi
->stopped
== 0) {
8369 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8373 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
8374 if (!mboolisset(qi
->stopped
, NBITVAL(prio
)))
8375 wlc_txflowcontrol_signal(wlc
, qi
, OFF
,
8382 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
)
8384 struct wlc_txq_info
*qi
;
8386 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
8388 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8395 wlc_txflowcontrol_signal(struct wlc_info
*wlc
, struct wlc_txq_info
*qi
, bool on
,
8398 struct wlc_if
*wlcif
;
8400 for (wlcif
= wlc
->wlcif_list
; wlcif
!= NULL
; wlcif
= wlcif
->next
) {
8401 if (wlcif
->qi
== qi
&& wlcif
->flags
& WLC_IF_LINKED
)
8402 wl_txflowcontrol(wlc
->wl
, wlcif
->wlif
, on
, prio
);
8406 static struct wlc_txq_info
*wlc_txq_alloc(struct wlc_info
*wlc
)
8408 struct wlc_txq_info
*qi
, *p
;
8410 qi
= wlc_calloc(wlc
->pub
->unit
, sizeof(struct wlc_txq_info
));
8413 * Have enough room for control packets along with HI watermark
8414 * Also, add room to txq for total psq packets if all the SCBs
8415 * leave PS mode. The watermark for flowcontrol to OS packets
8416 * will remain the same
8418 pktq_init(&qi
->q
, WLC_PREC_COUNT
,
8419 (2 * wlc
->pub
->tunables
->datahiwat
) + PKTQ_LEN_DEFAULT
8420 + wlc
->pub
->psq_pkts_total
);
8422 /* add this queue to the the global list */
8425 wlc
->tx_queues
= qi
;
8427 while (p
->next
!= NULL
)
8435 static void wlc_txq_free(struct wlc_info
*wlc
, struct wlc_txq_info
*qi
)
8437 struct wlc_txq_info
*p
;
8442 /* remove the queue from the linked list */
8445 wlc
->tx_queues
= p
->next
;
8447 while (p
!= NULL
&& p
->next
!= qi
)
8449 ASSERT(p
->next
== qi
);
8451 p
->next
= p
->next
->next
;
8458 * Flag 'scan in progress' to withhold dynamic phy calibration
8460 void wlc_scan_start(struct wlc_info
*wlc
)
8462 wlc_phy_hold_upd(wlc
->band
->pi
, PHY_HOLD_FOR_SCAN
, true);
8465 void wlc_scan_stop(struct wlc_info
*wlc
)
8467 wlc_phy_hold_upd(wlc
->band
->pi
, PHY_HOLD_FOR_SCAN
, false);
8470 void wlc_associate_upd(struct wlc_info
*wlc
, bool state
)
8472 wlc
->pub
->associated
= state
;
8473 wlc
->cfg
->associated
= state
;
8477 * When a remote STA/AP is removed by Mac80211, or when it can no longer accept
8478 * AMPDU traffic, packets pending in hardware have to be invalidated so that
8479 * when later on hardware releases them, they can be handled appropriately.
8481 void wlc_inval_dma_pkts(struct wlc_hw_info
*hw
,
8482 struct ieee80211_sta
*sta
,
8483 void (*dma_callback_fn
))
8485 struct hnddma_pub
*dmah
;
8487 for (i
= 0; i
< NFIFO
; i
++) {
8490 dma_walk_packets(dmah
, dma_callback_fn
, sta
);