rc.c 43 KB

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