2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/netdevice.h>
20 #include <brcmu_wifi.h>
21 #include <brcmu_utils.h>
26 #include "fwil_types.h"
27 #include "tracepoint.h"
29 #define PKTFILTER_BUF_SIZE 128
30 #define BRCMF_DEFAULT_BCN_TIMEOUT 3
31 #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
32 #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
33 #define BRCMF_DEFAULT_PACKET_FILTER "100 0 0 0 0x01 0x00"
35 /* boost value for RSSI_DELTA in preferred join selection */
36 #define BRCMF_JOIN_PREF_RSSI_BOOST 8
39 bool brcmf_c_prec_enq(struct device *dev, struct pktq *q,
40 struct sk_buff *pkt, int prec)
43 int eprec = -1; /* precedence to evict from */
45 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
46 struct brcmf_pub *drvr = bus_if->drvr;
48 /* Fast case, precedence queue is not full and we are also not
49 * exceeding total queue length
51 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
52 brcmu_pktq_penq(q, prec, pkt);
56 /* Determine precedence from which to evict packet, if any */
57 if (pktq_pfull(q, prec))
59 else if (pktq_full(q)) {
60 p = brcmu_pktq_peek_tail(q, &eprec);
67 /* Detect queueing to unconfigured precedence */
68 discard_oldest = ac_bitmap_tst(drvr->wme_dp, eprec);
69 if (eprec == prec && !discard_oldest)
70 return false; /* refuse newer (incoming) packet */
71 /* Evict packet according to discard policy */
72 p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) :
73 brcmu_pktq_pdeq_tail(q, eprec);
75 brcmf_err("brcmu_pktq_penq() failed, oldest %d\n",
78 brcmu_pkt_buf_free_skb(p);
82 p = brcmu_pktq_penq(q, prec, pkt);
84 brcmf_err("brcmu_pktq_penq() failed\n");
89 /* Convert user's input in hex pattern to byte-size mask */
90 static int brcmf_c_pattern_atoh(char *src, char *dst)
93 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
94 brcmf_err("Mask invalid format. Needs to start with 0x\n");
97 src = src + 2; /* Skip past 0x */
98 if (strlen(src) % 2 != 0) {
99 brcmf_err("Mask invalid format. Length must be even.\n");
102 for (i = 0; *src != '\0'; i++) {
105 strncpy(num, src, 2);
107 if (kstrtoul(num, 16, &res))
116 brcmf_c_pktfilter_offload_enable(struct brcmf_if *ifp, char *arg, int enable,
121 char *arg_save = NULL, *arg_org = NULL;
123 struct brcmf_pkt_filter_enable_le enable_parm;
125 arg_save = kstrdup(arg, GFP_ATOMIC);
131 argv = strsep(&arg_save, " ");
134 brcmf_err("No args provided\n");
138 /* Parse packet filter id. */
140 if (!kstrtoul(argv, 0, &res))
141 enable_parm.id = cpu_to_le32((u32)res);
143 /* Enable/disable the specified filter. */
144 enable_parm.enable = cpu_to_le32(enable);
146 err = brcmf_fil_iovar_data_set(ifp, "pkt_filter_enable", &enable_parm,
147 sizeof(enable_parm));
149 brcmf_err("Set pkt_filter_enable error (%d)\n", err);
151 /* Control the master mode */
152 err = brcmf_fil_iovar_int_set(ifp, "pkt_filter_mode", master_mode);
154 brcmf_err("Set pkt_filter_mode error (%d)\n", err);
160 static void brcmf_c_pktfilter_offload_set(struct brcmf_if *ifp, char *arg)
162 struct brcmf_pkt_filter_le *pkt_filter;
168 char *argv[8], *buf = NULL;
170 char *arg_save = NULL, *arg_org = NULL;
172 arg_save = kstrdup(arg, GFP_ATOMIC);
178 buf = kmalloc(PKTFILTER_BUF_SIZE, GFP_ATOMIC);
182 argv[i] = strsep(&arg_save, " ");
186 brcmf_err("Too many parameters\n");
189 argv[i] = strsep(&arg_save, " ");
193 brcmf_err("Not enough args provided %d\n", i);
197 pkt_filter = (struct brcmf_pkt_filter_le *)buf;
199 /* Parse packet filter id. */
201 if (!kstrtoul(argv[0], 0, &res))
202 pkt_filter->id = cpu_to_le32((u32)res);
204 /* Parse filter polarity. */
205 pkt_filter->negate_match = 0;
206 if (!kstrtoul(argv[1], 0, &res))
207 pkt_filter->negate_match = cpu_to_le32((u32)res);
209 /* Parse filter type. */
210 pkt_filter->type = 0;
211 if (!kstrtoul(argv[2], 0, &res))
212 pkt_filter->type = cpu_to_le32((u32)res);
214 /* Parse pattern filter offset. */
215 pkt_filter->u.pattern.offset = 0;
216 if (!kstrtoul(argv[3], 0, &res))
217 pkt_filter->u.pattern.offset = cpu_to_le32((u32)res);
219 /* Parse pattern filter mask. */
220 mask_size = brcmf_c_pattern_atoh(argv[4],
221 (char *)pkt_filter->u.pattern.mask_and_pattern);
223 /* Parse pattern filter pattern. */
224 pattern_size = brcmf_c_pattern_atoh(argv[5],
225 (char *)&pkt_filter->u.pattern.mask_and_pattern[mask_size]);
227 if (mask_size != pattern_size) {
228 brcmf_err("Mask and pattern not the same size\n");
232 pkt_filter->u.pattern.size_bytes = cpu_to_le32(mask_size);
233 buf_len = offsetof(struct brcmf_pkt_filter_le,
234 u.pattern.mask_and_pattern);
235 buf_len += mask_size + pattern_size;
237 err = brcmf_fil_iovar_data_set(ifp, "pkt_filter_add", pkt_filter,
240 brcmf_err("Set pkt_filter_add error (%d)\n", err);
248 int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
250 s8 eventmask[BRCMF_EVENTING_MASK_LEN];
251 u8 buf[BRCMF_DCMD_SMLEN];
252 struct brcmf_join_pref_params join_pref_params[2];
256 /* retreive mac address */
257 err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
258 sizeof(ifp->mac_addr));
260 brcmf_err("Retreiving cur_etheraddr failed, %d\n",
264 memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
266 /* query for 'ver' to get version info from firmware */
267 memset(buf, 0, sizeof(buf));
269 err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
271 brcmf_err("Retreiving version information failed, %d\n",
278 /* Print fw version info */
279 brcmf_err("Firmware version = %s\n", buf);
281 /* locate firmware version number for ethtool */
282 ptr = strrchr(buf, ' ') + 1;
283 strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver));
286 * Setup timeout if Beacons are lost and roam is off to report
289 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout",
290 BRCMF_DEFAULT_BCN_TIMEOUT);
292 brcmf_err("bcn_timeout error (%d)\n", err);
296 /* Enable/Disable build-in roaming to allowed ext supplicant to take
299 err = brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
301 brcmf_err("roam_off error (%d)\n", err);
305 /* Setup join_pref to select target by RSSI(with boost on 5GHz) */
306 join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
307 join_pref_params[0].len = 2;
308 join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
309 join_pref_params[0].band = WLC_BAND_5G;
310 join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
311 join_pref_params[1].len = 2;
312 join_pref_params[1].rssi_gain = 0;
313 join_pref_params[1].band = 0;
314 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
315 sizeof(join_pref_params));
317 brcmf_err("Set join_pref error (%d)\n", err);
319 /* Setup event_msgs, enable E_IF */
320 err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
321 BRCMF_EVENTING_MASK_LEN);
323 brcmf_err("Get event_msgs error (%d)\n", err);
326 setbit(eventmask, BRCMF_E_IF);
327 err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask,
328 BRCMF_EVENTING_MASK_LEN);
330 brcmf_err("Set event_msgs error (%d)\n", err);
334 /* Setup default scan channel time */
335 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
336 BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
338 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
343 /* Setup default scan unassoc time */
344 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
345 BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
347 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
352 /* Setup packet filter */
353 brcmf_c_pktfilter_offload_set(ifp, BRCMF_DEFAULT_PACKET_FILTER);
354 brcmf_c_pktfilter_offload_enable(ifp, BRCMF_DEFAULT_PACKET_FILTER,
357 /* do bus specific preinit here */
358 err = brcmf_bus_preinit(ifp->drvr->bus_if);
363 #ifdef CONFIG_BRCM_TRACING
364 void __brcmf_err(const char *func, const char *fmt, ...)
366 struct va_format vaf = {
373 pr_err("%s: %pV", func, &vaf);
374 trace_brcmf_err(func, &vaf);
378 #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
379 void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
381 struct va_format vaf = {
388 if (brcmf_msg_level & level)
389 pr_debug("%s %pV", func, &vaf);
390 trace_brcmf_dbg(level, func, &vaf);