~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/brcm80211/brcmsmac/wlc_bmac.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2010 Broadcom Corporation
 
3
 *
 
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.
 
7
 *
 
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.
 
15
 */
 
16
 
 
17
 
 
18
#include <linux/kernel.h>
 
19
#include <linux/module.h>
 
20
#include <linux/pci.h>
 
21
#include <linux/netdevice.h>
 
22
#include <linux/etherdevice.h>
 
23
 
 
24
#include <proto/802.11.h>
 
25
#include <bcmdefs.h>
 
26
#include <bcmdevs.h>
 
27
#include <bcmwifi.h>
 
28
#include <aiutils.h>
 
29
#include <bcmsrom.h>
 
30
#include <bcmotp.h>
 
31
#include <bcmutils.h>
 
32
#include <bcmnvram.h>
 
33
#include <wlioctl.h>
 
34
#include <sbconfig.h>
 
35
#include <sbchipc.h>
 
36
#include <pcicfg.h>
 
37
#include <sbhnddma.h>
 
38
#include <hnddma.h>
 
39
 
 
40
#include "wlc_types.h"
 
41
#include "wlc_pmu.h"
 
42
#include "d11.h"
 
43
#include "wlc_cfg.h"
 
44
#include "wlc_rate.h"
 
45
#include "wlc_scb.h"
 
46
#include "wlc_pub.h"
 
47
#include "wlc_key.h"
 
48
#include "wlc_phy_shim.h"
 
49
#include "phy/wlc_phy_hal.h"
 
50
#include "wlc_channel.h"
 
51
#include "wlc_main.h"
 
52
#include "wl_export.h"
 
53
#include "wl_ucode.h"
 
54
#include "wlc_antsel.h"
 
55
#include "pcie_core.h"
 
56
#include "wlc_alloc.h"
 
57
#include "wl_dbg.h"
 
58
#include "wlc_bmac.h"
 
59
 
 
60
#define TIMER_INTERVAL_WATCHDOG_BMAC    1000    /* watchdog timer, in unit of ms */
 
61
 
 
62
#define SYNTHPU_DLY_APHY_US     3700    /* a phy synthpu_dly time in us */
 
63
#define SYNTHPU_DLY_BPHY_US     1050    /* b/g phy synthpu_dly time in us, default */
 
64
#define SYNTHPU_DLY_NPHY_US     2048    /* n phy REV3 synthpu_dly time in us, default */
 
65
#define SYNTHPU_DLY_LPPHY_US    300     /* lpphy synthpu_dly time in us */
 
66
 
 
67
#define SYNTHPU_DLY_PHY_US_QT   100     /* QT synthpu_dly time in us */
 
68
 
 
69
#ifndef BMAC_DUP_TO_REMOVE
 
70
#define WLC_RM_WAIT_TX_SUSPEND          4       /* Wait Tx Suspend */
 
71
 
 
72
#define ANTCNT                  10      /* vanilla M_MAX_ANTCNT value */
 
73
 
 
74
#endif                          /* BMAC_DUP_TO_REMOVE */
 
75
 
 
76
#define DMAREG(wlc_hw, direction, fifonum) \
 
77
        ((direction == DMA_TX) ? \
 
78
                (void *)&(wlc_hw->regs->fifo64regs[fifonum].dmaxmt) : \
 
79
                (void *)&(wlc_hw->regs->fifo64regs[fifonum].dmarcv))
 
80
 
 
81
/*
 
82
 * The following table lists the buffer memory allocated to xmt fifos in HW.
 
83
 * the size is in units of 256bytes(one block), total size is HW dependent
 
84
 * ucode has default fifo partition, sw can overwrite if necessary
 
85
 *
 
86
 * This is documented in twiki under the topic UcodeTxFifo. Please ensure
 
87
 * the twiki is updated before making changes.
 
88
 */
 
89
 
 
90
#define XMTFIFOTBL_STARTREV     20      /* Starting corerev for the fifo size table */
 
91
 
 
92
static u16 xmtfifo_sz[][NFIFO] = {
 
93
        {20, 192, 192, 21, 17, 5},      /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */
 
94
        {9, 58, 22, 14, 14, 5}, /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */
 
95
        {20, 192, 192, 21, 17, 5},      /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */
 
96
        {20, 192, 192, 21, 17, 5},      /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */
 
97
        {9, 58, 22, 14, 14, 5}, /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
 
98
};
 
99
 
 
100
static void wlc_clkctl_clk(struct wlc_hw_info *wlc, uint mode);
 
101
static void wlc_coreinit(struct wlc_info *wlc);
 
102
 
 
103
/* used by wlc_wakeucode_init() */
 
104
static void wlc_write_inits(struct wlc_hw_info *wlc_hw,
 
105
                            const struct d11init *inits);
 
106
static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
 
107
                            const uint nbytes);
 
108
static void wlc_ucode_download(struct wlc_hw_info *wlc);
 
109
static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw);
 
110
 
 
111
/* used by wlc_dpc() */
 
112
static bool wlc_bmac_dotxstatus(struct wlc_hw_info *wlc, tx_status_t *txs,
 
113
                                u32 s2);
 
114
static bool wlc_bmac_txstatus(struct wlc_hw_info *wlc, bool bound, bool *fatal);
 
115
static bool wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound);
 
116
 
 
117
/* used by wlc_down() */
 
118
static void wlc_flushqueues(struct wlc_info *wlc);
 
119
 
 
120
static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs);
 
121
static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw);
 
122
static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw);
 
123
static bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info *wlc_hw,
 
124
                                       uint tx_fifo);
 
125
static void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info *wlc_hw, uint tx_fifo);
 
126
static void wlc_bmac_tx_fifo_resume(struct wlc_hw_info *wlc_hw, uint tx_fifo);
 
127
 
 
128
/* Low Level Prototypes */
 
129
static int wlc_bmac_bandtype(struct wlc_hw_info *wlc_hw);
 
130
static void wlc_bmac_info_init(struct wlc_hw_info *wlc_hw);
 
131
static void wlc_bmac_xtal(struct wlc_hw_info *wlc_hw, bool want);
 
132
static u16 wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset,
 
133
                                   u32 sel);
 
134
static void wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset,
 
135
                                  u16 v, u32 sel);
 
136
static void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk);
 
137
static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme);
 
138
static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw);
 
139
static void wlc_ucode_bsinit(struct wlc_hw_info *wlc_hw);
 
140
static bool wlc_validboardtype(struct wlc_hw_info *wlc);
 
141
static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw);
 
142
static bool wlc_bmac_validate_chip_access(struct wlc_hw_info *wlc_hw);
 
143
static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw);
 
144
static void wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init);
 
145
static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw);
 
146
static void wlc_bmac_mute(struct wlc_hw_info *wlc_hw, bool want, mbool flags);
 
147
static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw);
 
148
static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw);
 
149
static u32 wlc_wlintrsoff(struct wlc_info *wlc);
 
150
static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask);
 
151
static void wlc_gpio_init(struct wlc_info *wlc);
 
152
static void wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn,
 
153
                                      int len);
 
154
static void wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn,
 
155
                                      int len);
 
156
static void wlc_bmac_bsinit(struct wlc_info *wlc, chanspec_t chanspec);
 
157
static u32 wlc_setband_inact(struct wlc_info *wlc, uint bandunit);
 
158
static void wlc_bmac_setband(struct wlc_hw_info *wlc_hw, uint bandunit,
 
159
                             chanspec_t chanspec);
 
160
static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
 
161
                                        bool shortslot);
 
162
static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw);
 
163
static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw,
 
164
                                             u8 rate);
 
165
 
 
166
/* === Low Level functions === */
 
167
 
 
168
void wlc_bmac_set_shortslot(struct wlc_hw_info *wlc_hw, bool shortslot)
 
169
{
 
170
        wlc_hw->shortslot = shortslot;
 
171
 
 
172
        if (BAND_2G(wlc_bmac_bandtype(wlc_hw)) && wlc_hw->up) {
 
173
                wlc_suspend_mac_and_wait(wlc_hw->wlc);
 
174
                wlc_bmac_update_slot_timing(wlc_hw, shortslot);
 
175
                wlc_enable_mac(wlc_hw->wlc);
 
176
        }
 
177
}
 
178
 
 
179
/*
 
180
 * Update the slot timing for standard 11b/g (20us slots)
 
181
 * or shortslot 11g (9us slots)
 
182
 * The PSM needs to be suspended for this call.
 
183
 */
 
184
static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
 
185
                                        bool shortslot)
 
186
{
 
187
        d11regs_t *regs;
 
188
 
 
189
        regs = wlc_hw->regs;
 
190
 
 
191
        if (shortslot) {
 
192
                /* 11g short slot: 11a timing */
 
193
                W_REG(&regs->ifs_slot, 0x0207); /* APHY_SLOT_TIME */
 
194
                wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, APHY_SLOT_TIME);
 
195
        } else {
 
196
                /* 11g long slot: 11b timing */
 
197
                W_REG(&regs->ifs_slot, 0x0212); /* BPHY_SLOT_TIME */
 
198
                wlc_bmac_write_shm(wlc_hw, M_DOT11_SLOT, BPHY_SLOT_TIME);
 
199
        }
 
200
}
 
201
 
 
202
static void WLBANDINITFN(wlc_ucode_bsinit) (struct wlc_hw_info *wlc_hw)
 
203
{
 
204
        struct wiphy *wiphy = wlc_hw->wlc->wiphy;
 
205
 
 
206
        /* init microcode host flags */
 
207
        wlc_write_mhf(wlc_hw, wlc_hw->band->mhfs);
 
208
 
 
209
        /* do band-specific ucode IHR, SHM, and SCR inits */
 
210
        if (D11REV_IS(wlc_hw->corerev, 23)) {
 
211
                if (WLCISNPHY(wlc_hw->band)) {
 
212
                        wlc_write_inits(wlc_hw, d11n0bsinitvals16);
 
213
                } else {
 
214
                        wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev"
 
215
                                  " %d\n", __func__, wlc_hw->unit,
 
216
                                  wlc_hw->corerev);
 
217
                }
 
218
        } else {
 
219
                if (D11REV_IS(wlc_hw->corerev, 24)) {
 
220
                        if (WLCISLCNPHY(wlc_hw->band)) {
 
221
                                wlc_write_inits(wlc_hw, d11lcn0bsinitvals24);
 
222
                        } else
 
223
                                wiphy_err(wiphy, "%s: wl%d: unsupported phy in"
 
224
                                          " core rev %d\n", __func__,
 
225
                                          wlc_hw->unit, wlc_hw->corerev);
 
226
                } else {
 
227
                        wiphy_err(wiphy, "%s: wl%d: unsupported corerev %d\n",
 
228
                                __func__, wlc_hw->unit, wlc_hw->corerev);
 
229
                }
 
230
        }
 
231
}
 
232
 
 
233
/* switch to new band but leave it inactive */
 
234
static u32 WLBANDINITFN(wlc_setband_inact) (struct wlc_info *wlc, uint bandunit)
 
235
{
 
236
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
237
        u32 macintmask;
 
238
 
 
239
        BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
240
 
 
241
        WARN_ON((R_REG(&wlc_hw->regs->maccontrol) & MCTL_EN_MAC) != 0);
 
242
 
 
243
        /* disable interrupts */
 
244
        macintmask = wl_intrsoff(wlc->wl);
 
245
 
 
246
        /* radio off */
 
247
        wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
 
248
 
 
249
        wlc_bmac_core_phy_clk(wlc_hw, OFF);
 
250
 
 
251
        wlc_setxband(wlc_hw, bandunit);
 
252
 
 
253
        return macintmask;
 
254
}
 
255
 
 
256
/* Process received frames */
 
257
/*
 
258
 * Return true if more frames need to be processed. false otherwise.
 
259
 * Param 'bound' indicates max. # frames to process before break out.
 
260
 */
 
261
static bool
 
262
wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound)
 
263
{
 
264
        struct sk_buff *p;
 
265
        struct sk_buff *head = NULL;
 
266
        struct sk_buff *tail = NULL;
 
267
        uint n = 0;
 
268
        uint bound_limit = bound ? wlc_hw->wlc->pub->tunables->rxbnd : -1;
 
269
        wlc_d11rxhdr_t *wlc_rxhdr = NULL;
 
270
 
 
271
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
272
        /* gather received frames */
 
273
        while ((p = dma_rx(wlc_hw->di[fifo]))) {
 
274
 
 
275
                if (!tail)
 
276
                        head = tail = p;
 
277
                else {
 
278
                        tail->prev = p;
 
279
                        tail = p;
 
280
                }
 
281
 
 
282
                /* !give others some time to run! */
 
283
                if (++n >= bound_limit)
 
284
                        break;
 
285
        }
 
286
 
 
287
        /* post more rbufs */
 
288
        dma_rxfill(wlc_hw->di[fifo]);
 
289
 
 
290
        /* process each frame */
 
291
        while ((p = head) != NULL) {
 
292
                head = head->prev;
 
293
                p->prev = NULL;
 
294
 
 
295
                wlc_rxhdr = (wlc_d11rxhdr_t *) p->data;
 
296
 
 
297
                /* compute the RSSI from d11rxhdr and record it in wlc_rxd11hr */
 
298
                wlc_phy_rssi_compute(wlc_hw->band->pi, wlc_rxhdr);
 
299
 
 
300
                wlc_recv(wlc_hw->wlc, p);
 
301
        }
 
302
 
 
303
        return n >= bound_limit;
 
304
}
 
305
 
 
306
/* second-level interrupt processing
 
307
 *   Return true if another dpc needs to be re-scheduled. false otherwise.
 
308
 *   Param 'bounded' indicates if applicable loops should be bounded.
 
309
 */
 
310
bool wlc_dpc(struct wlc_info *wlc, bool bounded)
 
311
{
 
312
        u32 macintstatus;
 
313
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
314
        d11regs_t *regs = wlc_hw->regs;
 
315
        bool fatal = false;
 
316
        struct wiphy *wiphy = wlc->wiphy;
 
317
 
 
318
        if (DEVICEREMOVED(wlc)) {
 
319
                wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
 
320
                          __func__);
 
321
                wl_down(wlc->wl);
 
322
                return false;
 
323
        }
 
324
 
 
325
        /* grab and clear the saved software intstatus bits */
 
326
        macintstatus = wlc->macintstatus;
 
327
        wlc->macintstatus = 0;
 
328
 
 
329
        BCMMSG(wlc->wiphy, "wl%d: macintstatus 0x%x\n",
 
330
               wlc_hw->unit, macintstatus);
 
331
 
 
332
        WARN_ON(macintstatus & MI_PRQ); /* PRQ Interrupt in non-MBSS */
 
333
 
 
334
        /* BCN template is available */
 
335
        /* ZZZ: Use AP_ACTIVE ? */
 
336
        if (AP_ENAB(wlc->pub) && (!APSTA_ENAB(wlc->pub) || wlc->aps_associated)
 
337
            && (macintstatus & MI_BCNTPL)) {
 
338
                wlc_update_beacon(wlc);
 
339
        }
 
340
 
 
341
        /* PMQ entry addition */
 
342
        if (macintstatus & MI_PMQ) {
 
343
        }
 
344
 
 
345
        /* tx status */
 
346
        if (macintstatus & MI_TFS) {
 
347
                if (wlc_bmac_txstatus(wlc->hw, bounded, &fatal))
 
348
                        wlc->macintstatus |= MI_TFS;
 
349
                if (fatal) {
 
350
                        wiphy_err(wiphy, "MI_TFS: fatal\n");
 
351
                        goto fatal;
 
352
                }
 
353
        }
 
354
 
 
355
        if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
 
356
                wlc_tbtt(wlc, regs);
 
357
 
 
358
        /* ATIM window end */
 
359
        if (macintstatus & MI_ATIMWINEND) {
 
360
                BCMMSG(wlc->wiphy, "end of ATIM window\n");
 
361
                OR_REG(&regs->maccommand, wlc->qvalid);
 
362
                wlc->qvalid = 0;
 
363
        }
 
364
 
 
365
        /* received data or control frame, MI_DMAINT is indication of RX_FIFO interrupt */
 
366
        if (macintstatus & MI_DMAINT) {
 
367
                if (wlc_bmac_recv(wlc_hw, RX_FIFO, bounded)) {
 
368
                        wlc->macintstatus |= MI_DMAINT;
 
369
                }
 
370
        }
 
371
 
 
372
        /* TX FIFO suspend/flush completion */
 
373
        if (macintstatus & MI_TXSTOP) {
 
374
                if (wlc_bmac_tx_fifo_suspended(wlc_hw, TX_DATA_FIFO)) {
 
375
                        /* wiphy_err(wiphy, "dpc: fifo_suspend_comlete\n"); */
 
376
                }
 
377
        }
 
378
 
 
379
        /* noise sample collected */
 
380
        if (macintstatus & MI_BG_NOISE) {
 
381
                wlc_phy_noise_sample_intr(wlc_hw->band->pi);
 
382
        }
 
383
 
 
384
        if (macintstatus & MI_GP0) {
 
385
                wiphy_err(wiphy, "wl%d: PSM microcode watchdog fired at %d "
 
386
                        "(seconds). Resetting.\n", wlc_hw->unit, wlc_hw->now);
 
387
 
 
388
                printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
 
389
                                        __func__, wlc_hw->sih->chip,
 
390
                                        wlc_hw->sih->chiprev);
 
391
                /* big hammer */
 
392
                wl_init(wlc->wl);
 
393
        }
 
394
 
 
395
        /* gptimer timeout */
 
396
        if (macintstatus & MI_TO) {
 
397
                W_REG(&regs->gptimer, 0);
 
398
        }
 
399
 
 
400
        if (macintstatus & MI_RFDISABLE) {
 
401
                BCMMSG(wlc->wiphy, "wl%d: BMAC Detected a change on the"
 
402
                       " RF Disable Input\n", wlc_hw->unit);
 
403
                wl_rfkill_set_hw_state(wlc->wl);
 
404
        }
 
405
 
 
406
        /* send any enq'd tx packets. Just makes sure to jump start tx */
 
407
        if (!pktq_empty(&wlc->pkt_queue->q))
 
408
                wlc_send_q(wlc);
 
409
 
 
410
        /* it isn't done and needs to be resched if macintstatus is non-zero */
 
411
        return wlc->macintstatus != 0;
 
412
 
 
413
 fatal:
 
414
        wl_init(wlc->wl);
 
415
        return wlc->macintstatus != 0;
 
416
}
 
417
 
 
418
/* common low-level watchdog code */
 
419
void wlc_bmac_watchdog(void *arg)
 
420
{
 
421
        struct wlc_info *wlc = (struct wlc_info *) arg;
 
422
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
423
 
 
424
        BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
425
 
 
426
        if (!wlc_hw->up)
 
427
                return;
 
428
 
 
429
        /* increment second count */
 
430
        wlc_hw->now++;
 
431
 
 
432
        /* Check for FIFO error interrupts */
 
433
        wlc_bmac_fifoerrors(wlc_hw);
 
434
 
 
435
        /* make sure RX dma has buffers */
 
436
        dma_rxfill(wlc->hw->di[RX_FIFO]);
 
437
 
 
438
        wlc_phy_watchdog(wlc_hw->band->pi);
 
439
}
 
440
 
 
441
void
 
442
wlc_bmac_set_chanspec(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
 
443
                      bool mute, struct txpwr_limits *txpwr)
 
444
{
 
445
        uint bandunit;
 
446
 
 
447
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d: 0x%x\n", wlc_hw->unit, chanspec);
 
448
 
 
449
        wlc_hw->chanspec = chanspec;
 
450
 
 
451
        /* Switch bands if necessary */
 
452
        if (NBANDS_HW(wlc_hw) > 1) {
 
453
                bandunit = CHSPEC_WLCBANDUNIT(chanspec);
 
454
                if (wlc_hw->band->bandunit != bandunit) {
 
455
                        /* wlc_bmac_setband disables other bandunit,
 
456
                         *  use light band switch if not up yet
 
457
                         */
 
458
                        if (wlc_hw->up) {
 
459
                                wlc_phy_chanspec_radio_set(wlc_hw->
 
460
                                                           bandstate[bandunit]->
 
461
                                                           pi, chanspec);
 
462
                                wlc_bmac_setband(wlc_hw, bandunit, chanspec);
 
463
                        } else {
 
464
                                wlc_setxband(wlc_hw, bandunit);
 
465
                        }
 
466
                }
 
467
        }
 
468
 
 
469
        wlc_phy_initcal_enable(wlc_hw->band->pi, !mute);
 
470
 
 
471
        if (!wlc_hw->up) {
 
472
                if (wlc_hw->clk)
 
473
                        wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr,
 
474
                                                  chanspec);
 
475
                wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
 
476
        } else {
 
477
                wlc_phy_chanspec_set(wlc_hw->band->pi, chanspec);
 
478
                wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, chanspec);
 
479
 
 
480
                /* Update muting of the channel */
 
481
                wlc_bmac_mute(wlc_hw, mute, 0);
 
482
        }
 
483
}
 
484
 
 
485
int wlc_bmac_state_get(struct wlc_hw_info *wlc_hw, wlc_bmac_state_t *state)
 
486
{
 
487
        state->machwcap = wlc_hw->machwcap;
 
488
 
 
489
        return 0;
 
490
}
 
491
 
 
492
static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
 
493
{
 
494
        uint i;
 
495
        char name[8];
 
496
        /* ucode host flag 2 needed for pio mode, independent of band and fifo */
 
497
        u16 pio_mhf2 = 0;
 
498
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
499
        uint unit = wlc_hw->unit;
 
500
        wlc_tunables_t *tune = wlc->pub->tunables;
 
501
        struct wiphy *wiphy = wlc->wiphy;
 
502
 
 
503
        /* name and offsets for dma_attach */
 
504
        snprintf(name, sizeof(name), "wl%d", unit);
 
505
 
 
506
        if (wlc_hw->di[0] == 0) {       /* Init FIFOs */
 
507
                uint addrwidth;
 
508
                int dma_attach_err = 0;
 
509
                /* Find out the DMA addressing capability and let OS know
 
510
                 * All the channels within one DMA core have 'common-minimum' same
 
511
                 * capability
 
512
                 */
 
513
                addrwidth =
 
514
                    dma_addrwidth(wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 0));
 
515
 
 
516
                if (!wl_alloc_dma_resources(wlc_hw->wlc->wl, addrwidth)) {
 
517
                        wiphy_err(wiphy, "wl%d: wlc_attach: alloc_dma_"
 
518
                                  "resources failed\n", unit);
 
519
                        return false;
 
520
                }
 
521
 
 
522
                /*
 
523
                 * FIFO 0
 
524
                 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
 
525
                 * RX: RX_FIFO (RX data packets)
 
526
                 */
 
527
                wlc_hw->di[0] = dma_attach(name, wlc_hw->sih,
 
528
                                           (wme ? DMAREG(wlc_hw, DMA_TX, 0) :
 
529
                                            NULL), DMAREG(wlc_hw, DMA_RX, 0),
 
530
                                           (wme ? tune->ntxd : 0), tune->nrxd,
 
531
                                           tune->rxbufsz, -1, tune->nrxbufpost,
 
532
                                           WL_HWRXOFF, &wl_msg_level);
 
533
                dma_attach_err |= (NULL == wlc_hw->di[0]);
 
534
 
 
535
                /*
 
536
                 * FIFO 1
 
537
                 * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets)
 
538
                 *   (legacy) TX_DATA_FIFO (TX data packets)
 
539
                 * RX: UNUSED
 
540
                 */
 
541
                wlc_hw->di[1] = dma_attach(name, wlc_hw->sih,
 
542
                                           DMAREG(wlc_hw, DMA_TX, 1), NULL,
 
543
                                           tune->ntxd, 0, 0, -1, 0, 0,
 
544
                                           &wl_msg_level);
 
545
                dma_attach_err |= (NULL == wlc_hw->di[1]);
 
546
 
 
547
                /*
 
548
                 * FIFO 2
 
549
                 * TX: TX_AC_VI_FIFO (TX AC Video data packets)
 
550
                 * RX: UNUSED
 
551
                 */
 
552
                wlc_hw->di[2] = dma_attach(name, wlc_hw->sih,
 
553
                                           DMAREG(wlc_hw, DMA_TX, 2), NULL,
 
554
                                           tune->ntxd, 0, 0, -1, 0, 0,
 
555
                                           &wl_msg_level);
 
556
                dma_attach_err |= (NULL == wlc_hw->di[2]);
 
557
                /*
 
558
                 * FIFO 3
 
559
                 * TX: TX_AC_VO_FIFO (TX AC Voice data packets)
 
560
                 *   (legacy) TX_CTL_FIFO (TX control & mgmt packets)
 
561
                 */
 
562
                wlc_hw->di[3] = dma_attach(name, wlc_hw->sih,
 
563
                                           DMAREG(wlc_hw, DMA_TX, 3),
 
564
                                           NULL, tune->ntxd, 0, 0, -1,
 
565
                                           0, 0, &wl_msg_level);
 
566
                dma_attach_err |= (NULL == wlc_hw->di[3]);
 
567
/* Cleaner to leave this as if with AP defined */
 
568
 
 
569
                if (dma_attach_err) {
 
570
                        wiphy_err(wiphy, "wl%d: wlc_attach: dma_attach failed"
 
571
                                  "\n", unit);
 
572
                        return false;
 
573
                }
 
574
 
 
575
                /* get pointer to dma engine tx flow control variable */
 
576
                for (i = 0; i < NFIFO; i++)
 
577
                        if (wlc_hw->di[i])
 
578
                                wlc_hw->txavail[i] =
 
579
                                    (uint *) dma_getvar(wlc_hw->di[i],
 
580
                                                        "&txavail");
 
581
        }
 
582
 
 
583
        /* initial ucode host flags */
 
584
        wlc_mhfdef(wlc, wlc_hw->band->mhfs, pio_mhf2);
 
585
 
 
586
        return true;
 
587
}
 
588
 
 
589
static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw)
 
590
{
 
591
        uint j;
 
592
 
 
593
        for (j = 0; j < NFIFO; j++) {
 
594
                if (wlc_hw->di[j]) {
 
595
                        dma_detach(wlc_hw->di[j]);
 
596
                        wlc_hw->di[j] = NULL;
 
597
                }
 
598
        }
 
599
}
 
600
 
 
601
/* low level attach
 
602
 *    run backplane attach, init nvram
 
603
 *    run phy attach
 
604
 *    initialize software state for each core and band
 
605
 *    put the whole chip in reset(driver down state), no clock
 
606
 */
 
607
int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device, uint unit,
 
608
                    bool piomode, void *regsva, uint bustype, void *btparam)
 
609
{
 
610
        struct wlc_hw_info *wlc_hw;
 
611
        d11regs_t *regs;
 
612
        char *macaddr = NULL;
 
613
        char *vars;
 
614
        uint err = 0;
 
615
        uint j;
 
616
        bool wme = false;
 
617
        shared_phy_params_t sha_params;
 
618
        struct wiphy *wiphy = wlc->wiphy;
 
619
 
 
620
        BCMMSG(wlc->wiphy, "wl%d: vendor 0x%x device 0x%x\n", unit, vendor,
 
621
                device);
 
622
 
 
623
        wme = true;
 
624
 
 
625
        wlc_hw = wlc->hw;
 
626
        wlc_hw->wlc = wlc;
 
627
        wlc_hw->unit = unit;
 
628
        wlc_hw->band = wlc_hw->bandstate[0];
 
629
        wlc_hw->_piomode = piomode;
 
630
 
 
631
        /* populate struct wlc_hw_info with default values  */
 
632
        wlc_bmac_info_init(wlc_hw);
 
633
 
 
634
        /*
 
635
         * Do the hardware portion of the attach.
 
636
         * Also initialize software state that depends on the particular hardware
 
637
         * we are running.
 
638
         */
 
639
        wlc_hw->sih = ai_attach((uint) device, regsva, bustype, btparam,
 
640
                                &wlc_hw->vars, &wlc_hw->vars_size);
 
641
        if (wlc_hw->sih == NULL) {
 
642
                wiphy_err(wiphy, "wl%d: wlc_bmac_attach: si_attach failed\n",
 
643
                          unit);
 
644
                err = 11;
 
645
                goto fail;
 
646
        }
 
647
        vars = wlc_hw->vars;
 
648
 
 
649
        /*
 
650
         * Get vendid/devid nvram overwrites, which could be different
 
651
         * than those the BIOS recognizes for devices on PCMCIA_BUS,
 
652
         * SDIO_BUS, and SROMless devices on PCI_BUS.
 
653
         */
 
654
#ifdef BCMBUSTYPE
 
655
        bustype = BCMBUSTYPE;
 
656
#endif
 
657
        if (bustype != SI_BUS) {
 
658
                char *var;
 
659
 
 
660
                var = getvar(vars, "vendid");
 
661
                if (var) {
 
662
                        vendor = (u16) simple_strtoul(var, NULL, 0);
 
663
                        wiphy_err(wiphy, "Overriding vendor id = 0x%x\n",
 
664
                                  vendor);
 
665
                }
 
666
                var = getvar(vars, "devid");
 
667
                if (var) {
 
668
                        u16 devid = (u16) simple_strtoul(var, NULL, 0);
 
669
                        if (devid != 0xffff) {
 
670
                                device = devid;
 
671
                                wiphy_err(wiphy, "Overriding device id = 0x%x"
 
672
                                          "\n", device);
 
673
                        }
 
674
                }
 
675
 
 
676
                /* verify again the device is supported */
 
677
                if (!wlc_chipmatch(vendor, device)) {
 
678
                        wiphy_err(wiphy, "wl%d: wlc_bmac_attach: Unsupported "
 
679
                                "vendor/device (0x%x/0x%x)\n",
 
680
                                 unit, vendor, device);
 
681
                        err = 12;
 
682
                        goto fail;
 
683
                }
 
684
        }
 
685
 
 
686
        wlc_hw->vendorid = vendor;
 
687
        wlc_hw->deviceid = device;
 
688
 
 
689
        /* set bar0 window to point at D11 core */
 
690
        wlc_hw->regs = (d11regs_t *) ai_setcore(wlc_hw->sih, D11_CORE_ID, 0);
 
691
        wlc_hw->corerev = ai_corerev(wlc_hw->sih);
 
692
 
 
693
        regs = wlc_hw->regs;
 
694
 
 
695
        wlc->regs = wlc_hw->regs;
 
696
 
 
697
        /* validate chip, chiprev and corerev */
 
698
        if (!wlc_isgoodchip(wlc_hw)) {
 
699
                err = 13;
 
700
                goto fail;
 
701
        }
 
702
 
 
703
        /* initialize power control registers */
 
704
        ai_clkctl_init(wlc_hw->sih);
 
705
 
 
706
        /* request fastclock and force fastclock for the rest of attach
 
707
         * bring the d11 core out of reset.
 
708
         *   For PMU chips, the first wlc_clkctl_clk is no-op since core-clk is still false;
 
709
         *   But it will be called again inside wlc_corereset, after d11 is out of reset.
 
710
         */
 
711
        wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
712
        wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
 
713
 
 
714
        if (!wlc_bmac_validate_chip_access(wlc_hw)) {
 
715
                wiphy_err(wiphy, "wl%d: wlc_bmac_attach: validate_chip_access "
 
716
                        "failed\n", unit);
 
717
                err = 14;
 
718
                goto fail;
 
719
        }
 
720
 
 
721
        /* get the board rev, used just below */
 
722
        j = getintvar(vars, "boardrev");
 
723
        /* promote srom boardrev of 0xFF to 1 */
 
724
        if (j == BOARDREV_PROMOTABLE)
 
725
                j = BOARDREV_PROMOTED;
 
726
        wlc_hw->boardrev = (u16) j;
 
727
        if (!wlc_validboardtype(wlc_hw)) {
 
728
                wiphy_err(wiphy, "wl%d: wlc_bmac_attach: Unsupported Broadcom "
 
729
                        "board type (0x%x)" " or revision level (0x%x)\n",
 
730
                         unit, wlc_hw->sih->boardtype, wlc_hw->boardrev);
 
731
                err = 15;
 
732
                goto fail;
 
733
        }
 
734
        wlc_hw->sromrev = (u8) getintvar(vars, "sromrev");
 
735
        wlc_hw->boardflags = (u32) getintvar(vars, "boardflags");
 
736
        wlc_hw->boardflags2 = (u32) getintvar(vars, "boardflags2");
 
737
 
 
738
        if (wlc_hw->boardflags & BFL_NOPLLDOWN)
 
739
                wlc_bmac_pllreq(wlc_hw, true, WLC_PLLREQ_SHARED);
 
740
 
 
741
        if ((wlc_hw->sih->bustype == PCI_BUS)
 
742
            && (ai_pci_war16165(wlc_hw->sih)))
 
743
                wlc->war16165 = true;
 
744
 
 
745
        /* check device id(srom, nvram etc.) to set bands */
 
746
        if (wlc_hw->deviceid == BCM43224_D11N_ID) {
 
747
                /* Dualband boards */
 
748
                wlc_hw->_nbands = 2;
 
749
        } else
 
750
                wlc_hw->_nbands = 1;
 
751
 
 
752
        if ((wlc_hw->sih->chip == BCM43225_CHIP_ID))
 
753
                wlc_hw->_nbands = 1;
 
754
 
 
755
        /* BMAC_NOTE: remove init of pub values when wlc_attach() unconditionally does the
 
756
         * init of these values
 
757
         */
 
758
        wlc->vendorid = wlc_hw->vendorid;
 
759
        wlc->deviceid = wlc_hw->deviceid;
 
760
        wlc->pub->sih = wlc_hw->sih;
 
761
        wlc->pub->corerev = wlc_hw->corerev;
 
762
        wlc->pub->sromrev = wlc_hw->sromrev;
 
763
        wlc->pub->boardrev = wlc_hw->boardrev;
 
764
        wlc->pub->boardflags = wlc_hw->boardflags;
 
765
        wlc->pub->boardflags2 = wlc_hw->boardflags2;
 
766
        wlc->pub->_nbands = wlc_hw->_nbands;
 
767
 
 
768
        wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc);
 
769
 
 
770
        if (wlc_hw->physhim == NULL) {
 
771
                wiphy_err(wiphy, "wl%d: wlc_bmac_attach: wlc_phy_shim_attach "
 
772
                        "failed\n", unit);
 
773
                err = 25;
 
774
                goto fail;
 
775
        }
 
776
 
 
777
        /* pass all the parameters to wlc_phy_shared_attach in one struct */
 
778
        sha_params.sih = wlc_hw->sih;
 
779
        sha_params.physhim = wlc_hw->physhim;
 
780
        sha_params.unit = unit;
 
781
        sha_params.corerev = wlc_hw->corerev;
 
782
        sha_params.vars = vars;
 
783
        sha_params.vid = wlc_hw->vendorid;
 
784
        sha_params.did = wlc_hw->deviceid;
 
785
        sha_params.chip = wlc_hw->sih->chip;
 
786
        sha_params.chiprev = wlc_hw->sih->chiprev;
 
787
        sha_params.chippkg = wlc_hw->sih->chippkg;
 
788
        sha_params.sromrev = wlc_hw->sromrev;
 
789
        sha_params.boardtype = wlc_hw->sih->boardtype;
 
790
        sha_params.boardrev = wlc_hw->boardrev;
 
791
        sha_params.boardvendor = wlc_hw->sih->boardvendor;
 
792
        sha_params.boardflags = wlc_hw->boardflags;
 
793
        sha_params.boardflags2 = wlc_hw->boardflags2;
 
794
        sha_params.bustype = wlc_hw->sih->bustype;
 
795
        sha_params.buscorerev = wlc_hw->sih->buscorerev;
 
796
 
 
797
        /* alloc and save pointer to shared phy state area */
 
798
        wlc_hw->phy_sh = wlc_phy_shared_attach(&sha_params);
 
799
        if (!wlc_hw->phy_sh) {
 
800
                err = 16;
 
801
                goto fail;
 
802
        }
 
803
 
 
804
        /* initialize software state for each core and band */
 
805
        for (j = 0; j < NBANDS_HW(wlc_hw); j++) {
 
806
                /*
 
807
                 * band0 is always 2.4Ghz
 
808
                 * band1, if present, is 5Ghz
 
809
                 */
 
810
 
 
811
                /* So if this is a single band 11a card, use band 1 */
 
812
                if (IS_SINGLEBAND_5G(wlc_hw->deviceid))
 
813
                        j = BAND_5G_INDEX;
 
814
 
 
815
                wlc_setxband(wlc_hw, j);
 
816
 
 
817
                wlc_hw->band->bandunit = j;
 
818
                wlc_hw->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
 
819
                wlc->band->bandunit = j;
 
820
                wlc->band->bandtype = j ? WLC_BAND_5G : WLC_BAND_2G;
 
821
                wlc->core->coreidx = ai_coreidx(wlc_hw->sih);
 
822
 
 
823
                wlc_hw->machwcap = R_REG(&regs->machwcap);
 
824
                wlc_hw->machwcap_backup = wlc_hw->machwcap;
 
825
 
 
826
                /* init tx fifo size */
 
827
                wlc_hw->xmtfifo_sz =
 
828
                    xmtfifo_sz[(wlc_hw->corerev - XMTFIFOTBL_STARTREV)];
 
829
 
 
830
                /* Get a phy for this band */
 
831
                wlc_hw->band->pi = wlc_phy_attach(wlc_hw->phy_sh,
 
832
                        (void *)regs, wlc_bmac_bandtype(wlc_hw), vars,
 
833
                        wlc->wiphy);
 
834
                if (wlc_hw->band->pi == NULL) {
 
835
                        wiphy_err(wiphy, "wl%d: wlc_bmac_attach: wlc_phy_"
 
836
                                  "attach failed\n", unit);
 
837
                        err = 17;
 
838
                        goto fail;
 
839
                }
 
840
 
 
841
                wlc_phy_machwcap_set(wlc_hw->band->pi, wlc_hw->machwcap);
 
842
 
 
843
                wlc_phy_get_phyversion(wlc_hw->band->pi, &wlc_hw->band->phytype,
 
844
                                       &wlc_hw->band->phyrev,
 
845
                                       &wlc_hw->band->radioid,
 
846
                                       &wlc_hw->band->radiorev);
 
847
                wlc_hw->band->abgphy_encore =
 
848
                    wlc_phy_get_encore(wlc_hw->band->pi);
 
849
                wlc->band->abgphy_encore = wlc_phy_get_encore(wlc_hw->band->pi);
 
850
                wlc_hw->band->core_flags =
 
851
                    wlc_phy_get_coreflags(wlc_hw->band->pi);
 
852
 
 
853
                /* verify good phy_type & supported phy revision */
 
854
                if (WLCISNPHY(wlc_hw->band)) {
 
855
                        if (NCONF_HAS(wlc_hw->band->phyrev))
 
856
                                goto good_phy;
 
857
                        else
 
858
                                goto bad_phy;
 
859
                } else if (WLCISLCNPHY(wlc_hw->band)) {
 
860
                        if (LCNCONF_HAS(wlc_hw->band->phyrev))
 
861
                                goto good_phy;
 
862
                        else
 
863
                                goto bad_phy;
 
864
                } else {
 
865
 bad_phy:
 
866
                        wiphy_err(wiphy, "wl%d: wlc_bmac_attach: unsupported "
 
867
                                  "phy type/rev (%d/%d)\n", unit,
 
868
                                  wlc_hw->band->phytype, wlc_hw->band->phyrev);
 
869
                        err = 18;
 
870
                        goto fail;
 
871
                }
 
872
 
 
873
 good_phy:
 
874
                /* BMAC_NOTE: wlc->band->pi should not be set below and should be done in the
 
875
                 * high level attach. However we can not make that change until all low level access
 
876
                 * is changed to wlc_hw->band->pi. Instead do the wlc->band->pi init below, keeping
 
877
                 * wlc_hw->band->pi as well for incremental update of low level fns, and cut over
 
878
                 * low only init when all fns updated.
 
879
                 */
 
880
                wlc->band->pi = wlc_hw->band->pi;
 
881
                wlc->band->phytype = wlc_hw->band->phytype;
 
882
                wlc->band->phyrev = wlc_hw->band->phyrev;
 
883
                wlc->band->radioid = wlc_hw->band->radioid;
 
884
                wlc->band->radiorev = wlc_hw->band->radiorev;
 
885
 
 
886
                /* default contention windows size limits */
 
887
                wlc_hw->band->CWmin = APHY_CWMIN;
 
888
                wlc_hw->band->CWmax = PHY_CWMAX;
 
889
 
 
890
                if (!wlc_bmac_attach_dmapio(wlc, j, wme)) {
 
891
                        err = 19;
 
892
                        goto fail;
 
893
                }
 
894
        }
 
895
 
 
896
        /* disable core to match driver "down" state */
 
897
        wlc_coredisable(wlc_hw);
 
898
 
 
899
        /* Match driver "down" state */
 
900
        if (wlc_hw->sih->bustype == PCI_BUS)
 
901
                ai_pci_down(wlc_hw->sih);
 
902
 
 
903
        /* register sb interrupt callback functions */
 
904
        ai_register_intr_callback(wlc_hw->sih, (void *)wlc_wlintrsoff,
 
905
                                  (void *)wlc_wlintrsrestore, NULL, wlc);
 
906
 
 
907
        /* turn off pll and xtal to match driver "down" state */
 
908
        wlc_bmac_xtal(wlc_hw, OFF);
 
909
 
 
910
        /* *********************************************************************
 
911
         * The hardware is in the DOWN state at this point. D11 core
 
912
         * or cores are in reset with clocks off, and the board PLLs
 
913
         * are off if possible.
 
914
         *
 
915
         * Beyond this point, wlc->sbclk == false and chip registers
 
916
         * should not be touched.
 
917
         *********************************************************************
 
918
         */
 
919
 
 
920
        /* init etheraddr state variables */
 
921
        macaddr = wlc_get_macaddr(wlc_hw);
 
922
        if (macaddr == NULL) {
 
923
                wiphy_err(wiphy, "wl%d: wlc_bmac_attach: macaddr not found\n",
 
924
                          unit);
 
925
                err = 21;
 
926
                goto fail;
 
927
        }
 
928
        bcm_ether_atoe(macaddr, wlc_hw->etheraddr);
 
929
        if (is_broadcast_ether_addr(wlc_hw->etheraddr) ||
 
930
            is_zero_ether_addr(wlc_hw->etheraddr)) {
 
931
                wiphy_err(wiphy, "wl%d: wlc_bmac_attach: bad macaddr %s\n",
 
932
                          unit, macaddr);
 
933
                err = 22;
 
934
                goto fail;
 
935
        }
 
936
 
 
937
        BCMMSG(wlc->wiphy,
 
938
                 "deviceid 0x%x nbands %d board 0x%x macaddr: %s\n",
 
939
                 wlc_hw->deviceid, wlc_hw->_nbands,
 
940
                 wlc_hw->sih->boardtype, macaddr);
 
941
 
 
942
        return err;
 
943
 
 
944
 fail:
 
945
        wiphy_err(wiphy, "wl%d: wlc_bmac_attach: failed with err %d\n", unit,
 
946
                  err);
 
947
        return err;
 
948
}
 
949
 
 
950
/*
 
951
 * Initialize wlc_info default values ...
 
952
 * may get overrides later in this function
 
953
 *  BMAC_NOTES, move low out and resolve the dangling ones
 
954
 */
 
955
static void wlc_bmac_info_init(struct wlc_hw_info *wlc_hw)
 
956
{
 
957
        struct wlc_info *wlc = wlc_hw->wlc;
 
958
 
 
959
        /* set default sw macintmask value */
 
960
        wlc->defmacintmask = DEF_MACINTMASK;
 
961
 
 
962
        /* various 802.11g modes */
 
963
        wlc_hw->shortslot = false;
 
964
 
 
965
        wlc_hw->SFBL = RETRY_SHORT_FB;
 
966
        wlc_hw->LFBL = RETRY_LONG_FB;
 
967
 
 
968
        /* default mac retry limits */
 
969
        wlc_hw->SRL = RETRY_SHORT_DEF;
 
970
        wlc_hw->LRL = RETRY_LONG_DEF;
 
971
        wlc_hw->chanspec = CH20MHZ_CHSPEC(1);
 
972
}
 
973
 
 
974
/*
 
975
 * low level detach
 
976
 */
 
977
int wlc_bmac_detach(struct wlc_info *wlc)
 
978
{
 
979
        uint i;
 
980
        struct wlc_hwband *band;
 
981
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
982
        int callbacks;
 
983
 
 
984
        callbacks = 0;
 
985
 
 
986
        if (wlc_hw->sih) {
 
987
                /* detach interrupt sync mechanism since interrupt is disabled and per-port
 
988
                 * interrupt object may has been freed. this must be done before sb core switch
 
989
                 */
 
990
                ai_deregister_intr_callback(wlc_hw->sih);
 
991
 
 
992
                if (wlc_hw->sih->bustype == PCI_BUS)
 
993
                        ai_pci_sleep(wlc_hw->sih);
 
994
        }
 
995
 
 
996
        wlc_bmac_detach_dmapio(wlc_hw);
 
997
 
 
998
        band = wlc_hw->band;
 
999
        for (i = 0; i < NBANDS_HW(wlc_hw); i++) {
 
1000
                if (band->pi) {
 
1001
                        /* Detach this band's phy */
 
1002
                        wlc_phy_detach(band->pi);
 
1003
                        band->pi = NULL;
 
1004
                }
 
1005
                band = wlc_hw->bandstate[OTHERBANDUNIT(wlc)];
 
1006
        }
 
1007
 
 
1008
        /* Free shared phy state */
 
1009
        wlc_phy_shared_detach(wlc_hw->phy_sh);
 
1010
 
 
1011
        wlc_phy_shim_detach(wlc_hw->physhim);
 
1012
 
 
1013
        /* free vars */
 
1014
        kfree(wlc_hw->vars);
 
1015
        wlc_hw->vars = NULL;
 
1016
 
 
1017
        if (wlc_hw->sih) {
 
1018
                ai_detach(wlc_hw->sih);
 
1019
                wlc_hw->sih = NULL;
 
1020
        }
 
1021
 
 
1022
        return callbacks;
 
1023
 
 
1024
}
 
1025
 
 
1026
void wlc_bmac_reset(struct wlc_hw_info *wlc_hw)
 
1027
{
 
1028
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1029
 
 
1030
        /* reset the core */
 
1031
        if (!DEVICEREMOVED(wlc_hw->wlc))
 
1032
                wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
 
1033
 
 
1034
        /* purge the dma rings */
 
1035
        wlc_flushqueues(wlc_hw->wlc);
 
1036
 
 
1037
        wlc_reset_bmac_done(wlc_hw->wlc);
 
1038
}
 
1039
 
 
1040
void
 
1041
wlc_bmac_init(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
 
1042
                          bool mute) {
 
1043
        u32 macintmask;
 
1044
        bool fastclk;
 
1045
        struct wlc_info *wlc = wlc_hw->wlc;
 
1046
 
 
1047
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1048
 
 
1049
        /* request FAST clock if not on */
 
1050
        fastclk = wlc_hw->forcefastclk;
 
1051
        if (!fastclk)
 
1052
                wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
1053
 
 
1054
        /* disable interrupts */
 
1055
        macintmask = wl_intrsoff(wlc->wl);
 
1056
 
 
1057
        /* set up the specified band and chanspec */
 
1058
        wlc_setxband(wlc_hw, CHSPEC_WLCBANDUNIT(chanspec));
 
1059
        wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec);
 
1060
 
 
1061
        /* do one-time phy inits and calibration */
 
1062
        wlc_phy_cal_init(wlc_hw->band->pi);
 
1063
 
 
1064
        /* core-specific initialization */
 
1065
        wlc_coreinit(wlc);
 
1066
 
 
1067
        /* suspend the tx fifos and mute the phy for preism cac time */
 
1068
        if (mute)
 
1069
                wlc_bmac_mute(wlc_hw, ON, PHY_MUTE_FOR_PREISM);
 
1070
 
 
1071
        /* band-specific inits */
 
1072
        wlc_bmac_bsinit(wlc, chanspec);
 
1073
 
 
1074
        /* restore macintmask */
 
1075
        wl_intrsrestore(wlc->wl, macintmask);
 
1076
 
 
1077
        /* seed wake_override with WLC_WAKE_OVERRIDE_MACSUSPEND since the mac is suspended
 
1078
         * and wlc_enable_mac() will clear this override bit.
 
1079
         */
 
1080
        mboolset(wlc_hw->wake_override, WLC_WAKE_OVERRIDE_MACSUSPEND);
 
1081
 
 
1082
        /*
 
1083
         * initialize mac_suspend_depth to 1 to match ucode initial suspended state
 
1084
         */
 
1085
        wlc_hw->mac_suspend_depth = 1;
 
1086
 
 
1087
        /* restore the clk */
 
1088
        if (!fastclk)
 
1089
                wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
 
1090
}
 
1091
 
 
1092
int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw)
 
1093
{
 
1094
        uint coremask;
 
1095
 
 
1096
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1097
 
 
1098
        /*
 
1099
         * Enable pll and xtal, initialize the power control registers,
 
1100
         * and force fastclock for the remainder of wlc_up().
 
1101
         */
 
1102
        wlc_bmac_xtal(wlc_hw, ON);
 
1103
        ai_clkctl_init(wlc_hw->sih);
 
1104
        wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
1105
 
 
1106
        /*
 
1107
         * Configure pci/pcmcia here instead of in wlc_attach()
 
1108
         * to allow mfg hotswap:  down, hotswap (chip power cycle), up.
 
1109
         */
 
1110
        coremask = (1 << wlc_hw->wlc->core->coreidx);
 
1111
 
 
1112
        if (wlc_hw->sih->bustype == PCI_BUS)
 
1113
                ai_pci_setup(wlc_hw->sih, coremask);
 
1114
 
 
1115
        /*
 
1116
         * Need to read the hwradio status here to cover the case where the system
 
1117
         * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
 
1118
         */
 
1119
        if (wlc_bmac_radio_read_hwdisabled(wlc_hw)) {
 
1120
                /* put SB PCI in down state again */
 
1121
                if (wlc_hw->sih->bustype == PCI_BUS)
 
1122
                        ai_pci_down(wlc_hw->sih);
 
1123
                wlc_bmac_xtal(wlc_hw, OFF);
 
1124
                return -ENOMEDIUM;
 
1125
        }
 
1126
 
 
1127
        if (wlc_hw->sih->bustype == PCI_BUS)
 
1128
                ai_pci_up(wlc_hw->sih);
 
1129
 
 
1130
        /* reset the d11 core */
 
1131
        wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
 
1132
 
 
1133
        return 0;
 
1134
}
 
1135
 
 
1136
int wlc_bmac_up_finish(struct wlc_hw_info *wlc_hw)
 
1137
{
 
1138
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1139
 
 
1140
        wlc_hw->up = true;
 
1141
        wlc_phy_hw_state_upd(wlc_hw->band->pi, true);
 
1142
 
 
1143
        /* FULLY enable dynamic power control and d11 core interrupt */
 
1144
        wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
 
1145
        wl_intrson(wlc_hw->wlc->wl);
 
1146
        return 0;
 
1147
}
 
1148
 
 
1149
int wlc_bmac_down_prep(struct wlc_hw_info *wlc_hw)
 
1150
{
 
1151
        bool dev_gone;
 
1152
        uint callbacks = 0;
 
1153
 
 
1154
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1155
 
 
1156
        if (!wlc_hw->up)
 
1157
                return callbacks;
 
1158
 
 
1159
        dev_gone = DEVICEREMOVED(wlc_hw->wlc);
 
1160
 
 
1161
        /* disable interrupts */
 
1162
        if (dev_gone)
 
1163
                wlc_hw->wlc->macintmask = 0;
 
1164
        else {
 
1165
                /* now disable interrupts */
 
1166
                wl_intrsoff(wlc_hw->wlc->wl);
 
1167
 
 
1168
                /* ensure we're running on the pll clock again */
 
1169
                wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
1170
        }
 
1171
        /* down phy at the last of this stage */
 
1172
        callbacks += wlc_phy_down(wlc_hw->band->pi);
 
1173
 
 
1174
        return callbacks;
 
1175
}
 
1176
 
 
1177
int wlc_bmac_down_finish(struct wlc_hw_info *wlc_hw)
 
1178
{
 
1179
        uint callbacks = 0;
 
1180
        bool dev_gone;
 
1181
 
 
1182
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1183
 
 
1184
        if (!wlc_hw->up)
 
1185
                return callbacks;
 
1186
 
 
1187
        wlc_hw->up = false;
 
1188
        wlc_phy_hw_state_upd(wlc_hw->band->pi, false);
 
1189
 
 
1190
        dev_gone = DEVICEREMOVED(wlc_hw->wlc);
 
1191
 
 
1192
        if (dev_gone) {
 
1193
                wlc_hw->sbclk = false;
 
1194
                wlc_hw->clk = false;
 
1195
                wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
 
1196
 
 
1197
                /* reclaim any posted packets */
 
1198
                wlc_flushqueues(wlc_hw->wlc);
 
1199
        } else {
 
1200
 
 
1201
                /* Reset and disable the core */
 
1202
                if (ai_iscoreup(wlc_hw->sih)) {
 
1203
                        if (R_REG(&wlc_hw->regs->maccontrol) &
 
1204
                            MCTL_EN_MAC)
 
1205
                                wlc_suspend_mac_and_wait(wlc_hw->wlc);
 
1206
                        callbacks += wl_reset(wlc_hw->wlc->wl);
 
1207
                        wlc_coredisable(wlc_hw);
 
1208
                }
 
1209
 
 
1210
                /* turn off primary xtal and pll */
 
1211
                if (!wlc_hw->noreset) {
 
1212
                        if (wlc_hw->sih->bustype == PCI_BUS)
 
1213
                                ai_pci_down(wlc_hw->sih);
 
1214
                        wlc_bmac_xtal(wlc_hw, OFF);
 
1215
                }
 
1216
        }
 
1217
 
 
1218
        return callbacks;
 
1219
}
 
1220
 
 
1221
void wlc_bmac_wait_for_wake(struct wlc_hw_info *wlc_hw)
 
1222
{
 
1223
        /* delay before first read of ucode state */
 
1224
        udelay(40);
 
1225
 
 
1226
        /* wait until ucode is no longer asleep */
 
1227
        SPINWAIT((wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) ==
 
1228
                  DBGST_ASLEEP), wlc_hw->wlc->fastpwrup_dly);
 
1229
}
 
1230
 
 
1231
void wlc_bmac_hw_etheraddr(struct wlc_hw_info *wlc_hw, u8 *ea)
 
1232
{
 
1233
        memcpy(ea, wlc_hw->etheraddr, ETH_ALEN);
 
1234
}
 
1235
 
 
1236
static int wlc_bmac_bandtype(struct wlc_hw_info *wlc_hw)
 
1237
{
 
1238
        return wlc_hw->band->bandtype;
 
1239
}
 
1240
 
 
1241
/* control chip clock to save power, enable dynamic clock or force fast clock */
 
1242
static void wlc_clkctl_clk(struct wlc_hw_info *wlc_hw, uint mode)
 
1243
{
 
1244
        if (PMUCTL_ENAB(wlc_hw->sih)) {
 
1245
                /* new chips with PMU, CCS_FORCEHT will distribute the HT clock on backplane,
 
1246
                 *  but mac core will still run on ALP(not HT) when it enters powersave mode,
 
1247
                 *      which means the FCA bit may not be set.
 
1248
                 *      should wakeup mac if driver wants it to run on HT.
 
1249
                 */
 
1250
 
 
1251
                if (wlc_hw->clk) {
 
1252
                        if (mode == CLK_FAST) {
 
1253
                                OR_REG(&wlc_hw->regs->clk_ctl_st,
 
1254
                                       CCS_FORCEHT);
 
1255
 
 
1256
                                udelay(64);
 
1257
 
 
1258
                                SPINWAIT(((R_REG
 
1259
                                           (&wlc_hw->regs->
 
1260
                                            clk_ctl_st) & CCS_HTAVAIL) == 0),
 
1261
                                         PMU_MAX_TRANSITION_DLY);
 
1262
                                WARN_ON(!(R_REG
 
1263
                                          (&wlc_hw->regs->
 
1264
                                           clk_ctl_st) & CCS_HTAVAIL));
 
1265
                        } else {
 
1266
                                if ((wlc_hw->sih->pmurev == 0) &&
 
1267
                                    (R_REG
 
1268
                                     (&wlc_hw->regs->
 
1269
                                      clk_ctl_st) & (CCS_FORCEHT | CCS_HTAREQ)))
 
1270
                                        SPINWAIT(((R_REG
 
1271
                                                   (&wlc_hw->regs->
 
1272
                                                    clk_ctl_st) & CCS_HTAVAIL)
 
1273
                                                  == 0),
 
1274
                                                 PMU_MAX_TRANSITION_DLY);
 
1275
                                AND_REG(&wlc_hw->regs->clk_ctl_st,
 
1276
                                        ~CCS_FORCEHT);
 
1277
                        }
 
1278
                }
 
1279
                wlc_hw->forcefastclk = (mode == CLK_FAST);
 
1280
        } else {
 
1281
 
 
1282
                /* old chips w/o PMU, force HT through cc,
 
1283
                 * then use FCA to verify mac is running fast clock
 
1284
                 */
 
1285
 
 
1286
                wlc_hw->forcefastclk = ai_clkctl_cc(wlc_hw->sih, mode);
 
1287
 
 
1288
                /* check fast clock is available (if core is not in reset) */
 
1289
                if (wlc_hw->forcefastclk && wlc_hw->clk)
 
1290
                        WARN_ON(!(ai_core_sflags(wlc_hw->sih, 0, 0) &
 
1291
                                  SISF_FCLKA));
 
1292
 
 
1293
                /* keep the ucode wake bit on if forcefastclk is on
 
1294
                 * since we do not want ucode to put us back to slow clock
 
1295
                 * when it dozes for PM mode.
 
1296
                 * Code below matches the wake override bit with current forcefastclk state
 
1297
                 * Only setting bit in wake_override instead of waking ucode immediately
 
1298
                 * since old code (wlc.c 1.4499) had this behavior. Older code set
 
1299
                 * wlc->forcefastclk but only had the wake happen if the wakup_ucode work
 
1300
                 * (protected by an up check) was executed just below.
 
1301
                 */
 
1302
                if (wlc_hw->forcefastclk)
 
1303
                        mboolset(wlc_hw->wake_override,
 
1304
                                 WLC_WAKE_OVERRIDE_FORCEFAST);
 
1305
                else
 
1306
                        mboolclr(wlc_hw->wake_override,
 
1307
                                 WLC_WAKE_OVERRIDE_FORCEFAST);
 
1308
        }
 
1309
}
 
1310
 
 
1311
/* set initial host flags value */
 
1312
static void
 
1313
wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init)
 
1314
{
 
1315
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
1316
 
 
1317
        memset(mhfs, 0, MHFMAX * sizeof(u16));
 
1318
 
 
1319
        mhfs[MHF2] |= mhf2_init;
 
1320
 
 
1321
        /* prohibit use of slowclock on multifunction boards */
 
1322
        if (wlc_hw->boardflags & BFL_NOPLLDOWN)
 
1323
                mhfs[MHF1] |= MHF1_FORCEFASTCLK;
 
1324
 
 
1325
        if (WLCISNPHY(wlc_hw->band) && NREV_LT(wlc_hw->band->phyrev, 2)) {
 
1326
                mhfs[MHF2] |= MHF2_NPHY40MHZ_WAR;
 
1327
                mhfs[MHF1] |= MHF1_IQSWAP_WAR;
 
1328
        }
 
1329
}
 
1330
 
 
1331
/* set or clear ucode host flag bits
 
1332
 * it has an optimization for no-change write
 
1333
 * it only writes through shared memory when the core has clock;
 
1334
 * pre-CLK changes should use wlc_write_mhf to get around the optimization
 
1335
 *
 
1336
 *
 
1337
 * bands values are: WLC_BAND_AUTO <--- Current band only
 
1338
 *                   WLC_BAND_5G   <--- 5G band only
 
1339
 *                   WLC_BAND_2G   <--- 2G band only
 
1340
 *                   WLC_BAND_ALL  <--- All bands
 
1341
 */
 
1342
void
 
1343
wlc_bmac_mhf(struct wlc_hw_info *wlc_hw, u8 idx, u16 mask, u16 val,
 
1344
             int bands)
 
1345
{
 
1346
        u16 save;
 
1347
        u16 addr[MHFMAX] = {
 
1348
                M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
 
1349
                M_HOST_FLAGS5
 
1350
        };
 
1351
        struct wlc_hwband *band;
 
1352
 
 
1353
        if ((val & ~mask) || idx >= MHFMAX)
 
1354
                return; /* error condition */
 
1355
 
 
1356
        switch (bands) {
 
1357
                /* Current band only or all bands,
 
1358
                 * then set the band to current band
 
1359
                 */
 
1360
        case WLC_BAND_AUTO:
 
1361
        case WLC_BAND_ALL:
 
1362
                band = wlc_hw->band;
 
1363
                break;
 
1364
        case WLC_BAND_5G:
 
1365
                band = wlc_hw->bandstate[BAND_5G_INDEX];
 
1366
                break;
 
1367
        case WLC_BAND_2G:
 
1368
                band = wlc_hw->bandstate[BAND_2G_INDEX];
 
1369
                break;
 
1370
        default:
 
1371
                band = NULL;    /* error condition */
 
1372
        }
 
1373
 
 
1374
        if (band) {
 
1375
                save = band->mhfs[idx];
 
1376
                band->mhfs[idx] = (band->mhfs[idx] & ~mask) | val;
 
1377
 
 
1378
                /* optimization: only write through if changed, and
 
1379
                 * changed band is the current band
 
1380
                 */
 
1381
                if (wlc_hw->clk && (band->mhfs[idx] != save)
 
1382
                    && (band == wlc_hw->band))
 
1383
                        wlc_bmac_write_shm(wlc_hw, addr[idx],
 
1384
                                           (u16) band->mhfs[idx]);
 
1385
        }
 
1386
 
 
1387
        if (bands == WLC_BAND_ALL) {
 
1388
                wlc_hw->bandstate[0]->mhfs[idx] =
 
1389
                    (wlc_hw->bandstate[0]->mhfs[idx] & ~mask) | val;
 
1390
                wlc_hw->bandstate[1]->mhfs[idx] =
 
1391
                    (wlc_hw->bandstate[1]->mhfs[idx] & ~mask) | val;
 
1392
        }
 
1393
}
 
1394
 
 
1395
u16 wlc_bmac_mhf_get(struct wlc_hw_info *wlc_hw, u8 idx, int bands)
 
1396
{
 
1397
        struct wlc_hwband *band;
 
1398
 
 
1399
        if (idx >= MHFMAX)
 
1400
                return 0; /* error condition */
 
1401
        switch (bands) {
 
1402
        case WLC_BAND_AUTO:
 
1403
                band = wlc_hw->band;
 
1404
                break;
 
1405
        case WLC_BAND_5G:
 
1406
                band = wlc_hw->bandstate[BAND_5G_INDEX];
 
1407
                break;
 
1408
        case WLC_BAND_2G:
 
1409
                band = wlc_hw->bandstate[BAND_2G_INDEX];
 
1410
                break;
 
1411
        default:
 
1412
                band = NULL;            /* error condition */
 
1413
        }
 
1414
 
 
1415
        if (!band)
 
1416
                return 0;
 
1417
 
 
1418
        return band->mhfs[idx];
 
1419
}
 
1420
 
 
1421
static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs)
 
1422
{
 
1423
        u8 idx;
 
1424
        u16 addr[] = {
 
1425
                M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4,
 
1426
                M_HOST_FLAGS5
 
1427
        };
 
1428
 
 
1429
        for (idx = 0; idx < MHFMAX; idx++) {
 
1430
                wlc_bmac_write_shm(wlc_hw, addr[idx], mhfs[idx]);
 
1431
        }
 
1432
}
 
1433
 
 
1434
/* set the maccontrol register to desired reset state and
 
1435
 * initialize the sw cache of the register
 
1436
 */
 
1437
static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw)
 
1438
{
 
1439
        /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
 
1440
        wlc_hw->maccontrol = 0;
 
1441
        wlc_hw->suspended_fifos = 0;
 
1442
        wlc_hw->wake_override = 0;
 
1443
        wlc_hw->mute_override = 0;
 
1444
        wlc_bmac_mctrl(wlc_hw, ~0, MCTL_IHR_EN | MCTL_WAKE);
 
1445
}
 
1446
 
 
1447
/* set or clear maccontrol bits */
 
1448
void wlc_bmac_mctrl(struct wlc_hw_info *wlc_hw, u32 mask, u32 val)
 
1449
{
 
1450
        u32 maccontrol;
 
1451
        u32 new_maccontrol;
 
1452
 
 
1453
        if (val & ~mask)
 
1454
                return; /* error condition */
 
1455
        maccontrol = wlc_hw->maccontrol;
 
1456
        new_maccontrol = (maccontrol & ~mask) | val;
 
1457
 
 
1458
        /* if the new maccontrol value is the same as the old, nothing to do */
 
1459
        if (new_maccontrol == maccontrol)
 
1460
                return;
 
1461
 
 
1462
        /* something changed, cache the new value */
 
1463
        wlc_hw->maccontrol = new_maccontrol;
 
1464
 
 
1465
        /* write the new values with overrides applied */
 
1466
        wlc_mctrl_write(wlc_hw);
 
1467
}
 
1468
 
 
1469
/* write the software state of maccontrol and overrides to the maccontrol register */
 
1470
static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw)
 
1471
{
 
1472
        u32 maccontrol = wlc_hw->maccontrol;
 
1473
 
 
1474
        /* OR in the wake bit if overridden */
 
1475
        if (wlc_hw->wake_override)
 
1476
                maccontrol |= MCTL_WAKE;
 
1477
 
 
1478
        /* set AP and INFRA bits for mute if needed */
 
1479
        if (wlc_hw->mute_override) {
 
1480
                maccontrol &= ~(MCTL_AP);
 
1481
                maccontrol |= MCTL_INFRA;
 
1482
        }
 
1483
 
 
1484
        W_REG(&wlc_hw->regs->maccontrol, maccontrol);
 
1485
}
 
1486
 
 
1487
void wlc_ucode_wake_override_set(struct wlc_hw_info *wlc_hw, u32 override_bit)
 
1488
{
 
1489
        if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) {
 
1490
                mboolset(wlc_hw->wake_override, override_bit);
 
1491
                return;
 
1492
        }
 
1493
 
 
1494
        mboolset(wlc_hw->wake_override, override_bit);
 
1495
 
 
1496
        wlc_mctrl_write(wlc_hw);
 
1497
        wlc_bmac_wait_for_wake(wlc_hw);
 
1498
 
 
1499
        return;
 
1500
}
 
1501
 
 
1502
void wlc_ucode_wake_override_clear(struct wlc_hw_info *wlc_hw, u32 override_bit)
 
1503
{
 
1504
        mboolclr(wlc_hw->wake_override, override_bit);
 
1505
 
 
1506
        if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE))
 
1507
                return;
 
1508
 
 
1509
        wlc_mctrl_write(wlc_hw);
 
1510
 
 
1511
        return;
 
1512
}
 
1513
 
 
1514
/* When driver needs ucode to stop beaconing, it has to make sure that
 
1515
 * MCTL_AP is clear and MCTL_INFRA is set
 
1516
 * Mode           MCTL_AP        MCTL_INFRA
 
1517
 * AP                1              1
 
1518
 * STA               0              1 <--- This will ensure no beacons
 
1519
 * IBSS              0              0
 
1520
 */
 
1521
static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw)
 
1522
{
 
1523
        wlc_hw->mute_override = 1;
 
1524
 
 
1525
        /* if maccontrol already has AP == 0 and INFRA == 1 without this
 
1526
         * override, then there is no change to write
 
1527
         */
 
1528
        if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
 
1529
                return;
 
1530
 
 
1531
        wlc_mctrl_write(wlc_hw);
 
1532
 
 
1533
        return;
 
1534
}
 
1535
 
 
1536
/* Clear the override on AP and INFRA bits */
 
1537
static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw)
 
1538
{
 
1539
        if (wlc_hw->mute_override == 0)
 
1540
                return;
 
1541
 
 
1542
        wlc_hw->mute_override = 0;
 
1543
 
 
1544
        /* if maccontrol already has AP == 0 and INFRA == 1 without this
 
1545
         * override, then there is no change to write
 
1546
         */
 
1547
        if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA)
 
1548
                return;
 
1549
 
 
1550
        wlc_mctrl_write(wlc_hw);
 
1551
}
 
1552
 
 
1553
/*
 
1554
 * Write a MAC address to the given match reg offset in the RXE match engine.
 
1555
 */
 
1556
void
 
1557
wlc_bmac_set_addrmatch(struct wlc_hw_info *wlc_hw, int match_reg_offset,
 
1558
                       const u8 *addr)
 
1559
{
 
1560
        d11regs_t *regs;
 
1561
        u16 mac_l;
 
1562
        u16 mac_m;
 
1563
        u16 mac_h;
 
1564
 
 
1565
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d: wlc_bmac_set_addrmatch\n",
 
1566
                 wlc_hw->unit);
 
1567
 
 
1568
        regs = wlc_hw->regs;
 
1569
        mac_l = addr[0] | (addr[1] << 8);
 
1570
        mac_m = addr[2] | (addr[3] << 8);
 
1571
        mac_h = addr[4] | (addr[5] << 8);
 
1572
 
 
1573
        /* enter the MAC addr into the RXE match registers */
 
1574
        W_REG(&regs->rcm_ctl, RCM_INC_DATA | match_reg_offset);
 
1575
        W_REG(&regs->rcm_mat_data, mac_l);
 
1576
        W_REG(&regs->rcm_mat_data, mac_m);
 
1577
        W_REG(&regs->rcm_mat_data, mac_h);
 
1578
 
 
1579
}
 
1580
 
 
1581
void
 
1582
wlc_bmac_write_template_ram(struct wlc_hw_info *wlc_hw, int offset, int len,
 
1583
                            void *buf)
 
1584
{
 
1585
        d11regs_t *regs;
 
1586
        u32 word;
 
1587
        bool be_bit;
 
1588
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1589
 
 
1590
        regs = wlc_hw->regs;
 
1591
        W_REG(&regs->tplatewrptr, offset);
 
1592
 
 
1593
        /* if MCTL_BIGEND bit set in mac control register,
 
1594
         * the chip swaps data in fifo, as well as data in
 
1595
         * template ram
 
1596
         */
 
1597
        be_bit = (R_REG(&regs->maccontrol) & MCTL_BIGEND) != 0;
 
1598
 
 
1599
        while (len > 0) {
 
1600
                memcpy(&word, buf, sizeof(u32));
 
1601
 
 
1602
                if (be_bit)
 
1603
                        word = cpu_to_be32(word);
 
1604
                else
 
1605
                        word = cpu_to_le32(word);
 
1606
 
 
1607
                W_REG(&regs->tplatewrdata, word);
 
1608
 
 
1609
                buf = (u8 *) buf + sizeof(u32);
 
1610
                len -= sizeof(u32);
 
1611
        }
 
1612
}
 
1613
 
 
1614
void wlc_bmac_set_cwmin(struct wlc_hw_info *wlc_hw, u16 newmin)
 
1615
{
 
1616
        wlc_hw->band->CWmin = newmin;
 
1617
 
 
1618
        W_REG(&wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMIN);
 
1619
        (void)R_REG(&wlc_hw->regs->objaddr);
 
1620
        W_REG(&wlc_hw->regs->objdata, newmin);
 
1621
}
 
1622
 
 
1623
void wlc_bmac_set_cwmax(struct wlc_hw_info *wlc_hw, u16 newmax)
 
1624
{
 
1625
        wlc_hw->band->CWmax = newmax;
 
1626
 
 
1627
        W_REG(&wlc_hw->regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_CWMAX);
 
1628
        (void)R_REG(&wlc_hw->regs->objaddr);
 
1629
        W_REG(&wlc_hw->regs->objdata, newmax);
 
1630
}
 
1631
 
 
1632
void wlc_bmac_bw_set(struct wlc_hw_info *wlc_hw, u16 bw)
 
1633
{
 
1634
        bool fastclk;
 
1635
 
 
1636
        /* request FAST clock if not on */
 
1637
        fastclk = wlc_hw->forcefastclk;
 
1638
        if (!fastclk)
 
1639
                wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
1640
 
 
1641
        wlc_phy_bw_state_set(wlc_hw->band->pi, bw);
 
1642
 
 
1643
        wlc_bmac_phy_reset(wlc_hw);
 
1644
        wlc_phy_init(wlc_hw->band->pi, wlc_phy_chanspec_get(wlc_hw->band->pi));
 
1645
 
 
1646
        /* restore the clk */
 
1647
        if (!fastclk)
 
1648
                wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
 
1649
}
 
1650
 
 
1651
static void
 
1652
wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn, int len)
 
1653
{
 
1654
        d11regs_t *regs = wlc_hw->regs;
 
1655
 
 
1656
        wlc_bmac_write_template_ram(wlc_hw, T_BCN0_TPL_BASE, (len + 3) & ~3,
 
1657
                                    bcn);
 
1658
        /* write beacon length to SCR */
 
1659
        wlc_bmac_write_shm(wlc_hw, M_BCN0_FRM_BYTESZ, (u16) len);
 
1660
        /* mark beacon0 valid */
 
1661
        OR_REG(&regs->maccommand, MCMD_BCN0VLD);
 
1662
}
 
1663
 
 
1664
static void
 
1665
wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn, int len)
 
1666
{
 
1667
        d11regs_t *regs = wlc_hw->regs;
 
1668
 
 
1669
        wlc_bmac_write_template_ram(wlc_hw, T_BCN1_TPL_BASE, (len + 3) & ~3,
 
1670
                                    bcn);
 
1671
        /* write beacon length to SCR */
 
1672
        wlc_bmac_write_shm(wlc_hw, M_BCN1_FRM_BYTESZ, (u16) len);
 
1673
        /* mark beacon1 valid */
 
1674
        OR_REG(&regs->maccommand, MCMD_BCN1VLD);
 
1675
}
 
1676
 
 
1677
/* mac is assumed to be suspended at this point */
 
1678
void
 
1679
wlc_bmac_write_hw_bcntemplates(struct wlc_hw_info *wlc_hw, void *bcn, int len,
 
1680
                               bool both)
 
1681
{
 
1682
        d11regs_t *regs = wlc_hw->regs;
 
1683
 
 
1684
        if (both) {
 
1685
                wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
 
1686
                wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
 
1687
        } else {
 
1688
                /* bcn 0 */
 
1689
                if (!(R_REG(&regs->maccommand) & MCMD_BCN0VLD))
 
1690
                        wlc_write_hw_bcntemplate0(wlc_hw, bcn, len);
 
1691
                /* bcn 1 */
 
1692
                else if (!
 
1693
                         (R_REG(&regs->maccommand) & MCMD_BCN1VLD))
 
1694
                        wlc_write_hw_bcntemplate1(wlc_hw, bcn, len);
 
1695
        }
 
1696
}
 
1697
 
 
1698
static void WLBANDINITFN(wlc_bmac_upd_synthpu) (struct wlc_hw_info *wlc_hw)
 
1699
{
 
1700
        u16 v;
 
1701
        struct wlc_info *wlc = wlc_hw->wlc;
 
1702
        /* update SYNTHPU_DLY */
 
1703
 
 
1704
        if (WLCISLCNPHY(wlc->band)) {
 
1705
                v = SYNTHPU_DLY_LPPHY_US;
 
1706
        } else if (WLCISNPHY(wlc->band) && (NREV_GE(wlc->band->phyrev, 3))) {
 
1707
                v = SYNTHPU_DLY_NPHY_US;
 
1708
        } else {
 
1709
                v = SYNTHPU_DLY_BPHY_US;
 
1710
        }
 
1711
 
 
1712
        wlc_bmac_write_shm(wlc_hw, M_SYNTHPU_DLY, v);
 
1713
}
 
1714
 
 
1715
/* band-specific init */
 
1716
static void
 
1717
WLBANDINITFN(wlc_bmac_bsinit) (struct wlc_info *wlc, chanspec_t chanspec)
 
1718
{
 
1719
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
1720
 
 
1721
        BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
 
1722
                wlc_hw->band->bandunit);
 
1723
 
 
1724
        wlc_ucode_bsinit(wlc_hw);
 
1725
 
 
1726
        wlc_phy_init(wlc_hw->band->pi, chanspec);
 
1727
 
 
1728
        wlc_ucode_txant_set(wlc_hw);
 
1729
 
 
1730
        /* cwmin is band-specific, update hardware with value for current band */
 
1731
        wlc_bmac_set_cwmin(wlc_hw, wlc_hw->band->CWmin);
 
1732
        wlc_bmac_set_cwmax(wlc_hw, wlc_hw->band->CWmax);
 
1733
 
 
1734
        wlc_bmac_update_slot_timing(wlc_hw,
 
1735
                                    BAND_5G(wlc_hw->band->
 
1736
                                            bandtype) ? true : wlc_hw->
 
1737
                                    shortslot);
 
1738
 
 
1739
        /* write phytype and phyvers */
 
1740
        wlc_bmac_write_shm(wlc_hw, M_PHYTYPE, (u16) wlc_hw->band->phytype);
 
1741
        wlc_bmac_write_shm(wlc_hw, M_PHYVER, (u16) wlc_hw->band->phyrev);
 
1742
 
 
1743
        /* initialize the txphyctl1 rate table since shmem is shared between bands */
 
1744
        wlc_upd_ofdm_pctl1_table(wlc_hw);
 
1745
 
 
1746
        wlc_bmac_upd_synthpu(wlc_hw);
 
1747
}
 
1748
 
 
1749
static void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk)
 
1750
{
 
1751
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d: clk %d\n", wlc_hw->unit, clk);
 
1752
 
 
1753
        wlc_hw->phyclk = clk;
 
1754
 
 
1755
        if (OFF == clk) {       /* clear gmode bit, put phy into reset */
 
1756
 
 
1757
                ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC | SICF_GMODE),
 
1758
                               (SICF_PRST | SICF_FGC));
 
1759
                udelay(1);
 
1760
                ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_PRST);
 
1761
                udelay(1);
 
1762
 
 
1763
        } else {                /* take phy out of reset */
 
1764
 
 
1765
                ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_FGC);
 
1766
                udelay(1);
 
1767
                ai_core_cflags(wlc_hw->sih, (SICF_FGC), 0);
 
1768
                udelay(1);
 
1769
 
 
1770
        }
 
1771
}
 
1772
 
 
1773
/* Perform a soft reset of the PHY PLL */
 
1774
void wlc_bmac_core_phypll_reset(struct wlc_hw_info *wlc_hw)
 
1775
{
 
1776
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1777
 
 
1778
        ai_corereg(wlc_hw->sih, SI_CC_IDX,
 
1779
                   offsetof(chipcregs_t, chipcontrol_addr), ~0, 0);
 
1780
        udelay(1);
 
1781
        ai_corereg(wlc_hw->sih, SI_CC_IDX,
 
1782
                   offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
 
1783
        udelay(1);
 
1784
        ai_corereg(wlc_hw->sih, SI_CC_IDX,
 
1785
                   offsetof(chipcregs_t, chipcontrol_data), 0x4, 4);
 
1786
        udelay(1);
 
1787
        ai_corereg(wlc_hw->sih, SI_CC_IDX,
 
1788
                   offsetof(chipcregs_t, chipcontrol_data), 0x4, 0);
 
1789
        udelay(1);
 
1790
}
 
1791
 
 
1792
/* light way to turn on phy clock without reset for NPHY only
 
1793
 *  refer to wlc_bmac_core_phy_clk for full version
 
1794
 */
 
1795
void wlc_bmac_phyclk_fgc(struct wlc_hw_info *wlc_hw, bool clk)
 
1796
{
 
1797
        /* support(necessary for NPHY and HYPHY) only */
 
1798
        if (!WLCISNPHY(wlc_hw->band))
 
1799
                return;
 
1800
 
 
1801
        if (ON == clk)
 
1802
                ai_core_cflags(wlc_hw->sih, SICF_FGC, SICF_FGC);
 
1803
        else
 
1804
                ai_core_cflags(wlc_hw->sih, SICF_FGC, 0);
 
1805
 
 
1806
}
 
1807
 
 
1808
void wlc_bmac_macphyclk_set(struct wlc_hw_info *wlc_hw, bool clk)
 
1809
{
 
1810
        if (ON == clk)
 
1811
                ai_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE);
 
1812
        else
 
1813
                ai_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0);
 
1814
}
 
1815
 
 
1816
void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw)
 
1817
{
 
1818
        wlc_phy_t *pih = wlc_hw->band->pi;
 
1819
        u32 phy_bw_clkbits;
 
1820
        bool phy_in_reset = false;
 
1821
 
 
1822
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
1823
 
 
1824
        if (pih == NULL)
 
1825
                return;
 
1826
 
 
1827
        phy_bw_clkbits = wlc_phy_clk_bwbits(wlc_hw->band->pi);
 
1828
 
 
1829
        /* Specific reset sequence required for NPHY rev 3 and 4 */
 
1830
        if (WLCISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) &&
 
1831
            NREV_LE(wlc_hw->band->phyrev, 4)) {
 
1832
                /* Set the PHY bandwidth */
 
1833
                ai_core_cflags(wlc_hw->sih, SICF_BWMASK, phy_bw_clkbits);
 
1834
 
 
1835
                udelay(1);
 
1836
 
 
1837
                /* Perform a soft reset of the PHY PLL */
 
1838
                wlc_bmac_core_phypll_reset(wlc_hw);
 
1839
 
 
1840
                /* reset the PHY */
 
1841
                ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_PCLKE),
 
1842
                               (SICF_PRST | SICF_PCLKE));
 
1843
                phy_in_reset = true;
 
1844
        } else {
 
1845
 
 
1846
                ai_core_cflags(wlc_hw->sih,
 
1847
                               (SICF_PRST | SICF_PCLKE | SICF_BWMASK),
 
1848
                               (SICF_PRST | SICF_PCLKE | phy_bw_clkbits));
 
1849
        }
 
1850
 
 
1851
        udelay(2);
 
1852
        wlc_bmac_core_phy_clk(wlc_hw, ON);
 
1853
 
 
1854
        if (pih)
 
1855
                wlc_phy_anacore(pih, ON);
 
1856
}
 
1857
 
 
1858
/* switch to and initialize new band */
 
1859
static void
 
1860
WLBANDINITFN(wlc_bmac_setband) (struct wlc_hw_info *wlc_hw, uint bandunit,
 
1861
                                chanspec_t chanspec) {
 
1862
        struct wlc_info *wlc = wlc_hw->wlc;
 
1863
        u32 macintmask;
 
1864
 
 
1865
        /* Enable the d11 core before accessing it */
 
1866
        if (!ai_iscoreup(wlc_hw->sih)) {
 
1867
                ai_core_reset(wlc_hw->sih, 0, 0);
 
1868
                wlc_mctrl_reset(wlc_hw);
 
1869
        }
 
1870
 
 
1871
        macintmask = wlc_setband_inact(wlc, bandunit);
 
1872
 
 
1873
        if (!wlc_hw->up)
 
1874
                return;
 
1875
 
 
1876
        wlc_bmac_core_phy_clk(wlc_hw, ON);
 
1877
 
 
1878
        /* band-specific initializations */
 
1879
        wlc_bmac_bsinit(wlc, chanspec);
 
1880
 
 
1881
        /*
 
1882
         * If there are any pending software interrupt bits,
 
1883
         * then replace these with a harmless nonzero value
 
1884
         * so wlc_dpc() will re-enable interrupts when done.
 
1885
         */
 
1886
        if (wlc->macintstatus)
 
1887
                wlc->macintstatus = MI_DMAINT;
 
1888
 
 
1889
        /* restore macintmask */
 
1890
        wl_intrsrestore(wlc->wl, macintmask);
 
1891
 
 
1892
        /* ucode should still be suspended.. */
 
1893
        WARN_ON((R_REG(&wlc_hw->regs->maccontrol) & MCTL_EN_MAC) != 0);
 
1894
}
 
1895
 
 
1896
/* low-level band switch utility routine */
 
1897
void WLBANDINITFN(wlc_setxband) (struct wlc_hw_info *wlc_hw, uint bandunit)
 
1898
{
 
1899
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
 
1900
                bandunit);
 
1901
 
 
1902
        wlc_hw->band = wlc_hw->bandstate[bandunit];
 
1903
 
 
1904
        /* BMAC_NOTE: until we eliminate need for wlc->band refs in low level code */
 
1905
        wlc_hw->wlc->band = wlc_hw->wlc->bandstate[bandunit];
 
1906
 
 
1907
        /* set gmode core flag */
 
1908
        if (wlc_hw->sbclk && !wlc_hw->noreset) {
 
1909
                ai_core_cflags(wlc_hw->sih, SICF_GMODE,
 
1910
                               ((bandunit == 0) ? SICF_GMODE : 0));
 
1911
        }
 
1912
}
 
1913
 
 
1914
static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw)
 
1915
{
 
1916
 
 
1917
        /* reject unsupported corerev */
 
1918
        if (!VALID_COREREV(wlc_hw->corerev)) {
 
1919
                wiphy_err(wlc_hw->wlc->wiphy, "unsupported core rev %d\n",
 
1920
                          wlc_hw->corerev);
 
1921
                return false;
 
1922
        }
 
1923
 
 
1924
        return true;
 
1925
}
 
1926
 
 
1927
static bool wlc_validboardtype(struct wlc_hw_info *wlc_hw)
 
1928
{
 
1929
        bool goodboard = true;
 
1930
        uint boardrev = wlc_hw->boardrev;
 
1931
 
 
1932
        if (boardrev == 0)
 
1933
                goodboard = false;
 
1934
        else if (boardrev > 0xff) {
 
1935
                uint brt = (boardrev & 0xf000) >> 12;
 
1936
                uint b0 = (boardrev & 0xf00) >> 8;
 
1937
                uint b1 = (boardrev & 0xf0) >> 4;
 
1938
                uint b2 = boardrev & 0xf;
 
1939
 
 
1940
                if ((brt > 2) || (brt == 0) || (b0 > 9) || (b0 == 0) || (b1 > 9)
 
1941
                    || (b2 > 9))
 
1942
                        goodboard = false;
 
1943
        }
 
1944
 
 
1945
        if (wlc_hw->sih->boardvendor != PCI_VENDOR_ID_BROADCOM)
 
1946
                return goodboard;
 
1947
 
 
1948
        return goodboard;
 
1949
}
 
1950
 
 
1951
static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw)
 
1952
{
 
1953
        const char *varname = "macaddr";
 
1954
        char *macaddr;
 
1955
 
 
1956
        /* If macaddr exists, use it (Sromrev4, CIS, ...). */
 
1957
        macaddr = getvar(wlc_hw->vars, varname);
 
1958
        if (macaddr != NULL)
 
1959
                return macaddr;
 
1960
 
 
1961
        if (NBANDS_HW(wlc_hw) > 1)
 
1962
                varname = "et1macaddr";
 
1963
        else
 
1964
                varname = "il0macaddr";
 
1965
 
 
1966
        macaddr = getvar(wlc_hw->vars, varname);
 
1967
        if (macaddr == NULL) {
 
1968
                wiphy_err(wlc_hw->wlc->wiphy, "wl%d: wlc_get_macaddr: macaddr "
 
1969
                          "getvar(%s) not found\n", wlc_hw->unit, varname);
 
1970
        }
 
1971
 
 
1972
        return macaddr;
 
1973
}
 
1974
 
 
1975
/*
 
1976
 * Return true if radio is disabled, otherwise false.
 
1977
 * hw radio disable signal is an external pin, users activate it asynchronously
 
1978
 * this function could be called when driver is down and w/o clock
 
1979
 * it operates on different registers depending on corerev and boardflag.
 
1980
 */
 
1981
bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info *wlc_hw)
 
1982
{
 
1983
        bool v, clk, xtal;
 
1984
        u32 resetbits = 0, flags = 0;
 
1985
 
 
1986
        xtal = wlc_hw->sbclk;
 
1987
        if (!xtal)
 
1988
                wlc_bmac_xtal(wlc_hw, ON);
 
1989
 
 
1990
        /* may need to take core out of reset first */
 
1991
        clk = wlc_hw->clk;
 
1992
        if (!clk) {
 
1993
                /*
 
1994
                 * mac no longer enables phyclk automatically when driver
 
1995
                 * accesses phyreg throughput mac. This can be skipped since
 
1996
                 * only mac reg is accessed below
 
1997
                 */
 
1998
                flags |= SICF_PCLKE;
 
1999
 
 
2000
                /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
 
2001
                if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
 
2002
                    (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
 
2003
                    (wlc_hw->sih->chip == BCM43421_CHIP_ID))
 
2004
                        wlc_hw->regs =
 
2005
                            (d11regs_t *) ai_setcore(wlc_hw->sih, D11_CORE_ID,
 
2006
                                                     0);
 
2007
                ai_core_reset(wlc_hw->sih, flags, resetbits);
 
2008
                wlc_mctrl_reset(wlc_hw);
 
2009
        }
 
2010
 
 
2011
        v = ((R_REG(&wlc_hw->regs->phydebug) & PDBG_RFD) != 0);
 
2012
 
 
2013
        /* put core back into reset */
 
2014
        if (!clk)
 
2015
                ai_core_disable(wlc_hw->sih, 0);
 
2016
 
 
2017
        if (!xtal)
 
2018
                wlc_bmac_xtal(wlc_hw, OFF);
 
2019
 
 
2020
        return v;
 
2021
}
 
2022
 
 
2023
/* Initialize just the hardware when coming out of POR or S3/S5 system states */
 
2024
void wlc_bmac_hw_up(struct wlc_hw_info *wlc_hw)
 
2025
{
 
2026
        if (wlc_hw->wlc->pub->hw_up)
 
2027
                return;
 
2028
 
 
2029
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
2030
 
 
2031
        /*
 
2032
         * Enable pll and xtal, initialize the power control registers,
 
2033
         * and force fastclock for the remainder of wlc_up().
 
2034
         */
 
2035
        wlc_bmac_xtal(wlc_hw, ON);
 
2036
        ai_clkctl_init(wlc_hw->sih);
 
2037
        wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
2038
 
 
2039
        if (wlc_hw->sih->bustype == PCI_BUS) {
 
2040
                ai_pci_fixcfg(wlc_hw->sih);
 
2041
 
 
2042
                /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
 
2043
                if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
 
2044
                    (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
 
2045
                    (wlc_hw->sih->chip == BCM43421_CHIP_ID))
 
2046
                        wlc_hw->regs =
 
2047
                            (d11regs_t *) ai_setcore(wlc_hw->sih, D11_CORE_ID,
 
2048
                                                     0);
 
2049
        }
 
2050
 
 
2051
        /* Inform phy that a POR reset has occurred so it does a complete phy init */
 
2052
        wlc_phy_por_inform(wlc_hw->band->pi);
 
2053
 
 
2054
        wlc_hw->ucode_loaded = false;
 
2055
        wlc_hw->wlc->pub->hw_up = true;
 
2056
 
 
2057
        if ((wlc_hw->boardflags & BFL_FEM)
 
2058
            && (wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
 
2059
                if (!
 
2060
                    (wlc_hw->boardrev >= 0x1250
 
2061
                     && (wlc_hw->boardflags & BFL_FEM_BT)))
 
2062
                        ai_epa_4313war(wlc_hw->sih);
 
2063
        }
 
2064
}
 
2065
 
 
2066
static bool wlc_dma_rxreset(struct wlc_hw_info *wlc_hw, uint fifo)
 
2067
{
 
2068
        struct hnddma_pub *di = wlc_hw->di[fifo];
 
2069
        return dma_rxreset(di);
 
2070
}
 
2071
 
 
2072
/* d11 core reset
 
2073
 *   ensure fask clock during reset
 
2074
 *   reset dma
 
2075
 *   reset d11(out of reset)
 
2076
 *   reset phy(out of reset)
 
2077
 *   clear software macintstatus for fresh new start
 
2078
 * one testing hack wlc_hw->noreset will bypass the d11/phy reset
 
2079
 */
 
2080
void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags)
 
2081
{
 
2082
        d11regs_t *regs;
 
2083
        uint i;
 
2084
        bool fastclk;
 
2085
        u32 resetbits = 0;
 
2086
 
 
2087
        if (flags == WLC_USE_COREFLAGS)
 
2088
                flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0);
 
2089
 
 
2090
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
2091
 
 
2092
        regs = wlc_hw->regs;
 
2093
 
 
2094
        /* request FAST clock if not on  */
 
2095
        fastclk = wlc_hw->forcefastclk;
 
2096
        if (!fastclk)
 
2097
                wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
2098
 
 
2099
        /* reset the dma engines except first time thru */
 
2100
        if (ai_iscoreup(wlc_hw->sih)) {
 
2101
                for (i = 0; i < NFIFO; i++)
 
2102
                        if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) {
 
2103
                                wiphy_err(wlc_hw->wlc->wiphy, "wl%d: %s: "
 
2104
                                          "dma_txreset[%d]: cannot stop dma\n",
 
2105
                                           wlc_hw->unit, __func__, i);
 
2106
                        }
 
2107
 
 
2108
                if ((wlc_hw->di[RX_FIFO])
 
2109
                    && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) {
 
2110
                        wiphy_err(wlc_hw->wlc->wiphy, "wl%d: %s: dma_rxreset"
 
2111
                                  "[%d]: cannot stop dma\n",
 
2112
                                  wlc_hw->unit, __func__, RX_FIFO);
 
2113
                }
 
2114
        }
 
2115
        /* if noreset, just stop the psm and return */
 
2116
        if (wlc_hw->noreset) {
 
2117
                wlc_hw->wlc->macintstatus = 0;  /* skip wl_dpc after down */
 
2118
                wlc_bmac_mctrl(wlc_hw, MCTL_PSM_RUN | MCTL_EN_MAC, 0);
 
2119
                return;
 
2120
        }
 
2121
 
 
2122
        /*
 
2123
         * mac no longer enables phyclk automatically when driver accesses
 
2124
         * phyreg throughput mac, AND phy_reset is skipped at early stage when
 
2125
         * band->pi is invalid. need to enable PHY CLK
 
2126
         */
 
2127
        flags |= SICF_PCLKE;
 
2128
 
 
2129
        /* reset the core
 
2130
         * In chips with PMU, the fastclk request goes through d11 core reg 0x1e0, which
 
2131
         *  is cleared by the core_reset. have to re-request it.
 
2132
         *  This adds some delay and we can optimize it by also requesting fastclk through
 
2133
         *  chipcommon during this period if necessary. But that has to work coordinate
 
2134
         *  with other driver like mips/arm since they may touch chipcommon as well.
 
2135
         */
 
2136
        wlc_hw->clk = false;
 
2137
        ai_core_reset(wlc_hw->sih, flags, resetbits);
 
2138
        wlc_hw->clk = true;
 
2139
        if (wlc_hw->band && wlc_hw->band->pi)
 
2140
                wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true);
 
2141
 
 
2142
        wlc_mctrl_reset(wlc_hw);
 
2143
 
 
2144
        if (PMUCTL_ENAB(wlc_hw->sih))
 
2145
                wlc_clkctl_clk(wlc_hw, CLK_FAST);
 
2146
 
 
2147
        wlc_bmac_phy_reset(wlc_hw);
 
2148
 
 
2149
        /* turn on PHY_PLL */
 
2150
        wlc_bmac_core_phypll_ctl(wlc_hw, true);
 
2151
 
 
2152
        /* clear sw intstatus */
 
2153
        wlc_hw->wlc->macintstatus = 0;
 
2154
 
 
2155
        /* restore the clk setting */
 
2156
        if (!fastclk)
 
2157
                wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
 
2158
}
 
2159
 
 
2160
/* txfifo sizes needs to be modified(increased) since the newer cores
 
2161
 * have more memory.
 
2162
 */
 
2163
static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw)
 
2164
{
 
2165
        d11regs_t *regs = wlc_hw->regs;
 
2166
        u16 fifo_nu;
 
2167
        u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk;
 
2168
        u16 txfifo_def, txfifo_def1;
 
2169
        u16 txfifo_cmd;
 
2170
 
 
2171
        /* tx fifos start at TXFIFO_START_BLK from the Base address */
 
2172
        txfifo_startblk = TXFIFO_START_BLK;
 
2173
 
 
2174
        /* sequence of operations:  reset fifo, set fifo size, reset fifo */
 
2175
        for (fifo_nu = 0; fifo_nu < NFIFO; fifo_nu++) {
 
2176
 
 
2177
                txfifo_endblk = txfifo_startblk + wlc_hw->xmtfifo_sz[fifo_nu];
 
2178
                txfifo_def = (txfifo_startblk & 0xff) |
 
2179
                    (((txfifo_endblk - 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT);
 
2180
                txfifo_def1 = ((txfifo_startblk >> 8) & 0x1) |
 
2181
                    ((((txfifo_endblk -
 
2182
                        1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT);
 
2183
                txfifo_cmd =
 
2184
                    TXFIFOCMD_RESET_MASK | (fifo_nu << TXFIFOCMD_FIFOSEL_SHIFT);
 
2185
 
 
2186
                W_REG(&regs->xmtfifocmd, txfifo_cmd);
 
2187
                W_REG(&regs->xmtfifodef, txfifo_def);
 
2188
                W_REG(&regs->xmtfifodef1, txfifo_def1);
 
2189
 
 
2190
                W_REG(&regs->xmtfifocmd, txfifo_cmd);
 
2191
 
 
2192
                txfifo_startblk += wlc_hw->xmtfifo_sz[fifo_nu];
 
2193
        }
 
2194
        /*
 
2195
         * need to propagate to shm location to be in sync since ucode/hw won't
 
2196
         * do this
 
2197
         */
 
2198
        wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE0,
 
2199
                           wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]);
 
2200
        wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE1,
 
2201
                           wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]);
 
2202
        wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE2,
 
2203
                           ((wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO] << 8) | wlc_hw->
 
2204
                            xmtfifo_sz[TX_AC_BK_FIFO]));
 
2205
        wlc_bmac_write_shm(wlc_hw, M_FIFOSIZE3,
 
2206
                           ((wlc_hw->xmtfifo_sz[TX_ATIM_FIFO] << 8) | wlc_hw->
 
2207
                            xmtfifo_sz[TX_BCMC_FIFO]));
 
2208
}
 
2209
 
 
2210
/* d11 core init
 
2211
 *   reset PSM
 
2212
 *   download ucode/PCM
 
2213
 *   let ucode run to suspended
 
2214
 *   download ucode inits
 
2215
 *   config other core registers
 
2216
 *   init dma
 
2217
 */
 
2218
static void wlc_coreinit(struct wlc_info *wlc)
 
2219
{
 
2220
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
2221
        d11regs_t *regs;
 
2222
        u32 sflags;
 
2223
        uint bcnint_us;
 
2224
        uint i = 0;
 
2225
        bool fifosz_fixup = false;
 
2226
        int err = 0;
 
2227
        u16 buf[NFIFO];
 
2228
        struct wiphy *wiphy = wlc->wiphy;
 
2229
 
 
2230
        regs = wlc_hw->regs;
 
2231
 
 
2232
        BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
2233
 
 
2234
        /* reset PSM */
 
2235
        wlc_bmac_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE));
 
2236
 
 
2237
        wlc_ucode_download(wlc_hw);
 
2238
        /*
 
2239
         * FIFOSZ fixup. driver wants to controls the fifo allocation.
 
2240
         */
 
2241
        fifosz_fixup = true;
 
2242
 
 
2243
        /* let the PSM run to the suspended state, set mode to BSS STA */
 
2244
        W_REG(&regs->macintstatus, -1);
 
2245
        wlc_bmac_mctrl(wlc_hw, ~0,
 
2246
                       (MCTL_IHR_EN | MCTL_INFRA | MCTL_PSM_RUN | MCTL_WAKE));
 
2247
 
 
2248
        /* wait for ucode to self-suspend after auto-init */
 
2249
        SPINWAIT(((R_REG(&regs->macintstatus) & MI_MACSSPNDD) == 0),
 
2250
                 1000 * 1000);
 
2251
        if ((R_REG(&regs->macintstatus) & MI_MACSSPNDD) == 0)
 
2252
                wiphy_err(wiphy, "wl%d: wlc_coreinit: ucode did not self-"
 
2253
                          "suspend!\n", wlc_hw->unit);
 
2254
 
 
2255
        wlc_gpio_init(wlc);
 
2256
 
 
2257
        sflags = ai_core_sflags(wlc_hw->sih, 0, 0);
 
2258
 
 
2259
        if (D11REV_IS(wlc_hw->corerev, 23)) {
 
2260
                if (WLCISNPHY(wlc_hw->band))
 
2261
                        wlc_write_inits(wlc_hw, d11n0initvals16);
 
2262
                else
 
2263
                        wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev"
 
2264
                                  " %d\n", __func__, wlc_hw->unit,
 
2265
                                  wlc_hw->corerev);
 
2266
        } else if (D11REV_IS(wlc_hw->corerev, 24)) {
 
2267
                if (WLCISLCNPHY(wlc_hw->band)) {
 
2268
                        wlc_write_inits(wlc_hw, d11lcn0initvals24);
 
2269
                } else {
 
2270
                        wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev"
 
2271
                                  " %d\n", __func__, wlc_hw->unit,
 
2272
                                  wlc_hw->corerev);
 
2273
                }
 
2274
        } else {
 
2275
                wiphy_err(wiphy, "%s: wl%d: unsupported corerev %d\n",
 
2276
                          __func__, wlc_hw->unit, wlc_hw->corerev);
 
2277
        }
 
2278
 
 
2279
        /* For old ucode, txfifo sizes needs to be modified(increased) */
 
2280
        if (fifosz_fixup == true) {
 
2281
                wlc_corerev_fifofixup(wlc_hw);
 
2282
        }
 
2283
 
 
2284
        /* check txfifo allocations match between ucode and driver */
 
2285
        buf[TX_AC_BE_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE0);
 
2286
        if (buf[TX_AC_BE_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]) {
 
2287
                i = TX_AC_BE_FIFO;
 
2288
                err = -1;
 
2289
        }
 
2290
        buf[TX_AC_VI_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE1);
 
2291
        if (buf[TX_AC_VI_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]) {
 
2292
                i = TX_AC_VI_FIFO;
 
2293
                err = -1;
 
2294
        }
 
2295
        buf[TX_AC_BK_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE2);
 
2296
        buf[TX_AC_VO_FIFO] = (buf[TX_AC_BK_FIFO] >> 8) & 0xff;
 
2297
        buf[TX_AC_BK_FIFO] &= 0xff;
 
2298
        if (buf[TX_AC_BK_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BK_FIFO]) {
 
2299
                i = TX_AC_BK_FIFO;
 
2300
                err = -1;
 
2301
        }
 
2302
        if (buf[TX_AC_VO_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO]) {
 
2303
                i = TX_AC_VO_FIFO;
 
2304
                err = -1;
 
2305
        }
 
2306
        buf[TX_BCMC_FIFO] = wlc_bmac_read_shm(wlc_hw, M_FIFOSIZE3);
 
2307
        buf[TX_ATIM_FIFO] = (buf[TX_BCMC_FIFO] >> 8) & 0xff;
 
2308
        buf[TX_BCMC_FIFO] &= 0xff;
 
2309
        if (buf[TX_BCMC_FIFO] != wlc_hw->xmtfifo_sz[TX_BCMC_FIFO]) {
 
2310
                i = TX_BCMC_FIFO;
 
2311
                err = -1;
 
2312
        }
 
2313
        if (buf[TX_ATIM_FIFO] != wlc_hw->xmtfifo_sz[TX_ATIM_FIFO]) {
 
2314
                i = TX_ATIM_FIFO;
 
2315
                err = -1;
 
2316
        }
 
2317
        if (err != 0) {
 
2318
                wiphy_err(wiphy, "wlc_coreinit: txfifo mismatch: ucode size %d"
 
2319
                          " driver size %d index %d\n", buf[i],
 
2320
                          wlc_hw->xmtfifo_sz[i], i);
 
2321
        }
 
2322
 
 
2323
        /* make sure we can still talk to the mac */
 
2324
        WARN_ON(R_REG(&regs->maccontrol) == 0xffffffff);
 
2325
 
 
2326
        /* band-specific inits done by wlc_bsinit() */
 
2327
 
 
2328
        /* Set up frame burst size and antenna swap threshold init values */
 
2329
        wlc_bmac_write_shm(wlc_hw, M_MBURST_SIZE, MAXTXFRAMEBURST);
 
2330
        wlc_bmac_write_shm(wlc_hw, M_MAX_ANTCNT, ANTCNT);
 
2331
 
 
2332
        /* enable one rx interrupt per received frame */
 
2333
        W_REG(&regs->intrcvlazy[0], (1 << IRL_FC_SHIFT));
 
2334
 
 
2335
        /* set the station mode (BSS STA) */
 
2336
        wlc_bmac_mctrl(wlc_hw,
 
2337
                       (MCTL_INFRA | MCTL_DISCARD_PMQ | MCTL_AP),
 
2338
                       (MCTL_INFRA | MCTL_DISCARD_PMQ));
 
2339
 
 
2340
        /* set up Beacon interval */
 
2341
        bcnint_us = 0x8000 << 10;
 
2342
        W_REG(&regs->tsf_cfprep, (bcnint_us << CFPREP_CBI_SHIFT));
 
2343
        W_REG(&regs->tsf_cfpstart, bcnint_us);
 
2344
        W_REG(&regs->macintstatus, MI_GP1);
 
2345
 
 
2346
        /* write interrupt mask */
 
2347
        W_REG(&regs->intctrlregs[RX_FIFO].intmask, DEF_RXINTMASK);
 
2348
 
 
2349
        /* allow the MAC to control the PHY clock (dynamic on/off) */
 
2350
        wlc_bmac_macphyclk_set(wlc_hw, ON);
 
2351
 
 
2352
        /* program dynamic clock control fast powerup delay register */
 
2353
        wlc->fastpwrup_dly = ai_clkctl_fast_pwrup_delay(wlc_hw->sih);
 
2354
        W_REG(&regs->scc_fastpwrup_dly, wlc->fastpwrup_dly);
 
2355
 
 
2356
        /* tell the ucode the corerev */
 
2357
        wlc_bmac_write_shm(wlc_hw, M_MACHW_VER, (u16) wlc_hw->corerev);
 
2358
 
 
2359
        /* tell the ucode MAC capabilities */
 
2360
        wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_L,
 
2361
                           (u16) (wlc_hw->machwcap & 0xffff));
 
2362
        wlc_bmac_write_shm(wlc_hw, M_MACHW_CAP_H,
 
2363
                           (u16) ((wlc_hw->
 
2364
                                      machwcap >> 16) & 0xffff));
 
2365
 
 
2366
        /* write retry limits to SCR, this done after PSM init */
 
2367
        W_REG(&regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
 
2368
        (void)R_REG(&regs->objaddr);
 
2369
        W_REG(&regs->objdata, wlc_hw->SRL);
 
2370
        W_REG(&regs->objaddr, OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
 
2371
        (void)R_REG(&regs->objaddr);
 
2372
        W_REG(&regs->objdata, wlc_hw->LRL);
 
2373
 
 
2374
        /* write rate fallback retry limits */
 
2375
        wlc_bmac_write_shm(wlc_hw, M_SFRMTXCNTFBRTHSD, wlc_hw->SFBL);
 
2376
        wlc_bmac_write_shm(wlc_hw, M_LFRMTXCNTFBRTHSD, wlc_hw->LFBL);
 
2377
 
 
2378
        AND_REG(&regs->ifs_ctl, 0x0FFF);
 
2379
        W_REG(&regs->ifs_aifsn, EDCF_AIFSN_MIN);
 
2380
 
 
2381
        /* dma initializations */
 
2382
        wlc->txpend16165war = 0;
 
2383
 
 
2384
        /* init the tx dma engines */
 
2385
        for (i = 0; i < NFIFO; i++) {
 
2386
                if (wlc_hw->di[i])
 
2387
                        dma_txinit(wlc_hw->di[i]);
 
2388
        }
 
2389
 
 
2390
        /* init the rx dma engine(s) and post receive buffers */
 
2391
        dma_rxinit(wlc_hw->di[RX_FIFO]);
 
2392
        dma_rxfill(wlc_hw->di[RX_FIFO]);
 
2393
}
 
2394
 
 
2395
/* This function is used for changing the tsf frac register
 
2396
 * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz
 
2397
 * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz
 
2398
 * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz
 
2399
 * HTPHY Formula is 2^26/freq(MHz) e.g.
 
2400
 * For spuron2 - 126MHz -> 2^26/126 = 532610.0
 
2401
 *  - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082
 
2402
 * For spuron: 123MHz -> 2^26/123    = 545600.5
 
2403
 *  - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341
 
2404
 * For spur off: 120MHz -> 2^26/120    = 559240.5
 
2405
 *  - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
 
2406
 */
 
2407
 
 
2408
void wlc_bmac_switch_macfreq(struct wlc_hw_info *wlc_hw, u8 spurmode)
 
2409
{
 
2410
        d11regs_t *regs;
 
2411
        regs = wlc_hw->regs;
 
2412
 
 
2413
        if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
 
2414
            (wlc_hw->sih->chip == BCM43225_CHIP_ID)) {
 
2415
                if (spurmode == WL_SPURAVOID_ON2) {     /* 126Mhz */
 
2416
                        W_REG(&regs->tsf_clk_frac_l, 0x2082);
 
2417
                        W_REG(&regs->tsf_clk_frac_h, 0x8);
 
2418
                } else if (spurmode == WL_SPURAVOID_ON1) {      /* 123Mhz */
 
2419
                        W_REG(&regs->tsf_clk_frac_l, 0x5341);
 
2420
                        W_REG(&regs->tsf_clk_frac_h, 0x8);
 
2421
                } else {        /* 120Mhz */
 
2422
                        W_REG(&regs->tsf_clk_frac_l, 0x8889);
 
2423
                        W_REG(&regs->tsf_clk_frac_h, 0x8);
 
2424
                }
 
2425
        } else if (WLCISLCNPHY(wlc_hw->band)) {
 
2426
                if (spurmode == WL_SPURAVOID_ON1) {     /* 82Mhz */
 
2427
                        W_REG(&regs->tsf_clk_frac_l, 0x7CE0);
 
2428
                        W_REG(&regs->tsf_clk_frac_h, 0xC);
 
2429
                } else {        /* 80Mhz */
 
2430
                        W_REG(&regs->tsf_clk_frac_l, 0xCCCD);
 
2431
                        W_REG(&regs->tsf_clk_frac_h, 0xC);
 
2432
                }
 
2433
        }
 
2434
}
 
2435
 
 
2436
/* Initialize GPIOs that are controlled by D11 core */
 
2437
static void wlc_gpio_init(struct wlc_info *wlc)
 
2438
{
 
2439
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
2440
        d11regs_t *regs;
 
2441
        u32 gc, gm;
 
2442
 
 
2443
        regs = wlc_hw->regs;
 
2444
 
 
2445
        /* use GPIO select 0 to get all gpio signals from the gpio out reg */
 
2446
        wlc_bmac_mctrl(wlc_hw, MCTL_GPOUT_SEL_MASK, 0);
 
2447
 
 
2448
        /*
 
2449
         * Common GPIO setup:
 
2450
         *      G0 = LED 0 = WLAN Activity
 
2451
         *      G1 = LED 1 = WLAN 2.4 GHz Radio State
 
2452
         *      G2 = LED 2 = WLAN 5 GHz Radio State
 
2453
         *      G4 = radio disable input (HI enabled, LO disabled)
 
2454
         */
 
2455
 
 
2456
        gc = gm = 0;
 
2457
 
 
2458
        /* Allocate GPIOs for mimo antenna diversity feature */
 
2459
        if (wlc_hw->antsel_type == ANTSEL_2x3) {
 
2460
                /* Enable antenna diversity, use 2x3 mode */
 
2461
                wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
 
2462
                             MHF3_ANTSEL_EN, WLC_BAND_ALL);
 
2463
                wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE,
 
2464
                             MHF3_ANTSEL_MODE, WLC_BAND_ALL);
 
2465
 
 
2466
                /* init superswitch control */
 
2467
                wlc_phy_antsel_init(wlc_hw->band->pi, false);
 
2468
 
 
2469
        } else if (wlc_hw->antsel_type == ANTSEL_2x4) {
 
2470
                gm |= gc |= (BOARD_GPIO_12 | BOARD_GPIO_13);
 
2471
                /*
 
2472
                 * The board itself is powered by these GPIOs
 
2473
                 * (when not sending pattern) so set them high
 
2474
                 */
 
2475
                OR_REG(&regs->psm_gpio_oe,
 
2476
                       (BOARD_GPIO_12 | BOARD_GPIO_13));
 
2477
                OR_REG(&regs->psm_gpio_out,
 
2478
                       (BOARD_GPIO_12 | BOARD_GPIO_13));
 
2479
 
 
2480
                /* Enable antenna diversity, use 2x4 mode */
 
2481
                wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN,
 
2482
                             MHF3_ANTSEL_EN, WLC_BAND_ALL);
 
2483
                wlc_bmac_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, 0,
 
2484
                             WLC_BAND_ALL);
 
2485
 
 
2486
                /* Configure the desired clock to be 4Mhz */
 
2487
                wlc_bmac_write_shm(wlc_hw, M_ANTSEL_CLKDIV,
 
2488
                                   ANTSEL_CLKDIV_4MHZ);
 
2489
        }
 
2490
 
 
2491
        /* gpio 9 controls the PA.  ucode is responsible for wiggling out and oe */
 
2492
        if (wlc_hw->boardflags & BFL_PACTRL)
 
2493
                gm |= gc |= BOARD_GPIO_PACTRL;
 
2494
 
 
2495
        /* apply to gpiocontrol register */
 
2496
        ai_gpiocontrol(wlc_hw->sih, gm, gc, GPIO_DRV_PRIORITY);
 
2497
}
 
2498
 
 
2499
static void wlc_ucode_download(struct wlc_hw_info *wlc_hw)
 
2500
{
 
2501
        struct wlc_info *wlc;
 
2502
        wlc = wlc_hw->wlc;
 
2503
 
 
2504
        if (wlc_hw->ucode_loaded)
 
2505
                return;
 
2506
 
 
2507
        if (D11REV_IS(wlc_hw->corerev, 23)) {
 
2508
                if (WLCISNPHY(wlc_hw->band)) {
 
2509
                        wlc_ucode_write(wlc_hw, bcm43xx_16_mimo,
 
2510
                                        bcm43xx_16_mimosz);
 
2511
                        wlc_hw->ucode_loaded = true;
 
2512
                } else
 
2513
                        wiphy_err(wlc->wiphy, "%s: wl%d: unsupported phy in "
 
2514
                                  "corerev %d\n",
 
2515
                                  __func__, wlc_hw->unit, wlc_hw->corerev);
 
2516
        } else if (D11REV_IS(wlc_hw->corerev, 24)) {
 
2517
                if (WLCISLCNPHY(wlc_hw->band)) {
 
2518
                        wlc_ucode_write(wlc_hw, bcm43xx_24_lcn,
 
2519
                                        bcm43xx_24_lcnsz);
 
2520
                        wlc_hw->ucode_loaded = true;
 
2521
                } else {
 
2522
                        wiphy_err(wlc->wiphy, "%s: wl%d: unsupported phy in "
 
2523
                                  "corerev %d\n",
 
2524
                                  __func__, wlc_hw->unit, wlc_hw->corerev);
 
2525
                }
 
2526
        }
 
2527
}
 
2528
 
 
2529
static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
 
2530
                              const uint nbytes) {
 
2531
        d11regs_t *regs = wlc_hw->regs;
 
2532
        uint i;
 
2533
        uint count;
 
2534
 
 
2535
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
2536
 
 
2537
        count = (nbytes / sizeof(u32));
 
2538
 
 
2539
        W_REG(&regs->objaddr, (OBJADDR_AUTO_INC | OBJADDR_UCM_SEL));
 
2540
        (void)R_REG(&regs->objaddr);
 
2541
        for (i = 0; i < count; i++)
 
2542
                W_REG(&regs->objdata, ucode[i]);
 
2543
}
 
2544
 
 
2545
static void wlc_write_inits(struct wlc_hw_info *wlc_hw,
 
2546
                            const struct d11init *inits)
 
2547
{
 
2548
        int i;
 
2549
        volatile u8 *base;
 
2550
 
 
2551
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
2552
 
 
2553
        base = (volatile u8 *)wlc_hw->regs;
 
2554
 
 
2555
        for (i = 0; inits[i].addr != 0xffff; i++) {
 
2556
                if (inits[i].size == 2)
 
2557
                        W_REG((u16 *)(base + inits[i].addr),
 
2558
                              inits[i].value);
 
2559
                else if (inits[i].size == 4)
 
2560
                        W_REG((u32 *)(base + inits[i].addr),
 
2561
                              inits[i].value);
 
2562
        }
 
2563
}
 
2564
 
 
2565
static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw)
 
2566
{
 
2567
        u16 phyctl;
 
2568
        u16 phytxant = wlc_hw->bmac_phytxant;
 
2569
        u16 mask = PHY_TXC_ANT_MASK;
 
2570
 
 
2571
        /* set the Probe Response frame phy control word */
 
2572
        phyctl = wlc_bmac_read_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS);
 
2573
        phyctl = (phyctl & ~mask) | phytxant;
 
2574
        wlc_bmac_write_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS, phyctl);
 
2575
 
 
2576
        /* set the Response (ACK/CTS) frame phy control word */
 
2577
        phyctl = wlc_bmac_read_shm(wlc_hw, M_RSP_PCTLWD);
 
2578
        phyctl = (phyctl & ~mask) | phytxant;
 
2579
        wlc_bmac_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl);
 
2580
}
 
2581
 
 
2582
void wlc_bmac_txant_set(struct wlc_hw_info *wlc_hw, u16 phytxant)
 
2583
{
 
2584
        /* update sw state */
 
2585
        wlc_hw->bmac_phytxant = phytxant;
 
2586
 
 
2587
        /* push to ucode if up */
 
2588
        if (!wlc_hw->up)
 
2589
                return;
 
2590
        wlc_ucode_txant_set(wlc_hw);
 
2591
 
 
2592
}
 
2593
 
 
2594
u16 wlc_bmac_get_txant(struct wlc_hw_info *wlc_hw)
 
2595
{
 
2596
        return (u16) wlc_hw->wlc->stf->txant;
 
2597
}
 
2598
 
 
2599
void wlc_bmac_antsel_type_set(struct wlc_hw_info *wlc_hw, u8 antsel_type)
 
2600
{
 
2601
        wlc_hw->antsel_type = antsel_type;
 
2602
 
 
2603
        /* Update the antsel type for phy module to use */
 
2604
        wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type);
 
2605
}
 
2606
 
 
2607
void wlc_bmac_fifoerrors(struct wlc_hw_info *wlc_hw)
 
2608
{
 
2609
        bool fatal = false;
 
2610
        uint unit;
 
2611
        uint intstatus, idx;
 
2612
        d11regs_t *regs = wlc_hw->regs;
 
2613
        struct wiphy *wiphy = wlc_hw->wlc->wiphy;
 
2614
 
 
2615
        unit = wlc_hw->unit;
 
2616
 
 
2617
        for (idx = 0; idx < NFIFO; idx++) {
 
2618
                /* read intstatus register and ignore any non-error bits */
 
2619
                intstatus =
 
2620
                    R_REG(&regs->intctrlregs[idx].intstatus) & I_ERRORS;
 
2621
                if (!intstatus)
 
2622
                        continue;
 
2623
 
 
2624
                BCMMSG(wlc_hw->wlc->wiphy, "wl%d: intstatus%d 0x%x\n",
 
2625
                        unit, idx, intstatus);
 
2626
 
 
2627
                if (intstatus & I_RO) {
 
2628
                        wiphy_err(wiphy, "wl%d: fifo %d: receive fifo "
 
2629
                                  "overflow\n", unit, idx);
 
2630
                        fatal = true;
 
2631
                }
 
2632
 
 
2633
                if (intstatus & I_PC) {
 
2634
                        wiphy_err(wiphy, "wl%d: fifo %d: descriptor error\n",
 
2635
                                 unit, idx);
 
2636
                        fatal = true;
 
2637
                }
 
2638
 
 
2639
                if (intstatus & I_PD) {
 
2640
                        wiphy_err(wiphy, "wl%d: fifo %d: data error\n", unit,
 
2641
                                  idx);
 
2642
                        fatal = true;
 
2643
                }
 
2644
 
 
2645
                if (intstatus & I_DE) {
 
2646
                        wiphy_err(wiphy, "wl%d: fifo %d: descriptor protocol "
 
2647
                                  "error\n", unit, idx);
 
2648
                        fatal = true;
 
2649
                }
 
2650
 
 
2651
                if (intstatus & I_RU) {
 
2652
                        wiphy_err(wiphy, "wl%d: fifo %d: receive descriptor "
 
2653
                                  "underflow\n", idx, unit);
 
2654
                }
 
2655
 
 
2656
                if (intstatus & I_XU) {
 
2657
                        wiphy_err(wiphy, "wl%d: fifo %d: transmit fifo "
 
2658
                                  "underflow\n", idx, unit);
 
2659
                        fatal = true;
 
2660
                }
 
2661
 
 
2662
                if (fatal) {
 
2663
                        wlc_fatal_error(wlc_hw->wlc);   /* big hammer */
 
2664
                        break;
 
2665
                } else
 
2666
                        W_REG(&regs->intctrlregs[idx].intstatus,
 
2667
                              intstatus);
 
2668
        }
 
2669
}
 
2670
 
 
2671
void wlc_intrson(struct wlc_info *wlc)
 
2672
{
 
2673
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
2674
        wlc->macintmask = wlc->defmacintmask;
 
2675
        W_REG(&wlc_hw->regs->macintmask, wlc->macintmask);
 
2676
}
 
2677
 
 
2678
/* callback for siutils.c, which has only wlc handler, no wl
 
2679
 * they both check up, not only because there is no need to off/restore d11 interrupt
 
2680
 *  but also because per-port code may require sync with valid interrupt.
 
2681
 */
 
2682
 
 
2683
static u32 wlc_wlintrsoff(struct wlc_info *wlc)
 
2684
{
 
2685
        if (!wlc->hw->up)
 
2686
                return 0;
 
2687
 
 
2688
        return wl_intrsoff(wlc->wl);
 
2689
}
 
2690
 
 
2691
static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask)
 
2692
{
 
2693
        if (!wlc->hw->up)
 
2694
                return;
 
2695
 
 
2696
        wl_intrsrestore(wlc->wl, macintmask);
 
2697
}
 
2698
 
 
2699
u32 wlc_intrsoff(struct wlc_info *wlc)
 
2700
{
 
2701
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
2702
        u32 macintmask;
 
2703
 
 
2704
        if (!wlc_hw->clk)
 
2705
                return 0;
 
2706
 
 
2707
        macintmask = wlc->macintmask;   /* isr can still happen */
 
2708
 
 
2709
        W_REG(&wlc_hw->regs->macintmask, 0);
 
2710
        (void)R_REG(&wlc_hw->regs->macintmask); /* sync readback */
 
2711
        udelay(1);              /* ensure int line is no longer driven */
 
2712
        wlc->macintmask = 0;
 
2713
 
 
2714
        /* return previous macintmask; resolve race between us and our isr */
 
2715
        return wlc->macintstatus ? 0 : macintmask;
 
2716
}
 
2717
 
 
2718
void wlc_intrsrestore(struct wlc_info *wlc, u32 macintmask)
 
2719
{
 
2720
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
2721
        if (!wlc_hw->clk)
 
2722
                return;
 
2723
 
 
2724
        wlc->macintmask = macintmask;
 
2725
        W_REG(&wlc_hw->regs->macintmask, wlc->macintmask);
 
2726
}
 
2727
 
 
2728
static void wlc_bmac_mute(struct wlc_hw_info *wlc_hw, bool on, mbool flags)
 
2729
{
 
2730
        u8 null_ether_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
 
2731
 
 
2732
        if (on) {
 
2733
                /* suspend tx fifos */
 
2734
                wlc_bmac_tx_fifo_suspend(wlc_hw, TX_DATA_FIFO);
 
2735
                wlc_bmac_tx_fifo_suspend(wlc_hw, TX_CTL_FIFO);
 
2736
                wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_BK_FIFO);
 
2737
                wlc_bmac_tx_fifo_suspend(wlc_hw, TX_AC_VI_FIFO);
 
2738
 
 
2739
                /* zero the address match register so we do not send ACKs */
 
2740
                wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
 
2741
                                       null_ether_addr);
 
2742
        } else {
 
2743
                /* resume tx fifos */
 
2744
                if (!wlc_hw->wlc->tx_suspended) {
 
2745
                        wlc_bmac_tx_fifo_resume(wlc_hw, TX_DATA_FIFO);
 
2746
                }
 
2747
                wlc_bmac_tx_fifo_resume(wlc_hw, TX_CTL_FIFO);
 
2748
                wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_BK_FIFO);
 
2749
                wlc_bmac_tx_fifo_resume(wlc_hw, TX_AC_VI_FIFO);
 
2750
 
 
2751
                /* Restore address */
 
2752
                wlc_bmac_set_addrmatch(wlc_hw, RCM_MAC_OFFSET,
 
2753
                                       wlc_hw->etheraddr);
 
2754
        }
 
2755
 
 
2756
        wlc_phy_mute_upd(wlc_hw->band->pi, on, flags);
 
2757
 
 
2758
        if (on)
 
2759
                wlc_ucode_mute_override_set(wlc_hw);
 
2760
        else
 
2761
                wlc_ucode_mute_override_clear(wlc_hw);
 
2762
}
 
2763
 
 
2764
int wlc_bmac_xmtfifo_sz_get(struct wlc_hw_info *wlc_hw, uint fifo, uint *blocks)
 
2765
{
 
2766
        if (fifo >= NFIFO)
 
2767
                return -EINVAL;
 
2768
 
 
2769
        *blocks = wlc_hw->xmtfifo_sz[fifo];
 
2770
 
 
2771
        return 0;
 
2772
}
 
2773
 
 
2774
/* wlc_bmac_tx_fifo_suspended:
 
2775
 * Check the MAC's tx suspend status for a tx fifo.
 
2776
 *
 
2777
 * When the MAC acknowledges a tx suspend, it indicates that no more
 
2778
 * packets will be transmitted out the radio. This is independent of
 
2779
 * DMA channel suspension---the DMA may have finished suspending, or may still
 
2780
 * be pulling data into a tx fifo, by the time the MAC acks the suspend
 
2781
 * request.
 
2782
 */
 
2783
static bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info *wlc_hw, uint tx_fifo)
 
2784
{
 
2785
        /* check that a suspend has been requested and is no longer pending */
 
2786
 
 
2787
        /*
 
2788
         * for DMA mode, the suspend request is set in xmtcontrol of the DMA engine,
 
2789
         * and the tx fifo suspend at the lower end of the MAC is acknowledged in the
 
2790
         * chnstatus register.
 
2791
         * The tx fifo suspend completion is independent of the DMA suspend completion and
 
2792
         *   may be acked before or after the DMA is suspended.
 
2793
         */
 
2794
        if (dma_txsuspended(wlc_hw->di[tx_fifo]) &&
 
2795
            (R_REG(&wlc_hw->regs->chnstatus) &
 
2796
             (1 << tx_fifo)) == 0)
 
2797
                return true;
 
2798
 
 
2799
        return false;
 
2800
}
 
2801
 
 
2802
static void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info *wlc_hw, uint tx_fifo)
 
2803
{
 
2804
        u8 fifo = 1 << tx_fifo;
 
2805
 
 
2806
        /* Two clients of this code, 11h Quiet period and scanning. */
 
2807
 
 
2808
        /* only suspend if not already suspended */
 
2809
        if ((wlc_hw->suspended_fifos & fifo) == fifo)
 
2810
                return;
 
2811
 
 
2812
        /* force the core awake only if not already */
 
2813
        if (wlc_hw->suspended_fifos == 0)
 
2814
                wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_TXFIFO);
 
2815
 
 
2816
        wlc_hw->suspended_fifos |= fifo;
 
2817
 
 
2818
        if (wlc_hw->di[tx_fifo]) {
 
2819
                /* Suspending AMPDU transmissions in the middle can cause underflow
 
2820
                 * which may result in mismatch between ucode and driver
 
2821
                 * so suspend the mac before suspending the FIFO
 
2822
                 */
 
2823
                if (WLC_PHY_11N_CAP(wlc_hw->band))
 
2824
                        wlc_suspend_mac_and_wait(wlc_hw->wlc);
 
2825
 
 
2826
                dma_txsuspend(wlc_hw->di[tx_fifo]);
 
2827
 
 
2828
                if (WLC_PHY_11N_CAP(wlc_hw->band))
 
2829
                        wlc_enable_mac(wlc_hw->wlc);
 
2830
        }
 
2831
}
 
2832
 
 
2833
static void wlc_bmac_tx_fifo_resume(struct wlc_hw_info *wlc_hw, uint tx_fifo)
 
2834
{
 
2835
        /* BMAC_NOTE: WLC_TX_FIFO_ENAB is done in wlc_dpc() for DMA case but need to be done
 
2836
         * here for PIO otherwise the watchdog will catch the inconsistency and fire
 
2837
         */
 
2838
        /* Two clients of this code, 11h Quiet period and scanning. */
 
2839
        if (wlc_hw->di[tx_fifo])
 
2840
                dma_txresume(wlc_hw->di[tx_fifo]);
 
2841
 
 
2842
        /* allow core to sleep again */
 
2843
        if (wlc_hw->suspended_fifos == 0)
 
2844
                return;
 
2845
        else {
 
2846
                wlc_hw->suspended_fifos &= ~(1 << tx_fifo);
 
2847
                if (wlc_hw->suspended_fifos == 0)
 
2848
                        wlc_ucode_wake_override_clear(wlc_hw,
 
2849
                                                      WLC_WAKE_OVERRIDE_TXFIFO);
 
2850
        }
 
2851
}
 
2852
 
 
2853
/*
 
2854
 * Read and clear macintmask and macintstatus and intstatus registers.
 
2855
 * This routine should be called with interrupts off
 
2856
 * Return:
 
2857
 *   -1 if DEVICEREMOVED(wlc) evaluates to true;
 
2858
 *   0 if the interrupt is not for us, or we are in some special cases;
 
2859
 *   device interrupt status bits otherwise.
 
2860
 */
 
2861
static inline u32 wlc_intstatus(struct wlc_info *wlc, bool in_isr)
 
2862
{
 
2863
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
2864
        d11regs_t *regs = wlc_hw->regs;
 
2865
        u32 macintstatus;
 
2866
 
 
2867
        /* macintstatus includes a DMA interrupt summary bit */
 
2868
        macintstatus = R_REG(&regs->macintstatus);
 
2869
 
 
2870
        BCMMSG(wlc->wiphy, "wl%d: macintstatus: 0x%x\n", wlc_hw->unit,
 
2871
                 macintstatus);
 
2872
 
 
2873
        /* detect cardbus removed, in power down(suspend) and in reset */
 
2874
        if (DEVICEREMOVED(wlc))
 
2875
                return -1;
 
2876
 
 
2877
        /* DEVICEREMOVED succeeds even when the core is still resetting,
 
2878
         * handle that case here.
 
2879
         */
 
2880
        if (macintstatus == 0xffffffff)
 
2881
                return 0;
 
2882
 
 
2883
        /* defer unsolicited interrupts */
 
2884
        macintstatus &= (in_isr ? wlc->macintmask : wlc->defmacintmask);
 
2885
 
 
2886
        /* if not for us */
 
2887
        if (macintstatus == 0)
 
2888
                return 0;
 
2889
 
 
2890
        /* interrupts are already turned off for CFE build
 
2891
         * Caution: For CFE Turning off the interrupts again has some undesired
 
2892
         * consequences
 
2893
         */
 
2894
        /* turn off the interrupts */
 
2895
        W_REG(&regs->macintmask, 0);
 
2896
        (void)R_REG(&regs->macintmask); /* sync readback */
 
2897
        wlc->macintmask = 0;
 
2898
 
 
2899
        /* clear device interrupts */
 
2900
        W_REG(&regs->macintstatus, macintstatus);
 
2901
 
 
2902
        /* MI_DMAINT is indication of non-zero intstatus */
 
2903
        if (macintstatus & MI_DMAINT) {
 
2904
                /*
 
2905
                 * only fifo interrupt enabled is I_RI in
 
2906
                 * RX_FIFO. If MI_DMAINT is set, assume it
 
2907
                 * is set and clear the interrupt.
 
2908
                 */
 
2909
                W_REG(&regs->intctrlregs[RX_FIFO].intstatus,
 
2910
                      DEF_RXINTMASK);
 
2911
        }
 
2912
 
 
2913
        return macintstatus;
 
2914
}
 
2915
 
 
2916
/* Update wlc->macintstatus and wlc->intstatus[]. */
 
2917
/* Return true if they are updated successfully. false otherwise */
 
2918
bool wlc_intrsupd(struct wlc_info *wlc)
 
2919
{
 
2920
        u32 macintstatus;
 
2921
 
 
2922
        /* read and clear macintstatus and intstatus registers */
 
2923
        macintstatus = wlc_intstatus(wlc, false);
 
2924
 
 
2925
        /* device is removed */
 
2926
        if (macintstatus == 0xffffffff)
 
2927
                return false;
 
2928
 
 
2929
        /* update interrupt status in software */
 
2930
        wlc->macintstatus |= macintstatus;
 
2931
 
 
2932
        return true;
 
2933
}
 
2934
 
 
2935
/*
 
2936
 * First-level interrupt processing.
 
2937
 * Return true if this was our interrupt, false otherwise.
 
2938
 * *wantdpc will be set to true if further wlc_dpc() processing is required,
 
2939
 * false otherwise.
 
2940
 */
 
2941
bool wlc_isr(struct wlc_info *wlc, bool *wantdpc)
 
2942
{
 
2943
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
2944
        u32 macintstatus;
 
2945
 
 
2946
        *wantdpc = false;
 
2947
 
 
2948
        if (!wlc_hw->up || !wlc->macintmask)
 
2949
                return false;
 
2950
 
 
2951
        /* read and clear macintstatus and intstatus registers */
 
2952
        macintstatus = wlc_intstatus(wlc, true);
 
2953
 
 
2954
        if (macintstatus == 0xffffffff)
 
2955
                wiphy_err(wlc->wiphy, "DEVICEREMOVED detected in the ISR code"
 
2956
                          " path\n");
 
2957
 
 
2958
        /* it is not for us */
 
2959
        if (macintstatus == 0)
 
2960
                return false;
 
2961
 
 
2962
        *wantdpc = true;
 
2963
 
 
2964
        /* save interrupt status bits */
 
2965
        wlc->macintstatus = macintstatus;
 
2966
 
 
2967
        return true;
 
2968
 
 
2969
}
 
2970
 
 
2971
static bool
 
2972
wlc_bmac_dotxstatus(struct wlc_hw_info *wlc_hw, tx_status_t *txs, u32 s2)
 
2973
{
 
2974
        /* discard intermediate indications for ucode with one legitimate case:
 
2975
         *   e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
 
2976
         *   tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
 
2977
         *   transmission count)
 
2978
         */
 
2979
        if (!(txs->status & TX_STATUS_AMPDU)
 
2980
            && (txs->status & TX_STATUS_INTERMEDIATE)) {
 
2981
                return false;
 
2982
        }
 
2983
 
 
2984
        return wlc_dotxstatus(wlc_hw->wlc, txs, s2);
 
2985
}
 
2986
 
 
2987
/* process tx completion events in BMAC
 
2988
 * Return true if more tx status need to be processed. false otherwise.
 
2989
 */
 
2990
static bool
 
2991
wlc_bmac_txstatus(struct wlc_hw_info *wlc_hw, bool bound, bool *fatal)
 
2992
{
 
2993
        bool morepending = false;
 
2994
        struct wlc_info *wlc = wlc_hw->wlc;
 
2995
        d11regs_t *regs;
 
2996
        tx_status_t txstatus, *txs;
 
2997
        u32 s1, s2;
 
2998
        uint n = 0;
 
2999
        /*
 
3000
         * Param 'max_tx_num' indicates max. # tx status to process before
 
3001
         * break out.
 
3002
         */
 
3003
        uint max_tx_num = bound ? wlc->pub->tunables->txsbnd : -1;
 
3004
 
 
3005
        BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
3006
 
 
3007
        txs = &txstatus;
 
3008
        regs = wlc_hw->regs;
 
3009
        while (!(*fatal)
 
3010
               && (s1 = R_REG(&regs->frmtxstatus)) & TXS_V) {
 
3011
 
 
3012
                if (s1 == 0xffffffff) {
 
3013
                        wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n",
 
3014
                                wlc_hw->unit, __func__);
 
3015
                        return morepending;
 
3016
                }
 
3017
 
 
3018
                        s2 = R_REG(&regs->frmtxstatus2);
 
3019
 
 
3020
                txs->status = s1 & TXS_STATUS_MASK;
 
3021
                txs->frameid = (s1 & TXS_FID_MASK) >> TXS_FID_SHIFT;
 
3022
                txs->sequence = s2 & TXS_SEQ_MASK;
 
3023
                txs->phyerr = (s2 & TXS_PTX_MASK) >> TXS_PTX_SHIFT;
 
3024
                txs->lasttxtime = 0;
 
3025
 
 
3026
                *fatal = wlc_bmac_dotxstatus(wlc_hw, txs, s2);
 
3027
 
 
3028
                /* !give others some time to run! */
 
3029
                if (++n >= max_tx_num)
 
3030
                        break;
 
3031
        }
 
3032
 
 
3033
        if (*fatal)
 
3034
                return 0;
 
3035
 
 
3036
        if (n >= max_tx_num)
 
3037
                morepending = true;
 
3038
 
 
3039
        if (!pktq_empty(&wlc->pkt_queue->q))
 
3040
                wlc_send_q(wlc);
 
3041
 
 
3042
        return morepending;
 
3043
}
 
3044
 
 
3045
void wlc_suspend_mac_and_wait(struct wlc_info *wlc)
 
3046
{
 
3047
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
3048
        d11regs_t *regs = wlc_hw->regs;
 
3049
        u32 mc, mi;
 
3050
        struct wiphy *wiphy = wlc->wiphy;
 
3051
 
 
3052
        BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
 
3053
                wlc_hw->band->bandunit);
 
3054
 
 
3055
        /*
 
3056
         * Track overlapping suspend requests
 
3057
         */
 
3058
        wlc_hw->mac_suspend_depth++;
 
3059
        if (wlc_hw->mac_suspend_depth > 1)
 
3060
                return;
 
3061
 
 
3062
        /* force the core awake */
 
3063
        wlc_ucode_wake_override_set(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
 
3064
 
 
3065
        mc = R_REG(&regs->maccontrol);
 
3066
 
 
3067
        if (mc == 0xffffffff) {
 
3068
                wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
 
3069
                          __func__);
 
3070
                wl_down(wlc->wl);
 
3071
                return;
 
3072
        }
 
3073
        WARN_ON(mc & MCTL_PSM_JMP_0);
 
3074
        WARN_ON(!(mc & MCTL_PSM_RUN));
 
3075
        WARN_ON(!(mc & MCTL_EN_MAC));
 
3076
 
 
3077
        mi = R_REG(&regs->macintstatus);
 
3078
        if (mi == 0xffffffff) {
 
3079
                wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
 
3080
                          __func__);
 
3081
                wl_down(wlc->wl);
 
3082
                return;
 
3083
        }
 
3084
        WARN_ON(mi & MI_MACSSPNDD);
 
3085
 
 
3086
        wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, 0);
 
3087
 
 
3088
        SPINWAIT(!(R_REG(&regs->macintstatus) & MI_MACSSPNDD),
 
3089
                 WLC_MAX_MAC_SUSPEND);
 
3090
 
 
3091
        if (!(R_REG(&regs->macintstatus) & MI_MACSSPNDD)) {
 
3092
                wiphy_err(wiphy, "wl%d: wlc_suspend_mac_and_wait: waited %d uS"
 
3093
                          " and MI_MACSSPNDD is still not on.\n",
 
3094
                          wlc_hw->unit, WLC_MAX_MAC_SUSPEND);
 
3095
                wiphy_err(wiphy, "wl%d: psmdebug 0x%08x, phydebug 0x%08x, "
 
3096
                          "psm_brc 0x%04x\n", wlc_hw->unit,
 
3097
                          R_REG(&regs->psmdebug),
 
3098
                          R_REG(&regs->phydebug),
 
3099
                          R_REG(&regs->psm_brc));
 
3100
        }
 
3101
 
 
3102
        mc = R_REG(&regs->maccontrol);
 
3103
        if (mc == 0xffffffff) {
 
3104
                wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit,
 
3105
                          __func__);
 
3106
                wl_down(wlc->wl);
 
3107
                return;
 
3108
        }
 
3109
        WARN_ON(mc & MCTL_PSM_JMP_0);
 
3110
        WARN_ON(!(mc & MCTL_PSM_RUN));
 
3111
        WARN_ON(mc & MCTL_EN_MAC);
 
3112
}
 
3113
 
 
3114
void wlc_enable_mac(struct wlc_info *wlc)
 
3115
{
 
3116
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
3117
        d11regs_t *regs = wlc_hw->regs;
 
3118
        u32 mc, mi;
 
3119
 
 
3120
        BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit,
 
3121
                wlc->band->bandunit);
 
3122
 
 
3123
        /*
 
3124
         * Track overlapping suspend requests
 
3125
         */
 
3126
        wlc_hw->mac_suspend_depth--;
 
3127
        if (wlc_hw->mac_suspend_depth > 0)
 
3128
                return;
 
3129
 
 
3130
        mc = R_REG(&regs->maccontrol);
 
3131
        WARN_ON(mc & MCTL_PSM_JMP_0);
 
3132
        WARN_ON(mc & MCTL_EN_MAC);
 
3133
        WARN_ON(!(mc & MCTL_PSM_RUN));
 
3134
 
 
3135
        wlc_bmac_mctrl(wlc_hw, MCTL_EN_MAC, MCTL_EN_MAC);
 
3136
        W_REG(&regs->macintstatus, MI_MACSSPNDD);
 
3137
 
 
3138
        mc = R_REG(&regs->maccontrol);
 
3139
        WARN_ON(mc & MCTL_PSM_JMP_0);
 
3140
        WARN_ON(!(mc & MCTL_EN_MAC));
 
3141
        WARN_ON(!(mc & MCTL_PSM_RUN));
 
3142
 
 
3143
        mi = R_REG(&regs->macintstatus);
 
3144
        WARN_ON(mi & MI_MACSSPNDD);
 
3145
 
 
3146
        wlc_ucode_wake_override_clear(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
 
3147
}
 
3148
 
 
3149
static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw)
 
3150
{
 
3151
        u8 rate;
 
3152
        u8 rates[8] = {
 
3153
                WLC_RATE_6M, WLC_RATE_9M, WLC_RATE_12M, WLC_RATE_18M,
 
3154
                WLC_RATE_24M, WLC_RATE_36M, WLC_RATE_48M, WLC_RATE_54M
 
3155
        };
 
3156
        u16 entry_ptr;
 
3157
        u16 pctl1;
 
3158
        uint i;
 
3159
 
 
3160
        if (!WLC_PHY_11N_CAP(wlc_hw->band))
 
3161
                return;
 
3162
 
 
3163
        /* walk the phy rate table and update the entries */
 
3164
        for (i = 0; i < ARRAY_SIZE(rates); i++) {
 
3165
                rate = rates[i];
 
3166
 
 
3167
                entry_ptr = wlc_bmac_ofdm_ratetable_offset(wlc_hw, rate);
 
3168
 
 
3169
                /* read the SHM Rate Table entry OFDM PCTL1 values */
 
3170
                pctl1 =
 
3171
                    wlc_bmac_read_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS);
 
3172
 
 
3173
                /* modify the value */
 
3174
                pctl1 &= ~PHY_TXC1_MODE_MASK;
 
3175
                pctl1 |= (wlc_hw->hw_stf_ss_opmode << PHY_TXC1_MODE_SHIFT);
 
3176
 
 
3177
                /* Update the SHM Rate Table entry OFDM PCTL1 values */
 
3178
                wlc_bmac_write_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS,
 
3179
                                   pctl1);
 
3180
        }
 
3181
}
 
3182
 
 
3183
static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw, u8 rate)
 
3184
{
 
3185
        uint i;
 
3186
        u8 plcp_rate = 0;
 
3187
        struct plcp_signal_rate_lookup {
 
3188
                u8 rate;
 
3189
                u8 signal_rate;
 
3190
        };
 
3191
        /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */
 
3192
        const struct plcp_signal_rate_lookup rate_lookup[] = {
 
3193
                {WLC_RATE_6M, 0xB},
 
3194
                {WLC_RATE_9M, 0xF},
 
3195
                {WLC_RATE_12M, 0xA},
 
3196
                {WLC_RATE_18M, 0xE},
 
3197
                {WLC_RATE_24M, 0x9},
 
3198
                {WLC_RATE_36M, 0xD},
 
3199
                {WLC_RATE_48M, 0x8},
 
3200
                {WLC_RATE_54M, 0xC}
 
3201
        };
 
3202
 
 
3203
        for (i = 0; i < ARRAY_SIZE(rate_lookup); i++) {
 
3204
                if (rate == rate_lookup[i].rate) {
 
3205
                        plcp_rate = rate_lookup[i].signal_rate;
 
3206
                        break;
 
3207
                }
 
3208
        }
 
3209
 
 
3210
        /* Find the SHM pointer to the rate table entry by looking in the
 
3211
         * Direct-map Table
 
3212
         */
 
3213
        return 2 * wlc_bmac_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2));
 
3214
}
 
3215
 
 
3216
void wlc_bmac_band_stf_ss_set(struct wlc_hw_info *wlc_hw, u8 stf_mode)
 
3217
{
 
3218
        wlc_hw->hw_stf_ss_opmode = stf_mode;
 
3219
 
 
3220
        if (wlc_hw->clk)
 
3221
                wlc_upd_ofdm_pctl1_table(wlc_hw);
 
3222
}
 
3223
 
 
3224
void
 
3225
wlc_bmac_read_tsf(struct wlc_hw_info *wlc_hw, u32 *tsf_l_ptr,
 
3226
                  u32 *tsf_h_ptr)
 
3227
{
 
3228
        d11regs_t *regs = wlc_hw->regs;
 
3229
 
 
3230
        /* read the tsf timer low, then high to get an atomic read */
 
3231
        *tsf_l_ptr = R_REG(&regs->tsf_timerlow);
 
3232
        *tsf_h_ptr = R_REG(&regs->tsf_timerhigh);
 
3233
 
 
3234
        return;
 
3235
}
 
3236
 
 
3237
static bool wlc_bmac_validate_chip_access(struct wlc_hw_info *wlc_hw)
 
3238
{
 
3239
        d11regs_t *regs;
 
3240
        u32 w, val;
 
3241
        struct wiphy *wiphy = wlc_hw->wlc->wiphy;
 
3242
 
 
3243
        BCMMSG(wiphy, "wl%d\n", wlc_hw->unit);
 
3244
 
 
3245
        regs = wlc_hw->regs;
 
3246
 
 
3247
        /* Validate dchip register access */
 
3248
 
 
3249
        W_REG(&regs->objaddr, OBJADDR_SHM_SEL | 0);
 
3250
        (void)R_REG(&regs->objaddr);
 
3251
        w = R_REG(&regs->objdata);
 
3252
 
 
3253
        /* Can we write and read back a 32bit register? */
 
3254
        W_REG(&regs->objaddr, OBJADDR_SHM_SEL | 0);
 
3255
        (void)R_REG(&regs->objaddr);
 
3256
        W_REG(&regs->objdata, (u32) 0xaa5555aa);
 
3257
 
 
3258
        W_REG(&regs->objaddr, OBJADDR_SHM_SEL | 0);
 
3259
        (void)R_REG(&regs->objaddr);
 
3260
        val = R_REG(&regs->objdata);
 
3261
        if (val != (u32) 0xaa5555aa) {
 
3262
                wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, "
 
3263
                          "expected 0xaa5555aa\n", wlc_hw->unit, val);
 
3264
                return false;
 
3265
        }
 
3266
 
 
3267
        W_REG(&regs->objaddr, OBJADDR_SHM_SEL | 0);
 
3268
        (void)R_REG(&regs->objaddr);
 
3269
        W_REG(&regs->objdata, (u32) 0x55aaaa55);
 
3270
 
 
3271
        W_REG(&regs->objaddr, OBJADDR_SHM_SEL | 0);
 
3272
        (void)R_REG(&regs->objaddr);
 
3273
        val = R_REG(&regs->objdata);
 
3274
        if (val != (u32) 0x55aaaa55) {
 
3275
                wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, "
 
3276
                          "expected 0x55aaaa55\n", wlc_hw->unit, val);
 
3277
                return false;
 
3278
        }
 
3279
 
 
3280
        W_REG(&regs->objaddr, OBJADDR_SHM_SEL | 0);
 
3281
        (void)R_REG(&regs->objaddr);
 
3282
        W_REG(&regs->objdata, w);
 
3283
 
 
3284
        /* clear CFPStart */
 
3285
        W_REG(&regs->tsf_cfpstart, 0);
 
3286
 
 
3287
        w = R_REG(&regs->maccontrol);
 
3288
        if ((w != (MCTL_IHR_EN | MCTL_WAKE)) &&
 
3289
            (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) {
 
3290
                wiphy_err(wiphy, "wl%d: validate_chip_access: maccontrol = "
 
3291
                          "0x%x, expected 0x%x or 0x%x\n", wlc_hw->unit, w,
 
3292
                          (MCTL_IHR_EN | MCTL_WAKE),
 
3293
                          (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE));
 
3294
                return false;
 
3295
        }
 
3296
 
 
3297
        return true;
 
3298
}
 
3299
 
 
3300
#define PHYPLL_WAIT_US  100000
 
3301
 
 
3302
void wlc_bmac_core_phypll_ctl(struct wlc_hw_info *wlc_hw, bool on)
 
3303
{
 
3304
        d11regs_t *regs;
 
3305
        u32 tmp;
 
3306
 
 
3307
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
3308
 
 
3309
        tmp = 0;
 
3310
        regs = wlc_hw->regs;
 
3311
 
 
3312
        if (on) {
 
3313
                if ((wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
 
3314
                        OR_REG(&regs->clk_ctl_st,
 
3315
                               (CCS_ERSRC_REQ_HT | CCS_ERSRC_REQ_D11PLL |
 
3316
                                CCS_ERSRC_REQ_PHYPLL));
 
3317
                        SPINWAIT((R_REG(&regs->clk_ctl_st) &
 
3318
                                  (CCS_ERSRC_AVAIL_HT)) != (CCS_ERSRC_AVAIL_HT),
 
3319
                                 PHYPLL_WAIT_US);
 
3320
 
 
3321
                        tmp = R_REG(&regs->clk_ctl_st);
 
3322
                        if ((tmp & (CCS_ERSRC_AVAIL_HT)) !=
 
3323
                            (CCS_ERSRC_AVAIL_HT)) {
 
3324
                                wiphy_err(wlc_hw->wlc->wiphy, "%s: turn on PHY"
 
3325
                                          " PLL failed\n", __func__);
 
3326
                        }
 
3327
                } else {
 
3328
                        OR_REG(&regs->clk_ctl_st,
 
3329
                               (CCS_ERSRC_REQ_D11PLL | CCS_ERSRC_REQ_PHYPLL));
 
3330
                        SPINWAIT((R_REG(&regs->clk_ctl_st) &
 
3331
                                  (CCS_ERSRC_AVAIL_D11PLL |
 
3332
                                   CCS_ERSRC_AVAIL_PHYPLL)) !=
 
3333
                                 (CCS_ERSRC_AVAIL_D11PLL |
 
3334
                                  CCS_ERSRC_AVAIL_PHYPLL), PHYPLL_WAIT_US);
 
3335
 
 
3336
                        tmp = R_REG(&regs->clk_ctl_st);
 
3337
                        if ((tmp &
 
3338
                             (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL))
 
3339
                            !=
 
3340
                            (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) {
 
3341
                                wiphy_err(wlc_hw->wlc->wiphy, "%s: turn on "
 
3342
                                          "PHY PLL failed\n", __func__);
 
3343
                        }
 
3344
                }
 
3345
        } else {
 
3346
                /* Since the PLL may be shared, other cores can still be requesting it;
 
3347
                 * so we'll deassert the request but not wait for status to comply.
 
3348
                 */
 
3349
                AND_REG(&regs->clk_ctl_st, ~CCS_ERSRC_REQ_PHYPLL);
 
3350
                tmp = R_REG(&regs->clk_ctl_st);
 
3351
        }
 
3352
}
 
3353
 
 
3354
void wlc_coredisable(struct wlc_hw_info *wlc_hw)
 
3355
{
 
3356
        bool dev_gone;
 
3357
 
 
3358
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit);
 
3359
 
 
3360
        dev_gone = DEVICEREMOVED(wlc_hw->wlc);
 
3361
 
 
3362
        if (dev_gone)
 
3363
                return;
 
3364
 
 
3365
        if (wlc_hw->noreset)
 
3366
                return;
 
3367
 
 
3368
        /* radio off */
 
3369
        wlc_phy_switch_radio(wlc_hw->band->pi, OFF);
 
3370
 
 
3371
        /* turn off analog core */
 
3372
        wlc_phy_anacore(wlc_hw->band->pi, OFF);
 
3373
 
 
3374
        /* turn off PHYPLL to save power */
 
3375
        wlc_bmac_core_phypll_ctl(wlc_hw, false);
 
3376
 
 
3377
        /* No need to set wlc->pub->radio_active = OFF
 
3378
         * because this function needs down capability and
 
3379
         * radio_active is designed for BCMNODOWN.
 
3380
         */
 
3381
 
 
3382
        /* remove gpio controls */
 
3383
        if (wlc_hw->ucode_dbgsel)
 
3384
                ai_gpiocontrol(wlc_hw->sih, ~0, 0, GPIO_DRV_PRIORITY);
 
3385
 
 
3386
        wlc_hw->clk = false;
 
3387
        ai_core_disable(wlc_hw->sih, 0);
 
3388
        wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
 
3389
}
 
3390
 
 
3391
/* power both the pll and external oscillator on/off */
 
3392
static void wlc_bmac_xtal(struct wlc_hw_info *wlc_hw, bool want)
 
3393
{
 
3394
        BCMMSG(wlc_hw->wlc->wiphy, "wl%d: want %d\n", wlc_hw->unit, want);
 
3395
 
 
3396
        /* dont power down if plldown is false or we must poll hw radio disable */
 
3397
        if (!want && wlc_hw->pllreq)
 
3398
                return;
 
3399
 
 
3400
        if (wlc_hw->sih)
 
3401
                ai_clkctl_xtal(wlc_hw->sih, XTAL | PLL, want);
 
3402
 
 
3403
        wlc_hw->sbclk = want;
 
3404
        if (!wlc_hw->sbclk) {
 
3405
                wlc_hw->clk = false;
 
3406
                if (wlc_hw->band && wlc_hw->band->pi)
 
3407
                        wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false);
 
3408
        }
 
3409
}
 
3410
 
 
3411
static void wlc_flushqueues(struct wlc_info *wlc)
 
3412
{
 
3413
        struct wlc_hw_info *wlc_hw = wlc->hw;
 
3414
        uint i;
 
3415
 
 
3416
        wlc->txpend16165war = 0;
 
3417
 
 
3418
        /* free any posted tx packets */
 
3419
        for (i = 0; i < NFIFO; i++)
 
3420
                if (wlc_hw->di[i]) {
 
3421
                        dma_txreclaim(wlc_hw->di[i], HNDDMA_RANGE_ALL);
 
3422
                        TXPKTPENDCLR(wlc, i);
 
3423
                        BCMMSG(wlc->wiphy, "pktpend fifo %d clrd\n", i);
 
3424
                }
 
3425
 
 
3426
        /* free any posted rx packets */
 
3427
        dma_rxreclaim(wlc_hw->di[RX_FIFO]);
 
3428
}
 
3429
 
 
3430
u16 wlc_bmac_read_shm(struct wlc_hw_info *wlc_hw, uint offset)
 
3431
{
 
3432
        return wlc_bmac_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL);
 
3433
}
 
3434
 
 
3435
void wlc_bmac_write_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v)
 
3436
{
 
3437
        wlc_bmac_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL);
 
3438
}
 
3439
 
 
3440
static u16
 
3441
wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset, u32 sel)
 
3442
{
 
3443
        d11regs_t *regs = wlc_hw->regs;
 
3444
        volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata;
 
3445
        volatile u16 *objdata_hi = objdata_lo + 1;
 
3446
        u16 v;
 
3447
 
 
3448
        W_REG(&regs->objaddr, sel | (offset >> 2));
 
3449
        (void)R_REG(&regs->objaddr);
 
3450
        if (offset & 2) {
 
3451
                v = R_REG(objdata_hi);
 
3452
        } else {
 
3453
                v = R_REG(objdata_lo);
 
3454
        }
 
3455
 
 
3456
        return v;
 
3457
}
 
3458
 
 
3459
static void
 
3460
wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset, u16 v, u32 sel)
 
3461
{
 
3462
        d11regs_t *regs = wlc_hw->regs;
 
3463
        volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata;
 
3464
        volatile u16 *objdata_hi = objdata_lo + 1;
 
3465
 
 
3466
        W_REG(&regs->objaddr, sel | (offset >> 2));
 
3467
        (void)R_REG(&regs->objaddr);
 
3468
        if (offset & 2) {
 
3469
                W_REG(objdata_hi, v);
 
3470
        } else {
 
3471
                W_REG(objdata_lo, v);
 
3472
        }
 
3473
}
 
3474
 
 
3475
/* Copy a buffer to shared memory of specified type .
 
3476
 * SHM 'offset' needs to be an even address and
 
3477
 * Buffer length 'len' must be an even number of bytes
 
3478
 * 'sel' selects the type of memory
 
3479
 */
 
3480
void
 
3481
wlc_bmac_copyto_objmem(struct wlc_hw_info *wlc_hw, uint offset, const void *buf,
 
3482
                       int len, u32 sel)
 
3483
{
 
3484
        u16 v;
 
3485
        const u8 *p = (const u8 *)buf;
 
3486
        int i;
 
3487
 
 
3488
        if (len <= 0 || (offset & 1) || (len & 1))
 
3489
                return;
 
3490
 
 
3491
        for (i = 0; i < len; i += 2) {
 
3492
                v = p[i] | (p[i + 1] << 8);
 
3493
                wlc_bmac_write_objmem(wlc_hw, offset + i, v, sel);
 
3494
        }
 
3495
}
 
3496
 
 
3497
/* Copy a piece of shared memory of specified type to a buffer .
 
3498
 * SHM 'offset' needs to be an even address and
 
3499
 * Buffer length 'len' must be an even number of bytes
 
3500
 * 'sel' selects the type of memory
 
3501
 */
 
3502
void
 
3503
wlc_bmac_copyfrom_objmem(struct wlc_hw_info *wlc_hw, uint offset, void *buf,
 
3504
                         int len, u32 sel)
 
3505
{
 
3506
        u16 v;
 
3507
        u8 *p = (u8 *) buf;
 
3508
        int i;
 
3509
 
 
3510
        if (len <= 0 || (offset & 1) || (len & 1))
 
3511
                return;
 
3512
 
 
3513
        for (i = 0; i < len; i += 2) {
 
3514
                v = wlc_bmac_read_objmem(wlc_hw, offset + i, sel);
 
3515
                p[i] = v & 0xFF;
 
3516
                p[i + 1] = (v >> 8) & 0xFF;
 
3517
        }
 
3518
}
 
3519
 
 
3520
void wlc_bmac_copyfrom_vars(struct wlc_hw_info *wlc_hw, char **buf, uint *len)
 
3521
{
 
3522
        BCMMSG(wlc_hw->wlc->wiphy, "nvram vars totlen=%d\n",
 
3523
                wlc_hw->vars_size);
 
3524
 
 
3525
        *buf = wlc_hw->vars;
 
3526
        *len = wlc_hw->vars_size;
 
3527
}
 
3528
 
 
3529
void wlc_bmac_retrylimit_upd(struct wlc_hw_info *wlc_hw, u16 SRL, u16 LRL)
 
3530
{
 
3531
        wlc_hw->SRL = SRL;
 
3532
        wlc_hw->LRL = LRL;
 
3533
 
 
3534
        /* write retry limit to SCR, shouldn't need to suspend */
 
3535
        if (wlc_hw->up) {
 
3536
                W_REG(&wlc_hw->regs->objaddr,
 
3537
                      OBJADDR_SCR_SEL | S_DOT11_SRC_LMT);
 
3538
                (void)R_REG(&wlc_hw->regs->objaddr);
 
3539
                W_REG(&wlc_hw->regs->objdata, wlc_hw->SRL);
 
3540
                W_REG(&wlc_hw->regs->objaddr,
 
3541
                      OBJADDR_SCR_SEL | S_DOT11_LRC_LMT);
 
3542
                (void)R_REG(&wlc_hw->regs->objaddr);
 
3543
                W_REG(&wlc_hw->regs->objdata, wlc_hw->LRL);
 
3544
        }
 
3545
}
 
3546
 
 
3547
void wlc_bmac_pllreq(struct wlc_hw_info *wlc_hw, bool set, mbool req_bit)
 
3548
{
 
3549
        if (set) {
 
3550
                if (mboolisset(wlc_hw->pllreq, req_bit))
 
3551
                        return;
 
3552
 
 
3553
                mboolset(wlc_hw->pllreq, req_bit);
 
3554
 
 
3555
                if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
 
3556
                        if (!wlc_hw->sbclk) {
 
3557
                                wlc_bmac_xtal(wlc_hw, ON);
 
3558
                        }
 
3559
                }
 
3560
        } else {
 
3561
                if (!mboolisset(wlc_hw->pllreq, req_bit))
 
3562
                        return;
 
3563
 
 
3564
                mboolclr(wlc_hw->pllreq, req_bit);
 
3565
 
 
3566
                if (mboolisset(wlc_hw->pllreq, WLC_PLLREQ_FLIP)) {
 
3567
                        if (wlc_hw->sbclk) {
 
3568
                                wlc_bmac_xtal(wlc_hw, OFF);
 
3569
                        }
 
3570
                }
 
3571
        }
 
3572
 
 
3573
        return;
 
3574
}
 
3575
 
 
3576
u16 wlc_bmac_rate_shm_offset(struct wlc_hw_info *wlc_hw, u8 rate)
 
3577
{
 
3578
        u16 table_ptr;
 
3579
        u8 phy_rate, index;
 
3580
 
 
3581
        /* get the phy specific rate encoding for the PLCP SIGNAL field */
 
3582
        /* XXX4321 fixup needed ? */
 
3583
        if (IS_OFDM(rate))
 
3584
                table_ptr = M_RT_DIRMAP_A;
 
3585
        else
 
3586
                table_ptr = M_RT_DIRMAP_B;
 
3587
 
 
3588
        /* for a given rate, the LS-nibble of the PLCP SIGNAL field is
 
3589
         * the index into the rate table.
 
3590
         */
 
3591
        phy_rate = rate_info[rate] & WLC_RATE_MASK;
 
3592
        index = phy_rate & 0xf;
 
3593
 
 
3594
        /* Find the SHM pointer to the rate table entry by looking in the
 
3595
         * Direct-map Table
 
3596
         */
 
3597
        return 2 * wlc_bmac_read_shm(wlc_hw, table_ptr + (index * 2));
 
3598
}
 
3599
 
 
3600
void wlc_bmac_antsel_set(struct wlc_hw_info *wlc_hw, u32 antsel_avail)
 
3601
{
 
3602
        wlc_hw->antsel_avail = antsel_avail;
 
3603
}