rc.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. /*
  2. * Copyright (c) 2004 Video54 Technologies, Inc.
  3. * Copyright (c) 2004-2009 Atheros Communications, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "ath9k.h"
  18. static const struct ath_rate_table ar5416_11na_ratetable = {
  19. 42,
  20. 8, /* MCS start */
  21. {
  22. { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  23. 5400, 0, 12, 0, 0, 0, 0, 0 },
  24. { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  25. 7800, 1, 18, 0, 1, 1, 1, 1 },
  26. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  27. 10000, 2, 24, 2, 2, 2, 2, 2 },
  28. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  29. 13900, 3, 36, 2, 3, 3, 3, 3 },
  30. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  31. 17300, 4, 48, 4, 4, 4, 4, 4 },
  32. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  33. 23000, 5, 72, 4, 5, 5, 5, 5 },
  34. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  35. 27400, 6, 96, 4, 6, 6, 6, 6 },
  36. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  37. 29300, 7, 108, 4, 7, 7, 7, 7 },
  38. { VALID_2040, VALID_2040, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  39. 6400, 0, 0, 0, 8, 24, 8, 24 },
  40. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
  41. 12700, 1, 1, 2, 9, 25, 9, 25 },
  42. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  43. 18800, 2, 2, 2, 10, 26, 10, 26 },
  44. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
  45. 25000, 3, 3, 4, 11, 27, 11, 27 },
  46. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
  47. 36700, 4, 4, 4, 12, 28, 12, 28 },
  48. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
  49. 48100, 5, 5, 4, 13, 29, 13, 29 },
  50. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  51. 53500, 6, 6, 4, 14, 30, 14, 30 },
  52. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
  53. 59000, 7, 7, 4, 15, 31, 15, 32 },
  54. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
  55. 12700, 8, 8, 3, 16, 33, 16, 33 },
  56. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
  57. 24800, 9, 9, 2, 17, 34, 17, 34 },
  58. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
  59. 36600, 10, 10, 2, 18, 35, 18, 35 },
  60. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
  61. 48100, 11, 11, 4, 19, 36, 19, 36 },
  62. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
  63. 69500, 12, 12, 4, 20, 37, 20, 37 },
  64. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
  65. 89500, 13, 13, 4, 21, 38, 21, 38 },
  66. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
  67. 98900, 14, 14, 4, 22, 39, 22, 39 },
  68. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
  69. 108300, 15, 15, 4, 23, 40, 23, 41 },
  70. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  71. 13200, 0, 0, 0, 8, 24, 24, 24 },
  72. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  73. 25900, 1, 1, 2, 9, 25, 25, 25 },
  74. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  75. 38600, 2, 2, 2, 10, 26, 26, 26 },
  76. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
  77. 49800, 3, 3, 4, 11, 27, 27, 27 },
  78. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
  79. 72200, 4, 4, 4, 12, 28, 28, 28 },
  80. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
  81. 92900, 5, 5, 4, 13, 29, 29, 29 },
  82. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  83. 102700, 6, 6, 4, 14, 30, 30, 30 },
  84. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
  85. 112000, 7, 7, 4, 15, 31, 32, 32 },
  86. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  87. 122000, 7, 7, 4, 15, 31, 32, 32 },
  88. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
  89. 25800, 8, 8, 0, 16, 33, 33, 33 },
  90. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
  91. 49800, 9, 9, 2, 17, 34, 34, 34 },
  92. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
  93. 71900, 10, 10, 2, 18, 35, 35, 35 },
  94. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
  95. 92500, 11, 11, 4, 19, 36, 36, 36 },
  96. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
  97. 130300, 12, 12, 4, 20, 37, 37, 37 },
  98. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
  99. 162800, 13, 13, 4, 21, 38, 38, 38 },
  100. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
  101. 178200, 14, 14, 4, 22, 39, 39, 39 },
  102. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
  103. 192100, 15, 15, 4, 23, 40, 41, 41 },
  104. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  105. 207000, 15, 15, 4, 23, 40, 41, 41 },
  106. },
  107. 50, /* probe interval */
  108. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  109. };
  110. /* 4ms frame limit not used for NG mode. The values filled
  111. * for HT are the 64K max aggregate limit */
  112. static const struct ath_rate_table ar5416_11ng_ratetable = {
  113. 46,
  114. 12, /* MCS start */
  115. {
  116. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
  117. 900, 0, 2, 0, 0, 0, 0, 0 },
  118. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
  119. 1900, 1, 4, 1, 1, 1, 1, 1 },
  120. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
  121. 4900, 2, 11, 2, 2, 2, 2, 2 },
  122. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
  123. 8100, 3, 22, 3, 3, 3, 3, 3 },
  124. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  125. 5400, 4, 12, 4, 4, 4, 4, 4 },
  126. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  127. 7800, 5, 18, 4, 5, 5, 5, 5 },
  128. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  129. 10100, 6, 24, 6, 6, 6, 6, 6 },
  130. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  131. 14100, 7, 36, 6, 7, 7, 7, 7 },
  132. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  133. 17700, 8, 48, 8, 8, 8, 8, 8 },
  134. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  135. 23700, 9, 72, 8, 9, 9, 9, 9 },
  136. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  137. 27400, 10, 96, 8, 10, 10, 10, 10 },
  138. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  139. 30900, 11, 108, 8, 11, 11, 11, 11 },
  140. { INVALID, INVALID, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  141. 6400, 0, 0, 4, 12, 28, 12, 28 },
  142. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
  143. 12700, 1, 1, 6, 13, 29, 13, 29 },
  144. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  145. 18800, 2, 2, 6, 14, 30, 14, 30 },
  146. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
  147. 25000, 3, 3, 8, 15, 31, 15, 31 },
  148. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
  149. 36700, 4, 4, 8, 16, 32, 16, 32 },
  150. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
  151. 48100, 5, 5, 8, 17, 33, 17, 33 },
  152. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  153. 53500, 6, 6, 8, 18, 34, 18, 34 },
  154. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
  155. 59000, 7, 7, 8, 19, 35, 19, 36 },
  156. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
  157. 12700, 8, 8, 4, 20, 37, 20, 37 },
  158. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
  159. 24800, 9, 9, 6, 21, 38, 21, 38 },
  160. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
  161. 36600, 10, 10, 6, 22, 39, 22, 39 },
  162. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
  163. 48100, 11, 11, 8, 23, 40, 23, 40 },
  164. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
  165. 69500, 12, 12, 8, 24, 41, 24, 41 },
  166. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
  167. 89500, 13, 13, 8, 25, 42, 25, 42 },
  168. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
  169. 98900, 14, 14, 8, 26, 43, 26, 44 },
  170. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
  171. 108300, 15, 15, 8, 27, 44, 27, 45 },
  172. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  173. 13200, 0, 0, 8, 12, 28, 28, 28 },
  174. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  175. 25900, 1, 1, 8, 13, 29, 29, 29 },
  176. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  177. 38600, 2, 2, 8, 14, 30, 30, 30 },
  178. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
  179. 49800, 3, 3, 8, 15, 31, 31, 31 },
  180. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
  181. 72200, 4, 4, 8, 16, 32, 32, 32 },
  182. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
  183. 92900, 5, 5, 8, 17, 33, 33, 33 },
  184. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  185. 102700, 6, 6, 8, 18, 34, 34, 34 },
  186. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
  187. 112000, 7, 7, 8, 19, 35, 36, 36 },
  188. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  189. 122000, 7, 7, 8, 19, 35, 36, 36 },
  190. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
  191. 25800, 8, 8, 8, 20, 37, 37, 37 },
  192. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
  193. 49800, 9, 9, 8, 21, 38, 38, 38 },
  194. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
  195. 71900, 10, 10, 8, 22, 39, 39, 39 },
  196. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
  197. 92500, 11, 11, 8, 23, 40, 40, 40 },
  198. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
  199. 130300, 12, 12, 8, 24, 41, 41, 41 },
  200. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
  201. 162800, 13, 13, 8, 25, 42, 42, 42 },
  202. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
  203. 178200, 14, 14, 8, 26, 43, 43, 43 },
  204. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
  205. 192100, 15, 15, 8, 27, 44, 45, 45 },
  206. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  207. 207000, 15, 15, 8, 27, 44, 45, 45 },
  208. },
  209. 50, /* probe interval */
  210. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  211. };
  212. static const struct ath_rate_table ar5416_11a_ratetable = {
  213. 8,
  214. 0,
  215. {
  216. { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  217. 5400, 0, 12, 0, 0, 0 },
  218. { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  219. 7800, 1, 18, 0, 1, 0 },
  220. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  221. 10000, 2, 24, 2, 2, 0 },
  222. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  223. 13900, 3, 36, 2, 3, 0 },
  224. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  225. 17300, 4, 48, 4, 4, 0 },
  226. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  227. 23000, 5, 72, 4, 5, 0 },
  228. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  229. 27400, 6, 96, 4, 6, 0 },
  230. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  231. 29300, 7, 108, 4, 7, 0 },
  232. },
  233. 50, /* probe interval */
  234. 0, /* Phy rates allowed initially */
  235. };
  236. static const struct ath_rate_table ar5416_11g_ratetable = {
  237. 12,
  238. 0,
  239. {
  240. { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
  241. 900, 0, 2, 0, 0, 0 },
  242. { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
  243. 1900, 1, 4, 1, 1, 0 },
  244. { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
  245. 4900, 2, 11, 2, 2, 0 },
  246. { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
  247. 8100, 3, 22, 3, 3, 0 },
  248. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  249. 5400, 4, 12, 4, 4, 0 },
  250. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  251. 7800, 5, 18, 4, 5, 0 },
  252. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  253. 10000, 6, 24, 6, 6, 0 },
  254. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  255. 13900, 7, 36, 6, 7, 0 },
  256. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  257. 17300, 8, 48, 8, 8, 0 },
  258. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  259. 23000, 9, 72, 8, 9, 0 },
  260. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  261. 27400, 10, 96, 8, 10, 0 },
  262. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  263. 29300, 11, 108, 8, 11, 0 },
  264. },
  265. 50, /* probe interval */
  266. 0, /* Phy rates allowed initially */
  267. };
  268. static const struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX] = {
  269. [ATH9K_MODE_11A] = &ar5416_11a_ratetable,
  270. [ATH9K_MODE_11G] = &ar5416_11g_ratetable,
  271. [ATH9K_MODE_11NA_HT20] = &ar5416_11na_ratetable,
  272. [ATH9K_MODE_11NG_HT20] = &ar5416_11ng_ratetable,
  273. [ATH9K_MODE_11NA_HT40PLUS] = &ar5416_11na_ratetable,
  274. [ATH9K_MODE_11NA_HT40MINUS] = &ar5416_11na_ratetable,
  275. [ATH9K_MODE_11NG_HT40PLUS] = &ar5416_11ng_ratetable,
  276. [ATH9K_MODE_11NG_HT40MINUS] = &ar5416_11ng_ratetable,
  277. };
  278. static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
  279. struct ieee80211_tx_rate *rate);
  280. static inline int8_t median(int8_t a, int8_t b, int8_t c)
  281. {
  282. if (a >= b) {
  283. if (b >= c)
  284. return b;
  285. else if (a > c)
  286. return c;
  287. else
  288. return a;
  289. } else {
  290. if (a >= c)
  291. return a;
  292. else if (b >= c)
  293. return c;
  294. else
  295. return b;
  296. }
  297. }
  298. static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table,
  299. struct ath_rate_priv *ath_rc_priv)
  300. {
  301. u8 i, j, idx, idx_next;
  302. for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) {
  303. for (j = 0; j <= i-1; j++) {
  304. idx = ath_rc_priv->valid_rate_index[j];
  305. idx_next = ath_rc_priv->valid_rate_index[j+1];
  306. if (rate_table->info[idx].ratekbps >
  307. rate_table->info[idx_next].ratekbps) {
  308. ath_rc_priv->valid_rate_index[j] = idx_next;
  309. ath_rc_priv->valid_rate_index[j+1] = idx;
  310. }
  311. }
  312. }
  313. }
  314. static void ath_rc_init_valid_txmask(struct ath_rate_priv *ath_rc_priv)
  315. {
  316. u8 i;
  317. for (i = 0; i < ath_rc_priv->rate_table_size; i++)
  318. ath_rc_priv->valid_rate_index[i] = 0;
  319. }
  320. static inline void ath_rc_set_valid_txmask(struct ath_rate_priv *ath_rc_priv,
  321. u8 index, int valid_tx_rate)
  322. {
  323. BUG_ON(index > ath_rc_priv->rate_table_size);
  324. ath_rc_priv->valid_rate_index[index] = valid_tx_rate ? 1 : 0;
  325. }
  326. static inline
  327. int ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
  328. struct ath_rate_priv *ath_rc_priv,
  329. u8 cur_valid_txrate,
  330. u8 *next_idx)
  331. {
  332. u8 i;
  333. for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) {
  334. if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
  335. *next_idx = ath_rc_priv->valid_rate_index[i+1];
  336. return 1;
  337. }
  338. }
  339. /* No more valid rates */
  340. *next_idx = 0;
  341. return 0;
  342. }
  343. /* Return true only for single stream */
  344. static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
  345. {
  346. if (WLAN_RC_PHY_HT(phy) && !(capflag & WLAN_RC_HT_FLAG))
  347. return 0;
  348. if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
  349. return 0;
  350. if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
  351. return 0;
  352. if (!ignore_cw && WLAN_RC_PHY_HT(phy))
  353. if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
  354. return 0;
  355. return 1;
  356. }
  357. static inline int
  358. ath_rc_get_lower_rix(const struct ath_rate_table *rate_table,
  359. struct ath_rate_priv *ath_rc_priv,
  360. u8 cur_valid_txrate, u8 *next_idx)
  361. {
  362. int8_t i;
  363. for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) {
  364. if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
  365. *next_idx = ath_rc_priv->valid_rate_index[i-1];
  366. return 1;
  367. }
  368. }
  369. return 0;
  370. }
  371. static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv,
  372. const struct ath_rate_table *rate_table,
  373. u32 capflag)
  374. {
  375. u8 i, hi = 0;
  376. u32 valid;
  377. for (i = 0; i < rate_table->rate_cnt; i++) {
  378. valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
  379. rate_table->info[i].valid_single_stream :
  380. rate_table->info[i].valid);
  381. if (valid == 1) {
  382. u32 phy = rate_table->info[i].phy;
  383. u8 valid_rate_count = 0;
  384. if (!ath_rc_valid_phyrate(phy, capflag, 0))
  385. continue;
  386. valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
  387. ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i;
  388. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  389. ath_rc_set_valid_txmask(ath_rc_priv, i, 1);
  390. hi = A_MAX(hi, i);
  391. }
  392. }
  393. return hi;
  394. }
  395. static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
  396. const struct ath_rate_table *rate_table,
  397. struct ath_rateset *rateset,
  398. u32 capflag)
  399. {
  400. u8 i, j, hi = 0;
  401. /* Use intersection of working rates and valid rates */
  402. for (i = 0; i < rateset->rs_nrates; i++) {
  403. for (j = 0; j < rate_table->rate_cnt; j++) {
  404. u32 phy = rate_table->info[j].phy;
  405. u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
  406. rate_table->info[j].valid_single_stream :
  407. rate_table->info[j].valid);
  408. u8 rate = rateset->rs_rates[i];
  409. u8 dot11rate = rate_table->info[j].dot11rate;
  410. /* We allow a rate only if its valid and the
  411. * capflag matches one of the validity
  412. * (VALID/VALID_20/VALID_40) flags */
  413. if ((rate == dot11rate) &&
  414. ((valid & WLAN_RC_CAP_MODE(capflag)) ==
  415. WLAN_RC_CAP_MODE(capflag)) &&
  416. !WLAN_RC_PHY_HT(phy)) {
  417. u8 valid_rate_count = 0;
  418. if (!ath_rc_valid_phyrate(phy, capflag, 0))
  419. continue;
  420. valid_rate_count =
  421. ath_rc_priv->valid_phy_ratecnt[phy];
  422. ath_rc_priv->valid_phy_rateidx[phy]
  423. [valid_rate_count] = j;
  424. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  425. ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
  426. hi = A_MAX(hi, j);
  427. }
  428. }
  429. }
  430. return hi;
  431. }
  432. static u8 ath_rc_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
  433. const struct ath_rate_table *rate_table,
  434. u8 *mcs_set, u32 capflag)
  435. {
  436. struct ath_rateset *rateset = (struct ath_rateset *)mcs_set;
  437. u8 i, j, hi = 0;
  438. /* Use intersection of working rates and valid rates */
  439. for (i = 0; i < rateset->rs_nrates; i++) {
  440. for (j = 0; j < rate_table->rate_cnt; j++) {
  441. u32 phy = rate_table->info[j].phy;
  442. u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
  443. rate_table->info[j].valid_single_stream :
  444. rate_table->info[j].valid);
  445. u8 rate = rateset->rs_rates[i];
  446. u8 dot11rate = rate_table->info[j].dot11rate;
  447. if ((rate != dot11rate) || !WLAN_RC_PHY_HT(phy) ||
  448. !WLAN_RC_PHY_HT_VALID(valid, capflag))
  449. continue;
  450. if (!ath_rc_valid_phyrate(phy, capflag, 0))
  451. continue;
  452. ath_rc_priv->valid_phy_rateidx[phy]
  453. [ath_rc_priv->valid_phy_ratecnt[phy]] = j;
  454. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  455. ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
  456. hi = A_MAX(hi, j);
  457. }
  458. }
  459. return hi;
  460. }
  461. /* Finds the highest rate index we can use */
  462. static u8 ath_rc_get_highest_rix(struct ath_softc *sc,
  463. struct ath_rate_priv *ath_rc_priv,
  464. const struct ath_rate_table *rate_table,
  465. int *is_probing)
  466. {
  467. u32 best_thruput, this_thruput, now_msec;
  468. u8 rate, next_rate, best_rate, maxindex, minindex;
  469. int8_t index = 0;
  470. now_msec = jiffies_to_msecs(jiffies);
  471. *is_probing = 0;
  472. best_thruput = 0;
  473. maxindex = ath_rc_priv->max_valid_rate-1;
  474. minindex = 0;
  475. best_rate = minindex;
  476. /*
  477. * Try the higher rate first. It will reduce memory moving time
  478. * if we have very good channel characteristics.
  479. */
  480. for (index = maxindex; index >= minindex ; index--) {
  481. u8 per_thres;
  482. rate = ath_rc_priv->valid_rate_index[index];
  483. if (rate > ath_rc_priv->rate_max_phy)
  484. continue;
  485. /*
  486. * For TCP the average collision rate is around 11%,
  487. * so we ignore PERs less than this. This is to
  488. * prevent the rate we are currently using (whose
  489. * PER might be in the 10-15 range because of TCP
  490. * collisions) looking worse than the next lower
  491. * rate whose PER has decayed close to 0. If we
  492. * used to next lower rate, its PER would grow to
  493. * 10-15 and we would be worse off then staying
  494. * at the current rate.
  495. */
  496. per_thres = ath_rc_priv->per[rate];
  497. if (per_thres < 12)
  498. per_thres = 12;
  499. this_thruput = rate_table->info[rate].user_ratekbps *
  500. (100 - per_thres);
  501. if (best_thruput <= this_thruput) {
  502. best_thruput = this_thruput;
  503. best_rate = rate;
  504. }
  505. }
  506. rate = best_rate;
  507. /*
  508. * Must check the actual rate (ratekbps) to account for
  509. * non-monoticity of 11g's rate table
  510. */
  511. if (rate >= ath_rc_priv->rate_max_phy) {
  512. rate = ath_rc_priv->rate_max_phy;
  513. /* Probe the next allowed phy state */
  514. if (ath_rc_get_nextvalid_txrate(rate_table,
  515. ath_rc_priv, rate, &next_rate) &&
  516. (now_msec - ath_rc_priv->probe_time >
  517. rate_table->probe_interval) &&
  518. (ath_rc_priv->hw_maxretry_pktcnt >= 1)) {
  519. rate = next_rate;
  520. ath_rc_priv->probe_rate = rate;
  521. ath_rc_priv->probe_time = now_msec;
  522. ath_rc_priv->hw_maxretry_pktcnt = 0;
  523. *is_probing = 1;
  524. }
  525. }
  526. if (rate > (ath_rc_priv->rate_table_size - 1))
  527. rate = ath_rc_priv->rate_table_size - 1;
  528. if (rate_table->info[rate].valid &&
  529. (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG))
  530. return rate;
  531. if (rate_table->info[rate].valid_single_stream &&
  532. !(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG))
  533. return rate;
  534. /* This should not happen */
  535. WARN_ON(1);
  536. rate = ath_rc_priv->valid_rate_index[0];
  537. return rate;
  538. }
  539. static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table,
  540. struct ieee80211_tx_rate *rate,
  541. struct ieee80211_tx_rate_control *txrc,
  542. u8 tries, u8 rix, int rtsctsenable)
  543. {
  544. rate->count = tries;
  545. rate->idx = rate_table->info[rix].ratecode;
  546. if (txrc->short_preamble)
  547. rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
  548. if (txrc->rts || rtsctsenable)
  549. rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
  550. if (WLAN_RC_PHY_HT(rate_table->info[rix].phy)) {
  551. rate->flags |= IEEE80211_TX_RC_MCS;
  552. if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
  553. rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  554. if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
  555. rate->flags |= IEEE80211_TX_RC_SHORT_GI;
  556. }
  557. }
  558. static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
  559. const struct ath_rate_table *rate_table,
  560. struct ieee80211_tx_info *tx_info)
  561. {
  562. struct ieee80211_tx_rate *rates = tx_info->control.rates;
  563. int i = 0, rix = 0, cix, enable_g_protection = 0;
  564. /* get the cix for the lowest valid rix */
  565. for (i = 3; i >= 0; i--) {
  566. if (rates[i].count && (rates[i].idx >= 0)) {
  567. rix = ath_rc_get_rateindex(rate_table, &rates[i]);
  568. break;
  569. }
  570. }
  571. cix = rate_table->info[rix].ctrl_rate;
  572. /* All protection frames are transmited at 2Mb/s for 802.11g,
  573. * otherwise we transmit them at 1Mb/s */
  574. if (sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ &&
  575. !conf_is_ht(&sc->hw->conf))
  576. enable_g_protection = 1;
  577. /*
  578. * If 802.11g protection is enabled, determine whether to use RTS/CTS or
  579. * just CTS. Note that this is only done for OFDM/HT unicast frames.
  580. */
  581. if ((sc->sc_flags & SC_OP_PROTECT_ENABLE) &&
  582. (rate_table->info[rix].phy == WLAN_RC_PHY_OFDM ||
  583. WLAN_RC_PHY_HT(rate_table->info[rix].phy))) {
  584. rates[0].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
  585. cix = rate_table->info[enable_g_protection].ctrl_rate;
  586. }
  587. tx_info->control.rts_cts_rate_idx = cix;
  588. }
  589. static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
  590. struct ieee80211_tx_rate_control *txrc)
  591. {
  592. struct ath_softc *sc = priv;
  593. struct ath_rate_priv *ath_rc_priv = priv_sta;
  594. const struct ath_rate_table *rate_table;
  595. struct sk_buff *skb = txrc->skb;
  596. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  597. struct ieee80211_tx_rate *rates = tx_info->control.rates;
  598. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  599. __le16 fc = hdr->frame_control;
  600. u8 try_per_rate, i = 0, rix;
  601. int is_probe = 0;
  602. if (rate_control_send_low(sta, priv_sta, txrc))
  603. return;
  604. /*
  605. * For Multi Rate Retry we use a different number of
  606. * retry attempt counts. This ends up looking like this:
  607. *
  608. * MRR[0] = 4
  609. * MRR[1] = 4
  610. * MRR[2] = 4
  611. * MRR[3] = 8
  612. *
  613. */
  614. try_per_rate = 4;
  615. rate_table = sc->cur_rate_table;
  616. rix = ath_rc_get_highest_rix(sc, ath_rc_priv, rate_table, &is_probe);
  617. /*
  618. * If we're in HT mode and both us and our peer supports LDPC.
  619. * We don't need to check our own device's capabilities as our own
  620. * ht capabilities would have already been intersected with our peer's.
  621. */
  622. if (conf_is_ht(&sc->hw->conf) &&
  623. (sta->ht_cap.cap & IEEE80211_HT_CAP_LDPC_CODING))
  624. tx_info->flags |= IEEE80211_TX_CTL_LDPC;
  625. if (conf_is_ht(&sc->hw->conf) &&
  626. (sta->ht_cap.cap & IEEE80211_HT_CAP_TX_STBC))
  627. tx_info->flags |= (1 << IEEE80211_TX_CTL_STBC_SHIFT);
  628. if (is_probe) {
  629. /* set one try for probe rates. For the
  630. * probes don't enable rts */
  631. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  632. 1, rix, 0);
  633. /* Get the next tried/allowed rate. No RTS for the next series
  634. * after the probe rate
  635. */
  636. ath_rc_get_lower_rix(rate_table, ath_rc_priv, rix, &rix);
  637. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  638. try_per_rate, rix, 0);
  639. tx_info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
  640. } else {
  641. /* Set the choosen rate. No RTS for first series entry. */
  642. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  643. try_per_rate, rix, 0);
  644. }
  645. /* Fill in the other rates for multirate retry */
  646. for ( ; i < 4; i++) {
  647. /* Use twice the number of tries for the last MRR segment. */
  648. if (i + 1 == 4)
  649. try_per_rate = 8;
  650. ath_rc_get_lower_rix(rate_table, ath_rc_priv, rix, &rix);
  651. /* All other rates in the series have RTS enabled */
  652. ath_rc_rate_set_series(rate_table, &rates[i], txrc,
  653. try_per_rate, rix, 1);
  654. }
  655. /*
  656. * NB:Change rate series to enable aggregation when operating
  657. * at lower MCS rates. When first rate in series is MCS2
  658. * in HT40 @ 2.4GHz, series should look like:
  659. *
  660. * {MCS2, MCS1, MCS0, MCS0}.
  661. *
  662. * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
  663. * look like:
  664. *
  665. * {MCS3, MCS2, MCS1, MCS1}
  666. *
  667. * So, set fourth rate in series to be same as third one for
  668. * above conditions.
  669. */
  670. if ((sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ) &&
  671. (conf_is_ht(&sc->hw->conf))) {
  672. u8 dot11rate = rate_table->info[rix].dot11rate;
  673. u8 phy = rate_table->info[rix].phy;
  674. if (i == 4 &&
  675. ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
  676. (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
  677. rates[3].idx = rates[2].idx;
  678. rates[3].flags = rates[2].flags;
  679. }
  680. }
  681. /*
  682. * Force hardware to use computed duration for next
  683. * fragment by disabling multi-rate retry, which
  684. * updates duration based on the multi-rate duration table.
  685. *
  686. * FIXME: Fix duration
  687. */
  688. if (ieee80211_has_morefrags(fc) ||
  689. (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
  690. rates[1].count = rates[2].count = rates[3].count = 0;
  691. rates[1].idx = rates[2].idx = rates[3].idx = 0;
  692. rates[0].count = ATH_TXMAXTRY;
  693. }
  694. /* Setup RTS/CTS */
  695. ath_rc_rate_set_rtscts(sc, rate_table, tx_info);
  696. }
  697. static bool ath_rc_update_per(struct ath_softc *sc,
  698. const struct ath_rate_table *rate_table,
  699. struct ath_rate_priv *ath_rc_priv,
  700. struct ieee80211_tx_info *tx_info,
  701. int tx_rate, int xretries, int retries,
  702. u32 now_msec)
  703. {
  704. bool state_change = false;
  705. int count, n_bad_frames;
  706. u8 last_per;
  707. static u32 nretry_to_per_lookup[10] = {
  708. 100 * 0 / 1,
  709. 100 * 1 / 4,
  710. 100 * 1 / 2,
  711. 100 * 3 / 4,
  712. 100 * 4 / 5,
  713. 100 * 5 / 6,
  714. 100 * 6 / 7,
  715. 100 * 7 / 8,
  716. 100 * 8 / 9,
  717. 100 * 9 / 10
  718. };
  719. last_per = ath_rc_priv->per[tx_rate];
  720. n_bad_frames = tx_info->status.ampdu_len - tx_info->status.ampdu_ack_len;
  721. if (xretries) {
  722. if (xretries == 1) {
  723. ath_rc_priv->per[tx_rate] += 30;
  724. if (ath_rc_priv->per[tx_rate] > 100)
  725. ath_rc_priv->per[tx_rate] = 100;
  726. } else {
  727. /* xretries == 2 */
  728. count = ARRAY_SIZE(nretry_to_per_lookup);
  729. if (retries >= count)
  730. retries = count - 1;
  731. /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
  732. ath_rc_priv->per[tx_rate] =
  733. (u8)(last_per - (last_per >> 3) + (100 >> 3));
  734. }
  735. /* xretries == 1 or 2 */
  736. if (ath_rc_priv->probe_rate == tx_rate)
  737. ath_rc_priv->probe_rate = 0;
  738. } else { /* xretries == 0 */
  739. count = ARRAY_SIZE(nretry_to_per_lookup);
  740. if (retries >= count)
  741. retries = count - 1;
  742. if (n_bad_frames) {
  743. /* new_PER = 7/8*old_PER + 1/8*(currentPER)
  744. * Assuming that n_frames is not 0. The current PER
  745. * from the retries is 100 * retries / (retries+1),
  746. * since the first retries attempts failed, and the
  747. * next one worked. For the one that worked,
  748. * n_bad_frames subframes out of n_frames wored,
  749. * so the PER for that part is
  750. * 100 * n_bad_frames / n_frames, and it contributes
  751. * 100 * n_bad_frames / (n_frames * (retries+1)) to
  752. * the above PER. The expression below is a
  753. * simplified version of the sum of these two terms.
  754. */
  755. if (tx_info->status.ampdu_len > 0) {
  756. int n_frames, n_bad_tries;
  757. u8 cur_per, new_per;
  758. n_bad_tries = retries * tx_info->status.ampdu_len +
  759. n_bad_frames;
  760. n_frames = tx_info->status.ampdu_len * (retries + 1);
  761. cur_per = (100 * n_bad_tries / n_frames) >> 3;
  762. new_per = (u8)(last_per - (last_per >> 3) + cur_per);
  763. ath_rc_priv->per[tx_rate] = new_per;
  764. }
  765. } else {
  766. ath_rc_priv->per[tx_rate] =
  767. (u8)(last_per - (last_per >> 3) +
  768. (nretry_to_per_lookup[retries] >> 3));
  769. }
  770. /*
  771. * If we got at most one retry then increase the max rate if
  772. * this was a probe. Otherwise, ignore the probe.
  773. */
  774. if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
  775. if (retries > 0 || 2 * n_bad_frames > tx_info->status.ampdu_len) {
  776. /*
  777. * Since we probed with just a single attempt,
  778. * any retries means the probe failed. Also,
  779. * if the attempt worked, but more than half
  780. * the subframes were bad then also consider
  781. * the probe a failure.
  782. */
  783. ath_rc_priv->probe_rate = 0;
  784. } else {
  785. u8 probe_rate = 0;
  786. ath_rc_priv->rate_max_phy =
  787. ath_rc_priv->probe_rate;
  788. probe_rate = ath_rc_priv->probe_rate;
  789. if (ath_rc_priv->per[probe_rate] > 30)
  790. ath_rc_priv->per[probe_rate] = 20;
  791. ath_rc_priv->probe_rate = 0;
  792. /*
  793. * Since this probe succeeded, we allow the next
  794. * probe twice as soon. This allows the maxRate
  795. * to move up faster if the probes are
  796. * successful.
  797. */
  798. ath_rc_priv->probe_time =
  799. now_msec - rate_table->probe_interval / 2;
  800. }
  801. }
  802. if (retries > 0) {
  803. /*
  804. * Don't update anything. We don't know if
  805. * this was because of collisions or poor signal.
  806. */
  807. ath_rc_priv->hw_maxretry_pktcnt = 0;
  808. } else {
  809. /*
  810. * It worked with no retries. First ignore bogus (small)
  811. * rssi_ack values.
  812. */
  813. if (tx_rate == ath_rc_priv->rate_max_phy &&
  814. ath_rc_priv->hw_maxretry_pktcnt < 255) {
  815. ath_rc_priv->hw_maxretry_pktcnt++;
  816. }
  817. }
  818. }
  819. return state_change;
  820. }
  821. /* Update PER, RSSI and whatever else that the code thinks it is doing.
  822. If you can make sense of all this, you really need to go out more. */
  823. static void ath_rc_update_ht(struct ath_softc *sc,
  824. struct ath_rate_priv *ath_rc_priv,
  825. struct ieee80211_tx_info *tx_info,
  826. int tx_rate, int xretries, int retries)
  827. {
  828. u32 now_msec = jiffies_to_msecs(jiffies);
  829. int rate;
  830. u8 last_per;
  831. bool state_change = false;
  832. const struct ath_rate_table *rate_table = sc->cur_rate_table;
  833. int size = ath_rc_priv->rate_table_size;
  834. if ((tx_rate < 0) || (tx_rate > rate_table->rate_cnt))
  835. return;
  836. last_per = ath_rc_priv->per[tx_rate];
  837. /* Update PER first */
  838. state_change = ath_rc_update_per(sc, rate_table, ath_rc_priv,
  839. tx_info, tx_rate, xretries,
  840. retries, now_msec);
  841. /*
  842. * If this rate looks bad (high PER) then stop using it for
  843. * a while (except if we are probing).
  844. */
  845. if (ath_rc_priv->per[tx_rate] >= 55 && tx_rate > 0 &&
  846. rate_table->info[tx_rate].ratekbps <=
  847. rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
  848. ath_rc_get_lower_rix(rate_table, ath_rc_priv,
  849. (u8)tx_rate, &ath_rc_priv->rate_max_phy);
  850. /* Don't probe for a little while. */
  851. ath_rc_priv->probe_time = now_msec;
  852. }
  853. /* Make sure the rates below this have lower PER */
  854. /* Monotonicity is kept only for rates below the current rate. */
  855. if (ath_rc_priv->per[tx_rate] < last_per) {
  856. for (rate = tx_rate - 1; rate >= 0; rate--) {
  857. if (ath_rc_priv->per[rate] >
  858. ath_rc_priv->per[rate+1]) {
  859. ath_rc_priv->per[rate] =
  860. ath_rc_priv->per[rate+1];
  861. }
  862. }
  863. }
  864. /* Maintain monotonicity for rates above the current rate */
  865. for (rate = tx_rate; rate < size - 1; rate++) {
  866. if (ath_rc_priv->per[rate+1] <
  867. ath_rc_priv->per[rate])
  868. ath_rc_priv->per[rate+1] =
  869. ath_rc_priv->per[rate];
  870. }
  871. /* Every so often, we reduce the thresholds
  872. * and PER (different for CCK and OFDM). */
  873. if (now_msec - ath_rc_priv->per_down_time >=
  874. rate_table->probe_interval) {
  875. for (rate = 0; rate < size; rate++) {
  876. ath_rc_priv->per[rate] =
  877. 7 * ath_rc_priv->per[rate] / 8;
  878. }
  879. ath_rc_priv->per_down_time = now_msec;
  880. }
  881. ath_debug_stat_retries(sc, tx_rate, xretries, retries,
  882. ath_rc_priv->per[tx_rate]);
  883. }
  884. static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
  885. struct ieee80211_tx_rate *rate)
  886. {
  887. int rix;
  888. if (!(rate->flags & IEEE80211_TX_RC_MCS))
  889. return rate->idx;
  890. rix = rate->idx + rate_table->mcs_start;
  891. if ((rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  892. (rate->flags & IEEE80211_TX_RC_SHORT_GI))
  893. rix = rate_table->info[rix].ht_index;
  894. else if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  895. rix = rate_table->info[rix].sgi_index;
  896. else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  897. rix = rate_table->info[rix].cw40index;
  898. else
  899. rix = rate_table->info[rix].base_index;
  900. return rix;
  901. }
  902. static void ath_rc_tx_status(struct ath_softc *sc,
  903. struct ath_rate_priv *ath_rc_priv,
  904. struct ieee80211_tx_info *tx_info,
  905. int final_ts_idx, int xretries, int long_retry)
  906. {
  907. const struct ath_rate_table *rate_table;
  908. struct ieee80211_tx_rate *rates = tx_info->status.rates;
  909. u8 flags;
  910. u32 i = 0, rix;
  911. rate_table = sc->cur_rate_table;
  912. /*
  913. * If the first rate is not the final index, there
  914. * are intermediate rate failures to be processed.
  915. */
  916. if (final_ts_idx != 0) {
  917. /* Process intermediate rates that failed.*/
  918. for (i = 0; i < final_ts_idx ; i++) {
  919. if (rates[i].count != 0 && (rates[i].idx >= 0)) {
  920. flags = rates[i].flags;
  921. /* If HT40 and we have switched mode from
  922. * 40 to 20 => don't update */
  923. if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  924. !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
  925. return;
  926. rix = ath_rc_get_rateindex(rate_table, &rates[i]);
  927. ath_rc_update_ht(sc, ath_rc_priv, tx_info,
  928. rix, xretries ? 1 : 2,
  929. rates[i].count);
  930. }
  931. }
  932. } else {
  933. /*
  934. * Handle the special case of MIMO PS burst, where the second
  935. * aggregate is sent out with only one rate and one try.
  936. * Treating it as an excessive retry penalizes the rate
  937. * inordinately.
  938. */
  939. if (rates[0].count == 1 && xretries == 1)
  940. xretries = 2;
  941. }
  942. flags = rates[i].flags;
  943. /* If HT40 and we have switched mode from 40 to 20 => don't update */
  944. if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  945. !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
  946. return;
  947. rix = ath_rc_get_rateindex(rate_table, &rates[i]);
  948. ath_rc_update_ht(sc, ath_rc_priv, tx_info, rix, xretries, long_retry);
  949. }
  950. static const
  951. struct ath_rate_table *ath_choose_rate_table(struct ath_softc *sc,
  952. enum ieee80211_band band,
  953. bool is_ht,
  954. bool is_cw_40)
  955. {
  956. int mode = 0;
  957. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  958. switch(band) {
  959. case IEEE80211_BAND_2GHZ:
  960. mode = ATH9K_MODE_11G;
  961. if (is_ht)
  962. mode = ATH9K_MODE_11NG_HT20;
  963. if (is_cw_40)
  964. mode = ATH9K_MODE_11NG_HT40PLUS;
  965. break;
  966. case IEEE80211_BAND_5GHZ:
  967. mode = ATH9K_MODE_11A;
  968. if (is_ht)
  969. mode = ATH9K_MODE_11NA_HT20;
  970. if (is_cw_40)
  971. mode = ATH9K_MODE_11NA_HT40PLUS;
  972. break;
  973. default:
  974. ath_print(common, ATH_DBG_CONFIG, "Invalid band\n");
  975. return NULL;
  976. }
  977. BUG_ON(mode >= ATH9K_MODE_MAX);
  978. ath_print(common, ATH_DBG_CONFIG,
  979. "Choosing rate table for mode: %d\n", mode);
  980. sc->cur_rate_mode = mode;
  981. return hw_rate_table[mode];
  982. }
  983. static void ath_rc_init(struct ath_softc *sc,
  984. struct ath_rate_priv *ath_rc_priv,
  985. struct ieee80211_supported_band *sband,
  986. struct ieee80211_sta *sta,
  987. const struct ath_rate_table *rate_table)
  988. {
  989. struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
  990. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  991. u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
  992. u8 i, j, k, hi = 0, hthi = 0;
  993. /* Initial rate table size. Will change depending
  994. * on the working rate set */
  995. ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
  996. /* Initialize thresholds according to the global rate table */
  997. for (i = 0 ; i < ath_rc_priv->rate_table_size; i++) {
  998. ath_rc_priv->per[i] = 0;
  999. }
  1000. /* Determine the valid rates */
  1001. ath_rc_init_valid_txmask(ath_rc_priv);
  1002. for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
  1003. for (j = 0; j < MAX_TX_RATE_PHY; j++)
  1004. ath_rc_priv->valid_phy_rateidx[i][j] = 0;
  1005. ath_rc_priv->valid_phy_ratecnt[i] = 0;
  1006. }
  1007. if (!rateset->rs_nrates) {
  1008. /* No working rate, just initialize valid rates */
  1009. hi = ath_rc_init_validrates(ath_rc_priv, rate_table,
  1010. ath_rc_priv->ht_cap);
  1011. } else {
  1012. /* Use intersection of working rates and valid rates */
  1013. hi = ath_rc_setvalid_rates(ath_rc_priv, rate_table,
  1014. rateset, ath_rc_priv->ht_cap);
  1015. if (ath_rc_priv->ht_cap & WLAN_RC_HT_FLAG) {
  1016. hthi = ath_rc_setvalid_htrates(ath_rc_priv,
  1017. rate_table,
  1018. ht_mcs,
  1019. ath_rc_priv->ht_cap);
  1020. }
  1021. hi = A_MAX(hi, hthi);
  1022. }
  1023. ath_rc_priv->rate_table_size = hi + 1;
  1024. ath_rc_priv->rate_max_phy = 0;
  1025. BUG_ON(ath_rc_priv->rate_table_size > RATE_TABLE_SIZE);
  1026. for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
  1027. for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
  1028. ath_rc_priv->valid_rate_index[k++] =
  1029. ath_rc_priv->valid_phy_rateidx[i][j];
  1030. }
  1031. if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, 1)
  1032. || !ath_rc_priv->valid_phy_ratecnt[i])
  1033. continue;
  1034. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
  1035. }
  1036. BUG_ON(ath_rc_priv->rate_table_size > RATE_TABLE_SIZE);
  1037. BUG_ON(k > RATE_TABLE_SIZE);
  1038. ath_rc_priv->max_valid_rate = k;
  1039. ath_rc_sort_validrates(rate_table, ath_rc_priv);
  1040. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
  1041. sc->cur_rate_table = rate_table;
  1042. ath_print(common, ATH_DBG_CONFIG,
  1043. "RC Initialized with capabilities: 0x%x\n",
  1044. ath_rc_priv->ht_cap);
  1045. }
  1046. static u8 ath_rc_build_ht_caps(struct ath_softc *sc, struct ieee80211_sta *sta,
  1047. bool is_cw40, bool is_sgi40)
  1048. {
  1049. u8 caps = 0;
  1050. if (sta->ht_cap.ht_supported) {
  1051. caps = WLAN_RC_HT_FLAG;
  1052. if (sc->sc_ah->caps.tx_chainmask != 1 &&
  1053. ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_DS, 0, NULL)) {
  1054. if (sta->ht_cap.mcs.rx_mask[1])
  1055. caps |= WLAN_RC_DS_FLAG;
  1056. }
  1057. if (is_cw40)
  1058. caps |= WLAN_RC_40_FLAG;
  1059. if (is_sgi40)
  1060. caps |= WLAN_RC_SGI_FLAG;
  1061. }
  1062. return caps;
  1063. }
  1064. /***********************************/
  1065. /* mac80211 Rate Control callbacks */
  1066. /***********************************/
  1067. static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
  1068. struct ieee80211_sta *sta, void *priv_sta,
  1069. struct sk_buff *skb)
  1070. {
  1071. struct ath_softc *sc = priv;
  1072. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1073. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1074. struct ieee80211_hdr *hdr;
  1075. int final_ts_idx = 0, tx_status = 0, is_underrun = 0;
  1076. int long_retry = 0;
  1077. __le16 fc;
  1078. int i;
  1079. hdr = (struct ieee80211_hdr *)skb->data;
  1080. fc = hdr->frame_control;
  1081. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  1082. struct ieee80211_tx_rate *rate = &tx_info->status.rates[i];
  1083. if (!rate->count)
  1084. break;
  1085. final_ts_idx = i;
  1086. long_retry = rate->count - 1;
  1087. }
  1088. if (!priv_sta || !ieee80211_is_data(fc))
  1089. return;
  1090. /* This packet was aggregated but doesn't carry status info */
  1091. if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
  1092. !(tx_info->flags & IEEE80211_TX_STAT_AMPDU))
  1093. return;
  1094. if (tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED)
  1095. return;
  1096. /*
  1097. * If an underrun error is seen assume it as an excessive retry only
  1098. * if max frame trigger level has been reached (2 KB for singel stream,
  1099. * and 4 KB for dual stream). Adjust the long retry as if the frame was
  1100. * tried hw->max_rate_tries times to affect how ratectrl updates PER for
  1101. * the failed rate. In case of congestion on the bus penalizing these
  1102. * type of underruns should help hardware actually transmit new frames
  1103. * successfully by eventually preferring slower rates. This itself
  1104. * should also alleviate congestion on the bus.
  1105. */
  1106. if ((tx_info->pad[0] & ATH_TX_INFO_UNDERRUN) &&
  1107. (sc->sc_ah->tx_trig_level >= ath_rc_priv->tx_triglevel_max)) {
  1108. tx_status = 1;
  1109. is_underrun = 1;
  1110. }
  1111. if (tx_info->pad[0] & ATH_TX_INFO_XRETRY)
  1112. tx_status = 1;
  1113. ath_rc_tx_status(sc, ath_rc_priv, tx_info, final_ts_idx, tx_status,
  1114. (is_underrun) ? sc->hw->max_rate_tries : long_retry);
  1115. /* Check if aggregation has to be enabled for this tid */
  1116. if (conf_is_ht(&sc->hw->conf) &&
  1117. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  1118. if (ieee80211_is_data_qos(fc)) {
  1119. u8 *qc, tid;
  1120. struct ath_node *an;
  1121. qc = ieee80211_get_qos_ctl(hdr);
  1122. tid = qc[0] & 0xf;
  1123. an = (struct ath_node *)sta->drv_priv;
  1124. if(ath_tx_aggr_check(sc, an, tid))
  1125. ieee80211_start_tx_ba_session(sta, tid);
  1126. }
  1127. }
  1128. ath_debug_stat_rc(sc, ath_rc_get_rateindex(sc->cur_rate_table,
  1129. &tx_info->status.rates[final_ts_idx]));
  1130. }
  1131. static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
  1132. struct ieee80211_sta *sta, void *priv_sta)
  1133. {
  1134. struct ath_softc *sc = priv;
  1135. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1136. const struct ath_rate_table *rate_table;
  1137. bool is_cw40, is_sgi40;
  1138. int i, j = 0;
  1139. for (i = 0; i < sband->n_bitrates; i++) {
  1140. if (sta->supp_rates[sband->band] & BIT(i)) {
  1141. ath_rc_priv->neg_rates.rs_rates[j]
  1142. = (sband->bitrates[i].bitrate * 2) / 10;
  1143. j++;
  1144. }
  1145. }
  1146. ath_rc_priv->neg_rates.rs_nrates = j;
  1147. if (sta->ht_cap.ht_supported) {
  1148. for (i = 0, j = 0; i < 77; i++) {
  1149. if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
  1150. ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
  1151. if (j == ATH_RATE_MAX)
  1152. break;
  1153. }
  1154. ath_rc_priv->neg_ht_rates.rs_nrates = j;
  1155. }
  1156. is_cw40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1157. is_sgi40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  1158. /* Choose rate table first */
  1159. if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) ||
  1160. (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT) ||
  1161. (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)) {
  1162. rate_table = ath_choose_rate_table(sc, sband->band,
  1163. sta->ht_cap.ht_supported, is_cw40);
  1164. } else {
  1165. rate_table = hw_rate_table[sc->cur_rate_mode];
  1166. }
  1167. ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta, is_cw40, is_sgi40);
  1168. ath_rc_init(sc, priv_sta, sband, sta, rate_table);
  1169. }
  1170. static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
  1171. struct ieee80211_sta *sta, void *priv_sta,
  1172. u32 changed, enum nl80211_channel_type oper_chan_type)
  1173. {
  1174. struct ath_softc *sc = priv;
  1175. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1176. const struct ath_rate_table *rate_table = NULL;
  1177. bool oper_cw40 = false, oper_sgi40;
  1178. bool local_cw40 = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG) ?
  1179. true : false;
  1180. bool local_sgi40 = (ath_rc_priv->ht_cap & WLAN_RC_SGI_FLAG) ?
  1181. true : false;
  1182. /* FIXME: Handle AP mode later when we support CWM */
  1183. if (changed & IEEE80211_RC_HT_CHANGED) {
  1184. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1185. return;
  1186. if (oper_chan_type == NL80211_CHAN_HT40MINUS ||
  1187. oper_chan_type == NL80211_CHAN_HT40PLUS)
  1188. oper_cw40 = true;
  1189. oper_sgi40 = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1190. true : false;
  1191. if ((local_cw40 != oper_cw40) || (local_sgi40 != oper_sgi40)) {
  1192. rate_table = ath_choose_rate_table(sc, sband->band,
  1193. sta->ht_cap.ht_supported,
  1194. oper_cw40);
  1195. ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta,
  1196. oper_cw40, oper_sgi40);
  1197. ath_rc_init(sc, priv_sta, sband, sta, rate_table);
  1198. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
  1199. "Operating HT Bandwidth changed to: %d\n",
  1200. sc->hw->conf.channel_type);
  1201. sc->cur_rate_table = hw_rate_table[sc->cur_rate_mode];
  1202. }
  1203. }
  1204. }
  1205. static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  1206. {
  1207. struct ath_wiphy *aphy = hw->priv;
  1208. return aphy->sc;
  1209. }
  1210. static void ath_rate_free(void *priv)
  1211. {
  1212. return;
  1213. }
  1214. static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
  1215. {
  1216. struct ath_softc *sc = priv;
  1217. struct ath_rate_priv *rate_priv;
  1218. rate_priv = kzalloc(sizeof(struct ath_rate_priv), gfp);
  1219. if (!rate_priv) {
  1220. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  1221. "Unable to allocate private rc structure\n");
  1222. return NULL;
  1223. }
  1224. rate_priv->tx_triglevel_max = sc->sc_ah->caps.tx_triglevel_max;
  1225. return rate_priv;
  1226. }
  1227. static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
  1228. void *priv_sta)
  1229. {
  1230. struct ath_rate_priv *rate_priv = priv_sta;
  1231. kfree(rate_priv);
  1232. }
  1233. static struct rate_control_ops ath_rate_ops = {
  1234. .module = NULL,
  1235. .name = "ath9k_rate_control",
  1236. .tx_status = ath_tx_status,
  1237. .get_rate = ath_get_rate,
  1238. .rate_init = ath_rate_init,
  1239. .rate_update = ath_rate_update,
  1240. .alloc = ath_rate_alloc,
  1241. .free = ath_rate_free,
  1242. .alloc_sta = ath_rate_alloc_sta,
  1243. .free_sta = ath_rate_free_sta,
  1244. };
  1245. int ath_rate_control_register(void)
  1246. {
  1247. return ieee80211_rate_control_register(&ath_rate_ops);
  1248. }
  1249. void ath_rate_control_unregister(void)
  1250. {
  1251. ieee80211_rate_control_unregister(&ath_rate_ops);
  1252. }