main.c 37 KB

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