blob: bf8e2e1a15f64eeff973bc663caf3668186068ba [file] [log] [blame]
Henry Ptasinskia9533e72010-09-08 21:04:42 -07001/*
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 * This is "two-way" interface, acting as the SHIM layer between WL and PHY layer.
19 * WL driver can optinally call this translation layer to do some preprocessing, then reach PHY.
20 * On the PHY->WL driver direction, all calls go through this layer since PHY doesn't have the
21 * access to wlc_hw pointer.
22 */
23
Brett Rudley33279892010-10-01 18:03:27 -070024#include <linux/kernel.h>
Henry Ptasinskia9533e72010-09-08 21:04:42 -070025#include <bcmdefs.h>
Greg Kroah-Hartmana1c16ed2010-10-21 11:17:44 -070026#include <wlc_cfg.h>
27#include <linuxver.h>
28#include <bcmutils.h>
Henry Ptasinskia9533e72010-09-08 21:04:42 -070029#include <osl.h>
30
31#include <proto/802.11.h>
32#include <bcmwifi.h>
33#include <siutils.h>
34#include <bcmendian.h>
35#include <wlioctl.h>
36#include <sbconfig.h>
37#include <sbchipc.h>
38#include <pcicfg.h>
39#include <sbhndpio.h>
40#include <sbhnddma.h>
41#include <hnddma.h>
42#include <hndpmu.h>
43#include <d11.h>
44#include <wlc_rate.h>
45#include <wlc_pub.h>
46#include <wlc_channel.h>
47#include <bcmsrom.h>
48#include <wlc_key.h>
49
50#include <wlc_mac80211.h>
51
52#include <wlc_bmac.h>
53#include <wlc_phy_shim.h>
54#include <wlc_phy_hal.h>
55#include <wl_export.h>
56
57/* PHY SHIM module specific state */
58struct wlc_phy_shim_info {
59 wlc_hw_info_t *wlc_hw; /* pointer to main wlc_hw structure */
60 void *wlc; /* pointer to main wlc structure */
61 void *wl; /* pointer to os-specific private state */
62};
63
Greg Kroah-Hartman0d2f0722010-10-08 14:28:21 -070064wlc_phy_shim_info_t *wlc_phy_shim_attach(wlc_hw_info_t *wlc_hw,
Henry Ptasinskia9533e72010-09-08 21:04:42 -070065 void *wl, void *wlc) {
66 wlc_phy_shim_info_t *physhim = NULL;
67
mike.rapoport@gmail.com5fcc1fc2010-10-13 00:09:10 +020068 physhim = kzalloc(sizeof(wlc_phy_shim_info_t), GFP_ATOMIC);
Jason Cooperca8c1e52010-09-14 09:45:33 -040069 if (!physhim) {
mike.rapoport@gmail.com97e17d02010-10-13 00:09:09 +020070 WL_ERROR(("wl%d: wlc_phy_shim_attach: out of mem\n", wlc_hw->unit));
Henry Ptasinskia9533e72010-09-08 21:04:42 -070071 return NULL;
72 }
Henry Ptasinskia9533e72010-09-08 21:04:42 -070073 physhim->wlc_hw = wlc_hw;
74 physhim->wlc = wlc;
75 physhim->wl = wl;
76
77 return physhim;
78}
79
Greg Kroah-Hartman0d2f0722010-10-08 14:28:21 -070080void wlc_phy_shim_detach(wlc_phy_shim_info_t *physhim)
Jason Coopera2627bc2010-09-14 09:45:31 -040081{
Henry Ptasinskia9533e72010-09-08 21:04:42 -070082 if (!physhim)
83 return;
84
mike.rapoport@gmail.com182acb32010-10-13 00:09:12 +020085 kfree(physhim);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070086}
87
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040088struct wlapi_timer *wlapi_init_timer(wlc_phy_shim_info_t *physhim,
Henry Ptasinskia9533e72010-09-08 21:04:42 -070089 void (*fn) (void *arg), void *arg,
90 const char *name)
91{
92 return (struct wlapi_timer *)wl_init_timer(physhim->wl, fn, arg, name);
93}
94
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040095void wlapi_free_timer(wlc_phy_shim_info_t *physhim, struct wlapi_timer *t)
Henry Ptasinskia9533e72010-09-08 21:04:42 -070096{
97 wl_free_timer(physhim->wl, (struct wl_timer *)t);
98}
99
100void
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400101wlapi_add_timer(wlc_phy_shim_info_t *physhim, struct wlapi_timer *t, uint ms,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700102 int periodic)
103{
104 wl_add_timer(physhim->wl, (struct wl_timer *)t, ms, periodic);
105}
106
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400107bool wlapi_del_timer(wlc_phy_shim_info_t *physhim, struct wlapi_timer *t)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700108{
109 return wl_del_timer(physhim->wl, (struct wl_timer *)t);
110}
111
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400112void wlapi_intrson(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700113{
114 wl_intrson(physhim->wl);
115}
116
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700117u32 wlapi_intrsoff(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700118{
119 return wl_intrsoff(physhim->wl);
120}
121
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700122void wlapi_intrsrestore(wlc_phy_shim_info_t *physhim, u32 macintmask)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700123{
124 wl_intrsrestore(physhim->wl, macintmask);
125}
126
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700127void wlapi_bmac_write_shm(wlc_phy_shim_info_t *physhim, uint offset, u16 v)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700128{
129 wlc_bmac_write_shm(physhim->wlc_hw, offset, v);
130}
131
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700132u16 wlapi_bmac_read_shm(wlc_phy_shim_info_t *physhim, uint offset)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700133{
134 return wlc_bmac_read_shm(physhim->wlc_hw, offset);
135}
136
137void
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700138wlapi_bmac_mhf(wlc_phy_shim_info_t *physhim, u8 idx, u16 mask,
139 u16 val, int bands)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700140{
141 wlc_bmac_mhf(physhim->wlc_hw, idx, mask, val, bands);
142}
143
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700144void wlapi_bmac_corereset(wlc_phy_shim_info_t *physhim, u32 flags)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700145{
146 wlc_bmac_corereset(physhim->wlc_hw, flags);
147}
148
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400149void wlapi_suspend_mac_and_wait(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700150{
151 wlc_suspend_mac_and_wait(physhim->wlc);
152}
153
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700154void wlapi_switch_macfreq(wlc_phy_shim_info_t *physhim, u8 spurmode)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700155{
156 wlc_bmac_switch_macfreq(physhim->wlc_hw, spurmode);
157}
158
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400159void wlapi_enable_mac(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700160{
161 wlc_enable_mac(physhim->wlc);
162}
163
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700164void wlapi_bmac_mctrl(wlc_phy_shim_info_t *physhim, u32 mask, u32 val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700165{
166 wlc_bmac_mctrl(physhim->wlc_hw, mask, val);
167}
168
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400169void wlapi_bmac_phy_reset(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700170{
171 wlc_bmac_phy_reset(physhim->wlc_hw);
172}
173
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700174void wlapi_bmac_bw_set(wlc_phy_shim_info_t *physhim, u16 bw)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700175{
176 wlc_bmac_bw_set(physhim->wlc_hw, bw);
177}
178
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700179u16 wlapi_bmac_get_txant(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700180{
181 return wlc_bmac_get_txant(physhim->wlc_hw);
182}
183
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400184void wlapi_bmac_phyclk_fgc(wlc_phy_shim_info_t *physhim, bool clk)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700185{
186 wlc_bmac_phyclk_fgc(physhim->wlc_hw, clk);
187}
188
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400189void wlapi_bmac_macphyclk_set(wlc_phy_shim_info_t *physhim, bool clk)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700190{
191 wlc_bmac_macphyclk_set(physhim->wlc_hw, clk);
192}
193
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400194void wlapi_bmac_core_phypll_ctl(wlc_phy_shim_info_t *physhim, bool on)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700195{
196 wlc_bmac_core_phypll_ctl(physhim->wlc_hw, on);
197}
198
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400199void wlapi_bmac_core_phypll_reset(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700200{
201 wlc_bmac_core_phypll_reset(physhim->wlc_hw);
202}
203
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400204void wlapi_bmac_ucode_wake_override_phyreg_set(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700205{
206 wlc_ucode_wake_override_set(physhim->wlc_hw, WLC_WAKE_OVERRIDE_PHYREG);
207}
208
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400209void wlapi_bmac_ucode_wake_override_phyreg_clear(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700210{
211 wlc_ucode_wake_override_clear(physhim->wlc_hw,
212 WLC_WAKE_OVERRIDE_PHYREG);
213}
214
215void
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400216wlapi_bmac_write_template_ram(wlc_phy_shim_info_t *physhim, int offset,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700217 int len, void *buf)
218{
219 wlc_bmac_write_template_ram(physhim->wlc_hw, offset, len, buf);
220}
221
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700222u16 wlapi_bmac_rate_shm_offset(wlc_phy_shim_info_t *physhim, u8 rate)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700223{
224 return wlc_bmac_rate_shm_offset(physhim->wlc_hw, rate);
225}
226
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400227void wlapi_ucode_sample_init(wlc_phy_shim_info_t *physhim)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700228{
229}
230
231void
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400232wlapi_copyfrom_objmem(wlc_phy_shim_info_t *physhim, uint offset, void *buf,
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700233 int len, u32 sel)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700234{
235 wlc_bmac_copyfrom_objmem(physhim->wlc_hw, offset, buf, len, sel);
236}
237
238void
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400239wlapi_copyto_objmem(wlc_phy_shim_info_t *physhim, uint offset, const void *buf,
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700240 int l, u32 sel)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700241{
242 wlc_bmac_copyto_objmem(physhim->wlc_hw, offset, buf, l, sel);
243}