channel.c 6.5 KB

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