xref: /linux/drivers/net/wireless/ath/main.c (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
1 /*
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 
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 
19 #include <linux/export.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 
23 #include "ath.h"
24 #include "trace.h"
25 
26 MODULE_AUTHOR("Atheros Communications");
27 MODULE_DESCRIPTION("Shared library for Atheros wireless LAN cards.");
28 MODULE_LICENSE("Dual BSD/GPL");
29 
ath_rxbuf_alloc(struct ath_common * common,u32 len,gfp_t gfp_mask)30 struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
31 				u32 len,
32 				gfp_t gfp_mask)
33 {
34 	struct sk_buff *skb;
35 	u32 off;
36 
37 	/*
38 	 * Cache-line-align.  This is important (for the
39 	 * 5210 at least) as not doing so causes bogus data
40 	 * in rx'd frames.
41 	 */
42 
43 	/* Note: the kernel can allocate a value greater than
44 	 * what we ask it to give us. We really only need 4 KB as that
45 	 * is this hardware supports and in fact we need at least 3849
46 	 * as that is the MAX AMSDU size this hardware supports.
47 	 * Unfortunately this means we may get 8 KB here from the
48 	 * kernel... and that is actually what is observed on some
49 	 * systems :( */
50 	skb = __dev_alloc_skb(len + common->cachelsz - 1, gfp_mask);
51 	if (skb != NULL) {
52 		off = ((unsigned long) skb->data) % common->cachelsz;
53 		if (off != 0)
54 			skb_reserve(skb, common->cachelsz - off);
55 	} else {
56 		pr_err("skbuff alloc of size %u failed\n", len);
57 		return NULL;
58 	}
59 
60 	return skb;
61 }
62 EXPORT_SYMBOL(ath_rxbuf_alloc);
63 
ath_is_mybeacon(struct ath_common * common,struct ieee80211_hdr * hdr)64 bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr)
65 {
66 	return ieee80211_is_beacon(hdr->frame_control) &&
67 		!is_zero_ether_addr(common->curbssid) &&
68 		ether_addr_equal_64bits(hdr->addr3, common->curbssid);
69 }
70 EXPORT_SYMBOL(ath_is_mybeacon);
71 
ath_printk(const char * level,const struct ath_common * common,const char * fmt,...)72 void ath_printk(const char *level, const struct ath_common* common,
73 		const char *fmt, ...)
74 {
75 	struct va_format vaf;
76 	va_list args;
77 
78 	va_start(args, fmt);
79 
80 	vaf.fmt = fmt;
81 	vaf.va = &args;
82 
83 	if (common && common->hw && common->hw->wiphy) {
84 		printk("%sath: %s: %pV",
85 		       level, wiphy_name(common->hw->wiphy), &vaf);
86 		trace_ath_log(common->hw->wiphy, &vaf);
87 	} else {
88 		printk("%sath: %pV", level, &vaf);
89 	}
90 
91 	va_end(args);
92 }
93 EXPORT_SYMBOL(ath_printk);
94 
95 const char *ath_bus_type_strings[] = {
96 	[ATH_PCI] = "pci",
97 	[ATH_AHB] = "ahb",
98 	[ATH_USB] = "usb",
99 };
100 EXPORT_SYMBOL(ath_bus_type_strings);
101