rc.c 61 KB

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