rc.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  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. ASSERT((rate_table->info[rate].valid &&
  679. (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG)) ||
  680. (rate_table->info[rate].valid_single_stream &&
  681. !(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG)));
  682. return rate;
  683. }
  684. static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table,
  685. struct ieee80211_tx_rate *rate,
  686. struct ieee80211_tx_rate_control *txrc,
  687. u8 tries, u8 rix, int rtsctsenable)
  688. {
  689. rate->count = tries;
  690. rate->idx = rix;
  691. if (txrc->short_preamble)
  692. rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
  693. if (txrc->rts || rtsctsenable)
  694. rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
  695. if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
  696. rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  697. if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
  698. rate->flags |= IEEE80211_TX_RC_SHORT_GI;
  699. if (WLAN_RC_PHY_HT(rate_table->info[rix].phy))
  700. rate->flags |= IEEE80211_TX_RC_MCS;
  701. }
  702. static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
  703. const struct ath_rate_table *rate_table,
  704. struct ieee80211_tx_info *tx_info)
  705. {
  706. struct ieee80211_tx_rate *rates = tx_info->control.rates;
  707. int i = 0, rix = 0, cix, enable_g_protection = 0;
  708. /* get the cix for the lowest valid rix */
  709. for (i = 3; i >= 0; i--) {
  710. if (rates[i].count && (rates[i].idx >= 0)) {
  711. rix = rates[i].idx;
  712. break;
  713. }
  714. }
  715. cix = rate_table->info[rix].ctrl_rate;
  716. /* All protection frames are transmited at 2Mb/s for 802.11g,
  717. * otherwise we transmit them at 1Mb/s */
  718. if (sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ &&
  719. !conf_is_ht(&sc->hw->conf))
  720. enable_g_protection = 1;
  721. /*
  722. * If 802.11g protection is enabled, determine whether to use RTS/CTS or
  723. * just CTS. Note that this is only done for OFDM/HT unicast frames.
  724. */
  725. if ((sc->sc_flags & SC_OP_PROTECT_ENABLE) &&
  726. !(tx_info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  727. (rate_table->info[rix].phy == WLAN_RC_PHY_OFDM ||
  728. WLAN_RC_PHY_HT(rate_table->info[rix].phy))) {
  729. rates[0].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
  730. cix = rate_table->info[enable_g_protection].ctrl_rate;
  731. }
  732. tx_info->control.rts_cts_rate_idx = cix;
  733. }
  734. static u8 ath_rc_rate_getidx(struct ath_softc *sc,
  735. struct ath_rate_priv *ath_rc_priv,
  736. const struct ath_rate_table *rate_table,
  737. u8 rix, u16 stepdown,
  738. u16 min_rate)
  739. {
  740. u32 j;
  741. u8 nextindex = 0;
  742. if (min_rate) {
  743. for (j = RATE_TABLE_SIZE; j > 0; j--) {
  744. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  745. ath_rc_priv, rix, &nextindex))
  746. rix = nextindex;
  747. else
  748. break;
  749. }
  750. } else {
  751. for (j = stepdown; j > 0; j--) {
  752. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  753. ath_rc_priv, rix, &nextindex))
  754. rix = nextindex;
  755. else
  756. break;
  757. }
  758. }
  759. return rix;
  760. }
  761. static void ath_rc_ratefind(struct ath_softc *sc,
  762. struct ath_rate_priv *ath_rc_priv,
  763. struct ieee80211_tx_rate_control *txrc)
  764. {
  765. const struct ath_rate_table *rate_table;
  766. struct sk_buff *skb = txrc->skb;
  767. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  768. struct ieee80211_tx_rate *rates = tx_info->control.rates;
  769. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  770. __le16 fc = hdr->frame_control;
  771. u8 try_per_rate = 0, i = 0, rix, nrix;
  772. int is_probe = 0;
  773. rate_table = sc->cur_rate_table;
  774. rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table, &is_probe);
  775. nrix = rix;
  776. if (is_probe) {
  777. /* set one try for probe rates. For the
  778. * probes don't enable rts */
  779. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  780. 1, nrix, 0);
  781. try_per_rate = (ATH_11N_TXMAXTRY/4);
  782. /* Get the next tried/allowed rate. No RTS for the next series
  783. * after the probe rate
  784. */
  785. nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
  786. rate_table, nrix, 1, 0);
  787. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  788. try_per_rate, nrix, 0);
  789. tx_info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
  790. } else {
  791. try_per_rate = (ATH_11N_TXMAXTRY/4);
  792. /* Set the choosen rate. No RTS for first series entry. */
  793. ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
  794. try_per_rate, nrix, 0);
  795. }
  796. /* Fill in the other rates for multirate retry */
  797. for ( ; i < 4; i++) {
  798. u8 try_num;
  799. u8 min_rate;
  800. try_num = ((i + 1) == 4) ?
  801. ATH_11N_TXMAXTRY - (try_per_rate * i) : try_per_rate ;
  802. min_rate = (((i + 1) == 4) && 0);
  803. nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
  804. rate_table, nrix, 1, min_rate);
  805. /* All other rates in the series have RTS enabled */
  806. ath_rc_rate_set_series(rate_table, &rates[i], txrc,
  807. try_num, nrix, 1);
  808. }
  809. /*
  810. * NB:Change rate series to enable aggregation when operating
  811. * at lower MCS rates. When first rate in series is MCS2
  812. * in HT40 @ 2.4GHz, series should look like:
  813. *
  814. * {MCS2, MCS1, MCS0, MCS0}.
  815. *
  816. * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
  817. * look like:
  818. *
  819. * {MCS3, MCS2, MCS1, MCS1}
  820. *
  821. * So, set fourth rate in series to be same as third one for
  822. * above conditions.
  823. */
  824. if ((sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ) &&
  825. (conf_is_ht(&sc->hw->conf))) {
  826. u8 dot11rate = rate_table->info[rix].dot11rate;
  827. u8 phy = rate_table->info[rix].phy;
  828. if (i == 4 &&
  829. ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
  830. (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
  831. rates[3].idx = rates[2].idx;
  832. rates[3].flags = rates[2].flags;
  833. }
  834. }
  835. /*
  836. * Force hardware to use computed duration for next
  837. * fragment by disabling multi-rate retry, which
  838. * updates duration based on the multi-rate duration table.
  839. *
  840. * FIXME: Fix duration
  841. */
  842. if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  843. (ieee80211_has_morefrags(fc) ||
  844. (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG))) {
  845. rates[1].count = rates[2].count = rates[3].count = 0;
  846. rates[1].idx = rates[2].idx = rates[3].idx = 0;
  847. rates[0].count = ATH_TXMAXTRY;
  848. }
  849. /* Setup RTS/CTS */
  850. ath_rc_rate_set_rtscts(sc, rate_table, tx_info);
  851. }
  852. static bool ath_rc_update_per(struct ath_softc *sc,
  853. const struct ath_rate_table *rate_table,
  854. struct ath_rate_priv *ath_rc_priv,
  855. struct ath_tx_info_priv *tx_info_priv,
  856. int tx_rate, int xretries, int retries,
  857. u32 now_msec)
  858. {
  859. bool state_change = false;
  860. int count;
  861. u8 last_per;
  862. static u32 nretry_to_per_lookup[10] = {
  863. 100 * 0 / 1,
  864. 100 * 1 / 4,
  865. 100 * 1 / 2,
  866. 100 * 3 / 4,
  867. 100 * 4 / 5,
  868. 100 * 5 / 6,
  869. 100 * 6 / 7,
  870. 100 * 7 / 8,
  871. 100 * 8 / 9,
  872. 100 * 9 / 10
  873. };
  874. last_per = ath_rc_priv->state[tx_rate].per;
  875. if (xretries) {
  876. if (xretries == 1) {
  877. ath_rc_priv->state[tx_rate].per += 30;
  878. if (ath_rc_priv->state[tx_rate].per > 100)
  879. ath_rc_priv->state[tx_rate].per = 100;
  880. } else {
  881. /* xretries == 2 */
  882. count = ARRAY_SIZE(nretry_to_per_lookup);
  883. if (retries >= count)
  884. retries = count - 1;
  885. /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
  886. ath_rc_priv->state[tx_rate].per =
  887. (u8)(last_per - (last_per >> 3) + (100 >> 3));
  888. }
  889. /* xretries == 1 or 2 */
  890. if (ath_rc_priv->probe_rate == tx_rate)
  891. ath_rc_priv->probe_rate = 0;
  892. } else { /* xretries == 0 */
  893. count = ARRAY_SIZE(nretry_to_per_lookup);
  894. if (retries >= count)
  895. retries = count - 1;
  896. if (tx_info_priv->n_bad_frames) {
  897. /* new_PER = 7/8*old_PER + 1/8*(currentPER)
  898. * Assuming that n_frames is not 0. The current PER
  899. * from the retries is 100 * retries / (retries+1),
  900. * since the first retries attempts failed, and the
  901. * next one worked. For the one that worked,
  902. * n_bad_frames subframes out of n_frames wored,
  903. * so the PER for that part is
  904. * 100 * n_bad_frames / n_frames, and it contributes
  905. * 100 * n_bad_frames / (n_frames * (retries+1)) to
  906. * the above PER. The expression below is a
  907. * simplified version of the sum of these two terms.
  908. */
  909. if (tx_info_priv->n_frames > 0) {
  910. int n_frames, n_bad_frames;
  911. u8 cur_per, new_per;
  912. n_bad_frames = retries * tx_info_priv->n_frames +
  913. tx_info_priv->n_bad_frames;
  914. n_frames = tx_info_priv->n_frames * (retries + 1);
  915. cur_per = (100 * n_bad_frames / n_frames) >> 3;
  916. new_per = (u8)(last_per - (last_per >> 3) + cur_per);
  917. ath_rc_priv->state[tx_rate].per = new_per;
  918. }
  919. } else {
  920. ath_rc_priv->state[tx_rate].per =
  921. (u8)(last_per - (last_per >> 3) +
  922. (nretry_to_per_lookup[retries] >> 3));
  923. }
  924. ath_rc_priv->rssi_last_prev2 = ath_rc_priv->rssi_last_prev;
  925. ath_rc_priv->rssi_last_prev = ath_rc_priv->rssi_last;
  926. ath_rc_priv->rssi_last = tx_info_priv->tx.ts_rssi;
  927. ath_rc_priv->rssi_time = now_msec;
  928. /*
  929. * If we got at most one retry then increase the max rate if
  930. * this was a probe. Otherwise, ignore the probe.
  931. */
  932. if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
  933. if (retries > 0 || 2 * tx_info_priv->n_bad_frames >
  934. tx_info_priv->n_frames) {
  935. /*
  936. * Since we probed with just a single attempt,
  937. * any retries means the probe failed. Also,
  938. * if the attempt worked, but more than half
  939. * the subframes were bad then also consider
  940. * the probe a failure.
  941. */
  942. ath_rc_priv->probe_rate = 0;
  943. } else {
  944. u8 probe_rate = 0;
  945. ath_rc_priv->rate_max_phy =
  946. ath_rc_priv->probe_rate;
  947. probe_rate = ath_rc_priv->probe_rate;
  948. if (ath_rc_priv->state[probe_rate].per > 30)
  949. ath_rc_priv->state[probe_rate].per = 20;
  950. ath_rc_priv->probe_rate = 0;
  951. /*
  952. * Since this probe succeeded, we allow the next
  953. * probe twice as soon. This allows the maxRate
  954. * to move up faster if the probes are
  955. * succesful.
  956. */
  957. ath_rc_priv->probe_time =
  958. now_msec - rate_table->probe_interval / 2;
  959. }
  960. }
  961. if (retries > 0) {
  962. /*
  963. * Don't update anything. We don't know if
  964. * this was because of collisions or poor signal.
  965. *
  966. * Later: if rssi_ack is close to
  967. * ath_rc_priv->state[txRate].rssi_thres and we see lots
  968. * of retries, then we could increase
  969. * ath_rc_priv->state[txRate].rssi_thres.
  970. */
  971. ath_rc_priv->hw_maxretry_pktcnt = 0;
  972. } else {
  973. int32_t rssi_ackAvg;
  974. int8_t rssi_thres;
  975. int8_t rssi_ack_vmin;
  976. /*
  977. * It worked with no retries. First ignore bogus (small)
  978. * rssi_ack values.
  979. */
  980. if (tx_rate == ath_rc_priv->rate_max_phy &&
  981. ath_rc_priv->hw_maxretry_pktcnt < 255) {
  982. ath_rc_priv->hw_maxretry_pktcnt++;
  983. }
  984. if (tx_info_priv->tx.ts_rssi <
  985. rate_table->info[tx_rate].rssi_ack_validmin)
  986. goto exit;
  987. /* Average the rssi */
  988. if (tx_rate != ath_rc_priv->rssi_sum_rate) {
  989. ath_rc_priv->rssi_sum_rate = tx_rate;
  990. ath_rc_priv->rssi_sum =
  991. ath_rc_priv->rssi_sum_cnt = 0;
  992. }
  993. ath_rc_priv->rssi_sum += tx_info_priv->tx.ts_rssi;
  994. ath_rc_priv->rssi_sum_cnt++;
  995. if (ath_rc_priv->rssi_sum_cnt < 4)
  996. goto exit;
  997. rssi_ackAvg =
  998. (ath_rc_priv->rssi_sum + 2) / 4;
  999. rssi_thres =
  1000. ath_rc_priv->state[tx_rate].rssi_thres;
  1001. rssi_ack_vmin =
  1002. rate_table->info[tx_rate].rssi_ack_validmin;
  1003. ath_rc_priv->rssi_sum =
  1004. ath_rc_priv->rssi_sum_cnt = 0;
  1005. /* Now reduce the current rssi threshold */
  1006. if ((rssi_ackAvg < rssi_thres + 2) &&
  1007. (rssi_thres > rssi_ack_vmin)) {
  1008. ath_rc_priv->state[tx_rate].rssi_thres--;
  1009. }
  1010. state_change = true;
  1011. }
  1012. }
  1013. exit:
  1014. return state_change;
  1015. }
  1016. /* Update PER, RSSI and whatever else that the code thinks it is doing.
  1017. If you can make sense of all this, you really need to go out more. */
  1018. static void ath_rc_update_ht(struct ath_softc *sc,
  1019. struct ath_rate_priv *ath_rc_priv,
  1020. struct ath_tx_info_priv *tx_info_priv,
  1021. int tx_rate, int xretries, int retries)
  1022. {
  1023. #define CHK_RSSI(rate) \
  1024. ((ath_rc_priv->state[(rate)].rssi_thres + \
  1025. rate_table->info[(rate)].rssi_ack_deltamin) > \
  1026. ath_rc_priv->state[(rate)+1].rssi_thres)
  1027. u32 now_msec = jiffies_to_msecs(jiffies);
  1028. int rate;
  1029. u8 last_per;
  1030. bool state_change = false;
  1031. const struct ath_rate_table *rate_table = sc->cur_rate_table;
  1032. int size = ath_rc_priv->rate_table_size;
  1033. if ((tx_rate < 0) || (tx_rate > rate_table->rate_cnt))
  1034. return;
  1035. /* To compensate for some imbalance between ctrl and ext. channel */
  1036. if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy))
  1037. tx_info_priv->tx.ts_rssi =
  1038. tx_info_priv->tx.ts_rssi < 3 ? 0 :
  1039. tx_info_priv->tx.ts_rssi - 3;
  1040. last_per = ath_rc_priv->state[tx_rate].per;
  1041. /* Update PER first */
  1042. state_change = ath_rc_update_per(sc, rate_table, ath_rc_priv,
  1043. tx_info_priv, tx_rate, xretries,
  1044. retries, now_msec);
  1045. /*
  1046. * If this rate looks bad (high PER) then stop using it for
  1047. * a while (except if we are probing).
  1048. */
  1049. if (ath_rc_priv->state[tx_rate].per >= 55 && tx_rate > 0 &&
  1050. rate_table->info[tx_rate].ratekbps <=
  1051. rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
  1052. ath_rc_get_nextlowervalid_txrate(rate_table, ath_rc_priv,
  1053. (u8)tx_rate, &ath_rc_priv->rate_max_phy);
  1054. /* Don't probe for a little while. */
  1055. ath_rc_priv->probe_time = now_msec;
  1056. }
  1057. if (state_change) {
  1058. /*
  1059. * Make sure the rates above this have higher rssi thresholds.
  1060. * (Note: Monotonicity is kept within the OFDM rates and
  1061. * within the CCK rates. However, no adjustment is
  1062. * made to keep the rssi thresholds monotonically
  1063. * increasing between the CCK and OFDM rates.)
  1064. */
  1065. for (rate = tx_rate; rate < size - 1; rate++) {
  1066. if (rate_table->info[rate+1].phy !=
  1067. rate_table->info[tx_rate].phy)
  1068. break;
  1069. if (CHK_RSSI(rate)) {
  1070. ath_rc_priv->state[rate+1].rssi_thres =
  1071. ath_rc_priv->state[rate].rssi_thres +
  1072. rate_table->info[rate].rssi_ack_deltamin;
  1073. }
  1074. }
  1075. /* Make sure the rates below this have lower rssi thresholds. */
  1076. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1077. if (rate_table->info[rate].phy !=
  1078. rate_table->info[tx_rate].phy)
  1079. break;
  1080. if (CHK_RSSI(rate)) {
  1081. if (ath_rc_priv->state[rate+1].rssi_thres <
  1082. rate_table->info[rate].rssi_ack_deltamin)
  1083. ath_rc_priv->state[rate].rssi_thres = 0;
  1084. else {
  1085. ath_rc_priv->state[rate].rssi_thres =
  1086. ath_rc_priv->state[rate+1].rssi_thres -
  1087. rate_table->info[rate].rssi_ack_deltamin;
  1088. }
  1089. if (ath_rc_priv->state[rate].rssi_thres <
  1090. rate_table->info[rate].rssi_ack_validmin) {
  1091. ath_rc_priv->state[rate].rssi_thres =
  1092. rate_table->info[rate].rssi_ack_validmin;
  1093. }
  1094. }
  1095. }
  1096. }
  1097. /* Make sure the rates below this have lower PER */
  1098. /* Monotonicity is kept only for rates below the current rate. */
  1099. if (ath_rc_priv->state[tx_rate].per < last_per) {
  1100. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1101. if (rate_table->info[rate].phy !=
  1102. rate_table->info[tx_rate].phy)
  1103. break;
  1104. if (ath_rc_priv->state[rate].per >
  1105. ath_rc_priv->state[rate+1].per) {
  1106. ath_rc_priv->state[rate].per =
  1107. ath_rc_priv->state[rate+1].per;
  1108. }
  1109. }
  1110. }
  1111. /* Maintain monotonicity for rates above the current rate */
  1112. for (rate = tx_rate; rate < size - 1; rate++) {
  1113. if (ath_rc_priv->state[rate+1].per <
  1114. ath_rc_priv->state[rate].per)
  1115. ath_rc_priv->state[rate+1].per =
  1116. ath_rc_priv->state[rate].per;
  1117. }
  1118. /* Every so often, we reduce the thresholds and
  1119. * PER (different for CCK and OFDM). */
  1120. if (now_msec - ath_rc_priv->rssi_down_time >=
  1121. rate_table->rssi_reduce_interval) {
  1122. for (rate = 0; rate < size; rate++) {
  1123. if (ath_rc_priv->state[rate].rssi_thres >
  1124. rate_table->info[rate].rssi_ack_validmin)
  1125. ath_rc_priv->state[rate].rssi_thres -= 1;
  1126. }
  1127. ath_rc_priv->rssi_down_time = now_msec;
  1128. }
  1129. /* Every so often, we reduce the thresholds
  1130. * and PER (different for CCK and OFDM). */
  1131. if (now_msec - ath_rc_priv->per_down_time >=
  1132. rate_table->rssi_reduce_interval) {
  1133. for (rate = 0; rate < size; rate++) {
  1134. ath_rc_priv->state[rate].per =
  1135. 7 * ath_rc_priv->state[rate].per / 8;
  1136. }
  1137. ath_rc_priv->per_down_time = now_msec;
  1138. }
  1139. ath_debug_stat_retries(sc, tx_rate, xretries, retries,
  1140. ath_rc_priv->state[tx_rate].per);
  1141. #undef CHK_RSSI
  1142. }
  1143. static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
  1144. struct ieee80211_tx_rate *rate)
  1145. {
  1146. int rix;
  1147. if ((rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  1148. (rate->flags & IEEE80211_TX_RC_SHORT_GI))
  1149. rix = rate_table->info[rate->idx].ht_index;
  1150. else if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  1151. rix = rate_table->info[rate->idx].sgi_index;
  1152. else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  1153. rix = rate_table->info[rate->idx].cw40index;
  1154. else
  1155. rix = rate_table->info[rate->idx].base_index;
  1156. return rix;
  1157. }
  1158. static void ath_rc_tx_status(struct ath_softc *sc,
  1159. struct ath_rate_priv *ath_rc_priv,
  1160. struct ieee80211_tx_info *tx_info,
  1161. int final_ts_idx, int xretries, int long_retry)
  1162. {
  1163. struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
  1164. const struct ath_rate_table *rate_table;
  1165. struct ieee80211_tx_rate *rates = tx_info->status.rates;
  1166. u8 flags;
  1167. u32 i = 0, rix;
  1168. rate_table = sc->cur_rate_table;
  1169. /*
  1170. * If the first rate is not the final index, there
  1171. * are intermediate rate failures to be processed.
  1172. */
  1173. if (final_ts_idx != 0) {
  1174. /* Process intermediate rates that failed.*/
  1175. for (i = 0; i < final_ts_idx ; i++) {
  1176. if (rates[i].count != 0 && (rates[i].idx >= 0)) {
  1177. flags = rates[i].flags;
  1178. /* If HT40 and we have switched mode from
  1179. * 40 to 20 => don't update */
  1180. if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  1181. !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
  1182. return;
  1183. rix = ath_rc_get_rateindex(rate_table, &rates[i]);
  1184. ath_rc_update_ht(sc, ath_rc_priv,
  1185. tx_info_priv, rix,
  1186. xretries ? 1 : 2,
  1187. rates[i].count);
  1188. }
  1189. }
  1190. } else {
  1191. /*
  1192. * Handle the special case of MIMO PS burst, where the second
  1193. * aggregate is sent out with only one rate and one try.
  1194. * Treating it as an excessive retry penalizes the rate
  1195. * inordinately.
  1196. */
  1197. if (rates[0].count == 1 && xretries == 1)
  1198. xretries = 2;
  1199. }
  1200. flags = rates[i].flags;
  1201. /* If HT40 and we have switched mode from 40 to 20 => don't update */
  1202. if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
  1203. !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
  1204. return;
  1205. rix = ath_rc_get_rateindex(rate_table, &rates[i]);
  1206. ath_rc_update_ht(sc, ath_rc_priv, tx_info_priv, rix,
  1207. xretries, long_retry);
  1208. }
  1209. static const
  1210. struct ath_rate_table *ath_choose_rate_table(struct ath_softc *sc,
  1211. enum ieee80211_band band,
  1212. bool is_ht,
  1213. bool is_cw_40)
  1214. {
  1215. int mode = 0;
  1216. switch(band) {
  1217. case IEEE80211_BAND_2GHZ:
  1218. mode = ATH9K_MODE_11G;
  1219. if (is_ht)
  1220. mode = ATH9K_MODE_11NG_HT20;
  1221. if (is_cw_40)
  1222. mode = ATH9K_MODE_11NG_HT40PLUS;
  1223. break;
  1224. case IEEE80211_BAND_5GHZ:
  1225. mode = ATH9K_MODE_11A;
  1226. if (is_ht)
  1227. mode = ATH9K_MODE_11NA_HT20;
  1228. if (is_cw_40)
  1229. mode = ATH9K_MODE_11NA_HT40PLUS;
  1230. break;
  1231. default:
  1232. DPRINTF(sc, ATH_DBG_CONFIG, "Invalid band\n");
  1233. return NULL;
  1234. }
  1235. BUG_ON(mode >= ATH9K_MODE_MAX);
  1236. DPRINTF(sc, ATH_DBG_CONFIG, "Choosing rate table for mode: %d\n", mode);
  1237. return sc->hw_rate_table[mode];
  1238. }
  1239. static void ath_rc_init(struct ath_softc *sc,
  1240. struct ath_rate_priv *ath_rc_priv,
  1241. struct ieee80211_supported_band *sband,
  1242. struct ieee80211_sta *sta,
  1243. const struct ath_rate_table *rate_table)
  1244. {
  1245. struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
  1246. u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
  1247. u8 i, j, k, hi = 0, hthi = 0;
  1248. if (!rate_table) {
  1249. DPRINTF(sc, ATH_DBG_FATAL, "Rate table not initialized\n");
  1250. return;
  1251. }
  1252. /* Initial rate table size. Will change depending
  1253. * on the working rate set */
  1254. ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
  1255. /* Initialize thresholds according to the global rate table */
  1256. for (i = 0 ; i < ath_rc_priv->rate_table_size; i++) {
  1257. ath_rc_priv->state[i].rssi_thres =
  1258. rate_table->info[i].rssi_ack_validmin;
  1259. ath_rc_priv->state[i].per = 0;
  1260. }
  1261. /* Determine the valid rates */
  1262. ath_rc_init_valid_txmask(ath_rc_priv);
  1263. for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
  1264. for (j = 0; j < MAX_TX_RATE_PHY; j++)
  1265. ath_rc_priv->valid_phy_rateidx[i][j] = 0;
  1266. ath_rc_priv->valid_phy_ratecnt[i] = 0;
  1267. }
  1268. if (!rateset->rs_nrates) {
  1269. /* No working rate, just initialize valid rates */
  1270. hi = ath_rc_init_validrates(ath_rc_priv, rate_table,
  1271. ath_rc_priv->ht_cap);
  1272. } else {
  1273. /* Use intersection of working rates and valid rates */
  1274. hi = ath_rc_setvalid_rates(ath_rc_priv, rate_table,
  1275. rateset, ath_rc_priv->ht_cap);
  1276. if (ath_rc_priv->ht_cap & WLAN_RC_HT_FLAG) {
  1277. hthi = ath_rc_setvalid_htrates(ath_rc_priv,
  1278. rate_table,
  1279. ht_mcs,
  1280. ath_rc_priv->ht_cap);
  1281. }
  1282. hi = A_MAX(hi, hthi);
  1283. }
  1284. ath_rc_priv->rate_table_size = hi + 1;
  1285. ath_rc_priv->rate_max_phy = 0;
  1286. ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
  1287. for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
  1288. for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
  1289. ath_rc_priv->valid_rate_index[k++] =
  1290. ath_rc_priv->valid_phy_rateidx[i][j];
  1291. }
  1292. if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, 1)
  1293. || !ath_rc_priv->valid_phy_ratecnt[i])
  1294. continue;
  1295. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
  1296. }
  1297. ASSERT(ath_rc_priv->rate_table_size <= RATE_TABLE_SIZE);
  1298. ASSERT(k <= RATE_TABLE_SIZE);
  1299. ath_rc_priv->max_valid_rate = k;
  1300. ath_rc_sort_validrates(rate_table, ath_rc_priv);
  1301. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
  1302. sc->cur_rate_table = rate_table;
  1303. DPRINTF(sc, ATH_DBG_CONFIG, "RC Initialized with capabilities: 0x%x\n",
  1304. ath_rc_priv->ht_cap);
  1305. }
  1306. static u8 ath_rc_build_ht_caps(struct ath_softc *sc, struct ieee80211_sta *sta,
  1307. bool is_cw40, bool is_sgi40)
  1308. {
  1309. u8 caps = 0;
  1310. if (sta->ht_cap.ht_supported) {
  1311. caps = WLAN_RC_HT_FLAG;
  1312. if (sc->sc_ah->caps.tx_chainmask != 1 &&
  1313. ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_DS, 0, NULL)) {
  1314. if (sta->ht_cap.mcs.rx_mask[1])
  1315. caps |= WLAN_RC_DS_FLAG;
  1316. }
  1317. if (is_cw40)
  1318. caps |= WLAN_RC_40_FLAG;
  1319. if (is_sgi40)
  1320. caps |= WLAN_RC_SGI_FLAG;
  1321. }
  1322. return caps;
  1323. }
  1324. /***********************************/
  1325. /* mac80211 Rate Control callbacks */
  1326. /***********************************/
  1327. static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
  1328. struct ieee80211_sta *sta, void *priv_sta,
  1329. struct sk_buff *skb)
  1330. {
  1331. struct ath_softc *sc = priv;
  1332. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1333. struct ath_tx_info_priv *tx_info_priv = NULL;
  1334. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1335. struct ieee80211_hdr *hdr;
  1336. int final_ts_idx, tx_status = 0, is_underrun = 0;
  1337. __le16 fc;
  1338. hdr = (struct ieee80211_hdr *)skb->data;
  1339. fc = hdr->frame_control;
  1340. tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
  1341. final_ts_idx = tx_info_priv->tx.ts_rateindex;
  1342. if (!priv_sta || !ieee80211_is_data(fc) ||
  1343. !tx_info_priv->update_rc)
  1344. goto exit;
  1345. if (tx_info_priv->tx.ts_status & ATH9K_TXERR_FILT)
  1346. goto exit;
  1347. /*
  1348. * If underrun error is seen assume it as an excessive retry only
  1349. * if prefetch trigger level have reached the max (0x3f for 5416)
  1350. * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY
  1351. * times. This affects how ratectrl updates PER for the failed rate.
  1352. */
  1353. if (tx_info_priv->tx.ts_flags &
  1354. (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
  1355. ((sc->sc_ah->tx_trig_level) >= ath_rc_priv->tx_triglevel_max)) {
  1356. tx_status = 1;
  1357. is_underrun = 1;
  1358. }
  1359. if ((tx_info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
  1360. (tx_info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
  1361. tx_status = 1;
  1362. ath_rc_tx_status(sc, ath_rc_priv, tx_info, final_ts_idx, tx_status,
  1363. (is_underrun) ? ATH_11N_TXMAXTRY :
  1364. tx_info_priv->tx.ts_longretry);
  1365. /* Check if aggregation has to be enabled for this tid */
  1366. if (conf_is_ht(&sc->hw->conf) &&
  1367. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  1368. if (ieee80211_is_data_qos(fc)) {
  1369. u8 *qc, tid;
  1370. struct ath_node *an;
  1371. qc = ieee80211_get_qos_ctl(hdr);
  1372. tid = qc[0] & 0xf;
  1373. an = (struct ath_node *)sta->drv_priv;
  1374. if(ath_tx_aggr_check(sc, an, tid))
  1375. ieee80211_start_tx_ba_session(sc->hw, hdr->addr1, tid);
  1376. }
  1377. }
  1378. ath_debug_stat_rc(sc, skb);
  1379. exit:
  1380. kfree(tx_info_priv);
  1381. }
  1382. static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
  1383. struct ieee80211_tx_rate_control *txrc)
  1384. {
  1385. struct ieee80211_supported_band *sband = txrc->sband;
  1386. struct sk_buff *skb = txrc->skb;
  1387. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1388. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1389. struct ath_softc *sc = priv;
  1390. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1391. __le16 fc = hdr->frame_control;
  1392. /* lowest rate for management and NO_ACK frames */
  1393. if (!ieee80211_is_data(fc) ||
  1394. tx_info->flags & IEEE80211_TX_CTL_NO_ACK || !sta) {
  1395. tx_info->control.rates[0].idx = rate_lowest_index(sband, sta);
  1396. tx_info->control.rates[0].count =
  1397. (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) ?
  1398. 1 : ATH_MGT_TXMAXTRY;
  1399. return;
  1400. }
  1401. /* Find tx rate for unicast frames */
  1402. ath_rc_ratefind(sc, ath_rc_priv, txrc);
  1403. }
  1404. static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
  1405. struct ieee80211_sta *sta, void *priv_sta)
  1406. {
  1407. struct ath_softc *sc = priv;
  1408. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1409. const struct ath_rate_table *rate_table = NULL;
  1410. bool is_cw40, is_sgi40;
  1411. int i, j = 0;
  1412. for (i = 0; i < sband->n_bitrates; i++) {
  1413. if (sta->supp_rates[sband->band] & BIT(i)) {
  1414. ath_rc_priv->neg_rates.rs_rates[j]
  1415. = (sband->bitrates[i].bitrate * 2) / 10;
  1416. j++;
  1417. }
  1418. }
  1419. ath_rc_priv->neg_rates.rs_nrates = j;
  1420. if (sta->ht_cap.ht_supported) {
  1421. for (i = 0, j = 0; i < 77; i++) {
  1422. if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
  1423. ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
  1424. if (j == ATH_RATE_MAX)
  1425. break;
  1426. }
  1427. ath_rc_priv->neg_ht_rates.rs_nrates = j;
  1428. }
  1429. is_cw40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1430. is_sgi40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  1431. /* Choose rate table first */
  1432. if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) ||
  1433. (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT) ||
  1434. (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)) {
  1435. rate_table = ath_choose_rate_table(sc, sband->band,
  1436. sta->ht_cap.ht_supported,
  1437. is_cw40);
  1438. } else if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
  1439. /* cur_rate_table would be set on init through config() */
  1440. rate_table = sc->cur_rate_table;
  1441. }
  1442. ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta, is_cw40, is_sgi40);
  1443. ath_rc_init(sc, priv_sta, sband, sta, rate_table);
  1444. }
  1445. static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
  1446. struct ieee80211_sta *sta, void *priv_sta,
  1447. u32 changed)
  1448. {
  1449. struct ath_softc *sc = priv;
  1450. struct ath_rate_priv *ath_rc_priv = priv_sta;
  1451. const struct ath_rate_table *rate_table = NULL;
  1452. bool oper_cw40 = false, oper_sgi40;
  1453. bool local_cw40 = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG) ?
  1454. true : false;
  1455. bool local_sgi40 = (ath_rc_priv->ht_cap & WLAN_RC_SGI_FLAG) ?
  1456. true : false;
  1457. /* FIXME: Handle AP mode later when we support CWM */
  1458. if (changed & IEEE80211_RC_HT_CHANGED) {
  1459. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1460. return;
  1461. if (sc->hw->conf.channel_type == NL80211_CHAN_HT40MINUS ||
  1462. sc->hw->conf.channel_type == NL80211_CHAN_HT40PLUS)
  1463. oper_cw40 = true;
  1464. oper_sgi40 = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1465. true : false;
  1466. if ((local_cw40 != oper_cw40) || (local_sgi40 != oper_sgi40)) {
  1467. rate_table = ath_choose_rate_table(sc, sband->band,
  1468. sta->ht_cap.ht_supported,
  1469. oper_cw40);
  1470. ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta,
  1471. oper_cw40, oper_sgi40);
  1472. ath_rc_init(sc, priv_sta, sband, sta, rate_table);
  1473. DPRINTF(sc, ATH_DBG_CONFIG,
  1474. "Operating HT Bandwidth changed to: %d\n",
  1475. sc->hw->conf.channel_type);
  1476. }
  1477. }
  1478. }
  1479. static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  1480. {
  1481. struct ath_wiphy *aphy = hw->priv;
  1482. return aphy->sc;
  1483. }
  1484. static void ath_rate_free(void *priv)
  1485. {
  1486. return;
  1487. }
  1488. static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
  1489. {
  1490. struct ath_softc *sc = priv;
  1491. struct ath_rate_priv *rate_priv;
  1492. rate_priv = kzalloc(sizeof(struct ath_rate_priv), gfp);
  1493. if (!rate_priv) {
  1494. DPRINTF(sc, ATH_DBG_FATAL,
  1495. "Unable to allocate private rc structure\n");
  1496. return NULL;
  1497. }
  1498. rate_priv->rssi_down_time = jiffies_to_msecs(jiffies);
  1499. rate_priv->tx_triglevel_max = sc->sc_ah->caps.tx_triglevel_max;
  1500. return rate_priv;
  1501. }
  1502. static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
  1503. void *priv_sta)
  1504. {
  1505. struct ath_rate_priv *rate_priv = priv_sta;
  1506. kfree(rate_priv);
  1507. }
  1508. static struct rate_control_ops ath_rate_ops = {
  1509. .module = NULL,
  1510. .name = "ath9k_rate_control",
  1511. .tx_status = ath_tx_status,
  1512. .get_rate = ath_get_rate,
  1513. .rate_init = ath_rate_init,
  1514. .rate_update = ath_rate_update,
  1515. .alloc = ath_rate_alloc,
  1516. .free = ath_rate_free,
  1517. .alloc_sta = ath_rate_alloc_sta,
  1518. .free_sta = ath_rate_free_sta,
  1519. };
  1520. void ath_rate_attach(struct ath_softc *sc)
  1521. {
  1522. sc->hw_rate_table[ATH9K_MODE_11B] =
  1523. &ar5416_11b_ratetable;
  1524. sc->hw_rate_table[ATH9K_MODE_11A] =
  1525. &ar5416_11a_ratetable;
  1526. sc->hw_rate_table[ATH9K_MODE_11G] =
  1527. &ar5416_11g_ratetable;
  1528. sc->hw_rate_table[ATH9K_MODE_11NA_HT20] =
  1529. &ar5416_11na_ratetable;
  1530. sc->hw_rate_table[ATH9K_MODE_11NG_HT20] =
  1531. &ar5416_11ng_ratetable;
  1532. sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
  1533. &ar5416_11na_ratetable;
  1534. sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
  1535. &ar5416_11na_ratetable;
  1536. sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
  1537. &ar5416_11ng_ratetable;
  1538. sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
  1539. &ar5416_11ng_ratetable;
  1540. }
  1541. int ath_rate_control_register(void)
  1542. {
  1543. return ieee80211_rate_control_register(&ath_rate_ops);
  1544. }
  1545. void ath_rate_control_unregister(void)
  1546. {
  1547. ieee80211_rate_control_unregister(&ath_rate_ops);
  1548. }