main.c 29 KB

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