main.c 32 KB

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