core.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  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 "core.h"
  31. #include "cam.h"
  32. #include "base.h"
  33. #include "pci.h"
  34. #include "ps.h"
  35. #include <linux/export.h>
  36. void rtl_addr_delay(u32 addr)
  37. {
  38. if (addr == 0xfe)
  39. mdelay(50);
  40. else if (addr == 0xfd)
  41. mdelay(5);
  42. else if (addr == 0xfc)
  43. mdelay(1);
  44. else if (addr == 0xfb)
  45. udelay(50);
  46. else if (addr == 0xfa)
  47. udelay(5);
  48. else if (addr == 0xf9)
  49. udelay(1);
  50. }
  51. EXPORT_SYMBOL(rtl_addr_delay);
  52. void rtl_rfreg_delay(struct ieee80211_hw *hw, enum radio_path rfpath, u32 addr,
  53. u32 mask, u32 data)
  54. {
  55. if (addr == 0xfe) {
  56. mdelay(50);
  57. } else if (addr == 0xfd) {
  58. mdelay(5);
  59. } else if (addr == 0xfc) {
  60. mdelay(1);
  61. } else if (addr == 0xfb) {
  62. udelay(50);
  63. } else if (addr == 0xfa) {
  64. udelay(5);
  65. } else if (addr == 0xf9) {
  66. udelay(1);
  67. } else {
  68. rtl_set_rfreg(hw, rfpath, addr, mask, data);
  69. udelay(1);
  70. }
  71. }
  72. EXPORT_SYMBOL(rtl_rfreg_delay);
  73. void rtl_bb_delay(struct ieee80211_hw *hw, u32 addr, u32 data)
  74. {
  75. if (addr == 0xfe) {
  76. mdelay(50);
  77. } else if (addr == 0xfd) {
  78. mdelay(5);
  79. } else if (addr == 0xfc) {
  80. mdelay(1);
  81. } else if (addr == 0xfb) {
  82. udelay(50);
  83. } else if (addr == 0xfa) {
  84. udelay(5);
  85. } else if (addr == 0xf9) {
  86. udelay(1);
  87. } else {
  88. rtl_set_bbreg(hw, addr, MASKDWORD, data);
  89. udelay(1);
  90. }
  91. }
  92. EXPORT_SYMBOL(rtl_bb_delay);
  93. void rtl_fw_cb(const struct firmware *firmware, void *context)
  94. {
  95. struct ieee80211_hw *hw = context;
  96. struct rtl_priv *rtlpriv = rtl_priv(hw);
  97. int err;
  98. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  99. "Firmware callback routine entered!\n");
  100. complete(&rtlpriv->firmware_loading_complete);
  101. if (!firmware) {
  102. if (rtlpriv->cfg->alt_fw_name) {
  103. err = request_firmware(&firmware,
  104. rtlpriv->cfg->alt_fw_name,
  105. rtlpriv->io.dev);
  106. pr_info("Loading alternative firmware %s\n",
  107. rtlpriv->cfg->alt_fw_name);
  108. if (!err)
  109. goto found_alt;
  110. }
  111. pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name);
  112. rtlpriv->max_fw_size = 0;
  113. return;
  114. }
  115. found_alt:
  116. if (firmware->size > rtlpriv->max_fw_size) {
  117. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  118. "Firmware is too big!\n");
  119. release_firmware(firmware);
  120. return;
  121. }
  122. memcpy(rtlpriv->rtlhal.pfirmware, firmware->data, firmware->size);
  123. rtlpriv->rtlhal.fwsize = firmware->size;
  124. release_firmware(firmware);
  125. err = ieee80211_register_hw(hw);
  126. if (err) {
  127. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  128. "Can't register mac80211 hw\n");
  129. return;
  130. } else {
  131. rtlpriv->mac80211.mac80211_registered = 1;
  132. }
  133. set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  134. /*init rfkill */
  135. rtl_init_rfkill(hw);
  136. }
  137. EXPORT_SYMBOL(rtl_fw_cb);
  138. /*mutex for start & stop is must here. */
  139. static int rtl_op_start(struct ieee80211_hw *hw)
  140. {
  141. int err;
  142. struct rtl_priv *rtlpriv = rtl_priv(hw);
  143. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  144. if (!is_hal_stop(rtlhal))
  145. return 0;
  146. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  147. return 0;
  148. mutex_lock(&rtlpriv->locks.conf_mutex);
  149. err = rtlpriv->intf_ops->adapter_start(hw);
  150. if (!err)
  151. rtl_watch_dog_timer_callback((unsigned long)hw);
  152. mutex_unlock(&rtlpriv->locks.conf_mutex);
  153. return err;
  154. }
  155. static void rtl_op_stop(struct ieee80211_hw *hw)
  156. {
  157. struct rtl_priv *rtlpriv = rtl_priv(hw);
  158. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  159. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  160. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  161. if (is_hal_stop(rtlhal))
  162. return;
  163. /* here is must, because adhoc do stop and start,
  164. * but stop with RFOFF may cause something wrong,
  165. * like adhoc TP
  166. */
  167. if (unlikely(ppsc->rfpwr_state == ERFOFF)) {
  168. rtl_ips_nic_on(hw);
  169. }
  170. mutex_lock(&rtlpriv->locks.conf_mutex);
  171. mac->link_state = MAC80211_NOLINK;
  172. memset(mac->bssid, 0, ETH_ALEN);
  173. mac->vendor = PEER_UNKNOWN;
  174. /*reset sec info */
  175. rtl_cam_reset_sec_info(hw);
  176. rtl_deinit_deferred_work(hw);
  177. rtlpriv->intf_ops->adapter_stop(hw);
  178. mutex_unlock(&rtlpriv->locks.conf_mutex);
  179. }
  180. static void rtl_op_tx(struct ieee80211_hw *hw,
  181. struct ieee80211_tx_control *control,
  182. struct sk_buff *skb)
  183. {
  184. struct rtl_priv *rtlpriv = rtl_priv(hw);
  185. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  186. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  187. struct rtl_tcb_desc tcb_desc;
  188. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  189. if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
  190. goto err_free;
  191. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  192. goto err_free;
  193. if (!rtlpriv->intf_ops->waitq_insert(hw, control->sta, skb))
  194. rtlpriv->intf_ops->adapter_tx(hw, control->sta, skb, &tcb_desc);
  195. return;
  196. err_free:
  197. dev_kfree_skb_any(skb);
  198. }
  199. static int rtl_op_add_interface(struct ieee80211_hw *hw,
  200. struct ieee80211_vif *vif)
  201. {
  202. struct rtl_priv *rtlpriv = rtl_priv(hw);
  203. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  204. int err = 0;
  205. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
  206. if (mac->vif) {
  207. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  208. "vif has been set!! mac->vif = 0x%p\n", mac->vif);
  209. return -EOPNOTSUPP;
  210. }
  211. rtl_ips_nic_on(hw);
  212. mutex_lock(&rtlpriv->locks.conf_mutex);
  213. switch (ieee80211_vif_type_p2p(vif)) {
  214. case NL80211_IFTYPE_P2P_CLIENT:
  215. mac->p2p = P2P_ROLE_CLIENT;
  216. /*fall through*/
  217. case NL80211_IFTYPE_STATION:
  218. if (mac->beacon_enabled == 1) {
  219. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  220. "NL80211_IFTYPE_STATION\n");
  221. mac->beacon_enabled = 0;
  222. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  223. rtlpriv->cfg->maps
  224. [RTL_IBSS_INT_MASKS]);
  225. }
  226. mac->link_state = MAC80211_LINKED;
  227. break;
  228. case NL80211_IFTYPE_ADHOC:
  229. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  230. "NL80211_IFTYPE_ADHOC\n");
  231. mac->link_state = MAC80211_LINKED;
  232. rtlpriv->cfg->ops->set_bcn_reg(hw);
  233. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  234. mac->basic_rates = 0xfff;
  235. else
  236. mac->basic_rates = 0xff0;
  237. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  238. (u8 *) (&mac->basic_rates));
  239. break;
  240. case NL80211_IFTYPE_P2P_GO:
  241. mac->p2p = P2P_ROLE_GO;
  242. /*fall through*/
  243. case NL80211_IFTYPE_AP:
  244. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  245. "NL80211_IFTYPE_AP\n");
  246. mac->link_state = MAC80211_LINKED;
  247. rtlpriv->cfg->ops->set_bcn_reg(hw);
  248. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  249. mac->basic_rates = 0xfff;
  250. else
  251. mac->basic_rates = 0xff0;
  252. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  253. (u8 *) (&mac->basic_rates));
  254. break;
  255. case NL80211_IFTYPE_MESH_POINT:
  256. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  257. "NL80211_IFTYPE_MESH_POINT\n");
  258. mac->link_state = MAC80211_LINKED;
  259. rtlpriv->cfg->ops->set_bcn_reg(hw);
  260. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  261. mac->basic_rates = 0xfff;
  262. else
  263. mac->basic_rates = 0xff0;
  264. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  265. (u8 *)(&mac->basic_rates));
  266. break;
  267. default:
  268. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  269. "operation mode %d is not supported!\n", vif->type);
  270. err = -EOPNOTSUPP;
  271. goto out;
  272. }
  273. if (mac->p2p) {
  274. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  275. "p2p role %x\n", vif->type);
  276. mac->basic_rates = 0xff0;/*disable cck rate for p2p*/
  277. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  278. (u8 *)(&mac->basic_rates));
  279. }
  280. mac->vif = vif;
  281. mac->opmode = vif->type;
  282. rtlpriv->cfg->ops->set_network_type(hw, vif->type);
  283. memcpy(mac->mac_addr, vif->addr, ETH_ALEN);
  284. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  285. out:
  286. mutex_unlock(&rtlpriv->locks.conf_mutex);
  287. return err;
  288. }
  289. static void rtl_op_remove_interface(struct ieee80211_hw *hw,
  290. struct ieee80211_vif *vif)
  291. {
  292. struct rtl_priv *rtlpriv = rtl_priv(hw);
  293. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  294. mutex_lock(&rtlpriv->locks.conf_mutex);
  295. /* Free beacon resources */
  296. if ((vif->type == NL80211_IFTYPE_AP) ||
  297. (vif->type == NL80211_IFTYPE_ADHOC) ||
  298. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  299. if (mac->beacon_enabled == 1) {
  300. mac->beacon_enabled = 0;
  301. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  302. rtlpriv->cfg->maps
  303. [RTL_IBSS_INT_MASKS]);
  304. }
  305. }
  306. /*
  307. *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
  308. *NO LINK for our hardware.
  309. */
  310. mac->p2p = 0;
  311. mac->vif = NULL;
  312. mac->link_state = MAC80211_NOLINK;
  313. memset(mac->bssid, 0, ETH_ALEN);
  314. mac->vendor = PEER_UNKNOWN;
  315. mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
  316. rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
  317. mutex_unlock(&rtlpriv->locks.conf_mutex);
  318. }
  319. static int rtl_op_change_interface(struct ieee80211_hw *hw,
  320. struct ieee80211_vif *vif,
  321. enum nl80211_iftype new_type, bool p2p)
  322. {
  323. struct rtl_priv *rtlpriv = rtl_priv(hw);
  324. int ret;
  325. rtl_op_remove_interface(hw, vif);
  326. vif->type = new_type;
  327. vif->p2p = p2p;
  328. ret = rtl_op_add_interface(hw, vif);
  329. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  330. "p2p %x\n", p2p);
  331. return ret;
  332. }
  333. static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
  334. {
  335. struct rtl_priv *rtlpriv = rtl_priv(hw);
  336. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  337. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  338. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  339. struct ieee80211_conf *conf = &hw->conf;
  340. if (mac->skip_scan)
  341. return 1;
  342. mutex_lock(&rtlpriv->locks.conf_mutex);
  343. if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { /*BIT(2)*/
  344. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  345. "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
  346. }
  347. /*For IPS */
  348. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  349. if (hw->conf.flags & IEEE80211_CONF_IDLE)
  350. rtl_ips_nic_off(hw);
  351. else
  352. rtl_ips_nic_on(hw);
  353. } else {
  354. /*
  355. *although rfoff may not cause by ips, but we will
  356. *check the reason in set_rf_power_state function
  357. */
  358. if (unlikely(ppsc->rfpwr_state == ERFOFF))
  359. rtl_ips_nic_on(hw);
  360. }
  361. /*For LPS */
  362. if (changed & IEEE80211_CONF_CHANGE_PS) {
  363. cancel_delayed_work(&rtlpriv->works.ps_work);
  364. cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
  365. if (conf->flags & IEEE80211_CONF_PS) {
  366. rtlpriv->psc.sw_ps_enabled = true;
  367. /* sleep here is must, or we may recv the beacon and
  368. * cause mac80211 into wrong ps state, this will cause
  369. * power save nullfunc send fail, and further cause
  370. * pkt loss, So sleep must quickly but not immediatly
  371. * because that will cause nullfunc send by mac80211
  372. * fail, and cause pkt loss, we have tested that 5mA
  373. * is worked very well */
  374. if (!rtlpriv->psc.multi_buffered)
  375. queue_delayed_work(rtlpriv->works.rtl_wq,
  376. &rtlpriv->works.ps_work,
  377. MSECS(5));
  378. } else {
  379. rtl_swlps_rf_awake(hw);
  380. rtlpriv->psc.sw_ps_enabled = false;
  381. }
  382. }
  383. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
  384. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  385. "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
  386. hw->conf.long_frame_max_tx_count);
  387. mac->retry_long = hw->conf.long_frame_max_tx_count;
  388. mac->retry_short = hw->conf.long_frame_max_tx_count;
  389. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
  390. (u8 *) (&hw->conf.
  391. long_frame_max_tx_count));
  392. }
  393. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  394. struct ieee80211_channel *channel = hw->conf.chandef.chan;
  395. u8 wide_chan = (u8) channel->hw_value;
  396. if (mac->act_scanning)
  397. mac->n_channels++;
  398. if (rtlpriv->dm.supp_phymode_switch &&
  399. mac->link_state < MAC80211_LINKED &&
  400. !mac->act_scanning) {
  401. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  402. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  403. }
  404. /*
  405. *because we should back channel to
  406. *current_network.chan in in scanning,
  407. *So if set_chan == current_network.chan
  408. *we should set it.
  409. *because mac80211 tell us wrong bw40
  410. *info for cisco1253 bw20, so we modify
  411. *it here based on UPPER & LOWER
  412. */
  413. switch (cfg80211_get_chandef_type(&hw->conf.chandef)) {
  414. case NL80211_CHAN_HT20:
  415. case NL80211_CHAN_NO_HT:
  416. /* SC */
  417. mac->cur_40_prime_sc =
  418. PRIME_CHNL_OFFSET_DONT_CARE;
  419. rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
  420. mac->bw_40 = false;
  421. break;
  422. case NL80211_CHAN_HT40MINUS:
  423. /* SC */
  424. mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
  425. rtlphy->current_chan_bw =
  426. HT_CHANNEL_WIDTH_20_40;
  427. mac->bw_40 = true;
  428. /*wide channel */
  429. wide_chan -= 2;
  430. break;
  431. case NL80211_CHAN_HT40PLUS:
  432. /* SC */
  433. mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
  434. rtlphy->current_chan_bw =
  435. HT_CHANNEL_WIDTH_20_40;
  436. mac->bw_40 = true;
  437. /*wide channel */
  438. wide_chan += 2;
  439. break;
  440. default:
  441. mac->bw_40 = false;
  442. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  443. "switch case not processed\n");
  444. break;
  445. }
  446. if (wide_chan <= 0)
  447. wide_chan = 1;
  448. /* In scanning, before we go offchannel we may send a ps = 1
  449. * null to AP, and then we may send a ps = 0 null to AP quickly,
  450. * but first null may have caused AP to put lots of packet to
  451. * hw tx buffer. These packets must be tx'd before we go off
  452. * channel so we must delay more time to let AP flush these
  453. * packets before going offchannel, or dis-association or
  454. * delete BA will be caused by AP
  455. */
  456. if (rtlpriv->mac80211.offchan_delay) {
  457. rtlpriv->mac80211.offchan_delay = false;
  458. mdelay(50);
  459. }
  460. rtlphy->current_channel = wide_chan;
  461. rtlpriv->cfg->ops->switch_channel(hw);
  462. rtlpriv->cfg->ops->set_channel_access(hw);
  463. rtlpriv->cfg->ops->set_bw_mode(hw,
  464. cfg80211_get_chandef_type(&hw->conf.chandef));
  465. }
  466. mutex_unlock(&rtlpriv->locks.conf_mutex);
  467. return 0;
  468. }
  469. static void rtl_op_configure_filter(struct ieee80211_hw *hw,
  470. unsigned int changed_flags,
  471. unsigned int *new_flags, u64 multicast)
  472. {
  473. struct rtl_priv *rtlpriv = rtl_priv(hw);
  474. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  475. u32 rx_conf;
  476. *new_flags &= RTL_SUPPORTED_FILTERS;
  477. if (!changed_flags)
  478. return;
  479. /* if ssid not set to hw don't check bssid
  480. * here just used for linked scanning, & linked
  481. * and nolink check bssid is set in set network_type */
  482. if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
  483. (mac->link_state >= MAC80211_LINKED)) {
  484. if (mac->opmode != NL80211_IFTYPE_AP &&
  485. mac->opmode != NL80211_IFTYPE_MESH_POINT) {
  486. if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
  487. rtlpriv->cfg->ops->set_chk_bssid(hw, false);
  488. } else {
  489. rtlpriv->cfg->ops->set_chk_bssid(hw, true);
  490. }
  491. }
  492. }
  493. /* must be called after set_chk_bssid since that function modifies the
  494. * RCR register too. */
  495. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(&rx_conf));
  496. /*TODO: we disable broadcase now, so enable here */
  497. if (changed_flags & FIF_ALLMULTI) {
  498. if (*new_flags & FIF_ALLMULTI) {
  499. rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] |
  500. rtlpriv->cfg->maps[MAC_RCR_AB];
  501. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  502. "Enable receive multicast frame\n");
  503. } else {
  504. rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] |
  505. rtlpriv->cfg->maps[MAC_RCR_AB]);
  506. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  507. "Disable receive multicast frame\n");
  508. }
  509. }
  510. if (changed_flags & FIF_FCSFAIL) {
  511. if (*new_flags & FIF_FCSFAIL) {
  512. rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32];
  513. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  514. "Enable receive FCS error frame\n");
  515. } else {
  516. rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32];
  517. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  518. "Disable receive FCS error frame\n");
  519. }
  520. }
  521. if (changed_flags & FIF_CONTROL) {
  522. if (*new_flags & FIF_CONTROL) {
  523. rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
  524. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  525. "Enable receive control frame\n");
  526. } else {
  527. rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
  528. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  529. "Disable receive control frame\n");
  530. }
  531. }
  532. if (changed_flags & FIF_OTHER_BSS) {
  533. if (*new_flags & FIF_OTHER_BSS) {
  534. rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP];
  535. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  536. "Enable receive other BSS's frame\n");
  537. } else {
  538. rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP];
  539. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  540. "Disable receive other BSS's frame\n");
  541. }
  542. }
  543. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&rx_conf));
  544. }
  545. static int rtl_op_sta_add(struct ieee80211_hw *hw,
  546. struct ieee80211_vif *vif,
  547. struct ieee80211_sta *sta)
  548. {
  549. struct rtl_priv *rtlpriv = rtl_priv(hw);
  550. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  551. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  552. struct rtl_sta_info *sta_entry;
  553. if (sta) {
  554. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  555. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  556. list_add_tail(&sta_entry->list, &rtlpriv->entry_list);
  557. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  558. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  559. sta_entry->wireless_mode = WIRELESS_MODE_G;
  560. if (sta->supp_rates[0] <= 0xf)
  561. sta_entry->wireless_mode = WIRELESS_MODE_B;
  562. if (sta->ht_cap.ht_supported == true)
  563. sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
  564. if (vif->type == NL80211_IFTYPE_ADHOC)
  565. sta_entry->wireless_mode = WIRELESS_MODE_G;
  566. } else if (rtlhal->current_bandtype == BAND_ON_5G) {
  567. sta_entry->wireless_mode = WIRELESS_MODE_A;
  568. if (sta->ht_cap.ht_supported == true)
  569. sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
  570. if (vif->type == NL80211_IFTYPE_ADHOC)
  571. sta_entry->wireless_mode = WIRELESS_MODE_A;
  572. }
  573. /*disable cck rate for p2p*/
  574. if (mac->p2p)
  575. sta->supp_rates[0] &= 0xfffffff0;
  576. memcpy(sta_entry->mac_addr, sta->addr, ETH_ALEN);
  577. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  578. "Add sta addr is %pM\n", sta->addr);
  579. rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
  580. }
  581. return 0;
  582. }
  583. static int rtl_op_sta_remove(struct ieee80211_hw *hw,
  584. struct ieee80211_vif *vif,
  585. struct ieee80211_sta *sta)
  586. {
  587. struct rtl_priv *rtlpriv = rtl_priv(hw);
  588. struct rtl_sta_info *sta_entry;
  589. if (sta) {
  590. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  591. "Remove sta addr is %pM\n", sta->addr);
  592. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  593. sta_entry->wireless_mode = 0;
  594. sta_entry->ratr_index = 0;
  595. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  596. list_del(&sta_entry->list);
  597. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  598. }
  599. return 0;
  600. }
  601. static int _rtl_get_hal_qnum(u16 queue)
  602. {
  603. int qnum;
  604. switch (queue) {
  605. case 0:
  606. qnum = AC3_VO;
  607. break;
  608. case 1:
  609. qnum = AC2_VI;
  610. break;
  611. case 2:
  612. qnum = AC0_BE;
  613. break;
  614. case 3:
  615. qnum = AC1_BK;
  616. break;
  617. default:
  618. qnum = AC0_BE;
  619. break;
  620. }
  621. return qnum;
  622. }
  623. /*
  624. *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
  625. *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
  626. */
  627. static int rtl_op_conf_tx(struct ieee80211_hw *hw,
  628. struct ieee80211_vif *vif, u16 queue,
  629. const struct ieee80211_tx_queue_params *param)
  630. {
  631. struct rtl_priv *rtlpriv = rtl_priv(hw);
  632. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  633. int aci;
  634. if (queue >= AC_MAX) {
  635. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  636. "queue number %d is incorrect!\n", queue);
  637. return -EINVAL;
  638. }
  639. aci = _rtl_get_hal_qnum(queue);
  640. mac->ac[aci].aifs = param->aifs;
  641. mac->ac[aci].cw_min = cpu_to_le16(param->cw_min);
  642. mac->ac[aci].cw_max = cpu_to_le16(param->cw_max);
  643. mac->ac[aci].tx_op = cpu_to_le16(param->txop);
  644. memcpy(&mac->edca_param[aci], param, sizeof(*param));
  645. rtlpriv->cfg->ops->set_qos(hw, aci);
  646. return 0;
  647. }
  648. static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
  649. struct ieee80211_vif *vif,
  650. struct ieee80211_bss_conf *bss_conf, u32 changed)
  651. {
  652. struct rtl_priv *rtlpriv = rtl_priv(hw);
  653. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  654. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  655. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  656. struct ieee80211_sta *sta = NULL;
  657. mutex_lock(&rtlpriv->locks.conf_mutex);
  658. if ((vif->type == NL80211_IFTYPE_ADHOC) ||
  659. (vif->type == NL80211_IFTYPE_AP) ||
  660. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  661. if ((changed & BSS_CHANGED_BEACON) ||
  662. (changed & BSS_CHANGED_BEACON_ENABLED &&
  663. bss_conf->enable_beacon)) {
  664. if (mac->beacon_enabled == 0) {
  665. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  666. "BSS_CHANGED_BEACON_ENABLED\n");
  667. /*start hw beacon interrupt. */
  668. /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
  669. mac->beacon_enabled = 1;
  670. rtlpriv->cfg->ops->update_interrupt_mask(hw,
  671. rtlpriv->cfg->maps
  672. [RTL_IBSS_INT_MASKS],
  673. 0);
  674. if (rtlpriv->cfg->ops->linked_set_reg)
  675. rtlpriv->cfg->ops->linked_set_reg(hw);
  676. }
  677. }
  678. if ((changed & BSS_CHANGED_BEACON_ENABLED &&
  679. !bss_conf->enable_beacon)) {
  680. if (mac->beacon_enabled == 1) {
  681. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  682. "ADHOC DISABLE BEACON\n");
  683. mac->beacon_enabled = 0;
  684. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  685. rtlpriv->cfg->maps
  686. [RTL_IBSS_INT_MASKS]);
  687. }
  688. }
  689. if (changed & BSS_CHANGED_BEACON_INT) {
  690. RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
  691. "BSS_CHANGED_BEACON_INT\n");
  692. mac->beacon_interval = bss_conf->beacon_int;
  693. rtlpriv->cfg->ops->set_bcn_intv(hw);
  694. }
  695. }
  696. /*TODO: reference to enum ieee80211_bss_change */
  697. if (changed & BSS_CHANGED_ASSOC) {
  698. if (bss_conf->assoc) {
  699. struct ieee80211_sta *sta = NULL;
  700. /* we should reset all sec info & cam
  701. * before set cam after linked, we should not
  702. * reset in disassoc, that will cause tkip->wep
  703. * fail because some flag will be wrong */
  704. /* reset sec info */
  705. rtl_cam_reset_sec_info(hw);
  706. /* reset cam to fix wep fail issue
  707. * when change from wpa to wep */
  708. rtl_cam_reset_all_entry(hw);
  709. mac->link_state = MAC80211_LINKED;
  710. mac->cnt_after_linked = 0;
  711. mac->assoc_id = bss_conf->aid;
  712. memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN);
  713. if (rtlpriv->cfg->ops->linked_set_reg)
  714. rtlpriv->cfg->ops->linked_set_reg(hw);
  715. rcu_read_lock();
  716. sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
  717. if (!sta) {
  718. pr_err("ieee80211_find_sta returned NULL\n");
  719. rcu_read_unlock();
  720. goto out;
  721. }
  722. if (vif->type == NL80211_IFTYPE_STATION && sta)
  723. rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
  724. RT_TRACE(rtlpriv, COMP_EASY_CONCURRENT, DBG_LOUD,
  725. "send PS STATIC frame\n");
  726. if (rtlpriv->dm.supp_phymode_switch) {
  727. if (sta->ht_cap.ht_supported)
  728. rtl_send_smps_action(hw, sta,
  729. IEEE80211_SMPS_STATIC);
  730. }
  731. rcu_read_unlock();
  732. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  733. "BSS_CHANGED_ASSOC\n");
  734. } else {
  735. if (mac->link_state == MAC80211_LINKED) {
  736. rtlpriv->enter_ps = false;
  737. schedule_work(&rtlpriv->works.lps_change_work);
  738. }
  739. if (ppsc->p2p_ps_info.p2p_ps_mode > P2P_PS_NONE)
  740. rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE);
  741. mac->link_state = MAC80211_NOLINK;
  742. memset(mac->bssid, 0, ETH_ALEN);
  743. mac->vendor = PEER_UNKNOWN;
  744. if (rtlpriv->dm.supp_phymode_switch) {
  745. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  746. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  747. }
  748. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
  749. "BSS_CHANGED_UN_ASSOC\n");
  750. }
  751. }
  752. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  753. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  754. "BSS_CHANGED_ERP_CTS_PROT\n");
  755. mac->use_cts_protect = bss_conf->use_cts_prot;
  756. }
  757. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  758. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
  759. "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
  760. bss_conf->use_short_preamble);
  761. mac->short_preamble = bss_conf->use_short_preamble;
  762. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
  763. &mac->short_preamble);
  764. }
  765. if (changed & BSS_CHANGED_ERP_SLOT) {
  766. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  767. "BSS_CHANGED_ERP_SLOT\n");
  768. if (bss_conf->use_short_slot)
  769. mac->slot_time = RTL_SLOT_TIME_9;
  770. else
  771. mac->slot_time = RTL_SLOT_TIME_20;
  772. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  773. &mac->slot_time);
  774. }
  775. if (changed & BSS_CHANGED_HT) {
  776. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, "BSS_CHANGED_HT\n");
  777. rcu_read_lock();
  778. sta = get_sta(hw, vif, bss_conf->bssid);
  779. if (sta) {
  780. if (sta->ht_cap.ampdu_density >
  781. mac->current_ampdu_density)
  782. mac->current_ampdu_density =
  783. sta->ht_cap.ampdu_density;
  784. if (sta->ht_cap.ampdu_factor <
  785. mac->current_ampdu_factor)
  786. mac->current_ampdu_factor =
  787. sta->ht_cap.ampdu_factor;
  788. }
  789. rcu_read_unlock();
  790. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
  791. &mac->max_mss_density);
  792. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
  793. &mac->current_ampdu_factor);
  794. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
  795. &mac->current_ampdu_density);
  796. }
  797. if (changed & BSS_CHANGED_BSSID) {
  798. u32 basic_rates;
  799. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
  800. (u8 *) bss_conf->bssid);
  801. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, "%pM\n",
  802. bss_conf->bssid);
  803. mac->vendor = PEER_UNKNOWN;
  804. memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN);
  805. rtlpriv->cfg->ops->set_network_type(hw, vif->type);
  806. rcu_read_lock();
  807. sta = get_sta(hw, vif, bss_conf->bssid);
  808. if (!sta) {
  809. rcu_read_unlock();
  810. goto out;
  811. }
  812. if (rtlhal->current_bandtype == BAND_ON_5G) {
  813. mac->mode = WIRELESS_MODE_A;
  814. } else {
  815. if (sta->supp_rates[0] <= 0xf)
  816. mac->mode = WIRELESS_MODE_B;
  817. else
  818. mac->mode = WIRELESS_MODE_G;
  819. }
  820. if (sta->ht_cap.ht_supported) {
  821. if (rtlhal->current_bandtype == BAND_ON_2_4G)
  822. mac->mode = WIRELESS_MODE_N_24G;
  823. else
  824. mac->mode = WIRELESS_MODE_N_5G;
  825. }
  826. /* just station need it, because ibss & ap mode will
  827. * set in sta_add, and will be NULL here */
  828. if (mac->opmode == NL80211_IFTYPE_STATION) {
  829. struct rtl_sta_info *sta_entry;
  830. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  831. sta_entry->wireless_mode = mac->mode;
  832. }
  833. if (sta->ht_cap.ht_supported) {
  834. mac->ht_enable = true;
  835. /*
  836. * for cisco 1252 bw20 it's wrong
  837. * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  838. * mac->bw_40 = true;
  839. * }
  840. * */
  841. }
  842. if (changed & BSS_CHANGED_BASIC_RATES) {
  843. /* for 5G must << RATE_6M_INDEX = 4,
  844. * because 5G have no cck rate*/
  845. if (rtlhal->current_bandtype == BAND_ON_5G)
  846. basic_rates = sta->supp_rates[1] << 4;
  847. else
  848. basic_rates = sta->supp_rates[0];
  849. mac->basic_rates = basic_rates;
  850. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
  851. (u8 *)(&basic_rates));
  852. }
  853. rcu_read_unlock();
  854. }
  855. /*
  856. * For FW LPS:
  857. * To tell firmware we have connected
  858. * to an AP. For 92SE/CE power save v2.
  859. */
  860. if (changed & BSS_CHANGED_ASSOC) {
  861. if (bss_conf->assoc) {
  862. if (ppsc->fwctrl_lps) {
  863. u8 mstatus = RT_MEDIA_CONNECT;
  864. u8 keep_alive = 10;
  865. rtlpriv->cfg->ops->set_hw_reg(hw,
  866. HW_VAR_KEEP_ALIVE,
  867. &keep_alive);
  868. rtlpriv->cfg->ops->set_hw_reg(hw,
  869. HW_VAR_H2C_FW_JOINBSSRPT,
  870. &mstatus);
  871. ppsc->report_linked = true;
  872. }
  873. } else {
  874. if (ppsc->fwctrl_lps) {
  875. u8 mstatus = RT_MEDIA_DISCONNECT;
  876. rtlpriv->cfg->ops->set_hw_reg(hw,
  877. HW_VAR_H2C_FW_JOINBSSRPT,
  878. &mstatus);
  879. ppsc->report_linked = false;
  880. }
  881. }
  882. if (rtlpriv->cfg->ops->bt_wifi_media_status_notify)
  883. rtlpriv->cfg->ops->bt_wifi_media_status_notify(hw,
  884. ppsc->report_linked);
  885. }
  886. out:
  887. mutex_unlock(&rtlpriv->locks.conf_mutex);
  888. }
  889. static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  890. {
  891. struct rtl_priv *rtlpriv = rtl_priv(hw);
  892. u64 tsf;
  893. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
  894. return tsf;
  895. }
  896. static void rtl_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  897. u64 tsf)
  898. {
  899. struct rtl_priv *rtlpriv = rtl_priv(hw);
  900. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  901. u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
  902. mac->tsf = tsf;
  903. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, &bibss);
  904. }
  905. static void rtl_op_reset_tsf(struct ieee80211_hw *hw,
  906. struct ieee80211_vif *vif)
  907. {
  908. struct rtl_priv *rtlpriv = rtl_priv(hw);
  909. u8 tmp = 0;
  910. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, &tmp);
  911. }
  912. static void rtl_op_sta_notify(struct ieee80211_hw *hw,
  913. struct ieee80211_vif *vif,
  914. enum sta_notify_cmd cmd,
  915. struct ieee80211_sta *sta)
  916. {
  917. switch (cmd) {
  918. case STA_NOTIFY_SLEEP:
  919. break;
  920. case STA_NOTIFY_AWAKE:
  921. break;
  922. default:
  923. break;
  924. }
  925. }
  926. static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
  927. struct ieee80211_vif *vif,
  928. enum ieee80211_ampdu_mlme_action action,
  929. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  930. u8 buf_size)
  931. {
  932. struct rtl_priv *rtlpriv = rtl_priv(hw);
  933. switch (action) {
  934. case IEEE80211_AMPDU_TX_START:
  935. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  936. "IEEE80211_AMPDU_TX_START: TID:%d\n", tid);
  937. return rtl_tx_agg_start(hw, sta, tid, ssn);
  938. case IEEE80211_AMPDU_TX_STOP_CONT:
  939. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  940. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  941. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  942. "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid);
  943. return rtl_tx_agg_stop(hw, sta, tid);
  944. case IEEE80211_AMPDU_TX_OPERATIONAL:
  945. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  946. "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid);
  947. rtl_tx_agg_oper(hw, sta, tid);
  948. break;
  949. case IEEE80211_AMPDU_RX_START:
  950. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  951. "IEEE80211_AMPDU_RX_START:TID:%d\n", tid);
  952. return rtl_rx_agg_start(hw, sta, tid);
  953. case IEEE80211_AMPDU_RX_STOP:
  954. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  955. "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid);
  956. return rtl_rx_agg_stop(hw, sta, tid);
  957. default:
  958. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  959. "IEEE80211_AMPDU_ERR!!!!:\n");
  960. return -EOPNOTSUPP;
  961. }
  962. return 0;
  963. }
  964. static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
  965. {
  966. struct rtl_priv *rtlpriv = rtl_priv(hw);
  967. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  968. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  969. mac->act_scanning = true;
  970. if (rtlpriv->link_info.higher_busytraffic) {
  971. mac->skip_scan = true;
  972. return;
  973. }
  974. if (rtlpriv->dm.supp_phymode_switch) {
  975. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  976. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  977. }
  978. if (mac->link_state == MAC80211_LINKED) {
  979. rtlpriv->enter_ps = false;
  980. schedule_work(&rtlpriv->works.lps_change_work);
  981. mac->link_state = MAC80211_LINKED_SCANNING;
  982. } else {
  983. rtl_ips_nic_on(hw);
  984. }
  985. /* Dual mac */
  986. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  987. rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
  988. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
  989. }
  990. static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
  991. {
  992. struct rtl_priv *rtlpriv = rtl_priv(hw);
  993. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  994. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  995. mac->act_scanning = false;
  996. mac->skip_scan = false;
  997. if (rtlpriv->link_info.higher_busytraffic)
  998. return;
  999. /*p2p will use 1/6/11 to scan */
  1000. if (mac->n_channels == 3)
  1001. mac->p2p_in_use = true;
  1002. else
  1003. mac->p2p_in_use = false;
  1004. mac->n_channels = 0;
  1005. /* Dual mac */
  1006. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  1007. if (mac->link_state == MAC80211_LINKED_SCANNING) {
  1008. mac->link_state = MAC80211_LINKED;
  1009. if (mac->opmode == NL80211_IFTYPE_STATION) {
  1010. /* fix fwlps issue */
  1011. rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
  1012. }
  1013. }
  1014. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
  1015. }
  1016. static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1017. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1018. struct ieee80211_key_conf *key)
  1019. {
  1020. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1021. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1022. u8 key_type = NO_ENCRYPTION;
  1023. u8 key_idx;
  1024. bool group_key = false;
  1025. bool wep_only = false;
  1026. int err = 0;
  1027. u8 mac_addr[ETH_ALEN];
  1028. u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1029. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  1030. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1031. "not open hw encryption\n");
  1032. return -ENOSPC; /*User disabled HW-crypto */
  1033. }
  1034. /* To support IBSS, use sw-crypto for GTK */
  1035. if (((vif->type == NL80211_IFTYPE_ADHOC) ||
  1036. (vif->type == NL80211_IFTYPE_MESH_POINT)) &&
  1037. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  1038. return -ENOSPC;
  1039. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1040. "%s hardware based encryption for keyidx: %d, mac: %pM\n",
  1041. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  1042. sta ? sta->addr : bcast_addr);
  1043. rtlpriv->sec.being_setkey = true;
  1044. rtl_ips_nic_on(hw);
  1045. mutex_lock(&rtlpriv->locks.conf_mutex);
  1046. /* <1> get encryption alg */
  1047. switch (key->cipher) {
  1048. case WLAN_CIPHER_SUITE_WEP40:
  1049. key_type = WEP40_ENCRYPTION;
  1050. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n");
  1051. break;
  1052. case WLAN_CIPHER_SUITE_WEP104:
  1053. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
  1054. key_type = WEP104_ENCRYPTION;
  1055. break;
  1056. case WLAN_CIPHER_SUITE_TKIP:
  1057. key_type = TKIP_ENCRYPTION;
  1058. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
  1059. break;
  1060. case WLAN_CIPHER_SUITE_CCMP:
  1061. key_type = AESCCMP_ENCRYPTION;
  1062. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
  1063. break;
  1064. case WLAN_CIPHER_SUITE_AES_CMAC:
  1065. /*HW doesn't support CMAC encryption, use software CMAC */
  1066. key_type = AESCMAC_ENCRYPTION;
  1067. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CMAC\n");
  1068. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1069. "HW don't support CMAC encryption, use software CMAC\n");
  1070. err = -EOPNOTSUPP;
  1071. goto out_unlock;
  1072. default:
  1073. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "alg_err:%x!!!!\n",
  1074. key->cipher);
  1075. goto out_unlock;
  1076. }
  1077. if (key_type == WEP40_ENCRYPTION ||
  1078. key_type == WEP104_ENCRYPTION ||
  1079. mac->opmode == NL80211_IFTYPE_ADHOC)
  1080. rtlpriv->sec.use_defaultkey = true;
  1081. /* <2> get key_idx */
  1082. key_idx = (u8) (key->keyidx);
  1083. if (key_idx > 3)
  1084. goto out_unlock;
  1085. /* <3> if pairwise key enable_hw_sec */
  1086. group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  1087. /* wep always be group key, but there are two conditions:
  1088. * 1) wep only: is just for wep enc, in this condition
  1089. * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
  1090. * will be true & enable_hw_sec will be set when wep
  1091. * key setting.
  1092. * 2) wep(group) + AES(pairwise): some AP like cisco
  1093. * may use it, in this condition enable_hw_sec will not
  1094. * be set when wep key setting */
  1095. /* we must reset sec_info after lingked before set key,
  1096. * or some flag will be wrong*/
  1097. if (vif->type == NL80211_IFTYPE_AP ||
  1098. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1099. if (!group_key || key_type == WEP40_ENCRYPTION ||
  1100. key_type == WEP104_ENCRYPTION) {
  1101. if (group_key)
  1102. wep_only = true;
  1103. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1104. }
  1105. } else {
  1106. if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
  1107. rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
  1108. if (rtlpriv->sec.pairwise_enc_algorithm ==
  1109. NO_ENCRYPTION &&
  1110. (key_type == WEP40_ENCRYPTION ||
  1111. key_type == WEP104_ENCRYPTION))
  1112. wep_only = true;
  1113. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1114. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1115. "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
  1116. key_type);
  1117. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1118. }
  1119. }
  1120. /* <4> set key based on cmd */
  1121. switch (cmd) {
  1122. case SET_KEY:
  1123. if (wep_only) {
  1124. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1125. "set WEP(group/pairwise) key\n");
  1126. /* Pairwise key with an assigned MAC address. */
  1127. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1128. rtlpriv->sec.group_enc_algorithm = key_type;
  1129. /*set local buf about wep key. */
  1130. memcpy(rtlpriv->sec.key_buf[key_idx],
  1131. key->key, key->keylen);
  1132. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1133. eth_zero_addr(mac_addr);
  1134. } else if (group_key) { /* group key */
  1135. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1136. "set group key\n");
  1137. /* group key */
  1138. rtlpriv->sec.group_enc_algorithm = key_type;
  1139. /*set local buf about group key. */
  1140. memcpy(rtlpriv->sec.key_buf[key_idx],
  1141. key->key, key->keylen);
  1142. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1143. memcpy(mac_addr, bcast_addr, ETH_ALEN);
  1144. } else { /* pairwise key */
  1145. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1146. "set pairwise key\n");
  1147. if (!sta) {
  1148. RT_ASSERT(false,
  1149. "pairwise key without mac_addr\n");
  1150. err = -EOPNOTSUPP;
  1151. goto out_unlock;
  1152. }
  1153. /* Pairwise key with an assigned MAC address. */
  1154. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1155. /*set local buf about pairwise key. */
  1156. memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
  1157. key->key, key->keylen);
  1158. rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
  1159. rtlpriv->sec.pairwise_key =
  1160. rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
  1161. memcpy(mac_addr, sta->addr, ETH_ALEN);
  1162. }
  1163. rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
  1164. group_key, key_type, wep_only,
  1165. false);
  1166. /* <5> tell mac80211 do something: */
  1167. /*must use sw generate IV, or can not work !!!!. */
  1168. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1169. key->hw_key_idx = key_idx;
  1170. if (key_type == TKIP_ENCRYPTION)
  1171. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1172. /*use software CCMP encryption for management frames (MFP) */
  1173. if (key_type == AESCCMP_ENCRYPTION)
  1174. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1175. break;
  1176. case DISABLE_KEY:
  1177. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1178. "disable key delete one entry\n");
  1179. /*set local buf about wep key. */
  1180. if (vif->type == NL80211_IFTYPE_AP ||
  1181. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1182. if (sta)
  1183. rtl_cam_del_entry(hw, sta->addr);
  1184. }
  1185. memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
  1186. rtlpriv->sec.key_len[key_idx] = 0;
  1187. eth_zero_addr(mac_addr);
  1188. /*
  1189. *mac80211 will delete entrys one by one,
  1190. *so don't use rtl_cam_reset_all_entry
  1191. *or clear all entry here.
  1192. */
  1193. rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
  1194. rtl_cam_reset_sec_info(hw);
  1195. break;
  1196. default:
  1197. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1198. "cmd_err:%x!!!!\n", cmd);
  1199. }
  1200. out_unlock:
  1201. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1202. rtlpriv->sec.being_setkey = false;
  1203. return err;
  1204. }
  1205. static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
  1206. {
  1207. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1208. bool radio_state;
  1209. bool blocked;
  1210. u8 valid = 0;
  1211. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1212. return;
  1213. mutex_lock(&rtlpriv->locks.conf_mutex);
  1214. /*if Radio On return true here */
  1215. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  1216. if (valid) {
  1217. if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
  1218. rtlpriv->rfkill.rfkill_state = radio_state;
  1219. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1220. "wireless radio switch turned %s\n",
  1221. radio_state ? "on" : "off");
  1222. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  1223. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  1224. }
  1225. }
  1226. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1227. }
  1228. /* this function is called by mac80211 to flush tx buffer
  1229. * before switch channel or power save, or tx buffer packet
  1230. * maybe send after offchannel or rf sleep, this may cause
  1231. * dis-association by AP */
  1232. static void rtl_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1233. u32 queues, bool drop)
  1234. {
  1235. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1236. if (rtlpriv->intf_ops->flush)
  1237. rtlpriv->intf_ops->flush(hw, drop);
  1238. }
  1239. const struct ieee80211_ops rtl_ops = {
  1240. .start = rtl_op_start,
  1241. .stop = rtl_op_stop,
  1242. .tx = rtl_op_tx,
  1243. .add_interface = rtl_op_add_interface,
  1244. .remove_interface = rtl_op_remove_interface,
  1245. .change_interface = rtl_op_change_interface,
  1246. .config = rtl_op_config,
  1247. .configure_filter = rtl_op_configure_filter,
  1248. .sta_add = rtl_op_sta_add,
  1249. .sta_remove = rtl_op_sta_remove,
  1250. .set_key = rtl_op_set_key,
  1251. .conf_tx = rtl_op_conf_tx,
  1252. .bss_info_changed = rtl_op_bss_info_changed,
  1253. .get_tsf = rtl_op_get_tsf,
  1254. .set_tsf = rtl_op_set_tsf,
  1255. .reset_tsf = rtl_op_reset_tsf,
  1256. .sta_notify = rtl_op_sta_notify,
  1257. .ampdu_action = rtl_op_ampdu_action,
  1258. .sw_scan_start = rtl_op_sw_scan_start,
  1259. .sw_scan_complete = rtl_op_sw_scan_complete,
  1260. .rfkill_poll = rtl_op_rfkill_poll,
  1261. .flush = rtl_op_flush,
  1262. };
  1263. EXPORT_SYMBOL_GPL(rtl_ops);