rc.c 45 KB

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