Christian Lamparter | a1c5558 | 2009-04-14 22:11:20 +0200 | [diff] [blame] | 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 | |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 18 | |
Christian Lamparter | a1c5558 | 2009-04-14 22:11:20 +0200 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | |
Luis R. Rodriguez | d15dd3e | 2009-08-12 09:56:59 -0700 | [diff] [blame] | 22 | #include "ath.h" |
| 23 | |
Christian Lamparter | a1c5558 | 2009-04-14 22:11:20 +0200 | [diff] [blame] | 24 | MODULE_AUTHOR("Atheros Communications"); |
| 25 | MODULE_DESCRIPTION("Shared library for Atheros wireless LAN cards."); |
| 26 | MODULE_LICENSE("Dual BSD/GPL"); |
Luis R. Rodriguez | d15dd3e | 2009-08-12 09:56:59 -0700 | [diff] [blame] | 27 | |
| 28 | struct sk_buff *ath_rxbuf_alloc(struct ath_common *common, |
| 29 | u32 len, |
| 30 | gfp_t gfp_mask) |
| 31 | { |
| 32 | struct sk_buff *skb; |
| 33 | u32 off; |
| 34 | |
| 35 | /* |
| 36 | * Cache-line-align. This is important (for the |
| 37 | * 5210 at least) as not doing so causes bogus data |
| 38 | * in rx'd frames. |
| 39 | */ |
| 40 | |
| 41 | /* Note: the kernel can allocate a value greater than |
| 42 | * what we ask it to give us. We really only need 4 KB as that |
| 43 | * is this hardware supports and in fact we need at least 3849 |
| 44 | * as that is the MAX AMSDU size this hardware supports. |
| 45 | * Unfortunately this means we may get 8 KB here from the |
| 46 | * kernel... and that is actually what is observed on some |
| 47 | * systems :( */ |
| 48 | skb = __dev_alloc_skb(len + common->cachelsz - 1, gfp_mask); |
| 49 | if (skb != NULL) { |
| 50 | off = ((unsigned long) skb->data) % common->cachelsz; |
| 51 | if (off != 0) |
| 52 | skb_reserve(skb, common->cachelsz - off); |
| 53 | } else { |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 54 | pr_err("skbuff alloc of size %u failed\n", len); |
Luis R. Rodriguez | d15dd3e | 2009-08-12 09:56:59 -0700 | [diff] [blame] | 55 | return NULL; |
| 56 | } |
| 57 | |
| 58 | return skb; |
| 59 | } |
| 60 | EXPORT_SYMBOL(ath_rxbuf_alloc); |
Joe Perches | 21a99f9 | 2010-12-02 19:12:35 -0800 | [diff] [blame] | 61 | |
Oleksij Rempel | f1d267c | 2014-01-15 17:37:42 +0100 | [diff] [blame] | 62 | bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr) |
| 63 | { |
| 64 | return ieee80211_is_beacon(hdr->frame_control) && |
| 65 | !is_zero_ether_addr(common->curbssid) && |
| 66 | ether_addr_equal_64bits(hdr->addr3, common->curbssid); |
| 67 | } |
| 68 | EXPORT_SYMBOL(ath_is_mybeacon); |
| 69 | |
Ben Greear | 98b36a0 | 2012-03-08 10:20:55 -0800 | [diff] [blame] | 70 | void ath_printk(const char *level, const struct ath_common* common, |
| 71 | const char *fmt, ...) |
Joe Perches | 21a99f9 | 2010-12-02 19:12:35 -0800 | [diff] [blame] | 72 | { |
| 73 | struct va_format vaf; |
| 74 | va_list args; |
Joe Perches | 21a99f9 | 2010-12-02 19:12:35 -0800 | [diff] [blame] | 75 | |
| 76 | va_start(args, fmt); |
| 77 | |
| 78 | vaf.fmt = fmt; |
| 79 | vaf.va = &args; |
| 80 | |
Ben Greear | 98b36a0 | 2012-03-08 10:20:55 -0800 | [diff] [blame] | 81 | if (common && common->hw && common->hw->wiphy) |
| 82 | printk("%sath: %s: %pV", |
| 83 | level, wiphy_name(common->hw->wiphy), &vaf); |
| 84 | else |
| 85 | printk("%sath: %pV", level, &vaf); |
Joe Perches | 21a99f9 | 2010-12-02 19:12:35 -0800 | [diff] [blame] | 86 | |
| 87 | va_end(args); |
Joe Perches | 21a99f9 | 2010-12-02 19:12:35 -0800 | [diff] [blame] | 88 | } |
| 89 | EXPORT_SYMBOL(ath_printk); |