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