main.c 2.7 KB

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