main.c 37 KB

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