brcmfmac: switch to new platform data
[deliverable/linux.git] / drivers / net / wireless / broadcom / brcm80211 / brcmfmac / common.c
CommitLineData
5b435de0
AS
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 */
02f77195 16
5b435de0
AS
17#include <linux/kernel.h>
18#include <linux/string.h>
5b435de0 19#include <linux/netdevice.h>
5dc3b7b9 20#include <linux/module.h>
5b435de0
AS
21#include <brcmu_wifi.h>
22#include <brcmu_utils.h>
122d3d04 23#include "core.h"
d14f78b9 24#include "bus.h"
a8e8ed34 25#include "debug.h"
0af29bf7 26#include "fwil.h"
6f5838a4 27#include "fwil_types.h"
e5483576 28#include "tracepoint.h"
6b89dcb3 29#include "common.h"
8ea56be0 30#include "of.h"
6b89dcb3 31
d84d99e0
HM
32MODULE_AUTHOR("Broadcom Corporation");
33MODULE_DESCRIPTION("Broadcom 802.11 wireless LAN fullmac driver.");
34MODULE_LICENSE("Dual BSD/GPL");
35
6b89dcb3 36const u8 ALLFFMAC[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
5b435de0 37
0af29bf7
HM
38#define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
39#define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
5b435de0 40
e09cc63d
DK
41/* boost value for RSSI_DELTA in preferred join selection */
42#define BRCMF_JOIN_PREF_RSSI_BOOST 8
43
7d34b056
HM
44#define BRCMF_DEFAULT_TXGLOM_SIZE 32 /* max tx frames in glom chain */
45
46static int brcmf_sdiod_txglomsz = BRCMF_DEFAULT_TXGLOM_SIZE;
47module_param_named(txglomsz, brcmf_sdiod_txglomsz, int, 0);
48MODULE_PARM_DESC(txglomsz, "Maximum tx packet chain size [SDIO]");
49
50/* Debug level configuration. See debug.h for bits, sysfs modifiable */
51int brcmf_msg_level;
52module_param_named(debug, brcmf_msg_level, int, S_IRUSR | S_IWUSR);
53MODULE_PARM_DESC(debug, "Level of debug output");
54
55static int brcmf_p2p_enable;
56module_param_named(p2pon, brcmf_p2p_enable, int, 0);
57MODULE_PARM_DESC(p2pon, "Enable legacy p2p management functionality");
58
59static int brcmf_feature_disable;
60module_param_named(feature_disable, brcmf_feature_disable, int, 0);
61MODULE_PARM_DESC(feature_disable, "Disable features");
62
63static char brcmf_firmware_path[BRCMF_FW_ALTPATH_LEN];
64module_param_string(alternative_fw_path, brcmf_firmware_path,
65 BRCMF_FW_ALTPATH_LEN, S_IRUSR);
66MODULE_PARM_DESC(alternative_fw_path, "Alternative firmware path");
67
68static int brcmf_fcmode;
69module_param_named(fcmode, brcmf_fcmode, int, 0);
70MODULE_PARM_DESC(fcmode, "Mode of firmware signalled flow control");
71
72static int brcmf_roamoff;
73module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR);
74MODULE_PARM_DESC(roamoff, "Do not use internal roaming engine");
75
8ba83d4d
AS
76#ifdef DEBUG
77/* always succeed brcmf_bus_start() */
78static int brcmf_ignore_probe_fail;
79module_param_named(ignore_probe_fail, brcmf_ignore_probe_fail, int, 0);
80MODULE_PARM_DESC(ignore_probe_fail, "always succeed probe for debugging");
81#endif
82
4d792895 83static struct brcmfmac_platform_data *brcmfmac_pdata;
7d34b056
HM
84struct brcmf_mp_global_t brcmf_mp_global;
85
0af29bf7 86int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
5b435de0 87{
0af29bf7
HM
88 s8 eventmask[BRCMF_EVENTING_MASK_LEN];
89 u8 buf[BRCMF_DCMD_SMLEN];
e09cc63d 90 struct brcmf_join_pref_params join_pref_params[2];
48622903
AS
91 struct brcmf_rev_info_le revinfo;
92 struct brcmf_rev_info *ri;
0af29bf7
HM
93 char *ptr;
94 s32 err;
5b435de0 95
0af29bf7
HM
96 /* retreive mac address */
97 err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
98 sizeof(ifp->mac_addr));
99 if (err < 0) {
48622903 100 brcmf_err("Retreiving cur_etheraddr failed, %d\n", err);
0af29bf7 101 goto done;
5b435de0 102 }
0af29bf7 103 memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
5b435de0 104
48622903
AS
105 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_REVINFO,
106 &revinfo, sizeof(revinfo));
7f52c81d 107 ri = &ifp->drvr->revinfo;
48622903
AS
108 if (err < 0) {
109 brcmf_err("retrieving revision info failed, %d\n", err);
110 } else {
48622903
AS
111 ri->vendorid = le32_to_cpu(revinfo.vendorid);
112 ri->deviceid = le32_to_cpu(revinfo.deviceid);
113 ri->radiorev = le32_to_cpu(revinfo.radiorev);
114 ri->chiprev = le32_to_cpu(revinfo.chiprev);
115 ri->corerev = le32_to_cpu(revinfo.corerev);
116 ri->boardid = le32_to_cpu(revinfo.boardid);
117 ri->boardvendor = le32_to_cpu(revinfo.boardvendor);
118 ri->boardrev = le32_to_cpu(revinfo.boardrev);
119 ri->driverrev = le32_to_cpu(revinfo.driverrev);
120 ri->ucoderev = le32_to_cpu(revinfo.ucoderev);
121 ri->bus = le32_to_cpu(revinfo.bus);
122 ri->chipnum = le32_to_cpu(revinfo.chipnum);
123 ri->phytype = le32_to_cpu(revinfo.phytype);
124 ri->phyrev = le32_to_cpu(revinfo.phyrev);
125 ri->anarev = le32_to_cpu(revinfo.anarev);
126 ri->chippkg = le32_to_cpu(revinfo.chippkg);
127 ri->nvramrev = le32_to_cpu(revinfo.nvramrev);
128 }
7f52c81d 129 ri->result = err;
48622903 130
5b435de0
AS
131 /* query for 'ver' to get version info from firmware */
132 memset(buf, 0, sizeof(buf));
0af29bf7
HM
133 strcpy(buf, "ver");
134 err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
135 if (err < 0) {
5e8149f5 136 brcmf_err("Retreiving version information failed, %d\n",
0af29bf7
HM
137 err);
138 goto done;
139 }
140 ptr = (char *)buf;
5b435de0 141 strsep(&ptr, "\n");
55685b8f 142
5b435de0 143 /* Print fw version info */
5e8149f5 144 brcmf_err("Firmware version = %s\n", buf);
5b435de0 145
55685b8f
AS
146 /* locate firmware version number for ethtool */
147 ptr = strrchr(buf, ' ') + 1;
148 strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver));
149
5e787f75
DK
150 /* set mpc */
151 err = brcmf_fil_iovar_int_set(ifp, "mpc", 1);
152 if (err) {
153 brcmf_err("failed setting mpc\n");
154 goto done;
155 }
156
e09cc63d
DK
157 /* Setup join_pref to select target by RSSI(with boost on 5GHz) */
158 join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
159 join_pref_params[0].len = 2;
160 join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
161 join_pref_params[0].band = WLC_BAND_5G;
162 join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
163 join_pref_params[1].len = 2;
164 join_pref_params[1].rssi_gain = 0;
165 join_pref_params[1].band = 0;
166 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
167 sizeof(join_pref_params));
168 if (err)
169 brcmf_err("Set join_pref error (%d)\n", err);
170
0af29bf7
HM
171 /* Setup event_msgs, enable E_IF */
172 err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
173 BRCMF_EVENTING_MASK_LEN);
174 if (err) {
5e8149f5 175 brcmf_err("Get event_msgs error (%d)\n", err);
0af29bf7
HM
176 goto done;
177 }
178 setbit(eventmask, BRCMF_E_IF);
179 err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask,
180 BRCMF_EVENTING_MASK_LEN);
181 if (err) {
5e8149f5 182 brcmf_err("Set event_msgs error (%d)\n", err);
0af29bf7
HM
183 goto done;
184 }
185
186 /* Setup default scan channel time */
187 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
188 BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
189 if (err) {
5e8149f5 190 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
0af29bf7
HM
191 err);
192 goto done;
193 }
194
195 /* Setup default scan unassoc time */
196 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
197 BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
198 if (err) {
5e8149f5 199 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
0af29bf7
HM
200 err);
201 goto done;
202 }
203
7bf65aa9
HM
204 /* Enable tx beamforming, errors can be ignored (not supported) */
205 (void)brcmf_fil_iovar_int_set(ifp, "txbf", 1);
206
cf458287
AS
207 /* do bus specific preinit here */
208 err = brcmf_bus_preinit(ifp->drvr->bus_if);
0af29bf7
HM
209done:
210 return err;
5b435de0 211}
e5483576 212
e5483576
AS
213#if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
214void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
215{
216 struct va_format vaf = {
217 .fmt = fmt,
218 };
219 va_list args;
220
221 va_start(args, fmt);
222 vaf.va = &args;
223 if (brcmf_msg_level & level)
224 pr_debug("%s %pV", func, &vaf);
225 trace_brcmf_dbg(level, func, &vaf);
226 va_end(args);
227}
228#endif
7d34b056 229
d84d99e0 230static void brcmf_mp_attach(void)
7d34b056 231{
4d792895
HM
232 /* If module param firmware path is set then this will always be used,
233 * if not set then if available use the platform data version. To make
234 * sure it gets initialized at all, always copy the module param version
235 */
7d34b056
HM
236 strlcpy(brcmf_mp_global.firmware_path, brcmf_firmware_path,
237 BRCMF_FW_ALTPATH_LEN);
4d792895
HM
238 if ((brcmfmac_pdata) && (brcmfmac_pdata->fw_alternative_path) &&
239 (brcmf_mp_global.firmware_path[0] == '\0')) {
240 strlcpy(brcmf_mp_global.firmware_path,
241 brcmfmac_pdata->fw_alternative_path,
242 BRCMF_FW_ALTPATH_LEN);
243 }
7d34b056
HM
244}
245
4d792895
HM
246struct brcmfmac_sdio_pd *brcmf_get_module_param(struct device *dev,
247 enum brcmf_bus_type bus_type,
248 u32 chip, u32 chiprev)
8ea56be0 249{
4d792895
HM
250 struct brcmfmac_sdio_pd *pdata;
251 struct brcmfmac_pd_device *device_pd;
252 int i;
253
254 if (brcmfmac_pdata) {
255 for (i = 0; i < brcmfmac_pdata->device_count; i++) {
256 device_pd = &brcmfmac_pdata->devices[i];
257 if ((device_pd->bus_type == bus_type) &&
258 (device_pd->id == chip) &&
259 ((device_pd->rev == chiprev) ||
260 (device_pd->rev == -1))) {
261 brcmf_dbg(INFO, "Platform data for device found\n");
262 if (device_pd->bus_type == BRCMF_BUSTYPE_SDIO)
263 return &device_pd->bus.sdio;
264 break;
265 }
266 }
267 }
268 pdata = NULL;
269 brcmf_of_probe(dev, &pdata);
270
271 return pdata;
8ea56be0
HM
272}
273
7d34b056
HM
274int brcmf_mp_device_attach(struct brcmf_pub *drvr)
275{
276 drvr->settings = kzalloc(sizeof(*drvr->settings), GFP_ATOMIC);
73345fd2 277 if (!drvr->settings)
7d34b056 278 return -ENOMEM;
7d34b056
HM
279
280 drvr->settings->sdiod_txglomsz = brcmf_sdiod_txglomsz;
281 drvr->settings->p2p_enable = !!brcmf_p2p_enable;
282 drvr->settings->feature_disable = brcmf_feature_disable;
283 drvr->settings->fcmode = brcmf_fcmode;
284 drvr->settings->roamoff = !!brcmf_roamoff;
8ba83d4d
AS
285#ifdef DEBUG
286 drvr->settings->ignore_probe_fail = !!brcmf_ignore_probe_fail;
287#endif
7d34b056
HM
288 return 0;
289}
290
291void brcmf_mp_device_detach(struct brcmf_pub *drvr)
292{
293 kfree(drvr->settings);
294}
295
8ea56be0
HM
296static int __init brcmf_common_pd_probe(struct platform_device *pdev)
297{
298 brcmf_dbg(INFO, "Enter\n");
299
300 brcmfmac_pdata = dev_get_platdata(&pdev->dev);
301
302 if (brcmfmac_pdata->power_on)
303 brcmfmac_pdata->power_on();
304
305 return 0;
306}
307
308static int brcmf_common_pd_remove(struct platform_device *pdev)
309{
310 brcmf_dbg(INFO, "Enter\n");
311
312 if (brcmfmac_pdata->power_off)
313 brcmfmac_pdata->power_off();
314
315 return 0;
316}
317
318static struct platform_driver brcmf_pd = {
319 .remove = brcmf_common_pd_remove,
320 .driver = {
4d792895 321 .name = BRCMFMAC_PDATA_NAME,
8ea56be0
HM
322 }
323};
324
d84d99e0
HM
325static int __init brcmfmac_module_init(void)
326{
327 int err;
328
329 /* Initialize debug system first */
330 brcmf_debugfs_init();
331
8ea56be0
HM
332 /* Get the platform data (if available) for our devices */
333 err = platform_driver_probe(&brcmf_pd, brcmf_common_pd_probe);
334 if (err == -ENODEV)
335 brcmf_dbg(INFO, "No platform data available.\n");
336
d84d99e0
HM
337 /* Initialize global module paramaters */
338 brcmf_mp_attach();
339
340 /* Continue the initialization by registering the different busses */
341 err = brcmf_core_init();
8ea56be0 342 if (err) {
d84d99e0 343 brcmf_debugfs_exit();
8ea56be0
HM
344 if (brcmfmac_pdata)
345 platform_driver_unregister(&brcmf_pd);
346 }
d84d99e0
HM
347
348 return err;
349}
350
351static void __exit brcmfmac_module_exit(void)
352{
353 brcmf_core_exit();
8ea56be0
HM
354 if (brcmfmac_pdata)
355 platform_driver_unregister(&brcmf_pd);
d84d99e0
HM
356 brcmf_debugfs_exit();
357}
358
359module_init(brcmfmac_module_init);
360module_exit(brcmfmac_module_exit);
361
This page took 0.355398 seconds and 5 git commands to generate.