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