2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include <linux/pci.h>
17 #include <net/mac80211.h>
19 #include <brcm_hw_ids.h>
21 #include <chipcommon.h>
24 #include "phy/phy_hal.h"
27 #include "ucode_loader.h"
28 #include "mac80211_if.h"
31 #define TIMER_INTERVAL_WATCHDOG_BMAC 1000 /* watchdog timer, in unit of ms */
33 #define SYNTHPU_DLY_APHY_US 3700 /* a phy synthpu_dly time in us */
34 #define SYNTHPU_DLY_BPHY_US 1050 /* b/g phy synthpu_dly time in us, default */
35 #define SYNTHPU_DLY_NPHY_US 2048 /* n phy REV3 synthpu_dly time in us, default */
36 #define SYNTHPU_DLY_LPPHY_US 300 /* lpphy synthpu_dly time in us */
38 #define SYNTHPU_DLY_PHY_US_QT 100 /* QT synthpu_dly time in us */
40 #ifndef BMAC_DUP_TO_REMOVE
41 #define WLC_RM_WAIT_TX_SUSPEND 4 /* Wait Tx Suspend */
43 #define ANTCNT 10 /* vanilla M_MAX_ANTCNT value */
45 #endif /* BMAC_DUP_TO_REMOVE */
47 #define DMAREG(wlc_hw, direction, fifonum) \
48 ((direction == DMA_TX) ? \
49 (void *)&(wlc_hw->regs->fifo64regs[fifonum].dmaxmt) : \
50 (void *)&(wlc_hw->regs->fifo64regs[fifonum].dmarcv))
52 #define APHY_SLOT_TIME 9
53 #define BPHY_SLOT_TIME 20
56 * The following table lists the buffer memory allocated to xmt fifos in HW.
57 * the size is in units of 256bytes(one block), total size is HW dependent
58 * ucode has default fifo partition, sw can overwrite if necessary
60 * This is documented in twiki under the topic UcodeTxFifo. Please ensure
61 * the twiki is updated before making changes.
64 #define XMTFIFOTBL_STARTREV 20 /* Starting corerev for the fifo size table */
66 static u16 xmtfifo_sz
[][NFIFO
] = {
67 {20, 192, 192, 21, 17, 5}, /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */
68 {9, 58, 22, 14, 14, 5}, /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */
69 {20, 192, 192, 21, 17, 5}, /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */
70 {20, 192, 192, 21, 17, 5}, /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */
71 {9, 58, 22, 14, 14, 5}, /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
74 static void wlc_clkctl_clk(struct wlc_hw_info
*wlc
, uint mode
);
75 static void wlc_coreinit(struct wlc_info
*wlc
);
77 /* used by wlc_wakeucode_init() */
78 static void wlc_write_inits(struct wlc_hw_info
*wlc_hw
,
79 const struct d11init
*inits
);
80 static void wlc_ucode_write(struct wlc_hw_info
*wlc_hw
, const u32 ucode
[],
82 static void wlc_ucode_download(struct wlc_hw_info
*wlc
);
83 static void wlc_ucode_txant_set(struct wlc_hw_info
*wlc_hw
);
85 /* used by wlc_dpc() */
86 static bool wlc_bmac_dotxstatus(struct wlc_hw_info
*wlc
, tx_status_t
*txs
,
88 static bool wlc_bmac_txstatus(struct wlc_hw_info
*wlc
, bool bound
, bool *fatal
);
89 static bool wlc_bmac_recv(struct wlc_hw_info
*wlc_hw
, uint fifo
, bool bound
);
91 /* used by wlc_down() */
92 static void wlc_flushqueues(struct wlc_info
*wlc
);
94 static void wlc_write_mhf(struct wlc_hw_info
*wlc_hw
, u16
*mhfs
);
95 static void wlc_mctrl_reset(struct wlc_hw_info
*wlc_hw
);
96 static void wlc_corerev_fifofixup(struct wlc_hw_info
*wlc_hw
);
97 static bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info
*wlc_hw
,
99 static void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info
*wlc_hw
, uint tx_fifo
);
100 static void wlc_bmac_tx_fifo_resume(struct wlc_hw_info
*wlc_hw
, uint tx_fifo
);
102 /* Low Level Prototypes */
103 static int wlc_bmac_bandtype(struct wlc_hw_info
*wlc_hw
);
104 static void wlc_bmac_info_init(struct wlc_hw_info
*wlc_hw
);
105 static void wlc_bmac_xtal(struct wlc_hw_info
*wlc_hw
, bool want
);
106 static u16
wlc_bmac_read_objmem(struct wlc_hw_info
*wlc_hw
, uint offset
,
108 static void wlc_bmac_write_objmem(struct wlc_hw_info
*wlc_hw
, uint offset
,
110 static void wlc_bmac_core_phy_clk(struct wlc_hw_info
*wlc_hw
, bool clk
);
111 static bool wlc_bmac_attach_dmapio(struct wlc_info
*wlc
, uint j
, bool wme
);
112 static void wlc_bmac_detach_dmapio(struct wlc_hw_info
*wlc_hw
);
113 static void wlc_ucode_bsinit(struct wlc_hw_info
*wlc_hw
);
114 static bool wlc_validboardtype(struct wlc_hw_info
*wlc
);
115 static bool wlc_isgoodchip(struct wlc_hw_info
*wlc_hw
);
116 static bool wlc_bmac_validate_chip_access(struct wlc_hw_info
*wlc_hw
);
117 static char *wlc_get_macaddr(struct wlc_hw_info
*wlc_hw
);
118 static void wlc_mhfdef(struct wlc_info
*wlc
, u16
*mhfs
, u16 mhf2_init
);
119 static void wlc_mctrl_write(struct wlc_hw_info
*wlc_hw
);
120 static void wlc_bmac_mute(struct wlc_hw_info
*wlc_hw
, bool want
, mbool flags
);
121 static void wlc_ucode_mute_override_set(struct wlc_hw_info
*wlc_hw
);
122 static void wlc_ucode_mute_override_clear(struct wlc_hw_info
*wlc_hw
);
123 static u32
wlc_wlintrsoff(struct wlc_info
*wlc
);
124 static void wlc_wlintrsrestore(struct wlc_info
*wlc
, u32 macintmask
);
125 static void wlc_gpio_init(struct wlc_info
*wlc
);
126 static void wlc_write_hw_bcntemplate0(struct wlc_hw_info
*wlc_hw
, void *bcn
,
128 static void wlc_write_hw_bcntemplate1(struct wlc_hw_info
*wlc_hw
, void *bcn
,
130 static void wlc_bmac_bsinit(struct wlc_info
*wlc
, chanspec_t chanspec
);
131 static u32
wlc_setband_inact(struct wlc_info
*wlc
, uint bandunit
);
132 static void wlc_bmac_setband(struct wlc_hw_info
*wlc_hw
, uint bandunit
,
133 chanspec_t chanspec
);
134 static void wlc_bmac_update_slot_timing(struct wlc_hw_info
*wlc_hw
,
136 static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info
*wlc_hw
);
137 static u16
wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info
*wlc_hw
,
140 /* === Low Level functions === */
142 void wlc_bmac_set_shortslot(struct wlc_hw_info
*wlc_hw
, bool shortslot
)
144 wlc_hw
->shortslot
= shortslot
;
146 if (BAND_2G(wlc_bmac_bandtype(wlc_hw
)) && wlc_hw
->up
) {
147 wlc_suspend_mac_and_wait(wlc_hw
->wlc
);
148 wlc_bmac_update_slot_timing(wlc_hw
, shortslot
);
149 wlc_enable_mac(wlc_hw
->wlc
);
154 * Update the slot timing for standard 11b/g (20us slots)
155 * or shortslot 11g (9us slots)
156 * The PSM needs to be suspended for this call.
158 static void wlc_bmac_update_slot_timing(struct wlc_hw_info
*wlc_hw
,
166 /* 11g short slot: 11a timing */
167 W_REG(®s
->ifs_slot
, 0x0207); /* APHY_SLOT_TIME */
168 wlc_bmac_write_shm(wlc_hw
, M_DOT11_SLOT
, APHY_SLOT_TIME
);
170 /* 11g long slot: 11b timing */
171 W_REG(®s
->ifs_slot
, 0x0212); /* BPHY_SLOT_TIME */
172 wlc_bmac_write_shm(wlc_hw
, M_DOT11_SLOT
, BPHY_SLOT_TIME
);
176 static void WLBANDINITFN(wlc_ucode_bsinit
) (struct wlc_hw_info
*wlc_hw
)
178 struct wiphy
*wiphy
= wlc_hw
->wlc
->wiphy
;
180 /* init microcode host flags */
181 wlc_write_mhf(wlc_hw
, wlc_hw
->band
->mhfs
);
183 /* do band-specific ucode IHR, SHM, and SCR inits */
184 if (D11REV_IS(wlc_hw
->corerev
, 23)) {
185 if (WLCISNPHY(wlc_hw
->band
)) {
186 wlc_write_inits(wlc_hw
, d11n0bsinitvals16
);
188 wiphy_err(wiphy
, "%s: wl%d: unsupported phy in corerev"
189 " %d\n", __func__
, wlc_hw
->unit
,
193 if (D11REV_IS(wlc_hw
->corerev
, 24)) {
194 if (WLCISLCNPHY(wlc_hw
->band
)) {
195 wlc_write_inits(wlc_hw
, d11lcn0bsinitvals24
);
197 wiphy_err(wiphy
, "%s: wl%d: unsupported phy in"
198 " core rev %d\n", __func__
,
199 wlc_hw
->unit
, wlc_hw
->corerev
);
201 wiphy_err(wiphy
, "%s: wl%d: unsupported corerev %d\n",
202 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
207 /* switch to new band but leave it inactive */
208 static u32
WLBANDINITFN(wlc_setband_inact
) (struct wlc_info
*wlc
, uint bandunit
)
210 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
213 BCMMSG(wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
215 WARN_ON((R_REG(&wlc_hw
->regs
->maccontrol
) & MCTL_EN_MAC
) != 0);
217 /* disable interrupts */
218 macintmask
= brcms_intrsoff(wlc
->wl
);
221 wlc_phy_switch_radio(wlc_hw
->band
->pi
, OFF
);
223 wlc_bmac_core_phy_clk(wlc_hw
, OFF
);
225 wlc_setxband(wlc_hw
, bandunit
);
230 /* Process received frames */
232 * Return true if more frames need to be processed. false otherwise.
233 * Param 'bound' indicates max. # frames to process before break out.
236 wlc_bmac_recv(struct wlc_hw_info
*wlc_hw
, uint fifo
, bool bound
)
239 struct sk_buff
*head
= NULL
;
240 struct sk_buff
*tail
= NULL
;
242 uint bound_limit
= bound
? wlc_hw
->wlc
->pub
->tunables
->rxbnd
: -1;
243 wlc_d11rxhdr_t
*wlc_rxhdr
= NULL
;
245 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
246 /* gather received frames */
247 while ((p
= dma_rx(wlc_hw
->di
[fifo
]))) {
256 /* !give others some time to run! */
257 if (++n
>= bound_limit
)
261 /* post more rbufs */
262 dma_rxfill(wlc_hw
->di
[fifo
]);
264 /* process each frame */
265 while ((p
= head
) != NULL
) {
269 wlc_rxhdr
= (wlc_d11rxhdr_t
*) p
->data
;
271 /* compute the RSSI from d11rxhdr and record it in wlc_rxd11hr */
272 wlc_phy_rssi_compute(wlc_hw
->band
->pi
, wlc_rxhdr
);
274 wlc_recv(wlc_hw
->wlc
, p
);
277 return n
>= bound_limit
;
280 /* second-level interrupt processing
281 * Return true if another dpc needs to be re-scheduled. false otherwise.
282 * Param 'bounded' indicates if applicable loops should be bounded.
284 bool wlc_dpc(struct wlc_info
*wlc
, bool bounded
)
287 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
288 d11regs_t
*regs
= wlc_hw
->regs
;
290 struct wiphy
*wiphy
= wlc
->wiphy
;
292 if (DEVICEREMOVED(wlc
)) {
293 wiphy_err(wiphy
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
299 /* grab and clear the saved software intstatus bits */
300 macintstatus
= wlc
->macintstatus
;
301 wlc
->macintstatus
= 0;
303 BCMMSG(wlc
->wiphy
, "wl%d: macintstatus 0x%x\n",
304 wlc_hw
->unit
, macintstatus
);
306 WARN_ON(macintstatus
& MI_PRQ
); /* PRQ Interrupt in non-MBSS */
308 /* BCN template is available */
309 /* ZZZ: Use AP_ACTIVE ? */
310 if (AP_ENAB(wlc
->pub
) && (!APSTA_ENAB(wlc
->pub
))
311 && (macintstatus
& MI_BCNTPL
)) {
312 wlc_update_beacon(wlc
);
315 /* PMQ entry addition */
316 if (macintstatus
& MI_PMQ
) {
320 if (macintstatus
& MI_TFS
) {
321 if (wlc_bmac_txstatus(wlc
->hw
, bounded
, &fatal
))
322 wlc
->macintstatus
|= MI_TFS
;
324 wiphy_err(wiphy
, "MI_TFS: fatal\n");
329 if (macintstatus
& (MI_TBTT
| MI_DTIM_TBTT
))
332 /* ATIM window end */
333 if (macintstatus
& MI_ATIMWINEND
) {
334 BCMMSG(wlc
->wiphy
, "end of ATIM window\n");
335 OR_REG(®s
->maccommand
, wlc
->qvalid
);
339 /* received data or control frame, MI_DMAINT is indication of RX_FIFO interrupt */
340 if (macintstatus
& MI_DMAINT
) {
341 if (wlc_bmac_recv(wlc_hw
, RX_FIFO
, bounded
)) {
342 wlc
->macintstatus
|= MI_DMAINT
;
346 /* TX FIFO suspend/flush completion */
347 if (macintstatus
& MI_TXSTOP
) {
348 if (wlc_bmac_tx_fifo_suspended(wlc_hw
, TX_DATA_FIFO
)) {
349 /* wiphy_err(wiphy, "dpc: fifo_suspend_comlete\n"); */
353 /* noise sample collected */
354 if (macintstatus
& MI_BG_NOISE
) {
355 wlc_phy_noise_sample_intr(wlc_hw
->band
->pi
);
358 if (macintstatus
& MI_GP0
) {
359 wiphy_err(wiphy
, "wl%d: PSM microcode watchdog fired at %d "
360 "(seconds). Resetting.\n", wlc_hw
->unit
, wlc_hw
->now
);
362 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
363 __func__
, wlc_hw
->sih
->chip
,
364 wlc_hw
->sih
->chiprev
);
369 /* gptimer timeout */
370 if (macintstatus
& MI_TO
) {
371 W_REG(®s
->gptimer
, 0);
374 if (macintstatus
& MI_RFDISABLE
) {
375 BCMMSG(wlc
->wiphy
, "wl%d: BMAC Detected a change on the"
376 " RF Disable Input\n", wlc_hw
->unit
);
377 brcms_rfkill_set_hw_state(wlc
->wl
);
380 /* send any enq'd tx packets. Just makes sure to jump start tx */
381 if (!pktq_empty(&wlc
->pkt_queue
->q
))
384 /* it isn't done and needs to be resched if macintstatus is non-zero */
385 return wlc
->macintstatus
!= 0;
389 return wlc
->macintstatus
!= 0;
392 /* common low-level watchdog code */
393 void wlc_bmac_watchdog(void *arg
)
395 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
396 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
398 BCMMSG(wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
403 /* increment second count */
406 /* Check for FIFO error interrupts */
407 wlc_bmac_fifoerrors(wlc_hw
);
409 /* make sure RX dma has buffers */
410 dma_rxfill(wlc
->hw
->di
[RX_FIFO
]);
412 wlc_phy_watchdog(wlc_hw
->band
->pi
);
416 wlc_bmac_set_chanspec(struct wlc_hw_info
*wlc_hw
, chanspec_t chanspec
,
417 bool mute
, struct txpwr_limits
*txpwr
)
421 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d: 0x%x\n", wlc_hw
->unit
, chanspec
);
423 wlc_hw
->chanspec
= chanspec
;
425 /* Switch bands if necessary */
426 if (NBANDS_HW(wlc_hw
) > 1) {
427 bandunit
= CHSPEC_WLCBANDUNIT(chanspec
);
428 if (wlc_hw
->band
->bandunit
!= bandunit
) {
429 /* wlc_bmac_setband disables other bandunit,
430 * use light band switch if not up yet
433 wlc_phy_chanspec_radio_set(wlc_hw
->
434 bandstate
[bandunit
]->
436 wlc_bmac_setband(wlc_hw
, bandunit
, chanspec
);
438 wlc_setxband(wlc_hw
, bandunit
);
443 wlc_phy_initcal_enable(wlc_hw
->band
->pi
, !mute
);
447 wlc_phy_txpower_limit_set(wlc_hw
->band
->pi
, txpwr
,
449 wlc_phy_chanspec_radio_set(wlc_hw
->band
->pi
, chanspec
);
451 wlc_phy_chanspec_set(wlc_hw
->band
->pi
, chanspec
);
452 wlc_phy_txpower_limit_set(wlc_hw
->band
->pi
, txpwr
, chanspec
);
454 /* Update muting of the channel */
455 wlc_bmac_mute(wlc_hw
, mute
, 0);
459 int wlc_bmac_state_get(struct wlc_hw_info
*wlc_hw
, wlc_bmac_state_t
*state
)
461 state
->machwcap
= wlc_hw
->machwcap
;
466 static bool wlc_bmac_attach_dmapio(struct wlc_info
*wlc
, uint j
, bool wme
)
470 /* ucode host flag 2 needed for pio mode, independent of band and fifo */
472 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
473 uint unit
= wlc_hw
->unit
;
474 wlc_tunables_t
*tune
= wlc
->pub
->tunables
;
475 struct wiphy
*wiphy
= wlc
->wiphy
;
477 /* name and offsets for dma_attach */
478 snprintf(name
, sizeof(name
), "wl%d", unit
);
480 if (wlc_hw
->di
[0] == 0) { /* Init FIFOs */
482 int dma_attach_err
= 0;
483 /* Find out the DMA addressing capability and let OS know
484 * All the channels within one DMA core have 'common-minimum' same
488 dma_addrwidth(wlc_hw
->sih
, DMAREG(wlc_hw
, DMA_TX
, 0));
490 if (!wl_alloc_dma_resources(wlc_hw
->wlc
->wl
, addrwidth
)) {
491 wiphy_err(wiphy
, "wl%d: wlc_attach: alloc_dma_"
492 "resources failed\n", unit
);
498 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
499 * RX: RX_FIFO (RX data packets)
501 wlc_hw
->di
[0] = dma_attach(name
, wlc_hw
->sih
,
502 (wme
? DMAREG(wlc_hw
, DMA_TX
, 0) :
503 NULL
), DMAREG(wlc_hw
, DMA_RX
, 0),
504 (wme
? tune
->ntxd
: 0), tune
->nrxd
,
505 tune
->rxbufsz
, -1, tune
->nrxbufpost
,
506 WL_HWRXOFF
, &brcm_msg_level
);
507 dma_attach_err
|= (NULL
== wlc_hw
->di
[0]);
511 * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets)
512 * (legacy) TX_DATA_FIFO (TX data packets)
515 wlc_hw
->di
[1] = dma_attach(name
, wlc_hw
->sih
,
516 DMAREG(wlc_hw
, DMA_TX
, 1), NULL
,
517 tune
->ntxd
, 0, 0, -1, 0, 0,
519 dma_attach_err
|= (NULL
== wlc_hw
->di
[1]);
523 * TX: TX_AC_VI_FIFO (TX AC Video data packets)
526 wlc_hw
->di
[2] = dma_attach(name
, wlc_hw
->sih
,
527 DMAREG(wlc_hw
, DMA_TX
, 2), NULL
,
528 tune
->ntxd
, 0, 0, -1, 0, 0,
530 dma_attach_err
|= (NULL
== wlc_hw
->di
[2]);
533 * TX: TX_AC_VO_FIFO (TX AC Voice data packets)
534 * (legacy) TX_CTL_FIFO (TX control & mgmt packets)
536 wlc_hw
->di
[3] = dma_attach(name
, wlc_hw
->sih
,
537 DMAREG(wlc_hw
, DMA_TX
, 3),
538 NULL
, tune
->ntxd
, 0, 0, -1,
539 0, 0, &brcm_msg_level
);
540 dma_attach_err
|= (NULL
== wlc_hw
->di
[3]);
541 /* Cleaner to leave this as if with AP defined */
543 if (dma_attach_err
) {
544 wiphy_err(wiphy
, "wl%d: wlc_attach: dma_attach failed"
549 /* get pointer to dma engine tx flow control variable */
550 for (i
= 0; i
< NFIFO
; i
++)
553 (uint
*) dma_getvar(wlc_hw
->di
[i
],
557 /* initial ucode host flags */
558 wlc_mhfdef(wlc
, wlc_hw
->band
->mhfs
, pio_mhf2
);
563 static void wlc_bmac_detach_dmapio(struct wlc_hw_info
*wlc_hw
)
567 for (j
= 0; j
< NFIFO
; j
++) {
569 dma_detach(wlc_hw
->di
[j
]);
570 wlc_hw
->di
[j
] = NULL
;
576 * run backplane attach, init nvram
578 * initialize software state for each core and band
579 * put the whole chip in reset(driver down state), no clock
581 int wlc_bmac_attach(struct wlc_info
*wlc
, u16 vendor
, u16 device
, uint unit
,
582 bool piomode
, void *regsva
, uint bustype
, void *btparam
)
584 struct wlc_hw_info
*wlc_hw
;
586 char *macaddr
= NULL
;
591 shared_phy_params_t sha_params
;
592 struct wiphy
*wiphy
= wlc
->wiphy
;
594 BCMMSG(wlc
->wiphy
, "wl%d: vendor 0x%x device 0x%x\n", unit
, vendor
,
602 wlc_hw
->band
= wlc_hw
->bandstate
[0];
603 wlc_hw
->_piomode
= piomode
;
605 /* populate struct wlc_hw_info with default values */
606 wlc_bmac_info_init(wlc_hw
);
609 * Do the hardware portion of the attach.
610 * Also initialize software state that depends on the particular hardware
613 wlc_hw
->sih
= ai_attach(regsva
, bustype
, btparam
,
614 &wlc_hw
->vars
, &wlc_hw
->vars_size
);
615 if (wlc_hw
->sih
== NULL
) {
616 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: si_attach failed\n",
624 * Get vendid/devid nvram overwrites, which could be different
625 * than those the BIOS recognizes for devices on PCMCIA_BUS,
626 * SDIO_BUS, and SROMless devices on PCI_BUS.
629 bustype
= BCMBUSTYPE
;
631 if (bustype
!= SI_BUS
) {
634 var
= getvar(vars
, "vendid");
636 vendor
= (u16
) simple_strtoul(var
, NULL
, 0);
637 wiphy_err(wiphy
, "Overriding vendor id = 0x%x\n",
640 var
= getvar(vars
, "devid");
642 u16 devid
= (u16
) simple_strtoul(var
, NULL
, 0);
643 if (devid
!= 0xffff) {
645 wiphy_err(wiphy
, "Overriding device id = 0x%x"
650 /* verify again the device is supported */
651 if (!wlc_chipmatch(vendor
, device
)) {
652 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: Unsupported "
653 "vendor/device (0x%x/0x%x)\n",
654 unit
, vendor
, device
);
660 wlc_hw
->vendorid
= vendor
;
661 wlc_hw
->deviceid
= device
;
663 /* set bar0 window to point at D11 core */
664 wlc_hw
->regs
= (d11regs_t
*) ai_setcore(wlc_hw
->sih
, D11_CORE_ID
, 0);
665 wlc_hw
->corerev
= ai_corerev(wlc_hw
->sih
);
669 wlc
->regs
= wlc_hw
->regs
;
671 /* validate chip, chiprev and corerev */
672 if (!wlc_isgoodchip(wlc_hw
)) {
677 /* initialize power control registers */
678 ai_clkctl_init(wlc_hw
->sih
);
680 /* request fastclock and force fastclock for the rest of attach
681 * bring the d11 core out of reset.
682 * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk is still false;
683 * But it will be called again inside wlc_corereset, after d11 is out of reset.
685 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
686 wlc_bmac_corereset(wlc_hw
, WLC_USE_COREFLAGS
);
688 if (!wlc_bmac_validate_chip_access(wlc_hw
)) {
689 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: validate_chip_access "
695 /* get the board rev, used just below */
696 j
= getintvar(vars
, "boardrev");
697 /* promote srom boardrev of 0xFF to 1 */
698 if (j
== BOARDREV_PROMOTABLE
)
699 j
= BOARDREV_PROMOTED
;
700 wlc_hw
->boardrev
= (u16
) j
;
701 if (!wlc_validboardtype(wlc_hw
)) {
702 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: Unsupported Broadcom "
703 "board type (0x%x)" " or revision level (0x%x)\n",
704 unit
, wlc_hw
->sih
->boardtype
, wlc_hw
->boardrev
);
708 wlc_hw
->sromrev
= (u8
) getintvar(vars
, "sromrev");
709 wlc_hw
->boardflags
= (u32
) getintvar(vars
, "boardflags");
710 wlc_hw
->boardflags2
= (u32
) getintvar(vars
, "boardflags2");
712 if (wlc_hw
->boardflags
& BFL_NOPLLDOWN
)
713 wlc_bmac_pllreq(wlc_hw
, true, WLC_PLLREQ_SHARED
);
715 if ((wlc_hw
->sih
->bustype
== PCI_BUS
)
716 && (ai_pci_war16165(wlc_hw
->sih
)))
717 wlc
->war16165
= true;
719 /* check device id(srom, nvram etc.) to set bands */
720 if (wlc_hw
->deviceid
== BCM43224_D11N_ID
||
721 wlc_hw
->deviceid
== BCM43224_D11N_ID_VEN1
) {
722 /* Dualband boards */
727 if ((wlc_hw
->sih
->chip
== BCM43225_CHIP_ID
))
730 /* BMAC_NOTE: remove init of pub values when wlc_attach() unconditionally does the
731 * init of these values
733 wlc
->vendorid
= wlc_hw
->vendorid
;
734 wlc
->deviceid
= wlc_hw
->deviceid
;
735 wlc
->pub
->sih
= wlc_hw
->sih
;
736 wlc
->pub
->corerev
= wlc_hw
->corerev
;
737 wlc
->pub
->sromrev
= wlc_hw
->sromrev
;
738 wlc
->pub
->boardrev
= wlc_hw
->boardrev
;
739 wlc
->pub
->boardflags
= wlc_hw
->boardflags
;
740 wlc
->pub
->boardflags2
= wlc_hw
->boardflags2
;
741 wlc
->pub
->_nbands
= wlc_hw
->_nbands
;
743 wlc_hw
->physhim
= wlc_phy_shim_attach(wlc_hw
, wlc
->wl
, wlc
);
745 if (wlc_hw
->physhim
== NULL
) {
746 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: wlc_phy_shim_attach "
752 /* pass all the parameters to wlc_phy_shared_attach in one struct */
753 sha_params
.sih
= wlc_hw
->sih
;
754 sha_params
.physhim
= wlc_hw
->physhim
;
755 sha_params
.unit
= unit
;
756 sha_params
.corerev
= wlc_hw
->corerev
;
757 sha_params
.vars
= vars
;
758 sha_params
.vid
= wlc_hw
->vendorid
;
759 sha_params
.did
= wlc_hw
->deviceid
;
760 sha_params
.chip
= wlc_hw
->sih
->chip
;
761 sha_params
.chiprev
= wlc_hw
->sih
->chiprev
;
762 sha_params
.chippkg
= wlc_hw
->sih
->chippkg
;
763 sha_params
.sromrev
= wlc_hw
->sromrev
;
764 sha_params
.boardtype
= wlc_hw
->sih
->boardtype
;
765 sha_params
.boardrev
= wlc_hw
->boardrev
;
766 sha_params
.boardvendor
= wlc_hw
->sih
->boardvendor
;
767 sha_params
.boardflags
= wlc_hw
->boardflags
;
768 sha_params
.boardflags2
= wlc_hw
->boardflags2
;
769 sha_params
.bustype
= wlc_hw
->sih
->bustype
;
770 sha_params
.buscorerev
= wlc_hw
->sih
->buscorerev
;
772 /* alloc and save pointer to shared phy state area */
773 wlc_hw
->phy_sh
= wlc_phy_shared_attach(&sha_params
);
774 if (!wlc_hw
->phy_sh
) {
779 /* initialize software state for each core and band */
780 for (j
= 0; j
< NBANDS_HW(wlc_hw
); j
++) {
782 * band0 is always 2.4Ghz
783 * band1, if present, is 5Ghz
786 /* So if this is a single band 11a card, use band 1 */
787 if (IS_SINGLEBAND_5G(wlc_hw
->deviceid
))
790 wlc_setxband(wlc_hw
, j
);
792 wlc_hw
->band
->bandunit
= j
;
793 wlc_hw
->band
->bandtype
= j
? WLC_BAND_5G
: WLC_BAND_2G
;
794 wlc
->band
->bandunit
= j
;
795 wlc
->band
->bandtype
= j
? WLC_BAND_5G
: WLC_BAND_2G
;
796 wlc
->core
->coreidx
= ai_coreidx(wlc_hw
->sih
);
798 wlc_hw
->machwcap
= R_REG(®s
->machwcap
);
799 wlc_hw
->machwcap_backup
= wlc_hw
->machwcap
;
801 /* init tx fifo size */
803 xmtfifo_sz
[(wlc_hw
->corerev
- XMTFIFOTBL_STARTREV
)];
805 /* Get a phy for this band */
806 wlc_hw
->band
->pi
= wlc_phy_attach(wlc_hw
->phy_sh
,
807 (void *)regs
, wlc_bmac_bandtype(wlc_hw
), vars
,
809 if (wlc_hw
->band
->pi
== NULL
) {
810 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: wlc_phy_"
811 "attach failed\n", unit
);
816 wlc_phy_machwcap_set(wlc_hw
->band
->pi
, wlc_hw
->machwcap
);
818 wlc_phy_get_phyversion(wlc_hw
->band
->pi
, &wlc_hw
->band
->phytype
,
819 &wlc_hw
->band
->phyrev
,
820 &wlc_hw
->band
->radioid
,
821 &wlc_hw
->band
->radiorev
);
822 wlc_hw
->band
->abgphy_encore
=
823 wlc_phy_get_encore(wlc_hw
->band
->pi
);
824 wlc
->band
->abgphy_encore
= wlc_phy_get_encore(wlc_hw
->band
->pi
);
825 wlc_hw
->band
->core_flags
=
826 wlc_phy_get_coreflags(wlc_hw
->band
->pi
);
828 /* verify good phy_type & supported phy revision */
829 if (WLCISNPHY(wlc_hw
->band
)) {
830 if (NCONF_HAS(wlc_hw
->band
->phyrev
))
834 } else if (WLCISLCNPHY(wlc_hw
->band
)) {
835 if (LCNCONF_HAS(wlc_hw
->band
->phyrev
))
841 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: unsupported "
842 "phy type/rev (%d/%d)\n", unit
,
843 wlc_hw
->band
->phytype
, wlc_hw
->band
->phyrev
);
849 /* BMAC_NOTE: wlc->band->pi should not be set below and should be done in the
850 * high level attach. However we can not make that change until all low level access
851 * is changed to wlc_hw->band->pi. Instead do the wlc->band->pi init below, keeping
852 * wlc_hw->band->pi as well for incremental update of low level fns, and cut over
853 * low only init when all fns updated.
855 wlc
->band
->pi
= wlc_hw
->band
->pi
;
856 wlc
->band
->phytype
= wlc_hw
->band
->phytype
;
857 wlc
->band
->phyrev
= wlc_hw
->band
->phyrev
;
858 wlc
->band
->radioid
= wlc_hw
->band
->radioid
;
859 wlc
->band
->radiorev
= wlc_hw
->band
->radiorev
;
861 /* default contention windows size limits */
862 wlc_hw
->band
->CWmin
= APHY_CWMIN
;
863 wlc_hw
->band
->CWmax
= PHY_CWMAX
;
865 if (!wlc_bmac_attach_dmapio(wlc
, j
, wme
)) {
871 /* disable core to match driver "down" state */
872 wlc_coredisable(wlc_hw
);
874 /* Match driver "down" state */
875 if (wlc_hw
->sih
->bustype
== PCI_BUS
)
876 ai_pci_down(wlc_hw
->sih
);
878 /* register sb interrupt callback functions */
879 ai_register_intr_callback(wlc_hw
->sih
, (void *)wlc_wlintrsoff
,
880 (void *)wlc_wlintrsrestore
, NULL
, wlc
);
882 /* turn off pll and xtal to match driver "down" state */
883 wlc_bmac_xtal(wlc_hw
, OFF
);
885 /* *********************************************************************
886 * The hardware is in the DOWN state at this point. D11 core
887 * or cores are in reset with clocks off, and the board PLLs
888 * are off if possible.
890 * Beyond this point, wlc->sbclk == false and chip registers
891 * should not be touched.
892 *********************************************************************
895 /* init etheraddr state variables */
896 macaddr
= wlc_get_macaddr(wlc_hw
);
897 if (macaddr
== NULL
) {
898 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: macaddr not found\n",
903 brcmu_ether_atoe(macaddr
, wlc_hw
->etheraddr
);
904 if (is_broadcast_ether_addr(wlc_hw
->etheraddr
) ||
905 is_zero_ether_addr(wlc_hw
->etheraddr
)) {
906 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: bad macaddr %s\n",
913 "deviceid 0x%x nbands %d board 0x%x macaddr: %s\n",
914 wlc_hw
->deviceid
, wlc_hw
->_nbands
,
915 wlc_hw
->sih
->boardtype
, macaddr
);
920 wiphy_err(wiphy
, "wl%d: wlc_bmac_attach: failed with err %d\n", unit
,
926 * Initialize wlc_info default values ...
927 * may get overrides later in this function
928 * BMAC_NOTES, move low out and resolve the dangling ones
930 static void wlc_bmac_info_init(struct wlc_hw_info
*wlc_hw
)
932 struct wlc_info
*wlc
= wlc_hw
->wlc
;
934 /* set default sw macintmask value */
935 wlc
->defmacintmask
= DEF_MACINTMASK
;
937 /* various 802.11g modes */
938 wlc_hw
->shortslot
= false;
940 wlc_hw
->SFBL
= RETRY_SHORT_FB
;
941 wlc_hw
->LFBL
= RETRY_LONG_FB
;
943 /* default mac retry limits */
944 wlc_hw
->SRL
= RETRY_SHORT_DEF
;
945 wlc_hw
->LRL
= RETRY_LONG_DEF
;
946 wlc_hw
->chanspec
= CH20MHZ_CHSPEC(1);
952 int wlc_bmac_detach(struct wlc_info
*wlc
)
955 struct wlc_hwband
*band
;
956 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
962 /* detach interrupt sync mechanism since interrupt is disabled and per-port
963 * interrupt object may has been freed. this must be done before sb core switch
965 ai_deregister_intr_callback(wlc_hw
->sih
);
967 if (wlc_hw
->sih
->bustype
== PCI_BUS
)
968 ai_pci_sleep(wlc_hw
->sih
);
971 wlc_bmac_detach_dmapio(wlc_hw
);
974 for (i
= 0; i
< NBANDS_HW(wlc_hw
); i
++) {
976 /* Detach this band's phy */
977 wlc_phy_detach(band
->pi
);
980 band
= wlc_hw
->bandstate
[OTHERBANDUNIT(wlc
)];
983 /* Free shared phy state */
984 wlc_phy_shared_detach(wlc_hw
->phy_sh
);
986 wlc_phy_shim_detach(wlc_hw
->physhim
);
993 ai_detach(wlc_hw
->sih
);
1001 void wlc_bmac_reset(struct wlc_hw_info
*wlc_hw
)
1003 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1005 /* reset the core */
1006 if (!DEVICEREMOVED(wlc_hw
->wlc
))
1007 wlc_bmac_corereset(wlc_hw
, WLC_USE_COREFLAGS
);
1009 /* purge the dma rings */
1010 wlc_flushqueues(wlc_hw
->wlc
);
1012 wlc_reset_bmac_done(wlc_hw
->wlc
);
1016 wlc_bmac_init(struct wlc_hw_info
*wlc_hw
, chanspec_t chanspec
,
1020 struct wlc_info
*wlc
= wlc_hw
->wlc
;
1022 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1024 /* request FAST clock if not on */
1025 fastclk
= wlc_hw
->forcefastclk
;
1027 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
1029 /* disable interrupts */
1030 macintmask
= brcms_intrsoff(wlc
->wl
);
1032 /* set up the specified band and chanspec */
1033 wlc_setxband(wlc_hw
, CHSPEC_WLCBANDUNIT(chanspec
));
1034 wlc_phy_chanspec_radio_set(wlc_hw
->band
->pi
, chanspec
);
1036 /* do one-time phy inits and calibration */
1037 wlc_phy_cal_init(wlc_hw
->band
->pi
);
1039 /* core-specific initialization */
1042 /* suspend the tx fifos and mute the phy for preism cac time */
1044 wlc_bmac_mute(wlc_hw
, ON
, PHY_MUTE_FOR_PREISM
);
1046 /* band-specific inits */
1047 wlc_bmac_bsinit(wlc
, chanspec
);
1049 /* restore macintmask */
1050 brcms_intrsrestore(wlc
->wl
, macintmask
);
1052 /* seed wake_override with WLC_WAKE_OVERRIDE_MACSUSPEND since the mac is suspended
1053 * and wlc_enable_mac() will clear this override bit.
1055 mboolset(wlc_hw
->wake_override
, WLC_WAKE_OVERRIDE_MACSUSPEND
);
1058 * initialize mac_suspend_depth to 1 to match ucode initial suspended state
1060 wlc_hw
->mac_suspend_depth
= 1;
1062 /* restore the clk */
1064 wlc_clkctl_clk(wlc_hw
, CLK_DYNAMIC
);
1067 int wlc_bmac_up_prep(struct wlc_hw_info
*wlc_hw
)
1071 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1074 * Enable pll and xtal, initialize the power control registers,
1075 * and force fastclock for the remainder of wlc_up().
1077 wlc_bmac_xtal(wlc_hw
, ON
);
1078 ai_clkctl_init(wlc_hw
->sih
);
1079 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
1082 * Configure pci/pcmcia here instead of in wlc_attach()
1083 * to allow mfg hotswap: down, hotswap (chip power cycle), up.
1085 coremask
= (1 << wlc_hw
->wlc
->core
->coreidx
);
1087 if (wlc_hw
->sih
->bustype
== PCI_BUS
)
1088 ai_pci_setup(wlc_hw
->sih
, coremask
);
1091 * Need to read the hwradio status here to cover the case where the system
1092 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
1094 if (wlc_bmac_radio_read_hwdisabled(wlc_hw
)) {
1095 /* put SB PCI in down state again */
1096 if (wlc_hw
->sih
->bustype
== PCI_BUS
)
1097 ai_pci_down(wlc_hw
->sih
);
1098 wlc_bmac_xtal(wlc_hw
, OFF
);
1102 if (wlc_hw
->sih
->bustype
== PCI_BUS
)
1103 ai_pci_up(wlc_hw
->sih
);
1105 /* reset the d11 core */
1106 wlc_bmac_corereset(wlc_hw
, WLC_USE_COREFLAGS
);
1111 int wlc_bmac_up_finish(struct wlc_hw_info
*wlc_hw
)
1113 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1116 wlc_phy_hw_state_upd(wlc_hw
->band
->pi
, true);
1118 /* FULLY enable dynamic power control and d11 core interrupt */
1119 wlc_clkctl_clk(wlc_hw
, CLK_DYNAMIC
);
1120 brcms_intrson(wlc_hw
->wlc
->wl
);
1124 int wlc_bmac_down_prep(struct wlc_hw_info
*wlc_hw
)
1129 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1134 dev_gone
= DEVICEREMOVED(wlc_hw
->wlc
);
1136 /* disable interrupts */
1138 wlc_hw
->wlc
->macintmask
= 0;
1140 /* now disable interrupts */
1141 brcms_intrsoff(wlc_hw
->wlc
->wl
);
1143 /* ensure we're running on the pll clock again */
1144 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
1146 /* down phy at the last of this stage */
1147 callbacks
+= wlc_phy_down(wlc_hw
->band
->pi
);
1152 int wlc_bmac_down_finish(struct wlc_hw_info
*wlc_hw
)
1157 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1163 wlc_phy_hw_state_upd(wlc_hw
->band
->pi
, false);
1165 dev_gone
= DEVICEREMOVED(wlc_hw
->wlc
);
1168 wlc_hw
->sbclk
= false;
1169 wlc_hw
->clk
= false;
1170 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, false);
1172 /* reclaim any posted packets */
1173 wlc_flushqueues(wlc_hw
->wlc
);
1176 /* Reset and disable the core */
1177 if (ai_iscoreup(wlc_hw
->sih
)) {
1178 if (R_REG(&wlc_hw
->regs
->maccontrol
) &
1180 wlc_suspend_mac_and_wait(wlc_hw
->wlc
);
1181 callbacks
+= brcms_reset(wlc_hw
->wlc
->wl
);
1182 wlc_coredisable(wlc_hw
);
1185 /* turn off primary xtal and pll */
1186 if (!wlc_hw
->noreset
) {
1187 if (wlc_hw
->sih
->bustype
== PCI_BUS
)
1188 ai_pci_down(wlc_hw
->sih
);
1189 wlc_bmac_xtal(wlc_hw
, OFF
);
1196 void wlc_bmac_wait_for_wake(struct wlc_hw_info
*wlc_hw
)
1198 /* delay before first read of ucode state */
1201 /* wait until ucode is no longer asleep */
1202 SPINWAIT((wlc_bmac_read_shm(wlc_hw
, M_UCODE_DBGST
) ==
1203 DBGST_ASLEEP
), wlc_hw
->wlc
->fastpwrup_dly
);
1206 void wlc_bmac_hw_etheraddr(struct wlc_hw_info
*wlc_hw
, u8
*ea
)
1208 memcpy(ea
, wlc_hw
->etheraddr
, ETH_ALEN
);
1211 static int wlc_bmac_bandtype(struct wlc_hw_info
*wlc_hw
)
1213 return wlc_hw
->band
->bandtype
;
1216 /* control chip clock to save power, enable dynamic clock or force fast clock */
1217 static void wlc_clkctl_clk(struct wlc_hw_info
*wlc_hw
, uint mode
)
1219 if (PMUCTL_ENAB(wlc_hw
->sih
)) {
1220 /* new chips with PMU, CCS_FORCEHT will distribute the HT clock on backplane,
1221 * but mac core will still run on ALP(not HT) when it enters powersave mode,
1222 * which means the FCA bit may not be set.
1223 * should wakeup mac if driver wants it to run on HT.
1227 if (mode
== CLK_FAST
) {
1228 OR_REG(&wlc_hw
->regs
->clk_ctl_st
,
1235 clk_ctl_st
) & CCS_HTAVAIL
) == 0),
1236 PMU_MAX_TRANSITION_DLY
);
1239 clk_ctl_st
) & CCS_HTAVAIL
));
1241 if ((wlc_hw
->sih
->pmurev
== 0) &&
1244 clk_ctl_st
) & (CCS_FORCEHT
| CCS_HTAREQ
)))
1247 clk_ctl_st
) & CCS_HTAVAIL
)
1249 PMU_MAX_TRANSITION_DLY
);
1250 AND_REG(&wlc_hw
->regs
->clk_ctl_st
,
1254 wlc_hw
->forcefastclk
= (mode
== CLK_FAST
);
1257 /* old chips w/o PMU, force HT through cc,
1258 * then use FCA to verify mac is running fast clock
1261 wlc_hw
->forcefastclk
= ai_clkctl_cc(wlc_hw
->sih
, mode
);
1263 /* check fast clock is available (if core is not in reset) */
1264 if (wlc_hw
->forcefastclk
&& wlc_hw
->clk
)
1265 WARN_ON(!(ai_core_sflags(wlc_hw
->sih
, 0, 0) &
1268 /* keep the ucode wake bit on if forcefastclk is on
1269 * since we do not want ucode to put us back to slow clock
1270 * when it dozes for PM mode.
1271 * Code below matches the wake override bit with current forcefastclk state
1272 * Only setting bit in wake_override instead of waking ucode immediately
1273 * since old code (wlc.c 1.4499) had this behavior. Older code set
1274 * wlc->forcefastclk but only had the wake happen if the wakup_ucode work
1275 * (protected by an up check) was executed just below.
1277 if (wlc_hw
->forcefastclk
)
1278 mboolset(wlc_hw
->wake_override
,
1279 WLC_WAKE_OVERRIDE_FORCEFAST
);
1281 mboolclr(wlc_hw
->wake_override
,
1282 WLC_WAKE_OVERRIDE_FORCEFAST
);
1286 /* set initial host flags value */
1288 wlc_mhfdef(struct wlc_info
*wlc
, u16
*mhfs
, u16 mhf2_init
)
1290 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
1292 memset(mhfs
, 0, MHFMAX
* sizeof(u16
));
1294 mhfs
[MHF2
] |= mhf2_init
;
1296 /* prohibit use of slowclock on multifunction boards */
1297 if (wlc_hw
->boardflags
& BFL_NOPLLDOWN
)
1298 mhfs
[MHF1
] |= MHF1_FORCEFASTCLK
;
1300 if (WLCISNPHY(wlc_hw
->band
) && NREV_LT(wlc_hw
->band
->phyrev
, 2)) {
1301 mhfs
[MHF2
] |= MHF2_NPHY40MHZ_WAR
;
1302 mhfs
[MHF1
] |= MHF1_IQSWAP_WAR
;
1306 /* set or clear ucode host flag bits
1307 * it has an optimization for no-change write
1308 * it only writes through shared memory when the core has clock;
1309 * pre-CLK changes should use wlc_write_mhf to get around the optimization
1312 * bands values are: WLC_BAND_AUTO <--- Current band only
1313 * WLC_BAND_5G <--- 5G band only
1314 * WLC_BAND_2G <--- 2G band only
1315 * WLC_BAND_ALL <--- All bands
1318 wlc_bmac_mhf(struct wlc_hw_info
*wlc_hw
, u8 idx
, u16 mask
, u16 val
,
1322 u16 addr
[MHFMAX
] = {
1323 M_HOST_FLAGS1
, M_HOST_FLAGS2
, M_HOST_FLAGS3
, M_HOST_FLAGS4
,
1326 struct wlc_hwband
*band
;
1328 if ((val
& ~mask
) || idx
>= MHFMAX
)
1329 return; /* error condition */
1332 /* Current band only or all bands,
1333 * then set the band to current band
1337 band
= wlc_hw
->band
;
1340 band
= wlc_hw
->bandstate
[BAND_5G_INDEX
];
1343 band
= wlc_hw
->bandstate
[BAND_2G_INDEX
];
1346 band
= NULL
; /* error condition */
1350 save
= band
->mhfs
[idx
];
1351 band
->mhfs
[idx
] = (band
->mhfs
[idx
] & ~mask
) | val
;
1353 /* optimization: only write through if changed, and
1354 * changed band is the current band
1356 if (wlc_hw
->clk
&& (band
->mhfs
[idx
] != save
)
1357 && (band
== wlc_hw
->band
))
1358 wlc_bmac_write_shm(wlc_hw
, addr
[idx
],
1359 (u16
) band
->mhfs
[idx
]);
1362 if (bands
== WLC_BAND_ALL
) {
1363 wlc_hw
->bandstate
[0]->mhfs
[idx
] =
1364 (wlc_hw
->bandstate
[0]->mhfs
[idx
] & ~mask
) | val
;
1365 wlc_hw
->bandstate
[1]->mhfs
[idx
] =
1366 (wlc_hw
->bandstate
[1]->mhfs
[idx
] & ~mask
) | val
;
1370 u16
wlc_bmac_mhf_get(struct wlc_hw_info
*wlc_hw
, u8 idx
, int bands
)
1372 struct wlc_hwband
*band
;
1375 return 0; /* error condition */
1378 band
= wlc_hw
->band
;
1381 band
= wlc_hw
->bandstate
[BAND_5G_INDEX
];
1384 band
= wlc_hw
->bandstate
[BAND_2G_INDEX
];
1387 band
= NULL
; /* error condition */
1393 return band
->mhfs
[idx
];
1396 static void wlc_write_mhf(struct wlc_hw_info
*wlc_hw
, u16
*mhfs
)
1400 M_HOST_FLAGS1
, M_HOST_FLAGS2
, M_HOST_FLAGS3
, M_HOST_FLAGS4
,
1404 for (idx
= 0; idx
< MHFMAX
; idx
++) {
1405 wlc_bmac_write_shm(wlc_hw
, addr
[idx
], mhfs
[idx
]);
1409 /* set the maccontrol register to desired reset state and
1410 * initialize the sw cache of the register
1412 static void wlc_mctrl_reset(struct wlc_hw_info
*wlc_hw
)
1414 /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
1415 wlc_hw
->maccontrol
= 0;
1416 wlc_hw
->suspended_fifos
= 0;
1417 wlc_hw
->wake_override
= 0;
1418 wlc_hw
->mute_override
= 0;
1419 wlc_bmac_mctrl(wlc_hw
, ~0, MCTL_IHR_EN
| MCTL_WAKE
);
1422 /* set or clear maccontrol bits */
1423 void wlc_bmac_mctrl(struct wlc_hw_info
*wlc_hw
, u32 mask
, u32 val
)
1429 return; /* error condition */
1430 maccontrol
= wlc_hw
->maccontrol
;
1431 new_maccontrol
= (maccontrol
& ~mask
) | val
;
1433 /* if the new maccontrol value is the same as the old, nothing to do */
1434 if (new_maccontrol
== maccontrol
)
1437 /* something changed, cache the new value */
1438 wlc_hw
->maccontrol
= new_maccontrol
;
1440 /* write the new values with overrides applied */
1441 wlc_mctrl_write(wlc_hw
);
1444 /* write the software state of maccontrol and overrides to the maccontrol register */
1445 static void wlc_mctrl_write(struct wlc_hw_info
*wlc_hw
)
1447 u32 maccontrol
= wlc_hw
->maccontrol
;
1449 /* OR in the wake bit if overridden */
1450 if (wlc_hw
->wake_override
)
1451 maccontrol
|= MCTL_WAKE
;
1453 /* set AP and INFRA bits for mute if needed */
1454 if (wlc_hw
->mute_override
) {
1455 maccontrol
&= ~(MCTL_AP
);
1456 maccontrol
|= MCTL_INFRA
;
1459 W_REG(&wlc_hw
->regs
->maccontrol
, maccontrol
);
1462 void wlc_ucode_wake_override_set(struct wlc_hw_info
*wlc_hw
, u32 override_bit
)
1464 if (wlc_hw
->wake_override
|| (wlc_hw
->maccontrol
& MCTL_WAKE
)) {
1465 mboolset(wlc_hw
->wake_override
, override_bit
);
1469 mboolset(wlc_hw
->wake_override
, override_bit
);
1471 wlc_mctrl_write(wlc_hw
);
1472 wlc_bmac_wait_for_wake(wlc_hw
);
1477 void wlc_ucode_wake_override_clear(struct wlc_hw_info
*wlc_hw
, u32 override_bit
)
1479 mboolclr(wlc_hw
->wake_override
, override_bit
);
1481 if (wlc_hw
->wake_override
|| (wlc_hw
->maccontrol
& MCTL_WAKE
))
1484 wlc_mctrl_write(wlc_hw
);
1489 /* When driver needs ucode to stop beaconing, it has to make sure that
1490 * MCTL_AP is clear and MCTL_INFRA is set
1491 * Mode MCTL_AP MCTL_INFRA
1493 * STA 0 1 <--- This will ensure no beacons
1496 static void wlc_ucode_mute_override_set(struct wlc_hw_info
*wlc_hw
)
1498 wlc_hw
->mute_override
= 1;
1500 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1501 * override, then there is no change to write
1503 if ((wlc_hw
->maccontrol
& (MCTL_AP
| MCTL_INFRA
)) == MCTL_INFRA
)
1506 wlc_mctrl_write(wlc_hw
);
1511 /* Clear the override on AP and INFRA bits */
1512 static void wlc_ucode_mute_override_clear(struct wlc_hw_info
*wlc_hw
)
1514 if (wlc_hw
->mute_override
== 0)
1517 wlc_hw
->mute_override
= 0;
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
);
1529 * Write a MAC address to the given match reg offset in the RXE match engine.
1532 wlc_bmac_set_addrmatch(struct wlc_hw_info
*wlc_hw
, int match_reg_offset
,
1540 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d: wlc_bmac_set_addrmatch\n",
1543 regs
= wlc_hw
->regs
;
1544 mac_l
= addr
[0] | (addr
[1] << 8);
1545 mac_m
= addr
[2] | (addr
[3] << 8);
1546 mac_h
= addr
[4] | (addr
[5] << 8);
1548 /* enter the MAC addr into the RXE match registers */
1549 W_REG(®s
->rcm_ctl
, RCM_INC_DATA
| match_reg_offset
);
1550 W_REG(®s
->rcm_mat_data
, mac_l
);
1551 W_REG(®s
->rcm_mat_data
, mac_m
);
1552 W_REG(®s
->rcm_mat_data
, mac_h
);
1557 wlc_bmac_write_template_ram(struct wlc_hw_info
*wlc_hw
, int offset
, int len
,
1563 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1565 regs
= wlc_hw
->regs
;
1566 W_REG(®s
->tplatewrptr
, offset
);
1568 /* if MCTL_BIGEND bit set in mac control register,
1569 * the chip swaps data in fifo, as well as data in
1572 be_bit
= (R_REG(®s
->maccontrol
) & MCTL_BIGEND
) != 0;
1575 memcpy(&word
, buf
, sizeof(u32
));
1578 word
= cpu_to_be32(word
);
1580 word
= cpu_to_le32(word
);
1582 W_REG(®s
->tplatewrdata
, word
);
1584 buf
= (u8
*) buf
+ sizeof(u32
);
1589 void wlc_bmac_set_cwmin(struct wlc_hw_info
*wlc_hw
, u16 newmin
)
1591 wlc_hw
->band
->CWmin
= newmin
;
1593 W_REG(&wlc_hw
->regs
->objaddr
, OBJADDR_SCR_SEL
| S_DOT11_CWMIN
);
1594 (void)R_REG(&wlc_hw
->regs
->objaddr
);
1595 W_REG(&wlc_hw
->regs
->objdata
, newmin
);
1598 void wlc_bmac_set_cwmax(struct wlc_hw_info
*wlc_hw
, u16 newmax
)
1600 wlc_hw
->band
->CWmax
= newmax
;
1602 W_REG(&wlc_hw
->regs
->objaddr
, OBJADDR_SCR_SEL
| S_DOT11_CWMAX
);
1603 (void)R_REG(&wlc_hw
->regs
->objaddr
);
1604 W_REG(&wlc_hw
->regs
->objdata
, newmax
);
1607 void wlc_bmac_bw_set(struct wlc_hw_info
*wlc_hw
, u16 bw
)
1611 /* request FAST clock if not on */
1612 fastclk
= wlc_hw
->forcefastclk
;
1614 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
1616 wlc_phy_bw_state_set(wlc_hw
->band
->pi
, bw
);
1618 wlc_bmac_phy_reset(wlc_hw
);
1619 wlc_phy_init(wlc_hw
->band
->pi
, wlc_phy_chanspec_get(wlc_hw
->band
->pi
));
1621 /* restore the clk */
1623 wlc_clkctl_clk(wlc_hw
, CLK_DYNAMIC
);
1627 wlc_write_hw_bcntemplate0(struct wlc_hw_info
*wlc_hw
, void *bcn
, int len
)
1629 d11regs_t
*regs
= wlc_hw
->regs
;
1631 wlc_bmac_write_template_ram(wlc_hw
, T_BCN0_TPL_BASE
, (len
+ 3) & ~3,
1633 /* write beacon length to SCR */
1634 wlc_bmac_write_shm(wlc_hw
, M_BCN0_FRM_BYTESZ
, (u16
) len
);
1635 /* mark beacon0 valid */
1636 OR_REG(®s
->maccommand
, MCMD_BCN0VLD
);
1640 wlc_write_hw_bcntemplate1(struct wlc_hw_info
*wlc_hw
, void *bcn
, int len
)
1642 d11regs_t
*regs
= wlc_hw
->regs
;
1644 wlc_bmac_write_template_ram(wlc_hw
, T_BCN1_TPL_BASE
, (len
+ 3) & ~3,
1646 /* write beacon length to SCR */
1647 wlc_bmac_write_shm(wlc_hw
, M_BCN1_FRM_BYTESZ
, (u16
) len
);
1648 /* mark beacon1 valid */
1649 OR_REG(®s
->maccommand
, MCMD_BCN1VLD
);
1652 /* mac is assumed to be suspended at this point */
1654 wlc_bmac_write_hw_bcntemplates(struct wlc_hw_info
*wlc_hw
, void *bcn
, int len
,
1657 d11regs_t
*regs
= wlc_hw
->regs
;
1660 wlc_write_hw_bcntemplate0(wlc_hw
, bcn
, len
);
1661 wlc_write_hw_bcntemplate1(wlc_hw
, bcn
, len
);
1664 if (!(R_REG(®s
->maccommand
) & MCMD_BCN0VLD
))
1665 wlc_write_hw_bcntemplate0(wlc_hw
, bcn
, len
);
1668 (R_REG(®s
->maccommand
) & MCMD_BCN1VLD
))
1669 wlc_write_hw_bcntemplate1(wlc_hw
, bcn
, len
);
1673 static void WLBANDINITFN(wlc_bmac_upd_synthpu
) (struct wlc_hw_info
*wlc_hw
)
1676 struct wlc_info
*wlc
= wlc_hw
->wlc
;
1677 /* update SYNTHPU_DLY */
1679 if (WLCISLCNPHY(wlc
->band
)) {
1680 v
= SYNTHPU_DLY_LPPHY_US
;
1681 } else if (WLCISNPHY(wlc
->band
) && (NREV_GE(wlc
->band
->phyrev
, 3))) {
1682 v
= SYNTHPU_DLY_NPHY_US
;
1684 v
= SYNTHPU_DLY_BPHY_US
;
1687 wlc_bmac_write_shm(wlc_hw
, M_SYNTHPU_DLY
, v
);
1690 /* band-specific init */
1692 WLBANDINITFN(wlc_bmac_bsinit
) (struct wlc_info
*wlc
, chanspec_t chanspec
)
1694 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
1696 BCMMSG(wlc
->wiphy
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
1697 wlc_hw
->band
->bandunit
);
1699 wlc_ucode_bsinit(wlc_hw
);
1701 wlc_phy_init(wlc_hw
->band
->pi
, chanspec
);
1703 wlc_ucode_txant_set(wlc_hw
);
1705 /* cwmin is band-specific, update hardware with value for current band */
1706 wlc_bmac_set_cwmin(wlc_hw
, wlc_hw
->band
->CWmin
);
1707 wlc_bmac_set_cwmax(wlc_hw
, wlc_hw
->band
->CWmax
);
1709 wlc_bmac_update_slot_timing(wlc_hw
,
1710 BAND_5G(wlc_hw
->band
->
1711 bandtype
) ? true : wlc_hw
->
1714 /* write phytype and phyvers */
1715 wlc_bmac_write_shm(wlc_hw
, M_PHYTYPE
, (u16
) wlc_hw
->band
->phytype
);
1716 wlc_bmac_write_shm(wlc_hw
, M_PHYVER
, (u16
) wlc_hw
->band
->phyrev
);
1718 /* initialize the txphyctl1 rate table since shmem is shared between bands */
1719 wlc_upd_ofdm_pctl1_table(wlc_hw
);
1721 wlc_bmac_upd_synthpu(wlc_hw
);
1724 static void wlc_bmac_core_phy_clk(struct wlc_hw_info
*wlc_hw
, bool clk
)
1726 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d: clk %d\n", wlc_hw
->unit
, clk
);
1728 wlc_hw
->phyclk
= clk
;
1730 if (OFF
== clk
) { /* clear gmode bit, put phy into reset */
1732 ai_core_cflags(wlc_hw
->sih
, (SICF_PRST
| SICF_FGC
| SICF_GMODE
),
1733 (SICF_PRST
| SICF_FGC
));
1735 ai_core_cflags(wlc_hw
->sih
, (SICF_PRST
| SICF_FGC
), SICF_PRST
);
1738 } else { /* take phy out of reset */
1740 ai_core_cflags(wlc_hw
->sih
, (SICF_PRST
| SICF_FGC
), SICF_FGC
);
1742 ai_core_cflags(wlc_hw
->sih
, (SICF_FGC
), 0);
1748 /* Perform a soft reset of the PHY PLL */
1749 void wlc_bmac_core_phypll_reset(struct wlc_hw_info
*wlc_hw
)
1751 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1753 ai_corereg(wlc_hw
->sih
, SI_CC_IDX
,
1754 offsetof(chipcregs_t
, chipcontrol_addr
), ~0, 0);
1756 ai_corereg(wlc_hw
->sih
, SI_CC_IDX
,
1757 offsetof(chipcregs_t
, chipcontrol_data
), 0x4, 0);
1759 ai_corereg(wlc_hw
->sih
, SI_CC_IDX
,
1760 offsetof(chipcregs_t
, chipcontrol_data
), 0x4, 4);
1762 ai_corereg(wlc_hw
->sih
, SI_CC_IDX
,
1763 offsetof(chipcregs_t
, chipcontrol_data
), 0x4, 0);
1767 /* light way to turn on phy clock without reset for NPHY only
1768 * refer to wlc_bmac_core_phy_clk for full version
1770 void wlc_bmac_phyclk_fgc(struct wlc_hw_info
*wlc_hw
, bool clk
)
1772 /* support(necessary for NPHY and HYPHY) only */
1773 if (!WLCISNPHY(wlc_hw
->band
))
1777 ai_core_cflags(wlc_hw
->sih
, SICF_FGC
, SICF_FGC
);
1779 ai_core_cflags(wlc_hw
->sih
, SICF_FGC
, 0);
1783 void wlc_bmac_macphyclk_set(struct wlc_hw_info
*wlc_hw
, bool clk
)
1786 ai_core_cflags(wlc_hw
->sih
, SICF_MPCLKE
, SICF_MPCLKE
);
1788 ai_core_cflags(wlc_hw
->sih
, SICF_MPCLKE
, 0);
1791 void wlc_bmac_phy_reset(struct wlc_hw_info
*wlc_hw
)
1793 wlc_phy_t
*pih
= wlc_hw
->band
->pi
;
1795 bool phy_in_reset
= false;
1797 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
1802 phy_bw_clkbits
= wlc_phy_clk_bwbits(wlc_hw
->band
->pi
);
1804 /* Specific reset sequence required for NPHY rev 3 and 4 */
1805 if (WLCISNPHY(wlc_hw
->band
) && NREV_GE(wlc_hw
->band
->phyrev
, 3) &&
1806 NREV_LE(wlc_hw
->band
->phyrev
, 4)) {
1807 /* Set the PHY bandwidth */
1808 ai_core_cflags(wlc_hw
->sih
, SICF_BWMASK
, phy_bw_clkbits
);
1812 /* Perform a soft reset of the PHY PLL */
1813 wlc_bmac_core_phypll_reset(wlc_hw
);
1816 ai_core_cflags(wlc_hw
->sih
, (SICF_PRST
| SICF_PCLKE
),
1817 (SICF_PRST
| SICF_PCLKE
));
1818 phy_in_reset
= true;
1821 ai_core_cflags(wlc_hw
->sih
,
1822 (SICF_PRST
| SICF_PCLKE
| SICF_BWMASK
),
1823 (SICF_PRST
| SICF_PCLKE
| phy_bw_clkbits
));
1827 wlc_bmac_core_phy_clk(wlc_hw
, ON
);
1830 wlc_phy_anacore(pih
, ON
);
1833 /* switch to and initialize new band */
1835 WLBANDINITFN(wlc_bmac_setband
) (struct wlc_hw_info
*wlc_hw
, uint bandunit
,
1836 chanspec_t chanspec
) {
1837 struct wlc_info
*wlc
= wlc_hw
->wlc
;
1840 /* Enable the d11 core before accessing it */
1841 if (!ai_iscoreup(wlc_hw
->sih
)) {
1842 ai_core_reset(wlc_hw
->sih
, 0, 0);
1843 wlc_mctrl_reset(wlc_hw
);
1846 macintmask
= wlc_setband_inact(wlc
, bandunit
);
1851 wlc_bmac_core_phy_clk(wlc_hw
, ON
);
1853 /* band-specific initializations */
1854 wlc_bmac_bsinit(wlc
, chanspec
);
1857 * If there are any pending software interrupt bits,
1858 * then replace these with a harmless nonzero value
1859 * so wlc_dpc() will re-enable interrupts when done.
1861 if (wlc
->macintstatus
)
1862 wlc
->macintstatus
= MI_DMAINT
;
1864 /* restore macintmask */
1865 brcms_intrsrestore(wlc
->wl
, macintmask
);
1867 /* ucode should still be suspended.. */
1868 WARN_ON((R_REG(&wlc_hw
->regs
->maccontrol
) & MCTL_EN_MAC
) != 0);
1871 /* low-level band switch utility routine */
1872 void WLBANDINITFN(wlc_setxband
) (struct wlc_hw_info
*wlc_hw
, uint bandunit
)
1874 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
1877 wlc_hw
->band
= wlc_hw
->bandstate
[bandunit
];
1879 /* BMAC_NOTE: until we eliminate need for wlc->band refs in low level code */
1880 wlc_hw
->wlc
->band
= wlc_hw
->wlc
->bandstate
[bandunit
];
1882 /* set gmode core flag */
1883 if (wlc_hw
->sbclk
&& !wlc_hw
->noreset
) {
1884 ai_core_cflags(wlc_hw
->sih
, SICF_GMODE
,
1885 ((bandunit
== 0) ? SICF_GMODE
: 0));
1889 static bool wlc_isgoodchip(struct wlc_hw_info
*wlc_hw
)
1892 /* reject unsupported corerev */
1893 if (!VALID_COREREV(wlc_hw
->corerev
)) {
1894 wiphy_err(wlc_hw
->wlc
->wiphy
, "unsupported core rev %d\n",
1902 static bool wlc_validboardtype(struct wlc_hw_info
*wlc_hw
)
1904 bool goodboard
= true;
1905 uint boardrev
= wlc_hw
->boardrev
;
1909 else if (boardrev
> 0xff) {
1910 uint brt
= (boardrev
& 0xf000) >> 12;
1911 uint b0
= (boardrev
& 0xf00) >> 8;
1912 uint b1
= (boardrev
& 0xf0) >> 4;
1913 uint b2
= boardrev
& 0xf;
1915 if ((brt
> 2) || (brt
== 0) || (b0
> 9) || (b0
== 0) || (b1
> 9)
1920 if (wlc_hw
->sih
->boardvendor
!= PCI_VENDOR_ID_BROADCOM
)
1926 static char *wlc_get_macaddr(struct wlc_hw_info
*wlc_hw
)
1928 const char *varname
= "macaddr";
1931 /* If macaddr exists, use it (Sromrev4, CIS, ...). */
1932 macaddr
= getvar(wlc_hw
->vars
, varname
);
1933 if (macaddr
!= NULL
)
1936 if (NBANDS_HW(wlc_hw
) > 1)
1937 varname
= "et1macaddr";
1939 varname
= "il0macaddr";
1941 macaddr
= getvar(wlc_hw
->vars
, varname
);
1942 if (macaddr
== NULL
) {
1943 wiphy_err(wlc_hw
->wlc
->wiphy
, "wl%d: wlc_get_macaddr: macaddr "
1944 "getvar(%s) not found\n", wlc_hw
->unit
, varname
);
1951 * Return true if radio is disabled, otherwise false.
1952 * hw radio disable signal is an external pin, users activate it asynchronously
1953 * this function could be called when driver is down and w/o clock
1954 * it operates on different registers depending on corerev and boardflag.
1956 bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info
*wlc_hw
)
1959 u32 resetbits
= 0, flags
= 0;
1961 xtal
= wlc_hw
->sbclk
;
1963 wlc_bmac_xtal(wlc_hw
, ON
);
1965 /* may need to take core out of reset first */
1969 * mac no longer enables phyclk automatically when driver
1970 * accesses phyreg throughput mac. This can be skipped since
1971 * only mac reg is accessed below
1973 flags
|= SICF_PCLKE
;
1975 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
1976 if ((wlc_hw
->sih
->chip
== BCM43224_CHIP_ID
) ||
1977 (wlc_hw
->sih
->chip
== BCM43225_CHIP_ID
) ||
1978 (wlc_hw
->sih
->chip
== BCM43421_CHIP_ID
))
1980 (d11regs_t
*) ai_setcore(wlc_hw
->sih
, D11_CORE_ID
,
1982 ai_core_reset(wlc_hw
->sih
, flags
, resetbits
);
1983 wlc_mctrl_reset(wlc_hw
);
1986 v
= ((R_REG(&wlc_hw
->regs
->phydebug
) & PDBG_RFD
) != 0);
1988 /* put core back into reset */
1990 ai_core_disable(wlc_hw
->sih
, 0);
1993 wlc_bmac_xtal(wlc_hw
, OFF
);
1998 /* Initialize just the hardware when coming out of POR or S3/S5 system states */
1999 void wlc_bmac_hw_up(struct wlc_hw_info
*wlc_hw
)
2001 if (wlc_hw
->wlc
->pub
->hw_up
)
2004 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
2007 * Enable pll and xtal, initialize the power control registers,
2008 * and force fastclock for the remainder of wlc_up().
2010 wlc_bmac_xtal(wlc_hw
, ON
);
2011 ai_clkctl_init(wlc_hw
->sih
);
2012 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
2014 if (wlc_hw
->sih
->bustype
== PCI_BUS
) {
2015 ai_pci_fixcfg(wlc_hw
->sih
);
2017 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2018 if ((wlc_hw
->sih
->chip
== BCM43224_CHIP_ID
) ||
2019 (wlc_hw
->sih
->chip
== BCM43225_CHIP_ID
) ||
2020 (wlc_hw
->sih
->chip
== BCM43421_CHIP_ID
))
2022 (d11regs_t
*) ai_setcore(wlc_hw
->sih
, D11_CORE_ID
,
2026 /* Inform phy that a POR reset has occurred so it does a complete phy init */
2027 wlc_phy_por_inform(wlc_hw
->band
->pi
);
2029 wlc_hw
->ucode_loaded
= false;
2030 wlc_hw
->wlc
->pub
->hw_up
= true;
2032 if ((wlc_hw
->boardflags
& BFL_FEM
)
2033 && (wlc_hw
->sih
->chip
== BCM4313_CHIP_ID
)) {
2035 (wlc_hw
->boardrev
>= 0x1250
2036 && (wlc_hw
->boardflags
& BFL_FEM_BT
)))
2037 ai_epa_4313war(wlc_hw
->sih
);
2041 static bool wlc_dma_rxreset(struct wlc_hw_info
*wlc_hw
, uint fifo
)
2043 struct dma_pub
*di
= wlc_hw
->di
[fifo
];
2044 return dma_rxreset(di
);
2048 * ensure fask clock during reset
2050 * reset d11(out of reset)
2051 * reset phy(out of reset)
2052 * clear software macintstatus for fresh new start
2053 * one testing hack wlc_hw->noreset will bypass the d11/phy reset
2055 void wlc_bmac_corereset(struct wlc_hw_info
*wlc_hw
, u32 flags
)
2062 if (flags
== WLC_USE_COREFLAGS
)
2063 flags
= (wlc_hw
->band
->pi
? wlc_hw
->band
->core_flags
: 0);
2065 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
2067 regs
= wlc_hw
->regs
;
2069 /* request FAST clock if not on */
2070 fastclk
= wlc_hw
->forcefastclk
;
2072 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
2074 /* reset the dma engines except first time thru */
2075 if (ai_iscoreup(wlc_hw
->sih
)) {
2076 for (i
= 0; i
< NFIFO
; i
++)
2077 if ((wlc_hw
->di
[i
]) && (!dma_txreset(wlc_hw
->di
[i
]))) {
2078 wiphy_err(wlc_hw
->wlc
->wiphy
, "wl%d: %s: "
2079 "dma_txreset[%d]: cannot stop dma\n",
2080 wlc_hw
->unit
, __func__
, i
);
2083 if ((wlc_hw
->di
[RX_FIFO
])
2084 && (!wlc_dma_rxreset(wlc_hw
, RX_FIFO
))) {
2085 wiphy_err(wlc_hw
->wlc
->wiphy
, "wl%d: %s: dma_rxreset"
2086 "[%d]: cannot stop dma\n",
2087 wlc_hw
->unit
, __func__
, RX_FIFO
);
2090 /* if noreset, just stop the psm and return */
2091 if (wlc_hw
->noreset
) {
2092 wlc_hw
->wlc
->macintstatus
= 0; /* skip wl_dpc after down */
2093 wlc_bmac_mctrl(wlc_hw
, MCTL_PSM_RUN
| MCTL_EN_MAC
, 0);
2098 * mac no longer enables phyclk automatically when driver accesses
2099 * phyreg throughput mac, AND phy_reset is skipped at early stage when
2100 * band->pi is invalid. need to enable PHY CLK
2102 flags
|= SICF_PCLKE
;
2105 * In chips with PMU, the fastclk request goes through d11 core reg 0x1e0, which
2106 * is cleared by the core_reset. have to re-request it.
2107 * This adds some delay and we can optimize it by also requesting fastclk through
2108 * chipcommon during this period if necessary. But that has to work coordinate
2109 * with other driver like mips/arm since they may touch chipcommon as well.
2111 wlc_hw
->clk
= false;
2112 ai_core_reset(wlc_hw
->sih
, flags
, resetbits
);
2114 if (wlc_hw
->band
&& wlc_hw
->band
->pi
)
2115 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, true);
2117 wlc_mctrl_reset(wlc_hw
);
2119 if (PMUCTL_ENAB(wlc_hw
->sih
))
2120 wlc_clkctl_clk(wlc_hw
, CLK_FAST
);
2122 wlc_bmac_phy_reset(wlc_hw
);
2124 /* turn on PHY_PLL */
2125 wlc_bmac_core_phypll_ctl(wlc_hw
, true);
2127 /* clear sw intstatus */
2128 wlc_hw
->wlc
->macintstatus
= 0;
2130 /* restore the clk setting */
2132 wlc_clkctl_clk(wlc_hw
, CLK_DYNAMIC
);
2135 /* txfifo sizes needs to be modified(increased) since the newer cores
2138 static void wlc_corerev_fifofixup(struct wlc_hw_info
*wlc_hw
)
2140 d11regs_t
*regs
= wlc_hw
->regs
;
2142 u16 txfifo_startblk
= TXFIFO_START_BLK
, txfifo_endblk
;
2143 u16 txfifo_def
, txfifo_def1
;
2146 /* tx fifos start at TXFIFO_START_BLK from the Base address */
2147 txfifo_startblk
= TXFIFO_START_BLK
;
2149 /* sequence of operations: reset fifo, set fifo size, reset fifo */
2150 for (fifo_nu
= 0; fifo_nu
< NFIFO
; fifo_nu
++) {
2152 txfifo_endblk
= txfifo_startblk
+ wlc_hw
->xmtfifo_sz
[fifo_nu
];
2153 txfifo_def
= (txfifo_startblk
& 0xff) |
2154 (((txfifo_endblk
- 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT
);
2155 txfifo_def1
= ((txfifo_startblk
>> 8) & 0x1) |
2157 1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT
);
2159 TXFIFOCMD_RESET_MASK
| (fifo_nu
<< TXFIFOCMD_FIFOSEL_SHIFT
);
2161 W_REG(®s
->xmtfifocmd
, txfifo_cmd
);
2162 W_REG(®s
->xmtfifodef
, txfifo_def
);
2163 W_REG(®s
->xmtfifodef1
, txfifo_def1
);
2165 W_REG(®s
->xmtfifocmd
, txfifo_cmd
);
2167 txfifo_startblk
+= wlc_hw
->xmtfifo_sz
[fifo_nu
];
2170 * need to propagate to shm location to be in sync since ucode/hw won't
2173 wlc_bmac_write_shm(wlc_hw
, M_FIFOSIZE0
,
2174 wlc_hw
->xmtfifo_sz
[TX_AC_BE_FIFO
]);
2175 wlc_bmac_write_shm(wlc_hw
, M_FIFOSIZE1
,
2176 wlc_hw
->xmtfifo_sz
[TX_AC_VI_FIFO
]);
2177 wlc_bmac_write_shm(wlc_hw
, M_FIFOSIZE2
,
2178 ((wlc_hw
->xmtfifo_sz
[TX_AC_VO_FIFO
] << 8) | wlc_hw
->
2179 xmtfifo_sz
[TX_AC_BK_FIFO
]));
2180 wlc_bmac_write_shm(wlc_hw
, M_FIFOSIZE3
,
2181 ((wlc_hw
->xmtfifo_sz
[TX_ATIM_FIFO
] << 8) | wlc_hw
->
2182 xmtfifo_sz
[TX_BCMC_FIFO
]));
2187 * download ucode/PCM
2188 * let ucode run to suspended
2189 * download ucode inits
2190 * config other core registers
2193 static void wlc_coreinit(struct wlc_info
*wlc
)
2195 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
2200 bool fifosz_fixup
= false;
2203 struct wiphy
*wiphy
= wlc
->wiphy
;
2205 regs
= wlc_hw
->regs
;
2207 BCMMSG(wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
2210 wlc_bmac_mctrl(wlc_hw
, ~0, (MCTL_IHR_EN
| MCTL_PSM_JMP_0
| MCTL_WAKE
));
2212 wlc_ucode_download(wlc_hw
);
2214 * FIFOSZ fixup. driver wants to controls the fifo allocation.
2216 fifosz_fixup
= true;
2218 /* let the PSM run to the suspended state, set mode to BSS STA */
2219 W_REG(®s
->macintstatus
, -1);
2220 wlc_bmac_mctrl(wlc_hw
, ~0,
2221 (MCTL_IHR_EN
| MCTL_INFRA
| MCTL_PSM_RUN
| MCTL_WAKE
));
2223 /* wait for ucode to self-suspend after auto-init */
2224 SPINWAIT(((R_REG(®s
->macintstatus
) & MI_MACSSPNDD
) == 0),
2226 if ((R_REG(®s
->macintstatus
) & MI_MACSSPNDD
) == 0)
2227 wiphy_err(wiphy
, "wl%d: wlc_coreinit: ucode did not self-"
2228 "suspend!\n", wlc_hw
->unit
);
2232 sflags
= ai_core_sflags(wlc_hw
->sih
, 0, 0);
2234 if (D11REV_IS(wlc_hw
->corerev
, 23)) {
2235 if (WLCISNPHY(wlc_hw
->band
))
2236 wlc_write_inits(wlc_hw
, d11n0initvals16
);
2238 wiphy_err(wiphy
, "%s: wl%d: unsupported phy in corerev"
2239 " %d\n", __func__
, wlc_hw
->unit
,
2241 } else if (D11REV_IS(wlc_hw
->corerev
, 24)) {
2242 if (WLCISLCNPHY(wlc_hw
->band
)) {
2243 wlc_write_inits(wlc_hw
, d11lcn0initvals24
);
2245 wiphy_err(wiphy
, "%s: wl%d: unsupported phy in corerev"
2246 " %d\n", __func__
, wlc_hw
->unit
,
2250 wiphy_err(wiphy
, "%s: wl%d: unsupported corerev %d\n",
2251 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
2254 /* For old ucode, txfifo sizes needs to be modified(increased) */
2255 if (fifosz_fixup
== true) {
2256 wlc_corerev_fifofixup(wlc_hw
);
2259 /* check txfifo allocations match between ucode and driver */
2260 buf
[TX_AC_BE_FIFO
] = wlc_bmac_read_shm(wlc_hw
, M_FIFOSIZE0
);
2261 if (buf
[TX_AC_BE_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_BE_FIFO
]) {
2265 buf
[TX_AC_VI_FIFO
] = wlc_bmac_read_shm(wlc_hw
, M_FIFOSIZE1
);
2266 if (buf
[TX_AC_VI_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_VI_FIFO
]) {
2270 buf
[TX_AC_BK_FIFO
] = wlc_bmac_read_shm(wlc_hw
, M_FIFOSIZE2
);
2271 buf
[TX_AC_VO_FIFO
] = (buf
[TX_AC_BK_FIFO
] >> 8) & 0xff;
2272 buf
[TX_AC_BK_FIFO
] &= 0xff;
2273 if (buf
[TX_AC_BK_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_BK_FIFO
]) {
2277 if (buf
[TX_AC_VO_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_VO_FIFO
]) {
2281 buf
[TX_BCMC_FIFO
] = wlc_bmac_read_shm(wlc_hw
, M_FIFOSIZE3
);
2282 buf
[TX_ATIM_FIFO
] = (buf
[TX_BCMC_FIFO
] >> 8) & 0xff;
2283 buf
[TX_BCMC_FIFO
] &= 0xff;
2284 if (buf
[TX_BCMC_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_BCMC_FIFO
]) {
2288 if (buf
[TX_ATIM_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_ATIM_FIFO
]) {
2293 wiphy_err(wiphy
, "wlc_coreinit: txfifo mismatch: ucode size %d"
2294 " driver size %d index %d\n", buf
[i
],
2295 wlc_hw
->xmtfifo_sz
[i
], i
);
2298 /* make sure we can still talk to the mac */
2299 WARN_ON(R_REG(®s
->maccontrol
) == 0xffffffff);
2301 /* band-specific inits done by wlc_bsinit() */
2303 /* Set up frame burst size and antenna swap threshold init values */
2304 wlc_bmac_write_shm(wlc_hw
, M_MBURST_SIZE
, MAXTXFRAMEBURST
);
2305 wlc_bmac_write_shm(wlc_hw
, M_MAX_ANTCNT
, ANTCNT
);
2307 /* enable one rx interrupt per received frame */
2308 W_REG(®s
->intrcvlazy
[0], (1 << IRL_FC_SHIFT
));
2310 /* set the station mode (BSS STA) */
2311 wlc_bmac_mctrl(wlc_hw
,
2312 (MCTL_INFRA
| MCTL_DISCARD_PMQ
| MCTL_AP
),
2313 (MCTL_INFRA
| MCTL_DISCARD_PMQ
));
2315 /* set up Beacon interval */
2316 bcnint_us
= 0x8000 << 10;
2317 W_REG(®s
->tsf_cfprep
, (bcnint_us
<< CFPREP_CBI_SHIFT
));
2318 W_REG(®s
->tsf_cfpstart
, bcnint_us
);
2319 W_REG(®s
->macintstatus
, MI_GP1
);
2321 /* write interrupt mask */
2322 W_REG(®s
->intctrlregs
[RX_FIFO
].intmask
, DEF_RXINTMASK
);
2324 /* allow the MAC to control the PHY clock (dynamic on/off) */
2325 wlc_bmac_macphyclk_set(wlc_hw
, ON
);
2327 /* program dynamic clock control fast powerup delay register */
2328 wlc
->fastpwrup_dly
= ai_clkctl_fast_pwrup_delay(wlc_hw
->sih
);
2329 W_REG(®s
->scc_fastpwrup_dly
, wlc
->fastpwrup_dly
);
2331 /* tell the ucode the corerev */
2332 wlc_bmac_write_shm(wlc_hw
, M_MACHW_VER
, (u16
) wlc_hw
->corerev
);
2334 /* tell the ucode MAC capabilities */
2335 wlc_bmac_write_shm(wlc_hw
, M_MACHW_CAP_L
,
2336 (u16
) (wlc_hw
->machwcap
& 0xffff));
2337 wlc_bmac_write_shm(wlc_hw
, M_MACHW_CAP_H
,
2339 machwcap
>> 16) & 0xffff));
2341 /* write retry limits to SCR, this done after PSM init */
2342 W_REG(®s
->objaddr
, OBJADDR_SCR_SEL
| S_DOT11_SRC_LMT
);
2343 (void)R_REG(®s
->objaddr
);
2344 W_REG(®s
->objdata
, wlc_hw
->SRL
);
2345 W_REG(®s
->objaddr
, OBJADDR_SCR_SEL
| S_DOT11_LRC_LMT
);
2346 (void)R_REG(®s
->objaddr
);
2347 W_REG(®s
->objdata
, wlc_hw
->LRL
);
2349 /* write rate fallback retry limits */
2350 wlc_bmac_write_shm(wlc_hw
, M_SFRMTXCNTFBRTHSD
, wlc_hw
->SFBL
);
2351 wlc_bmac_write_shm(wlc_hw
, M_LFRMTXCNTFBRTHSD
, wlc_hw
->LFBL
);
2353 AND_REG(®s
->ifs_ctl
, 0x0FFF);
2354 W_REG(®s
->ifs_aifsn
, EDCF_AIFSN_MIN
);
2356 /* dma initializations */
2357 wlc
->txpend16165war
= 0;
2359 /* init the tx dma engines */
2360 for (i
= 0; i
< NFIFO
; i
++) {
2362 dma_txinit(wlc_hw
->di
[i
]);
2365 /* init the rx dma engine(s) and post receive buffers */
2366 dma_rxinit(wlc_hw
->di
[RX_FIFO
]);
2367 dma_rxfill(wlc_hw
->di
[RX_FIFO
]);
2370 /* This function is used for changing the tsf frac register
2371 * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz
2372 * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz
2373 * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz
2374 * HTPHY Formula is 2^26/freq(MHz) e.g.
2375 * For spuron2 - 126MHz -> 2^26/126 = 532610.0
2376 * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082
2377 * For spuron: 123MHz -> 2^26/123 = 545600.5
2378 * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341
2379 * For spur off: 120MHz -> 2^26/120 = 559240.5
2380 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
2383 void wlc_bmac_switch_macfreq(struct wlc_hw_info
*wlc_hw
, u8 spurmode
)
2386 regs
= wlc_hw
->regs
;
2388 if ((wlc_hw
->sih
->chip
== BCM43224_CHIP_ID
) ||
2389 (wlc_hw
->sih
->chip
== BCM43225_CHIP_ID
)) {
2390 if (spurmode
== WL_SPURAVOID_ON2
) { /* 126Mhz */
2391 W_REG(®s
->tsf_clk_frac_l
, 0x2082);
2392 W_REG(®s
->tsf_clk_frac_h
, 0x8);
2393 } else if (spurmode
== WL_SPURAVOID_ON1
) { /* 123Mhz */
2394 W_REG(®s
->tsf_clk_frac_l
, 0x5341);
2395 W_REG(®s
->tsf_clk_frac_h
, 0x8);
2396 } else { /* 120Mhz */
2397 W_REG(®s
->tsf_clk_frac_l
, 0x8889);
2398 W_REG(®s
->tsf_clk_frac_h
, 0x8);
2400 } else if (WLCISLCNPHY(wlc_hw
->band
)) {
2401 if (spurmode
== WL_SPURAVOID_ON1
) { /* 82Mhz */
2402 W_REG(®s
->tsf_clk_frac_l
, 0x7CE0);
2403 W_REG(®s
->tsf_clk_frac_h
, 0xC);
2404 } else { /* 80Mhz */
2405 W_REG(®s
->tsf_clk_frac_l
, 0xCCCD);
2406 W_REG(®s
->tsf_clk_frac_h
, 0xC);
2411 /* Initialize GPIOs that are controlled by D11 core */
2412 static void wlc_gpio_init(struct wlc_info
*wlc
)
2414 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
2418 regs
= wlc_hw
->regs
;
2420 /* use GPIO select 0 to get all gpio signals from the gpio out reg */
2421 wlc_bmac_mctrl(wlc_hw
, MCTL_GPOUT_SEL_MASK
, 0);
2424 * Common GPIO setup:
2425 * G0 = LED 0 = WLAN Activity
2426 * G1 = LED 1 = WLAN 2.4 GHz Radio State
2427 * G2 = LED 2 = WLAN 5 GHz Radio State
2428 * G4 = radio disable input (HI enabled, LO disabled)
2433 /* Allocate GPIOs for mimo antenna diversity feature */
2434 if (wlc_hw
->antsel_type
== ANTSEL_2x3
) {
2435 /* Enable antenna diversity, use 2x3 mode */
2436 wlc_bmac_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_EN
,
2437 MHF3_ANTSEL_EN
, WLC_BAND_ALL
);
2438 wlc_bmac_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_MODE
,
2439 MHF3_ANTSEL_MODE
, WLC_BAND_ALL
);
2441 /* init superswitch control */
2442 wlc_phy_antsel_init(wlc_hw
->band
->pi
, false);
2444 } else if (wlc_hw
->antsel_type
== ANTSEL_2x4
) {
2445 gm
|= gc
|= (BOARD_GPIO_12
| BOARD_GPIO_13
);
2447 * The board itself is powered by these GPIOs
2448 * (when not sending pattern) so set them high
2450 OR_REG(®s
->psm_gpio_oe
,
2451 (BOARD_GPIO_12
| BOARD_GPIO_13
));
2452 OR_REG(®s
->psm_gpio_out
,
2453 (BOARD_GPIO_12
| BOARD_GPIO_13
));
2455 /* Enable antenna diversity, use 2x4 mode */
2456 wlc_bmac_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_EN
,
2457 MHF3_ANTSEL_EN
, WLC_BAND_ALL
);
2458 wlc_bmac_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_MODE
, 0,
2461 /* Configure the desired clock to be 4Mhz */
2462 wlc_bmac_write_shm(wlc_hw
, M_ANTSEL_CLKDIV
,
2463 ANTSEL_CLKDIV_4MHZ
);
2466 /* gpio 9 controls the PA. ucode is responsible for wiggling out and oe */
2467 if (wlc_hw
->boardflags
& BFL_PACTRL
)
2468 gm
|= gc
|= BOARD_GPIO_PACTRL
;
2470 /* apply to gpiocontrol register */
2471 ai_gpiocontrol(wlc_hw
->sih
, gm
, gc
, GPIO_DRV_PRIORITY
);
2474 static void wlc_ucode_download(struct wlc_hw_info
*wlc_hw
)
2476 struct wlc_info
*wlc
;
2479 if (wlc_hw
->ucode_loaded
)
2482 if (D11REV_IS(wlc_hw
->corerev
, 23)) {
2483 if (WLCISNPHY(wlc_hw
->band
)) {
2484 wlc_ucode_write(wlc_hw
, bcm43xx_16_mimo
,
2486 wlc_hw
->ucode_loaded
= true;
2488 wiphy_err(wlc
->wiphy
, "%s: wl%d: unsupported phy in "
2490 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
2491 } else if (D11REV_IS(wlc_hw
->corerev
, 24)) {
2492 if (WLCISLCNPHY(wlc_hw
->band
)) {
2493 wlc_ucode_write(wlc_hw
, bcm43xx_24_lcn
,
2495 wlc_hw
->ucode_loaded
= true;
2497 wiphy_err(wlc
->wiphy
, "%s: wl%d: unsupported phy in "
2499 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
2504 static void wlc_ucode_write(struct wlc_hw_info
*wlc_hw
, const u32 ucode
[],
2505 const uint nbytes
) {
2506 d11regs_t
*regs
= wlc_hw
->regs
;
2510 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
2512 count
= (nbytes
/ sizeof(u32
));
2514 W_REG(®s
->objaddr
, (OBJADDR_AUTO_INC
| OBJADDR_UCM_SEL
));
2515 (void)R_REG(®s
->objaddr
);
2516 for (i
= 0; i
< count
; i
++)
2517 W_REG(®s
->objdata
, ucode
[i
]);
2520 static void wlc_write_inits(struct wlc_hw_info
*wlc_hw
,
2521 const struct d11init
*inits
)
2526 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
2528 base
= (volatile u8
*)wlc_hw
->regs
;
2530 for (i
= 0; inits
[i
].addr
!= 0xffff; i
++) {
2531 if (inits
[i
].size
== 2)
2532 W_REG((u16
*)(base
+ inits
[i
].addr
),
2534 else if (inits
[i
].size
== 4)
2535 W_REG((u32
*)(base
+ inits
[i
].addr
),
2540 static void wlc_ucode_txant_set(struct wlc_hw_info
*wlc_hw
)
2543 u16 phytxant
= wlc_hw
->bmac_phytxant
;
2544 u16 mask
= PHY_TXC_ANT_MASK
;
2546 /* set the Probe Response frame phy control word */
2547 phyctl
= wlc_bmac_read_shm(wlc_hw
, M_CTXPRS_BLK
+ C_CTX_PCTLWD_POS
);
2548 phyctl
= (phyctl
& ~mask
) | phytxant
;
2549 wlc_bmac_write_shm(wlc_hw
, M_CTXPRS_BLK
+ C_CTX_PCTLWD_POS
, phyctl
);
2551 /* set the Response (ACK/CTS) frame phy control word */
2552 phyctl
= wlc_bmac_read_shm(wlc_hw
, M_RSP_PCTLWD
);
2553 phyctl
= (phyctl
& ~mask
) | phytxant
;
2554 wlc_bmac_write_shm(wlc_hw
, M_RSP_PCTLWD
, phyctl
);
2557 void wlc_bmac_txant_set(struct wlc_hw_info
*wlc_hw
, u16 phytxant
)
2559 /* update sw state */
2560 wlc_hw
->bmac_phytxant
= phytxant
;
2562 /* push to ucode if up */
2565 wlc_ucode_txant_set(wlc_hw
);
2569 u16
wlc_bmac_get_txant(struct wlc_hw_info
*wlc_hw
)
2571 return (u16
) wlc_hw
->wlc
->stf
->txant
;
2574 void wlc_bmac_antsel_type_set(struct wlc_hw_info
*wlc_hw
, u8 antsel_type
)
2576 wlc_hw
->antsel_type
= antsel_type
;
2578 /* Update the antsel type for phy module to use */
2579 wlc_phy_antsel_type_set(wlc_hw
->band
->pi
, antsel_type
);
2582 void wlc_bmac_fifoerrors(struct wlc_hw_info
*wlc_hw
)
2586 uint intstatus
, idx
;
2587 d11regs_t
*regs
= wlc_hw
->regs
;
2588 struct wiphy
*wiphy
= wlc_hw
->wlc
->wiphy
;
2590 unit
= wlc_hw
->unit
;
2592 for (idx
= 0; idx
< NFIFO
; idx
++) {
2593 /* read intstatus register and ignore any non-error bits */
2595 R_REG(®s
->intctrlregs
[idx
].intstatus
) & I_ERRORS
;
2599 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d: intstatus%d 0x%x\n",
2600 unit
, idx
, intstatus
);
2602 if (intstatus
& I_RO
) {
2603 wiphy_err(wiphy
, "wl%d: fifo %d: receive fifo "
2604 "overflow\n", unit
, idx
);
2608 if (intstatus
& I_PC
) {
2609 wiphy_err(wiphy
, "wl%d: fifo %d: descriptor error\n",
2614 if (intstatus
& I_PD
) {
2615 wiphy_err(wiphy
, "wl%d: fifo %d: data error\n", unit
,
2620 if (intstatus
& I_DE
) {
2621 wiphy_err(wiphy
, "wl%d: fifo %d: descriptor protocol "
2622 "error\n", unit
, idx
);
2626 if (intstatus
& I_RU
) {
2627 wiphy_err(wiphy
, "wl%d: fifo %d: receive descriptor "
2628 "underflow\n", idx
, unit
);
2631 if (intstatus
& I_XU
) {
2632 wiphy_err(wiphy
, "wl%d: fifo %d: transmit fifo "
2633 "underflow\n", idx
, unit
);
2638 wlc_fatal_error(wlc_hw
->wlc
); /* big hammer */
2641 W_REG(®s
->intctrlregs
[idx
].intstatus
,
2646 void wlc_intrson(struct wlc_info
*wlc
)
2648 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
2649 wlc
->macintmask
= wlc
->defmacintmask
;
2650 W_REG(&wlc_hw
->regs
->macintmask
, wlc
->macintmask
);
2653 /* callback for siutils.c, which has only wlc handler, no wl
2654 * they both check up, not only because there is no need to off/restore d11 interrupt
2655 * but also because per-port code may require sync with valid interrupt.
2658 static u32
wlc_wlintrsoff(struct wlc_info
*wlc
)
2663 return brcms_intrsoff(wlc
->wl
);
2666 static void wlc_wlintrsrestore(struct wlc_info
*wlc
, u32 macintmask
)
2671 brcms_intrsrestore(wlc
->wl
, macintmask
);
2674 u32
wlc_intrsoff(struct wlc_info
*wlc
)
2676 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
2682 macintmask
= wlc
->macintmask
; /* isr can still happen */
2684 W_REG(&wlc_hw
->regs
->macintmask
, 0);
2685 (void)R_REG(&wlc_hw
->regs
->macintmask
); /* sync readback */
2686 udelay(1); /* ensure int line is no longer driven */
2687 wlc
->macintmask
= 0;
2689 /* return previous macintmask; resolve race between us and our isr */
2690 return wlc
->macintstatus
? 0 : macintmask
;
2693 void wlc_intrsrestore(struct wlc_info
*wlc
, u32 macintmask
)
2695 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
2699 wlc
->macintmask
= macintmask
;
2700 W_REG(&wlc_hw
->regs
->macintmask
, wlc
->macintmask
);
2703 static void wlc_bmac_mute(struct wlc_hw_info
*wlc_hw
, bool on
, mbool flags
)
2705 u8 null_ether_addr
[ETH_ALEN
] = {0, 0, 0, 0, 0, 0};
2708 /* suspend tx fifos */
2709 wlc_bmac_tx_fifo_suspend(wlc_hw
, TX_DATA_FIFO
);
2710 wlc_bmac_tx_fifo_suspend(wlc_hw
, TX_CTL_FIFO
);
2711 wlc_bmac_tx_fifo_suspend(wlc_hw
, TX_AC_BK_FIFO
);
2712 wlc_bmac_tx_fifo_suspend(wlc_hw
, TX_AC_VI_FIFO
);
2714 /* zero the address match register so we do not send ACKs */
2715 wlc_bmac_set_addrmatch(wlc_hw
, RCM_MAC_OFFSET
,
2718 /* resume tx fifos */
2719 if (!wlc_hw
->wlc
->tx_suspended
) {
2720 wlc_bmac_tx_fifo_resume(wlc_hw
, TX_DATA_FIFO
);
2722 wlc_bmac_tx_fifo_resume(wlc_hw
, TX_CTL_FIFO
);
2723 wlc_bmac_tx_fifo_resume(wlc_hw
, TX_AC_BK_FIFO
);
2724 wlc_bmac_tx_fifo_resume(wlc_hw
, TX_AC_VI_FIFO
);
2726 /* Restore address */
2727 wlc_bmac_set_addrmatch(wlc_hw
, RCM_MAC_OFFSET
,
2731 wlc_phy_mute_upd(wlc_hw
->band
->pi
, on
, flags
);
2734 wlc_ucode_mute_override_set(wlc_hw
);
2736 wlc_ucode_mute_override_clear(wlc_hw
);
2739 int wlc_bmac_xmtfifo_sz_get(struct wlc_hw_info
*wlc_hw
, uint fifo
, uint
*blocks
)
2744 *blocks
= wlc_hw
->xmtfifo_sz
[fifo
];
2749 /* wlc_bmac_tx_fifo_suspended:
2750 * Check the MAC's tx suspend status for a tx fifo.
2752 * When the MAC acknowledges a tx suspend, it indicates that no more
2753 * packets will be transmitted out the radio. This is independent of
2754 * DMA channel suspension---the DMA may have finished suspending, or may still
2755 * be pulling data into a tx fifo, by the time the MAC acks the suspend
2758 static bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info
*wlc_hw
, uint tx_fifo
)
2760 /* check that a suspend has been requested and is no longer pending */
2763 * for DMA mode, the suspend request is set in xmtcontrol of the DMA engine,
2764 * and the tx fifo suspend at the lower end of the MAC is acknowledged in the
2765 * chnstatus register.
2766 * The tx fifo suspend completion is independent of the DMA suspend completion and
2767 * may be acked before or after the DMA is suspended.
2769 if (dma_txsuspended(wlc_hw
->di
[tx_fifo
]) &&
2770 (R_REG(&wlc_hw
->regs
->chnstatus
) &
2771 (1 << tx_fifo
)) == 0)
2777 static void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info
*wlc_hw
, uint tx_fifo
)
2779 u8 fifo
= 1 << tx_fifo
;
2781 /* Two clients of this code, 11h Quiet period and scanning. */
2783 /* only suspend if not already suspended */
2784 if ((wlc_hw
->suspended_fifos
& fifo
) == fifo
)
2787 /* force the core awake only if not already */
2788 if (wlc_hw
->suspended_fifos
== 0)
2789 wlc_ucode_wake_override_set(wlc_hw
, WLC_WAKE_OVERRIDE_TXFIFO
);
2791 wlc_hw
->suspended_fifos
|= fifo
;
2793 if (wlc_hw
->di
[tx_fifo
]) {
2794 /* Suspending AMPDU transmissions in the middle can cause underflow
2795 * which may result in mismatch between ucode and driver
2796 * so suspend the mac before suspending the FIFO
2798 if (WLC_PHY_11N_CAP(wlc_hw
->band
))
2799 wlc_suspend_mac_and_wait(wlc_hw
->wlc
);
2801 dma_txsuspend(wlc_hw
->di
[tx_fifo
]);
2803 if (WLC_PHY_11N_CAP(wlc_hw
->band
))
2804 wlc_enable_mac(wlc_hw
->wlc
);
2808 static void wlc_bmac_tx_fifo_resume(struct wlc_hw_info
*wlc_hw
, uint tx_fifo
)
2810 /* BMAC_NOTE: WLC_TX_FIFO_ENAB is done in wlc_dpc() for DMA case but need to be done
2811 * here for PIO otherwise the watchdog will catch the inconsistency and fire
2813 /* Two clients of this code, 11h Quiet period and scanning. */
2814 if (wlc_hw
->di
[tx_fifo
])
2815 dma_txresume(wlc_hw
->di
[tx_fifo
]);
2817 /* allow core to sleep again */
2818 if (wlc_hw
->suspended_fifos
== 0)
2821 wlc_hw
->suspended_fifos
&= ~(1 << tx_fifo
);
2822 if (wlc_hw
->suspended_fifos
== 0)
2823 wlc_ucode_wake_override_clear(wlc_hw
,
2824 WLC_WAKE_OVERRIDE_TXFIFO
);
2829 * Read and clear macintmask and macintstatus and intstatus registers.
2830 * This routine should be called with interrupts off
2832 * -1 if DEVICEREMOVED(wlc) evaluates to true;
2833 * 0 if the interrupt is not for us, or we are in some special cases;
2834 * device interrupt status bits otherwise.
2836 static inline u32
wlc_intstatus(struct wlc_info
*wlc
, bool in_isr
)
2838 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
2839 d11regs_t
*regs
= wlc_hw
->regs
;
2842 /* macintstatus includes a DMA interrupt summary bit */
2843 macintstatus
= R_REG(®s
->macintstatus
);
2845 BCMMSG(wlc
->wiphy
, "wl%d: macintstatus: 0x%x\n", wlc_hw
->unit
,
2848 /* detect cardbus removed, in power down(suspend) and in reset */
2849 if (DEVICEREMOVED(wlc
))
2852 /* DEVICEREMOVED succeeds even when the core is still resetting,
2853 * handle that case here.
2855 if (macintstatus
== 0xffffffff)
2858 /* defer unsolicited interrupts */
2859 macintstatus
&= (in_isr
? wlc
->macintmask
: wlc
->defmacintmask
);
2862 if (macintstatus
== 0)
2865 /* interrupts are already turned off for CFE build
2866 * Caution: For CFE Turning off the interrupts again has some undesired
2869 /* turn off the interrupts */
2870 W_REG(®s
->macintmask
, 0);
2871 (void)R_REG(®s
->macintmask
); /* sync readback */
2872 wlc
->macintmask
= 0;
2874 /* clear device interrupts */
2875 W_REG(®s
->macintstatus
, macintstatus
);
2877 /* MI_DMAINT is indication of non-zero intstatus */
2878 if (macintstatus
& MI_DMAINT
) {
2880 * only fifo interrupt enabled is I_RI in
2881 * RX_FIFO. If MI_DMAINT is set, assume it
2882 * is set and clear the interrupt.
2884 W_REG(®s
->intctrlregs
[RX_FIFO
].intstatus
,
2888 return macintstatus
;
2891 /* Update wlc->macintstatus and wlc->intstatus[]. */
2892 /* Return true if they are updated successfully. false otherwise */
2893 bool wlc_intrsupd(struct wlc_info
*wlc
)
2897 /* read and clear macintstatus and intstatus registers */
2898 macintstatus
= wlc_intstatus(wlc
, false);
2900 /* device is removed */
2901 if (macintstatus
== 0xffffffff)
2904 /* update interrupt status in software */
2905 wlc
->macintstatus
|= macintstatus
;
2911 * First-level interrupt processing.
2912 * Return true if this was our interrupt, false otherwise.
2913 * *wantdpc will be set to true if further wlc_dpc() processing is required,
2916 bool wlc_isr(struct wlc_info
*wlc
, bool *wantdpc
)
2918 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
2923 if (!wlc_hw
->up
|| !wlc
->macintmask
)
2926 /* read and clear macintstatus and intstatus registers */
2927 macintstatus
= wlc_intstatus(wlc
, true);
2929 if (macintstatus
== 0xffffffff)
2930 wiphy_err(wlc
->wiphy
, "DEVICEREMOVED detected in the ISR code"
2933 /* it is not for us */
2934 if (macintstatus
== 0)
2939 /* save interrupt status bits */
2940 wlc
->macintstatus
= macintstatus
;
2947 wlc_bmac_dotxstatus(struct wlc_hw_info
*wlc_hw
, tx_status_t
*txs
, u32 s2
)
2949 /* discard intermediate indications for ucode with one legitimate case:
2950 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
2951 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
2952 * transmission count)
2954 if (!(txs
->status
& TX_STATUS_AMPDU
)
2955 && (txs
->status
& TX_STATUS_INTERMEDIATE
)) {
2959 return wlc_dotxstatus(wlc_hw
->wlc
, txs
, s2
);
2962 /* process tx completion events in BMAC
2963 * Return true if more tx status need to be processed. false otherwise.
2966 wlc_bmac_txstatus(struct wlc_hw_info
*wlc_hw
, bool bound
, bool *fatal
)
2968 bool morepending
= false;
2969 struct wlc_info
*wlc
= wlc_hw
->wlc
;
2971 tx_status_t txstatus
, *txs
;
2975 * Param 'max_tx_num' indicates max. # tx status to process before
2978 uint max_tx_num
= bound
? wlc
->pub
->tunables
->txsbnd
: -1;
2980 BCMMSG(wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
2983 regs
= wlc_hw
->regs
;
2985 && (s1
= R_REG(®s
->frmtxstatus
)) & TXS_V
) {
2987 if (s1
== 0xffffffff) {
2988 wiphy_err(wlc
->wiphy
, "wl%d: %s: dead chip\n",
2989 wlc_hw
->unit
, __func__
);
2993 s2
= R_REG(®s
->frmtxstatus2
);
2995 txs
->status
= s1
& TXS_STATUS_MASK
;
2996 txs
->frameid
= (s1
& TXS_FID_MASK
) >> TXS_FID_SHIFT
;
2997 txs
->sequence
= s2
& TXS_SEQ_MASK
;
2998 txs
->phyerr
= (s2
& TXS_PTX_MASK
) >> TXS_PTX_SHIFT
;
2999 txs
->lasttxtime
= 0;
3001 *fatal
= wlc_bmac_dotxstatus(wlc_hw
, txs
, s2
);
3003 /* !give others some time to run! */
3004 if (++n
>= max_tx_num
)
3011 if (n
>= max_tx_num
)
3014 if (!pktq_empty(&wlc
->pkt_queue
->q
))
3020 void wlc_suspend_mac_and_wait(struct wlc_info
*wlc
)
3022 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
3023 d11regs_t
*regs
= wlc_hw
->regs
;
3025 struct wiphy
*wiphy
= wlc
->wiphy
;
3027 BCMMSG(wlc
->wiphy
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
3028 wlc_hw
->band
->bandunit
);
3031 * Track overlapping suspend requests
3033 wlc_hw
->mac_suspend_depth
++;
3034 if (wlc_hw
->mac_suspend_depth
> 1)
3037 /* force the core awake */
3038 wlc_ucode_wake_override_set(wlc_hw
, WLC_WAKE_OVERRIDE_MACSUSPEND
);
3040 mc
= R_REG(®s
->maccontrol
);
3042 if (mc
== 0xffffffff) {
3043 wiphy_err(wiphy
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
3045 brcms_down(wlc
->wl
);
3048 WARN_ON(mc
& MCTL_PSM_JMP_0
);
3049 WARN_ON(!(mc
& MCTL_PSM_RUN
));
3050 WARN_ON(!(mc
& MCTL_EN_MAC
));
3052 mi
= R_REG(®s
->macintstatus
);
3053 if (mi
== 0xffffffff) {
3054 wiphy_err(wiphy
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
3056 brcms_down(wlc
->wl
);
3059 WARN_ON(mi
& MI_MACSSPNDD
);
3061 wlc_bmac_mctrl(wlc_hw
, MCTL_EN_MAC
, 0);
3063 SPINWAIT(!(R_REG(®s
->macintstatus
) & MI_MACSSPNDD
),
3064 WLC_MAX_MAC_SUSPEND
);
3066 if (!(R_REG(®s
->macintstatus
) & MI_MACSSPNDD
)) {
3067 wiphy_err(wiphy
, "wl%d: wlc_suspend_mac_and_wait: waited %d uS"
3068 " and MI_MACSSPNDD is still not on.\n",
3069 wlc_hw
->unit
, WLC_MAX_MAC_SUSPEND
);
3070 wiphy_err(wiphy
, "wl%d: psmdebug 0x%08x, phydebug 0x%08x, "
3071 "psm_brc 0x%04x\n", wlc_hw
->unit
,
3072 R_REG(®s
->psmdebug
),
3073 R_REG(®s
->phydebug
),
3074 R_REG(®s
->psm_brc
));
3077 mc
= R_REG(®s
->maccontrol
);
3078 if (mc
== 0xffffffff) {
3079 wiphy_err(wiphy
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
3081 brcms_down(wlc
->wl
);
3084 WARN_ON(mc
& MCTL_PSM_JMP_0
);
3085 WARN_ON(!(mc
& MCTL_PSM_RUN
));
3086 WARN_ON(mc
& MCTL_EN_MAC
);
3089 void wlc_enable_mac(struct wlc_info
*wlc
)
3091 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
3092 d11regs_t
*regs
= wlc_hw
->regs
;
3095 BCMMSG(wlc
->wiphy
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
3096 wlc
->band
->bandunit
);
3099 * Track overlapping suspend requests
3101 wlc_hw
->mac_suspend_depth
--;
3102 if (wlc_hw
->mac_suspend_depth
> 0)
3105 mc
= R_REG(®s
->maccontrol
);
3106 WARN_ON(mc
& MCTL_PSM_JMP_0
);
3107 WARN_ON(mc
& MCTL_EN_MAC
);
3108 WARN_ON(!(mc
& MCTL_PSM_RUN
));
3110 wlc_bmac_mctrl(wlc_hw
, MCTL_EN_MAC
, MCTL_EN_MAC
);
3111 W_REG(®s
->macintstatus
, MI_MACSSPNDD
);
3113 mc
= R_REG(®s
->maccontrol
);
3114 WARN_ON(mc
& MCTL_PSM_JMP_0
);
3115 WARN_ON(!(mc
& MCTL_EN_MAC
));
3116 WARN_ON(!(mc
& MCTL_PSM_RUN
));
3118 mi
= R_REG(®s
->macintstatus
);
3119 WARN_ON(mi
& MI_MACSSPNDD
);
3121 wlc_ucode_wake_override_clear(wlc_hw
, WLC_WAKE_OVERRIDE_MACSUSPEND
);
3124 static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info
*wlc_hw
)
3128 WLC_RATE_6M
, WLC_RATE_9M
, WLC_RATE_12M
, WLC_RATE_18M
,
3129 WLC_RATE_24M
, WLC_RATE_36M
, WLC_RATE_48M
, WLC_RATE_54M
3135 if (!WLC_PHY_11N_CAP(wlc_hw
->band
))
3138 /* walk the phy rate table and update the entries */
3139 for (i
= 0; i
< ARRAY_SIZE(rates
); i
++) {
3142 entry_ptr
= wlc_bmac_ofdm_ratetable_offset(wlc_hw
, rate
);
3144 /* read the SHM Rate Table entry OFDM PCTL1 values */
3146 wlc_bmac_read_shm(wlc_hw
, entry_ptr
+ M_RT_OFDM_PCTL1_POS
);
3148 /* modify the value */
3149 pctl1
&= ~PHY_TXC1_MODE_MASK
;
3150 pctl1
|= (wlc_hw
->hw_stf_ss_opmode
<< PHY_TXC1_MODE_SHIFT
);
3152 /* Update the SHM Rate Table entry OFDM PCTL1 values */
3153 wlc_bmac_write_shm(wlc_hw
, entry_ptr
+ M_RT_OFDM_PCTL1_POS
,
3158 static u16
wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info
*wlc_hw
, u8 rate
)
3162 struct plcp_signal_rate_lookup
{
3166 /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */
3167 const struct plcp_signal_rate_lookup rate_lookup
[] = {
3170 {WLC_RATE_12M
, 0xA},
3171 {WLC_RATE_18M
, 0xE},
3172 {WLC_RATE_24M
, 0x9},
3173 {WLC_RATE_36M
, 0xD},
3174 {WLC_RATE_48M
, 0x8},
3178 for (i
= 0; i
< ARRAY_SIZE(rate_lookup
); i
++) {
3179 if (rate
== rate_lookup
[i
].rate
) {
3180 plcp_rate
= rate_lookup
[i
].signal_rate
;
3185 /* Find the SHM pointer to the rate table entry by looking in the
3188 return 2 * wlc_bmac_read_shm(wlc_hw
, M_RT_DIRMAP_A
+ (plcp_rate
* 2));
3191 void wlc_bmac_band_stf_ss_set(struct wlc_hw_info
*wlc_hw
, u8 stf_mode
)
3193 wlc_hw
->hw_stf_ss_opmode
= stf_mode
;
3196 wlc_upd_ofdm_pctl1_table(wlc_hw
);
3200 wlc_bmac_read_tsf(struct wlc_hw_info
*wlc_hw
, u32
*tsf_l_ptr
,
3203 d11regs_t
*regs
= wlc_hw
->regs
;
3205 /* read the tsf timer low, then high to get an atomic read */
3206 *tsf_l_ptr
= R_REG(®s
->tsf_timerlow
);
3207 *tsf_h_ptr
= R_REG(®s
->tsf_timerhigh
);
3212 static bool wlc_bmac_validate_chip_access(struct wlc_hw_info
*wlc_hw
)
3216 struct wiphy
*wiphy
= wlc_hw
->wlc
->wiphy
;
3218 BCMMSG(wiphy
, "wl%d\n", wlc_hw
->unit
);
3220 regs
= wlc_hw
->regs
;
3222 /* Validate dchip register access */
3224 W_REG(®s
->objaddr
, OBJADDR_SHM_SEL
| 0);
3225 (void)R_REG(®s
->objaddr
);
3226 w
= R_REG(®s
->objdata
);
3228 /* Can we write and read back a 32bit register? */
3229 W_REG(®s
->objaddr
, OBJADDR_SHM_SEL
| 0);
3230 (void)R_REG(®s
->objaddr
);
3231 W_REG(®s
->objdata
, (u32
) 0xaa5555aa);
3233 W_REG(®s
->objaddr
, OBJADDR_SHM_SEL
| 0);
3234 (void)R_REG(®s
->objaddr
);
3235 val
= R_REG(®s
->objdata
);
3236 if (val
!= (u32
) 0xaa5555aa) {
3237 wiphy_err(wiphy
, "wl%d: validate_chip_access: SHM = 0x%x, "
3238 "expected 0xaa5555aa\n", wlc_hw
->unit
, val
);
3242 W_REG(®s
->objaddr
, OBJADDR_SHM_SEL
| 0);
3243 (void)R_REG(®s
->objaddr
);
3244 W_REG(®s
->objdata
, (u32
) 0x55aaaa55);
3246 W_REG(®s
->objaddr
, OBJADDR_SHM_SEL
| 0);
3247 (void)R_REG(®s
->objaddr
);
3248 val
= R_REG(®s
->objdata
);
3249 if (val
!= (u32
) 0x55aaaa55) {
3250 wiphy_err(wiphy
, "wl%d: validate_chip_access: SHM = 0x%x, "
3251 "expected 0x55aaaa55\n", wlc_hw
->unit
, val
);
3255 W_REG(®s
->objaddr
, OBJADDR_SHM_SEL
| 0);
3256 (void)R_REG(®s
->objaddr
);
3257 W_REG(®s
->objdata
, w
);
3259 /* clear CFPStart */
3260 W_REG(®s
->tsf_cfpstart
, 0);
3262 w
= R_REG(®s
->maccontrol
);
3263 if ((w
!= (MCTL_IHR_EN
| MCTL_WAKE
)) &&
3264 (w
!= (MCTL_IHR_EN
| MCTL_GMODE
| MCTL_WAKE
))) {
3265 wiphy_err(wiphy
, "wl%d: validate_chip_access: maccontrol = "
3266 "0x%x, expected 0x%x or 0x%x\n", wlc_hw
->unit
, w
,
3267 (MCTL_IHR_EN
| MCTL_WAKE
),
3268 (MCTL_IHR_EN
| MCTL_GMODE
| MCTL_WAKE
));
3275 #define PHYPLL_WAIT_US 100000
3277 void wlc_bmac_core_phypll_ctl(struct wlc_hw_info
*wlc_hw
, bool on
)
3282 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
3285 regs
= wlc_hw
->regs
;
3288 if ((wlc_hw
->sih
->chip
== BCM4313_CHIP_ID
)) {
3289 OR_REG(®s
->clk_ctl_st
,
3290 (CCS_ERSRC_REQ_HT
| CCS_ERSRC_REQ_D11PLL
|
3291 CCS_ERSRC_REQ_PHYPLL
));
3292 SPINWAIT((R_REG(®s
->clk_ctl_st
) &
3293 (CCS_ERSRC_AVAIL_HT
)) != (CCS_ERSRC_AVAIL_HT
),
3296 tmp
= R_REG(®s
->clk_ctl_st
);
3297 if ((tmp
& (CCS_ERSRC_AVAIL_HT
)) !=
3298 (CCS_ERSRC_AVAIL_HT
)) {
3299 wiphy_err(wlc_hw
->wlc
->wiphy
, "%s: turn on PHY"
3300 " PLL failed\n", __func__
);
3303 OR_REG(®s
->clk_ctl_st
,
3304 (CCS_ERSRC_REQ_D11PLL
| CCS_ERSRC_REQ_PHYPLL
));
3305 SPINWAIT((R_REG(®s
->clk_ctl_st
) &
3306 (CCS_ERSRC_AVAIL_D11PLL
|
3307 CCS_ERSRC_AVAIL_PHYPLL
)) !=
3308 (CCS_ERSRC_AVAIL_D11PLL
|
3309 CCS_ERSRC_AVAIL_PHYPLL
), PHYPLL_WAIT_US
);
3311 tmp
= R_REG(®s
->clk_ctl_st
);
3313 (CCS_ERSRC_AVAIL_D11PLL
| CCS_ERSRC_AVAIL_PHYPLL
))
3315 (CCS_ERSRC_AVAIL_D11PLL
| CCS_ERSRC_AVAIL_PHYPLL
)) {
3316 wiphy_err(wlc_hw
->wlc
->wiphy
, "%s: turn on "
3317 "PHY PLL failed\n", __func__
);
3321 /* Since the PLL may be shared, other cores can still be requesting it;
3322 * so we'll deassert the request but not wait for status to comply.
3324 AND_REG(®s
->clk_ctl_st
, ~CCS_ERSRC_REQ_PHYPLL
);
3325 tmp
= R_REG(®s
->clk_ctl_st
);
3329 void wlc_coredisable(struct wlc_hw_info
*wlc_hw
)
3333 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d\n", wlc_hw
->unit
);
3335 dev_gone
= DEVICEREMOVED(wlc_hw
->wlc
);
3340 if (wlc_hw
->noreset
)
3344 wlc_phy_switch_radio(wlc_hw
->band
->pi
, OFF
);
3346 /* turn off analog core */
3347 wlc_phy_anacore(wlc_hw
->band
->pi
, OFF
);
3349 /* turn off PHYPLL to save power */
3350 wlc_bmac_core_phypll_ctl(wlc_hw
, false);
3352 /* No need to set wlc->pub->radio_active = OFF
3353 * because this function needs down capability and
3354 * radio_active is designed for BCMNODOWN.
3357 /* remove gpio controls */
3358 if (wlc_hw
->ucode_dbgsel
)
3359 ai_gpiocontrol(wlc_hw
->sih
, ~0, 0, GPIO_DRV_PRIORITY
);
3361 wlc_hw
->clk
= false;
3362 ai_core_disable(wlc_hw
->sih
, 0);
3363 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, false);
3366 /* power both the pll and external oscillator on/off */
3367 static void wlc_bmac_xtal(struct wlc_hw_info
*wlc_hw
, bool want
)
3369 BCMMSG(wlc_hw
->wlc
->wiphy
, "wl%d: want %d\n", wlc_hw
->unit
, want
);
3371 /* dont power down if plldown is false or we must poll hw radio disable */
3372 if (!want
&& wlc_hw
->pllreq
)
3376 ai_clkctl_xtal(wlc_hw
->sih
, XTAL
| PLL
, want
);
3378 wlc_hw
->sbclk
= want
;
3379 if (!wlc_hw
->sbclk
) {
3380 wlc_hw
->clk
= false;
3381 if (wlc_hw
->band
&& wlc_hw
->band
->pi
)
3382 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, false);
3386 static void wlc_flushqueues(struct wlc_info
*wlc
)
3388 struct wlc_hw_info
*wlc_hw
= wlc
->hw
;
3391 wlc
->txpend16165war
= 0;
3393 /* free any posted tx packets */
3394 for (i
= 0; i
< NFIFO
; i
++)
3395 if (wlc_hw
->di
[i
]) {
3396 dma_txreclaim(wlc_hw
->di
[i
], DMA_RANGE_ALL
);
3397 TXPKTPENDCLR(wlc
, i
);
3398 BCMMSG(wlc
->wiphy
, "pktpend fifo %d clrd\n", i
);
3401 /* free any posted rx packets */
3402 dma_rxreclaim(wlc_hw
->di
[RX_FIFO
]);
3405 u16
wlc_bmac_read_shm(struct wlc_hw_info
*wlc_hw
, uint offset
)
3407 return wlc_bmac_read_objmem(wlc_hw
, offset
, OBJADDR_SHM_SEL
);
3410 void wlc_bmac_write_shm(struct wlc_hw_info
*wlc_hw
, uint offset
, u16 v
)
3412 wlc_bmac_write_objmem(wlc_hw
, offset
, v
, OBJADDR_SHM_SEL
);
3416 wlc_bmac_read_objmem(struct wlc_hw_info
*wlc_hw
, uint offset
, u32 sel
)
3418 d11regs_t
*regs
= wlc_hw
->regs
;
3419 volatile u16
*objdata_lo
= (volatile u16
*)®s
->objdata
;
3420 volatile u16
*objdata_hi
= objdata_lo
+ 1;
3423 W_REG(®s
->objaddr
, sel
| (offset
>> 2));
3424 (void)R_REG(®s
->objaddr
);
3426 v
= R_REG(objdata_hi
);
3428 v
= R_REG(objdata_lo
);
3435 wlc_bmac_write_objmem(struct wlc_hw_info
*wlc_hw
, uint offset
, u16 v
, 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;
3441 W_REG(®s
->objaddr
, sel
| (offset
>> 2));
3442 (void)R_REG(®s
->objaddr
);
3444 W_REG(objdata_hi
, v
);
3446 W_REG(objdata_lo
, v
);
3450 /* Copy a buffer to shared memory of specified type .
3451 * SHM 'offset' needs to be an even address and
3452 * Buffer length 'len' must be an even number of bytes
3453 * 'sel' selects the type of memory
3456 wlc_bmac_copyto_objmem(struct wlc_hw_info
*wlc_hw
, uint offset
, const void *buf
,
3460 const u8
*p
= (const u8
*)buf
;
3463 if (len
<= 0 || (offset
& 1) || (len
& 1))
3466 for (i
= 0; i
< len
; i
+= 2) {
3467 v
= p
[i
] | (p
[i
+ 1] << 8);
3468 wlc_bmac_write_objmem(wlc_hw
, offset
+ i
, v
, sel
);
3472 /* Copy a piece of shared memory of specified type to a buffer .
3473 * SHM 'offset' needs to be an even address and
3474 * Buffer length 'len' must be an even number of bytes
3475 * 'sel' selects the type of memory
3478 wlc_bmac_copyfrom_objmem(struct wlc_hw_info
*wlc_hw
, uint offset
, void *buf
,
3485 if (len
<= 0 || (offset
& 1) || (len
& 1))
3488 for (i
= 0; i
< len
; i
+= 2) {
3489 v
= wlc_bmac_read_objmem(wlc_hw
, offset
+ i
, sel
);
3491 p
[i
+ 1] = (v
>> 8) & 0xFF;
3495 void wlc_bmac_copyfrom_vars(struct wlc_hw_info
*wlc_hw
, char **buf
, uint
*len
)
3497 BCMMSG(wlc_hw
->wlc
->wiphy
, "nvram vars totlen=%d\n",
3500 *buf
= wlc_hw
->vars
;
3501 *len
= wlc_hw
->vars_size
;
3504 void wlc_bmac_retrylimit_upd(struct wlc_hw_info
*wlc_hw
, u16 SRL
, u16 LRL
)
3509 /* write retry limit to SCR, shouldn't need to suspend */
3511 W_REG(&wlc_hw
->regs
->objaddr
,
3512 OBJADDR_SCR_SEL
| S_DOT11_SRC_LMT
);
3513 (void)R_REG(&wlc_hw
->regs
->objaddr
);
3514 W_REG(&wlc_hw
->regs
->objdata
, wlc_hw
->SRL
);
3515 W_REG(&wlc_hw
->regs
->objaddr
,
3516 OBJADDR_SCR_SEL
| S_DOT11_LRC_LMT
);
3517 (void)R_REG(&wlc_hw
->regs
->objaddr
);
3518 W_REG(&wlc_hw
->regs
->objdata
, wlc_hw
->LRL
);
3522 void wlc_bmac_pllreq(struct wlc_hw_info
*wlc_hw
, bool set
, mbool req_bit
)
3525 if (mboolisset(wlc_hw
->pllreq
, req_bit
))
3528 mboolset(wlc_hw
->pllreq
, req_bit
);
3530 if (mboolisset(wlc_hw
->pllreq
, WLC_PLLREQ_FLIP
)) {
3531 if (!wlc_hw
->sbclk
) {
3532 wlc_bmac_xtal(wlc_hw
, ON
);
3536 if (!mboolisset(wlc_hw
->pllreq
, req_bit
))
3539 mboolclr(wlc_hw
->pllreq
, req_bit
);
3541 if (mboolisset(wlc_hw
->pllreq
, WLC_PLLREQ_FLIP
)) {
3542 if (wlc_hw
->sbclk
) {
3543 wlc_bmac_xtal(wlc_hw
, OFF
);
3551 u16
wlc_bmac_rate_shm_offset(struct wlc_hw_info
*wlc_hw
, u8 rate
)
3556 /* get the phy specific rate encoding for the PLCP SIGNAL field */
3557 /* XXX4321 fixup needed ? */
3559 table_ptr
= M_RT_DIRMAP_A
;
3561 table_ptr
= M_RT_DIRMAP_B
;
3563 /* for a given rate, the LS-nibble of the PLCP SIGNAL field is
3564 * the index into the rate table.
3566 phy_rate
= rate_info
[rate
] & WLC_RATE_MASK
;
3567 index
= phy_rate
& 0xf;
3569 /* Find the SHM pointer to the rate table entry by looking in the
3572 return 2 * wlc_bmac_read_shm(wlc_hw
, table_ptr
+ (index
* 2));
3575 void wlc_bmac_antsel_set(struct wlc_hw_info
*wlc_hw
, u32 antsel_avail
)
3577 wlc_hw
->antsel_avail
= antsel_avail
;