channel.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * File: channel.c
  20. *
  21. */
  22. #include "baseband.h"
  23. #include "channel.h"
  24. #include "device.h"
  25. #include "rf.h"
  26. static struct ieee80211_rate vnt_rates_bg[] = {
  27. { .bitrate = 10, .hw_value = RATE_1M },
  28. { .bitrate = 20, .hw_value = RATE_2M },
  29. { .bitrate = 55, .hw_value = RATE_5M },
  30. { .bitrate = 110, .hw_value = RATE_11M },
  31. { .bitrate = 60, .hw_value = RATE_6M },
  32. { .bitrate = 90, .hw_value = RATE_9M },
  33. { .bitrate = 120, .hw_value = RATE_12M },
  34. { .bitrate = 180, .hw_value = RATE_18M },
  35. { .bitrate = 240, .hw_value = RATE_24M },
  36. { .bitrate = 360, .hw_value = RATE_36M },
  37. { .bitrate = 480, .hw_value = RATE_48M },
  38. { .bitrate = 540, .hw_value = RATE_54M },
  39. };
  40. static struct ieee80211_rate vnt_rates_a[] = {
  41. { .bitrate = 60, .hw_value = RATE_6M },
  42. { .bitrate = 90, .hw_value = RATE_9M },
  43. { .bitrate = 120, .hw_value = RATE_12M },
  44. { .bitrate = 180, .hw_value = RATE_18M },
  45. { .bitrate = 240, .hw_value = RATE_24M },
  46. { .bitrate = 360, .hw_value = RATE_36M },
  47. { .bitrate = 480, .hw_value = RATE_48M },
  48. { .bitrate = 540, .hw_value = RATE_54M },
  49. };
  50. static struct ieee80211_channel vnt_channels_2ghz[] = {
  51. { .center_freq = 2412, .hw_value = 1 },
  52. { .center_freq = 2417, .hw_value = 2 },
  53. { .center_freq = 2422, .hw_value = 3 },
  54. { .center_freq = 2427, .hw_value = 4 },
  55. { .center_freq = 2432, .hw_value = 5 },
  56. { .center_freq = 2437, .hw_value = 6 },
  57. { .center_freq = 2442, .hw_value = 7 },
  58. { .center_freq = 2447, .hw_value = 8 },
  59. { .center_freq = 2452, .hw_value = 9 },
  60. { .center_freq = 2457, .hw_value = 10 },
  61. { .center_freq = 2462, .hw_value = 11 },
  62. { .center_freq = 2467, .hw_value = 12 },
  63. { .center_freq = 2472, .hw_value = 13 },
  64. { .center_freq = 2484, .hw_value = 14 }
  65. };
  66. static struct ieee80211_channel vnt_channels_5ghz[] = {
  67. { .center_freq = 4915, .hw_value = 15 },
  68. { .center_freq = 4920, .hw_value = 16 },
  69. { .center_freq = 4925, .hw_value = 17 },
  70. { .center_freq = 4935, .hw_value = 18 },
  71. { .center_freq = 4940, .hw_value = 19 },
  72. { .center_freq = 4945, .hw_value = 20 },
  73. { .center_freq = 4960, .hw_value = 21 },
  74. { .center_freq = 4980, .hw_value = 22 },
  75. { .center_freq = 5035, .hw_value = 23 },
  76. { .center_freq = 5040, .hw_value = 24 },
  77. { .center_freq = 5045, .hw_value = 25 },
  78. { .center_freq = 5055, .hw_value = 26 },
  79. { .center_freq = 5060, .hw_value = 27 },
  80. { .center_freq = 5080, .hw_value = 28 },
  81. { .center_freq = 5170, .hw_value = 29 },
  82. { .center_freq = 5180, .hw_value = 30 },
  83. { .center_freq = 5190, .hw_value = 31 },
  84. { .center_freq = 5200, .hw_value = 32 },
  85. { .center_freq = 5210, .hw_value = 33 },
  86. { .center_freq = 5220, .hw_value = 34 },
  87. { .center_freq = 5230, .hw_value = 35 },
  88. { .center_freq = 5240, .hw_value = 36 },
  89. { .center_freq = 5260, .hw_value = 37 },
  90. { .center_freq = 5280, .hw_value = 38 },
  91. { .center_freq = 5300, .hw_value = 39 },
  92. { .center_freq = 5320, .hw_value = 40 },
  93. { .center_freq = 5500, .hw_value = 41 },
  94. { .center_freq = 5520, .hw_value = 42 },
  95. { .center_freq = 5540, .hw_value = 43 },
  96. { .center_freq = 5560, .hw_value = 44 },
  97. { .center_freq = 5580, .hw_value = 45 },
  98. { .center_freq = 5600, .hw_value = 46 },
  99. { .center_freq = 5620, .hw_value = 47 },
  100. { .center_freq = 5640, .hw_value = 48 },
  101. { .center_freq = 5660, .hw_value = 49 },
  102. { .center_freq = 5680, .hw_value = 50 },
  103. { .center_freq = 5700, .hw_value = 51 },
  104. { .center_freq = 5745, .hw_value = 52 },
  105. { .center_freq = 5765, .hw_value = 53 },
  106. { .center_freq = 5785, .hw_value = 54 },
  107. { .center_freq = 5805, .hw_value = 55 },
  108. { .center_freq = 5825, .hw_value = 56 }
  109. };
  110. static struct ieee80211_supported_band vnt_supported_2ghz_band = {
  111. .channels = vnt_channels_2ghz,
  112. .n_channels = ARRAY_SIZE(vnt_channels_2ghz),
  113. .bitrates = vnt_rates_bg,
  114. .n_bitrates = ARRAY_SIZE(vnt_rates_bg),
  115. };
  116. static struct ieee80211_supported_band vnt_supported_5ghz_band = {
  117. .channels = vnt_channels_5ghz,
  118. .n_channels = ARRAY_SIZE(vnt_channels_5ghz),
  119. .bitrates = vnt_rates_a,
  120. .n_bitrates = ARRAY_SIZE(vnt_rates_a),
  121. };
  122. void vnt_init_bands(struct vnt_private *priv)
  123. {
  124. struct ieee80211_channel *ch;
  125. int i;
  126. switch (priv->byRFType) {
  127. case RF_AIROHA7230:
  128. case RF_UW2452:
  129. case RF_NOTHING:
  130. default:
  131. ch = vnt_channels_5ghz;
  132. for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
  133. ch[i].max_power = 0x3f;
  134. ch[i].flags = IEEE80211_CHAN_NO_HT40;
  135. }
  136. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  137. &vnt_supported_5ghz_band;
  138. /* fallthrough */
  139. case RF_RFMD2959:
  140. case RF_AIROHA:
  141. case RF_AL2230S:
  142. case RF_UW2451:
  143. case RF_VT3226:
  144. ch = vnt_channels_2ghz;
  145. for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
  146. ch[i].max_power = 0x3f;
  147. ch[i].flags = IEEE80211_CHAN_NO_HT40;
  148. }
  149. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  150. &vnt_supported_2ghz_band;
  151. break;
  152. }
  153. }
  154. /**
  155. * set_channel() - Set NIC media channel
  156. *
  157. * @pDeviceHandler: The adapter to be set
  158. * @uConnectionChannel: Channel to be set
  159. *
  160. * Return Value: true if succeeded; false if failed.
  161. *
  162. */
  163. bool set_channel(void *pDeviceHandler, struct ieee80211_channel *ch)
  164. {
  165. struct vnt_private *pDevice = pDeviceHandler;
  166. bool bResult = true;
  167. if (pDevice->byCurrentCh == ch->hw_value)
  168. return bResult;
  169. /* Set VGA to max sensitivity */
  170. if (pDevice->bUpdateBBVGA &&
  171. pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) {
  172. pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
  173. BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
  174. }
  175. /* clear NAV */
  176. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV);
  177. /* TX_PE will reserve 3 us for MAX2829 A mode only,
  178. it is for better TX throughput */
  179. if (pDevice->byRFType == RF_AIROHA7230)
  180. RFbAL7230SelectChannelPostProcess(pDevice, pDevice->byCurrentCh,
  181. ch->hw_value);
  182. pDevice->byCurrentCh = ch->hw_value;
  183. bResult &= RFbSelectChannel(pDevice, pDevice->byRFType,
  184. ch->hw_value);
  185. /* Init Synthesizer Table */
  186. if (pDevice->bEnablePSMode)
  187. RFvWriteWakeProgSyn(pDevice, pDevice->byRFType, ch->hw_value);
  188. BBvSoftwareReset(pDevice);
  189. if (pDevice->byLocalID > REV_ID_VT3253_B1) {
  190. unsigned long flags;
  191. spin_lock_irqsave(&pDevice->lock, flags);
  192. /* set HW default power register */
  193. MACvSelectPage1(pDevice->PortOffset);
  194. RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
  195. VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWRCCK,
  196. pDevice->byCurPwr);
  197. RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
  198. VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWROFDM,
  199. pDevice->byCurPwr);
  200. MACvSelectPage0(pDevice->PortOffset);
  201. spin_unlock_irqrestore(&pDevice->lock, flags);
  202. }
  203. if (pDevice->byBBType == BB_TYPE_11B)
  204. RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
  205. else
  206. RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
  207. return bResult;
  208. }