main.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. changed & BSS_CHANGED_BEACON) {
  569. wcn36xx_dbg(WCN36XX_DBG_MAC,
  570. "mac bss changed beacon enabled %d\n",
  571. bss_conf->enable_beacon);
  572. if (bss_conf->enable_beacon) {
  573. vif_priv->bss_index = 0xff;
  574. wcn36xx_smd_config_bss(wcn, vif, NULL,
  575. vif->addr, false);
  576. skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
  577. &tim_len);
  578. if (!skb) {
  579. wcn36xx_err("failed to alloc beacon skb\n");
  580. goto out;
  581. }
  582. wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
  583. dev_kfree_skb(skb);
  584. if (vif->type == NL80211_IFTYPE_ADHOC ||
  585. vif->type == NL80211_IFTYPE_MESH_POINT)
  586. link_state = WCN36XX_HAL_LINK_IBSS_STATE;
  587. else
  588. link_state = WCN36XX_HAL_LINK_AP_STATE;
  589. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  590. link_state);
  591. } else {
  592. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  593. WCN36XX_HAL_LINK_IDLE_STATE);
  594. wcn36xx_smd_delete_bss(wcn, vif);
  595. }
  596. }
  597. out:
  598. return;
  599. }
  600. /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
  601. static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  602. {
  603. struct wcn36xx *wcn = hw->priv;
  604. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
  605. wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
  606. return 0;
  607. }
  608. static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
  609. struct ieee80211_vif *vif)
  610. {
  611. struct wcn36xx *wcn = hw->priv;
  612. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  613. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
  614. list_del(&vif_priv->list);
  615. wcn36xx_smd_delete_sta_self(wcn, vif->addr);
  616. }
  617. static int wcn36xx_add_interface(struct ieee80211_hw *hw,
  618. struct ieee80211_vif *vif)
  619. {
  620. struct wcn36xx *wcn = hw->priv;
  621. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  622. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
  623. vif, vif->type);
  624. if (!(NL80211_IFTYPE_STATION == vif->type ||
  625. NL80211_IFTYPE_AP == vif->type ||
  626. NL80211_IFTYPE_ADHOC == vif->type ||
  627. NL80211_IFTYPE_MESH_POINT == vif->type)) {
  628. wcn36xx_warn("Unsupported interface type requested: %d\n",
  629. vif->type);
  630. return -EOPNOTSUPP;
  631. }
  632. list_add(&vif_priv->list, &wcn->vif_list);
  633. wcn36xx_smd_add_sta_self(wcn, vif);
  634. return 0;
  635. }
  636. static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  637. struct ieee80211_sta *sta)
  638. {
  639. struct wcn36xx *wcn = hw->priv;
  640. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  641. struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  642. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
  643. vif, sta->addr);
  644. vif_priv->sta = sta_priv;
  645. sta_priv->vif = vif_priv;
  646. /*
  647. * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
  648. * at this stage AID is not available yet.
  649. */
  650. if (NL80211_IFTYPE_STATION != vif->type) {
  651. wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
  652. sta_priv->aid = sta->aid;
  653. wcn36xx_smd_config_sta(wcn, vif, sta);
  654. }
  655. return 0;
  656. }
  657. static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
  658. struct ieee80211_vif *vif,
  659. struct ieee80211_sta *sta)
  660. {
  661. struct wcn36xx *wcn = hw->priv;
  662. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  663. struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  664. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
  665. vif, sta->addr, sta_priv->sta_index);
  666. wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
  667. vif_priv->sta = NULL;
  668. sta_priv->vif = NULL;
  669. return 0;
  670. }
  671. #ifdef CONFIG_PM
  672. static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
  673. {
  674. struct wcn36xx *wcn = hw->priv;
  675. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
  676. flush_workqueue(wcn->hal_ind_wq);
  677. wcn36xx_smd_set_power_params(wcn, true);
  678. return 0;
  679. }
  680. static int wcn36xx_resume(struct ieee80211_hw *hw)
  681. {
  682. struct wcn36xx *wcn = hw->priv;
  683. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
  684. flush_workqueue(wcn->hal_ind_wq);
  685. wcn36xx_smd_set_power_params(wcn, false);
  686. return 0;
  687. }
  688. #endif
  689. static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
  690. struct ieee80211_vif *vif,
  691. enum ieee80211_ampdu_mlme_action action,
  692. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  693. u8 buf_size)
  694. {
  695. struct wcn36xx *wcn = hw->priv;
  696. struct wcn36xx_sta *sta_priv = NULL;
  697. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
  698. action, tid);
  699. sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  700. switch (action) {
  701. case IEEE80211_AMPDU_RX_START:
  702. sta_priv->tid = tid;
  703. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
  704. get_sta_index(vif, sta_priv));
  705. wcn36xx_smd_add_ba(wcn);
  706. wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv));
  707. ieee80211_start_tx_ba_session(sta, tid, 0);
  708. break;
  709. case IEEE80211_AMPDU_RX_STOP:
  710. wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
  711. break;
  712. case IEEE80211_AMPDU_TX_START:
  713. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  714. break;
  715. case IEEE80211_AMPDU_TX_OPERATIONAL:
  716. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
  717. get_sta_index(vif, sta_priv));
  718. break;
  719. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  720. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  721. case IEEE80211_AMPDU_TX_STOP_CONT:
  722. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  723. break;
  724. default:
  725. wcn36xx_err("Unknown AMPDU action\n");
  726. }
  727. return 0;
  728. }
  729. static const struct ieee80211_ops wcn36xx_ops = {
  730. .start = wcn36xx_start,
  731. .stop = wcn36xx_stop,
  732. .add_interface = wcn36xx_add_interface,
  733. .remove_interface = wcn36xx_remove_interface,
  734. #ifdef CONFIG_PM
  735. .suspend = wcn36xx_suspend,
  736. .resume = wcn36xx_resume,
  737. #endif
  738. .config = wcn36xx_config,
  739. .configure_filter = wcn36xx_configure_filter,
  740. .tx = wcn36xx_tx,
  741. .set_key = wcn36xx_set_key,
  742. .sw_scan_start = wcn36xx_sw_scan_start,
  743. .sw_scan_complete = wcn36xx_sw_scan_complete,
  744. .bss_info_changed = wcn36xx_bss_info_changed,
  745. .set_rts_threshold = wcn36xx_set_rts_threshold,
  746. .sta_add = wcn36xx_sta_add,
  747. .sta_remove = wcn36xx_sta_remove,
  748. .ampdu_action = wcn36xx_ampdu_action,
  749. };
  750. static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
  751. {
  752. int ret = 0;
  753. static const u32 cipher_suites[] = {
  754. WLAN_CIPHER_SUITE_WEP40,
  755. WLAN_CIPHER_SUITE_WEP104,
  756. WLAN_CIPHER_SUITE_TKIP,
  757. WLAN_CIPHER_SUITE_CCMP,
  758. };
  759. wcn->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  760. IEEE80211_HW_HAS_RATE_CONTROL |
  761. IEEE80211_HW_SUPPORTS_PS |
  762. IEEE80211_HW_CONNECTION_MONITOR |
  763. IEEE80211_HW_AMPDU_AGGREGATION |
  764. IEEE80211_HW_TIMING_BEACON_ONLY;
  765. wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  766. BIT(NL80211_IFTYPE_AP) |
  767. BIT(NL80211_IFTYPE_ADHOC) |
  768. BIT(NL80211_IFTYPE_MESH_POINT);
  769. wcn->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wcn_band_2ghz;
  770. wcn->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wcn_band_5ghz;
  771. wcn->hw->wiphy->cipher_suites = cipher_suites;
  772. wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  773. wcn->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  774. #ifdef CONFIG_PM
  775. wcn->hw->wiphy->wowlan = &wowlan_support;
  776. #endif
  777. wcn->hw->max_listen_interval = 200;
  778. wcn->hw->queues = 4;
  779. SET_IEEE80211_DEV(wcn->hw, wcn->dev);
  780. wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
  781. wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
  782. return ret;
  783. }
  784. static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
  785. struct platform_device *pdev)
  786. {
  787. struct resource *res;
  788. /* Set TX IRQ */
  789. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  790. "wcnss_wlantx_irq");
  791. if (!res) {
  792. wcn36xx_err("failed to get tx_irq\n");
  793. return -ENOENT;
  794. }
  795. wcn->tx_irq = res->start;
  796. /* Set RX IRQ */
  797. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  798. "wcnss_wlanrx_irq");
  799. if (!res) {
  800. wcn36xx_err("failed to get rx_irq\n");
  801. return -ENOENT;
  802. }
  803. wcn->rx_irq = res->start;
  804. /* Map the memory */
  805. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  806. "wcnss_mmio");
  807. if (!res) {
  808. wcn36xx_err("failed to get mmio\n");
  809. return -ENOENT;
  810. }
  811. wcn->mmio = ioremap(res->start, resource_size(res));
  812. if (!wcn->mmio) {
  813. wcn36xx_err("failed to map io memory\n");
  814. return -ENOMEM;
  815. }
  816. return 0;
  817. }
  818. static int wcn36xx_probe(struct platform_device *pdev)
  819. {
  820. struct ieee80211_hw *hw;
  821. struct wcn36xx *wcn;
  822. int ret;
  823. u8 addr[ETH_ALEN];
  824. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
  825. hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
  826. if (!hw) {
  827. wcn36xx_err("failed to alloc hw\n");
  828. ret = -ENOMEM;
  829. goto out_err;
  830. }
  831. platform_set_drvdata(pdev, hw);
  832. wcn = hw->priv;
  833. wcn->hw = hw;
  834. wcn->dev = &pdev->dev;
  835. wcn->ctrl_ops = pdev->dev.platform_data;
  836. mutex_init(&wcn->hal_mutex);
  837. if (!wcn->ctrl_ops->get_hw_mac(addr)) {
  838. wcn36xx_info("mac address: %pM\n", addr);
  839. SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
  840. }
  841. ret = wcn36xx_platform_get_resources(wcn, pdev);
  842. if (ret)
  843. goto out_wq;
  844. wcn36xx_init_ieee80211(wcn);
  845. ret = ieee80211_register_hw(wcn->hw);
  846. if (ret)
  847. goto out_unmap;
  848. return 0;
  849. out_unmap:
  850. iounmap(wcn->mmio);
  851. out_wq:
  852. ieee80211_free_hw(hw);
  853. out_err:
  854. return ret;
  855. }
  856. static int wcn36xx_remove(struct platform_device *pdev)
  857. {
  858. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  859. struct wcn36xx *wcn = hw->priv;
  860. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
  861. mutex_destroy(&wcn->hal_mutex);
  862. ieee80211_unregister_hw(hw);
  863. iounmap(wcn->mmio);
  864. ieee80211_free_hw(hw);
  865. return 0;
  866. }
  867. static const struct platform_device_id wcn36xx_platform_id_table[] = {
  868. {
  869. .name = "wcn36xx",
  870. .driver_data = 0
  871. },
  872. {}
  873. };
  874. MODULE_DEVICE_TABLE(platform, wcn36xx_platform_id_table);
  875. static struct platform_driver wcn36xx_driver = {
  876. .probe = wcn36xx_probe,
  877. .remove = wcn36xx_remove,
  878. .driver = {
  879. .name = "wcn36xx",
  880. .owner = THIS_MODULE,
  881. },
  882. .id_table = wcn36xx_platform_id_table,
  883. };
  884. static int __init wcn36xx_init(void)
  885. {
  886. platform_driver_register(&wcn36xx_driver);
  887. return 0;
  888. }
  889. module_init(wcn36xx_init);
  890. static void __exit wcn36xx_exit(void)
  891. {
  892. platform_driver_unregister(&wcn36xx_driver);
  893. }
  894. module_exit(wcn36xx_exit);
  895. MODULE_LICENSE("Dual BSD/GPL");
  896. MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
  897. MODULE_FIRMWARE(WLAN_NV_FILE);