rc.c 44 KB

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