staging: brcm80211: migrate #includes from headers into .c files.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / brcm80211 / sys / wlc_bmac.c
blobfc5201d5171ada801d1b7bca1acb9e44d3994ed2
1 /*
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.
17 #ifndef WLC_LOW
18 #error "This file needs WLC_LOW"
19 #endif
21 #include <linux/kernel.h>
22 #include <wlc_cfg.h>
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/netdevice.h>
26 #include <bcmdefs.h>
27 #include <osl.h>
28 #include <proto/802.11.h>
29 #include <bcmwifi.h>
30 #include <bcmutils.h>
31 #include <siutils.h>
32 #include <bcmendian.h>
33 #include <wlioctl.h>
34 #include <sbconfig.h>
35 #include <sbchipc.h>
36 #include <pcicfg.h>
37 #include <sbhndpio.h>
38 #include <sbhnddma.h>
39 #include <hnddma.h>
40 #include <hndpmu.h>
41 #include <d11.h>
42 #include <wlc_rate.h>
43 #include <wlc_pub.h>
44 #include <wlc_channel.h>
45 #include <bcmsrom.h>
46 #include <wlc_key.h>
47 #include <bcmdevs.h>
48 /* BMAC_NOTE: a WLC_HIGH compile include of wlc.h adds in more structures and type
49 * dependencies. Need to include these to files to allow a clean include of wlc.h
50 * with WLC_HIGH defined.
51 * At some point we may be able to skip the include of wlc.h and instead just
52 * define a stub wlc_info and band struct to allow rpc calls to get the rpc handle.
54 #include <wlc_event.h>
55 #include <wlc_mac80211.h>
56 #include <wlc_bmac.h>
57 #include <wlc_phy_shim.h>
58 #include <wlc_phy_hal.h>
59 #include <wl_export.h>
60 #include "wl_ucode.h"
61 #include "d11ucode_ext.h"
62 #ifdef BCMSDIO
63 #include <bcmsdh.h>
64 #endif
65 #include <bcmotp.h>
67 /* BMAC_NOTE: With WLC_HIGH defined, some fns in this file make calls to high level
68 * functions defined in the headers below. We should be eliminating those calls and
69 * will be able to delete these include lines.
71 #include <wlc_antsel.h>
73 #include <pcie_core.h>
75 #include <wlc_alloc.h>
76 #include <wl_dbg.h>
78 #define TIMER_INTERVAL_WATCHDOG_BMAC 1000 /* watchdog timer, in unit of ms */
80 #define SYNTHPU_DLY_APHY_US 3700 /* a phy synthpu_dly time in us */
81 #define SYNTHPU_DLY_BPHY_US 1050 /* b/g phy synthpu_dly time in us, default */
82 #define SYNTHPU_DLY_NPHY_US 2048 /* n phy REV3 synthpu_dly time in us, default */
83 #define SYNTHPU_DLY_LPPHY_US 300 /* lpphy synthpu_dly time in us */
85 #define SYNTHPU_DLY_PHY_US_QT 100 /* QT synthpu_dly time in us */
87 #ifndef BMAC_DUP_TO_REMOVE
88 #define WLC_RM_WAIT_TX_SUSPEND 4 /* Wait Tx Suspend */
90 #define ANTCNT 10 /* vanilla M_MAX_ANTCNT value */
92 #endif /* BMAC_DUP_TO_REMOVE */
94 #define DMAREG(wlc_hw, direction, fifonum) (D11REV_LT(wlc_hw->corerev, 11) ? \
95 ((direction == DMA_TX) ? \
96 (void *)&(wlc_hw->regs->fifo.f32regs.dmaregs[fifonum].xmt) : \
97 (void *)&(wlc_hw->regs->fifo.f32regs.dmaregs[fifonum].rcv)) : \
98 ((direction == DMA_TX) ? \
99 (void *)&(wlc_hw->regs->fifo.f64regs[fifonum].dmaxmt) : \
100 (void *)&(wlc_hw->regs->fifo.f64regs[fifonum].dmarcv)))
103 * The following table lists the buffer memory allocated to xmt fifos in HW.
104 * the size is in units of 256bytes(one block), total size is HW dependent
105 * ucode has default fifo partition, sw can overwrite if necessary
107 * This is documented in twiki under the topic UcodeTxFifo. Please ensure
108 * the twiki is updated before making changes.
111 #define XMTFIFOTBL_STARTREV 20 /* Starting corerev for the fifo size table */
113 static u16 xmtfifo_sz[][NFIFO] = {
114 {20, 192, 192, 21, 17, 5}, /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */
115 {9, 58, 22, 14, 14, 5}, /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */
116 {20, 192, 192, 21, 17, 5}, /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */
117 {20, 192, 192, 21, 17, 5}, /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */
118 {9, 58, 22, 14, 14, 5}, /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
121 static void wlc_clkctl_clk(wlc_hw_info_t *wlc, uint mode);
122 static void wlc_coreinit(wlc_info_t *wlc);
124 /* used by wlc_wakeucode_init() */
125 static void wlc_write_inits(wlc_hw_info_t *wlc_hw, const d11init_t *inits);
126 static void wlc_ucode_write(wlc_hw_info_t *wlc_hw, const u32 ucode[],
127 const uint nbytes);
128 static void wlc_ucode_download(wlc_hw_info_t *wlc);
129 static void wlc_ucode_txant_set(wlc_hw_info_t *wlc_hw);
131 /* used by wlc_dpc() */
132 static bool wlc_bmac_dotxstatus(wlc_hw_info_t *wlc, tx_status_t *txs,
133 u32 s2);
134 static bool wlc_bmac_txstatus_corerev4(wlc_hw_info_t *wlc);
135 static bool wlc_bmac_txstatus(wlc_hw_info_t *wlc, bool bound, bool *fatal);
136 static bool wlc_bmac_recv(wlc_hw_info_t *wlc_hw, uint fifo, bool bound);
138 /* used by wlc_down() */
139 static void wlc_flushqueues(wlc_info_t *wlc);
141 static void wlc_write_mhf(wlc_hw_info_t *wlc_hw, u16 *mhfs);
142 static void wlc_mctrl_reset(wlc_hw_info_t *wlc_hw);
143 static void wlc_corerev_fifofixup(wlc_hw_info_t *wlc_hw);
145 /* Low Level Prototypes */
146 static u16 wlc_bmac_read_objmem(wlc_hw_info_t *wlc_hw, uint offset,
147 u32 sel);
148 static void wlc_bmac_write_objmem(wlc_hw_info_t *wlc_hw, uint offset, u16 v,
149 u32 sel);
150 static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme);
151 static void wlc_bmac_detach_dmapio(wlc_hw_info_t *wlc_hw);
152 static void wlc_ucode_bsinit(wlc_hw_info_t *wlc_hw);
153 static bool wlc_validboardtype(wlc_hw_info_t *wlc);
154 static bool wlc_isgoodchip(wlc_hw_info_t *wlc_hw);
155 static char *wlc_get_macaddr(wlc_hw_info_t *wlc_hw);
156 static void wlc_mhfdef(wlc_info_t *wlc, u16 *mhfs, u16 mhf2_init);
157 static void wlc_mctrl_write(wlc_hw_info_t *wlc_hw);
158 static void wlc_ucode_mute_override_set(wlc_hw_info_t *wlc_hw);
159 static void wlc_ucode_mute_override_clear(wlc_hw_info_t *wlc_hw);
160 static u32 wlc_wlintrsoff(wlc_info_t *wlc);
161 static void wlc_wlintrsrestore(wlc_info_t *wlc, u32 macintmask);
162 static void wlc_gpio_init(wlc_info_t *wlc);
163 static void wlc_write_hw_bcntemplate0(wlc_hw_info_t *wlc_hw, void *bcn,
164 int len);
165 static void wlc_write_hw_bcntemplate1(wlc_hw_info_t *wlc_hw, void *bcn,
166 int len);
167 static void wlc_bmac_bsinit(wlc_info_t *wlc, chanspec_t chanspec);
168 static u32 wlc_setband_inact(wlc_info_t *wlc, uint bandunit);
169 static void wlc_bmac_setband(wlc_hw_info_t *wlc_hw, uint bandunit,
170 chanspec_t chanspec);
171 static void wlc_bmac_update_slot_timing(wlc_hw_info_t *wlc_hw, bool shortslot);
172 static void wlc_upd_ofdm_pctl1_table(wlc_hw_info_t *wlc_hw);
173 static u16 wlc_bmac_ofdm_ratetable_offset(wlc_hw_info_t *wlc_hw,
174 u8 rate);
176 /* === Low Level functions === */
178 void wlc_bmac_set_shortslot(wlc_hw_info_t *wlc_hw, bool shortslot)
180 wlc_hw->shortslot = shortslot;
182 if (BAND_2G(wlc_hw->band->bandtype) && wlc_hw->up) {
183 wlc_suspend_mac_and_wait(wlc_hw->wlc);
184 wlc_bmac_update_slot_timing(wlc_hw, shortslot);
185 wlc_enable_mac(wlc_hw->wlc);
190 * Update the slot timing for standard 11b/g (20us slots)
191 * or shortslot 11g (9us slots)
192 * The PSM needs to be suspended for this call.
194 static void wlc_bmac_update_slot_timing(wlc_hw_info_t *wlc_hw, bool shortslot)
196 osl_t *osh;
197 d11regs_t *regs;
199 osh = wlc_hw->osh;
200 regs = wlc_hw->regs;
202 if (shortslot) {
203 /* 11g short slot: 11a timing */
204 W_REG(osh, &regs->ifs_slot, 0x0207); /* APHY_SLOT_TIME */
205 wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, APHY_SLOT_TIME);
206 } else {
207 /* 11g long slot: 11b timing */
208 W_REG(osh, &regs->ifs_slot, 0x0212); /* BPHY_SLOT_TIME */
209 wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, BPHY_SLOT_TIME);
213 static void WLBANDINITFN(wlc_ucode_bsinit) (wlc_hw_info_t *wlc_hw)
215 /* init microcode host flags */
216 wlc_write_mhf(wlc_hw, wlc_hw->band->mhfs);
218 /* do band-specific ucode IHR, SHM, and SCR inits */
219 if (D11REV_IS(wlc_hw->corerev, 23)) {
220 if (WLCISNPHY(wlc_hw->band)) {
221 wlc_write_inits(wlc_hw, d11n0bsinitvals16);
222 } else {
223 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n",
224 __func__, wlc_hw->unit, wlc_hw->corerev));
226 } else {
227 if (D11REV_IS(wlc_hw->corerev, 24)) {
228 if (WLCISLCNPHY(wlc_hw->band)) {
229 wlc_write_inits(wlc_hw, d11lcn0bsinitvals24);
230 } else
231 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n", __func__, wlc_hw->unit, wlc_hw->corerev));
232 } else {
233 WL_ERROR(("%s: wl%d: unsupported corerev %d\n",
234 __func__, wlc_hw->unit, wlc_hw->corerev));
239 /* switch to new band but leave it inactive */
240 static u32 WLBANDINITFN(wlc_setband_inact) (wlc_info_t *wlc, uint bandunit)
242 wlc_hw_info_t *wlc_hw = wlc->hw;
243 u32 macintmask;
244 u32 tmp;
246 WL_TRACE(("wl%d: wlc_setband_inact\n", wlc_hw->unit));
248 ASSERT(bandunit != wlc_hw->band->bandunit);
249 ASSERT(si_iscoreup(wlc_hw->sih));
250 ASSERT((R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol) & MCTL_EN_MAC) ==
253 /* disable interrupts */
254 macintmask = wl_intrsoff(wlc->wl);
256 /* radio off */
257 wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
259 ASSERT(wlc_hw->clk);
261 if (D11REV_LT(wlc_hw->corerev, 17))
262 tmp = R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol);
264 wlc_bmac_core_phy_clk(wlc_hw, OFF);
266 wlc_setxband(wlc_hw, bandunit);
268 return macintmask;
271 /* Process received frames */
273 * Return true if more frames need to be processed. false otherwise.
274 * Param 'bound' indicates max. # frames to process before break out.
276 static bool BCMFASTPATH
277 wlc_bmac_recv(wlc_hw_info_t *wlc_hw, uint fifo, bool bound)
279 void *p;
280 void *head = NULL;
281 void *tail = NULL;
282 uint n = 0;
283 uint bound_limit = bound ? wlc_hw->wlc->pub->tunables->rxbnd : -1;
284 u32 tsf_h, tsf_l;
285 wlc_d11rxhdr_t *wlc_rxhdr = NULL;
287 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__));
288 /* gather received frames */
289 while ((p = dma_rx(wlc_hw->di[fifo]))) {
291 if (!tail)
292 head = tail = p;
293 else {
294 PKTSETLINK(tail, p);
295 tail = p;
298 /* !give others some time to run! */
299 if (++n >= bound_limit)
300 break;
303 /* get the TSF REG reading */
304 wlc_bmac_read_tsf(wlc_hw, &tsf_l, &tsf_h);
306 /* post more rbufs */
307 dma_rxfill(wlc_hw->di[fifo]);
309 /* process each frame */
310 while ((p = head) != NULL) {
311 head = PKTLINK(head);
312 PKTSETLINK(p, NULL);
314 /* record the tsf_l in wlc_rxd11hdr */
315 wlc_rxhdr = (wlc_d11rxhdr_t *) PKTDATA(p);
316 wlc_rxhdr->tsf_l = htol32(tsf_l);
318 /* compute the RSSI from d11rxhdr and record it in wlc_rxd11hr */
319 wlc_phy_rssi_compute(wlc_hw->band->pi, wlc_rxhdr);
321 wlc_recv(wlc_hw->wlc, p);
324 return n >= bound_limit;
327 /* second-level interrupt processing
328 * Return true if another dpc needs to be re-scheduled. false otherwise.
329 * Param 'bounded' indicates if applicable loops should be bounded.
331 bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
333 u32 macintstatus;
334 wlc_hw_info_t *wlc_hw = wlc->hw;
335 d11regs_t *regs = wlc_hw->regs;
336 bool fatal = false;
338 if (DEVICEREMOVED(wlc)) {
339 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__));
340 wl_down(wlc->wl);
341 return false;
344 /* grab and clear the saved software intstatus bits */
345 macintstatus = wlc->macintstatus;
346 wlc->macintstatus = 0;
348 WL_TRACE(("wl%d: wlc_dpc: macintstatus 0x%x\n", wlc_hw->unit,
349 macintstatus));
351 if (macintstatus & MI_PRQ) {
352 /* Process probe request FIFO */
353 ASSERT(0 && "PRQ Interrupt in non-MBSS");
356 /* BCN template is available */
357 /* ZZZ: Use AP_ACTIVE ? */
358 if (AP_ENAB(wlc->pub) && (!APSTA_ENAB(wlc->pub) || wlc->aps_associated)
359 && (macintstatus & MI_BCNTPL)) {
360 wlc_update_beacon(wlc);
363 /* PMQ entry addition */
364 if (macintstatus & MI_PMQ) {
367 /* tx status */
368 if (macintstatus & MI_TFS) {
369 if (wlc_bmac_txstatus(wlc->hw, bounded, &fatal))
370 wlc->macintstatus |= MI_TFS;
371 if (fatal) {
372 WL_ERROR(("MI_TFS: fatal\n"));
373 goto fatal;
377 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
378 wlc_tbtt(wlc, regs);
380 /* ATIM window end */
381 if (macintstatus & MI_ATIMWINEND) {
382 WL_TRACE(("wlc_isr: end of ATIM window\n"));
384 OR_REG(wlc_hw->osh, &regs->maccommand, wlc->qvalid);
385 wlc->qvalid = 0;
388 /* phy tx error */
389 if (macintstatus & MI_PHYTXERR) {
390 WLCNTINCR(wlc->pub->_cnt->txphyerr);
393 /* received data or control frame, MI_DMAINT is indication of RX_FIFO interrupt */
394 if (macintstatus & MI_DMAINT) {
395 if (wlc_bmac_recv(wlc_hw, RX_FIFO, bounded)) {
396 wlc->macintstatus |= MI_DMAINT;
400 /* TX FIFO suspend/flush completion */
401 if (macintstatus & MI_TXSTOP) {
402 if (wlc_bmac_tx_fifo_suspended(wlc_hw, TX_DATA_FIFO)) {
403 /* WL_ERROR(("dpc: fifo_suspend_comlete\n")); */
407 /* noise sample collected */
408 if (macintstatus & MI_BG_NOISE) {
409 wlc_phy_noise_sample_intr(wlc_hw->band->pi);
412 if (macintstatus & MI_GP0) {
413 WL_ERROR(("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n", wlc_hw->unit, wlc_hw->now));
415 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
416 __func__, CHIPID(wlc_hw->sih->chip),
417 CHIPREV(wlc_hw->sih->chiprev));
419 WLCNTINCR(wlc->pub->_cnt->psmwds);
421 /* big hammer */
422 wl_init(wlc->wl);
425 /* gptimer timeout */
426 if (macintstatus & MI_TO) {
427 W_REG(wlc_hw->osh, &regs->gptimer, 0);
430 if (macintstatus & MI_RFDISABLE) {
431 #if defined(BCMDBG)
432 u32 rfd = R_REG(wlc_hw->osh, &regs->phydebug) & PDBG_RFD;
433 #endif
435 WL_ERROR(("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n", wlc_hw->unit, rfd));
437 WLCNTINCR(wlc->pub->_cnt->rfdisable);
440 /* send any enq'd tx packets. Just makes sure to jump start tx */
441 if (!pktq_empty(&wlc->active_queue->q))
442 wlc_send_q(wlc, wlc->active_queue);
444 ASSERT(wlc_ps_check(wlc));
446 /* make sure the bound indication and the implementation are in sync */
447 ASSERT(bounded == true || wlc->macintstatus == 0);
449 /* it isn't done and needs to be resched if macintstatus is non-zero */
450 return wlc->macintstatus != 0;
452 fatal:
453 wl_init(wlc->wl);
454 return wlc->macintstatus != 0;
457 /* common low-level watchdog code */
458 void wlc_bmac_watchdog(void *arg)
460 wlc_info_t *wlc = (wlc_info_t *) arg;
461 wlc_hw_info_t *wlc_hw = wlc->hw;
463 WL_TRACE(("wl%d: wlc_bmac_watchdog\n", wlc_hw->unit));
465 if (!wlc_hw->up)
466 return;
468 /* increment second count */
469 wlc_hw->now++;
471 /* Check for FIFO error interrupts */
472 wlc_bmac_fifoerrors(wlc_hw);
474 /* make sure RX dma has buffers */
475 dma_rxfill(wlc->hw->di[RX_FIFO]);
476 if (D11REV_IS(wlc_hw->corerev, 4)) {
477 dma_rxfill(wlc->hw->di[RX_TXSTATUS_FIFO]);
480 wlc_phy_watchdog(wlc_hw->band->pi);
483 void
484 wlc_bmac_set_chanspec(wlc_hw_info_t *wlc_hw, chanspec_t chanspec, bool mute,
485 struct txpwr_limits *txpwr)
487 uint bandunit;
489 WL_TRACE(("wl%d: wlc_bmac_set_chanspec 0x%x\n", wlc_hw->unit,
490 chanspec));
492 wlc_hw->chanspec = chanspec;
494 /* Switch bands if necessary */
495 if (NBANDS_HW(wlc_hw) > 1) {
496 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
497 if (wlc_hw->band->bandunit != bandunit) {
498 /* wlc_bmac_setband disables other bandunit,
499 * use light band switch if not up yet
501 if (wlc_hw->up) {
502 wlc_phy_chanspec_radio_set(wlc_hw->
503 bandstate[bandunit]->
504 pi, chanspec);
505 wlc_bmac_setband(wlc_hw, bandunit, chanspec);
506 } else {
507 wlc_setxband(wlc_hw, bandunit);
512 wlc_phy_initcal_enable(wlc_hw->band->pi, !mute);
514 if (!wlc_hw->up) {
515 if (wlc_hw->clk)
516 wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr,
517 chanspec);
518 wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
519 } else {
520 wlc_phy_chanspec_set(wlc_hw->band->pi, chanspec);
521 wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, chanspec);
523 /* Update muting of the channel */
524 wlc_bmac_mute(wlc_hw, mute, 0);
528 int wlc_bmac_revinfo_get(wlc_hw_info_t *wlc_hw, wlc_bmac_revinfo_t *revinfo)
530 si_t *sih = wlc_hw->sih;
531 uint idx;
533 revinfo->vendorid = wlc_hw->vendorid;
534 revinfo->deviceid = wlc_hw->deviceid;
536 revinfo->boardrev = wlc_hw->boardrev;
537 revinfo->corerev = wlc_hw->corerev;
538 revinfo->sromrev = wlc_hw->sromrev;
539 revinfo->chiprev = sih->chiprev;
540 revinfo->chip = sih->chip;
541 revinfo->chippkg = sih->chippkg;
542 revinfo->boardtype = sih->boardtype;
543 revinfo->boardvendor = sih->boardvendor;
544 revinfo->bustype = sih->bustype;
545 revinfo->buscoretype = sih->buscoretype;
546 revinfo->buscorerev = sih->buscorerev;
547 revinfo->issim = sih->issim;
549 revinfo->nbands = NBANDS_HW(wlc_hw);
551 for (idx = 0; idx < NBANDS_HW(wlc_hw); idx++) {
552 wlc_hwband_t *band = wlc_hw->bandstate[idx];
553 revinfo->band[idx].bandunit = band->bandunit;
554 revinfo->band[idx].bandtype = band->bandtype;
555 revinfo->band[idx].phytype = band->phytype;
556 revinfo->band[idx].phyrev = band->phyrev;
557 revinfo->band[idx].radioid = band->radioid;
558 revinfo->band[idx].radiorev = band->radiorev;
559 revinfo->band[idx].abgphy_encore = band->abgphy_encore;
560 revinfo->band[idx].anarev = 0;
563 return 0;
566 int wlc_bmac_state_get(wlc_hw_info_t *wlc_hw, wlc_bmac_state_t *state)
568 state->machwcap = wlc_hw->machwcap;
570 return 0;
573 static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme)
575 uint i;
576 char name[8];
577 /* ucode host flag 2 needed for pio mode, independent of band and fifo */
578 u16 pio_mhf2 = 0;
579 wlc_hw_info_t *wlc_hw = wlc->hw;
580 uint unit = wlc_hw->unit;
581 wlc_tunables_t *tune = wlc->pub->tunables;
583 /* name and offsets for dma_attach */
584 snprintf(name, sizeof(name), "wl%d", unit);
586 if (wlc_hw->di[0] == 0) { /* Init FIFOs */
587 uint addrwidth;
588 int dma_attach_err = 0;
589 osl_t *osh = wlc_hw->osh;
591 /* Find out the DMA addressing capability and let OS know
592 * All the channels within one DMA core have 'common-minimum' same
593 * capability
595 addrwidth =
596 dma_addrwidth(wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 0));
597 OSL_DMADDRWIDTH(osh, addrwidth);
599 if (!wl_alloc_dma_resources(wlc_hw->wlc->wl, addrwidth)) {
600 WL_ERROR(("wl%d: wlc_attach: alloc_dma_resources failed\n", unit));
601 return false;
605 * FIFO 0
606 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
607 * RX: RX_FIFO (RX data packets)
609 ASSERT(TX_AC_BK_FIFO == 0);
610 ASSERT(RX_FIFO == 0);
611 wlc_hw->di[0] = dma_attach(osh, name, wlc_hw->sih,
612 (wme ? DMAREG(wlc_hw, DMA_TX, 0) :
613 NULL), DMAREG(wlc_hw, DMA_RX, 0),
614 (wme ? tune->ntxd : 0), tune->nrxd,
615 tune->rxbufsz, -1, tune->nrxbufpost,
616 WL_HWRXOFF, &wl_msg_level);
617 dma_attach_err |= (NULL == wlc_hw->di[0]);
620 * FIFO 1
621 * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets)
622 * (legacy) TX_DATA_FIFO (TX data packets)
623 * RX: UNUSED
625 ASSERT(TX_AC_BE_FIFO == 1);
626 ASSERT(TX_DATA_FIFO == 1);
627 wlc_hw->di[1] = dma_attach(osh, name, wlc_hw->sih,
628 DMAREG(wlc_hw, DMA_TX, 1), NULL,
629 tune->ntxd, 0, 0, -1, 0, 0,
630 &wl_msg_level);
631 dma_attach_err |= (NULL == wlc_hw->di[1]);
634 * FIFO 2
635 * TX: TX_AC_VI_FIFO (TX AC Video data packets)
636 * RX: UNUSED
638 ASSERT(TX_AC_VI_FIFO == 2);
639 wlc_hw->di[2] = dma_attach(osh, name, wlc_hw->sih,
640 DMAREG(wlc_hw, DMA_TX, 2), NULL,
641 tune->ntxd, 0, 0, -1, 0, 0,
642 &wl_msg_level);
643 dma_attach_err |= (NULL == wlc_hw->di[2]);
645 * FIFO 3
646 * TX: TX_AC_VO_FIFO (TX AC Voice data packets)
647 * (legacy) TX_CTL_FIFO (TX control & mgmt packets)
648 * RX: RX_TXSTATUS_FIFO (transmit-status packets)
649 * for corerev < 5 only
651 ASSERT(TX_AC_VO_FIFO == 3);
652 ASSERT(TX_CTL_FIFO == 3);
653 if (D11REV_IS(wlc_hw->corerev, 4)) {
654 ASSERT(RX_TXSTATUS_FIFO == 3);
655 wlc_hw->di[3] = dma_attach(osh, name, wlc_hw->sih,
656 DMAREG(wlc_hw, DMA_TX, 3),
657 DMAREG(wlc_hw, DMA_RX, 3),
658 tune->ntxd, tune->nrxd,
659 sizeof(tx_status_t), -1,
660 tune->nrxbufpost, 0,
661 &wl_msg_level);
662 dma_attach_err |= (NULL == wlc_hw->di[3]);
663 } else {
664 wlc_hw->di[3] = dma_attach(osh, name, wlc_hw->sih,
665 DMAREG(wlc_hw, DMA_TX, 3),
666 NULL, tune->ntxd, 0, 0, -1,
667 0, 0, &wl_msg_level);
668 dma_attach_err |= (NULL == wlc_hw->di[3]);
670 /* Cleaner to leave this as if with AP defined */
672 if (dma_attach_err) {
673 WL_ERROR(("wl%d: wlc_attach: dma_attach failed\n",
674 unit));
675 return false;
678 /* get pointer to dma engine tx flow control variable */
679 for (i = 0; i < NFIFO; i++)
680 if (wlc_hw->di[i])
681 wlc_hw->txavail[i] =
682 (uint *) dma_getvar(wlc_hw->di[i],
683 "&txavail");
686 /* initial ucode host flags */
687 wlc_mhfdef(wlc, wlc_hw->band->mhfs, pio_mhf2);
689 return true;
692 static void wlc_bmac_detach_dmapio(wlc_hw_info_t *wlc_hw)
694 uint j;
696 for (j = 0; j < NFIFO; j++) {
697 if (wlc_hw->di[j]) {
698 dma_detach(wlc_hw->di[j]);
699 wlc_hw->di[j] = NULL;
704 /* low level attach
705 * run backplane attach, init nvram
706 * run phy attach
707 * initialize software state for each core and band
708 * put the whole chip in reset(driver down state), no clock
710 int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
711 bool piomode, osl_t *osh, void *regsva, uint bustype,
712 void *btparam)
714 wlc_hw_info_t *wlc_hw;
715 d11regs_t *regs;
716 char *macaddr = NULL;
717 char *vars;
718 uint err = 0;
719 uint j;
720 bool wme = false;
721 shared_phy_params_t sha_params;
723 WL_TRACE(("wl%d: wlc_bmac_attach: vendor 0x%x device 0x%x\n", unit,
724 vendor, device));
726 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
728 wme = true;
730 wlc_hw = wlc->hw;
731 wlc_hw->wlc = wlc;
732 wlc_hw->unit = unit;
733 wlc_hw->osh = osh;
734 wlc_hw->band = wlc_hw->bandstate[0];
735 wlc_hw->_piomode = piomode;
737 /* populate wlc_hw_info_t with default values */
738 wlc_bmac_info_init(wlc_hw);
741 * Do the hardware portion of the attach.
742 * Also initialize software state that depends on the particular hardware
743 * we are running.
745 wlc_hw->sih = si_attach((uint) device, osh, regsva, bustype, btparam,
746 &wlc_hw->vars, &wlc_hw->vars_size);
747 if (wlc_hw->sih == NULL) {
748 WL_ERROR(("wl%d: wlc_bmac_attach: si_attach failed\n", unit));
749 err = 11;
750 goto fail;
752 vars = wlc_hw->vars;
755 * Get vendid/devid nvram overwrites, which could be different
756 * than those the BIOS recognizes for devices on PCMCIA_BUS,
757 * SDIO_BUS, and SROMless devices on PCI_BUS.
759 #ifdef BCMBUSTYPE
760 bustype = BCMBUSTYPE;
761 #endif
762 if (bustype != SI_BUS) {
763 char *var;
765 var = getvar(vars, "vendid");
766 if (var) {
767 vendor = (u16) simple_strtoul(var, NULL, 0);
768 WL_ERROR(("Overriding vendor id = 0x%x\n", vendor));
770 var = getvar(vars, "devid");
771 if (var) {
772 u16 devid = (u16) simple_strtoul(var, NULL, 0);
773 if (devid != 0xffff) {
774 device = devid;
775 WL_ERROR(("Overriding device id = 0x%x\n",
776 device));
780 /* verify again the device is supported */
781 if (!wlc_chipmatch(vendor, device)) {
782 WL_ERROR(("wl%d: wlc_bmac_attach: Unsupported vendor/device (0x%x/0x%x)\n", unit, vendor, device));
783 err = 12;
784 goto fail;
788 wlc_hw->vendorid = vendor;
789 wlc_hw->deviceid = device;
791 /* set bar0 window to point at D11 core */
792 wlc_hw->regs = (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID, 0);
793 wlc_hw->corerev = si_corerev(wlc_hw->sih);
795 regs = wlc_hw->regs;
797 wlc->regs = wlc_hw->regs;
799 /* validate chip, chiprev and corerev */
800 if (!wlc_isgoodchip(wlc_hw)) {
801 err = 13;
802 goto fail;
805 /* initialize power control registers */
806 si_clkctl_init(wlc_hw->sih);
808 /* request fastclock and force fastclock for the rest of attach
809 * bring the d11 core out of reset.
810 * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk is still false;
811 * But it will be called again inside wlc_corereset, after d11 is out of reset.
813 wlc_clkctl_clk(wlc_hw, CLK_FAST);
814 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
816 if (!wlc_bmac_validate_chip_access(wlc_hw)) {
817 WL_ERROR(("wl%d: wlc_bmac_attach: validate_chip_access failed\n", unit));
818 err = 14;
819 goto fail;
822 /* get the board rev, used just below */
823 j = getintvar(vars, "boardrev");
824 /* promote srom boardrev of 0xFF to 1 */
825 if (j == BOARDREV_PROMOTABLE)
826 j = BOARDREV_PROMOTED;
827 wlc_hw->boardrev = (u16) j;
828 if (!wlc_validboardtype(wlc_hw)) {
829 WL_ERROR(("wl%d: wlc_bmac_attach: Unsupported Broadcom board type (0x%x)" " or revision level (0x%x)\n", unit, wlc_hw->sih->boardtype, wlc_hw->boardrev));
830 err = 15;
831 goto fail;
833 wlc_hw->sromrev = (u8) getintvar(vars, "sromrev");
834 wlc_hw->boardflags = (u32) getintvar(vars, "boardflags");
835 wlc_hw->boardflags2 = (u32) getintvar(vars, "boardflags2");
837 if (D11REV_LE(wlc_hw->corerev, 4)
838 || (wlc_hw->boardflags & BFL_NOPLLDOWN))
839 wlc_bmac_pllreq(wlc_hw, true, WLC_PLLREQ_SHARED);
841 if ((BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS)
842 && (si_pci_war16165(wlc_hw->sih)))
843 wlc->war16165 = true;
845 /* check device id(srom, nvram etc.) to set bands */
846 if (wlc_hw->deviceid == BCM43224_D11N_ID) {
847 /* Dualband boards */
848 wlc_hw->_nbands = 2;
849 } else
850 wlc_hw->_nbands = 1;
852 if ((CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID))
853 wlc_hw->_nbands = 1;
855 /* BMAC_NOTE: remove init of pub values when wlc_attach() unconditionally does the
856 * init of these values
858 wlc->vendorid = wlc_hw->vendorid;
859 wlc->deviceid = wlc_hw->deviceid;
860 wlc->pub->sih = wlc_hw->sih;
861 wlc->pub->corerev = wlc_hw->corerev;
862 wlc->pub->sromrev = wlc_hw->sromrev;
863 wlc->pub->boardrev = wlc_hw->boardrev;
864 wlc->pub->boardflags = wlc_hw->boardflags;
865 wlc->pub->boardflags2 = wlc_hw->boardflags2;
866 wlc->pub->_nbands = wlc_hw->_nbands;
868 wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc);
870 if (wlc_hw->physhim == NULL) {
871 WL_ERROR(("wl%d: wlc_bmac_attach: wlc_phy_shim_attach failed\n",
872 unit));
873 err = 25;
874 goto fail;
877 /* pass all the parameters to wlc_phy_shared_attach in one struct */
878 sha_params.osh = osh;
879 sha_params.sih = wlc_hw->sih;
880 sha_params.physhim = wlc_hw->physhim;
881 sha_params.unit = unit;
882 sha_params.corerev = wlc_hw->corerev;
883 sha_params.vars = vars;
884 sha_params.vid = wlc_hw->vendorid;
885 sha_params.did = wlc_hw->deviceid;
886 sha_params.chip = wlc_hw->sih->chip;
887 sha_params.chiprev = wlc_hw->sih->chiprev;
888 sha_params.chippkg = wlc_hw->sih->chippkg;
889 sha_params.sromrev = wlc_hw->sromrev;
890 sha_params.boardtype = wlc_hw->sih->boardtype;
891 sha_params.boardrev = wlc_hw->boardrev;
892 sha_params.boardvendor = wlc_hw->sih->boardvendor;
893 sha_params.boardflags = wlc_hw->boardflags;
894 sha_params.boardflags2 = wlc_hw->boardflags2;
895 sha_params.bustype = wlc_hw->sih->bustype;
896 sha_params.buscorerev = wlc_hw->sih->buscorerev;
898 /* alloc and save pointer to shared phy state area */
899 wlc_hw->phy_sh = wlc_phy_shared_attach(&sha_params);
900 if (!wlc_hw->phy_sh) {
901 err = 16;
902 goto fail;
905 /* initialize software state for each core and band */
906 for (j = 0; j < NBANDS_HW(wlc_hw); j++) {
908 * band0 is always 2.4Ghz
909 * band1, if present, is 5Ghz
912 /* So if this is a single band 11a card, use band 1 */
913 if (IS_SINGLEBAND_5G(wlc_hw->deviceid))
914 j = BAND_5G_INDEX;
916 wlc_setxband(wlc_hw, j);
918 wlc_hw->band->bandunit = j;
919 wlc_hw->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
920 wlc->band->bandunit = j;
921 wlc->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
922 wlc->core->coreidx = si_coreidx(wlc_hw->sih);
924 if (D11REV_GE(wlc_hw->corerev, 13)) {
925 wlc_hw->machwcap = R_REG(wlc_hw->osh, &regs->machwcap);
926 wlc_hw->machwcap_backup = wlc_hw->machwcap;
929 /* init tx fifo size */
930 ASSERT((wlc_hw->corerev - XMTFIFOTBL_STARTREV) <
931 ARRAY_SIZE(xmtfifo_sz));
932 wlc_hw->xmtfifo_sz =
933 xmtfifo_sz[(wlc_hw->corerev - XMTFIFOTBL_STARTREV)];
935 /* Get a phy for this band */
936 wlc_hw->band->pi = wlc_phy_attach(wlc_hw->phy_sh,
937 (void *)regs, wlc_hw->band->bandtype, vars);
938 if (wlc_hw->band->pi == NULL) {
939 WL_ERROR(("wl%d: wlc_bmac_attach: wlc_phy_attach failed\n", unit));
940 err = 17;
941 goto fail;
944 wlc_phy_machwcap_set(wlc_hw->band->pi, wlc_hw->machwcap);
946 wlc_phy_get_phyversion(wlc_hw->band->pi, &wlc_hw->band->phytype,
947 &wlc_hw->band->phyrev,
948 &wlc_hw->band->radioid,
949 &wlc_hw->band->radiorev);
950 wlc_hw->band->abgphy_encore =
951 wlc_phy_get_encore(wlc_hw->band->pi);
952 wlc->band->abgphy_encore = wlc_phy_get_encore(wlc_hw->band->pi);
953 wlc_hw->band->core_flags =
954 wlc_phy_get_coreflags(wlc_hw->band->pi);
956 /* verify good phy_type & supported phy revision */
957 if (WLCISNPHY(wlc_hw->band)) {
958 if (NCONF_HAS(wlc_hw->band->phyrev))
959 goto good_phy;
960 else
961 goto bad_phy;
962 } else if (WLCISLCNPHY(wlc_hw->band)) {
963 if (LCNCONF_HAS(wlc_hw->band->phyrev))
964 goto good_phy;
965 else
966 goto bad_phy;
967 } else {
968 bad_phy:
969 WL_ERROR(("wl%d: wlc_bmac_attach: unsupported phy type/rev (%d/%d)\n", unit, wlc_hw->band->phytype, wlc_hw->band->phyrev));
970 err = 18;
971 goto fail;
974 good_phy:
975 /* BMAC_NOTE: wlc->band->pi should not be set below and should be done in the
976 * high level attach. However we can not make that change until all low level access
977 * is changed to wlc_hw->band->pi. Instead do the wlc->band->pi init below, keeping
978 * wlc_hw->band->pi as well for incremental update of low level fns, and cut over
979 * low only init when all fns updated.
981 wlc->band->pi = wlc_hw->band->pi;
982 wlc->band->phytype = wlc_hw->band->phytype;
983 wlc->band->phyrev = wlc_hw->band->phyrev;
984 wlc->band->radioid = wlc_hw->band->radioid;
985 wlc->band->radiorev = wlc_hw->band->radiorev;
987 /* default contention windows size limits */
988 wlc_hw->band->CWmin = APHY_CWMIN;
989 wlc_hw->band->CWmax = PHY_CWMAX;
991 if (!wlc_bmac_attach_dmapio(wlc, j, wme)) {
992 err = 19;
993 goto fail;
997 /* disable core to match driver "down" state */
998 wlc_coredisable(wlc_hw);
1000 /* Match driver "down" state */
1001 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS)
1002 si_pci_down(wlc_hw->sih);
1004 /* register sb interrupt callback functions */
1005 si_register_intr_callback(wlc_hw->sih, (void *)wlc_wlintrsoff,
1006 (void *)wlc_wlintrsrestore, NULL, wlc);
1008 /* turn off pll and xtal to match driver "down" state */
1009 wlc_bmac_xtal(wlc_hw, OFF);
1011 /* *********************************************************************
1012 * The hardware is in the DOWN state at this point. D11 core
1013 * or cores are in reset with clocks off, and the board PLLs
1014 * are off if possible.
1016 * Beyond this point, wlc->sbclk == false and chip registers
1017 * should not be touched.
1018 *********************************************************************
1021 /* init etheraddr state variables */
1022 macaddr = wlc_get_macaddr(wlc_hw);
1023 if (macaddr == NULL) {
1024 WL_ERROR(("wl%d: wlc_bmac_attach: macaddr not found\n", unit));
1025 err = 21;
1026 goto fail;
1028 bcm_ether_atoe(macaddr, &wlc_hw->etheraddr);
1029 if (ETHER_ISBCAST((char *)&wlc_hw->etheraddr) ||
1030 ETHER_ISNULLADDR((char *)&wlc_hw->etheraddr)) {
1031 WL_ERROR(("wl%d: wlc_bmac_attach: bad macaddr %s\n", unit,
1032 macaddr));
1033 err = 22;
1034 goto fail;
1037 WL_ERROR(("%s:: deviceid 0x%x nbands %d board 0x%x macaddr: %s\n",
1038 __func__, wlc_hw->deviceid, wlc_hw->_nbands,
1039 wlc_hw->sih->boardtype, macaddr));
1041 return err;
1043 fail:
1044 WL_ERROR(("wl%d: wlc_bmac_attach: failed with err %d\n", unit, err));
1045 return err;
1049 * Initialize wlc_info default values ...
1050 * may get overrides later in this function
1051 * BMAC_NOTES, move low out and resolve the dangling ones
1053 void wlc_bmac_info_init(wlc_hw_info_t *wlc_hw)
1055 wlc_info_t *wlc = wlc_hw->wlc;
1057 /* set default sw macintmask value */
1058 wlc->defmacintmask = DEF_MACINTMASK;
1060 /* various 802.11g modes */
1061 wlc_hw->shortslot = false;
1063 wlc_hw->SFBL = RETRY_SHORT_FB;
1064 wlc_hw->LFBL = RETRY_LONG_FB;
1066 /* default mac retry limits */
1067 wlc_hw->SRL = RETRY_SHORT_DEF;
1068 wlc_hw->LRL = RETRY_LONG_DEF;
1069 wlc_hw->chanspec = CH20MHZ_CHSPEC(1);
1073 * low level detach
1075 int wlc_bmac_detach(wlc_info_t *wlc)
1077 uint i;
1078 wlc_hwband_t *band;
1079 wlc_hw_info_t *wlc_hw = wlc->hw;
1080 int callbacks;
1082 callbacks = 0;
1084 if (wlc_hw->sih) {
1085 /* detach interrupt sync mechanism since interrupt is disabled and per-port
1086 * interrupt object may has been freed. this must be done before sb core switch
1088 si_deregister_intr_callback(wlc_hw->sih);
1090 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS)
1091 si_pci_sleep(wlc_hw->sih);
1094 wlc_bmac_detach_dmapio(wlc_hw);
1096 band = wlc_hw->band;
1097 for (i = 0; i < NBANDS_HW(wlc_hw); i++) {
1098 if (band->pi) {
1099 /* Detach this band's phy */
1100 wlc_phy_detach(band->pi);
1101 band->pi = NULL;
1103 band = wlc_hw->bandstate[OTHERBANDUNIT(wlc)];
1106 /* Free shared phy state */
1107 wlc_phy_shared_detach(wlc_hw->phy_sh);
1109 wlc_phy_shim_detach(wlc_hw->physhim);
1111 /* free vars */
1112 if (wlc_hw->vars) {
1113 kfree(wlc_hw->vars);
1114 wlc_hw->vars = NULL;
1117 if (wlc_hw->sih) {
1118 si_detach(wlc_hw->sih);
1119 wlc_hw->sih = NULL;
1122 return callbacks;
1126 void wlc_bmac_reset(wlc_hw_info_t *wlc_hw)
1128 WL_TRACE(("wl%d: wlc_bmac_reset\n", wlc_hw->unit));
1130 WLCNTINCR(wlc_hw->wlc->pub->_cnt->reset);
1132 /* reset the core */
1133 if (!DEVICEREMOVED(wlc_hw->wlc))
1134 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
1136 /* purge the dma rings */
1137 wlc_flushqueues(wlc_hw->wlc);
1139 wlc_reset_bmac_done(wlc_hw->wlc);
1142 void
1143 wlc_bmac_init(wlc_hw_info_t *wlc_hw, chanspec_t chanspec,
1144 bool mute) {
1145 u32 macintmask;
1146 bool fastclk;
1147 wlc_info_t *wlc = wlc_hw->wlc;
1149 WL_TRACE(("wl%d: wlc_bmac_init\n", wlc_hw->unit));
1151 /* request FAST clock if not on */
1152 fastclk = wlc_hw->forcefastclk;
1153 if (!fastclk)
1154 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1156 /* disable interrupts */
1157 macintmask = wl_intrsoff(wlc->wl);
1159 /* set up the specified band and chanspec */
1160 wlc_setxband(wlc_hw, CHSPEC_WLCBANDUNIT(chanspec));
1161 wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
1163 /* do one-time phy inits and calibration */
1164 wlc_phy_cal_init(wlc_hw->band->pi);
1166 /* core-specific initialization */
1167 wlc_coreinit(wlc);
1169 /* suspend the tx fifos and mute the phy for preism cac time */
1170 if (mute)
1171 wlc_bmac_mute(wlc_hw, ON, PHY_MUTE_FOR_PREISM);
1173 /* band-specific inits */
1174 wlc_bmac_bsinit(wlc, chanspec);
1176 /* restore macintmask */
1177 wl_intrsrestore(wlc->wl, macintmask);
1179 /* seed wake_override with WLC_WAKE_OVERRIDE_MACSUSPEND since the mac is suspended
1180 * and wlc_enable_mac() will clear this override bit.
1182 mboolset(wlc_hw->wake_override, WLC_WAKE_OVERRIDE_MACSUSPEND);
1185 * initialize mac_suspend_depth to 1 to match ucode initial suspended state
1187 wlc_hw->mac_suspend_depth = 1;
1189 /* restore the clk */
1190 if (!fastclk)
1191 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1194 int wlc_bmac_up_prep(wlc_hw_info_t *wlc_hw)
1196 uint coremask;
1198 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__));
1200 ASSERT(wlc_hw->wlc->pub->hw_up && wlc_hw->wlc->macintmask == 0);
1203 * Enable pll and xtal, initialize the power control registers,
1204 * and force fastclock for the remainder of wlc_up().
1206 wlc_bmac_xtal(wlc_hw, ON);
1207 si_clkctl_init(wlc_hw->sih);
1208 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1211 * Configure pci/pcmcia here instead of in wlc_attach()
1212 * to allow mfg hotswap: down, hotswap (chip power cycle), up.
1214 coremask = (1 << wlc_hw->wlc->core->coreidx);
1216 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS)
1217 si_pci_setup(wlc_hw->sih, coremask);
1219 ASSERT(si_coreid(wlc_hw->sih) == D11_CORE_ID);
1222 * Need to read the hwradio status here to cover the case where the system
1223 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
1225 if (wlc_bmac_radio_read_hwdisabled(wlc_hw)) {
1226 /* put SB PCI in down state again */
1227 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS)
1228 si_pci_down(wlc_hw->sih);
1229 wlc_bmac_xtal(wlc_hw, OFF);
1230 return BCME_RADIOOFF;
1233 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS)
1234 si_pci_up(wlc_hw->sih);
1236 /* reset the d11 core */
1237 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
1239 return 0;
1242 int wlc_bmac_up_finish(wlc_hw_info_t *wlc_hw)
1244 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__));
1246 wlc_hw->up = true;
1247 wlc_phy_hw_state_upd(wlc_hw->band->pi, true);
1249 /* FULLY enable dynamic power control and d11 core interrupt */
1250 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1251 ASSERT(wlc_hw->wlc->macintmask == 0);
1252 wl_intrson(wlc_hw->wlc->wl);
1253 return 0;
1256 int wlc_bmac_down_prep(wlc_hw_info_t *wlc_hw)
1258 bool dev_gone;
1259 uint callbacks = 0;
1261 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__));
1263 if (!wlc_hw->up)
1264 return callbacks;
1266 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
1268 /* disable interrupts */
1269 if (dev_gone)
1270 wlc_hw->wlc->macintmask = 0;
1271 else {
1272 /* now disable interrupts */
1273 wl_intrsoff(wlc_hw->wlc->wl);
1275 /* ensure we're running on the pll clock again */
1276 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1278 /* down phy at the last of this stage */
1279 callbacks += wlc_phy_down(wlc_hw->band->pi);
1281 return callbacks;
1284 int wlc_bmac_down_finish(wlc_hw_info_t *wlc_hw)
1286 uint callbacks = 0;
1287 bool dev_gone;
1289 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__));
1291 if (!wlc_hw->up)
1292 return callbacks;
1294 wlc_hw->up = false;
1295 wlc_phy_hw_state_upd(wlc_hw->band->pi, false);
1297 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
1299 if (dev_gone) {
1300 wlc_hw->sbclk = false;
1301 wlc_hw->clk = false;
1302 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
1304 /* reclaim any posted packets */
1305 wlc_flushqueues(wlc_hw->wlc);
1306 } else {
1308 /* Reset and disable the core */
1309 if (si_iscoreup(wlc_hw->sih)) {
1310 if (R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol) &
1311 MCTL_EN_MAC)
1312 wlc_suspend_mac_and_wait(wlc_hw->wlc);
1313 callbacks += wl_reset(wlc_hw->wlc->wl);
1314 wlc_coredisable(wlc_hw);
1317 /* turn off primary xtal and pll */
1318 if (!wlc_hw->noreset) {
1319 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS)
1320 si_pci_down(wlc_hw->sih);
1321 wlc_bmac_xtal(wlc_hw, OFF);
1325 return callbacks;
1328 void wlc_bmac_wait_for_wake(wlc_hw_info_t *wlc_hw)
1330 if (D11REV_IS(wlc_hw->corerev, 4)) /* no slowclock */
1331 udelay(5);
1332 else {
1333 /* delay before first read of ucode state */
1334 udelay(40);
1336 /* wait until ucode is no longer asleep */
1337 SPINWAIT((wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) ==
1338 DBGST_ASLEEP), wlc_hw->wlc->fastpwrup_dly);
1341 ASSERT(wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) != DBGST_ASLEEP);
1344 void wlc_bmac_hw_etheraddr(wlc_hw_info_t *wlc_hw, struct ether_addr *ea)
1346 bcopy(&wlc_hw->etheraddr, ea, ETHER_ADDR_LEN);
1349 void wlc_bmac_set_hw_etheraddr(wlc_hw_info_t *wlc_hw, struct ether_addr *ea)
1351 bcopy(ea, &wlc_hw->etheraddr, ETHER_ADDR_LEN);
1354 int wlc_bmac_bandtype(wlc_hw_info_t *wlc_hw)
1356 return wlc_hw->band->bandtype;
1359 void *wlc_cur_phy(wlc_info_t *wlc)
1361 wlc_hw_info_t *wlc_hw = wlc->hw;
1362 return (void *)wlc_hw->band->pi;
1365 /* control chip clock to save power, enable dynamic clock or force fast clock */
1366 static void wlc_clkctl_clk(wlc_hw_info_t *wlc_hw, uint mode)
1368 if (PMUCTL_ENAB(wlc_hw->sih)) {
1369 /* new chips with PMU, CCS_FORCEHT will distribute the HT clock on backplane,
1370 * but mac core will still run on ALP(not HT) when it enters powersave mode,
1371 * which means the FCA bit may not be set.
1372 * should wakeup mac if driver wants it to run on HT.
1375 if (wlc_hw->clk) {
1376 if (mode == CLK_FAST) {
1377 OR_REG(wlc_hw->osh, &wlc_hw->regs->clk_ctl_st,
1378 CCS_FORCEHT);
1380 udelay(64);
1382 SPINWAIT(((R_REG
1383 (wlc_hw->osh,
1384 &wlc_hw->regs->
1385 clk_ctl_st) & CCS_HTAVAIL) == 0),
1386 PMU_MAX_TRANSITION_DLY);
1387 ASSERT(R_REG
1388 (wlc_hw->osh,
1389 &wlc_hw->regs->
1390 clk_ctl_st) & CCS_HTAVAIL);
1391 } else {
1392 if ((wlc_hw->sih->pmurev == 0) &&
1393 (R_REG
1394 (wlc_hw->osh,
1395 &wlc_hw->regs->
1396 clk_ctl_st) & (CCS_FORCEHT | CCS_HTAREQ)))
1397 SPINWAIT(((R_REG
1398 (wlc_hw->osh,
1399 &wlc_hw->regs->
1400 clk_ctl_st) & CCS_HTAVAIL)
1401 == 0),
1402 PMU_MAX_TRANSITION_DLY);
1403 AND_REG(wlc_hw->osh, &wlc_hw->regs->clk_ctl_st,
1404 ~CCS_FORCEHT);
1407 wlc_hw->forcefastclk = (mode == CLK_FAST);
1408 } else {
1409 bool wakeup_ucode;
1411 /* old chips w/o PMU, force HT through cc,
1412 * then use FCA to verify mac is running fast clock
1415 wakeup_ucode = D11REV_LT(wlc_hw->corerev, 9);
1417 if (wlc_hw->up && wakeup_ucode)
1418 wlc_ucode_wake_override_set(wlc_hw,
1419 WLC_WAKE_OVERRIDE_CLKCTL);
1421 wlc_hw->forcefastclk = si_clkctl_cc(wlc_hw->sih, mode);
1423 if (D11REV_LT(wlc_hw->corerev, 11)) {
1424 /* ucode WAR for old chips */
1425 if (wlc_hw->forcefastclk)
1426 wlc_bmac_mhf(wlc_hw, MHF1, MHF1_FORCEFASTCLK,
1427 MHF1_FORCEFASTCLK, WLC_BAND_ALL);
1428 else
1429 wlc_bmac_mhf(wlc_hw, MHF1, MHF1_FORCEFASTCLK, 0,
1430 WLC_BAND_ALL);
1433 /* check fast clock is available (if core is not in reset) */
1434 if (D11REV_GT(wlc_hw->corerev, 4) && wlc_hw->forcefastclk
1435 && wlc_hw->clk)
1436 ASSERT(si_core_sflags(wlc_hw->sih, 0, 0) & SISF_FCLKA);
1438 /* keep the ucode wake bit on if forcefastclk is on
1439 * since we do not want ucode to put us back to slow clock
1440 * when it dozes for PM mode.
1441 * Code below matches the wake override bit with current forcefastclk state
1442 * Only setting bit in wake_override instead of waking ucode immediately
1443 * since old code (wlc.c 1.4499) had this behavior. Older code set
1444 * wlc->forcefastclk but only had the wake happen if the wakup_ucode work
1445 * (protected by an up check) was executed just below.
1447 if (wlc_hw->forcefastclk)
1448 mboolset(wlc_hw->wake_override,
1449 WLC_WAKE_OVERRIDE_FORCEFAST);
1450 else
1451 mboolclr(wlc_hw->wake_override,
1452 WLC_WAKE_OVERRIDE_FORCEFAST);
1454 /* ok to clear the wakeup now */
1455 if (wlc_hw->up && wakeup_ucode)
1456 wlc_ucode_wake_override_clear(wlc_hw,
1457 WLC_WAKE_OVERRIDE_CLKCTL);
1461 /* set initial host flags value */
1462 static void
1463 wlc_mhfdef(wlc_info_t *wlc, u16 *mhfs, u16 mhf2_init)
1465 wlc_hw_info_t *wlc_hw = wlc->hw;
1467 bzero(mhfs, sizeof(u16) * MHFMAX);
1469 mhfs[MHF2] |= mhf2_init;
1471 /* prohibit use of slowclock on multifunction boards */
1472 if (wlc_hw->boardflags & BFL_NOPLLDOWN)
1473 mhfs[MHF1] |= MHF1_FORCEFASTCLK;
1475 if (WLCISNPHY(wlc_hw->band) && NREV_LT(wlc_hw->band->phyrev, 2)) {
1476 mhfs[MHF2] |= MHF2_NPHY40MHZ_WAR;
1477 mhfs[MHF1] |= MHF1_IQSWAP_WAR;
1481 /* set or clear ucode host flag bits
1482 * it has an optimization for no-change write
1483 * it only writes through shared memory when the core has clock;
1484 * pre-CLK changes should use wlc_write_mhf to get around the optimization
1487 * bands values are: WLC_BAND_AUTO <--- Current band only
1488 * WLC_BAND_5G <--- 5G band only
1489 * WLC_BAND_2G <--- 2G band only
1490 * WLC_BAND_ALL <--- All bands
1492 void
1493 wlc_bmac_mhf(wlc_hw_info_t *wlc_hw, u8 idx, u16 mask, u16 val,
1494 int bands)
1496 u16 save;
1497 u16 addr[MHFMAX] = {
1498 M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
1499 M_HOST_FLAGS5
1501 wlc_hwband_t *band;
1503 ASSERT((val & ~mask) == 0);
1504 ASSERT(idx < MHFMAX);
1505 ASSERT(ARRAY_SIZE(addr) == MHFMAX);
1507 switch (bands) {
1508 /* Current band only or all bands,
1509 * then set the band to current band
1511 case WLC_BAND_AUTO:
1512 case WLC_BAND_ALL:
1513 band = wlc_hw->band;
1514 break;
1515 case WLC_BAND_5G:
1516 band = wlc_hw->bandstate[BAND_5G_INDEX];
1517 break;
1518 case WLC_BAND_2G:
1519 band = wlc_hw->bandstate[BAND_2G_INDEX];
1520 break;
1521 default:
1522 ASSERT(0);
1523 band = NULL;
1526 if (band) {
1527 save = band->mhfs[idx];
1528 band->mhfs[idx] = (band->mhfs[idx] & ~mask) | val;
1530 /* optimization: only write through if changed, and
1531 * changed band is the current band
1533 if (wlc_hw->clk && (band->mhfs[idx] != save)
1534 && (band == wlc_hw->band))
1535 wlc_bmac_write_shm(wlc_hw, addr[idx],
1536 (u16) band->mhfs[idx]);
1539 if (bands == WLC_BAND_ALL) {
1540 wlc_hw->bandstate[0]->mhfs[idx] =
1541 (wlc_hw->bandstate[0]->mhfs[idx] & ~mask) | val;
1542 wlc_hw->bandstate[1]->mhfs[idx] =
1543 (wlc_hw->bandstate[1]->mhfs[idx] & ~mask) | val;
1547 u16 wlc_bmac_mhf_get(wlc_hw_info_t *wlc_hw, u8 idx, int bands)
1549 wlc_hwband_t *band;
1550 ASSERT(idx < MHFMAX);
1552 switch (bands) {
1553 case WLC_BAND_AUTO:
1554 band = wlc_hw->band;
1555 break;
1556 case WLC_BAND_5G:
1557 band = wlc_hw->bandstate[BAND_5G_INDEX];
1558 break;
1559 case WLC_BAND_2G:
1560 band = wlc_hw->bandstate[BAND_2G_INDEX];
1561 break;
1562 default:
1563 ASSERT(0);
1564 band = NULL;
1567 if (!band)
1568 return 0;
1570 return band->mhfs[idx];
1573 static void wlc_write_mhf(wlc_hw_info_t *wlc_hw, u16 *mhfs)
1575 u8 idx;
1576 u16 addr[] = {
1577 M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
1578 M_HOST_FLAGS5
1581 ASSERT(ARRAY_SIZE(addr) == MHFMAX);
1583 for (idx = 0; idx < MHFMAX; idx++) {
1584 wlc_bmac_write_shm(wlc_hw, addr[idx], mhfs[idx]);
1588 /* set the maccontrol register to desired reset state and
1589 * initialize the sw cache of the register
1591 static void wlc_mctrl_reset(wlc_hw_info_t *wlc_hw)
1593 /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
1594 wlc_hw->maccontrol = 0;
1595 wlc_hw->suspended_fifos = 0;
1596 wlc_hw->wake_override = 0;
1597 wlc_hw->mute_override = 0;
1598 wlc_bmac_mctrl(wlc_hw, ~0, MCTL_IHR_EN | MCTL_WAKE);
1601 /* set or clear maccontrol bits */
1602 void wlc_bmac_mctrl(wlc_hw_info_t *wlc_hw, u32 mask, u32 val)
1604 u32 maccontrol;
1605 u32 new_maccontrol;
1607 ASSERT((val & ~mask) == 0);
1609 maccontrol = wlc_hw->maccontrol;
1610 new_maccontrol = (maccontrol & ~mask) | val;
1612 /* if the new maccontrol value is the same as the old, nothing to do */
1613 if (new_maccontrol == maccontrol)
1614 return;
1616 /* something changed, cache the new value */
1617 wlc_hw->maccontrol = new_maccontrol;
1619 /* write the new values with overrides applied */
1620 wlc_mctrl_write(wlc_hw);
1623 /* write the software state of maccontrol and overrides to the maccontrol register */
1624 static void wlc_mctrl_write(wlc_hw_info_t *wlc_hw)
1626 u32 maccontrol = wlc_hw->maccontrol;
1628 /* OR in the wake bit if overridden */
1629 if (wlc_hw->wake_override)
1630 maccontrol |= MCTL_WAKE;
1632 /* set AP and INFRA bits for mute if needed */
1633 if (wlc_hw->mute_override) {
1634 maccontrol &= ~(MCTL_AP);
1635 maccontrol |= MCTL_INFRA;
1638 W_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol, maccontrol);
1641 void wlc_ucode_wake_override_set(wlc_hw_info_t *wlc_hw, u32 override_bit)
1643 ASSERT((wlc_hw->wake_override & override_bit) == 0);
1645 if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) {
1646 mboolset(wlc_hw->wake_override, override_bit);
1647 return;
1650 mboolset(wlc_hw->wake_override, override_bit);
1652 wlc_mctrl_write(wlc_hw);
1653 wlc_bmac_wait_for_wake(wlc_hw);
1655 return;
1658 void wlc_ucode_wake_override_clear(wlc_hw_info_t *wlc_hw, u32 override_bit)
1660 ASSERT(wlc_hw->wake_override & override_bit);
1662 mboolclr(wlc_hw->wake_override, override_bit);
1664 if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE))
1665 return;
1667 wlc_mctrl_write(wlc_hw);
1669 return;
1672 /* When driver needs ucode to stop beaconing, it has to make sure that
1673 * MCTL_AP is clear and MCTL_INFRA is set
1674 * Mode MCTL_AP MCTL_INFRA
1675 * AP 1 1
1676 * STA 0 1 <--- This will ensure no beacons
1677 * IBSS 0 0
1679 static void wlc_ucode_mute_override_set(wlc_hw_info_t *wlc_hw)
1681 wlc_hw->mute_override = 1;
1683 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1684 * override, then there is no change to write
1686 if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
1687 return;
1689 wlc_mctrl_write(wlc_hw);
1691 return;
1694 /* Clear the override on AP and INFRA bits */
1695 static void wlc_ucode_mute_override_clear(wlc_hw_info_t *wlc_hw)
1697 if (wlc_hw->mute_override == 0)
1698 return;
1700 wlc_hw->mute_override = 0;
1702 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1703 * override, then there is no change to write
1705 if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
1706 return;
1708 wlc_mctrl_write(wlc_hw);
1712 * Write a MAC address to the rcmta structure
1714 void
1715 wlc_bmac_set_rcmta(wlc_hw_info_t *wlc_hw, int idx,
1716 const struct ether_addr *addr)
1718 d11regs_t *regs = wlc_hw->regs;
1719 volatile u16 *objdata16 = (volatile u16 *)&regs->objdata;
1720 u32 mac_hm;
1721 u16 mac_l;
1722 osl_t *osh;
1724 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__));
1726 ASSERT(wlc_hw->corerev > 4);
1728 mac_hm =
1729 (addr->octet[3] << 24) | (addr->octet[2] << 16) | (addr->
1730 octet[1] << 8) |
1731 addr->octet[0];
1732 mac_l = (addr->octet[5] << 8) | addr->octet[4];
1734 osh = wlc_hw->osh;
1736 W_REG(osh, &regs->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2)));
1737 (void)R_REG(osh, &regs->objaddr);
1738 W_REG(osh, &regs->objdata, mac_hm);
1739 W_REG(osh, &regs->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1)));
1740 (void)R_REG(osh, &regs->objaddr);
1741 W_REG(osh, objdata16, mac_l);
1745 * Write a MAC address to the given match reg offset in the RXE match engine.
1747 void
1748 wlc_bmac_set_addrmatch(wlc_hw_info_t *wlc_hw, int match_reg_offset,
1749 const struct ether_addr *addr)
1751 d11regs_t *regs;
1752 u16 mac_l;
1753 u16 mac_m;
1754 u16 mac_h;
1755 osl_t *osh;
1757 WL_TRACE(("wl%d: wlc_bmac_set_addrmatch\n", wlc_hw->unit));
1759 ASSERT((match_reg_offset < RCM_SIZE) || (wlc_hw->corerev == 4));
1761 regs = wlc_hw->regs;
1762 mac_l = addr->octet[0] | (addr->octet[1] << 8);
1763 mac_m = addr->octet[2] | (addr->octet[3] << 8);
1764 mac_h = addr->octet[4] | (addr->octet[5] << 8);
1766 osh = wlc_hw->osh;
1768 /* enter the MAC addr into the RXE match registers */
1769 W_REG(osh, &regs->rcm_ctl, RCM_INC_DATA | match_reg_offset);
1770 W_REG(osh, &regs->rcm_mat_data, mac_l);
1771 W_REG(osh, &regs->rcm_mat_data, mac_m);
1772 W_REG(osh, &regs->rcm_mat_data, mac_h);
1776 void
1777 wlc_bmac_write_template_ram(wlc_hw_info_t *wlc_hw, int offset, int len,
1778 void *buf)
1780 d11regs_t *regs;
1781 u32 word;
1782 bool be_bit;
1783 #ifdef IL_BIGENDIAN
1784 volatile u16 *dptr = NULL;
1785 #endif /* IL_BIGENDIAN */
1786 osl_t *osh;
1788 WL_TRACE(("wl%d: wlc_bmac_write_template_ram\n", wlc_hw->unit));
1790 regs = wlc_hw->regs;
1791 osh = wlc_hw->osh;
1793 ASSERT(IS_ALIGNED(offset, sizeof(u32)));
1794 ASSERT(IS_ALIGNED(len, sizeof(u32)));
1795 ASSERT((offset & ~0xffff) == 0);
1797 W_REG(osh, &regs->tplatewrptr, offset);
1799 /* if MCTL_BIGEND bit set in mac control register,
1800 * the chip swaps data in fifo, as well as data in
1801 * template ram
1803 be_bit = (R_REG(osh, &regs->maccontrol) & MCTL_BIGEND) != 0;
1805 while (len > 0) {
1806 bcopy((u8 *) buf, &word, sizeof(u32));
1808 if (be_bit)
1809 word = hton32(word);
1810 else
1811 word = htol32(word);
1813 W_REG(osh, &regs->tplatewrdata, word);
1815 buf = (u8 *) buf + sizeof(u32);
1816 len -= sizeof(u32);
1820 void wlc_bmac_set_cwmin(wlc_hw_info_t *wlc_hw, u16 newmin)
1822 osl_t *osh;
1824 osh = wlc_hw->osh;
1825 wlc_hw->band->CWmin = newmin;
1827 W_REG(osh, &wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMIN);
1828 (void)R_REG(osh, &wlc_hw->regs->objaddr);
1829 W_REG(osh, &wlc_hw->regs->objdata, newmin);
1832 void wlc_bmac_set_cwmax(wlc_hw_info_t *wlc_hw, u16 newmax)
1834 osl_t *osh;
1836 osh = wlc_hw->osh;
1837 wlc_hw->band->CWmax = newmax;
1839 W_REG(osh, &wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMAX);
1840 (void)R_REG(osh, &wlc_hw->regs->objaddr);
1841 W_REG(osh, &wlc_hw->regs->objdata, newmax);
1844 void wlc_bmac_bw_set(wlc_hw_info_t *wlc_hw, u16 bw)
1846 bool fastclk;
1847 u32 tmp;
1849 /* request FAST clock if not on */
1850 fastclk = wlc_hw->forcefastclk;
1851 if (!fastclk)
1852 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1854 wlc_phy_bw_state_set(wlc_hw->band->pi, bw);
1856 ASSERT(wlc_hw->clk);
1857 if (D11REV_LT(wlc_hw->corerev, 17))
1858 tmp = R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol);
1860 wlc_bmac_phy_reset(wlc_hw);
1861 wlc_phy_init(wlc_hw->band->pi, wlc_phy_chanspec_get(wlc_hw->band->pi));
1863 /* restore the clk */
1864 if (!fastclk)
1865 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1868 static void
1869 wlc_write_hw_bcntemplate0(wlc_hw_info_t *wlc_hw, void *bcn, int len)
1871 d11regs_t *regs = wlc_hw->regs;
1873 wlc_bmac_write_template_ram(wlc_hw, T_BCN0_TPL_BASE, (len + 3) & ~3,
1874 bcn);
1875 /* write beacon length to SCR */
1876 ASSERT(len < 65536);
1877 wlc_bmac_write_shm(wlc_hw, M_BCN0_FRM_BYTESZ, (u16) len);
1878 /* mark beacon0 valid */
1879 OR_REG(wlc_hw->osh, &regs->maccommand, MCMD_BCN0VLD);
1882 static void
1883 wlc_write_hw_bcntemplate1(wlc_hw_info_t *wlc_hw, void *bcn, int len)
1885 d11regs_t *regs = wlc_hw->regs;
1887 wlc_bmac_write_template_ram(wlc_hw, T_BCN1_TPL_BASE, (len + 3) & ~3,
1888 bcn);
1889 /* write beacon length to SCR */
1890 ASSERT(len < 65536);
1891 wlc_bmac_write_shm(wlc_hw, M_BCN1_FRM_BYTESZ, (u16) len);
1892 /* mark beacon1 valid */
1893 OR_REG(wlc_hw->osh, &regs->maccommand, MCMD_BCN1VLD);
1896 /* mac is assumed to be suspended at this point */
1897 void
1898 wlc_bmac_write_hw_bcntemplates(wlc_hw_info_t *wlc_hw, void *bcn, int len,
1899 bool both)
1901 d11regs_t *regs = wlc_hw->regs;
1903 if (both) {
1904 wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
1905 wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
1906 } else {
1907 /* bcn 0 */
1908 if (!(R_REG(wlc_hw->osh, &regs->maccommand) & MCMD_BCN0VLD))
1909 wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
1910 /* bcn 1 */
1911 else if (!
1912 (R_REG(wlc_hw->osh, &regs->maccommand) & MCMD_BCN1VLD))
1913 wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
1914 else /* one template should always have been available */
1915 ASSERT(0);
1919 static void WLBANDINITFN(wlc_bmac_upd_synthpu) (wlc_hw_info_t *wlc_hw)
1921 u16 v;
1922 wlc_info_t *wlc = wlc_hw->wlc;
1923 /* update SYNTHPU_DLY */
1925 if (WLCISLCNPHY(wlc->band)) {
1926 v = SYNTHPU_DLY_LPPHY_US;
1927 } else if (WLCISNPHY(wlc->band) && (NREV_GE(wlc->band->phyrev, 3))) {
1928 v = SYNTHPU_DLY_NPHY_US;
1929 } else {
1930 v = SYNTHPU_DLY_BPHY_US;
1933 wlc_bmac_write_shm(wlc_hw, M_SYNTHPU_DLY, v);
1936 /* band-specific init */
1937 static void
1938 WLBANDINITFN(wlc_bmac_bsinit) (wlc_info_t *wlc, chanspec_t chanspec)
1940 wlc_hw_info_t *wlc_hw = wlc->hw;
1942 WL_TRACE(("wl%d: wlc_bmac_bsinit: bandunit %d\n", wlc_hw->unit,
1943 wlc_hw->band->bandunit));
1945 /* sanity check */
1946 if (PHY_TYPE(R_REG(wlc_hw->osh, &wlc_hw->regs->phyversion)) !=
1947 PHY_TYPE_LCNXN)
1948 ASSERT((uint)
1949 PHY_TYPE(R_REG(wlc_hw->osh, &wlc_hw->regs->phyversion))
1950 == wlc_hw->band->phytype);
1952 wlc_ucode_bsinit(wlc_hw);
1954 wlc_phy_init(wlc_hw->band->pi, chanspec);
1956 wlc_ucode_txant_set(wlc_hw);
1958 /* cwmin is band-specific, update hardware with value for current band */
1959 wlc_bmac_set_cwmin(wlc_hw, wlc_hw->band->CWmin);
1960 wlc_bmac_set_cwmax(wlc_hw, wlc_hw->band->CWmax);
1962 wlc_bmac_update_slot_timing(wlc_hw,
1963 BAND_5G(wlc_hw->band->
1964 bandtype) ? true : wlc_hw->
1965 shortslot);
1967 /* write phytype and phyvers */
1968 wlc_bmac_write_shm(wlc_hw, M_PHYTYPE, (u16) wlc_hw->band->phytype);
1969 wlc_bmac_write_shm(wlc_hw, M_PHYVER, (u16) wlc_hw->band->phyrev);
1971 /* initialize the txphyctl1 rate table since shmem is shared between bands */
1972 wlc_upd_ofdm_pctl1_table(wlc_hw);
1974 wlc_bmac_upd_synthpu(wlc_hw);
1977 void wlc_bmac_core_phy_clk(wlc_hw_info_t *wlc_hw, bool clk)
1979 WL_TRACE(("wl%d: wlc_bmac_core_phy_clk: clk %d\n", wlc_hw->unit, clk));
1981 wlc_hw->phyclk = clk;
1983 if (OFF == clk) { /* clear gmode bit, put phy into reset */
1985 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC | SICF_GMODE),
1986 (SICF_PRST | SICF_FGC));
1987 udelay(1);
1988 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_PRST);
1989 udelay(1);
1991 } else { /* take phy out of reset */
1993 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_FGC);
1994 udelay(1);
1995 si_core_cflags(wlc_hw->sih, (SICF_FGC), 0);
1996 udelay(1);
2001 /* Perform a soft reset of the PHY PLL */
2002 void wlc_bmac_core_phypll_reset(wlc_hw_info_t *wlc_hw)
2004 WL_TRACE(("wl%d: wlc_bmac_core_phypll_reset\n", wlc_hw->unit));
2006 si_corereg(wlc_hw->sih, SI_CC_IDX,
2007 offsetof(chipcregs_t, chipcontrol_addr), ~0, 0);
2008 udelay(1);
2009 si_corereg(wlc_hw->sih, SI_CC_IDX,
2010 offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
2011 udelay(1);
2012 si_corereg(wlc_hw->sih, SI_CC_IDX,
2013 offsetof(chipcregs_t, chipcontrol_data), 0x4, 4);
2014 udelay(1);
2015 si_corereg(wlc_hw->sih, SI_CC_IDX,
2016 offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
2017 udelay(1);
2020 /* light way to turn on phy clock without reset for NPHY only
2021 * refer to wlc_bmac_core_phy_clk for full version
2023 void wlc_bmac_phyclk_fgc(wlc_hw_info_t *wlc_hw, bool clk)
2025 /* support(necessary for NPHY and HYPHY) only */
2026 if (!WLCISNPHY(wlc_hw->band))
2027 return;
2029 if (ON == clk)
2030 si_core_cflags(wlc_hw->sih, SICF_FGC, SICF_FGC);
2031 else
2032 si_core_cflags(wlc_hw->sih, SICF_FGC, 0);
2036 void wlc_bmac_macphyclk_set(wlc_hw_info_t *wlc_hw, bool clk)
2038 if (ON == clk)
2039 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE);
2040 else
2041 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0);
2044 void wlc_bmac_phy_reset(wlc_hw_info_t *wlc_hw)
2046 wlc_phy_t *pih = wlc_hw->band->pi;
2047 u32 phy_bw_clkbits;
2048 bool phy_in_reset = false;
2050 WL_TRACE(("wl%d: wlc_bmac_phy_reset\n", wlc_hw->unit));
2052 if (pih == NULL)
2053 return;
2055 phy_bw_clkbits = wlc_phy_clk_bwbits(wlc_hw->band->pi);
2057 /* Specfic reset sequence required for NPHY rev 3 and 4 */
2058 if (WLCISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) &&
2059 NREV_LE(wlc_hw->band->phyrev, 4)) {
2060 /* Set the PHY bandwidth */
2061 si_core_cflags(wlc_hw->sih, SICF_BWMASK, phy_bw_clkbits);
2063 udelay(1);
2065 /* Perform a soft reset of the PHY PLL */
2066 wlc_bmac_core_phypll_reset(wlc_hw);
2068 /* reset the PHY */
2069 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_PCLKE),
2070 (SICF_PRST | SICF_PCLKE));
2071 phy_in_reset = true;
2072 } else {
2074 si_core_cflags(wlc_hw->sih,
2075 (SICF_PRST | SICF_PCLKE | SICF_BWMASK),
2076 (SICF_PRST | SICF_PCLKE | phy_bw_clkbits));
2079 udelay(2);
2080 wlc_bmac_core_phy_clk(wlc_hw, ON);
2082 if (pih)
2083 wlc_phy_anacore(pih, ON);
2086 /* switch to and initialize new band */
2087 static void
2088 WLBANDINITFN(wlc_bmac_setband) (wlc_hw_info_t *wlc_hw, uint bandunit,
2089 chanspec_t chanspec) {
2090 wlc_info_t *wlc = wlc_hw->wlc;
2091 u32 macintmask;
2093 ASSERT(NBANDS_HW(wlc_hw) > 1);
2094 ASSERT(bandunit != wlc_hw->band->bandunit);
2096 /* Enable the d11 core before accessing it */
2097 if (!si_iscoreup(wlc_hw->sih)) {
2098 si_core_reset(wlc_hw->sih, 0, 0);
2099 ASSERT(si_iscoreup(wlc_hw->sih));
2100 wlc_mctrl_reset(wlc_hw);
2103 macintmask = wlc_setband_inact(wlc, bandunit);
2105 if (!wlc_hw->up)
2106 return;
2108 wlc_bmac_core_phy_clk(wlc_hw, ON);
2110 /* band-specific initializations */
2111 wlc_bmac_bsinit(wlc, chanspec);
2114 * If there are any pending software interrupt bits,
2115 * then replace these with a harmless nonzero value
2116 * so wlc_dpc() will re-enable interrupts when done.
2118 if (wlc->macintstatus)
2119 wlc->macintstatus = MI_DMAINT;
2121 /* restore macintmask */
2122 wl_intrsrestore(wlc->wl, macintmask);
2124 /* ucode should still be suspended.. */
2125 ASSERT((R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol) & MCTL_EN_MAC) ==
2129 /* low-level band switch utility routine */
2130 void WLBANDINITFN(wlc_setxband) (wlc_hw_info_t *wlc_hw, uint bandunit)
2132 WL_TRACE(("wl%d: wlc_setxband: bandunit %d\n", wlc_hw->unit, bandunit));
2134 wlc_hw->band = wlc_hw->bandstate[bandunit];
2136 /* BMAC_NOTE: until we eliminate need for wlc->band refs in low level code */
2137 wlc_hw->wlc->band = wlc_hw->wlc->bandstate[bandunit];
2139 /* set gmode core flag */
2140 if (wlc_hw->sbclk && !wlc_hw->noreset) {
2141 si_core_cflags(wlc_hw->sih, SICF_GMODE,
2142 ((bandunit == 0) ? SICF_GMODE : 0));
2146 static bool wlc_isgoodchip(wlc_hw_info_t *wlc_hw)
2149 /* reject unsupported corerev */
2150 if (!VALID_COREREV(wlc_hw->corerev)) {
2151 WL_ERROR(("unsupported core rev %d\n", wlc_hw->corerev));
2152 return false;
2155 return true;
2158 static bool wlc_validboardtype(wlc_hw_info_t *wlc_hw)
2160 bool goodboard = true;
2161 uint boardrev = wlc_hw->boardrev;
2163 if (boardrev == 0)
2164 goodboard = false;
2165 else if (boardrev > 0xff) {
2166 uint brt = (boardrev & 0xf000) >> 12;
2167 uint b0 = (boardrev & 0xf00) >> 8;
2168 uint b1 = (boardrev & 0xf0) >> 4;
2169 uint b2 = boardrev & 0xf;
2171 if ((brt > 2) || (brt == 0) || (b0 > 9) || (b0 == 0) || (b1 > 9)
2172 || (b2 > 9))
2173 goodboard = false;
2176 if (wlc_hw->sih->boardvendor != VENDOR_BROADCOM)
2177 return goodboard;
2179 return goodboard;
2182 static char *wlc_get_macaddr(wlc_hw_info_t *wlc_hw)
2184 const char *varname = "macaddr";
2185 char *macaddr;
2187 /* If macaddr exists, use it (Sromrev4, CIS, ...). */
2188 macaddr = getvar(wlc_hw->vars, varname);
2189 if (macaddr != NULL)
2190 return macaddr;
2192 if (NBANDS_HW(wlc_hw) > 1)
2193 varname = "et1macaddr";
2194 else
2195 varname = "il0macaddr";
2197 macaddr = getvar(wlc_hw->vars, varname);
2198 if (macaddr == NULL) {
2199 WL_ERROR(("wl%d: wlc_get_macaddr: macaddr getvar(%s) not found\n", wlc_hw->unit, varname));
2202 return macaddr;
2206 * Return true if radio is disabled, otherwise false.
2207 * hw radio disable signal is an external pin, users activate it asynchronously
2208 * this function could be called when driver is down and w/o clock
2209 * it operates on different registers depending on corerev and boardflag.
2211 bool wlc_bmac_radio_read_hwdisabled(wlc_hw_info_t *wlc_hw)
2213 bool v, clk, xtal;
2214 u32 resetbits = 0, flags = 0;
2216 xtal = wlc_hw->sbclk;
2217 if (!xtal)
2218 wlc_bmac_xtal(wlc_hw, ON);
2220 /* may need to take core out of reset first */
2221 clk = wlc_hw->clk;
2222 if (!clk) {
2223 if (D11REV_LE(wlc_hw->corerev, 11))
2224 resetbits |= SICF_PCLKE;
2227 * corerev >= 18, mac no longer enables phyclk automatically when driver accesses
2228 * phyreg throughput mac. This can be skipped since only mac reg is accessed below
2230 if (D11REV_GE(wlc_hw->corerev, 18))
2231 flags |= SICF_PCLKE;
2233 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2234 if ((CHIPID(wlc_hw->sih->chip) == BCM43224_CHIP_ID) ||
2235 (CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID) ||
2236 (CHIPID(wlc_hw->sih->chip) == BCM43421_CHIP_ID))
2237 wlc_hw->regs =
2238 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID,
2240 si_core_reset(wlc_hw->sih, flags, resetbits);
2241 wlc_mctrl_reset(wlc_hw);
2244 v = ((R_REG(wlc_hw->osh, &wlc_hw->regs->phydebug) & PDBG_RFD) != 0);
2246 /* put core back into reset */
2247 if (!clk)
2248 si_core_disable(wlc_hw->sih, 0);
2250 if (!xtal)
2251 wlc_bmac_xtal(wlc_hw, OFF);
2253 return v;
2256 /* Initialize just the hardware when coming out of POR or S3/S5 system states */
2257 void wlc_bmac_hw_up(wlc_hw_info_t *wlc_hw)
2259 if (wlc_hw->wlc->pub->hw_up)
2260 return;
2262 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__));
2265 * Enable pll and xtal, initialize the power control registers,
2266 * and force fastclock for the remainder of wlc_up().
2268 wlc_bmac_xtal(wlc_hw, ON);
2269 si_clkctl_init(wlc_hw->sih);
2270 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2272 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) {
2273 si_pci_fixcfg(wlc_hw->sih);
2275 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2276 if ((CHIPID(wlc_hw->sih->chip) == BCM43224_CHIP_ID) ||
2277 (CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID) ||
2278 (CHIPID(wlc_hw->sih->chip) == BCM43421_CHIP_ID))
2279 wlc_hw->regs =
2280 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID,
2284 /* Inform phy that a POR reset has occurred so it does a complete phy init */
2285 wlc_phy_por_inform(wlc_hw->band->pi);
2287 wlc_hw->ucode_loaded = false;
2288 wlc_hw->wlc->pub->hw_up = true;
2290 if ((wlc_hw->boardflags & BFL_FEM)
2291 && (CHIPID(wlc_hw->sih->chip) == BCM4313_CHIP_ID)) {
2292 if (!
2293 (wlc_hw->boardrev >= 0x1250
2294 && (wlc_hw->boardflags & BFL_FEM_BT)))
2295 si_epa_4313war(wlc_hw->sih);
2299 static bool wlc_dma_rxreset(wlc_hw_info_t *wlc_hw, uint fifo)
2301 hnddma_t *di = wlc_hw->di[fifo];
2302 osl_t *osh;
2304 if (D11REV_LT(wlc_hw->corerev, 12)) {
2305 bool rxidle = true;
2306 u16 rcv_frm_cnt = 0;
2308 osh = wlc_hw->osh;
2310 W_REG(osh, &wlc_hw->regs->rcv_fifo_ctl, fifo << 8);
2311 SPINWAIT((!(rxidle = dma_rxidle(di))) &&
2312 ((rcv_frm_cnt =
2313 R_REG(osh, &wlc_hw->regs->rcv_frm_cnt)) != 0),
2314 50000);
2316 if (!rxidle && (rcv_frm_cnt != 0))
2317 WL_ERROR(("wl%d: %s: rxdma[%d] not idle && rcv_frm_cnt(%d) not zero\n", wlc_hw->unit, __func__, fifo, rcv_frm_cnt));
2318 mdelay(2);
2321 return dma_rxreset(di);
2324 /* d11 core reset
2325 * ensure fask clock during reset
2326 * reset dma
2327 * reset d11(out of reset)
2328 * reset phy(out of reset)
2329 * clear software macintstatus for fresh new start
2330 * one testing hack wlc_hw->noreset will bypass the d11/phy reset
2332 void wlc_bmac_corereset(wlc_hw_info_t *wlc_hw, u32 flags)
2334 d11regs_t *regs;
2335 uint i;
2336 bool fastclk;
2337 u32 resetbits = 0;
2339 if (flags == WLC_USE_COREFLAGS)
2340 flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0);
2342 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__));
2344 regs = wlc_hw->regs;
2346 /* request FAST clock if not on */
2347 fastclk = wlc_hw->forcefastclk;
2348 if (!fastclk)
2349 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2351 /* reset the dma engines except first time thru */
2352 if (si_iscoreup(wlc_hw->sih)) {
2353 for (i = 0; i < NFIFO; i++)
2354 if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) {
2355 WL_ERROR(("wl%d: %s: dma_txreset[%d]: cannot stop dma\n", wlc_hw->unit, __func__, i));
2358 if ((wlc_hw->di[RX_FIFO])
2359 && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) {
2360 WL_ERROR(("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n", wlc_hw->unit, __func__, RX_FIFO));
2362 if (D11REV_IS(wlc_hw->corerev, 4)
2363 && wlc_hw->di[RX_TXSTATUS_FIFO]
2364 && (!wlc_dma_rxreset(wlc_hw, RX_TXSTATUS_FIFO))) {
2365 WL_ERROR(("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n", wlc_hw->unit, __func__, RX_TXSTATUS_FIFO));
2368 /* if noreset, just stop the psm and return */
2369 if (wlc_hw->noreset) {
2370 wlc_hw->wlc->macintstatus = 0; /* skip wl_dpc after down */
2371 wlc_bmac_mctrl(wlc_hw, MCTL_PSM_RUN | MCTL_EN_MAC, 0);
2372 return;
2375 if (D11REV_LE(wlc_hw->corerev, 11))
2376 resetbits |= SICF_PCLKE;
2379 * corerev >= 18, mac no longer enables phyclk automatically when driver accesses phyreg
2380 * throughput mac, AND phy_reset is skipped at early stage when band->pi is invalid
2381 * need to enable PHY CLK
2383 if (D11REV_GE(wlc_hw->corerev, 18))
2384 flags |= SICF_PCLKE;
2386 /* reset the core
2387 * In chips with PMU, the fastclk request goes through d11 core reg 0x1e0, which
2388 * is cleared by the core_reset. have to re-request it.
2389 * This adds some delay and we can optimize it by also requesting fastclk through
2390 * chipcommon during this period if necessary. But that has to work coordinate
2391 * with other driver like mips/arm since they may touch chipcommon as well.
2393 wlc_hw->clk = false;
2394 si_core_reset(wlc_hw->sih, flags, resetbits);
2395 wlc_hw->clk = true;
2396 if (wlc_hw->band && wlc_hw->band->pi)
2397 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true);
2399 wlc_mctrl_reset(wlc_hw);
2401 if (PMUCTL_ENAB(wlc_hw->sih))
2402 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2404 wlc_bmac_phy_reset(wlc_hw);
2406 /* turn on PHY_PLL */
2407 wlc_bmac_core_phypll_ctl(wlc_hw, true);
2409 /* clear sw intstatus */
2410 wlc_hw->wlc->macintstatus = 0;
2412 /* restore the clk setting */
2413 if (!fastclk)
2414 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
2417 /* If the ucode that supports corerev 5 is used for corerev 9 and above,
2418 * txfifo sizes needs to be modified(increased) since the newer cores
2419 * have more memory.
2421 static void wlc_corerev_fifofixup(wlc_hw_info_t *wlc_hw)
2423 d11regs_t *regs = wlc_hw->regs;
2424 u16 fifo_nu;
2425 u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk;
2426 u16 txfifo_def, txfifo_def1;
2427 u16 txfifo_cmd;
2428 osl_t *osh;
2430 if (D11REV_LT(wlc_hw->corerev, 9))
2431 goto exit;
2433 /* tx fifos start at TXFIFO_START_BLK from the Base address */
2434 txfifo_startblk = TXFIFO_START_BLK;
2436 osh = wlc_hw->osh;
2438 /* sequence of operations: reset fifo, set fifo size, reset fifo */
2439 for (fifo_nu = 0; fifo_nu < NFIFO; fifo_nu++) {
2441 txfifo_endblk = txfifo_startblk + wlc_hw->xmtfifo_sz[fifo_nu];
2442 txfifo_def = (txfifo_startblk & 0xff) |
2443 (((txfifo_endblk - 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT);
2444 txfifo_def1 = ((txfifo_startblk >> 8) & 0x1) |
2445 ((((txfifo_endblk -
2446 1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT);
2447 txfifo_cmd =
2448 TXFIFOCMD_RESET_MASK | (fifo_nu << TXFIFOCMD_FIFOSEL_SHIFT);
2450 W_REG(osh, &regs->xmtfifocmd, txfifo_cmd);
2451 W_REG(osh, &regs->xmtfifodef, txfifo_def);
2452 if (D11REV_GE(wlc_hw->corerev, 16))
2453 W_REG(osh, &regs->xmtfifodef1, txfifo_def1);
2455 W_REG(osh, &regs->xmtfifocmd, txfifo_cmd);
2457 txfifo_startblk += wlc_hw->xmtfifo_sz[fifo_nu];
2459 exit:
2460 /* need to propagate to shm location to be in sync since ucode/hw won't do this */
2461 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE0,
2462 wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]);
2463 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE1,
2464 wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]);
2465 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE2,
2466 ((wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO] << 8) | wlc_hw->
2467 xmtfifo_sz[TX_AC_BK_FIFO]));
2468 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE3,
2469 ((wlc_hw->xmtfifo_sz[TX_ATIM_FIFO] << 8) | wlc_hw->
2470 xmtfifo_sz[TX_BCMC_FIFO]));
2473 /* d11 core init
2474 * reset PSM
2475 * download ucode/PCM
2476 * let ucode run to suspended
2477 * download ucode inits
2478 * config other core registers
2479 * init dma
2481 static void wlc_coreinit(wlc_info_t *wlc)
2483 wlc_hw_info_t *wlc_hw = wlc->hw;
2484 d11regs_t *regs;
2485 u32 sflags;
2486 uint bcnint_us;
2487 uint i = 0;
2488 bool fifosz_fixup = false;
2489 osl_t *osh;
2490 int err = 0;
2491 u16 buf[NFIFO];
2493 regs = wlc_hw->regs;
2494 osh = wlc_hw->osh;
2496 WL_TRACE(("wl%d: wlc_coreinit\n", wlc_hw->unit));
2498 /* reset PSM */
2499 wlc_bmac_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE));
2501 wlc_ucode_download(wlc_hw);
2503 * FIFOSZ fixup
2504 * 1) core5-9 use ucode 5 to save space since the PSM is the same
2505 * 2) newer chips, driver wants to controls the fifo allocation
2507 if (D11REV_GE(wlc_hw->corerev, 4))
2508 fifosz_fixup = true;
2510 /* let the PSM run to the suspended state, set mode to BSS STA */
2511 W_REG(osh, &regs->macintstatus, -1);
2512 wlc_bmac_mctrl(wlc_hw, ~0,
2513 (MCTL_IHR_EN | MCTL_INFRA | MCTL_PSM_RUN | MCTL_WAKE));
2515 /* wait for ucode to self-suspend after auto-init */
2516 SPINWAIT(((R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD) == 0),
2517 1000 * 1000);
2518 if ((R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD) == 0)
2519 WL_ERROR(("wl%d: wlc_coreinit: ucode did not self-suspend!\n",
2520 wlc_hw->unit));
2522 wlc_gpio_init(wlc);
2524 sflags = si_core_sflags(wlc_hw->sih, 0, 0);
2526 if (D11REV_IS(wlc_hw->corerev, 23)) {
2527 if (WLCISNPHY(wlc_hw->band))
2528 wlc_write_inits(wlc_hw, d11n0initvals16);
2529 else
2530 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n",
2531 __func__, wlc_hw->unit, wlc_hw->corerev));
2532 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2533 if (WLCISLCNPHY(wlc_hw->band)) {
2534 wlc_write_inits(wlc_hw, d11lcn0initvals24);
2535 } else {
2536 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n",
2537 __func__, wlc_hw->unit, wlc_hw->corerev));
2539 } else {
2540 WL_ERROR(("%s: wl%d: unsupported corerev %d\n",
2541 __func__, wlc_hw->unit, wlc_hw->corerev));
2544 /* For old ucode, txfifo sizes needs to be modified(increased) for Corerev >= 9 */
2545 if (fifosz_fixup == true) {
2546 wlc_corerev_fifofixup(wlc_hw);
2549 /* check txfifo allocations match between ucode and driver */
2550 buf[TX_AC_BE_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE0);
2551 if (buf[TX_AC_BE_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]) {
2552 i = TX_AC_BE_FIFO;
2553 err = -1;
2555 buf[TX_AC_VI_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE1);
2556 if (buf[TX_AC_VI_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]) {
2557 i = TX_AC_VI_FIFO;
2558 err = -1;
2560 buf[TX_AC_BK_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE2);
2561 buf[TX_AC_VO_FIFO] = (buf[TX_AC_BK_FIFO] >> 8) & 0xff;
2562 buf[TX_AC_BK_FIFO] &= 0xff;
2563 if (buf[TX_AC_BK_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BK_FIFO]) {
2564 i = TX_AC_BK_FIFO;
2565 err = -1;
2567 if (buf[TX_AC_VO_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO]) {
2568 i = TX_AC_VO_FIFO;
2569 err = -1;
2571 buf[TX_BCMC_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE3);
2572 buf[TX_ATIM_FIFO] = (buf[TX_BCMC_FIFO] >> 8) & 0xff;
2573 buf[TX_BCMC_FIFO] &= 0xff;
2574 if (buf[TX_BCMC_FIFO] != wlc_hw->xmtfifo_sz[TX_BCMC_FIFO]) {
2575 i = TX_BCMC_FIFO;
2576 err = -1;
2578 if (buf[TX_ATIM_FIFO] != wlc_hw->xmtfifo_sz[TX_ATIM_FIFO]) {
2579 i = TX_ATIM_FIFO;
2580 err = -1;
2582 if (err != 0) {
2583 WL_ERROR(("wlc_coreinit: txfifo mismatch: ucode size %d driver size %d index %d\n", buf[i], wlc_hw->xmtfifo_sz[i], i));
2584 /* DO NOT ASSERT corerev < 4 even there is a mismatch
2585 * shmem, since driver don't overwrite those chip and
2586 * ucode initialize data will be used.
2588 if (D11REV_GE(wlc_hw->corerev, 4))
2589 ASSERT(0);
2592 /* make sure we can still talk to the mac */
2593 ASSERT(R_REG(osh, &regs->maccontrol) != 0xffffffff);
2595 /* band-specific inits done by wlc_bsinit() */
2597 /* Set up frame burst size and antenna swap threshold init values */
2598 wlc_bmac_write_shm(wlc_hw, M_MBURST_SIZE, MAXTXFRAMEBURST);
2599 wlc_bmac_write_shm(wlc_hw, M_MAX_ANTCNT, ANTCNT);
2601 /* enable one rx interrupt per received frame */
2602 W_REG(osh, &regs->intrcvlazy[0], (1 << IRL_FC_SHIFT));
2603 if (D11REV_IS(wlc_hw->corerev, 4))
2604 W_REG(osh, &regs->intrcvlazy[3], (1 << IRL_FC_SHIFT));
2606 /* set the station mode (BSS STA) */
2607 wlc_bmac_mctrl(wlc_hw,
2608 (MCTL_INFRA | MCTL_DISCARD_PMQ | MCTL_AP),
2609 (MCTL_INFRA | MCTL_DISCARD_PMQ));
2611 /* set up Beacon interval */
2612 bcnint_us = 0x8000 << 10;
2613 W_REG(osh, &regs->tsf_cfprep, (bcnint_us << CFPREP_CBI_SHIFT));
2614 W_REG(osh, &regs->tsf_cfpstart, bcnint_us);
2615 W_REG(osh, &regs->macintstatus, MI_GP1);
2617 /* write interrupt mask */
2618 W_REG(osh, &regs->intctrlregs[RX_FIFO].intmask, DEF_RXINTMASK);
2619 if (D11REV_IS(wlc_hw->corerev, 4))
2620 W_REG(osh, &regs->intctrlregs[RX_TXSTATUS_FIFO].intmask,
2621 DEF_RXINTMASK);
2623 /* allow the MAC to control the PHY clock (dynamic on/off) */
2624 wlc_bmac_macphyclk_set(wlc_hw, ON);
2626 /* program dynamic clock control fast powerup delay register */
2627 if (D11REV_GT(wlc_hw->corerev, 4)) {
2628 wlc->fastpwrup_dly = si_clkctl_fast_pwrup_delay(wlc_hw->sih);
2629 W_REG(osh, &regs->scc_fastpwrup_dly, wlc->fastpwrup_dly);
2632 /* tell the ucode the corerev */
2633 wlc_bmac_write_shm(wlc_hw, M_MACHW_VER, (u16) wlc_hw->corerev);
2635 /* tell the ucode MAC capabilities */
2636 if (D11REV_GE(wlc_hw->corerev, 13)) {
2637 wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_L,
2638 (u16) (wlc_hw->machwcap & 0xffff));
2639 wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_H,
2640 (u16) ((wlc_hw->
2641 machwcap >> 16) & 0xffff));
2644 /* write retry limits to SCR, this done after PSM init */
2645 W_REG(osh, &regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
2646 (void)R_REG(osh, &regs->objaddr);
2647 W_REG(osh, &regs->objdata, wlc_hw->SRL);
2648 W_REG(osh, &regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
2649 (void)R_REG(osh, &regs->objaddr);
2650 W_REG(osh, &regs->objdata, wlc_hw->LRL);
2652 /* write rate fallback retry limits */
2653 wlc_bmac_write_shm(wlc_hw, M_SFRMTXCNTFBRTHSD, wlc_hw->SFBL);
2654 wlc_bmac_write_shm(wlc_hw, M_LFRMTXCNTFBRTHSD, wlc_hw->LFBL);
2656 if (D11REV_GE(wlc_hw->corerev, 16)) {
2657 AND_REG(osh, &regs->ifs_ctl, 0x0FFF);
2658 W_REG(osh, &regs->ifs_aifsn, EDCF_AIFSN_MIN);
2661 /* dma initializations */
2662 wlc->txpend16165war = 0;
2664 /* init the tx dma engines */
2665 for (i = 0; i < NFIFO; i++) {
2666 if (wlc_hw->di[i])
2667 dma_txinit(wlc_hw->di[i]);
2670 /* init the rx dma engine(s) and post receive buffers */
2671 dma_rxinit(wlc_hw->di[RX_FIFO]);
2672 dma_rxfill(wlc_hw->di[RX_FIFO]);
2673 if (D11REV_IS(wlc_hw->corerev, 4)) {
2674 dma_rxinit(wlc_hw->di[RX_TXSTATUS_FIFO]);
2675 dma_rxfill(wlc_hw->di[RX_TXSTATUS_FIFO]);
2679 /* This function is used for changing the tsf frac register
2680 * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz
2681 * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz
2682 * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz
2683 * HTPHY Formula is 2^26/freq(MHz) e.g.
2684 * For spuron2 - 126MHz -> 2^26/126 = 532610.0
2685 * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082
2686 * For spuron: 123MHz -> 2^26/123 = 545600.5
2687 * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341
2688 * For spur off: 120MHz -> 2^26/120 = 559240.5
2689 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
2692 void wlc_bmac_switch_macfreq(wlc_hw_info_t *wlc_hw, u8 spurmode)
2694 d11regs_t *regs;
2695 osl_t *osh;
2696 regs = wlc_hw->regs;
2697 osh = wlc_hw->osh;
2699 if ((CHIPID(wlc_hw->sih->chip) == BCM43224_CHIP_ID) ||
2700 (CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID)) {
2701 if (spurmode == WL_SPURAVOID_ON2) { /* 126Mhz */
2702 W_REG(osh, &regs->tsf_clk_frac_l, 0x2082);
2703 W_REG(osh, &regs->tsf_clk_frac_h, 0x8);
2704 } else if (spurmode == WL_SPURAVOID_ON1) { /* 123Mhz */
2705 W_REG(osh, &regs->tsf_clk_frac_l, 0x5341);
2706 W_REG(osh, &regs->tsf_clk_frac_h, 0x8);
2707 } else { /* 120Mhz */
2708 W_REG(osh, &regs->tsf_clk_frac_l, 0x8889);
2709 W_REG(osh, &regs->tsf_clk_frac_h, 0x8);
2711 } else if (WLCISLCNPHY(wlc_hw->band)) {
2712 if (spurmode == WL_SPURAVOID_ON1) { /* 82Mhz */
2713 W_REG(osh, &regs->tsf_clk_frac_l, 0x7CE0);
2714 W_REG(osh, &regs->tsf_clk_frac_h, 0xC);
2715 } else { /* 80Mhz */
2716 W_REG(osh, &regs->tsf_clk_frac_l, 0xCCCD);
2717 W_REG(osh, &regs->tsf_clk_frac_h, 0xC);
2722 /* Initialize GPIOs that are controlled by D11 core */
2723 static void wlc_gpio_init(wlc_info_t *wlc)
2725 wlc_hw_info_t *wlc_hw = wlc->hw;
2726 d11regs_t *regs;
2727 u32 gc, gm;
2728 osl_t *osh;
2730 regs = wlc_hw->regs;
2731 osh = wlc_hw->osh;
2733 /* use GPIO select 0 to get all gpio signals from the gpio out reg */
2734 wlc_bmac_mctrl(wlc_hw, MCTL_GPOUT_SEL_MASK, 0);
2737 * Common GPIO setup:
2738 * G0 = LED 0 = WLAN Activity
2739 * G1 = LED 1 = WLAN 2.4 GHz Radio State
2740 * G2 = LED 2 = WLAN 5 GHz Radio State
2741 * G4 = radio disable input (HI enabled, LO disabled)
2744 gc = gm = 0;
2746 /* Allocate GPIOs for mimo antenna diversity feature */
2747 if (WLANTSEL_ENAB(wlc)) {
2748 if (wlc_hw->antsel_type == ANTSEL_2x3) {
2749 /* Enable antenna diversity, use 2x3 mode */
2750 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
2751 MHF3_ANTSEL_EN, WLC_BAND_ALL);
2752 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE,
2753 MHF3_ANTSEL_MODE, WLC_BAND_ALL);
2755 /* init superswitch control */
2756 wlc_phy_antsel_init(wlc_hw->band->pi, false);
2758 } else if (wlc_hw->antsel_type == ANTSEL_2x4) {
2759 ASSERT((gm & BOARD_GPIO_12) == 0);
2760 gm |= gc |= (BOARD_GPIO_12 | BOARD_GPIO_13);
2761 /* The board itself is powered by these GPIOs (when not sending pattern)
2762 * So set them high
2764 OR_REG(osh, &regs->psm_gpio_oe,
2765 (BOARD_GPIO_12 | BOARD_GPIO_13));
2766 OR_REG(osh, &regs->psm_gpio_out,
2767 (BOARD_GPIO_12 | BOARD_GPIO_13));
2769 /* Enable antenna diversity, use 2x4 mode */
2770 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
2771 MHF3_ANTSEL_EN, WLC_BAND_ALL);
2772 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, 0,
2773 WLC_BAND_ALL);
2775 /* Configure the desired clock to be 4Mhz */
2776 wlc_bmac_write_shm(wlc_hw, M_ANTSEL_CLKDIV,
2777 ANTSEL_CLKDIV_4MHZ);
2780 /* gpio 9 controls the PA. ucode is responsible for wiggling out and oe */
2781 if (wlc_hw->boardflags & BFL_PACTRL)
2782 gm |= gc |= BOARD_GPIO_PACTRL;
2784 /* apply to gpiocontrol register */
2785 si_gpiocontrol(wlc_hw->sih, gm, gc, GPIO_DRV_PRIORITY);
2788 static void wlc_ucode_download(wlc_hw_info_t *wlc_hw)
2790 wlc_info_t *wlc;
2791 wlc = wlc_hw->wlc;
2793 if (wlc_hw->ucode_loaded)
2794 return;
2796 if (D11REV_IS(wlc_hw->corerev, 23)) {
2797 if (WLCISNPHY(wlc_hw->band)) {
2798 wlc_ucode_write(wlc_hw, bcm43xx_16_mimo,
2799 bcm43xx_16_mimosz);
2800 wlc_hw->ucode_loaded = true;
2801 } else
2802 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n",
2803 __func__, wlc_hw->unit, wlc_hw->corerev));
2804 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2805 if (WLCISLCNPHY(wlc_hw->band)) {
2806 wlc_ucode_write(wlc_hw, bcm43xx_24_lcn,
2807 bcm43xx_24_lcnsz);
2808 wlc_hw->ucode_loaded = true;
2809 } else {
2810 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n",
2811 __func__, wlc_hw->unit, wlc_hw->corerev));
2816 static void wlc_ucode_write(wlc_hw_info_t *wlc_hw, const u32 ucode[],
2817 const uint nbytes) {
2818 osl_t *osh;
2819 d11regs_t *regs = wlc_hw->regs;
2820 uint i;
2821 uint count;
2823 osh = wlc_hw->osh;
2825 WL_TRACE(("wl%d: wlc_ucode_write\n", wlc_hw->unit));
2827 ASSERT(IS_ALIGNED(nbytes, sizeof(u32)));
2829 count = (nbytes / sizeof(u32));
2831 W_REG(osh, &regs->objaddr, (OBJADDR_AUTO_INC | OBJADDR_UCM_SEL));
2832 (void)R_REG(osh, &regs->objaddr);
2833 for (i = 0; i < count; i++)
2834 W_REG(osh, &regs->objdata, ucode[i]);
2837 static void wlc_write_inits(wlc_hw_info_t *wlc_hw, const d11init_t *inits)
2839 int i;
2840 osl_t *osh;
2841 volatile u8 *base;
2843 WL_TRACE(("wl%d: wlc_write_inits\n", wlc_hw->unit));
2845 osh = wlc_hw->osh;
2846 base = (volatile u8 *)wlc_hw->regs;
2848 for (i = 0; inits[i].addr != 0xffff; i++) {
2849 ASSERT((inits[i].size == 2) || (inits[i].size == 4));
2851 if (inits[i].size == 2)
2852 W_REG(osh, (u16 *)(base + inits[i].addr),
2853 inits[i].value);
2854 else if (inits[i].size == 4)
2855 W_REG(osh, (u32 *)(base + inits[i].addr),
2856 inits[i].value);
2860 static void wlc_ucode_txant_set(wlc_hw_info_t *wlc_hw)
2862 u16 phyctl;
2863 u16 phytxant = wlc_hw->bmac_phytxant;
2864 u16 mask = PHY_TXC_ANT_MASK;
2866 /* set the Probe Response frame phy control word */
2867 phyctl = wlc_bmac_read_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS);
2868 phyctl = (phyctl & ~mask) | phytxant;
2869 wlc_bmac_write_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS, phyctl);
2871 /* set the Response (ACK/CTS) frame phy control word */
2872 phyctl = wlc_bmac_read_shm(wlc_hw, M_RSP_PCTLWD);
2873 phyctl = (phyctl & ~mask) | phytxant;
2874 wlc_bmac_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl);
2877 void wlc_bmac_txant_set(wlc_hw_info_t *wlc_hw, u16 phytxant)
2879 /* update sw state */
2880 wlc_hw->bmac_phytxant = phytxant;
2882 /* push to ucode if up */
2883 if (!wlc_hw->up)
2884 return;
2885 wlc_ucode_txant_set(wlc_hw);
2889 u16 wlc_bmac_get_txant(wlc_hw_info_t *wlc_hw)
2891 return (u16) wlc_hw->wlc->stf->txant;
2894 void wlc_bmac_antsel_type_set(wlc_hw_info_t *wlc_hw, u8 antsel_type)
2896 wlc_hw->antsel_type = antsel_type;
2898 /* Update the antsel type for phy module to use */
2899 wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type);
2902 void wlc_bmac_fifoerrors(wlc_hw_info_t *wlc_hw)
2904 bool fatal = false;
2905 uint unit;
2906 uint intstatus, idx;
2907 d11regs_t *regs = wlc_hw->regs;
2909 unit = wlc_hw->unit;
2911 for (idx = 0; idx < NFIFO; idx++) {
2912 /* read intstatus register and ignore any non-error bits */
2913 intstatus =
2914 R_REG(wlc_hw->osh,
2915 &regs->intctrlregs[idx].intstatus) & I_ERRORS;
2916 if (!intstatus)
2917 continue;
2919 WL_TRACE(("wl%d: wlc_bmac_fifoerrors: intstatus%d 0x%x\n", unit,
2920 idx, intstatus));
2922 if (intstatus & I_RO) {
2923 WL_ERROR(("wl%d: fifo %d: receive fifo overflow\n",
2924 unit, idx));
2925 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxoflo);
2926 fatal = true;
2929 if (intstatus & I_PC) {
2930 WL_ERROR(("wl%d: fifo %d: descriptor error\n", unit,
2931 idx));
2932 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmade);
2933 fatal = true;
2936 if (intstatus & I_PD) {
2937 WL_ERROR(("wl%d: fifo %d: data error\n", unit, idx));
2938 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmada);
2939 fatal = true;
2942 if (intstatus & I_DE) {
2943 WL_ERROR(("wl%d: fifo %d: descriptor protocol error\n",
2944 unit, idx));
2945 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmape);
2946 fatal = true;
2949 if (intstatus & I_RU) {
2950 WL_ERROR(("wl%d: fifo %d: receive descriptor underflow\n", unit, idx));
2951 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxuflo[idx]);
2954 if (intstatus & I_XU) {
2955 WL_ERROR(("wl%d: fifo %d: transmit fifo underflow\n",
2956 idx, unit));
2957 WLCNTINCR(wlc_hw->wlc->pub->_cnt->txuflo);
2958 fatal = true;
2961 if (fatal) {
2962 wlc_fatal_error(wlc_hw->wlc); /* big hammer */
2963 break;
2964 } else
2965 W_REG(wlc_hw->osh, &regs->intctrlregs[idx].intstatus,
2966 intstatus);
2970 void wlc_intrson(wlc_info_t *wlc)
2972 wlc_hw_info_t *wlc_hw = wlc->hw;
2973 ASSERT(wlc->defmacintmask);
2974 wlc->macintmask = wlc->defmacintmask;
2975 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask);
2978 /* callback for siutils.c, which has only wlc handler, no wl
2979 * they both check up, not only because there is no need to off/restore d11 interrupt
2980 * but also because per-port code may require sync with valid interrupt.
2983 static u32 wlc_wlintrsoff(wlc_info_t *wlc)
2985 if (!wlc->hw->up)
2986 return 0;
2988 return wl_intrsoff(wlc->wl);
2991 static void wlc_wlintrsrestore(wlc_info_t *wlc, u32 macintmask)
2993 if (!wlc->hw->up)
2994 return;
2996 wl_intrsrestore(wlc->wl, macintmask);
2999 u32 wlc_intrsoff(wlc_info_t *wlc)
3001 wlc_hw_info_t *wlc_hw = wlc->hw;
3002 u32 macintmask;
3004 if (!wlc_hw->clk)
3005 return 0;
3007 macintmask = wlc->macintmask; /* isr can still happen */
3009 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, 0);
3010 (void)R_REG(wlc_hw->osh, &wlc_hw->regs->macintmask); /* sync readback */
3011 udelay(1); /* ensure int line is no longer driven */
3012 wlc->macintmask = 0;
3014 /* return previous macintmask; resolve race between us and our isr */
3015 return wlc->macintstatus ? 0 : macintmask;
3018 void wlc_intrsrestore(wlc_info_t *wlc, u32 macintmask)
3020 wlc_hw_info_t *wlc_hw = wlc->hw;
3021 if (!wlc_hw->clk)
3022 return;
3024 wlc->macintmask = macintmask;
3025 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask);
3028 void wlc_bmac_mute(wlc_hw_info_t *wlc_hw, bool on, mbool flags)
3030 struct ether_addr null_ether_addr = { {0, 0, 0, 0, 0, 0} };
3032 if (on) {
3033 /* suspend tx fifos */
3034 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_DATA_FIFO);
3035 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_CTL_FIFO);
3036 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_BK_FIFO);
3037 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_VI_FIFO);
3039 /* zero the address match register so we do not send ACKs */
3040 wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
3041 &null_ether_addr);
3042 } else {
3043 /* resume tx fifos */
3044 if (!wlc_hw->wlc->tx_suspended) {
3045 wlc_bmac_tx_fifo_resume(wlc_hw, TX_DATA_FIFO);
3047 wlc_bmac_tx_fifo_resume(wlc_hw, TX_CTL_FIFO);
3048 wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_BK_FIFO);
3049 wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_VI_FIFO);
3051 /* Restore address */
3052 wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
3053 &wlc_hw->etheraddr);
3056 wlc_phy_mute_upd(wlc_hw->band->pi, on, flags);
3058 if (on)
3059 wlc_ucode_mute_override_set(wlc_hw);
3060 else
3061 wlc_ucode_mute_override_clear(wlc_hw);
3064 void wlc_bmac_set_deaf(wlc_hw_info_t *wlc_hw, bool user_flag)
3066 wlc_phy_set_deaf(wlc_hw->band->pi, user_flag);
3069 int wlc_bmac_xmtfifo_sz_get(wlc_hw_info_t *wlc_hw, uint fifo, uint *blocks)
3071 if (fifo >= NFIFO)
3072 return BCME_RANGE;
3074 *blocks = wlc_hw->xmtfifo_sz[fifo];
3076 return 0;
3079 int wlc_bmac_xmtfifo_sz_set(wlc_hw_info_t *wlc_hw, uint fifo, uint blocks)
3081 if (fifo >= NFIFO || blocks > 299)
3082 return BCME_RANGE;
3084 /* BMAC_NOTE, change blocks to u16 */
3085 wlc_hw->xmtfifo_sz[fifo] = (u16) blocks;
3087 return 0;
3090 /* wlc_bmac_tx_fifo_suspended:
3091 * Check the MAC's tx suspend status for a tx fifo.
3093 * When the MAC acknowledges a tx suspend, it indicates that no more
3094 * packets will be transmitted out the radio. This is independent of
3095 * DMA channel suspension---the DMA may have finished suspending, or may still
3096 * be pulling data into a tx fifo, by the time the MAC acks the suspend
3097 * request.
3099 bool wlc_bmac_tx_fifo_suspended(wlc_hw_info_t *wlc_hw, uint tx_fifo)
3101 /* check that a suspend has been requested and is no longer pending */
3104 * for DMA mode, the suspend request is set in xmtcontrol of the DMA engine,
3105 * and the tx fifo suspend at the lower end of the MAC is acknowledged in the
3106 * chnstatus register.
3107 * The tx fifo suspend completion is independent of the DMA suspend completion and
3108 * may be acked before or after the DMA is suspended.
3110 if (dma_txsuspended(wlc_hw->di[tx_fifo]) &&
3111 (R_REG(wlc_hw->osh, &wlc_hw->regs->chnstatus) &
3112 (1 << tx_fifo)) == 0)
3113 return true;
3115 return false;
3118 void wlc_bmac_tx_fifo_suspend(wlc_hw_info_t *wlc_hw, uint tx_fifo)
3120 u8 fifo = 1 << tx_fifo;
3122 /* Two clients of this code, 11h Quiet period and scanning. */
3124 /* only suspend if not already suspended */
3125 if ((wlc_hw->suspended_fifos & fifo) == fifo)
3126 return;
3128 /* force the core awake only if not already */
3129 if (wlc_hw->suspended_fifos == 0)
3130 wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_TXFIFO);
3132 wlc_hw->suspended_fifos |= fifo;
3134 if (wlc_hw->di[tx_fifo]) {
3135 /* Suspending AMPDU transmissions in the middle can cause underflow
3136 * which may result in mismatch between ucode and driver
3137 * so suspend the mac before suspending the FIFO
3139 if (WLC_PHY_11N_CAP(wlc_hw->band))
3140 wlc_suspend_mac_and_wait(wlc_hw->wlc);
3142 dma_txsuspend(wlc_hw->di[tx_fifo]);
3144 if (WLC_PHY_11N_CAP(wlc_hw->band))
3145 wlc_enable_mac(wlc_hw->wlc);
3149 void wlc_bmac_tx_fifo_resume(wlc_hw_info_t *wlc_hw, uint tx_fifo)
3151 /* BMAC_NOTE: WLC_TX_FIFO_ENAB is done in wlc_dpc() for DMA case but need to be done
3152 * here for PIO otherwise the watchdog will catch the inconsistency and fire
3154 /* Two clients of this code, 11h Quiet period and scanning. */
3155 if (wlc_hw->di[tx_fifo])
3156 dma_txresume(wlc_hw->di[tx_fifo]);
3158 /* allow core to sleep again */
3159 if (wlc_hw->suspended_fifos == 0)
3160 return;
3161 else {
3162 wlc_hw->suspended_fifos &= ~(1 << tx_fifo);
3163 if (wlc_hw->suspended_fifos == 0)
3164 wlc_ucode_wake_override_clear(wlc_hw,
3165 WLC_WAKE_OVERRIDE_TXFIFO);
3170 * Read and clear macintmask and macintstatus and intstatus registers.
3171 * This routine should be called with interrupts off
3172 * Return:
3173 * -1 if DEVICEREMOVED(wlc) evaluates to true;
3174 * 0 if the interrupt is not for us, or we are in some special cases;
3175 * device interrupt status bits otherwise.
3177 static inline u32 wlc_intstatus(wlc_info_t *wlc, bool in_isr)
3179 wlc_hw_info_t *wlc_hw = wlc->hw;
3180 d11regs_t *regs = wlc_hw->regs;
3181 u32 macintstatus;
3182 u32 intstatus_rxfifo, intstatus_txsfifo;
3183 osl_t *osh;
3185 osh = wlc_hw->osh;
3187 /* macintstatus includes a DMA interrupt summary bit */
3188 macintstatus = R_REG(osh, &regs->macintstatus);
3190 WL_TRACE(("wl%d: macintstatus: 0x%x\n", wlc_hw->unit, macintstatus));
3192 /* detect cardbus removed, in power down(suspend) and in reset */
3193 if (DEVICEREMOVED(wlc))
3194 return -1;
3196 /* DEVICEREMOVED succeeds even when the core is still resetting,
3197 * handle that case here.
3199 if (macintstatus == 0xffffffff)
3200 return 0;
3202 /* defer unsolicited interrupts */
3203 macintstatus &= (in_isr ? wlc->macintmask : wlc->defmacintmask);
3205 /* if not for us */
3206 if (macintstatus == 0)
3207 return 0;
3209 /* interrupts are already turned off for CFE build
3210 * Caution: For CFE Turning off the interrupts again has some undesired
3211 * consequences
3213 /* turn off the interrupts */
3214 W_REG(osh, &regs->macintmask, 0);
3215 #ifndef BCMSDIO
3216 (void)R_REG(osh, &regs->macintmask); /* sync readback */
3217 #endif
3218 wlc->macintmask = 0;
3220 /* clear device interrupts */
3221 W_REG(osh, &regs->macintstatus, macintstatus);
3223 /* MI_DMAINT is indication of non-zero intstatus */
3224 if (macintstatus & MI_DMAINT) {
3225 if (D11REV_IS(wlc_hw->corerev, 4)) {
3226 intstatus_rxfifo =
3227 R_REG(osh, &regs->intctrlregs[RX_FIFO].intstatus);
3228 intstatus_txsfifo =
3229 R_REG(osh,
3230 &regs->intctrlregs[RX_TXSTATUS_FIFO].
3231 intstatus);
3232 WL_TRACE(("wl%d: intstatus_rxfifo 0x%x, intstatus_txsfifo 0x%x\n", wlc_hw->unit, intstatus_rxfifo, intstatus_txsfifo));
3234 /* defer unsolicited interrupt hints */
3235 intstatus_rxfifo &= DEF_RXINTMASK;
3236 intstatus_txsfifo &= DEF_RXINTMASK;
3238 /* MI_DMAINT bit in macintstatus is indication of RX_FIFO interrupt */
3239 /* clear interrupt hints */
3240 if (intstatus_rxfifo)
3241 W_REG(osh,
3242 &regs->intctrlregs[RX_FIFO].intstatus,
3243 intstatus_rxfifo);
3244 else
3245 macintstatus &= ~MI_DMAINT;
3247 /* MI_TFS bit in macintstatus is encoding of RX_TXSTATUS_FIFO interrupt */
3248 if (intstatus_txsfifo) {
3249 W_REG(osh,
3250 &regs->intctrlregs[RX_TXSTATUS_FIFO].
3251 intstatus, intstatus_txsfifo);
3252 macintstatus |= MI_TFS;
3254 } else {
3256 * For corerevs >= 5, only fifo interrupt enabled is I_RI in RX_FIFO.
3257 * If MI_DMAINT is set, assume it is set and clear the interrupt.
3259 W_REG(osh, &regs->intctrlregs[RX_FIFO].intstatus,
3260 DEF_RXINTMASK);
3264 return macintstatus;
3267 /* Update wlc->macintstatus and wlc->intstatus[]. */
3268 /* Return true if they are updated successfully. false otherwise */
3269 bool wlc_intrsupd(wlc_info_t *wlc)
3271 u32 macintstatus;
3273 ASSERT(wlc->macintstatus != 0);
3275 /* read and clear macintstatus and intstatus registers */
3276 macintstatus = wlc_intstatus(wlc, false);
3278 /* device is removed */
3279 if (macintstatus == 0xffffffff)
3280 return false;
3282 /* update interrupt status in software */
3283 wlc->macintstatus |= macintstatus;
3285 return true;
3289 * First-level interrupt processing.
3290 * Return true if this was our interrupt, false otherwise.
3291 * *wantdpc will be set to true if further wlc_dpc() processing is required,
3292 * false otherwise.
3294 bool BCMFASTPATH wlc_isr(wlc_info_t *wlc, bool *wantdpc)
3296 wlc_hw_info_t *wlc_hw = wlc->hw;
3297 u32 macintstatus;
3299 *wantdpc = false;
3301 if (!wlc_hw->up || !wlc->macintmask)
3302 return false;
3304 /* read and clear macintstatus and intstatus registers */
3305 macintstatus = wlc_intstatus(wlc, true);
3307 if (macintstatus == 0xffffffff)
3308 WL_ERROR(("DEVICEREMOVED detected in the ISR code path.\n"));
3310 /* it is not for us */
3311 if (macintstatus == 0)
3312 return false;
3314 *wantdpc = true;
3316 /* save interrupt status bits */
3317 ASSERT(wlc->macintstatus == 0);
3318 wlc->macintstatus = macintstatus;
3320 return true;
3324 /* process tx completion events for corerev < 5 */
3325 static bool wlc_bmac_txstatus_corerev4(wlc_hw_info_t *wlc_hw)
3327 void *status_p;
3328 tx_status_t *txs;
3329 osl_t *osh;
3330 bool fatal = false;
3332 WL_TRACE(("wl%d: wlc_txstatusrecv\n", wlc_hw->unit));
3334 osh = wlc_hw->osh;
3336 while (!fatal && (status_p = dma_rx(wlc_hw->di[RX_TXSTATUS_FIFO]))) {
3338 txs = (tx_status_t *) PKTDATA(status_p);
3339 /* MAC uses little endian only */
3340 ltoh16_buf((void *)txs, sizeof(tx_status_t));
3342 /* shift low bits for tx_status_t status compatibility */
3343 txs->status = (txs->status & ~TXS_COMPAT_MASK)
3344 | (((txs->status & TXS_COMPAT_MASK) << TXS_COMPAT_SHIFT));
3346 fatal = wlc_bmac_dotxstatus(wlc_hw, txs, 0);
3348 PKTFREE(osh, status_p, false);
3351 if (fatal)
3352 return true;
3354 /* post more rbufs */
3355 dma_rxfill(wlc_hw->di[RX_TXSTATUS_FIFO]);
3357 return false;
3360 static bool BCMFASTPATH
3361 wlc_bmac_dotxstatus(wlc_hw_info_t *wlc_hw, tx_status_t *txs, u32 s2)
3363 /* discard intermediate indications for ucode with one legitimate case:
3364 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
3365 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
3366 * transmission count)
3368 if (!(txs->status & TX_STATUS_AMPDU)
3369 && (txs->status & TX_STATUS_INTERMEDIATE)) {
3370 return false;
3373 return wlc_dotxstatus(wlc_hw->wlc, txs, s2);
3376 /* process tx completion events in BMAC
3377 * Return true if more tx status need to be processed. false otherwise.
3379 static bool BCMFASTPATH
3380 wlc_bmac_txstatus(wlc_hw_info_t *wlc_hw, bool bound, bool *fatal)
3382 bool morepending = false;
3383 wlc_info_t *wlc = wlc_hw->wlc;
3385 WL_TRACE(("wl%d: wlc_bmac_txstatus\n", wlc_hw->unit));
3387 if (D11REV_IS(wlc_hw->corerev, 4)) {
3388 /* to retire soon */
3389 *fatal = wlc_bmac_txstatus_corerev4(wlc->hw);
3391 if (*fatal)
3392 return 0;
3393 } else {
3394 /* corerev >= 5 */
3395 d11regs_t *regs;
3396 osl_t *osh;
3397 tx_status_t txstatus, *txs;
3398 u32 s1, s2;
3399 uint n = 0;
3400 /* Param 'max_tx_num' indicates max. # tx status to process before break out. */
3401 uint max_tx_num = bound ? wlc->pub->tunables->txsbnd : -1;
3403 txs = &txstatus;
3404 regs = wlc_hw->regs;
3405 osh = wlc_hw->osh;
3406 while (!(*fatal)
3407 && (s1 = R_REG(osh, &regs->frmtxstatus)) & TXS_V) {
3409 if (s1 == 0xffffffff) {
3410 WL_ERROR(("wl%d: %s: dead chip\n",
3411 wlc_hw->unit, __func__));
3412 ASSERT(s1 != 0xffffffff);
3413 return morepending;
3416 s2 = R_REG(osh, &regs->frmtxstatus2);
3418 txs->status = s1 & TXS_STATUS_MASK;
3419 txs->frameid = (s1 & TXS_FID_MASK) >> TXS_FID_SHIFT;
3420 txs->sequence = s2 & TXS_SEQ_MASK;
3421 txs->phyerr = (s2 & TXS_PTX_MASK) >> TXS_PTX_SHIFT;
3422 txs->lasttxtime = 0;
3424 *fatal = wlc_bmac_dotxstatus(wlc_hw, txs, s2);
3426 /* !give others some time to run! */
3427 if (++n >= max_tx_num)
3428 break;
3431 if (*fatal)
3432 return 0;
3434 if (n >= max_tx_num)
3435 morepending = true;
3438 if (!pktq_empty(&wlc->active_queue->q))
3439 wlc_send_q(wlc, wlc->active_queue);
3441 return morepending;
3444 void wlc_suspend_mac_and_wait(wlc_info_t *wlc)
3446 wlc_hw_info_t *wlc_hw = wlc->hw;
3447 d11regs_t *regs = wlc_hw->regs;
3448 u32 mc, mi;
3449 osl_t *osh;
3451 WL_TRACE(("wl%d: wlc_suspend_mac_and_wait: bandunit %d\n", wlc_hw->unit,
3452 wlc_hw->band->bandunit));
3455 * Track overlapping suspend requests
3457 wlc_hw->mac_suspend_depth++;
3458 if (wlc_hw->mac_suspend_depth > 1)
3459 return;
3461 osh = wlc_hw->osh;
3463 /* force the core awake */
3464 wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
3466 mc = R_REG(osh, &regs->maccontrol);
3468 if (mc == 0xffffffff) {
3469 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__));
3470 wl_down(wlc->wl);
3471 return;
3473 ASSERT(!(mc & MCTL_PSM_JMP_0));
3474 ASSERT(mc & MCTL_PSM_RUN);
3475 ASSERT(mc & MCTL_EN_MAC);
3477 mi = R_REG(osh, &regs->macintstatus);
3478 if (mi == 0xffffffff) {
3479 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__));
3480 wl_down(wlc->wl);
3481 return;
3483 ASSERT(!(mi & MI_MACSSPNDD));
3485 wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, 0);
3487 SPINWAIT(!(R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD),
3488 WLC_MAX_MAC_SUSPEND);
3490 if (!(R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD)) {
3491 WL_ERROR(("wl%d: wlc_suspend_mac_and_wait: waited %d uS and "
3492 "MI_MACSSPNDD is still not on.\n",
3493 wlc_hw->unit, WLC_MAX_MAC_SUSPEND));
3494 WL_ERROR(("wl%d: psmdebug 0x%08x, phydebug 0x%08x, psm_brc 0x%04x\n", wlc_hw->unit, R_REG(osh, &regs->psmdebug), R_REG(osh, &regs->phydebug), R_REG(osh, &regs->psm_brc)));
3497 mc = R_REG(osh, &regs->maccontrol);
3498 if (mc == 0xffffffff) {
3499 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__));
3500 wl_down(wlc->wl);
3501 return;
3503 ASSERT(!(mc & MCTL_PSM_JMP_0));
3504 ASSERT(mc & MCTL_PSM_RUN);
3505 ASSERT(!(mc & MCTL_EN_MAC));
3508 void wlc_enable_mac(wlc_info_t *wlc)
3510 wlc_hw_info_t *wlc_hw = wlc->hw;
3511 d11regs_t *regs = wlc_hw->regs;
3512 u32 mc, mi;
3513 osl_t *osh;
3515 WL_TRACE(("wl%d: wlc_enable_mac: bandunit %d\n", wlc_hw->unit,
3516 wlc->band->bandunit));
3519 * Track overlapping suspend requests
3521 ASSERT(wlc_hw->mac_suspend_depth > 0);
3522 wlc_hw->mac_suspend_depth--;
3523 if (wlc_hw->mac_suspend_depth > 0)
3524 return;
3526 osh = wlc_hw->osh;
3528 mc = R_REG(osh, &regs->maccontrol);
3529 ASSERT(!(mc & MCTL_PSM_JMP_0));
3530 ASSERT(!(mc & MCTL_EN_MAC));
3531 ASSERT(mc & MCTL_PSM_RUN);
3533 wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, MCTL_EN_MAC);
3534 W_REG(osh, &regs->macintstatus, MI_MACSSPNDD);
3536 mc = R_REG(osh, &regs->maccontrol);
3537 ASSERT(!(mc & MCTL_PSM_JMP_0));
3538 ASSERT(mc & MCTL_EN_MAC);
3539 ASSERT(mc & MCTL_PSM_RUN);
3541 mi = R_REG(osh, &regs->macintstatus);
3542 ASSERT(!(mi & MI_MACSSPNDD));
3544 wlc_ucode_wake_override_clear(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
3547 void wlc_bmac_ifsctl_edcrs_set(wlc_hw_info_t *wlc_hw, bool abie, bool isht)
3549 if (!(WLCISNPHY(wlc_hw->band) && (D11REV_GE(wlc_hw->corerev, 16))))
3550 return;
3552 if (isht) {
3553 if (WLCISNPHY(wlc_hw->band) && NREV_LT(wlc_hw->band->phyrev, 3)) {
3554 AND_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1,
3555 ~IFS_CTL1_EDCRS);
3557 } else {
3558 /* enable EDCRS for non-11n association */
3559 OR_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1, IFS_CTL1_EDCRS);
3562 if (WLCISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3)) {
3563 if (CHSPEC_IS20(wlc_hw->chanspec)) {
3564 /* 20 mhz, use 20U ED only */
3565 OR_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1,
3566 IFS_CTL1_EDCRS);
3567 AND_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1,
3568 ~IFS_CTL1_EDCRS_20L);
3569 AND_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1,
3570 ~IFS_CTL1_EDCRS_40);
3571 } else {
3572 /* 40 mhz, use 20U 20L and 40 ED */
3573 OR_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1,
3574 IFS_CTL1_EDCRS);
3575 OR_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1,
3576 IFS_CTL1_EDCRS_20L);
3577 OR_REG(wlc_hw->osh, &wlc_hw->regs->ifs_ctl1,
3578 IFS_CTL1_EDCRS_40);
3583 static void wlc_upd_ofdm_pctl1_table(wlc_hw_info_t *wlc_hw)
3585 u8 rate;
3586 u8 rates[8] = {
3587 WLC_RATE_6M, WLC_RATE_9M, WLC_RATE_12M, WLC_RATE_18M,
3588 WLC_RATE_24M, WLC_RATE_36M, WLC_RATE_48M, WLC_RATE_54M
3590 u16 entry_ptr;
3591 u16 pctl1;
3592 uint i;
3594 if (!WLC_PHY_11N_CAP(wlc_hw->band))
3595 return;
3597 /* walk the phy rate table and update the entries */
3598 for (i = 0; i < ARRAY_SIZE(rates); i++) {
3599 rate = rates[i];
3601 entry_ptr = wlc_bmac_ofdm_ratetable_offset(wlc_hw, rate);
3603 /* read the SHM Rate Table entry OFDM PCTL1 values */
3604 pctl1 =
3605 wlc_bmac_read_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS);
3607 /* modify the value */
3608 pctl1 &= ~PHY_TXC1_MODE_MASK;
3609 pctl1 |= (wlc_hw->hw_stf_ss_opmode << PHY_TXC1_MODE_SHIFT);
3611 /* Update the SHM Rate Table entry OFDM PCTL1 values */
3612 wlc_bmac_write_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS,
3613 pctl1);
3617 static u16 wlc_bmac_ofdm_ratetable_offset(wlc_hw_info_t *wlc_hw, u8 rate)
3619 uint i;
3620 u8 plcp_rate = 0;
3621 struct plcp_signal_rate_lookup {
3622 u8 rate;
3623 u8 signal_rate;
3625 /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */
3626 const struct plcp_signal_rate_lookup rate_lookup[] = {
3627 {WLC_RATE_6M, 0xB},
3628 {WLC_RATE_9M, 0xF},
3629 {WLC_RATE_12M, 0xA},
3630 {WLC_RATE_18M, 0xE},
3631 {WLC_RATE_24M, 0x9},
3632 {WLC_RATE_36M, 0xD},
3633 {WLC_RATE_48M, 0x8},
3634 {WLC_RATE_54M, 0xC}
3637 for (i = 0; i < ARRAY_SIZE(rate_lookup); i++) {
3638 if (rate == rate_lookup[i].rate) {
3639 plcp_rate = rate_lookup[i].signal_rate;
3640 break;
3644 /* Find the SHM pointer to the rate table entry by looking in the
3645 * Direct-map Table
3647 return 2 * wlc_bmac_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2));
3650 void wlc_bmac_band_stf_ss_set(wlc_hw_info_t *wlc_hw, u8 stf_mode)
3652 wlc_hw->hw_stf_ss_opmode = stf_mode;
3654 if (wlc_hw->clk)
3655 wlc_upd_ofdm_pctl1_table(wlc_hw);
3658 void BCMFASTPATH
3659 wlc_bmac_read_tsf(wlc_hw_info_t *wlc_hw, u32 *tsf_l_ptr,
3660 u32 *tsf_h_ptr)
3662 d11regs_t *regs = wlc_hw->regs;
3664 /* read the tsf timer low, then high to get an atomic read */
3665 *tsf_l_ptr = R_REG(wlc_hw->osh, &regs->tsf_timerlow);
3666 *tsf_h_ptr = R_REG(wlc_hw->osh, &regs->tsf_timerhigh);
3668 return;
3671 bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw)
3673 d11regs_t *regs;
3674 u32 w, val;
3675 volatile u16 *reg16;
3676 osl_t *osh;
3678 WL_TRACE(("wl%d: validate_chip_access\n", wlc_hw->unit));
3680 regs = wlc_hw->regs;
3681 osh = wlc_hw->osh;
3683 /* Validate dchip register access */
3685 W_REG(osh, &regs->objaddr, OBJADDR_SHM_SEL | 0);
3686 (void)R_REG(osh, &regs->objaddr);
3687 w = R_REG(osh, &regs->objdata);
3689 /* Can we write and read back a 32bit register? */
3690 W_REG(osh, &regs->objaddr, OBJADDR_SHM_SEL | 0);
3691 (void)R_REG(osh, &regs->objaddr);
3692 W_REG(osh, &regs->objdata, (u32) 0xaa5555aa);
3694 W_REG(osh, &regs->objaddr, OBJADDR_SHM_SEL | 0);
3695 (void)R_REG(osh, &regs->objaddr);
3696 val = R_REG(osh, &regs->objdata);
3697 if (val != (u32) 0xaa5555aa) {
3698 WL_ERROR(("wl%d: validate_chip_access: SHM = 0x%x, expected 0xaa5555aa\n", wlc_hw->unit, val));
3699 return false;
3702 W_REG(osh, &regs->objaddr, OBJADDR_SHM_SEL | 0);
3703 (void)R_REG(osh, &regs->objaddr);
3704 W_REG(osh, &regs->objdata, (u32) 0x55aaaa55);
3706 W_REG(osh, &regs->objaddr, OBJADDR_SHM_SEL | 0);
3707 (void)R_REG(osh, &regs->objaddr);
3708 val = R_REG(osh, &regs->objdata);
3709 if (val != (u32) 0x55aaaa55) {
3710 WL_ERROR(("wl%d: validate_chip_access: SHM = 0x%x, expected 0x55aaaa55\n", wlc_hw->unit, val));
3711 return false;
3714 W_REG(osh, &regs->objaddr, OBJADDR_SHM_SEL | 0);
3715 (void)R_REG(osh, &regs->objaddr);
3716 W_REG(osh, &regs->objdata, w);
3718 if (D11REV_LT(wlc_hw->corerev, 11)) {
3719 /* if 32 bit writes are split into 16 bit writes, are they in the correct order
3720 * for our interface, low to high
3722 reg16 = (volatile u16 *)&regs->tsf_cfpstart;
3724 /* write the CFPStart register low half explicitly, starting a buffered write */
3725 W_REG(osh, reg16, 0xAAAA);
3727 /* Write a 32 bit value to CFPStart to test the 16 bit split order.
3728 * If the low 16 bits are written first, followed by the high 16 bits then the
3729 * 32 bit value 0xCCCCBBBB should end up in the register.
3730 * If the order is reversed, then the write to the high half will trigger a buffered
3731 * write of 0xCCCCAAAA.
3732 * If the bus is 32 bits, then this is not much of a test, and the reg should
3733 * have the correct value 0xCCCCBBBB.
3735 W_REG(osh, &regs->tsf_cfpstart, 0xCCCCBBBB);
3737 /* verify with the 16 bit registers that have no side effects */
3738 val = R_REG(osh, &regs->tsf_cfpstrt_l);
3739 if (val != (uint) 0xBBBB) {
3740 WL_ERROR(("wl%d: validate_chip_access: tsf_cfpstrt_l = 0x%x, expected" " 0x%x\n", wlc_hw->unit, val, 0xBBBB));
3741 return false;
3743 val = R_REG(osh, &regs->tsf_cfpstrt_h);
3744 if (val != (uint) 0xCCCC) {
3745 WL_ERROR(("wl%d: validate_chip_access: tsf_cfpstrt_h = 0x%x, expected" " 0x%x\n", wlc_hw->unit, val, 0xCCCC));
3746 return false;
3751 /* clear CFPStart */
3752 W_REG(osh, &regs->tsf_cfpstart, 0);
3754 w = R_REG(osh, &regs->maccontrol);
3755 if ((w != (MCTL_IHR_EN | MCTL_WAKE)) &&
3756 (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) {
3757 WL_ERROR(("wl%d: validate_chip_access: maccontrol = 0x%x, expected 0x%x or 0x%x\n", wlc_hw->unit, w, (MCTL_IHR_EN | MCTL_WAKE), (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE)));
3758 return false;
3761 return true;
3764 #define PHYPLL_WAIT_US 100000
3766 void wlc_bmac_core_phypll_ctl(wlc_hw_info_t *wlc_hw, bool on)
3768 d11regs_t *regs;
3769 osl_t *osh;
3770 u32 tmp;
3772 WL_TRACE(("wl%d: wlc_bmac_core_phypll_ctl\n", wlc_hw->unit));
3774 tmp = 0;
3775 regs = wlc_hw->regs;
3776 osh = wlc_hw->osh;
3778 if (D11REV_LE(wlc_hw->corerev, 16) || D11REV_IS(wlc_hw->corerev, 20))
3779 return;
3781 if (on) {
3782 if ((wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
3783 OR_REG(osh, &regs->clk_ctl_st,
3784 (CCS_ERSRC_REQ_HT | CCS_ERSRC_REQ_D11PLL |
3785 CCS_ERSRC_REQ_PHYPLL));
3786 SPINWAIT((R_REG(osh, &regs->clk_ctl_st) &
3787 (CCS_ERSRC_AVAIL_HT)) != (CCS_ERSRC_AVAIL_HT),
3788 PHYPLL_WAIT_US);
3790 tmp = R_REG(osh, &regs->clk_ctl_st);
3791 if ((tmp & (CCS_ERSRC_AVAIL_HT)) !=
3792 (CCS_ERSRC_AVAIL_HT)) {
3793 WL_ERROR(("%s: turn on PHY PLL failed\n",
3794 __func__));
3795 ASSERT(0);
3797 } else {
3798 OR_REG(osh, &regs->clk_ctl_st,
3799 (CCS_ERSRC_REQ_D11PLL | CCS_ERSRC_REQ_PHYPLL));
3800 SPINWAIT((R_REG(osh, &regs->clk_ctl_st) &
3801 (CCS_ERSRC_AVAIL_D11PLL |
3802 CCS_ERSRC_AVAIL_PHYPLL)) !=
3803 (CCS_ERSRC_AVAIL_D11PLL |
3804 CCS_ERSRC_AVAIL_PHYPLL), PHYPLL_WAIT_US);
3806 tmp = R_REG(osh, &regs->clk_ctl_st);
3807 if ((tmp &
3808 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL))
3810 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) {
3811 WL_ERROR(("%s: turn on PHY PLL failed\n",
3812 __func__));
3813 ASSERT(0);
3816 } else {
3817 /* Since the PLL may be shared, other cores can still be requesting it;
3818 * so we'll deassert the request but not wait for status to comply.
3820 AND_REG(osh, &regs->clk_ctl_st, ~CCS_ERSRC_REQ_PHYPLL);
3821 tmp = R_REG(osh, &regs->clk_ctl_st);
3825 void wlc_coredisable(wlc_hw_info_t *wlc_hw)
3827 bool dev_gone;
3829 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__));
3831 ASSERT(!wlc_hw->up);
3833 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
3835 if (dev_gone)
3836 return;
3838 if (wlc_hw->noreset)
3839 return;
3841 /* radio off */
3842 wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
3844 /* turn off analog core */
3845 wlc_phy_anacore(wlc_hw->band->pi, OFF);
3847 /* turn off PHYPLL to save power */
3848 wlc_bmac_core_phypll_ctl(wlc_hw, false);
3850 /* No need to set wlc->pub->radio_active = OFF
3851 * because this function needs down capability and
3852 * radio_active is designed for BCMNODOWN.
3855 /* remove gpio controls */
3856 if (wlc_hw->ucode_dbgsel)
3857 si_gpiocontrol(wlc_hw->sih, ~0, 0, GPIO_DRV_PRIORITY);
3859 wlc_hw->clk = false;
3860 si_core_disable(wlc_hw->sih, 0);
3861 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
3864 /* power both the pll and external oscillator on/off */
3865 void wlc_bmac_xtal(wlc_hw_info_t *wlc_hw, bool want)
3867 WL_TRACE(("wl%d: wlc_bmac_xtal: want %d\n", wlc_hw->unit, want));
3869 /* dont power down if plldown is false or we must poll hw radio disable */
3870 if (!want && wlc_hw->pllreq)
3871 return;
3873 if (wlc_hw->sih)
3874 si_clkctl_xtal(wlc_hw->sih, XTAL | PLL, want);
3876 wlc_hw->sbclk = want;
3877 if (!wlc_hw->sbclk) {
3878 wlc_hw->clk = false;
3879 if (wlc_hw->band && wlc_hw->band->pi)
3880 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
3884 static void wlc_flushqueues(wlc_info_t *wlc)
3886 wlc_hw_info_t *wlc_hw = wlc->hw;
3887 uint i;
3889 wlc->txpend16165war = 0;
3891 /* free any posted tx packets */
3892 for (i = 0; i < NFIFO; i++)
3893 if (wlc_hw->di[i]) {
3894 dma_txreclaim(wlc_hw->di[i], HNDDMA_RANGE_ALL);
3895 TXPKTPENDCLR(wlc, i);
3896 WL_TRACE(("wlc_flushqueues: pktpend fifo %d cleared\n",
3897 i));
3900 /* free any posted rx packets */
3901 dma_rxreclaim(wlc_hw->di[RX_FIFO]);
3902 if (D11REV_IS(wlc_hw->corerev, 4))
3903 dma_rxreclaim(wlc_hw->di[RX_TXSTATUS_FIFO]);
3906 u16 wlc_bmac_read_shm(wlc_hw_info_t *wlc_hw, uint offset)
3908 return wlc_bmac_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL);
3911 void wlc_bmac_write_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v)
3913 wlc_bmac_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL);
3916 /* Set a range of shared memory to a value.
3917 * SHM 'offset' needs to be an even address and
3918 * Buffer length 'len' must be an even number of bytes
3920 void wlc_bmac_set_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v, int len)
3922 int i;
3924 /* offset and len need to be even */
3925 ASSERT((offset & 1) == 0);
3926 ASSERT((len & 1) == 0);
3928 if (len <= 0)
3929 return;
3931 for (i = 0; i < len; i += 2) {
3932 wlc_bmac_write_objmem(wlc_hw, offset + i, v, OBJADDR_SHM_SEL);
3936 static u16
3937 wlc_bmac_read_objmem(wlc_hw_info_t *wlc_hw, uint offset, u32 sel)
3939 d11regs_t *regs = wlc_hw->regs;
3940 volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata;
3941 volatile u16 *objdata_hi = objdata_lo + 1;
3942 u16 v;
3944 ASSERT((offset & 1) == 0);
3946 W_REG(wlc_hw->osh, &regs->objaddr, sel | (offset >> 2));
3947 (void)R_REG(wlc_hw->osh, &regs->objaddr);
3948 if (offset & 2) {
3949 v = R_REG(wlc_hw->osh, objdata_hi);
3950 } else {
3951 v = R_REG(wlc_hw->osh, objdata_lo);
3954 return v;
3957 static void
3958 wlc_bmac_write_objmem(wlc_hw_info_t *wlc_hw, uint offset, u16 v, u32 sel)
3960 d11regs_t *regs = wlc_hw->regs;
3961 volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata;
3962 volatile u16 *objdata_hi = objdata_lo + 1;
3964 ASSERT((offset & 1) == 0);
3966 W_REG(wlc_hw->osh, &regs->objaddr, sel | (offset >> 2));
3967 (void)R_REG(wlc_hw->osh, &regs->objaddr);
3968 if (offset & 2) {
3969 W_REG(wlc_hw->osh, objdata_hi, v);
3970 } else {
3971 W_REG(wlc_hw->osh, objdata_lo, v);
3975 /* Copy a buffer to shared memory of specified type .
3976 * SHM 'offset' needs to be an even address and
3977 * Buffer length 'len' must be an even number of bytes
3978 * 'sel' selects the type of memory
3980 void
3981 wlc_bmac_copyto_objmem(wlc_hw_info_t *wlc_hw, uint offset, const void *buf,
3982 int len, u32 sel)
3984 u16 v;
3985 const u8 *p = (const u8 *)buf;
3986 int i;
3988 /* offset and len need to be even */
3989 ASSERT((offset & 1) == 0);
3990 ASSERT((len & 1) == 0);
3992 if (len <= 0)
3993 return;
3995 for (i = 0; i < len; i += 2) {
3996 v = p[i] | (p[i + 1] << 8);
3997 wlc_bmac_write_objmem(wlc_hw, offset + i, v, sel);
4001 /* Copy a piece of shared memory of specified type to a buffer .
4002 * SHM 'offset' needs to be an even address and
4003 * Buffer length 'len' must be an even number of bytes
4004 * 'sel' selects the type of memory
4006 void
4007 wlc_bmac_copyfrom_objmem(wlc_hw_info_t *wlc_hw, uint offset, void *buf,
4008 int len, u32 sel)
4010 u16 v;
4011 u8 *p = (u8 *) buf;
4012 int i;
4014 /* offset and len need to be even */
4015 ASSERT((offset & 1) == 0);
4016 ASSERT((len & 1) == 0);
4018 if (len <= 0)
4019 return;
4021 for (i = 0; i < len; i += 2) {
4022 v = wlc_bmac_read_objmem(wlc_hw, offset + i, sel);
4023 p[i] = v & 0xFF;
4024 p[i + 1] = (v >> 8) & 0xFF;
4028 void wlc_bmac_copyfrom_vars(wlc_hw_info_t *wlc_hw, char **buf, uint *len)
4030 WL_TRACE(("wlc_bmac_copyfrom_vars, nvram vars totlen=%d\n",
4031 wlc_hw->vars_size));
4033 *buf = wlc_hw->vars;
4034 *len = wlc_hw->vars_size;
4037 void wlc_bmac_retrylimit_upd(wlc_hw_info_t *wlc_hw, u16 SRL, u16 LRL)
4039 wlc_hw->SRL = SRL;
4040 wlc_hw->LRL = LRL;
4042 /* write retry limit to SCR, shouldn't need to suspend */
4043 if (wlc_hw->up) {
4044 W_REG(wlc_hw->osh, &wlc_hw->regs->objaddr,
4045 OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
4046 (void)R_REG(wlc_hw->osh, &wlc_hw->regs->objaddr);
4047 W_REG(wlc_hw->osh, &wlc_hw->regs->objdata, wlc_hw->SRL);
4048 W_REG(wlc_hw->osh, &wlc_hw->regs->objaddr,
4049 OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
4050 (void)R_REG(wlc_hw->osh, &wlc_hw->regs->objaddr);
4051 W_REG(wlc_hw->osh, &wlc_hw->regs->objdata, wlc_hw->LRL);
4055 void wlc_bmac_set_noreset(wlc_hw_info_t *wlc_hw, bool noreset_flag)
4057 wlc_hw->noreset = noreset_flag;
4060 void wlc_bmac_set_ucode_loaded(wlc_hw_info_t *wlc_hw, bool ucode_loaded)
4062 wlc_hw->ucode_loaded = ucode_loaded;
4065 void wlc_bmac_pllreq(wlc_hw_info_t *wlc_hw, bool set, mbool req_bit)
4067 ASSERT(req_bit);
4069 if (set) {
4070 if (mboolisset(wlc_hw->pllreq, req_bit))
4071 return;
4073 mboolset(wlc_hw->pllreq, req_bit);
4075 if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
4076 if (!wlc_hw->sbclk) {
4077 wlc_bmac_xtal(wlc_hw, ON);
4080 } else {
4081 if (!mboolisset(wlc_hw->pllreq, req_bit))
4082 return;
4084 mboolclr(wlc_hw->pllreq, req_bit);
4086 if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
4087 if (wlc_hw->sbclk) {
4088 wlc_bmac_xtal(wlc_hw, OFF);
4093 return;
4096 void wlc_bmac_set_clk(wlc_hw_info_t *wlc_hw, bool on)
4098 if (on) {
4099 /* power up pll and oscillator */
4100 wlc_bmac_xtal(wlc_hw, ON);
4102 /* enable core(s), ignore bandlocked
4103 * Leave with the same band selected as we entered
4105 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
4106 } else {
4107 /* if already down, must skip the core disable */
4108 if (wlc_hw->clk) {
4109 /* disable core(s), ignore bandlocked */
4110 wlc_coredisable(wlc_hw);
4112 /* power down pll and oscillator */
4113 wlc_bmac_xtal(wlc_hw, OFF);
4117 /* this will be true for all ai chips */
4118 bool wlc_bmac_taclear(wlc_hw_info_t *wlc_hw, bool ta_ok)
4120 return true;
4123 /* Lower down relevant GPIOs like LED when going down w/o
4124 * doing PCI config cycles or touching interrupts
4126 void wlc_gpio_fast_deinit(wlc_hw_info_t *wlc_hw)
4128 if ((wlc_hw == NULL) || (wlc_hw->sih == NULL))
4129 return;
4131 /* Only chips with internal bus or PCIE cores or certain PCI cores
4132 * are able to switch cores w/o disabling interrupts
4134 if (!((BUSTYPE(wlc_hw->sih->bustype) == SI_BUS) ||
4135 ((BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) &&
4136 ((wlc_hw->sih->buscoretype == PCIE_CORE_ID) ||
4137 (wlc_hw->sih->buscorerev >= 13)))))
4138 return;
4140 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__));
4141 return;
4144 bool wlc_bmac_radio_hw(wlc_hw_info_t *wlc_hw, bool enable)
4146 /* Do not access Phy registers if core is not up */
4147 if (si_iscoreup(wlc_hw->sih) == false)
4148 return false;
4150 if (enable) {
4151 if (PMUCTL_ENAB(wlc_hw->sih)) {
4152 AND_REG(wlc_hw->osh, &wlc_hw->regs->clk_ctl_st,
4153 ~CCS_FORCEHWREQOFF);
4154 si_pmu_radio_enable(wlc_hw->sih, true);
4157 wlc_phy_anacore(wlc_hw->band->pi, ON);
4158 wlc_phy_switch_radio(wlc_hw->band->pi, ON);
4160 /* resume d11 core */
4161 wlc_enable_mac(wlc_hw->wlc);
4162 } else {
4163 /* suspend d11 core */
4164 wlc_suspend_mac_and_wait(wlc_hw->wlc);
4166 wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
4167 wlc_phy_anacore(wlc_hw->band->pi, OFF);
4169 if (PMUCTL_ENAB(wlc_hw->sih)) {
4170 si_pmu_radio_enable(wlc_hw->sih, false);
4171 OR_REG(wlc_hw->osh, &wlc_hw->regs->clk_ctl_st,
4172 CCS_FORCEHWREQOFF);
4176 return true;
4179 u16 wlc_bmac_rate_shm_offset(wlc_hw_info_t *wlc_hw, u8 rate)
4181 u16 table_ptr;
4182 u8 phy_rate, index;
4184 /* get the phy specific rate encoding for the PLCP SIGNAL field */
4185 /* XXX4321 fixup needed ? */
4186 if (IS_OFDM(rate))
4187 table_ptr = M_RT_DIRMAP_A;
4188 else
4189 table_ptr = M_RT_DIRMAP_B;
4191 /* for a given rate, the LS-nibble of the PLCP SIGNAL field is
4192 * the index into the rate table.
4194 phy_rate = rate_info[rate] & RATE_MASK;
4195 index = phy_rate & 0xf;
4197 /* Find the SHM pointer to the rate table entry by looking in the
4198 * Direct-map Table
4200 return 2 * wlc_bmac_read_shm(wlc_hw, table_ptr + (index * 2));
4203 void wlc_bmac_set_txpwr_percent(wlc_hw_info_t *wlc_hw, u8 val)
4205 wlc_phy_txpwr_percent_set(wlc_hw->band->pi, val);
4208 void wlc_bmac_antsel_set(wlc_hw_info_t *wlc_hw, u32 antsel_avail)
4210 wlc_hw->antsel_avail = antsel_avail;