main.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  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_dbg(WCN36XX_DBG_MAC, "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. mutex_lock(&wcn->conf_mutex);
  333. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  334. int ch = WCN36XX_HW_CHANNEL(wcn);
  335. wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
  336. ch);
  337. list_for_each_entry(tmp, &wcn->vif_list, list) {
  338. vif = wcn36xx_priv_to_vif(tmp);
  339. wcn36xx_smd_switch_channel(wcn, vif, ch);
  340. }
  341. }
  342. if (changed & IEEE80211_CONF_CHANGE_PS) {
  343. list_for_each_entry(tmp, &wcn->vif_list, list) {
  344. vif = wcn36xx_priv_to_vif(tmp);
  345. if (hw->conf.flags & IEEE80211_CONF_PS) {
  346. if (vif->bss_conf.ps) /* ps allowed ? */
  347. wcn36xx_pmc_enter_bmps_state(wcn, vif);
  348. } else {
  349. wcn36xx_pmc_exit_bmps_state(wcn, vif);
  350. }
  351. }
  352. }
  353. mutex_unlock(&wcn->conf_mutex);
  354. return 0;
  355. }
  356. static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
  357. unsigned int changed,
  358. unsigned int *total, u64 multicast)
  359. {
  360. struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
  361. struct wcn36xx *wcn = hw->priv;
  362. struct wcn36xx_vif *tmp;
  363. struct ieee80211_vif *vif = NULL;
  364. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
  365. mutex_lock(&wcn->conf_mutex);
  366. *total &= FIF_ALLMULTI;
  367. fp = (void *)(unsigned long)multicast;
  368. list_for_each_entry(tmp, &wcn->vif_list, list) {
  369. vif = wcn36xx_priv_to_vif(tmp);
  370. /* FW handles MC filtering only when connected as STA */
  371. if (*total & FIF_ALLMULTI)
  372. wcn36xx_smd_set_mc_list(wcn, vif, NULL);
  373. else if (NL80211_IFTYPE_STATION == vif->type && tmp->sta_assoc)
  374. wcn36xx_smd_set_mc_list(wcn, vif, fp);
  375. }
  376. mutex_unlock(&wcn->conf_mutex);
  377. kfree(fp);
  378. }
  379. static u64 wcn36xx_prepare_multicast(struct ieee80211_hw *hw,
  380. struct netdev_hw_addr_list *mc_list)
  381. {
  382. struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
  383. struct netdev_hw_addr *ha;
  384. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac prepare multicast list\n");
  385. fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
  386. if (!fp) {
  387. wcn36xx_err("Out of memory setting filters.\n");
  388. return 0;
  389. }
  390. fp->mc_addr_count = 0;
  391. /* update multicast filtering parameters */
  392. if (netdev_hw_addr_list_count(mc_list) <=
  393. WCN36XX_HAL_MAX_NUM_MULTICAST_ADDRESS) {
  394. netdev_hw_addr_list_for_each(ha, mc_list) {
  395. memcpy(fp->mc_addr[fp->mc_addr_count],
  396. ha->addr, ETH_ALEN);
  397. fp->mc_addr_count++;
  398. }
  399. }
  400. return (u64)(unsigned long)fp;
  401. }
  402. static void wcn36xx_tx(struct ieee80211_hw *hw,
  403. struct ieee80211_tx_control *control,
  404. struct sk_buff *skb)
  405. {
  406. struct wcn36xx *wcn = hw->priv;
  407. struct wcn36xx_sta *sta_priv = NULL;
  408. if (control->sta)
  409. sta_priv = wcn36xx_sta_to_priv(control->sta);
  410. if (wcn36xx_start_tx(wcn, sta_priv, skb))
  411. ieee80211_free_txskb(wcn->hw, skb);
  412. }
  413. static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  414. struct ieee80211_vif *vif,
  415. struct ieee80211_sta *sta,
  416. struct ieee80211_key_conf *key_conf)
  417. {
  418. struct wcn36xx *wcn = hw->priv;
  419. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  420. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  421. int ret = 0;
  422. u8 key[WLAN_MAX_KEY_LEN];
  423. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n");
  424. wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n",
  425. cmd, key_conf->cipher, key_conf->keyidx,
  426. key_conf->keylen, key_conf->flags);
  427. wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ",
  428. key_conf->key,
  429. key_conf->keylen);
  430. mutex_lock(&wcn->conf_mutex);
  431. switch (key_conf->cipher) {
  432. case WLAN_CIPHER_SUITE_WEP40:
  433. vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
  434. break;
  435. case WLAN_CIPHER_SUITE_WEP104:
  436. vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
  437. break;
  438. case WLAN_CIPHER_SUITE_CCMP:
  439. vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP;
  440. break;
  441. case WLAN_CIPHER_SUITE_TKIP:
  442. vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP;
  443. break;
  444. default:
  445. wcn36xx_err("Unsupported key type 0x%x\n",
  446. key_conf->cipher);
  447. ret = -EOPNOTSUPP;
  448. goto out;
  449. }
  450. switch (cmd) {
  451. case SET_KEY:
  452. if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) {
  453. /*
  454. * Supplicant is sending key in the wrong order:
  455. * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b)
  456. * but HW expects it to be in the order as described in
  457. * IEEE 802.11 spec (see chapter 11.7) like this:
  458. * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b)
  459. */
  460. memcpy(key, key_conf->key, 16);
  461. memcpy(key + 16, key_conf->key + 24, 8);
  462. memcpy(key + 24, key_conf->key + 16, 8);
  463. } else {
  464. memcpy(key, key_conf->key, key_conf->keylen);
  465. }
  466. if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) {
  467. sta_priv->is_data_encrypted = true;
  468. /* Reconfigure bss with encrypt_type */
  469. if (NL80211_IFTYPE_STATION == vif->type)
  470. wcn36xx_smd_config_bss(wcn,
  471. vif,
  472. sta,
  473. sta->addr,
  474. true);
  475. wcn36xx_smd_set_stakey(wcn,
  476. vif_priv->encrypt_type,
  477. key_conf->keyidx,
  478. key_conf->keylen,
  479. key,
  480. get_sta_index(vif, sta_priv));
  481. } else {
  482. wcn36xx_smd_set_bsskey(wcn,
  483. vif_priv->encrypt_type,
  484. key_conf->keyidx,
  485. key_conf->keylen,
  486. key);
  487. if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) ||
  488. (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) {
  489. sta_priv->is_data_encrypted = true;
  490. wcn36xx_smd_set_stakey(wcn,
  491. vif_priv->encrypt_type,
  492. key_conf->keyidx,
  493. key_conf->keylen,
  494. key,
  495. get_sta_index(vif, sta_priv));
  496. }
  497. }
  498. break;
  499. case DISABLE_KEY:
  500. if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) {
  501. vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
  502. wcn36xx_smd_remove_bsskey(wcn,
  503. vif_priv->encrypt_type,
  504. key_conf->keyidx);
  505. } else {
  506. sta_priv->is_data_encrypted = false;
  507. /* do not remove key if disassociated */
  508. if (sta_priv->aid)
  509. wcn36xx_smd_remove_stakey(wcn,
  510. vif_priv->encrypt_type,
  511. key_conf->keyidx,
  512. get_sta_index(vif, sta_priv));
  513. }
  514. break;
  515. default:
  516. wcn36xx_err("Unsupported key cmd 0x%x\n", cmd);
  517. ret = -EOPNOTSUPP;
  518. goto out;
  519. }
  520. out:
  521. mutex_unlock(&wcn->conf_mutex);
  522. return ret;
  523. }
  524. static void wcn36xx_hw_scan_worker(struct work_struct *work)
  525. {
  526. struct wcn36xx *wcn = container_of(work, struct wcn36xx, scan_work);
  527. struct cfg80211_scan_request *req = wcn->scan_req;
  528. u8 channels[WCN36XX_HAL_PNO_MAX_NETW_CHANNELS_EX];
  529. struct cfg80211_scan_info scan_info = {};
  530. bool aborted = false;
  531. int i;
  532. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 scan %d channels worker\n", req->n_channels);
  533. for (i = 0; i < req->n_channels; i++)
  534. channels[i] = req->channels[i]->hw_value;
  535. wcn36xx_smd_update_scan_params(wcn, channels, req->n_channels);
  536. wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN);
  537. for (i = 0; i < req->n_channels; i++) {
  538. mutex_lock(&wcn->scan_lock);
  539. aborted = wcn->scan_aborted;
  540. mutex_unlock(&wcn->scan_lock);
  541. if (aborted)
  542. break;
  543. wcn->scan_freq = req->channels[i]->center_freq;
  544. wcn->scan_band = req->channels[i]->band;
  545. wcn36xx_smd_start_scan(wcn, req->channels[i]->hw_value);
  546. msleep(30);
  547. wcn36xx_smd_end_scan(wcn, req->channels[i]->hw_value);
  548. wcn->scan_freq = 0;
  549. }
  550. wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN);
  551. scan_info.aborted = aborted;
  552. ieee80211_scan_completed(wcn->hw, &scan_info);
  553. mutex_lock(&wcn->scan_lock);
  554. wcn->scan_req = NULL;
  555. mutex_unlock(&wcn->scan_lock);
  556. }
  557. static int wcn36xx_hw_scan(struct ieee80211_hw *hw,
  558. struct ieee80211_vif *vif,
  559. struct ieee80211_scan_request *hw_req)
  560. {
  561. struct wcn36xx *wcn = hw->priv;
  562. mutex_lock(&wcn->scan_lock);
  563. if (wcn->scan_req) {
  564. mutex_unlock(&wcn->scan_lock);
  565. return -EBUSY;
  566. }
  567. wcn->scan_aborted = false;
  568. wcn->scan_req = &hw_req->req;
  569. mutex_unlock(&wcn->scan_lock);
  570. if (!get_feat_caps(wcn->fw_feat_caps, SCAN_OFFLOAD)) {
  571. /* legacy manual/sw scan */
  572. schedule_work(&wcn->scan_work);
  573. return 0;
  574. }
  575. return wcn36xx_smd_start_hw_scan(wcn, vif, &hw_req->req);
  576. }
  577. static void wcn36xx_cancel_hw_scan(struct ieee80211_hw *hw,
  578. struct ieee80211_vif *vif)
  579. {
  580. struct wcn36xx *wcn = hw->priv;
  581. mutex_lock(&wcn->scan_lock);
  582. wcn->scan_aborted = true;
  583. mutex_unlock(&wcn->scan_lock);
  584. /* ieee80211_scan_completed will be called on FW scan indication */
  585. wcn36xx_smd_stop_hw_scan(wcn);
  586. cancel_work_sync(&wcn->scan_work);
  587. }
  588. static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta,
  589. enum nl80211_band band)
  590. {
  591. int i, size;
  592. u16 *rates_table;
  593. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  594. u32 rates = sta->supp_rates[band];
  595. memset(&sta_priv->supported_rates, 0,
  596. sizeof(sta_priv->supported_rates));
  597. sta_priv->supported_rates.op_rate_mode = STA_11n;
  598. size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates);
  599. rates_table = sta_priv->supported_rates.dsss_rates;
  600. if (band == NL80211_BAND_2GHZ) {
  601. for (i = 0; i < size; i++) {
  602. if (rates & 0x01) {
  603. rates_table[i] = wcn_2ghz_rates[i].hw_value;
  604. rates = rates >> 1;
  605. }
  606. }
  607. }
  608. size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates);
  609. rates_table = sta_priv->supported_rates.ofdm_rates;
  610. for (i = 0; i < size; i++) {
  611. if (rates & 0x01) {
  612. rates_table[i] = wcn_5ghz_rates[i].hw_value;
  613. rates = rates >> 1;
  614. }
  615. }
  616. if (sta->ht_cap.ht_supported) {
  617. BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) >
  618. sizeof(sta_priv->supported_rates.supported_mcs_set));
  619. memcpy(sta_priv->supported_rates.supported_mcs_set,
  620. sta->ht_cap.mcs.rx_mask,
  621. sizeof(sta->ht_cap.mcs.rx_mask));
  622. }
  623. }
  624. void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates)
  625. {
  626. u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = {
  627. HW_RATE_INDEX_6MBPS,
  628. HW_RATE_INDEX_9MBPS,
  629. HW_RATE_INDEX_12MBPS,
  630. HW_RATE_INDEX_18MBPS,
  631. HW_RATE_INDEX_24MBPS,
  632. HW_RATE_INDEX_36MBPS,
  633. HW_RATE_INDEX_48MBPS,
  634. HW_RATE_INDEX_54MBPS
  635. };
  636. u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = {
  637. HW_RATE_INDEX_1MBPS,
  638. HW_RATE_INDEX_2MBPS,
  639. HW_RATE_INDEX_5_5MBPS,
  640. HW_RATE_INDEX_11MBPS
  641. };
  642. rates->op_rate_mode = STA_11n;
  643. memcpy(rates->dsss_rates, dsss_rates,
  644. sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES);
  645. memcpy(rates->ofdm_rates, ofdm_rates,
  646. sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES);
  647. rates->supported_mcs_set[0] = 0xFF;
  648. }
  649. static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
  650. struct ieee80211_vif *vif,
  651. struct ieee80211_bss_conf *bss_conf,
  652. u32 changed)
  653. {
  654. struct wcn36xx *wcn = hw->priv;
  655. struct sk_buff *skb = NULL;
  656. u16 tim_off, tim_len;
  657. enum wcn36xx_hal_link_state link_state;
  658. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  659. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
  660. vif, changed);
  661. mutex_lock(&wcn->conf_mutex);
  662. if (changed & BSS_CHANGED_BEACON_INFO) {
  663. wcn36xx_dbg(WCN36XX_DBG_MAC,
  664. "mac bss changed dtim period %d\n",
  665. bss_conf->dtim_period);
  666. vif_priv->dtim_period = bss_conf->dtim_period;
  667. }
  668. if (changed & BSS_CHANGED_BSSID) {
  669. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n",
  670. bss_conf->bssid);
  671. if (!is_zero_ether_addr(bss_conf->bssid)) {
  672. vif_priv->is_joining = true;
  673. vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
  674. wcn36xx_smd_join(wcn, bss_conf->bssid,
  675. vif->addr, WCN36XX_HW_CHANNEL(wcn));
  676. wcn36xx_smd_config_bss(wcn, vif, NULL,
  677. bss_conf->bssid, false);
  678. } else {
  679. vif_priv->is_joining = false;
  680. wcn36xx_smd_delete_bss(wcn, vif);
  681. vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
  682. }
  683. }
  684. if (changed & BSS_CHANGED_SSID) {
  685. wcn36xx_dbg(WCN36XX_DBG_MAC,
  686. "mac bss changed ssid\n");
  687. wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ",
  688. bss_conf->ssid, bss_conf->ssid_len);
  689. vif_priv->ssid.length = bss_conf->ssid_len;
  690. memcpy(&vif_priv->ssid.ssid,
  691. bss_conf->ssid,
  692. bss_conf->ssid_len);
  693. }
  694. if (changed & BSS_CHANGED_ASSOC) {
  695. vif_priv->is_joining = false;
  696. if (bss_conf->assoc) {
  697. struct ieee80211_sta *sta;
  698. struct wcn36xx_sta *sta_priv;
  699. wcn36xx_dbg(WCN36XX_DBG_MAC,
  700. "mac assoc bss %pM vif %pM AID=%d\n",
  701. bss_conf->bssid,
  702. vif->addr,
  703. bss_conf->aid);
  704. vif_priv->sta_assoc = true;
  705. /*
  706. * Holding conf_mutex ensures mutal exclusion with
  707. * wcn36xx_sta_remove() and as such ensures that sta
  708. * won't be freed while we're operating on it. As such
  709. * we do not need to hold the rcu_read_lock().
  710. */
  711. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  712. if (!sta) {
  713. wcn36xx_err("sta %pM is not found\n",
  714. bss_conf->bssid);
  715. goto out;
  716. }
  717. sta_priv = wcn36xx_sta_to_priv(sta);
  718. wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
  719. wcn36xx_smd_set_link_st(wcn, bss_conf->bssid,
  720. vif->addr,
  721. WCN36XX_HAL_LINK_POSTASSOC_STATE);
  722. wcn36xx_smd_config_bss(wcn, vif, sta,
  723. bss_conf->bssid,
  724. true);
  725. sta_priv->aid = bss_conf->aid;
  726. /*
  727. * config_sta must be called from because this is the
  728. * place where AID is available.
  729. */
  730. wcn36xx_smd_config_sta(wcn, vif, sta);
  731. } else {
  732. wcn36xx_dbg(WCN36XX_DBG_MAC,
  733. "disassociated bss %pM vif %pM AID=%d\n",
  734. bss_conf->bssid,
  735. vif->addr,
  736. bss_conf->aid);
  737. vif_priv->sta_assoc = false;
  738. wcn36xx_smd_set_link_st(wcn,
  739. bss_conf->bssid,
  740. vif->addr,
  741. WCN36XX_HAL_LINK_IDLE_STATE);
  742. }
  743. }
  744. if (changed & BSS_CHANGED_AP_PROBE_RESP) {
  745. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n");
  746. skb = ieee80211_proberesp_get(hw, vif);
  747. if (!skb) {
  748. wcn36xx_err("failed to alloc probereq skb\n");
  749. goto out;
  750. }
  751. wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb);
  752. dev_kfree_skb(skb);
  753. }
  754. if (changed & BSS_CHANGED_BEACON_ENABLED ||
  755. changed & BSS_CHANGED_BEACON) {
  756. wcn36xx_dbg(WCN36XX_DBG_MAC,
  757. "mac bss changed beacon enabled %d\n",
  758. bss_conf->enable_beacon);
  759. if (bss_conf->enable_beacon) {
  760. vif_priv->dtim_period = bss_conf->dtim_period;
  761. vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
  762. wcn36xx_smd_config_bss(wcn, vif, NULL,
  763. vif->addr, false);
  764. skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
  765. &tim_len);
  766. if (!skb) {
  767. wcn36xx_err("failed to alloc beacon skb\n");
  768. goto out;
  769. }
  770. wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
  771. dev_kfree_skb(skb);
  772. if (vif->type == NL80211_IFTYPE_ADHOC ||
  773. vif->type == NL80211_IFTYPE_MESH_POINT)
  774. link_state = WCN36XX_HAL_LINK_IBSS_STATE;
  775. else
  776. link_state = WCN36XX_HAL_LINK_AP_STATE;
  777. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  778. link_state);
  779. } else {
  780. wcn36xx_smd_delete_bss(wcn, vif);
  781. wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
  782. WCN36XX_HAL_LINK_IDLE_STATE);
  783. }
  784. }
  785. out:
  786. mutex_unlock(&wcn->conf_mutex);
  787. return;
  788. }
  789. /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
  790. static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  791. {
  792. struct wcn36xx *wcn = hw->priv;
  793. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
  794. mutex_lock(&wcn->conf_mutex);
  795. wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
  796. mutex_unlock(&wcn->conf_mutex);
  797. return 0;
  798. }
  799. static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
  800. struct ieee80211_vif *vif)
  801. {
  802. struct wcn36xx *wcn = hw->priv;
  803. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  804. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
  805. mutex_lock(&wcn->conf_mutex);
  806. list_del(&vif_priv->list);
  807. wcn36xx_smd_delete_sta_self(wcn, vif->addr);
  808. mutex_unlock(&wcn->conf_mutex);
  809. }
  810. static int wcn36xx_add_interface(struct ieee80211_hw *hw,
  811. struct ieee80211_vif *vif)
  812. {
  813. struct wcn36xx *wcn = hw->priv;
  814. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  815. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
  816. vif, vif->type);
  817. if (!(NL80211_IFTYPE_STATION == vif->type ||
  818. NL80211_IFTYPE_AP == vif->type ||
  819. NL80211_IFTYPE_ADHOC == vif->type ||
  820. NL80211_IFTYPE_MESH_POINT == vif->type)) {
  821. wcn36xx_warn("Unsupported interface type requested: %d\n",
  822. vif->type);
  823. return -EOPNOTSUPP;
  824. }
  825. mutex_lock(&wcn->conf_mutex);
  826. list_add(&vif_priv->list, &wcn->vif_list);
  827. wcn36xx_smd_add_sta_self(wcn, vif);
  828. mutex_unlock(&wcn->conf_mutex);
  829. return 0;
  830. }
  831. static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  832. struct ieee80211_sta *sta)
  833. {
  834. struct wcn36xx *wcn = hw->priv;
  835. struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
  836. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  837. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
  838. vif, sta->addr);
  839. mutex_lock(&wcn->conf_mutex);
  840. spin_lock_init(&sta_priv->ampdu_lock);
  841. sta_priv->vif = vif_priv;
  842. /*
  843. * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
  844. * at this stage AID is not available yet.
  845. */
  846. if (NL80211_IFTYPE_STATION != vif->type) {
  847. wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
  848. sta_priv->aid = sta->aid;
  849. wcn36xx_smd_config_sta(wcn, vif, sta);
  850. }
  851. mutex_unlock(&wcn->conf_mutex);
  852. return 0;
  853. }
  854. static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
  855. struct ieee80211_vif *vif,
  856. struct ieee80211_sta *sta)
  857. {
  858. struct wcn36xx *wcn = hw->priv;
  859. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
  860. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
  861. vif, sta->addr, sta_priv->sta_index);
  862. mutex_lock(&wcn->conf_mutex);
  863. wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
  864. sta_priv->vif = NULL;
  865. mutex_unlock(&wcn->conf_mutex);
  866. return 0;
  867. }
  868. #ifdef CONFIG_PM
  869. static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
  870. {
  871. struct wcn36xx *wcn = hw->priv;
  872. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
  873. flush_workqueue(wcn->hal_ind_wq);
  874. wcn36xx_smd_set_power_params(wcn, true);
  875. return 0;
  876. }
  877. static int wcn36xx_resume(struct ieee80211_hw *hw)
  878. {
  879. struct wcn36xx *wcn = hw->priv;
  880. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
  881. flush_workqueue(wcn->hal_ind_wq);
  882. wcn36xx_smd_set_power_params(wcn, false);
  883. return 0;
  884. }
  885. #endif
  886. static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
  887. struct ieee80211_vif *vif,
  888. struct ieee80211_ampdu_params *params)
  889. {
  890. struct wcn36xx *wcn = hw->priv;
  891. struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(params->sta);
  892. struct ieee80211_sta *sta = params->sta;
  893. enum ieee80211_ampdu_mlme_action action = params->action;
  894. u16 tid = params->tid;
  895. u16 *ssn = &params->ssn;
  896. wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
  897. action, tid);
  898. mutex_lock(&wcn->conf_mutex);
  899. switch (action) {
  900. case IEEE80211_AMPDU_RX_START:
  901. sta_priv->tid = tid;
  902. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
  903. get_sta_index(vif, sta_priv));
  904. wcn36xx_smd_add_ba(wcn);
  905. wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv));
  906. break;
  907. case IEEE80211_AMPDU_RX_STOP:
  908. wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
  909. break;
  910. case IEEE80211_AMPDU_TX_START:
  911. spin_lock_bh(&sta_priv->ampdu_lock);
  912. sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START;
  913. spin_unlock_bh(&sta_priv->ampdu_lock);
  914. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  915. break;
  916. case IEEE80211_AMPDU_TX_OPERATIONAL:
  917. spin_lock_bh(&sta_priv->ampdu_lock);
  918. sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_OPERATIONAL;
  919. spin_unlock_bh(&sta_priv->ampdu_lock);
  920. wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
  921. get_sta_index(vif, sta_priv));
  922. break;
  923. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  924. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  925. case IEEE80211_AMPDU_TX_STOP_CONT:
  926. spin_lock_bh(&sta_priv->ampdu_lock);
  927. sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_NONE;
  928. spin_unlock_bh(&sta_priv->ampdu_lock);
  929. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  930. break;
  931. default:
  932. wcn36xx_err("Unknown AMPDU action\n");
  933. }
  934. mutex_unlock(&wcn->conf_mutex);
  935. return 0;
  936. }
  937. static const struct ieee80211_ops wcn36xx_ops = {
  938. .start = wcn36xx_start,
  939. .stop = wcn36xx_stop,
  940. .add_interface = wcn36xx_add_interface,
  941. .remove_interface = wcn36xx_remove_interface,
  942. #ifdef CONFIG_PM
  943. .suspend = wcn36xx_suspend,
  944. .resume = wcn36xx_resume,
  945. #endif
  946. .config = wcn36xx_config,
  947. .prepare_multicast = wcn36xx_prepare_multicast,
  948. .configure_filter = wcn36xx_configure_filter,
  949. .tx = wcn36xx_tx,
  950. .set_key = wcn36xx_set_key,
  951. .hw_scan = wcn36xx_hw_scan,
  952. .cancel_hw_scan = wcn36xx_cancel_hw_scan,
  953. .bss_info_changed = wcn36xx_bss_info_changed,
  954. .set_rts_threshold = wcn36xx_set_rts_threshold,
  955. .sta_add = wcn36xx_sta_add,
  956. .sta_remove = wcn36xx_sta_remove,
  957. .ampdu_action = wcn36xx_ampdu_action,
  958. };
  959. static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
  960. {
  961. int ret = 0;
  962. static const u32 cipher_suites[] = {
  963. WLAN_CIPHER_SUITE_WEP40,
  964. WLAN_CIPHER_SUITE_WEP104,
  965. WLAN_CIPHER_SUITE_TKIP,
  966. WLAN_CIPHER_SUITE_CCMP,
  967. };
  968. ieee80211_hw_set(wcn->hw, TIMING_BEACON_ONLY);
  969. ieee80211_hw_set(wcn->hw, AMPDU_AGGREGATION);
  970. ieee80211_hw_set(wcn->hw, CONNECTION_MONITOR);
  971. ieee80211_hw_set(wcn->hw, SUPPORTS_PS);
  972. ieee80211_hw_set(wcn->hw, SIGNAL_DBM);
  973. ieee80211_hw_set(wcn->hw, HAS_RATE_CONTROL);
  974. ieee80211_hw_set(wcn->hw, SINGLE_SCAN_ON_ALL_BANDS);
  975. wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  976. BIT(NL80211_IFTYPE_AP) |
  977. BIT(NL80211_IFTYPE_ADHOC) |
  978. BIT(NL80211_IFTYPE_MESH_POINT);
  979. wcn->hw->wiphy->bands[NL80211_BAND_2GHZ] = &wcn_band_2ghz;
  980. if (wcn->rf_id != RF_IRIS_WCN3620)
  981. wcn->hw->wiphy->bands[NL80211_BAND_5GHZ] = &wcn_band_5ghz;
  982. wcn->hw->wiphy->max_scan_ssids = WCN36XX_MAX_SCAN_SSIDS;
  983. wcn->hw->wiphy->max_scan_ie_len = WCN36XX_MAX_SCAN_IE_LEN;
  984. wcn->hw->wiphy->cipher_suites = cipher_suites;
  985. wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  986. #ifdef CONFIG_PM
  987. wcn->hw->wiphy->wowlan = &wowlan_support;
  988. #endif
  989. wcn->hw->max_listen_interval = 200;
  990. wcn->hw->queues = 4;
  991. SET_IEEE80211_DEV(wcn->hw, wcn->dev);
  992. wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
  993. wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
  994. wiphy_ext_feature_set(wcn->hw->wiphy,
  995. NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  996. return ret;
  997. }
  998. static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
  999. struct platform_device *pdev)
  1000. {
  1001. struct device_node *mmio_node;
  1002. struct device_node *iris_node;
  1003. struct resource *res;
  1004. int index;
  1005. int ret;
  1006. /* Set TX IRQ */
  1007. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "tx");
  1008. if (!res) {
  1009. wcn36xx_err("failed to get tx_irq\n");
  1010. return -ENOENT;
  1011. }
  1012. wcn->tx_irq = res->start;
  1013. /* Set RX IRQ */
  1014. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "rx");
  1015. if (!res) {
  1016. wcn36xx_err("failed to get rx_irq\n");
  1017. return -ENOENT;
  1018. }
  1019. wcn->rx_irq = res->start;
  1020. /* Acquire SMSM tx enable handle */
  1021. wcn->tx_enable_state = qcom_smem_state_get(&pdev->dev,
  1022. "tx-enable", &wcn->tx_enable_state_bit);
  1023. if (IS_ERR(wcn->tx_enable_state)) {
  1024. wcn36xx_err("failed to get tx-enable state\n");
  1025. return PTR_ERR(wcn->tx_enable_state);
  1026. }
  1027. /* Acquire SMSM tx rings empty handle */
  1028. wcn->tx_rings_empty_state = qcom_smem_state_get(&pdev->dev,
  1029. "tx-rings-empty", &wcn->tx_rings_empty_state_bit);
  1030. if (IS_ERR(wcn->tx_rings_empty_state)) {
  1031. wcn36xx_err("failed to get tx-rings-empty state\n");
  1032. return PTR_ERR(wcn->tx_rings_empty_state);
  1033. }
  1034. mmio_node = of_parse_phandle(pdev->dev.parent->of_node, "qcom,mmio", 0);
  1035. if (!mmio_node) {
  1036. wcn36xx_err("failed to acquire qcom,mmio reference\n");
  1037. return -EINVAL;
  1038. }
  1039. wcn->is_pronto = !!of_device_is_compatible(mmio_node, "qcom,pronto");
  1040. /* Map the CCU memory */
  1041. index = of_property_match_string(mmio_node, "reg-names", "ccu");
  1042. wcn->ccu_base = of_iomap(mmio_node, index);
  1043. if (!wcn->ccu_base) {
  1044. wcn36xx_err("failed to map ccu memory\n");
  1045. ret = -ENOMEM;
  1046. goto put_mmio_node;
  1047. }
  1048. /* Map the DXE memory */
  1049. index = of_property_match_string(mmio_node, "reg-names", "dxe");
  1050. wcn->dxe_base = of_iomap(mmio_node, index);
  1051. if (!wcn->dxe_base) {
  1052. wcn36xx_err("failed to map dxe memory\n");
  1053. ret = -ENOMEM;
  1054. goto unmap_ccu;
  1055. }
  1056. /* External RF module */
  1057. iris_node = of_get_child_by_name(mmio_node, "iris");
  1058. if (iris_node) {
  1059. if (of_device_is_compatible(iris_node, "qcom,wcn3620"))
  1060. wcn->rf_id = RF_IRIS_WCN3620;
  1061. of_node_put(iris_node);
  1062. }
  1063. of_node_put(mmio_node);
  1064. return 0;
  1065. unmap_ccu:
  1066. iounmap(wcn->ccu_base);
  1067. put_mmio_node:
  1068. of_node_put(mmio_node);
  1069. return ret;
  1070. }
  1071. static int wcn36xx_probe(struct platform_device *pdev)
  1072. {
  1073. struct ieee80211_hw *hw;
  1074. struct wcn36xx *wcn;
  1075. void *wcnss;
  1076. int ret;
  1077. const u8 *addr;
  1078. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
  1079. wcnss = dev_get_drvdata(pdev->dev.parent);
  1080. hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
  1081. if (!hw) {
  1082. wcn36xx_err("failed to alloc hw\n");
  1083. ret = -ENOMEM;
  1084. goto out_err;
  1085. }
  1086. platform_set_drvdata(pdev, hw);
  1087. wcn = hw->priv;
  1088. wcn->hw = hw;
  1089. wcn->dev = &pdev->dev;
  1090. wcn->first_boot = true;
  1091. mutex_init(&wcn->conf_mutex);
  1092. mutex_init(&wcn->hal_mutex);
  1093. mutex_init(&wcn->scan_lock);
  1094. INIT_WORK(&wcn->scan_work, wcn36xx_hw_scan_worker);
  1095. wcn->smd_channel = qcom_wcnss_open_channel(wcnss, "WLAN_CTRL", wcn36xx_smd_rsp_process, hw);
  1096. if (IS_ERR(wcn->smd_channel)) {
  1097. wcn36xx_err("failed to open WLAN_CTRL channel\n");
  1098. ret = PTR_ERR(wcn->smd_channel);
  1099. goto out_wq;
  1100. }
  1101. addr = of_get_property(pdev->dev.of_node, "local-mac-address", &ret);
  1102. if (addr && ret != ETH_ALEN) {
  1103. wcn36xx_err("invalid local-mac-address\n");
  1104. ret = -EINVAL;
  1105. goto out_wq;
  1106. } else if (addr) {
  1107. wcn36xx_info("mac address: %pM\n", addr);
  1108. SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
  1109. }
  1110. ret = wcn36xx_platform_get_resources(wcn, pdev);
  1111. if (ret)
  1112. goto out_wq;
  1113. wcn36xx_init_ieee80211(wcn);
  1114. ret = ieee80211_register_hw(wcn->hw);
  1115. if (ret)
  1116. goto out_unmap;
  1117. return 0;
  1118. out_unmap:
  1119. iounmap(wcn->ccu_base);
  1120. iounmap(wcn->dxe_base);
  1121. out_wq:
  1122. ieee80211_free_hw(hw);
  1123. out_err:
  1124. return ret;
  1125. }
  1126. static int wcn36xx_remove(struct platform_device *pdev)
  1127. {
  1128. struct ieee80211_hw *hw = platform_get_drvdata(pdev);
  1129. struct wcn36xx *wcn = hw->priv;
  1130. wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
  1131. release_firmware(wcn->nv);
  1132. ieee80211_unregister_hw(hw);
  1133. qcom_smem_state_put(wcn->tx_enable_state);
  1134. qcom_smem_state_put(wcn->tx_rings_empty_state);
  1135. rpmsg_destroy_ept(wcn->smd_channel);
  1136. iounmap(wcn->dxe_base);
  1137. iounmap(wcn->ccu_base);
  1138. mutex_destroy(&wcn->hal_mutex);
  1139. ieee80211_free_hw(hw);
  1140. return 0;
  1141. }
  1142. static const struct of_device_id wcn36xx_of_match[] = {
  1143. { .compatible = "qcom,wcnss-wlan" },
  1144. {}
  1145. };
  1146. MODULE_DEVICE_TABLE(of, wcn36xx_of_match);
  1147. static struct platform_driver wcn36xx_driver = {
  1148. .probe = wcn36xx_probe,
  1149. .remove = wcn36xx_remove,
  1150. .driver = {
  1151. .name = "wcn36xx",
  1152. .of_match_table = wcn36xx_of_match,
  1153. },
  1154. };
  1155. module_platform_driver(wcn36xx_driver);
  1156. MODULE_LICENSE("Dual BSD/GPL");
  1157. MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
  1158. MODULE_FIRMWARE(WLAN_NV_FILE);