ah.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted (subject to the limitations in the
  7. * disclaimer below) provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the
  15. * distribution.
  16. *
  17. * * Neither the name of Qualcomm Atheros nor the names of its
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  22. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  23. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  32. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  33. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include "ah.h"
  36. #include "ah_internal.h"
  37. #include <asf_bitmap.h>
  38. extern struct ath_hal *ar5416Attach(HAL_SOFTC sc, adf_os_device_t dev,
  39. HAL_STATUS *status);
  40. struct ath_hal*
  41. ath_hal_attach_tgt(a_uint32_t devid,HAL_SOFTC sc,
  42. adf_os_device_t dev,
  43. a_uint32_t flags, HAL_STATUS *error)
  44. {
  45. struct ath_hal *ah = AH_NULL;
  46. ah = ar5416Attach(sc, dev, error);
  47. return ah;
  48. }
  49. HAL_STATUS
  50. ath_hal_getcapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type)
  51. {
  52. const HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
  53. switch (type) {
  54. case HAL_CAP_TSF_ADJUST:
  55. return HAL_ENOTSUPP;
  56. case HAL_CAP_BSSIDMASK:
  57. return pCap->halBssIdMaskSupport ? HAL_OK : HAL_ENOTSUPP;
  58. case HAL_CAP_VEOL:
  59. return pCap->halVEOLSupport ? HAL_OK : HAL_ENOTSUPP;
  60. default:
  61. return HAL_EINVAL;
  62. }
  63. }
  64. #define CCK_SIFS_TIME 10
  65. #define CCK_PREAMBLE_BITS 144
  66. #define CCK_PLCP_BITS 48
  67. #define OFDM_SIFS_TIME 16
  68. #define OFDM_PREAMBLE_TIME 20
  69. #define OFDM_PLCP_BITS 22
  70. #define OFDM_SYMBOL_TIME 4
  71. #define OFDM_SIFS_TIME_HALF 32
  72. #define OFDM_PREAMBLE_TIME_HALF 40
  73. #define OFDM_PLCP_BITS_HALF 22
  74. #define OFDM_SYMBOL_TIME_HALF 8
  75. #define OFDM_SIFS_TIME_QUARTER 64
  76. #define OFDM_PREAMBLE_TIME_QUARTER 80
  77. #define OFDM_PLCP_BITS_QUARTER 22
  78. #define OFDM_SYMBOL_TIME_QUARTER 16
  79. a_uint16_t
  80. ath_hal_computetxtime(struct ath_hal *ah,
  81. const HAL_RATE_TABLE *rates, a_uint32_t frameLen, a_uint16_t rateix,
  82. HAL_BOOL shortPreamble)
  83. {
  84. a_uint32_t bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  85. a_uint32_t kbps;
  86. kbps = rates->info[rateix].rateKbps;
  87. /*
  88. * index can be invalid duting dynamic Turbo transitions.
  89. */
  90. if(kbps == 0) return 0;
  91. switch (rates->info[rateix].phy) {
  92. case IEEE80211_T_CCK:
  93. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  94. if (shortPreamble && rates->info[rateix].shortPreamble)
  95. phyTime >>= 1;
  96. numBits = frameLen << 3;
  97. txTime = phyTime + ((numBits * 1000)/kbps);
  98. /* TODO: make sure the same value of txTime can use in all device */
  99. if (ath_hal_getcapability(ah, HAL_CAP_HT) != HAL_OK)
  100. txTime = txTime + CCK_SIFS_TIME;
  101. break;
  102. case IEEE80211_T_OFDM:
  103. /* full rate channel */
  104. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  105. HALASSERT(bitsPerSymbol != 0);
  106. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  107. numSymbols = asf_howmany(numBits, bitsPerSymbol);
  108. txTime = OFDM_PREAMBLE_TIME + (numSymbols * OFDM_SYMBOL_TIME);
  109. /* TODO: make sure the same value of txTime can use in all device */
  110. if (ath_hal_getcapability(ah, HAL_CAP_HT) != HAL_OK)
  111. txTime = txTime + OFDM_SIFS_TIME;
  112. break;
  113. default:
  114. txTime = 0;
  115. break;
  116. }
  117. return txTime;
  118. }
  119. #undef CCK_SIFS_TIME
  120. #undef CCK_PREAMBLE_BITS
  121. #undef CCK_PLCP_BITS
  122. #undef OFDM_SIFS_TIME
  123. #undef OFDM_PREAMBLE_TIME
  124. #undef OFDM_PLCP_BITS
  125. #undef OFDM_SYMBOL_TIME
  126. #ifdef MAGPIE_MERLIN
  127. a_uint32_t
  128. ath_hal_get_curmode(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *chan)
  129. {
  130. if (!chan)
  131. return HAL_MODE_11NG;
  132. if (IS_CHAN_NA(chan))
  133. return HAL_MODE_11NA;
  134. if (IS_CHAN_A(chan))
  135. return HAL_MODE_11A;
  136. if (IS_CHAN_NG(chan))
  137. return HAL_MODE_11NG;
  138. if (IS_CHAN_G(chan))
  139. return HAL_MODE_11G;
  140. if (IS_CHAN_B(chan))
  141. return HAL_MODE_11B;
  142. HALASSERT(0);
  143. return HAL_MODE_11NG;
  144. }
  145. #endif
  146. HAL_BOOL
  147. ath_hal_wait(struct ath_hal *ah, a_uint32_t reg, a_uint32_t mask, a_uint32_t val)
  148. {
  149. #define AH_TIMEOUT_11N 100000
  150. #define AH_TIMEOUT_11G 1000
  151. a_int32_t i;
  152. if (ath_hal_getcapability(ah, HAL_CAP_HT) == HAL_OK) {
  153. for (i = 0; i < AH_TIMEOUT_11N; i++) {
  154. if ((ioread32_mac(reg) & mask) == val)
  155. return AH_TRUE;
  156. OS_DELAY(10);
  157. }
  158. } else {
  159. for (i = 0; i < AH_TIMEOUT_11G; i++) {
  160. if ((ioread32_mac(reg) & mask) == val)
  161. return AH_TRUE;
  162. OS_DELAY(10);
  163. }
  164. }
  165. return AH_FALSE;
  166. #undef AH_TIMEOUT_11N
  167. #undef AH_TIMEOUT_11G
  168. }