18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2009 Atheros Communications Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/kernel.h> 208c2ecf20Sopenharmony_ci#include <linux/module.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include "ath.h" 238c2ecf20Sopenharmony_ci#include "trace.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ciMODULE_AUTHOR("Atheros Communications"); 268c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Shared library for Atheros wireless LAN cards."); 278c2ecf20Sopenharmony_ciMODULE_LICENSE("Dual BSD/GPL"); 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct sk_buff *ath_rxbuf_alloc(struct ath_common *common, 308c2ecf20Sopenharmony_ci u32 len, 318c2ecf20Sopenharmony_ci gfp_t gfp_mask) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci struct sk_buff *skb; 348c2ecf20Sopenharmony_ci u32 off; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci /* 378c2ecf20Sopenharmony_ci * Cache-line-align. This is important (for the 388c2ecf20Sopenharmony_ci * 5210 at least) as not doing so causes bogus data 398c2ecf20Sopenharmony_ci * in rx'd frames. 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci /* Note: the kernel can allocate a value greater than 438c2ecf20Sopenharmony_ci * what we ask it to give us. We really only need 4 KB as that 448c2ecf20Sopenharmony_ci * is this hardware supports and in fact we need at least 3849 458c2ecf20Sopenharmony_ci * as that is the MAX AMSDU size this hardware supports. 468c2ecf20Sopenharmony_ci * Unfortunately this means we may get 8 KB here from the 478c2ecf20Sopenharmony_ci * kernel... and that is actually what is observed on some 488c2ecf20Sopenharmony_ci * systems :( */ 498c2ecf20Sopenharmony_ci skb = __dev_alloc_skb(len + common->cachelsz - 1, gfp_mask); 508c2ecf20Sopenharmony_ci if (skb != NULL) { 518c2ecf20Sopenharmony_ci off = ((unsigned long) skb->data) % common->cachelsz; 528c2ecf20Sopenharmony_ci if (off != 0) 538c2ecf20Sopenharmony_ci skb_reserve(skb, common->cachelsz - off); 548c2ecf20Sopenharmony_ci } else { 558c2ecf20Sopenharmony_ci pr_err("skbuff alloc of size %u failed\n", len); 568c2ecf20Sopenharmony_ci return NULL; 578c2ecf20Sopenharmony_ci } 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci return skb; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath_rxbuf_alloc); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cibool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci return ieee80211_is_beacon(hdr->frame_control) && 668c2ecf20Sopenharmony_ci !is_zero_ether_addr(common->curbssid) && 678c2ecf20Sopenharmony_ci ether_addr_equal_64bits(hdr->addr3, common->curbssid); 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath_is_mybeacon); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_civoid ath_printk(const char *level, const struct ath_common* common, 728c2ecf20Sopenharmony_ci const char *fmt, ...) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci struct va_format vaf; 758c2ecf20Sopenharmony_ci va_list args; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci va_start(args, fmt); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci vaf.fmt = fmt; 808c2ecf20Sopenharmony_ci vaf.va = &args; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if (common && common->hw && common->hw->wiphy) { 838c2ecf20Sopenharmony_ci printk("%sath: %s: %pV", 848c2ecf20Sopenharmony_ci level, wiphy_name(common->hw->wiphy), &vaf); 858c2ecf20Sopenharmony_ci trace_ath_log(common->hw->wiphy, &vaf); 868c2ecf20Sopenharmony_ci } else { 878c2ecf20Sopenharmony_ci printk("%sath: %pV", level, &vaf); 888c2ecf20Sopenharmony_ci } 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci va_end(args); 918c2ecf20Sopenharmony_ci} 928c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath_printk); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciconst char *ath_bus_type_strings[] = { 958c2ecf20Sopenharmony_ci [ATH_PCI] = "pci", 968c2ecf20Sopenharmony_ci [ATH_AHB] = "ahb", 978c2ecf20Sopenharmony_ci [ATH_USB] = "usb", 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath_bus_type_strings); 100