rc.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039
  1. /*
  2. * Copyright (c) 2004 Video54 Technologies, Inc.
  3. * Copyright (c) 2004-2008 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. /*
  18. * Atheros rate control algorithm
  19. */
  20. #include "core.h"
  21. /* FIXME: remove this include! */
  22. #include "../net/mac80211/rate.h"
  23. static u32 tx_triglevel_max;
  24. static struct ath_rate_table ar5416_11na_ratetable = {
  25. 42,
  26. {
  27. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  28. 5400, 0x0b, 0x00, 12,
  29. 0, 2, 1, 0, 0, 0, 0, 0 },
  30. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  31. 7800, 0x0f, 0x00, 18,
  32. 0, 3, 1, 1, 1, 1, 1, 0 },
  33. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  34. 10000, 0x0a, 0x00, 24,
  35. 2, 4, 2, 2, 2, 2, 2, 0 },
  36. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  37. 13900, 0x0e, 0x00, 36,
  38. 2, 6, 2, 3, 3, 3, 3, 0 },
  39. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  40. 17300, 0x09, 0x00, 48,
  41. 4, 10, 3, 4, 4, 4, 4, 0 },
  42. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  43. 23000, 0x0d, 0x00, 72,
  44. 4, 14, 3, 5, 5, 5, 5, 0 },
  45. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  46. 27400, 0x08, 0x00, 96,
  47. 4, 20, 3, 6, 6, 6, 6, 0 },
  48. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  49. 29300, 0x0c, 0x00, 108,
  50. 4, 23, 3, 7, 7, 7, 7, 0 },
  51. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  52. 6400, 0x80, 0x00, 0,
  53. 0, 2, 3, 8, 24, 8, 24, 3216 },
  54. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */
  55. 12700, 0x81, 0x00, 1,
  56. 2, 4, 3, 9, 25, 9, 25, 6434 },
  57. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  58. 18800, 0x82, 0x00, 2,
  59. 2, 6, 3, 10, 26, 10, 26, 9650 },
  60. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */
  61. 25000, 0x83, 0x00, 3,
  62. 4, 10, 3, 11, 27, 11, 27, 12868 },
  63. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */
  64. 36700, 0x84, 0x00, 4,
  65. 4, 14, 3, 12, 28, 12, 28, 19304 },
  66. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */
  67. 48100, 0x85, 0x00, 5,
  68. 4, 20, 3, 13, 29, 13, 29, 25740 },
  69. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  70. 53500, 0x86, 0x00, 6,
  71. 4, 23, 3, 14, 30, 14, 30, 28956 },
  72. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */
  73. 59000, 0x87, 0x00, 7,
  74. 4, 25, 3, 15, 31, 15, 32, 32180 },
  75. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */
  76. 12700, 0x88, 0x00,
  77. 8, 0, 2, 3, 16, 33, 16, 33, 6430 },
  78. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */
  79. 24800, 0x89, 0x00, 9,
  80. 2, 4, 3, 17, 34, 17, 34, 12860 },
  81. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */
  82. 36600, 0x8a, 0x00, 10,
  83. 2, 6, 3, 18, 35, 18, 35, 19300 },
  84. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */
  85. 48100, 0x8b, 0x00, 11,
  86. 4, 10, 3, 19, 36, 19, 36, 25736 },
  87. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */
  88. 69500, 0x8c, 0x00, 12,
  89. 4, 14, 3, 20, 37, 20, 37, 38600 },
  90. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */
  91. 89500, 0x8d, 0x00, 13,
  92. 4, 20, 3, 21, 38, 21, 38, 51472 },
  93. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */
  94. 98900, 0x8e, 0x00, 14,
  95. 4, 23, 3, 22, 39, 22, 39, 57890 },
  96. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */
  97. 108300, 0x8f, 0x00, 15,
  98. 4, 25, 3, 23, 40, 23, 41, 64320 },
  99. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  100. 13200, 0x80, 0x00, 0,
  101. 0, 2, 3, 8, 24, 24, 24, 6684 },
  102. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  103. 25900, 0x81, 0x00, 1,
  104. 2, 4, 3, 9, 25, 25, 25, 13368 },
  105. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  106. 38600, 0x82, 0x00, 2,
  107. 2, 6, 3, 10, 26, 26, 26, 20052 },
  108. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */
  109. 49800, 0x83, 0x00, 3,
  110. 4, 10, 3, 11, 27, 27, 27, 26738 },
  111. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */
  112. 72200, 0x84, 0x00, 4,
  113. 4, 14, 3, 12, 28, 28, 28, 40104 },
  114. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */
  115. 92900, 0x85, 0x00, 5,
  116. 4, 20, 3, 13, 29, 29, 29, 53476 },
  117. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  118. 102700, 0x86, 0x00, 6,
  119. 4, 23, 3, 14, 30, 30, 30, 60156 },
  120. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */
  121. 112000, 0x87, 0x00, 7,
  122. 4, 25, 3, 15, 31, 32, 32, 66840 },
  123. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  124. 122000, 0x87, 0x00, 7,
  125. 4, 25, 3, 15, 31, 32, 32, 74200 },
  126. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */
  127. 25800, 0x88, 0x00, 8,
  128. 0, 2, 3, 16, 33, 33, 33, 13360 },
  129. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */
  130. 49800, 0x89, 0x00, 9,
  131. 2, 4, 3, 17, 34, 34, 34, 26720 },
  132. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */
  133. 71900, 0x8a, 0x00, 10,
  134. 2, 6, 3, 18, 35, 35, 35, 40080 },
  135. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */
  136. 92500, 0x8b, 0x00, 11,
  137. 4, 10, 3, 19, 36, 36, 36, 53440 },
  138. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */
  139. 130300, 0x8c, 0x00, 12,
  140. 4, 14, 3, 20, 37, 37, 37, 80160 },
  141. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */
  142. 162800, 0x8d, 0x00, 13,
  143. 4, 20, 3, 21, 38, 38, 38, 106880 },
  144. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */
  145. 178200, 0x8e, 0x00, 14,
  146. 4, 23, 3, 22, 39, 39, 39, 120240 },
  147. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */
  148. 192100, 0x8f, 0x00, 15,
  149. 4, 25, 3, 23, 40, 41, 41, 133600 },
  150. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  151. 207000, 0x8f, 0x00, 15,
  152. 4, 25, 3, 23, 40, 41, 41, 148400 },
  153. },
  154. 50, /* probe interval */
  155. 50, /* rssi reduce interval */
  156. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  157. };
  158. /* TRUE_ALL - valid for 20/40/Legacy,
  159. * TRUE - Legacy only,
  160. * TRUE_20 - HT 20 only,
  161. * TRUE_40 - HT 40 only */
  162. /* 4ms frame limit not used for NG mode. The values filled
  163. * for HT are the 64K max aggregate limit */
  164. static struct ath_rate_table ar5416_11ng_ratetable = {
  165. 46,
  166. {
  167. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 1000, /* 1 Mb */
  168. 900, 0x1b, 0x00, 2,
  169. 0, 0, 1, 0, 0, 0, 0, 0 },
  170. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 2000, /* 2 Mb */
  171. 1900, 0x1a, 0x04, 4,
  172. 1, 1, 1, 1, 1, 1, 1, 0 },
  173. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
  174. 4900, 0x19, 0x04, 11,
  175. 2, 2, 2, 2, 2, 2, 2, 0 },
  176. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 11000, /* 11 Mb */
  177. 8100, 0x18, 0x04, 22,
  178. 3, 3, 2, 3, 3, 3, 3, 0 },
  179. { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  180. 5400, 0x0b, 0x00, 12,
  181. 4, 2, 1, 4, 4, 4, 4, 0 },
  182. { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  183. 7800, 0x0f, 0x00, 18,
  184. 4, 3, 1, 5, 5, 5, 5, 0 },
  185. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  186. 10100, 0x0a, 0x00, 24,
  187. 6, 4, 1, 6, 6, 6, 6, 0 },
  188. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  189. 14100, 0x0e, 0x00, 36,
  190. 6, 6, 2, 7, 7, 7, 7, 0 },
  191. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  192. 17700, 0x09, 0x00, 48,
  193. 8, 10, 3, 8, 8, 8, 8, 0 },
  194. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  195. 23700, 0x0d, 0x00, 72,
  196. 8, 14, 3, 9, 9, 9, 9, 0 },
  197. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  198. 27400, 0x08, 0x00, 96,
  199. 8, 20, 3, 10, 10, 10, 10, 0 },
  200. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  201. 30900, 0x0c, 0x00, 108,
  202. 8, 23, 3, 11, 11, 11, 11, 0 },
  203. { FALSE, FALSE, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  204. 6400, 0x80, 0x00, 0,
  205. 4, 2, 3, 12, 28, 12, 28, 3216 },
  206. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */
  207. 12700, 0x81, 0x00, 1,
  208. 6, 4, 3, 13, 29, 13, 29, 6434 },
  209. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  210. 18800, 0x82, 0x00, 2,
  211. 6, 6, 3, 14, 30, 14, 30, 9650 },
  212. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */
  213. 25000, 0x83, 0x00, 3,
  214. 8, 10, 3, 15, 31, 15, 31, 12868 },
  215. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */
  216. 36700, 0x84, 0x00, 4,
  217. 8, 14, 3, 16, 32, 16, 32, 19304 },
  218. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */
  219. 48100, 0x85, 0x00, 5,
  220. 8, 20, 3, 17, 33, 17, 33, 25740 },
  221. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  222. 53500, 0x86, 0x00, 6,
  223. 8, 23, 3, 18, 34, 18, 34, 28956 },
  224. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */
  225. 59000, 0x87, 0x00, 7,
  226. 8, 25, 3, 19, 35, 19, 36, 32180 },
  227. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */
  228. 12700, 0x88, 0x00, 8,
  229. 4, 2, 3, 20, 37, 20, 37, 6430 },
  230. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */
  231. 24800, 0x89, 0x00, 9,
  232. 6, 4, 3, 21, 38, 21, 38, 12860 },
  233. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */
  234. 36600, 0x8a, 0x00, 10,
  235. 6, 6, 3, 22, 39, 22, 39, 19300 },
  236. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */
  237. 48100, 0x8b, 0x00, 11,
  238. 8, 10, 3, 23, 40, 23, 40, 25736 },
  239. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */
  240. 69500, 0x8c, 0x00, 12,
  241. 8, 14, 3, 24, 41, 24, 41, 38600 },
  242. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */
  243. 89500, 0x8d, 0x00, 13,
  244. 8, 20, 3, 25, 42, 25, 42, 51472 },
  245. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */
  246. 98900, 0x8e, 0x00, 14,
  247. 8, 23, 3, 26, 43, 26, 44, 57890 },
  248. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */
  249. 108300, 0x8f, 0x00, 15,
  250. 8, 25, 3, 27, 44, 27, 45, 64320 },
  251. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  252. 13200, 0x80, 0x00, 0,
  253. 8, 2, 3, 12, 28, 28, 28, 6684 },
  254. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  255. 25900, 0x81, 0x00, 1,
  256. 8, 4, 3, 13, 29, 29, 29, 13368 },
  257. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  258. 38600, 0x82, 0x00, 2,
  259. 8, 6, 3, 14, 30, 30, 30, 20052 },
  260. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */
  261. 49800, 0x83, 0x00, 3,
  262. 8, 10, 3, 15, 31, 31, 31, 26738 },
  263. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */
  264. 72200, 0x84, 0x00, 4,
  265. 8, 14, 3, 16, 32, 32, 32, 40104 },
  266. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */
  267. 92900, 0x85, 0x00, 5,
  268. 8, 20, 3, 17, 33, 33, 33, 53476 },
  269. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  270. 102700, 0x86, 0x00, 6,
  271. 8, 23, 3, 18, 34, 34, 34, 60156 },
  272. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */
  273. 112000, 0x87, 0x00, 7,
  274. 8, 23, 3, 19, 35, 36, 36, 66840 },
  275. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  276. 122000, 0x87, 0x00, 7,
  277. 8, 25, 3, 19, 35, 36, 36, 74200 },
  278. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */
  279. 25800, 0x88, 0x00, 8,
  280. 8, 2, 3, 20, 37, 37, 37, 13360 },
  281. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */
  282. 49800, 0x89, 0x00, 9,
  283. 8, 4, 3, 21, 38, 38, 38, 26720 },
  284. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */
  285. 71900, 0x8a, 0x00, 10,
  286. 8, 6, 3, 22, 39, 39, 39, 40080 },
  287. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */
  288. 92500, 0x8b, 0x00, 11,
  289. 8, 10, 3, 23, 40, 40, 40, 53440 },
  290. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */
  291. 130300, 0x8c, 0x00, 12,
  292. 8, 14, 3, 24, 41, 41, 41, 80160 },
  293. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */
  294. 162800, 0x8d, 0x00, 13,
  295. 8, 20, 3, 25, 42, 42, 42, 106880 },
  296. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */
  297. 178200, 0x8e, 0x00, 14,
  298. 8, 23, 3, 26, 43, 43, 43, 120240 },
  299. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */
  300. 192100, 0x8f, 0x00, 15,
  301. 8, 23, 3, 27, 44, 45, 45, 133600 },
  302. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  303. 207000, 0x8f, 0x00, 15,
  304. 8, 25, 3, 27, 44, 45, 45, 148400 },
  305. },
  306. 50, /* probe interval */
  307. 50, /* rssi reduce interval */
  308. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  309. };
  310. static struct ath_rate_table ar5416_11a_ratetable = {
  311. 8,
  312. {
  313. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  314. 5400, 0x0b, 0x00, (0x80|12),
  315. 0, 2, 1, 0, 0 },
  316. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  317. 7800, 0x0f, 0x00, 18,
  318. 0, 3, 1, 1, 0 },
  319. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  320. 10000, 0x0a, 0x00, (0x80|24),
  321. 2, 4, 2, 2, 0 },
  322. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  323. 13900, 0x0e, 0x00, 36,
  324. 2, 6, 2, 3, 0 },
  325. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  326. 17300, 0x09, 0x00, (0x80|48),
  327. 4, 10, 3, 4, 0 },
  328. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  329. 23000, 0x0d, 0x00, 72,
  330. 4, 14, 3, 5, 0 },
  331. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  332. 27400, 0x08, 0x00, 96,
  333. 4, 19, 3, 6, 0 },
  334. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  335. 29300, 0x0c, 0x00, 108,
  336. 4, 23, 3, 7, 0 },
  337. },
  338. 50, /* probe interval */
  339. 50, /* rssi reduce interval */
  340. 0, /* Phy rates allowed initially */
  341. };
  342. static struct ath_rate_table ar5416_11a_ratetable_Half = {
  343. 8,
  344. {
  345. { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 6 Mb */
  346. 2700, 0x0b, 0x00, (0x80|6),
  347. 0, 2, 1, 0, 0},
  348. { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 9 Mb */
  349. 3900, 0x0f, 0x00, 9,
  350. 0, 3, 1, 1, 0 },
  351. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 12 Mb */
  352. 5000, 0x0a, 0x00, (0x80|12),
  353. 2, 4, 2, 2, 0 },
  354. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 18 Mb */
  355. 6950, 0x0e, 0x00, 18,
  356. 2, 6, 2, 3, 0 },
  357. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 24 Mb */
  358. 8650, 0x09, 0x00, (0x80|24),
  359. 4, 10, 3, 4, 0 },
  360. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 36 Mb */
  361. 11500, 0x0d, 0x00, 36,
  362. 4, 14, 3, 5, 0 },
  363. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 48 Mb */
  364. 13700, 0x08, 0x00, 48,
  365. 4, 19, 3, 6, 0 },
  366. { TRUE, TRUE, WLAN_PHY_OFDM, 27000, /* 54 Mb */
  367. 14650, 0x0c, 0x00, 54,
  368. 4, 23, 3, 7, 0 },
  369. },
  370. 50, /* probe interval */
  371. 50, /* rssi reduce interval */
  372. 0, /* Phy rates allowed initially */
  373. };
  374. static struct ath_rate_table ar5416_11a_ratetable_Quarter = {
  375. 8,
  376. {
  377. { TRUE, TRUE, WLAN_PHY_OFDM, 1500, /* 6 Mb */
  378. 1350, 0x0b, 0x00, (0x80|3),
  379. 0, 2, 1, 0, 0 },
  380. { TRUE, TRUE, WLAN_PHY_OFDM, 2250, /* 9 Mb */
  381. 1950, 0x0f, 0x00, 4,
  382. 0, 3, 1, 1, 0 },
  383. { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 12 Mb */
  384. 2500, 0x0a, 0x00, (0x80|6),
  385. 2, 4, 2, 2, 0 },
  386. { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 18 Mb */
  387. 3475, 0x0e, 0x00, 9,
  388. 2, 6, 2, 3, 0 },
  389. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 25 Mb */
  390. 4325, 0x09, 0x00, (0x80|12),
  391. 4, 10, 3, 4, 0 },
  392. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 36 Mb */
  393. 5750, 0x0d, 0x00, 18,
  394. 4, 14, 3, 5, 0 },
  395. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 48 Mb */
  396. 6850, 0x08, 0x00, 24,
  397. 4, 19, 3, 6, 0 },
  398. { TRUE, TRUE, WLAN_PHY_OFDM, 13500, /* 54 Mb */
  399. 7325, 0x0c, 0x00, 27,
  400. 4, 23, 3, 7, 0 },
  401. },
  402. 50, /* probe interval */
  403. 50, /* rssi reduce interval */
  404. 0, /* Phy rates allowed initially */
  405. };
  406. static struct ath_rate_table ar5416_11g_ratetable = {
  407. 12,
  408. {
  409. { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */
  410. 900, 0x1b, 0x00, 2,
  411. 0, 0, 1, 0, 0 },
  412. { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */
  413. 1900, 0x1a, 0x04, 4,
  414. 1, 1, 1, 1, 0 },
  415. { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
  416. 4900, 0x19, 0x04, 11,
  417. 2, 2, 2, 2, 0 },
  418. { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */
  419. 8100, 0x18, 0x04, 22,
  420. 3, 3, 2, 3, 0 },
  421. { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  422. 5400, 0x0b, 0x00, 12,
  423. 4, 2, 1, 4, 0 },
  424. { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  425. 7800, 0x0f, 0x00, 18,
  426. 4, 3, 1, 5, 0 },
  427. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  428. 10000, 0x0a, 0x00, 24,
  429. 6, 4, 1, 6, 0 },
  430. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  431. 13900, 0x0e, 0x00, 36,
  432. 6, 6, 2, 7, 0 },
  433. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  434. 17300, 0x09, 0x00, 48,
  435. 8, 10, 3, 8, 0 },
  436. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  437. 23000, 0x0d, 0x00, 72,
  438. 8, 14, 3, 9, 0 },
  439. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  440. 27400, 0x08, 0x00, 96,
  441. 8, 19, 3, 10, 0 },
  442. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  443. 29300, 0x0c, 0x00, 108,
  444. 8, 23, 3, 11, 0 },
  445. },
  446. 50, /* probe interval */
  447. 50, /* rssi reduce interval */
  448. 0, /* Phy rates allowed initially */
  449. };
  450. static struct ath_rate_table ar5416_11b_ratetable = {
  451. 4,
  452. {
  453. { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */
  454. 900, 0x1b, 0x00, (0x80|2),
  455. 0, 0, 1, 0, 0 },
  456. { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */
  457. 1800, 0x1a, 0x04, (0x80|4),
  458. 1, 1, 1, 1, 0 },
  459. { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
  460. 4300, 0x19, 0x04, (0x80|11),
  461. 1, 2, 2, 2, 0 },
  462. { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */
  463. 7100, 0x18, 0x04, (0x80|22),
  464. 1, 4, 100, 3, 0 },
  465. },
  466. 100, /* probe interval */
  467. 100, /* rssi reduce interval */
  468. 0, /* Phy rates allowed initially */
  469. };
  470. static void ar5416_attach_ratetables(struct ath_rate_softc *sc)
  471. {
  472. /*
  473. * Attach rate tables.
  474. */
  475. sc->hw_rate_table[ATH9K_MODE_11B] = &ar5416_11b_ratetable;
  476. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable;
  477. sc->hw_rate_table[ATH9K_MODE_11G] = &ar5416_11g_ratetable;
  478. sc->hw_rate_table[ATH9K_MODE_11NA_HT20] = &ar5416_11na_ratetable;
  479. sc->hw_rate_table[ATH9K_MODE_11NG_HT20] = &ar5416_11ng_ratetable;
  480. sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
  481. &ar5416_11na_ratetable;
  482. sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
  483. &ar5416_11na_ratetable;
  484. sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
  485. &ar5416_11ng_ratetable;
  486. sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
  487. &ar5416_11ng_ratetable;
  488. }
  489. static void ar5416_setquarter_ratetable(struct ath_rate_softc *sc)
  490. {
  491. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Quarter;
  492. return;
  493. }
  494. static void ar5416_sethalf_ratetable(struct ath_rate_softc *sc)
  495. {
  496. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Half;
  497. return;
  498. }
  499. static void ar5416_setfull_ratetable(struct ath_rate_softc *sc)
  500. {
  501. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable;
  502. return;
  503. }
  504. /*
  505. * Return the median of three numbers
  506. */
  507. static inline int8_t median(int8_t a, int8_t b, int8_t c)
  508. {
  509. if (a >= b) {
  510. if (b >= c)
  511. return b;
  512. else if (a > c)
  513. return c;
  514. else
  515. return a;
  516. } else {
  517. if (a >= c)
  518. return a;
  519. else if (b >= c)
  520. return c;
  521. else
  522. return b;
  523. }
  524. }
  525. static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table,
  526. struct ath_tx_ratectrl *rate_ctrl)
  527. {
  528. u8 i, j, idx, idx_next;
  529. for (i = rate_ctrl->max_valid_rate - 1; i > 0; i--) {
  530. for (j = 0; j <= i-1; j++) {
  531. idx = rate_ctrl->valid_rate_index[j];
  532. idx_next = rate_ctrl->valid_rate_index[j+1];
  533. if (rate_table->info[idx].ratekbps >
  534. rate_table->info[idx_next].ratekbps) {
  535. rate_ctrl->valid_rate_index[j] = idx_next;
  536. rate_ctrl->valid_rate_index[j+1] = idx;
  537. }
  538. }
  539. }
  540. }
  541. /* Access functions for valid_txrate_mask */
  542. static void ath_rc_init_valid_txmask(struct ath_tx_ratectrl *rate_ctrl)
  543. {
  544. u8 i;
  545. for (i = 0; i < rate_ctrl->rate_table_size; i++)
  546. rate_ctrl->valid_rate_index[i] = FALSE;
  547. }
  548. static inline void ath_rc_set_valid_txmask(struct ath_tx_ratectrl *rate_ctrl,
  549. u8 index, int valid_tx_rate)
  550. {
  551. ASSERT(index <= rate_ctrl->rate_table_size);
  552. rate_ctrl->valid_rate_index[index] = valid_tx_rate ? TRUE : FALSE;
  553. }
  554. static inline int ath_rc_isvalid_txmask(struct ath_tx_ratectrl *rate_ctrl,
  555. u8 index)
  556. {
  557. ASSERT(index <= rate_ctrl->rate_table_size);
  558. return rate_ctrl->valid_rate_index[index];
  559. }
  560. /* Iterators for valid_txrate_mask */
  561. static inline int
  562. ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
  563. struct ath_tx_ratectrl *rate_ctrl,
  564. u8 cur_valid_txrate,
  565. u8 *next_idx)
  566. {
  567. u8 i;
  568. for (i = 0; i < rate_ctrl->max_valid_rate - 1; i++) {
  569. if (rate_ctrl->valid_rate_index[i] == cur_valid_txrate) {
  570. *next_idx = rate_ctrl->valid_rate_index[i+1];
  571. return TRUE;
  572. }
  573. }
  574. /* No more valid rates */
  575. *next_idx = 0;
  576. return FALSE;
  577. }
  578. /* Return true only for single stream */
  579. static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
  580. {
  581. if (WLAN_RC_PHY_HT(phy) & !(capflag & WLAN_RC_HT_FLAG))
  582. return FALSE;
  583. if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
  584. return FALSE;
  585. if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
  586. return FALSE;
  587. if (!ignore_cw && WLAN_RC_PHY_HT(phy))
  588. if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
  589. return FALSE;
  590. if (!WLAN_RC_PHY_40(phy) && (capflag & WLAN_RC_40_FLAG))
  591. return FALSE;
  592. return TRUE;
  593. }
  594. static inline int
  595. ath_rc_get_nextlowervalid_txrate(const struct ath_rate_table *rate_table,
  596. struct ath_tx_ratectrl *rate_ctrl,
  597. u8 cur_valid_txrate, u8 *next_idx)
  598. {
  599. int8_t i;
  600. for (i = 1; i < rate_ctrl->max_valid_rate ; i++) {
  601. if (rate_ctrl->valid_rate_index[i] == cur_valid_txrate) {
  602. *next_idx = rate_ctrl->valid_rate_index[i-1];
  603. return TRUE;
  604. }
  605. }
  606. return FALSE;
  607. }
  608. /*
  609. * Initialize the Valid Rate Index from valid entries in Rate Table
  610. */
  611. static u8
  612. ath_rc_sib_init_validrates(struct ath_rate_node *ath_rc_priv,
  613. const struct ath_rate_table *rate_table,
  614. u32 capflag)
  615. {
  616. struct ath_tx_ratectrl *rate_ctrl;
  617. u8 i, hi = 0;
  618. u32 valid;
  619. rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
  620. for (i = 0; i < rate_table->rate_cnt; i++) {
  621. valid = (ath_rc_priv->single_stream ?
  622. rate_table->info[i].valid_single_stream :
  623. rate_table->info[i].valid);
  624. if (valid == TRUE) {
  625. u32 phy = rate_table->info[i].phy;
  626. u8 valid_rate_count = 0;
  627. if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
  628. continue;
  629. valid_rate_count = rate_ctrl->valid_phy_ratecnt[phy];
  630. rate_ctrl->valid_phy_rateidx[phy][valid_rate_count] = i;
  631. rate_ctrl->valid_phy_ratecnt[phy] += 1;
  632. ath_rc_set_valid_txmask(rate_ctrl, i, TRUE);
  633. hi = A_MAX(hi, i);
  634. }
  635. }
  636. return hi;
  637. }
  638. /*
  639. * Initialize the Valid Rate Index from Rate Set
  640. */
  641. static u8
  642. ath_rc_sib_setvalid_rates(struct ath_rate_node *ath_rc_priv,
  643. const struct ath_rate_table *rate_table,
  644. struct ath_rateset *rateset,
  645. u32 capflag)
  646. {
  647. /* XXX: Clean me up and make identation friendly */
  648. u8 i, j, hi = 0;
  649. struct ath_tx_ratectrl *rate_ctrl =
  650. (struct ath_tx_ratectrl *)(ath_rc_priv);
  651. /* Use intersection of working rates and valid rates */
  652. for (i = 0; i < rateset->rs_nrates; i++) {
  653. for (j = 0; j < rate_table->rate_cnt; j++) {
  654. u32 phy = rate_table->info[j].phy;
  655. u32 valid = (ath_rc_priv->single_stream ?
  656. rate_table->info[j].valid_single_stream :
  657. rate_table->info[j].valid);
  658. /* We allow a rate only if its valid and the
  659. * capflag matches one of the validity
  660. * (TRUE/TRUE_20/TRUE_40) flags */
  661. /* XXX: catch the negative of this branch
  662. * first and then continue */
  663. if (((rateset->rs_rates[i] & 0x7F) ==
  664. (rate_table->info[j].dot11rate & 0x7F)) &&
  665. ((valid & WLAN_RC_CAP_MODE(capflag)) ==
  666. WLAN_RC_CAP_MODE(capflag)) &&
  667. !WLAN_RC_PHY_HT(phy)) {
  668. u8 valid_rate_count = 0;
  669. if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
  670. continue;
  671. valid_rate_count =
  672. rate_ctrl->valid_phy_ratecnt[phy];
  673. rate_ctrl->valid_phy_rateidx[phy]
  674. [valid_rate_count] = j;
  675. rate_ctrl->valid_phy_ratecnt[phy] += 1;
  676. ath_rc_set_valid_txmask(rate_ctrl, j, TRUE);
  677. hi = A_MAX(hi, j);
  678. }
  679. }
  680. }
  681. return hi;
  682. }
  683. static u8
  684. ath_rc_sib_setvalid_htrates(struct ath_rate_node *ath_rc_priv,
  685. const struct ath_rate_table *rate_table,
  686. u8 *mcs_set, u32 capflag)
  687. {
  688. u8 i, j, hi = 0;
  689. struct ath_tx_ratectrl *rate_ctrl =
  690. (struct ath_tx_ratectrl *)(ath_rc_priv);
  691. /* Use intersection of working rates and valid rates */
  692. for (i = 0; i < ((struct ath_rateset *)mcs_set)->rs_nrates; i++) {
  693. for (j = 0; j < rate_table->rate_cnt; j++) {
  694. u32 phy = rate_table->info[j].phy;
  695. u32 valid = (ath_rc_priv->single_stream ?
  696. rate_table->info[j].valid_single_stream :
  697. rate_table->info[j].valid);
  698. if (((((struct ath_rateset *)
  699. mcs_set)->rs_rates[i] & 0x7F) !=
  700. (rate_table->info[j].dot11rate & 0x7F)) ||
  701. !WLAN_RC_PHY_HT(phy) ||
  702. !WLAN_RC_PHY_HT_VALID(valid, capflag))
  703. continue;
  704. if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
  705. continue;
  706. rate_ctrl->valid_phy_rateidx[phy]
  707. [rate_ctrl->valid_phy_ratecnt[phy]] = j;
  708. rate_ctrl->valid_phy_ratecnt[phy] += 1;
  709. ath_rc_set_valid_txmask(rate_ctrl, j, TRUE);
  710. hi = A_MAX(hi, j);
  711. }
  712. }
  713. return hi;
  714. }
  715. /*
  716. * Attach to a device instance. Setup the public definition
  717. * of how much per-node space we need and setup the private
  718. * phy tables that have rate control parameters.
  719. */
  720. struct ath_rate_softc *ath_rate_attach(struct ath_hal *ah)
  721. {
  722. struct ath_rate_softc *asc;
  723. /* we are only in user context so we can sleep for memory */
  724. asc = kzalloc(sizeof(struct ath_rate_softc), GFP_KERNEL);
  725. if (asc == NULL)
  726. return NULL;
  727. ar5416_attach_ratetables(asc);
  728. /* Save Maximum TX Trigger Level (used for 11n) */
  729. tx_triglevel_max = ah->ah_caps.tx_triglevel_max;
  730. /* return alias for ath_rate_softc * */
  731. return asc;
  732. }
  733. static struct ath_rate_node *ath_rate_node_alloc(struct ath_vap *avp,
  734. struct ath_rate_softc *rsc,
  735. gfp_t gfp)
  736. {
  737. struct ath_rate_node *anode;
  738. anode = kzalloc(sizeof(struct ath_rate_node), gfp);
  739. if (anode == NULL)
  740. return NULL;
  741. anode->avp = avp;
  742. anode->asc = rsc;
  743. avp->rc_node = anode;
  744. return anode;
  745. }
  746. static void ath_rate_node_free(struct ath_rate_node *anode)
  747. {
  748. if (anode != NULL)
  749. kfree(anode);
  750. }
  751. void ath_rate_detach(struct ath_rate_softc *asc)
  752. {
  753. if (asc != NULL)
  754. kfree(asc);
  755. }
  756. u8 ath_rate_findrateix(struct ath_softc *sc,
  757. u8 dot11rate)
  758. {
  759. const struct ath_rate_table *ratetable;
  760. struct ath_rate_softc *rsc = sc->sc_rc;
  761. int i;
  762. ratetable = rsc->hw_rate_table[sc->sc_curmode];
  763. if (WARN_ON(!ratetable))
  764. return 0;
  765. for (i = 0; i < ratetable->rate_cnt; i++) {
  766. if ((ratetable->info[i].dot11rate & 0x7f) == (dot11rate & 0x7f))
  767. return i;
  768. }
  769. return 0;
  770. }
  771. /*
  772. * Update rate-control state on a device state change. When
  773. * operating as a station this includes associate/reassociate
  774. * with an AP. Otherwise this gets called, for example, when
  775. * the we transition to run state when operating as an AP.
  776. */
  777. void ath_rate_newstate(struct ath_softc *sc, struct ath_vap *avp)
  778. {
  779. struct ath_rate_softc *asc = sc->sc_rc;
  780. /* For half and quarter rate channles use different
  781. * rate tables
  782. */
  783. if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_HALF)
  784. ar5416_sethalf_ratetable(asc);
  785. else if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_QUARTER)
  786. ar5416_setquarter_ratetable(asc);
  787. else /* full rate */
  788. ar5416_setfull_ratetable(asc);
  789. if (avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) {
  790. asc->fixedrix =
  791. sc->sc_rixmap[avp->av_config.av_fixed_rateset & 0xff];
  792. /* NB: check the fixed rate exists */
  793. if (asc->fixedrix == 0xff)
  794. asc->fixedrix = IEEE80211_FIXED_RATE_NONE;
  795. } else {
  796. asc->fixedrix = IEEE80211_FIXED_RATE_NONE;
  797. }
  798. }
  799. static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
  800. struct ath_rate_node *ath_rc_priv,
  801. const struct ath_rate_table *rate_table,
  802. int probe_allowed, int *is_probing,
  803. int is_retry)
  804. {
  805. u32 dt, best_thruput, this_thruput, now_msec;
  806. u8 rate, next_rate, best_rate, maxindex, minindex;
  807. int8_t rssi_last, rssi_reduce = 0, index = 0;
  808. struct ath_tx_ratectrl *rate_ctrl = NULL;
  809. rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv ?
  810. (ath_rc_priv) : NULL);
  811. *is_probing = FALSE;
  812. rssi_last = median(rate_ctrl->rssi_last,
  813. rate_ctrl->rssi_last_prev,
  814. rate_ctrl->rssi_last_prev2);
  815. /*
  816. * Age (reduce) last ack rssi based on how old it is.
  817. * The bizarre numbers are so the delta is 160msec,
  818. * meaning we divide by 16.
  819. * 0msec <= dt <= 25msec: don't derate
  820. * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB
  821. * 185msec <= dt: derate by 10dB
  822. */
  823. now_msec = jiffies_to_msecs(jiffies);
  824. dt = now_msec - rate_ctrl->rssi_time;
  825. if (dt >= 185)
  826. rssi_reduce = 10;
  827. else if (dt >= 25)
  828. rssi_reduce = (u8)((dt - 25) >> 4);
  829. /* Now reduce rssi_last by rssi_reduce */
  830. if (rssi_last < rssi_reduce)
  831. rssi_last = 0;
  832. else
  833. rssi_last -= rssi_reduce;
  834. /*
  835. * Now look up the rate in the rssi table and return it.
  836. * If no rates match then we return 0 (lowest rate)
  837. */
  838. best_thruput = 0;
  839. maxindex = rate_ctrl->max_valid_rate-1;
  840. minindex = 0;
  841. best_rate = minindex;
  842. /*
  843. * Try the higher rate first. It will reduce memory moving time
  844. * if we have very good channel characteristics.
  845. */
  846. for (index = maxindex; index >= minindex ; index--) {
  847. u8 per_thres;
  848. rate = rate_ctrl->valid_rate_index[index];
  849. if (rate > rate_ctrl->rate_max_phy)
  850. continue;
  851. /*
  852. * For TCP the average collision rate is around 11%,
  853. * so we ignore PERs less than this. This is to
  854. * prevent the rate we are currently using (whose
  855. * PER might be in the 10-15 range because of TCP
  856. * collisions) looking worse than the next lower
  857. * rate whose PER has decayed close to 0. If we
  858. * used to next lower rate, its PER would grow to
  859. * 10-15 and we would be worse off then staying
  860. * at the current rate.
  861. */
  862. per_thres = rate_ctrl->state[rate].per;
  863. if (per_thres < 12)
  864. per_thres = 12;
  865. this_thruput = rate_table->info[rate].user_ratekbps *
  866. (100 - per_thres);
  867. if (best_thruput <= this_thruput) {
  868. best_thruput = this_thruput;
  869. best_rate = rate;
  870. }
  871. }
  872. rate = best_rate;
  873. /* if we are retrying for more than half the number
  874. * of max retries, use the min rate for the next retry
  875. */
  876. if (is_retry)
  877. rate = rate_ctrl->valid_rate_index[minindex];
  878. rate_ctrl->rssi_last_lookup = rssi_last;
  879. /*
  880. * Must check the actual rate (ratekbps) to account for
  881. * non-monoticity of 11g's rate table
  882. */
  883. if (rate >= rate_ctrl->rate_max_phy && probe_allowed) {
  884. rate = rate_ctrl->rate_max_phy;
  885. /* Probe the next allowed phy state */
  886. /* FIXME:XXXX Check to make sure ratMax is checked properly */
  887. if (ath_rc_get_nextvalid_txrate(rate_table,
  888. rate_ctrl, rate, &next_rate) &&
  889. (now_msec - rate_ctrl->probe_time >
  890. rate_table->probe_interval) &&
  891. (rate_ctrl->hw_maxretry_pktcnt >= 1)) {
  892. rate = next_rate;
  893. rate_ctrl->probe_rate = rate;
  894. rate_ctrl->probe_time = now_msec;
  895. rate_ctrl->hw_maxretry_pktcnt = 0;
  896. *is_probing = TRUE;
  897. }
  898. }
  899. /*
  900. * Make sure rate is not higher than the allowed maximum.
  901. * We should also enforce the min, but I suspect the min is
  902. * normally 1 rather than 0 because of the rate 9 vs 6 issue
  903. * in the old code.
  904. */
  905. if (rate > (rate_ctrl->rate_table_size - 1))
  906. rate = rate_ctrl->rate_table_size - 1;
  907. ASSERT((rate_table->info[rate].valid && !ath_rc_priv->single_stream) ||
  908. (rate_table->info[rate].valid_single_stream &&
  909. ath_rc_priv->single_stream));
  910. return rate;
  911. }
  912. static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table ,
  913. struct ath_rc_series *series,
  914. u8 tries,
  915. u8 rix,
  916. int rtsctsenable)
  917. {
  918. series->tries = tries;
  919. series->flags = (rtsctsenable ? ATH_RC_RTSCTS_FLAG : 0) |
  920. (WLAN_RC_PHY_DS(rate_table->info[rix].phy) ?
  921. ATH_RC_DS_FLAG : 0) |
  922. (WLAN_RC_PHY_40(rate_table->info[rix].phy) ?
  923. ATH_RC_CW40_FLAG : 0) |
  924. (WLAN_RC_PHY_SGI(rate_table->info[rix].phy) ?
  925. ATH_RC_SGI_FLAG : 0);
  926. series->rix = rate_table->info[rix].base_index;
  927. series->max_4ms_framelen = rate_table->info[rix].max_4ms_framelen;
  928. }
  929. static u8 ath_rc_rate_getidx(struct ath_softc *sc,
  930. struct ath_rate_node *ath_rc_priv,
  931. const struct ath_rate_table *rate_table,
  932. u8 rix, u16 stepdown,
  933. u16 min_rate)
  934. {
  935. u32 j;
  936. u8 nextindex;
  937. struct ath_tx_ratectrl *rate_ctrl =
  938. (struct ath_tx_ratectrl *)(ath_rc_priv);
  939. if (min_rate) {
  940. for (j = RATE_TABLE_SIZE; j > 0; j--) {
  941. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  942. rate_ctrl, rix, &nextindex))
  943. rix = nextindex;
  944. else
  945. break;
  946. }
  947. } else {
  948. for (j = stepdown; j > 0; j--) {
  949. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  950. rate_ctrl, rix, &nextindex))
  951. rix = nextindex;
  952. else
  953. break;
  954. }
  955. }
  956. return rix;
  957. }
  958. static void ath_rc_ratefind(struct ath_softc *sc,
  959. struct ath_rate_node *ath_rc_priv,
  960. int num_tries, int num_rates, unsigned int rcflag,
  961. struct ath_rc_series series[], int *is_probe,
  962. int is_retry)
  963. {
  964. u8 try_per_rate = 0, i = 0, rix, nrix;
  965. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  966. struct ath_rate_table *rate_table;
  967. rate_table =
  968. (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode];
  969. rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table,
  970. (rcflag & ATH_RC_PROBE_ALLOWED) ? 1 : 0,
  971. is_probe, is_retry);
  972. nrix = rix;
  973. if ((rcflag & ATH_RC_PROBE_ALLOWED) && (*is_probe)) {
  974. /* set one try for probe rates. For the
  975. * probes don't enable rts */
  976. ath_rc_rate_set_series(rate_table,
  977. &series[i++], 1, nrix, FALSE);
  978. try_per_rate = (num_tries/num_rates);
  979. /* Get the next tried/allowed rate. No RTS for the next series
  980. * after the probe rate
  981. */
  982. nrix = ath_rc_rate_getidx(sc,
  983. ath_rc_priv, rate_table, nrix, 1, FALSE);
  984. ath_rc_rate_set_series(rate_table,
  985. &series[i++], try_per_rate, nrix, 0);
  986. } else {
  987. try_per_rate = (num_tries/num_rates);
  988. /* Set the choosen rate. No RTS for first series entry. */
  989. ath_rc_rate_set_series(rate_table,
  990. &series[i++], try_per_rate, nrix, FALSE);
  991. }
  992. /* Fill in the other rates for multirate retry */
  993. for ( ; i < num_rates; i++) {
  994. u8 try_num;
  995. u8 min_rate;
  996. try_num = ((i + 1) == num_rates) ?
  997. num_tries - (try_per_rate * i) : try_per_rate ;
  998. min_rate = (((i + 1) == num_rates) &&
  999. (rcflag & ATH_RC_MINRATE_LASTRATE)) ? 1 : 0;
  1000. nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
  1001. rate_table, nrix, 1, min_rate);
  1002. /* All other rates in the series have RTS enabled */
  1003. ath_rc_rate_set_series(rate_table,
  1004. &series[i], try_num, nrix, TRUE);
  1005. }
  1006. /*
  1007. * NB:Change rate series to enable aggregation when operating
  1008. * at lower MCS rates. When first rate in series is MCS2
  1009. * in HT40 @ 2.4GHz, series should look like:
  1010. *
  1011. * {MCS2, MCS1, MCS0, MCS0}.
  1012. *
  1013. * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
  1014. * look like:
  1015. *
  1016. * {MCS3, MCS2, MCS1, MCS1}
  1017. *
  1018. * So, set fourth rate in series to be same as third one for
  1019. * above conditions.
  1020. */
  1021. if ((sc->sc_curmode == ATH9K_MODE_11NG_HT20) ||
  1022. (sc->sc_curmode == ATH9K_MODE_11NG_HT40PLUS) ||
  1023. (sc->sc_curmode == ATH9K_MODE_11NG_HT40MINUS)) {
  1024. u8 dot11rate = rate_table->info[rix].dot11rate;
  1025. u8 phy = rate_table->info[rix].phy;
  1026. if (i == 4 &&
  1027. ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
  1028. (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
  1029. series[3].rix = series[2].rix;
  1030. series[3].flags = series[2].flags;
  1031. series[3].max_4ms_framelen = series[2].max_4ms_framelen;
  1032. }
  1033. }
  1034. }
  1035. /*
  1036. * Return the Tx rate series.
  1037. */
  1038. static void ath_rate_findrate(struct ath_softc *sc,
  1039. struct ath_rate_node *ath_rc_priv,
  1040. int num_tries,
  1041. int num_rates,
  1042. unsigned int rcflag,
  1043. struct ath_rc_series series[],
  1044. int *is_probe,
  1045. int is_retry)
  1046. {
  1047. struct ath_vap *avp = ath_rc_priv->avp;
  1048. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1049. if (!num_rates || !num_tries)
  1050. return;
  1051. if (avp->av_config.av_fixed_rateset == IEEE80211_FIXED_RATE_NONE) {
  1052. ath_rc_ratefind(sc, ath_rc_priv, num_tries, num_rates,
  1053. rcflag, series, is_probe, is_retry);
  1054. } else {
  1055. /* Fixed rate */
  1056. int idx;
  1057. u8 flags;
  1058. u32 rix;
  1059. struct ath_rate_softc *asc = ath_rc_priv->asc;
  1060. struct ath_rate_table *rate_table;
  1061. rate_table = (struct ath_rate_table *)
  1062. asc->hw_rate_table[sc->sc_curmode];
  1063. for (idx = 0; idx < 4; idx++) {
  1064. unsigned int mcs;
  1065. u8 series_rix = 0;
  1066. series[idx].tries = IEEE80211_RATE_IDX_ENTRY(
  1067. avp->av_config.av_fixed_retryset, idx);
  1068. mcs = IEEE80211_RATE_IDX_ENTRY(
  1069. avp->av_config.av_fixed_rateset, idx);
  1070. if (idx == 3 && (mcs & 0xf0) == 0x70)
  1071. mcs = (mcs & ~0xf0)|0x80;
  1072. if (!(mcs & 0x80))
  1073. flags = 0;
  1074. else
  1075. flags = ((ath_rc_priv->ht_cap &
  1076. WLAN_RC_DS_FLAG) ?
  1077. ATH_RC_DS_FLAG : 0) |
  1078. ((ath_rc_priv->ht_cap &
  1079. WLAN_RC_40_FLAG) ?
  1080. ATH_RC_CW40_FLAG : 0) |
  1081. ((ath_rc_priv->ht_cap &
  1082. WLAN_RC_SGI_FLAG) ?
  1083. ((ath_rc_priv->ht_cap &
  1084. WLAN_RC_40_FLAG) ?
  1085. ATH_RC_SGI_FLAG : 0) : 0);
  1086. series[idx].rix = sc->sc_rixmap[mcs];
  1087. series_rix = series[idx].rix;
  1088. /* XXX: Give me some cleanup love */
  1089. if ((flags & ATH_RC_CW40_FLAG) &&
  1090. (flags & ATH_RC_SGI_FLAG))
  1091. rix = rate_table->info[series_rix].ht_index;
  1092. else if (flags & ATH_RC_SGI_FLAG)
  1093. rix = rate_table->info[series_rix].sgi_index;
  1094. else if (flags & ATH_RC_CW40_FLAG)
  1095. rix = rate_table->info[series_rix].cw40index;
  1096. else
  1097. rix = rate_table->info[series_rix].base_index;
  1098. series[idx].max_4ms_framelen =
  1099. rate_table->info[rix].max_4ms_framelen;
  1100. series[idx].flags = flags;
  1101. }
  1102. }
  1103. }
  1104. static void ath_rc_update_ht(struct ath_softc *sc,
  1105. struct ath_rate_node *ath_rc_priv,
  1106. struct ath_tx_info_priv *info_priv,
  1107. int tx_rate, int xretries, int retries)
  1108. {
  1109. struct ath_tx_ratectrl *rate_ctrl;
  1110. u32 now_msec = jiffies_to_msecs(jiffies);
  1111. int state_change = FALSE, rate, count;
  1112. u8 last_per;
  1113. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  1114. struct ath_rate_table *rate_table =
  1115. (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode];
  1116. static u32 nretry_to_per_lookup[10] = {
  1117. 100 * 0 / 1,
  1118. 100 * 1 / 4,
  1119. 100 * 1 / 2,
  1120. 100 * 3 / 4,
  1121. 100 * 4 / 5,
  1122. 100 * 5 / 6,
  1123. 100 * 6 / 7,
  1124. 100 * 7 / 8,
  1125. 100 * 8 / 9,
  1126. 100 * 9 / 10
  1127. };
  1128. if (!ath_rc_priv)
  1129. return;
  1130. rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
  1131. ASSERT(tx_rate >= 0);
  1132. if (tx_rate < 0)
  1133. return;
  1134. /* To compensate for some imbalance between ctrl and ext. channel */
  1135. if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy))
  1136. info_priv->tx.ts_rssi =
  1137. info_priv->tx.ts_rssi < 3 ? 0 :
  1138. info_priv->tx.ts_rssi - 3;
  1139. last_per = rate_ctrl->state[tx_rate].per;
  1140. if (xretries) {
  1141. /* Update the PER. */
  1142. if (xretries == 1) {
  1143. rate_ctrl->state[tx_rate].per += 30;
  1144. if (rate_ctrl->state[tx_rate].per > 100)
  1145. rate_ctrl->state[tx_rate].per = 100;
  1146. } else {
  1147. /* xretries == 2 */
  1148. count = ARRAY_SIZE(nretry_to_per_lookup);
  1149. if (retries >= count)
  1150. retries = count - 1;
  1151. /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
  1152. rate_ctrl->state[tx_rate].per =
  1153. (u8)(rate_ctrl->state[tx_rate].per -
  1154. (rate_ctrl->state[tx_rate].per >> 3) +
  1155. ((100) >> 3));
  1156. }
  1157. /* xretries == 1 or 2 */
  1158. if (rate_ctrl->probe_rate == tx_rate)
  1159. rate_ctrl->probe_rate = 0;
  1160. } else { /* xretries == 0 */
  1161. /* Update the PER. */
  1162. /* Make sure it doesn't index out of array's bounds. */
  1163. count = ARRAY_SIZE(nretry_to_per_lookup);
  1164. if (retries >= count)
  1165. retries = count - 1;
  1166. if (info_priv->n_bad_frames) {
  1167. /* new_PER = 7/8*old_PER + 1/8*(currentPER)
  1168. * Assuming that n_frames is not 0. The current PER
  1169. * from the retries is 100 * retries / (retries+1),
  1170. * since the first retries attempts failed, and the
  1171. * next one worked. For the one that worked,
  1172. * n_bad_frames subframes out of n_frames wored,
  1173. * so the PER for that part is
  1174. * 100 * n_bad_frames / n_frames, and it contributes
  1175. * 100 * n_bad_frames / (n_frames * (retries+1)) to
  1176. * the above PER. The expression below is a
  1177. * simplified version of the sum of these two terms.
  1178. */
  1179. if (info_priv->n_frames > 0)
  1180. rate_ctrl->state[tx_rate].per
  1181. = (u8)
  1182. (rate_ctrl->state[tx_rate].per -
  1183. (rate_ctrl->state[tx_rate].per >> 3) +
  1184. ((100*(retries*info_priv->n_frames +
  1185. info_priv->n_bad_frames) /
  1186. (info_priv->n_frames *
  1187. (retries+1))) >> 3));
  1188. } else {
  1189. /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
  1190. rate_ctrl->state[tx_rate].per = (u8)
  1191. (rate_ctrl->state[tx_rate].per -
  1192. (rate_ctrl->state[tx_rate].per >> 3) +
  1193. (nretry_to_per_lookup[retries] >> 3));
  1194. }
  1195. rate_ctrl->rssi_last_prev2 = rate_ctrl->rssi_last_prev;
  1196. rate_ctrl->rssi_last_prev = rate_ctrl->rssi_last;
  1197. rate_ctrl->rssi_last = info_priv->tx.ts_rssi;
  1198. rate_ctrl->rssi_time = now_msec;
  1199. /*
  1200. * If we got at most one retry then increase the max rate if
  1201. * this was a probe. Otherwise, ignore the probe.
  1202. */
  1203. if (rate_ctrl->probe_rate && rate_ctrl->probe_rate == tx_rate) {
  1204. if (retries > 0 || 2 * info_priv->n_bad_frames >
  1205. info_priv->n_frames) {
  1206. /*
  1207. * Since we probed with just a single attempt,
  1208. * any retries means the probe failed. Also,
  1209. * if the attempt worked, but more than half
  1210. * the subframes were bad then also consider
  1211. * the probe a failure.
  1212. */
  1213. rate_ctrl->probe_rate = 0;
  1214. } else {
  1215. u8 probe_rate = 0;
  1216. rate_ctrl->rate_max_phy = rate_ctrl->probe_rate;
  1217. probe_rate = rate_ctrl->probe_rate;
  1218. if (rate_ctrl->state[probe_rate].per > 30)
  1219. rate_ctrl->state[probe_rate].per = 20;
  1220. rate_ctrl->probe_rate = 0;
  1221. /*
  1222. * Since this probe succeeded, we allow the next
  1223. * probe twice as soon. This allows the maxRate
  1224. * to move up faster if the probes are
  1225. * succesful.
  1226. */
  1227. rate_ctrl->probe_time = now_msec -
  1228. rate_table->probe_interval / 2;
  1229. }
  1230. }
  1231. if (retries > 0) {
  1232. /*
  1233. * Don't update anything. We don't know if
  1234. * this was because of collisions or poor signal.
  1235. *
  1236. * Later: if rssi_ack is close to
  1237. * rate_ctrl->state[txRate].rssi_thres and we see lots
  1238. * of retries, then we could increase
  1239. * rate_ctrl->state[txRate].rssi_thres.
  1240. */
  1241. rate_ctrl->hw_maxretry_pktcnt = 0;
  1242. } else {
  1243. /*
  1244. * It worked with no retries. First ignore bogus (small)
  1245. * rssi_ack values.
  1246. */
  1247. if (tx_rate == rate_ctrl->rate_max_phy &&
  1248. rate_ctrl->hw_maxretry_pktcnt < 255) {
  1249. rate_ctrl->hw_maxretry_pktcnt++;
  1250. }
  1251. if (info_priv->tx.ts_rssi >=
  1252. rate_table->info[tx_rate].rssi_ack_validmin) {
  1253. /* Average the rssi */
  1254. if (tx_rate != rate_ctrl->rssi_sum_rate) {
  1255. rate_ctrl->rssi_sum_rate = tx_rate;
  1256. rate_ctrl->rssi_sum =
  1257. rate_ctrl->rssi_sum_cnt = 0;
  1258. }
  1259. rate_ctrl->rssi_sum += info_priv->tx.ts_rssi;
  1260. rate_ctrl->rssi_sum_cnt++;
  1261. if (rate_ctrl->rssi_sum_cnt > 4) {
  1262. int32_t rssi_ackAvg =
  1263. (rate_ctrl->rssi_sum + 2) / 4;
  1264. int8_t rssi_thres =
  1265. rate_ctrl->state[tx_rate].
  1266. rssi_thres;
  1267. int8_t rssi_ack_vmin =
  1268. rate_table->info[tx_rate].
  1269. rssi_ack_validmin;
  1270. rate_ctrl->rssi_sum =
  1271. rate_ctrl->rssi_sum_cnt = 0;
  1272. /* Now reduce the current
  1273. * rssi threshold. */
  1274. if ((rssi_ackAvg < rssi_thres + 2) &&
  1275. (rssi_thres > rssi_ack_vmin)) {
  1276. rate_ctrl->state[tx_rate].
  1277. rssi_thres--;
  1278. }
  1279. state_change = TRUE;
  1280. }
  1281. }
  1282. }
  1283. }
  1284. /* For all cases */
  1285. /*
  1286. * If this rate looks bad (high PER) then stop using it for
  1287. * a while (except if we are probing).
  1288. */
  1289. if (rate_ctrl->state[tx_rate].per >= 55 && tx_rate > 0 &&
  1290. rate_table->info[tx_rate].ratekbps <=
  1291. rate_table->info[rate_ctrl->rate_max_phy].ratekbps) {
  1292. ath_rc_get_nextlowervalid_txrate(rate_table, rate_ctrl,
  1293. (u8) tx_rate, &rate_ctrl->rate_max_phy);
  1294. /* Don't probe for a little while. */
  1295. rate_ctrl->probe_time = now_msec;
  1296. }
  1297. if (state_change) {
  1298. /*
  1299. * Make sure the rates above this have higher rssi thresholds.
  1300. * (Note: Monotonicity is kept within the OFDM rates and
  1301. * within the CCK rates. However, no adjustment is
  1302. * made to keep the rssi thresholds monotonically
  1303. * increasing between the CCK and OFDM rates.)
  1304. */
  1305. for (rate = tx_rate; rate <
  1306. rate_ctrl->rate_table_size - 1; rate++) {
  1307. if (rate_table->info[rate+1].phy !=
  1308. rate_table->info[tx_rate].phy)
  1309. break;
  1310. if (rate_ctrl->state[rate].rssi_thres +
  1311. rate_table->info[rate].rssi_ack_deltamin >
  1312. rate_ctrl->state[rate+1].rssi_thres) {
  1313. rate_ctrl->state[rate+1].rssi_thres =
  1314. rate_ctrl->state[rate].
  1315. rssi_thres +
  1316. rate_table->info[rate].
  1317. rssi_ack_deltamin;
  1318. }
  1319. }
  1320. /* Make sure the rates below this have lower rssi thresholds. */
  1321. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1322. if (rate_table->info[rate].phy !=
  1323. rate_table->info[tx_rate].phy)
  1324. break;
  1325. if (rate_ctrl->state[rate].rssi_thres +
  1326. rate_table->info[rate].rssi_ack_deltamin >
  1327. rate_ctrl->state[rate+1].rssi_thres) {
  1328. if (rate_ctrl->state[rate+1].rssi_thres <
  1329. rate_table->info[rate].
  1330. rssi_ack_deltamin)
  1331. rate_ctrl->state[rate].rssi_thres = 0;
  1332. else {
  1333. rate_ctrl->state[rate].rssi_thres =
  1334. rate_ctrl->state[rate+1].
  1335. rssi_thres -
  1336. rate_table->info[rate].
  1337. rssi_ack_deltamin;
  1338. }
  1339. if (rate_ctrl->state[rate].rssi_thres <
  1340. rate_table->info[rate].
  1341. rssi_ack_validmin) {
  1342. rate_ctrl->state[rate].rssi_thres =
  1343. rate_table->info[rate].
  1344. rssi_ack_validmin;
  1345. }
  1346. }
  1347. }
  1348. }
  1349. /* Make sure the rates below this have lower PER */
  1350. /* Monotonicity is kept only for rates below the current rate. */
  1351. if (rate_ctrl->state[tx_rate].per < last_per) {
  1352. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1353. if (rate_table->info[rate].phy !=
  1354. rate_table->info[tx_rate].phy)
  1355. break;
  1356. if (rate_ctrl->state[rate].per >
  1357. rate_ctrl->state[rate+1].per) {
  1358. rate_ctrl->state[rate].per =
  1359. rate_ctrl->state[rate+1].per;
  1360. }
  1361. }
  1362. }
  1363. /* Maintain monotonicity for rates above the current rate */
  1364. for (rate = tx_rate; rate < rate_ctrl->rate_table_size - 1; rate++) {
  1365. if (rate_ctrl->state[rate+1].per < rate_ctrl->state[rate].per)
  1366. rate_ctrl->state[rate+1].per =
  1367. rate_ctrl->state[rate].per;
  1368. }
  1369. /* Every so often, we reduce the thresholds and
  1370. * PER (different for CCK and OFDM). */
  1371. if (now_msec - rate_ctrl->rssi_down_time >=
  1372. rate_table->rssi_reduce_interval) {
  1373. for (rate = 0; rate < rate_ctrl->rate_table_size; rate++) {
  1374. if (rate_ctrl->state[rate].rssi_thres >
  1375. rate_table->info[rate].rssi_ack_validmin)
  1376. rate_ctrl->state[rate].rssi_thres -= 1;
  1377. }
  1378. rate_ctrl->rssi_down_time = now_msec;
  1379. }
  1380. /* Every so often, we reduce the thresholds
  1381. * and PER (different for CCK and OFDM). */
  1382. if (now_msec - rate_ctrl->per_down_time >=
  1383. rate_table->rssi_reduce_interval) {
  1384. for (rate = 0; rate < rate_ctrl->rate_table_size; rate++) {
  1385. rate_ctrl->state[rate].per =
  1386. 7 * rate_ctrl->state[rate].per / 8;
  1387. }
  1388. rate_ctrl->per_down_time = now_msec;
  1389. }
  1390. }
  1391. /*
  1392. * This routine is called in rate control callback tx_status() to give
  1393. * the status of previous frames.
  1394. */
  1395. static void ath_rc_update(struct ath_softc *sc,
  1396. struct ath_rate_node *ath_rc_priv,
  1397. struct ath_tx_info_priv *info_priv, int final_ts_idx,
  1398. int xretries, int long_retry)
  1399. {
  1400. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  1401. struct ath_rate_table *rate_table;
  1402. struct ath_tx_ratectrl *rate_ctrl;
  1403. struct ath_rc_series rcs[4];
  1404. u8 flags;
  1405. u32 series = 0, rix;
  1406. memcpy(rcs, info_priv->rcs, 4 * sizeof(rcs[0]));
  1407. rate_table = (struct ath_rate_table *)
  1408. asc->hw_rate_table[sc->sc_curmode];
  1409. rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
  1410. ASSERT(rcs[0].tries != 0);
  1411. /*
  1412. * If the first rate is not the final index, there
  1413. * are intermediate rate failures to be processed.
  1414. */
  1415. if (final_ts_idx != 0) {
  1416. /* Process intermediate rates that failed.*/
  1417. for (series = 0; series < final_ts_idx ; series++) {
  1418. if (rcs[series].tries != 0) {
  1419. flags = rcs[series].flags;
  1420. /* If HT40 and we have switched mode from
  1421. * 40 to 20 => don't update */
  1422. if ((flags & ATH_RC_CW40_FLAG) &&
  1423. (rate_ctrl->rc_phy_mode !=
  1424. (flags & ATH_RC_CW40_FLAG)))
  1425. return;
  1426. if ((flags & ATH_RC_CW40_FLAG) &&
  1427. (flags & ATH_RC_SGI_FLAG))
  1428. rix = rate_table->info[
  1429. rcs[series].rix].ht_index;
  1430. else if (flags & ATH_RC_SGI_FLAG)
  1431. rix = rate_table->info[
  1432. rcs[series].rix].sgi_index;
  1433. else if (flags & ATH_RC_CW40_FLAG)
  1434. rix = rate_table->info[
  1435. rcs[series].rix].cw40index;
  1436. else
  1437. rix = rate_table->info[
  1438. rcs[series].rix].base_index;
  1439. ath_rc_update_ht(sc, ath_rc_priv,
  1440. info_priv, rix,
  1441. xretries ? 1 : 2,
  1442. rcs[series].tries);
  1443. }
  1444. }
  1445. } else {
  1446. /*
  1447. * Handle the special case of MIMO PS burst, where the second
  1448. * aggregate is sent out with only one rate and one try.
  1449. * Treating it as an excessive retry penalizes the rate
  1450. * inordinately.
  1451. */
  1452. if (rcs[0].tries == 1 && xretries == 1)
  1453. xretries = 2;
  1454. }
  1455. flags = rcs[series].flags;
  1456. /* If HT40 and we have switched mode from 40 to 20 => don't update */
  1457. if ((flags & ATH_RC_CW40_FLAG) &&
  1458. (rate_ctrl->rc_phy_mode != (flags & ATH_RC_CW40_FLAG)))
  1459. return;
  1460. if ((flags & ATH_RC_CW40_FLAG) && (flags & ATH_RC_SGI_FLAG))
  1461. rix = rate_table->info[rcs[series].rix].ht_index;
  1462. else if (flags & ATH_RC_SGI_FLAG)
  1463. rix = rate_table->info[rcs[series].rix].sgi_index;
  1464. else if (flags & ATH_RC_CW40_FLAG)
  1465. rix = rate_table->info[rcs[series].rix].cw40index;
  1466. else
  1467. rix = rate_table->info[rcs[series].rix].base_index;
  1468. ath_rc_update_ht(sc, ath_rc_priv, info_priv, rix,
  1469. xretries, long_retry);
  1470. }
  1471. /*
  1472. * Process a tx descriptor for a completed transmit (success or failure).
  1473. */
  1474. static void ath_rate_tx_complete(struct ath_softc *sc,
  1475. struct ath_node *an,
  1476. struct ath_rate_node *rc_priv,
  1477. struct ath_tx_info_priv *info_priv)
  1478. {
  1479. int final_ts_idx = info_priv->tx.ts_rateindex;
  1480. int tx_status = 0, is_underrun = 0;
  1481. struct ath_vap *avp;
  1482. avp = rc_priv->avp;
  1483. if ((avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) ||
  1484. (info_priv->tx.ts_status & ATH9K_TXERR_FILT))
  1485. return;
  1486. if (info_priv->tx.ts_rssi > 0) {
  1487. ATH_RSSI_LPF(an->an_chainmask_sel.tx_avgrssi,
  1488. info_priv->tx.ts_rssi);
  1489. }
  1490. /*
  1491. * If underrun error is seen assume it as an excessive retry only
  1492. * if prefetch trigger level have reached the max (0x3f for 5416)
  1493. * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY
  1494. * times. This affects how ratectrl updates PER for the failed rate.
  1495. */
  1496. if (info_priv->tx.ts_flags &
  1497. (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
  1498. ((sc->sc_ah->ah_txTrigLevel) >= tx_triglevel_max)) {
  1499. tx_status = 1;
  1500. is_underrun = 1;
  1501. }
  1502. if ((info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
  1503. (info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
  1504. tx_status = 1;
  1505. ath_rc_update(sc, rc_priv, info_priv, final_ts_idx, tx_status,
  1506. (is_underrun) ? ATH_11N_TXMAXTRY :
  1507. info_priv->tx.ts_longretry);
  1508. }
  1509. /*
  1510. * Update the SIB's rate control information
  1511. *
  1512. * This should be called when the supported rates change
  1513. * (e.g. SME operation, wireless mode change)
  1514. *
  1515. * It will determine which rates are valid for use.
  1516. */
  1517. static void ath_rc_sib_update(struct ath_softc *sc,
  1518. struct ath_rate_node *ath_rc_priv,
  1519. u32 capflag, int keep_state,
  1520. struct ath_rateset *negotiated_rates,
  1521. struct ath_rateset *negotiated_htrates)
  1522. {
  1523. struct ath_rate_table *rate_table = NULL;
  1524. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  1525. struct ath_rateset *rateset = negotiated_rates;
  1526. u8 *ht_mcs = (u8 *)negotiated_htrates;
  1527. struct ath_tx_ratectrl *rate_ctrl =
  1528. (struct ath_tx_ratectrl *)ath_rc_priv;
  1529. u8 i, j, k, hi = 0, hthi = 0;
  1530. rate_table = (struct ath_rate_table *)
  1531. asc->hw_rate_table[sc->sc_curmode];
  1532. /* Initial rate table size. Will change depending
  1533. * on the working rate set */
  1534. rate_ctrl->rate_table_size = MAX_TX_RATE_TBL;
  1535. /* Initialize thresholds according to the global rate table */
  1536. for (i = 0 ; (i < rate_ctrl->rate_table_size) && (!keep_state); i++) {
  1537. rate_ctrl->state[i].rssi_thres =
  1538. rate_table->info[i].rssi_ack_validmin;
  1539. rate_ctrl->state[i].per = 0;
  1540. }
  1541. /* Determine the valid rates */
  1542. ath_rc_init_valid_txmask(rate_ctrl);
  1543. for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
  1544. for (j = 0; j < MAX_TX_RATE_PHY; j++)
  1545. rate_ctrl->valid_phy_rateidx[i][j] = 0;
  1546. rate_ctrl->valid_phy_ratecnt[i] = 0;
  1547. }
  1548. rate_ctrl->rc_phy_mode = (capflag & WLAN_RC_40_FLAG);
  1549. /* Set stream capability */
  1550. ath_rc_priv->single_stream = (capflag & WLAN_RC_DS_FLAG) ? 0 : 1;
  1551. if (!rateset->rs_nrates) {
  1552. /* No working rate, just initialize valid rates */
  1553. hi = ath_rc_sib_init_validrates(ath_rc_priv, rate_table,
  1554. capflag);
  1555. } else {
  1556. /* Use intersection of working rates and valid rates */
  1557. hi = ath_rc_sib_setvalid_rates(ath_rc_priv, rate_table,
  1558. rateset, capflag);
  1559. if (capflag & WLAN_RC_HT_FLAG) {
  1560. hthi = ath_rc_sib_setvalid_htrates(ath_rc_priv,
  1561. rate_table,
  1562. ht_mcs,
  1563. capflag);
  1564. }
  1565. hi = A_MAX(hi, hthi);
  1566. }
  1567. rate_ctrl->rate_table_size = hi + 1;
  1568. rate_ctrl->rate_max_phy = 0;
  1569. ASSERT(rate_ctrl->rate_table_size <= MAX_TX_RATE_TBL);
  1570. for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
  1571. for (j = 0; j < rate_ctrl->valid_phy_ratecnt[i]; j++) {
  1572. rate_ctrl->valid_rate_index[k++] =
  1573. rate_ctrl->valid_phy_rateidx[i][j];
  1574. }
  1575. if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, TRUE)
  1576. || !rate_ctrl->valid_phy_ratecnt[i])
  1577. continue;
  1578. rate_ctrl->rate_max_phy = rate_ctrl->valid_phy_rateidx[i][j-1];
  1579. }
  1580. ASSERT(rate_ctrl->rate_table_size <= MAX_TX_RATE_TBL);
  1581. ASSERT(k <= MAX_TX_RATE_TBL);
  1582. rate_ctrl->max_valid_rate = k;
  1583. /*
  1584. * Some third party vendors don't send the supported rate series in
  1585. * order. So sorting to make sure its in order, otherwise our RateFind
  1586. * Algo will select wrong rates
  1587. */
  1588. ath_rc_sort_validrates(rate_table, rate_ctrl);
  1589. rate_ctrl->rate_max_phy = rate_ctrl->valid_rate_index[k-4];
  1590. }
  1591. /*
  1592. * Update rate-control state on station associate/reassociate.
  1593. */
  1594. static int ath_rate_newassoc(struct ath_softc *sc,
  1595. struct ath_rate_node *ath_rc_priv,
  1596. unsigned int capflag,
  1597. struct ath_rateset *negotiated_rates,
  1598. struct ath_rateset *negotiated_htrates)
  1599. {
  1600. ath_rc_priv->ht_cap =
  1601. ((capflag & ATH_RC_DS_FLAG) ? WLAN_RC_DS_FLAG : 0) |
  1602. ((capflag & ATH_RC_SGI_FLAG) ? WLAN_RC_SGI_FLAG : 0) |
  1603. ((capflag & ATH_RC_HT_FLAG) ? WLAN_RC_HT_FLAG : 0) |
  1604. ((capflag & ATH_RC_CW40_FLAG) ? WLAN_RC_40_FLAG : 0);
  1605. ath_rc_sib_update(sc, ath_rc_priv, ath_rc_priv->ht_cap, 0,
  1606. negotiated_rates, negotiated_htrates);
  1607. return 0;
  1608. }
  1609. /*
  1610. * This routine is called to initialize the rate control parameters
  1611. * in the SIB. It is called initially during system initialization
  1612. * or when a station is associated with the AP.
  1613. */
  1614. static void ath_rc_sib_init(struct ath_rate_node *ath_rc_priv)
  1615. {
  1616. struct ath_tx_ratectrl *rate_ctrl;
  1617. rate_ctrl = (struct ath_tx_ratectrl *)(ath_rc_priv);
  1618. rate_ctrl->rssi_down_time = jiffies_to_msecs(jiffies);
  1619. }
  1620. static void ath_setup_rates(struct ath_softc *sc,
  1621. struct ieee80211_supported_band *sband,
  1622. struct ieee80211_sta *sta,
  1623. struct ath_rate_node *rc_priv)
  1624. {
  1625. int i, j = 0;
  1626. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1627. for (i = 0; i < sband->n_bitrates; i++) {
  1628. if (sta->supp_rates[sband->band] & BIT(i)) {
  1629. rc_priv->neg_rates.rs_rates[j]
  1630. = (sband->bitrates[i].bitrate * 2) / 10;
  1631. j++;
  1632. }
  1633. }
  1634. rc_priv->neg_rates.rs_nrates = j;
  1635. }
  1636. void ath_rc_node_update(struct ieee80211_hw *hw, struct ath_rate_node *rc_priv)
  1637. {
  1638. struct ath_softc *sc = hw->priv;
  1639. u32 capflag = 0;
  1640. if (hw->conf.ht.enabled) {
  1641. capflag |= ATH_RC_HT_FLAG | ATH_RC_DS_FLAG;
  1642. if (sc->sc_ht_info.tx_chan_width == ATH9K_HT_MACMODE_2040)
  1643. capflag |= ATH_RC_CW40_FLAG;
  1644. }
  1645. ath_rate_newassoc(sc, rc_priv, capflag,
  1646. &rc_priv->neg_rates,
  1647. &rc_priv->neg_ht_rates);
  1648. }
  1649. /* Rate Control callbacks */
  1650. static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
  1651. struct ieee80211_sta *sta, void *priv_sta,
  1652. struct sk_buff *skb)
  1653. {
  1654. struct ath_softc *sc = priv;
  1655. struct ath_tx_info_priv *tx_info_priv;
  1656. struct ath_node *an;
  1657. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1658. struct ieee80211_hdr *hdr;
  1659. __le16 fc;
  1660. hdr = (struct ieee80211_hdr *)skb->data;
  1661. fc = hdr->frame_control;
  1662. /* XXX: UGLY HACK!! */
  1663. tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
  1664. an = (struct ath_node *)sta->drv_priv;
  1665. if (tx_info_priv == NULL)
  1666. return;
  1667. if (an && priv_sta && ieee80211_is_data(fc))
  1668. ath_rate_tx_complete(sc, an, priv_sta, tx_info_priv);
  1669. kfree(tx_info_priv);
  1670. tx_info->control.vif = NULL;
  1671. }
  1672. static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
  1673. struct ieee80211_tx_rate_control *txrc)
  1674. {
  1675. struct ieee80211_supported_band *sband = txrc->sband;
  1676. struct sk_buff *skb = txrc->skb;
  1677. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1678. struct ath_softc *sc = priv;
  1679. struct ieee80211_hw *hw = sc->hw;
  1680. struct ath_tx_info_priv *tx_info_priv;
  1681. struct ath_rate_node *ath_rc_priv = priv_sta;
  1682. struct ath_node *an;
  1683. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1684. int is_probe = FALSE;
  1685. s8 lowest_idx;
  1686. __le16 fc = hdr->frame_control;
  1687. u8 *qc, tid;
  1688. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1689. /* allocate driver private area of tx_info, XXX: UGLY HACK! */
  1690. tx_info->control.vif = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC);
  1691. tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
  1692. ASSERT(tx_info_priv != NULL);
  1693. lowest_idx = rate_lowest_index(sband, sta);
  1694. tx_info_priv->min_rate = (sband->bitrates[lowest_idx].bitrate * 2) / 10;
  1695. /* lowest rate for management and multicast/broadcast frames */
  1696. if (!ieee80211_is_data(fc) ||
  1697. is_multicast_ether_addr(hdr->addr1) || !sta) {
  1698. tx_info->control.rates[0].idx = lowest_idx;
  1699. return;
  1700. }
  1701. /* Find tx rate for unicast frames */
  1702. ath_rate_findrate(sc, ath_rc_priv,
  1703. ATH_11N_TXMAXTRY, 4,
  1704. ATH_RC_PROBE_ALLOWED,
  1705. tx_info_priv->rcs,
  1706. &is_probe,
  1707. false);
  1708. #if 0
  1709. if (is_probe)
  1710. sel->probe_idx = ath_rc_priv->tx_ratectrl.probe_rate;
  1711. #endif
  1712. /* Ratecontrol sometimes returns invalid rate index */
  1713. if (tx_info_priv->rcs[0].rix != 0xff)
  1714. ath_rc_priv->prev_data_rix = tx_info_priv->rcs[0].rix;
  1715. else
  1716. tx_info_priv->rcs[0].rix = ath_rc_priv->prev_data_rix;
  1717. tx_info->control.rates[0].idx = tx_info_priv->rcs[0].rix;
  1718. /* Check if aggregation has to be enabled for this tid */
  1719. if (hw->conf.ht.enabled) {
  1720. if (ieee80211_is_data_qos(fc)) {
  1721. qc = ieee80211_get_qos_ctl(hdr);
  1722. tid = qc[0] & 0xf;
  1723. an = (struct ath_node *)sta->drv_priv;
  1724. if(ath_tx_aggr_check(sc, an, tid))
  1725. ieee80211_start_tx_ba_session(hw, hdr->addr1, tid);
  1726. }
  1727. }
  1728. }
  1729. static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
  1730. struct ieee80211_sta *sta, void *priv_sta)
  1731. {
  1732. struct ath_softc *sc = priv;
  1733. struct ath_rate_node *ath_rc_priv = priv_sta;
  1734. int i, j = 0;
  1735. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1736. ath_setup_rates(sc, sband, sta, ath_rc_priv);
  1737. if (sta->ht_cap.ht_supported) {
  1738. for (i = 0; i < 77; i++) {
  1739. if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
  1740. ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
  1741. if (j == ATH_RATE_MAX)
  1742. break;
  1743. }
  1744. ath_rc_priv->neg_ht_rates.rs_nrates = j;
  1745. }
  1746. ath_rc_node_update(sc->hw, priv_sta);
  1747. }
  1748. static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  1749. {
  1750. struct ath_softc *sc = hw->priv;
  1751. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1752. return hw->priv;
  1753. }
  1754. static void ath_rate_free(void *priv)
  1755. {
  1756. return;
  1757. }
  1758. static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
  1759. {
  1760. struct ieee80211_vif *vif;
  1761. struct ath_softc *sc = priv;
  1762. struct ath_vap *avp;
  1763. struct ath_rate_node *rate_priv;
  1764. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1765. vif = sc->sc_vaps[0];
  1766. ASSERT(vif);
  1767. avp = (void *)vif->drv_priv;
  1768. rate_priv = ath_rate_node_alloc(avp, sc->sc_rc, gfp);
  1769. if (!rate_priv) {
  1770. DPRINTF(sc, ATH_DBG_FATAL,
  1771. "%s: Unable to allocate private rc structure\n",
  1772. __func__);
  1773. return NULL;
  1774. }
  1775. ath_rc_sib_init(rate_priv);
  1776. return rate_priv;
  1777. }
  1778. static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
  1779. void *priv_sta)
  1780. {
  1781. struct ath_rate_node *rate_priv = priv_sta;
  1782. struct ath_softc *sc = priv;
  1783. DPRINTF(sc, ATH_DBG_RATE, "%s", __func__);
  1784. ath_rate_node_free(rate_priv);
  1785. }
  1786. static struct rate_control_ops ath_rate_ops = {
  1787. .module = NULL,
  1788. .name = "ath9k_rate_control",
  1789. .tx_status = ath_tx_status,
  1790. .get_rate = ath_get_rate,
  1791. .rate_init = ath_rate_init,
  1792. .alloc = ath_rate_alloc,
  1793. .free = ath_rate_free,
  1794. .alloc_sta = ath_rate_alloc_sta,
  1795. .free_sta = ath_rate_free_sta,
  1796. };
  1797. int ath_rate_control_register(void)
  1798. {
  1799. return ieee80211_rate_control_register(&ath_rate_ops);
  1800. }
  1801. void ath_rate_control_unregister(void)
  1802. {
  1803. ieee80211_rate_control_unregister(&ath_rate_ops);
  1804. }