rc.c 44 KB

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