staging: brcm80211: remove include file proto/802.1d.h
[firefly-linux-kernel-4.4.55.git] / drivers / staging / brcm80211 / brcmsmac / wlc_phy_shim.c
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  * 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
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27
28 #include <proto/802.11.h>
29 #include <osl.h>
30 #include <bcmdefs.h>
31 #include <bcmutils.h>
32 #include <bcmwifi.h>
33 #include <siutils.h>
34 #include <wlioctl.h>
35 #include <sbconfig.h>
36 #include <sbchipc.h>
37 #include <pcicfg.h>
38 #include <sbhnddma.h>
39 #include <hnddma.h>
40 #include <hndpmu.h>
41
42 #include "wlc_types.h"
43 #include "wl_dbg.h"
44 #include "sbhndpio.h"
45 #include "wlc_cfg.h"
46 #include "d11.h"
47 #include "wlc_rate.h"
48 #include "wlc_scb.h"
49 #include "wlc_pub.h"
50 #include "phy/wlc_phy_hal.h"
51 #include "wlc_channel.h"
52 #include "bcmsrom.h"
53 #include "wlc_key.h"
54 #include "wlc_bmac.h"
55 #include "wlc_phy_hal.h"
56 #include "wl_export.h"
57 #include "wlc_bsscfg.h"
58 #include "wlc_mac80211.h"
59 #include "wlc_phy_shim.h"
60
61 /* PHY SHIM module specific state */
62 struct wlc_phy_shim_info {
63         struct wlc_hw_info *wlc_hw;     /* pointer to main wlc_hw structure */
64         void *wlc;              /* pointer to main wlc structure */
65         void *wl;               /* pointer to os-specific private state */
66 };
67
68 wlc_phy_shim_info_t *wlc_phy_shim_attach(struct wlc_hw_info *wlc_hw,
69                                                        void *wl, void *wlc) {
70         wlc_phy_shim_info_t *physhim = NULL;
71
72         physhim = kzalloc(sizeof(wlc_phy_shim_info_t), GFP_ATOMIC);
73         if (!physhim) {
74                 WL_ERROR("wl%d: wlc_phy_shim_attach: out of mem\n",
75                          wlc_hw->unit);
76                 return NULL;
77         }
78         physhim->wlc_hw = wlc_hw;
79         physhim->wlc = wlc;
80         physhim->wl = wl;
81
82         return physhim;
83 }
84
85 void wlc_phy_shim_detach(wlc_phy_shim_info_t *physhim)
86 {
87         if (!physhim)
88                 return;
89
90         kfree(physhim);
91 }
92
93 struct wlapi_timer *wlapi_init_timer(wlc_phy_shim_info_t *physhim,
94                                      void (*fn) (void *arg), void *arg,
95                                      const char *name)
96 {
97         return (struct wlapi_timer *)wl_init_timer(physhim->wl, fn, arg, name);
98 }
99
100 void wlapi_free_timer(wlc_phy_shim_info_t *physhim, struct wlapi_timer *t)
101 {
102         wl_free_timer(physhim->wl, (struct wl_timer *)t);
103 }
104
105 void
106 wlapi_add_timer(wlc_phy_shim_info_t *physhim, struct wlapi_timer *t, uint ms,
107                 int periodic)
108 {
109         wl_add_timer(physhim->wl, (struct wl_timer *)t, ms, periodic);
110 }
111
112 bool wlapi_del_timer(wlc_phy_shim_info_t *physhim, struct wlapi_timer *t)
113 {
114         return wl_del_timer(physhim->wl, (struct wl_timer *)t);
115 }
116
117 void wlapi_intrson(wlc_phy_shim_info_t *physhim)
118 {
119         wl_intrson(physhim->wl);
120 }
121
122 u32 wlapi_intrsoff(wlc_phy_shim_info_t *physhim)
123 {
124         return wl_intrsoff(physhim->wl);
125 }
126
127 void wlapi_intrsrestore(wlc_phy_shim_info_t *physhim, u32 macintmask)
128 {
129         wl_intrsrestore(physhim->wl, macintmask);
130 }
131
132 void wlapi_bmac_write_shm(wlc_phy_shim_info_t *physhim, uint offset, u16 v)
133 {
134         wlc_bmac_write_shm(physhim->wlc_hw, offset, v);
135 }
136
137 u16 wlapi_bmac_read_shm(wlc_phy_shim_info_t *physhim, uint offset)
138 {
139         return wlc_bmac_read_shm(physhim->wlc_hw, offset);
140 }
141
142 void
143 wlapi_bmac_mhf(wlc_phy_shim_info_t *physhim, u8 idx, u16 mask,
144                u16 val, int bands)
145 {
146         wlc_bmac_mhf(physhim->wlc_hw, idx, mask, val, bands);
147 }
148
149 void wlapi_bmac_corereset(wlc_phy_shim_info_t *physhim, u32 flags)
150 {
151         wlc_bmac_corereset(physhim->wlc_hw, flags);
152 }
153
154 void wlapi_suspend_mac_and_wait(wlc_phy_shim_info_t *physhim)
155 {
156         wlc_suspend_mac_and_wait(physhim->wlc);
157 }
158
159 void wlapi_switch_macfreq(wlc_phy_shim_info_t *physhim, u8 spurmode)
160 {
161         wlc_bmac_switch_macfreq(physhim->wlc_hw, spurmode);
162 }
163
164 void wlapi_enable_mac(wlc_phy_shim_info_t *physhim)
165 {
166         wlc_enable_mac(physhim->wlc);
167 }
168
169 void wlapi_bmac_mctrl(wlc_phy_shim_info_t *physhim, u32 mask, u32 val)
170 {
171         wlc_bmac_mctrl(physhim->wlc_hw, mask, val);
172 }
173
174 void wlapi_bmac_phy_reset(wlc_phy_shim_info_t *physhim)
175 {
176         wlc_bmac_phy_reset(physhim->wlc_hw);
177 }
178
179 void wlapi_bmac_bw_set(wlc_phy_shim_info_t *physhim, u16 bw)
180 {
181         wlc_bmac_bw_set(physhim->wlc_hw, bw);
182 }
183
184 u16 wlapi_bmac_get_txant(wlc_phy_shim_info_t *physhim)
185 {
186         return wlc_bmac_get_txant(physhim->wlc_hw);
187 }
188
189 void wlapi_bmac_phyclk_fgc(wlc_phy_shim_info_t *physhim, bool clk)
190 {
191         wlc_bmac_phyclk_fgc(physhim->wlc_hw, clk);
192 }
193
194 void wlapi_bmac_macphyclk_set(wlc_phy_shim_info_t *physhim, bool clk)
195 {
196         wlc_bmac_macphyclk_set(physhim->wlc_hw, clk);
197 }
198
199 void wlapi_bmac_core_phypll_ctl(wlc_phy_shim_info_t *physhim, bool on)
200 {
201         wlc_bmac_core_phypll_ctl(physhim->wlc_hw, on);
202 }
203
204 void wlapi_bmac_core_phypll_reset(wlc_phy_shim_info_t *physhim)
205 {
206         wlc_bmac_core_phypll_reset(physhim->wlc_hw);
207 }
208
209 void wlapi_bmac_ucode_wake_override_phyreg_set(wlc_phy_shim_info_t *physhim)
210 {
211         wlc_ucode_wake_override_set(physhim->wlc_hw, WLC_WAKE_OVERRIDE_PHYREG);
212 }
213
214 void wlapi_bmac_ucode_wake_override_phyreg_clear(wlc_phy_shim_info_t *physhim)
215 {
216         wlc_ucode_wake_override_clear(physhim->wlc_hw,
217                                       WLC_WAKE_OVERRIDE_PHYREG);
218 }
219
220 void
221 wlapi_bmac_write_template_ram(wlc_phy_shim_info_t *physhim, int offset,
222                               int len, void *buf)
223 {
224         wlc_bmac_write_template_ram(physhim->wlc_hw, offset, len, buf);
225 }
226
227 u16 wlapi_bmac_rate_shm_offset(wlc_phy_shim_info_t *physhim, u8 rate)
228 {
229         return wlc_bmac_rate_shm_offset(physhim->wlc_hw, rate);
230 }
231
232 void wlapi_ucode_sample_init(wlc_phy_shim_info_t *physhim)
233 {
234 }
235
236 void
237 wlapi_copyfrom_objmem(wlc_phy_shim_info_t *physhim, uint offset, void *buf,
238                       int len, u32 sel)
239 {
240         wlc_bmac_copyfrom_objmem(physhim->wlc_hw, offset, buf, len, sel);
241 }
242
243 void
244 wlapi_copyto_objmem(wlc_phy_shim_info_t *physhim, uint offset, const void *buf,
245                     int l, u32 sel)
246 {
247         wlc_bmac_copyto_objmem(physhim->wlc_hw, offset, buf, l, sel);
248 }