main.c 35 KB

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