rc.c 45 KB

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