base.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2009-2012 Realtek Corporation.*/
  3. #include "wifi.h"
  4. #include "rc.h"
  5. #include "base.h"
  6. #include "efuse.h"
  7. #include "cam.h"
  8. #include "ps.h"
  9. #include "regd.h"
  10. #include "pci.h"
  11. #include <linux/ip.h>
  12. #include <linux/module.h>
  13. #include <linux/udp.h>
  14. /*
  15. *NOTICE!!!: This file will be very big, we should
  16. *keep it clear under following roles:
  17. *
  18. *This file include following parts, so, if you add new
  19. *functions into this file, please check which part it
  20. *should includes. or check if you should add new part
  21. *for this file:
  22. *
  23. *1) mac80211 init functions
  24. *2) tx information functions
  25. *3) functions called by core.c
  26. *4) wq & timer callback functions
  27. *5) frame process functions
  28. *6) IOT functions
  29. *7) sysfs functions
  30. *8) vif functions
  31. *9) ...
  32. */
  33. /*********************************************************
  34. *
  35. * mac80211 init functions
  36. *
  37. *********************************************************/
  38. static struct ieee80211_channel rtl_channeltable_2g[] = {
  39. {.center_freq = 2412, .hw_value = 1,},
  40. {.center_freq = 2417, .hw_value = 2,},
  41. {.center_freq = 2422, .hw_value = 3,},
  42. {.center_freq = 2427, .hw_value = 4,},
  43. {.center_freq = 2432, .hw_value = 5,},
  44. {.center_freq = 2437, .hw_value = 6,},
  45. {.center_freq = 2442, .hw_value = 7,},
  46. {.center_freq = 2447, .hw_value = 8,},
  47. {.center_freq = 2452, .hw_value = 9,},
  48. {.center_freq = 2457, .hw_value = 10,},
  49. {.center_freq = 2462, .hw_value = 11,},
  50. {.center_freq = 2467, .hw_value = 12,},
  51. {.center_freq = 2472, .hw_value = 13,},
  52. {.center_freq = 2484, .hw_value = 14,},
  53. };
  54. static struct ieee80211_channel rtl_channeltable_5g[] = {
  55. {.center_freq = 5180, .hw_value = 36,},
  56. {.center_freq = 5200, .hw_value = 40,},
  57. {.center_freq = 5220, .hw_value = 44,},
  58. {.center_freq = 5240, .hw_value = 48,},
  59. {.center_freq = 5260, .hw_value = 52,},
  60. {.center_freq = 5280, .hw_value = 56,},
  61. {.center_freq = 5300, .hw_value = 60,},
  62. {.center_freq = 5320, .hw_value = 64,},
  63. {.center_freq = 5500, .hw_value = 100,},
  64. {.center_freq = 5520, .hw_value = 104,},
  65. {.center_freq = 5540, .hw_value = 108,},
  66. {.center_freq = 5560, .hw_value = 112,},
  67. {.center_freq = 5580, .hw_value = 116,},
  68. {.center_freq = 5600, .hw_value = 120,},
  69. {.center_freq = 5620, .hw_value = 124,},
  70. {.center_freq = 5640, .hw_value = 128,},
  71. {.center_freq = 5660, .hw_value = 132,},
  72. {.center_freq = 5680, .hw_value = 136,},
  73. {.center_freq = 5700, .hw_value = 140,},
  74. {.center_freq = 5745, .hw_value = 149,},
  75. {.center_freq = 5765, .hw_value = 153,},
  76. {.center_freq = 5785, .hw_value = 157,},
  77. {.center_freq = 5805, .hw_value = 161,},
  78. {.center_freq = 5825, .hw_value = 165,},
  79. };
  80. static struct ieee80211_rate rtl_ratetable_2g[] = {
  81. {.bitrate = 10, .hw_value = 0x00,},
  82. {.bitrate = 20, .hw_value = 0x01,},
  83. {.bitrate = 55, .hw_value = 0x02,},
  84. {.bitrate = 110, .hw_value = 0x03,},
  85. {.bitrate = 60, .hw_value = 0x04,},
  86. {.bitrate = 90, .hw_value = 0x05,},
  87. {.bitrate = 120, .hw_value = 0x06,},
  88. {.bitrate = 180, .hw_value = 0x07,},
  89. {.bitrate = 240, .hw_value = 0x08,},
  90. {.bitrate = 360, .hw_value = 0x09,},
  91. {.bitrate = 480, .hw_value = 0x0a,},
  92. {.bitrate = 540, .hw_value = 0x0b,},
  93. };
  94. static struct ieee80211_rate rtl_ratetable_5g[] = {
  95. {.bitrate = 60, .hw_value = 0x04,},
  96. {.bitrate = 90, .hw_value = 0x05,},
  97. {.bitrate = 120, .hw_value = 0x06,},
  98. {.bitrate = 180, .hw_value = 0x07,},
  99. {.bitrate = 240, .hw_value = 0x08,},
  100. {.bitrate = 360, .hw_value = 0x09,},
  101. {.bitrate = 480, .hw_value = 0x0a,},
  102. {.bitrate = 540, .hw_value = 0x0b,},
  103. };
  104. static const struct ieee80211_supported_band rtl_band_2ghz = {
  105. .band = NL80211_BAND_2GHZ,
  106. .channels = rtl_channeltable_2g,
  107. .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
  108. .bitrates = rtl_ratetable_2g,
  109. .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
  110. .ht_cap = {0},
  111. };
  112. static struct ieee80211_supported_band rtl_band_5ghz = {
  113. .band = NL80211_BAND_5GHZ,
  114. .channels = rtl_channeltable_5g,
  115. .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
  116. .bitrates = rtl_ratetable_5g,
  117. .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
  118. .ht_cap = {0},
  119. };
  120. static const u8 tid_to_ac[] = {
  121. 2, /* IEEE80211_AC_BE */
  122. 3, /* IEEE80211_AC_BK */
  123. 3, /* IEEE80211_AC_BK */
  124. 2, /* IEEE80211_AC_BE */
  125. 1, /* IEEE80211_AC_VI */
  126. 1, /* IEEE80211_AC_VI */
  127. 0, /* IEEE80211_AC_VO */
  128. 0, /* IEEE80211_AC_VO */
  129. };
  130. u8 rtl_tid_to_ac(u8 tid)
  131. {
  132. return tid_to_ac[tid];
  133. }
  134. EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
  135. static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
  136. struct ieee80211_sta_ht_cap *ht_cap)
  137. {
  138. struct rtl_priv *rtlpriv = rtl_priv(hw);
  139. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  140. ht_cap->ht_supported = true;
  141. ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  142. IEEE80211_HT_CAP_SGI_40 |
  143. IEEE80211_HT_CAP_SGI_20 |
  144. IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
  145. if (rtlpriv->rtlhal.disable_amsdu_8k)
  146. ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  147. /*
  148. *Maximum length of AMPDU that the STA can receive.
  149. *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  150. */
  151. ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  152. /*Minimum MPDU start spacing , */
  153. ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  154. ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  155. /*hw->wiphy->bands[NL80211_BAND_2GHZ]
  156. *base on ant_num
  157. *rx_mask: RX mask
  158. *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
  159. *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
  160. *if rx_ant >= 3 rx_mask[2]= 0xff;
  161. *if BW_40 rx_mask[4]= 0x01;
  162. *highest supported RX rate
  163. */
  164. if (rtlpriv->dm.supp_phymode_switch) {
  165. pr_info("Support phy mode switch\n");
  166. ht_cap->mcs.rx_mask[0] = 0xFF;
  167. ht_cap->mcs.rx_mask[1] = 0xFF;
  168. ht_cap->mcs.rx_mask[4] = 0x01;
  169. ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
  170. } else {
  171. if (get_rf_type(rtlphy) == RF_1T2R ||
  172. get_rf_type(rtlphy) == RF_2T2R) {
  173. rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
  174. "1T2R or 2T2R\n");
  175. ht_cap->mcs.rx_mask[0] = 0xFF;
  176. ht_cap->mcs.rx_mask[1] = 0xFF;
  177. ht_cap->mcs.rx_mask[4] = 0x01;
  178. ht_cap->mcs.rx_highest =
  179. cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
  180. } else if (get_rf_type(rtlphy) == RF_1T1R) {
  181. rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
  182. ht_cap->mcs.rx_mask[0] = 0xFF;
  183. ht_cap->mcs.rx_mask[1] = 0x00;
  184. ht_cap->mcs.rx_mask[4] = 0x01;
  185. ht_cap->mcs.rx_highest =
  186. cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
  187. }
  188. }
  189. }
  190. static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
  191. struct ieee80211_sta_vht_cap *vht_cap)
  192. {
  193. struct rtl_priv *rtlpriv = rtl_priv(hw);
  194. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  195. if (!(rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT))
  196. return;
  197. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE ||
  198. rtlhal->hw_type == HARDWARE_TYPE_RTL8822BE) {
  199. u16 mcs_map;
  200. vht_cap->vht_supported = true;
  201. vht_cap->cap =
  202. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  203. IEEE80211_VHT_CAP_SHORT_GI_80 |
  204. IEEE80211_VHT_CAP_TXSTBC |
  205. IEEE80211_VHT_CAP_RXSTBC_1 |
  206. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  207. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  208. IEEE80211_VHT_CAP_HTC_VHT |
  209. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  210. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  211. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  212. 0;
  213. mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  214. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  215. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  216. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  217. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  218. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  219. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  220. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
  221. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  222. vht_cap->vht_mcs.rx_highest =
  223. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
  224. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  225. vht_cap->vht_mcs.tx_highest =
  226. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
  227. } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
  228. u16 mcs_map;
  229. vht_cap->vht_supported = true;
  230. vht_cap->cap =
  231. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  232. IEEE80211_VHT_CAP_SHORT_GI_80 |
  233. IEEE80211_VHT_CAP_TXSTBC |
  234. IEEE80211_VHT_CAP_RXSTBC_1 |
  235. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  236. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  237. IEEE80211_VHT_CAP_HTC_VHT |
  238. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  239. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  240. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  241. 0;
  242. mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  243. IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
  244. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  245. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  246. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  247. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  248. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  249. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
  250. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  251. vht_cap->vht_mcs.rx_highest =
  252. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
  253. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  254. vht_cap->vht_mcs.tx_highest =
  255. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
  256. }
  257. }
  258. static void _rtl_init_mac80211(struct ieee80211_hw *hw)
  259. {
  260. struct rtl_priv *rtlpriv = rtl_priv(hw);
  261. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  262. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  263. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  264. struct ieee80211_supported_band *sband;
  265. if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
  266. rtlhal->bandset == BAND_ON_BOTH) {
  267. /* 1: 2.4 G bands */
  268. /* <1> use mac->bands as mem for hw->wiphy->bands */
  269. sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
  270. /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
  271. * to default value(1T1R) */
  272. memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz,
  273. sizeof(struct ieee80211_supported_band));
  274. /* <3> init ht cap base on ant_num */
  275. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  276. /* <4> set mac->sband to wiphy->sband */
  277. hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
  278. /* 2: 5 G bands */
  279. /* <1> use mac->bands as mem for hw->wiphy->bands */
  280. sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
  281. /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
  282. * to default value(1T1R) */
  283. memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz,
  284. sizeof(struct ieee80211_supported_band));
  285. /* <3> init ht cap base on ant_num */
  286. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  287. _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
  288. /* <4> set mac->sband to wiphy->sband */
  289. hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
  290. } else {
  291. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  292. /* <1> use mac->bands as mem for hw->wiphy->bands */
  293. sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
  294. /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
  295. * to default value(1T1R) */
  296. memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]),
  297. &rtl_band_2ghz,
  298. sizeof(struct ieee80211_supported_band));
  299. /* <3> init ht cap base on ant_num */
  300. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  301. /* <4> set mac->sband to wiphy->sband */
  302. hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
  303. } else if (rtlhal->current_bandtype == BAND_ON_5G) {
  304. /* <1> use mac->bands as mem for hw->wiphy->bands */
  305. sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
  306. /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
  307. * to default value(1T1R) */
  308. memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]),
  309. &rtl_band_5ghz,
  310. sizeof(struct ieee80211_supported_band));
  311. /* <3> init ht cap base on ant_num */
  312. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  313. _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
  314. /* <4> set mac->sband to wiphy->sband */
  315. hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
  316. } else {
  317. pr_err("Err BAND %d\n",
  318. rtlhal->current_bandtype);
  319. }
  320. }
  321. /* <5> set hw caps */
  322. ieee80211_hw_set(hw, SIGNAL_DBM);
  323. ieee80211_hw_set(hw, RX_INCLUDES_FCS);
  324. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  325. ieee80211_hw_set(hw, MFP_CAPABLE);
  326. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  327. ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
  328. ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
  329. /* swlps or hwlps has been set in diff chip in init_sw_vars */
  330. if (rtlpriv->psc.swctrl_lps) {
  331. ieee80211_hw_set(hw, SUPPORTS_PS);
  332. ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
  333. }
  334. if (rtlpriv->psc.fwctrl_lps) {
  335. ieee80211_hw_set(hw, SUPPORTS_PS);
  336. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  337. }
  338. hw->wiphy->interface_modes =
  339. BIT(NL80211_IFTYPE_AP) |
  340. BIT(NL80211_IFTYPE_STATION) |
  341. BIT(NL80211_IFTYPE_ADHOC) |
  342. BIT(NL80211_IFTYPE_MESH_POINT) |
  343. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  344. BIT(NL80211_IFTYPE_P2P_GO);
  345. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  346. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  347. hw->wiphy->rts_threshold = 2347;
  348. hw->queues = AC_MAX;
  349. hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
  350. /* TODO: Correct this value for our hw */
  351. hw->max_listen_interval = MAX_LISTEN_INTERVAL;
  352. hw->max_rate_tries = MAX_RATE_TRIES;
  353. /* hw->max_rates = 1; */
  354. hw->sta_data_size = sizeof(struct rtl_sta_info);
  355. /* wowlan is not supported by kernel if CONFIG_PM is not defined */
  356. #ifdef CONFIG_PM
  357. if (rtlpriv->psc.wo_wlan_mode) {
  358. if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
  359. rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
  360. if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
  361. rtlpriv->wowlan.n_patterns =
  362. MAX_SUPPORT_WOL_PATTERN_NUM;
  363. rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
  364. rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
  365. }
  366. hw->wiphy->wowlan = &rtlpriv->wowlan;
  367. }
  368. #endif
  369. /* <6> mac address */
  370. if (is_valid_ether_addr(rtlefuse->dev_addr)) {
  371. SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
  372. } else {
  373. u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
  374. get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
  375. SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
  376. }
  377. }
  378. static void rtl_watchdog_wq_callback(struct work_struct *work);
  379. static void rtl_fwevt_wq_callback(struct work_struct *work);
  380. static void rtl_c2hcmd_wq_callback(struct work_struct *work);
  381. static int _rtl_init_deferred_work(struct ieee80211_hw *hw)
  382. {
  383. struct rtl_priv *rtlpriv = rtl_priv(hw);
  384. struct workqueue_struct *wq;
  385. wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
  386. if (!wq)
  387. return -ENOMEM;
  388. /* <1> timer */
  389. timer_setup(&rtlpriv->works.watchdog_timer,
  390. rtl_watch_dog_timer_callback, 0);
  391. /* <2> work queue */
  392. rtlpriv->works.hw = hw;
  393. rtlpriv->works.rtl_wq = wq;
  394. INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
  395. rtl_watchdog_wq_callback);
  396. INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
  397. rtl_ips_nic_off_wq_callback);
  398. INIT_DELAYED_WORK(&rtlpriv->works.ps_work, rtl_swlps_wq_callback);
  399. INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
  400. rtl_swlps_rfon_wq_callback);
  401. INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, rtl_fwevt_wq_callback);
  402. INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq, rtl_c2hcmd_wq_callback);
  403. return 0;
  404. }
  405. void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq)
  406. {
  407. struct rtl_priv *rtlpriv = rtl_priv(hw);
  408. del_timer_sync(&rtlpriv->works.watchdog_timer);
  409. cancel_delayed_work_sync(&rtlpriv->works.watchdog_wq);
  410. if (ips_wq)
  411. cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
  412. else
  413. cancel_delayed_work_sync(&rtlpriv->works.ips_nic_off_wq);
  414. cancel_delayed_work_sync(&rtlpriv->works.ps_work);
  415. cancel_delayed_work_sync(&rtlpriv->works.ps_rfon_wq);
  416. cancel_delayed_work_sync(&rtlpriv->works.fwevt_wq);
  417. cancel_delayed_work_sync(&rtlpriv->works.c2hcmd_wq);
  418. }
  419. EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
  420. void rtl_init_rfkill(struct ieee80211_hw *hw)
  421. {
  422. struct rtl_priv *rtlpriv = rtl_priv(hw);
  423. bool radio_state;
  424. bool blocked;
  425. u8 valid = 0;
  426. /*set init state to on */
  427. rtlpriv->rfkill.rfkill_state = true;
  428. wiphy_rfkill_set_hw_state(hw->wiphy, 0);
  429. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  430. if (valid) {
  431. pr_info("rtlwifi: wireless switch is %s\n",
  432. rtlpriv->rfkill.rfkill_state ? "on" : "off");
  433. rtlpriv->rfkill.rfkill_state = radio_state;
  434. blocked = rtlpriv->rfkill.rfkill_state != 1;
  435. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  436. }
  437. wiphy_rfkill_start_polling(hw->wiphy);
  438. }
  439. EXPORT_SYMBOL(rtl_init_rfkill);
  440. void rtl_deinit_rfkill(struct ieee80211_hw *hw)
  441. {
  442. wiphy_rfkill_stop_polling(hw->wiphy);
  443. }
  444. EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
  445. int rtl_init_core(struct ieee80211_hw *hw)
  446. {
  447. struct rtl_priv *rtlpriv = rtl_priv(hw);
  448. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  449. /* <1> init mac80211 */
  450. _rtl_init_mac80211(hw);
  451. rtlmac->hw = hw;
  452. /* <2> rate control register */
  453. hw->rate_control_algorithm = "rtl_rc";
  454. /*
  455. * <3> init CRDA must come after init
  456. * mac80211 hw in _rtl_init_mac80211.
  457. */
  458. if (rtl_regd_init(hw, rtl_reg_notifier)) {
  459. pr_err("REGD init failed\n");
  460. return 1;
  461. }
  462. /* <4> locks */
  463. mutex_init(&rtlpriv->locks.conf_mutex);
  464. mutex_init(&rtlpriv->locks.ips_mutex);
  465. mutex_init(&rtlpriv->locks.lps_mutex);
  466. spin_lock_init(&rtlpriv->locks.irq_th_lock);
  467. spin_lock_init(&rtlpriv->locks.h2c_lock);
  468. spin_lock_init(&rtlpriv->locks.rf_ps_lock);
  469. spin_lock_init(&rtlpriv->locks.rf_lock);
  470. spin_lock_init(&rtlpriv->locks.waitq_lock);
  471. spin_lock_init(&rtlpriv->locks.entry_list_lock);
  472. spin_lock_init(&rtlpriv->locks.scan_list_lock);
  473. spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
  474. spin_lock_init(&rtlpriv->locks.fw_ps_lock);
  475. spin_lock_init(&rtlpriv->locks.iqk_lock);
  476. /* <5> init list */
  477. INIT_LIST_HEAD(&rtlpriv->entry_list);
  478. INIT_LIST_HEAD(&rtlpriv->scan_list.list);
  479. skb_queue_head_init(&rtlpriv->tx_report.queue);
  480. skb_queue_head_init(&rtlpriv->c2hcmd_queue);
  481. rtlmac->link_state = MAC80211_NOLINK;
  482. /* <6> init deferred work */
  483. return _rtl_init_deferred_work(hw);
  484. }
  485. EXPORT_SYMBOL_GPL(rtl_init_core);
  486. static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
  487. static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw,
  488. bool timeout);
  489. void rtl_deinit_core(struct ieee80211_hw *hw)
  490. {
  491. struct rtl_priv *rtlpriv = rtl_priv(hw);
  492. rtl_c2hcmd_launcher(hw, 0);
  493. rtl_free_entries_from_scan_list(hw);
  494. rtl_free_entries_from_ack_queue(hw, false);
  495. if (rtlpriv->works.rtl_wq) {
  496. destroy_workqueue(rtlpriv->works.rtl_wq);
  497. rtlpriv->works.rtl_wq = NULL;
  498. }
  499. }
  500. EXPORT_SYMBOL_GPL(rtl_deinit_core);
  501. void rtl_init_rx_config(struct ieee80211_hw *hw)
  502. {
  503. struct rtl_priv *rtlpriv = rtl_priv(hw);
  504. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  505. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
  506. }
  507. EXPORT_SYMBOL_GPL(rtl_init_rx_config);
  508. /*********************************************************
  509. *
  510. * tx information functions
  511. *
  512. *********************************************************/
  513. static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
  514. struct rtl_tcb_desc *tcb_desc,
  515. struct ieee80211_tx_info *info)
  516. {
  517. struct rtl_priv *rtlpriv = rtl_priv(hw);
  518. u8 rate_flag = info->control.rates[0].flags;
  519. tcb_desc->use_shortpreamble = false;
  520. /* 1M can only use Long Preamble. 11B spec */
  521. if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
  522. return;
  523. else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  524. tcb_desc->use_shortpreamble = true;
  525. return;
  526. }
  527. static void _rtl_query_shortgi(struct ieee80211_hw *hw,
  528. struct ieee80211_sta *sta,
  529. struct rtl_tcb_desc *tcb_desc,
  530. struct ieee80211_tx_info *info)
  531. {
  532. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  533. u8 rate_flag = info->control.rates[0].flags;
  534. u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
  535. u8 sgi_80 = 0, bw_80 = 0;
  536. tcb_desc->use_shortgi = false;
  537. if (sta == NULL)
  538. return;
  539. sgi_40 = sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  540. sgi_20 = sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
  541. sgi_80 = sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
  542. if (!sta->deflink.ht_cap.ht_supported &&
  543. !sta->deflink.vht_cap.vht_supported)
  544. return;
  545. if (!sgi_40 && !sgi_20)
  546. return;
  547. if (mac->opmode == NL80211_IFTYPE_STATION) {
  548. bw_40 = mac->bw_40;
  549. bw_80 = mac->bw_80;
  550. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  551. mac->opmode == NL80211_IFTYPE_ADHOC ||
  552. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  553. bw_40 = sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  554. bw_80 = sta->deflink.vht_cap.vht_supported;
  555. }
  556. if (bw_80) {
  557. if (sgi_80)
  558. tcb_desc->use_shortgi = true;
  559. else
  560. tcb_desc->use_shortgi = false;
  561. } else {
  562. if (bw_40 && sgi_40)
  563. tcb_desc->use_shortgi = true;
  564. else if (!bw_40 && sgi_20)
  565. tcb_desc->use_shortgi = true;
  566. }
  567. if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
  568. tcb_desc->use_shortgi = false;
  569. }
  570. static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
  571. struct rtl_tcb_desc *tcb_desc,
  572. struct ieee80211_tx_info *info)
  573. {
  574. struct rtl_priv *rtlpriv = rtl_priv(hw);
  575. u8 rate_flag = info->control.rates[0].flags;
  576. /* Common Settings */
  577. tcb_desc->rts_stbc = false;
  578. tcb_desc->cts_enable = false;
  579. tcb_desc->rts_sc = 0;
  580. tcb_desc->rts_bw = false;
  581. tcb_desc->rts_use_shortpreamble = false;
  582. tcb_desc->rts_use_shortgi = false;
  583. if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  584. /* Use CTS-to-SELF in protection mode. */
  585. tcb_desc->rts_enable = true;
  586. tcb_desc->cts_enable = true;
  587. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  588. } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
  589. /* Use RTS-CTS in protection mode. */
  590. tcb_desc->rts_enable = true;
  591. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  592. }
  593. }
  594. u8 rtl_mrate_idx_to_arfr_id(struct ieee80211_hw *hw, u8 rate_index,
  595. enum wireless_mode wirelessmode)
  596. {
  597. struct rtl_priv *rtlpriv = rtl_priv(hw);
  598. struct rtl_phy *rtlphy = &rtlpriv->phy;
  599. u8 ret = 0;
  600. switch (rate_index) {
  601. case RATR_INX_WIRELESS_NGB:
  602. if (rtlphy->rf_type == RF_1T1R)
  603. ret = RATEID_IDX_BGN_40M_1SS;
  604. else
  605. ret = RATEID_IDX_BGN_40M_2SS;
  606. ; break;
  607. case RATR_INX_WIRELESS_N:
  608. case RATR_INX_WIRELESS_NG:
  609. if (rtlphy->rf_type == RF_1T1R)
  610. ret = RATEID_IDX_GN_N1SS;
  611. else
  612. ret = RATEID_IDX_GN_N2SS;
  613. ; break;
  614. case RATR_INX_WIRELESS_NB:
  615. if (rtlphy->rf_type == RF_1T1R)
  616. ret = RATEID_IDX_BGN_20M_1SS_BN;
  617. else
  618. ret = RATEID_IDX_BGN_20M_2SS_BN;
  619. ; break;
  620. case RATR_INX_WIRELESS_GB:
  621. ret = RATEID_IDX_BG;
  622. break;
  623. case RATR_INX_WIRELESS_G:
  624. ret = RATEID_IDX_G;
  625. break;
  626. case RATR_INX_WIRELESS_B:
  627. ret = RATEID_IDX_B;
  628. break;
  629. case RATR_INX_WIRELESS_MC:
  630. if (wirelessmode == WIRELESS_MODE_B ||
  631. wirelessmode == WIRELESS_MODE_G ||
  632. wirelessmode == WIRELESS_MODE_N_24G ||
  633. wirelessmode == WIRELESS_MODE_AC_24G)
  634. ret = RATEID_IDX_BG;
  635. else
  636. ret = RATEID_IDX_G;
  637. break;
  638. case RATR_INX_WIRELESS_AC_5N:
  639. if (rtlphy->rf_type == RF_1T1R)
  640. ret = RATEID_IDX_VHT_1SS;
  641. else
  642. ret = RATEID_IDX_VHT_2SS;
  643. break;
  644. case RATR_INX_WIRELESS_AC_24N:
  645. if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
  646. if (rtlphy->rf_type == RF_1T1R)
  647. ret = RATEID_IDX_VHT_1SS;
  648. else
  649. ret = RATEID_IDX_VHT_2SS;
  650. } else {
  651. if (rtlphy->rf_type == RF_1T1R)
  652. ret = RATEID_IDX_MIX1;
  653. else
  654. ret = RATEID_IDX_MIX2;
  655. }
  656. break;
  657. default:
  658. ret = RATEID_IDX_BGN_40M_2SS;
  659. break;
  660. }
  661. return ret;
  662. }
  663. EXPORT_SYMBOL(rtl_mrate_idx_to_arfr_id);
  664. static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
  665. struct ieee80211_sta *sta,
  666. struct rtl_tcb_desc *tcb_desc)
  667. {
  668. #define SET_RATE_ID(rate_id) \
  669. ({typeof(rate_id) _id = rate_id; \
  670. ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
  671. rtl_mrate_idx_to_arfr_id(hw, _id, \
  672. (sta_entry ? sta_entry->wireless_mode : \
  673. WIRELESS_MODE_G)) : \
  674. _id); })
  675. struct rtl_priv *rtlpriv = rtl_priv(hw);
  676. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  677. struct rtl_sta_info *sta_entry = NULL;
  678. u8 ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC);
  679. if (sta) {
  680. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  681. ratr_index = sta_entry->ratr_index;
  682. }
  683. if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
  684. if (mac->opmode == NL80211_IFTYPE_STATION) {
  685. tcb_desc->ratr_index = 0;
  686. } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
  687. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  688. if (tcb_desc->multicast || tcb_desc->broadcast) {
  689. tcb_desc->hw_rate =
  690. rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
  691. tcb_desc->use_driver_rate = 1;
  692. tcb_desc->ratr_index =
  693. SET_RATE_ID(RATR_INX_WIRELESS_MC);
  694. } else {
  695. tcb_desc->ratr_index = ratr_index;
  696. }
  697. } else if (mac->opmode == NL80211_IFTYPE_AP) {
  698. tcb_desc->ratr_index = ratr_index;
  699. }
  700. }
  701. if (rtlpriv->dm.useramask) {
  702. tcb_desc->ratr_index = ratr_index;
  703. /* TODO we will differentiate adhoc and station future */
  704. if (mac->opmode == NL80211_IFTYPE_STATION ||
  705. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  706. tcb_desc->mac_id = 0;
  707. if (sta &&
  708. (rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID))
  709. ; /* use sta_entry->ratr_index */
  710. else if (mac->mode == WIRELESS_MODE_AC_5G)
  711. tcb_desc->ratr_index =
  712. SET_RATE_ID(RATR_INX_WIRELESS_AC_5N);
  713. else if (mac->mode == WIRELESS_MODE_AC_24G)
  714. tcb_desc->ratr_index =
  715. SET_RATE_ID(RATR_INX_WIRELESS_AC_24N);
  716. else if (mac->mode == WIRELESS_MODE_N_24G)
  717. tcb_desc->ratr_index =
  718. SET_RATE_ID(RATR_INX_WIRELESS_NGB);
  719. else if (mac->mode == WIRELESS_MODE_N_5G)
  720. tcb_desc->ratr_index =
  721. SET_RATE_ID(RATR_INX_WIRELESS_NG);
  722. else if (mac->mode & WIRELESS_MODE_G)
  723. tcb_desc->ratr_index =
  724. SET_RATE_ID(RATR_INX_WIRELESS_GB);
  725. else if (mac->mode & WIRELESS_MODE_B)
  726. tcb_desc->ratr_index =
  727. SET_RATE_ID(RATR_INX_WIRELESS_B);
  728. else if (mac->mode & WIRELESS_MODE_A)
  729. tcb_desc->ratr_index =
  730. SET_RATE_ID(RATR_INX_WIRELESS_G);
  731. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  732. mac->opmode == NL80211_IFTYPE_ADHOC) {
  733. if (NULL != sta) {
  734. if (sta->aid > 0)
  735. tcb_desc->mac_id = sta->aid + 1;
  736. else
  737. tcb_desc->mac_id = 1;
  738. } else {
  739. tcb_desc->mac_id = 0;
  740. }
  741. }
  742. }
  743. #undef SET_RATE_ID
  744. }
  745. static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
  746. struct ieee80211_sta *sta,
  747. struct rtl_tcb_desc *tcb_desc)
  748. {
  749. struct rtl_priv *rtlpriv = rtl_priv(hw);
  750. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  751. tcb_desc->packet_bw = false;
  752. if (!sta)
  753. return;
  754. if (mac->opmode == NL80211_IFTYPE_AP ||
  755. mac->opmode == NL80211_IFTYPE_ADHOC ||
  756. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  757. if (!(sta->deflink.ht_cap.ht_supported) ||
  758. !(sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  759. return;
  760. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  761. if (!mac->bw_40 || !(sta->deflink.ht_cap.ht_supported))
  762. return;
  763. }
  764. if (tcb_desc->multicast || tcb_desc->broadcast)
  765. return;
  766. /*use legency rate, shall use 20MHz */
  767. if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
  768. return;
  769. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
  770. if (rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT) {
  771. if (mac->opmode == NL80211_IFTYPE_AP ||
  772. mac->opmode == NL80211_IFTYPE_ADHOC ||
  773. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  774. if (!(sta->deflink.vht_cap.vht_supported))
  775. return;
  776. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  777. if (!mac->bw_80 ||
  778. !(sta->deflink.vht_cap.vht_supported))
  779. return;
  780. }
  781. if (tcb_desc->hw_rate <=
  782. rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
  783. return;
  784. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
  785. }
  786. }
  787. static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
  788. struct ieee80211_sta *sta)
  789. {
  790. struct rtl_priv *rtlpriv = rtl_priv(hw);
  791. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  792. u8 hw_rate;
  793. u16 tx_mcs_map = le16_to_cpu(sta->deflink.vht_cap.vht_mcs.tx_mcs_map);
  794. if ((get_rf_type(rtlphy) == RF_2T2R) &&
  795. (tx_mcs_map & 0x000c) != 0x000c) {
  796. if ((tx_mcs_map & 0x000c) >> 2 ==
  797. IEEE80211_VHT_MCS_SUPPORT_0_7)
  798. hw_rate =
  799. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
  800. else if ((tx_mcs_map & 0x000c) >> 2 ==
  801. IEEE80211_VHT_MCS_SUPPORT_0_8)
  802. hw_rate =
  803. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS8];
  804. else
  805. hw_rate =
  806. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  807. } else {
  808. if ((tx_mcs_map & 0x0003) ==
  809. IEEE80211_VHT_MCS_SUPPORT_0_7)
  810. hw_rate =
  811. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
  812. else if ((tx_mcs_map & 0x0003) ==
  813. IEEE80211_VHT_MCS_SUPPORT_0_8)
  814. hw_rate =
  815. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS8];
  816. else
  817. hw_rate =
  818. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  819. }
  820. return hw_rate;
  821. }
  822. static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
  823. struct ieee80211_sta *sta)
  824. {
  825. struct rtl_priv *rtlpriv = rtl_priv(hw);
  826. struct rtl_phy *rtlphy = &rtlpriv->phy;
  827. u8 hw_rate;
  828. if (get_rf_type(rtlphy) == RF_2T2R &&
  829. sta->deflink.ht_cap.mcs.rx_mask[1] != 0)
  830. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
  831. else
  832. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
  833. return hw_rate;
  834. }
  835. /* mac80211's rate_idx is like this:
  836. *
  837. * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
  838. *
  839. * B/G rate:
  840. * (rx_status->flag & RX_FLAG_HT) = 0,
  841. * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
  842. *
  843. * N rate:
  844. * (rx_status->flag & RX_FLAG_HT) = 1,
  845. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  846. *
  847. * 5G band:rx_status->band == NL80211_BAND_5GHZ
  848. * A rate:
  849. * (rx_status->flag & RX_FLAG_HT) = 0,
  850. * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
  851. *
  852. * N rate:
  853. * (rx_status->flag & RX_FLAG_HT) = 1,
  854. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  855. *
  856. * VHT rates:
  857. * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
  858. * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
  859. */
  860. int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
  861. u8 desc_rate)
  862. {
  863. int rate_idx;
  864. if (isvht) {
  865. switch (desc_rate) {
  866. case DESC_RATEVHT1SS_MCS0:
  867. rate_idx = 0;
  868. break;
  869. case DESC_RATEVHT1SS_MCS1:
  870. rate_idx = 1;
  871. break;
  872. case DESC_RATEVHT1SS_MCS2:
  873. rate_idx = 2;
  874. break;
  875. case DESC_RATEVHT1SS_MCS3:
  876. rate_idx = 3;
  877. break;
  878. case DESC_RATEVHT1SS_MCS4:
  879. rate_idx = 4;
  880. break;
  881. case DESC_RATEVHT1SS_MCS5:
  882. rate_idx = 5;
  883. break;
  884. case DESC_RATEVHT1SS_MCS6:
  885. rate_idx = 6;
  886. break;
  887. case DESC_RATEVHT1SS_MCS7:
  888. rate_idx = 7;
  889. break;
  890. case DESC_RATEVHT1SS_MCS8:
  891. rate_idx = 8;
  892. break;
  893. case DESC_RATEVHT1SS_MCS9:
  894. rate_idx = 9;
  895. break;
  896. case DESC_RATEVHT2SS_MCS0:
  897. rate_idx = 0;
  898. break;
  899. case DESC_RATEVHT2SS_MCS1:
  900. rate_idx = 1;
  901. break;
  902. case DESC_RATEVHT2SS_MCS2:
  903. rate_idx = 2;
  904. break;
  905. case DESC_RATEVHT2SS_MCS3:
  906. rate_idx = 3;
  907. break;
  908. case DESC_RATEVHT2SS_MCS4:
  909. rate_idx = 4;
  910. break;
  911. case DESC_RATEVHT2SS_MCS5:
  912. rate_idx = 5;
  913. break;
  914. case DESC_RATEVHT2SS_MCS6:
  915. rate_idx = 6;
  916. break;
  917. case DESC_RATEVHT2SS_MCS7:
  918. rate_idx = 7;
  919. break;
  920. case DESC_RATEVHT2SS_MCS8:
  921. rate_idx = 8;
  922. break;
  923. case DESC_RATEVHT2SS_MCS9:
  924. rate_idx = 9;
  925. break;
  926. default:
  927. rate_idx = 0;
  928. break;
  929. }
  930. return rate_idx;
  931. }
  932. if (false == isht) {
  933. if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
  934. switch (desc_rate) {
  935. case DESC_RATE1M:
  936. rate_idx = 0;
  937. break;
  938. case DESC_RATE2M:
  939. rate_idx = 1;
  940. break;
  941. case DESC_RATE5_5M:
  942. rate_idx = 2;
  943. break;
  944. case DESC_RATE11M:
  945. rate_idx = 3;
  946. break;
  947. case DESC_RATE6M:
  948. rate_idx = 4;
  949. break;
  950. case DESC_RATE9M:
  951. rate_idx = 5;
  952. break;
  953. case DESC_RATE12M:
  954. rate_idx = 6;
  955. break;
  956. case DESC_RATE18M:
  957. rate_idx = 7;
  958. break;
  959. case DESC_RATE24M:
  960. rate_idx = 8;
  961. break;
  962. case DESC_RATE36M:
  963. rate_idx = 9;
  964. break;
  965. case DESC_RATE48M:
  966. rate_idx = 10;
  967. break;
  968. case DESC_RATE54M:
  969. rate_idx = 11;
  970. break;
  971. default:
  972. rate_idx = 0;
  973. break;
  974. }
  975. } else {
  976. switch (desc_rate) {
  977. case DESC_RATE6M:
  978. rate_idx = 0;
  979. break;
  980. case DESC_RATE9M:
  981. rate_idx = 1;
  982. break;
  983. case DESC_RATE12M:
  984. rate_idx = 2;
  985. break;
  986. case DESC_RATE18M:
  987. rate_idx = 3;
  988. break;
  989. case DESC_RATE24M:
  990. rate_idx = 4;
  991. break;
  992. case DESC_RATE36M:
  993. rate_idx = 5;
  994. break;
  995. case DESC_RATE48M:
  996. rate_idx = 6;
  997. break;
  998. case DESC_RATE54M:
  999. rate_idx = 7;
  1000. break;
  1001. default:
  1002. rate_idx = 0;
  1003. break;
  1004. }
  1005. }
  1006. } else {
  1007. switch (desc_rate) {
  1008. case DESC_RATEMCS0:
  1009. rate_idx = 0;
  1010. break;
  1011. case DESC_RATEMCS1:
  1012. rate_idx = 1;
  1013. break;
  1014. case DESC_RATEMCS2:
  1015. rate_idx = 2;
  1016. break;
  1017. case DESC_RATEMCS3:
  1018. rate_idx = 3;
  1019. break;
  1020. case DESC_RATEMCS4:
  1021. rate_idx = 4;
  1022. break;
  1023. case DESC_RATEMCS5:
  1024. rate_idx = 5;
  1025. break;
  1026. case DESC_RATEMCS6:
  1027. rate_idx = 6;
  1028. break;
  1029. case DESC_RATEMCS7:
  1030. rate_idx = 7;
  1031. break;
  1032. case DESC_RATEMCS8:
  1033. rate_idx = 8;
  1034. break;
  1035. case DESC_RATEMCS9:
  1036. rate_idx = 9;
  1037. break;
  1038. case DESC_RATEMCS10:
  1039. rate_idx = 10;
  1040. break;
  1041. case DESC_RATEMCS11:
  1042. rate_idx = 11;
  1043. break;
  1044. case DESC_RATEMCS12:
  1045. rate_idx = 12;
  1046. break;
  1047. case DESC_RATEMCS13:
  1048. rate_idx = 13;
  1049. break;
  1050. case DESC_RATEMCS14:
  1051. rate_idx = 14;
  1052. break;
  1053. case DESC_RATEMCS15:
  1054. rate_idx = 15;
  1055. break;
  1056. default:
  1057. rate_idx = 0;
  1058. break;
  1059. }
  1060. }
  1061. return rate_idx;
  1062. }
  1063. EXPORT_SYMBOL(rtlwifi_rate_mapping);
  1064. static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw,
  1065. struct ieee80211_tx_info *info)
  1066. {
  1067. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1068. struct ieee80211_tx_rate *r = &info->status.rates[0];
  1069. struct ieee80211_rate *txrate;
  1070. u8 hw_value = 0x0;
  1071. if (r->flags & IEEE80211_TX_RC_MCS) {
  1072. /* HT MCS0-15 */
  1073. hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 +
  1074. r->idx;
  1075. } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) {
  1076. /* VHT MCS0-9, NSS */
  1077. if (ieee80211_rate_get_vht_nss(r) == 2)
  1078. hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  1079. else
  1080. hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  1081. hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r);
  1082. } else {
  1083. /* legacy */
  1084. txrate = ieee80211_get_tx_rate(hw, info);
  1085. if (txrate)
  1086. hw_value = txrate->hw_value;
  1087. }
  1088. /* check 5G band */
  1089. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G &&
  1090. hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M])
  1091. hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M];
  1092. return hw_value;
  1093. }
  1094. void rtl_get_tcb_desc(struct ieee80211_hw *hw,
  1095. struct ieee80211_tx_info *info,
  1096. struct ieee80211_sta *sta,
  1097. struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
  1098. {
  1099. #define SET_RATE_ID(rate_id) \
  1100. ({typeof(rate_id) _id = rate_id; \
  1101. ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
  1102. rtl_mrate_idx_to_arfr_id(hw, _id, \
  1103. (sta_entry ? sta_entry->wireless_mode : \
  1104. WIRELESS_MODE_G)) : \
  1105. _id); })
  1106. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1107. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  1108. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1109. struct rtl_sta_info *sta_entry =
  1110. (sta ? (struct rtl_sta_info *)sta->drv_priv : NULL);
  1111. __le16 fc = rtl_get_fc(skb);
  1112. tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info);
  1113. if (rtl_is_tx_report_skb(hw, skb))
  1114. tcb_desc->use_spe_rpt = 1;
  1115. if (ieee80211_is_data(fc)) {
  1116. /*
  1117. *we set data rate INX 0
  1118. *in rtl_rc.c if skb is special data or
  1119. *mgt which need low data rate.
  1120. */
  1121. /*
  1122. *So tcb_desc->hw_rate is just used for
  1123. *special data and mgt frames
  1124. */
  1125. if (info->control.rates[0].idx == 0 ||
  1126. ieee80211_is_nullfunc(fc)) {
  1127. tcb_desc->use_driver_rate = true;
  1128. tcb_desc->ratr_index =
  1129. SET_RATE_ID(RATR_INX_WIRELESS_MC);
  1130. tcb_desc->disable_ratefallback = 1;
  1131. } else {
  1132. /*
  1133. *because hw will nerver use hw_rate
  1134. *when tcb_desc->use_driver_rate = false
  1135. *so we never set highest N rate here,
  1136. *and N rate will all be controlled by FW
  1137. *when tcb_desc->use_driver_rate = false
  1138. */
  1139. if (sta && sta->deflink.vht_cap.vht_supported) {
  1140. tcb_desc->hw_rate =
  1141. _rtl_get_vht_highest_n_rate(hw, sta);
  1142. } else {
  1143. if (sta && sta->deflink.ht_cap.ht_supported) {
  1144. tcb_desc->hw_rate =
  1145. _rtl_get_highest_n_rate(hw, sta);
  1146. } else {
  1147. if (rtlmac->mode == WIRELESS_MODE_B) {
  1148. tcb_desc->hw_rate =
  1149. rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
  1150. } else {
  1151. tcb_desc->hw_rate =
  1152. rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
  1153. }
  1154. }
  1155. }
  1156. }
  1157. if (is_multicast_ether_addr(hdr->addr1))
  1158. tcb_desc->multicast = 1;
  1159. else if (is_broadcast_ether_addr(hdr->addr1))
  1160. tcb_desc->broadcast = 1;
  1161. _rtl_txrate_selectmode(hw, sta, tcb_desc);
  1162. _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
  1163. _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
  1164. _rtl_query_shortgi(hw, sta, tcb_desc, info);
  1165. _rtl_query_protection_mode(hw, tcb_desc, info);
  1166. } else {
  1167. tcb_desc->use_driver_rate = true;
  1168. tcb_desc->ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC);
  1169. tcb_desc->disable_ratefallback = 1;
  1170. tcb_desc->mac_id = 0;
  1171. tcb_desc->packet_bw = false;
  1172. }
  1173. #undef SET_RATE_ID
  1174. }
  1175. EXPORT_SYMBOL(rtl_get_tcb_desc);
  1176. bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
  1177. {
  1178. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1179. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1180. __le16 fc = rtl_get_fc(skb);
  1181. if (ieee80211_is_auth(fc)) {
  1182. rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
  1183. mac->link_state = MAC80211_LINKING;
  1184. /* Dul mac */
  1185. rtlpriv->phy.need_iqk = true;
  1186. }
  1187. return true;
  1188. }
  1189. EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
  1190. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
  1191. u8 *bssid, u16 tid);
  1192. static void process_agg_start(struct ieee80211_hw *hw,
  1193. struct ieee80211_hdr *hdr, u16 tid)
  1194. {
  1195. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1196. struct ieee80211_rx_status rx_status = { 0 };
  1197. struct sk_buff *skb_delba = NULL;
  1198. skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
  1199. if (skb_delba) {
  1200. rx_status.freq = hw->conf.chandef.chan->center_freq;
  1201. rx_status.band = hw->conf.chandef.chan->band;
  1202. rx_status.flag |= RX_FLAG_DECRYPTED;
  1203. rx_status.flag |= RX_FLAG_MACTIME_START;
  1204. rx_status.rate_idx = 0;
  1205. rx_status.signal = 50 + 10;
  1206. memcpy(IEEE80211_SKB_RXCB(skb_delba),
  1207. &rx_status, sizeof(rx_status));
  1208. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
  1209. "fake del\n",
  1210. skb_delba->data,
  1211. skb_delba->len);
  1212. ieee80211_rx_irqsafe(hw, skb_delba);
  1213. }
  1214. }
  1215. bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
  1216. {
  1217. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1218. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1219. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1220. __le16 fc = rtl_get_fc(skb);
  1221. u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
  1222. u8 category;
  1223. if (!ieee80211_is_action(fc))
  1224. return true;
  1225. category = *act;
  1226. act++;
  1227. switch (category) {
  1228. case ACT_CAT_BA:
  1229. switch (*act) {
  1230. case ACT_ADDBAREQ:
  1231. if (mac->act_scanning)
  1232. return false;
  1233. rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1234. "%s ACT_ADDBAREQ From :%pM\n",
  1235. is_tx ? "Tx" : "Rx", hdr->addr2);
  1236. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
  1237. skb->data, skb->len);
  1238. if (!is_tx) {
  1239. struct ieee80211_sta *sta = NULL;
  1240. struct rtl_sta_info *sta_entry = NULL;
  1241. struct rtl_tid_data *tid_data;
  1242. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1243. u16 capab = 0, tid = 0;
  1244. rcu_read_lock();
  1245. sta = rtl_find_sta(hw, hdr->addr3);
  1246. if (sta == NULL) {
  1247. rtl_dbg(rtlpriv, COMP_SEND | COMP_RECV,
  1248. DBG_DMESG, "sta is NULL\n");
  1249. rcu_read_unlock();
  1250. return true;
  1251. }
  1252. sta_entry =
  1253. (struct rtl_sta_info *)sta->drv_priv;
  1254. capab =
  1255. le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1256. tid = (capab &
  1257. IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1258. if (tid >= MAX_TID_COUNT) {
  1259. rcu_read_unlock();
  1260. return true;
  1261. }
  1262. tid_data = &sta_entry->tids[tid];
  1263. if (tid_data->agg.rx_agg_state ==
  1264. RTL_RX_AGG_START)
  1265. process_agg_start(hw, hdr, tid);
  1266. rcu_read_unlock();
  1267. }
  1268. break;
  1269. case ACT_ADDBARSP:
  1270. rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1271. "%s ACT_ADDBARSP From :%pM\n",
  1272. is_tx ? "Tx" : "Rx", hdr->addr2);
  1273. break;
  1274. case ACT_DELBA:
  1275. rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1276. "ACT_ADDBADEL From :%pM\n", hdr->addr2);
  1277. break;
  1278. }
  1279. break;
  1280. default:
  1281. break;
  1282. }
  1283. return true;
  1284. }
  1285. EXPORT_SYMBOL_GPL(rtl_action_proc);
  1286. static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
  1287. int type)
  1288. {
  1289. struct ieee80211_hw *hw = rtlpriv->hw;
  1290. rtlpriv->ra.is_special_data = true;
  1291. if (rtlpriv->cfg->ops->get_btc_status())
  1292. rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
  1293. rtlpriv, type);
  1294. rtl_lps_leave(hw, false);
  1295. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1296. }
  1297. static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
  1298. struct sk_buff *skb, bool is_enc)
  1299. {
  1300. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1301. u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
  1302. u8 encrypt_header_len = 0;
  1303. u8 offset;
  1304. switch (rtlpriv->sec.pairwise_enc_algorithm) {
  1305. case WEP40_ENCRYPTION:
  1306. case WEP104_ENCRYPTION:
  1307. encrypt_header_len = 4;/*WEP_IV_LEN*/
  1308. break;
  1309. case TKIP_ENCRYPTION:
  1310. encrypt_header_len = 8;/*TKIP_IV_LEN*/
  1311. break;
  1312. case AESCCMP_ENCRYPTION:
  1313. encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
  1314. break;
  1315. default:
  1316. break;
  1317. }
  1318. offset = mac_hdr_len + SNAP_SIZE;
  1319. if (is_enc)
  1320. offset += encrypt_header_len;
  1321. return skb->data + offset;
  1322. }
  1323. /*should call before software enc*/
  1324. u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
  1325. bool is_enc)
  1326. {
  1327. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1328. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1329. __le16 fc = rtl_get_fc(skb);
  1330. u16 ether_type;
  1331. const u8 *ether_type_ptr;
  1332. const struct iphdr *ip;
  1333. if (!ieee80211_is_data(fc))
  1334. goto end;
  1335. ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
  1336. ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
  1337. if (ETH_P_IP == ether_type) {
  1338. ip = (struct iphdr *)((u8 *)ether_type_ptr +
  1339. PROTOC_TYPE_SIZE);
  1340. if (IPPROTO_UDP == ip->protocol) {
  1341. struct udphdr *udp = (struct udphdr *)((u8 *)ip +
  1342. (ip->ihl << 2));
  1343. if (((((u8 *)udp)[1] == 68) &&
  1344. (((u8 *)udp)[3] == 67)) ||
  1345. ((((u8 *)udp)[1] == 67) &&
  1346. (((u8 *)udp)[3] == 68))) {
  1347. /* 68 : UDP BOOTP client
  1348. * 67 : UDP BOOTP server
  1349. */
  1350. rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV),
  1351. DBG_DMESG, "dhcp %s !!\n",
  1352. (is_tx) ? "Tx" : "Rx");
  1353. if (is_tx)
  1354. setup_special_tx(rtlpriv, ppsc,
  1355. PACKET_DHCP);
  1356. return true;
  1357. }
  1358. }
  1359. } else if (ETH_P_ARP == ether_type) {
  1360. if (is_tx)
  1361. setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
  1362. return true;
  1363. } else if (ETH_P_PAE == ether_type) {
  1364. /* EAPOL is seens as in-4way */
  1365. rtlpriv->btcoexist.btc_info.in_4way = true;
  1366. rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
  1367. rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1368. "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
  1369. if (is_tx) {
  1370. rtlpriv->ra.is_special_data = true;
  1371. rtl_lps_leave(hw, false);
  1372. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1373. setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
  1374. }
  1375. return true;
  1376. } else if (ETH_P_IPV6 == ether_type) {
  1377. /* TODO: Handle any IPv6 cases that need special handling.
  1378. * For now, always return false
  1379. */
  1380. goto end;
  1381. }
  1382. end:
  1383. rtlpriv->ra.is_special_data = false;
  1384. return false;
  1385. }
  1386. EXPORT_SYMBOL_GPL(rtl_is_special_data);
  1387. void rtl_tx_ackqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
  1388. {
  1389. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1390. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1391. __skb_queue_tail(&tx_report->queue, skb);
  1392. }
  1393. EXPORT_SYMBOL_GPL(rtl_tx_ackqueue);
  1394. static void rtl_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
  1395. bool ack)
  1396. {
  1397. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1398. struct ieee80211_tx_info *info;
  1399. info = IEEE80211_SKB_CB(skb);
  1400. ieee80211_tx_info_clear_status(info);
  1401. if (ack) {
  1402. rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_LOUD,
  1403. "tx report: ack\n");
  1404. info->flags |= IEEE80211_TX_STAT_ACK;
  1405. } else {
  1406. rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_LOUD,
  1407. "tx report: not ack\n");
  1408. info->flags &= ~IEEE80211_TX_STAT_ACK;
  1409. }
  1410. ieee80211_tx_status_irqsafe(hw, skb);
  1411. }
  1412. bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
  1413. {
  1414. u16 ether_type;
  1415. const u8 *ether_type_ptr;
  1416. __le16 fc = rtl_get_fc(skb);
  1417. ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
  1418. ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
  1419. if (ether_type == ETH_P_PAE || ieee80211_is_nullfunc(fc))
  1420. return true;
  1421. return false;
  1422. }
  1423. static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw,
  1424. struct rtlwifi_tx_info *tx_info)
  1425. {
  1426. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1427. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1428. u16 sn;
  1429. /* SW_DEFINE[11:8] are reserved (driver fills zeros)
  1430. * SW_DEFINE[7:2] are used by driver
  1431. * SW_DEFINE[1:0] are reserved for firmware (driver fills zeros)
  1432. */
  1433. sn = (atomic_inc_return(&tx_report->sn) & 0x003F) << 2;
  1434. tx_report->last_sent_sn = sn;
  1435. tx_report->last_sent_time = jiffies;
  1436. tx_info->sn = sn;
  1437. tx_info->send_time = tx_report->last_sent_time;
  1438. rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
  1439. "Send TX-Report sn=0x%X\n", sn);
  1440. return sn;
  1441. }
  1442. void rtl_set_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
  1443. struct ieee80211_hw *hw, struct rtlwifi_tx_info *tx_info)
  1444. {
  1445. if (ptcb_desc->use_spe_rpt) {
  1446. u16 sn = rtl_get_tx_report_sn(hw, tx_info);
  1447. SET_TX_DESC_SPE_RPT(pdesc, 1);
  1448. SET_TX_DESC_SW_DEFINE(pdesc, sn);
  1449. }
  1450. }
  1451. EXPORT_SYMBOL_GPL(rtl_set_tx_report);
  1452. void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
  1453. {
  1454. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1455. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1456. struct rtlwifi_tx_info *tx_info;
  1457. struct sk_buff_head *queue = &tx_report->queue;
  1458. struct sk_buff *skb;
  1459. u16 sn;
  1460. u8 st, retry;
  1461. if (rtlpriv->cfg->spec_ver & RTL_SPEC_EXT_C2H) {
  1462. sn = GET_TX_REPORT_SN_V2(tmp_buf);
  1463. st = GET_TX_REPORT_ST_V2(tmp_buf);
  1464. retry = GET_TX_REPORT_RETRY_V2(tmp_buf);
  1465. } else {
  1466. sn = GET_TX_REPORT_SN_V1(tmp_buf);
  1467. st = GET_TX_REPORT_ST_V1(tmp_buf);
  1468. retry = GET_TX_REPORT_RETRY_V1(tmp_buf);
  1469. }
  1470. tx_report->last_recv_sn = sn;
  1471. skb_queue_walk(queue, skb) {
  1472. tx_info = rtl_tx_skb_cb_info(skb);
  1473. if (tx_info->sn == sn) {
  1474. skb_unlink(skb, queue);
  1475. rtl_tx_status(hw, skb, st == 0);
  1476. break;
  1477. }
  1478. }
  1479. rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
  1480. "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
  1481. st, sn, retry);
  1482. }
  1483. EXPORT_SYMBOL_GPL(rtl_tx_report_handler);
  1484. bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
  1485. {
  1486. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1487. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1488. if (tx_report->last_sent_sn == tx_report->last_recv_sn)
  1489. return true;
  1490. if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
  1491. rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
  1492. "Check TX-Report timeout!! s_sn=0x%X r_sn=0x%X\n",
  1493. tx_report->last_sent_sn, tx_report->last_recv_sn);
  1494. return true; /* 3 sec. (timeout) seen as acked */
  1495. }
  1496. return false;
  1497. }
  1498. void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
  1499. {
  1500. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1501. int i;
  1502. for (i = 0; i < wait_ms; i++) {
  1503. if (rtl_check_tx_report_acked(hw))
  1504. break;
  1505. usleep_range(1000, 2000);
  1506. rtl_dbg(rtlpriv, COMP_SEC, DBG_DMESG,
  1507. "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
  1508. }
  1509. }
  1510. u32 rtl_get_hal_edca_param(struct ieee80211_hw *hw,
  1511. struct ieee80211_vif *vif,
  1512. enum wireless_mode wirelessmode,
  1513. struct ieee80211_tx_queue_params *param)
  1514. {
  1515. u32 reg = 0;
  1516. u8 sifstime = 10;
  1517. u8 slottime = 20;
  1518. /* AIFS = AIFSN * slot time + SIFS */
  1519. switch (wirelessmode) {
  1520. case WIRELESS_MODE_A:
  1521. case WIRELESS_MODE_N_24G:
  1522. case WIRELESS_MODE_N_5G:
  1523. case WIRELESS_MODE_AC_5G:
  1524. case WIRELESS_MODE_AC_24G:
  1525. sifstime = 16;
  1526. slottime = 9;
  1527. break;
  1528. case WIRELESS_MODE_G:
  1529. slottime = (vif->bss_conf.use_short_slot ? 9 : 20);
  1530. break;
  1531. default:
  1532. break;
  1533. }
  1534. reg |= (param->txop & 0x7FF) << 16;
  1535. reg |= (fls(param->cw_max) & 0xF) << 12;
  1536. reg |= (fls(param->cw_min) & 0xF) << 8;
  1537. reg |= (param->aifs & 0x0F) * slottime + sifstime;
  1538. return reg;
  1539. }
  1540. EXPORT_SYMBOL_GPL(rtl_get_hal_edca_param);
  1541. /*********************************************************
  1542. *
  1543. * functions called by core.c
  1544. *
  1545. *********************************************************/
  1546. int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1547. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  1548. {
  1549. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1550. struct rtl_tid_data *tid_data;
  1551. struct rtl_sta_info *sta_entry = NULL;
  1552. if (sta == NULL)
  1553. return -EINVAL;
  1554. if (unlikely(tid >= MAX_TID_COUNT))
  1555. return -EINVAL;
  1556. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1557. tid_data = &sta_entry->tids[tid];
  1558. rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG,
  1559. "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
  1560. *ssn);
  1561. tid_data->agg.agg_state = RTL_AGG_START;
  1562. return IEEE80211_AMPDU_TX_START_IMMEDIATE;
  1563. }
  1564. int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1565. struct ieee80211_sta *sta, u16 tid)
  1566. {
  1567. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1568. struct rtl_sta_info *sta_entry = NULL;
  1569. if (sta == NULL)
  1570. return -EINVAL;
  1571. rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG,
  1572. "on ra = %pM tid = %d\n", sta->addr, tid);
  1573. if (unlikely(tid >= MAX_TID_COUNT))
  1574. return -EINVAL;
  1575. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1576. sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
  1577. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1578. return 0;
  1579. }
  1580. int rtl_rx_agg_start(struct ieee80211_hw *hw,
  1581. struct ieee80211_sta *sta, u16 tid)
  1582. {
  1583. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1584. struct rtl_tid_data *tid_data;
  1585. struct rtl_sta_info *sta_entry = NULL;
  1586. u8 reject_agg;
  1587. if (sta == NULL)
  1588. return -EINVAL;
  1589. if (unlikely(tid >= MAX_TID_COUNT))
  1590. return -EINVAL;
  1591. if (rtlpriv->cfg->ops->get_btc_status()) {
  1592. rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
  1593. &reject_agg,
  1594. NULL, NULL);
  1595. if (reject_agg)
  1596. return -EINVAL;
  1597. }
  1598. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1599. tid_data = &sta_entry->tids[tid];
  1600. rtl_dbg(rtlpriv, COMP_RECV, DBG_DMESG,
  1601. "on ra = %pM tid = %d\n", sta->addr, tid);
  1602. tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
  1603. return 0;
  1604. }
  1605. int rtl_rx_agg_stop(struct ieee80211_hw *hw,
  1606. struct ieee80211_sta *sta, u16 tid)
  1607. {
  1608. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1609. struct rtl_sta_info *sta_entry = NULL;
  1610. if (sta == NULL)
  1611. return -EINVAL;
  1612. rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG,
  1613. "on ra = %pM tid = %d\n", sta->addr, tid);
  1614. if (unlikely(tid >= MAX_TID_COUNT))
  1615. return -EINVAL;
  1616. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1617. sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
  1618. return 0;
  1619. }
  1620. int rtl_tx_agg_oper(struct ieee80211_hw *hw,
  1621. struct ieee80211_sta *sta, u16 tid)
  1622. {
  1623. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1624. struct rtl_sta_info *sta_entry = NULL;
  1625. if (sta == NULL)
  1626. return -EINVAL;
  1627. rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG,
  1628. "on ra = %pM tid = %d\n", sta->addr, tid);
  1629. if (unlikely(tid >= MAX_TID_COUNT))
  1630. return -EINVAL;
  1631. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1632. sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
  1633. return 0;
  1634. }
  1635. void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
  1636. {
  1637. struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
  1638. u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0;
  1639. if (rtlpriv->cfg->ops->get_btc_status())
  1640. btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
  1641. &ctrl_agg_size, &agg_size);
  1642. rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
  1643. "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
  1644. reject_agg, ctrl_agg_size, agg_size);
  1645. rtlpriv->hw->max_rx_aggregation_subframes =
  1646. (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF_HT);
  1647. }
  1648. EXPORT_SYMBOL(rtl_rx_ampdu_apply);
  1649. /*********************************************************
  1650. *
  1651. * wq & timer callback functions
  1652. *
  1653. *********************************************************/
  1654. /* this function is used for roaming */
  1655. void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
  1656. {
  1657. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1658. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1659. if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
  1660. return;
  1661. if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
  1662. return;
  1663. /* check if this really is a beacon */
  1664. if (!ieee80211_is_beacon(hdr->frame_control) &&
  1665. !ieee80211_is_probe_resp(hdr->frame_control))
  1666. return;
  1667. /* min. beacon length + FCS_LEN */
  1668. if (skb->len <= 40 + FCS_LEN)
  1669. return;
  1670. /* and only beacons from the associated BSSID, please */
  1671. if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
  1672. return;
  1673. rtlpriv->link_info.bcn_rx_inperiod++;
  1674. }
  1675. EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
  1676. static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
  1677. {
  1678. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1679. struct rtl_bssid_entry *entry, *next;
  1680. list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
  1681. list_del(&entry->list);
  1682. kfree(entry);
  1683. rtlpriv->scan_list.num--;
  1684. }
  1685. }
  1686. static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw,
  1687. bool chk_timeout)
  1688. {
  1689. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1690. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1691. struct sk_buff_head *queue = &tx_report->queue;
  1692. struct sk_buff *skb, *tmp;
  1693. struct rtlwifi_tx_info *tx_info;
  1694. skb_queue_walk_safe(queue, skb, tmp) {
  1695. tx_info = rtl_tx_skb_cb_info(skb);
  1696. if (chk_timeout &&
  1697. time_after(tx_info->send_time + HZ, jiffies))
  1698. continue;
  1699. skb_unlink(skb, queue);
  1700. rtl_tx_status(hw, skb, false);
  1701. }
  1702. }
  1703. void rtl_scan_list_expire(struct ieee80211_hw *hw)
  1704. {
  1705. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1706. struct rtl_bssid_entry *entry, *next;
  1707. unsigned long flags;
  1708. spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
  1709. list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
  1710. /* 180 seconds */
  1711. if (jiffies_to_msecs(jiffies - entry->age) < 180000)
  1712. continue;
  1713. list_del(&entry->list);
  1714. rtlpriv->scan_list.num--;
  1715. rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD,
  1716. "BSSID=%pM is expire in scan list (total=%d)\n",
  1717. entry->bssid, rtlpriv->scan_list.num);
  1718. kfree(entry);
  1719. }
  1720. spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
  1721. rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
  1722. }
  1723. void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
  1724. {
  1725. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1726. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1727. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1728. unsigned long flags;
  1729. struct rtl_bssid_entry *entry = NULL, *iter;
  1730. /* check if it is scanning */
  1731. if (!mac->act_scanning)
  1732. return;
  1733. /* check if this really is a beacon */
  1734. if (!ieee80211_is_beacon(hdr->frame_control) &&
  1735. !ieee80211_is_probe_resp(hdr->frame_control))
  1736. return;
  1737. spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
  1738. list_for_each_entry(iter, &rtlpriv->scan_list.list, list) {
  1739. if (memcmp(iter->bssid, hdr->addr3, ETH_ALEN) == 0) {
  1740. list_del_init(&iter->list);
  1741. entry = iter;
  1742. rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD,
  1743. "Update BSSID=%pM to scan list (total=%d)\n",
  1744. hdr->addr3, rtlpriv->scan_list.num);
  1745. break;
  1746. }
  1747. }
  1748. if (!entry) {
  1749. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  1750. if (!entry)
  1751. goto label_err;
  1752. memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
  1753. rtlpriv->scan_list.num++;
  1754. rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD,
  1755. "Add BSSID=%pM to scan list (total=%d)\n",
  1756. hdr->addr3, rtlpriv->scan_list.num);
  1757. }
  1758. entry->age = jiffies;
  1759. list_add_tail(&entry->list, &rtlpriv->scan_list.list);
  1760. label_err:
  1761. spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
  1762. }
  1763. EXPORT_SYMBOL(rtl_collect_scan_list);
  1764. static void rtl_watchdog_wq_callback(struct work_struct *work)
  1765. {
  1766. struct rtl_works *rtlworks = container_of(work, struct rtl_works,
  1767. watchdog_wq.work);
  1768. struct ieee80211_hw *hw = rtlworks->hw;
  1769. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1770. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1771. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1772. bool busytraffic = false;
  1773. bool tx_busy_traffic = false;
  1774. bool rx_busy_traffic = false;
  1775. bool higher_busytraffic = false;
  1776. bool higher_busyrxtraffic = false;
  1777. u8 idx, tid;
  1778. u32 rx_cnt_inp4eriod = 0;
  1779. u32 tx_cnt_inp4eriod = 0;
  1780. u32 aver_rx_cnt_inperiod = 0;
  1781. u32 aver_tx_cnt_inperiod = 0;
  1782. u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
  1783. u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
  1784. if (is_hal_stop(rtlhal))
  1785. return;
  1786. /* <1> Determine if action frame is allowed */
  1787. if (mac->link_state > MAC80211_NOLINK) {
  1788. if (mac->cnt_after_linked < 20)
  1789. mac->cnt_after_linked++;
  1790. } else {
  1791. mac->cnt_after_linked = 0;
  1792. }
  1793. /* <2> to check if traffic busy, if
  1794. * busytraffic we don't change channel
  1795. */
  1796. if (mac->link_state >= MAC80211_LINKED) {
  1797. /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
  1798. for (idx = 0; idx <= 2; idx++) {
  1799. rtlpriv->link_info.num_rx_in4period[idx] =
  1800. rtlpriv->link_info.num_rx_in4period[idx + 1];
  1801. rtlpriv->link_info.num_tx_in4period[idx] =
  1802. rtlpriv->link_info.num_tx_in4period[idx + 1];
  1803. }
  1804. rtlpriv->link_info.num_rx_in4period[3] =
  1805. rtlpriv->link_info.num_rx_inperiod;
  1806. rtlpriv->link_info.num_tx_in4period[3] =
  1807. rtlpriv->link_info.num_tx_inperiod;
  1808. for (idx = 0; idx <= 3; idx++) {
  1809. rx_cnt_inp4eriod +=
  1810. rtlpriv->link_info.num_rx_in4period[idx];
  1811. tx_cnt_inp4eriod +=
  1812. rtlpriv->link_info.num_tx_in4period[idx];
  1813. }
  1814. aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
  1815. aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
  1816. /* (2) check traffic busy */
  1817. if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
  1818. busytraffic = true;
  1819. if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
  1820. rx_busy_traffic = true;
  1821. else
  1822. tx_busy_traffic = false;
  1823. }
  1824. /* Higher Tx/Rx data. */
  1825. if (aver_rx_cnt_inperiod > 4000 ||
  1826. aver_tx_cnt_inperiod > 4000) {
  1827. higher_busytraffic = true;
  1828. /* Extremely high Rx data. */
  1829. if (aver_rx_cnt_inperiod > 5000)
  1830. higher_busyrxtraffic = true;
  1831. }
  1832. /* check every tid's tx traffic */
  1833. for (tid = 0; tid <= 7; tid++) {
  1834. for (idx = 0; idx <= 2; idx++)
  1835. rtlpriv->link_info.tidtx_in4period[tid][idx] =
  1836. rtlpriv->link_info.tidtx_in4period[tid]
  1837. [idx + 1];
  1838. rtlpriv->link_info.tidtx_in4period[tid][3] =
  1839. rtlpriv->link_info.tidtx_inperiod[tid];
  1840. for (idx = 0; idx <= 3; idx++)
  1841. tidtx_inp4eriod[tid] +=
  1842. rtlpriv->link_info.tidtx_in4period[tid][idx];
  1843. aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
  1844. if (aver_tidtx_inperiod[tid] > 5000)
  1845. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1846. true;
  1847. else
  1848. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1849. false;
  1850. }
  1851. /* PS is controlled by coex. */
  1852. if (rtlpriv->cfg->ops->get_btc_status() &&
  1853. rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
  1854. goto label_lps_done;
  1855. if (rtlpriv->link_info.num_rx_inperiod +
  1856. rtlpriv->link_info.num_tx_inperiod > 8 ||
  1857. rtlpriv->link_info.num_rx_inperiod > 2)
  1858. rtl_lps_leave(hw, true);
  1859. else
  1860. rtl_lps_enter(hw, true);
  1861. label_lps_done:
  1862. ;
  1863. }
  1864. for (tid = 0; tid <= 7; tid++)
  1865. rtlpriv->link_info.tidtx_inperiod[tid] = 0;
  1866. rtlpriv->link_info.busytraffic = busytraffic;
  1867. rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
  1868. rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
  1869. rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
  1870. rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
  1871. rtlpriv->stats.txbytesunicast_inperiod =
  1872. rtlpriv->stats.txbytesunicast -
  1873. rtlpriv->stats.txbytesunicast_last;
  1874. rtlpriv->stats.rxbytesunicast_inperiod =
  1875. rtlpriv->stats.rxbytesunicast -
  1876. rtlpriv->stats.rxbytesunicast_last;
  1877. rtlpriv->stats.txbytesunicast_last = rtlpriv->stats.txbytesunicast;
  1878. rtlpriv->stats.rxbytesunicast_last = rtlpriv->stats.rxbytesunicast;
  1879. rtlpriv->stats.txbytesunicast_inperiod_tp =
  1880. (u32)(rtlpriv->stats.txbytesunicast_inperiod * 8 / 2 /
  1881. 1024 / 1024);
  1882. rtlpriv->stats.rxbytesunicast_inperiod_tp =
  1883. (u32)(rtlpriv->stats.rxbytesunicast_inperiod * 8 / 2 /
  1884. 1024 / 1024);
  1885. /* <3> DM */
  1886. if (!rtlpriv->cfg->mod_params->disable_watchdog)
  1887. rtlpriv->cfg->ops->dm_watchdog(hw);
  1888. /* <4> roaming */
  1889. if (mac->link_state == MAC80211_LINKED &&
  1890. mac->opmode == NL80211_IFTYPE_STATION) {
  1891. if ((rtlpriv->link_info.bcn_rx_inperiod +
  1892. rtlpriv->link_info.num_rx_inperiod) == 0) {
  1893. rtlpriv->link_info.roam_times++;
  1894. rtl_dbg(rtlpriv, COMP_ERR, DBG_DMESG,
  1895. "AP off for %d s\n",
  1896. (rtlpriv->link_info.roam_times * 2));
  1897. /* if we can't recv beacon for 10s,
  1898. * we should reconnect this AP
  1899. */
  1900. if (rtlpriv->link_info.roam_times >= 5) {
  1901. pr_err("AP off, try to reconnect now\n");
  1902. rtlpriv->link_info.roam_times = 0;
  1903. ieee80211_connection_loss(
  1904. rtlpriv->mac80211.vif);
  1905. }
  1906. } else {
  1907. rtlpriv->link_info.roam_times = 0;
  1908. }
  1909. }
  1910. if (rtlpriv->cfg->ops->get_btc_status())
  1911. rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
  1912. if (rtlpriv->btcoexist.btc_info.in_4way) {
  1913. if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
  1914. msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
  1915. rtlpriv->btcoexist.btc_info.in_4way = false;
  1916. }
  1917. rtlpriv->link_info.num_rx_inperiod = 0;
  1918. rtlpriv->link_info.num_tx_inperiod = 0;
  1919. rtlpriv->link_info.bcn_rx_inperiod = 0;
  1920. /* <6> scan list */
  1921. rtl_scan_list_expire(hw);
  1922. /* <7> check ack queue */
  1923. rtl_free_entries_from_ack_queue(hw, true);
  1924. }
  1925. void rtl_watch_dog_timer_callback(struct timer_list *t)
  1926. {
  1927. struct rtl_priv *rtlpriv = from_timer(rtlpriv, t, works.watchdog_timer);
  1928. queue_delayed_work(rtlpriv->works.rtl_wq,
  1929. &rtlpriv->works.watchdog_wq, 0);
  1930. mod_timer(&rtlpriv->works.watchdog_timer,
  1931. jiffies + MSECS(RTL_WATCH_DOG_TIME));
  1932. }
  1933. static void rtl_fwevt_wq_callback(struct work_struct *work)
  1934. {
  1935. struct rtl_works *rtlworks = container_of(work, struct rtl_works,
  1936. fwevt_wq.work);
  1937. struct ieee80211_hw *hw = rtlworks->hw;
  1938. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1939. rtlpriv->cfg->ops->c2h_command_handle(hw);
  1940. }
  1941. static void rtl_c2h_content_parsing(struct ieee80211_hw *hw,
  1942. struct sk_buff *skb);
  1943. static bool rtl_c2h_fast_cmd(struct ieee80211_hw *hw, struct sk_buff *skb)
  1944. {
  1945. u8 cmd_id = GET_C2H_CMD_ID(skb->data);
  1946. switch (cmd_id) {
  1947. case C2H_BT_MP:
  1948. return true;
  1949. default:
  1950. break;
  1951. }
  1952. return false;
  1953. }
  1954. void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
  1955. {
  1956. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1957. if (rtl_c2h_fast_cmd(hw, skb)) {
  1958. rtl_c2h_content_parsing(hw, skb);
  1959. kfree_skb(skb);
  1960. return;
  1961. }
  1962. /* enqueue */
  1963. skb_queue_tail(&rtlpriv->c2hcmd_queue, skb);
  1964. /* wake up wq */
  1965. queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
  1966. }
  1967. EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
  1968. static void rtl_c2h_content_parsing(struct ieee80211_hw *hw,
  1969. struct sk_buff *skb)
  1970. {
  1971. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1972. const struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops;
  1973. const struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
  1974. u8 cmd_id, cmd_len;
  1975. u8 *cmd_buf = NULL;
  1976. cmd_id = GET_C2H_CMD_ID(skb->data);
  1977. cmd_len = skb->len - C2H_DATA_OFFSET;
  1978. cmd_buf = GET_C2H_DATA_PTR(skb->data);
  1979. switch (cmd_id) {
  1980. case C2H_DBG:
  1981. rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "[C2H], C2H_DBG!!\n");
  1982. break;
  1983. case C2H_TXBF:
  1984. rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE,
  1985. "[C2H], C2H_TXBF!!\n");
  1986. break;
  1987. case C2H_TX_REPORT:
  1988. rtl_tx_report_handler(hw, cmd_buf, cmd_len);
  1989. break;
  1990. case C2H_RA_RPT:
  1991. if (hal_ops->c2h_ra_report_handler)
  1992. hal_ops->c2h_ra_report_handler(hw, cmd_buf, cmd_len);
  1993. break;
  1994. case C2H_BT_INFO:
  1995. rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE,
  1996. "[C2H], C2H_BT_INFO!!\n");
  1997. if (rtlpriv->cfg->ops->get_btc_status())
  1998. btc_ops->btc_btinfo_notify(rtlpriv, cmd_buf, cmd_len);
  1999. break;
  2000. case C2H_BT_MP:
  2001. rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE,
  2002. "[C2H], C2H_BT_MP!!\n");
  2003. if (rtlpriv->cfg->ops->get_btc_status())
  2004. btc_ops->btc_btmpinfo_notify(rtlpriv, cmd_buf, cmd_len);
  2005. break;
  2006. default:
  2007. rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE,
  2008. "[C2H], Unknown packet!! cmd_id(%#X)!\n", cmd_id);
  2009. break;
  2010. }
  2011. }
  2012. void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
  2013. {
  2014. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2015. struct sk_buff *skb;
  2016. int i;
  2017. for (i = 0; i < 200; i++) {
  2018. /* dequeue a task */
  2019. skb = skb_dequeue(&rtlpriv->c2hcmd_queue);
  2020. /* do it */
  2021. if (!skb)
  2022. break;
  2023. rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG, "C2H rx_desc_shift=%d\n",
  2024. *((u8 *)skb->cb));
  2025. RT_PRINT_DATA(rtlpriv, COMP_FW, DBG_DMESG,
  2026. "C2H data: ", skb->data, skb->len);
  2027. if (exec)
  2028. rtl_c2h_content_parsing(hw, skb);
  2029. /* free */
  2030. dev_kfree_skb_any(skb);
  2031. }
  2032. }
  2033. static void rtl_c2hcmd_wq_callback(struct work_struct *work)
  2034. {
  2035. struct rtl_works *rtlworks = container_of(work, struct rtl_works,
  2036. c2hcmd_wq.work);
  2037. struct ieee80211_hw *hw = rtlworks->hw;
  2038. rtl_c2hcmd_launcher(hw, 1);
  2039. }
  2040. /*********************************************************
  2041. *
  2042. * frame process functions
  2043. *
  2044. *********************************************************/
  2045. u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
  2046. {
  2047. struct ieee80211_mgmt *mgmt = (void *)data;
  2048. u8 *pos, *end;
  2049. pos = (u8 *)mgmt->u.beacon.variable;
  2050. end = data + len;
  2051. while (pos < end) {
  2052. if (pos + 2 + pos[1] > end)
  2053. return NULL;
  2054. if (pos[0] == ie)
  2055. return pos;
  2056. pos += 2 + pos[1];
  2057. }
  2058. return NULL;
  2059. }
  2060. /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
  2061. /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
  2062. static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
  2063. enum ieee80211_smps_mode smps,
  2064. u8 *da, u8 *bssid)
  2065. {
  2066. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2067. struct sk_buff *skb;
  2068. struct ieee80211_mgmt *action_frame;
  2069. /* 27 = header + category + action + smps mode */
  2070. skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
  2071. if (!skb)
  2072. return NULL;
  2073. skb_reserve(skb, hw->extra_tx_headroom);
  2074. action_frame = skb_put_zero(skb, 27);
  2075. memcpy(action_frame->da, da, ETH_ALEN);
  2076. memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
  2077. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  2078. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2079. IEEE80211_STYPE_ACTION);
  2080. action_frame->u.action.category = WLAN_CATEGORY_HT;
  2081. action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
  2082. switch (smps) {
  2083. case IEEE80211_SMPS_AUTOMATIC:/* 0 */
  2084. case IEEE80211_SMPS_NUM_MODES:/* 4 */
  2085. WARN_ON(1);
  2086. fallthrough;
  2087. case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
  2088. action_frame->u.action.u.ht_smps.smps_control =
  2089. WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
  2090. break;
  2091. case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
  2092. action_frame->u.action.u.ht_smps.smps_control =
  2093. WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
  2094. break;
  2095. case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
  2096. action_frame->u.action.u.ht_smps.smps_control =
  2097. WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
  2098. break;
  2099. }
  2100. return skb;
  2101. }
  2102. int rtl_send_smps_action(struct ieee80211_hw *hw,
  2103. struct ieee80211_sta *sta,
  2104. enum ieee80211_smps_mode smps)
  2105. {
  2106. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2107. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  2108. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  2109. struct sk_buff *skb = NULL;
  2110. struct rtl_tcb_desc tcb_desc;
  2111. u8 bssid[ETH_ALEN] = {0};
  2112. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  2113. if (rtlpriv->mac80211.act_scanning)
  2114. goto err_free;
  2115. if (!sta)
  2116. goto err_free;
  2117. if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
  2118. goto err_free;
  2119. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  2120. goto err_free;
  2121. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
  2122. memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
  2123. else
  2124. memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
  2125. skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
  2126. /* this is a type = mgmt * stype = action frame */
  2127. if (skb) {
  2128. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2129. struct rtl_sta_info *sta_entry =
  2130. (struct rtl_sta_info *) sta->drv_priv;
  2131. sta_entry->mimo_ps = smps;
  2132. /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */
  2133. info->control.rates[0].idx = 0;
  2134. info->band = hw->conf.chandef.chan->band;
  2135. rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
  2136. }
  2137. return 1;
  2138. err_free:
  2139. return 0;
  2140. }
  2141. EXPORT_SYMBOL(rtl_send_smps_action);
  2142. void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
  2143. {
  2144. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2145. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  2146. enum io_type iotype;
  2147. if (!is_hal_stop(rtlhal)) {
  2148. switch (operation) {
  2149. case SCAN_OPT_BACKUP:
  2150. iotype = IO_CMD_PAUSE_DM_BY_SCAN;
  2151. rtlpriv->cfg->ops->set_hw_reg(hw,
  2152. HW_VAR_IO_CMD,
  2153. (u8 *)&iotype);
  2154. break;
  2155. case SCAN_OPT_RESTORE:
  2156. iotype = IO_CMD_RESUME_DM_BY_SCAN;
  2157. rtlpriv->cfg->ops->set_hw_reg(hw,
  2158. HW_VAR_IO_CMD,
  2159. (u8 *)&iotype);
  2160. break;
  2161. default:
  2162. pr_err("Unknown Scan Backup operation.\n");
  2163. break;
  2164. }
  2165. }
  2166. }
  2167. EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
  2168. /* because mac80211 have issues when can receive del ba
  2169. * so here we just make a fake del_ba if we receive a ba_req
  2170. * but rx_agg was opened to let mac80211 release some ba
  2171. * related resources, so please this del_ba for tx
  2172. */
  2173. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
  2174. u8 *sa, u8 *bssid, u16 tid)
  2175. {
  2176. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2177. struct sk_buff *skb;
  2178. struct ieee80211_mgmt *action_frame;
  2179. u16 params;
  2180. /* 27 = header + category + action + smps mode */
  2181. skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
  2182. if (!skb)
  2183. return NULL;
  2184. skb_reserve(skb, hw->extra_tx_headroom);
  2185. action_frame = skb_put_zero(skb, 34);
  2186. memcpy(action_frame->sa, sa, ETH_ALEN);
  2187. memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
  2188. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  2189. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2190. IEEE80211_STYPE_ACTION);
  2191. action_frame->u.action.category = WLAN_CATEGORY_BACK;
  2192. action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  2193. params = (u16)(1 << 11); /* bit 11 initiator */
  2194. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  2195. action_frame->u.action.u.delba.params = cpu_to_le16(params);
  2196. action_frame->u.action.u.delba.reason_code =
  2197. cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
  2198. return skb;
  2199. }
  2200. /*********************************************************
  2201. *
  2202. * IOT functions
  2203. *
  2204. *********************************************************/
  2205. static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
  2206. struct octet_string vendor_ie)
  2207. {
  2208. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2209. bool matched = false;
  2210. static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
  2211. static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
  2212. static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
  2213. static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
  2214. static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
  2215. static u8 racap[] = { 0x00, 0x0c, 0x43 };
  2216. static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
  2217. static u8 marvcap[] = { 0x00, 0x50, 0x43 };
  2218. if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
  2219. memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
  2220. rtlpriv->mac80211.vendor = PEER_ATH;
  2221. matched = true;
  2222. } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
  2223. memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
  2224. memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
  2225. rtlpriv->mac80211.vendor = PEER_BROAD;
  2226. matched = true;
  2227. } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
  2228. rtlpriv->mac80211.vendor = PEER_RAL;
  2229. matched = true;
  2230. } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
  2231. rtlpriv->mac80211.vendor = PEER_CISCO;
  2232. matched = true;
  2233. } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
  2234. rtlpriv->mac80211.vendor = PEER_MARV;
  2235. matched = true;
  2236. }
  2237. return matched;
  2238. }
  2239. static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
  2240. unsigned int len)
  2241. {
  2242. struct ieee80211_mgmt *mgmt = (void *)data;
  2243. struct octet_string vendor_ie;
  2244. u8 *pos, *end;
  2245. pos = (u8 *)mgmt->u.beacon.variable;
  2246. end = data + len;
  2247. while (pos < end) {
  2248. if (pos[0] == 221) {
  2249. vendor_ie.length = pos[1];
  2250. vendor_ie.octet = &pos[2];
  2251. if (rtl_chk_vendor_ouisub(hw, vendor_ie))
  2252. return true;
  2253. }
  2254. if (pos + 2 + pos[1] > end)
  2255. return false;
  2256. pos += 2 + pos[1];
  2257. }
  2258. return false;
  2259. }
  2260. void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
  2261. {
  2262. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2263. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2264. struct ieee80211_hdr *hdr = (void *)data;
  2265. u32 vendor = PEER_UNKNOWN;
  2266. static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
  2267. static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
  2268. static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
  2269. static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
  2270. static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
  2271. static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
  2272. static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
  2273. static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
  2274. static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
  2275. static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
  2276. static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
  2277. static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
  2278. static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
  2279. static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
  2280. static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
  2281. static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
  2282. if (mac->opmode != NL80211_IFTYPE_STATION)
  2283. return;
  2284. if (mac->link_state == MAC80211_NOLINK) {
  2285. mac->vendor = PEER_UNKNOWN;
  2286. return;
  2287. }
  2288. if (mac->cnt_after_linked > 2)
  2289. return;
  2290. /* check if this really is a beacon */
  2291. if (!ieee80211_is_beacon(hdr->frame_control))
  2292. return;
  2293. /* min. beacon length + FCS_LEN */
  2294. if (len <= 40 + FCS_LEN)
  2295. return;
  2296. /* and only beacons from the associated BSSID, please */
  2297. if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
  2298. return;
  2299. if (rtl_find_221_ie(hw, data, len))
  2300. vendor = mac->vendor;
  2301. if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
  2302. (memcmp(mac->bssid, ap5_2, 3) == 0) ||
  2303. (memcmp(mac->bssid, ap5_3, 3) == 0) ||
  2304. (memcmp(mac->bssid, ap5_4, 3) == 0) ||
  2305. (memcmp(mac->bssid, ap5_5, 3) == 0) ||
  2306. (memcmp(mac->bssid, ap5_6, 3) == 0) ||
  2307. vendor == PEER_ATH) {
  2308. vendor = PEER_ATH;
  2309. rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
  2310. } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
  2311. (memcmp(mac->bssid, ap4_5, 3) == 0) ||
  2312. (memcmp(mac->bssid, ap4_1, 3) == 0) ||
  2313. (memcmp(mac->bssid, ap4_2, 3) == 0) ||
  2314. (memcmp(mac->bssid, ap4_3, 3) == 0) ||
  2315. vendor == PEER_RAL) {
  2316. rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
  2317. vendor = PEER_RAL;
  2318. } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
  2319. vendor == PEER_CISCO) {
  2320. vendor = PEER_CISCO;
  2321. rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
  2322. } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
  2323. (memcmp(mac->bssid, ap3_2, 3) == 0) ||
  2324. (memcmp(mac->bssid, ap3_3, 3) == 0) ||
  2325. vendor == PEER_BROAD) {
  2326. rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
  2327. vendor = PEER_BROAD;
  2328. } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
  2329. vendor == PEER_MARV) {
  2330. vendor = PEER_MARV;
  2331. rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
  2332. }
  2333. mac->vendor = vendor;
  2334. }
  2335. EXPORT_SYMBOL_GPL(rtl_recognize_peer);
  2336. MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
  2337. MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
  2338. MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
  2339. MODULE_LICENSE("GPL");
  2340. MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
  2341. static int __init rtl_core_module_init(void)
  2342. {
  2343. BUILD_BUG_ON(TX_PWR_BY_RATE_NUM_RATE < TX_PWR_BY_RATE_NUM_SECTION);
  2344. BUILD_BUG_ON(MAX_RATE_SECTION_NUM != MAX_RATE_SECTION);
  2345. BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_24G != MAX_RATE_SECTION);
  2346. BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_5G != (MAX_RATE_SECTION - 1));
  2347. if (rtl_rate_control_register())
  2348. pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
  2349. /* add debugfs */
  2350. rtl_debugfs_add_topdir();
  2351. return 0;
  2352. }
  2353. static void __exit rtl_core_module_exit(void)
  2354. {
  2355. /*RC*/
  2356. rtl_rate_control_unregister();
  2357. /* remove debugfs */
  2358. rtl_debugfs_remove_topdir();
  2359. }
  2360. module_init(rtl_core_module_init);
  2361. module_exit(rtl_core_module_exit);