rc.c 45 KB

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