main.c 2.9 KB

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