rc.c 47 KB

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