/* * Copyright (c) 2010 Broadcom Corporation * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* watchdog timer, in unit of ms */ #define TIMER_INTERVAL_WATCHDOG 1000 /* radio monitor timer, in unit of ms */ #define TIMER_INTERVAL_RADIOCHK 800
/* beacon interval, in unit of 1024TU */ #define BEACON_INTERVAL_DEFAULT 100
/* n-mode support capability */ /* 2x2 includes both 1x1 & 2x2 devices * reserved #define 2 for future when we want to separate 1x1 & 2x2 and * control it independently
*/ #define WL_11N_2x2 1 #define WL_11N_3x3 3 #define WL_11N_4x4 4
/* # of entries in Tx FIFO */ #define NTXD 64 /* Max # of entries in Rx FIFO based on 4kb page size */ #define NRXD 256
/* Amount of headroom to leave in Tx FIFO */ #define TX_HEADROOM 4
/* try to keep this # rbufs posted to the chip */ #define NRXBUFPOST 32
/* max # frames to process in brcms_c_recv() */ #define RXBND 8 /* max # tx status to process in wlc_txstatus() */ #define TXSBND 8
/* * The following table lists the buffer memory allocated to xmt fifos in HW. * the size is in units of 256bytes(one block), total size is HW dependent * ucode has default fifo partition, sw can overwrite if necessary * * This is documented in twiki under the topic UcodeTxFifo. Please ensure * the twiki is updated before making changes.
*/
/* Starting corerev for the fifo size table */ #define XMTFIFOTBL_STARTREV 17
/* currently the best mechanism for determining SIFS is the band in use */ static u16 get_sifs(struct brcms_band *band)
{ return band->bandtype == BRCM_BAND_5G ? APHY_SIFS_TIME :
BPHY_SIFS_TIME;
}
/* * Detect Card removed. * Even checking an sbconfig register read will not false trigger when the core * is in reset it breaks CF address mechanism. Accessing gphy phyversion will * cause SB error if aphy is in reset on 4306B0-DB. Need a simple accessible * reg with fixed 0/1 pattern (some platforms return all 0). * If clocks are present, call the sb routine which will figure out if the * device is removed.
*/ staticbool brcms_deviceremoved(struct brcms_c_info *wlc)
{
u32 macctrl;
/* * Update the slot timing for standard 11b/g (20us slots) * or shortslot 11g (9us slots) * The PSM needs to be suspended for this call.
*/ staticvoid brcms_b_update_slot_timing(struct brcms_hardware *wlc_hw, bool shortslot)
{ struct bcma_device *core = wlc_hw->d11core;
/* discard intermediate indications for ucode with one legitimate case: * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, * but the subsequent tx of DATA failed. so it will start rts/cts * from the beginning (resetting the rts transmission count)
*/ if (!(txs->status & TX_STATUS_AMPDU)
&& (txs->status & TX_STATUS_INTERMEDIATE)) {
brcms_dbg_tx(wlc->hw->d11core, "INTERMEDIATE but not AMPDU\n");
fatal = false; goto out;
}
/* * brcms_c_ampdu_dotxstatus() will trace tx descriptors for AMPDU * frames; this traces them for the rest.
*/
trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, sizeof(*txh));
supr_status = txs->status & TX_STATUS_SUPR_MASK; if (supr_status == TX_STATUS_SUPR_BADCH) { unsigned xfts = le16_to_cpu(txh->XtraFrameTypes);
brcms_dbg_tx(wlc->hw->d11core, "Pkt tx suppressed, dest chan %u, current %d\n",
(xfts >> XFTS_CHANNEL_SHIFT) & 0xff,
CHSPEC_CHANNEL(wlc->default_bss->chanspec));
}
if (!lastframe) {
brcms_err(wlc->hw->d11core, "Not last frame!\n");
} else { /* * Set information to be consumed by Minstrel ht. * * The "fallback limit" is the number of tx attempts a given * MPDU is sent at the "primary" rate. Tx attempts beyond that * limit are sent at the "secondary" rate. * A 'short frame' does not exceed RTS threshold.
*/
u16 sfbl, /* Short Frame Rate Fallback Limit */
lfbl, /* Long Frame Rate Fallback Limit */
fbl;
if ((tx_frame_count > fbl) && (txrate[1].idx >= 0)) { /* * rate selection requested a fallback rate * and we used it
*/
txrate[0].count = fbl;
txrate[1].count = tx_frame_count - fbl;
} else { /* * rate selection did not request fallback rate, or * we didn't need it
*/
txrate[0].count = tx_frame_count; /* * rc80211_minstrel.c:minstrel_tx_status() expects * unused rates to be marked with idx = -1
*/
txrate[1].idx = -1;
txrate[1].count = 0;
}
/* clear the rest of the rates */ for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
txrate[i].idx = -1;
txrate[i].count = 0;
}
if (txs->status & TX_STATUS_ACK_RCV)
tx_info->flags |= IEEE80211_TX_STAT_ACK;
}
if (lastframe) { /* remove PLCP & Broadcom tx descriptor header */
skb_pull(p, D11_PHY_HDR_LEN);
skb_pull(p, D11_TXH_LEN);
ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
} else {
brcms_err(wlc->hw->d11core, "%s: Not last frame => not calling tx_status\n",
__func__);
}
fatal = false;
out: if (fatal) { if (txh)
trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, sizeof(*txh));
brcmu_pkt_buf_free_skb(p);
}
*fatal = brcms_c_dotxstatus(wlc_hw->wlc, txs); if (*fatal) returnfalse;
n++;
}
return n >= max_tx_num;
}
staticvoid brcms_c_tbtt(struct brcms_c_info *wlc)
{ if (wlc->bsscfg->type == BRCMS_TYPE_ADHOC) /* * DirFrmQ is now valid...defer setting until end * of ATIM window
*/
wlc->qvalid |= MCMD_DIRFRMQVAL;
}
/* get pointer to dma engine tx flow control variable */ for (i = 0; i < NFIFO; i++) if (wlc_hw->di[i])
wlc_hw->txavail[i] =
(uint *) dma_getvar(wlc_hw->di[i], "&txavail");
}
for (j = 0; j < NFIFO; j++) { if (wlc_hw->di[j]) {
dma_detach(wlc_hw->di[j]);
wlc_hw->di[j] = NULL;
}
}
}
/* * Initialize brcms_c_info default values ... * may get overrides later in this function * BMAC_NOTES, move low out and resolve the dangling ones
*/ staticvoid brcms_b_info_init(struct brcms_hardware *wlc_hw)
{ struct brcms_c_info *wlc = wlc_hw->wlc;
/* set default sw macintmask value */
wlc->defmacintmask = DEF_MACINTMASK;
/* various 802.11g modes */
wlc_hw->shortslot = false;
staticvoid brcms_b_wait_for_wake(struct brcms_hardware *wlc_hw)
{ /* delay before first read of ucode state */
udelay(40);
/* wait until ucode is no longer asleep */
SPINWAIT((brcms_b_read_shm(wlc_hw, M_UCODE_DBGST) ==
DBGST_ASLEEP), wlc_hw->wlc->fastpwrup_dly);
}
/* control chip clock to save power, enable dynamic clock or force fast clock */ staticvoid brcms_b_clkctl_clk(struct brcms_hardware *wlc_hw, enum bcma_clkmode mode)
{ if (ai_get_cccaps(wlc_hw->sih) & CC_CAP_PMU) { /* new chips with PMU, CCS_FORCEHT will distribute the HT clock * on backplane, but mac core will still run on ALP(not HT) when * it enters powersave mode, which means the FCA bit may not be * set. Should wakeup mac if driver wants it to run on HT.
*/
if (wlc_hw->clk) { if (mode == BCMA_CLKMODE_FAST) {
bcma_set32(wlc_hw->d11core,
D11REGOFFS(clk_ctl_st),
CCS_FORCEHT);
/* check fast clock is available (if core is not in reset) */ if (wlc_hw->forcefastclk && wlc_hw->clk)
WARN_ON(!(bcma_aread32(wlc_hw->d11core, BCMA_IOST) &
SISF_FCLKA));
/* * keep the ucode wake bit on if forcefastclk is on since we * do not want ucode to put us back to slow clock when it dozes * for PM mode. Code below matches the wake override bit with * current forcefastclk state. Only setting bit in wake_override * instead of waking ucode immediately since old code had this * behavior. Older code set wlc->forcefastclk but only had the * wake happen if the wakup_ucode work (protected by an up * check) was executed just below.
*/ if (wlc_hw->forcefastclk)
mboolset(wlc_hw->wake_override,
BRCMS_WAKE_OVERRIDE_FORCEFAST); else
mboolclr(wlc_hw->wake_override,
BRCMS_WAKE_OVERRIDE_FORCEFAST);
}
}
/* set or clear ucode host flag bits * it has an optimization for no-change write * it only writes through shared memory when the core has clock; * pre-CLK changes should use wlc_write_mhf to get around the optimization * * * bands values are: BRCM_BAND_AUTO <--- Current band only * BRCM_BAND_5G <--- 5G band only * BRCM_BAND_2G <--- 2G band only * BRCM_BAND_ALL <--- All bands
*/ void
brcms_b_mhf(struct brcms_hardware *wlc_hw, u8 idx, u16 mask, u16 val, int bands)
{
u16 save;
u16 addr[MHFMAX] = {
M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
M_HOST_FLAGS5
}; struct brcms_hw_band *band;
switch (bands) { /* Current band only or all bands, * then set the band to current band
*/ case BRCM_BAND_AUTO: case BRCM_BAND_ALL:
band = wlc_hw->band; break; case BRCM_BAND_5G:
band = wlc_hw->bandstate[BAND_5G_INDEX]; break; case BRCM_BAND_2G:
band = wlc_hw->bandstate[BAND_2G_INDEX]; break; default:
band = NULL; /* error condition */
}
if (band) {
save = band->mhfs[idx];
band->mhfs[idx] = (band->mhfs[idx] & ~mask) | val;
/* optimization: only write through if changed, and * changed band is the current band
*/ if (wlc_hw->clk && (band->mhfs[idx] != save)
&& (band == wlc_hw->band))
brcms_b_write_shm(wlc_hw, addr[idx],
(u16) band->mhfs[idx]);
}
/* set the maccontrol register to desired reset state and * initialize the sw cache of the register
*/ staticvoid brcms_c_mctrl_reset(struct brcms_hardware *wlc_hw)
{ /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
wlc_hw->maccontrol = 0;
wlc_hw->suspended_fifos = 0;
wlc_hw->wake_override = 0;
wlc_hw->mute_override = 0;
brcms_b_mctrl(wlc_hw, ~0, MCTL_IHR_EN | MCTL_WAKE);
}
/* * write the software state of maccontrol and * overrides to the maccontrol register
*/ staticvoid brcms_c_mctrl_write(struct brcms_hardware *wlc_hw)
{
u32 maccontrol = wlc_hw->maccontrol;
/* OR in the wake bit if overridden */ if (wlc_hw->wake_override)
maccontrol |= MCTL_WAKE;
/* set AP and INFRA bits for mute if needed */ if (wlc_hw->mute_override) {
maccontrol &= ~(MCTL_AP);
maccontrol |= MCTL_INFRA;
}
if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) return;
brcms_c_mctrl_write(wlc_hw);
}
/* When driver needs ucode to stop beaconing, it has to make sure that * MCTL_AP is clear and MCTL_INFRA is set * Mode MCTL_AP MCTL_INFRA * AP 1 1 * STA 0 1 <--- This will ensure no beacons * IBSS 0 0
*/ staticvoid brcms_c_ucode_mute_override_set(struct brcms_hardware *wlc_hw)
{
wlc_hw->mute_override = 1;
/* if maccontrol already has AP == 0 and INFRA == 1 without this * override, then there is no change to write
*/ if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA) return;
brcms_c_mctrl_write(wlc_hw);
}
/* Clear the override on AP and INFRA bits */ staticvoid brcms_c_ucode_mute_override_clear(struct brcms_hardware *wlc_hw)
{ if (wlc_hw->mute_override == 0) return;
wlc_hw->mute_override = 0;
/* if maccontrol already has AP == 0 and INFRA == 1 without this * override, then there is no change to write
*/ if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA) return;
brcms_c_mctrl_write(wlc_hw);
}
/* * Write a MAC address to the given match reg offset in the RXE match engine.
*/ staticvoid
brcms_b_set_addrmatch(struct brcms_hardware *wlc_hw, int match_reg_offset, const u8 *addr)
{ struct bcma_device *core = wlc_hw->d11core;
u16 mac_l;
u16 mac_m;
u16 mac_h;
/* enter the MAC addr into the RXE match registers */
bcma_write16(core, D11REGOFFS(rcm_ctl),
RCM_INC_DATA | match_reg_offset);
bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_l);
bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_m);
bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_h);
}
/* if MCTL_BIGEND bit set in mac control register, * the chip swaps data in fifo, as well as data in * template ram
*/
be_bit = (bcma_read32(core, D11REGOFFS(maccontrol)) & MCTL_BIGEND) != 0;
while (len > 0) {
memcpy(&word, buf, sizeof(u32));
if (be_bit) {
word_be = cpu_to_be32(word);
word = *(u32 *)&word_be;
} else {
word_le = cpu_to_le32(word);
word = *(u32 *)&word_le;
}
if (BRCMS_ISLCNPHY(wlc->band))
v = SYNTHPU_DLY_LPPHY_US; elseif (BRCMS_ISNPHY(wlc->band) && (NREV_GE(wlc->band->phyrev, 3)))
v = SYNTHPU_DLY_NPHY_US; else
v = SYNTHPU_DLY_BPHY_US;
for (i = 0; i < ARRAY_SIZE(rate_lookup); i++) { if (rate == rate_lookup[i].rate) {
plcp_rate = rate_lookup[i].signal_rate; break;
}
}
/* Find the SHM pointer to the rate table entry by looking in the * Direct-map Table
*/ return 2 * brcms_b_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2));
}
/* * cwmin is band-specific, update hardware * with value for current band
*/
brcms_b_set_cwmin(wlc_hw, wlc_hw->band->CWmin);
brcms_b_set_cwmax(wlc_hw, wlc_hw->band->CWmax);
/* light way to turn on phy clock without reset for NPHY only * refer to brcms_b_core_phy_clk for full version
*/ void brcms_b_phyclk_fgc(struct brcms_hardware *wlc_hw, bool clk)
{ /* support(necessary for NPHY and HYPHY) only */ if (!BRCMS_ISNPHY(wlc_hw->band)) return;
if (ON == clk)
brcms_b_core_ioctl(wlc_hw, SICF_FGC, SICF_FGC); else
brcms_b_core_ioctl(wlc_hw, SICF_FGC, 0);
}
void brcms_b_macphyclk_set(struct brcms_hardware *wlc_hw, bool clk)
{ if (ON == clk)
brcms_b_core_ioctl(wlc_hw, SICF_MPCLKE, SICF_MPCLKE); else
brcms_b_core_ioctl(wlc_hw, SICF_MPCLKE, 0);
}
/* Specific reset sequence required for NPHY rev 3 and 4 */ if (BRCMS_ISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) &&
NREV_LE(wlc_hw->band->phyrev, 4)) { /* Set the PHY bandwidth */
brcms_b_core_ioctl(wlc_hw, SICF_BWMASK, phy_bw_clkbits);
udelay(1);
/* Perform a soft reset of the PHY PLL */
brcms_b_core_phypll_reset(wlc_hw);
/* switch to and initialize new band */ staticvoid brcms_b_setband(struct brcms_hardware *wlc_hw, uint bandunit,
u16 chanspec) { struct brcms_c_info *wlc = wlc_hw->wlc;
u32 macintmask;
/* Enable the d11 core before accessing it */ if (!bcma_core_is_enabled(wlc_hw->d11core)) {
bcma_core_enable(wlc_hw->d11core, 0);
brcms_c_mctrl_reset(wlc_hw);
}
/* * If there are any pending software interrupt bits, * then replace these with a harmless nonzero value * so brcms_c_dpc() will re-enable interrupts when done.
*/ if (wlc->macintstatus)
wlc->macintstatus = MI_DMAINT;
/* power both the pll and external oscillator on/off */ staticvoid brcms_b_xtal(struct brcms_hardware *wlc_hw, bool want)
{
brcms_dbg_info(wlc_hw->d11core, "wl%d: want %d\n", wlc_hw->unit, want);
/* * dont power down if plldown is false or * we must poll hw radio disable
*/ if (!want && wlc_hw->pllreq) return;
wlc_hw->sbclk = want; if (!wlc_hw->sbclk) {
wlc_hw->clk = false; if (wlc_hw->band && wlc_hw->band->pi)
wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
}
}
/* * Return true if radio is disabled, otherwise false. * hw radio disable signal is an external pin, users activate it asynchronously * this function could be called when driver is down and w/o clock * it operates on different registers depending on corerev and boardflag.
*/ staticbool brcms_b_radio_read_hwdisabled(struct brcms_hardware *wlc_hw)
{ bool v, clk, xtal;
u32 flags = 0;
xtal = wlc_hw->sbclk; if (!xtal)
brcms_b_xtal(wlc_hw, ON);
/* may need to take core out of reset first */
clk = wlc_hw->clk; if (!clk) { /* * mac no longer enables phyclk automatically when driver * accesses phyreg throughput mac. This can be skipped since * only mac reg is accessed below
*/ if (D11REV_GE(wlc_hw->corerev, 18))
flags |= SICF_PCLKE;
/* * TODO: test suspend/resume * * AI chip doesn't restore bar0win2 on * hibernation/resume, need sw fixup
*/
/* request FAST clock if not on */
fastclk = wlc_hw->forcefastclk; if (!fastclk)
brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST);
/* reset the dma engines except first time thru */ if (bcma_core_is_enabled(wlc_hw->d11core)) { for (i = 0; i < NFIFO; i++) if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i])))
brcms_err(wlc_hw->d11core, "wl%d: %s: " "dma_txreset[%d]: cannot stop dma\n",
wlc_hw->unit, __func__, i);
if ((wlc_hw->di[RX_FIFO])
&& (!wlc_dma_rxreset(wlc_hw, RX_FIFO)))
brcms_err(wlc_hw->d11core, "wl%d: %s: dma_rxreset" "[%d]: cannot stop dma\n",
wlc_hw->unit, __func__, RX_FIFO);
} /* if noreset, just stop the psm and return */ if (wlc_hw->noreset) {
wlc_hw->wlc->macintstatus = 0; /* skip wl_dpc after down */
brcms_b_mctrl(wlc_hw, MCTL_PSM_RUN | MCTL_EN_MAC, 0); return;
}
/* * mac no longer enables phyclk automatically when driver accesses * phyreg throughput mac, AND phy_reset is skipped at early stage when * band->pi is invalid. need to enable PHY CLK
*/ if (D11REV_GE(wlc_hw->corerev, 18))
flags |= SICF_PCLKE;
/* * reset the core * In chips with PMU, the fastclk request goes through d11 core * reg 0x1e0, which is cleared by the core_reset. have to re-request it. * * This adds some delay and we can optimize it by also requesting * fastclk through chipcommon during this period if necessary. But * that has to work coordinate with other driver like mips/arm since * they may touch chipcommon as well.
*/
wlc_hw->clk = false;
bcma_core_enable(wlc_hw->d11core, flags);
wlc_hw->clk = true; if (wlc_hw->band && wlc_hw->band->pi)
wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true);
brcms_c_mctrl_reset(wlc_hw);
if (ai_get_cccaps(wlc_hw->sih) & CC_CAP_PMU)
brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST);
brcms_b_phy_reset(wlc_hw);
/* turn on PHY_PLL */
brcms_b_core_phypll_ctl(wlc_hw, true);
txfifo_startblk += wlc_hw->xmtfifo_sz[fifo_nu];
} /* * need to propagate to shm location to be in sync since ucode/hw won't * do this
*/
brcms_b_write_shm(wlc_hw, M_FIFOSIZE0,
wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]);
brcms_b_write_shm(wlc_hw, M_FIFOSIZE1,
wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]);
brcms_b_write_shm(wlc_hw, M_FIFOSIZE2,
((wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO] << 8) | wlc_hw->
xmtfifo_sz[TX_AC_BK_FIFO]));
brcms_b_write_shm(wlc_hw, M_FIFOSIZE3,
((wlc_hw->xmtfifo_sz[TX_ATIM_FIFO] << 8) | wlc_hw->
xmtfifo_sz[TX_BCMC_FIFO]));
}
/* This function is used for changing the tsf frac register * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz * HTPHY Formula is 2^26/freq(MHz) e.g. * For spuron2 - 126MHz -> 2^26/126 = 532610.0 * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082 * For spuron: 123MHz -> 2^26/123 = 545600.5 * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341 * For spur off: 120MHz -> 2^26/120 = 559240.5 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
*/
/* Initialize GPIOs that are controlled by D11 core */ staticvoid brcms_c_gpio_init(struct brcms_c_info *wlc)
{ struct brcms_hardware *wlc_hw = wlc->hw;
u32 gc, gm;
/* use GPIO select 0 to get all gpio signals from the gpio out reg */
brcms_b_mctrl(wlc_hw, MCTL_GPOUT_SEL_MASK, 0);
/* * Common GPIO setup: * G0 = LED 0 = WLAN Activity * G1 = LED 1 = WLAN 2.4 GHz Radio State * G2 = LED 2 = WLAN 5 GHz Radio State * G4 = radio disable input (HI enabled, LO disabled)
*/
gc = gm = 0;
/* Allocate GPIOs for mimo antenna diversity feature */ if (wlc_hw->antsel_type == ANTSEL_2x3) { /* Enable antenna diversity, use 2x3 mode */
brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
MHF3_ANTSEL_EN, BRCM_BAND_ALL);
brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE,
MHF3_ANTSEL_MODE, BRCM_BAND_ALL);
/* init superswitch control */
wlc_phy_antsel_init(wlc_hw->band->pi, false);
} elseif (wlc_hw->antsel_type == ANTSEL_2x4) {
gm |= gc |= (BOARD_GPIO_12 | BOARD_GPIO_13); /* * The board itself is powered by these GPIOs * (when not sending pattern) so set them high
*/
bcma_set16(wlc_hw->d11core, D11REGOFFS(psm_gpio_oe),
(BOARD_GPIO_12 | BOARD_GPIO_13));
bcma_set16(wlc_hw->d11core, D11REGOFFS(psm_gpio_out),
(BOARD_GPIO_12 | BOARD_GPIO_13));
macintmask = wlc->macintmask; /* isr can still happen */
bcma_write32(wlc_hw->d11core, D11REGOFFS(macintmask), 0);
(void)bcma_read32(wlc_hw->d11core, D11REGOFFS(macintmask));
udelay(1); /* ensure int line is no longer driven */
wlc->macintmask = 0;
/* return previous macintmask; resolve race between us and our isr */ return wlc->macintstatus ? 0 : macintmask;
}
/* assumes that the d11 MAC is enabled */ staticvoid brcms_b_tx_fifo_suspend(struct brcms_hardware *wlc_hw,
uint tx_fifo)
{
u8 fifo = 1 << tx_fifo;
/* Two clients of this code, 11h Quiet period and scanning. */
/* only suspend if not already suspended */ if ((wlc_hw->suspended_fifos & fifo) == fifo) return;
/* force the core awake only if not already */ if (wlc_hw->suspended_fifos == 0)
brcms_c_ucode_wake_override_set(wlc_hw,
BRCMS_WAKE_OVERRIDE_TXFIFO);
wlc_hw->suspended_fifos |= fifo;
if (wlc_hw->di[tx_fifo]) { /* * Suspending AMPDU transmissions in the middle can cause * underflow which may result in mismatch between ucode and * driver so suspend the mac before suspending the FIFO
*/ if (BRCMS_PHY_11N_CAP(wlc_hw->band))
brcms_c_suspend_mac_and_wait(wlc_hw->wlc);
dma_txsuspend(wlc_hw->di[tx_fifo]);
if (BRCMS_PHY_11N_CAP(wlc_hw->band))
brcms_c_enable_mac(wlc_hw->wlc);
}
}
staticvoid brcms_b_tx_fifo_resume(struct brcms_hardware *wlc_hw,
uint tx_fifo)
{ /* BMAC_NOTE: BRCMS_TX_FIFO_ENAB is done in brcms_c_dpc() for DMA case * but need to be done here for PIO otherwise the watchdog will catch * the inconsistency and fire
*/ /* Two clients of this code, 11h Quiet period and scanning. */ if (wlc_hw->di[tx_fifo])
dma_txresume(wlc_hw->di[tx_fifo]);
/* allow core to sleep again */ if (wlc_hw->suspended_fifos == 0) return; else {
wlc_hw->suspended_fifos &= ~(1 << tx_fifo); if (wlc_hw->suspended_fifos == 0)
brcms_c_ucode_wake_override_clear(wlc_hw,
BRCMS_WAKE_OVERRIDE_TXFIFO);
}
}
/* precondition: requires the mac core to be enabled */ staticvoid brcms_b_mute(struct brcms_hardware *wlc_hw, bool mute_tx)
{ staticconst u8 null_ether_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
u8 *ethaddr = wlc_hw->wlc->pub->cur_etheraddr;
/* zero the address match register so we do not send ACKs */
brcms_b_set_addrmatch(wlc_hw, RCM_MAC_OFFSET, null_ether_addr);
} else { /* resume tx fifos */
brcms_b_tx_fifo_resume(wlc_hw, TX_DATA_FIFO);
brcms_b_tx_fifo_resume(wlc_hw, TX_CTL_FIFO);
brcms_b_tx_fifo_resume(wlc_hw, TX_AC_BK_FIFO);
brcms_b_tx_fifo_resume(wlc_hw, TX_AC_VI_FIFO);
/* * Read and clear macintmask and macintstatus and intstatus registers. * This routine should be called with interrupts off * Return: * -1 if brcms_deviceremoved(wlc) evaluates to true; * 0 if the interrupt is not for us, or we are in some special cases; * device interrupt status bits otherwise.
*/ staticinline u32 wlc_intstatus(struct brcms_c_info *wlc, bool in_isr)
{ struct brcms_hardware *wlc_hw = wlc->hw; struct bcma_device *core = wlc_hw->d11core;
u32 macintstatus, mask;
/* macintstatus includes a DMA interrupt summary bit */
macintstatus = bcma_read32(core, D11REGOFFS(macintstatus));
mask = in_isr ? wlc->macintmask : wlc->defmacintmask;
/* MI_DMAINT is indication of non-zero intstatus */ if (macintstatus & MI_DMAINT) /* * only fifo interrupt enabled is I_RI in * RX_FIFO. If MI_DMAINT is set, assume it * is set and clear the interrupt.
*/
bcma_write32(core, D11REGOFFS(intctrlregs[RX_FIFO].intstatus),
DEF_RXINTMASK);
return macintstatus;
}
/* Update wlc->macintstatus and wlc->intstatus[]. */ /* Return true if they are updated successfully. false otherwise */ bool brcms_c_intrsupd(struct brcms_c_info *wlc)
{
u32 macintstatus;
/* read and clear macintstatus and intstatus registers */
macintstatus = wlc_intstatus(wlc, false);
/* device is removed */ if (macintstatus == 0xffffffff) returnfalse;
/* update interrupt status in software */
wlc->macintstatus |= macintstatus;
returntrue;
}
/* * First-level interrupt processing. * Return true if this was our interrupt * and if further brcms_c_dpc() processing is required, * false otherwise.
*/ bool brcms_c_isr(struct brcms_c_info *wlc)
{ struct brcms_hardware *wlc_hw = wlc->hw;
u32 macintstatus;
if (!wlc_hw->up || !wlc->macintmask) returnfalse;
/* read and clear macintstatus and intstatus registers */
macintstatus = wlc_intstatus(wlc, true);
if (macintstatus == 0xffffffff) {
brcms_err(wlc_hw->d11core, "DEVICEREMOVED detected in the ISR code path\n"); returnfalse;
}
/* it is not for us */ if (macintstatus == 0) returnfalse;
/* save interrupt status bits */
wlc->macintstatus = macintstatus;
/* Can we write and read back a 32bit register? */
bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0);
(void)bcma_read32(core, D11REGOFFS(objaddr));
bcma_write32(core, D11REGOFFS(objdata), (u32) 0xaa5555aa);
tmp = bcma_read32(core, D11REGOFFS(clk_ctl_st)); if ((tmp &
(CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL))
!=
(CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL))
brcms_err(core, "%s: turn on PHY PLL failed\n",
__func__);
}
} else { /* * Since the PLL may be shared, other cores can still * be requesting it; so we'll deassert the request but * not wait for status to comply.
*/
bcma_mask32(core, D11REGOFFS(clk_ctl_st),
~CCS_ERSRC_REQ_PHYPLL);
(void)bcma_read32(core, D11REGOFFS(clk_ctl_st));
}
}
/* free any posted tx packets */ for (i = 0; i < NFIFO; i++) { if (wlc_hw->di[i]) {
dma_txreclaim(wlc_hw->di[i], DMA_RANGE_ALL); if (i < TX_BCMC_FIFO)
ieee80211_wake_queue(wlc->pub->ieee_hw,
brcms_fifo_to_ac(i));
}
}
/* free any posted rx packets */
dma_rxreclaim(wlc_hw->di[RX_FIFO]);
}
bcma_write32(core, D11REGOFFS(objaddr), sel | (offset >> 2));
(void)bcma_read32(core, D11REGOFFS(objaddr)); if (offset & 2)
objoff += 2;
bcma_wflush16(core, objoff, v);
}
/* * Read a single u16 from shared memory. * SHM 'offset' needs to be an even address
*/
u16 brcms_b_read_shm(struct brcms_hardware *wlc_hw, uint offset)
{ return brcms_b_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL);
}
/* * Write a single u16 to shared memory. * SHM 'offset' needs to be an even address
*/ void brcms_b_write_shm(struct brcms_hardware *wlc_hw, uint offset, u16 v)
{
brcms_b_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL);
}
/* * Copy a buffer to shared memory of specified type . * SHM 'offset' needs to be an even address and * Buffer length 'len' must be an even number of bytes * 'sel' selects the type of memory
*/ void
brcms_b_copyto_objmem(struct brcms_hardware *wlc_hw, uint offset, constvoid *buf, int len, u32 sel)
{
u16 v; const u8 *p = (const u8 *)buf; int i;
for (i = 0; i < len; i += 2) {
v = p[i] | (p[i + 1] << 8);
brcms_b_write_objmem(wlc_hw, offset + i, v, sel);
}
}
/* * Copy a piece of shared memory of specified type to a buffer . * SHM 'offset' needs to be an even address and * Buffer length 'len' must be an even number of bytes * 'sel' selects the type of memory
*/ void
brcms_b_copyfrom_objmem(struct brcms_hardware *wlc_hw, uint offset, void *buf, int len, u32 sel)
{
u16 v;
u8 *p = (u8 *) buf; int i;
for (i = 0; i < len; i += 2) {
v = brcms_b_read_objmem(wlc_hw, offset + i, sel);
p[i] = v & 0xFF;
p[i + 1] = (v >> 8) & 0xFF;
}
}
/* Copy a buffer to shared memory. * SHM 'offset' needs to be an even address and * Buffer length 'len' must be an even number of bytes
*/ staticvoid brcms_c_copyto_shm(struct brcms_c_info *wlc, uint offset, constvoid *buf, int len)
{
brcms_b_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
}
/* * conditions under which the PM bit should be set in outgoing frames * and STAY_AWAKE is meaningful
*/ staticbool brcms_c_ps_allowed(struct brcms_c_info *wlc)
{ /* not supporting PS so always return false for now */ returnfalse;
}
brcms_ucode_download(wlc_hw); /* * FIFOSZ fixup. driver wants to controls the fifo allocation.
*/
fifosz_fixup = true;
/* let the PSM run to the suspended state, set mode to BSS STA */
bcma_write32(core, D11REGOFFS(macintstatus), -1);
brcms_b_mctrl(wlc_hw, ~0,
(MCTL_IHR_EN | MCTL_INFRA | MCTL_PSM_RUN | MCTL_WAKE));
/* wait for ucode to self-suspend after auto-init */
SPINWAIT(((bcma_read32(core, D11REGOFFS(macintstatus)) &
MI_MACSSPNDD) == 0), 1000 * 1000); if ((bcma_read32(core, D11REGOFFS(macintstatus)) & MI_MACSSPNDD) == 0)
brcms_err(core, "wl%d: wlc_coreinit: ucode did not self-" "suspend!\n", wlc_hw->unit);
/* set up the specified band and chanspec */
brcms_c_setxband(wlc_hw, chspec_bandunit(chanspec));
wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
/* do one-time phy inits and calibration */
wlc_phy_cal_init(wlc_hw->band->pi);
/* seed wake_override with BRCMS_WAKE_OVERRIDE_MACSUSPEND since the mac * is suspended and brcms_c_enable_mac() will clear this override bit.
*/
mboolset(wlc_hw->wake_override, BRCMS_WAKE_OVERRIDE_MACSUSPEND);
/* * initialize mac_suspend_depth to 1 to match ucode * initial suspended state
*/
wlc_hw->mac_suspend_depth = 1;
/* restore the clk */ if (!fastclk)
brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC);
}
staticvoid brcms_c_set_phy_chanspec(struct brcms_c_info *wlc,
u16 chanspec)
{ /* Save our copy of the chanspec */
wlc->chanspec = chanspec;
/* Set the chanspec and power limits for this locale */
brcms_c_channel_set_chanspec(wlc->cmi, chanspec, BRCMS_TXPWR_MAX);
if (wlc->stf->ss_algosel_auto)
brcms_c_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel,
chanspec);
/* incoming rates are in 500kbps units as in 802.11 Supported Rates */
memset(br, 0, BRCM_MAXRATE + 1);
/* For each basic rate in the rates list, make an entry in the * best basic lookup.
*/ for (i = 0; i < rateset->count; i++) { /* only make an entry for a basic rate */ if (!(rateset->rates[i] & BRCMS_RATE_FLAG)) continue;
/* mask off basic bit */
rate = (rateset->rates[i] & BRCMS_RATE_MASK);
if (rate > BRCM_MAXRATE) {
brcms_err(wlc->hw->d11core, "brcms_c_rate_lookup_init: " "invalid rate 0x%X in rate set\n",
rateset->rates[i]); continue;
}
br[rate] = rate;
}
/* The rate lookup table now has non-zero entries for each * basic rate, equal to the basic rate: br[basicN] = basicN * * To look up the best basic rate corresponding to any * particular rate, code can use the basic_rate table * like this * * basic_rate = wlc->band->basic_rate[tx_rate] * * Make sure there is a best basic rate entry for * every rate by walking up the table from low rates * to high, filling in holes in the lookup table
*/
for (i = 0; i < wlc->band->hw_rateset.count; i++) {
rate = wlc->band->hw_rateset.rates[i];
if (br[rate] != 0) { /* This rate is a basic rate. * Keep track of the best basic rate so far by * modulation type.
*/ if (is_ofdm_rate(rate))
ofdm_basic = rate; else
cck_basic = rate;
continue;
}
/* This rate is not a basic rate so figure out the * best basic rate less than this rate and fill in * the hole in the table
*/
/* * We might have been bandlocked during down and the chip * power-cycled (hibernate). Figure out the right band to park on
*/ if (wlc->bandlocked || wlc->pub->_nbands == 1) { /* updated in brcms_c_bandlock() */
parkband = wlc->band->bandunit;
band_order[0] = band_order[1] = parkband;
} else { /* park on the band of the specified chanspec */
parkband = chspec_bandunit(chanspec);
/* order so that parkband initialize last */
band_order[0] = parkband ^ 1;
band_order[1] = parkband;
}
/* make each band operational, software state init */ for (i = 0; i < wlc->pub->_nbands; i++) {
uint j = band_order[i];
wlc->band = wlc->bandstate[j];
brcms_default_rateset(wlc, &default_rateset);
/* fill in hw_rate */
brcms_c_rateset_filter(&default_rateset, &wlc->band->hw_rateset, false, BRCMS_RATES_CCK_OFDM, BRCMS_RATE_MASK,
(bool) (wlc->pub->_n_enab & SUPPORT_11N));
/* * ucode, hwmac update * Channel dependent updates for ucode and hw
*/ staticvoid brcms_c_ucode_mac_upd(struct brcms_c_info *wlc)
{ /* enable or disable any active IBSSs depending on whether or not * we are on the home channel
*/ if (wlc->home_chanspec == wlc_phy_chanspec_get(wlc->band->pi)) { if (wlc->pub->associated) { /* * BMAC_NOTE: This is something that should be fixed * in ucode inits. I think that the ucode inits set * up the bcn templates and shm values with a bogus * beacon. This should not be done in the inits. If * ucode needs to set up a beacon for testing, the * test routines should write it down, not expect the * inits to populate a bogus beacon.
*/ if (BRCMS_PHY_11N_CAP(wlc->band))
brcms_b_write_shm(wlc->hw,
M_BCN_TXTSF_OFFSET, 0);
}
} else { /* disable an active IBSS if we are not on the home channel */
}
}
/* Shared memory address for the table we are reading */
dir_table = is_ofdm_rate(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
/* Shared memory address for the table we are writing */
basic_table = is_ofdm_rate(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
/* * for a given rate, the LS-nibble of the PLCP SIGNAL field is * the index into the rate table.
*/
phy_rate = rate_info[rate] & BRCMS_RATE_MASK;
basic_phy_rate = rate_info[basic_rate] & BRCMS_RATE_MASK;
index = phy_rate & 0xf;
basic_index = basic_phy_rate & 0xf;
/* Find the SHM pointer to the ACK rate entry by looking in the * Direct-map Table
*/
basic_ptr = brcms_b_read_shm(wlc->hw, (dir_table + basic_index * 2));
/* Update the SHM BSS-basic-rate-set mapping table with the pointer * to the correct basic rate for the given incoming rate
*/
brcms_b_write_shm(wlc->hw, (basic_table + index * 2), basic_ptr);
}
/* walk the phy rate table and update SHM basic rate lookup table */ for (i = 0; i < rs.count; i++) {
rate = rs.rates[i] & BRCMS_RATE_MASK;
/* for a given rate brcms_basic_rate returns the rate at * which a response ACK/CTS should be sent.
*/
basic_rate = brcms_basic_rate(wlc, rate); if (basic_rate == 0) /* This should only happen if we are using a * restricted rateset.
*/
basic_rate = rs.rates[0] & BRCMS_RATE_MASK;
if (!awake_before)
brcms_b_wait_for_wake(wlc->hw);
}
/* * Write this BSS config's MAC address to core. * Updates RXE match engine.
*/ staticvoid brcms_c_set_mac(struct brcms_bss_cfg *bsscfg)
{ struct brcms_c_info *wlc = bsscfg->wlc;
/* enter the MAC addr into the RXE match registers */
brcms_c_set_addrmatch(wlc, RCM_MAC_OFFSET, wlc->pub->cur_etheraddr);
brcms_c_ampdu_macaddr_upd(wlc);
}
/* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl). * Updates RXE match engine.
*/ staticvoid brcms_c_set_bssid(struct brcms_bss_cfg *bsscfg)
{ /* we need to update BSSID in RXE match registers */
brcms_c_set_addrmatch(bsscfg->wlc, RCM_BSSID_OFFSET, bsscfg->BSSID);
}
/* * Suspend the MAC and update the slot timing * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
*/ staticvoid brcms_c_switch_shortslot(struct brcms_c_info *wlc, bool shortslot)
{ /* use the override if it is set */ if (wlc->shortslot_override != BRCMS_SHORTSLOT_AUTO)
shortslot = (wlc->shortslot_override == BRCMS_SHORTSLOT_ON);
if (!brcms_c_valid_chanspec_db(wlc->cmi, chanspec)) {
brcms_err(wlc->hw->d11core, "wl%d: %s: Bad channel %d\n",
wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec)); return;
}
/* Switch bands if necessary */ if (wlc->pub->_nbands > 1) {
bandunit = chspec_bandunit(chanspec); if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) { if (wlc->bandlocked) {
brcms_err(wlc->hw->d11core, "wl%d: %s: chspec %d band is locked!\n",
wlc->pub->unit, __func__,
CHSPEC_CHANNEL(chanspec)); return;
} /* * should the setband call come after the * brcms_b_chanspec() ? if the setband updates * (brcms_c_bsinit) use low level calls to inspect and * set state, the state inspected may be from the wrong * band, or the following brcms_b_set_chanspec() may * undo the work.
*/
brcms_c_setband(wlc, bandunit);
}
}
/* sync up phy/radio chanspec */
brcms_c_set_phy_chanspec(wlc, chanspec);
/* Fix the hardware rateset based on bw. * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
*/
brcms_c_rateset_bw_mcs_filter(&wlc->band->hw_rateset,
wlc->band->mimo_cap_40 ? brcms_chspec_bw(chanspec) : 0);
}
/* update some mac configuration since chanspec changed */
brcms_c_ucode_mac_upd(wlc);
}
/* * This function changes the phytxctl for beacon based on current * beacon ratespec AND txant setting as per this table: * ratespec CCK ant = wlc->stf->txant * OFDM ant = 3
*/ void brcms_c_beacon_phytxctl_txant_upd(struct brcms_c_info *wlc,
u32 bcn_rspec)
{
u16 phyctl;
u16 phytxant = wlc->stf->phytxant;
u16 mask = PHY_TXC_ANT_MASK;
/* for non-siso rates or default setting, use the available chains */ if (BRCMS_PHY_11N_CAP(wlc->band))
phytxant = brcms_c_stf_phytxchain_sel(wlc, bcn_rspec);
/* * centralized protection config change function to simplify debugging, no * consistency checking this should be called only on changes to avoid overhead * in periodic function
*/ void brcms_c_protection_upd(struct brcms_c_info *wlc, uint idx, int val)
{ /* * Cannot use brcms_dbg_* here because this function is called * before wlc is sufficiently initialized.
*/
BCMMSG(wlc->wiphy, "idx %d, val %d\n", idx, val);
switch (idx) { case BRCMS_PROT_G_SPEC:
wlc->protection->_g = (bool) val; break; case BRCMS_PROT_G_OVR:
wlc->protection->g_override = (s8) val; break; case BRCMS_PROT_G_USER:
wlc->protection->gmode_user = (u8) val; break; case BRCMS_PROT_OVERLAP:
wlc->protection->overlap = (s8) val; break; case BRCMS_PROT_N_USER:
wlc->protection->nmode_user = (s8) val; break; case BRCMS_PROT_N_CFG:
wlc->protection->n_cfg = (s8) val; break; case BRCMS_PROT_N_CFG_OVR:
wlc->protection->n_cfg_override = (s8) val; break; case BRCMS_PROT_N_NONGF:
wlc->protection->nongf = (bool) val; break; case BRCMS_PROT_N_NONGF_OVR:
wlc->protection->nongf_override = (s8) val; break; case BRCMS_PROT_N_PAM_OVR:
wlc->protection->n_pam_override = (s8) val; break; case BRCMS_PROT_N_OBSS:
wlc->protection->n_obss = (bool) val; break;
default: break;
}
}
staticvoid brcms_c_ht_update_sgi_rx(struct brcms_c_info *wlc, int val)
{ if (wlc->pub->up) {
brcms_c_update_beacon(wlc);
brcms_c_update_probe_resp(wlc, true);
}
}
/* Only apply params if the core is out of reset and has clocks */ if (!wlc->clk) {
brcms_err(wlc->hw->d11core, "wl%d: %s : no-clock\n",
wlc->pub->unit, __func__); return;
}
memset(&acp_shm, 0, sizeof(struct shm_acparams)); /* fill in shm ac params struct */
acp_shm.txop = params->txop; /* convert from units of 32us to us for ucode */
wlc->edcf_txop[aci & 0x3] = acp_shm.txop =
EDCF_TXOP2USEC(acp_shm.txop);
acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK);
/* Fill in shm acparam table */
shm_entry = (u16 *) &acp_shm; for (i = 0; i < (int)sizeof(struct shm_acparams); i += 2)
brcms_b_write_shm(wlc->hw,
M_EDCF_QINFO +
wme_ac2fifo[aci] * M_EDCF_QLEN + i,
*shm_entry++);
}
for (i_ac = 0; i_ac < IEEE80211_NUM_ACS; i_ac++, edcf_acp++) { /* find out which ac this set of params applies to */
aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
/* fill in shm ac params struct */
txq_pars.txop = edcf_acp->TXOP;
txq_pars.aifs = edcf_acp->ACI;
if (suspend) {
brcms_c_suspend_mac_and_wait(wlc);
brcms_c_enable_mac(wlc);
}
}
staticvoid brcms_c_radio_monitor_start(struct brcms_c_info *wlc)
{ /* Don't start the timer if HWRADIO feature is disabled */ if (wlc->radio_monitor) return;
staticbool brcms_c_timers_init(struct brcms_c_info *wlc, int unit)
{
wlc->wdtimer = brcms_init_timer(wlc->wl, brcms_c_watchdog_by_timer,
wlc, "watchdog"); if (!wlc->wdtimer) {
wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for wdtimer " "failed\n", unit); goto fail;
}
wlc->radio_timer = brcms_init_timer(wlc->wl, brcms_c_radio_timer,
wlc, "radio"); if (!wlc->radio_timer) {
wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for radio_timer " "failed\n", unit); goto fail;
}
returntrue;
fail: returnfalse;
}
/* * Initialize brcms_c_info default values ... * may get overrides later in this function
*/ staticvoid brcms_c_info_init(struct brcms_c_info *wlc, int unit)
{ int i;
/* Save our copy of the chanspec */
wlc->chanspec = ch20mhz_chspec(1);
/* populate struct brcms_hardware with default values */
brcms_b_info_init(wlc_hw);
/* * Do the hardware portion of the attach. Also initialize software * state that depends on the particular hardware we are running.
*/
wlc_hw->sih = ai_attach(core->bus); if (wlc_hw->sih == NULL) {
wiphy_err(wiphy, "wl%d: brcms_b_attach: si_attach failed\n",
unit);
err = 11; goto fail;
}
/* verify again the device is supported */ if (!brcms_c_chipmatch(core)) {
wiphy_err(wiphy, "wl%d: brcms_b_attach: Unsupported device\n",
unit);
err = 12; goto fail;
}
/* validate chip, chiprev and corerev */ if (!brcms_c_isgoodchip(wlc_hw)) {
err = 13; goto fail;
}
/* initialize power control registers */
ai_clkctl_init(wlc_hw->sih);
/* request fastclock and force fastclock for the rest of attach * bring the d11 core out of reset. * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk * is still false; But it will be called again inside wlc_corereset, * after d11 is out of reset.
*/
brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST);
brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS);
/* alloc and save pointer to shared phy state area */
wlc_hw->phy_sh = wlc_phy_shared_attach(&sha_params); if (!wlc_hw->phy_sh) {
err = 16; goto fail;
}
/* initialize software state for each core and band */ for (j = 0; j < wlc_hw->_nbands; j++) { /* * band0 is always 2.4Ghz * band1, if present, is 5Ghz
*/
good_phy: /* * BMAC_NOTE: wlc->band->pi should not be set below and should * be done in the high level attach. However we can not make * that change until all low level access is changed to * wlc_hw->band->pi. Instead do the wlc->band->pi init below, * keeping wlc_hw->band->pi as well for incremental update of * low level fns, and cut over low only init when all fns * updated.
*/
wlc->band->pi = wlc_hw->band->pi;
wlc->band->phytype = wlc_hw->band->phytype;
wlc->band->phyrev = wlc_hw->band->phyrev;
wlc->band->radioid = wlc_hw->band->radioid;
wlc->band->radiorev = wlc_hw->band->radiorev;
brcms_dbg_info(core, "wl%d: phy %u/%u radio %x/%u\n", unit,
wlc->band->phytype, wlc->band->phyrev,
wlc->band->radioid, wlc->band->radiorev); /* default contention windows size limits */
wlc_hw->band->CWmin = APHY_CWMIN;
wlc_hw->band->CWmax = PHY_CWMAX;
/* disable core to match driver "down" state */
brcms_c_coredisable(wlc_hw);
/* Match driver "down" state */
bcma_host_pci_down(wlc_hw->d11core->bus);
/* turn off pll and xtal to match driver "down" state */
brcms_b_xtal(wlc_hw, OFF);
/* ******************************************************************* * The hardware is in the DOWN state at this point. D11 core * or cores are in reset with clocks off, and the board PLLs * are off if possible. * * Beyond this point, wlc->sbclk == false and chip registers * should not be touched. *********************************************************************
*/
/* init etheraddr state variables */
brcms_c_get_macaddr(wlc_hw, wlc_hw->etheraddr);
if (is_broadcast_ether_addr(wlc_hw->etheraddr) ||
is_zero_ether_addr(wlc_hw->etheraddr)) {
wiphy_err(wiphy, "wl%d: brcms_b_attach: bad macaddr\n",
unit);
err = 22; goto fail;
}
/* init default and target BSS with some sane initial values */
memset(bi, 0, sizeof(*bi));
bi->beacon_period = BEACON_INTERVAL_DEFAULT;
/* fill the default channel as the first valid channel * starting from the 2G channels
*/
chanspec = ch20mhz_chspec(1);
wlc->home_chanspec = bi->chanspec = chanspec;
/* find the band of our default channel */
band = wlc->band; if (wlc->pub->_nbands > 1 &&
band->bandunit != chspec_bandunit(chanspec))
band = wlc->bandstate[OTHERBANDUNIT(wlc)];
/* init bss rates to the band specific default rate set */
brcms_c_rateset_default(&bi->rateset, NULL, band->phytype,
band->bandtype, false, BRCMS_RATE_MASK_FULL,
(bool) (wlc->pub->_n_enab & SUPPORT_11N),
brcms_chspec_bw(chanspec), wlc->stf->txstreams);
if (wlc->pub->_n_enab & SUPPORT_11N)
bi->flags |= BRCMS_BSS_HT;
}
band = wlc_hw->band; for (i = 0; i < wlc_hw->_nbands; i++) { if (band->pi) { /* Detach this band's phy */
wlc_phy_detach(band->pi);
band->pi = NULL;
}
band = wlc_hw->bandstate[OTHERBANDUNIT(wlc)];
}
/* Free shared phy state */
kfree(wlc_hw->phy_sh);
wlc_phy_shim_detach(wlc_hw->physhim);
if (wlc_hw->sih) {
ai_detach(wlc_hw->sih);
wlc_hw->sih = NULL;
}
}
/* * Return a count of the number of driver callbacks still pending. * * General policy is that brcms_c_detach can only dealloc/free software states. * It can NOT touch hardware registers since the d11core may be in reset and * clock may not be available. * One exception is sb register access, which is possible if crystal is turned * on after "down" state, driver should avoid software timer with the exception * of radio_monitor.
*/
uint brcms_c_detach(struct brcms_c_info *wlc)
{
uint callbacks;
/* update state that depends on the current value of "ap" */ staticvoid brcms_c_ap_upd(struct brcms_c_info *wlc)
{ /* STA-BSS; short capable */
wlc->PLCPHdr_override = BRCMS_PLCP_SHORT;
}
/* Initialize just the hardware when coming out of POR or S3/S5 system states */ staticvoid brcms_b_hw_up(struct brcms_hardware *wlc_hw)
{ if (wlc_hw->wlc->pub->hw_up) return;
/* * Enable pll and xtal, initialize the power control registers, * and force fastclock for the remainder of brcms_c_up().
*/
brcms_b_xtal(wlc_hw, ON);
ai_clkctl_init(wlc_hw->sih);
brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST);
/* * TODO: test suspend/resume * * AI chip doesn't restore bar0win2 on * hibernation/resume, need sw fixup
*/
/* * Inform phy that a POR reset has occurred so * it does a complete phy init
*/
wlc_phy_por_inform(wlc_hw->band->pi);
/* * Enable pll and xtal, initialize the power control registers, * and force fastclock for the remainder of brcms_c_up().
*/
brcms_b_xtal(wlc_hw, ON);
ai_clkctl_init(wlc_hw->sih);
brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST);
/* * Configure pci/pcmcia here instead of in brcms_c_attach() * to allow mfg hotswap: down, hotswap (chip power cycle), up.
*/
bcma_host_pci_irq_ctl(wlc_hw->d11core->bus, wlc_hw->d11core, true);
/* * Need to read the hwradio status here to cover the case where the * system is loaded with the hw radio disabled. We do not want to * bring the driver up in this case.
*/ if (brcms_b_radio_read_hwdisabled(wlc_hw)) { /* put SB PCI in down state again */
bcma_host_pci_down(wlc_hw->d11core->bus);
brcms_b_xtal(wlc_hw, OFF); return -ENOMEDIUM;
}
bcma_host_pci_up(wlc_hw->d11core->bus);
/* reset the d11 core */
brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS);
/* * Need to read the hwradio status here to cover the case where the * system is loaded with the hw radio disabled. We do not want to bring * the driver up in this case. If radio is disabled, abort up, lower * power, start radio timer and return 0(for NDIS) don't call * radio_update to avoid looping brcms_c_up. * * brcms_b_up_prep() returns either 0 or -BCME_RADIOOFF only
*/ if (!wlc->pub->radio_disabled) { int status = brcms_b_up_prep(wlc->hw); if (status == -ENOMEDIUM) { if (!mboolisset
(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) { struct brcms_bss_cfg *bsscfg = wlc->bsscfg;
mboolset(wlc->pub->radio_disabled,
WL_RADIO_HW_DISABLE); if (bsscfg->type == BRCMS_TYPE_STATION ||
bsscfg->type == BRCMS_TYPE_ADHOC)
brcms_err(wlc->hw->d11core, "wl%d: up: rfdisable -> " "bsscfg_disable()\n",
wlc->pub->unit);
}
}
}
if (wlc->pub->radio_disabled) {
brcms_c_radio_monitor_start(wlc); return 0;
}
/* brcms_b_up_prep has done brcms_c_corereset(). so clk is on, set it */
wlc->clk = true;
brcms_c_radio_monitor_stop(wlc);
/* Set EDCF hostflags */
brcms_b_mhf(wlc->hw, MHF1, MHF1_EDCF, MHF1_EDCF, BRCM_BAND_ALL);
/* Program the TX wme params with the current settings */
brcms_c_wme_retries_write(wlc);
/* start one second watchdog timer */
brcms_add_timer(wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true);
wlc->WDarmed = true;
/* ensure antenna config is up to date */
brcms_c_stf_phy_txant_upd(wlc); /* ensure LDPC config is in sync */
brcms_c_ht_update_ldpc(wlc, wlc->stf->ldpc);
/* disable interrupts */ if (dev_gone)
wlc_hw->wlc->macintmask = 0; else { /* now disable interrupts */
brcms_intrsoff(wlc_hw->wlc->wl);
/* ensure we're running on the pll clock again */
brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST);
} /* down phy at the last of this stage */
callbacks += wlc_phy_down(wlc_hw->band->pi);
/* reclaim any posted packets */
brcms_c_flushqueues(wlc_hw->wlc);
} else {
/* Reset and disable the core */ if (bcma_core_is_enabled(wlc_hw->d11core)) { if (bcma_read32(wlc_hw->d11core,
D11REGOFFS(maccontrol)) & MCTL_EN_MAC)
brcms_c_suspend_mac_and_wait(wlc_hw->wlc);
callbacks += brcms_reset(wlc_hw->wlc->wl);
brcms_c_coredisable(wlc_hw);
}
/* turn off primary xtal and pll */ if (!wlc_hw->noreset) {
bcma_host_pci_down(wlc_hw->d11core->bus);
brcms_b_xtal(wlc_hw, OFF);
}
}
return callbacks;
}
/* * Mark the interface nonoperational, stop the software mechanisms, * disable the hardware, free any transient buffer state. * Return a count of the number of driver callbacks still pending.
*/
uint brcms_c_down(struct brcms_c_info *wlc)
{
/* check if we are already in the going down path */ if (wlc->going_down) {
brcms_err(wlc->hw->d11core, "wl%d: %s: Driver going down so return\n",
wlc->pub->unit, __func__); return 0;
} if (!wlc->pub->up) return callbacks;
wlc->going_down = true;
callbacks += brcms_b_bmac_down_prep(wlc->hw);
brcms_deviceremoved(wlc);
/* Call any registered down handlers */ for (i = 0; i < BRCMS_MAXMODULES; i++) { if (wlc->modulecb[i].down_fn)
callbacks +=
wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
}
/* cancel the watchdog timer */ if (wlc->WDarmed) { if (!brcms_del_timer(wlc->wdtimer))
callbacks++;
wlc->WDarmed = false;
}
/* brcms_b_down_finish has done brcms_c_coredisable(). so clk is off */
wlc->clk = false;
wlc->going_down = false; return callbacks;
}
/* Set the current gmode configuration */ int brcms_c_set_gmode(struct brcms_c_info *wlc, u8 gmode, bool config)
{ int ret = 0;
uint i; struct brcms_c_rateset rs; /* Default to 54g Auto */ /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
s8 shortslot = BRCMS_SHORTSLOT_AUTO; bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */ struct brcms_band *band;
/* if N-support is enabled, allow Gmode set as long as requested * Gmode is not GMODE_LEGACY_B
*/ if ((wlc->pub->_n_enab & SUPPORT_11N) && gmode == GMODE_LEGACY_B) return -ENOTSUPP;
/* verify that we are dealing with 2G band and grab the band pointer */ if (wlc->band->bandtype == BRCM_BAND_2G)
band = wlc->band; elseif ((wlc->pub->_nbands > 1) &&
(wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == BRCM_BAND_2G))
band = wlc->bandstate[OTHERBANDUNIT(wlc)]; else return -EINVAL;
/* update configuration value */ if (config)
brcms_c_protection_upd(wlc, BRCMS_PROT_G_USER, gmode);
/* force GMODE_AUTO if NMODE is ON */
brcms_c_set_gmode(wlc, GMODE_AUTO, true); if (nmode == WL_11N_3x3)
wlc->pub->_n_enab = SUPPORT_HT; else
wlc->pub->_n_enab = SUPPORT_11N;
wlc->default_bss->flags |= BRCMS_BSS_HT; /* add the mcs rates to the default and hw ratesets */
brcms_c_rateset_mcs_build(&wlc->default_bss->rateset,
wlc->stf->txstreams); for (i = 0; i < wlc->pub->_nbands; i++)
memcpy(wlc->bandstate[i]->hw_rateset.mcs,
wlc->default_bss->rateset.mcs, MCSSET_LEN);
/* * shortslot is an 11g feature, so no more work if we are * currently on the 5G band
*/ if (wlc->band->bandtype == BRCM_BAND_5G) return;
if (wlc->pub->up && wlc->pub->associated) { /* let watchdog or beacon processing update shortslot */
} elseif (wlc->pub->up) { /* unassociated shortslot is off */
brcms_c_switch_shortslot(wlc, false);
} else { /* driver is down, so just update the brcms_c_info
* value */ if (wlc->shortslot_override == BRCMS_SHORTSLOT_AUTO)
wlc->shortslot = false; else
wlc->shortslot =
(wlc->shortslot_override ==
BRCMS_SHORTSLOT_ON);
}
}
/* * register watchdog and down handlers.
*/ int brcms_c_module_register(struct brcms_pub *pub, constchar *name, struct brcms_info *hdl, int (*d_fn)(void *handle))
{ struct brcms_c_info *wlc = (struct brcms_c_info *) pub->wlc; int i;
/* find an empty entry and just add, no duplication check! */ for (i = 0; i < BRCMS_MAXMODULES; i++) { if (wlc->modulecb[i].name[0] == '\0') {
strscpy(wlc->modulecb[i].name, name, sizeof(wlc->modulecb[i].name));
wlc->modulecb[i].hdl = hdl;
wlc->modulecb[i].down_fn = d_fn; return 0;
}
}
/* get the phy specific rate encoding for the PLCP SIGNAL field */ if (is_ofdm_rate(rate))
table_ptr = M_RT_DIRMAP_A; else
table_ptr = M_RT_DIRMAP_B;
/* for a given rate, the LS-nibble of the PLCP SIGNAL field is * the index into the rate table.
*/
phy_rate = rate_info[rate] & BRCMS_RATE_MASK;
index = phy_rate & 0xf;
/* Find the SHM pointer to the rate table entry by looking in the * Direct-map Table
*/ return 2 * brcms_b_read_shm(wlc_hw, table_ptr + (index * 2));
}
/* * bcmc_fid_generate: * Generate frame ID for a BCMC packet. The frag field is not used * for MC frames so is used as part of the sequence number.
*/ staticinline u16
bcmc_fid_generate(struct brcms_c_info *wlc, struct brcms_bss_cfg *bsscfg, struct d11txh *txh)
{
u16 frameid;
/* * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that * is less than or equal to the rate of the immediately previous * frame in the FES
*/
rspec = brcms_basic_rate(wlc, rspec); /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
dur =
brcms_c_calc_frame_time(wlc, rspec, preamble_type,
(DOT11_ACK_LEN + FCS_LEN)); return dur;
}
static uint
brcms_c_calc_ba_time(struct brcms_c_info *wlc, u32 rspec,
u8 preamble_type)
{ /* * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that * is less than or equal to the rate of the immediately previous * frame in the FES
*/
rspec = brcms_basic_rate(wlc, rspec); /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */ return brcms_c_calc_frame_time(wlc, rspec, preamble_type,
(DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
FCS_LEN));
}
/* brcms_c_compute_frame_dur() * * Calculate the 802.11 MAC header DUR field for MPDU * DUR for a single frame = 1 SIFS + 1 ACK * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time * * rate MPDU rate in unit of 500kbps * next_frag_len next MPDU length in bytes * preamble_type use short/GF or long/MM PLCP header
*/ static u16
brcms_c_compute_frame_dur(struct brcms_c_info *wlc, u32 rate,
u8 preamble_type, uint next_frag_len)
{
u16 dur, sifs;
if (next_frag_len) { /* Double the current DUR to get 2 SIFS + 2 ACKs */
dur *= 2; /* add another SIFS and the frag time */
dur += sifs;
dur +=
(u16) brcms_c_calc_frame_time(wlc, rate, preamble_type,
next_frag_len);
} return dur;
}
/* * Return true if the specified rate is supported by the specified band. * BRCM_BAND_AUTO indicates the current band.
*/ staticbool brcms_c_valid_rate(struct brcms_c_info *wlc, u32 rspec, int band, bool verbose)
{ struct brcms_c_rateset *hw_rateset;
uint i;
if ((band == BRCM_BAND_AUTO) || (band == wlc->band->bandtype))
hw_rateset = &wlc->band->hw_rateset; elseif (wlc->pub->_nbands > 1)
hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset; else /* other band specified and we are a single band device */ returnfalse;
/* check if this is a mimo rate */ if (is_mcs_rate(rspec)) { if ((rspec & RSPEC_RATE_MASK) >= MCS_TABLE_SIZE) goto error;
for (i = 0; i < hw_rateset->count; i++) if (hw_rateset->rates[i] == rspec2rate(rspec)) returntrue;
error: if (verbose)
brcms_err(wlc->hw->d11core, "wl%d: valid_rate: rate spec 0x%x " "not in hw_rateset\n", wlc->pub->unit, rspec);
/* validate the combination of rate/mcs/stf is allowed */ if ((wlc->pub->_n_enab & SUPPORT_11N) && ismcs) { /* mcs only allowed when nmode */ if (stf > PHY_TXC1_MODE_SDM) {
brcms_err(core, "wl%d: %s: Invalid stf\n",
wlc->pub->unit, __func__); goto done;
}
/* mcs 32 is a special case, DUP mode 40 only */ if (rate == 32) { if (!CHSPEC_IS40(wlc->home_chanspec) ||
((stf != PHY_TXC1_MODE_SISO)
&& (stf != PHY_TXC1_MODE_CDD))) {
brcms_err(core, "wl%d: %s: Invalid mcs 32\n",
wlc->pub->unit, __func__); goto done;
} /* mcs > 7 must use stf SDM */
} elseif (rate > HIGHEST_SINGLE_STREAM_MCS) { /* mcs > 7 must use stf SDM */ if (stf != PHY_TXC1_MODE_SDM) {
brcms_dbg_mac80211(core, "wl%d: enabling " "SDM mode for mcs %d\n",
wlc->pub->unit, rate);
stf = PHY_TXC1_MODE_SDM;
}
} else { /* * MCS 0-7 may use SISO, CDD, and for * phy_rev >= 3 STBC
*/ if ((stf > PHY_TXC1_MODE_STBC) ||
(!BRCMS_STBC_CAP_PHY(wlc)
&& (stf == PHY_TXC1_MODE_STBC))) {
brcms_err(core, "wl%d: %s: Invalid STBC\n",
wlc->pub->unit, __func__); goto done;
}
}
} elseif (is_ofdm_rate(rate)) { if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
brcms_err(core, "wl%d: %s: Invalid OFDM\n",
wlc->pub->unit, __func__); goto done;
}
} elseif (is_cck_rate(rate)) { if ((cur_band->bandtype != BRCM_BAND_2G)
|| (stf != PHY_TXC1_MODE_SISO)) {
brcms_err(core, "wl%d: %s: Invalid CCK\n",
wlc->pub->unit, __func__); goto done;
}
} else {
brcms_err(core, "wl%d: %s: Unknown rate type\n",
wlc->pub->unit, __func__); goto done;
} /* make sure multiple antennae are available for non-siso rates */ if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
brcms_err(core, "wl%d: %s: SISO antenna but !SISO " "request\n", wlc->pub->unit, __func__); goto done;
}
rspec = rate; if (ismcs) {
rspec |= RSPEC_MIMORATE; /* For STBC populate the STC field of the ratespec */ if (stf == PHY_TXC1_MODE_STBC) {
u8 stc;
stc = 1; /* Nss for single stream is always 1 */
rspec |= (stc << RSPEC_STC_SHIFT);
}
}
rspec |= (stf << RSPEC_STF_SHIFT);
if (override_mcs_only)
rspec |= RSPEC_OVERRIDE_MCS_ONLY;
/* * Compute PLCP, but only requires actual rate and length of pkt. * Rate is given in the driver standard multiple of 500 kbps. * le is set for 11 Mbps rate if necessary. * Broken out for PRQ.
*/
staticvoid brcms_c_cck_plcp_set(struct brcms_c_info *wlc, int rate_500,
uint length, u8 *plcp)
{
u16 usec = 0;
u8 le = 0;
switch (rate_500) { case BRCM_RATE_1M:
usec = length << 3; break; case BRCM_RATE_2M:
usec = length << 2; break; case BRCM_RATE_5M5:
usec = (length << 4) / 11; if ((length << 4) - (usec * 11) > 0)
usec++; break; case BRCM_RATE_11M:
usec = (length << 3) / 11; if ((length << 3) - (usec * 11) > 0) {
usec++; if ((usec * 11) - (length << 3) >= 8)
le = D11B_PLCP_SIGNAL_LE;
} break;
/* brcms_c_compute_rtscts_dur() * * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK * * cts cts-to-self or rts/cts * rts_rate rts or cts rate in unit of 500kbps * rate next MPDU rate in unit of 500kbps * frame_len next MPDU frame length in bytes
*/
u16
brcms_c_compute_rtscts_dur(struct brcms_c_info *wlc, bool cts_only,
u32 rts_rate,
u32 frame_rate, u8 rts_preamble_type,
u8 frame_preamble_type, uint frame_len, bool ba)
{
u16 dur, sifs;
/* setup frameid */ if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { /* non-AP STA should never use BCMC queue */ if (queue == TX_BCMC_FIFO) {
brcms_err(wlc->hw->d11core, "wl%d: %s: ASSERT queue == TX_BCMC!\n",
wlc->pub->unit, __func__);
frameid = bcmc_fid_generate(wlc, NULL, txh);
} else { /* Increment the counter for first fragment */ if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
scb->seqnum[p->priority]++;
/* extract fragment number from frame first */
seq = le16_to_cpu(h->seq_ctrl) & FRAGNUM_MASK;
seq |= (scb->seqnum[p->priority] << SEQNUM_SHIFT);
h->seq_ctrl = cpu_to_le16(seq);
/* * Currently only support same setting for primary and * fallback rates. Unify flags for each rate into a * single value for the frame
*/
use_rts |=
txrate[k]->
flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false;
use_cts |=
txrate[k]->
flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false;
/* * (1) RATE: * determine and validate primary rate * and fallback rates
*/ if (!rspec_active(rspec[k])) {
rspec[k] = BRCM_RATE_1M;
} else { if (!is_multicast_ether_addr(h->addr1)) { /* set tx antenna config */
brcms_c_antsel_antcfg_get(wlc->asi, false, false, 0, 0, &antcfg, &fbantcfg);
}
}
}
phyctl1_stf = wlc->stf->ss_opmode;
if (wlc->pub->_n_enab & SUPPORT_11N) { for (k = 0; k < hw->max_rates; k++) { /* * apply siso/cdd to single stream mcs's or ofdm * if rspec is auto selected
*/ if (((is_mcs_rate(rspec[k]) &&
is_single_stream(rspec[k] & RSPEC_RATE_MASK)) ||
is_ofdm_rate(rspec[k]))
&& ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
|| !(rspec[k] & RSPEC_OVERRIDE))) {
rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
/* For SISO MCS use STBC if possible */ if (is_mcs_rate(rspec[k])
&& BRCMS_STF_SS_STBC_TX(wlc, scb)) {
u8 stc;
/* Nss for single stream is always 1 */
stc = 1;
rspec[k] |= (PHY_TXC1_MODE_STBC <<
RSPEC_STF_SHIFT) |
(stc << RSPEC_STC_SHIFT);
} else
rspec[k] |=
(phyctl1_stf << RSPEC_STF_SHIFT);
}
/* * Is the phy configured to use 40MHZ frames? If * so then pick the desired txbw
*/ if (brcms_chspec_bw(wlc->chanspec) == BRCMS_40_MHZ) { /* default txbw is 20in40 SB */
mimo_ctlchbw = mimo_txbw =
CHSPEC_SB_UPPER(wlc_phy_chanspec_get(
wlc->band->pi))
? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
if (is_mcs_rate(rspec[k])) { /* mcs 32 must be 40b/w DUP */ if ((rspec[k] & RSPEC_RATE_MASK)
== 32) {
mimo_txbw =
PHY_TXC1_BW_40MHZ_DUP; /* use override */
} elseif (wlc->mimo_40txbw != AUTO)
mimo_txbw = wlc->mimo_40txbw; /* else check if dst is using 40 Mhz */ elseif (scb->flags & SCB_IS40)
mimo_txbw = PHY_TXC1_BW_40MHZ;
} elseif (is_ofdm_rate(rspec[k])) { if (wlc->ofdm_40txbw != AUTO)
mimo_txbw = wlc->ofdm_40txbw;
} elseif (wlc->cck_40txbw != AUTO) {
mimo_txbw = wlc->cck_40txbw;
}
} else { /* * mcs32 is 40 b/w only. * This is possible for probe packets on * a STA during SCAN
*/ if ((rspec[k] & RSPEC_RATE_MASK) == 32) /* mcs 0 */
rspec[k] = RSPEC_MIMORATE;
if (is_mcs_rate(rspec[k])) {
preamble_type[k] = mimo_preamble_type;
/* * if SGI is selected, then forced mm * for single stream
*/ if ((rspec[k] & RSPEC_SHORT_GI)
&& is_single_stream(rspec[k] &
RSPEC_RATE_MASK))
preamble_type[k] = BRCMS_MM_PREAMBLE;
}
/* should be better conditionalized */ if (!is_mcs_rate(rspec[0])
&& (tx_info->control.rates[0].
flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
preamble_type[k] = BRCMS_SHORT_PREAMBLE;
}
} else { for (k = 0; k < hw->max_rates; k++) { /* Set ctrlchbw as 20Mhz */
rspec[k] &= ~RSPEC_BW_MASK;
rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
/* for nphy, stf of ofdm frames must follow policies */ if (BRCMS_ISNPHY(wlc->band) && is_ofdm_rate(rspec[k])) {
rspec[k] &= ~RSPEC_STF_MASK;
rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
}
}
}
/* Reset these for use with AMPDU's */
txrate[0]->count = 0;
txrate[1]->count = 0;
/* (2) PROTECTION, may change rspec */ if ((ieee80211_is_data(h->frame_control) ||
ieee80211_is_mgmt(h->frame_control)) &&
(phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1))
use_rts = true;
/* (3) PLCP: determine PLCP header and MAC duration,
* fill struct d11txh */
brcms_c_compute_plcp(wlc, rspec[0], phylen, plcp);
brcms_c_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
memcpy(&txh->FragPLCPFallback,
plcp_fallback, sizeof(txh->FragPLCPFallback));
/* Length field now put in CCK FBR CRC field */ if (is_cck_rate(rspec[1])) {
txh->FragPLCPFallback[4] = phylen & 0xff;
txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
}
/* * TxStatus, Note the case of recreating the first frag of a suppressed * frame then we may need to reset the retry cnt's via the status reg
*/
txh->TxStatus = cpu_to_le16(status);
/* * extra fields for ucode AMPDU aggregation, the new fields are added to * the END of previous structure so that it's compatible in driver.
*/
txh->MaxNMpdus = cpu_to_le16(0);
txh->MaxABytes_MRT = cpu_to_le16(0);
txh->MaxABytes_FBR = cpu_to_le16(0);
txh->MinMBytes = cpu_to_le16(0);
/* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration,
* furnish struct d11txh */ /* RTS PLCP header and RTS frame */ if (use_rts || use_cts) { if (use_rts && use_cts)
use_cts = false;
for (k = 0; k < 2; k++) {
rts_rspec[k] = brcms_c_rspec_to_rts_rspec(wlc, rspec[k], false,
mimo_ctlchbw);
}
/* * For mcs frames, if mixedmode(overloaded with long preamble) * is going to be set, fill in non-zero MModeLen and/or * MModeFbrLen it will be unnecessary if they are separated
*/ if (is_mcs_rate(rspec[0]) &&
(preamble_type[0] == BRCMS_MM_PREAMBLE)) {
u16 mmodelen =
brcms_c_calc_lsig_len(wlc, rspec[0], phylen);
txh->MModeLen = cpu_to_le16(mmodelen);
}
if (dma->txavail == 0) { /* * We sometimes get a frame from mac80211 after stopping * the queues. This only ever seems to be a single frame * and is seems likely to be a race. TX_HEADROOM should * ensure that we have enough space to handle these stray * packets, so warn if there isn't. If we're out of space * in the tx ring and the tx queue isn't stopped then * we've really got a bug; warn loudly if that happens.
*/
brcms_warn(wlc->hw->d11core, "Received frame for tx with no space in DMA ring\n");
WARN_ON(!ieee80211_queue_stopped(wlc->pub->ieee_hw,
skb_get_queue_mapping(skb))); return -ENOSPC;
}
/* When a BC/MC frame is being committed to the BCMC fifo * via DMA (NOT PIO), update ucode or BSS info as appropriate.
*/ if (fifo == TX_BCMC_FIFO)
frameid = le16_to_cpu(txh->TxFrameID);
/* Commit BCMC sequence number in the SHM frame ID location */ if (frameid != INVALIDFID) { /* * To inform the ucode of the last mcast frame posted * so that it can clear moredata bit
*/
brcms_b_write_shm(wlc->hw, M_BCMC_FID, frameid);
}
ret = brcms_c_txfifo(wlc, fifo, skb); /* * The only reason for brcms_c_txfifo to fail is because * there weren't any DMA descriptors, but we've already * checked for that. So if it does fail yell loudly.
*/
WARN_ON_ONCE(ret);
int
brcms_c_txfifo(struct brcms_c_info *wlc, uint fifo, struct sk_buff *p)
{ struct dma_pub *dma = wlc->hw->di[fifo]; int ret;
u16 queue;
ret = dma_txfast(wlc, dma, p); if (ret < 0)
wiphy_err(wlc->wiphy, "txfifo: fatal, toss frames !!!\n");
/* * Stop queue if DMA ring is full. Reserve some free descriptors, * as we sometimes receive a frame from mac80211 after the queues * are stopped.
*/
queue = skb_get_queue_mapping(p); if (dma->txavail <= TX_HEADROOM && fifo < TX_BCMC_FIFO &&
!ieee80211_queue_stopped(wlc->pub->ieee_hw, queue))
ieee80211_stop_queue(wlc->pub->ieee_hw, queue);
if (use_rspec) /* use frame rate as rts rate */
rts_rspec = rspec; elseif (wlc->band->gmode && wlc->protection->_g && !is_cck_rate(rspec)) /* Use 11Mbps as the g protection RTS target rate and fallback. * Use the brcms_basic_rate() lookup to find the best basic rate * under the target in case 11 Mbps is not Basic. * 6 and 9 Mbps are not usually selected by rate selection, but * even if the OFDM rate we are protecting is 6 or 9 Mbps, 11 * is more robust.
*/
rts_rspec = brcms_basic_rate(wlc, BRCM_RATE_11M); else /* calculate RTS rate and fallback rate based on the frame rate * RTS must be sent at a basic rate since it is a * control frame, sec 9.6 of 802.11 spec
*/
rts_rspec = brcms_basic_rate(wlc, rspec);
if (BRCMS_PHY_11N_CAP(wlc->band)) { /* set rts txbw to correct side band */
rts_rspec &= ~RSPEC_BW_MASK;
/* * if rspec/rspec_fallback is 40MHz, then send RTS on both * 20MHz channel (DUP), otherwise send RTS on control channel
*/ if (rspec_is40mhz(rspec) && !is_cck_rate(rts_rspec))
rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT); else
rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
/* pick siso/cdd as default for ofdm */ if (is_ofdm_rate(rts_rspec)) {
rts_rspec &= ~RSPEC_STF_MASK;
rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
}
} return rts_rspec;
}
/* Update beacon listen interval in shared memory */ staticvoid brcms_c_bcn_li_upd(struct brcms_c_info *wlc)
{ /* wake up every DTIM is the default */ if (wlc->bcn_li_dtim == 1)
brcms_b_write_shm(wlc->hw, M_BCN_LI, 0); else
brcms_b_write_shm(wlc->hw, M_BCN_LI,
(wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
}
/* read the tsf timer low, then high to get an atomic read */
*tsf_l_ptr = bcma_read32(core, D11REGOFFS(tsf_timerlow));
*tsf_h_ptr = bcma_read32(core, D11REGOFFS(tsf_timerhigh));
}
/* * recover 64bit TSF value from the 16bit TSF value in the rx header * given the assumption that the TSF passed in header is within 65ms * of the current tsf. * * 6 5 4 4 3 2 1 * 3.......6.......8.......0.......2.......4.......6.......8......0 * |<---------- tsf_h ----------->||<--- tsf_l -->||<-RxTSFTime ->| * * The RxTSFTime are the lowest 16 bits and provided by the ucode. The * tsf_l is filled in by brcms_b_recv, which is done earlier in the * receive call sequence after rx interrupt. Only the higher 16 bits * are used. Finally, the tsf_h is read from the tsf register.
*/ static u64 brcms_c_recover_tsf64(struct brcms_c_info *wlc, struct d11rxhdr *rxh)
{
u32 tsf_h, tsf_l;
u16 rx_tsf_0_15, rx_tsf_16_31;
/* * a greater tsf time indicates the low 16 bits of * tsf_l wrapped, so decrement the high 16 bits.
*/ if ((u16)tsf_l < rx_tsf_0_15) {
rx_tsf_16_31 -= 1; if (rx_tsf_16_31 == 0xffff)
tsf_h -= 1;
}
rspec = brcms_c_compute_rspec(rxh, plcp); if (is_mcs_rate(rspec)) {
rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
rx_status->encoding = RX_ENC_HT; if (rspec_is40mhz(rspec))
rx_status->bw = RATE_INFO_BW_40;
} else { switch (rspec2rate(rspec)) { case BRCM_RATE_1M:
rx_status->rate_idx = 0; break; case BRCM_RATE_2M:
rx_status->rate_idx = 1; break; case BRCM_RATE_5M5:
rx_status->rate_idx = 2; break; case BRCM_RATE_11M:
rx_status->rate_idx = 3; break; case BRCM_RATE_6M:
rx_status->rate_idx = 4; break; case BRCM_RATE_9M:
rx_status->rate_idx = 5; break; case BRCM_RATE_12M:
rx_status->rate_idx = 6; break; case BRCM_RATE_18M:
rx_status->rate_idx = 7; break; case BRCM_RATE_24M:
rx_status->rate_idx = 8; break; case BRCM_RATE_36M:
rx_status->rate_idx = 9; break; case BRCM_RATE_48M:
rx_status->rate_idx = 10; break; case BRCM_RATE_54M:
rx_status->rate_idx = 11; break; default:
brcms_err(wlc->hw->d11core, "%s: Unknown rate\n", __func__);
}
/* * For 5GHz, we should decrease the index as it is * a subset of the 2.4G rates. See bitrates field * of brcms_band_5GHz_nphy (in mac80211_if.c).
*/ if (rx_status->band == NL80211_BAND_5GHZ)
rx_status->rate_idx -= BRCMS_LEGACY_5G_RATE_OFFSET;
/* Determine short preamble and rate_idx */ if (is_cck_rate(rspec)) { if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
} elseif (is_ofdm_rate(rspec)) {
rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
} else {
brcms_err(wlc->hw->d11core, "%s: Unknown modulation\n",
__func__);
}
}
if (plcp3_issgi(plcp[3]))
rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
/* calculate frame duration for Mixed-mode L-SIG spoofing, return * number of bytes goes in the length field * * Formula given by HT PHY Spec v 1.13 * len = 3(nsyms + nstream + 3) - 3
*/
u16
brcms_c_calc_lsig_len(struct brcms_c_info *wlc, u32 ratespec,
uint mac_len)
{
uint nsyms, len = 0, kNdps;
if (is_mcs_rate(ratespec)) {
uint mcs = ratespec & RSPEC_RATE_MASK; int tot_streams = (mcs_2_txstreams(mcs) + 1) +
rspec_stc(ratespec);
/* * the payload duration calculation matches that * of regular ofdm
*/ /* 1000Ndbps = kbps * 4 */
kNdps = mcs_2_rate(mcs, rspec_is40mhz(ratespec),
rspec_issgi(ratespec)) * 4;
if (rspec_stc(ratespec) == 0)
nsyms =
CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
APHY_TAIL_NBITS) * 1000, kNdps); else /* STBC needs to have even number of symbols */
nsyms =
2 *
CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
APHY_TAIL_NBITS) * 1000, 2 * kNdps);
/* (+3) account for HT-SIG(2) and HT-STF(1) */
nsyms += (tot_streams + 3); /* * 3 bytes/symbol @ legacy 6Mbps rate * (-3) excluding service bits and tail bits
*/
len = (3 * nsyms) - 3;
}
/* * walk the phy rate table and update MAC core SHM * basic rate table entries
*/ for (i = 0; i < rs.count; i++) {
rate = rs.rates[i] & BRCMS_RATE_MASK;
/* Calculate the Probe Response PLCP for the given rate */
brcms_c_compute_plcp(wlc, rate, frame_len, plcp);
/* * Calculate the duration of the Probe Response * frame plus SIFS for the MAC
*/
dur = (u16) brcms_c_calc_frame_time(wlc, rate,
BRCMS_LONG_PREAMBLE, frame_len);
dur += sifs;
/* Get tx_info */
tx_info = IEEE80211_SKB_CB(beacon);
len = min_t(size_t, beacon->len, BCN_TMPL_LEN);
wlc->bcn_rspec = ieee80211_get_tx_rate(ieee_hw, tx_info)->hw_value;
brcms_c_compute_plcp(wlc, wlc->bcn_rspec,
len + FCS_LEN - D11_PHY_HDR_LEN, beacon->data);
/* "Regular" and 16 MBSS but not for 4 MBSS */ /* Update the phytxctl for the beacon based on the rspec */
brcms_c_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
if (bcn0) { /* write the probe response into the template region */
brcms_b_write_template_ram(wlc_hw, T_BCN0_TPL_BASE,
(len + 3) & ~3, beacon->data);
/* write beacon length to SCR */
brcms_b_write_shm(wlc_hw, M_BCN0_FRM_BYTESZ, (u16) len);
} if (bcn1) { /* write the probe response into the template region */
brcms_b_write_template_ram(wlc_hw, T_BCN1_TPL_BASE,
(len + 3) & ~3, beacon->data);
/* Hardware beaconing for this config */
u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
/* Check if both templates are in use, if so sched. an interrupt * that will call back into this routine
*/ if ((bcma_read32(core, D11REGOFFS(maccommand)) & both_valid) == both_valid) /* clear any previous status */
bcma_write32(core, D11REGOFFS(macintstatus), MI_BCNTPL);
/* Check that after scheduling the interrupt both of the * templates are still busy. if not clear the int. & remask
*/ if ((bcma_read32(core, D11REGOFFS(maccommand)) & both_valid) == both_valid) {
wlc->defmacintmask |= MI_BCNTPL; return;
}
void brcms_c_enable_probe_resp(struct brcms_c_info *wlc, bool enable)
{ /* * prevent ucode from sending probe responses by setting the timeout * to 1, it can not send it in that time frame.
*/
wlc->prb_resp_timeout = enable ? BRCMS_PRB_RESP_TIMEOUT : 1;
brcms_b_write_shm(wlc->hw, M_PRS_MAXTIME, wlc->prb_resp_timeout); /* TODO: if (enable) => also deactivate receiving of probe request */
}
len = min_t(size_t, probe_resp->len, BCN_TMPL_LEN);
if (suspend)
brcms_c_suspend_mac_and_wait(wlc);
/* write the probe response into the template region */
brcms_b_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
(len + 3) & ~3, probe_resp->data);
/* write the length of the probe response frame (+PLCP/-FCS) */
brcms_b_write_shm(wlc->hw, M_PRB_RESP_FRM_LEN, (u16) len);
/* write the SSID and SSID length */
brcms_c_shm_ssid_upd(wlc, cfg);
/* * Write PLCP headers and durations for probe response frames * at all rates. Use the actual frame length covered by the * PLCP header for the call to brcms_c_mod_prb_rsp_rate_table() * by subtracting the PLCP len and adding the FCS.
*/
brcms_c_mod_prb_rsp_rate_table(wlc,
(u16)len + FCS_LEN - D11_PHY_HDR_LEN);
/* * When a remote STA/AP is removed by Mac80211, or when it can no longer accept * AMPDU traffic, packets pending in hardware have to be invalidated so that * when later on hardware releases them, they can be handled appropriately.
*/ void brcms_c_inval_dma_pkts(struct brcms_hardware *hw, struct ieee80211_sta *sta, void (*dma_callback_fn))
{ struct dma_pub *dmah; int i; for (i = 0; i < NFIFO; i++) {
dmah = hw->di[i]; if (dmah != NULL)
dma_walk_packets(dmah, dma_callback_fn, sta);
}
}
int brcms_c_get_curband(struct brcms_c_info *wlc)
{ return wlc->band->bandunit;
}
bool brcms_c_tx_flush_completed(struct brcms_c_info *wlc)
{ int i;
/* Kick DMA to send any pending AMPDU */ for (i = 0; i < ARRAY_SIZE(wlc->hw->di); i++) if (wlc->hw->di[i])
dma_kick_tx(wlc->hw->di[i]);
/* read the tsf timer low, then high to get an atomic read */
bcma_write32(wlc->hw->d11core, D11REGOFFS(tsf_timerlow), tsf_l);
bcma_write32(wlc->hw->d11core, D11REGOFFS(tsf_timerhigh), tsf_h);
brcms_c_time_unlock(wlc);
}
int brcms_c_set_tx_power(struct brcms_c_info *wlc, int txpwr)
{
uint qdbm;
/* Remove override bit and clip to max qdbm value */
qdbm = min_t(uint, txpwr * BRCMS_TXPWR_DB_FACTOR, 0xff); return wlc_phy_txpower_set(wlc->band->pi, qdbm, false);
}
int brcms_c_get_tx_power(struct brcms_c_info *wlc)
{
uint qdbm; bool override;
/* Return qdbm units */ return (int)(qdbm / BRCMS_TXPWR_DB_FACTOR);
}
/* Process received frames */ /* * Return true if more frames need to be processed. false otherwise. * Param 'bound' indicates max. # frames to process before break out.
*/ staticvoid brcms_c_recv(struct brcms_c_info *wlc, struct sk_buff *p)
{ struct d11rxhdr *rxh; struct ieee80211_hdr *h;
uint len; bool is_amsdu;
/* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */ if (rxh->RxStatus1 & RXS_PBPRES) { if (p->len < 2) {
brcms_err(wlc->hw->d11core, "wl%d: recv: rcvd runt of len %d\n",
wlc->pub->unit, p->len); goto toss;
}
skb_pull(p, 2);
}
h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN);
len = p->len;
if (rxh->RxStatus1 & RXS_FCSERR) { if (!(wlc->filter_flags & FIF_FCSFAIL)) goto toss;
}
/* check received pkt has at least frame control field */ if (len < D11_PHY_HDR_LEN + sizeof(h->frame_control)) goto toss;
/* not supporting A-MSDU */
is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK; if (is_amsdu) goto toss;
brcms_c_recvctl(wlc, rxh, p); return;
toss:
brcmu_pkt_buf_free_skb(p);
}
/* Process received frames */ /* * Return true if more frames need to be processed. false otherwise. * Param 'bound' indicates max. # frames to process before break out.
*/ staticbool
brcms_b_recv(struct brcms_hardware *wlc_hw, uint fifo, bool bound)
{ struct sk_buff *p; struct sk_buff *next = NULL; struct sk_buff_head recv_frames;
WARN_ON(macintstatus & MI_PRQ); /* PRQ Interrupt in non-MBSS */
/* tx status */ if (macintstatus & MI_TFS) { bool fatal; if (brcms_b_txstatus(wlc->hw, bounded, &fatal))
wlc->macintstatus |= MI_TFS; if (fatal) {
brcms_err(core, "MI_TFS: fatal\n"); goto fatal;
}
}
if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
brcms_c_tbtt(wlc);
/* ATIM window end */ if (macintstatus & MI_ATIMWINEND) {
brcms_dbg_info(core, "end of ATIM window\n");
bcma_set32(core, D11REGOFFS(maccommand), wlc->qvalid);
wlc->qvalid = 0;
}
/* * received data or control frame, MI_DMAINT is * indication of RX_FIFO interrupt
*/ if (macintstatus & MI_DMAINT) if (brcms_b_recv(wlc_hw, RX_FIFO, bounded))
wlc->macintstatus |= MI_DMAINT;
/* noise sample collected */ if (macintstatus & MI_BG_NOISE)
wlc_phy_noise_sample_intr(wlc_hw->band->pi);
if (macintstatus & MI_GP0) {
brcms_err(core, "wl%d: PSM microcode watchdog fired at %d " "(seconds). Resetting.\n", wlc_hw->unit, wlc_hw->now);
/* write ethernet address to core */
brcms_c_set_mac(wlc->bsscfg);
brcms_c_set_bssid(wlc->bsscfg);
/* Update tsf_cfprep if associated and up */ if (wlc->pub->associated && wlc->pub->up) {
u32 bi;
/* get beacon period and convert to uS */
bi = wlc->bsscfg->current_bss->beacon_period << 10; /* * update since init path would reset * to default value
*/
bcma_write32(core, D11REGOFFS(tsf_cfprep),
bi << CFPREP_CBI_SHIFT);
/* Update maccontrol PM related bits */
brcms_c_set_ps_ctrl(wlc);
}
/* * Initialize WME parameters; if they haven't been set by some other * mechanism (IOVar, etc) then read them from the hardware.
*/ if (GFIELD(wlc->wme_retries[0], EDCF_SHORT) == 0) { /* Uninitialized; read from HW */ int ac;
for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
wlc->wme_retries[ac] =
brcms_b_read_shm(wlc->hw, M_AC_TXLMT_ADDR(ac));
}
}
/* * The common driver entry routine. Error codes should be unique
*/ struct brcms_c_info *
brcms_c_attach(struct brcms_info *wl, struct bcma_device *core, uint unit, bool piomode, uint *perr)
{ struct brcms_c_info *wlc;
uint err = 0;
uint i, j; struct brcms_pub *pub;
/* allocate struct brcms_c_info state and its substructures */
wlc = brcms_c_attach_malloc(unit, &err, 0); if (wlc == NULL) goto fail;
wlc->wiphy = wl->wiphy;
pub = wlc->pub;
/* populate struct brcms_c_info with default values */
brcms_c_info_init(wlc, unit);
/* update sta/ap related parameters */
brcms_c_ap_upd(wlc);
/* * low level attach steps(all hw accesses go * inside, no more in rest of the attach)
*/
err = brcms_b_attach(wlc, core, unit, piomode); if (err) goto fail;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.