main.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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/firmware.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/of_address.h>
  21. #include <linux/of_device.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/rpmsg.h>
  24. #include <linux/soc/qcom/smem_state.h>
  25. #include <linux/soc/qcom/wcnss_ctrl.h>
  26. #include "wcn36xx.h"
  27. unsigned int wcn36xx_dbg_mask;
  28. module_param_named(debug_mask, wcn36xx_dbg_mask, uint, 0644);
  29. MODULE_PARM_DESC(debug_mask, "Debugging mask");
  30. #define CHAN2G(_freq, _idx) { \
  31. .band = NL80211_BAND_2GHZ, \
  32. .center_freq = (_freq), \
  33. .hw_value = (_idx), \
  34. .max_power = 25, \
  35. }
  36. #define CHAN5G(_freq, _idx) { \
  37. .band = NL80211_BAND_5GHZ, \
  38. .center_freq = (_freq), \
  39. .hw_value = (_idx), \
  40. .max_power = 25, \
  41. }
  42. /* The wcn firmware expects channel values to matching
  43. * their mnemonic values. So use these for .hw_value. */
  44. static struct ieee80211_channel wcn_2ghz_channels[] = {
  45. CHAN2G(2412, 1), /* Channel 1 */
  46. CHAN2G(2417, 2), /* Channel 2 */
  47. CHAN2G(2422, 3), /* Channel 3 */
  48. CHAN2G(2427, 4), /* Channel 4 */
  49. CHAN2G(2432, 5), /* Channel 5 */
  50. CHAN2G(2437, 6), /* Channel 6 */
  51. CHAN2G(2442, 7), /* Channel 7 */
  52. CHAN2G(2447, 8), /* Channel 8 */
  53. CHAN2G(2452, 9), /* Channel 9 */
  54. CHAN2G(2457, 10), /* Channel 10 */
  55. CHAN2G(2462, 11), /* Channel 11 */
  56. CHAN2G(2467, 12), /* Channel 12 */
  57. CHAN2G(2472, 13), /* Channel 13 */
  58. CHAN2G(2484, 14) /* Channel 14 */
  59. };
  60. static struct ieee80211_channel wcn_5ghz_channels[] = {
  61. CHAN5G(5180, 36),
  62. CHAN5G(5200, 40),
  63. CHAN5G(5220, 44),
  64. CHAN5G(5240, 48),
  65. CHAN5G(5260, 52),
  66. CHAN5G(5280, 56),
  67. CHAN5G(5300, 60),
  68. CHAN5G(5320, 64),
  69. CHAN5G(5500, 100),
  70. CHAN5G(5520, 104),
  71. CHAN5G(5540, 108),
  72. CHAN5G(5560, 112),
  73. CHAN5G(5580, 116),
  74. CHAN5G(5600, 120),
  75. CHAN5G(5620, 124),
  76. CHAN5G(5640, 128),
  77. CHAN5G(5660, 132),
  78. CHAN5G(5700, 140),
  79. CHAN5G(5745, 149),
  80. CHAN5G(5765, 153),
  81. CHAN5G(5785, 157),
  82. CHAN5G(5805, 161),
  83. CHAN5G(5825, 165)
  84. };
  85. #define RATE(_bitrate, _hw_rate, _flags) { \
  86. .bitrate = (_bitrate), \
  87. .flags = (_flags), \
  88. .hw_value = (_hw_rate), \
  89. .hw_value_short = (_hw_rate) \
  90. }
  91. static struct ieee80211_rate wcn_2ghz_rates[] = {
  92. RATE(10, HW_RATE_INDEX_1MBPS, 0),
  93. RATE(20, HW_RATE_INDEX_2MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
  94. RATE(55, HW_RATE_INDEX_5_5MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
  95. RATE(110, HW_RATE_INDEX_11MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
  96. RATE(60, HW_RATE_INDEX_6MBPS, 0),
  97. RATE(90, HW_RATE_INDEX_9MBPS, 0),
  98. RATE(120, HW_RATE_INDEX_12MBPS, 0),
  99. RATE(180, HW_RATE_INDEX_18MBPS, 0),
  100. RATE(240, HW_RATE_INDEX_24MBPS, 0),
  101. RATE(360, HW_RATE_INDEX_36MBPS, 0),
  102. RATE(480, HW_RATE_INDEX_48MBPS, 0),
  103. RATE(540, HW_RATE_INDEX_54MBPS, 0)
  104. };
  105. static struct ieee80211_rate wcn_5ghz_rates[] = {
  106. RATE(60, HW_RATE_INDEX_6MBPS, 0),
  107. RATE(90, HW_RATE_INDEX_9MBPS, 0),
  108. RATE(120, HW_RATE_INDEX_12MBPS, 0),
  109. RATE(180, HW_RATE_INDEX_18MBPS, 0),
  110. RATE(240, HW_RATE_INDEX_24MBPS, 0),
  111. RATE(360, HW_RATE_INDEX_36MBPS, 0),
  112. RATE(480, HW_RATE_INDEX_48MBPS, 0),
  113. RATE(540, HW_RATE_INDEX_54MBPS, 0)
  114. };
  115. static struct ieee80211_supported_band wcn_band_2ghz = {
  116. .channels = wcn_2ghz_channels,
  117. .n_channels = ARRAY_SIZE(wcn_2ghz_channels),
  118. .bitrates = wcn_2ghz_rates,
  119. .n_bitrates = ARRAY_SIZE(wcn_2ghz_rates),
  120. .ht_cap = {
  121. .cap = IEEE80211_HT_CAP_GRN_FLD |
  122. IEEE80211_HT_CAP_SGI_20 |
  123. IEEE80211_HT_CAP_DSSSCCK40 |
  124. IEEE80211_HT_CAP_LSIG_TXOP_PROT,
  125. .ht_supported = true,
  126. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
  127. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  128. .mcs = {
  129. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  130. .rx_highest = cpu_to_le16(72),
  131. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  132. }
  133. }
  134. };
  135. static struct ieee80211_supported_band wcn_band_5ghz = {
  136. .channels = wcn_5ghz_channels,
  137. .n_channels = ARRAY_SIZE(wcn_5ghz_channels),
  138. .bitrates = wcn_5ghz_rates,
  139. .n_bitrates = ARRAY_SIZE(wcn_5ghz_rates),
  140. .ht_cap = {
  141. .cap = IEEE80211_HT_CAP_GRN_FLD |
  142. IEEE80211_HT_CAP_SGI_20 |
  143. IEEE80211_HT_CAP_DSSSCCK40 |
  144. IEEE80211_HT_CAP_LSIG_TXOP_PROT |
  145. IEEE80211_HT_CAP_SGI_40 |
  146. IEEE80211_HT_CAP_SUP_WIDTH_20_40,
  147. .ht_supported = true,
  148. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
  149. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  150. .mcs = {
  151. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  152. .rx_highest = cpu_to_le16(72),
  153. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  154. }
  155. }
  156. };
  157. #ifdef CONFIG_PM
  158. static const struct wiphy_wowlan_support wowlan_support = {
  159. .flags = WIPHY_WOWLAN_ANY
  160. };
  161. #endif
  162. static inline u8 get_sta_index(struct ieee80211_vif *vif,
  163. struct wcn36xx_sta *sta_priv)
  164. {
  165. return NL80211_IFTYPE_STATION == vif->type ?
  166. sta_priv->bss_sta_index :
  167. sta_priv->sta_index;
  168. }
  169. static const char * const wcn36xx_caps_names[] = {
  170. "MCC", /* 0 */
  171. "P2P", /* 1 */
  172. "DOT11AC", /* 2 */
  173. "SLM_SESSIONIZATION", /* 3 */
  174. "DOT11AC_OPMODE", /* 4 */
  175. "SAP32STA", /* 5 */
  176. "TDLS", /* 6 */
  177. "P2P_GO_NOA_DECOUPLE_INIT_SCAN",/* 7 */
  178. "WLANACTIVE_OFFLOAD", /* 8 */
  179. "BEACON_OFFLOAD", /* 9 */
  180. "SCAN_OFFLOAD", /* 10 */
  181. "ROAM_OFFLOAD", /* 11 */
  182. "BCN_MISS_OFFLOAD", /* 12 */
  183. "STA_POWERSAVE", /* 13 */
  184. "STA_ADVANCED_PWRSAVE", /* 14 */
  185. "AP_UAPSD", /* 15 */
  186. "AP_DFS", /* 16 */
  187. "BLOCKACK", /* 17 */
  188. "PHY_ERR", /* 18 */
  189. "BCN_FILTER", /* 19 */
  190. "RTT", /* 20 */
  191. "RATECTRL", /* 21 */
  192. "WOW", /* 22 */
  193. "WLAN_ROAM_SCAN_OFFLOAD", /* 23 */
  194. "SPECULATIVE_PS_POLL", /* 24 */
  195. "SCAN_SCH", /* 25 */
  196. "IBSS_HEARTBEAT_OFFLOAD", /* 26 */
  197. "WLAN_SCAN_OFFLOAD", /* 27 */
  198. "WLAN_PERIODIC_TX_PTRN", /* 28 */
  199. "ADVANCE_TDLS", /* 29 */
  200. "BATCH_SCAN", /* 30 */
  201. "FW_IN_TX_PATH", /* 31 */
  202. "EXTENDED_NSOFFLOAD_SLOT", /* 32 */
  203. "CH_SWITCH_V1", /* 33 */
  204. "HT40_OBSS_SCAN", /* 34 */
  205. "UPDATE_CHANNEL_LIST", /* 35 */
  206. "WLAN_MCADDR_FLT", /* 36 */
  207. "WLAN_CH144", /* 37 */
  208. "NAN", /* 38 */
  209. "TDLS_SCAN_COEXISTENCE", /* 39 */
  210. "LINK_LAYER_STATS_MEAS", /* 40 */
  211. "MU_MIMO", /* 41 */
  212. "EXTENDED_SCAN", /* 42 */
  213. "DYNAMIC_WMM_PS", /* 43 */
  214. "MAC_SPOOFED_SCAN", /* 44 */
  215. "BMU_ERROR_GENERIC_RECOVERY", /* 45 */
  216. "DISA", /* 46 */
  217. "FW_STATS", /* 47 */
  218. "WPS_PRBRSP_TMPL", /* 48 */
  219. "BCN_IE_FLT_DELTA", /* 49 */
  220. "TDLS_OFF_CHANNEL", /* 51 */
  221. "RTT3", /* 52 */
  222. "MGMT_FRAME_LOGGING", /* 53 */
  223. "ENHANCED_TXBD_COMPLETION", /* 54 */
  224. "LOGGING_ENHANCEMENT", /* 55 */
  225. "EXT_SCAN_ENHANCED", /* 56 */
  226. "MEMORY_DUMP_SUPPORTED", /* 57 */
  227. "PER_PKT_STATS_SUPPORTED", /* 58 */
  228. "EXT_LL_STAT", /* 60 */
  229. "WIFI_CONFIG", /* 61 */
  230. "ANTENNA_DIVERSITY_SELECTION", /* 62 */
  231. };
  232. static const char *wcn36xx_get_cap_name(enum place_holder_in_cap_bitmap x)
  233. {
  234. if (x >= ARRAY_SIZE(wcn36xx_caps_names))
  235. return "UNKNOWN";
  236. return wcn36xx_caps_names[x];
  237. }
  238. static void wcn36xx_feat_caps_info(struct wcn36xx *wcn)
  239. {
  240. int i;
  241. for (i = 0; i < MAX_FEATURE_SUPPORTED; i++) {
  242. if (get_feat_caps(wcn->fw_feat_caps, i))
  243. wcn36xx_info("FW Cap %s\n", wcn36xx_get_cap_name(i));
  244. }
  245. }
  246. static int wcn36xx_start(struct ieee80211_hw *hw)
  247. {
  248. struct wcn36xx *wcn = hw->priv;
  249. int ret;
  250. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac start\n");
  251. /* SMD initialization */
  252. ret = wcn36xx_smd_open(wcn);
  253. if (ret) {
  254. wcn36xx_err("Failed to open smd channel: %d\n", ret);
  255. goto out_err;
  256. }
  257. /* Allocate memory pools for Mgmt BD headers and Data BD headers */
  258. ret = wcn36xx_dxe_allocate_mem_pools(wcn);
  259. if (ret) {
  260. wcn36xx_err("Failed to alloc DXE mempool: %d\n", ret);
  261. goto out_smd_close;
  262. }
  263. ret = wcn36xx_dxe_alloc_ctl_blks(wcn);
  264. if (ret) {
  265. wcn36xx_err("Failed to alloc DXE ctl blocks: %d\n", ret);
  266. goto out_free_dxe_pool;
  267. }
  268. wcn->hal_buf = kmalloc(WCN36XX_HAL_BUF_SIZE, GFP_KERNEL);
  269. if (!wcn->hal_buf) {
  270. wcn36xx_err("Failed to allocate smd buf\n");
  271. ret = -ENOMEM;
  272. goto out_free_dxe_ctl;
  273. }
  274. ret = wcn36xx_smd_load_nv(wcn);
  275. if (ret) {
  276. wcn36xx_err("Failed to push NV to chip\n");
  277. goto out_free_smd_buf;
  278. }
  279. ret = wcn36xx_smd_start(wcn);
  280. if (ret) {
  281. wcn36xx_err("Failed to start chip\n");
  282. goto out_free_smd_buf;
  283. }
  284. if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
  285. ret = wcn36xx_smd_feature_caps_exchange(wcn);
  286. if (ret)
  287. wcn36xx_warn("Exchange feature caps failed\n");
  288. else
  289. wcn36xx_feat_caps_info(wcn);
  290. }
  291. /* DMA channel initialization */
  292. ret = wcn36xx_dxe_init(wcn);
  293. if (ret) {
  294. wcn36xx_err("DXE init failed\n");
  295. goto out_smd_stop;
  296. }
  297. wcn36xx_debugfs_init(wcn);
  298. INIT_LIST_HEAD(&wcn->vif_list);
  299. spin_lock_init(&wcn->dxe_lock);
  300. return 0;
  301. out_smd_stop:
  302. wcn36xx_smd_stop(wcn);
  303. out_free_smd_buf:
  304. kfree(wcn->hal_buf);
  305. out_free_dxe_ctl:
  306. wcn36xx_dxe_free_ctl_blks(wcn);
  307. out_free_dxe_pool:
  308. wcn36xx_dxe_free_mem_pools(wcn);
  309. out_smd_close:
  310. wcn36xx_smd_close(wcn);
  311. out_err:
  312. return ret;
  313. }
  314. static void wcn36xx_stop(struct ieee80211_hw *hw)
  315. {
  316. struct wcn36xx *wcn = hw->priv;
  317. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac stop\n");
  318. wcn36xx_debugfs_exit(wcn);
  319. wcn36xx_smd_stop(wcn);
  320. wcn36xx_dxe_deinit(wcn);
  321. wcn36xx_smd_close(wcn);
  322. wcn36xx_dxe_free_mem_pools(wcn);
  323. wcn36xx_dxe_free_ctl_blks(wcn);
  324. kfree(wcn->hal_buf);
  325. }
  326. static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
  327. {
  328. struct wcn36xx *wcn = hw->priv;
  329. struct ieee80211_vif *vif = NULL;
  330. struct wcn36xx_vif *tmp;
  331. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
  332. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  333. int ch = WCN36XX_HW_CHANNEL(wcn);
  334. wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
  335. ch);
  336. list_for_each_entry(tmp, &wcn->vif_list, list) {
  337. vif = wcn36xx_priv_to_vif(tmp);
  338. wcn36xx_smd_switch_channel(wcn, vif, ch);
  339. }
  340. }
  341. return 0;
  342. }
  343. static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
  344. unsigned int changed,
  345. unsigned int *total, u64 multicast)
  346. {
  347. struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
  348. struct wcn36xx *wcn = hw->priv;
  349. struct wcn36xx_vif *tmp;
  350. struct ieee80211_vif *vif = NULL;
  351. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
  352. *total &= FIF_ALLMULTI;
  353. fp = (void *)(unsigned long)multicast;
  354. list_for_each_entry(tmp, &wcn->vif_list, list) {
  355. vif = wcn36xx_priv_to_vif(tmp);
  356. /* FW handles MC filtering only when connected as STA */
  357. if (*total & FIF_ALLMULTI)
  358. wcn36xx_smd_set_mc_list(wcn, vif, NULL);
  359. else if (NL80211_IFTYPE_STATION == vif->type && tmp->sta_assoc)
  360. wcn36xx_smd_set_mc_list(wcn, vif, fp);
  361. }
  362. kfree(fp);
  363. }
  364. static u64 wcn36xx_prepare_multicast(struct ieee80211_hw *hw,
  365. struct netdev_hw_addr_list *mc_list)
  366. {
  367. struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
  368. struct netdev_hw_addr *ha;
  369. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac prepare multicast list\n");
  370. fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
  371. if (!fp) {
  372. wcn36xx_err("Out of memory setting filters.\n");
  373. return 0;
  374. }
  375. fp->mc_addr_count = 0;
  376. /* update multicast filtering parameters */
  377. if (netdev_hw_addr_list_count(mc_list) <=
  378. WCN36XX_HAL_MAX_NUM_MULTICAST_ADDRESS) {
  379. netdev_hw_addr_list_for_each(ha, mc_list) {
  380. memcpy(fp->mc_addr[fp->mc_addr_count],
  381. ha->addr, ETH_ALEN);
  382. fp->mc_addr_count++;
  383. }
  384. }
  385. return (u64)(unsigned long)fp;
  386. }
  387. static void wcn36xx_tx(struct ieee80211_hw *hw,
  388. struct ieee80211_tx_control *control,
  389. struct sk_buff *skb)
  390. {
  391. struct wcn36xx *wcn = hw->priv;
  392. struct wcn36xx_sta *sta_priv = NULL;
  393. if (control->sta)
  394. sta_priv = wcn36xx_sta_to_priv(control->sta);
  395. if (wcn36xx_start_tx(wcn, sta_priv, skb))
  396. ieee80211_free_txskb(wcn->hw, skb);
  397. }
  398. static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  399. struct ieee80211_vif *vif,
  400. struct ieee80211_sta *sta,
  401. struct ieee80211_key_conf *key_conf)
  402. {
  403. struct wcn36xx *wcn = hw->priv;
  404. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  405. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  406. int ret = 0;
  407. u8 key[WLAN_MAX_KEY_LEN];
  408. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n");
  409. wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n",
  410. cmd, key_conf->cipher, key_conf->keyidx,
  411. key_conf->keylen, key_conf->flags);
  412. wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ",
  413. key_conf->key,
  414. key_conf->keylen);
  415. switch (key_conf->cipher) {
  416. case WLAN_CIPHER_SUITE_WEP40:
  417. vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
  418. break;
  419. case WLAN_CIPHER_SUITE_WEP104:
  420. vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
  421. break;
  422. case WLAN_CIPHER_SUITE_CCMP:
  423. vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP;
  424. break;
  425. case WLAN_CIPHER_SUITE_TKIP:
  426. vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP;
  427. break;
  428. default:
  429. wcn36xx_err("Unsupported key type 0x%x\n",
  430. key_conf->cipher);
  431. ret = -EOPNOTSUPP;
  432. goto out;
  433. }
  434. switch (cmd) {
  435. case SET_KEY:
  436. if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) {
  437. /*
  438. * Supplicant is sending key in the wrong order:
  439. * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b)
  440. * but HW expects it to be in the order as described in
  441. * IEEE 802.11 spec (see chapter 11.7) like this:
  442. * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b)
  443. */
  444. memcpy(key, key_conf->key, 16);
  445. memcpy(key + 16, key_conf->key + 24, 8);
  446. memcpy(key + 24, key_conf->key + 16, 8);
  447. } else {
  448. memcpy(key, key_conf->key, key_conf->keylen);
  449. }
  450. if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) {
  451. sta_priv->is_data_encrypted = true;
  452. /* Reconfigure bss with encrypt_type */
  453. if (NL80211_IFTYPE_STATION == vif->type)
  454. wcn36xx_smd_config_bss(wcn,
  455. vif,
  456. sta,
  457. sta->addr,
  458. true);
  459. wcn36xx_smd_set_stakey(wcn,
  460. vif_priv->encrypt_type,
  461. key_conf->keyidx,
  462. key_conf->keylen,
  463. key,
  464. get_sta_index(vif, sta_priv));
  465. } else {
  466. wcn36xx_smd_set_bsskey(wcn,
  467. vif_priv->encrypt_type,
  468. key_conf->keyidx,
  469. key_conf->keylen,
  470. key);
  471. if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) ||
  472. (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) {
  473. sta_priv->is_data_encrypted = true;
  474. wcn36xx_smd_set_stakey(wcn,
  475. vif_priv->encrypt_type,
  476. key_conf->keyidx,
  477. key_conf->keylen,
  478. key,
  479. get_sta_index(vif, sta_priv));
  480. }
  481. }
  482. break;
  483. case DISABLE_KEY:
  484. if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) {
  485. vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
  486. wcn36xx_smd_remove_bsskey(wcn,
  487. vif_priv->encrypt_type,
  488. key_conf->keyidx);
  489. } else {
  490. sta_priv->is_data_encrypted = false;
  491. /* do not remove key if disassociated */
  492. if (sta_priv->aid)
  493. wcn36xx_smd_remove_stakey(wcn,
  494. vif_priv->encrypt_type,
  495. key_conf->keyidx,
  496. get_sta_index(vif, sta_priv));
  497. }
  498. break;
  499. default:
  500. wcn36xx_err("Unsupported key cmd 0x%x\n", cmd);
  501. ret = -EOPNOTSUPP;
  502. goto out;
  503. }
  504. out:
  505. return ret;
  506. }
  507. static void wcn36xx_hw_scan_worker(struct work_struct *work)
  508. {
  509. struct wcn36xx *wcn = container_of(work, struct wcn36xx, scan_work);
  510. struct cfg80211_scan_request *req = wcn->scan_req;
  511. u8 channels[WCN36XX_HAL_PNO_MAX_NETW_CHANNELS_EX];
  512. struct cfg80211_scan_info scan_info = {};
  513. bool aborted = false;
  514. int i;
  515. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 scan %d channels worker\n", req->n_channels);
  516. for (i = 0; i < req->n_channels; i++)
  517. channels[i] = req->channels[i]->hw_value;
  518. wcn36xx_smd_update_scan_params(wcn, channels, req->n_channels);
  519. wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN);
  520. for (i = 0; i < req->n_channels; i++) {
  521. mutex_lock(&wcn->scan_lock);
  522. aborted = wcn->scan_aborted;
  523. mutex_unlock(&wcn->scan_lock);
  524. if (aborted)
  525. break;
  526. wcn->scan_freq = req->channels[i]->center_freq;
  527. wcn->scan_band = req->channels[i]->band;
  528. wcn36xx_smd_start_scan(wcn, req->channels[i]->hw_value);
  529. msleep(30);
  530. wcn36xx_smd_end_scan(wcn, req->channels[i]->hw_value);
  531. wcn->scan_freq = 0;
  532. }
  533. wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN);
  534. scan_info.aborted = aborted;
  535. ieee80211_scan_completed(wcn->hw, &scan_info);
  536. mutex_lock(&wcn->scan_lock);
  537. wcn->scan_req = NULL;
  538. mutex_unlock(&wcn->scan_lock);
  539. }
  540. static int wcn36xx_hw_scan(struct ieee80211_hw *hw,
  541. struct ieee80211_vif *vif,
  542. struct ieee80211_scan_request *hw_req)
  543. {
  544. struct wcn36xx *wcn = hw->priv;
  545. mutex_lock(&wcn->scan_lock);
  546. if (wcn->scan_req) {
  547. mutex_unlock(&wcn->scan_lock);
  548. return -EBUSY;
  549. }
  550. wcn->scan_aborted = false;
  551. wcn->scan_req = &hw_req->req;
  552. mutex_unlock(&wcn->scan_lock);
  553. schedule_work(&wcn->scan_work);
  554. return 0;
  555. }
  556. static void wcn36xx_cancel_hw_scan(struct ieee80211_hw *hw,
  557. struct ieee80211_vif *vif)
  558. {
  559. struct wcn36xx *wcn = hw->priv;
  560. mutex_lock(&wcn->scan_lock);
  561. wcn->scan_aborted = true;
  562. mutex_unlock(&wcn->scan_lock);
  563. cancel_work_sync(&wcn->scan_work);
  564. }
  565. static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta,
  566. enum nl80211_band band)
  567. {
  568. int i, size;
  569. u16 *rates_table;
  570. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  571. u32 rates = sta->supp_rates[band];
  572. memset(&sta_priv->supported_rates, 0,
  573. sizeof(sta_priv->supported_rates));
  574. sta_priv->supported_rates.op_rate_mode = STA_11n;
  575. size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates);
  576. rates_table = sta_priv->supported_rates.dsss_rates;
  577. if (band == NL80211_BAND_2GHZ) {
  578. for (i = 0; i < size; i++) {
  579. if (rates & 0x01) {
  580. rates_table[i] = wcn_2ghz_rates[i].hw_value;
  581. rates = rates >> 1;
  582. }
  583. }
  584. }
  585. size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates);
  586. rates_table = sta_priv->supported_rates.ofdm_rates;
  587. for (i = 0; i < size; i++) {
  588. if (rates & 0x01) {
  589. rates_table[i] = wcn_5ghz_rates[i].hw_value;
  590. rates = rates >> 1;
  591. }
  592. }
  593. if (sta->ht_cap.ht_supported) {
  594. BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) >
  595. sizeof(sta_priv->supported_rates.supported_mcs_set));
  596. memcpy(sta_priv->supported_rates.supported_mcs_set,
  597. sta->ht_cap.mcs.rx_mask,
  598. sizeof(sta->ht_cap.mcs.rx_mask));
  599. }
  600. }
  601. void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates)
  602. {
  603. u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = {
  604. HW_RATE_INDEX_6MBPS,
  605. HW_RATE_INDEX_9MBPS,
  606. HW_RATE_INDEX_12MBPS,
  607. HW_RATE_INDEX_18MBPS,
  608. HW_RATE_INDEX_24MBPS,
  609. HW_RATE_INDEX_36MBPS,
  610. HW_RATE_INDEX_48MBPS,
  611. HW_RATE_INDEX_54MBPS
  612. };
  613. u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = {
  614. HW_RATE_INDEX_1MBPS,
  615. HW_RATE_INDEX_2MBPS,
  616. HW_RATE_INDEX_5_5MBPS,
  617. HW_RATE_INDEX_11MBPS
  618. };
  619. rates->op_rate_mode = STA_11n;
  620. memcpy(rates->dsss_rates, dsss_rates,
  621. sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES);
  622. memcpy(rates->ofdm_rates, ofdm_rates,
  623. sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES);
  624. rates->supported_mcs_set[0] = 0xFF;
  625. }
  626. static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
  627. struct ieee80211_vif *vif,
  628. struct ieee80211_bss_conf *bss_conf,
  629. u32 changed)
  630. {
  631. struct wcn36xx *wcn = hw->priv;
  632. struct sk_buff *skb = NULL;
  633. u16 tim_off, tim_len;
  634. enum wcn36xx_hal_link_state link_state;
  635. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  636. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
  637. vif, changed);
  638. if (changed & BSS_CHANGED_BEACON_INFO) {
  639. wcn36xx_dbg(WCN36XX_DBG_MAC,
  640. "mac bss changed dtim period %d\n",
  641. bss_conf->dtim_period);
  642. vif_priv->dtim_period = bss_conf->dtim_period;
  643. }
  644. if (changed & BSS_CHANGED_PS) {
  645. wcn36xx_dbg(WCN36XX_DBG_MAC,
  646. "mac bss PS set %d\n",
  647. bss_conf->ps);
  648. if (bss_conf->ps) {
  649. wcn36xx_pmc_enter_bmps_state(wcn, vif);
  650. } else {
  651. wcn36xx_pmc_exit_bmps_state(wcn, vif);
  652. }
  653. }
  654. if (changed & BSS_CHANGED_BSSID) {
  655. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n",
  656. bss_conf->bssid);
  657. if (!is_zero_ether_addr(bss_conf->bssid)) {
  658. vif_priv->is_joining = true;
  659. vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
  660. wcn36xx_smd_join(wcn, bss_conf->bssid,
  661. vif->addr, WCN36XX_HW_CHANNEL(wcn));
  662. wcn36xx_smd_config_bss(wcn, vif, NULL,
  663. bss_conf->bssid, false);
  664. } else {
  665. vif_priv->is_joining = false;
  666. wcn36xx_smd_delete_bss(wcn, vif);
  667. vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
  668. }
  669. }
  670. if (changed & BSS_CHANGED_SSID) {
  671. wcn36xx_dbg(WCN36XX_DBG_MAC,
  672. "mac bss changed ssid\n");
  673. wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ",
  674. bss_conf->ssid, bss_conf->ssid_len);
  675. vif_priv->ssid.length = bss_conf->ssid_len;
  676. memcpy(&vif_priv->ssid.ssid,
  677. bss_conf->ssid,
  678. bss_conf->ssid_len);
  679. }
  680. if (changed & BSS_CHANGED_ASSOC) {
  681. vif_priv->is_joining = false;
  682. if (bss_conf->assoc) {
  683. struct ieee80211_sta *sta;
  684. struct wcn36xx_sta *sta_priv;
  685. wcn36xx_dbg(WCN36XX_DBG_MAC,
  686. "mac assoc bss %pM vif %pM AID=%d\n",
  687. bss_conf->bssid,
  688. vif->addr,
  689. bss_conf->aid);
  690. vif_priv->sta_assoc = true;
  691. rcu_read_lock();
  692. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  693. if (!sta) {
  694. wcn36xx_err("sta %pM is not found\n",
  695. bss_conf->bssid);
  696. rcu_read_unlock();
  697. goto out;
  698. }
  699. sta_priv = wcn36xx_sta_to_priv(sta);
  700. wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
  701. wcn36xx_smd_set_link_st(wcn, bss_conf->bssid,
  702. vif->addr,
  703. WCN36XX_HAL_LINK_POSTASSOC_STATE);
  704. wcn36xx_smd_config_bss(wcn, vif, sta,
  705. bss_conf->bssid,
  706. true);
  707. sta_priv->aid = bss_conf->aid;
  708. /*
  709. * config_sta must be called from because this is the
  710. * place where AID is available.
  711. */
  712. wcn36xx_smd_config_sta(wcn, vif, sta);
  713. rcu_read_unlock();
  714. } else {
  715. wcn36xx_dbg(WCN36XX_DBG_MAC,
  716. "disassociated bss %pM vif %pM AID=%d\n",
  717. bss_conf->bssid,
  718. vif->addr,
  719. bss_conf->aid);
  720. vif_priv->sta_assoc = false;
  721. wcn36xx_smd_set_link_st(wcn,
  722. bss_conf->bssid,
  723. vif->addr,
  724. WCN36XX_HAL_LINK_IDLE_STATE);
  725. }
  726. }
  727. if (changed & BSS_CHANGED_AP_PROBE_RESP) {
  728. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n");
  729. skb = ieee80211_proberesp_get(hw, vif);
  730. if (!skb) {
  731. wcn36xx_err("failed to alloc probereq skb\n");
  732. goto out;
  733. }
  734. wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb);
  735. dev_kfree_skb(skb);
  736. }
  737. if (changed & BSS_CHANGED_BEACON_ENABLED ||
  738. changed & BSS_CHANGED_BEACON) {
  739. wcn36xx_dbg(WCN36XX_DBG_MAC,
  740. "mac bss changed beacon enabled %d\n",
  741. bss_conf->enable_beacon);
  742. if (bss_conf->enable_beacon) {
  743. vif_priv->dtim_period = bss_conf->dtim_period;
  744. vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
  745. wcn36xx_smd_config_bss(wcn, vif, NULL,
  746. vif->addr, false);
  747. skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
  748. &tim_len);
  749. if (!skb) {
  750. wcn36xx_err("failed to alloc beacon skb\n");
  751. goto out;
  752. }
  753. wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
  754. dev_kfree_skb(skb);
  755. if (vif->type == NL80211_IFTYPE_ADHOC ||
  756. vif->type == NL80211_IFTYPE_MESH_POINT)
  757. link_state = WCN36XX_HAL_LINK_IBSS_STATE;
  758. else
  759. link_state = WCN36XX_HAL_LINK_AP_STATE;
  760. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  761. link_state);
  762. } else {
  763. wcn36xx_smd_delete_bss(wcn, vif);
  764. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  765. WCN36XX_HAL_LINK_IDLE_STATE);
  766. }
  767. }
  768. out:
  769. return;
  770. }
  771. /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
  772. static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  773. {
  774. struct wcn36xx *wcn = hw->priv;
  775. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
  776. wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
  777. return 0;
  778. }
  779. static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
  780. struct ieee80211_vif *vif)
  781. {
  782. struct wcn36xx *wcn = hw->priv;
  783. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  784. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
  785. list_del(&vif_priv->list);
  786. wcn36xx_smd_delete_sta_self(wcn, vif->addr);
  787. }
  788. static int wcn36xx_add_interface(struct ieee80211_hw *hw,
  789. struct ieee80211_vif *vif)
  790. {
  791. struct wcn36xx *wcn = hw->priv;
  792. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  793. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
  794. vif, vif->type);
  795. if (!(NL80211_IFTYPE_STATION == vif->type ||
  796. NL80211_IFTYPE_AP == vif->type ||
  797. NL80211_IFTYPE_ADHOC == vif->type ||
  798. NL80211_IFTYPE_MESH_POINT == vif->type)) {
  799. wcn36xx_warn("Unsupported interface type requested: %d\n",
  800. vif->type);
  801. return -EOPNOTSUPP;
  802. }
  803. list_add(&vif_priv->list, &wcn->vif_list);
  804. wcn36xx_smd_add_sta_self(wcn, vif);
  805. return 0;
  806. }
  807. static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  808. struct ieee80211_sta *sta)
  809. {
  810. struct wcn36xx *wcn = hw->priv;
  811. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  812. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  813. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
  814. vif, sta->addr);
  815. spin_lock_init(&sta_priv->ampdu_lock);
  816. sta_priv->vif = vif_priv;
  817. /*
  818. * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
  819. * at this stage AID is not available yet.
  820. */
  821. if (NL80211_IFTYPE_STATION != vif->type) {
  822. wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
  823. sta_priv->aid = sta->aid;
  824. wcn36xx_smd_config_sta(wcn, vif, sta);
  825. }
  826. return 0;
  827. }
  828. static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
  829. struct ieee80211_vif *vif,
  830. struct ieee80211_sta *sta)
  831. {
  832. struct wcn36xx *wcn = hw->priv;
  833. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  834. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
  835. vif, sta->addr, sta_priv->sta_index);
  836. wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
  837. sta_priv->vif = NULL;
  838. return 0;
  839. }
  840. #ifdef CONFIG_PM
  841. static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
  842. {
  843. struct wcn36xx *wcn = hw->priv;
  844. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
  845. flush_workqueue(wcn->hal_ind_wq);
  846. wcn36xx_smd_set_power_params(wcn, true);
  847. return 0;
  848. }
  849. static int wcn36xx_resume(struct ieee80211_hw *hw)
  850. {
  851. struct wcn36xx *wcn = hw->priv;
  852. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
  853. flush_workqueue(wcn->hal_ind_wq);
  854. wcn36xx_smd_set_power_params(wcn, false);
  855. return 0;
  856. }
  857. #endif
  858. static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
  859. struct ieee80211_vif *vif,
  860. struct ieee80211_ampdu_params *params)
  861. {
  862. struct wcn36xx *wcn = hw->priv;
  863. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(params->sta);
  864. struct ieee80211_sta *sta = params->sta;
  865. enum ieee80211_ampdu_mlme_action action = params->action;
  866. u16 tid = params->tid;
  867. u16 *ssn = &params->ssn;
  868. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
  869. action, tid);
  870. switch (action) {
  871. case IEEE80211_AMPDU_RX_START:
  872. sta_priv->tid = tid;
  873. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
  874. get_sta_index(vif, sta_priv));
  875. wcn36xx_smd_add_ba(wcn);
  876. wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv));
  877. break;
  878. case IEEE80211_AMPDU_RX_STOP:
  879. wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
  880. break;
  881. case IEEE80211_AMPDU_TX_START:
  882. spin_lock_bh(&sta_priv->ampdu_lock);
  883. sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START;
  884. spin_unlock_bh(&sta_priv->ampdu_lock);
  885. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  886. break;
  887. case IEEE80211_AMPDU_TX_OPERATIONAL:
  888. spin_lock_bh(&sta_priv->ampdu_lock);
  889. sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_OPERATIONAL;
  890. spin_unlock_bh(&sta_priv->ampdu_lock);
  891. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
  892. get_sta_index(vif, sta_priv));
  893. break;
  894. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  895. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  896. case IEEE80211_AMPDU_TX_STOP_CONT:
  897. spin_lock_bh(&sta_priv->ampdu_lock);
  898. sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_NONE;
  899. spin_unlock_bh(&sta_priv->ampdu_lock);
  900. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  901. break;
  902. default:
  903. wcn36xx_err("Unknown AMPDU action\n");
  904. }
  905. return 0;
  906. }
  907. static const struct ieee80211_ops wcn36xx_ops = {
  908. .start = wcn36xx_start,
  909. .stop = wcn36xx_stop,
  910. .add_interface = wcn36xx_add_interface,
  911. .remove_interface = wcn36xx_remove_interface,
  912. #ifdef CONFIG_PM
  913. .suspend = wcn36xx_suspend,
  914. .resume = wcn36xx_resume,
  915. #endif
  916. .config = wcn36xx_config,
  917. .prepare_multicast = wcn36xx_prepare_multicast,
  918. .configure_filter = wcn36xx_configure_filter,
  919. .tx = wcn36xx_tx,
  920. .set_key = wcn36xx_set_key,
  921. .hw_scan = wcn36xx_hw_scan,
  922. .cancel_hw_scan = wcn36xx_cancel_hw_scan,
  923. .bss_info_changed = wcn36xx_bss_info_changed,
  924. .set_rts_threshold = wcn36xx_set_rts_threshold,
  925. .sta_add = wcn36xx_sta_add,
  926. .sta_remove = wcn36xx_sta_remove,
  927. .ampdu_action = wcn36xx_ampdu_action,
  928. };
  929. static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
  930. {
  931. int ret = 0;
  932. static const u32 cipher_suites[] = {
  933. WLAN_CIPHER_SUITE_WEP40,
  934. WLAN_CIPHER_SUITE_WEP104,
  935. WLAN_CIPHER_SUITE_TKIP,
  936. WLAN_CIPHER_SUITE_CCMP,
  937. };
  938. ieee80211_hw_set(wcn->hw, TIMING_BEACON_ONLY);
  939. ieee80211_hw_set(wcn->hw, AMPDU_AGGREGATION);
  940. ieee80211_hw_set(wcn->hw, CONNECTION_MONITOR);
  941. ieee80211_hw_set(wcn->hw, SUPPORTS_PS);
  942. ieee80211_hw_set(wcn->hw, SIGNAL_DBM);
  943. ieee80211_hw_set(wcn->hw, HAS_RATE_CONTROL);
  944. ieee80211_hw_set(wcn->hw, SINGLE_SCAN_ON_ALL_BANDS);
  945. wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  946. BIT(NL80211_IFTYPE_AP) |
  947. BIT(NL80211_IFTYPE_ADHOC) |
  948. BIT(NL80211_IFTYPE_MESH_POINT);
  949. wcn->hw->wiphy->bands[NL80211_BAND_2GHZ] = &wcn_band_2ghz;
  950. wcn->hw->wiphy->bands[NL80211_BAND_5GHZ] = &wcn_band_5ghz;
  951. wcn->hw->wiphy->max_scan_ssids = WCN36XX_MAX_SCAN_SSIDS;
  952. wcn->hw->wiphy->max_scan_ie_len = WCN36XX_MAX_SCAN_IE_LEN;
  953. wcn->hw->wiphy->cipher_suites = cipher_suites;
  954. wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  955. wcn->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  956. #ifdef CONFIG_PM
  957. wcn->hw->wiphy->wowlan = &wowlan_support;
  958. #endif
  959. wcn->hw->max_listen_interval = 200;
  960. wcn->hw->queues = 4;
  961. SET_IEEE80211_DEV(wcn->hw, wcn->dev);
  962. wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
  963. wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
  964. wiphy_ext_feature_set(wcn->hw->wiphy,
  965. NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  966. return ret;
  967. }
  968. static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
  969. struct platform_device *pdev)
  970. {
  971. struct device_node *mmio_node;
  972. struct resource *res;
  973. int index;
  974. int ret;
  975. /* Set TX IRQ */
  976. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "tx");
  977. if (!res) {
  978. wcn36xx_err("failed to get tx_irq\n");
  979. return -ENOENT;
  980. }
  981. wcn->tx_irq = res->start;
  982. /* Set RX IRQ */
  983. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "rx");
  984. if (!res) {
  985. wcn36xx_err("failed to get rx_irq\n");
  986. return -ENOENT;
  987. }
  988. wcn->rx_irq = res->start;
  989. /* Acquire SMSM tx enable handle */
  990. wcn->tx_enable_state = qcom_smem_state_get(&pdev->dev,
  991. "tx-enable", &wcn->tx_enable_state_bit);
  992. if (IS_ERR(wcn->tx_enable_state)) {
  993. wcn36xx_err("failed to get tx-enable state\n");
  994. return PTR_ERR(wcn->tx_enable_state);
  995. }
  996. /* Acquire SMSM tx rings empty handle */
  997. wcn->tx_rings_empty_state = qcom_smem_state_get(&pdev->dev,
  998. "tx-rings-empty", &wcn->tx_rings_empty_state_bit);
  999. if (IS_ERR(wcn->tx_rings_empty_state)) {
  1000. wcn36xx_err("failed to get tx-rings-empty state\n");
  1001. return PTR_ERR(wcn->tx_rings_empty_state);
  1002. }
  1003. mmio_node = of_parse_phandle(pdev->dev.parent->of_node, "qcom,mmio", 0);
  1004. if (!mmio_node) {
  1005. wcn36xx_err("failed to acquire qcom,mmio reference\n");
  1006. return -EINVAL;
  1007. }
  1008. wcn->is_pronto = !!of_device_is_compatible(mmio_node, "qcom,pronto");
  1009. /* Map the CCU memory */
  1010. index = of_property_match_string(mmio_node, "reg-names", "ccu");
  1011. wcn->ccu_base = of_iomap(mmio_node, index);
  1012. if (!wcn->ccu_base) {
  1013. wcn36xx_err("failed to map ccu memory\n");
  1014. ret = -ENOMEM;
  1015. goto put_mmio_node;
  1016. }
  1017. /* Map the DXE memory */
  1018. index = of_property_match_string(mmio_node, "reg-names", "dxe");
  1019. wcn->dxe_base = of_iomap(mmio_node, index);
  1020. if (!wcn->dxe_base) {
  1021. wcn36xx_err("failed to map dxe memory\n");
  1022. ret = -ENOMEM;
  1023. goto unmap_ccu;
  1024. }
  1025. of_node_put(mmio_node);
  1026. return 0;
  1027. unmap_ccu:
  1028. iounmap(wcn->ccu_base);
  1029. put_mmio_node:
  1030. of_node_put(mmio_node);
  1031. return ret;
  1032. }
  1033. static int wcn36xx_probe(struct platform_device *pdev)
  1034. {
  1035. struct ieee80211_hw *hw;
  1036. struct wcn36xx *wcn;
  1037. void *wcnss;
  1038. int ret;
  1039. const u8 *addr;
  1040. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
  1041. wcnss = dev_get_drvdata(pdev->dev.parent);
  1042. hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
  1043. if (!hw) {
  1044. wcn36xx_err("failed to alloc hw\n");
  1045. ret = -ENOMEM;
  1046. goto out_err;
  1047. }
  1048. platform_set_drvdata(pdev, hw);
  1049. wcn = hw->priv;
  1050. wcn->hw = hw;
  1051. wcn->dev = &pdev->dev;
  1052. mutex_init(&wcn->hal_mutex);
  1053. mutex_init(&wcn->scan_lock);
  1054. INIT_WORK(&wcn->scan_work, wcn36xx_hw_scan_worker);
  1055. wcn->smd_channel = qcom_wcnss_open_channel(wcnss, "WLAN_CTRL", wcn36xx_smd_rsp_process, hw);
  1056. if (IS_ERR(wcn->smd_channel)) {
  1057. wcn36xx_err("failed to open WLAN_CTRL channel\n");
  1058. ret = PTR_ERR(wcn->smd_channel);
  1059. goto out_wq;
  1060. }
  1061. addr = of_get_property(pdev->dev.of_node, "local-mac-address", &ret);
  1062. if (addr && ret != ETH_ALEN) {
  1063. wcn36xx_err("invalid local-mac-address\n");
  1064. ret = -EINVAL;
  1065. goto out_wq;
  1066. } else if (addr) {
  1067. wcn36xx_info("mac address: %pM\n", addr);
  1068. SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
  1069. }
  1070. ret = wcn36xx_platform_get_resources(wcn, pdev);
  1071. if (ret)
  1072. goto out_wq;
  1073. wcn36xx_init_ieee80211(wcn);
  1074. ret = ieee80211_register_hw(wcn->hw);
  1075. if (ret)
  1076. goto out_unmap;
  1077. return 0;
  1078. out_unmap:
  1079. iounmap(wcn->ccu_base);
  1080. iounmap(wcn->dxe_base);
  1081. out_wq:
  1082. ieee80211_free_hw(hw);
  1083. out_err:
  1084. return ret;
  1085. }
  1086. static int wcn36xx_remove(struct platform_device *pdev)
  1087. {
  1088. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  1089. struct wcn36xx *wcn = hw->priv;
  1090. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
  1091. release_firmware(wcn->nv);
  1092. ieee80211_unregister_hw(hw);
  1093. qcom_smem_state_put(wcn->tx_enable_state);
  1094. qcom_smem_state_put(wcn->tx_rings_empty_state);
  1095. iounmap(wcn->dxe_base);
  1096. iounmap(wcn->ccu_base);
  1097. mutex_destroy(&wcn->hal_mutex);
  1098. ieee80211_free_hw(hw);
  1099. return 0;
  1100. }
  1101. static const struct of_device_id wcn36xx_of_match[] = {
  1102. { .compatible = "qcom,wcnss-wlan" },
  1103. {}
  1104. };
  1105. MODULE_DEVICE_TABLE(of, wcn36xx_of_match);
  1106. static struct platform_driver wcn36xx_driver = {
  1107. .probe = wcn36xx_probe,
  1108. .remove = wcn36xx_remove,
  1109. .driver = {
  1110. .name = "wcn36xx",
  1111. .of_match_table = wcn36xx_of_match,
  1112. },
  1113. };
  1114. module_platform_driver(wcn36xx_driver);
  1115. MODULE_LICENSE("Dual BSD/GPL");
  1116. MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
  1117. MODULE_FIRMWARE(WLAN_NV_FILE);