common.h 4.2 KB

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