rc.c 44 KB

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