main.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include "wcn36xx.h"
  20. unsigned int wcn36xx_dbg_mask;
  21. module_param_named(debug_mask, wcn36xx_dbg_mask, uint, 0644);
  22. MODULE_PARM_DESC(debug_mask, "Debugging mask");
  23. #define CHAN2G(_freq, _idx) { \
  24. .band = IEEE80211_BAND_2GHZ, \
  25. .center_freq = (_freq), \
  26. .hw_value = (_idx), \
  27. .max_power = 25, \
  28. }
  29. #define CHAN5G(_freq, _idx) { \
  30. .band = IEEE80211_BAND_5GHZ, \
  31. .center_freq = (_freq), \
  32. .hw_value = (_idx), \
  33. .max_power = 25, \
  34. }
  35. /* The wcn firmware expects channel values to matching
  36. * their mnemonic values. So use these for .hw_value. */
  37. static struct ieee80211_channel wcn_2ghz_channels[] = {
  38. CHAN2G(2412, 1), /* Channel 1 */
  39. CHAN2G(2417, 2), /* Channel 2 */
  40. CHAN2G(2422, 3), /* Channel 3 */
  41. CHAN2G(2427, 4), /* Channel 4 */
  42. CHAN2G(2432, 5), /* Channel 5 */
  43. CHAN2G(2437, 6), /* Channel 6 */
  44. CHAN2G(2442, 7), /* Channel 7 */
  45. CHAN2G(2447, 8), /* Channel 8 */
  46. CHAN2G(2452, 9), /* Channel 9 */
  47. CHAN2G(2457, 10), /* Channel 10 */
  48. CHAN2G(2462, 11), /* Channel 11 */
  49. CHAN2G(2467, 12), /* Channel 12 */
  50. CHAN2G(2472, 13), /* Channel 13 */
  51. CHAN2G(2484, 14) /* Channel 14 */
  52. };
  53. static struct ieee80211_channel wcn_5ghz_channels[] = {
  54. CHAN5G(5180, 36),
  55. CHAN5G(5200, 40),
  56. CHAN5G(5220, 44),
  57. CHAN5G(5240, 48),
  58. CHAN5G(5260, 52),
  59. CHAN5G(5280, 56),
  60. CHAN5G(5300, 60),
  61. CHAN5G(5320, 64),
  62. CHAN5G(5500, 100),
  63. CHAN5G(5520, 104),
  64. CHAN5G(5540, 108),
  65. CHAN5G(5560, 112),
  66. CHAN5G(5580, 116),
  67. CHAN5G(5600, 120),
  68. CHAN5G(5620, 124),
  69. CHAN5G(5640, 128),
  70. CHAN5G(5660, 132),
  71. CHAN5G(5700, 140),
  72. CHAN5G(5745, 149),
  73. CHAN5G(5765, 153),
  74. CHAN5G(5785, 157),
  75. CHAN5G(5805, 161),
  76. CHAN5G(5825, 165)
  77. };
  78. #define RATE(_bitrate, _hw_rate, _flags) { \
  79. .bitrate = (_bitrate), \
  80. .flags = (_flags), \
  81. .hw_value = (_hw_rate), \
  82. .hw_value_short = (_hw_rate) \
  83. }
  84. static struct ieee80211_rate wcn_2ghz_rates[] = {
  85. RATE(10, HW_RATE_INDEX_1MBPS, 0),
  86. RATE(20, HW_RATE_INDEX_2MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
  87. RATE(55, HW_RATE_INDEX_5_5MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
  88. RATE(110, HW_RATE_INDEX_11MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
  89. RATE(60, HW_RATE_INDEX_6MBPS, 0),
  90. RATE(90, HW_RATE_INDEX_9MBPS, 0),
  91. RATE(120, HW_RATE_INDEX_12MBPS, 0),
  92. RATE(180, HW_RATE_INDEX_18MBPS, 0),
  93. RATE(240, HW_RATE_INDEX_24MBPS, 0),
  94. RATE(360, HW_RATE_INDEX_36MBPS, 0),
  95. RATE(480, HW_RATE_INDEX_48MBPS, 0),
  96. RATE(540, HW_RATE_INDEX_54MBPS, 0)
  97. };
  98. static struct ieee80211_rate wcn_5ghz_rates[] = {
  99. RATE(60, HW_RATE_INDEX_6MBPS, 0),
  100. RATE(90, HW_RATE_INDEX_9MBPS, 0),
  101. RATE(120, HW_RATE_INDEX_12MBPS, 0),
  102. RATE(180, HW_RATE_INDEX_18MBPS, 0),
  103. RATE(240, HW_RATE_INDEX_24MBPS, 0),
  104. RATE(360, HW_RATE_INDEX_36MBPS, 0),
  105. RATE(480, HW_RATE_INDEX_48MBPS, 0),
  106. RATE(540, HW_RATE_INDEX_54MBPS, 0)
  107. };
  108. static struct ieee80211_supported_band wcn_band_2ghz = {
  109. .channels = wcn_2ghz_channels,
  110. .n_channels = ARRAY_SIZE(wcn_2ghz_channels),
  111. .bitrates = wcn_2ghz_rates,
  112. .n_bitrates = ARRAY_SIZE(wcn_2ghz_rates),
  113. .ht_cap = {
  114. .cap = IEEE80211_HT_CAP_GRN_FLD |
  115. IEEE80211_HT_CAP_SGI_20 |
  116. IEEE80211_HT_CAP_DSSSCCK40 |
  117. IEEE80211_HT_CAP_LSIG_TXOP_PROT,
  118. .ht_supported = true,
  119. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
  120. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  121. .mcs = {
  122. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  123. .rx_highest = cpu_to_le16(72),
  124. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  125. }
  126. }
  127. };
  128. static struct ieee80211_supported_band wcn_band_5ghz = {
  129. .channels = wcn_5ghz_channels,
  130. .n_channels = ARRAY_SIZE(wcn_5ghz_channels),
  131. .bitrates = wcn_5ghz_rates,
  132. .n_bitrates = ARRAY_SIZE(wcn_5ghz_rates),
  133. .ht_cap = {
  134. .cap = IEEE80211_HT_CAP_GRN_FLD |
  135. IEEE80211_HT_CAP_SGI_20 |
  136. IEEE80211_HT_CAP_DSSSCCK40 |
  137. IEEE80211_HT_CAP_LSIG_TXOP_PROT |
  138. IEEE80211_HT_CAP_SGI_40 |
  139. IEEE80211_HT_CAP_SUP_WIDTH_20_40,
  140. .ht_supported = true,
  141. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
  142. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  143. .mcs = {
  144. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  145. .rx_highest = cpu_to_le16(72),
  146. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  147. }
  148. }
  149. };
  150. #ifdef CONFIG_PM
  151. static const struct wiphy_wowlan_support wowlan_support = {
  152. .flags = WIPHY_WOWLAN_ANY
  153. };
  154. #endif
  155. static inline u8 get_sta_index(struct ieee80211_vif *vif,
  156. struct wcn36xx_sta *sta_priv)
  157. {
  158. return NL80211_IFTYPE_STATION == vif->type ?
  159. sta_priv->bss_sta_index :
  160. sta_priv->sta_index;
  161. }
  162. static int wcn36xx_start(struct ieee80211_hw *hw)
  163. {
  164. struct wcn36xx *wcn = hw->priv;
  165. int ret;
  166. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac start\n");
  167. /* SMD initialization */
  168. ret = wcn36xx_smd_open(wcn);
  169. if (ret) {
  170. wcn36xx_err("Failed to open smd channel: %d\n", ret);
  171. goto out_err;
  172. }
  173. /* Allocate memory pools for Mgmt BD headers and Data BD headers */
  174. ret = wcn36xx_dxe_allocate_mem_pools(wcn);
  175. if (ret) {
  176. wcn36xx_err("Failed to alloc DXE mempool: %d\n", ret);
  177. goto out_smd_close;
  178. }
  179. ret = wcn36xx_dxe_alloc_ctl_blks(wcn);
  180. if (ret) {
  181. wcn36xx_err("Failed to alloc DXE ctl blocks: %d\n", ret);
  182. goto out_free_dxe_pool;
  183. }
  184. wcn->hal_buf = kmalloc(WCN36XX_HAL_BUF_SIZE, GFP_KERNEL);
  185. if (!wcn->hal_buf) {
  186. wcn36xx_err("Failed to allocate smd buf\n");
  187. ret = -ENOMEM;
  188. goto out_free_dxe_ctl;
  189. }
  190. ret = wcn36xx_smd_load_nv(wcn);
  191. if (ret) {
  192. wcn36xx_err("Failed to push NV to chip\n");
  193. goto out_free_smd_buf;
  194. }
  195. ret = wcn36xx_smd_start(wcn);
  196. if (ret) {
  197. wcn36xx_err("Failed to start chip\n");
  198. goto out_free_smd_buf;
  199. }
  200. /* DMA channel initialization */
  201. ret = wcn36xx_dxe_init(wcn);
  202. if (ret) {
  203. wcn36xx_err("DXE init failed\n");
  204. goto out_smd_stop;
  205. }
  206. wcn36xx_debugfs_init(wcn);
  207. if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
  208. ret = wcn36xx_smd_feature_caps_exchange(wcn);
  209. if (ret)
  210. wcn36xx_warn("Exchange feature caps failed\n");
  211. }
  212. INIT_LIST_HEAD(&wcn->vif_list);
  213. return 0;
  214. out_smd_stop:
  215. wcn36xx_smd_stop(wcn);
  216. out_free_smd_buf:
  217. kfree(wcn->hal_buf);
  218. out_free_dxe_pool:
  219. wcn36xx_dxe_free_mem_pools(wcn);
  220. out_free_dxe_ctl:
  221. wcn36xx_dxe_free_ctl_blks(wcn);
  222. out_smd_close:
  223. wcn36xx_smd_close(wcn);
  224. out_err:
  225. return ret;
  226. }
  227. static void wcn36xx_stop(struct ieee80211_hw *hw)
  228. {
  229. struct wcn36xx *wcn = hw->priv;
  230. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac stop\n");
  231. wcn36xx_debugfs_exit(wcn);
  232. wcn36xx_smd_stop(wcn);
  233. wcn36xx_dxe_deinit(wcn);
  234. wcn36xx_smd_close(wcn);
  235. wcn36xx_dxe_free_mem_pools(wcn);
  236. wcn36xx_dxe_free_ctl_blks(wcn);
  237. kfree(wcn->hal_buf);
  238. }
  239. static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
  240. {
  241. struct wcn36xx *wcn = hw->priv;
  242. struct ieee80211_vif *vif = NULL;
  243. struct wcn36xx_vif *tmp;
  244. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
  245. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  246. int ch = WCN36XX_HW_CHANNEL(wcn);
  247. wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
  248. ch);
  249. list_for_each_entry(tmp, &wcn->vif_list, list) {
  250. vif = container_of((void *)tmp,
  251. struct ieee80211_vif,
  252. drv_priv);
  253. wcn36xx_smd_switch_channel(wcn, vif, ch);
  254. }
  255. }
  256. return 0;
  257. }
  258. #define WCN36XX_SUPPORTED_FILTERS (0)
  259. static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
  260. unsigned int changed,
  261. unsigned int *total, u64 multicast)
  262. {
  263. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
  264. *total &= WCN36XX_SUPPORTED_FILTERS;
  265. }
  266. static void wcn36xx_tx(struct ieee80211_hw *hw,
  267. struct ieee80211_tx_control *control,
  268. struct sk_buff *skb)
  269. {
  270. struct wcn36xx *wcn = hw->priv;
  271. struct wcn36xx_sta *sta_priv = NULL;
  272. if (control->sta)
  273. sta_priv = (struct wcn36xx_sta *)control->sta->drv_priv;
  274. if (wcn36xx_start_tx(wcn, sta_priv, skb))
  275. ieee80211_free_txskb(wcn->hw, skb);
  276. }
  277. static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  278. struct ieee80211_vif *vif,
  279. struct ieee80211_sta *sta,
  280. struct ieee80211_key_conf *key_conf)
  281. {
  282. struct wcn36xx *wcn = hw->priv;
  283. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  284. struct wcn36xx_sta *sta_priv = vif_priv->sta;
  285. int ret = 0;
  286. u8 key[WLAN_MAX_KEY_LEN];
  287. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n");
  288. wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n",
  289. cmd, key_conf->cipher, key_conf->keyidx,
  290. key_conf->keylen, key_conf->flags);
  291. wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ",
  292. key_conf->key,
  293. key_conf->keylen);
  294. switch (key_conf->cipher) {
  295. case WLAN_CIPHER_SUITE_WEP40:
  296. vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
  297. break;
  298. case WLAN_CIPHER_SUITE_WEP104:
  299. vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
  300. break;
  301. case WLAN_CIPHER_SUITE_CCMP:
  302. vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP;
  303. break;
  304. case WLAN_CIPHER_SUITE_TKIP:
  305. vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP;
  306. break;
  307. default:
  308. wcn36xx_err("Unsupported key type 0x%x\n",
  309. key_conf->cipher);
  310. ret = -EOPNOTSUPP;
  311. goto out;
  312. }
  313. switch (cmd) {
  314. case SET_KEY:
  315. if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) {
  316. /*
  317. * Supplicant is sending key in the wrong order:
  318. * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b)
  319. * but HW expects it to be in the order as described in
  320. * IEEE 802.11 spec (see chapter 11.7) like this:
  321. * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b)
  322. */
  323. memcpy(key, key_conf->key, 16);
  324. memcpy(key + 16, key_conf->key + 24, 8);
  325. memcpy(key + 24, key_conf->key + 16, 8);
  326. } else {
  327. memcpy(key, key_conf->key, key_conf->keylen);
  328. }
  329. if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) {
  330. sta_priv->is_data_encrypted = true;
  331. /* Reconfigure bss with encrypt_type */
  332. if (NL80211_IFTYPE_STATION == vif->type)
  333. wcn36xx_smd_config_bss(wcn,
  334. vif,
  335. sta,
  336. sta->addr,
  337. true);
  338. wcn36xx_smd_set_stakey(wcn,
  339. vif_priv->encrypt_type,
  340. key_conf->keyidx,
  341. key_conf->keylen,
  342. key,
  343. get_sta_index(vif, sta_priv));
  344. } else {
  345. wcn36xx_smd_set_bsskey(wcn,
  346. vif_priv->encrypt_type,
  347. key_conf->keyidx,
  348. key_conf->keylen,
  349. key);
  350. if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) ||
  351. (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) {
  352. sta_priv->is_data_encrypted = true;
  353. wcn36xx_smd_set_stakey(wcn,
  354. vif_priv->encrypt_type,
  355. key_conf->keyidx,
  356. key_conf->keylen,
  357. key,
  358. get_sta_index(vif, sta_priv));
  359. }
  360. }
  361. break;
  362. case DISABLE_KEY:
  363. if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) {
  364. wcn36xx_smd_remove_bsskey(wcn,
  365. vif_priv->encrypt_type,
  366. key_conf->keyidx);
  367. } else {
  368. sta_priv->is_data_encrypted = false;
  369. /* do not remove key if disassociated */
  370. if (sta_priv->aid)
  371. wcn36xx_smd_remove_stakey(wcn,
  372. vif_priv->encrypt_type,
  373. key_conf->keyidx,
  374. get_sta_index(vif, sta_priv));
  375. }
  376. break;
  377. default:
  378. wcn36xx_err("Unsupported key cmd 0x%x\n", cmd);
  379. ret = -EOPNOTSUPP;
  380. goto out;
  381. break;
  382. }
  383. out:
  384. return ret;
  385. }
  386. static void wcn36xx_sw_scan_start(struct ieee80211_hw *hw)
  387. {
  388. struct wcn36xx *wcn = hw->priv;
  389. wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN);
  390. wcn36xx_smd_start_scan(wcn);
  391. }
  392. static void wcn36xx_sw_scan_complete(struct ieee80211_hw *hw)
  393. {
  394. struct wcn36xx *wcn = hw->priv;
  395. wcn36xx_smd_end_scan(wcn);
  396. wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN);
  397. }
  398. static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta,
  399. enum ieee80211_band band)
  400. {
  401. int i, size;
  402. u16 *rates_table;
  403. struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  404. u32 rates = sta->supp_rates[band];
  405. memset(&sta_priv->supported_rates, 0,
  406. sizeof(sta_priv->supported_rates));
  407. sta_priv->supported_rates.op_rate_mode = STA_11n;
  408. size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates);
  409. rates_table = sta_priv->supported_rates.dsss_rates;
  410. if (band == IEEE80211_BAND_2GHZ) {
  411. for (i = 0; i < size; i++) {
  412. if (rates & 0x01) {
  413. rates_table[i] = wcn_2ghz_rates[i].hw_value;
  414. rates = rates >> 1;
  415. }
  416. }
  417. }
  418. size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates);
  419. rates_table = sta_priv->supported_rates.ofdm_rates;
  420. for (i = 0; i < size; i++) {
  421. if (rates & 0x01) {
  422. rates_table[i] = wcn_5ghz_rates[i].hw_value;
  423. rates = rates >> 1;
  424. }
  425. }
  426. if (sta->ht_cap.ht_supported) {
  427. BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) >
  428. sizeof(sta_priv->supported_rates.supported_mcs_set));
  429. memcpy(sta_priv->supported_rates.supported_mcs_set,
  430. sta->ht_cap.mcs.rx_mask,
  431. sizeof(sta->ht_cap.mcs.rx_mask));
  432. }
  433. }
  434. void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates)
  435. {
  436. u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = {
  437. HW_RATE_INDEX_6MBPS,
  438. HW_RATE_INDEX_9MBPS,
  439. HW_RATE_INDEX_12MBPS,
  440. HW_RATE_INDEX_18MBPS,
  441. HW_RATE_INDEX_24MBPS,
  442. HW_RATE_INDEX_36MBPS,
  443. HW_RATE_INDEX_48MBPS,
  444. HW_RATE_INDEX_54MBPS
  445. };
  446. u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = {
  447. HW_RATE_INDEX_1MBPS,
  448. HW_RATE_INDEX_2MBPS,
  449. HW_RATE_INDEX_5_5MBPS,
  450. HW_RATE_INDEX_11MBPS
  451. };
  452. rates->op_rate_mode = STA_11n;
  453. memcpy(rates->dsss_rates, dsss_rates,
  454. sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES);
  455. memcpy(rates->ofdm_rates, ofdm_rates,
  456. sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES);
  457. rates->supported_mcs_set[0] = 0xFF;
  458. }
  459. static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
  460. struct ieee80211_vif *vif,
  461. struct ieee80211_bss_conf *bss_conf,
  462. u32 changed)
  463. {
  464. struct wcn36xx *wcn = hw->priv;
  465. struct sk_buff *skb = NULL;
  466. u16 tim_off, tim_len;
  467. enum wcn36xx_hal_link_state link_state;
  468. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  469. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
  470. vif, changed);
  471. if (changed & BSS_CHANGED_BEACON_INFO) {
  472. wcn36xx_dbg(WCN36XX_DBG_MAC,
  473. "mac bss changed dtim period %d\n",
  474. bss_conf->dtim_period);
  475. vif_priv->dtim_period = bss_conf->dtim_period;
  476. }
  477. if (changed & BSS_CHANGED_PS) {
  478. wcn36xx_dbg(WCN36XX_DBG_MAC,
  479. "mac bss PS set %d\n",
  480. bss_conf->ps);
  481. if (bss_conf->ps) {
  482. wcn36xx_pmc_enter_bmps_state(wcn, vif);
  483. } else {
  484. wcn36xx_pmc_exit_bmps_state(wcn, vif);
  485. }
  486. }
  487. if (changed & BSS_CHANGED_BSSID) {
  488. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n",
  489. bss_conf->bssid);
  490. if (!is_zero_ether_addr(bss_conf->bssid)) {
  491. vif_priv->is_joining = true;
  492. vif_priv->bss_index = 0xff;
  493. wcn36xx_smd_join(wcn, bss_conf->bssid,
  494. vif->addr, WCN36XX_HW_CHANNEL(wcn));
  495. wcn36xx_smd_config_bss(wcn, vif, NULL,
  496. bss_conf->bssid, false);
  497. } else {
  498. vif_priv->is_joining = false;
  499. wcn36xx_smd_delete_bss(wcn, vif);
  500. }
  501. }
  502. if (changed & BSS_CHANGED_SSID) {
  503. wcn36xx_dbg(WCN36XX_DBG_MAC,
  504. "mac bss changed ssid\n");
  505. wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ",
  506. bss_conf->ssid, bss_conf->ssid_len);
  507. vif_priv->ssid.length = bss_conf->ssid_len;
  508. memcpy(&vif_priv->ssid.ssid,
  509. bss_conf->ssid,
  510. bss_conf->ssid_len);
  511. }
  512. if (changed & BSS_CHANGED_ASSOC) {
  513. vif_priv->is_joining = false;
  514. if (bss_conf->assoc) {
  515. struct ieee80211_sta *sta;
  516. struct wcn36xx_sta *sta_priv;
  517. wcn36xx_dbg(WCN36XX_DBG_MAC,
  518. "mac assoc bss %pM vif %pM AID=%d\n",
  519. bss_conf->bssid,
  520. vif->addr,
  521. bss_conf->aid);
  522. rcu_read_lock();
  523. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  524. if (!sta) {
  525. wcn36xx_err("sta %pM is not found\n",
  526. bss_conf->bssid);
  527. rcu_read_unlock();
  528. goto out;
  529. }
  530. sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  531. wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
  532. wcn36xx_smd_set_link_st(wcn, bss_conf->bssid,
  533. vif->addr,
  534. WCN36XX_HAL_LINK_POSTASSOC_STATE);
  535. wcn36xx_smd_config_bss(wcn, vif, sta,
  536. bss_conf->bssid,
  537. true);
  538. sta_priv->aid = bss_conf->aid;
  539. /*
  540. * config_sta must be called from because this is the
  541. * place where AID is available.
  542. */
  543. wcn36xx_smd_config_sta(wcn, vif, sta);
  544. rcu_read_unlock();
  545. } else {
  546. wcn36xx_dbg(WCN36XX_DBG_MAC,
  547. "disassociated bss %pM vif %pM AID=%d\n",
  548. bss_conf->bssid,
  549. vif->addr,
  550. bss_conf->aid);
  551. wcn36xx_smd_set_link_st(wcn,
  552. bss_conf->bssid,
  553. vif->addr,
  554. WCN36XX_HAL_LINK_IDLE_STATE);
  555. }
  556. }
  557. if (changed & BSS_CHANGED_AP_PROBE_RESP) {
  558. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n");
  559. skb = ieee80211_proberesp_get(hw, vif);
  560. if (!skb) {
  561. wcn36xx_err("failed to alloc probereq skb\n");
  562. goto out;
  563. }
  564. wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb);
  565. dev_kfree_skb(skb);
  566. }
  567. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  568. wcn36xx_dbg(WCN36XX_DBG_MAC,
  569. "mac bss changed beacon enabled %d\n",
  570. bss_conf->enable_beacon);
  571. if (bss_conf->enable_beacon) {
  572. vif_priv->bss_index = 0xff;
  573. wcn36xx_smd_config_bss(wcn, vif, NULL,
  574. vif->addr, false);
  575. skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
  576. &tim_len);
  577. if (!skb) {
  578. wcn36xx_err("failed to alloc beacon skb\n");
  579. goto out;
  580. }
  581. wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
  582. dev_kfree_skb(skb);
  583. if (vif->type == NL80211_IFTYPE_ADHOC ||
  584. vif->type == NL80211_IFTYPE_MESH_POINT)
  585. link_state = WCN36XX_HAL_LINK_IBSS_STATE;
  586. else
  587. link_state = WCN36XX_HAL_LINK_AP_STATE;
  588. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  589. link_state);
  590. } else {
  591. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  592. WCN36XX_HAL_LINK_IDLE_STATE);
  593. wcn36xx_smd_delete_bss(wcn, vif);
  594. }
  595. }
  596. out:
  597. return;
  598. }
  599. /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
  600. static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  601. {
  602. struct wcn36xx *wcn = hw->priv;
  603. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
  604. wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
  605. return 0;
  606. }
  607. static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
  608. struct ieee80211_vif *vif)
  609. {
  610. struct wcn36xx *wcn = hw->priv;
  611. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  612. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
  613. list_del(&vif_priv->list);
  614. wcn36xx_smd_delete_sta_self(wcn, vif->addr);
  615. }
  616. static int wcn36xx_add_interface(struct ieee80211_hw *hw,
  617. struct ieee80211_vif *vif)
  618. {
  619. struct wcn36xx *wcn = hw->priv;
  620. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  621. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
  622. vif, vif->type);
  623. if (!(NL80211_IFTYPE_STATION == vif->type ||
  624. NL80211_IFTYPE_AP == vif->type ||
  625. NL80211_IFTYPE_ADHOC == vif->type ||
  626. NL80211_IFTYPE_MESH_POINT == vif->type)) {
  627. wcn36xx_warn("Unsupported interface type requested: %d\n",
  628. vif->type);
  629. return -EOPNOTSUPP;
  630. }
  631. list_add(&vif_priv->list, &wcn->vif_list);
  632. wcn36xx_smd_add_sta_self(wcn, vif);
  633. return 0;
  634. }
  635. static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  636. struct ieee80211_sta *sta)
  637. {
  638. struct wcn36xx *wcn = hw->priv;
  639. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  640. struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  641. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
  642. vif, sta->addr);
  643. vif_priv->sta = sta_priv;
  644. sta_priv->vif = vif_priv;
  645. /*
  646. * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
  647. * at this stage AID is not available yet.
  648. */
  649. if (NL80211_IFTYPE_STATION != vif->type) {
  650. wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
  651. sta_priv->aid = sta->aid;
  652. wcn36xx_smd_config_sta(wcn, vif, sta);
  653. }
  654. return 0;
  655. }
  656. static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
  657. struct ieee80211_vif *vif,
  658. struct ieee80211_sta *sta)
  659. {
  660. struct wcn36xx *wcn = hw->priv;
  661. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  662. struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  663. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
  664. vif, sta->addr, sta_priv->sta_index);
  665. wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
  666. vif_priv->sta = NULL;
  667. sta_priv->vif = NULL;
  668. return 0;
  669. }
  670. #ifdef CONFIG_PM
  671. static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
  672. {
  673. struct wcn36xx *wcn = hw->priv;
  674. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
  675. flush_workqueue(wcn->hal_ind_wq);
  676. wcn36xx_smd_set_power_params(wcn, true);
  677. return 0;
  678. }
  679. static int wcn36xx_resume(struct ieee80211_hw *hw)
  680. {
  681. struct wcn36xx *wcn = hw->priv;
  682. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
  683. flush_workqueue(wcn->hal_ind_wq);
  684. wcn36xx_smd_set_power_params(wcn, false);
  685. return 0;
  686. }
  687. #endif
  688. static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
  689. struct ieee80211_vif *vif,
  690. enum ieee80211_ampdu_mlme_action action,
  691. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  692. u8 buf_size)
  693. {
  694. struct wcn36xx *wcn = hw->priv;
  695. struct wcn36xx_sta *sta_priv = NULL;
  696. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
  697. action, tid);
  698. sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  699. switch (action) {
  700. case IEEE80211_AMPDU_RX_START:
  701. sta_priv->tid = tid;
  702. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
  703. get_sta_index(vif, sta_priv));
  704. wcn36xx_smd_add_ba(wcn);
  705. wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv));
  706. ieee80211_start_tx_ba_session(sta, tid, 0);
  707. break;
  708. case IEEE80211_AMPDU_RX_STOP:
  709. wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
  710. break;
  711. case IEEE80211_AMPDU_TX_START:
  712. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  713. break;
  714. case IEEE80211_AMPDU_TX_OPERATIONAL:
  715. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
  716. get_sta_index(vif, sta_priv));
  717. break;
  718. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  719. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  720. case IEEE80211_AMPDU_TX_STOP_CONT:
  721. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  722. break;
  723. default:
  724. wcn36xx_err("Unknown AMPDU action\n");
  725. }
  726. return 0;
  727. }
  728. static const struct ieee80211_ops wcn36xx_ops = {
  729. .start = wcn36xx_start,
  730. .stop = wcn36xx_stop,
  731. .add_interface = wcn36xx_add_interface,
  732. .remove_interface = wcn36xx_remove_interface,
  733. #ifdef CONFIG_PM
  734. .suspend = wcn36xx_suspend,
  735. .resume = wcn36xx_resume,
  736. #endif
  737. .config = wcn36xx_config,
  738. .configure_filter = wcn36xx_configure_filter,
  739. .tx = wcn36xx_tx,
  740. .set_key = wcn36xx_set_key,
  741. .sw_scan_start = wcn36xx_sw_scan_start,
  742. .sw_scan_complete = wcn36xx_sw_scan_complete,
  743. .bss_info_changed = wcn36xx_bss_info_changed,
  744. .set_rts_threshold = wcn36xx_set_rts_threshold,
  745. .sta_add = wcn36xx_sta_add,
  746. .sta_remove = wcn36xx_sta_remove,
  747. .ampdu_action = wcn36xx_ampdu_action,
  748. };
  749. static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
  750. {
  751. int ret = 0;
  752. static const u32 cipher_suites[] = {
  753. WLAN_CIPHER_SUITE_WEP40,
  754. WLAN_CIPHER_SUITE_WEP104,
  755. WLAN_CIPHER_SUITE_TKIP,
  756. WLAN_CIPHER_SUITE_CCMP,
  757. };
  758. wcn->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  759. IEEE80211_HW_HAS_RATE_CONTROL |
  760. IEEE80211_HW_SUPPORTS_PS |
  761. IEEE80211_HW_CONNECTION_MONITOR |
  762. IEEE80211_HW_AMPDU_AGGREGATION |
  763. IEEE80211_HW_TIMING_BEACON_ONLY;
  764. wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  765. BIT(NL80211_IFTYPE_AP) |
  766. BIT(NL80211_IFTYPE_ADHOC) |
  767. BIT(NL80211_IFTYPE_MESH_POINT);
  768. wcn->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wcn_band_2ghz;
  769. wcn->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wcn_band_5ghz;
  770. wcn->hw->wiphy->cipher_suites = cipher_suites;
  771. wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  772. wcn->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  773. #ifdef CONFIG_PM
  774. wcn->hw->wiphy->wowlan = &wowlan_support;
  775. #endif
  776. wcn->hw->max_listen_interval = 200;
  777. wcn->hw->queues = 4;
  778. SET_IEEE80211_DEV(wcn->hw, wcn->dev);
  779. wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
  780. wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
  781. return ret;
  782. }
  783. static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
  784. struct platform_device *pdev)
  785. {
  786. struct resource *res;
  787. /* Set TX IRQ */
  788. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  789. "wcnss_wlantx_irq");
  790. if (!res) {
  791. wcn36xx_err("failed to get tx_irq\n");
  792. return -ENOENT;
  793. }
  794. wcn->tx_irq = res->start;
  795. /* Set RX IRQ */
  796. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  797. "wcnss_wlanrx_irq");
  798. if (!res) {
  799. wcn36xx_err("failed to get rx_irq\n");
  800. return -ENOENT;
  801. }
  802. wcn->rx_irq = res->start;
  803. /* Map the memory */
  804. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  805. "wcnss_mmio");
  806. if (!res) {
  807. wcn36xx_err("failed to get mmio\n");
  808. return -ENOENT;
  809. }
  810. wcn->mmio = ioremap(res->start, resource_size(res));
  811. if (!wcn->mmio) {
  812. wcn36xx_err("failed to map io memory\n");
  813. return -ENOMEM;
  814. }
  815. return 0;
  816. }
  817. static int wcn36xx_probe(struct platform_device *pdev)
  818. {
  819. struct ieee80211_hw *hw;
  820. struct wcn36xx *wcn;
  821. int ret;
  822. u8 addr[ETH_ALEN];
  823. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
  824. hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
  825. if (!hw) {
  826. wcn36xx_err("failed to alloc hw\n");
  827. ret = -ENOMEM;
  828. goto out_err;
  829. }
  830. platform_set_drvdata(pdev, hw);
  831. wcn = hw->priv;
  832. wcn->hw = hw;
  833. wcn->dev = &pdev->dev;
  834. wcn->ctrl_ops = pdev->dev.platform_data;
  835. mutex_init(&wcn->hal_mutex);
  836. if (!wcn->ctrl_ops->get_hw_mac(addr)) {
  837. wcn36xx_info("mac address: %pM\n", addr);
  838. SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
  839. }
  840. ret = wcn36xx_platform_get_resources(wcn, pdev);
  841. if (ret)
  842. goto out_wq;
  843. wcn36xx_init_ieee80211(wcn);
  844. ret = ieee80211_register_hw(wcn->hw);
  845. if (ret)
  846. goto out_unmap;
  847. return 0;
  848. out_unmap:
  849. iounmap(wcn->mmio);
  850. out_wq:
  851. ieee80211_free_hw(hw);
  852. out_err:
  853. return ret;
  854. }
  855. static int wcn36xx_remove(struct platform_device *pdev)
  856. {
  857. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  858. struct wcn36xx *wcn = hw->priv;
  859. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
  860. mutex_destroy(&wcn->hal_mutex);
  861. ieee80211_unregister_hw(hw);
  862. iounmap(wcn->mmio);
  863. ieee80211_free_hw(hw);
  864. return 0;
  865. }
  866. static const struct platform_device_id wcn36xx_platform_id_table[] = {
  867. {
  868. .name = "wcn36xx",
  869. .driver_data = 0
  870. },
  871. {}
  872. };
  873. MODULE_DEVICE_TABLE(platform, wcn36xx_platform_id_table);
  874. static struct platform_driver wcn36xx_driver = {
  875. .probe = wcn36xx_probe,
  876. .remove = wcn36xx_remove,
  877. .driver = {
  878. .name = "wcn36xx",
  879. .owner = THIS_MODULE,
  880. },
  881. .id_table = wcn36xx_platform_id_table,
  882. };
  883. static int __init wcn36xx_init(void)
  884. {
  885. platform_driver_register(&wcn36xx_driver);
  886. return 0;
  887. }
  888. module_init(wcn36xx_init);
  889. static void __exit wcn36xx_exit(void)
  890. {
  891. platform_driver_unregister(&wcn36xx_driver);
  892. }
  893. module_exit(wcn36xx_exit);
  894. MODULE_LICENSE("Dual BSD/GPL");
  895. MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
  896. MODULE_FIRMWARE(WLAN_NV_FILE);