Commit | Line | Data |
---|---|---|
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> |
5b435de0 AS |
20 | #include <brcmu_wifi.h> |
21 | #include <brcmu_utils.h> | |
122d3d04 | 22 | #include "core.h" |
d14f78b9 | 23 | #include "bus.h" |
a8e8ed34 | 24 | #include "debug.h" |
0af29bf7 | 25 | #include "fwil.h" |
6f5838a4 | 26 | #include "fwil_types.h" |
e5483576 | 27 | #include "tracepoint.h" |
6b89dcb3 HM |
28 | #include "common.h" |
29 | ||
30 | const u8 ALLFFMAC[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
5b435de0 | 31 | |
0af29bf7 HM |
32 | #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40 |
33 | #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40 | |
5b435de0 | 34 | |
e09cc63d DK |
35 | /* boost value for RSSI_DELTA in preferred join selection */ |
36 | #define BRCMF_JOIN_PREF_RSSI_BOOST 8 | |
37 | ||
7d34b056 HM |
38 | #define BRCMF_DEFAULT_TXGLOM_SIZE 32 /* max tx frames in glom chain */ |
39 | ||
40 | static int brcmf_sdiod_txglomsz = BRCMF_DEFAULT_TXGLOM_SIZE; | |
41 | module_param_named(txglomsz, brcmf_sdiod_txglomsz, int, 0); | |
42 | MODULE_PARM_DESC(txglomsz, "Maximum tx packet chain size [SDIO]"); | |
43 | ||
44 | /* Debug level configuration. See debug.h for bits, sysfs modifiable */ | |
45 | int brcmf_msg_level; | |
46 | module_param_named(debug, brcmf_msg_level, int, S_IRUSR | S_IWUSR); | |
47 | MODULE_PARM_DESC(debug, "Level of debug output"); | |
48 | ||
49 | static int brcmf_p2p_enable; | |
50 | module_param_named(p2pon, brcmf_p2p_enable, int, 0); | |
51 | MODULE_PARM_DESC(p2pon, "Enable legacy p2p management functionality"); | |
52 | ||
53 | static int brcmf_feature_disable; | |
54 | module_param_named(feature_disable, brcmf_feature_disable, int, 0); | |
55 | MODULE_PARM_DESC(feature_disable, "Disable features"); | |
56 | ||
57 | static char brcmf_firmware_path[BRCMF_FW_ALTPATH_LEN]; | |
58 | module_param_string(alternative_fw_path, brcmf_firmware_path, | |
59 | BRCMF_FW_ALTPATH_LEN, S_IRUSR); | |
60 | MODULE_PARM_DESC(alternative_fw_path, "Alternative firmware path"); | |
61 | ||
62 | static int brcmf_fcmode; | |
63 | module_param_named(fcmode, brcmf_fcmode, int, 0); | |
64 | MODULE_PARM_DESC(fcmode, "Mode of firmware signalled flow control"); | |
65 | ||
66 | static int brcmf_roamoff; | |
67 | module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR); | |
68 | MODULE_PARM_DESC(roamoff, "Do not use internal roaming engine"); | |
69 | ||
8ba83d4d AS |
70 | #ifdef DEBUG |
71 | /* always succeed brcmf_bus_start() */ | |
72 | static int brcmf_ignore_probe_fail; | |
73 | module_param_named(ignore_probe_fail, brcmf_ignore_probe_fail, int, 0); | |
74 | MODULE_PARM_DESC(ignore_probe_fail, "always succeed probe for debugging"); | |
75 | #endif | |
76 | ||
7d34b056 HM |
77 | struct brcmf_mp_global_t brcmf_mp_global; |
78 | ||
0af29bf7 | 79 | int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) |
5b435de0 | 80 | { |
0af29bf7 HM |
81 | s8 eventmask[BRCMF_EVENTING_MASK_LEN]; |
82 | u8 buf[BRCMF_DCMD_SMLEN]; | |
e09cc63d | 83 | struct brcmf_join_pref_params join_pref_params[2]; |
48622903 AS |
84 | struct brcmf_rev_info_le revinfo; |
85 | struct brcmf_rev_info *ri; | |
0af29bf7 HM |
86 | char *ptr; |
87 | s32 err; | |
5b435de0 | 88 | |
0af29bf7 HM |
89 | /* retreive mac address */ |
90 | err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr, | |
91 | sizeof(ifp->mac_addr)); | |
92 | if (err < 0) { | |
48622903 | 93 | brcmf_err("Retreiving cur_etheraddr failed, %d\n", err); |
0af29bf7 | 94 | goto done; |
5b435de0 | 95 | } |
0af29bf7 | 96 | memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac)); |
5b435de0 | 97 | |
48622903 AS |
98 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_REVINFO, |
99 | &revinfo, sizeof(revinfo)); | |
7f52c81d | 100 | ri = &ifp->drvr->revinfo; |
48622903 AS |
101 | if (err < 0) { |
102 | brcmf_err("retrieving revision info failed, %d\n", err); | |
103 | } else { | |
48622903 AS |
104 | ri->vendorid = le32_to_cpu(revinfo.vendorid); |
105 | ri->deviceid = le32_to_cpu(revinfo.deviceid); | |
106 | ri->radiorev = le32_to_cpu(revinfo.radiorev); | |
107 | ri->chiprev = le32_to_cpu(revinfo.chiprev); | |
108 | ri->corerev = le32_to_cpu(revinfo.corerev); | |
109 | ri->boardid = le32_to_cpu(revinfo.boardid); | |
110 | ri->boardvendor = le32_to_cpu(revinfo.boardvendor); | |
111 | ri->boardrev = le32_to_cpu(revinfo.boardrev); | |
112 | ri->driverrev = le32_to_cpu(revinfo.driverrev); | |
113 | ri->ucoderev = le32_to_cpu(revinfo.ucoderev); | |
114 | ri->bus = le32_to_cpu(revinfo.bus); | |
115 | ri->chipnum = le32_to_cpu(revinfo.chipnum); | |
116 | ri->phytype = le32_to_cpu(revinfo.phytype); | |
117 | ri->phyrev = le32_to_cpu(revinfo.phyrev); | |
118 | ri->anarev = le32_to_cpu(revinfo.anarev); | |
119 | ri->chippkg = le32_to_cpu(revinfo.chippkg); | |
120 | ri->nvramrev = le32_to_cpu(revinfo.nvramrev); | |
121 | } | |
7f52c81d | 122 | ri->result = err; |
48622903 | 123 | |
5b435de0 AS |
124 | /* query for 'ver' to get version info from firmware */ |
125 | memset(buf, 0, sizeof(buf)); | |
0af29bf7 HM |
126 | strcpy(buf, "ver"); |
127 | err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf)); | |
128 | if (err < 0) { | |
5e8149f5 | 129 | brcmf_err("Retreiving version information failed, %d\n", |
0af29bf7 HM |
130 | err); |
131 | goto done; | |
132 | } | |
133 | ptr = (char *)buf; | |
5b435de0 | 134 | strsep(&ptr, "\n"); |
55685b8f | 135 | |
5b435de0 | 136 | /* Print fw version info */ |
5e8149f5 | 137 | brcmf_err("Firmware version = %s\n", buf); |
5b435de0 | 138 | |
55685b8f AS |
139 | /* locate firmware version number for ethtool */ |
140 | ptr = strrchr(buf, ' ') + 1; | |
141 | strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver)); | |
142 | ||
5e787f75 DK |
143 | /* set mpc */ |
144 | err = brcmf_fil_iovar_int_set(ifp, "mpc", 1); | |
145 | if (err) { | |
146 | brcmf_err("failed setting mpc\n"); | |
147 | goto done; | |
148 | } | |
149 | ||
e09cc63d DK |
150 | /* Setup join_pref to select target by RSSI(with boost on 5GHz) */ |
151 | join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA; | |
152 | join_pref_params[0].len = 2; | |
153 | join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST; | |
154 | join_pref_params[0].band = WLC_BAND_5G; | |
155 | join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI; | |
156 | join_pref_params[1].len = 2; | |
157 | join_pref_params[1].rssi_gain = 0; | |
158 | join_pref_params[1].band = 0; | |
159 | err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params, | |
160 | sizeof(join_pref_params)); | |
161 | if (err) | |
162 | brcmf_err("Set join_pref error (%d)\n", err); | |
163 | ||
0af29bf7 HM |
164 | /* Setup event_msgs, enable E_IF */ |
165 | err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask, | |
166 | BRCMF_EVENTING_MASK_LEN); | |
167 | if (err) { | |
5e8149f5 | 168 | brcmf_err("Get event_msgs error (%d)\n", err); |
0af29bf7 HM |
169 | goto done; |
170 | } | |
171 | setbit(eventmask, BRCMF_E_IF); | |
172 | err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask, | |
173 | BRCMF_EVENTING_MASK_LEN); | |
174 | if (err) { | |
5e8149f5 | 175 | brcmf_err("Set event_msgs error (%d)\n", err); |
0af29bf7 HM |
176 | goto done; |
177 | } | |
178 | ||
179 | /* Setup default scan channel time */ | |
180 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME, | |
181 | BRCMF_DEFAULT_SCAN_CHANNEL_TIME); | |
182 | if (err) { | |
5e8149f5 | 183 | brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n", |
0af29bf7 HM |
184 | err); |
185 | goto done; | |
186 | } | |
187 | ||
188 | /* Setup default scan unassoc time */ | |
189 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME, | |
190 | BRCMF_DEFAULT_SCAN_UNASSOC_TIME); | |
191 | if (err) { | |
5e8149f5 | 192 | brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n", |
0af29bf7 HM |
193 | err); |
194 | goto done; | |
195 | } | |
196 | ||
7bf65aa9 HM |
197 | /* Enable tx beamforming, errors can be ignored (not supported) */ |
198 | (void)brcmf_fil_iovar_int_set(ifp, "txbf", 1); | |
199 | ||
cf458287 AS |
200 | /* do bus specific preinit here */ |
201 | err = brcmf_bus_preinit(ifp->drvr->bus_if); | |
0af29bf7 HM |
202 | done: |
203 | return err; | |
5b435de0 | 204 | } |
e5483576 | 205 | |
e5483576 AS |
206 | #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG) |
207 | void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...) | |
208 | { | |
209 | struct va_format vaf = { | |
210 | .fmt = fmt, | |
211 | }; | |
212 | va_list args; | |
213 | ||
214 | va_start(args, fmt); | |
215 | vaf.va = &args; | |
216 | if (brcmf_msg_level & level) | |
217 | pr_debug("%s %pV", func, &vaf); | |
218 | trace_brcmf_dbg(level, func, &vaf); | |
219 | va_end(args); | |
220 | } | |
221 | #endif | |
7d34b056 HM |
222 | |
223 | void brcmf_mp_attach(void) | |
224 | { | |
225 | strlcpy(brcmf_mp_global.firmware_path, brcmf_firmware_path, | |
226 | BRCMF_FW_ALTPATH_LEN); | |
227 | } | |
228 | ||
229 | int brcmf_mp_device_attach(struct brcmf_pub *drvr) | |
230 | { | |
231 | drvr->settings = kzalloc(sizeof(*drvr->settings), GFP_ATOMIC); | |
232 | if (!drvr->settings) { | |
233 | brcmf_err("Failed to alloca storage space for settings\n"); | |
234 | return -ENOMEM; | |
235 | } | |
236 | ||
237 | drvr->settings->sdiod_txglomsz = brcmf_sdiod_txglomsz; | |
238 | drvr->settings->p2p_enable = !!brcmf_p2p_enable; | |
239 | drvr->settings->feature_disable = brcmf_feature_disable; | |
240 | drvr->settings->fcmode = brcmf_fcmode; | |
241 | drvr->settings->roamoff = !!brcmf_roamoff; | |
8ba83d4d AS |
242 | #ifdef DEBUG |
243 | drvr->settings->ignore_probe_fail = !!brcmf_ignore_probe_fail; | |
244 | #endif | |
7d34b056 HM |
245 | return 0; |
246 | } | |
247 | ||
248 | void brcmf_mp_device_detach(struct brcmf_pub *drvr) | |
249 | { | |
250 | kfree(drvr->settings); | |
251 | } | |
252 |