core.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  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. break;
  939. case IEEE80211_AMPDU_TX_STOP_CONT:
  940. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  941. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  942. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  943. "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid);
  944. return rtl_tx_agg_stop(hw, sta, tid);
  945. case IEEE80211_AMPDU_TX_OPERATIONAL:
  946. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  947. "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid);
  948. rtl_tx_agg_oper(hw, sta, tid);
  949. break;
  950. case IEEE80211_AMPDU_RX_START:
  951. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  952. "IEEE80211_AMPDU_RX_START:TID:%d\n", tid);
  953. return rtl_rx_agg_start(hw, sta, tid);
  954. case IEEE80211_AMPDU_RX_STOP:
  955. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
  956. "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid);
  957. return rtl_rx_agg_stop(hw, sta, tid);
  958. default:
  959. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  960. "IEEE80211_AMPDU_ERR!!!!:\n");
  961. return -EOPNOTSUPP;
  962. }
  963. return 0;
  964. }
  965. static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
  966. {
  967. struct rtl_priv *rtlpriv = rtl_priv(hw);
  968. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  969. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  970. mac->act_scanning = true;
  971. if (rtlpriv->link_info.higher_busytraffic) {
  972. mac->skip_scan = true;
  973. return;
  974. }
  975. if (rtlpriv->dm.supp_phymode_switch) {
  976. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  977. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  978. }
  979. if (mac->link_state == MAC80211_LINKED) {
  980. rtlpriv->enter_ps = false;
  981. schedule_work(&rtlpriv->works.lps_change_work);
  982. mac->link_state = MAC80211_LINKED_SCANNING;
  983. } else {
  984. rtl_ips_nic_on(hw);
  985. }
  986. /* Dual mac */
  987. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  988. rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
  989. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
  990. }
  991. static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
  992. {
  993. struct rtl_priv *rtlpriv = rtl_priv(hw);
  994. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  995. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
  996. mac->act_scanning = false;
  997. mac->skip_scan = false;
  998. if (rtlpriv->link_info.higher_busytraffic)
  999. return;
  1000. /*p2p will use 1/6/11 to scan */
  1001. if (mac->n_channels == 3)
  1002. mac->p2p_in_use = true;
  1003. else
  1004. mac->p2p_in_use = false;
  1005. mac->n_channels = 0;
  1006. /* Dual mac */
  1007. rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
  1008. if (mac->link_state == MAC80211_LINKED_SCANNING) {
  1009. mac->link_state = MAC80211_LINKED;
  1010. if (mac->opmode == NL80211_IFTYPE_STATION) {
  1011. /* fix fwlps issue */
  1012. rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
  1013. }
  1014. }
  1015. rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
  1016. }
  1017. static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1018. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1019. struct ieee80211_key_conf *key)
  1020. {
  1021. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1022. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1023. u8 key_type = NO_ENCRYPTION;
  1024. u8 key_idx;
  1025. bool group_key = false;
  1026. bool wep_only = false;
  1027. int err = 0;
  1028. u8 mac_addr[ETH_ALEN];
  1029. u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1030. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  1031. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1032. "not open hw encryption\n");
  1033. return -ENOSPC; /*User disabled HW-crypto */
  1034. }
  1035. /* To support IBSS, use sw-crypto for GTK */
  1036. if (((vif->type == NL80211_IFTYPE_ADHOC) ||
  1037. (vif->type == NL80211_IFTYPE_MESH_POINT)) &&
  1038. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  1039. return -ENOSPC;
  1040. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1041. "%s hardware based encryption for keyidx: %d, mac: %pM\n",
  1042. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  1043. sta ? sta->addr : bcast_addr);
  1044. rtlpriv->sec.being_setkey = true;
  1045. rtl_ips_nic_on(hw);
  1046. mutex_lock(&rtlpriv->locks.conf_mutex);
  1047. /* <1> get encryption alg */
  1048. switch (key->cipher) {
  1049. case WLAN_CIPHER_SUITE_WEP40:
  1050. key_type = WEP40_ENCRYPTION;
  1051. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n");
  1052. break;
  1053. case WLAN_CIPHER_SUITE_WEP104:
  1054. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
  1055. key_type = WEP104_ENCRYPTION;
  1056. break;
  1057. case WLAN_CIPHER_SUITE_TKIP:
  1058. key_type = TKIP_ENCRYPTION;
  1059. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
  1060. break;
  1061. case WLAN_CIPHER_SUITE_CCMP:
  1062. key_type = AESCCMP_ENCRYPTION;
  1063. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
  1064. break;
  1065. case WLAN_CIPHER_SUITE_AES_CMAC:
  1066. /*HW doesn't support CMAC encryption, use software CMAC */
  1067. key_type = AESCMAC_ENCRYPTION;
  1068. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CMAC\n");
  1069. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1070. "HW don't support CMAC encryption, use software CMAC\n");
  1071. err = -EOPNOTSUPP;
  1072. goto out_unlock;
  1073. default:
  1074. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "alg_err:%x!!!!\n",
  1075. key->cipher);
  1076. goto out_unlock;
  1077. }
  1078. if (key_type == WEP40_ENCRYPTION ||
  1079. key_type == WEP104_ENCRYPTION ||
  1080. mac->opmode == NL80211_IFTYPE_ADHOC)
  1081. rtlpriv->sec.use_defaultkey = true;
  1082. /* <2> get key_idx */
  1083. key_idx = (u8) (key->keyidx);
  1084. if (key_idx > 3)
  1085. goto out_unlock;
  1086. /* <3> if pairwise key enable_hw_sec */
  1087. group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  1088. /* wep always be group key, but there are two conditions:
  1089. * 1) wep only: is just for wep enc, in this condition
  1090. * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
  1091. * will be true & enable_hw_sec will be set when wep
  1092. * key setting.
  1093. * 2) wep(group) + AES(pairwise): some AP like cisco
  1094. * may use it, in this condition enable_hw_sec will not
  1095. * be set when wep key setting */
  1096. /* we must reset sec_info after lingked before set key,
  1097. * or some flag will be wrong*/
  1098. if (vif->type == NL80211_IFTYPE_AP ||
  1099. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1100. if (!group_key || key_type == WEP40_ENCRYPTION ||
  1101. key_type == WEP104_ENCRYPTION) {
  1102. if (group_key)
  1103. wep_only = true;
  1104. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1105. }
  1106. } else {
  1107. if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
  1108. rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
  1109. if (rtlpriv->sec.pairwise_enc_algorithm ==
  1110. NO_ENCRYPTION &&
  1111. (key_type == WEP40_ENCRYPTION ||
  1112. key_type == WEP104_ENCRYPTION))
  1113. wep_only = true;
  1114. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1115. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1116. "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
  1117. key_type);
  1118. rtlpriv->cfg->ops->enable_hw_sec(hw);
  1119. }
  1120. }
  1121. /* <4> set key based on cmd */
  1122. switch (cmd) {
  1123. case SET_KEY:
  1124. if (wep_only) {
  1125. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1126. "set WEP(group/pairwise) key\n");
  1127. /* Pairwise key with an assigned MAC address. */
  1128. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1129. rtlpriv->sec.group_enc_algorithm = key_type;
  1130. /*set local buf about wep key. */
  1131. memcpy(rtlpriv->sec.key_buf[key_idx],
  1132. key->key, key->keylen);
  1133. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1134. eth_zero_addr(mac_addr);
  1135. } else if (group_key) { /* group key */
  1136. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1137. "set group key\n");
  1138. /* group key */
  1139. rtlpriv->sec.group_enc_algorithm = key_type;
  1140. /*set local buf about group key. */
  1141. memcpy(rtlpriv->sec.key_buf[key_idx],
  1142. key->key, key->keylen);
  1143. rtlpriv->sec.key_len[key_idx] = key->keylen;
  1144. memcpy(mac_addr, bcast_addr, ETH_ALEN);
  1145. } else { /* pairwise key */
  1146. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1147. "set pairwise key\n");
  1148. if (!sta) {
  1149. RT_ASSERT(false,
  1150. "pairwise key without mac_addr\n");
  1151. err = -EOPNOTSUPP;
  1152. goto out_unlock;
  1153. }
  1154. /* Pairwise key with an assigned MAC address. */
  1155. rtlpriv->sec.pairwise_enc_algorithm = key_type;
  1156. /*set local buf about pairwise key. */
  1157. memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
  1158. key->key, key->keylen);
  1159. rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
  1160. rtlpriv->sec.pairwise_key =
  1161. rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
  1162. memcpy(mac_addr, sta->addr, ETH_ALEN);
  1163. }
  1164. rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
  1165. group_key, key_type, wep_only,
  1166. false);
  1167. /* <5> tell mac80211 do something: */
  1168. /*must use sw generate IV, or can not work !!!!. */
  1169. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1170. key->hw_key_idx = key_idx;
  1171. if (key_type == TKIP_ENCRYPTION)
  1172. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1173. /*use software CCMP encryption for management frames (MFP) */
  1174. if (key_type == AESCCMP_ENCRYPTION)
  1175. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1176. break;
  1177. case DISABLE_KEY:
  1178. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1179. "disable key delete one entry\n");
  1180. /*set local buf about wep key. */
  1181. if (vif->type == NL80211_IFTYPE_AP ||
  1182. vif->type == NL80211_IFTYPE_MESH_POINT) {
  1183. if (sta)
  1184. rtl_cam_del_entry(hw, sta->addr);
  1185. }
  1186. memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
  1187. rtlpriv->sec.key_len[key_idx] = 0;
  1188. eth_zero_addr(mac_addr);
  1189. /*
  1190. *mac80211 will delete entrys one by one,
  1191. *so don't use rtl_cam_reset_all_entry
  1192. *or clear all entry here.
  1193. */
  1194. rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
  1195. rtl_cam_reset_sec_info(hw);
  1196. break;
  1197. default:
  1198. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1199. "cmd_err:%x!!!!\n", cmd);
  1200. }
  1201. out_unlock:
  1202. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1203. rtlpriv->sec.being_setkey = false;
  1204. return err;
  1205. }
  1206. static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
  1207. {
  1208. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1209. bool radio_state;
  1210. bool blocked;
  1211. u8 valid = 0;
  1212. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1213. return;
  1214. mutex_lock(&rtlpriv->locks.conf_mutex);
  1215. /*if Radio On return true here */
  1216. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  1217. if (valid) {
  1218. if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
  1219. rtlpriv->rfkill.rfkill_state = radio_state;
  1220. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1221. "wireless radio switch turned %s\n",
  1222. radio_state ? "on" : "off");
  1223. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  1224. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  1225. }
  1226. }
  1227. mutex_unlock(&rtlpriv->locks.conf_mutex);
  1228. }
  1229. /* this function is called by mac80211 to flush tx buffer
  1230. * before switch channel or power save, or tx buffer packet
  1231. * maybe send after offchannel or rf sleep, this may cause
  1232. * dis-association by AP */
  1233. static void rtl_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1234. u32 queues, bool drop)
  1235. {
  1236. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1237. if (rtlpriv->intf_ops->flush)
  1238. rtlpriv->intf_ops->flush(hw, drop);
  1239. }
  1240. const struct ieee80211_ops rtl_ops = {
  1241. .start = rtl_op_start,
  1242. .stop = rtl_op_stop,
  1243. .tx = rtl_op_tx,
  1244. .add_interface = rtl_op_add_interface,
  1245. .remove_interface = rtl_op_remove_interface,
  1246. .change_interface = rtl_op_change_interface,
  1247. .config = rtl_op_config,
  1248. .configure_filter = rtl_op_configure_filter,
  1249. .sta_add = rtl_op_sta_add,
  1250. .sta_remove = rtl_op_sta_remove,
  1251. .set_key = rtl_op_set_key,
  1252. .conf_tx = rtl_op_conf_tx,
  1253. .bss_info_changed = rtl_op_bss_info_changed,
  1254. .get_tsf = rtl_op_get_tsf,
  1255. .set_tsf = rtl_op_set_tsf,
  1256. .reset_tsf = rtl_op_reset_tsf,
  1257. .sta_notify = rtl_op_sta_notify,
  1258. .ampdu_action = rtl_op_ampdu_action,
  1259. .sw_scan_start = rtl_op_sw_scan_start,
  1260. .sw_scan_complete = rtl_op_sw_scan_complete,
  1261. .rfkill_poll = rtl_op_rfkill_poll,
  1262. .flush = rtl_op_flush,
  1263. };
  1264. EXPORT_SYMBOL_GPL(rtl_ops);