xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/ath/main.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2009 Atheros Communications Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, and/or distribute this software for any
5*4882a593Smuzhiyun  * purpose with or without fee is hereby granted, provided that the above
6*4882a593Smuzhiyun  * copyright notice and this permission notice appear in all copies.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*4882a593Smuzhiyun  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*4882a593Smuzhiyun  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*4882a593Smuzhiyun  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*4882a593Smuzhiyun  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*4882a593Smuzhiyun  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*4882a593Smuzhiyun  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <linux/kernel.h>
20*4882a593Smuzhiyun #include <linux/module.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include "ath.h"
23*4882a593Smuzhiyun #include "trace.h"
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun MODULE_AUTHOR("Atheros Communications");
26*4882a593Smuzhiyun MODULE_DESCRIPTION("Shared library for Atheros wireless LAN cards.");
27*4882a593Smuzhiyun MODULE_LICENSE("Dual BSD/GPL");
28*4882a593Smuzhiyun 
ath_rxbuf_alloc(struct ath_common * common,u32 len,gfp_t gfp_mask)29*4882a593Smuzhiyun struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
30*4882a593Smuzhiyun 				u32 len,
31*4882a593Smuzhiyun 				gfp_t gfp_mask)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	struct sk_buff *skb;
34*4882a593Smuzhiyun 	u32 off;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	/*
37*4882a593Smuzhiyun 	 * Cache-line-align.  This is important (for the
38*4882a593Smuzhiyun 	 * 5210 at least) as not doing so causes bogus data
39*4882a593Smuzhiyun 	 * in rx'd frames.
40*4882a593Smuzhiyun 	 */
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	/* Note: the kernel can allocate a value greater than
43*4882a593Smuzhiyun 	 * what we ask it to give us. We really only need 4 KB as that
44*4882a593Smuzhiyun 	 * is this hardware supports and in fact we need at least 3849
45*4882a593Smuzhiyun 	 * as that is the MAX AMSDU size this hardware supports.
46*4882a593Smuzhiyun 	 * Unfortunately this means we may get 8 KB here from the
47*4882a593Smuzhiyun 	 * kernel... and that is actually what is observed on some
48*4882a593Smuzhiyun 	 * systems :( */
49*4882a593Smuzhiyun 	skb = __dev_alloc_skb(len + common->cachelsz - 1, gfp_mask);
50*4882a593Smuzhiyun 	if (skb != NULL) {
51*4882a593Smuzhiyun 		off = ((unsigned long) skb->data) % common->cachelsz;
52*4882a593Smuzhiyun 		if (off != 0)
53*4882a593Smuzhiyun 			skb_reserve(skb, common->cachelsz - off);
54*4882a593Smuzhiyun 	} else {
55*4882a593Smuzhiyun 		pr_err("skbuff alloc of size %u failed\n", len);
56*4882a593Smuzhiyun 		return NULL;
57*4882a593Smuzhiyun 	}
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	return skb;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun EXPORT_SYMBOL(ath_rxbuf_alloc);
62*4882a593Smuzhiyun 
ath_is_mybeacon(struct ath_common * common,struct ieee80211_hdr * hdr)63*4882a593Smuzhiyun bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun 	return ieee80211_is_beacon(hdr->frame_control) &&
66*4882a593Smuzhiyun 		!is_zero_ether_addr(common->curbssid) &&
67*4882a593Smuzhiyun 		ether_addr_equal_64bits(hdr->addr3, common->curbssid);
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun EXPORT_SYMBOL(ath_is_mybeacon);
70*4882a593Smuzhiyun 
ath_printk(const char * level,const struct ath_common * common,const char * fmt,...)71*4882a593Smuzhiyun void ath_printk(const char *level, const struct ath_common* common,
72*4882a593Smuzhiyun 		const char *fmt, ...)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	struct va_format vaf;
75*4882a593Smuzhiyun 	va_list args;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	va_start(args, fmt);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	vaf.fmt = fmt;
80*4882a593Smuzhiyun 	vaf.va = &args;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	if (common && common->hw && common->hw->wiphy) {
83*4882a593Smuzhiyun 		printk("%sath: %s: %pV",
84*4882a593Smuzhiyun 		       level, wiphy_name(common->hw->wiphy), &vaf);
85*4882a593Smuzhiyun 		trace_ath_log(common->hw->wiphy, &vaf);
86*4882a593Smuzhiyun 	} else {
87*4882a593Smuzhiyun 		printk("%sath: %pV", level, &vaf);
88*4882a593Smuzhiyun 	}
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	va_end(args);
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun EXPORT_SYMBOL(ath_printk);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun const char *ath_bus_type_strings[] = {
95*4882a593Smuzhiyun 	[ATH_PCI] = "pci",
96*4882a593Smuzhiyun 	[ATH_AHB] = "ahb",
97*4882a593Smuzhiyun 	[ATH_USB] = "usb",
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun EXPORT_SYMBOL(ath_bus_type_strings);
100