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.
18 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
26 #include <proto/802.11.h>
30 #include <bcmendian.h>
42 #include <wlc_channel.h>
46 /* BMAC_NOTE: a WLC_HIGH compile include of wlc.h adds in more structures and type
47 * dependencies. Need to include these to files to allow a clean include of wlc.h
48 * with WLC_HIGH defined.
49 * At some point we may be able to skip the include of wlc.h and instead just
50 * define a stub wlc_info and band struct to allow rpc calls to get the rpc handle.
52 #include <wlc_event.h>
53 #include <wlc_mac80211.h>
55 #include <wlc_phy_shim.h>
56 #include <wlc_phy_hal.h>
57 #include <wl_export.h>
59 #include "d11ucode_ext.h"
62 /* BMAC_NOTE: With WLC_HIGH defined, some fns in this file make calls to high level
63 * functions defined in the headers below. We should be eliminating those calls and
64 * will be able to delete these include lines.
66 #include <wlc_antsel.h>
68 #include <pcie_core.h>
70 #include <wlc_alloc.h>
73 #define TIMER_INTERVAL_WATCHDOG_BMAC 1000 /* watchdog timer, in unit of ms */
75 #define SYNTHPU_DLY_APHY_US 3700 /* a phy synthpu_dly time in us */
76 #define SYNTHPU_DLY_BPHY_US 1050 /* b/g phy synthpu_dly time in us, default */
77 #define SYNTHPU_DLY_NPHY_US 2048 /* n phy REV3 synthpu_dly time in us, default */
78 #define SYNTHPU_DLY_LPPHY_US 300 /* lpphy synthpu_dly time in us */
80 #define SYNTHPU_DLY_PHY_US_QT 100 /* QT synthpu_dly time in us */
82 #ifndef BMAC_DUP_TO_REMOVE
83 #define WLC_RM_WAIT_TX_SUSPEND 4 /* Wait Tx Suspend */
85 #define ANTCNT 10 /* vanilla M_MAX_ANTCNT value */
87 #endif /* BMAC_DUP_TO_REMOVE */
89 #define DMAREG(wlc_hw, direction, fifonum) (D11REV_LT(wlc_hw->corerev, 11) ? \
90 ((direction == DMA_TX) ? \
91 (void *)&(wlc_hw->regs->fifo.f32regs.dmaregs[fifonum].xmt) : \
92 (void *)&(wlc_hw->regs->fifo.f32regs.dmaregs[fifonum].rcv)) : \
93 ((direction == DMA_TX) ? \
94 (void *)&(wlc_hw->regs->fifo.f64regs[fifonum].dmaxmt) : \
95 (void *)&(wlc_hw->regs->fifo.f64regs[fifonum].dmarcv)))
98 * The following table lists the buffer memory allocated to xmt fifos in HW.
99 * the size is in units of 256bytes(one block), total size is HW dependent
100 * ucode has default fifo partition, sw can overwrite if necessary
102 * This is documented in twiki under the topic UcodeTxFifo. Please ensure
103 * the twiki is updated before making changes.
106 #define XMTFIFOTBL_STARTREV 20 /* Starting corerev for the fifo size table */
108 static u16 xmtfifo_sz[][NFIFO] = {
109 {20, 192, 192, 21, 17, 5}, /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */
110 {9, 58, 22, 14, 14, 5}, /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */
111 {20, 192, 192, 21, 17, 5}, /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */
112 {20, 192, 192, 21, 17, 5}, /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */
113 {9, 58, 22, 14, 14, 5}, /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
116 static void wlc_clkctl_clk(struct wlc_hw_info *wlc, uint mode);
117 static void wlc_coreinit(struct wlc_info *wlc);
119 /* used by wlc_wakeucode_init() */
120 static void wlc_write_inits(struct wlc_hw_info *wlc_hw, const d11init_t *inits);
121 static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
123 static void wlc_ucode_download(struct wlc_hw_info *wlc);
124 static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw);
126 /* used by wlc_dpc() */
127 static bool wlc_bmac_dotxstatus(struct wlc_hw_info *wlc, tx_status_t *txs,
129 static bool wlc_bmac_txstatus_corerev4(struct wlc_hw_info *wlc);
130 static bool wlc_bmac_txstatus(struct wlc_hw_info *wlc, bool bound, bool *fatal);
131 static bool wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound);
133 /* used by wlc_down() */
134 static void wlc_flushqueues(struct wlc_info *wlc);
136 static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs);
137 static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw);
138 static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw);
140 /* Low Level Prototypes */
141 static u16 wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset,
143 static void wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset,
145 static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme);
146 static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw);
147 static void wlc_ucode_bsinit(struct wlc_hw_info *wlc_hw);
148 static bool wlc_validboardtype(struct wlc_hw_info *wlc);
149 static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw);
150 static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw);
151 static void wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init);
152 static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw);
153 static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw);
154 static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw);
155 static u32 wlc_wlintrsoff(struct wlc_info *wlc);
156 static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask);
157 static void wlc_gpio_init(struct wlc_info *wlc);
158 static void wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn,
160 static void wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn,
162 static void wlc_bmac_bsinit(struct wlc_info *wlc, chanspec_t chanspec);
163 static u32 wlc_setband_inact(struct wlc_info *wlc, uint bandunit);
164 static void wlc_bmac_setband(struct wlc_hw_info *wlc_hw, uint bandunit,
165 chanspec_t chanspec);
166 static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
168 static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw);
169 static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw,
172 /* === Low Level functions === */
174 void wlc_bmac_set_shortslot(struct wlc_hw_info *wlc_hw, bool shortslot)
176 wlc_hw->shortslot = shortslot;
178 if (BAND_2G(wlc_bmac_bandtype(wlc_hw)) && wlc_hw->up) {
179 wlc_suspend_mac_and_wait(wlc_hw->wlc);
180 wlc_bmac_update_slot_timing(wlc_hw, shortslot);
181 wlc_enable_mac(wlc_hw->wlc);
186 * Update the slot timing for standard 11b/g (20us slots)
187 * or shortslot 11g (9us slots)
188 * The PSM needs to be suspended for this call.
190 static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
193 struct osl_info *osh;
200 /* 11g short slot: 11a timing */
201 W_REG(osh, ®s->ifs_slot, 0x0207); /* APHY_SLOT_TIME */
202 wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, APHY_SLOT_TIME);
204 /* 11g long slot: 11b timing */
205 W_REG(osh, ®s->ifs_slot, 0x0212); /* BPHY_SLOT_TIME */
206 wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, BPHY_SLOT_TIME);
210 static void WLBANDINITFN(wlc_ucode_bsinit) (struct wlc_hw_info *wlc_hw)
212 /* init microcode host flags */
213 wlc_write_mhf(wlc_hw, wlc_hw->band->mhfs);
215 /* do band-specific ucode IHR, SHM, and SCR inits */
216 if (D11REV_IS(wlc_hw->corerev, 23)) {
217 if (WLCISNPHY(wlc_hw->band)) {
218 wlc_write_inits(wlc_hw, d11n0bsinitvals16);
220 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
221 __func__, wlc_hw->unit, wlc_hw->corerev);
224 if (D11REV_IS(wlc_hw->corerev, 24)) {
225 if (WLCISLCNPHY(wlc_hw->band)) {
226 wlc_write_inits(wlc_hw, d11lcn0bsinitvals24);
228 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
229 __func__, wlc_hw->unit,
232 WL_ERROR("%s: wl%d: unsupported corerev %d\n",
233 __func__, wlc_hw->unit, wlc_hw->corerev);
238 /* switch to new band but leave it inactive */
239 static u32 WLBANDINITFN(wlc_setband_inact) (struct wlc_info *wlc, uint bandunit)
241 struct wlc_hw_info *wlc_hw = wlc->hw;
245 WL_TRACE("wl%d: wlc_setband_inact\n", wlc_hw->unit);
247 ASSERT(bandunit != wlc_hw->band->bandunit);
248 ASSERT(si_iscoreup(wlc_hw->sih));
249 ASSERT((R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol) & MCTL_EN_MAC) ==
252 /* disable interrupts */
253 macintmask = wl_intrsoff(wlc->wl);
256 wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
260 if (D11REV_LT(wlc_hw->corerev, 17))
261 tmp = R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol);
263 wlc_bmac_core_phy_clk(wlc_hw, OFF);
265 wlc_setxband(wlc_hw, bandunit);
270 /* Process received frames */
272 * Return true if more frames need to be processed. false otherwise.
273 * Param 'bound' indicates max. # frames to process before break out.
275 static bool BCMFASTPATH
276 wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound)
279 struct sk_buff *head = NULL;
280 struct sk_buff *tail = NULL;
282 uint bound_limit = bound ? wlc_hw->wlc->pub->tunables->rxbnd : -1;
284 wlc_d11rxhdr_t *wlc_rxhdr = NULL;
286 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
287 /* gather received frames */
288 while ((p = dma_rx(wlc_hw->di[fifo]))) {
297 /* !give others some time to run! */
298 if (++n >= bound_limit)
302 /* get the TSF REG reading */
303 wlc_bmac_read_tsf(wlc_hw, &tsf_l, &tsf_h);
305 /* post more rbufs */
306 dma_rxfill(wlc_hw->di[fifo]);
308 /* process each frame */
309 while ((p = head) != NULL) {
313 /* record the tsf_l in wlc_rxd11hdr */
314 wlc_rxhdr = (wlc_d11rxhdr_t *) p->data;
315 wlc_rxhdr->tsf_l = htol32(tsf_l);
317 /* compute the RSSI from d11rxhdr and record it in wlc_rxd11hr */
318 wlc_phy_rssi_compute(wlc_hw->band->pi, wlc_rxhdr);
320 wlc_recv(wlc_hw->wlc, p);
323 return n >= bound_limit;
326 /* second-level interrupt processing
327 * Return true if another dpc needs to be re-scheduled. false otherwise.
328 * Param 'bounded' indicates if applicable loops should be bounded.
330 bool BCMFASTPATH wlc_dpc(struct wlc_info *wlc, bool bounded)
333 struct wlc_hw_info *wlc_hw = wlc->hw;
334 d11regs_t *regs = wlc_hw->regs;
337 if (DEVICEREMOVED(wlc)) {
338 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
343 /* grab and clear the saved software intstatus bits */
344 macintstatus = wlc->macintstatus;
345 wlc->macintstatus = 0;
347 WL_TRACE("wl%d: wlc_dpc: macintstatus 0x%x\n",
348 wlc_hw->unit, macintstatus);
350 if (macintstatus & MI_PRQ) {
351 /* Process probe request FIFO */
352 ASSERT(0 && "PRQ Interrupt in non-MBSS");
355 /* BCN template is available */
356 /* ZZZ: Use AP_ACTIVE ? */
357 if (AP_ENAB(wlc->pub) && (!APSTA_ENAB(wlc->pub) || wlc->aps_associated)
358 && (macintstatus & MI_BCNTPL)) {
359 wlc_update_beacon(wlc);
362 /* PMQ entry addition */
363 if (macintstatus & MI_PMQ) {
367 if (macintstatus & MI_TFS) {
368 if (wlc_bmac_txstatus(wlc->hw, bounded, &fatal))
369 wlc->macintstatus |= MI_TFS;
371 WL_ERROR("MI_TFS: fatal\n");
376 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
379 /* ATIM window end */
380 if (macintstatus & MI_ATIMWINEND) {
381 WL_TRACE("wlc_isr: end of ATIM window\n");
383 OR_REG(wlc_hw->osh, ®s->maccommand, wlc->qvalid);
388 if (macintstatus & MI_PHYTXERR) {
389 WLCNTINCR(wlc->pub->_cnt->txphyerr);
392 /* received data or control frame, MI_DMAINT is indication of RX_FIFO interrupt */
393 if (macintstatus & MI_DMAINT) {
394 if (wlc_bmac_recv(wlc_hw, RX_FIFO, bounded)) {
395 wlc->macintstatus |= MI_DMAINT;
399 /* TX FIFO suspend/flush completion */
400 if (macintstatus & MI_TXSTOP) {
401 if (wlc_bmac_tx_fifo_suspended(wlc_hw, TX_DATA_FIFO)) {
402 /* WL_ERROR("dpc: fifo_suspend_comlete\n"); */
406 /* noise sample collected */
407 if (macintstatus & MI_BG_NOISE) {
408 wlc_phy_noise_sample_intr(wlc_hw->band->pi);
411 if (macintstatus & MI_GP0) {
412 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
413 wlc_hw->unit, wlc_hw->now);
415 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
416 __func__, wlc_hw->sih->chip,
417 wlc_hw->sih->chiprev);
419 WLCNTINCR(wlc->pub->_cnt->psmwds);
425 /* gptimer timeout */
426 if (macintstatus & MI_TO) {
427 W_REG(wlc_hw->osh, ®s->gptimer, 0);
430 if (macintstatus & MI_RFDISABLE) {
432 u32 rfd = R_REG(wlc_hw->osh, ®s->phydebug) & PDBG_RFD;
435 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
438 WLCNTINCR(wlc->pub->_cnt->rfdisable);
441 /* send any enq'd tx packets. Just makes sure to jump start tx */
442 if (!pktq_empty(&wlc->active_queue->q))
443 wlc_send_q(wlc, wlc->active_queue);
445 ASSERT(wlc_ps_check(wlc));
447 /* make sure the bound indication and the implementation are in sync */
448 ASSERT(bounded == true || wlc->macintstatus == 0);
450 /* it isn't done and needs to be resched if macintstatus is non-zero */
451 return wlc->macintstatus != 0;
455 return wlc->macintstatus != 0;
458 /* common low-level watchdog code */
459 void wlc_bmac_watchdog(void *arg)
461 struct wlc_info *wlc = (struct wlc_info *) arg;
462 struct wlc_hw_info *wlc_hw = wlc->hw;
464 WL_TRACE("wl%d: wlc_bmac_watchdog\n", wlc_hw->unit);
469 /* increment second count */
472 /* Check for FIFO error interrupts */
473 wlc_bmac_fifoerrors(wlc_hw);
475 /* make sure RX dma has buffers */
476 dma_rxfill(wlc->hw->di[RX_FIFO]);
477 if (D11REV_IS(wlc_hw->corerev, 4)) {
478 dma_rxfill(wlc->hw->di[RX_TXSTATUS_FIFO]);
481 wlc_phy_watchdog(wlc_hw->band->pi);
485 wlc_bmac_set_chanspec(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
486 bool mute, struct txpwr_limits *txpwr)
490 WL_TRACE("wl%d: wlc_bmac_set_chanspec 0x%x\n",
491 wlc_hw->unit, chanspec);
493 wlc_hw->chanspec = chanspec;
495 /* Switch bands if necessary */
496 if (NBANDS_HW(wlc_hw) > 1) {
497 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
498 if (wlc_hw->band->bandunit != bandunit) {
499 /* wlc_bmac_setband disables other bandunit,
500 * use light band switch if not up yet
503 wlc_phy_chanspec_radio_set(wlc_hw->
504 bandstate[bandunit]->
506 wlc_bmac_setband(wlc_hw, bandunit, chanspec);
508 wlc_setxband(wlc_hw, bandunit);
513 wlc_phy_initcal_enable(wlc_hw->band->pi, !mute);
517 wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr,
519 wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
521 wlc_phy_chanspec_set(wlc_hw->band->pi, chanspec);
522 wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, chanspec);
524 /* Update muting of the channel */
525 wlc_bmac_mute(wlc_hw, mute, 0);
529 int wlc_bmac_state_get(struct wlc_hw_info *wlc_hw, wlc_bmac_state_t *state)
531 state->machwcap = wlc_hw->machwcap;
536 static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
540 /* ucode host flag 2 needed for pio mode, independent of band and fifo */
542 struct wlc_hw_info *wlc_hw = wlc->hw;
543 uint unit = wlc_hw->unit;
544 wlc_tunables_t *tune = wlc->pub->tunables;
546 /* name and offsets for dma_attach */
547 snprintf(name, sizeof(name), "wl%d", unit);
549 if (wlc_hw->di[0] == 0) { /* Init FIFOs */
551 int dma_attach_err = 0;
552 struct osl_info *osh = wlc_hw->osh;
554 /* Find out the DMA addressing capability and let OS know
555 * All the channels within one DMA core have 'common-minimum' same
559 dma_addrwidth(wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 0));
561 if (!wl_alloc_dma_resources(wlc_hw->wlc->wl, addrwidth)) {
562 WL_ERROR("wl%d: wlc_attach: alloc_dma_resources failed\n",
569 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
570 * RX: RX_FIFO (RX data packets)
572 ASSERT(TX_AC_BK_FIFO == 0);
573 ASSERT(RX_FIFO == 0);
574 wlc_hw->di[0] = dma_attach(osh, name, wlc_hw->sih,
575 (wme ? DMAREG(wlc_hw, DMA_TX, 0) :
576 NULL), DMAREG(wlc_hw, DMA_RX, 0),
577 (wme ? tune->ntxd : 0), tune->nrxd,
578 tune->rxbufsz, -1, tune->nrxbufpost,
579 WL_HWRXOFF, &wl_msg_level);
580 dma_attach_err |= (NULL == wlc_hw->di[0]);
584 * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets)
585 * (legacy) TX_DATA_FIFO (TX data packets)
588 ASSERT(TX_AC_BE_FIFO == 1);
589 ASSERT(TX_DATA_FIFO == 1);
590 wlc_hw->di[1] = dma_attach(osh, name, wlc_hw->sih,
591 DMAREG(wlc_hw, DMA_TX, 1), NULL,
592 tune->ntxd, 0, 0, -1, 0, 0,
594 dma_attach_err |= (NULL == wlc_hw->di[1]);
598 * TX: TX_AC_VI_FIFO (TX AC Video data packets)
601 ASSERT(TX_AC_VI_FIFO == 2);
602 wlc_hw->di[2] = dma_attach(osh, name, wlc_hw->sih,
603 DMAREG(wlc_hw, DMA_TX, 2), NULL,
604 tune->ntxd, 0, 0, -1, 0, 0,
606 dma_attach_err |= (NULL == wlc_hw->di[2]);
609 * TX: TX_AC_VO_FIFO (TX AC Voice data packets)
610 * (legacy) TX_CTL_FIFO (TX control & mgmt packets)
611 * RX: RX_TXSTATUS_FIFO (transmit-status packets)
612 * for corerev < 5 only
614 ASSERT(TX_AC_VO_FIFO == 3);
615 ASSERT(TX_CTL_FIFO == 3);
616 if (D11REV_IS(wlc_hw->corerev, 4)) {
617 ASSERT(RX_TXSTATUS_FIFO == 3);
618 wlc_hw->di[3] = dma_attach(osh, name, wlc_hw->sih,
619 DMAREG(wlc_hw, DMA_TX, 3),
620 DMAREG(wlc_hw, DMA_RX, 3),
621 tune->ntxd, tune->nrxd,
622 sizeof(tx_status_t), -1,
625 dma_attach_err |= (NULL == wlc_hw->di[3]);
627 wlc_hw->di[3] = dma_attach(osh, name, wlc_hw->sih,
628 DMAREG(wlc_hw, DMA_TX, 3),
629 NULL, tune->ntxd, 0, 0, -1,
630 0, 0, &wl_msg_level);
631 dma_attach_err |= (NULL == wlc_hw->di[3]);
633 /* Cleaner to leave this as if with AP defined */
635 if (dma_attach_err) {
636 WL_ERROR("wl%d: wlc_attach: dma_attach failed\n", unit);
640 /* get pointer to dma engine tx flow control variable */
641 for (i = 0; i < NFIFO; i++)
644 (uint *) dma_getvar(wlc_hw->di[i],
648 /* initial ucode host flags */
649 wlc_mhfdef(wlc, wlc_hw->band->mhfs, pio_mhf2);
654 static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw)
658 for (j = 0; j < NFIFO; j++) {
660 dma_detach(wlc_hw->di[j]);
661 wlc_hw->di[j] = NULL;
667 * run backplane attach, init nvram
669 * initialize software state for each core and band
670 * put the whole chip in reset(driver down state), no clock
672 int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device, uint unit,
673 bool piomode, struct osl_info *osh, void *regsva,
674 uint bustype, void *btparam)
676 struct wlc_hw_info *wlc_hw;
678 char *macaddr = NULL;
683 shared_phy_params_t sha_params;
685 WL_TRACE("wl%d: wlc_bmac_attach: vendor 0x%x device 0x%x\n",
686 unit, vendor, device);
688 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
696 wlc_hw->band = wlc_hw->bandstate[0];
697 wlc_hw->_piomode = piomode;
699 /* populate struct wlc_hw_info with default values */
700 wlc_bmac_info_init(wlc_hw);
703 * Do the hardware portion of the attach.
704 * Also initialize software state that depends on the particular hardware
707 wlc_hw->sih = si_attach((uint) device, osh, regsva, bustype, btparam,
708 &wlc_hw->vars, &wlc_hw->vars_size);
709 if (wlc_hw->sih == NULL) {
710 WL_ERROR("wl%d: wlc_bmac_attach: si_attach failed\n", unit);
717 * Get vendid/devid nvram overwrites, which could be different
718 * than those the BIOS recognizes for devices on PCMCIA_BUS,
719 * SDIO_BUS, and SROMless devices on PCI_BUS.
722 bustype = BCMBUSTYPE;
724 if (bustype != SI_BUS) {
727 var = getvar(vars, "vendid");
729 vendor = (u16) simple_strtoul(var, NULL, 0);
730 WL_ERROR("Overriding vendor id = 0x%x\n", vendor);
732 var = getvar(vars, "devid");
734 u16 devid = (u16) simple_strtoul(var, NULL, 0);
735 if (devid != 0xffff) {
737 WL_ERROR("Overriding device id = 0x%x\n",
742 /* verify again the device is supported */
743 if (!wlc_chipmatch(vendor, device)) {
744 WL_ERROR("wl%d: wlc_bmac_attach: Unsupported vendor/device (0x%x/0x%x)\n",
745 unit, vendor, device);
751 wlc_hw->vendorid = vendor;
752 wlc_hw->deviceid = device;
754 /* set bar0 window to point at D11 core */
755 wlc_hw->regs = (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID, 0);
756 wlc_hw->corerev = si_corerev(wlc_hw->sih);
760 wlc->regs = wlc_hw->regs;
762 /* validate chip, chiprev and corerev */
763 if (!wlc_isgoodchip(wlc_hw)) {
768 /* initialize power control registers */
769 si_clkctl_init(wlc_hw->sih);
771 /* request fastclock and force fastclock for the rest of attach
772 * bring the d11 core out of reset.
773 * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk is still false;
774 * But it will be called again inside wlc_corereset, after d11 is out of reset.
776 wlc_clkctl_clk(wlc_hw, CLK_FAST);
777 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
779 if (!wlc_bmac_validate_chip_access(wlc_hw)) {
780 WL_ERROR("wl%d: wlc_bmac_attach: validate_chip_access failed\n",
786 /* get the board rev, used just below */
787 j = getintvar(vars, "boardrev");
788 /* promote srom boardrev of 0xFF to 1 */
789 if (j == BOARDREV_PROMOTABLE)
790 j = BOARDREV_PROMOTED;
791 wlc_hw->boardrev = (u16) j;
792 if (!wlc_validboardtype(wlc_hw)) {
793 WL_ERROR("wl%d: wlc_bmac_attach: Unsupported Broadcom board type (0x%x)" " or revision level (0x%x)\n",
794 unit, wlc_hw->sih->boardtype, wlc_hw->boardrev);
798 wlc_hw->sromrev = (u8) getintvar(vars, "sromrev");
799 wlc_hw->boardflags = (u32) getintvar(vars, "boardflags");
800 wlc_hw->boardflags2 = (u32) getintvar(vars, "boardflags2");
802 if (D11REV_LE(wlc_hw->corerev, 4)
803 || (wlc_hw->boardflags & BFL_NOPLLDOWN))
804 wlc_bmac_pllreq(wlc_hw, true, WLC_PLLREQ_SHARED);
806 if ((wlc_hw->sih->bustype == PCI_BUS)
807 && (si_pci_war16165(wlc_hw->sih)))
808 wlc->war16165 = true;
810 /* check device id(srom, nvram etc.) to set bands */
811 if (wlc_hw->deviceid == BCM43224_D11N_ID) {
812 /* Dualband boards */
817 if ((wlc_hw->sih->chip == BCM43225_CHIP_ID))
820 /* BMAC_NOTE: remove init of pub values when wlc_attach() unconditionally does the
821 * init of these values
823 wlc->vendorid = wlc_hw->vendorid;
824 wlc->deviceid = wlc_hw->deviceid;
825 wlc->pub->sih = wlc_hw->sih;
826 wlc->pub->corerev = wlc_hw->corerev;
827 wlc->pub->sromrev = wlc_hw->sromrev;
828 wlc->pub->boardrev = wlc_hw->boardrev;
829 wlc->pub->boardflags = wlc_hw->boardflags;
830 wlc->pub->boardflags2 = wlc_hw->boardflags2;
831 wlc->pub->_nbands = wlc_hw->_nbands;
833 wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc);
835 if (wlc_hw->physhim == NULL) {
836 WL_ERROR("wl%d: wlc_bmac_attach: wlc_phy_shim_attach failed\n",
842 /* pass all the parameters to wlc_phy_shared_attach in one struct */
843 sha_params.osh = osh;
844 sha_params.sih = wlc_hw->sih;
845 sha_params.physhim = wlc_hw->physhim;
846 sha_params.unit = unit;
847 sha_params.corerev = wlc_hw->corerev;
848 sha_params.vars = vars;
849 sha_params.vid = wlc_hw->vendorid;
850 sha_params.did = wlc_hw->deviceid;
851 sha_params.chip = wlc_hw->sih->chip;
852 sha_params.chiprev = wlc_hw->sih->chiprev;
853 sha_params.chippkg = wlc_hw->sih->chippkg;
854 sha_params.sromrev = wlc_hw->sromrev;
855 sha_params.boardtype = wlc_hw->sih->boardtype;
856 sha_params.boardrev = wlc_hw->boardrev;
857 sha_params.boardvendor = wlc_hw->sih->boardvendor;
858 sha_params.boardflags = wlc_hw->boardflags;
859 sha_params.boardflags2 = wlc_hw->boardflags2;
860 sha_params.bustype = wlc_hw->sih->bustype;
861 sha_params.buscorerev = wlc_hw->sih->buscorerev;
863 /* alloc and save pointer to shared phy state area */
864 wlc_hw->phy_sh = wlc_phy_shared_attach(&sha_params);
865 if (!wlc_hw->phy_sh) {
870 /* initialize software state for each core and band */
871 for (j = 0; j < NBANDS_HW(wlc_hw); j++) {
873 * band0 is always 2.4Ghz
874 * band1, if present, is 5Ghz
877 /* So if this is a single band 11a card, use band 1 */
878 if (IS_SINGLEBAND_5G(wlc_hw->deviceid))
881 wlc_setxband(wlc_hw, j);
883 wlc_hw->band->bandunit = j;
884 wlc_hw->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
885 wlc->band->bandunit = j;
886 wlc->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
887 wlc->core->coreidx = si_coreidx(wlc_hw->sih);
889 if (D11REV_GE(wlc_hw->corerev, 13)) {
890 wlc_hw->machwcap = R_REG(wlc_hw->osh, ®s->machwcap);
891 wlc_hw->machwcap_backup = wlc_hw->machwcap;
894 /* init tx fifo size */
895 ASSERT((wlc_hw->corerev - XMTFIFOTBL_STARTREV) <
896 ARRAY_SIZE(xmtfifo_sz));
898 xmtfifo_sz[(wlc_hw->corerev - XMTFIFOTBL_STARTREV)];
900 /* Get a phy for this band */
901 wlc_hw->band->pi = wlc_phy_attach(wlc_hw->phy_sh,
902 (void *)regs, wlc_bmac_bandtype(wlc_hw), vars);
903 if (wlc_hw->band->pi == NULL) {
904 WL_ERROR("wl%d: wlc_bmac_attach: wlc_phy_attach failed\n",
910 wlc_phy_machwcap_set(wlc_hw->band->pi, wlc_hw->machwcap);
912 wlc_phy_get_phyversion(wlc_hw->band->pi, &wlc_hw->band->phytype,
913 &wlc_hw->band->phyrev,
914 &wlc_hw->band->radioid,
915 &wlc_hw->band->radiorev);
916 wlc_hw->band->abgphy_encore =
917 wlc_phy_get_encore(wlc_hw->band->pi);
918 wlc->band->abgphy_encore = wlc_phy_get_encore(wlc_hw->band->pi);
919 wlc_hw->band->core_flags =
920 wlc_phy_get_coreflags(wlc_hw->band->pi);
922 /* verify good phy_type & supported phy revision */
923 if (WLCISNPHY(wlc_hw->band)) {
924 if (NCONF_HAS(wlc_hw->band->phyrev))
928 } else if (WLCISLCNPHY(wlc_hw->band)) {
929 if (LCNCONF_HAS(wlc_hw->band->phyrev))
935 WL_ERROR("wl%d: wlc_bmac_attach: unsupported phy type/rev (%d/%d)\n",
937 wlc_hw->band->phytype, wlc_hw->band->phyrev);
943 /* BMAC_NOTE: wlc->band->pi should not be set below and should be done in the
944 * high level attach. However we can not make that change until all low level access
945 * is changed to wlc_hw->band->pi. Instead do the wlc->band->pi init below, keeping
946 * wlc_hw->band->pi as well for incremental update of low level fns, and cut over
947 * low only init when all fns updated.
949 wlc->band->pi = wlc_hw->band->pi;
950 wlc->band->phytype = wlc_hw->band->phytype;
951 wlc->band->phyrev = wlc_hw->band->phyrev;
952 wlc->band->radioid = wlc_hw->band->radioid;
953 wlc->band->radiorev = wlc_hw->band->radiorev;
955 /* default contention windows size limits */
956 wlc_hw->band->CWmin = APHY_CWMIN;
957 wlc_hw->band->CWmax = PHY_CWMAX;
959 if (!wlc_bmac_attach_dmapio(wlc, j, wme)) {
965 /* disable core to match driver "down" state */
966 wlc_coredisable(wlc_hw);
968 /* Match driver "down" state */
969 if (wlc_hw->sih->bustype == PCI_BUS)
970 si_pci_down(wlc_hw->sih);
972 /* register sb interrupt callback functions */
973 si_register_intr_callback(wlc_hw->sih, (void *)wlc_wlintrsoff,
974 (void *)wlc_wlintrsrestore, NULL, wlc);
976 /* turn off pll and xtal to match driver "down" state */
977 wlc_bmac_xtal(wlc_hw, OFF);
979 /* *********************************************************************
980 * The hardware is in the DOWN state at this point. D11 core
981 * or cores are in reset with clocks off, and the board PLLs
982 * are off if possible.
984 * Beyond this point, wlc->sbclk == false and chip registers
985 * should not be touched.
986 *********************************************************************
989 /* init etheraddr state variables */
990 macaddr = wlc_get_macaddr(wlc_hw);
991 if (macaddr == NULL) {
992 WL_ERROR("wl%d: wlc_bmac_attach: macaddr not found\n", unit);
996 bcm_ether_atoe(macaddr, wlc_hw->etheraddr);
997 if (is_broadcast_ether_addr(wlc_hw->etheraddr) ||
998 is_zero_ether_addr(wlc_hw->etheraddr)) {
999 WL_ERROR("wl%d: wlc_bmac_attach: bad macaddr %s\n",
1005 WL_ERROR("%s:: deviceid 0x%x nbands %d board 0x%x macaddr: %s\n",
1006 __func__, wlc_hw->deviceid, wlc_hw->_nbands,
1007 wlc_hw->sih->boardtype, macaddr);
1012 WL_ERROR("wl%d: wlc_bmac_attach: failed with err %d\n", unit, err);
1017 * Initialize wlc_info default values ...
1018 * may get overrides later in this function
1019 * BMAC_NOTES, move low out and resolve the dangling ones
1021 void wlc_bmac_info_init(struct wlc_hw_info *wlc_hw)
1023 struct wlc_info *wlc = wlc_hw->wlc;
1025 /* set default sw macintmask value */
1026 wlc->defmacintmask = DEF_MACINTMASK;
1028 /* various 802.11g modes */
1029 wlc_hw->shortslot = false;
1031 wlc_hw->SFBL = RETRY_SHORT_FB;
1032 wlc_hw->LFBL = RETRY_LONG_FB;
1034 /* default mac retry limits */
1035 wlc_hw->SRL = RETRY_SHORT_DEF;
1036 wlc_hw->LRL = RETRY_LONG_DEF;
1037 wlc_hw->chanspec = CH20MHZ_CHSPEC(1);
1043 int wlc_bmac_detach(struct wlc_info *wlc)
1047 struct wlc_hw_info *wlc_hw = wlc->hw;
1053 /* detach interrupt sync mechanism since interrupt is disabled and per-port
1054 * interrupt object may has been freed. this must be done before sb core switch
1056 si_deregister_intr_callback(wlc_hw->sih);
1058 if (wlc_hw->sih->bustype == PCI_BUS)
1059 si_pci_sleep(wlc_hw->sih);
1062 wlc_bmac_detach_dmapio(wlc_hw);
1064 band = wlc_hw->band;
1065 for (i = 0; i < NBANDS_HW(wlc_hw); i++) {
1067 /* Detach this band's phy */
1068 wlc_phy_detach(band->pi);
1071 band = wlc_hw->bandstate[OTHERBANDUNIT(wlc)];
1074 /* Free shared phy state */
1075 wlc_phy_shared_detach(wlc_hw->phy_sh);
1077 wlc_phy_shim_detach(wlc_hw->physhim);
1081 kfree(wlc_hw->vars);
1082 wlc_hw->vars = NULL;
1086 si_detach(wlc_hw->sih);
1094 void wlc_bmac_reset(struct wlc_hw_info *wlc_hw)
1096 WL_TRACE("wl%d: wlc_bmac_reset\n", wlc_hw->unit);
1098 WLCNTINCR(wlc_hw->wlc->pub->_cnt->reset);
1100 /* reset the core */
1101 if (!DEVICEREMOVED(wlc_hw->wlc))
1102 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
1104 /* purge the dma rings */
1105 wlc_flushqueues(wlc_hw->wlc);
1107 wlc_reset_bmac_done(wlc_hw->wlc);
1111 wlc_bmac_init(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
1115 struct wlc_info *wlc = wlc_hw->wlc;
1117 WL_TRACE("wl%d: wlc_bmac_init\n", wlc_hw->unit);
1119 /* request FAST clock if not on */
1120 fastclk = wlc_hw->forcefastclk;
1122 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1124 /* disable interrupts */
1125 macintmask = wl_intrsoff(wlc->wl);
1127 /* set up the specified band and chanspec */
1128 wlc_setxband(wlc_hw, CHSPEC_WLCBANDUNIT(chanspec));
1129 wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
1131 /* do one-time phy inits and calibration */
1132 wlc_phy_cal_init(wlc_hw->band->pi);
1134 /* core-specific initialization */
1137 /* suspend the tx fifos and mute the phy for preism cac time */
1139 wlc_bmac_mute(wlc_hw, ON, PHY_MUTE_FOR_PREISM);
1141 /* band-specific inits */
1142 wlc_bmac_bsinit(wlc, chanspec);
1144 /* restore macintmask */
1145 wl_intrsrestore(wlc->wl, macintmask);
1147 /* seed wake_override with WLC_WAKE_OVERRIDE_MACSUSPEND since the mac is suspended
1148 * and wlc_enable_mac() will clear this override bit.
1150 mboolset(wlc_hw->wake_override, WLC_WAKE_OVERRIDE_MACSUSPEND);
1153 * initialize mac_suspend_depth to 1 to match ucode initial suspended state
1155 wlc_hw->mac_suspend_depth = 1;
1157 /* restore the clk */
1159 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1162 int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw)
1166 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1168 ASSERT(wlc_hw->wlc->pub->hw_up && wlc_hw->wlc->macintmask == 0);
1171 * Enable pll and xtal, initialize the power control registers,
1172 * and force fastclock for the remainder of wlc_up().
1174 wlc_bmac_xtal(wlc_hw, ON);
1175 si_clkctl_init(wlc_hw->sih);
1176 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1179 * Configure pci/pcmcia here instead of in wlc_attach()
1180 * to allow mfg hotswap: down, hotswap (chip power cycle), up.
1182 coremask = (1 << wlc_hw->wlc->core->coreidx);
1184 if (wlc_hw->sih->bustype == PCI_BUS)
1185 si_pci_setup(wlc_hw->sih, coremask);
1187 ASSERT(si_coreid(wlc_hw->sih) == D11_CORE_ID);
1190 * Need to read the hwradio status here to cover the case where the system
1191 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
1193 if (wlc_bmac_radio_read_hwdisabled(wlc_hw)) {
1194 /* put SB PCI in down state again */
1195 if (wlc_hw->sih->bustype == PCI_BUS)
1196 si_pci_down(wlc_hw->sih);
1197 wlc_bmac_xtal(wlc_hw, OFF);
1198 return BCME_RADIOOFF;
1201 if (wlc_hw->sih->bustype == PCI_BUS)
1202 si_pci_up(wlc_hw->sih);
1204 /* reset the d11 core */
1205 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
1210 int wlc_bmac_up_finish(struct wlc_hw_info *wlc_hw)
1212 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1215 wlc_phy_hw_state_upd(wlc_hw->band->pi, true);
1217 /* FULLY enable dynamic power control and d11 core interrupt */
1218 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1219 ASSERT(wlc_hw->wlc->macintmask == 0);
1220 wl_intrson(wlc_hw->wlc->wl);
1224 int wlc_bmac_down_prep(struct wlc_hw_info *wlc_hw)
1229 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1234 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
1236 /* disable interrupts */
1238 wlc_hw->wlc->macintmask = 0;
1240 /* now disable interrupts */
1241 wl_intrsoff(wlc_hw->wlc->wl);
1243 /* ensure we're running on the pll clock again */
1244 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1246 /* down phy at the last of this stage */
1247 callbacks += wlc_phy_down(wlc_hw->band->pi);
1252 int wlc_bmac_down_finish(struct wlc_hw_info *wlc_hw)
1257 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1263 wlc_phy_hw_state_upd(wlc_hw->band->pi, false);
1265 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
1268 wlc_hw->sbclk = false;
1269 wlc_hw->clk = false;
1270 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
1272 /* reclaim any posted packets */
1273 wlc_flushqueues(wlc_hw->wlc);
1276 /* Reset and disable the core */
1277 if (si_iscoreup(wlc_hw->sih)) {
1278 if (R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol) &
1280 wlc_suspend_mac_and_wait(wlc_hw->wlc);
1281 callbacks += wl_reset(wlc_hw->wlc->wl);
1282 wlc_coredisable(wlc_hw);
1285 /* turn off primary xtal and pll */
1286 if (!wlc_hw->noreset) {
1287 if (wlc_hw->sih->bustype == PCI_BUS)
1288 si_pci_down(wlc_hw->sih);
1289 wlc_bmac_xtal(wlc_hw, OFF);
1296 void wlc_bmac_wait_for_wake(struct wlc_hw_info *wlc_hw)
1298 if (D11REV_IS(wlc_hw->corerev, 4)) /* no slowclock */
1301 /* delay before first read of ucode state */
1304 /* wait until ucode is no longer asleep */
1305 SPINWAIT((wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) ==
1306 DBGST_ASLEEP), wlc_hw->wlc->fastpwrup_dly);
1309 ASSERT(wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) != DBGST_ASLEEP);
1312 void wlc_bmac_hw_etheraddr(struct wlc_hw_info *wlc_hw, u8 *ea)
1314 bcopy(wlc_hw->etheraddr, ea, ETH_ALEN);
1317 int wlc_bmac_bandtype(struct wlc_hw_info *wlc_hw)
1319 return wlc_hw->band->bandtype;
1322 /* control chip clock to save power, enable dynamic clock or force fast clock */
1323 static void wlc_clkctl_clk(struct wlc_hw_info *wlc_hw, uint mode)
1325 if (PMUCTL_ENAB(wlc_hw->sih)) {
1326 /* new chips with PMU, CCS_FORCEHT will distribute the HT clock on backplane,
1327 * but mac core will still run on ALP(not HT) when it enters powersave mode,
1328 * which means the FCA bit may not be set.
1329 * should wakeup mac if driver wants it to run on HT.
1333 if (mode == CLK_FAST) {
1334 OR_REG(wlc_hw->osh, &wlc_hw->regs->clk_ctl_st,
1342 clk_ctl_st) & CCS_HTAVAIL) == 0),
1343 PMU_MAX_TRANSITION_DLY);
1347 clk_ctl_st) & CCS_HTAVAIL);
1349 if ((wlc_hw->sih->pmurev == 0) &&
1353 clk_ctl_st) & (CCS_FORCEHT | CCS_HTAREQ)))
1357 clk_ctl_st) & CCS_HTAVAIL)
1359 PMU_MAX_TRANSITION_DLY);
1360 AND_REG(wlc_hw->osh, &wlc_hw->regs->clk_ctl_st,
1364 wlc_hw->forcefastclk = (mode == CLK_FAST);
1368 /* old chips w/o PMU, force HT through cc,
1369 * then use FCA to verify mac is running fast clock
1372 wakeup_ucode = D11REV_LT(wlc_hw->corerev, 9);
1374 if (wlc_hw->up && wakeup_ucode)
1375 wlc_ucode_wake_override_set(wlc_hw,
1376 WLC_WAKE_OVERRIDE_CLKCTL);
1378 wlc_hw->forcefastclk = si_clkctl_cc(wlc_hw->sih, mode);
1380 if (D11REV_LT(wlc_hw->corerev, 11)) {
1381 /* ucode WAR for old chips */
1382 if (wlc_hw->forcefastclk)
1383 wlc_bmac_mhf(wlc_hw, MHF1, MHF1_FORCEFASTCLK,
1384 MHF1_FORCEFASTCLK, WLC_BAND_ALL);
1386 wlc_bmac_mhf(wlc_hw, MHF1, MHF1_FORCEFASTCLK, 0,
1390 /* check fast clock is available (if core is not in reset) */
1391 if (D11REV_GT(wlc_hw->corerev, 4) && wlc_hw->forcefastclk
1393 ASSERT(si_core_sflags(wlc_hw->sih, 0, 0) & SISF_FCLKA);
1395 /* keep the ucode wake bit on if forcefastclk is on
1396 * since we do not want ucode to put us back to slow clock
1397 * when it dozes for PM mode.
1398 * Code below matches the wake override bit with current forcefastclk state
1399 * Only setting bit in wake_override instead of waking ucode immediately
1400 * since old code (wlc.c 1.4499) had this behavior. Older code set
1401 * wlc->forcefastclk but only had the wake happen if the wakup_ucode work
1402 * (protected by an up check) was executed just below.
1404 if (wlc_hw->forcefastclk)
1405 mboolset(wlc_hw->wake_override,
1406 WLC_WAKE_OVERRIDE_FORCEFAST);
1408 mboolclr(wlc_hw->wake_override,
1409 WLC_WAKE_OVERRIDE_FORCEFAST);
1411 /* ok to clear the wakeup now */
1412 if (wlc_hw->up && wakeup_ucode)
1413 wlc_ucode_wake_override_clear(wlc_hw,
1414 WLC_WAKE_OVERRIDE_CLKCTL);
1418 /* set initial host flags value */
1420 wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init)
1422 struct wlc_hw_info *wlc_hw = wlc->hw;
1424 memset(mhfs, 0, MHFMAX * sizeof(u16));
1426 mhfs[MHF2] |= mhf2_init;
1428 /* prohibit use of slowclock on multifunction boards */
1429 if (wlc_hw->boardflags & BFL_NOPLLDOWN)
1430 mhfs[MHF1] |= MHF1_FORCEFASTCLK;
1432 if (WLCISNPHY(wlc_hw->band) && NREV_LT(wlc_hw->band->phyrev, 2)) {
1433 mhfs[MHF2] |= MHF2_NPHY40MHZ_WAR;
1434 mhfs[MHF1] |= MHF1_IQSWAP_WAR;
1438 /* set or clear ucode host flag bits
1439 * it has an optimization for no-change write
1440 * it only writes through shared memory when the core has clock;
1441 * pre-CLK changes should use wlc_write_mhf to get around the optimization
1444 * bands values are: WLC_BAND_AUTO <--- Current band only
1445 * WLC_BAND_5G <--- 5G band only
1446 * WLC_BAND_2G <--- 2G band only
1447 * WLC_BAND_ALL <--- All bands
1450 wlc_bmac_mhf(struct wlc_hw_info *wlc_hw, u8 idx, u16 mask, u16 val,
1454 u16 addr[MHFMAX] = {
1455 M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
1460 ASSERT((val & ~mask) == 0);
1461 ASSERT(idx < MHFMAX);
1462 ASSERT(ARRAY_SIZE(addr) == MHFMAX);
1465 /* Current band only or all bands,
1466 * then set the band to current band
1470 band = wlc_hw->band;
1473 band = wlc_hw->bandstate[BAND_5G_INDEX];
1476 band = wlc_hw->bandstate[BAND_2G_INDEX];
1484 save = band->mhfs[idx];
1485 band->mhfs[idx] = (band->mhfs[idx] & ~mask) | val;
1487 /* optimization: only write through if changed, and
1488 * changed band is the current band
1490 if (wlc_hw->clk && (band->mhfs[idx] != save)
1491 && (band == wlc_hw->band))
1492 wlc_bmac_write_shm(wlc_hw, addr[idx],
1493 (u16) band->mhfs[idx]);
1496 if (bands == WLC_BAND_ALL) {
1497 wlc_hw->bandstate[0]->mhfs[idx] =
1498 (wlc_hw->bandstate[0]->mhfs[idx] & ~mask) | val;
1499 wlc_hw->bandstate[1]->mhfs[idx] =
1500 (wlc_hw->bandstate[1]->mhfs[idx] & ~mask) | val;
1504 u16 wlc_bmac_mhf_get(struct wlc_hw_info *wlc_hw, u8 idx, int bands)
1507 ASSERT(idx < MHFMAX);
1511 band = wlc_hw->band;
1514 band = wlc_hw->bandstate[BAND_5G_INDEX];
1517 band = wlc_hw->bandstate[BAND_2G_INDEX];
1527 return band->mhfs[idx];
1530 static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs)
1534 M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
1538 ASSERT(ARRAY_SIZE(addr) == MHFMAX);
1540 for (idx = 0; idx < MHFMAX; idx++) {
1541 wlc_bmac_write_shm(wlc_hw, addr[idx], mhfs[idx]);
1545 /* set the maccontrol register to desired reset state and
1546 * initialize the sw cache of the register
1548 static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw)
1550 /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
1551 wlc_hw->maccontrol = 0;
1552 wlc_hw->suspended_fifos = 0;
1553 wlc_hw->wake_override = 0;
1554 wlc_hw->mute_override = 0;
1555 wlc_bmac_mctrl(wlc_hw, ~0, MCTL_IHR_EN | MCTL_WAKE);
1558 /* set or clear maccontrol bits */
1559 void wlc_bmac_mctrl(struct wlc_hw_info *wlc_hw, u32 mask, u32 val)
1564 ASSERT((val & ~mask) == 0);
1566 maccontrol = wlc_hw->maccontrol;
1567 new_maccontrol = (maccontrol & ~mask) | val;
1569 /* if the new maccontrol value is the same as the old, nothing to do */
1570 if (new_maccontrol == maccontrol)
1573 /* something changed, cache the new value */
1574 wlc_hw->maccontrol = new_maccontrol;
1576 /* write the new values with overrides applied */
1577 wlc_mctrl_write(wlc_hw);
1580 /* write the software state of maccontrol and overrides to the maccontrol register */
1581 static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw)
1583 u32 maccontrol = wlc_hw->maccontrol;
1585 /* OR in the wake bit if overridden */
1586 if (wlc_hw->wake_override)
1587 maccontrol |= MCTL_WAKE;
1589 /* set AP and INFRA bits for mute if needed */
1590 if (wlc_hw->mute_override) {
1591 maccontrol &= ~(MCTL_AP);
1592 maccontrol |= MCTL_INFRA;
1595 W_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol, maccontrol);
1598 void wlc_ucode_wake_override_set(struct wlc_hw_info *wlc_hw, u32 override_bit)
1600 ASSERT((wlc_hw->wake_override & override_bit) == 0);
1602 if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) {
1603 mboolset(wlc_hw->wake_override, override_bit);
1607 mboolset(wlc_hw->wake_override, override_bit);
1609 wlc_mctrl_write(wlc_hw);
1610 wlc_bmac_wait_for_wake(wlc_hw);
1615 void wlc_ucode_wake_override_clear(struct wlc_hw_info *wlc_hw, u32 override_bit)
1617 ASSERT(wlc_hw->wake_override & override_bit);
1619 mboolclr(wlc_hw->wake_override, override_bit);
1621 if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE))
1624 wlc_mctrl_write(wlc_hw);
1629 /* When driver needs ucode to stop beaconing, it has to make sure that
1630 * MCTL_AP is clear and MCTL_INFRA is set
1631 * Mode MCTL_AP MCTL_INFRA
1633 * STA 0 1 <--- This will ensure no beacons
1636 static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw)
1638 wlc_hw->mute_override = 1;
1640 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1641 * override, then there is no change to write
1643 if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
1646 wlc_mctrl_write(wlc_hw);
1651 /* Clear the override on AP and INFRA bits */
1652 static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw)
1654 if (wlc_hw->mute_override == 0)
1657 wlc_hw->mute_override = 0;
1659 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1660 * override, then there is no change to write
1662 if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
1665 wlc_mctrl_write(wlc_hw);
1669 * Write a MAC address to the rcmta structure
1672 wlc_bmac_set_rcmta(struct wlc_hw_info *wlc_hw, int idx,
1675 d11regs_t *regs = wlc_hw->regs;
1676 volatile u16 *objdata16 = (volatile u16 *)®s->objdata;
1679 struct osl_info *osh;
1681 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
1683 ASSERT(wlc_hw->corerev > 4);
1686 (addr[3] << 24) | (addr[2] << 16) |
1687 (addr[1] << 8) | addr[0];
1688 mac_l = (addr[5] << 8) | addr[4];
1692 W_REG(osh, ®s->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2)));
1693 (void)R_REG(osh, ®s->objaddr);
1694 W_REG(osh, ®s->objdata, mac_hm);
1695 W_REG(osh, ®s->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1)));
1696 (void)R_REG(osh, ®s->objaddr);
1697 W_REG(osh, objdata16, mac_l);
1701 * Write a MAC address to the given match reg offset in the RXE match engine.
1704 wlc_bmac_set_addrmatch(struct wlc_hw_info *wlc_hw, int match_reg_offset,
1711 struct osl_info *osh;
1713 WL_TRACE("wl%d: wlc_bmac_set_addrmatch\n", wlc_hw->unit);
1715 ASSERT((match_reg_offset < RCM_SIZE) || (wlc_hw->corerev == 4));
1717 regs = wlc_hw->regs;
1718 mac_l = addr[0] | (addr[1] << 8);
1719 mac_m = addr[2] | (addr[3] << 8);
1720 mac_h = addr[4] | (addr[5] << 8);
1724 /* enter the MAC addr into the RXE match registers */
1725 W_REG(osh, ®s->rcm_ctl, RCM_INC_DATA | match_reg_offset);
1726 W_REG(osh, ®s->rcm_mat_data, mac_l);
1727 W_REG(osh, ®s->rcm_mat_data, mac_m);
1728 W_REG(osh, ®s->rcm_mat_data, mac_h);
1733 wlc_bmac_write_template_ram(struct wlc_hw_info *wlc_hw, int offset, int len,
1740 volatile u16 *dptr = NULL;
1741 #endif /* IL_BIGENDIAN */
1742 struct osl_info *osh;
1744 WL_TRACE("wl%d: wlc_bmac_write_template_ram\n", wlc_hw->unit);
1746 regs = wlc_hw->regs;
1749 ASSERT(IS_ALIGNED(offset, sizeof(u32)));
1750 ASSERT(IS_ALIGNED(len, sizeof(u32)));
1751 ASSERT((offset & ~0xffff) == 0);
1753 W_REG(osh, ®s->tplatewrptr, offset);
1755 /* if MCTL_BIGEND bit set in mac control register,
1756 * the chip swaps data in fifo, as well as data in
1759 be_bit = (R_REG(osh, ®s->maccontrol) & MCTL_BIGEND) != 0;
1762 bcopy((u8 *) buf, &word, sizeof(u32));
1765 word = hton32(word);
1767 word = htol32(word);
1769 W_REG(osh, ®s->tplatewrdata, word);
1771 buf = (u8 *) buf + sizeof(u32);
1776 void wlc_bmac_set_cwmin(struct wlc_hw_info *wlc_hw, u16 newmin)
1778 struct osl_info *osh;
1781 wlc_hw->band->CWmin = newmin;
1783 W_REG(osh, &wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMIN);
1784 (void)R_REG(osh, &wlc_hw->regs->objaddr);
1785 W_REG(osh, &wlc_hw->regs->objdata, newmin);
1788 void wlc_bmac_set_cwmax(struct wlc_hw_info *wlc_hw, u16 newmax)
1790 struct osl_info *osh;
1793 wlc_hw->band->CWmax = newmax;
1795 W_REG(osh, &wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMAX);
1796 (void)R_REG(osh, &wlc_hw->regs->objaddr);
1797 W_REG(osh, &wlc_hw->regs->objdata, newmax);
1800 void wlc_bmac_bw_set(struct wlc_hw_info *wlc_hw, u16 bw)
1805 /* request FAST clock if not on */
1806 fastclk = wlc_hw->forcefastclk;
1808 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1810 wlc_phy_bw_state_set(wlc_hw->band->pi, bw);
1812 ASSERT(wlc_hw->clk);
1813 if (D11REV_LT(wlc_hw->corerev, 17))
1814 tmp = R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol);
1816 wlc_bmac_phy_reset(wlc_hw);
1817 wlc_phy_init(wlc_hw->band->pi, wlc_phy_chanspec_get(wlc_hw->band->pi));
1819 /* restore the clk */
1821 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1825 wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn, int len)
1827 d11regs_t *regs = wlc_hw->regs;
1829 wlc_bmac_write_template_ram(wlc_hw, T_BCN0_TPL_BASE, (len + 3) & ~3,
1831 /* write beacon length to SCR */
1832 ASSERT(len < 65536);
1833 wlc_bmac_write_shm(wlc_hw, M_BCN0_FRM_BYTESZ, (u16) len);
1834 /* mark beacon0 valid */
1835 OR_REG(wlc_hw->osh, ®s->maccommand, MCMD_BCN0VLD);
1839 wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn, int len)
1841 d11regs_t *regs = wlc_hw->regs;
1843 wlc_bmac_write_template_ram(wlc_hw, T_BCN1_TPL_BASE, (len + 3) & ~3,
1845 /* write beacon length to SCR */
1846 ASSERT(len < 65536);
1847 wlc_bmac_write_shm(wlc_hw, M_BCN1_FRM_BYTESZ, (u16) len);
1848 /* mark beacon1 valid */
1849 OR_REG(wlc_hw->osh, ®s->maccommand, MCMD_BCN1VLD);
1852 /* mac is assumed to be suspended at this point */
1854 wlc_bmac_write_hw_bcntemplates(struct wlc_hw_info *wlc_hw, void *bcn, int len,
1857 d11regs_t *regs = wlc_hw->regs;
1860 wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
1861 wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
1864 if (!(R_REG(wlc_hw->osh, ®s->maccommand) & MCMD_BCN0VLD))
1865 wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
1868 (R_REG(wlc_hw->osh, ®s->maccommand) & MCMD_BCN1VLD))
1869 wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
1870 else /* one template should always have been available */
1875 static void WLBANDINITFN(wlc_bmac_upd_synthpu) (struct wlc_hw_info *wlc_hw)
1878 struct wlc_info *wlc = wlc_hw->wlc;
1879 /* update SYNTHPU_DLY */
1881 if (WLCISLCNPHY(wlc->band)) {
1882 v = SYNTHPU_DLY_LPPHY_US;
1883 } else if (WLCISNPHY(wlc->band) && (NREV_GE(wlc->band->phyrev, 3))) {
1884 v = SYNTHPU_DLY_NPHY_US;
1886 v = SYNTHPU_DLY_BPHY_US;
1889 wlc_bmac_write_shm(wlc_hw, M_SYNTHPU_DLY, v);
1892 /* band-specific init */
1894 WLBANDINITFN(wlc_bmac_bsinit) (struct wlc_info *wlc, chanspec_t chanspec)
1896 struct wlc_hw_info *wlc_hw = wlc->hw;
1898 WL_TRACE("wl%d: wlc_bmac_bsinit: bandunit %d\n",
1899 wlc_hw->unit, wlc_hw->band->bandunit);
1902 if (PHY_TYPE(R_REG(wlc_hw->osh, &wlc_hw->regs->phyversion)) !=
1905 PHY_TYPE(R_REG(wlc_hw->osh, &wlc_hw->regs->phyversion))
1906 == wlc_hw->band->phytype);
1908 wlc_ucode_bsinit(wlc_hw);
1910 wlc_phy_init(wlc_hw->band->pi, chanspec);
1912 wlc_ucode_txant_set(wlc_hw);
1914 /* cwmin is band-specific, update hardware with value for current band */
1915 wlc_bmac_set_cwmin(wlc_hw, wlc_hw->band->CWmin);
1916 wlc_bmac_set_cwmax(wlc_hw, wlc_hw->band->CWmax);
1918 wlc_bmac_update_slot_timing(wlc_hw,
1919 BAND_5G(wlc_hw->band->
1920 bandtype) ? true : wlc_hw->
1923 /* write phytype and phyvers */
1924 wlc_bmac_write_shm(wlc_hw, M_PHYTYPE, (u16) wlc_hw->band->phytype);
1925 wlc_bmac_write_shm(wlc_hw, M_PHYVER, (u16) wlc_hw->band->phyrev);
1927 /* initialize the txphyctl1 rate table since shmem is shared between bands */
1928 wlc_upd_ofdm_pctl1_table(wlc_hw);
1930 wlc_bmac_upd_synthpu(wlc_hw);
1933 void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk)
1935 WL_TRACE("wl%d: wlc_bmac_core_phy_clk: clk %d\n", wlc_hw->unit, clk);
1937 wlc_hw->phyclk = clk;
1939 if (OFF == clk) { /* clear gmode bit, put phy into reset */
1941 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC | SICF_GMODE),
1942 (SICF_PRST | SICF_FGC));
1944 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_PRST);
1947 } else { /* take phy out of reset */
1949 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_FGC);
1951 si_core_cflags(wlc_hw->sih, (SICF_FGC), 0);
1957 /* Perform a soft reset of the PHY PLL */
1958 void wlc_bmac_core_phypll_reset(struct wlc_hw_info *wlc_hw)
1960 WL_TRACE("wl%d: wlc_bmac_core_phypll_reset\n", wlc_hw->unit);
1962 si_corereg(wlc_hw->sih, SI_CC_IDX,
1963 offsetof(chipcregs_t, chipcontrol_addr), ~0, 0);
1965 si_corereg(wlc_hw->sih, SI_CC_IDX,
1966 offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
1968 si_corereg(wlc_hw->sih, SI_CC_IDX,
1969 offsetof(chipcregs_t, chipcontrol_data), 0x4, 4);
1971 si_corereg(wlc_hw->sih, SI_CC_IDX,
1972 offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
1976 /* light way to turn on phy clock without reset for NPHY only
1977 * refer to wlc_bmac_core_phy_clk for full version
1979 void wlc_bmac_phyclk_fgc(struct wlc_hw_info *wlc_hw, bool clk)
1981 /* support(necessary for NPHY and HYPHY) only */
1982 if (!WLCISNPHY(wlc_hw->band))
1986 si_core_cflags(wlc_hw->sih, SICF_FGC, SICF_FGC);
1988 si_core_cflags(wlc_hw->sih, SICF_FGC, 0);
1992 void wlc_bmac_macphyclk_set(struct wlc_hw_info *wlc_hw, bool clk)
1995 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE);
1997 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0);
2000 void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw)
2002 wlc_phy_t *pih = wlc_hw->band->pi;
2004 bool phy_in_reset = false;
2006 WL_TRACE("wl%d: wlc_bmac_phy_reset\n", wlc_hw->unit);
2011 phy_bw_clkbits = wlc_phy_clk_bwbits(wlc_hw->band->pi);
2013 /* Specfic reset sequence required for NPHY rev 3 and 4 */
2014 if (WLCISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) &&
2015 NREV_LE(wlc_hw->band->phyrev, 4)) {
2016 /* Set the PHY bandwidth */
2017 si_core_cflags(wlc_hw->sih, SICF_BWMASK, phy_bw_clkbits);
2021 /* Perform a soft reset of the PHY PLL */
2022 wlc_bmac_core_phypll_reset(wlc_hw);
2025 si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_PCLKE),
2026 (SICF_PRST | SICF_PCLKE));
2027 phy_in_reset = true;
2030 si_core_cflags(wlc_hw->sih,
2031 (SICF_PRST | SICF_PCLKE | SICF_BWMASK),
2032 (SICF_PRST | SICF_PCLKE | phy_bw_clkbits));
2036 wlc_bmac_core_phy_clk(wlc_hw, ON);
2039 wlc_phy_anacore(pih, ON);
2042 /* switch to and initialize new band */
2044 WLBANDINITFN(wlc_bmac_setband) (struct wlc_hw_info *wlc_hw, uint bandunit,
2045 chanspec_t chanspec) {
2046 struct wlc_info *wlc = wlc_hw->wlc;
2049 ASSERT(NBANDS_HW(wlc_hw) > 1);
2050 ASSERT(bandunit != wlc_hw->band->bandunit);
2052 /* Enable the d11 core before accessing it */
2053 if (!si_iscoreup(wlc_hw->sih)) {
2054 si_core_reset(wlc_hw->sih, 0, 0);
2055 ASSERT(si_iscoreup(wlc_hw->sih));
2056 wlc_mctrl_reset(wlc_hw);
2059 macintmask = wlc_setband_inact(wlc, bandunit);
2064 wlc_bmac_core_phy_clk(wlc_hw, ON);
2066 /* band-specific initializations */
2067 wlc_bmac_bsinit(wlc, chanspec);
2070 * If there are any pending software interrupt bits,
2071 * then replace these with a harmless nonzero value
2072 * so wlc_dpc() will re-enable interrupts when done.
2074 if (wlc->macintstatus)
2075 wlc->macintstatus = MI_DMAINT;
2077 /* restore macintmask */
2078 wl_intrsrestore(wlc->wl, macintmask);
2080 /* ucode should still be suspended.. */
2081 ASSERT((R_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol) & MCTL_EN_MAC) ==
2085 /* low-level band switch utility routine */
2086 void WLBANDINITFN(wlc_setxband) (struct wlc_hw_info *wlc_hw, uint bandunit)
2088 WL_TRACE("wl%d: wlc_setxband: bandunit %d\n", wlc_hw->unit, bandunit);
2090 wlc_hw->band = wlc_hw->bandstate[bandunit];
2092 /* BMAC_NOTE: until we eliminate need for wlc->band refs in low level code */
2093 wlc_hw->wlc->band = wlc_hw->wlc->bandstate[bandunit];
2095 /* set gmode core flag */
2096 if (wlc_hw->sbclk && !wlc_hw->noreset) {
2097 si_core_cflags(wlc_hw->sih, SICF_GMODE,
2098 ((bandunit == 0) ? SICF_GMODE : 0));
2102 static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw)
2105 /* reject unsupported corerev */
2106 if (!VALID_COREREV(wlc_hw->corerev)) {
2107 WL_ERROR("unsupported core rev %d\n", wlc_hw->corerev);
2114 static bool wlc_validboardtype(struct wlc_hw_info *wlc_hw)
2116 bool goodboard = true;
2117 uint boardrev = wlc_hw->boardrev;
2121 else if (boardrev > 0xff) {
2122 uint brt = (boardrev & 0xf000) >> 12;
2123 uint b0 = (boardrev & 0xf00) >> 8;
2124 uint b1 = (boardrev & 0xf0) >> 4;
2125 uint b2 = boardrev & 0xf;
2127 if ((brt > 2) || (brt == 0) || (b0 > 9) || (b0 == 0) || (b1 > 9)
2132 if (wlc_hw->sih->boardvendor != VENDOR_BROADCOM)
2138 static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw)
2140 const char *varname = "macaddr";
2143 /* If macaddr exists, use it (Sromrev4, CIS, ...). */
2144 macaddr = getvar(wlc_hw->vars, varname);
2145 if (macaddr != NULL)
2148 if (NBANDS_HW(wlc_hw) > 1)
2149 varname = "et1macaddr";
2151 varname = "il0macaddr";
2153 macaddr = getvar(wlc_hw->vars, varname);
2154 if (macaddr == NULL) {
2155 WL_ERROR("wl%d: wlc_get_macaddr: macaddr getvar(%s) not found\n",
2156 wlc_hw->unit, varname);
2163 * Return true if radio is disabled, otherwise false.
2164 * hw radio disable signal is an external pin, users activate it asynchronously
2165 * this function could be called when driver is down and w/o clock
2166 * it operates on different registers depending on corerev and boardflag.
2168 bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info *wlc_hw)
2171 u32 resetbits = 0, flags = 0;
2173 xtal = wlc_hw->sbclk;
2175 wlc_bmac_xtal(wlc_hw, ON);
2177 /* may need to take core out of reset first */
2180 if (D11REV_LE(wlc_hw->corerev, 11))
2181 resetbits |= SICF_PCLKE;
2184 * corerev >= 18, mac no longer enables phyclk automatically when driver accesses
2185 * phyreg throughput mac. This can be skipped since only mac reg is accessed below
2187 if (D11REV_GE(wlc_hw->corerev, 18))
2188 flags |= SICF_PCLKE;
2190 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2191 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2192 (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
2193 (wlc_hw->sih->chip == BCM43421_CHIP_ID))
2195 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID,
2197 si_core_reset(wlc_hw->sih, flags, resetbits);
2198 wlc_mctrl_reset(wlc_hw);
2201 v = ((R_REG(wlc_hw->osh, &wlc_hw->regs->phydebug) & PDBG_RFD) != 0);
2203 /* put core back into reset */
2205 si_core_disable(wlc_hw->sih, 0);
2208 wlc_bmac_xtal(wlc_hw, OFF);
2213 /* Initialize just the hardware when coming out of POR or S3/S5 system states */
2214 void wlc_bmac_hw_up(struct wlc_hw_info *wlc_hw)
2216 if (wlc_hw->wlc->pub->hw_up)
2219 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
2222 * Enable pll and xtal, initialize the power control registers,
2223 * and force fastclock for the remainder of wlc_up().
2225 wlc_bmac_xtal(wlc_hw, ON);
2226 si_clkctl_init(wlc_hw->sih);
2227 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2229 if (wlc_hw->sih->bustype == PCI_BUS) {
2230 si_pci_fixcfg(wlc_hw->sih);
2232 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2233 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2234 (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
2235 (wlc_hw->sih->chip == BCM43421_CHIP_ID))
2237 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID,
2241 /* Inform phy that a POR reset has occurred so it does a complete phy init */
2242 wlc_phy_por_inform(wlc_hw->band->pi);
2244 wlc_hw->ucode_loaded = false;
2245 wlc_hw->wlc->pub->hw_up = true;
2247 if ((wlc_hw->boardflags & BFL_FEM)
2248 && (wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
2250 (wlc_hw->boardrev >= 0x1250
2251 && (wlc_hw->boardflags & BFL_FEM_BT)))
2252 si_epa_4313war(wlc_hw->sih);
2256 static bool wlc_dma_rxreset(struct wlc_hw_info *wlc_hw, uint fifo)
2258 struct hnddma_pub *di = wlc_hw->di[fifo];
2259 struct osl_info *osh;
2261 if (D11REV_LT(wlc_hw->corerev, 12)) {
2263 u16 rcv_frm_cnt = 0;
2267 W_REG(osh, &wlc_hw->regs->rcv_fifo_ctl, fifo << 8);
2268 SPINWAIT((!(rxidle = dma_rxidle(di))) &&
2270 R_REG(osh, &wlc_hw->regs->rcv_frm_cnt)) != 0),
2273 if (!rxidle && (rcv_frm_cnt != 0))
2274 WL_ERROR("wl%d: %s: rxdma[%d] not idle && rcv_frm_cnt(%d) not zero\n",
2275 wlc_hw->unit, __func__, fifo, rcv_frm_cnt);
2279 return dma_rxreset(di);
2283 * ensure fask clock during reset
2285 * reset d11(out of reset)
2286 * reset phy(out of reset)
2287 * clear software macintstatus for fresh new start
2288 * one testing hack wlc_hw->noreset will bypass the d11/phy reset
2290 void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags)
2297 if (flags == WLC_USE_COREFLAGS)
2298 flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0);
2300 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
2302 regs = wlc_hw->regs;
2304 /* request FAST clock if not on */
2305 fastclk = wlc_hw->forcefastclk;
2307 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2309 /* reset the dma engines except first time thru */
2310 if (si_iscoreup(wlc_hw->sih)) {
2311 for (i = 0; i < NFIFO; i++)
2312 if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) {
2313 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
2314 wlc_hw->unit, __func__, i);
2317 if ((wlc_hw->di[RX_FIFO])
2318 && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) {
2319 WL_ERROR("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n",
2320 wlc_hw->unit, __func__, RX_FIFO);
2322 if (D11REV_IS(wlc_hw->corerev, 4)
2323 && wlc_hw->di[RX_TXSTATUS_FIFO]
2324 && (!wlc_dma_rxreset(wlc_hw, RX_TXSTATUS_FIFO))) {
2325 WL_ERROR("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n",
2326 wlc_hw->unit, __func__, RX_TXSTATUS_FIFO);
2329 /* if noreset, just stop the psm and return */
2330 if (wlc_hw->noreset) {
2331 wlc_hw->wlc->macintstatus = 0; /* skip wl_dpc after down */
2332 wlc_bmac_mctrl(wlc_hw, MCTL_PSM_RUN | MCTL_EN_MAC, 0);
2336 if (D11REV_LE(wlc_hw->corerev, 11))
2337 resetbits |= SICF_PCLKE;
2340 * corerev >= 18, mac no longer enables phyclk automatically when driver accesses phyreg
2341 * throughput mac, AND phy_reset is skipped at early stage when band->pi is invalid
2342 * need to enable PHY CLK
2344 if (D11REV_GE(wlc_hw->corerev, 18))
2345 flags |= SICF_PCLKE;
2348 * In chips with PMU, the fastclk request goes through d11 core reg 0x1e0, which
2349 * is cleared by the core_reset. have to re-request it.
2350 * This adds some delay and we can optimize it by also requesting fastclk through
2351 * chipcommon during this period if necessary. But that has to work coordinate
2352 * with other driver like mips/arm since they may touch chipcommon as well.
2354 wlc_hw->clk = false;
2355 si_core_reset(wlc_hw->sih, flags, resetbits);
2357 if (wlc_hw->band && wlc_hw->band->pi)
2358 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true);
2360 wlc_mctrl_reset(wlc_hw);
2362 if (PMUCTL_ENAB(wlc_hw->sih))
2363 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2365 wlc_bmac_phy_reset(wlc_hw);
2367 /* turn on PHY_PLL */
2368 wlc_bmac_core_phypll_ctl(wlc_hw, true);
2370 /* clear sw intstatus */
2371 wlc_hw->wlc->macintstatus = 0;
2373 /* restore the clk setting */
2375 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
2378 /* If the ucode that supports corerev 5 is used for corerev 9 and above,
2379 * txfifo sizes needs to be modified(increased) since the newer cores
2382 static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw)
2384 d11regs_t *regs = wlc_hw->regs;
2386 u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk;
2387 u16 txfifo_def, txfifo_def1;
2389 struct osl_info *osh;
2391 if (D11REV_LT(wlc_hw->corerev, 9))
2394 /* tx fifos start at TXFIFO_START_BLK from the Base address */
2395 txfifo_startblk = TXFIFO_START_BLK;
2399 /* sequence of operations: reset fifo, set fifo size, reset fifo */
2400 for (fifo_nu = 0; fifo_nu < NFIFO; fifo_nu++) {
2402 txfifo_endblk = txfifo_startblk + wlc_hw->xmtfifo_sz[fifo_nu];
2403 txfifo_def = (txfifo_startblk & 0xff) |
2404 (((txfifo_endblk - 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT);
2405 txfifo_def1 = ((txfifo_startblk >> 8) & 0x1) |
2407 1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT);
2409 TXFIFOCMD_RESET_MASK | (fifo_nu << TXFIFOCMD_FIFOSEL_SHIFT);
2411 W_REG(osh, ®s->xmtfifocmd, txfifo_cmd);
2412 W_REG(osh, ®s->xmtfifodef, txfifo_def);
2413 if (D11REV_GE(wlc_hw->corerev, 16))
2414 W_REG(osh, ®s->xmtfifodef1, txfifo_def1);
2416 W_REG(osh, ®s->xmtfifocmd, txfifo_cmd);
2418 txfifo_startblk += wlc_hw->xmtfifo_sz[fifo_nu];
2421 /* need to propagate to shm location to be in sync since ucode/hw won't do this */
2422 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE0,
2423 wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]);
2424 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE1,
2425 wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]);
2426 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE2,
2427 ((wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO] << 8) | wlc_hw->
2428 xmtfifo_sz[TX_AC_BK_FIFO]));
2429 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE3,
2430 ((wlc_hw->xmtfifo_sz[TX_ATIM_FIFO] << 8) | wlc_hw->
2431 xmtfifo_sz[TX_BCMC_FIFO]));
2436 * download ucode/PCM
2437 * let ucode run to suspended
2438 * download ucode inits
2439 * config other core registers
2442 static void wlc_coreinit(struct wlc_info *wlc)
2444 struct wlc_hw_info *wlc_hw = wlc->hw;
2449 bool fifosz_fixup = false;
2450 struct osl_info *osh;
2454 regs = wlc_hw->regs;
2457 WL_TRACE("wl%d: wlc_coreinit\n", wlc_hw->unit);
2460 wlc_bmac_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE));
2462 wlc_ucode_download(wlc_hw);
2465 * 1) core5-9 use ucode 5 to save space since the PSM is the same
2466 * 2) newer chips, driver wants to controls the fifo allocation
2468 if (D11REV_GE(wlc_hw->corerev, 4))
2469 fifosz_fixup = true;
2471 /* let the PSM run to the suspended state, set mode to BSS STA */
2472 W_REG(osh, ®s->macintstatus, -1);
2473 wlc_bmac_mctrl(wlc_hw, ~0,
2474 (MCTL_IHR_EN | MCTL_INFRA | MCTL_PSM_RUN | MCTL_WAKE));
2476 /* wait for ucode to self-suspend after auto-init */
2477 SPINWAIT(((R_REG(osh, ®s->macintstatus) & MI_MACSSPNDD) == 0),
2479 if ((R_REG(osh, ®s->macintstatus) & MI_MACSSPNDD) == 0)
2480 WL_ERROR("wl%d: wlc_coreinit: ucode did not self-suspend!\n",
2485 sflags = si_core_sflags(wlc_hw->sih, 0, 0);
2487 if (D11REV_IS(wlc_hw->corerev, 23)) {
2488 if (WLCISNPHY(wlc_hw->band))
2489 wlc_write_inits(wlc_hw, d11n0initvals16);
2491 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2492 __func__, wlc_hw->unit, wlc_hw->corerev);
2493 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2494 if (WLCISLCNPHY(wlc_hw->band)) {
2495 wlc_write_inits(wlc_hw, d11lcn0initvals24);
2497 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2498 __func__, wlc_hw->unit, wlc_hw->corerev);
2501 WL_ERROR("%s: wl%d: unsupported corerev %d\n",
2502 __func__, wlc_hw->unit, wlc_hw->corerev);
2505 /* For old ucode, txfifo sizes needs to be modified(increased) for Corerev >= 9 */
2506 if (fifosz_fixup == true) {
2507 wlc_corerev_fifofixup(wlc_hw);
2510 /* check txfifo allocations match between ucode and driver */
2511 buf[TX_AC_BE_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE0);
2512 if (buf[TX_AC_BE_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]) {
2516 buf[TX_AC_VI_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE1);
2517 if (buf[TX_AC_VI_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]) {
2521 buf[TX_AC_BK_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE2);
2522 buf[TX_AC_VO_FIFO] = (buf[TX_AC_BK_FIFO] >> 8) & 0xff;
2523 buf[TX_AC_BK_FIFO] &= 0xff;
2524 if (buf[TX_AC_BK_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BK_FIFO]) {
2528 if (buf[TX_AC_VO_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO]) {
2532 buf[TX_BCMC_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE3);
2533 buf[TX_ATIM_FIFO] = (buf[TX_BCMC_FIFO] >> 8) & 0xff;
2534 buf[TX_BCMC_FIFO] &= 0xff;
2535 if (buf[TX_BCMC_FIFO] != wlc_hw->xmtfifo_sz[TX_BCMC_FIFO]) {
2539 if (buf[TX_ATIM_FIFO] != wlc_hw->xmtfifo_sz[TX_ATIM_FIFO]) {
2544 WL_ERROR("wlc_coreinit: txfifo mismatch: ucode size %d driver size %d index %d\n",
2545 buf[i], wlc_hw->xmtfifo_sz[i], i);
2546 /* DO NOT ASSERT corerev < 4 even there is a mismatch
2547 * shmem, since driver don't overwrite those chip and
2548 * ucode initialize data will be used.
2550 if (D11REV_GE(wlc_hw->corerev, 4))
2554 /* make sure we can still talk to the mac */
2555 ASSERT(R_REG(osh, ®s->maccontrol) != 0xffffffff);
2557 /* band-specific inits done by wlc_bsinit() */
2559 /* Set up frame burst size and antenna swap threshold init values */
2560 wlc_bmac_write_shm(wlc_hw, M_MBURST_SIZE, MAXTXFRAMEBURST);
2561 wlc_bmac_write_shm(wlc_hw, M_MAX_ANTCNT, ANTCNT);
2563 /* enable one rx interrupt per received frame */
2564 W_REG(osh, ®s->intrcvlazy[0], (1 << IRL_FC_SHIFT));
2565 if (D11REV_IS(wlc_hw->corerev, 4))
2566 W_REG(osh, ®s->intrcvlazy[3], (1 << IRL_FC_SHIFT));
2568 /* set the station mode (BSS STA) */
2569 wlc_bmac_mctrl(wlc_hw,
2570 (MCTL_INFRA | MCTL_DISCARD_PMQ | MCTL_AP),
2571 (MCTL_INFRA | MCTL_DISCARD_PMQ));
2573 /* set up Beacon interval */
2574 bcnint_us = 0x8000 << 10;
2575 W_REG(osh, ®s->tsf_cfprep, (bcnint_us << CFPREP_CBI_SHIFT));
2576 W_REG(osh, ®s->tsf_cfpstart, bcnint_us);
2577 W_REG(osh, ®s->macintstatus, MI_GP1);
2579 /* write interrupt mask */
2580 W_REG(osh, ®s->intctrlregs[RX_FIFO].intmask, DEF_RXINTMASK);
2581 if (D11REV_IS(wlc_hw->corerev, 4))
2582 W_REG(osh, ®s->intctrlregs[RX_TXSTATUS_FIFO].intmask,
2585 /* allow the MAC to control the PHY clock (dynamic on/off) */
2586 wlc_bmac_macphyclk_set(wlc_hw, ON);
2588 /* program dynamic clock control fast powerup delay register */
2589 if (D11REV_GT(wlc_hw->corerev, 4)) {
2590 wlc->fastpwrup_dly = si_clkctl_fast_pwrup_delay(wlc_hw->sih);
2591 W_REG(osh, ®s->scc_fastpwrup_dly, wlc->fastpwrup_dly);
2594 /* tell the ucode the corerev */
2595 wlc_bmac_write_shm(wlc_hw, M_MACHW_VER, (u16) wlc_hw->corerev);
2597 /* tell the ucode MAC capabilities */
2598 if (D11REV_GE(wlc_hw->corerev, 13)) {
2599 wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_L,
2600 (u16) (wlc_hw->machwcap & 0xffff));
2601 wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_H,
2603 machwcap >> 16) & 0xffff));
2606 /* write retry limits to SCR, this done after PSM init */
2607 W_REG(osh, ®s->objaddr, OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
2608 (void)R_REG(osh, ®s->objaddr);
2609 W_REG(osh, ®s->objdata, wlc_hw->SRL);
2610 W_REG(osh, ®s->objaddr, OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
2611 (void)R_REG(osh, ®s->objaddr);
2612 W_REG(osh, ®s->objdata, wlc_hw->LRL);
2614 /* write rate fallback retry limits */
2615 wlc_bmac_write_shm(wlc_hw, M_SFRMTXCNTFBRTHSD, wlc_hw->SFBL);
2616 wlc_bmac_write_shm(wlc_hw, M_LFRMTXCNTFBRTHSD, wlc_hw->LFBL);
2618 if (D11REV_GE(wlc_hw->corerev, 16)) {
2619 AND_REG(osh, ®s->ifs_ctl, 0x0FFF);
2620 W_REG(osh, ®s->ifs_aifsn, EDCF_AIFSN_MIN);
2623 /* dma initializations */
2624 wlc->txpend16165war = 0;
2626 /* init the tx dma engines */
2627 for (i = 0; i < NFIFO; i++) {
2629 dma_txinit(wlc_hw->di[i]);
2632 /* init the rx dma engine(s) and post receive buffers */
2633 dma_rxinit(wlc_hw->di[RX_FIFO]);
2634 dma_rxfill(wlc_hw->di[RX_FIFO]);
2635 if (D11REV_IS(wlc_hw->corerev, 4)) {
2636 dma_rxinit(wlc_hw->di[RX_TXSTATUS_FIFO]);
2637 dma_rxfill(wlc_hw->di[RX_TXSTATUS_FIFO]);
2641 /* This function is used for changing the tsf frac register
2642 * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz
2643 * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz
2644 * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz
2645 * HTPHY Formula is 2^26/freq(MHz) e.g.
2646 * For spuron2 - 126MHz -> 2^26/126 = 532610.0
2647 * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082
2648 * For spuron: 123MHz -> 2^26/123 = 545600.5
2649 * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341
2650 * For spur off: 120MHz -> 2^26/120 = 559240.5
2651 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
2654 void wlc_bmac_switch_macfreq(struct wlc_hw_info *wlc_hw, u8 spurmode)
2657 struct osl_info *osh;
2658 regs = wlc_hw->regs;
2661 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2662 (wlc_hw->sih->chip == BCM43225_CHIP_ID)) {
2663 if (spurmode == WL_SPURAVOID_ON2) { /* 126Mhz */
2664 W_REG(osh, ®s->tsf_clk_frac_l, 0x2082);
2665 W_REG(osh, ®s->tsf_clk_frac_h, 0x8);
2666 } else if (spurmode == WL_SPURAVOID_ON1) { /* 123Mhz */
2667 W_REG(osh, ®s->tsf_clk_frac_l, 0x5341);
2668 W_REG(osh, ®s->tsf_clk_frac_h, 0x8);
2669 } else { /* 120Mhz */
2670 W_REG(osh, ®s->tsf_clk_frac_l, 0x8889);
2671 W_REG(osh, ®s->tsf_clk_frac_h, 0x8);
2673 } else if (WLCISLCNPHY(wlc_hw->band)) {
2674 if (spurmode == WL_SPURAVOID_ON1) { /* 82Mhz */
2675 W_REG(osh, ®s->tsf_clk_frac_l, 0x7CE0);
2676 W_REG(osh, ®s->tsf_clk_frac_h, 0xC);
2677 } else { /* 80Mhz */
2678 W_REG(osh, ®s->tsf_clk_frac_l, 0xCCCD);
2679 W_REG(osh, ®s->tsf_clk_frac_h, 0xC);
2684 /* Initialize GPIOs that are controlled by D11 core */
2685 static void wlc_gpio_init(struct wlc_info *wlc)
2687 struct wlc_hw_info *wlc_hw = wlc->hw;
2690 struct osl_info *osh;
2692 regs = wlc_hw->regs;
2695 /* use GPIO select 0 to get all gpio signals from the gpio out reg */
2696 wlc_bmac_mctrl(wlc_hw, MCTL_GPOUT_SEL_MASK, 0);
2699 * Common GPIO setup:
2700 * G0 = LED 0 = WLAN Activity
2701 * G1 = LED 1 = WLAN 2.4 GHz Radio State
2702 * G2 = LED 2 = WLAN 5 GHz Radio State
2703 * G4 = radio disable input (HI enabled, LO disabled)
2708 /* Allocate GPIOs for mimo antenna diversity feature */
2709 if (WLANTSEL_ENAB(wlc)) {
2710 if (wlc_hw->antsel_type == ANTSEL_2x3) {
2711 /* Enable antenna diversity, use 2x3 mode */
2712 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
2713 MHF3_ANTSEL_EN, WLC_BAND_ALL);
2714 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE,
2715 MHF3_ANTSEL_MODE, WLC_BAND_ALL);
2717 /* init superswitch control */
2718 wlc_phy_antsel_init(wlc_hw->band->pi, false);
2720 } else if (wlc_hw->antsel_type == ANTSEL_2x4) {
2721 ASSERT((gm & BOARD_GPIO_12) == 0);
2722 gm |= gc |= (BOARD_GPIO_12 | BOARD_GPIO_13);
2723 /* The board itself is powered by these GPIOs (when not sending pattern)
2726 OR_REG(osh, ®s->psm_gpio_oe,
2727 (BOARD_GPIO_12 | BOARD_GPIO_13));
2728 OR_REG(osh, ®s->psm_gpio_out,
2729 (BOARD_GPIO_12 | BOARD_GPIO_13));
2731 /* Enable antenna diversity, use 2x4 mode */
2732 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
2733 MHF3_ANTSEL_EN, WLC_BAND_ALL);
2734 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, 0,
2737 /* Configure the desired clock to be 4Mhz */
2738 wlc_bmac_write_shm(wlc_hw, M_ANTSEL_CLKDIV,
2739 ANTSEL_CLKDIV_4MHZ);
2742 /* gpio 9 controls the PA. ucode is responsible for wiggling out and oe */
2743 if (wlc_hw->boardflags & BFL_PACTRL)
2744 gm |= gc |= BOARD_GPIO_PACTRL;
2746 /* apply to gpiocontrol register */
2747 si_gpiocontrol(wlc_hw->sih, gm, gc, GPIO_DRV_PRIORITY);
2750 static void wlc_ucode_download(struct wlc_hw_info *wlc_hw)
2752 struct wlc_info *wlc;
2755 if (wlc_hw->ucode_loaded)
2758 if (D11REV_IS(wlc_hw->corerev, 23)) {
2759 if (WLCISNPHY(wlc_hw->band)) {
2760 wlc_ucode_write(wlc_hw, bcm43xx_16_mimo,
2762 wlc_hw->ucode_loaded = true;
2764 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2765 __func__, wlc_hw->unit, wlc_hw->corerev);
2766 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2767 if (WLCISLCNPHY(wlc_hw->band)) {
2768 wlc_ucode_write(wlc_hw, bcm43xx_24_lcn,
2770 wlc_hw->ucode_loaded = true;
2772 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2773 __func__, wlc_hw->unit, wlc_hw->corerev);
2778 static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
2779 const uint nbytes) {
2780 struct osl_info *osh;
2781 d11regs_t *regs = wlc_hw->regs;
2787 WL_TRACE("wl%d: wlc_ucode_write\n", wlc_hw->unit);
2789 ASSERT(IS_ALIGNED(nbytes, sizeof(u32)));
2791 count = (nbytes / sizeof(u32));
2793 W_REG(osh, ®s->objaddr, (OBJADDR_AUTO_INC | OBJADDR_UCM_SEL));
2794 (void)R_REG(osh, ®s->objaddr);
2795 for (i = 0; i < count; i++)
2796 W_REG(osh, ®s->objdata, ucode[i]);
2799 static void wlc_write_inits(struct wlc_hw_info *wlc_hw, const d11init_t *inits)
2802 struct osl_info *osh;
2805 WL_TRACE("wl%d: wlc_write_inits\n", wlc_hw->unit);
2808 base = (volatile u8 *)wlc_hw->regs;
2810 for (i = 0; inits[i].addr != 0xffff; i++) {
2811 ASSERT((inits[i].size == 2) || (inits[i].size == 4));
2813 if (inits[i].size == 2)
2814 W_REG(osh, (u16 *)(base + inits[i].addr),
2816 else if (inits[i].size == 4)
2817 W_REG(osh, (u32 *)(base + inits[i].addr),
2822 static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw)
2825 u16 phytxant = wlc_hw->bmac_phytxant;
2826 u16 mask = PHY_TXC_ANT_MASK;
2828 /* set the Probe Response frame phy control word */
2829 phyctl = wlc_bmac_read_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS);
2830 phyctl = (phyctl & ~mask) | phytxant;
2831 wlc_bmac_write_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS, phyctl);
2833 /* set the Response (ACK/CTS) frame phy control word */
2834 phyctl = wlc_bmac_read_shm(wlc_hw, M_RSP_PCTLWD);
2835 phyctl = (phyctl & ~mask) | phytxant;
2836 wlc_bmac_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl);
2839 void wlc_bmac_txant_set(struct wlc_hw_info *wlc_hw, u16 phytxant)
2841 /* update sw state */
2842 wlc_hw->bmac_phytxant = phytxant;
2844 /* push to ucode if up */
2847 wlc_ucode_txant_set(wlc_hw);
2851 u16 wlc_bmac_get_txant(struct wlc_hw_info *wlc_hw)
2853 return (u16) wlc_hw->wlc->stf->txant;
2856 void wlc_bmac_antsel_type_set(struct wlc_hw_info *wlc_hw, u8 antsel_type)
2858 wlc_hw->antsel_type = antsel_type;
2860 /* Update the antsel type for phy module to use */
2861 wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type);
2864 void wlc_bmac_fifoerrors(struct wlc_hw_info *wlc_hw)
2868 uint intstatus, idx;
2869 d11regs_t *regs = wlc_hw->regs;
2871 unit = wlc_hw->unit;
2873 for (idx = 0; idx < NFIFO; idx++) {
2874 /* read intstatus register and ignore any non-error bits */
2877 ®s->intctrlregs[idx].intstatus) & I_ERRORS;
2881 WL_TRACE("wl%d: wlc_bmac_fifoerrors: intstatus%d 0x%x\n",
2882 unit, idx, intstatus);
2884 if (intstatus & I_RO) {
2885 WL_ERROR("wl%d: fifo %d: receive fifo overflow\n",
2887 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxoflo);
2891 if (intstatus & I_PC) {
2892 WL_ERROR("wl%d: fifo %d: descriptor error\n",
2894 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmade);
2898 if (intstatus & I_PD) {
2899 WL_ERROR("wl%d: fifo %d: data error\n", unit, idx);
2900 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmada);
2904 if (intstatus & I_DE) {
2905 WL_ERROR("wl%d: fifo %d: descriptor protocol error\n",
2907 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmape);
2911 if (intstatus & I_RU) {
2912 WL_ERROR("wl%d: fifo %d: receive descriptor underflow\n",
2914 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxuflo[idx]);
2917 if (intstatus & I_XU) {
2918 WL_ERROR("wl%d: fifo %d: transmit fifo underflow\n",
2920 WLCNTINCR(wlc_hw->wlc->pub->_cnt->txuflo);
2925 wlc_fatal_error(wlc_hw->wlc); /* big hammer */
2928 W_REG(wlc_hw->osh, ®s->intctrlregs[idx].intstatus,
2933 void wlc_intrson(struct wlc_info *wlc)
2935 struct wlc_hw_info *wlc_hw = wlc->hw;
2936 ASSERT(wlc->defmacintmask);
2937 wlc->macintmask = wlc->defmacintmask;
2938 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask);
2941 /* callback for siutils.c, which has only wlc handler, no wl
2942 * they both check up, not only because there is no need to off/restore d11 interrupt
2943 * but also because per-port code may require sync with valid interrupt.
2946 static u32 wlc_wlintrsoff(struct wlc_info *wlc)
2951 return wl_intrsoff(wlc->wl);
2954 static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask)
2959 wl_intrsrestore(wlc->wl, macintmask);
2962 u32 wlc_intrsoff(struct wlc_info *wlc)
2964 struct wlc_hw_info *wlc_hw = wlc->hw;
2970 macintmask = wlc->macintmask; /* isr can still happen */
2972 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, 0);
2973 (void)R_REG(wlc_hw->osh, &wlc_hw->regs->macintmask); /* sync readback */
2974 udelay(1); /* ensure int line is no longer driven */
2975 wlc->macintmask = 0;
2977 /* return previous macintmask; resolve race between us and our isr */
2978 return wlc->macintstatus ? 0 : macintmask;
2981 void wlc_intrsrestore(struct wlc_info *wlc, u32 macintmask)
2983 struct wlc_hw_info *wlc_hw = wlc->hw;
2987 wlc->macintmask = macintmask;
2988 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask);
2991 void wlc_bmac_mute(struct wlc_hw_info *wlc_hw, bool on, mbool flags)
2993 u8 null_ether_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
2996 /* suspend tx fifos */
2997 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_DATA_FIFO);
2998 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_CTL_FIFO);
2999 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_BK_FIFO);
3000 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_VI_FIFO);
3002 /* zero the address match register so we do not send ACKs */
3003 wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
3006 /* resume tx fifos */
3007 if (!wlc_hw->wlc->tx_suspended) {
3008 wlc_bmac_tx_fifo_resume(wlc_hw, TX_DATA_FIFO);
3010 wlc_bmac_tx_fifo_resume(wlc_hw, TX_CTL_FIFO);
3011 wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_BK_FIFO);
3012 wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_VI_FIFO);
3014 /* Restore address */
3015 wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
3019 wlc_phy_mute_upd(wlc_hw->band->pi, on, flags);
3022 wlc_ucode_mute_override_set(wlc_hw);
3024 wlc_ucode_mute_override_clear(wlc_hw);
3027 int wlc_bmac_xmtfifo_sz_get(struct wlc_hw_info *wlc_hw, uint fifo, uint *blocks)
3032 *blocks = wlc_hw->xmtfifo_sz[fifo];
3037 /* wlc_bmac_tx_fifo_suspended:
3038 * Check the MAC's tx suspend status for a tx fifo.
3040 * When the MAC acknowledges a tx suspend, it indicates that no more
3041 * packets will be transmitted out the radio. This is independent of
3042 * DMA channel suspension---the DMA may have finished suspending, or may still
3043 * be pulling data into a tx fifo, by the time the MAC acks the suspend
3046 bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info *wlc_hw, uint tx_fifo)
3048 /* check that a suspend has been requested and is no longer pending */
3051 * for DMA mode, the suspend request is set in xmtcontrol of the DMA engine,
3052 * and the tx fifo suspend at the lower end of the MAC is acknowledged in the
3053 * chnstatus register.
3054 * The tx fifo suspend completion is independent of the DMA suspend completion and
3055 * may be acked before or after the DMA is suspended.
3057 if (dma_txsuspended(wlc_hw->di[tx_fifo]) &&
3058 (R_REG(wlc_hw->osh, &wlc_hw->regs->chnstatus) &
3059 (1 << tx_fifo)) == 0)
3065 void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info *wlc_hw, uint tx_fifo)
3067 u8 fifo = 1 << tx_fifo;
3069 /* Two clients of this code, 11h Quiet period and scanning. */
3071 /* only suspend if not already suspended */
3072 if ((wlc_hw->suspended_fifos & fifo) == fifo)
3075 /* force the core awake only if not already */
3076 if (wlc_hw->suspended_fifos == 0)
3077 wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_TXFIFO);
3079 wlc_hw->suspended_fifos |= fifo;
3081 if (wlc_hw->di[tx_fifo]) {
3082 /* Suspending AMPDU transmissions in the middle can cause underflow
3083 * which may result in mismatch between ucode and driver
3084 * so suspend the mac before suspending the FIFO
3086 if (WLC_PHY_11N_CAP(wlc_hw->band))
3087 wlc_suspend_mac_and_wait(wlc_hw->wlc);
3089 dma_txsuspend(wlc_hw->di[tx_fifo]);
3091 if (WLC_PHY_11N_CAP(wlc_hw->band))
3092 wlc_enable_mac(wlc_hw->wlc);
3096 void wlc_bmac_tx_fifo_resume(struct wlc_hw_info *wlc_hw, uint tx_fifo)
3098 /* BMAC_NOTE: WLC_TX_FIFO_ENAB is done in wlc_dpc() for DMA case but need to be done
3099 * here for PIO otherwise the watchdog will catch the inconsistency and fire
3101 /* Two clients of this code, 11h Quiet period and scanning. */
3102 if (wlc_hw->di[tx_fifo])
3103 dma_txresume(wlc_hw->di[tx_fifo]);
3105 /* allow core to sleep again */
3106 if (wlc_hw->suspended_fifos == 0)
3109 wlc_hw->suspended_fifos &= ~(1 << tx_fifo);
3110 if (wlc_hw->suspended_fifos == 0)
3111 wlc_ucode_wake_override_clear(wlc_hw,
3112 WLC_WAKE_OVERRIDE_TXFIFO);
3117 * Read and clear macintmask and macintstatus and intstatus registers.
3118 * This routine should be called with interrupts off
3120 * -1 if DEVICEREMOVED(wlc) evaluates to true;
3121 * 0 if the interrupt is not for us, or we are in some special cases;
3122 * device interrupt status bits otherwise.
3124 static inline u32 wlc_intstatus(struct wlc_info *wlc, bool in_isr)
3126 struct wlc_hw_info *wlc_hw = wlc->hw;
3127 d11regs_t *regs = wlc_hw->regs;
3129 u32 intstatus_rxfifo, intstatus_txsfifo;
3130 struct osl_info *osh;
3134 /* macintstatus includes a DMA interrupt summary bit */
3135 macintstatus = R_REG(osh, ®s->macintstatus);
3137 WL_TRACE("wl%d: macintstatus: 0x%x\n", wlc_hw->unit, macintstatus);
3139 /* detect cardbus removed, in power down(suspend) and in reset */
3140 if (DEVICEREMOVED(wlc))
3143 /* DEVICEREMOVED succeeds even when the core is still resetting,
3144 * handle that case here.
3146 if (macintstatus == 0xffffffff)
3149 /* defer unsolicited interrupts */
3150 macintstatus &= (in_isr ? wlc->macintmask : wlc->defmacintmask);
3153 if (macintstatus == 0)
3156 /* interrupts are already turned off for CFE build
3157 * Caution: For CFE Turning off the interrupts again has some undesired
3160 /* turn off the interrupts */
3161 W_REG(osh, ®s->macintmask, 0);
3162 (void)R_REG(osh, ®s->macintmask); /* sync readback */
3163 wlc->macintmask = 0;
3165 /* clear device interrupts */
3166 W_REG(osh, ®s->macintstatus, macintstatus);
3168 /* MI_DMAINT is indication of non-zero intstatus */
3169 if (macintstatus & MI_DMAINT) {
3170 if (D11REV_IS(wlc_hw->corerev, 4)) {
3172 R_REG(osh, ®s->intctrlregs[RX_FIFO].intstatus);
3175 ®s->intctrlregs[RX_TXSTATUS_FIFO].
3177 WL_TRACE("wl%d: intstatus_rxfifo 0x%x, intstatus_txsfifo 0x%x\n",
3179 intstatus_rxfifo, intstatus_txsfifo);
3181 /* defer unsolicited interrupt hints */
3182 intstatus_rxfifo &= DEF_RXINTMASK;
3183 intstatus_txsfifo &= DEF_RXINTMASK;
3185 /* MI_DMAINT bit in macintstatus is indication of RX_FIFO interrupt */
3186 /* clear interrupt hints */
3187 if (intstatus_rxfifo)
3189 ®s->intctrlregs[RX_FIFO].intstatus,
3192 macintstatus &= ~MI_DMAINT;
3194 /* MI_TFS bit in macintstatus is encoding of RX_TXSTATUS_FIFO interrupt */
3195 if (intstatus_txsfifo) {
3197 ®s->intctrlregs[RX_TXSTATUS_FIFO].
3198 intstatus, intstatus_txsfifo);
3199 macintstatus |= MI_TFS;
3203 * For corerevs >= 5, only fifo interrupt enabled is I_RI in RX_FIFO.
3204 * If MI_DMAINT is set, assume it is set and clear the interrupt.
3206 W_REG(osh, ®s->intctrlregs[RX_FIFO].intstatus,
3211 return macintstatus;
3214 /* Update wlc->macintstatus and wlc->intstatus[]. */
3215 /* Return true if they are updated successfully. false otherwise */
3216 bool wlc_intrsupd(struct wlc_info *wlc)
3220 ASSERT(wlc->macintstatus != 0);
3222 /* read and clear macintstatus and intstatus registers */
3223 macintstatus = wlc_intstatus(wlc, false);
3225 /* device is removed */
3226 if (macintstatus == 0xffffffff)
3229 /* update interrupt status in software */
3230 wlc->macintstatus |= macintstatus;
3236 * First-level interrupt processing.
3237 * Return true if this was our interrupt, false otherwise.
3238 * *wantdpc will be set to true if further wlc_dpc() processing is required,
3241 bool BCMFASTPATH wlc_isr(struct wlc_info *wlc, bool *wantdpc)
3243 struct wlc_hw_info *wlc_hw = wlc->hw;
3248 if (!wlc_hw->up || !wlc->macintmask)
3251 /* read and clear macintstatus and intstatus registers */
3252 macintstatus = wlc_intstatus(wlc, true);
3254 if (macintstatus == 0xffffffff)
3255 WL_ERROR("DEVICEREMOVED detected in the ISR code path\n");
3257 /* it is not for us */
3258 if (macintstatus == 0)
3263 /* save interrupt status bits */
3264 ASSERT(wlc->macintstatus == 0);
3265 wlc->macintstatus = macintstatus;
3271 /* process tx completion events for corerev < 5 */
3272 static bool wlc_bmac_txstatus_corerev4(struct wlc_hw_info *wlc_hw)
3274 struct sk_buff *status_p;
3276 struct osl_info *osh;
3279 WL_TRACE("wl%d: wlc_txstatusrecv\n", wlc_hw->unit);
3283 while (!fatal && (status_p = dma_rx(wlc_hw->di[RX_TXSTATUS_FIFO]))) {
3285 txs = (tx_status_t *) status_p->data;
3286 /* MAC uses little endian only */
3287 ltoh16_buf((void *)txs, sizeof(tx_status_t));
3289 /* shift low bits for tx_status_t status compatibility */
3290 txs->status = (txs->status & ~TXS_COMPAT_MASK)
3291 | (((txs->status & TXS_COMPAT_MASK) << TXS_COMPAT_SHIFT));
3293 fatal = wlc_bmac_dotxstatus(wlc_hw, txs, 0);
3295 pkt_buf_free_skb(osh, status_p, false);
3301 /* post more rbufs */
3302 dma_rxfill(wlc_hw->di[RX_TXSTATUS_FIFO]);
3307 static bool BCMFASTPATH
3308 wlc_bmac_dotxstatus(struct wlc_hw_info *wlc_hw, tx_status_t *txs, u32 s2)
3310 /* discard intermediate indications for ucode with one legitimate case:
3311 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
3312 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
3313 * transmission count)
3315 if (!(txs->status & TX_STATUS_AMPDU)
3316 && (txs->status & TX_STATUS_INTERMEDIATE)) {
3320 return wlc_dotxstatus(wlc_hw->wlc, txs, s2);
3323 /* process tx completion events in BMAC
3324 * Return true if more tx status need to be processed. false otherwise.
3326 static bool BCMFASTPATH
3327 wlc_bmac_txstatus(struct wlc_hw_info *wlc_hw, bool bound, bool *fatal)
3329 bool morepending = false;
3330 struct wlc_info *wlc = wlc_hw->wlc;
3332 WL_TRACE("wl%d: wlc_bmac_txstatus\n", wlc_hw->unit);
3334 if (D11REV_IS(wlc_hw->corerev, 4)) {
3335 /* to retire soon */
3336 *fatal = wlc_bmac_txstatus_corerev4(wlc->hw);
3343 struct osl_info *osh;
3344 tx_status_t txstatus, *txs;
3347 /* Param 'max_tx_num' indicates max. # tx status to process before break out. */
3348 uint max_tx_num = bound ? wlc->pub->tunables->txsbnd : -1;
3351 regs = wlc_hw->regs;
3354 && (s1 = R_REG(osh, ®s->frmtxstatus)) & TXS_V) {
3356 if (s1 == 0xffffffff) {
3357 WL_ERROR("wl%d: %s: dead chip\n",
3358 wlc_hw->unit, __func__);
3359 ASSERT(s1 != 0xffffffff);
3363 s2 = R_REG(osh, ®s->frmtxstatus2);
3365 txs->status = s1 & TXS_STATUS_MASK;
3366 txs->frameid = (s1 & TXS_FID_MASK) >> TXS_FID_SHIFT;
3367 txs->sequence = s2 & TXS_SEQ_MASK;
3368 txs->phyerr = (s2 & TXS_PTX_MASK) >> TXS_PTX_SHIFT;
3369 txs->lasttxtime = 0;
3371 *fatal = wlc_bmac_dotxstatus(wlc_hw, txs, s2);
3373 /* !give others some time to run! */
3374 if (++n >= max_tx_num)
3381 if (n >= max_tx_num)
3385 if (!pktq_empty(&wlc->active_queue->q))
3386 wlc_send_q(wlc, wlc->active_queue);
3391 void wlc_suspend_mac_and_wait(struct wlc_info *wlc)
3393 struct wlc_hw_info *wlc_hw = wlc->hw;
3394 d11regs_t *regs = wlc_hw->regs;
3396 struct osl_info *osh;
3398 WL_TRACE("wl%d: wlc_suspend_mac_and_wait: bandunit %d\n",
3399 wlc_hw->unit, wlc_hw->band->bandunit);
3402 * Track overlapping suspend requests
3404 wlc_hw->mac_suspend_depth++;
3405 if (wlc_hw->mac_suspend_depth > 1)
3410 /* force the core awake */
3411 wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
3413 mc = R_REG(osh, ®s->maccontrol);
3415 if (mc == 0xffffffff) {
3416 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
3420 ASSERT(!(mc & MCTL_PSM_JMP_0));
3421 ASSERT(mc & MCTL_PSM_RUN);
3422 ASSERT(mc & MCTL_EN_MAC);
3424 mi = R_REG(osh, ®s->macintstatus);
3425 if (mi == 0xffffffff) {
3426 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
3430 ASSERT(!(mi & MI_MACSSPNDD));
3432 wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, 0);
3434 SPINWAIT(!(R_REG(osh, ®s->macintstatus) & MI_MACSSPNDD),
3435 WLC_MAX_MAC_SUSPEND);
3437 if (!(R_REG(osh, ®s->macintstatus) & MI_MACSSPNDD)) {
3438 WL_ERROR("wl%d: wlc_suspend_mac_and_wait: waited %d uS and MI_MACSSPNDD is still not on.\n",
3439 wlc_hw->unit, WLC_MAX_MAC_SUSPEND);
3440 WL_ERROR("wl%d: psmdebug 0x%08x, phydebug 0x%08x, psm_brc 0x%04x\n",
3442 R_REG(osh, ®s->psmdebug),
3443 R_REG(osh, ®s->phydebug),
3444 R_REG(osh, ®s->psm_brc));
3447 mc = R_REG(osh, ®s->maccontrol);
3448 if (mc == 0xffffffff) {
3449 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
3453 ASSERT(!(mc & MCTL_PSM_JMP_0));
3454 ASSERT(mc & MCTL_PSM_RUN);
3455 ASSERT(!(mc & MCTL_EN_MAC));
3458 void wlc_enable_mac(struct wlc_info *wlc)
3460 struct wlc_hw_info *wlc_hw = wlc->hw;
3461 d11regs_t *regs = wlc_hw->regs;
3463 struct osl_info *osh;
3465 WL_TRACE("wl%d: wlc_enable_mac: bandunit %d\n",
3466 wlc_hw->unit, wlc->band->bandunit);
3469 * Track overlapping suspend requests
3471 ASSERT(wlc_hw->mac_suspend_depth > 0);
3472 wlc_hw->mac_suspend_depth--;
3473 if (wlc_hw->mac_suspend_depth > 0)
3478 mc = R_REG(osh, ®s->maccontrol);
3479 ASSERT(!(mc & MCTL_PSM_JMP_0));
3480 ASSERT(!(mc & MCTL_EN_MAC));
3481 ASSERT(mc & MCTL_PSM_RUN);
3483 wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, MCTL_EN_MAC);
3484 W_REG(osh, ®s->macintstatus, MI_MACSSPNDD);
3486 mc = R_REG(osh, ®s->maccontrol);
3487 ASSERT(!(mc & MCTL_PSM_JMP_0));
3488 ASSERT(mc & MCTL_EN_MAC);
3489 ASSERT(mc & MCTL_PSM_RUN);
3491 mi = R_REG(osh, ®s->macintstatus);
3492 ASSERT(!(mi & MI_MACSSPNDD));
3494 wlc_ucode_wake_override_clear(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
3497 static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw)
3501 WLC_RATE_6M, WLC_RATE_9M, WLC_RATE_12M, WLC_RATE_18M,
3502 WLC_RATE_24M, WLC_RATE_36M, WLC_RATE_48M, WLC_RATE_54M
3508 if (!WLC_PHY_11N_CAP(wlc_hw->band))
3511 /* walk the phy rate table and update the entries */
3512 for (i = 0; i < ARRAY_SIZE(rates); i++) {
3515 entry_ptr = wlc_bmac_ofdm_ratetable_offset(wlc_hw, rate);
3517 /* read the SHM Rate Table entry OFDM PCTL1 values */
3519 wlc_bmac_read_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS);
3521 /* modify the value */
3522 pctl1 &= ~PHY_TXC1_MODE_MASK;
3523 pctl1 |= (wlc_hw->hw_stf_ss_opmode << PHY_TXC1_MODE_SHIFT);
3525 /* Update the SHM Rate Table entry OFDM PCTL1 values */
3526 wlc_bmac_write_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS,
3531 static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw, u8 rate)
3535 struct plcp_signal_rate_lookup {
3539 /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */
3540 const struct plcp_signal_rate_lookup rate_lookup[] = {
3543 {WLC_RATE_12M, 0xA},
3544 {WLC_RATE_18M, 0xE},
3545 {WLC_RATE_24M, 0x9},
3546 {WLC_RATE_36M, 0xD},
3547 {WLC_RATE_48M, 0x8},
3551 for (i = 0; i < ARRAY_SIZE(rate_lookup); i++) {
3552 if (rate == rate_lookup[i].rate) {
3553 plcp_rate = rate_lookup[i].signal_rate;
3558 /* Find the SHM pointer to the rate table entry by looking in the
3561 return 2 * wlc_bmac_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2));
3564 void wlc_bmac_band_stf_ss_set(struct wlc_hw_info *wlc_hw, u8 stf_mode)
3566 wlc_hw->hw_stf_ss_opmode = stf_mode;
3569 wlc_upd_ofdm_pctl1_table(wlc_hw);
3573 wlc_bmac_read_tsf(struct wlc_hw_info *wlc_hw, u32 *tsf_l_ptr,
3576 d11regs_t *regs = wlc_hw->regs;
3578 /* read the tsf timer low, then high to get an atomic read */
3579 *tsf_l_ptr = R_REG(wlc_hw->osh, ®s->tsf_timerlow);
3580 *tsf_h_ptr = R_REG(wlc_hw->osh, ®s->tsf_timerhigh);
3585 bool wlc_bmac_validate_chip_access(struct wlc_hw_info *wlc_hw)
3589 volatile u16 *reg16;
3590 struct osl_info *osh;
3592 WL_TRACE("wl%d: validate_chip_access\n", wlc_hw->unit);
3594 regs = wlc_hw->regs;
3597 /* Validate dchip register access */
3599 W_REG(osh, ®s->objaddr, OBJADDR_SHM_SEL | 0);
3600 (void)R_REG(osh, ®s->objaddr);
3601 w = R_REG(osh, ®s->objdata);
3603 /* Can we write and read back a 32bit register? */
3604 W_REG(osh, ®s->objaddr, OBJADDR_SHM_SEL | 0);
3605 (void)R_REG(osh, ®s->objaddr);
3606 W_REG(osh, ®s->objdata, (u32) 0xaa5555aa);
3608 W_REG(osh, ®s->objaddr, OBJADDR_SHM_SEL | 0);
3609 (void)R_REG(osh, ®s->objaddr);
3610 val = R_REG(osh, ®s->objdata);
3611 if (val != (u32) 0xaa5555aa) {
3612 WL_ERROR("wl%d: validate_chip_access: SHM = 0x%x, expected 0xaa5555aa\n",
3617 W_REG(osh, ®s->objaddr, OBJADDR_SHM_SEL | 0);
3618 (void)R_REG(osh, ®s->objaddr);
3619 W_REG(osh, ®s->objdata, (u32) 0x55aaaa55);
3621 W_REG(osh, ®s->objaddr, OBJADDR_SHM_SEL | 0);
3622 (void)R_REG(osh, ®s->objaddr);
3623 val = R_REG(osh, ®s->objdata);
3624 if (val != (u32) 0x55aaaa55) {
3625 WL_ERROR("wl%d: validate_chip_access: SHM = 0x%x, expected 0x55aaaa55\n",
3630 W_REG(osh, ®s->objaddr, OBJADDR_SHM_SEL | 0);
3631 (void)R_REG(osh, ®s->objaddr);
3632 W_REG(osh, ®s->objdata, w);
3634 if (D11REV_LT(wlc_hw->corerev, 11)) {
3635 /* if 32 bit writes are split into 16 bit writes, are they in the correct order
3636 * for our interface, low to high
3638 reg16 = (volatile u16 *)®s->tsf_cfpstart;
3640 /* write the CFPStart register low half explicitly, starting a buffered write */
3641 W_REG(osh, reg16, 0xAAAA);
3643 /* Write a 32 bit value to CFPStart to test the 16 bit split order.
3644 * If the low 16 bits are written first, followed by the high 16 bits then the
3645 * 32 bit value 0xCCCCBBBB should end up in the register.
3646 * If the order is reversed, then the write to the high half will trigger a buffered
3647 * write of 0xCCCCAAAA.
3648 * If the bus is 32 bits, then this is not much of a test, and the reg should
3649 * have the correct value 0xCCCCBBBB.
3651 W_REG(osh, ®s->tsf_cfpstart, 0xCCCCBBBB);
3653 /* verify with the 16 bit registers that have no side effects */
3654 val = R_REG(osh, ®s->tsf_cfpstrt_l);
3655 if (val != (uint) 0xBBBB) {
3656 WL_ERROR("wl%d: validate_chip_access: tsf_cfpstrt_l = 0x%x, expected 0x%x\n",
3657 wlc_hw->unit, val, 0xBBBB);
3660 val = R_REG(osh, ®s->tsf_cfpstrt_h);
3661 if (val != (uint) 0xCCCC) {
3662 WL_ERROR("wl%d: validate_chip_access: tsf_cfpstrt_h = 0x%x, expected 0x%x\n",
3663 wlc_hw->unit, val, 0xCCCC);
3669 /* clear CFPStart */
3670 W_REG(osh, ®s->tsf_cfpstart, 0);
3672 w = R_REG(osh, ®s->maccontrol);
3673 if ((w != (MCTL_IHR_EN | MCTL_WAKE)) &&
3674 (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) {
3675 WL_ERROR("wl%d: validate_chip_access: maccontrol = 0x%x, expected 0x%x or 0x%x\n",
3677 (MCTL_IHR_EN | MCTL_WAKE),
3678 (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE));
3685 #define PHYPLL_WAIT_US 100000
3687 void wlc_bmac_core_phypll_ctl(struct wlc_hw_info *wlc_hw, bool on)
3690 struct osl_info *osh;
3693 WL_TRACE("wl%d: wlc_bmac_core_phypll_ctl\n", wlc_hw->unit);
3696 regs = wlc_hw->regs;
3699 if (D11REV_LE(wlc_hw->corerev, 16) || D11REV_IS(wlc_hw->corerev, 20))
3703 if ((wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
3704 OR_REG(osh, ®s->clk_ctl_st,
3705 (CCS_ERSRC_REQ_HT | CCS_ERSRC_REQ_D11PLL |
3706 CCS_ERSRC_REQ_PHYPLL));
3707 SPINWAIT((R_REG(osh, ®s->clk_ctl_st) &
3708 (CCS_ERSRC_AVAIL_HT)) != (CCS_ERSRC_AVAIL_HT),
3711 tmp = R_REG(osh, ®s->clk_ctl_st);
3712 if ((tmp & (CCS_ERSRC_AVAIL_HT)) !=
3713 (CCS_ERSRC_AVAIL_HT)) {
3714 WL_ERROR("%s: turn on PHY PLL failed\n",
3719 OR_REG(osh, ®s->clk_ctl_st,
3720 (CCS_ERSRC_REQ_D11PLL | CCS_ERSRC_REQ_PHYPLL));
3721 SPINWAIT((R_REG(osh, ®s->clk_ctl_st) &
3722 (CCS_ERSRC_AVAIL_D11PLL |
3723 CCS_ERSRC_AVAIL_PHYPLL)) !=
3724 (CCS_ERSRC_AVAIL_D11PLL |
3725 CCS_ERSRC_AVAIL_PHYPLL), PHYPLL_WAIT_US);
3727 tmp = R_REG(osh, ®s->clk_ctl_st);
3729 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL))
3731 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) {
3732 WL_ERROR("%s: turn on PHY PLL failed\n",
3738 /* Since the PLL may be shared, other cores can still be requesting it;
3739 * so we'll deassert the request but not wait for status to comply.
3741 AND_REG(osh, ®s->clk_ctl_st, ~CCS_ERSRC_REQ_PHYPLL);
3742 tmp = R_REG(osh, ®s->clk_ctl_st);
3746 void wlc_coredisable(struct wlc_hw_info *wlc_hw)
3750 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
3752 ASSERT(!wlc_hw->up);
3754 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
3759 if (wlc_hw->noreset)
3763 wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
3765 /* turn off analog core */
3766 wlc_phy_anacore(wlc_hw->band->pi, OFF);
3768 /* turn off PHYPLL to save power */
3769 wlc_bmac_core_phypll_ctl(wlc_hw, false);
3771 /* No need to set wlc->pub->radio_active = OFF
3772 * because this function needs down capability and
3773 * radio_active is designed for BCMNODOWN.
3776 /* remove gpio controls */
3777 if (wlc_hw->ucode_dbgsel)
3778 si_gpiocontrol(wlc_hw->sih, ~0, 0, GPIO_DRV_PRIORITY);
3780 wlc_hw->clk = false;
3781 si_core_disable(wlc_hw->sih, 0);
3782 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
3785 /* power both the pll and external oscillator on/off */
3786 void wlc_bmac_xtal(struct wlc_hw_info *wlc_hw, bool want)
3788 WL_TRACE("wl%d: wlc_bmac_xtal: want %d\n", wlc_hw->unit, want);
3790 /* dont power down if plldown is false or we must poll hw radio disable */
3791 if (!want && wlc_hw->pllreq)
3795 si_clkctl_xtal(wlc_hw->sih, XTAL | PLL, want);
3797 wlc_hw->sbclk = want;
3798 if (!wlc_hw->sbclk) {
3799 wlc_hw->clk = false;
3800 if (wlc_hw->band && wlc_hw->band->pi)
3801 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
3805 static void wlc_flushqueues(struct wlc_info *wlc)
3807 struct wlc_hw_info *wlc_hw = wlc->hw;
3810 wlc->txpend16165war = 0;
3812 /* free any posted tx packets */
3813 for (i = 0; i < NFIFO; i++)
3814 if (wlc_hw->di[i]) {
3815 dma_txreclaim(wlc_hw->di[i], HNDDMA_RANGE_ALL);
3816 TXPKTPENDCLR(wlc, i);
3817 WL_TRACE("wlc_flushqueues: pktpend fifo %d cleared\n",
3821 /* free any posted rx packets */
3822 dma_rxreclaim(wlc_hw->di[RX_FIFO]);
3823 if (D11REV_IS(wlc_hw->corerev, 4))
3824 dma_rxreclaim(wlc_hw->di[RX_TXSTATUS_FIFO]);
3827 u16 wlc_bmac_read_shm(struct wlc_hw_info *wlc_hw, uint offset)
3829 return wlc_bmac_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL);
3832 void wlc_bmac_write_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v)
3834 wlc_bmac_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL);
3837 /* Set a range of shared memory to a value.
3838 * SHM 'offset' needs to be an even address and
3839 * Buffer length 'len' must be an even number of bytes
3841 void wlc_bmac_set_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v, int len)
3845 /* offset and len need to be even */
3846 ASSERT((offset & 1) == 0);
3847 ASSERT((len & 1) == 0);
3852 for (i = 0; i < len; i += 2) {
3853 wlc_bmac_write_objmem(wlc_hw, offset + i, v, OBJADDR_SHM_SEL);
3858 wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset, u32 sel)
3860 d11regs_t *regs = wlc_hw->regs;
3861 volatile u16 *objdata_lo = (volatile u16 *)®s->objdata;
3862 volatile u16 *objdata_hi = objdata_lo + 1;
3865 ASSERT((offset & 1) == 0);
3867 W_REG(wlc_hw->osh, ®s->objaddr, sel | (offset >> 2));
3868 (void)R_REG(wlc_hw->osh, ®s->objaddr);
3870 v = R_REG(wlc_hw->osh, objdata_hi);
3872 v = R_REG(wlc_hw->osh, objdata_lo);
3879 wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset, u16 v, u32 sel)
3881 d11regs_t *regs = wlc_hw->regs;
3882 volatile u16 *objdata_lo = (volatile u16 *)®s->objdata;
3883 volatile u16 *objdata_hi = objdata_lo + 1;
3885 ASSERT((offset & 1) == 0);
3887 W_REG(wlc_hw->osh, ®s->objaddr, sel | (offset >> 2));
3888 (void)R_REG(wlc_hw->osh, ®s->objaddr);
3890 W_REG(wlc_hw->osh, objdata_hi, v);
3892 W_REG(wlc_hw->osh, objdata_lo, v);
3896 /* Copy a buffer to shared memory of specified type .
3897 * SHM 'offset' needs to be an even address and
3898 * Buffer length 'len' must be an even number of bytes
3899 * 'sel' selects the type of memory
3902 wlc_bmac_copyto_objmem(struct wlc_hw_info *wlc_hw, uint offset, const void *buf,
3906 const u8 *p = (const u8 *)buf;
3909 /* offset and len need to be even */
3910 ASSERT((offset & 1) == 0);
3911 ASSERT((len & 1) == 0);
3916 for (i = 0; i < len; i += 2) {
3917 v = p[i] | (p[i + 1] << 8);
3918 wlc_bmac_write_objmem(wlc_hw, offset + i, v, sel);
3922 /* Copy a piece of shared memory of specified type to a buffer .
3923 * SHM 'offset' needs to be an even address and
3924 * Buffer length 'len' must be an even number of bytes
3925 * 'sel' selects the type of memory
3928 wlc_bmac_copyfrom_objmem(struct wlc_hw_info *wlc_hw, uint offset, void *buf,
3935 /* offset and len need to be even */
3936 ASSERT((offset & 1) == 0);
3937 ASSERT((len & 1) == 0);
3942 for (i = 0; i < len; i += 2) {
3943 v = wlc_bmac_read_objmem(wlc_hw, offset + i, sel);
3945 p[i + 1] = (v >> 8) & 0xFF;
3949 void wlc_bmac_copyfrom_vars(struct wlc_hw_info *wlc_hw, char **buf, uint *len)
3951 WL_TRACE("wlc_bmac_copyfrom_vars, nvram vars totlen=%d\n",
3954 *buf = wlc_hw->vars;
3955 *len = wlc_hw->vars_size;
3958 void wlc_bmac_retrylimit_upd(struct wlc_hw_info *wlc_hw, u16 SRL, u16 LRL)
3963 /* write retry limit to SCR, shouldn't need to suspend */
3965 W_REG(wlc_hw->osh, &wlc_hw->regs->objaddr,
3966 OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
3967 (void)R_REG(wlc_hw->osh, &wlc_hw->regs->objaddr);
3968 W_REG(wlc_hw->osh, &wlc_hw->regs->objdata, wlc_hw->SRL);
3969 W_REG(wlc_hw->osh, &wlc_hw->regs->objaddr,
3970 OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
3971 (void)R_REG(wlc_hw->osh, &wlc_hw->regs->objaddr);
3972 W_REG(wlc_hw->osh, &wlc_hw->regs->objdata, wlc_hw->LRL);
3976 void wlc_bmac_set_noreset(struct wlc_hw_info *wlc_hw, bool noreset_flag)
3978 wlc_hw->noreset = noreset_flag;
3981 void wlc_bmac_pllreq(struct wlc_hw_info *wlc_hw, bool set, mbool req_bit)
3986 if (mboolisset(wlc_hw->pllreq, req_bit))
3989 mboolset(wlc_hw->pllreq, req_bit);
3991 if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
3992 if (!wlc_hw->sbclk) {
3993 wlc_bmac_xtal(wlc_hw, ON);
3997 if (!mboolisset(wlc_hw->pllreq, req_bit))
4000 mboolclr(wlc_hw->pllreq, req_bit);
4002 if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
4003 if (wlc_hw->sbclk) {
4004 wlc_bmac_xtal(wlc_hw, OFF);
4012 /* this will be true for all ai chips */
4013 bool wlc_bmac_taclear(struct wlc_hw_info *wlc_hw, bool ta_ok)
4018 u16 wlc_bmac_rate_shm_offset(struct wlc_hw_info *wlc_hw, u8 rate)
4023 /* get the phy specific rate encoding for the PLCP SIGNAL field */
4024 /* XXX4321 fixup needed ? */
4026 table_ptr = M_RT_DIRMAP_A;
4028 table_ptr = M_RT_DIRMAP_B;
4030 /* for a given rate, the LS-nibble of the PLCP SIGNAL field is
4031 * the index into the rate table.
4033 phy_rate = rate_info[rate] & RATE_MASK;
4034 index = phy_rate & 0xf;
4036 /* Find the SHM pointer to the rate table entry by looking in the
4039 return 2 * wlc_bmac_read_shm(wlc_hw, table_ptr + (index * 2));
4042 void wlc_bmac_antsel_set(struct wlc_hw_info *wlc_hw, u32 antsel_avail)
4044 wlc_hw->antsel_avail = antsel_avail;