Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/dev/athk/main.c
103756 views
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
#if defined(__FreeBSD__)
30
MODULE_VERSION(athk_common, 1);
31
MODULE_DEPEND(athk_common, linuxkpi, 1, 1, 1);
32
MODULE_DEPEND(athk_common, linuxkpi_wlan, 1, 1, 1);
33
#endif
34
35
struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
36
u32 len,
37
gfp_t gfp_mask)
38
{
39
struct sk_buff *skb;
40
u32 off;
41
42
/*
43
* Cache-line-align. This is important (for the
44
* 5210 at least) as not doing so causes bogus data
45
* in rx'd frames.
46
*/
47
48
/* Note: the kernel can allocate a value greater than
49
* what we ask it to give us. We really only need 4 KB as that
50
* is this hardware supports and in fact we need at least 3849
51
* as that is the MAX AMSDU size this hardware supports.
52
* Unfortunately this means we may get 8 KB here from the
53
* kernel... and that is actually what is observed on some
54
* systems :( */
55
skb = __dev_alloc_skb(len + common->cachelsz - 1, gfp_mask);
56
if (skb != NULL) {
57
off = ((unsigned long) skb->data) % common->cachelsz;
58
if (off != 0)
59
skb_reserve(skb, common->cachelsz - off);
60
} else {
61
pr_err("skbuff alloc of size %u failed\n", len);
62
return NULL;
63
}
64
65
return skb;
66
}
67
EXPORT_SYMBOL(ath_rxbuf_alloc);
68
69
bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr)
70
{
71
return ieee80211_is_beacon(hdr->frame_control) &&
72
!is_zero_ether_addr(common->curbssid) &&
73
ether_addr_equal_64bits(hdr->addr3, common->curbssid);
74
}
75
EXPORT_SYMBOL(ath_is_mybeacon);
76
77
void ath_printk(const char *level, const struct ath_common* common,
78
const char *fmt, ...)
79
{
80
struct va_format vaf;
81
va_list args;
82
83
va_start(args, fmt);
84
85
vaf.fmt = fmt;
86
vaf.va = &args;
87
88
if (common && common->hw && common->hw->wiphy) {
89
printk("%sath: %s: %pV",
90
level, wiphy_name(common->hw->wiphy), &vaf);
91
trace_ath_log(common->hw->wiphy, &vaf);
92
} else {
93
printk("%sath: %pV", level, &vaf);
94
}
95
96
va_end(args);
97
}
98
EXPORT_SYMBOL(ath_printk);
99
100
const char *ath_bus_type_strings[] = {
101
[ATH_PCI] = "pci",
102
[ATH_AHB] = "ahb",
103
[ATH_USB] = "usb",
104
};
105
EXPORT_SYMBOL(ath_bus_type_strings);
106
107