base.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #include "wifi.h"
  30. #include "rc.h"
  31. #include "base.h"
  32. #include "efuse.h"
  33. #include "cam.h"
  34. #include "ps.h"
  35. #include "regd.h"
  36. #include <linux/ip.h>
  37. #include <linux/module.h>
  38. /*
  39. *NOTICE!!!: This file will be very big, we should
  40. *keep it clear under following roles:
  41. *
  42. *This file include following parts, so, if you add new
  43. *functions into this file, please check which part it
  44. *should includes. or check if you should add new part
  45. *for this file:
  46. *
  47. *1) mac80211 init functions
  48. *2) tx information functions
  49. *3) functions called by core.c
  50. *4) wq & timer callback functions
  51. *5) frame process functions
  52. *6) IOT functions
  53. *7) sysfs functions
  54. *8) ...
  55. */
  56. /*********************************************************
  57. *
  58. * mac80211 init functions
  59. *
  60. *********************************************************/
  61. static struct ieee80211_channel rtl_channeltable_2g[] = {
  62. {.center_freq = 2412, .hw_value = 1,},
  63. {.center_freq = 2417, .hw_value = 2,},
  64. {.center_freq = 2422, .hw_value = 3,},
  65. {.center_freq = 2427, .hw_value = 4,},
  66. {.center_freq = 2432, .hw_value = 5,},
  67. {.center_freq = 2437, .hw_value = 6,},
  68. {.center_freq = 2442, .hw_value = 7,},
  69. {.center_freq = 2447, .hw_value = 8,},
  70. {.center_freq = 2452, .hw_value = 9,},
  71. {.center_freq = 2457, .hw_value = 10,},
  72. {.center_freq = 2462, .hw_value = 11,},
  73. {.center_freq = 2467, .hw_value = 12,},
  74. {.center_freq = 2472, .hw_value = 13,},
  75. {.center_freq = 2484, .hw_value = 14,},
  76. };
  77. static struct ieee80211_channel rtl_channeltable_5g[] = {
  78. {.center_freq = 5180, .hw_value = 36,},
  79. {.center_freq = 5200, .hw_value = 40,},
  80. {.center_freq = 5220, .hw_value = 44,},
  81. {.center_freq = 5240, .hw_value = 48,},
  82. {.center_freq = 5260, .hw_value = 52,},
  83. {.center_freq = 5280, .hw_value = 56,},
  84. {.center_freq = 5300, .hw_value = 60,},
  85. {.center_freq = 5320, .hw_value = 64,},
  86. {.center_freq = 5500, .hw_value = 100,},
  87. {.center_freq = 5520, .hw_value = 104,},
  88. {.center_freq = 5540, .hw_value = 108,},
  89. {.center_freq = 5560, .hw_value = 112,},
  90. {.center_freq = 5580, .hw_value = 116,},
  91. {.center_freq = 5600, .hw_value = 120,},
  92. {.center_freq = 5620, .hw_value = 124,},
  93. {.center_freq = 5640, .hw_value = 128,},
  94. {.center_freq = 5660, .hw_value = 132,},
  95. {.center_freq = 5680, .hw_value = 136,},
  96. {.center_freq = 5700, .hw_value = 140,},
  97. {.center_freq = 5745, .hw_value = 149,},
  98. {.center_freq = 5765, .hw_value = 153,},
  99. {.center_freq = 5785, .hw_value = 157,},
  100. {.center_freq = 5805, .hw_value = 161,},
  101. {.center_freq = 5825, .hw_value = 165,},
  102. };
  103. static struct ieee80211_rate rtl_ratetable_2g[] = {
  104. {.bitrate = 10, .hw_value = 0x00,},
  105. {.bitrate = 20, .hw_value = 0x01,},
  106. {.bitrate = 55, .hw_value = 0x02,},
  107. {.bitrate = 110, .hw_value = 0x03,},
  108. {.bitrate = 60, .hw_value = 0x04,},
  109. {.bitrate = 90, .hw_value = 0x05,},
  110. {.bitrate = 120, .hw_value = 0x06,},
  111. {.bitrate = 180, .hw_value = 0x07,},
  112. {.bitrate = 240, .hw_value = 0x08,},
  113. {.bitrate = 360, .hw_value = 0x09,},
  114. {.bitrate = 480, .hw_value = 0x0a,},
  115. {.bitrate = 540, .hw_value = 0x0b,},
  116. };
  117. static struct ieee80211_rate rtl_ratetable_5g[] = {
  118. {.bitrate = 60, .hw_value = 0x04,},
  119. {.bitrate = 90, .hw_value = 0x05,},
  120. {.bitrate = 120, .hw_value = 0x06,},
  121. {.bitrate = 180, .hw_value = 0x07,},
  122. {.bitrate = 240, .hw_value = 0x08,},
  123. {.bitrate = 360, .hw_value = 0x09,},
  124. {.bitrate = 480, .hw_value = 0x0a,},
  125. {.bitrate = 540, .hw_value = 0x0b,},
  126. };
  127. static const struct ieee80211_supported_band rtl_band_2ghz = {
  128. .band = IEEE80211_BAND_2GHZ,
  129. .channels = rtl_channeltable_2g,
  130. .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
  131. .bitrates = rtl_ratetable_2g,
  132. .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
  133. .ht_cap = {0},
  134. };
  135. static struct ieee80211_supported_band rtl_band_5ghz = {
  136. .band = IEEE80211_BAND_5GHZ,
  137. .channels = rtl_channeltable_5g,
  138. .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
  139. .bitrates = rtl_ratetable_5g,
  140. .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
  141. .ht_cap = {0},
  142. };
  143. static const u8 tid_to_ac[] = {
  144. 2, /* IEEE80211_AC_BE */
  145. 3, /* IEEE80211_AC_BK */
  146. 3, /* IEEE80211_AC_BK */
  147. 2, /* IEEE80211_AC_BE */
  148. 1, /* IEEE80211_AC_VI */
  149. 1, /* IEEE80211_AC_VI */
  150. 0, /* IEEE80211_AC_VO */
  151. 0, /* IEEE80211_AC_VO */
  152. };
  153. u8 rtl_tid_to_ac(u8 tid)
  154. {
  155. return tid_to_ac[tid];
  156. }
  157. static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
  158. struct ieee80211_sta_ht_cap *ht_cap)
  159. {
  160. struct rtl_priv *rtlpriv = rtl_priv(hw);
  161. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  162. ht_cap->ht_supported = true;
  163. ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  164. IEEE80211_HT_CAP_SGI_40 |
  165. IEEE80211_HT_CAP_SGI_20 |
  166. IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
  167. if (rtlpriv->rtlhal.disable_amsdu_8k)
  168. ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  169. /*
  170. *Maximum length of AMPDU that the STA can receive.
  171. *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  172. */
  173. ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  174. /*Minimum MPDU start spacing , */
  175. ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  176. ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  177. /*
  178. *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
  179. *base on ant_num
  180. *rx_mask: RX mask
  181. *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7
  182. *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15
  183. *if rx_ant >=3 rx_mask[2]=0xff;
  184. *if BW_40 rx_mask[4]=0x01;
  185. *highest supported RX rate
  186. */
  187. if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_2T2R) {
  188. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T2R or 2T2R\n");
  189. ht_cap->mcs.rx_mask[0] = 0xFF;
  190. ht_cap->mcs.rx_mask[1] = 0xFF;
  191. ht_cap->mcs.rx_mask[4] = 0x01;
  192. ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
  193. } else if (get_rf_type(rtlphy) == RF_1T1R) {
  194. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
  195. ht_cap->mcs.rx_mask[0] = 0xFF;
  196. ht_cap->mcs.rx_mask[1] = 0x00;
  197. ht_cap->mcs.rx_mask[4] = 0x01;
  198. ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
  199. }
  200. }
  201. static void _rtl_init_mac80211(struct ieee80211_hw *hw)
  202. {
  203. struct rtl_priv *rtlpriv = rtl_priv(hw);
  204. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  205. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  206. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  207. struct ieee80211_supported_band *sband;
  208. if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset ==
  209. BAND_ON_BOTH) {
  210. /* 1: 2.4 G bands */
  211. /* <1> use mac->bands as mem for hw->wiphy->bands */
  212. sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
  213. /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
  214. * to default value(1T1R) */
  215. memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
  216. sizeof(struct ieee80211_supported_band));
  217. /* <3> init ht cap base on ant_num */
  218. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  219. /* <4> set mac->sband to wiphy->sband */
  220. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
  221. /* 2: 5 G bands */
  222. /* <1> use mac->bands as mem for hw->wiphy->bands */
  223. sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
  224. /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
  225. * to default value(1T1R) */
  226. memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
  227. sizeof(struct ieee80211_supported_band));
  228. /* <3> init ht cap base on ant_num */
  229. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  230. /* <4> set mac->sband to wiphy->sband */
  231. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
  232. } else {
  233. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  234. /* <1> use mac->bands as mem for hw->wiphy->bands */
  235. sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
  236. /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
  237. * to default value(1T1R) */
  238. memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
  239. &rtl_band_2ghz,
  240. sizeof(struct ieee80211_supported_band));
  241. /* <3> init ht cap base on ant_num */
  242. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  243. /* <4> set mac->sband to wiphy->sband */
  244. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
  245. } else if (rtlhal->current_bandtype == BAND_ON_5G) {
  246. /* <1> use mac->bands as mem for hw->wiphy->bands */
  247. sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
  248. /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
  249. * to default value(1T1R) */
  250. memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
  251. &rtl_band_5ghz,
  252. sizeof(struct ieee80211_supported_band));
  253. /* <3> init ht cap base on ant_num */
  254. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  255. /* <4> set mac->sband to wiphy->sband */
  256. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
  257. } else {
  258. RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n",
  259. rtlhal->current_bandtype);
  260. }
  261. }
  262. /* <5> set hw caps */
  263. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  264. IEEE80211_HW_RX_INCLUDES_FCS |
  265. IEEE80211_HW_AMPDU_AGGREGATION |
  266. IEEE80211_HW_CONNECTION_MONITOR |
  267. /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
  268. IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
  269. /* swlps or hwlps has been set in diff chip in init_sw_vars */
  270. if (rtlpriv->psc.swctrl_lps)
  271. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  272. IEEE80211_HW_PS_NULLFUNC_STACK |
  273. /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
  274. 0;
  275. hw->wiphy->interface_modes =
  276. BIT(NL80211_IFTYPE_AP) |
  277. BIT(NL80211_IFTYPE_STATION) |
  278. BIT(NL80211_IFTYPE_ADHOC);
  279. hw->wiphy->rts_threshold = 2347;
  280. hw->queues = AC_MAX;
  281. hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
  282. /* TODO: Correct this value for our hw */
  283. /* TODO: define these hard code value */
  284. hw->channel_change_time = 100;
  285. hw->max_listen_interval = 10;
  286. hw->max_rate_tries = 4;
  287. /* hw->max_rates = 1; */
  288. hw->sta_data_size = sizeof(struct rtl_sta_info);
  289. /* <6> mac address */
  290. if (is_valid_ether_addr(rtlefuse->dev_addr)) {
  291. SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
  292. } else {
  293. u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
  294. get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
  295. SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
  296. }
  297. }
  298. static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
  299. {
  300. struct rtl_priv *rtlpriv = rtl_priv(hw);
  301. /* <1> timer */
  302. init_timer(&rtlpriv->works.watchdog_timer);
  303. setup_timer(&rtlpriv->works.watchdog_timer,
  304. rtl_watch_dog_timer_callback, (unsigned long)hw);
  305. /* <2> work queue */
  306. rtlpriv->works.hw = hw;
  307. rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0);
  308. INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
  309. (void *)rtl_watchdog_wq_callback);
  310. INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
  311. (void *)rtl_ips_nic_off_wq_callback);
  312. INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
  313. (void *)rtl_swlps_wq_callback);
  314. INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
  315. (void *)rtl_swlps_rfon_wq_callback);
  316. }
  317. void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
  318. {
  319. struct rtl_priv *rtlpriv = rtl_priv(hw);
  320. del_timer_sync(&rtlpriv->works.watchdog_timer);
  321. cancel_delayed_work(&rtlpriv->works.watchdog_wq);
  322. cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
  323. cancel_delayed_work(&rtlpriv->works.ps_work);
  324. cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
  325. }
  326. void rtl_init_rfkill(struct ieee80211_hw *hw)
  327. {
  328. struct rtl_priv *rtlpriv = rtl_priv(hw);
  329. bool radio_state;
  330. bool blocked;
  331. u8 valid = 0;
  332. /*set init state to on */
  333. rtlpriv->rfkill.rfkill_state = true;
  334. wiphy_rfkill_set_hw_state(hw->wiphy, 0);
  335. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  336. if (valid) {
  337. pr_info("wireless switch is %s\n",
  338. rtlpriv->rfkill.rfkill_state ? "on" : "off");
  339. rtlpriv->rfkill.rfkill_state = radio_state;
  340. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  341. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  342. }
  343. wiphy_rfkill_start_polling(hw->wiphy);
  344. }
  345. EXPORT_SYMBOL(rtl_init_rfkill);
  346. void rtl_deinit_rfkill(struct ieee80211_hw *hw)
  347. {
  348. wiphy_rfkill_stop_polling(hw->wiphy);
  349. }
  350. int rtl_init_core(struct ieee80211_hw *hw)
  351. {
  352. struct rtl_priv *rtlpriv = rtl_priv(hw);
  353. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  354. /* <1> init mac80211 */
  355. _rtl_init_mac80211(hw);
  356. rtlmac->hw = hw;
  357. /* <2> rate control register */
  358. hw->rate_control_algorithm = "rtl_rc";
  359. /*
  360. * <3> init CRDA must come after init
  361. * mac80211 hw in _rtl_init_mac80211.
  362. */
  363. if (rtl_regd_init(hw, rtl_reg_notifier)) {
  364. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n");
  365. return 1;
  366. } else {
  367. /* CRDA regd hint must after init CRDA */
  368. if (regulatory_hint(hw->wiphy, rtlpriv->regd.alpha2)) {
  369. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  370. "regulatory_hint fail\n");
  371. }
  372. }
  373. /* <4> locks */
  374. mutex_init(&rtlpriv->locks.conf_mutex);
  375. mutex_init(&rtlpriv->locks.ps_mutex);
  376. spin_lock_init(&rtlpriv->locks.ips_lock);
  377. spin_lock_init(&rtlpriv->locks.irq_th_lock);
  378. spin_lock_init(&rtlpriv->locks.h2c_lock);
  379. spin_lock_init(&rtlpriv->locks.rf_ps_lock);
  380. spin_lock_init(&rtlpriv->locks.rf_lock);
  381. spin_lock_init(&rtlpriv->locks.waitq_lock);
  382. spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
  383. rtlmac->link_state = MAC80211_NOLINK;
  384. /* <5> init deferred work */
  385. _rtl_init_deferred_work(hw);
  386. return 0;
  387. }
  388. void rtl_deinit_core(struct ieee80211_hw *hw)
  389. {
  390. }
  391. void rtl_init_rx_config(struct ieee80211_hw *hw)
  392. {
  393. struct rtl_priv *rtlpriv = rtl_priv(hw);
  394. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  395. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
  396. }
  397. /*********************************************************
  398. *
  399. * tx information functions
  400. *
  401. *********************************************************/
  402. static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
  403. struct rtl_tcb_desc *tcb_desc,
  404. struct ieee80211_tx_info *info)
  405. {
  406. struct rtl_priv *rtlpriv = rtl_priv(hw);
  407. u8 rate_flag = info->control.rates[0].flags;
  408. tcb_desc->use_shortpreamble = false;
  409. /* 1M can only use Long Preamble. 11B spec */
  410. if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
  411. return;
  412. else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  413. tcb_desc->use_shortpreamble = true;
  414. return;
  415. }
  416. static void _rtl_query_shortgi(struct ieee80211_hw *hw,
  417. struct ieee80211_sta *sta,
  418. struct rtl_tcb_desc *tcb_desc,
  419. struct ieee80211_tx_info *info)
  420. {
  421. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  422. u8 rate_flag = info->control.rates[0].flags;
  423. u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
  424. tcb_desc->use_shortgi = false;
  425. if (sta == NULL)
  426. return;
  427. sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  428. sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
  429. if (!(sta->ht_cap.ht_supported))
  430. return;
  431. if (!sgi_40 && !sgi_20)
  432. return;
  433. if (mac->opmode == NL80211_IFTYPE_STATION)
  434. bw_40 = mac->bw_40;
  435. else if (mac->opmode == NL80211_IFTYPE_AP ||
  436. mac->opmode == NL80211_IFTYPE_ADHOC)
  437. bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
  438. if (bw_40 && sgi_40)
  439. tcb_desc->use_shortgi = true;
  440. else if ((bw_40 == false) && sgi_20)
  441. tcb_desc->use_shortgi = true;
  442. if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
  443. tcb_desc->use_shortgi = false;
  444. }
  445. static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
  446. struct rtl_tcb_desc *tcb_desc,
  447. struct ieee80211_tx_info *info)
  448. {
  449. struct rtl_priv *rtlpriv = rtl_priv(hw);
  450. u8 rate_flag = info->control.rates[0].flags;
  451. /* Common Settings */
  452. tcb_desc->rts_stbc = false;
  453. tcb_desc->cts_enable = false;
  454. tcb_desc->rts_sc = 0;
  455. tcb_desc->rts_bw = false;
  456. tcb_desc->rts_use_shortpreamble = false;
  457. tcb_desc->rts_use_shortgi = false;
  458. if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  459. /* Use CTS-to-SELF in protection mode. */
  460. tcb_desc->rts_enable = true;
  461. tcb_desc->cts_enable = true;
  462. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  463. } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
  464. /* Use RTS-CTS in protection mode. */
  465. tcb_desc->rts_enable = true;
  466. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  467. }
  468. }
  469. static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
  470. struct ieee80211_sta *sta,
  471. struct rtl_tcb_desc *tcb_desc)
  472. {
  473. struct rtl_priv *rtlpriv = rtl_priv(hw);
  474. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  475. struct rtl_sta_info *sta_entry = NULL;
  476. u8 ratr_index = 7;
  477. if (sta) {
  478. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  479. ratr_index = sta_entry->ratr_index;
  480. }
  481. if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
  482. if (mac->opmode == NL80211_IFTYPE_STATION) {
  483. tcb_desc->ratr_index = 0;
  484. } else if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  485. if (tcb_desc->multicast || tcb_desc->broadcast) {
  486. tcb_desc->hw_rate =
  487. rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
  488. tcb_desc->use_driver_rate = 1;
  489. } else {
  490. /* TODO */
  491. }
  492. tcb_desc->ratr_index = ratr_index;
  493. } else if (mac->opmode == NL80211_IFTYPE_AP) {
  494. tcb_desc->ratr_index = ratr_index;
  495. }
  496. }
  497. if (rtlpriv->dm.useramask) {
  498. /* TODO we will differentiate adhoc and station futrue */
  499. if (mac->opmode == NL80211_IFTYPE_STATION) {
  500. tcb_desc->mac_id = 0;
  501. if (mac->mode == WIRELESS_MODE_N_24G)
  502. tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
  503. else if (mac->mode == WIRELESS_MODE_N_5G)
  504. tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
  505. else if (mac->mode & WIRELESS_MODE_G)
  506. tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
  507. else if (mac->mode & WIRELESS_MODE_B)
  508. tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
  509. else if (mac->mode & WIRELESS_MODE_A)
  510. tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
  511. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  512. mac->opmode == NL80211_IFTYPE_ADHOC) {
  513. if (NULL != sta) {
  514. if (sta->aid > 0)
  515. tcb_desc->mac_id = sta->aid + 1;
  516. else
  517. tcb_desc->mac_id = 1;
  518. } else {
  519. tcb_desc->mac_id = 0;
  520. }
  521. }
  522. }
  523. }
  524. static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
  525. struct ieee80211_sta *sta,
  526. struct rtl_tcb_desc *tcb_desc)
  527. {
  528. struct rtl_priv *rtlpriv = rtl_priv(hw);
  529. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  530. tcb_desc->packet_bw = false;
  531. if (!sta)
  532. return;
  533. if (mac->opmode == NL80211_IFTYPE_AP ||
  534. mac->opmode == NL80211_IFTYPE_ADHOC) {
  535. if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
  536. return;
  537. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  538. if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
  539. return;
  540. }
  541. if (tcb_desc->multicast || tcb_desc->broadcast)
  542. return;
  543. /*use legency rate, shall use 20MHz */
  544. if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
  545. return;
  546. tcb_desc->packet_bw = true;
  547. }
  548. static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw)
  549. {
  550. struct rtl_priv *rtlpriv = rtl_priv(hw);
  551. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  552. u8 hw_rate;
  553. if (get_rf_type(rtlphy) == RF_2T2R)
  554. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
  555. else
  556. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
  557. return hw_rate;
  558. }
  559. /* mac80211's rate_idx is like this:
  560. *
  561. * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
  562. *
  563. * B/G rate:
  564. * (rx_status->flag & RX_FLAG_HT) = 0,
  565. * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11,
  566. *
  567. * N rate:
  568. * (rx_status->flag & RX_FLAG_HT) = 1,
  569. * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
  570. *
  571. * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
  572. * A rate:
  573. * (rx_status->flag & RX_FLAG_HT) = 0,
  574. * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7,
  575. *
  576. * N rate:
  577. * (rx_status->flag & RX_FLAG_HT) = 1,
  578. * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
  579. */
  580. int rtlwifi_rate_mapping(struct ieee80211_hw *hw,
  581. bool isht, u8 desc_rate, bool first_ampdu)
  582. {
  583. int rate_idx;
  584. if (false == isht) {
  585. if (IEEE80211_BAND_2GHZ == hw->conf.channel->band) {
  586. switch (desc_rate) {
  587. case DESC92_RATE1M:
  588. rate_idx = 0;
  589. break;
  590. case DESC92_RATE2M:
  591. rate_idx = 1;
  592. break;
  593. case DESC92_RATE5_5M:
  594. rate_idx = 2;
  595. break;
  596. case DESC92_RATE11M:
  597. rate_idx = 3;
  598. break;
  599. case DESC92_RATE6M:
  600. rate_idx = 4;
  601. break;
  602. case DESC92_RATE9M:
  603. rate_idx = 5;
  604. break;
  605. case DESC92_RATE12M:
  606. rate_idx = 6;
  607. break;
  608. case DESC92_RATE18M:
  609. rate_idx = 7;
  610. break;
  611. case DESC92_RATE24M:
  612. rate_idx = 8;
  613. break;
  614. case DESC92_RATE36M:
  615. rate_idx = 9;
  616. break;
  617. case DESC92_RATE48M:
  618. rate_idx = 10;
  619. break;
  620. case DESC92_RATE54M:
  621. rate_idx = 11;
  622. break;
  623. default:
  624. rate_idx = 0;
  625. break;
  626. }
  627. } else {
  628. switch (desc_rate) {
  629. case DESC92_RATE6M:
  630. rate_idx = 0;
  631. break;
  632. case DESC92_RATE9M:
  633. rate_idx = 1;
  634. break;
  635. case DESC92_RATE12M:
  636. rate_idx = 2;
  637. break;
  638. case DESC92_RATE18M:
  639. rate_idx = 3;
  640. break;
  641. case DESC92_RATE24M:
  642. rate_idx = 4;
  643. break;
  644. case DESC92_RATE36M:
  645. rate_idx = 5;
  646. break;
  647. case DESC92_RATE48M:
  648. rate_idx = 6;
  649. break;
  650. case DESC92_RATE54M:
  651. rate_idx = 7;
  652. break;
  653. default:
  654. rate_idx = 0;
  655. break;
  656. }
  657. }
  658. } else {
  659. switch (desc_rate) {
  660. case DESC92_RATEMCS0:
  661. rate_idx = 0;
  662. break;
  663. case DESC92_RATEMCS1:
  664. rate_idx = 1;
  665. break;
  666. case DESC92_RATEMCS2:
  667. rate_idx = 2;
  668. break;
  669. case DESC92_RATEMCS3:
  670. rate_idx = 3;
  671. break;
  672. case DESC92_RATEMCS4:
  673. rate_idx = 4;
  674. break;
  675. case DESC92_RATEMCS5:
  676. rate_idx = 5;
  677. break;
  678. case DESC92_RATEMCS6:
  679. rate_idx = 6;
  680. break;
  681. case DESC92_RATEMCS7:
  682. rate_idx = 7;
  683. break;
  684. case DESC92_RATEMCS8:
  685. rate_idx = 8;
  686. break;
  687. case DESC92_RATEMCS9:
  688. rate_idx = 9;
  689. break;
  690. case DESC92_RATEMCS10:
  691. rate_idx = 10;
  692. break;
  693. case DESC92_RATEMCS11:
  694. rate_idx = 11;
  695. break;
  696. case DESC92_RATEMCS12:
  697. rate_idx = 12;
  698. break;
  699. case DESC92_RATEMCS13:
  700. rate_idx = 13;
  701. break;
  702. case DESC92_RATEMCS14:
  703. rate_idx = 14;
  704. break;
  705. case DESC92_RATEMCS15:
  706. rate_idx = 15;
  707. break;
  708. default:
  709. rate_idx = 0;
  710. break;
  711. }
  712. }
  713. return rate_idx;
  714. }
  715. EXPORT_SYMBOL(rtlwifi_rate_mapping);
  716. bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
  717. {
  718. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  719. struct rtl_priv *rtlpriv = rtl_priv(hw);
  720. __le16 fc = rtl_get_fc(skb);
  721. if (rtlpriv->dm.supp_phymode_switch &&
  722. mac->link_state < MAC80211_LINKED &&
  723. (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
  724. if (rtlpriv->cfg->ops->check_switch_to_dmdp)
  725. rtlpriv->cfg->ops->check_switch_to_dmdp(hw);
  726. }
  727. if (ieee80211_is_auth(fc)) {
  728. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
  729. rtl_ips_nic_on(hw);
  730. mac->link_state = MAC80211_LINKING;
  731. /* Dual mac */
  732. rtlpriv->phy.need_iqk = true;
  733. }
  734. return true;
  735. }
  736. void rtl_get_tcb_desc(struct ieee80211_hw *hw,
  737. struct ieee80211_tx_info *info,
  738. struct ieee80211_sta *sta,
  739. struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
  740. {
  741. struct rtl_priv *rtlpriv = rtl_priv(hw);
  742. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  743. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  744. struct ieee80211_rate *txrate;
  745. __le16 fc = hdr->frame_control;
  746. txrate = ieee80211_get_tx_rate(hw, info);
  747. if (txrate)
  748. tcb_desc->hw_rate = txrate->hw_value;
  749. else
  750. tcb_desc->hw_rate = 0;
  751. if (ieee80211_is_data(fc)) {
  752. /*
  753. *we set data rate INX 0
  754. *in rtl_rc.c if skb is special data or
  755. *mgt which need low data rate.
  756. */
  757. /*
  758. *So tcb_desc->hw_rate is just used for
  759. *special data and mgt frames
  760. */
  761. if (info->control.rates[0].idx == 0 ||
  762. ieee80211_is_nullfunc(fc)) {
  763. tcb_desc->use_driver_rate = true;
  764. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  765. tcb_desc->disable_ratefallback = 1;
  766. } else {
  767. /*
  768. *because hw will nerver use hw_rate
  769. *when tcb_desc->use_driver_rate = false
  770. *so we never set highest N rate here,
  771. *and N rate will all be controlled by FW
  772. *when tcb_desc->use_driver_rate = false
  773. */
  774. if (sta && (sta->ht_cap.ht_supported)) {
  775. tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw);
  776. } else {
  777. if (rtlmac->mode == WIRELESS_MODE_B) {
  778. tcb_desc->hw_rate =
  779. rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
  780. } else {
  781. tcb_desc->hw_rate =
  782. rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
  783. }
  784. }
  785. }
  786. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  787. tcb_desc->multicast = 1;
  788. else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
  789. tcb_desc->broadcast = 1;
  790. _rtl_txrate_selectmode(hw, sta, tcb_desc);
  791. _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
  792. _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
  793. _rtl_query_shortgi(hw, sta, tcb_desc, info);
  794. _rtl_query_protection_mode(hw, tcb_desc, info);
  795. } else {
  796. tcb_desc->use_driver_rate = true;
  797. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  798. tcb_desc->disable_ratefallback = 1;
  799. tcb_desc->mac_id = 0;
  800. tcb_desc->packet_bw = false;
  801. }
  802. }
  803. EXPORT_SYMBOL(rtl_get_tcb_desc);
  804. bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
  805. {
  806. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  807. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  808. struct rtl_priv *rtlpriv = rtl_priv(hw);
  809. __le16 fc = hdr->frame_control;
  810. u8 *act = (u8 *)skb->data + MAC80211_3ADDR_LEN;
  811. u8 category;
  812. if (!ieee80211_is_action(fc))
  813. return true;
  814. category = *act;
  815. act++;
  816. switch (category) {
  817. case ACT_CAT_BA:
  818. switch (*act) {
  819. case ACT_ADDBAREQ:
  820. if (mac->act_scanning)
  821. return false;
  822. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  823. "%s ACT_ADDBAREQ From :%pM\n",
  824. is_tx ? "Tx" : "Rx", hdr->addr2);
  825. break;
  826. case ACT_ADDBARSP:
  827. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  828. "%s ACT_ADDBARSP From :%pM\n",
  829. is_tx ? "Tx" : "Rx", hdr->addr2);
  830. break;
  831. case ACT_DELBA:
  832. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  833. "ACT_ADDBADEL From :%pM\n", hdr->addr2);
  834. break;
  835. }
  836. break;
  837. default:
  838. break;
  839. }
  840. return true;
  841. }
  842. /*should call before software enc*/
  843. u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
  844. {
  845. struct rtl_priv *rtlpriv = rtl_priv(hw);
  846. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  847. __le16 fc = rtl_get_fc(skb);
  848. u16 ether_type;
  849. u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
  850. const struct iphdr *ip;
  851. if (!ieee80211_is_data(fc))
  852. return false;
  853. ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len +
  854. SNAP_SIZE + PROTOC_TYPE_SIZE);
  855. ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE);
  856. /* ether_type = ntohs(ether_type); */
  857. if (ETH_P_IP == ether_type) {
  858. if (IPPROTO_UDP == ip->protocol) {
  859. struct udphdr *udp = (struct udphdr *)((u8 *) ip +
  860. (ip->ihl << 2));
  861. if (((((u8 *) udp)[1] == 68) &&
  862. (((u8 *) udp)[3] == 67)) ||
  863. ((((u8 *) udp)[1] == 67) &&
  864. (((u8 *) udp)[3] == 68))) {
  865. /*
  866. * 68 : UDP BOOTP client
  867. * 67 : UDP BOOTP server
  868. */
  869. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
  870. DBG_DMESG, "dhcp %s !!\n",
  871. is_tx ? "Tx" : "Rx");
  872. if (is_tx) {
  873. schedule_work(&rtlpriv->
  874. works.lps_leave_work);
  875. ppsc->last_delaylps_stamp_jiffies =
  876. jiffies;
  877. }
  878. return true;
  879. }
  880. }
  881. } else if (ETH_P_ARP == ether_type) {
  882. if (is_tx) {
  883. schedule_work(&rtlpriv->works.lps_leave_work);
  884. ppsc->last_delaylps_stamp_jiffies = jiffies;
  885. }
  886. return true;
  887. } else if (ETH_P_PAE == ether_type) {
  888. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  889. "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx");
  890. if (is_tx) {
  891. schedule_work(&rtlpriv->works.lps_leave_work);
  892. ppsc->last_delaylps_stamp_jiffies = jiffies;
  893. }
  894. return true;
  895. } else if (ETH_P_IPV6 == ether_type) {
  896. /* IPv6 */
  897. return true;
  898. }
  899. return false;
  900. }
  901. /*********************************************************
  902. *
  903. * functions called by core.c
  904. *
  905. *********************************************************/
  906. int rtl_tx_agg_start(struct ieee80211_hw *hw,
  907. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  908. {
  909. struct rtl_priv *rtlpriv = rtl_priv(hw);
  910. struct rtl_tid_data *tid_data;
  911. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  912. struct rtl_sta_info *sta_entry = NULL;
  913. if (sta == NULL)
  914. return -EINVAL;
  915. if (unlikely(tid >= MAX_TID_COUNT))
  916. return -EINVAL;
  917. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  918. if (!sta_entry)
  919. return -ENXIO;
  920. tid_data = &sta_entry->tids[tid];
  921. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d seq:%d\n",
  922. sta->addr, tid, tid_data->seq_number);
  923. *ssn = tid_data->seq_number;
  924. tid_data->agg.agg_state = RTL_AGG_START;
  925. ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
  926. return 0;
  927. }
  928. int rtl_tx_agg_stop(struct ieee80211_hw *hw,
  929. struct ieee80211_sta *sta, u16 tid)
  930. {
  931. struct rtl_priv *rtlpriv = rtl_priv(hw);
  932. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  933. struct rtl_sta_info *sta_entry = NULL;
  934. if (sta == NULL)
  935. return -EINVAL;
  936. if (!sta->addr) {
  937. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
  938. return -EINVAL;
  939. }
  940. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
  941. sta->addr, tid);
  942. if (unlikely(tid >= MAX_TID_COUNT))
  943. return -EINVAL;
  944. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  945. sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
  946. ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
  947. return 0;
  948. }
  949. int rtl_tx_agg_oper(struct ieee80211_hw *hw,
  950. struct ieee80211_sta *sta, u16 tid)
  951. {
  952. struct rtl_priv *rtlpriv = rtl_priv(hw);
  953. struct rtl_sta_info *sta_entry = NULL;
  954. if (sta == NULL)
  955. return -EINVAL;
  956. if (!sta->addr) {
  957. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
  958. return -EINVAL;
  959. }
  960. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
  961. sta->addr, tid);
  962. if (unlikely(tid >= MAX_TID_COUNT))
  963. return -EINVAL;
  964. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  965. sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
  966. return 0;
  967. }
  968. /*********************************************************
  969. *
  970. * wq & timer callback functions
  971. *
  972. *********************************************************/
  973. void rtl_watchdog_wq_callback(void *data)
  974. {
  975. struct rtl_works *rtlworks = container_of_dwork_rtl(data,
  976. struct rtl_works,
  977. watchdog_wq);
  978. struct ieee80211_hw *hw = rtlworks->hw;
  979. struct rtl_priv *rtlpriv = rtl_priv(hw);
  980. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  981. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  982. bool busytraffic = false;
  983. bool higher_busytraffic = false;
  984. bool higher_busyrxtraffic = false;
  985. u8 idx, tid;
  986. u32 rx_cnt_inp4eriod = 0;
  987. u32 tx_cnt_inp4eriod = 0;
  988. u32 aver_rx_cnt_inperiod = 0;
  989. u32 aver_tx_cnt_inperiod = 0;
  990. u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
  991. u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
  992. bool enter_ps = false;
  993. if (is_hal_stop(rtlhal))
  994. return;
  995. /* <1> Determine if action frame is allowed */
  996. if (mac->link_state > MAC80211_NOLINK) {
  997. if (mac->cnt_after_linked < 20)
  998. mac->cnt_after_linked++;
  999. } else {
  1000. mac->cnt_after_linked = 0;
  1001. }
  1002. /*
  1003. *<2> to check if traffic busy, if
  1004. * busytraffic we don't change channel
  1005. */
  1006. if (mac->link_state >= MAC80211_LINKED) {
  1007. /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
  1008. for (idx = 0; idx <= 2; idx++) {
  1009. rtlpriv->link_info.num_rx_in4period[idx] =
  1010. rtlpriv->link_info.num_rx_in4period[idx + 1];
  1011. rtlpriv->link_info.num_tx_in4period[idx] =
  1012. rtlpriv->link_info.num_tx_in4period[idx + 1];
  1013. }
  1014. rtlpriv->link_info.num_rx_in4period[3] =
  1015. rtlpriv->link_info.num_rx_inperiod;
  1016. rtlpriv->link_info.num_tx_in4period[3] =
  1017. rtlpriv->link_info.num_tx_inperiod;
  1018. for (idx = 0; idx <= 3; idx++) {
  1019. rx_cnt_inp4eriod +=
  1020. rtlpriv->link_info.num_rx_in4period[idx];
  1021. tx_cnt_inp4eriod +=
  1022. rtlpriv->link_info.num_tx_in4period[idx];
  1023. }
  1024. aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
  1025. aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
  1026. /* (2) check traffic busy */
  1027. if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100)
  1028. busytraffic = true;
  1029. /* Higher Tx/Rx data. */
  1030. if (aver_rx_cnt_inperiod > 4000 ||
  1031. aver_tx_cnt_inperiod > 4000) {
  1032. higher_busytraffic = true;
  1033. /* Extremely high Rx data. */
  1034. if (aver_rx_cnt_inperiod > 5000)
  1035. higher_busyrxtraffic = true;
  1036. }
  1037. /* check every tid's tx traffic */
  1038. for (tid = 0; tid <= 7; tid++) {
  1039. for (idx = 0; idx <= 2; idx++)
  1040. rtlpriv->link_info.tidtx_in4period[tid][idx] =
  1041. rtlpriv->link_info.tidtx_in4period[tid]
  1042. [idx + 1];
  1043. rtlpriv->link_info.tidtx_in4period[tid][3] =
  1044. rtlpriv->link_info.tidtx_inperiod[tid];
  1045. for (idx = 0; idx <= 3; idx++)
  1046. tidtx_inp4eriod[tid] +=
  1047. rtlpriv->link_info.tidtx_in4period[tid][idx];
  1048. aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
  1049. if (aver_tidtx_inperiod[tid] > 5000)
  1050. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1051. true;
  1052. else
  1053. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1054. false;
  1055. }
  1056. if (((rtlpriv->link_info.num_rx_inperiod +
  1057. rtlpriv->link_info.num_tx_inperiod) > 8) ||
  1058. (rtlpriv->link_info.num_rx_inperiod > 2))
  1059. enter_ps = false;
  1060. else
  1061. enter_ps = true;
  1062. /* LeisurePS only work in infra mode. */
  1063. if (enter_ps)
  1064. rtl_lps_enter(hw);
  1065. else
  1066. rtl_lps_leave(hw);
  1067. }
  1068. rtlpriv->link_info.num_rx_inperiod = 0;
  1069. rtlpriv->link_info.num_tx_inperiod = 0;
  1070. for (tid = 0; tid <= 7; tid++)
  1071. rtlpriv->link_info.tidtx_inperiod[tid] = 0;
  1072. rtlpriv->link_info.busytraffic = busytraffic;
  1073. rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
  1074. rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
  1075. /* <3> DM */
  1076. rtlpriv->cfg->ops->dm_watchdog(hw);
  1077. }
  1078. void rtl_watch_dog_timer_callback(unsigned long data)
  1079. {
  1080. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  1081. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1082. queue_delayed_work(rtlpriv->works.rtl_wq,
  1083. &rtlpriv->works.watchdog_wq, 0);
  1084. mod_timer(&rtlpriv->works.watchdog_timer,
  1085. jiffies + MSECS(RTL_WATCH_DOG_TIME));
  1086. }
  1087. /*********************************************************
  1088. *
  1089. * frame process functions
  1090. *
  1091. *********************************************************/
  1092. u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
  1093. {
  1094. struct ieee80211_mgmt *mgmt = (void *)data;
  1095. u8 *pos, *end;
  1096. pos = (u8 *)mgmt->u.beacon.variable;
  1097. end = data + len;
  1098. while (pos < end) {
  1099. if (pos + 2 + pos[1] > end)
  1100. return NULL;
  1101. if (pos[0] == ie)
  1102. return pos;
  1103. pos += 2 + pos[1];
  1104. }
  1105. return NULL;
  1106. }
  1107. /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
  1108. /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
  1109. static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
  1110. enum ieee80211_smps_mode smps, u8 *da, u8 *bssid)
  1111. {
  1112. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1113. struct sk_buff *skb;
  1114. struct ieee80211_mgmt *action_frame;
  1115. /* 27 = header + category + action + smps mode */
  1116. skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
  1117. if (!skb)
  1118. return NULL;
  1119. skb_reserve(skb, hw->extra_tx_headroom);
  1120. action_frame = (void *)skb_put(skb, 27);
  1121. memset(action_frame, 0, 27);
  1122. memcpy(action_frame->da, da, ETH_ALEN);
  1123. memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
  1124. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  1125. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1126. IEEE80211_STYPE_ACTION);
  1127. action_frame->u.action.category = WLAN_CATEGORY_HT;
  1128. action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
  1129. switch (smps) {
  1130. case IEEE80211_SMPS_AUTOMATIC:/* 0 */
  1131. case IEEE80211_SMPS_NUM_MODES:/* 4 */
  1132. WARN_ON(1);
  1133. case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
  1134. action_frame->u.action.u.ht_smps.smps_control =
  1135. WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
  1136. break;
  1137. case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
  1138. action_frame->u.action.u.ht_smps.smps_control =
  1139. WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
  1140. break;
  1141. case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
  1142. action_frame->u.action.u.ht_smps.smps_control =
  1143. WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
  1144. break;
  1145. }
  1146. return skb;
  1147. }
  1148. int rtl_send_smps_action(struct ieee80211_hw *hw,
  1149. struct ieee80211_sta *sta, u8 *da, u8 *bssid,
  1150. enum ieee80211_smps_mode smps)
  1151. {
  1152. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1153. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1154. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1155. struct sk_buff *skb = rtl_make_smps_action(hw, smps, da, bssid);
  1156. struct rtl_tcb_desc tcb_desc;
  1157. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  1158. if (rtlpriv->mac80211.act_scanning)
  1159. goto err_free;
  1160. if (!sta)
  1161. goto err_free;
  1162. if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
  1163. goto err_free;
  1164. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1165. goto err_free;
  1166. /* this is a type = mgmt * stype = action frame */
  1167. if (skb) {
  1168. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1169. struct rtl_sta_info *sta_entry =
  1170. (struct rtl_sta_info *) sta->drv_priv;
  1171. sta_entry->mimo_ps = smps;
  1172. rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
  1173. info->control.rates[0].idx = 0;
  1174. info->band = hw->conf.channel->band;
  1175. rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
  1176. }
  1177. err_free:
  1178. return 0;
  1179. }
  1180. /*********************************************************
  1181. *
  1182. * IOT functions
  1183. *
  1184. *********************************************************/
  1185. static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
  1186. struct octet_string vendor_ie)
  1187. {
  1188. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1189. bool matched = false;
  1190. static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
  1191. static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
  1192. static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
  1193. static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
  1194. static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
  1195. static u8 racap[] = { 0x00, 0x0c, 0x43 };
  1196. static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
  1197. static u8 marvcap[] = { 0x00, 0x50, 0x43 };
  1198. if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
  1199. memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
  1200. rtlpriv->mac80211.vendor = PEER_ATH;
  1201. matched = true;
  1202. } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
  1203. memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
  1204. memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
  1205. rtlpriv->mac80211.vendor = PEER_BROAD;
  1206. matched = true;
  1207. } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
  1208. rtlpriv->mac80211.vendor = PEER_RAL;
  1209. matched = true;
  1210. } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
  1211. rtlpriv->mac80211.vendor = PEER_CISCO;
  1212. matched = true;
  1213. } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
  1214. rtlpriv->mac80211.vendor = PEER_MARV;
  1215. matched = true;
  1216. }
  1217. return matched;
  1218. }
  1219. static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
  1220. unsigned int len)
  1221. {
  1222. struct ieee80211_mgmt *mgmt = (void *)data;
  1223. struct octet_string vendor_ie;
  1224. u8 *pos, *end;
  1225. pos = (u8 *)mgmt->u.beacon.variable;
  1226. end = data + len;
  1227. while (pos < end) {
  1228. if (pos[0] == 221) {
  1229. vendor_ie.length = pos[1];
  1230. vendor_ie.octet = &pos[2];
  1231. if (rtl_chk_vendor_ouisub(hw, vendor_ie))
  1232. return true;
  1233. }
  1234. if (pos + 2 + pos[1] > end)
  1235. return false;
  1236. pos += 2 + pos[1];
  1237. }
  1238. return false;
  1239. }
  1240. void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
  1241. {
  1242. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1243. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1244. struct ieee80211_hdr *hdr = (void *)data;
  1245. u32 vendor = PEER_UNKNOWN;
  1246. static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
  1247. static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
  1248. static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
  1249. static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
  1250. static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
  1251. static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
  1252. static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
  1253. static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
  1254. static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
  1255. static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
  1256. static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
  1257. static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
  1258. static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
  1259. static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
  1260. static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
  1261. static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
  1262. if (mac->opmode != NL80211_IFTYPE_STATION)
  1263. return;
  1264. if (mac->link_state == MAC80211_NOLINK) {
  1265. mac->vendor = PEER_UNKNOWN;
  1266. return;
  1267. }
  1268. if (mac->cnt_after_linked > 2)
  1269. return;
  1270. /* check if this really is a beacon */
  1271. if (!ieee80211_is_beacon(hdr->frame_control))
  1272. return;
  1273. /* min. beacon length + FCS_LEN */
  1274. if (len <= 40 + FCS_LEN)
  1275. return;
  1276. /* and only beacons from the associated BSSID, please */
  1277. if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
  1278. return;
  1279. if (rtl_find_221_ie(hw, data, len))
  1280. vendor = mac->vendor;
  1281. if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
  1282. (memcmp(mac->bssid, ap5_2, 3) == 0) ||
  1283. (memcmp(mac->bssid, ap5_3, 3) == 0) ||
  1284. (memcmp(mac->bssid, ap5_4, 3) == 0) ||
  1285. (memcmp(mac->bssid, ap5_5, 3) == 0) ||
  1286. (memcmp(mac->bssid, ap5_6, 3) == 0) ||
  1287. vendor == PEER_ATH) {
  1288. vendor = PEER_ATH;
  1289. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
  1290. } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
  1291. (memcmp(mac->bssid, ap4_5, 3) == 0) ||
  1292. (memcmp(mac->bssid, ap4_1, 3) == 0) ||
  1293. (memcmp(mac->bssid, ap4_2, 3) == 0) ||
  1294. (memcmp(mac->bssid, ap4_3, 3) == 0) ||
  1295. vendor == PEER_RAL) {
  1296. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
  1297. vendor = PEER_RAL;
  1298. } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
  1299. vendor == PEER_CISCO) {
  1300. vendor = PEER_CISCO;
  1301. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
  1302. } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
  1303. (memcmp(mac->bssid, ap3_2, 3) == 0) ||
  1304. (memcmp(mac->bssid, ap3_3, 3) == 0) ||
  1305. vendor == PEER_BROAD) {
  1306. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
  1307. vendor = PEER_BROAD;
  1308. } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
  1309. vendor == PEER_MARV) {
  1310. vendor = PEER_MARV;
  1311. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
  1312. }
  1313. mac->vendor = vendor;
  1314. }
  1315. /*********************************************************
  1316. *
  1317. * sysfs functions
  1318. *
  1319. *********************************************************/
  1320. static ssize_t rtl_show_debug_level(struct device *d,
  1321. struct device_attribute *attr, char *buf)
  1322. {
  1323. struct ieee80211_hw *hw = dev_get_drvdata(d);
  1324. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1325. return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
  1326. }
  1327. static ssize_t rtl_store_debug_level(struct device *d,
  1328. struct device_attribute *attr,
  1329. const char *buf, size_t count)
  1330. {
  1331. struct ieee80211_hw *hw = dev_get_drvdata(d);
  1332. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1333. unsigned long val;
  1334. int ret;
  1335. ret = strict_strtoul(buf, 0, &val);
  1336. if (ret) {
  1337. printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf);
  1338. } else {
  1339. rtlpriv->dbg.global_debuglevel = val;
  1340. printk(KERN_DEBUG "debuglevel:%x\n",
  1341. rtlpriv->dbg.global_debuglevel);
  1342. }
  1343. return strnlen(buf, count);
  1344. }
  1345. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  1346. rtl_show_debug_level, rtl_store_debug_level);
  1347. static struct attribute *rtl_sysfs_entries[] = {
  1348. &dev_attr_debug_level.attr,
  1349. NULL
  1350. };
  1351. /*
  1352. * "name" is folder name witch will be
  1353. * put in device directory like :
  1354. * sys/devices/pci0000:00/0000:00:1c.4/
  1355. * 0000:06:00.0/rtl_sysfs
  1356. */
  1357. struct attribute_group rtl_attribute_group = {
  1358. .name = "rtlsysfs",
  1359. .attrs = rtl_sysfs_entries,
  1360. };
  1361. MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
  1362. MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
  1363. MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
  1364. MODULE_LICENSE("GPL");
  1365. MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
  1366. static int __init rtl_core_module_init(void)
  1367. {
  1368. if (rtl_rate_control_register())
  1369. pr_err("Unable to register rtl_rc, use default RC !!\n");
  1370. return 0;
  1371. }
  1372. static void __exit rtl_core_module_exit(void)
  1373. {
  1374. /*RC*/
  1375. rtl_rate_control_unregister();
  1376. }
  1377. module_init(rtl_core_module_init);
  1378. module_exit(rtl_core_module_exit);