rc.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  1. /*
  2. * Copyright (c) 2004 Video54 Technologies, Inc.
  3. * Copyright (c) 2004-2009 Atheros Communications, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "ath9k.h"
  18. static const struct ath_rate_table ar5416_11na_ratetable = {
  19. 42,
  20. {
  21. { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  22. 5400, 0x0b, 0x00, 12,
  23. 0, 2, 1, 0, 0, 0, 0, 0 },
  24. { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  25. 7800, 0x0f, 0x00, 18,
  26. 0, 3, 1, 1, 1, 1, 1, 0 },
  27. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  28. 10000, 0x0a, 0x00, 24,
  29. 2, 4, 2, 2, 2, 2, 2, 0 },
  30. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  31. 13900, 0x0e, 0x00, 36,
  32. 2, 6, 2, 3, 3, 3, 3, 0 },
  33. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  34. 17300, 0x09, 0x00, 48,
  35. 4, 10, 3, 4, 4, 4, 4, 0 },
  36. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  37. 23000, 0x0d, 0x00, 72,
  38. 4, 14, 3, 5, 5, 5, 5, 0 },
  39. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  40. 27400, 0x08, 0x00, 96,
  41. 4, 20, 3, 6, 6, 6, 6, 0 },
  42. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  43. 29300, 0x0c, 0x00, 108,
  44. 4, 23, 3, 7, 7, 7, 7, 0 },
  45. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  46. 6400, 0x80, 0x00, 0,
  47. 0, 2, 3, 8, 24, 8, 24, 3216 },
  48. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
  49. 12700, 0x81, 0x00, 1,
  50. 2, 4, 3, 9, 25, 9, 25, 6434 },
  51. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  52. 18800, 0x82, 0x00, 2,
  53. 2, 6, 3, 10, 26, 10, 26, 9650 },
  54. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
  55. 25000, 0x83, 0x00, 3,
  56. 4, 10, 3, 11, 27, 11, 27, 12868 },
  57. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
  58. 36700, 0x84, 0x00, 4,
  59. 4, 14, 3, 12, 28, 12, 28, 19304 },
  60. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
  61. 48100, 0x85, 0x00, 5,
  62. 4, 20, 3, 13, 29, 13, 29, 25740 },
  63. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  64. 53500, 0x86, 0x00, 6,
  65. 4, 23, 3, 14, 30, 14, 30, 28956 },
  66. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
  67. 59000, 0x87, 0x00, 7,
  68. 4, 25, 3, 15, 31, 15, 32, 32180 },
  69. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
  70. 12700, 0x88, 0x00,
  71. 8, 0, 2, 3, 16, 33, 16, 33, 6430 },
  72. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
  73. 24800, 0x89, 0x00, 9,
  74. 2, 4, 3, 17, 34, 17, 34, 12860 },
  75. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
  76. 36600, 0x8a, 0x00, 10,
  77. 2, 6, 3, 18, 35, 18, 35, 19300 },
  78. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
  79. 48100, 0x8b, 0x00, 11,
  80. 4, 10, 3, 19, 36, 19, 36, 25736 },
  81. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
  82. 69500, 0x8c, 0x00, 12,
  83. 4, 14, 3, 20, 37, 20, 37, 38600 },
  84. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
  85. 89500, 0x8d, 0x00, 13,
  86. 4, 20, 3, 21, 38, 21, 38, 51472 },
  87. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
  88. 98900, 0x8e, 0x00, 14,
  89. 4, 23, 3, 22, 39, 22, 39, 57890 },
  90. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
  91. 108300, 0x8f, 0x00, 15,
  92. 4, 25, 3, 23, 40, 23, 41, 64320 },
  93. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  94. 13200, 0x80, 0x00, 0,
  95. 0, 2, 3, 8, 24, 24, 24, 6684 },
  96. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  97. 25900, 0x81, 0x00, 1,
  98. 2, 4, 3, 9, 25, 25, 25, 13368 },
  99. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  100. 38600, 0x82, 0x00, 2,
  101. 2, 6, 3, 10, 26, 26, 26, 20052 },
  102. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
  103. 49800, 0x83, 0x00, 3,
  104. 4, 10, 3, 11, 27, 27, 27, 26738 },
  105. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
  106. 72200, 0x84, 0x00, 4,
  107. 4, 14, 3, 12, 28, 28, 28, 40104 },
  108. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
  109. 92900, 0x85, 0x00, 5,
  110. 4, 20, 3, 13, 29, 29, 29, 53476 },
  111. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  112. 102700, 0x86, 0x00, 6,
  113. 4, 23, 3, 14, 30, 30, 30, 60156 },
  114. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
  115. 112000, 0x87, 0x00, 7,
  116. 4, 25, 3, 15, 31, 32, 32, 66840 },
  117. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  118. 122000, 0x87, 0x00, 7,
  119. 4, 25, 3, 15, 31, 32, 32, 74200 },
  120. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
  121. 25800, 0x88, 0x00, 8,
  122. 0, 2, 3, 16, 33, 33, 33, 13360 },
  123. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
  124. 49800, 0x89, 0x00, 9,
  125. 2, 4, 3, 17, 34, 34, 34, 26720 },
  126. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
  127. 71900, 0x8a, 0x00, 10,
  128. 2, 6, 3, 18, 35, 35, 35, 40080 },
  129. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
  130. 92500, 0x8b, 0x00, 11,
  131. 4, 10, 3, 19, 36, 36, 36, 53440 },
  132. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
  133. 130300, 0x8c, 0x00, 12,
  134. 4, 14, 3, 20, 37, 37, 37, 80160 },
  135. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
  136. 162800, 0x8d, 0x00, 13,
  137. 4, 20, 3, 21, 38, 38, 38, 106880 },
  138. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
  139. 178200, 0x8e, 0x00, 14,
  140. 4, 23, 3, 22, 39, 39, 39, 120240 },
  141. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
  142. 192100, 0x8f, 0x00, 15,
  143. 4, 25, 3, 23, 40, 41, 41, 133600 },
  144. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  145. 207000, 0x8f, 0x00, 15,
  146. 4, 25, 3, 23, 40, 41, 41, 148400 },
  147. },
  148. 50, /* probe interval */
  149. 50, /* rssi reduce interval */
  150. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  151. };
  152. /* 4ms frame limit not used for NG mode. The values filled
  153. * for HT are the 64K max aggregate limit */
  154. static const struct ath_rate_table ar5416_11ng_ratetable = {
  155. 46,
  156. {
  157. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
  158. 900, 0x1b, 0x00, 2,
  159. 0, 0, 1, 0, 0, 0, 0, 0 },
  160. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
  161. 1900, 0x1a, 0x04, 4,
  162. 1, 1, 1, 1, 1, 1, 1, 0 },
  163. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
  164. 4900, 0x19, 0x04, 11,
  165. 2, 2, 2, 2, 2, 2, 2, 0 },
  166. { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
  167. 8100, 0x18, 0x04, 22,
  168. 3, 3, 2, 3, 3, 3, 3, 0 },
  169. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  170. 5400, 0x0b, 0x00, 12,
  171. 4, 2, 1, 4, 4, 4, 4, 0 },
  172. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  173. 7800, 0x0f, 0x00, 18,
  174. 4, 3, 1, 5, 5, 5, 5, 0 },
  175. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  176. 10100, 0x0a, 0x00, 24,
  177. 6, 4, 1, 6, 6, 6, 6, 0 },
  178. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  179. 14100, 0x0e, 0x00, 36,
  180. 6, 6, 2, 7, 7, 7, 7, 0 },
  181. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  182. 17700, 0x09, 0x00, 48,
  183. 8, 10, 3, 8, 8, 8, 8, 0 },
  184. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  185. 23700, 0x0d, 0x00, 72,
  186. 8, 14, 3, 9, 9, 9, 9, 0 },
  187. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  188. 27400, 0x08, 0x00, 96,
  189. 8, 20, 3, 10, 10, 10, 10, 0 },
  190. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  191. 30900, 0x0c, 0x00, 108,
  192. 8, 23, 3, 11, 11, 11, 11, 0 },
  193. { INVALID, INVALID, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  194. 6400, 0x80, 0x00, 0,
  195. 4, 2, 3, 12, 28, 12, 28, 3216 },
  196. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
  197. 12700, 0x81, 0x00, 1,
  198. 6, 4, 3, 13, 29, 13, 29, 6434 },
  199. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  200. 18800, 0x82, 0x00, 2,
  201. 6, 6, 3, 14, 30, 14, 30, 9650 },
  202. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
  203. 25000, 0x83, 0x00, 3,
  204. 8, 10, 3, 15, 31, 15, 31, 12868 },
  205. { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
  206. 36700, 0x84, 0x00, 4,
  207. 8, 14, 3, 16, 32, 16, 32, 19304 },
  208. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
  209. 48100, 0x85, 0x00, 5,
  210. 8, 20, 3, 17, 33, 17, 33, 25740 },
  211. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  212. 53500, 0x86, 0x00, 6,
  213. 8, 23, 3, 18, 34, 18, 34, 28956 },
  214. { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
  215. 59000, 0x87, 0x00, 7,
  216. 8, 25, 3, 19, 35, 19, 36, 32180 },
  217. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
  218. 12700, 0x88, 0x00, 8,
  219. 4, 2, 3, 20, 37, 20, 37, 6430 },
  220. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
  221. 24800, 0x89, 0x00, 9,
  222. 6, 4, 3, 21, 38, 21, 38, 12860 },
  223. { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
  224. 36600, 0x8a, 0x00, 10,
  225. 6, 6, 3, 22, 39, 22, 39, 19300 },
  226. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
  227. 48100, 0x8b, 0x00, 11,
  228. 8, 10, 3, 23, 40, 23, 40, 25736 },
  229. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
  230. 69500, 0x8c, 0x00, 12,
  231. 8, 14, 3, 24, 41, 24, 41, 38600 },
  232. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
  233. 89500, 0x8d, 0x00, 13,
  234. 8, 20, 3, 25, 42, 25, 42, 51472 },
  235. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
  236. 98900, 0x8e, 0x00, 14,
  237. 8, 23, 3, 26, 43, 26, 44, 57890 },
  238. { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
  239. 108300, 0x8f, 0x00, 15,
  240. 8, 25, 3, 27, 44, 27, 45, 64320 },
  241. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  242. 13200, 0x80, 0x00, 0,
  243. 8, 2, 3, 12, 28, 28, 28, 6684 },
  244. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  245. 25900, 0x81, 0x00, 1,
  246. 8, 4, 3, 13, 29, 29, 29, 13368 },
  247. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  248. 38600, 0x82, 0x00, 2,
  249. 8, 6, 3, 14, 30, 30, 30, 20052 },
  250. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
  251. 49800, 0x83, 0x00, 3,
  252. 8, 10, 3, 15, 31, 31, 31, 26738 },
  253. { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
  254. 72200, 0x84, 0x00, 4,
  255. 8, 14, 3, 16, 32, 32, 32, 40104 },
  256. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
  257. 92900, 0x85, 0x00, 5,
  258. 8, 20, 3, 17, 33, 33, 33, 53476 },
  259. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  260. 102700, 0x86, 0x00, 6,
  261. 8, 23, 3, 18, 34, 34, 34, 60156 },
  262. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
  263. 112000, 0x87, 0x00, 7,
  264. 8, 23, 3, 19, 35, 36, 36, 66840 },
  265. { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  266. 122000, 0x87, 0x00, 7,
  267. 8, 25, 3, 19, 35, 36, 36, 74200 },
  268. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
  269. 25800, 0x88, 0x00, 8,
  270. 8, 2, 3, 20, 37, 37, 37, 13360 },
  271. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
  272. 49800, 0x89, 0x00, 9,
  273. 8, 4, 3, 21, 38, 38, 38, 26720 },
  274. { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
  275. 71900, 0x8a, 0x00, 10,
  276. 8, 6, 3, 22, 39, 39, 39, 40080 },
  277. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
  278. 92500, 0x8b, 0x00, 11,
  279. 8, 10, 3, 23, 40, 40, 40, 53440 },
  280. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
  281. 130300, 0x8c, 0x00, 12,
  282. 8, 14, 3, 24, 41, 41, 41, 80160 },
  283. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
  284. 162800, 0x8d, 0x00, 13,
  285. 8, 20, 3, 25, 42, 42, 42, 106880 },
  286. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
  287. 178200, 0x8e, 0x00, 14,
  288. 8, 23, 3, 26, 43, 43, 43, 120240 },
  289. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
  290. 192100, 0x8f, 0x00, 15,
  291. 8, 23, 3, 27, 44, 45, 45, 133600 },
  292. { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  293. 207000, 0x8f, 0x00, 15,
  294. 8, 25, 3, 27, 44, 45, 45, 148400 },
  295. },
  296. 50, /* probe interval */
  297. 50, /* rssi reduce interval */
  298. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  299. };
  300. static const struct ath_rate_table ar5416_11a_ratetable = {
  301. 8,
  302. {
  303. { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  304. 5400, 0x0b, 0x00, (0x80|12),
  305. 0, 2, 1, 0, 0 },
  306. { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  307. 7800, 0x0f, 0x00, 18,
  308. 0, 3, 1, 1, 0 },
  309. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  310. 10000, 0x0a, 0x00, (0x80|24),
  311. 2, 4, 2, 2, 0 },
  312. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  313. 13900, 0x0e, 0x00, 36,
  314. 2, 6, 2, 3, 0 },
  315. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  316. 17300, 0x09, 0x00, (0x80|48),
  317. 4, 10, 3, 4, 0 },
  318. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  319. 23000, 0x0d, 0x00, 72,
  320. 4, 14, 3, 5, 0 },
  321. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  322. 27400, 0x08, 0x00, 96,
  323. 4, 19, 3, 6, 0 },
  324. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  325. 29300, 0x0c, 0x00, 108,
  326. 4, 23, 3, 7, 0 },
  327. },
  328. 50, /* probe interval */
  329. 50, /* rssi reduce interval */
  330. 0, /* Phy rates allowed initially */
  331. };
  332. static const struct ath_rate_table ar5416_11g_ratetable = {
  333. 12,
  334. {
  335. { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
  336. 900, 0x1b, 0x00, 2,
  337. 0, 0, 1, 0, 0 },
  338. { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
  339. 1900, 0x1a, 0x04, 4,
  340. 1, 1, 1, 1, 0 },
  341. { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
  342. 4900, 0x19, 0x04, 11,
  343. 2, 2, 2, 2, 0 },
  344. { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
  345. 8100, 0x18, 0x04, 22,
  346. 3, 3, 2, 3, 0 },
  347. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
  348. 5400, 0x0b, 0x00, 12,
  349. 4, 2, 1, 4, 0 },
  350. { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
  351. 7800, 0x0f, 0x00, 18,
  352. 4, 3, 1, 5, 0 },
  353. { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
  354. 10000, 0x0a, 0x00, 24,
  355. 6, 4, 1, 6, 0 },
  356. { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
  357. 13900, 0x0e, 0x00, 36,
  358. 6, 6, 2, 7, 0 },
  359. { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
  360. 17300, 0x09, 0x00, 48,
  361. 8, 10, 3, 8, 0 },
  362. { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
  363. 23000, 0x0d, 0x00, 72,
  364. 8, 14, 3, 9, 0 },
  365. { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
  366. 27400, 0x08, 0x00, 96,
  367. 8, 19, 3, 10, 0 },
  368. { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
  369. 29300, 0x0c, 0x00, 108,
  370. 8, 23, 3, 11, 0 },
  371. },
  372. 50, /* probe interval */
  373. 50, /* rssi reduce interval */
  374. 0, /* Phy rates allowed initially */
  375. };
  376. static const struct ath_rate_table ar5416_11b_ratetable = {
  377. 4,
  378. {
  379. { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
  380. 900, 0x1b, 0x00, (0x80|2),
  381. 0, 0, 1, 0, 0 },
  382. { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
  383. 1800, 0x1a, 0x04, (0x80|4),
  384. 1, 1, 1, 1, 0 },
  385. { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
  386. 4300, 0x19, 0x04, (0x80|11),
  387. 1, 2, 2, 2, 0 },
  388. { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
  389. 7100, 0x18, 0x04, (0x80|22),
  390. 1, 4, 100, 3, 0 },
  391. },
  392. 100, /* probe interval */
  393. 100, /* rssi reduce interval */
  394. 0, /* Phy rates allowed initially */
  395. };
  396. static inline int8_t median(int8_t a, int8_t b, int8_t c)
  397. {
  398. if (a >= b) {
  399. if (b >= c)
  400. return b;
  401. else if (a > c)
  402. return c;
  403. else
  404. return a;
  405. } else {
  406. if (a >= c)
  407. return a;
  408. else if (b >= c)
  409. return c;
  410. else
  411. return b;
  412. }
  413. }
  414. static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table,
  415. struct ath_rate_priv *ath_rc_priv)
  416. {
  417. u8 i, j, idx, idx_next;
  418. for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) {
  419. for (j = 0; j <= i-1; j++) {
  420. idx = ath_rc_priv->valid_rate_index[j];
  421. idx_next = ath_rc_priv->valid_rate_index[j+1];
  422. if (rate_table->info[idx].ratekbps >
  423. rate_table->info[idx_next].ratekbps) {
  424. ath_rc_priv->valid_rate_index[j] = idx_next;
  425. ath_rc_priv->valid_rate_index[j+1] = idx;
  426. }
  427. }
  428. }
  429. }
  430. static void ath_rc_init_valid_txmask(struct ath_rate_priv *ath_rc_priv)
  431. {
  432. u8 i;
  433. for (i = 0; i < ath_rc_priv->rate_table_size; i++)
  434. ath_rc_priv->valid_rate_index[i] = 0;
  435. }
  436. static inline void ath_rc_set_valid_txmask(struct ath_rate_priv *ath_rc_priv,
  437. u8 index, int valid_tx_rate)
  438. {
  439. ASSERT(index <= ath_rc_priv->rate_table_size);
  440. ath_rc_priv->valid_rate_index[index] = valid_tx_rate ? 1 : 0;
  441. }
  442. static inline int ath_rc_isvalid_txmask(struct ath_rate_priv *ath_rc_priv,
  443. u8 index)
  444. {
  445. ASSERT(index <= ath_rc_priv->rate_table_size);
  446. return ath_rc_priv->valid_rate_index[index];
  447. }
  448. static inline
  449. int ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
  450. struct ath_rate_priv *ath_rc_priv,
  451. u8 cur_valid_txrate,
  452. u8 *next_idx)
  453. {
  454. u8 i;
  455. for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) {
  456. if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
  457. *next_idx = ath_rc_priv->valid_rate_index[i+1];
  458. return 1;
  459. }
  460. }
  461. /* No more valid rates */
  462. *next_idx = 0;
  463. return 0;
  464. }
  465. /* Return true only for single stream */
  466. static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
  467. {
  468. if (WLAN_RC_PHY_HT(phy) && !(capflag & WLAN_RC_HT_FLAG))
  469. return 0;
  470. if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
  471. return 0;
  472. if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
  473. return 0;
  474. if (!ignore_cw && WLAN_RC_PHY_HT(phy))
  475. if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
  476. return 0;
  477. if (!WLAN_RC_PHY_40(phy) && (capflag & WLAN_RC_40_FLAG))
  478. return 0;
  479. return 1;
  480. }
  481. static inline int
  482. ath_rc_get_nextlowervalid_txrate(const struct ath_rate_table *rate_table,
  483. struct ath_rate_priv *ath_rc_priv,
  484. u8 cur_valid_txrate, u8 *next_idx)
  485. {
  486. int8_t i;
  487. for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) {
  488. if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
  489. *next_idx = ath_rc_priv->valid_rate_index[i-1];
  490. return 1;
  491. }
  492. }
  493. return 0;
  494. }
  495. static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv,
  496. const struct ath_rate_table *rate_table,
  497. u32 capflag)
  498. {
  499. u8 i, hi = 0;
  500. u32 valid;
  501. for (i = 0; i < rate_table->rate_cnt; i++) {
  502. valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
  503. rate_table->info[i].valid_single_stream :
  504. rate_table->info[i].valid);
  505. if (valid == 1) {
  506. u32 phy = rate_table->info[i].phy;
  507. u8 valid_rate_count = 0;
  508. if (!ath_rc_valid_phyrate(phy, capflag, 0))
  509. continue;
  510. valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
  511. ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i;
  512. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  513. ath_rc_set_valid_txmask(ath_rc_priv, i, 1);
  514. hi = A_MAX(hi, i);
  515. }
  516. }
  517. return hi;
  518. }
  519. static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
  520. const struct ath_rate_table *rate_table,
  521. struct ath_rateset *rateset,
  522. u32 capflag)
  523. {
  524. u8 i, j, hi = 0;
  525. /* Use intersection of working rates and valid rates */
  526. for (i = 0; i < rateset->rs_nrates; i++) {
  527. for (j = 0; j < rate_table->rate_cnt; j++) {
  528. u32 phy = rate_table->info[j].phy;
  529. u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
  530. rate_table->info[j].valid_single_stream :
  531. rate_table->info[j].valid);
  532. u8 rate = rateset->rs_rates[i];
  533. u8 dot11rate = rate_table->info[j].dot11rate;
  534. /* We allow a rate only if its valid and the
  535. * capflag matches one of the validity
  536. * (VALID/VALID_20/VALID_40) flags */
  537. if (((rate & 0x7F) == (dot11rate & 0x7F)) &&
  538. ((valid & WLAN_RC_CAP_MODE(capflag)) ==
  539. WLAN_RC_CAP_MODE(capflag)) &&
  540. !WLAN_RC_PHY_HT(phy)) {
  541. u8 valid_rate_count = 0;
  542. if (!ath_rc_valid_phyrate(phy, capflag, 0))
  543. continue;
  544. valid_rate_count =
  545. ath_rc_priv->valid_phy_ratecnt[phy];
  546. ath_rc_priv->valid_phy_rateidx[phy]
  547. [valid_rate_count] = j;
  548. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  549. ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
  550. hi = A_MAX(hi, j);
  551. }
  552. }
  553. }
  554. return hi;
  555. }
  556. static u8 ath_rc_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
  557. const struct ath_rate_table *rate_table,
  558. u8 *mcs_set, u32 capflag)
  559. {
  560. struct ath_rateset *rateset = (struct ath_rateset *)mcs_set;
  561. u8 i, j, hi = 0;
  562. /* Use intersection of working rates and valid rates */
  563. for (i = 0; i < rateset->rs_nrates; i++) {
  564. for (j = 0; j < rate_table->rate_cnt; j++) {
  565. u32 phy = rate_table->info[j].phy;
  566. u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
  567. rate_table->info[j].valid_single_stream :
  568. rate_table->info[j].valid);
  569. u8 rate = rateset->rs_rates[i];
  570. u8 dot11rate = rate_table->info[j].dot11rate;
  571. if (((rate & 0x7F) != (dot11rate & 0x7F)) ||
  572. !WLAN_RC_PHY_HT(phy) ||
  573. !WLAN_RC_PHY_HT_VALID(valid, capflag))
  574. continue;
  575. if (!ath_rc_valid_phyrate(phy, capflag, 0))
  576. continue;
  577. ath_rc_priv->valid_phy_rateidx[phy]
  578. [ath_rc_priv->valid_phy_ratecnt[phy]] = j;
  579. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  580. ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
  581. hi = A_MAX(hi, j);
  582. }
  583. }
  584. return hi;
  585. }
  586. static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
  587. struct ath_rate_priv *ath_rc_priv,
  588. const struct ath_rate_table *rate_table,
  589. int *is_probing)
  590. {
  591. u32 dt, best_thruput, this_thruput, now_msec;
  592. u8 rate, next_rate, best_rate, maxindex, minindex;
  593. int8_t rssi_last, rssi_reduce = 0, index = 0;
  594. *is_probing = 0;
  595. rssi_last = median(ath_rc_priv->rssi_last,
  596. ath_rc_priv->rssi_last_prev,
  597. ath_rc_priv->rssi_last_prev2);
  598. /*
  599. * Age (reduce) last ack rssi based on how old it is.
  600. * The bizarre numbers are so the delta is 160msec,
  601. * meaning we divide by 16.
  602. * 0msec <= dt <= 25msec: don't derate
  603. * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB
  604. * 185msec <= dt: derate by 10dB
  605. */
  606. now_msec = jiffies_to_msecs(jiffies);
  607. dt = now_msec - ath_rc_priv->rssi_time;
  608. if (dt >= 185)
  609. rssi_reduce = 10;
  610. else if (dt >= 25)
  611. rssi_reduce = (u8)((dt - 25) >> 4);
  612. /* Now reduce rssi_last by rssi_reduce */
  613. if (rssi_last < rssi_reduce)
  614. rssi_last = 0;
  615. else
  616. rssi_last -= rssi_reduce;
  617. /*
  618. * Now look up the rate in the rssi table and return it.
  619. * If no rates match then we return 0 (lowest rate)
  620. */
  621. best_thruput = 0;
  622. maxindex = ath_rc_priv->max_valid_rate-1;
  623. minindex = 0;
  624. best_rate = minindex;
  625. /*
  626. * Try the higher rate first. It will reduce memory moving time
  627. * if we have very good channel characteristics.
  628. */
  629. for (index = maxindex; index >= minindex ; index--) {
  630. u8 per_thres;
  631. rate = ath_rc_priv->valid_rate_index[index];
  632. if (rate > ath_rc_priv->rate_max_phy)
  633. continue;
  634. /*
  635. * For TCP the average collision rate is around 11%,
  636. * so we ignore PERs less than this. This is to
  637. * prevent the rate we are currently using (whose
  638. * PER might be in the 10-15 range because of TCP
  639. * collisions) looking worse than the next lower
  640. * rate whose PER has decayed close to 0. If we
  641. * used to next lower rate, its PER would grow to
  642. * 10-15 and we would be worse off then staying
  643. * at the current rate.
  644. */
  645. per_thres = ath_rc_priv->state[rate].per;
  646. if (per_thres < 12)
  647. per_thres = 12;
  648. this_thruput = rate_table->info[rate].user_ratekbps *
  649. (100 - per_thres);
  650. if (best_thruput <= this_thruput) {
  651. best_thruput = this_thruput;
  652. best_rate = rate;
  653. }
  654. }
  655. rate = best_rate;
  656. ath_rc_priv->rssi_last_lookup = rssi_last;
  657. /*
  658. * Must check the actual rate (ratekbps) to account for
  659. * non-monoticity of 11g's rate table
  660. */
  661. if (rate >= ath_rc_priv->rate_max_phy) {
  662. rate = ath_rc_priv->rate_max_phy;
  663. /* Probe the next allowed phy state */
  664. if (ath_rc_get_nextvalid_txrate(rate_table,
  665. ath_rc_priv, rate, &next_rate) &&
  666. (now_msec - ath_rc_priv->probe_time >
  667. rate_table->probe_interval) &&
  668. (ath_rc_priv->hw_maxretry_pktcnt >= 1)) {
  669. rate = next_rate;
  670. ath_rc_priv->probe_rate = rate;
  671. ath_rc_priv->probe_time = now_msec;
  672. ath_rc_priv->hw_maxretry_pktcnt = 0;
  673. *is_probing = 1;
  674. }
  675. }
  676. if (rate > (ath_rc_priv->rate_table_size - 1))
  677. rate = ath_rc_priv->rate_table_size - 1;
  678. if (rate_table->info[rate].valid &&
  679. (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG))
  680. return rate;
  681. if (rate_table->info[rate].valid_single_stream &&
  682. !(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG));
  683. return rate;
  684. /* This should not happen */
  685. WARN_ON(1);
  686. rate = ath_rc_priv->valid_rate_index[0];
  687. return rate;
  688. }
  689. static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table,
  690. struct ieee80211_tx_rate *rate,
  691. struct ieee80211_tx_rate_control *txrc,
  692. u8 tries, u8 rix, int rtsctsenable)
  693. {
  694. rate->count = tries;
  695. rate->idx = rix;
  696. if (txrc->short_preamble)
  697. rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
  698. if (txrc->rts || rtsctsenable)
  699. rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
  700. if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
  701. rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  702. if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
  703. rate->flags |= IEEE80211_TX_RC_SHORT_GI;
  704. if (WLAN_RC_PHY_HT(rate_table->info[rix].phy))
  705. rate->flags |= IEEE80211_TX_RC_MCS;
  706. }
  707. static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
  708. const struct ath_rate_table *rate_table,
  709. struct ieee80211_tx_info *tx_info)
  710. {
  711. struct ieee80211_tx_rate *rates = tx_info->control.rates;
  712. int i = 0, rix = 0, cix, enable_g_protection = 0;
  713. /* get the cix for the lowest valid rix */
  714. for (i = 3; i >= 0; i--) {
  715. if (rates[i].count && (rates[i].idx >= 0)) {
  716. rix = rates[i].idx;
  717. break;
  718. }
  719. }
  720. cix = rate_table->info[rix].ctrl_rate;
  721. /* All protection frames are transmited at 2Mb/s for 802.11g,
  722. * otherwise we transmit them at 1Mb/s */
  723. if (sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ &&
  724. !conf_is_ht(&sc->hw->conf))
  725. enable_g_protection = 1;
  726. /*
  727. * If 802.11g protection is enabled, determine whether to use RTS/CTS or
  728. * just CTS. Note that this is only done for OFDM/HT unicast frames.
  729. */
  730. if ((sc->sc_flags & SC_OP_PROTECT_ENABLE) &&
  731. !(tx_info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  732. (rate_table->info[rix].phy == WLAN_RC_PHY_OFDM ||
  733. WLAN_RC_PHY_HT(rate_table->info[rix].phy))) {
  734. rates[0].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
  735. cix = rate_table->info[enable_g_protection].ctrl_rate;
  736. }
  737. tx_info->control.rts_cts_rate_idx = cix;
  738. }
  739. static u8 ath_rc_rate_getidx(struct ath_softc *sc,
  740. struct ath_rate_priv *ath_rc_priv,
  741. const struct ath_rate_table *rate_table,
  742. u8 rix, u16 stepdown,
  743. u16 min_rate)
  744. {
  745. u32 j;
  746. u8 nextindex = 0;
  747. if (min_rate) {
  748. for (j = RATE_TABLE_SIZE; j > 0; j--) {
  749. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  750. ath_rc_priv, rix, &nextindex))
  751. rix = nextindex;
  752. else
  753. break;
  754. }
  755. } else {
  756. for (j = stepdown; j > 0; j--) {
  757. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  758. ath_rc_priv, rix, &nextindex))
  759. rix = nextindex;
  760. else
  761. break;
  762. }
  763. }
  764. return rix;
  765. }
  766. static void ath_rc_ratefind(struct ath_softc *sc,
  767. struct ath_rate_priv *ath_rc_priv,
  768. struct ieee80211_tx_rate_control *txrc)
  769. {
  770. const struct ath_rate_table *rate_table;
  771. struct sk_buff *skb = txrc->skb;
  772. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  773. struct ieee80211_tx_rate *rates = tx_info->control.rates;
  774. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  775. __le16 fc = hdr->frame_control;
  776. u8 try_per_rate, i = 0, rix, nrix;
  777. int is_probe = 0;
  778. /*
  779. * For Multi Rate Retry we use a different number of
  780. * retry attempt counts. This ends up looking like this:
  781. *
  782. * MRR[0] = 2
  783. * MRR[1] = 2
  784. * MRR[2] = 2
  785. * MRR[3] = 4
  786. *
  787. */
  788. try_per_rate = sc->hw->max_rate_tries;
  789. rate_table = sc->cur_rate_table;
  790. rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table, &is_probe);
  791. nrix = rix;
  792. if (is_probe) {
  793. /* set one try for probe rates. For the
  794. * probes don't enable rts */
  795. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  796. 1, nrix, 0);
  797. /* Get the next tried/allowed rate. No RTS for the next series
  798. * after the probe rate
  799. */
  800. nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
  801. rate_table, nrix, 1, 0);
  802. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  803. try_per_rate, nrix, 0);
  804. tx_info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
  805. } else {
  806. /* Set the choosen rate. No RTS for first series entry. */
  807. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  808. try_per_rate, nrix, 0);
  809. }
  810. /* Fill in the other rates for multirate retry */
  811. for ( ; i < 4; i++) {
  812. u8 min_rate;
  813. /* Use twice the number of tries for the last MRR segment. */
  814. if (i + 1 == 4)
  815. try_per_rate = 4;
  816. min_rate = (((i + 1) == 4) && 0);
  817. nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
  818. rate_table, nrix, 1, min_rate);
  819. /* All other rates in the series have RTS enabled */
  820. ath_rc_rate_set_series(rate_table, &rates[i], txrc,
  821. try_per_rate, nrix, 1);
  822. }
  823. /*
  824. * NB:Change rate series to enable aggregation when operating
  825. * at lower MCS rates. When first rate in series is MCS2
  826. * in HT40 @ 2.4GHz, series should look like:
  827. *
  828. * {MCS2, MCS1, MCS0, MCS0}.
  829. *
  830. * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
  831. * look like:
  832. *
  833. * {MCS3, MCS2, MCS1, MCS1}
  834. *
  835. * So, set fourth rate in series to be same as third one for
  836. * above conditions.
  837. */
  838. if ((sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ) &&
  839. (conf_is_ht(&sc->hw->conf))) {
  840. u8 dot11rate = rate_table->info[rix].dot11rate;
  841. u8 phy = rate_table->info[rix].phy;
  842. if (i == 4 &&
  843. ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
  844. (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
  845. rates[3].idx = rates[2].idx;
  846. rates[3].flags = rates[2].flags;
  847. }
  848. }
  849. /*
  850. * Force hardware to use computed duration for next
  851. * fragment by disabling multi-rate retry, which
  852. * updates duration based on the multi-rate duration table.
  853. *
  854. * FIXME: Fix duration
  855. */
  856. if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  857. (ieee80211_has_morefrags(fc) ||
  858. (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG))) {
  859. rates[1].count = rates[2].count = rates[3].count = 0;
  860. rates[1].idx = rates[2].idx = rates[3].idx = 0;
  861. rates[0].count = ATH_TXMAXTRY;
  862. }
  863. /* Setup RTS/CTS */
  864. ath_rc_rate_set_rtscts(sc, rate_table, tx_info);
  865. }
  866. static bool ath_rc_update_per(struct ath_softc *sc,
  867. const struct ath_rate_table *rate_table,
  868. struct ath_rate_priv *ath_rc_priv,
  869. struct ath_tx_info_priv *tx_info_priv,
  870. int tx_rate, int xretries, int retries,
  871. u32 now_msec)
  872. {
  873. bool state_change = false;
  874. int count;
  875. u8 last_per;
  876. static u32 nretry_to_per_lookup[10] = {
  877. 100 * 0 / 1,
  878. 100 * 1 / 4,
  879. 100 * 1 / 2,
  880. 100 * 3 / 4,
  881. 100 * 4 / 5,
  882. 100 * 5 / 6,
  883. 100 * 6 / 7,
  884. 100 * 7 / 8,
  885. 100 * 8 / 9,
  886. 100 * 9 / 10
  887. };
  888. last_per = ath_rc_priv->state[tx_rate].per;
  889. if (xretries) {
  890. if (xretries == 1) {
  891. ath_rc_priv->state[tx_rate].per += 30;
  892. if (ath_rc_priv->state[tx_rate].per > 100)
  893. ath_rc_priv->state[tx_rate].per = 100;
  894. } else {
  895. /* xretries == 2 */
  896. count = ARRAY_SIZE(nretry_to_per_lookup);
  897. if (retries >= count)
  898. retries = count - 1;
  899. /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
  900. ath_rc_priv->state[tx_rate].per =
  901. (u8)(last_per - (last_per >> 3) + (100 >> 3));
  902. }
  903. /* xretries == 1 or 2 */
  904. if (ath_rc_priv->probe_rate == tx_rate)
  905. ath_rc_priv->probe_rate = 0;
  906. } else { /* xretries == 0 */
  907. count = ARRAY_SIZE(nretry_to_per_lookup);
  908. if (retries >= count)
  909. retries = count - 1;
  910. if (tx_info_priv->n_bad_frames) {
  911. /* new_PER = 7/8*old_PER + 1/8*(currentPER)
  912. * Assuming that n_frames is not 0. The current PER
  913. * from the retries is 100 * retries / (retries+1),
  914. * since the first retries attempts failed, and the
  915. * next one worked. For the one that worked,
  916. * n_bad_frames subframes out of n_frames wored,
  917. * so the PER for that part is
  918. * 100 * n_bad_frames / n_frames, and it contributes
  919. * 100 * n_bad_frames / (n_frames * (retries+1)) to
  920. * the above PER. The expression below is a
  921. * simplified version of the sum of these two terms.
  922. */
  923. if (tx_info_priv->n_frames > 0) {
  924. int n_frames, n_bad_frames;
  925. u8 cur_per, new_per;
  926. n_bad_frames = retries * tx_info_priv->n_frames +
  927. tx_info_priv->n_bad_frames;
  928. n_frames = tx_info_priv->n_frames * (retries + 1);
  929. cur_per = (100 * n_bad_frames / n_frames) >> 3;
  930. new_per = (u8)(last_per - (last_per >> 3) + cur_per);
  931. ath_rc_priv->state[tx_rate].per = new_per;
  932. }
  933. } else {
  934. ath_rc_priv->state[tx_rate].per =
  935. (u8)(last_per - (last_per >> 3) +
  936. (nretry_to_per_lookup[retries] >> 3));
  937. }
  938. ath_rc_priv->rssi_last_prev2 = ath_rc_priv->rssi_last_prev;
  939. ath_rc_priv->rssi_last_prev = ath_rc_priv->rssi_last;
  940. ath_rc_priv->rssi_last = tx_info_priv->tx.ts_rssi;
  941. ath_rc_priv->rssi_time = now_msec;
  942. /*
  943. * If we got at most one retry then increase the max rate if
  944. * this was a probe. Otherwise, ignore the probe.
  945. */
  946. if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
  947. if (retries > 0 || 2 * tx_info_priv->n_bad_frames >
  948. tx_info_priv->n_frames) {
  949. /*
  950. * Since we probed with just a single attempt,
  951. * any retries means the probe failed. Also,
  952. * if the attempt worked, but more than half
  953. * the subframes were bad then also consider
  954. * the probe a failure.
  955. */
  956. ath_rc_priv->probe_rate = 0;
  957. } else {
  958. u8 probe_rate = 0;
  959. ath_rc_priv->rate_max_phy =
  960. ath_rc_priv->probe_rate;
  961. probe_rate = ath_rc_priv->probe_rate;
  962. if (ath_rc_priv->state[probe_rate].per > 30)
  963. ath_rc_priv->state[probe_rate].per = 20;
  964. ath_rc_priv->probe_rate = 0;
  965. /*
  966. * Since this probe succeeded, we allow the next
  967. * probe twice as soon. This allows the maxRate
  968. * to move up faster if the probes are
  969. * succesful.
  970. */
  971. ath_rc_priv->probe_time =
  972. now_msec - rate_table->probe_interval / 2;
  973. }
  974. }
  975. if (retries > 0) {
  976. /*
  977. * Don't update anything. We don't know if
  978. * this was because of collisions or poor signal.
  979. *
  980. * Later: if rssi_ack is close to
  981. * ath_rc_priv->state[txRate].rssi_thres and we see lots
  982. * of retries, then we could increase
  983. * ath_rc_priv->state[txRate].rssi_thres.
  984. */
  985. ath_rc_priv->hw_maxretry_pktcnt = 0;
  986. } else {
  987. int32_t rssi_ackAvg;
  988. int8_t rssi_thres;
  989. int8_t rssi_ack_vmin;
  990. /*
  991. * It worked with no retries. First ignore bogus (small)
  992. * rssi_ack values.
  993. */
  994. if (tx_rate == ath_rc_priv->rate_max_phy &&
  995. ath_rc_priv->hw_maxretry_pktcnt < 255) {
  996. ath_rc_priv->hw_maxretry_pktcnt++;
  997. }
  998. if (tx_info_priv->tx.ts_rssi <
  999. rate_table->info[tx_rate].rssi_ack_validmin)
  1000. goto exit;
  1001. /* Average the rssi */
  1002. if (tx_rate != ath_rc_priv->rssi_sum_rate) {
  1003. ath_rc_priv->rssi_sum_rate = tx_rate;
  1004. ath_rc_priv->rssi_sum =
  1005. ath_rc_priv->rssi_sum_cnt = 0;
  1006. }
  1007. ath_rc_priv->rssi_sum += tx_info_priv->tx.ts_rssi;
  1008. ath_rc_priv->rssi_sum_cnt++;
  1009. if (ath_rc_priv->rssi_sum_cnt < 4)
  1010. goto exit;
  1011. rssi_ackAvg =
  1012. (ath_rc_priv->rssi_sum + 2) / 4;
  1013. rssi_thres =
  1014. ath_rc_priv->state[tx_rate].rssi_thres;
  1015. rssi_ack_vmin =
  1016. rate_table->info[tx_rate].rssi_ack_validmin;
  1017. ath_rc_priv->rssi_sum =
  1018. ath_rc_priv->rssi_sum_cnt = 0;
  1019. /* Now reduce the current rssi threshold */
  1020. if ((rssi_ackAvg < rssi_thres + 2) &&
  1021. (rssi_thres > rssi_ack_vmin)) {
  1022. ath_rc_priv->state[tx_rate].rssi_thres--;
  1023. }
  1024. state_change = true;
  1025. }
  1026. }
  1027. exit:
  1028. return state_change;
  1029. }
  1030. /* Update PER, RSSI and whatever else that the code thinks it is doing.
  1031. If you can make sense of all this, you really need to go out more. */
  1032. static void ath_rc_update_ht(struct ath_softc *sc,
  1033. struct ath_rate_priv *ath_rc_priv,
  1034. struct ath_tx_info_priv *tx_info_priv,
  1035. int tx_rate, int xretries, int retries)
  1036. {
  1037. #define CHK_RSSI(rate) \
  1038. ((ath_rc_priv->state[(rate)].rssi_thres + \
  1039. rate_table->info[(rate)].rssi_ack_deltamin) > \
  1040. ath_rc_priv->state[(rate)+1].rssi_thres)
  1041. u32 now_msec = jiffies_to_msecs(jiffies);
  1042. int rate;
  1043. u8 last_per;
  1044. bool state_change = false;
  1045. const struct ath_rate_table *rate_table = sc->cur_rate_table;
  1046. int size = ath_rc_priv->rate_table_size;
  1047. if ((tx_rate < 0) || (tx_rate > rate_table->rate_cnt))
  1048. return;
  1049. /* To compensate for some imbalance between ctrl and ext. channel */
  1050. if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy))
  1051. tx_info_priv->tx.ts_rssi =
  1052. tx_info_priv->tx.ts_rssi < 3 ? 0 :
  1053. tx_info_priv->tx.ts_rssi - 3;
  1054. last_per = ath_rc_priv->state[tx_rate].per;
  1055. /* Update PER first */
  1056. state_change = ath_rc_update_per(sc, rate_table, ath_rc_priv,
  1057. tx_info_priv, tx_rate, xretries,
  1058. retries, now_msec);
  1059. /*
  1060. * If this rate looks bad (high PER) then stop using it for
  1061. * a while (except if we are probing).
  1062. */
  1063. if (ath_rc_priv->state[tx_rate].per >= 55 && tx_rate > 0 &&
  1064. rate_table->info[tx_rate].ratekbps <=
  1065. rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
  1066. ath_rc_get_nextlowervalid_txrate(rate_table, ath_rc_priv,
  1067. (u8)tx_rate, &ath_rc_priv->rate_max_phy);
  1068. /* Don't probe for a little while. */
  1069. ath_rc_priv->probe_time = now_msec;
  1070. }
  1071. if (state_change) {
  1072. /*
  1073. * Make sure the rates above this have higher rssi thresholds.
  1074. * (Note: Monotonicity is kept within the OFDM rates and
  1075. * within the CCK rates. However, no adjustment is
  1076. * made to keep the rssi thresholds monotonically
  1077. * increasing between the CCK and OFDM rates.)
  1078. */
  1079. for (rate = tx_rate; rate < size - 1; rate++) {
  1080. if (rate_table->info[rate+1].phy !=
  1081. rate_table->info[tx_rate].phy)
  1082. break;
  1083. if (CHK_RSSI(rate)) {
  1084. ath_rc_priv->state[rate+1].rssi_thres =
  1085. ath_rc_priv->state[rate].rssi_thres +
  1086. rate_table->info[rate].rssi_ack_deltamin;
  1087. }
  1088. }
  1089. /* Make sure the rates below this have lower rssi thresholds. */
  1090. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1091. if (rate_table->info[rate].phy !=
  1092. rate_table->info[tx_rate].phy)
  1093. break;
  1094. if (CHK_RSSI(rate)) {
  1095. if (ath_rc_priv->state[rate+1].rssi_thres <
  1096. rate_table->info[rate].rssi_ack_deltamin)
  1097. ath_rc_priv->state[rate].rssi_thres = 0;
  1098. else {
  1099. ath_rc_priv->state[rate].rssi_thres =
  1100. ath_rc_priv->state[rate+1].rssi_thres -
  1101. rate_table->info[rate].rssi_ack_deltamin;
  1102. }
  1103. if (ath_rc_priv->state[rate].rssi_thres <
  1104. rate_table->info[rate].rssi_ack_validmin) {
  1105. ath_rc_priv->state[rate].rssi_thres =
  1106. rate_table->info[rate].rssi_ack_validmin;
  1107. }
  1108. }
  1109. }
  1110. }
  1111. /* Make sure the rates below this have lower PER */
  1112. /* Monotonicity is kept only for rates below the current rate. */
  1113. if (ath_rc_priv->state[tx_rate].per < last_per) {
  1114. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1115. if (rate_table->info[rate].phy !=
  1116. rate_table->info[tx_rate].phy)
  1117. break;
  1118. if (ath_rc_priv->state[rate].per >
  1119. ath_rc_priv->state[rate+1].per) {
  1120. ath_rc_priv->state[rate].per =
  1121. ath_rc_priv->state[rate+1].per;
  1122. }
  1123. }
  1124. }
  1125. /* Maintain monotonicity for rates above the current rate */
  1126. for (rate = tx_rate; rate < size - 1; rate++) {
  1127. if (ath_rc_priv->state[rate+1].per <
  1128. ath_rc_priv->state[rate].per)
  1129. ath_rc_priv->state[rate+1].per =
  1130. ath_rc_priv->state[rate].per;
  1131. }
  1132. /* Every so often, we reduce the thresholds and
  1133. * PER (different for CCK and OFDM). */
  1134. if (now_msec - ath_rc_priv->rssi_down_time >=
  1135. rate_table->rssi_reduce_interval) {
  1136. for (rate = 0; rate < size; rate++) {
  1137. if (ath_rc_priv->state[rate].rssi_thres >
  1138. rate_table->info[rate].rssi_ack_validmin)
  1139. ath_rc_priv->state[rate].rssi_thres -= 1;
  1140. }
  1141. ath_rc_priv->rssi_down_time = now_msec;
  1142. }
  1143. /* Every so often, we reduce the thresholds
  1144. * and PER (different for CCK and OFDM). */
  1145. if (now_msec - ath_rc_priv->per_down_time >=
  1146. rate_table->rssi_reduce_interval) {
  1147. for (rate = 0; rate < size; rate++) {
  1148. ath_rc_priv->state[rate].per =
  1149. 7 * ath_rc_priv->state[rate].per / 8;
  1150. }
  1151. ath_rc_priv->per_down_time = now_msec;
  1152. }
  1153. ath_debug_stat_retries(sc, tx_rate, xretries, retries,
  1154. ath_rc_priv->state[tx_rate].per);
  1155. #undef CHK_RSSI
  1156. }
  1157. static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
  1158. struct ieee80211_tx_rate *rate)
  1159. {
  1160. int rix;
  1161. if ((rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  1162. (rate->flags & IEEE80211_TX_RC_SHORT_GI))
  1163. rix = rate_table->info[rate->idx].ht_index;
  1164. else if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  1165. rix = rate_table->info[rate->idx].sgi_index;
  1166. else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  1167. rix = rate_table->info[rate->idx].cw40index;
  1168. else
  1169. rix = rate_table->info[rate->idx].base_index;
  1170. return rix;
  1171. }
  1172. static void ath_rc_tx_status(struct ath_softc *sc,
  1173. struct ath_rate_priv *ath_rc_priv,
  1174. struct ieee80211_tx_info *tx_info,
  1175. int final_ts_idx, int xretries, int long_retry)
  1176. {
  1177. struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
  1178. const struct ath_rate_table *rate_table;
  1179. struct ieee80211_tx_rate *rates = tx_info->status.rates;
  1180. u8 flags;
  1181. u32 i = 0, rix;
  1182. rate_table = sc->cur_rate_table;
  1183. /*
  1184. * If the first rate is not the final index, there
  1185. * are intermediate rate failures to be processed.
  1186. */
  1187. if (final_ts_idx != 0) {
  1188. /* Process intermediate rates that failed.*/
  1189. for (i = 0; i < final_ts_idx ; i++) {
  1190. if (rates[i].count != 0 && (rates[i].idx >= 0)) {
  1191. flags = rates[i].flags;
  1192. /* If HT40 and we have switched mode from
  1193. * 40 to 20 => don't update */
  1194. if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  1195. !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
  1196. return;
  1197. rix = ath_rc_get_rateindex(rate_table, &rates[i]);
  1198. ath_rc_update_ht(sc, ath_rc_priv,
  1199. tx_info_priv, rix,
  1200. xretries ? 1 : 2,
  1201. rates[i].count);
  1202. }
  1203. }
  1204. } else {
  1205. /*
  1206. * Handle the special case of MIMO PS burst, where the second
  1207. * aggregate is sent out with only one rate and one try.
  1208. * Treating it as an excessive retry penalizes the rate
  1209. * inordinately.
  1210. */
  1211. if (rates[0].count == 1 && xretries == 1)
  1212. xretries = 2;
  1213. }
  1214. flags = rates[i].flags;
  1215. /* If HT40 and we have switched mode from 40 to 20 => don't update */
  1216. if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  1217. !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
  1218. return;
  1219. rix = ath_rc_get_rateindex(rate_table, &rates[i]);
  1220. ath_rc_update_ht(sc, ath_rc_priv, tx_info_priv, rix,
  1221. xretries, long_retry);
  1222. }
  1223. static const
  1224. struct ath_rate_table *ath_choose_rate_table(struct ath_softc *sc,
  1225. enum ieee80211_band band,
  1226. bool is_ht,
  1227. bool is_cw_40)
  1228. {
  1229. int mode = 0;
  1230. switch(band) {
  1231. case IEEE80211_BAND_2GHZ:
  1232. mode = ATH9K_MODE_11G;
  1233. if (is_ht)
  1234. mode = ATH9K_MODE_11NG_HT20;
  1235. if (is_cw_40)
  1236. mode = ATH9K_MODE_11NG_HT40PLUS;
  1237. break;
  1238. case IEEE80211_BAND_5GHZ:
  1239. mode = ATH9K_MODE_11A;
  1240. if (is_ht)
  1241. mode = ATH9K_MODE_11NA_HT20;
  1242. if (is_cw_40)
  1243. mode = ATH9K_MODE_11NA_HT40PLUS;
  1244. break;
  1245. default:
  1246. DPRINTF(sc, ATH_DBG_CONFIG, "Invalid band\n");
  1247. return NULL;
  1248. }
  1249. BUG_ON(mode >= ATH9K_MODE_MAX);
  1250. DPRINTF(sc, ATH_DBG_CONFIG, "Choosing rate table for mode: %d\n", mode);
  1251. return sc->hw_rate_table[mode];
  1252. }
  1253. static void ath_rc_init(struct ath_softc *sc,
  1254. struct ath_rate_priv *ath_rc_priv,
  1255. struct ieee80211_supported_band *sband,
  1256. struct ieee80211_sta *sta,
  1257. const struct ath_rate_table *rate_table)
  1258. {
  1259. struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
  1260. u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
  1261. u8 i, j, k, hi = 0, hthi = 0;
  1262. if (!rate_table) {
  1263. DPRINTF(sc, ATH_DBG_FATAL, "Rate table not initialized\n");
  1264. return;
  1265. }
  1266. /* Initial rate table size. Will change depending
  1267. * on the working rate set */
  1268. ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
  1269. /* Initialize thresholds according to the global rate table */
  1270. for (i = 0 ; i < ath_rc_priv->rate_table_size; i++) {
  1271. ath_rc_priv->state[i].rssi_thres =
  1272. rate_table->info[i].rssi_ack_validmin;
  1273. ath_rc_priv->state[i].per = 0;
  1274. }
  1275. /* Determine the valid rates */
  1276. ath_rc_init_valid_txmask(ath_rc_priv);
  1277. for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
  1278. for (j = 0; j < MAX_TX_RATE_PHY; j++)
  1279. ath_rc_priv->valid_phy_rateidx[i][j] = 0;
  1280. ath_rc_priv->valid_phy_ratecnt[i] = 0;
  1281. }
  1282. if (!rateset->rs_nrates) {
  1283. /* No working rate, just initialize valid rates */
  1284. hi = ath_rc_init_validrates(ath_rc_priv, rate_table,
  1285. ath_rc_priv->ht_cap);
  1286. } else {
  1287. /* Use intersection of working rates and valid rates */
  1288. hi = ath_rc_setvalid_rates(ath_rc_priv, rate_table,
  1289. rateset, ath_rc_priv->ht_cap);
  1290. if (ath_rc_priv->ht_cap & WLAN_RC_HT_FLAG) {
  1291. hthi = ath_rc_setvalid_htrates(ath_rc_priv,
  1292. rate_table,
  1293. ht_mcs,
  1294. ath_rc_priv->ht_cap);
  1295. }
  1296. hi = A_MAX(hi, hthi);
  1297. }
  1298. ath_rc_priv->rate_table_size = hi + 1;
  1299. ath_rc_priv->rate_max_phy = 0;
  1300. ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
  1301. for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
  1302. for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
  1303. ath_rc_priv->valid_rate_index[k++] =
  1304. ath_rc_priv->valid_phy_rateidx[i][j];
  1305. }
  1306. if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, 1)
  1307. || !ath_rc_priv->valid_phy_ratecnt[i])
  1308. continue;
  1309. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
  1310. }
  1311. ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
  1312. ASSERT(k <= RATE_TABLE_SIZE);
  1313. ath_rc_priv->max_valid_rate = k;
  1314. ath_rc_sort_validrates(rate_table, ath_rc_priv);
  1315. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
  1316. sc->cur_rate_table = rate_table;
  1317. DPRINTF(sc, ATH_DBG_CONFIG, "RC Initialized with capabilities: 0x%x\n",
  1318. ath_rc_priv->ht_cap);
  1319. }
  1320. static u8 ath_rc_build_ht_caps(struct ath_softc *sc, struct ieee80211_sta *sta,
  1321. bool is_cw40, bool is_sgi40)
  1322. {
  1323. u8 caps = 0;
  1324. if (sta->ht_cap.ht_supported) {
  1325. caps = WLAN_RC_HT_FLAG;
  1326. if (sc->sc_ah->caps.tx_chainmask != 1 &&
  1327. ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_DS, 0, NULL)) {
  1328. if (sta->ht_cap.mcs.rx_mask[1])
  1329. caps |= WLAN_RC_DS_FLAG;
  1330. }
  1331. if (is_cw40)
  1332. caps |= WLAN_RC_40_FLAG;
  1333. if (is_sgi40)
  1334. caps |= WLAN_RC_SGI_FLAG;
  1335. }
  1336. return caps;
  1337. }
  1338. /***********************************/
  1339. /* mac80211 Rate Control callbacks */
  1340. /***********************************/
  1341. static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
  1342. struct ieee80211_sta *sta, void *priv_sta,
  1343. struct sk_buff *skb)
  1344. {
  1345. struct ath_softc *sc = priv;
  1346. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1347. struct ath_tx_info_priv *tx_info_priv = NULL;
  1348. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1349. struct ieee80211_hdr *hdr;
  1350. int final_ts_idx, tx_status = 0, is_underrun = 0;
  1351. __le16 fc;
  1352. hdr = (struct ieee80211_hdr *)skb->data;
  1353. fc = hdr->frame_control;
  1354. tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
  1355. final_ts_idx = tx_info_priv->tx.ts_rateindex;
  1356. if (!priv_sta || !ieee80211_is_data(fc) ||
  1357. !tx_info_priv->update_rc)
  1358. goto exit;
  1359. if (tx_info_priv->tx.ts_status & ATH9K_TXERR_FILT)
  1360. goto exit;
  1361. /*
  1362. * If underrun error is seen assume it as an excessive retry only
  1363. * if prefetch trigger level have reached the max (0x3f for 5416)
  1364. * Adjust the long retry as if the frame was tried hw->max_rate_tries
  1365. * times. This affects how ratectrl updates PER for the failed rate.
  1366. */
  1367. if (tx_info_priv->tx.ts_flags &
  1368. (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
  1369. ((sc->sc_ah->tx_trig_level) >= ath_rc_priv->tx_triglevel_max)) {
  1370. tx_status = 1;
  1371. is_underrun = 1;
  1372. }
  1373. if ((tx_info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
  1374. (tx_info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
  1375. tx_status = 1;
  1376. ath_rc_tx_status(sc, ath_rc_priv, tx_info, final_ts_idx, tx_status,
  1377. (is_underrun) ? sc->hw->max_rate_tries :
  1378. tx_info_priv->tx.ts_longretry);
  1379. /* Check if aggregation has to be enabled for this tid */
  1380. if (conf_is_ht(&sc->hw->conf) &&
  1381. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  1382. if (ieee80211_is_data_qos(fc)) {
  1383. u8 *qc, tid;
  1384. struct ath_node *an;
  1385. qc = ieee80211_get_qos_ctl(hdr);
  1386. tid = qc[0] & 0xf;
  1387. an = (struct ath_node *)sta->drv_priv;
  1388. if(ath_tx_aggr_check(sc, an, tid))
  1389. ieee80211_start_tx_ba_session(sc->hw, hdr->addr1, tid);
  1390. }
  1391. }
  1392. ath_debug_stat_rc(sc, skb);
  1393. exit:
  1394. kfree(tx_info_priv);
  1395. }
  1396. static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
  1397. struct ieee80211_tx_rate_control *txrc)
  1398. {
  1399. struct ieee80211_supported_band *sband = txrc->sband;
  1400. struct sk_buff *skb = txrc->skb;
  1401. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1402. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1403. struct ath_softc *sc = priv;
  1404. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1405. __le16 fc = hdr->frame_control;
  1406. /* lowest rate for management and NO_ACK frames */
  1407. if (!ieee80211_is_data(fc) ||
  1408. tx_info->flags & IEEE80211_TX_CTL_NO_ACK || !sta) {
  1409. tx_info->control.rates[0].idx = rate_lowest_index(sband, sta);
  1410. tx_info->control.rates[0].count =
  1411. (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) ?
  1412. 1 : ATH_MGT_TXMAXTRY;
  1413. return;
  1414. }
  1415. /* Find tx rate for unicast frames */
  1416. ath_rc_ratefind(sc, ath_rc_priv, txrc);
  1417. }
  1418. static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
  1419. struct ieee80211_sta *sta, void *priv_sta)
  1420. {
  1421. struct ath_softc *sc = priv;
  1422. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1423. const struct ath_rate_table *rate_table = NULL;
  1424. bool is_cw40, is_sgi40;
  1425. int i, j = 0;
  1426. for (i = 0; i < sband->n_bitrates; i++) {
  1427. if (sta->supp_rates[sband->band] & BIT(i)) {
  1428. ath_rc_priv->neg_rates.rs_rates[j]
  1429. = (sband->bitrates[i].bitrate * 2) / 10;
  1430. j++;
  1431. }
  1432. }
  1433. ath_rc_priv->neg_rates.rs_nrates = j;
  1434. if (sta->ht_cap.ht_supported) {
  1435. for (i = 0, j = 0; i < 77; i++) {
  1436. if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
  1437. ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
  1438. if (j == ATH_RATE_MAX)
  1439. break;
  1440. }
  1441. ath_rc_priv->neg_ht_rates.rs_nrates = j;
  1442. }
  1443. is_cw40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1444. is_sgi40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  1445. /* Choose rate table first */
  1446. if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) ||
  1447. (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT) ||
  1448. (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)) {
  1449. rate_table = ath_choose_rate_table(sc, sband->band,
  1450. sta->ht_cap.ht_supported,
  1451. is_cw40);
  1452. } else if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
  1453. /* cur_rate_table would be set on init through config() */
  1454. rate_table = sc->cur_rate_table;
  1455. }
  1456. ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta, is_cw40, is_sgi40);
  1457. ath_rc_init(sc, priv_sta, sband, sta, rate_table);
  1458. }
  1459. static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
  1460. struct ieee80211_sta *sta, void *priv_sta,
  1461. u32 changed)
  1462. {
  1463. struct ath_softc *sc = priv;
  1464. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1465. const struct ath_rate_table *rate_table = NULL;
  1466. bool oper_cw40 = false, oper_sgi40;
  1467. bool local_cw40 = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG) ?
  1468. true : false;
  1469. bool local_sgi40 = (ath_rc_priv->ht_cap & WLAN_RC_SGI_FLAG) ?
  1470. true : false;
  1471. /* FIXME: Handle AP mode later when we support CWM */
  1472. if (changed & IEEE80211_RC_HT_CHANGED) {
  1473. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1474. return;
  1475. if (sc->hw->conf.channel_type == NL80211_CHAN_HT40MINUS ||
  1476. sc->hw->conf.channel_type == NL80211_CHAN_HT40PLUS)
  1477. oper_cw40 = true;
  1478. oper_sgi40 = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1479. true : false;
  1480. if ((local_cw40 != oper_cw40) || (local_sgi40 != oper_sgi40)) {
  1481. rate_table = ath_choose_rate_table(sc, sband->band,
  1482. sta->ht_cap.ht_supported,
  1483. oper_cw40);
  1484. ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta,
  1485. oper_cw40, oper_sgi40);
  1486. ath_rc_init(sc, priv_sta, sband, sta, rate_table);
  1487. DPRINTF(sc, ATH_DBG_CONFIG,
  1488. "Operating HT Bandwidth changed to: %d\n",
  1489. sc->hw->conf.channel_type);
  1490. }
  1491. }
  1492. }
  1493. static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  1494. {
  1495. struct ath_wiphy *aphy = hw->priv;
  1496. return aphy->sc;
  1497. }
  1498. static void ath_rate_free(void *priv)
  1499. {
  1500. return;
  1501. }
  1502. static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
  1503. {
  1504. struct ath_softc *sc = priv;
  1505. struct ath_rate_priv *rate_priv;
  1506. rate_priv = kzalloc(sizeof(struct ath_rate_priv), gfp);
  1507. if (!rate_priv) {
  1508. DPRINTF(sc, ATH_DBG_FATAL,
  1509. "Unable to allocate private rc structure\n");
  1510. return NULL;
  1511. }
  1512. rate_priv->rssi_down_time = jiffies_to_msecs(jiffies);
  1513. rate_priv->tx_triglevel_max = sc->sc_ah->caps.tx_triglevel_max;
  1514. return rate_priv;
  1515. }
  1516. static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
  1517. void *priv_sta)
  1518. {
  1519. struct ath_rate_priv *rate_priv = priv_sta;
  1520. kfree(rate_priv);
  1521. }
  1522. static struct rate_control_ops ath_rate_ops = {
  1523. .module = NULL,
  1524. .name = "ath9k_rate_control",
  1525. .tx_status = ath_tx_status,
  1526. .get_rate = ath_get_rate,
  1527. .rate_init = ath_rate_init,
  1528. .rate_update = ath_rate_update,
  1529. .alloc = ath_rate_alloc,
  1530. .free = ath_rate_free,
  1531. .alloc_sta = ath_rate_alloc_sta,
  1532. .free_sta = ath_rate_free_sta,
  1533. };
  1534. void ath_rate_attach(struct ath_softc *sc)
  1535. {
  1536. sc->hw_rate_table[ATH9K_MODE_11B] =
  1537. &ar5416_11b_ratetable;
  1538. sc->hw_rate_table[ATH9K_MODE_11A] =
  1539. &ar5416_11a_ratetable;
  1540. sc->hw_rate_table[ATH9K_MODE_11G] =
  1541. &ar5416_11g_ratetable;
  1542. sc->hw_rate_table[ATH9K_MODE_11NA_HT20] =
  1543. &ar5416_11na_ratetable;
  1544. sc->hw_rate_table[ATH9K_MODE_11NG_HT20] =
  1545. &ar5416_11ng_ratetable;
  1546. sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
  1547. &ar5416_11na_ratetable;
  1548. sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
  1549. &ar5416_11na_ratetable;
  1550. sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
  1551. &ar5416_11ng_ratetable;
  1552. sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
  1553. &ar5416_11ng_ratetable;
  1554. }
  1555. int ath_rate_control_register(void)
  1556. {
  1557. return ieee80211_rate_control_register(&ath_rate_ops);
  1558. }
  1559. void ath_rate_control_unregister(void)
  1560. {
  1561. ieee80211_rate_control_unregister(&ath_rate_ops);
  1562. }