common.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include <net/mac80211.h>
  17. #include "../ath.h"
  18. #include "../debug.h"
  19. #include "hw.h"
  20. /* Common header for Atheros 802.11n base driver cores */
  21. #define WME_NUM_TID 16
  22. #define WME_BA_BMP_SIZE 64
  23. #define WME_MAX_BA WME_BA_BMP_SIZE
  24. #define ATH_TID_MAX_BUFS (2 * WME_MAX_BA)
  25. #define WME_AC_BE 0
  26. #define WME_AC_BK 1
  27. #define WME_AC_VI 2
  28. #define WME_AC_VO 3
  29. #define WME_NUM_AC 4
  30. #define ATH_RSSI_DUMMY_MARKER 0x127
  31. #define ATH_RSSI_LPF_LEN 10
  32. #define RSSI_LPF_THRESHOLD -20
  33. #define ATH_RSSI_EP_MULTIPLIER (1<<7)
  34. #define ATH_EP_MUL(x, mul) ((x) * (mul))
  35. #define ATH_RSSI_IN(x) (ATH_EP_MUL((x), ATH_RSSI_EP_MULTIPLIER))
  36. #define ATH_LPF_RSSI(x, y, len) \
  37. ((x != ATH_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
  38. #define ATH_RSSI_LPF(x, y) do { \
  39. if ((y) >= RSSI_LPF_THRESHOLD) \
  40. x = ATH_LPF_RSSI((x), ATH_RSSI_IN((y)), ATH_RSSI_LPF_LEN); \
  41. } while (0)
  42. #define ATH_EP_RND(x, mul) \
  43. ((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
  44. struct ath_atx_ac {
  45. int sched;
  46. int qnum;
  47. struct list_head list;
  48. struct list_head tid_q;
  49. };
  50. struct ath_buf_state {
  51. int bfs_nframes;
  52. u16 bfs_al;
  53. u16 bfs_frmlen;
  54. int bfs_seqno;
  55. int bfs_tidno;
  56. int bfs_retries;
  57. u8 bf_type;
  58. u32 bfs_keyix;
  59. enum ath9k_key_type bfs_keytype;
  60. };
  61. struct ath_buf {
  62. struct list_head list;
  63. struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or
  64. an aggregate) */
  65. struct ath_buf *bf_next; /* next subframe in the aggregate */
  66. struct sk_buff *bf_mpdu; /* enclosing frame structure */
  67. struct ath_desc *bf_desc; /* virtual addr of desc */
  68. dma_addr_t bf_daddr; /* physical addr of desc */
  69. dma_addr_t bf_buf_addr; /* physical addr of data buffer */
  70. bool bf_stale;
  71. bool bf_isnullfunc;
  72. u16 bf_flags;
  73. struct ath_buf_state bf_state;
  74. dma_addr_t bf_dmacontext;
  75. struct ath_wiphy *aphy;
  76. };
  77. struct ath_atx_tid {
  78. struct list_head list;
  79. struct list_head buf_q;
  80. struct ath_node *an;
  81. struct ath_atx_ac *ac;
  82. struct ath_buf *tx_buf[ATH_TID_MAX_BUFS];
  83. u16 seq_start;
  84. u16 seq_next;
  85. u16 baw_size;
  86. int tidno;
  87. int baw_head; /* first un-acked tx buffer */
  88. int baw_tail; /* next unused tx buffer slot */
  89. int sched;
  90. int paused;
  91. u8 state;
  92. };
  93. struct ath_node {
  94. struct ath_common *common;
  95. struct ath_atx_tid tid[WME_NUM_TID];
  96. struct ath_atx_ac ac[WME_NUM_AC];
  97. u16 maxampdu;
  98. u8 mpdudensity;
  99. int last_rssi;
  100. };
  101. int ath9k_cmn_rx_skb_preprocess(struct ath_common *common,
  102. struct ieee80211_hw *hw,
  103. struct sk_buff *skb,
  104. struct ath_rx_status *rx_stats,
  105. struct ieee80211_rx_status *rx_status,
  106. bool *decrypt_error);
  107. void ath9k_cmn_rx_skb_postprocess(struct ath_common *common,
  108. struct sk_buff *skb,
  109. struct ath_rx_status *rx_stats,
  110. struct ieee80211_rx_status *rxs,
  111. bool decrypt_error);
  112. int ath9k_cmn_padpos(__le16 frame_control);