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>
19 #include <linux/module.h>
20 #include <linux/pci.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
25 #include <brcm_hw_ids.h>
26 #include <brcmu_wifi.h>
30 #include <brcmu_utils.h>
31 #include <chipcommon.h>
41 #include "phy/phy_hal.h"
44 #include "ucode_loader.h"
47 #include "bottom_mac.h"
48 #include "mac80211_if.h"
50 #define TIMER_INTERVAL_WATCHDOG_BMAC 1000 /* watchdog timer, in unit of ms */
52 #define SYNTHPU_DLY_APHY_US 3700 /* a phy synthpu_dly time in us */
53 #define SYNTHPU_DLY_BPHY_US 1050 /* b/g phy synthpu_dly time in us, default */
54 #define SYNTHPU_DLY_NPHY_US 2048 /* n phy REV3 synthpu_dly time in us, default */
55 #define SYNTHPU_DLY_LPPHY_US 300 /* lpphy synthpu_dly time in us */
57 #define SYNTHPU_DLY_PHY_US_QT 100 /* QT synthpu_dly time in us */
59 #ifndef BMAC_DUP_TO_REMOVE
60 #define WLC_RM_WAIT_TX_SUSPEND 4 /* Wait Tx Suspend */
62 #define ANTCNT 10 /* vanilla M_MAX_ANTCNT value */
64 #endif /* BMAC_DUP_TO_REMOVE */
66 #define DMAREG(wlc_hw, direction, fifonum) \
67 ((direction == DMA_TX) ? \
68 (void *)&(wlc_hw->regs->fifo64regs[fifonum].dmaxmt) : \
69 (void *)&(wlc_hw->regs->fifo64regs[fifonum].dmarcv))
71 #define APHY_SLOT_TIME 9
72 #define BPHY_SLOT_TIME 20
75 * The following table lists the buffer memory allocated to xmt fifos in HW.
76 * the size is in units of 256bytes(one block), total size is HW dependent
77 * ucode has default fifo partition, sw can overwrite if necessary
79 * This is documented in twiki under the topic UcodeTxFifo. Please ensure
80 * the twiki is updated before making changes.
83 #define XMTFIFOTBL_STARTREV 20 /* Starting corerev for the fifo size table */
85 static u16 xmtfifo_sz[][NFIFO] = {
86 {20, 192, 192, 21, 17, 5}, /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */
87 {9, 58, 22, 14, 14, 5}, /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */
88 {20, 192, 192, 21, 17, 5}, /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */
89 {20, 192, 192, 21, 17, 5}, /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */
90 {9, 58, 22, 14, 14, 5}, /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
93 static void wlc_clkctl_clk(struct wlc_hw_info *wlc, uint mode);
94 static void wlc_coreinit(struct wlc_info *wlc);
96 /* used by wlc_wakeucode_init() */
97 static void wlc_write_inits(struct wlc_hw_info *wlc_hw,
98 const struct d11init *inits);
99 static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
101 static void wlc_ucode_download(struct wlc_hw_info *wlc);
102 static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw);
104 /* used by wlc_dpc() */
105 static bool wlc_bmac_dotxstatus(struct wlc_hw_info *wlc, tx_status_t *txs,
107 static bool wlc_bmac_txstatus(struct wlc_hw_info *wlc, bool bound, bool *fatal);
108 static bool wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound);
110 /* used by wlc_down() */
111 static void wlc_flushqueues(struct wlc_info *wlc);
113 static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs);
114 static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw);
115 static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw);
116 static bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info *wlc_hw,
118 static void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info *wlc_hw, uint tx_fifo);
119 static void wlc_bmac_tx_fifo_resume(struct wlc_hw_info *wlc_hw, uint tx_fifo);
121 /* Low Level Prototypes */
122 static int wlc_bmac_bandtype(struct wlc_hw_info *wlc_hw);
123 static void wlc_bmac_info_init(struct wlc_hw_info *wlc_hw);
124 static void wlc_bmac_xtal(struct wlc_hw_info *wlc_hw, bool want);
125 static u16 wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset,
127 static void wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset,
129 static void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk);
130 static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme);
131 static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw);
132 static void wlc_ucode_bsinit(struct wlc_hw_info *wlc_hw);
133 static bool wlc_validboardtype(struct wlc_hw_info *wlc);
134 static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw);
135 static bool wlc_bmac_validate_chip_access(struct wlc_hw_info *wlc_hw);
136 static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw);
137 static void wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init);
138 static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw);
139 static void wlc_bmac_mute(struct wlc_hw_info *wlc_hw, bool want, mbool flags);
140 static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw);
141 static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw);
142 static u32 wlc_wlintrsoff(struct wlc_info *wlc);
143 static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask);
144 static void wlc_gpio_init(struct wlc_info *wlc);
145 static void wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn,
147 static void wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn,
149 static void wlc_bmac_bsinit(struct wlc_info *wlc, chanspec_t chanspec);
150 static u32 wlc_setband_inact(struct wlc_info *wlc, uint bandunit);
151 static void wlc_bmac_setband(struct wlc_hw_info *wlc_hw, uint bandunit,
152 chanspec_t chanspec);
153 static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
155 static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw);
156 static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw,
159 /* === Low Level functions === */
161 void wlc_bmac_set_shortslot(struct wlc_hw_info *wlc_hw, bool shortslot)
163 wlc_hw->shortslot = shortslot;
165 if (BAND_2G(wlc_bmac_bandtype(wlc_hw)) && wlc_hw->up) {
166 wlc_suspend_mac_and_wait(wlc_hw->wlc);
167 wlc_bmac_update_slot_timing(wlc_hw, shortslot);
168 wlc_enable_mac(wlc_hw->wlc);
173 * Update the slot timing for standard 11b/g (20us slots)
174 * or shortslot 11g (9us slots)
175 * The PSM needs to be suspended for this call.
177 static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
185 /* 11g short slot: 11a timing */
186 W_REG(®s->ifs_slot, 0x0207); /* APHY_SLOT_TIME */
187 wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, APHY_SLOT_TIME);
189 /* 11g long slot: 11b timing */
190 W_REG(®s->ifs_slot, 0x0212); /* BPHY_SLOT_TIME */
191 wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, BPHY_SLOT_TIME);
195 static void WLBANDINITFN(wlc_ucode_bsinit) (struct wlc_hw_info *wlc_hw)
197 struct wiphy *wiphy = wlc_hw->wlc->wiphy;
199 /* init microcode host flags */
200 wlc_write_mhf(wlc_hw, wlc_hw->band->mhfs);
202 /* do band-specific ucode IHR, SHM, and SCR inits */
203 if (D11REV_IS(wlc_hw->corerev, 23)) {
204 if (WLCISNPHY(wlc_hw->band)) {
205 wlc_write_inits(wlc_hw, d11n0bsinitvals16);
207 wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev"
208 " %d\n", __func__, wlc_hw->unit,
212 if (D11REV_IS(wlc_hw->corerev, 24)) {
213 if (WLCISLCNPHY(wlc_hw->band)) {
214 wlc_write_inits(wlc_hw, d11lcn0bsinitvals24);
216 wiphy_err(wiphy, "%s: wl%d: unsupported phy in"
217 " core rev %d\n", __func__,
218 wlc_hw->unit, wlc_hw->corerev);
220 wiphy_err(wiphy, "%s: wl%d: unsupported corerev %d\n",
221 __func__, wlc_hw->unit, wlc_hw->corerev);
226 /* switch to new band but leave it inactive */
227 static u32 WLBANDINITFN(wlc_setband_inact) (struct wlc_info *wlc, uint bandunit)
229 struct wlc_hw_info *wlc_hw = wlc->hw;
232 BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
234 WARN_ON((R_REG(&wlc_hw->regs->maccontrol) & MCTL_EN_MAC) != 0);
236 /* disable interrupts */
237 macintmask = brcms_intrsoff(wlc->wl);
240 wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
242 wlc_bmac_core_phy_clk(wlc_hw, OFF);
244 wlc_setxband(wlc_hw, bandunit);
249 /* Process received frames */
251 * Return true if more frames need to be processed. false otherwise.
252 * Param 'bound' indicates max. # frames to process before break out.
255 wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound)
258 struct sk_buff *head = NULL;
259 struct sk_buff *tail = NULL;
261 uint bound_limit = bound ? wlc_hw->wlc->pub->tunables->rxbnd : -1;
262 wlc_d11rxhdr_t *wlc_rxhdr = NULL;
264 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
265 /* gather received frames */
266 while ((p = dma_rx(wlc_hw->di[fifo]))) {
275 /* !give others some time to run! */
276 if (++n >= bound_limit)
280 /* post more rbufs */
281 dma_rxfill(wlc_hw->di[fifo]);
283 /* process each frame */
284 while ((p = head) != NULL) {
288 wlc_rxhdr = (wlc_d11rxhdr_t *) p->data;
290 /* compute the RSSI from d11rxhdr and record it in wlc_rxd11hr */
291 wlc_phy_rssi_compute(wlc_hw->band->pi, wlc_rxhdr);
293 wlc_recv(wlc_hw->wlc, p);
296 return n >= bound_limit;
299 /* second-level interrupt processing
300 * Return true if another dpc needs to be re-scheduled. false otherwise.
301 * Param 'bounded' indicates if applicable loops should be bounded.
303 bool wlc_dpc(struct wlc_info *wlc, bool bounded)
306 struct wlc_hw_info *wlc_hw = wlc->hw;
307 d11regs_t *regs = wlc_hw->regs;
309 struct wiphy *wiphy = wlc->wiphy;
311 if (DEVICEREMOVED(wlc)) {
312 wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
318 /* grab and clear the saved software intstatus bits */
319 macintstatus = wlc->macintstatus;
320 wlc->macintstatus = 0;
322 BCMMSG(wlc->wiphy, "wl%d: macintstatus 0x%x\n",
323 wlc_hw->unit, macintstatus);
325 WARN_ON(macintstatus & MI_PRQ); /* PRQ Interrupt in non-MBSS */
327 /* BCN template is available */
328 /* ZZZ: Use AP_ACTIVE ? */
329 if (AP_ENAB(wlc->pub) && (!APSTA_ENAB(wlc->pub))
330 && (macintstatus & MI_BCNTPL)) {
331 wlc_update_beacon(wlc);
334 /* PMQ entry addition */
335 if (macintstatus & MI_PMQ) {
339 if (macintstatus & MI_TFS) {
340 if (wlc_bmac_txstatus(wlc->hw, bounded, &fatal))
341 wlc->macintstatus |= MI_TFS;
343 wiphy_err(wiphy, "MI_TFS: fatal\n");
348 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
351 /* ATIM window end */
352 if (macintstatus & MI_ATIMWINEND) {
353 BCMMSG(wlc->wiphy, "end of ATIM window\n");
354 OR_REG(®s->maccommand, wlc->qvalid);
358 /* received data or control frame, MI_DMAINT is indication of RX_FIFO interrupt */
359 if (macintstatus & MI_DMAINT) {
360 if (wlc_bmac_recv(wlc_hw, RX_FIFO, bounded)) {
361 wlc->macintstatus |= MI_DMAINT;
365 /* TX FIFO suspend/flush completion */
366 if (macintstatus & MI_TXSTOP) {
367 if (wlc_bmac_tx_fifo_suspended(wlc_hw, TX_DATA_FIFO)) {
368 /* wiphy_err(wiphy, "dpc: fifo_suspend_comlete\n"); */
372 /* noise sample collected */
373 if (macintstatus & MI_BG_NOISE) {
374 wlc_phy_noise_sample_intr(wlc_hw->band->pi);
377 if (macintstatus & MI_GP0) {
378 wiphy_err(wiphy, "wl%d: PSM microcode watchdog fired at %d "
379 "(seconds). Resetting.\n", wlc_hw->unit, wlc_hw->now);
381 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
382 __func__, wlc_hw->sih->chip,
383 wlc_hw->sih->chiprev);
388 /* gptimer timeout */
389 if (macintstatus & MI_TO) {
390 W_REG(®s->gptimer, 0);
393 if (macintstatus & MI_RFDISABLE) {
394 BCMMSG(wlc->wiphy, "wl%d: BMAC Detected a change on the"
395 " RF Disable Input\n", wlc_hw->unit);
396 brcms_rfkill_set_hw_state(wlc->wl);
399 /* send any enq'd tx packets. Just makes sure to jump start tx */
400 if (!pktq_empty(&wlc->pkt_queue->q))
403 /* it isn't done and needs to be resched if macintstatus is non-zero */
404 return wlc->macintstatus != 0;
408 return wlc->macintstatus != 0;
411 /* common low-level watchdog code */
412 void wlc_bmac_watchdog(void *arg)
414 struct wlc_info *wlc = (struct wlc_info *) arg;
415 struct wlc_hw_info *wlc_hw = wlc->hw;
417 BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
422 /* increment second count */
425 /* Check for FIFO error interrupts */
426 wlc_bmac_fifoerrors(wlc_hw);
428 /* make sure RX dma has buffers */
429 dma_rxfill(wlc->hw->di[RX_FIFO]);
431 wlc_phy_watchdog(wlc_hw->band->pi);
435 wlc_bmac_set_chanspec(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
436 bool mute, struct txpwr_limits *txpwr)
440 BCMMSG(wlc_hw->wlc->wiphy, "wl%d: 0x%x\n", wlc_hw->unit, chanspec);
442 wlc_hw->chanspec = chanspec;
444 /* Switch bands if necessary */
445 if (NBANDS_HW(wlc_hw) > 1) {
446 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
447 if (wlc_hw->band->bandunit != bandunit) {
448 /* wlc_bmac_setband disables other bandunit,
449 * use light band switch if not up yet
452 wlc_phy_chanspec_radio_set(wlc_hw->
453 bandstate[bandunit]->
455 wlc_bmac_setband(wlc_hw, bandunit, chanspec);
457 wlc_setxband(wlc_hw, bandunit);
462 wlc_phy_initcal_enable(wlc_hw->band->pi, !mute);
466 wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr,
468 wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
470 wlc_phy_chanspec_set(wlc_hw->band->pi, chanspec);
471 wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, chanspec);
473 /* Update muting of the channel */
474 wlc_bmac_mute(wlc_hw, mute, 0);
478 int wlc_bmac_state_get(struct wlc_hw_info *wlc_hw, wlc_bmac_state_t *state)
480 state->machwcap = wlc_hw->machwcap;
485 static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
489 /* ucode host flag 2 needed for pio mode, independent of band and fifo */
491 struct wlc_hw_info *wlc_hw = wlc->hw;
492 uint unit = wlc_hw->unit;
493 wlc_tunables_t *tune = wlc->pub->tunables;
494 struct wiphy *wiphy = wlc->wiphy;
496 /* name and offsets for dma_attach */
497 snprintf(name, sizeof(name), "wl%d", unit);
499 if (wlc_hw->di[0] == 0) { /* Init FIFOs */
501 int dma_attach_err = 0;
502 /* Find out the DMA addressing capability and let OS know
503 * All the channels within one DMA core have 'common-minimum' same
507 dma_addrwidth(wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 0));
509 if (!wl_alloc_dma_resources(wlc_hw->wlc->wl, addrwidth)) {
510 wiphy_err(wiphy, "wl%d: wlc_attach: alloc_dma_"
511 "resources failed\n", unit);
517 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
518 * RX: RX_FIFO (RX data packets)
520 wlc_hw->di[0] = dma_attach(name, wlc_hw->sih,
521 (wme ? DMAREG(wlc_hw, DMA_TX, 0) :
522 NULL), DMAREG(wlc_hw, DMA_RX, 0),
523 (wme ? tune->ntxd : 0), tune->nrxd,
524 tune->rxbufsz, -1, tune->nrxbufpost,
525 WL_HWRXOFF, &brcm_msg_level);
526 dma_attach_err |= (NULL == wlc_hw->di[0]);
530 * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets)
531 * (legacy) TX_DATA_FIFO (TX data packets)
534 wlc_hw->di[1] = dma_attach(name, wlc_hw->sih,
535 DMAREG(wlc_hw, DMA_TX, 1), NULL,
536 tune->ntxd, 0, 0, -1, 0, 0,
538 dma_attach_err |= (NULL == wlc_hw->di[1]);
542 * TX: TX_AC_VI_FIFO (TX AC Video data packets)
545 wlc_hw->di[2] = dma_attach(name, wlc_hw->sih,
546 DMAREG(wlc_hw, DMA_TX, 2), NULL,
547 tune->ntxd, 0, 0, -1, 0, 0,
549 dma_attach_err |= (NULL == wlc_hw->di[2]);
552 * TX: TX_AC_VO_FIFO (TX AC Voice data packets)
553 * (legacy) TX_CTL_FIFO (TX control & mgmt packets)
555 wlc_hw->di[3] = dma_attach(name, wlc_hw->sih,
556 DMAREG(wlc_hw, DMA_TX, 3),
557 NULL, tune->ntxd, 0, 0, -1,
558 0, 0, &brcm_msg_level);
559 dma_attach_err |= (NULL == wlc_hw->di[3]);
560 /* Cleaner to leave this as if with AP defined */
562 if (dma_attach_err) {
563 wiphy_err(wiphy, "wl%d: wlc_attach: dma_attach failed"
568 /* get pointer to dma engine tx flow control variable */
569 for (i = 0; i < NFIFO; i++)
572 (uint *) dma_getvar(wlc_hw->di[i],
576 /* initial ucode host flags */
577 wlc_mhfdef(wlc, wlc_hw->band->mhfs, pio_mhf2);
582 static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw)
586 for (j = 0; j < NFIFO; j++) {
588 dma_detach(wlc_hw->di[j]);
589 wlc_hw->di[j] = NULL;
595 * run backplane attach, init nvram
597 * initialize software state for each core and band
598 * put the whole chip in reset(driver down state), no clock
600 int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device, uint unit,
601 bool piomode, void *regsva, uint bustype, void *btparam)
603 struct wlc_hw_info *wlc_hw;
605 char *macaddr = NULL;
610 shared_phy_params_t sha_params;
611 struct wiphy *wiphy = wlc->wiphy;
613 BCMMSG(wlc->wiphy, "wl%d: vendor 0x%x device 0x%x\n", unit, vendor,
621 wlc_hw->band = wlc_hw->bandstate[0];
622 wlc_hw->_piomode = piomode;
624 /* populate struct wlc_hw_info with default values */
625 wlc_bmac_info_init(wlc_hw);
628 * Do the hardware portion of the attach.
629 * Also initialize software state that depends on the particular hardware
632 wlc_hw->sih = ai_attach((uint) device, regsva, bustype, btparam,
633 &wlc_hw->vars, &wlc_hw->vars_size);
634 if (wlc_hw->sih == NULL) {
635 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: si_attach failed\n",
643 * Get vendid/devid nvram overwrites, which could be different
644 * than those the BIOS recognizes for devices on PCMCIA_BUS,
645 * SDIO_BUS, and SROMless devices on PCI_BUS.
648 bustype = BCMBUSTYPE;
650 if (bustype != SI_BUS) {
653 var = getvar(vars, "vendid");
655 vendor = (u16) simple_strtoul(var, NULL, 0);
656 wiphy_err(wiphy, "Overriding vendor id = 0x%x\n",
659 var = getvar(vars, "devid");
661 u16 devid = (u16) simple_strtoul(var, NULL, 0);
662 if (devid != 0xffff) {
664 wiphy_err(wiphy, "Overriding device id = 0x%x"
669 /* verify again the device is supported */
670 if (!wlc_chipmatch(vendor, device)) {
671 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: Unsupported "
672 "vendor/device (0x%x/0x%x)\n",
673 unit, vendor, device);
679 wlc_hw->vendorid = vendor;
680 wlc_hw->deviceid = device;
682 /* set bar0 window to point at D11 core */
683 wlc_hw->regs = (d11regs_t *) ai_setcore(wlc_hw->sih, D11_CORE_ID, 0);
684 wlc_hw->corerev = ai_corerev(wlc_hw->sih);
688 wlc->regs = wlc_hw->regs;
690 /* validate chip, chiprev and corerev */
691 if (!wlc_isgoodchip(wlc_hw)) {
696 /* initialize power control registers */
697 ai_clkctl_init(wlc_hw->sih);
699 /* request fastclock and force fastclock for the rest of attach
700 * bring the d11 core out of reset.
701 * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk is still false;
702 * But it will be called again inside wlc_corereset, after d11 is out of reset.
704 wlc_clkctl_clk(wlc_hw, CLK_FAST);
705 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
707 if (!wlc_bmac_validate_chip_access(wlc_hw)) {
708 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: validate_chip_access "
714 /* get the board rev, used just below */
715 j = getintvar(vars, "boardrev");
716 /* promote srom boardrev of 0xFF to 1 */
717 if (j == BOARDREV_PROMOTABLE)
718 j = BOARDREV_PROMOTED;
719 wlc_hw->boardrev = (u16) j;
720 if (!wlc_validboardtype(wlc_hw)) {
721 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: Unsupported Broadcom "
722 "board type (0x%x)" " or revision level (0x%x)\n",
723 unit, wlc_hw->sih->boardtype, wlc_hw->boardrev);
727 wlc_hw->sromrev = (u8) getintvar(vars, "sromrev");
728 wlc_hw->boardflags = (u32) getintvar(vars, "boardflags");
729 wlc_hw->boardflags2 = (u32) getintvar(vars, "boardflags2");
731 if (wlc_hw->boardflags & BFL_NOPLLDOWN)
732 wlc_bmac_pllreq(wlc_hw, true, WLC_PLLREQ_SHARED);
734 if ((wlc_hw->sih->bustype == PCI_BUS)
735 && (ai_pci_war16165(wlc_hw->sih)))
736 wlc->war16165 = true;
738 /* check device id(srom, nvram etc.) to set bands */
739 if (wlc_hw->deviceid == BCM43224_D11N_ID ||
740 wlc_hw->deviceid == BCM43224_D11N_ID_VEN1) {
741 /* Dualband boards */
746 if ((wlc_hw->sih->chip == BCM43225_CHIP_ID))
749 /* BMAC_NOTE: remove init of pub values when wlc_attach() unconditionally does the
750 * init of these values
752 wlc->vendorid = wlc_hw->vendorid;
753 wlc->deviceid = wlc_hw->deviceid;
754 wlc->pub->sih = wlc_hw->sih;
755 wlc->pub->corerev = wlc_hw->corerev;
756 wlc->pub->sromrev = wlc_hw->sromrev;
757 wlc->pub->boardrev = wlc_hw->boardrev;
758 wlc->pub->boardflags = wlc_hw->boardflags;
759 wlc->pub->boardflags2 = wlc_hw->boardflags2;
760 wlc->pub->_nbands = wlc_hw->_nbands;
762 wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc);
764 if (wlc_hw->physhim == NULL) {
765 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: wlc_phy_shim_attach "
771 /* pass all the parameters to wlc_phy_shared_attach in one struct */
772 sha_params.sih = wlc_hw->sih;
773 sha_params.physhim = wlc_hw->physhim;
774 sha_params.unit = unit;
775 sha_params.corerev = wlc_hw->corerev;
776 sha_params.vars = vars;
777 sha_params.vid = wlc_hw->vendorid;
778 sha_params.did = wlc_hw->deviceid;
779 sha_params.chip = wlc_hw->sih->chip;
780 sha_params.chiprev = wlc_hw->sih->chiprev;
781 sha_params.chippkg = wlc_hw->sih->chippkg;
782 sha_params.sromrev = wlc_hw->sromrev;
783 sha_params.boardtype = wlc_hw->sih->boardtype;
784 sha_params.boardrev = wlc_hw->boardrev;
785 sha_params.boardvendor = wlc_hw->sih->boardvendor;
786 sha_params.boardflags = wlc_hw->boardflags;
787 sha_params.boardflags2 = wlc_hw->boardflags2;
788 sha_params.bustype = wlc_hw->sih->bustype;
789 sha_params.buscorerev = wlc_hw->sih->buscorerev;
791 /* alloc and save pointer to shared phy state area */
792 wlc_hw->phy_sh = wlc_phy_shared_attach(&sha_params);
793 if (!wlc_hw->phy_sh) {
798 /* initialize software state for each core and band */
799 for (j = 0; j < NBANDS_HW(wlc_hw); j++) {
801 * band0 is always 2.4Ghz
802 * band1, if present, is 5Ghz
805 /* So if this is a single band 11a card, use band 1 */
806 if (IS_SINGLEBAND_5G(wlc_hw->deviceid))
809 wlc_setxband(wlc_hw, j);
811 wlc_hw->band->bandunit = j;
812 wlc_hw->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
813 wlc->band->bandunit = j;
814 wlc->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
815 wlc->core->coreidx = ai_coreidx(wlc_hw->sih);
817 wlc_hw->machwcap = R_REG(®s->machwcap);
818 wlc_hw->machwcap_backup = wlc_hw->machwcap;
820 /* init tx fifo size */
822 xmtfifo_sz[(wlc_hw->corerev - XMTFIFOTBL_STARTREV)];
824 /* Get a phy for this band */
825 wlc_hw->band->pi = wlc_phy_attach(wlc_hw->phy_sh,
826 (void *)regs, wlc_bmac_bandtype(wlc_hw), vars,
828 if (wlc_hw->band->pi == NULL) {
829 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: wlc_phy_"
830 "attach failed\n", unit);
835 wlc_phy_machwcap_set(wlc_hw->band->pi, wlc_hw->machwcap);
837 wlc_phy_get_phyversion(wlc_hw->band->pi, &wlc_hw->band->phytype,
838 &wlc_hw->band->phyrev,
839 &wlc_hw->band->radioid,
840 &wlc_hw->band->radiorev);
841 wlc_hw->band->abgphy_encore =
842 wlc_phy_get_encore(wlc_hw->band->pi);
843 wlc->band->abgphy_encore = wlc_phy_get_encore(wlc_hw->band->pi);
844 wlc_hw->band->core_flags =
845 wlc_phy_get_coreflags(wlc_hw->band->pi);
847 /* verify good phy_type & supported phy revision */
848 if (WLCISNPHY(wlc_hw->band)) {
849 if (NCONF_HAS(wlc_hw->band->phyrev))
853 } else if (WLCISLCNPHY(wlc_hw->band)) {
854 if (LCNCONF_HAS(wlc_hw->band->phyrev))
860 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: unsupported "
861 "phy type/rev (%d/%d)\n", unit,
862 wlc_hw->band->phytype, wlc_hw->band->phyrev);
868 /* BMAC_NOTE: wlc->band->pi should not be set below and should be done in the
869 * high level attach. However we can not make that change until all low level access
870 * is changed to wlc_hw->band->pi. Instead do the wlc->band->pi init below, keeping
871 * wlc_hw->band->pi as well for incremental update of low level fns, and cut over
872 * low only init when all fns updated.
874 wlc->band->pi = wlc_hw->band->pi;
875 wlc->band->phytype = wlc_hw->band->phytype;
876 wlc->band->phyrev = wlc_hw->band->phyrev;
877 wlc->band->radioid = wlc_hw->band->radioid;
878 wlc->band->radiorev = wlc_hw->band->radiorev;
880 /* default contention windows size limits */
881 wlc_hw->band->CWmin = APHY_CWMIN;
882 wlc_hw->band->CWmax = PHY_CWMAX;
884 if (!wlc_bmac_attach_dmapio(wlc, j, wme)) {
890 /* disable core to match driver "down" state */
891 wlc_coredisable(wlc_hw);
893 /* Match driver "down" state */
894 if (wlc_hw->sih->bustype == PCI_BUS)
895 ai_pci_down(wlc_hw->sih);
897 /* register sb interrupt callback functions */
898 ai_register_intr_callback(wlc_hw->sih, (void *)wlc_wlintrsoff,
899 (void *)wlc_wlintrsrestore, NULL, wlc);
901 /* turn off pll and xtal to match driver "down" state */
902 wlc_bmac_xtal(wlc_hw, OFF);
904 /* *********************************************************************
905 * The hardware is in the DOWN state at this point. D11 core
906 * or cores are in reset with clocks off, and the board PLLs
907 * are off if possible.
909 * Beyond this point, wlc->sbclk == false and chip registers
910 * should not be touched.
911 *********************************************************************
914 /* init etheraddr state variables */
915 macaddr = wlc_get_macaddr(wlc_hw);
916 if (macaddr == NULL) {
917 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: macaddr not found\n",
922 brcmu_ether_atoe(macaddr, wlc_hw->etheraddr);
923 if (is_broadcast_ether_addr(wlc_hw->etheraddr) ||
924 is_zero_ether_addr(wlc_hw->etheraddr)) {
925 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: bad macaddr %s\n",
932 "deviceid 0x%x nbands %d board 0x%x macaddr: %s\n",
933 wlc_hw->deviceid, wlc_hw->_nbands,
934 wlc_hw->sih->boardtype, macaddr);
939 wiphy_err(wiphy, "wl%d: wlc_bmac_attach: failed with err %d\n", unit,
945 * Initialize wlc_info default values ...
946 * may get overrides later in this function
947 * BMAC_NOTES, move low out and resolve the dangling ones
949 static void wlc_bmac_info_init(struct wlc_hw_info *wlc_hw)
951 struct wlc_info *wlc = wlc_hw->wlc;
953 /* set default sw macintmask value */
954 wlc->defmacintmask = DEF_MACINTMASK;
956 /* various 802.11g modes */
957 wlc_hw->shortslot = false;
959 wlc_hw->SFBL = RETRY_SHORT_FB;
960 wlc_hw->LFBL = RETRY_LONG_FB;
962 /* default mac retry limits */
963 wlc_hw->SRL = RETRY_SHORT_DEF;
964 wlc_hw->LRL = RETRY_LONG_DEF;
965 wlc_hw->chanspec = CH20MHZ_CHSPEC(1);
971 int wlc_bmac_detach(struct wlc_info *wlc)
974 struct wlc_hwband *band;
975 struct wlc_hw_info *wlc_hw = wlc->hw;
981 /* detach interrupt sync mechanism since interrupt is disabled and per-port
982 * interrupt object may has been freed. this must be done before sb core switch
984 ai_deregister_intr_callback(wlc_hw->sih);
986 if (wlc_hw->sih->bustype == PCI_BUS)
987 ai_pci_sleep(wlc_hw->sih);
990 wlc_bmac_detach_dmapio(wlc_hw);
993 for (i = 0; i < NBANDS_HW(wlc_hw); i++) {
995 /* Detach this band's phy */
996 wlc_phy_detach(band->pi);
999 band = wlc_hw->bandstate[OTHERBANDUNIT(wlc)];
1002 /* Free shared phy state */
1003 wlc_phy_shared_detach(wlc_hw->phy_sh);
1005 wlc_phy_shim_detach(wlc_hw->physhim);
1008 kfree(wlc_hw->vars);
1009 wlc_hw->vars = NULL;
1012 ai_detach(wlc_hw->sih);
1020 void wlc_bmac_reset(struct wlc_hw_info *wlc_hw)
1022 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1024 /* reset the core */
1025 if (!DEVICEREMOVED(wlc_hw->wlc))
1026 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
1028 /* purge the dma rings */
1029 wlc_flushqueues(wlc_hw->wlc);
1031 wlc_reset_bmac_done(wlc_hw->wlc);
1035 wlc_bmac_init(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
1039 struct wlc_info *wlc = wlc_hw->wlc;
1041 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1043 /* request FAST clock if not on */
1044 fastclk = wlc_hw->forcefastclk;
1046 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1048 /* disable interrupts */
1049 macintmask = brcms_intrsoff(wlc->wl);
1051 /* set up the specified band and chanspec */
1052 wlc_setxband(wlc_hw, CHSPEC_WLCBANDUNIT(chanspec));
1053 wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
1055 /* do one-time phy inits and calibration */
1056 wlc_phy_cal_init(wlc_hw->band->pi);
1058 /* core-specific initialization */
1061 /* suspend the tx fifos and mute the phy for preism cac time */
1063 wlc_bmac_mute(wlc_hw, ON, PHY_MUTE_FOR_PREISM);
1065 /* band-specific inits */
1066 wlc_bmac_bsinit(wlc, chanspec);
1068 /* restore macintmask */
1069 brcms_intrsrestore(wlc->wl, macintmask);
1071 /* seed wake_override with WLC_WAKE_OVERRIDE_MACSUSPEND since the mac is suspended
1072 * and wlc_enable_mac() will clear this override bit.
1074 mboolset(wlc_hw->wake_override, WLC_WAKE_OVERRIDE_MACSUSPEND);
1077 * initialize mac_suspend_depth to 1 to match ucode initial suspended state
1079 wlc_hw->mac_suspend_depth = 1;
1081 /* restore the clk */
1083 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1086 int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw)
1090 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1093 * Enable pll and xtal, initialize the power control registers,
1094 * and force fastclock for the remainder of wlc_up().
1096 wlc_bmac_xtal(wlc_hw, ON);
1097 ai_clkctl_init(wlc_hw->sih);
1098 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1101 * Configure pci/pcmcia here instead of in wlc_attach()
1102 * to allow mfg hotswap: down, hotswap (chip power cycle), up.
1104 coremask = (1 << wlc_hw->wlc->core->coreidx);
1106 if (wlc_hw->sih->bustype == PCI_BUS)
1107 ai_pci_setup(wlc_hw->sih, coremask);
1110 * Need to read the hwradio status here to cover the case where the system
1111 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
1113 if (wlc_bmac_radio_read_hwdisabled(wlc_hw)) {
1114 /* put SB PCI in down state again */
1115 if (wlc_hw->sih->bustype == PCI_BUS)
1116 ai_pci_down(wlc_hw->sih);
1117 wlc_bmac_xtal(wlc_hw, OFF);
1121 if (wlc_hw->sih->bustype == PCI_BUS)
1122 ai_pci_up(wlc_hw->sih);
1124 /* reset the d11 core */
1125 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
1130 int wlc_bmac_up_finish(struct wlc_hw_info *wlc_hw)
1132 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1135 wlc_phy_hw_state_upd(wlc_hw->band->pi, true);
1137 /* FULLY enable dynamic power control and d11 core interrupt */
1138 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1139 brcms_intrson(wlc_hw->wlc->wl);
1143 int wlc_bmac_down_prep(struct wlc_hw_info *wlc_hw)
1148 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1153 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
1155 /* disable interrupts */
1157 wlc_hw->wlc->macintmask = 0;
1159 /* now disable interrupts */
1160 brcms_intrsoff(wlc_hw->wlc->wl);
1162 /* ensure we're running on the pll clock again */
1163 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1165 /* down phy at the last of this stage */
1166 callbacks += wlc_phy_down(wlc_hw->band->pi);
1171 int wlc_bmac_down_finish(struct wlc_hw_info *wlc_hw)
1176 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1182 wlc_phy_hw_state_upd(wlc_hw->band->pi, false);
1184 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
1187 wlc_hw->sbclk = false;
1188 wlc_hw->clk = false;
1189 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
1191 /* reclaim any posted packets */
1192 wlc_flushqueues(wlc_hw->wlc);
1195 /* Reset and disable the core */
1196 if (ai_iscoreup(wlc_hw->sih)) {
1197 if (R_REG(&wlc_hw->regs->maccontrol) &
1199 wlc_suspend_mac_and_wait(wlc_hw->wlc);
1200 callbacks += brcms_reset(wlc_hw->wlc->wl);
1201 wlc_coredisable(wlc_hw);
1204 /* turn off primary xtal and pll */
1205 if (!wlc_hw->noreset) {
1206 if (wlc_hw->sih->bustype == PCI_BUS)
1207 ai_pci_down(wlc_hw->sih);
1208 wlc_bmac_xtal(wlc_hw, OFF);
1215 void wlc_bmac_wait_for_wake(struct wlc_hw_info *wlc_hw)
1217 /* delay before first read of ucode state */
1220 /* wait until ucode is no longer asleep */
1221 SPINWAIT((wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) ==
1222 DBGST_ASLEEP), wlc_hw->wlc->fastpwrup_dly);
1225 void wlc_bmac_hw_etheraddr(struct wlc_hw_info *wlc_hw, u8 *ea)
1227 memcpy(ea, wlc_hw->etheraddr, ETH_ALEN);
1230 static int wlc_bmac_bandtype(struct wlc_hw_info *wlc_hw)
1232 return wlc_hw->band->bandtype;
1235 /* control chip clock to save power, enable dynamic clock or force fast clock */
1236 static void wlc_clkctl_clk(struct wlc_hw_info *wlc_hw, uint mode)
1238 if (PMUCTL_ENAB(wlc_hw->sih)) {
1239 /* new chips with PMU, CCS_FORCEHT will distribute the HT clock on backplane,
1240 * but mac core will still run on ALP(not HT) when it enters powersave mode,
1241 * which means the FCA bit may not be set.
1242 * should wakeup mac if driver wants it to run on HT.
1246 if (mode == CLK_FAST) {
1247 OR_REG(&wlc_hw->regs->clk_ctl_st,
1254 clk_ctl_st) & CCS_HTAVAIL) == 0),
1255 PMU_MAX_TRANSITION_DLY);
1258 clk_ctl_st) & CCS_HTAVAIL));
1260 if ((wlc_hw->sih->pmurev == 0) &&
1263 clk_ctl_st) & (CCS_FORCEHT | CCS_HTAREQ)))
1266 clk_ctl_st) & CCS_HTAVAIL)
1268 PMU_MAX_TRANSITION_DLY);
1269 AND_REG(&wlc_hw->regs->clk_ctl_st,
1273 wlc_hw->forcefastclk = (mode == CLK_FAST);
1276 /* old chips w/o PMU, force HT through cc,
1277 * then use FCA to verify mac is running fast clock
1280 wlc_hw->forcefastclk = ai_clkctl_cc(wlc_hw->sih, mode);
1282 /* check fast clock is available (if core is not in reset) */
1283 if (wlc_hw->forcefastclk && wlc_hw->clk)
1284 WARN_ON(!(ai_core_sflags(wlc_hw->sih, 0, 0) &
1287 /* keep the ucode wake bit on if forcefastclk is on
1288 * since we do not want ucode to put us back to slow clock
1289 * when it dozes for PM mode.
1290 * Code below matches the wake override bit with current forcefastclk state
1291 * Only setting bit in wake_override instead of waking ucode immediately
1292 * since old code (wlc.c 1.4499) had this behavior. Older code set
1293 * wlc->forcefastclk but only had the wake happen if the wakup_ucode work
1294 * (protected by an up check) was executed just below.
1296 if (wlc_hw->forcefastclk)
1297 mboolset(wlc_hw->wake_override,
1298 WLC_WAKE_OVERRIDE_FORCEFAST);
1300 mboolclr(wlc_hw->wake_override,
1301 WLC_WAKE_OVERRIDE_FORCEFAST);
1305 /* set initial host flags value */
1307 wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init)
1309 struct wlc_hw_info *wlc_hw = wlc->hw;
1311 memset(mhfs, 0, MHFMAX * sizeof(u16));
1313 mhfs[MHF2] |= mhf2_init;
1315 /* prohibit use of slowclock on multifunction boards */
1316 if (wlc_hw->boardflags & BFL_NOPLLDOWN)
1317 mhfs[MHF1] |= MHF1_FORCEFASTCLK;
1319 if (WLCISNPHY(wlc_hw->band) && NREV_LT(wlc_hw->band->phyrev, 2)) {
1320 mhfs[MHF2] |= MHF2_NPHY40MHZ_WAR;
1321 mhfs[MHF1] |= MHF1_IQSWAP_WAR;
1325 /* set or clear ucode host flag bits
1326 * it has an optimization for no-change write
1327 * it only writes through shared memory when the core has clock;
1328 * pre-CLK changes should use wlc_write_mhf to get around the optimization
1331 * bands values are: WLC_BAND_AUTO <--- Current band only
1332 * WLC_BAND_5G <--- 5G band only
1333 * WLC_BAND_2G <--- 2G band only
1334 * WLC_BAND_ALL <--- All bands
1337 wlc_bmac_mhf(struct wlc_hw_info *wlc_hw, u8 idx, u16 mask, u16 val,
1341 u16 addr[MHFMAX] = {
1342 M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
1345 struct wlc_hwband *band;
1347 if ((val & ~mask) || idx >= MHFMAX)
1348 return; /* error condition */
1351 /* Current band only or all bands,
1352 * then set the band to current band
1356 band = wlc_hw->band;
1359 band = wlc_hw->bandstate[BAND_5G_INDEX];
1362 band = wlc_hw->bandstate[BAND_2G_INDEX];
1365 band = NULL; /* error condition */
1369 save = band->mhfs[idx];
1370 band->mhfs[idx] = (band->mhfs[idx] & ~mask) | val;
1372 /* optimization: only write through if changed, and
1373 * changed band is the current band
1375 if (wlc_hw->clk && (band->mhfs[idx] != save)
1376 && (band == wlc_hw->band))
1377 wlc_bmac_write_shm(wlc_hw, addr[idx],
1378 (u16) band->mhfs[idx]);
1381 if (bands == WLC_BAND_ALL) {
1382 wlc_hw->bandstate[0]->mhfs[idx] =
1383 (wlc_hw->bandstate[0]->mhfs[idx] & ~mask) | val;
1384 wlc_hw->bandstate[1]->mhfs[idx] =
1385 (wlc_hw->bandstate[1]->mhfs[idx] & ~mask) | val;
1389 u16 wlc_bmac_mhf_get(struct wlc_hw_info *wlc_hw, u8 idx, int bands)
1391 struct wlc_hwband *band;
1394 return 0; /* error condition */
1397 band = wlc_hw->band;
1400 band = wlc_hw->bandstate[BAND_5G_INDEX];
1403 band = wlc_hw->bandstate[BAND_2G_INDEX];
1406 band = NULL; /* error condition */
1412 return band->mhfs[idx];
1415 static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs)
1419 M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
1423 for (idx = 0; idx < MHFMAX; idx++) {
1424 wlc_bmac_write_shm(wlc_hw, addr[idx], mhfs[idx]);
1428 /* set the maccontrol register to desired reset state and
1429 * initialize the sw cache of the register
1431 static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw)
1433 /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
1434 wlc_hw->maccontrol = 0;
1435 wlc_hw->suspended_fifos = 0;
1436 wlc_hw->wake_override = 0;
1437 wlc_hw->mute_override = 0;
1438 wlc_bmac_mctrl(wlc_hw, ~0, MCTL_IHR_EN | MCTL_WAKE);
1441 /* set or clear maccontrol bits */
1442 void wlc_bmac_mctrl(struct wlc_hw_info *wlc_hw, u32 mask, u32 val)
1448 return; /* error condition */
1449 maccontrol = wlc_hw->maccontrol;
1450 new_maccontrol = (maccontrol & ~mask) | val;
1452 /* if the new maccontrol value is the same as the old, nothing to do */
1453 if (new_maccontrol == maccontrol)
1456 /* something changed, cache the new value */
1457 wlc_hw->maccontrol = new_maccontrol;
1459 /* write the new values with overrides applied */
1460 wlc_mctrl_write(wlc_hw);
1463 /* write the software state of maccontrol and overrides to the maccontrol register */
1464 static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw)
1466 u32 maccontrol = wlc_hw->maccontrol;
1468 /* OR in the wake bit if overridden */
1469 if (wlc_hw->wake_override)
1470 maccontrol |= MCTL_WAKE;
1472 /* set AP and INFRA bits for mute if needed */
1473 if (wlc_hw->mute_override) {
1474 maccontrol &= ~(MCTL_AP);
1475 maccontrol |= MCTL_INFRA;
1478 W_REG(&wlc_hw->regs->maccontrol, maccontrol);
1481 void wlc_ucode_wake_override_set(struct wlc_hw_info *wlc_hw, u32 override_bit)
1483 if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) {
1484 mboolset(wlc_hw->wake_override, override_bit);
1488 mboolset(wlc_hw->wake_override, override_bit);
1490 wlc_mctrl_write(wlc_hw);
1491 wlc_bmac_wait_for_wake(wlc_hw);
1496 void wlc_ucode_wake_override_clear(struct wlc_hw_info *wlc_hw, u32 override_bit)
1498 mboolclr(wlc_hw->wake_override, override_bit);
1500 if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE))
1503 wlc_mctrl_write(wlc_hw);
1508 /* When driver needs ucode to stop beaconing, it has to make sure that
1509 * MCTL_AP is clear and MCTL_INFRA is set
1510 * Mode MCTL_AP MCTL_INFRA
1512 * STA 0 1 <--- This will ensure no beacons
1515 static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw)
1517 wlc_hw->mute_override = 1;
1519 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1520 * override, then there is no change to write
1522 if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
1525 wlc_mctrl_write(wlc_hw);
1530 /* Clear the override on AP and INFRA bits */
1531 static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw)
1533 if (wlc_hw->mute_override == 0)
1536 wlc_hw->mute_override = 0;
1538 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1539 * override, then there is no change to write
1541 if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
1544 wlc_mctrl_write(wlc_hw);
1548 * Write a MAC address to the given match reg offset in the RXE match engine.
1551 wlc_bmac_set_addrmatch(struct wlc_hw_info *wlc_hw, int match_reg_offset,
1559 BCMMSG(wlc_hw->wlc->wiphy, "wl%d: wlc_bmac_set_addrmatch\n",
1562 regs = wlc_hw->regs;
1563 mac_l = addr[0] | (addr[1] << 8);
1564 mac_m = addr[2] | (addr[3] << 8);
1565 mac_h = addr[4] | (addr[5] << 8);
1567 /* enter the MAC addr into the RXE match registers */
1568 W_REG(®s->rcm_ctl, RCM_INC_DATA | match_reg_offset);
1569 W_REG(®s->rcm_mat_data, mac_l);
1570 W_REG(®s->rcm_mat_data, mac_m);
1571 W_REG(®s->rcm_mat_data, mac_h);
1576 wlc_bmac_write_template_ram(struct wlc_hw_info *wlc_hw, int offset, int len,
1582 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1584 regs = wlc_hw->regs;
1585 W_REG(®s->tplatewrptr, offset);
1587 /* if MCTL_BIGEND bit set in mac control register,
1588 * the chip swaps data in fifo, as well as data in
1591 be_bit = (R_REG(®s->maccontrol) & MCTL_BIGEND) != 0;
1594 memcpy(&word, buf, sizeof(u32));
1597 word = cpu_to_be32(word);
1599 word = cpu_to_le32(word);
1601 W_REG(®s->tplatewrdata, word);
1603 buf = (u8 *) buf + sizeof(u32);
1608 void wlc_bmac_set_cwmin(struct wlc_hw_info *wlc_hw, u16 newmin)
1610 wlc_hw->band->CWmin = newmin;
1612 W_REG(&wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMIN);
1613 (void)R_REG(&wlc_hw->regs->objaddr);
1614 W_REG(&wlc_hw->regs->objdata, newmin);
1617 void wlc_bmac_set_cwmax(struct wlc_hw_info *wlc_hw, u16 newmax)
1619 wlc_hw->band->CWmax = newmax;
1621 W_REG(&wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMAX);
1622 (void)R_REG(&wlc_hw->regs->objaddr);
1623 W_REG(&wlc_hw->regs->objdata, newmax);
1626 void wlc_bmac_bw_set(struct wlc_hw_info *wlc_hw, u16 bw)
1630 /* request FAST clock if not on */
1631 fastclk = wlc_hw->forcefastclk;
1633 wlc_clkctl_clk(wlc_hw, CLK_FAST);
1635 wlc_phy_bw_state_set(wlc_hw->band->pi, bw);
1637 wlc_bmac_phy_reset(wlc_hw);
1638 wlc_phy_init(wlc_hw->band->pi, wlc_phy_chanspec_get(wlc_hw->band->pi));
1640 /* restore the clk */
1642 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1646 wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn, int len)
1648 d11regs_t *regs = wlc_hw->regs;
1650 wlc_bmac_write_template_ram(wlc_hw, T_BCN0_TPL_BASE, (len + 3) & ~3,
1652 /* write beacon length to SCR */
1653 wlc_bmac_write_shm(wlc_hw, M_BCN0_FRM_BYTESZ, (u16) len);
1654 /* mark beacon0 valid */
1655 OR_REG(®s->maccommand, MCMD_BCN0VLD);
1659 wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn, int len)
1661 d11regs_t *regs = wlc_hw->regs;
1663 wlc_bmac_write_template_ram(wlc_hw, T_BCN1_TPL_BASE, (len + 3) & ~3,
1665 /* write beacon length to SCR */
1666 wlc_bmac_write_shm(wlc_hw, M_BCN1_FRM_BYTESZ, (u16) len);
1667 /* mark beacon1 valid */
1668 OR_REG(®s->maccommand, MCMD_BCN1VLD);
1671 /* mac is assumed to be suspended at this point */
1673 wlc_bmac_write_hw_bcntemplates(struct wlc_hw_info *wlc_hw, void *bcn, int len,
1676 d11regs_t *regs = wlc_hw->regs;
1679 wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
1680 wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
1683 if (!(R_REG(®s->maccommand) & MCMD_BCN0VLD))
1684 wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
1687 (R_REG(®s->maccommand) & MCMD_BCN1VLD))
1688 wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
1692 static void WLBANDINITFN(wlc_bmac_upd_synthpu) (struct wlc_hw_info *wlc_hw)
1695 struct wlc_info *wlc = wlc_hw->wlc;
1696 /* update SYNTHPU_DLY */
1698 if (WLCISLCNPHY(wlc->band)) {
1699 v = SYNTHPU_DLY_LPPHY_US;
1700 } else if (WLCISNPHY(wlc->band) && (NREV_GE(wlc->band->phyrev, 3))) {
1701 v = SYNTHPU_DLY_NPHY_US;
1703 v = SYNTHPU_DLY_BPHY_US;
1706 wlc_bmac_write_shm(wlc_hw, M_SYNTHPU_DLY, v);
1709 /* band-specific init */
1711 WLBANDINITFN(wlc_bmac_bsinit) (struct wlc_info *wlc, chanspec_t chanspec)
1713 struct wlc_hw_info *wlc_hw = wlc->hw;
1715 BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
1716 wlc_hw->band->bandunit);
1718 wlc_ucode_bsinit(wlc_hw);
1720 wlc_phy_init(wlc_hw->band->pi, chanspec);
1722 wlc_ucode_txant_set(wlc_hw);
1724 /* cwmin is band-specific, update hardware with value for current band */
1725 wlc_bmac_set_cwmin(wlc_hw, wlc_hw->band->CWmin);
1726 wlc_bmac_set_cwmax(wlc_hw, wlc_hw->band->CWmax);
1728 wlc_bmac_update_slot_timing(wlc_hw,
1729 BAND_5G(wlc_hw->band->
1730 bandtype) ? true : wlc_hw->
1733 /* write phytype and phyvers */
1734 wlc_bmac_write_shm(wlc_hw, M_PHYTYPE, (u16) wlc_hw->band->phytype);
1735 wlc_bmac_write_shm(wlc_hw, M_PHYVER, (u16) wlc_hw->band->phyrev);
1737 /* initialize the txphyctl1 rate table since shmem is shared between bands */
1738 wlc_upd_ofdm_pctl1_table(wlc_hw);
1740 wlc_bmac_upd_synthpu(wlc_hw);
1743 static void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk)
1745 BCMMSG(wlc_hw->wlc->wiphy, "wl%d: clk %d\n", wlc_hw->unit, clk);
1747 wlc_hw->phyclk = clk;
1749 if (OFF == clk) { /* clear gmode bit, put phy into reset */
1751 ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC | SICF_GMODE),
1752 (SICF_PRST | SICF_FGC));
1754 ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_PRST);
1757 } else { /* take phy out of reset */
1759 ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_FGC);
1761 ai_core_cflags(wlc_hw->sih, (SICF_FGC), 0);
1767 /* Perform a soft reset of the PHY PLL */
1768 void wlc_bmac_core_phypll_reset(struct wlc_hw_info *wlc_hw)
1770 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1772 ai_corereg(wlc_hw->sih, SI_CC_IDX,
1773 offsetof(chipcregs_t, chipcontrol_addr), ~0, 0);
1775 ai_corereg(wlc_hw->sih, SI_CC_IDX,
1776 offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
1778 ai_corereg(wlc_hw->sih, SI_CC_IDX,
1779 offsetof(chipcregs_t, chipcontrol_data), 0x4, 4);
1781 ai_corereg(wlc_hw->sih, SI_CC_IDX,
1782 offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
1786 /* light way to turn on phy clock without reset for NPHY only
1787 * refer to wlc_bmac_core_phy_clk for full version
1789 void wlc_bmac_phyclk_fgc(struct wlc_hw_info *wlc_hw, bool clk)
1791 /* support(necessary for NPHY and HYPHY) only */
1792 if (!WLCISNPHY(wlc_hw->band))
1796 ai_core_cflags(wlc_hw->sih, SICF_FGC, SICF_FGC);
1798 ai_core_cflags(wlc_hw->sih, SICF_FGC, 0);
1802 void wlc_bmac_macphyclk_set(struct wlc_hw_info *wlc_hw, bool clk)
1805 ai_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE);
1807 ai_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0);
1810 void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw)
1812 wlc_phy_t *pih = wlc_hw->band->pi;
1814 bool phy_in_reset = false;
1816 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
1821 phy_bw_clkbits = wlc_phy_clk_bwbits(wlc_hw->band->pi);
1823 /* Specific reset sequence required for NPHY rev 3 and 4 */
1824 if (WLCISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) &&
1825 NREV_LE(wlc_hw->band->phyrev, 4)) {
1826 /* Set the PHY bandwidth */
1827 ai_core_cflags(wlc_hw->sih, SICF_BWMASK, phy_bw_clkbits);
1831 /* Perform a soft reset of the PHY PLL */
1832 wlc_bmac_core_phypll_reset(wlc_hw);
1835 ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_PCLKE),
1836 (SICF_PRST | SICF_PCLKE));
1837 phy_in_reset = true;
1840 ai_core_cflags(wlc_hw->sih,
1841 (SICF_PRST | SICF_PCLKE | SICF_BWMASK),
1842 (SICF_PRST | SICF_PCLKE | phy_bw_clkbits));
1846 wlc_bmac_core_phy_clk(wlc_hw, ON);
1849 wlc_phy_anacore(pih, ON);
1852 /* switch to and initialize new band */
1854 WLBANDINITFN(wlc_bmac_setband) (struct wlc_hw_info *wlc_hw, uint bandunit,
1855 chanspec_t chanspec) {
1856 struct wlc_info *wlc = wlc_hw->wlc;
1859 /* Enable the d11 core before accessing it */
1860 if (!ai_iscoreup(wlc_hw->sih)) {
1861 ai_core_reset(wlc_hw->sih, 0, 0);
1862 wlc_mctrl_reset(wlc_hw);
1865 macintmask = wlc_setband_inact(wlc, bandunit);
1870 wlc_bmac_core_phy_clk(wlc_hw, ON);
1872 /* band-specific initializations */
1873 wlc_bmac_bsinit(wlc, chanspec);
1876 * If there are any pending software interrupt bits,
1877 * then replace these with a harmless nonzero value
1878 * so wlc_dpc() will re-enable interrupts when done.
1880 if (wlc->macintstatus)
1881 wlc->macintstatus = MI_DMAINT;
1883 /* restore macintmask */
1884 brcms_intrsrestore(wlc->wl, macintmask);
1886 /* ucode should still be suspended.. */
1887 WARN_ON((R_REG(&wlc_hw->regs->maccontrol) & MCTL_EN_MAC) != 0);
1890 /* low-level band switch utility routine */
1891 void WLBANDINITFN(wlc_setxband) (struct wlc_hw_info *wlc_hw, uint bandunit)
1893 BCMMSG(wlc_hw->wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
1896 wlc_hw->band = wlc_hw->bandstate[bandunit];
1898 /* BMAC_NOTE: until we eliminate need for wlc->band refs in low level code */
1899 wlc_hw->wlc->band = wlc_hw->wlc->bandstate[bandunit];
1901 /* set gmode core flag */
1902 if (wlc_hw->sbclk && !wlc_hw->noreset) {
1903 ai_core_cflags(wlc_hw->sih, SICF_GMODE,
1904 ((bandunit == 0) ? SICF_GMODE : 0));
1908 static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw)
1911 /* reject unsupported corerev */
1912 if (!VALID_COREREV(wlc_hw->corerev)) {
1913 wiphy_err(wlc_hw->wlc->wiphy, "unsupported core rev %d\n",
1921 static bool wlc_validboardtype(struct wlc_hw_info *wlc_hw)
1923 bool goodboard = true;
1924 uint boardrev = wlc_hw->boardrev;
1928 else if (boardrev > 0xff) {
1929 uint brt = (boardrev & 0xf000) >> 12;
1930 uint b0 = (boardrev & 0xf00) >> 8;
1931 uint b1 = (boardrev & 0xf0) >> 4;
1932 uint b2 = boardrev & 0xf;
1934 if ((brt > 2) || (brt == 0) || (b0 > 9) || (b0 == 0) || (b1 > 9)
1939 if (wlc_hw->sih->boardvendor != PCI_VENDOR_ID_BROADCOM)
1945 static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw)
1947 const char *varname = "macaddr";
1950 /* If macaddr exists, use it (Sromrev4, CIS, ...). */
1951 macaddr = getvar(wlc_hw->vars, varname);
1952 if (macaddr != NULL)
1955 if (NBANDS_HW(wlc_hw) > 1)
1956 varname = "et1macaddr";
1958 varname = "il0macaddr";
1960 macaddr = getvar(wlc_hw->vars, varname);
1961 if (macaddr == NULL) {
1962 wiphy_err(wlc_hw->wlc->wiphy, "wl%d: wlc_get_macaddr: macaddr "
1963 "getvar(%s) not found\n", wlc_hw->unit, varname);
1970 * Return true if radio is disabled, otherwise false.
1971 * hw radio disable signal is an external pin, users activate it asynchronously
1972 * this function could be called when driver is down and w/o clock
1973 * it operates on different registers depending on corerev and boardflag.
1975 bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info *wlc_hw)
1978 u32 resetbits = 0, flags = 0;
1980 xtal = wlc_hw->sbclk;
1982 wlc_bmac_xtal(wlc_hw, ON);
1984 /* may need to take core out of reset first */
1988 * mac no longer enables phyclk automatically when driver
1989 * accesses phyreg throughput mac. This can be skipped since
1990 * only mac reg is accessed below
1992 flags |= SICF_PCLKE;
1994 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
1995 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
1996 (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
1997 (wlc_hw->sih->chip == BCM43421_CHIP_ID))
1999 (d11regs_t *) ai_setcore(wlc_hw->sih, D11_CORE_ID,
2001 ai_core_reset(wlc_hw->sih, flags, resetbits);
2002 wlc_mctrl_reset(wlc_hw);
2005 v = ((R_REG(&wlc_hw->regs->phydebug) & PDBG_RFD) != 0);
2007 /* put core back into reset */
2009 ai_core_disable(wlc_hw->sih, 0);
2012 wlc_bmac_xtal(wlc_hw, OFF);
2017 /* Initialize just the hardware when coming out of POR or S3/S5 system states */
2018 void wlc_bmac_hw_up(struct wlc_hw_info *wlc_hw)
2020 if (wlc_hw->wlc->pub->hw_up)
2023 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
2026 * Enable pll and xtal, initialize the power control registers,
2027 * and force fastclock for the remainder of wlc_up().
2029 wlc_bmac_xtal(wlc_hw, ON);
2030 ai_clkctl_init(wlc_hw->sih);
2031 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2033 if (wlc_hw->sih->bustype == PCI_BUS) {
2034 ai_pci_fixcfg(wlc_hw->sih);
2036 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2037 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2038 (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
2039 (wlc_hw->sih->chip == BCM43421_CHIP_ID))
2041 (d11regs_t *) ai_setcore(wlc_hw->sih, D11_CORE_ID,
2045 /* Inform phy that a POR reset has occurred so it does a complete phy init */
2046 wlc_phy_por_inform(wlc_hw->band->pi);
2048 wlc_hw->ucode_loaded = false;
2049 wlc_hw->wlc->pub->hw_up = true;
2051 if ((wlc_hw->boardflags & BFL_FEM)
2052 && (wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
2054 (wlc_hw->boardrev >= 0x1250
2055 && (wlc_hw->boardflags & BFL_FEM_BT)))
2056 ai_epa_4313war(wlc_hw->sih);
2060 static bool wlc_dma_rxreset(struct wlc_hw_info *wlc_hw, uint fifo)
2062 struct dma_pub *di = wlc_hw->di[fifo];
2063 return dma_rxreset(di);
2067 * ensure fask clock during reset
2069 * reset d11(out of reset)
2070 * reset phy(out of reset)
2071 * clear software macintstatus for fresh new start
2072 * one testing hack wlc_hw->noreset will bypass the d11/phy reset
2074 void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags)
2081 if (flags == WLC_USE_COREFLAGS)
2082 flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0);
2084 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
2086 regs = wlc_hw->regs;
2088 /* request FAST clock if not on */
2089 fastclk = wlc_hw->forcefastclk;
2091 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2093 /* reset the dma engines except first time thru */
2094 if (ai_iscoreup(wlc_hw->sih)) {
2095 for (i = 0; i < NFIFO; i++)
2096 if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) {
2097 wiphy_err(wlc_hw->wlc->wiphy, "wl%d: %s: "
2098 "dma_txreset[%d]: cannot stop dma\n",
2099 wlc_hw->unit, __func__, i);
2102 if ((wlc_hw->di[RX_FIFO])
2103 && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) {
2104 wiphy_err(wlc_hw->wlc->wiphy, "wl%d: %s: dma_rxreset"
2105 "[%d]: cannot stop dma\n",
2106 wlc_hw->unit, __func__, RX_FIFO);
2109 /* if noreset, just stop the psm and return */
2110 if (wlc_hw->noreset) {
2111 wlc_hw->wlc->macintstatus = 0; /* skip wl_dpc after down */
2112 wlc_bmac_mctrl(wlc_hw, MCTL_PSM_RUN | MCTL_EN_MAC, 0);
2117 * mac no longer enables phyclk automatically when driver accesses
2118 * phyreg throughput mac, AND phy_reset is skipped at early stage when
2119 * band->pi is invalid. need to enable PHY CLK
2121 flags |= SICF_PCLKE;
2124 * In chips with PMU, the fastclk request goes through d11 core reg 0x1e0, which
2125 * is cleared by the core_reset. have to re-request it.
2126 * This adds some delay and we can optimize it by also requesting fastclk through
2127 * chipcommon during this period if necessary. But that has to work coordinate
2128 * with other driver like mips/arm since they may touch chipcommon as well.
2130 wlc_hw->clk = false;
2131 ai_core_reset(wlc_hw->sih, flags, resetbits);
2133 if (wlc_hw->band && wlc_hw->band->pi)
2134 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true);
2136 wlc_mctrl_reset(wlc_hw);
2138 if (PMUCTL_ENAB(wlc_hw->sih))
2139 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2141 wlc_bmac_phy_reset(wlc_hw);
2143 /* turn on PHY_PLL */
2144 wlc_bmac_core_phypll_ctl(wlc_hw, true);
2146 /* clear sw intstatus */
2147 wlc_hw->wlc->macintstatus = 0;
2149 /* restore the clk setting */
2151 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
2154 /* txfifo sizes needs to be modified(increased) since the newer cores
2157 static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw)
2159 d11regs_t *regs = wlc_hw->regs;
2161 u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk;
2162 u16 txfifo_def, txfifo_def1;
2165 /* tx fifos start at TXFIFO_START_BLK from the Base address */
2166 txfifo_startblk = TXFIFO_START_BLK;
2168 /* sequence of operations: reset fifo, set fifo size, reset fifo */
2169 for (fifo_nu = 0; fifo_nu < NFIFO; fifo_nu++) {
2171 txfifo_endblk = txfifo_startblk + wlc_hw->xmtfifo_sz[fifo_nu];
2172 txfifo_def = (txfifo_startblk & 0xff) |
2173 (((txfifo_endblk - 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT);
2174 txfifo_def1 = ((txfifo_startblk >> 8) & 0x1) |
2176 1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT);
2178 TXFIFOCMD_RESET_MASK | (fifo_nu << TXFIFOCMD_FIFOSEL_SHIFT);
2180 W_REG(®s->xmtfifocmd, txfifo_cmd);
2181 W_REG(®s->xmtfifodef, txfifo_def);
2182 W_REG(®s->xmtfifodef1, txfifo_def1);
2184 W_REG(®s->xmtfifocmd, txfifo_cmd);
2186 txfifo_startblk += wlc_hw->xmtfifo_sz[fifo_nu];
2189 * need to propagate to shm location to be in sync since ucode/hw won't
2192 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE0,
2193 wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]);
2194 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE1,
2195 wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]);
2196 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE2,
2197 ((wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO] << 8) | wlc_hw->
2198 xmtfifo_sz[TX_AC_BK_FIFO]));
2199 wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE3,
2200 ((wlc_hw->xmtfifo_sz[TX_ATIM_FIFO] << 8) | wlc_hw->
2201 xmtfifo_sz[TX_BCMC_FIFO]));
2206 * download ucode/PCM
2207 * let ucode run to suspended
2208 * download ucode inits
2209 * config other core registers
2212 static void wlc_coreinit(struct wlc_info *wlc)
2214 struct wlc_hw_info *wlc_hw = wlc->hw;
2219 bool fifosz_fixup = false;
2222 struct wiphy *wiphy = wlc->wiphy;
2224 regs = wlc_hw->regs;
2226 BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
2229 wlc_bmac_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE));
2231 wlc_ucode_download(wlc_hw);
2233 * FIFOSZ fixup. driver wants to controls the fifo allocation.
2235 fifosz_fixup = true;
2237 /* let the PSM run to the suspended state, set mode to BSS STA */
2238 W_REG(®s->macintstatus, -1);
2239 wlc_bmac_mctrl(wlc_hw, ~0,
2240 (MCTL_IHR_EN | MCTL_INFRA | MCTL_PSM_RUN | MCTL_WAKE));
2242 /* wait for ucode to self-suspend after auto-init */
2243 SPINWAIT(((R_REG(®s->macintstatus) & MI_MACSSPNDD) == 0),
2245 if ((R_REG(®s->macintstatus) & MI_MACSSPNDD) == 0)
2246 wiphy_err(wiphy, "wl%d: wlc_coreinit: ucode did not self-"
2247 "suspend!\n", wlc_hw->unit);
2251 sflags = ai_core_sflags(wlc_hw->sih, 0, 0);
2253 if (D11REV_IS(wlc_hw->corerev, 23)) {
2254 if (WLCISNPHY(wlc_hw->band))
2255 wlc_write_inits(wlc_hw, d11n0initvals16);
2257 wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev"
2258 " %d\n", __func__, wlc_hw->unit,
2260 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2261 if (WLCISLCNPHY(wlc_hw->band)) {
2262 wlc_write_inits(wlc_hw, d11lcn0initvals24);
2264 wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev"
2265 " %d\n", __func__, wlc_hw->unit,
2269 wiphy_err(wiphy, "%s: wl%d: unsupported corerev %d\n",
2270 __func__, wlc_hw->unit, wlc_hw->corerev);
2273 /* For old ucode, txfifo sizes needs to be modified(increased) */
2274 if (fifosz_fixup == true) {
2275 wlc_corerev_fifofixup(wlc_hw);
2278 /* check txfifo allocations match between ucode and driver */
2279 buf[TX_AC_BE_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE0);
2280 if (buf[TX_AC_BE_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]) {
2284 buf[TX_AC_VI_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE1);
2285 if (buf[TX_AC_VI_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]) {
2289 buf[TX_AC_BK_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE2);
2290 buf[TX_AC_VO_FIFO] = (buf[TX_AC_BK_FIFO] >> 8) & 0xff;
2291 buf[TX_AC_BK_FIFO] &= 0xff;
2292 if (buf[TX_AC_BK_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BK_FIFO]) {
2296 if (buf[TX_AC_VO_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO]) {
2300 buf[TX_BCMC_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE3);
2301 buf[TX_ATIM_FIFO] = (buf[TX_BCMC_FIFO] >> 8) & 0xff;
2302 buf[TX_BCMC_FIFO] &= 0xff;
2303 if (buf[TX_BCMC_FIFO] != wlc_hw->xmtfifo_sz[TX_BCMC_FIFO]) {
2307 if (buf[TX_ATIM_FIFO] != wlc_hw->xmtfifo_sz[TX_ATIM_FIFO]) {
2312 wiphy_err(wiphy, "wlc_coreinit: txfifo mismatch: ucode size %d"
2313 " driver size %d index %d\n", buf[i],
2314 wlc_hw->xmtfifo_sz[i], i);
2317 /* make sure we can still talk to the mac */
2318 WARN_ON(R_REG(®s->maccontrol) == 0xffffffff);
2320 /* band-specific inits done by wlc_bsinit() */
2322 /* Set up frame burst size and antenna swap threshold init values */
2323 wlc_bmac_write_shm(wlc_hw, M_MBURST_SIZE, MAXTXFRAMEBURST);
2324 wlc_bmac_write_shm(wlc_hw, M_MAX_ANTCNT, ANTCNT);
2326 /* enable one rx interrupt per received frame */
2327 W_REG(®s->intrcvlazy[0], (1 << IRL_FC_SHIFT));
2329 /* set the station mode (BSS STA) */
2330 wlc_bmac_mctrl(wlc_hw,
2331 (MCTL_INFRA | MCTL_DISCARD_PMQ | MCTL_AP),
2332 (MCTL_INFRA | MCTL_DISCARD_PMQ));
2334 /* set up Beacon interval */
2335 bcnint_us = 0x8000 << 10;
2336 W_REG(®s->tsf_cfprep, (bcnint_us << CFPREP_CBI_SHIFT));
2337 W_REG(®s->tsf_cfpstart, bcnint_us);
2338 W_REG(®s->macintstatus, MI_GP1);
2340 /* write interrupt mask */
2341 W_REG(®s->intctrlregs[RX_FIFO].intmask, DEF_RXINTMASK);
2343 /* allow the MAC to control the PHY clock (dynamic on/off) */
2344 wlc_bmac_macphyclk_set(wlc_hw, ON);
2346 /* program dynamic clock control fast powerup delay register */
2347 wlc->fastpwrup_dly = ai_clkctl_fast_pwrup_delay(wlc_hw->sih);
2348 W_REG(®s->scc_fastpwrup_dly, wlc->fastpwrup_dly);
2350 /* tell the ucode the corerev */
2351 wlc_bmac_write_shm(wlc_hw, M_MACHW_VER, (u16) wlc_hw->corerev);
2353 /* tell the ucode MAC capabilities */
2354 wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_L,
2355 (u16) (wlc_hw->machwcap & 0xffff));
2356 wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_H,
2358 machwcap >> 16) & 0xffff));
2360 /* write retry limits to SCR, this done after PSM init */
2361 W_REG(®s->objaddr, OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
2362 (void)R_REG(®s->objaddr);
2363 W_REG(®s->objdata, wlc_hw->SRL);
2364 W_REG(®s->objaddr, OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
2365 (void)R_REG(®s->objaddr);
2366 W_REG(®s->objdata, wlc_hw->LRL);
2368 /* write rate fallback retry limits */
2369 wlc_bmac_write_shm(wlc_hw, M_SFRMTXCNTFBRTHSD, wlc_hw->SFBL);
2370 wlc_bmac_write_shm(wlc_hw, M_LFRMTXCNTFBRTHSD, wlc_hw->LFBL);
2372 AND_REG(®s->ifs_ctl, 0x0FFF);
2373 W_REG(®s->ifs_aifsn, EDCF_AIFSN_MIN);
2375 /* dma initializations */
2376 wlc->txpend16165war = 0;
2378 /* init the tx dma engines */
2379 for (i = 0; i < NFIFO; i++) {
2381 dma_txinit(wlc_hw->di[i]);
2384 /* init the rx dma engine(s) and post receive buffers */
2385 dma_rxinit(wlc_hw->di[RX_FIFO]);
2386 dma_rxfill(wlc_hw->di[RX_FIFO]);
2389 /* This function is used for changing the tsf frac register
2390 * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz
2391 * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz
2392 * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz
2393 * HTPHY Formula is 2^26/freq(MHz) e.g.
2394 * For spuron2 - 126MHz -> 2^26/126 = 532610.0
2395 * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082
2396 * For spuron: 123MHz -> 2^26/123 = 545600.5
2397 * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341
2398 * For spur off: 120MHz -> 2^26/120 = 559240.5
2399 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
2402 void wlc_bmac_switch_macfreq(struct wlc_hw_info *wlc_hw, u8 spurmode)
2405 regs = wlc_hw->regs;
2407 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2408 (wlc_hw->sih->chip == BCM43225_CHIP_ID)) {
2409 if (spurmode == WL_SPURAVOID_ON2) { /* 126Mhz */
2410 W_REG(®s->tsf_clk_frac_l, 0x2082);
2411 W_REG(®s->tsf_clk_frac_h, 0x8);
2412 } else if (spurmode == WL_SPURAVOID_ON1) { /* 123Mhz */
2413 W_REG(®s->tsf_clk_frac_l, 0x5341);
2414 W_REG(®s->tsf_clk_frac_h, 0x8);
2415 } else { /* 120Mhz */
2416 W_REG(®s->tsf_clk_frac_l, 0x8889);
2417 W_REG(®s->tsf_clk_frac_h, 0x8);
2419 } else if (WLCISLCNPHY(wlc_hw->band)) {
2420 if (spurmode == WL_SPURAVOID_ON1) { /* 82Mhz */
2421 W_REG(®s->tsf_clk_frac_l, 0x7CE0);
2422 W_REG(®s->tsf_clk_frac_h, 0xC);
2423 } else { /* 80Mhz */
2424 W_REG(®s->tsf_clk_frac_l, 0xCCCD);
2425 W_REG(®s->tsf_clk_frac_h, 0xC);
2430 /* Initialize GPIOs that are controlled by D11 core */
2431 static void wlc_gpio_init(struct wlc_info *wlc)
2433 struct wlc_hw_info *wlc_hw = wlc->hw;
2437 regs = wlc_hw->regs;
2439 /* use GPIO select 0 to get all gpio signals from the gpio out reg */
2440 wlc_bmac_mctrl(wlc_hw, MCTL_GPOUT_SEL_MASK, 0);
2443 * Common GPIO setup:
2444 * G0 = LED 0 = WLAN Activity
2445 * G1 = LED 1 = WLAN 2.4 GHz Radio State
2446 * G2 = LED 2 = WLAN 5 GHz Radio State
2447 * G4 = radio disable input (HI enabled, LO disabled)
2452 /* Allocate GPIOs for mimo antenna diversity feature */
2453 if (wlc_hw->antsel_type == ANTSEL_2x3) {
2454 /* Enable antenna diversity, use 2x3 mode */
2455 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
2456 MHF3_ANTSEL_EN, WLC_BAND_ALL);
2457 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE,
2458 MHF3_ANTSEL_MODE, WLC_BAND_ALL);
2460 /* init superswitch control */
2461 wlc_phy_antsel_init(wlc_hw->band->pi, false);
2463 } else if (wlc_hw->antsel_type == ANTSEL_2x4) {
2464 gm |= gc |= (BOARD_GPIO_12 | BOARD_GPIO_13);
2466 * The board itself is powered by these GPIOs
2467 * (when not sending pattern) so set them high
2469 OR_REG(®s->psm_gpio_oe,
2470 (BOARD_GPIO_12 | BOARD_GPIO_13));
2471 OR_REG(®s->psm_gpio_out,
2472 (BOARD_GPIO_12 | BOARD_GPIO_13));
2474 /* Enable antenna diversity, use 2x4 mode */
2475 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
2476 MHF3_ANTSEL_EN, WLC_BAND_ALL);
2477 wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, 0,
2480 /* Configure the desired clock to be 4Mhz */
2481 wlc_bmac_write_shm(wlc_hw, M_ANTSEL_CLKDIV,
2482 ANTSEL_CLKDIV_4MHZ);
2485 /* gpio 9 controls the PA. ucode is responsible for wiggling out and oe */
2486 if (wlc_hw->boardflags & BFL_PACTRL)
2487 gm |= gc |= BOARD_GPIO_PACTRL;
2489 /* apply to gpiocontrol register */
2490 ai_gpiocontrol(wlc_hw->sih, gm, gc, GPIO_DRV_PRIORITY);
2493 static void wlc_ucode_download(struct wlc_hw_info *wlc_hw)
2495 struct wlc_info *wlc;
2498 if (wlc_hw->ucode_loaded)
2501 if (D11REV_IS(wlc_hw->corerev, 23)) {
2502 if (WLCISNPHY(wlc_hw->band)) {
2503 wlc_ucode_write(wlc_hw, bcm43xx_16_mimo,
2505 wlc_hw->ucode_loaded = true;
2507 wiphy_err(wlc->wiphy, "%s: wl%d: unsupported phy in "
2509 __func__, wlc_hw->unit, wlc_hw->corerev);
2510 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2511 if (WLCISLCNPHY(wlc_hw->band)) {
2512 wlc_ucode_write(wlc_hw, bcm43xx_24_lcn,
2514 wlc_hw->ucode_loaded = true;
2516 wiphy_err(wlc->wiphy, "%s: wl%d: unsupported phy in "
2518 __func__, wlc_hw->unit, wlc_hw->corerev);
2523 static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
2524 const uint nbytes) {
2525 d11regs_t *regs = wlc_hw->regs;
2529 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
2531 count = (nbytes / sizeof(u32));
2533 W_REG(®s->objaddr, (OBJADDR_AUTO_INC | OBJADDR_UCM_SEL));
2534 (void)R_REG(®s->objaddr);
2535 for (i = 0; i < count; i++)
2536 W_REG(®s->objdata, ucode[i]);
2539 static void wlc_write_inits(struct wlc_hw_info *wlc_hw,
2540 const struct d11init *inits)
2545 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
2547 base = (volatile u8 *)wlc_hw->regs;
2549 for (i = 0; inits[i].addr != 0xffff; i++) {
2550 if (inits[i].size == 2)
2551 W_REG((u16 *)(base + inits[i].addr),
2553 else if (inits[i].size == 4)
2554 W_REG((u32 *)(base + inits[i].addr),
2559 static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw)
2562 u16 phytxant = wlc_hw->bmac_phytxant;
2563 u16 mask = PHY_TXC_ANT_MASK;
2565 /* set the Probe Response frame phy control word */
2566 phyctl = wlc_bmac_read_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS);
2567 phyctl = (phyctl & ~mask) | phytxant;
2568 wlc_bmac_write_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS, phyctl);
2570 /* set the Response (ACK/CTS) frame phy control word */
2571 phyctl = wlc_bmac_read_shm(wlc_hw, M_RSP_PCTLWD);
2572 phyctl = (phyctl & ~mask) | phytxant;
2573 wlc_bmac_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl);
2576 void wlc_bmac_txant_set(struct wlc_hw_info *wlc_hw, u16 phytxant)
2578 /* update sw state */
2579 wlc_hw->bmac_phytxant = phytxant;
2581 /* push to ucode if up */
2584 wlc_ucode_txant_set(wlc_hw);
2588 u16 wlc_bmac_get_txant(struct wlc_hw_info *wlc_hw)
2590 return (u16) wlc_hw->wlc->stf->txant;
2593 void wlc_bmac_antsel_type_set(struct wlc_hw_info *wlc_hw, u8 antsel_type)
2595 wlc_hw->antsel_type = antsel_type;
2597 /* Update the antsel type for phy module to use */
2598 wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type);
2601 void wlc_bmac_fifoerrors(struct wlc_hw_info *wlc_hw)
2605 uint intstatus, idx;
2606 d11regs_t *regs = wlc_hw->regs;
2607 struct wiphy *wiphy = wlc_hw->wlc->wiphy;
2609 unit = wlc_hw->unit;
2611 for (idx = 0; idx < NFIFO; idx++) {
2612 /* read intstatus register and ignore any non-error bits */
2614 R_REG(®s->intctrlregs[idx].intstatus) & I_ERRORS;
2618 BCMMSG(wlc_hw->wlc->wiphy, "wl%d: intstatus%d 0x%x\n",
2619 unit, idx, intstatus);
2621 if (intstatus & I_RO) {
2622 wiphy_err(wiphy, "wl%d: fifo %d: receive fifo "
2623 "overflow\n", unit, idx);
2627 if (intstatus & I_PC) {
2628 wiphy_err(wiphy, "wl%d: fifo %d: descriptor error\n",
2633 if (intstatus & I_PD) {
2634 wiphy_err(wiphy, "wl%d: fifo %d: data error\n", unit,
2639 if (intstatus & I_DE) {
2640 wiphy_err(wiphy, "wl%d: fifo %d: descriptor protocol "
2641 "error\n", unit, idx);
2645 if (intstatus & I_RU) {
2646 wiphy_err(wiphy, "wl%d: fifo %d: receive descriptor "
2647 "underflow\n", idx, unit);
2650 if (intstatus & I_XU) {
2651 wiphy_err(wiphy, "wl%d: fifo %d: transmit fifo "
2652 "underflow\n", idx, unit);
2657 wlc_fatal_error(wlc_hw->wlc); /* big hammer */
2660 W_REG(®s->intctrlregs[idx].intstatus,
2665 void wlc_intrson(struct wlc_info *wlc)
2667 struct wlc_hw_info *wlc_hw = wlc->hw;
2668 wlc->macintmask = wlc->defmacintmask;
2669 W_REG(&wlc_hw->regs->macintmask, wlc->macintmask);
2672 /* callback for siutils.c, which has only wlc handler, no wl
2673 * they both check up, not only because there is no need to off/restore d11 interrupt
2674 * but also because per-port code may require sync with valid interrupt.
2677 static u32 wlc_wlintrsoff(struct wlc_info *wlc)
2682 return brcms_intrsoff(wlc->wl);
2685 static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask)
2690 brcms_intrsrestore(wlc->wl, macintmask);
2693 u32 wlc_intrsoff(struct wlc_info *wlc)
2695 struct wlc_hw_info *wlc_hw = wlc->hw;
2701 macintmask = wlc->macintmask; /* isr can still happen */
2703 W_REG(&wlc_hw->regs->macintmask, 0);
2704 (void)R_REG(&wlc_hw->regs->macintmask); /* sync readback */
2705 udelay(1); /* ensure int line is no longer driven */
2706 wlc->macintmask = 0;
2708 /* return previous macintmask; resolve race between us and our isr */
2709 return wlc->macintstatus ? 0 : macintmask;
2712 void wlc_intrsrestore(struct wlc_info *wlc, u32 macintmask)
2714 struct wlc_hw_info *wlc_hw = wlc->hw;
2718 wlc->macintmask = macintmask;
2719 W_REG(&wlc_hw->regs->macintmask, wlc->macintmask);
2722 static void wlc_bmac_mute(struct wlc_hw_info *wlc_hw, bool on, mbool flags)
2724 u8 null_ether_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
2727 /* suspend tx fifos */
2728 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_DATA_FIFO);
2729 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_CTL_FIFO);
2730 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_BK_FIFO);
2731 wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_VI_FIFO);
2733 /* zero the address match register so we do not send ACKs */
2734 wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
2737 /* resume tx fifos */
2738 if (!wlc_hw->wlc->tx_suspended) {
2739 wlc_bmac_tx_fifo_resume(wlc_hw, TX_DATA_FIFO);
2741 wlc_bmac_tx_fifo_resume(wlc_hw, TX_CTL_FIFO);
2742 wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_BK_FIFO);
2743 wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_VI_FIFO);
2745 /* Restore address */
2746 wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
2750 wlc_phy_mute_upd(wlc_hw->band->pi, on, flags);
2753 wlc_ucode_mute_override_set(wlc_hw);
2755 wlc_ucode_mute_override_clear(wlc_hw);
2758 int wlc_bmac_xmtfifo_sz_get(struct wlc_hw_info *wlc_hw, uint fifo, uint *blocks)
2763 *blocks = wlc_hw->xmtfifo_sz[fifo];
2768 /* wlc_bmac_tx_fifo_suspended:
2769 * Check the MAC's tx suspend status for a tx fifo.
2771 * When the MAC acknowledges a tx suspend, it indicates that no more
2772 * packets will be transmitted out the radio. This is independent of
2773 * DMA channel suspension---the DMA may have finished suspending, or may still
2774 * be pulling data into a tx fifo, by the time the MAC acks the suspend
2777 static bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info *wlc_hw, uint tx_fifo)
2779 /* check that a suspend has been requested and is no longer pending */
2782 * for DMA mode, the suspend request is set in xmtcontrol of the DMA engine,
2783 * and the tx fifo suspend at the lower end of the MAC is acknowledged in the
2784 * chnstatus register.
2785 * The tx fifo suspend completion is independent of the DMA suspend completion and
2786 * may be acked before or after the DMA is suspended.
2788 if (dma_txsuspended(wlc_hw->di[tx_fifo]) &&
2789 (R_REG(&wlc_hw->regs->chnstatus) &
2790 (1 << tx_fifo)) == 0)
2796 static void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info *wlc_hw, uint tx_fifo)
2798 u8 fifo = 1 << tx_fifo;
2800 /* Two clients of this code, 11h Quiet period and scanning. */
2802 /* only suspend if not already suspended */
2803 if ((wlc_hw->suspended_fifos & fifo) == fifo)
2806 /* force the core awake only if not already */
2807 if (wlc_hw->suspended_fifos == 0)
2808 wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_TXFIFO);
2810 wlc_hw->suspended_fifos |= fifo;
2812 if (wlc_hw->di[tx_fifo]) {
2813 /* Suspending AMPDU transmissions in the middle can cause underflow
2814 * which may result in mismatch between ucode and driver
2815 * so suspend the mac before suspending the FIFO
2817 if (WLC_PHY_11N_CAP(wlc_hw->band))
2818 wlc_suspend_mac_and_wait(wlc_hw->wlc);
2820 dma_txsuspend(wlc_hw->di[tx_fifo]);
2822 if (WLC_PHY_11N_CAP(wlc_hw->band))
2823 wlc_enable_mac(wlc_hw->wlc);
2827 static void wlc_bmac_tx_fifo_resume(struct wlc_hw_info *wlc_hw, uint tx_fifo)
2829 /* BMAC_NOTE: WLC_TX_FIFO_ENAB is done in wlc_dpc() for DMA case but need to be done
2830 * here for PIO otherwise the watchdog will catch the inconsistency and fire
2832 /* Two clients of this code, 11h Quiet period and scanning. */
2833 if (wlc_hw->di[tx_fifo])
2834 dma_txresume(wlc_hw->di[tx_fifo]);
2836 /* allow core to sleep again */
2837 if (wlc_hw->suspended_fifos == 0)
2840 wlc_hw->suspended_fifos &= ~(1 << tx_fifo);
2841 if (wlc_hw->suspended_fifos == 0)
2842 wlc_ucode_wake_override_clear(wlc_hw,
2843 WLC_WAKE_OVERRIDE_TXFIFO);
2848 * Read and clear macintmask and macintstatus and intstatus registers.
2849 * This routine should be called with interrupts off
2851 * -1 if DEVICEREMOVED(wlc) evaluates to true;
2852 * 0 if the interrupt is not for us, or we are in some special cases;
2853 * device interrupt status bits otherwise.
2855 static inline u32 wlc_intstatus(struct wlc_info *wlc, bool in_isr)
2857 struct wlc_hw_info *wlc_hw = wlc->hw;
2858 d11regs_t *regs = wlc_hw->regs;
2861 /* macintstatus includes a DMA interrupt summary bit */
2862 macintstatus = R_REG(®s->macintstatus);
2864 BCMMSG(wlc->wiphy, "wl%d: macintstatus: 0x%x\n", wlc_hw->unit,
2867 /* detect cardbus removed, in power down(suspend) and in reset */
2868 if (DEVICEREMOVED(wlc))
2871 /* DEVICEREMOVED succeeds even when the core is still resetting,
2872 * handle that case here.
2874 if (macintstatus == 0xffffffff)
2877 /* defer unsolicited interrupts */
2878 macintstatus &= (in_isr ? wlc->macintmask : wlc->defmacintmask);
2881 if (macintstatus == 0)
2884 /* interrupts are already turned off for CFE build
2885 * Caution: For CFE Turning off the interrupts again has some undesired
2888 /* turn off the interrupts */
2889 W_REG(®s->macintmask, 0);
2890 (void)R_REG(®s->macintmask); /* sync readback */
2891 wlc->macintmask = 0;
2893 /* clear device interrupts */
2894 W_REG(®s->macintstatus, macintstatus);
2896 /* MI_DMAINT is indication of non-zero intstatus */
2897 if (macintstatus & MI_DMAINT) {
2899 * only fifo interrupt enabled is I_RI in
2900 * RX_FIFO. If MI_DMAINT is set, assume it
2901 * is set and clear the interrupt.
2903 W_REG(®s->intctrlregs[RX_FIFO].intstatus,
2907 return macintstatus;
2910 /* Update wlc->macintstatus and wlc->intstatus[]. */
2911 /* Return true if they are updated successfully. false otherwise */
2912 bool wlc_intrsupd(struct wlc_info *wlc)
2916 /* read and clear macintstatus and intstatus registers */
2917 macintstatus = wlc_intstatus(wlc, false);
2919 /* device is removed */
2920 if (macintstatus == 0xffffffff)
2923 /* update interrupt status in software */
2924 wlc->macintstatus |= macintstatus;
2930 * First-level interrupt processing.
2931 * Return true if this was our interrupt, false otherwise.
2932 * *wantdpc will be set to true if further wlc_dpc() processing is required,
2935 bool wlc_isr(struct wlc_info *wlc, bool *wantdpc)
2937 struct wlc_hw_info *wlc_hw = wlc->hw;
2942 if (!wlc_hw->up || !wlc->macintmask)
2945 /* read and clear macintstatus and intstatus registers */
2946 macintstatus = wlc_intstatus(wlc, true);
2948 if (macintstatus == 0xffffffff)
2949 wiphy_err(wlc->wiphy, "DEVICEREMOVED detected in the ISR code"
2952 /* it is not for us */
2953 if (macintstatus == 0)
2958 /* save interrupt status bits */
2959 wlc->macintstatus = macintstatus;
2966 wlc_bmac_dotxstatus(struct wlc_hw_info *wlc_hw, tx_status_t *txs, u32 s2)
2968 /* discard intermediate indications for ucode with one legitimate case:
2969 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
2970 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
2971 * transmission count)
2973 if (!(txs->status & TX_STATUS_AMPDU)
2974 && (txs->status & TX_STATUS_INTERMEDIATE)) {
2978 return wlc_dotxstatus(wlc_hw->wlc, txs, s2);
2981 /* process tx completion events in BMAC
2982 * Return true if more tx status need to be processed. false otherwise.
2985 wlc_bmac_txstatus(struct wlc_hw_info *wlc_hw, bool bound, bool *fatal)
2987 bool morepending = false;
2988 struct wlc_info *wlc = wlc_hw->wlc;
2990 tx_status_t txstatus, *txs;
2994 * Param 'max_tx_num' indicates max. # tx status to process before
2997 uint max_tx_num = bound ? wlc->pub->tunables->txsbnd : -1;
2999 BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
3002 regs = wlc_hw->regs;
3004 && (s1 = R_REG(®s->frmtxstatus)) & TXS_V) {
3006 if (s1 == 0xffffffff) {
3007 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n",
3008 wlc_hw->unit, __func__);
3012 s2 = R_REG(®s->frmtxstatus2);
3014 txs->status = s1 & TXS_STATUS_MASK;
3015 txs->frameid = (s1 & TXS_FID_MASK) >> TXS_FID_SHIFT;
3016 txs->sequence = s2 & TXS_SEQ_MASK;
3017 txs->phyerr = (s2 & TXS_PTX_MASK) >> TXS_PTX_SHIFT;
3018 txs->lasttxtime = 0;
3020 *fatal = wlc_bmac_dotxstatus(wlc_hw, txs, s2);
3022 /* !give others some time to run! */
3023 if (++n >= max_tx_num)
3030 if (n >= max_tx_num)
3033 if (!pktq_empty(&wlc->pkt_queue->q))
3039 void wlc_suspend_mac_and_wait(struct wlc_info *wlc)
3041 struct wlc_hw_info *wlc_hw = wlc->hw;
3042 d11regs_t *regs = wlc_hw->regs;
3044 struct wiphy *wiphy = wlc->wiphy;
3046 BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
3047 wlc_hw->band->bandunit);
3050 * Track overlapping suspend requests
3052 wlc_hw->mac_suspend_depth++;
3053 if (wlc_hw->mac_suspend_depth > 1)
3056 /* force the core awake */
3057 wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
3059 mc = R_REG(®s->maccontrol);
3061 if (mc == 0xffffffff) {
3062 wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
3064 brcms_down(wlc->wl);
3067 WARN_ON(mc & MCTL_PSM_JMP_0);
3068 WARN_ON(!(mc & MCTL_PSM_RUN));
3069 WARN_ON(!(mc & MCTL_EN_MAC));
3071 mi = R_REG(®s->macintstatus);
3072 if (mi == 0xffffffff) {
3073 wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
3075 brcms_down(wlc->wl);
3078 WARN_ON(mi & MI_MACSSPNDD);
3080 wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, 0);
3082 SPINWAIT(!(R_REG(®s->macintstatus) & MI_MACSSPNDD),
3083 WLC_MAX_MAC_SUSPEND);
3085 if (!(R_REG(®s->macintstatus) & MI_MACSSPNDD)) {
3086 wiphy_err(wiphy, "wl%d: wlc_suspend_mac_and_wait: waited %d uS"
3087 " and MI_MACSSPNDD is still not on.\n",
3088 wlc_hw->unit, WLC_MAX_MAC_SUSPEND);
3089 wiphy_err(wiphy, "wl%d: psmdebug 0x%08x, phydebug 0x%08x, "
3090 "psm_brc 0x%04x\n", wlc_hw->unit,
3091 R_REG(®s->psmdebug),
3092 R_REG(®s->phydebug),
3093 R_REG(®s->psm_brc));
3096 mc = R_REG(®s->maccontrol);
3097 if (mc == 0xffffffff) {
3098 wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
3100 brcms_down(wlc->wl);
3103 WARN_ON(mc & MCTL_PSM_JMP_0);
3104 WARN_ON(!(mc & MCTL_PSM_RUN));
3105 WARN_ON(mc & MCTL_EN_MAC);
3108 void wlc_enable_mac(struct wlc_info *wlc)
3110 struct wlc_hw_info *wlc_hw = wlc->hw;
3111 d11regs_t *regs = wlc_hw->regs;
3114 BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
3115 wlc->band->bandunit);
3118 * Track overlapping suspend requests
3120 wlc_hw->mac_suspend_depth--;
3121 if (wlc_hw->mac_suspend_depth > 0)
3124 mc = R_REG(®s->maccontrol);
3125 WARN_ON(mc & MCTL_PSM_JMP_0);
3126 WARN_ON(mc & MCTL_EN_MAC);
3127 WARN_ON(!(mc & MCTL_PSM_RUN));
3129 wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, MCTL_EN_MAC);
3130 W_REG(®s->macintstatus, MI_MACSSPNDD);
3132 mc = R_REG(®s->maccontrol);
3133 WARN_ON(mc & MCTL_PSM_JMP_0);
3134 WARN_ON(!(mc & MCTL_EN_MAC));
3135 WARN_ON(!(mc & MCTL_PSM_RUN));
3137 mi = R_REG(®s->macintstatus);
3138 WARN_ON(mi & MI_MACSSPNDD);
3140 wlc_ucode_wake_override_clear(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
3143 static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw)
3147 WLC_RATE_6M, WLC_RATE_9M, WLC_RATE_12M, WLC_RATE_18M,
3148 WLC_RATE_24M, WLC_RATE_36M, WLC_RATE_48M, WLC_RATE_54M
3154 if (!WLC_PHY_11N_CAP(wlc_hw->band))
3157 /* walk the phy rate table and update the entries */
3158 for (i = 0; i < ARRAY_SIZE(rates); i++) {
3161 entry_ptr = wlc_bmac_ofdm_ratetable_offset(wlc_hw, rate);
3163 /* read the SHM Rate Table entry OFDM PCTL1 values */
3165 wlc_bmac_read_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS);
3167 /* modify the value */
3168 pctl1 &= ~PHY_TXC1_MODE_MASK;
3169 pctl1 |= (wlc_hw->hw_stf_ss_opmode << PHY_TXC1_MODE_SHIFT);
3171 /* Update the SHM Rate Table entry OFDM PCTL1 values */
3172 wlc_bmac_write_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS,
3177 static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw, u8 rate)
3181 struct plcp_signal_rate_lookup {
3185 /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */
3186 const struct plcp_signal_rate_lookup rate_lookup[] = {
3189 {WLC_RATE_12M, 0xA},
3190 {WLC_RATE_18M, 0xE},
3191 {WLC_RATE_24M, 0x9},
3192 {WLC_RATE_36M, 0xD},
3193 {WLC_RATE_48M, 0x8},
3197 for (i = 0; i < ARRAY_SIZE(rate_lookup); i++) {
3198 if (rate == rate_lookup[i].rate) {
3199 plcp_rate = rate_lookup[i].signal_rate;
3204 /* Find the SHM pointer to the rate table entry by looking in the
3207 return 2 * wlc_bmac_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2));
3210 void wlc_bmac_band_stf_ss_set(struct wlc_hw_info *wlc_hw, u8 stf_mode)
3212 wlc_hw->hw_stf_ss_opmode = stf_mode;
3215 wlc_upd_ofdm_pctl1_table(wlc_hw);
3219 wlc_bmac_read_tsf(struct wlc_hw_info *wlc_hw, u32 *tsf_l_ptr,
3222 d11regs_t *regs = wlc_hw->regs;
3224 /* read the tsf timer low, then high to get an atomic read */
3225 *tsf_l_ptr = R_REG(®s->tsf_timerlow);
3226 *tsf_h_ptr = R_REG(®s->tsf_timerhigh);
3231 static bool wlc_bmac_validate_chip_access(struct wlc_hw_info *wlc_hw)
3235 struct wiphy *wiphy = wlc_hw->wlc->wiphy;
3237 BCMMSG(wiphy, "wl%d\n", wlc_hw->unit);
3239 regs = wlc_hw->regs;
3241 /* Validate dchip register access */
3243 W_REG(®s->objaddr, OBJADDR_SHM_SEL | 0);
3244 (void)R_REG(®s->objaddr);
3245 w = R_REG(®s->objdata);
3247 /* Can we write and read back a 32bit register? */
3248 W_REG(®s->objaddr, OBJADDR_SHM_SEL | 0);
3249 (void)R_REG(®s->objaddr);
3250 W_REG(®s->objdata, (u32) 0xaa5555aa);
3252 W_REG(®s->objaddr, OBJADDR_SHM_SEL | 0);
3253 (void)R_REG(®s->objaddr);
3254 val = R_REG(®s->objdata);
3255 if (val != (u32) 0xaa5555aa) {
3256 wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, "
3257 "expected 0xaa5555aa\n", wlc_hw->unit, val);
3261 W_REG(®s->objaddr, OBJADDR_SHM_SEL | 0);
3262 (void)R_REG(®s->objaddr);
3263 W_REG(®s->objdata, (u32) 0x55aaaa55);
3265 W_REG(®s->objaddr, OBJADDR_SHM_SEL | 0);
3266 (void)R_REG(®s->objaddr);
3267 val = R_REG(®s->objdata);
3268 if (val != (u32) 0x55aaaa55) {
3269 wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, "
3270 "expected 0x55aaaa55\n", wlc_hw->unit, val);
3274 W_REG(®s->objaddr, OBJADDR_SHM_SEL | 0);
3275 (void)R_REG(®s->objaddr);
3276 W_REG(®s->objdata, w);
3278 /* clear CFPStart */
3279 W_REG(®s->tsf_cfpstart, 0);
3281 w = R_REG(®s->maccontrol);
3282 if ((w != (MCTL_IHR_EN | MCTL_WAKE)) &&
3283 (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) {
3284 wiphy_err(wiphy, "wl%d: validate_chip_access: maccontrol = "
3285 "0x%x, expected 0x%x or 0x%x\n", wlc_hw->unit, w,
3286 (MCTL_IHR_EN | MCTL_WAKE),
3287 (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE));
3294 #define PHYPLL_WAIT_US 100000
3296 void wlc_bmac_core_phypll_ctl(struct wlc_hw_info *wlc_hw, bool on)
3301 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
3304 regs = wlc_hw->regs;
3307 if ((wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
3308 OR_REG(®s->clk_ctl_st,
3309 (CCS_ERSRC_REQ_HT | CCS_ERSRC_REQ_D11PLL |
3310 CCS_ERSRC_REQ_PHYPLL));
3311 SPINWAIT((R_REG(®s->clk_ctl_st) &
3312 (CCS_ERSRC_AVAIL_HT)) != (CCS_ERSRC_AVAIL_HT),
3315 tmp = R_REG(®s->clk_ctl_st);
3316 if ((tmp & (CCS_ERSRC_AVAIL_HT)) !=
3317 (CCS_ERSRC_AVAIL_HT)) {
3318 wiphy_err(wlc_hw->wlc->wiphy, "%s: turn on PHY"
3319 " PLL failed\n", __func__);
3322 OR_REG(®s->clk_ctl_st,
3323 (CCS_ERSRC_REQ_D11PLL | CCS_ERSRC_REQ_PHYPLL));
3324 SPINWAIT((R_REG(®s->clk_ctl_st) &
3325 (CCS_ERSRC_AVAIL_D11PLL |
3326 CCS_ERSRC_AVAIL_PHYPLL)) !=
3327 (CCS_ERSRC_AVAIL_D11PLL |
3328 CCS_ERSRC_AVAIL_PHYPLL), PHYPLL_WAIT_US);
3330 tmp = R_REG(®s->clk_ctl_st);
3332 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL))
3334 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) {
3335 wiphy_err(wlc_hw->wlc->wiphy, "%s: turn on "
3336 "PHY PLL failed\n", __func__);
3340 /* Since the PLL may be shared, other cores can still be requesting it;
3341 * so we'll deassert the request but not wait for status to comply.
3343 AND_REG(®s->clk_ctl_st, ~CCS_ERSRC_REQ_PHYPLL);
3344 tmp = R_REG(®s->clk_ctl_st);
3348 void wlc_coredisable(struct wlc_hw_info *wlc_hw)
3352 BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
3354 dev_gone = DEVICEREMOVED(wlc_hw->wlc);
3359 if (wlc_hw->noreset)
3363 wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
3365 /* turn off analog core */
3366 wlc_phy_anacore(wlc_hw->band->pi, OFF);
3368 /* turn off PHYPLL to save power */
3369 wlc_bmac_core_phypll_ctl(wlc_hw, false);
3371 /* No need to set wlc->pub->radio_active = OFF
3372 * because this function needs down capability and
3373 * radio_active is designed for BCMNODOWN.
3376 /* remove gpio controls */
3377 if (wlc_hw->ucode_dbgsel)
3378 ai_gpiocontrol(wlc_hw->sih, ~0, 0, GPIO_DRV_PRIORITY);
3380 wlc_hw->clk = false;
3381 ai_core_disable(wlc_hw->sih, 0);
3382 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
3385 /* power both the pll and external oscillator on/off */
3386 static void wlc_bmac_xtal(struct wlc_hw_info *wlc_hw, bool want)
3388 BCMMSG(wlc_hw->wlc->wiphy, "wl%d: want %d\n", wlc_hw->unit, want);
3390 /* dont power down if plldown is false or we must poll hw radio disable */
3391 if (!want && wlc_hw->pllreq)
3395 ai_clkctl_xtal(wlc_hw->sih, XTAL | PLL, want);
3397 wlc_hw->sbclk = want;
3398 if (!wlc_hw->sbclk) {
3399 wlc_hw->clk = false;
3400 if (wlc_hw->band && wlc_hw->band->pi)
3401 wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
3405 static void wlc_flushqueues(struct wlc_info *wlc)
3407 struct wlc_hw_info *wlc_hw = wlc->hw;
3410 wlc->txpend16165war = 0;
3412 /* free any posted tx packets */
3413 for (i = 0; i < NFIFO; i++)
3414 if (wlc_hw->di[i]) {
3415 dma_txreclaim(wlc_hw->di[i], DMA_RANGE_ALL);
3416 TXPKTPENDCLR(wlc, i);
3417 BCMMSG(wlc->wiphy, "pktpend fifo %d clrd\n", i);
3420 /* free any posted rx packets */
3421 dma_rxreclaim(wlc_hw->di[RX_FIFO]);
3424 u16 wlc_bmac_read_shm(struct wlc_hw_info *wlc_hw, uint offset)
3426 return wlc_bmac_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL);
3429 void wlc_bmac_write_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v)
3431 wlc_bmac_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL);
3435 wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset, u32 sel)
3437 d11regs_t *regs = wlc_hw->regs;
3438 volatile u16 *objdata_lo = (volatile u16 *)®s->objdata;
3439 volatile u16 *objdata_hi = objdata_lo + 1;
3442 W_REG(®s->objaddr, sel | (offset >> 2));
3443 (void)R_REG(®s->objaddr);
3445 v = R_REG(objdata_hi);
3447 v = R_REG(objdata_lo);
3454 wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset, u16 v, u32 sel)
3456 d11regs_t *regs = wlc_hw->regs;
3457 volatile u16 *objdata_lo = (volatile u16 *)®s->objdata;
3458 volatile u16 *objdata_hi = objdata_lo + 1;
3460 W_REG(®s->objaddr, sel | (offset >> 2));
3461 (void)R_REG(®s->objaddr);
3463 W_REG(objdata_hi, v);
3465 W_REG(objdata_lo, v);
3469 /* Copy a buffer to shared memory of specified type .
3470 * SHM 'offset' needs to be an even address and
3471 * Buffer length 'len' must be an even number of bytes
3472 * 'sel' selects the type of memory
3475 wlc_bmac_copyto_objmem(struct wlc_hw_info *wlc_hw, uint offset, const void *buf,
3479 const u8 *p = (const u8 *)buf;
3482 if (len <= 0 || (offset & 1) || (len & 1))
3485 for (i = 0; i < len; i += 2) {
3486 v = p[i] | (p[i + 1] << 8);
3487 wlc_bmac_write_objmem(wlc_hw, offset + i, v, sel);
3491 /* Copy a piece of shared memory of specified type to a buffer .
3492 * SHM 'offset' needs to be an even address and
3493 * Buffer length 'len' must be an even number of bytes
3494 * 'sel' selects the type of memory
3497 wlc_bmac_copyfrom_objmem(struct wlc_hw_info *wlc_hw, uint offset, void *buf,
3504 if (len <= 0 || (offset & 1) || (len & 1))
3507 for (i = 0; i < len; i += 2) {
3508 v = wlc_bmac_read_objmem(wlc_hw, offset + i, sel);
3510 p[i + 1] = (v >> 8) & 0xFF;
3514 void wlc_bmac_copyfrom_vars(struct wlc_hw_info *wlc_hw, char **buf, uint *len)
3516 BCMMSG(wlc_hw->wlc->wiphy, "nvram vars totlen=%d\n",
3519 *buf = wlc_hw->vars;
3520 *len = wlc_hw->vars_size;
3523 void wlc_bmac_retrylimit_upd(struct wlc_hw_info *wlc_hw, u16 SRL, u16 LRL)
3528 /* write retry limit to SCR, shouldn't need to suspend */
3530 W_REG(&wlc_hw->regs->objaddr,
3531 OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
3532 (void)R_REG(&wlc_hw->regs->objaddr);
3533 W_REG(&wlc_hw->regs->objdata, wlc_hw->SRL);
3534 W_REG(&wlc_hw->regs->objaddr,
3535 OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
3536 (void)R_REG(&wlc_hw->regs->objaddr);
3537 W_REG(&wlc_hw->regs->objdata, wlc_hw->LRL);
3541 void wlc_bmac_pllreq(struct wlc_hw_info *wlc_hw, bool set, mbool req_bit)
3544 if (mboolisset(wlc_hw->pllreq, req_bit))
3547 mboolset(wlc_hw->pllreq, req_bit);
3549 if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
3550 if (!wlc_hw->sbclk) {
3551 wlc_bmac_xtal(wlc_hw, ON);
3555 if (!mboolisset(wlc_hw->pllreq, req_bit))
3558 mboolclr(wlc_hw->pllreq, req_bit);
3560 if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
3561 if (wlc_hw->sbclk) {
3562 wlc_bmac_xtal(wlc_hw, OFF);
3570 u16 wlc_bmac_rate_shm_offset(struct wlc_hw_info *wlc_hw, u8 rate)
3575 /* get the phy specific rate encoding for the PLCP SIGNAL field */
3576 /* XXX4321 fixup needed ? */
3578 table_ptr = M_RT_DIRMAP_A;
3580 table_ptr = M_RT_DIRMAP_B;
3582 /* for a given rate, the LS-nibble of the PLCP SIGNAL field is
3583 * the index into the rate table.
3585 phy_rate = rate_info[rate] & WLC_RATE_MASK;
3586 index = phy_rate & 0xf;
3588 /* Find the SHM pointer to the rate table entry by looking in the
3591 return 2 * wlc_bmac_read_shm(wlc_hw, table_ptr + (index * 2));
3594 void wlc_bmac_antsel_set(struct wlc_hw_info *wlc_hw, u32 antsel_avail)
3596 wlc_hw->antsel_avail = antsel_avail;