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"
36 bool brcmf_c_prec_enq(struct device
*dev
, struct pktq
*q
,
37 struct sk_buff
*pkt
, int prec
)
40 int eprec
= -1; /* precedence to evict from */
42 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
43 struct brcmf_pub
*drvr
= bus_if
->drvr
;
45 /* Fast case, precedence queue is not full and we are also not
46 * exceeding total queue length
48 if (!pktq_pfull(q
, prec
) && !pktq_full(q
)) {
49 brcmu_pktq_penq(q
, prec
, pkt
);
53 /* Determine precedence from which to evict packet, if any */
54 if (pktq_pfull(q
, prec
))
56 else if (pktq_full(q
)) {
57 p
= brcmu_pktq_peek_tail(q
, &eprec
);
64 /* Detect queueing to unconfigured precedence */
65 discard_oldest
= ac_bitmap_tst(drvr
->wme_dp
, eprec
);
66 if (eprec
== prec
&& !discard_oldest
)
67 return false; /* refuse newer (incoming) packet */
68 /* Evict packet according to discard policy */
69 p
= discard_oldest
? brcmu_pktq_pdeq(q
, eprec
) :
70 brcmu_pktq_pdeq_tail(q
, eprec
);
72 brcmf_err("brcmu_pktq_penq() failed, oldest %d\n",
75 brcmu_pkt_buf_free_skb(p
);
79 p
= brcmu_pktq_penq(q
, prec
, pkt
);
81 brcmf_err("brcmu_pktq_penq() failed\n");
86 /* Convert user's input in hex pattern to byte-size mask */
87 static int brcmf_c_pattern_atoh(char *src
, char *dst
)
90 if (strncmp(src
, "0x", 2) != 0 && strncmp(src
, "0X", 2) != 0) {
91 brcmf_err("Mask invalid format. Needs to start with 0x\n");
94 src
= src
+ 2; /* Skip past 0x */
95 if (strlen(src
) % 2 != 0) {
96 brcmf_err("Mask invalid format. Length must be even.\n");
99 for (i
= 0; *src
!= '\0'; i
++) {
102 strncpy(num
, src
, 2);
104 if (kstrtoul(num
, 16, &res
))
113 brcmf_c_pktfilter_offload_enable(struct brcmf_if
*ifp
, char *arg
, int enable
,
118 char *arg_save
= NULL
, *arg_org
= NULL
;
120 struct brcmf_pkt_filter_enable_le enable_parm
;
122 arg_save
= kstrdup(arg
, GFP_ATOMIC
);
128 argv
= strsep(&arg_save
, " ");
131 brcmf_err("No args provided\n");
135 /* Parse packet filter id. */
137 if (!kstrtoul(argv
, 0, &res
))
138 enable_parm
.id
= cpu_to_le32((u32
)res
);
140 /* Enable/disable the specified filter. */
141 enable_parm
.enable
= cpu_to_le32(enable
);
143 err
= brcmf_fil_iovar_data_set(ifp
, "pkt_filter_enable", &enable_parm
,
144 sizeof(enable_parm
));
146 brcmf_err("Set pkt_filter_enable error (%d)\n", err
);
148 /* Control the master mode */
149 err
= brcmf_fil_iovar_int_set(ifp
, "pkt_filter_mode", master_mode
);
151 brcmf_err("Set pkt_filter_mode error (%d)\n", err
);
157 static void brcmf_c_pktfilter_offload_set(struct brcmf_if
*ifp
, char *arg
)
159 struct brcmf_pkt_filter_le
*pkt_filter
;
165 char *argv
[8], *buf
= NULL
;
167 char *arg_save
= NULL
, *arg_org
= NULL
;
169 arg_save
= kstrdup(arg
, GFP_ATOMIC
);
175 buf
= kmalloc(PKTFILTER_BUF_SIZE
, GFP_ATOMIC
);
179 argv
[i
] = strsep(&arg_save
, " ");
183 brcmf_err("Too many parameters\n");
186 argv
[i
] = strsep(&arg_save
, " ");
190 brcmf_err("Not enough args provided %d\n", i
);
194 pkt_filter
= (struct brcmf_pkt_filter_le
*)buf
;
196 /* Parse packet filter id. */
198 if (!kstrtoul(argv
[0], 0, &res
))
199 pkt_filter
->id
= cpu_to_le32((u32
)res
);
201 /* Parse filter polarity. */
202 pkt_filter
->negate_match
= 0;
203 if (!kstrtoul(argv
[1], 0, &res
))
204 pkt_filter
->negate_match
= cpu_to_le32((u32
)res
);
206 /* Parse filter type. */
207 pkt_filter
->type
= 0;
208 if (!kstrtoul(argv
[2], 0, &res
))
209 pkt_filter
->type
= cpu_to_le32((u32
)res
);
211 /* Parse pattern filter offset. */
212 pkt_filter
->u
.pattern
.offset
= 0;
213 if (!kstrtoul(argv
[3], 0, &res
))
214 pkt_filter
->u
.pattern
.offset
= cpu_to_le32((u32
)res
);
216 /* Parse pattern filter mask. */
217 mask_size
= brcmf_c_pattern_atoh(argv
[4],
218 (char *)pkt_filter
->u
.pattern
.mask_and_pattern
);
220 /* Parse pattern filter pattern. */
221 pattern_size
= brcmf_c_pattern_atoh(argv
[5],
222 (char *)&pkt_filter
->u
.pattern
.mask_and_pattern
[mask_size
]);
224 if (mask_size
!= pattern_size
) {
225 brcmf_err("Mask and pattern not the same size\n");
229 pkt_filter
->u
.pattern
.size_bytes
= cpu_to_le32(mask_size
);
230 buf_len
= offsetof(struct brcmf_pkt_filter_le
,
231 u
.pattern
.mask_and_pattern
);
232 buf_len
+= mask_size
+ pattern_size
;
234 err
= brcmf_fil_iovar_data_set(ifp
, "pkt_filter_add", pkt_filter
,
237 brcmf_err("Set pkt_filter_add error (%d)\n", err
);
245 int brcmf_c_preinit_dcmds(struct brcmf_if
*ifp
)
247 s8 eventmask
[BRCMF_EVENTING_MASK_LEN
];
248 u8 buf
[BRCMF_DCMD_SMLEN
];
252 /* retreive mac address */
253 err
= brcmf_fil_iovar_data_get(ifp
, "cur_etheraddr", ifp
->mac_addr
,
254 sizeof(ifp
->mac_addr
));
256 brcmf_err("Retreiving cur_etheraddr failed, %d\n",
260 memcpy(ifp
->drvr
->mac
, ifp
->mac_addr
, sizeof(ifp
->drvr
->mac
));
262 /* query for 'ver' to get version info from firmware */
263 memset(buf
, 0, sizeof(buf
));
265 err
= brcmf_fil_iovar_data_get(ifp
, "ver", buf
, sizeof(buf
));
267 brcmf_err("Retreiving version information failed, %d\n",
274 /* Print fw version info */
275 brcmf_err("Firmware version = %s\n", buf
);
277 /* locate firmware version number for ethtool */
278 ptr
= strrchr(buf
, ' ') + 1;
279 strlcpy(ifp
->drvr
->fwver
, ptr
, sizeof(ifp
->drvr
->fwver
));
282 * Setup timeout if Beacons are lost and roam is off to report
285 err
= brcmf_fil_iovar_int_set(ifp
, "bcn_timeout",
286 BRCMF_DEFAULT_BCN_TIMEOUT
);
288 brcmf_err("bcn_timeout error (%d)\n", err
);
292 /* Enable/Disable build-in roaming to allowed ext supplicant to take
295 err
= brcmf_fil_iovar_int_set(ifp
, "roam_off", 1);
297 brcmf_err("roam_off error (%d)\n", err
);
301 /* Setup event_msgs, enable E_IF */
302 err
= brcmf_fil_iovar_data_get(ifp
, "event_msgs", eventmask
,
303 BRCMF_EVENTING_MASK_LEN
);
305 brcmf_err("Get event_msgs error (%d)\n", err
);
308 setbit(eventmask
, BRCMF_E_IF
);
309 err
= brcmf_fil_iovar_data_set(ifp
, "event_msgs", eventmask
,
310 BRCMF_EVENTING_MASK_LEN
);
312 brcmf_err("Set event_msgs error (%d)\n", err
);
316 /* Setup default scan channel time */
317 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_CHANNEL_TIME
,
318 BRCMF_DEFAULT_SCAN_CHANNEL_TIME
);
320 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
325 /* Setup default scan unassoc time */
326 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_UNASSOC_TIME
,
327 BRCMF_DEFAULT_SCAN_UNASSOC_TIME
);
329 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
334 /* Setup packet filter */
335 brcmf_c_pktfilter_offload_set(ifp
, BRCMF_DEFAULT_PACKET_FILTER
);
336 brcmf_c_pktfilter_offload_enable(ifp
, BRCMF_DEFAULT_PACKET_FILTER
,
339 /* do bus specific preinit here */
340 err
= brcmf_bus_preinit(ifp
->drvr
->bus_if
);
345 #ifdef CONFIG_BRCM_TRACING
346 void __brcmf_err(const char *func
, const char *fmt
, ...)
348 struct va_format vaf
= {
355 pr_err("%s: %pV", func
, &vaf
);
356 trace_brcmf_err(func
, &vaf
);
360 #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
361 void __brcmf_dbg(u32 level
, const char *func
, const char *fmt
, ...)
363 struct va_format vaf
= {
370 if (brcmf_msg_level
& level
)
371 pr_debug("%s %pV", func
, &vaf
);
372 trace_brcmf_dbg(level
, func
, &vaf
);