rc.c 50 KB

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