blob: 338d723376043e78d813b1423f3c93e14cec820b [file] [log] [blame]
Christian Lampartera1c55582009-04-14 22:11:20 +02001/*
2 * Copyright (c) 2009 Atheros Communications Inc.
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
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Joe Perches516304b2012-03-18 17:30:52 -070017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Christian Lampartera1c55582009-04-14 22:11:20 +020019#include <linux/kernel.h>
20#include <linux/module.h>
21
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -070022#include "ath.h"
Sujith Manoharane6664df2014-09-27 13:27:45 +053023#include "trace.h"
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -070024
Christian Lampartera1c55582009-04-14 22:11:20 +020025MODULE_AUTHOR("Atheros Communications");
26MODULE_DESCRIPTION("Shared library for Atheros wireless LAN cards.");
27MODULE_LICENSE("Dual BSD/GPL");
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -070028
29struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
30 u32 len,
31 gfp_t gfp_mask)
32{
33 struct sk_buff *skb;
34 u32 off;
35
36 /*
37 * Cache-line-align. This is important (for the
38 * 5210 at least) as not doing so causes bogus data
39 * in rx'd frames.
40 */
41
42 /* Note: the kernel can allocate a value greater than
43 * what we ask it to give us. We really only need 4 KB as that
44 * is this hardware supports and in fact we need at least 3849
45 * as that is the MAX AMSDU size this hardware supports.
46 * Unfortunately this means we may get 8 KB here from the
47 * kernel... and that is actually what is observed on some
48 * systems :( */
49 skb = __dev_alloc_skb(len + common->cachelsz - 1, gfp_mask);
50 if (skb != NULL) {
51 off = ((unsigned long) skb->data) % common->cachelsz;
52 if (off != 0)
53 skb_reserve(skb, common->cachelsz - off);
54 } else {
Joe Perches516304b2012-03-18 17:30:52 -070055 pr_err("skbuff alloc of size %u failed\n", len);
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -070056 return NULL;
57 }
58
59 return skb;
60}
61EXPORT_SYMBOL(ath_rxbuf_alloc);
Joe Perches21a99f92010-12-02 19:12:35 -080062
Oleksij Rempelf1d267c2014-01-15 17:37:42 +010063bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr)
64{
65 return ieee80211_is_beacon(hdr->frame_control) &&
66 !is_zero_ether_addr(common->curbssid) &&
67 ether_addr_equal_64bits(hdr->addr3, common->curbssid);
68}
69EXPORT_SYMBOL(ath_is_mybeacon);
70
Ben Greear98b36a02012-03-08 10:20:55 -080071void ath_printk(const char *level, const struct ath_common* common,
72 const char *fmt, ...)
Joe Perches21a99f92010-12-02 19:12:35 -080073{
74 struct va_format vaf;
75 va_list args;
Joe Perches21a99f92010-12-02 19:12:35 -080076
77 va_start(args, fmt);
78
79 vaf.fmt = fmt;
80 vaf.va = &args;
81
Sujith Manoharand2a993e2014-10-07 10:14:36 +053082 if (common && common->hw && common->hw->wiphy) {
Ben Greear98b36a02012-03-08 10:20:55 -080083 printk("%sath: %s: %pV",
84 level, wiphy_name(common->hw->wiphy), &vaf);
Sujith Manoharand2a993e2014-10-07 10:14:36 +053085 trace_ath_log(common->hw->wiphy, &vaf);
86 } else {
Ben Greear98b36a02012-03-08 10:20:55 -080087 printk("%sath: %pV", level, &vaf);
Sujith Manoharand2a993e2014-10-07 10:14:36 +053088 }
Sujith Manoharane6664df2014-09-27 13:27:45 +053089
Joe Perches21a99f92010-12-02 19:12:35 -080090 va_end(args);
Joe Perches21a99f92010-12-02 19:12:35 -080091}
92EXPORT_SYMBOL(ath_printk);