wmi.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/skbuff.h>
  18. #include "core.h"
  19. #include "htc.h"
  20. #include "debug.h"
  21. #include "wmi.h"
  22. #include "mac.h"
  23. /* MAIN WMI cmd track */
  24. static struct wmi_cmd_map wmi_cmd_map = {
  25. .init_cmdid = WMI_INIT_CMDID,
  26. .start_scan_cmdid = WMI_START_SCAN_CMDID,
  27. .stop_scan_cmdid = WMI_STOP_SCAN_CMDID,
  28. .scan_chan_list_cmdid = WMI_SCAN_CHAN_LIST_CMDID,
  29. .scan_sch_prio_tbl_cmdid = WMI_SCAN_SCH_PRIO_TBL_CMDID,
  30. .pdev_set_regdomain_cmdid = WMI_PDEV_SET_REGDOMAIN_CMDID,
  31. .pdev_set_channel_cmdid = WMI_PDEV_SET_CHANNEL_CMDID,
  32. .pdev_set_param_cmdid = WMI_PDEV_SET_PARAM_CMDID,
  33. .pdev_pktlog_enable_cmdid = WMI_PDEV_PKTLOG_ENABLE_CMDID,
  34. .pdev_pktlog_disable_cmdid = WMI_PDEV_PKTLOG_DISABLE_CMDID,
  35. .pdev_set_wmm_params_cmdid = WMI_PDEV_SET_WMM_PARAMS_CMDID,
  36. .pdev_set_ht_cap_ie_cmdid = WMI_PDEV_SET_HT_CAP_IE_CMDID,
  37. .pdev_set_vht_cap_ie_cmdid = WMI_PDEV_SET_VHT_CAP_IE_CMDID,
  38. .pdev_set_dscp_tid_map_cmdid = WMI_PDEV_SET_DSCP_TID_MAP_CMDID,
  39. .pdev_set_quiet_mode_cmdid = WMI_PDEV_SET_QUIET_MODE_CMDID,
  40. .pdev_green_ap_ps_enable_cmdid = WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID,
  41. .pdev_get_tpc_config_cmdid = WMI_PDEV_GET_TPC_CONFIG_CMDID,
  42. .pdev_set_base_macaddr_cmdid = WMI_PDEV_SET_BASE_MACADDR_CMDID,
  43. .vdev_create_cmdid = WMI_VDEV_CREATE_CMDID,
  44. .vdev_delete_cmdid = WMI_VDEV_DELETE_CMDID,
  45. .vdev_start_request_cmdid = WMI_VDEV_START_REQUEST_CMDID,
  46. .vdev_restart_request_cmdid = WMI_VDEV_RESTART_REQUEST_CMDID,
  47. .vdev_up_cmdid = WMI_VDEV_UP_CMDID,
  48. .vdev_stop_cmdid = WMI_VDEV_STOP_CMDID,
  49. .vdev_down_cmdid = WMI_VDEV_DOWN_CMDID,
  50. .vdev_set_param_cmdid = WMI_VDEV_SET_PARAM_CMDID,
  51. .vdev_install_key_cmdid = WMI_VDEV_INSTALL_KEY_CMDID,
  52. .peer_create_cmdid = WMI_PEER_CREATE_CMDID,
  53. .peer_delete_cmdid = WMI_PEER_DELETE_CMDID,
  54. .peer_flush_tids_cmdid = WMI_PEER_FLUSH_TIDS_CMDID,
  55. .peer_set_param_cmdid = WMI_PEER_SET_PARAM_CMDID,
  56. .peer_assoc_cmdid = WMI_PEER_ASSOC_CMDID,
  57. .peer_add_wds_entry_cmdid = WMI_PEER_ADD_WDS_ENTRY_CMDID,
  58. .peer_remove_wds_entry_cmdid = WMI_PEER_REMOVE_WDS_ENTRY_CMDID,
  59. .peer_mcast_group_cmdid = WMI_PEER_MCAST_GROUP_CMDID,
  60. .bcn_tx_cmdid = WMI_BCN_TX_CMDID,
  61. .pdev_send_bcn_cmdid = WMI_PDEV_SEND_BCN_CMDID,
  62. .bcn_tmpl_cmdid = WMI_BCN_TMPL_CMDID,
  63. .bcn_filter_rx_cmdid = WMI_BCN_FILTER_RX_CMDID,
  64. .prb_req_filter_rx_cmdid = WMI_PRB_REQ_FILTER_RX_CMDID,
  65. .mgmt_tx_cmdid = WMI_MGMT_TX_CMDID,
  66. .prb_tmpl_cmdid = WMI_PRB_TMPL_CMDID,
  67. .addba_clear_resp_cmdid = WMI_ADDBA_CLEAR_RESP_CMDID,
  68. .addba_send_cmdid = WMI_ADDBA_SEND_CMDID,
  69. .addba_status_cmdid = WMI_ADDBA_STATUS_CMDID,
  70. .delba_send_cmdid = WMI_DELBA_SEND_CMDID,
  71. .addba_set_resp_cmdid = WMI_ADDBA_SET_RESP_CMDID,
  72. .send_singleamsdu_cmdid = WMI_SEND_SINGLEAMSDU_CMDID,
  73. .sta_powersave_mode_cmdid = WMI_STA_POWERSAVE_MODE_CMDID,
  74. .sta_powersave_param_cmdid = WMI_STA_POWERSAVE_PARAM_CMDID,
  75. .sta_mimo_ps_mode_cmdid = WMI_STA_MIMO_PS_MODE_CMDID,
  76. .pdev_dfs_enable_cmdid = WMI_PDEV_DFS_ENABLE_CMDID,
  77. .pdev_dfs_disable_cmdid = WMI_PDEV_DFS_DISABLE_CMDID,
  78. .roam_scan_mode = WMI_ROAM_SCAN_MODE,
  79. .roam_scan_rssi_threshold = WMI_ROAM_SCAN_RSSI_THRESHOLD,
  80. .roam_scan_period = WMI_ROAM_SCAN_PERIOD,
  81. .roam_scan_rssi_change_threshold = WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
  82. .roam_ap_profile = WMI_ROAM_AP_PROFILE,
  83. .ofl_scan_add_ap_profile = WMI_ROAM_AP_PROFILE,
  84. .ofl_scan_remove_ap_profile = WMI_OFL_SCAN_REMOVE_AP_PROFILE,
  85. .ofl_scan_period = WMI_OFL_SCAN_PERIOD,
  86. .p2p_dev_set_device_info = WMI_P2P_DEV_SET_DEVICE_INFO,
  87. .p2p_dev_set_discoverability = WMI_P2P_DEV_SET_DISCOVERABILITY,
  88. .p2p_go_set_beacon_ie = WMI_P2P_GO_SET_BEACON_IE,
  89. .p2p_go_set_probe_resp_ie = WMI_P2P_GO_SET_PROBE_RESP_IE,
  90. .p2p_set_vendor_ie_data_cmdid = WMI_P2P_SET_VENDOR_IE_DATA_CMDID,
  91. .ap_ps_peer_param_cmdid = WMI_AP_PS_PEER_PARAM_CMDID,
  92. .ap_ps_peer_uapsd_coex_cmdid = WMI_AP_PS_PEER_UAPSD_COEX_CMDID,
  93. .peer_rate_retry_sched_cmdid = WMI_PEER_RATE_RETRY_SCHED_CMDID,
  94. .wlan_profile_trigger_cmdid = WMI_WLAN_PROFILE_TRIGGER_CMDID,
  95. .wlan_profile_set_hist_intvl_cmdid =
  96. WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
  97. .wlan_profile_get_profile_data_cmdid =
  98. WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
  99. .wlan_profile_enable_profile_id_cmdid =
  100. WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
  101. .wlan_profile_list_profile_id_cmdid =
  102. WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
  103. .pdev_suspend_cmdid = WMI_PDEV_SUSPEND_CMDID,
  104. .pdev_resume_cmdid = WMI_PDEV_RESUME_CMDID,
  105. .add_bcn_filter_cmdid = WMI_ADD_BCN_FILTER_CMDID,
  106. .rmv_bcn_filter_cmdid = WMI_RMV_BCN_FILTER_CMDID,
  107. .wow_add_wake_pattern_cmdid = WMI_WOW_ADD_WAKE_PATTERN_CMDID,
  108. .wow_del_wake_pattern_cmdid = WMI_WOW_DEL_WAKE_PATTERN_CMDID,
  109. .wow_enable_disable_wake_event_cmdid =
  110. WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
  111. .wow_enable_cmdid = WMI_WOW_ENABLE_CMDID,
  112. .wow_hostwakeup_from_sleep_cmdid = WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
  113. .rtt_measreq_cmdid = WMI_RTT_MEASREQ_CMDID,
  114. .rtt_tsf_cmdid = WMI_RTT_TSF_CMDID,
  115. .vdev_spectral_scan_configure_cmdid =
  116. WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
  117. .vdev_spectral_scan_enable_cmdid = WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
  118. .request_stats_cmdid = WMI_REQUEST_STATS_CMDID,
  119. .set_arp_ns_offload_cmdid = WMI_SET_ARP_NS_OFFLOAD_CMDID,
  120. .network_list_offload_config_cmdid =
  121. WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID,
  122. .gtk_offload_cmdid = WMI_GTK_OFFLOAD_CMDID,
  123. .csa_offload_enable_cmdid = WMI_CSA_OFFLOAD_ENABLE_CMDID,
  124. .csa_offload_chanswitch_cmdid = WMI_CSA_OFFLOAD_CHANSWITCH_CMDID,
  125. .chatter_set_mode_cmdid = WMI_CHATTER_SET_MODE_CMDID,
  126. .peer_tid_addba_cmdid = WMI_PEER_TID_ADDBA_CMDID,
  127. .peer_tid_delba_cmdid = WMI_PEER_TID_DELBA_CMDID,
  128. .sta_dtim_ps_method_cmdid = WMI_STA_DTIM_PS_METHOD_CMDID,
  129. .sta_uapsd_auto_trig_cmdid = WMI_STA_UAPSD_AUTO_TRIG_CMDID,
  130. .sta_keepalive_cmd = WMI_STA_KEEPALIVE_CMD,
  131. .echo_cmdid = WMI_ECHO_CMDID,
  132. .pdev_utf_cmdid = WMI_PDEV_UTF_CMDID,
  133. .dbglog_cfg_cmdid = WMI_DBGLOG_CFG_CMDID,
  134. .pdev_qvit_cmdid = WMI_PDEV_QVIT_CMDID,
  135. .pdev_ftm_intg_cmdid = WMI_PDEV_FTM_INTG_CMDID,
  136. .vdev_set_keepalive_cmdid = WMI_VDEV_SET_KEEPALIVE_CMDID,
  137. .vdev_get_keepalive_cmdid = WMI_VDEV_GET_KEEPALIVE_CMDID,
  138. .force_fw_hang_cmdid = WMI_FORCE_FW_HANG_CMDID,
  139. .gpio_config_cmdid = WMI_GPIO_CONFIG_CMDID,
  140. .gpio_output_cmdid = WMI_GPIO_OUTPUT_CMDID,
  141. };
  142. /* 10.X WMI cmd track */
  143. static struct wmi_cmd_map wmi_10x_cmd_map = {
  144. .init_cmdid = WMI_10X_INIT_CMDID,
  145. .start_scan_cmdid = WMI_10X_START_SCAN_CMDID,
  146. .stop_scan_cmdid = WMI_10X_STOP_SCAN_CMDID,
  147. .scan_chan_list_cmdid = WMI_10X_SCAN_CHAN_LIST_CMDID,
  148. .scan_sch_prio_tbl_cmdid = WMI_CMD_UNDEFINED,
  149. .pdev_set_regdomain_cmdid = WMI_10X_PDEV_SET_REGDOMAIN_CMDID,
  150. .pdev_set_channel_cmdid = WMI_10X_PDEV_SET_CHANNEL_CMDID,
  151. .pdev_set_param_cmdid = WMI_10X_PDEV_SET_PARAM_CMDID,
  152. .pdev_pktlog_enable_cmdid = WMI_10X_PDEV_PKTLOG_ENABLE_CMDID,
  153. .pdev_pktlog_disable_cmdid = WMI_10X_PDEV_PKTLOG_DISABLE_CMDID,
  154. .pdev_set_wmm_params_cmdid = WMI_10X_PDEV_SET_WMM_PARAMS_CMDID,
  155. .pdev_set_ht_cap_ie_cmdid = WMI_10X_PDEV_SET_HT_CAP_IE_CMDID,
  156. .pdev_set_vht_cap_ie_cmdid = WMI_10X_PDEV_SET_VHT_CAP_IE_CMDID,
  157. .pdev_set_dscp_tid_map_cmdid = WMI_10X_PDEV_SET_DSCP_TID_MAP_CMDID,
  158. .pdev_set_quiet_mode_cmdid = WMI_10X_PDEV_SET_QUIET_MODE_CMDID,
  159. .pdev_green_ap_ps_enable_cmdid = WMI_10X_PDEV_GREEN_AP_PS_ENABLE_CMDID,
  160. .pdev_get_tpc_config_cmdid = WMI_10X_PDEV_GET_TPC_CONFIG_CMDID,
  161. .pdev_set_base_macaddr_cmdid = WMI_10X_PDEV_SET_BASE_MACADDR_CMDID,
  162. .vdev_create_cmdid = WMI_10X_VDEV_CREATE_CMDID,
  163. .vdev_delete_cmdid = WMI_10X_VDEV_DELETE_CMDID,
  164. .vdev_start_request_cmdid = WMI_10X_VDEV_START_REQUEST_CMDID,
  165. .vdev_restart_request_cmdid = WMI_10X_VDEV_RESTART_REQUEST_CMDID,
  166. .vdev_up_cmdid = WMI_10X_VDEV_UP_CMDID,
  167. .vdev_stop_cmdid = WMI_10X_VDEV_STOP_CMDID,
  168. .vdev_down_cmdid = WMI_10X_VDEV_DOWN_CMDID,
  169. .vdev_set_param_cmdid = WMI_10X_VDEV_SET_PARAM_CMDID,
  170. .vdev_install_key_cmdid = WMI_10X_VDEV_INSTALL_KEY_CMDID,
  171. .peer_create_cmdid = WMI_10X_PEER_CREATE_CMDID,
  172. .peer_delete_cmdid = WMI_10X_PEER_DELETE_CMDID,
  173. .peer_flush_tids_cmdid = WMI_10X_PEER_FLUSH_TIDS_CMDID,
  174. .peer_set_param_cmdid = WMI_10X_PEER_SET_PARAM_CMDID,
  175. .peer_assoc_cmdid = WMI_10X_PEER_ASSOC_CMDID,
  176. .peer_add_wds_entry_cmdid = WMI_10X_PEER_ADD_WDS_ENTRY_CMDID,
  177. .peer_remove_wds_entry_cmdid = WMI_10X_PEER_REMOVE_WDS_ENTRY_CMDID,
  178. .peer_mcast_group_cmdid = WMI_10X_PEER_MCAST_GROUP_CMDID,
  179. .bcn_tx_cmdid = WMI_10X_BCN_TX_CMDID,
  180. .pdev_send_bcn_cmdid = WMI_10X_PDEV_SEND_BCN_CMDID,
  181. .bcn_tmpl_cmdid = WMI_CMD_UNDEFINED,
  182. .bcn_filter_rx_cmdid = WMI_10X_BCN_FILTER_RX_CMDID,
  183. .prb_req_filter_rx_cmdid = WMI_10X_PRB_REQ_FILTER_RX_CMDID,
  184. .mgmt_tx_cmdid = WMI_10X_MGMT_TX_CMDID,
  185. .prb_tmpl_cmdid = WMI_CMD_UNDEFINED,
  186. .addba_clear_resp_cmdid = WMI_10X_ADDBA_CLEAR_RESP_CMDID,
  187. .addba_send_cmdid = WMI_10X_ADDBA_SEND_CMDID,
  188. .addba_status_cmdid = WMI_10X_ADDBA_STATUS_CMDID,
  189. .delba_send_cmdid = WMI_10X_DELBA_SEND_CMDID,
  190. .addba_set_resp_cmdid = WMI_10X_ADDBA_SET_RESP_CMDID,
  191. .send_singleamsdu_cmdid = WMI_10X_SEND_SINGLEAMSDU_CMDID,
  192. .sta_powersave_mode_cmdid = WMI_10X_STA_POWERSAVE_MODE_CMDID,
  193. .sta_powersave_param_cmdid = WMI_10X_STA_POWERSAVE_PARAM_CMDID,
  194. .sta_mimo_ps_mode_cmdid = WMI_10X_STA_MIMO_PS_MODE_CMDID,
  195. .pdev_dfs_enable_cmdid = WMI_10X_PDEV_DFS_ENABLE_CMDID,
  196. .pdev_dfs_disable_cmdid = WMI_10X_PDEV_DFS_DISABLE_CMDID,
  197. .roam_scan_mode = WMI_10X_ROAM_SCAN_MODE,
  198. .roam_scan_rssi_threshold = WMI_10X_ROAM_SCAN_RSSI_THRESHOLD,
  199. .roam_scan_period = WMI_10X_ROAM_SCAN_PERIOD,
  200. .roam_scan_rssi_change_threshold =
  201. WMI_10X_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
  202. .roam_ap_profile = WMI_10X_ROAM_AP_PROFILE,
  203. .ofl_scan_add_ap_profile = WMI_10X_OFL_SCAN_ADD_AP_PROFILE,
  204. .ofl_scan_remove_ap_profile = WMI_10X_OFL_SCAN_REMOVE_AP_PROFILE,
  205. .ofl_scan_period = WMI_10X_OFL_SCAN_PERIOD,
  206. .p2p_dev_set_device_info = WMI_10X_P2P_DEV_SET_DEVICE_INFO,
  207. .p2p_dev_set_discoverability = WMI_10X_P2P_DEV_SET_DISCOVERABILITY,
  208. .p2p_go_set_beacon_ie = WMI_10X_P2P_GO_SET_BEACON_IE,
  209. .p2p_go_set_probe_resp_ie = WMI_10X_P2P_GO_SET_PROBE_RESP_IE,
  210. .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNDEFINED,
  211. .ap_ps_peer_param_cmdid = WMI_CMD_UNDEFINED,
  212. .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNDEFINED,
  213. .peer_rate_retry_sched_cmdid = WMI_10X_PEER_RATE_RETRY_SCHED_CMDID,
  214. .wlan_profile_trigger_cmdid = WMI_10X_WLAN_PROFILE_TRIGGER_CMDID,
  215. .wlan_profile_set_hist_intvl_cmdid =
  216. WMI_10X_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
  217. .wlan_profile_get_profile_data_cmdid =
  218. WMI_10X_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
  219. .wlan_profile_enable_profile_id_cmdid =
  220. WMI_10X_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
  221. .wlan_profile_list_profile_id_cmdid =
  222. WMI_10X_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
  223. .pdev_suspend_cmdid = WMI_10X_PDEV_SUSPEND_CMDID,
  224. .pdev_resume_cmdid = WMI_10X_PDEV_RESUME_CMDID,
  225. .add_bcn_filter_cmdid = WMI_10X_ADD_BCN_FILTER_CMDID,
  226. .rmv_bcn_filter_cmdid = WMI_10X_RMV_BCN_FILTER_CMDID,
  227. .wow_add_wake_pattern_cmdid = WMI_10X_WOW_ADD_WAKE_PATTERN_CMDID,
  228. .wow_del_wake_pattern_cmdid = WMI_10X_WOW_DEL_WAKE_PATTERN_CMDID,
  229. .wow_enable_disable_wake_event_cmdid =
  230. WMI_10X_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
  231. .wow_enable_cmdid = WMI_10X_WOW_ENABLE_CMDID,
  232. .wow_hostwakeup_from_sleep_cmdid =
  233. WMI_10X_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
  234. .rtt_measreq_cmdid = WMI_10X_RTT_MEASREQ_CMDID,
  235. .rtt_tsf_cmdid = WMI_10X_RTT_TSF_CMDID,
  236. .vdev_spectral_scan_configure_cmdid =
  237. WMI_10X_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
  238. .vdev_spectral_scan_enable_cmdid =
  239. WMI_10X_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
  240. .request_stats_cmdid = WMI_10X_REQUEST_STATS_CMDID,
  241. .set_arp_ns_offload_cmdid = WMI_CMD_UNDEFINED,
  242. .network_list_offload_config_cmdid = WMI_CMD_UNDEFINED,
  243. .gtk_offload_cmdid = WMI_CMD_UNDEFINED,
  244. .csa_offload_enable_cmdid = WMI_CMD_UNDEFINED,
  245. .csa_offload_chanswitch_cmdid = WMI_CMD_UNDEFINED,
  246. .chatter_set_mode_cmdid = WMI_CMD_UNDEFINED,
  247. .peer_tid_addba_cmdid = WMI_CMD_UNDEFINED,
  248. .peer_tid_delba_cmdid = WMI_CMD_UNDEFINED,
  249. .sta_dtim_ps_method_cmdid = WMI_CMD_UNDEFINED,
  250. .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNDEFINED,
  251. .sta_keepalive_cmd = WMI_CMD_UNDEFINED,
  252. .echo_cmdid = WMI_10X_ECHO_CMDID,
  253. .pdev_utf_cmdid = WMI_10X_PDEV_UTF_CMDID,
  254. .dbglog_cfg_cmdid = WMI_10X_DBGLOG_CFG_CMDID,
  255. .pdev_qvit_cmdid = WMI_10X_PDEV_QVIT_CMDID,
  256. .pdev_ftm_intg_cmdid = WMI_CMD_UNDEFINED,
  257. .vdev_set_keepalive_cmdid = WMI_CMD_UNDEFINED,
  258. .vdev_get_keepalive_cmdid = WMI_CMD_UNDEFINED,
  259. .force_fw_hang_cmdid = WMI_CMD_UNDEFINED,
  260. .gpio_config_cmdid = WMI_10X_GPIO_CONFIG_CMDID,
  261. .gpio_output_cmdid = WMI_10X_GPIO_OUTPUT_CMDID,
  262. };
  263. int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
  264. {
  265. int ret;
  266. ret = wait_for_completion_timeout(&ar->wmi.service_ready,
  267. WMI_SERVICE_READY_TIMEOUT_HZ);
  268. return ret;
  269. }
  270. int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
  271. {
  272. int ret;
  273. ret = wait_for_completion_timeout(&ar->wmi.unified_ready,
  274. WMI_UNIFIED_READY_TIMEOUT_HZ);
  275. return ret;
  276. }
  277. static struct sk_buff *ath10k_wmi_alloc_skb(u32 len)
  278. {
  279. struct sk_buff *skb;
  280. u32 round_len = roundup(len, 4);
  281. skb = ath10k_htc_alloc_skb(WMI_SKB_HEADROOM + round_len);
  282. if (!skb)
  283. return NULL;
  284. skb_reserve(skb, WMI_SKB_HEADROOM);
  285. if (!IS_ALIGNED((unsigned long)skb->data, 4))
  286. ath10k_warn("Unaligned WMI skb\n");
  287. skb_put(skb, round_len);
  288. memset(skb->data, 0, round_len);
  289. return skb;
  290. }
  291. static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
  292. {
  293. dev_kfree_skb(skb);
  294. }
  295. static int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
  296. u32 cmd_id)
  297. {
  298. struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
  299. struct wmi_cmd_hdr *cmd_hdr;
  300. int ret;
  301. u32 cmd = 0;
  302. if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
  303. return -ENOMEM;
  304. cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
  305. cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
  306. cmd_hdr->cmd_id = __cpu_to_le32(cmd);
  307. memset(skb_cb, 0, sizeof(*skb_cb));
  308. ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
  309. trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len, ret);
  310. if (ret)
  311. goto err_pull;
  312. return 0;
  313. err_pull:
  314. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  315. return ret;
  316. }
  317. static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
  318. {
  319. struct wmi_bcn_tx_arg arg = {0};
  320. int ret;
  321. lockdep_assert_held(&arvif->ar->data_lock);
  322. if (arvif->beacon == NULL)
  323. return;
  324. arg.vdev_id = arvif->vdev_id;
  325. arg.tx_rate = 0;
  326. arg.tx_power = 0;
  327. arg.bcn = arvif->beacon->data;
  328. arg.bcn_len = arvif->beacon->len;
  329. ret = ath10k_wmi_beacon_send_nowait(arvif->ar, &arg);
  330. if (ret)
  331. return;
  332. dev_kfree_skb_any(arvif->beacon);
  333. arvif->beacon = NULL;
  334. }
  335. static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
  336. struct ieee80211_vif *vif)
  337. {
  338. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  339. ath10k_wmi_tx_beacon_nowait(arvif);
  340. }
  341. static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
  342. {
  343. spin_lock_bh(&ar->data_lock);
  344. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  345. IEEE80211_IFACE_ITER_NORMAL,
  346. ath10k_wmi_tx_beacons_iter,
  347. NULL);
  348. spin_unlock_bh(&ar->data_lock);
  349. }
  350. static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
  351. {
  352. /* try to send pending beacons first. they take priority */
  353. ath10k_wmi_tx_beacons_nowait(ar);
  354. wake_up(&ar->wmi.tx_credits_wq);
  355. }
  356. static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb,
  357. u32 cmd_id)
  358. {
  359. int ret = -EINVAL;
  360. if (cmd_id == WMI_CMD_UNDEFINED) {
  361. ath10k_warn("wmi command %d is not supported by firmware\n",
  362. cmd_id);
  363. return ret;
  364. }
  365. wait_event_timeout(ar->wmi.tx_credits_wq, ({
  366. /* try to send pending beacons first. they take priority */
  367. ath10k_wmi_tx_beacons_nowait(ar);
  368. ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
  369. (ret != -EAGAIN);
  370. }), 3*HZ);
  371. if (ret)
  372. dev_kfree_skb_any(skb);
  373. return ret;
  374. }
  375. int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
  376. {
  377. int ret = 0;
  378. struct wmi_mgmt_tx_cmd *cmd;
  379. struct ieee80211_hdr *hdr;
  380. struct sk_buff *wmi_skb;
  381. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  382. int len;
  383. u16 fc;
  384. hdr = (struct ieee80211_hdr *)skb->data;
  385. fc = le16_to_cpu(hdr->frame_control);
  386. if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control)))
  387. return -EINVAL;
  388. len = sizeof(cmd->hdr) + skb->len;
  389. len = round_up(len, 4);
  390. wmi_skb = ath10k_wmi_alloc_skb(len);
  391. if (!wmi_skb)
  392. return -ENOMEM;
  393. cmd = (struct wmi_mgmt_tx_cmd *)wmi_skb->data;
  394. cmd->hdr.vdev_id = __cpu_to_le32(ATH10K_SKB_CB(skb)->vdev_id);
  395. cmd->hdr.tx_rate = 0;
  396. cmd->hdr.tx_power = 0;
  397. cmd->hdr.buf_len = __cpu_to_le32((u32)(skb->len));
  398. memcpy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr), ETH_ALEN);
  399. memcpy(cmd->buf, skb->data, skb->len);
  400. ath10k_dbg(ATH10K_DBG_WMI, "wmi mgmt tx skb %p len %d ftype %02x stype %02x\n",
  401. wmi_skb, wmi_skb->len, fc & IEEE80211_FCTL_FTYPE,
  402. fc & IEEE80211_FCTL_STYPE);
  403. /* Send the management frame buffer to the target */
  404. ret = ath10k_wmi_cmd_send(ar, wmi_skb, ar->wmi.cmd->mgmt_tx_cmdid);
  405. if (ret) {
  406. dev_kfree_skb_any(skb);
  407. return ret;
  408. }
  409. /* TODO: report tx status to mac80211 - temporary just ACK */
  410. info->flags |= IEEE80211_TX_STAT_ACK;
  411. ieee80211_tx_status_irqsafe(ar->hw, skb);
  412. return ret;
  413. }
  414. static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
  415. {
  416. struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
  417. enum wmi_scan_event_type event_type;
  418. enum wmi_scan_completion_reason reason;
  419. u32 freq;
  420. u32 req_id;
  421. u32 scan_id;
  422. u32 vdev_id;
  423. event_type = __le32_to_cpu(event->event_type);
  424. reason = __le32_to_cpu(event->reason);
  425. freq = __le32_to_cpu(event->channel_freq);
  426. req_id = __le32_to_cpu(event->scan_req_id);
  427. scan_id = __le32_to_cpu(event->scan_id);
  428. vdev_id = __le32_to_cpu(event->vdev_id);
  429. ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENTID\n");
  430. ath10k_dbg(ATH10K_DBG_WMI,
  431. "scan event type %d reason %d freq %d req_id %d "
  432. "scan_id %d vdev_id %d\n",
  433. event_type, reason, freq, req_id, scan_id, vdev_id);
  434. spin_lock_bh(&ar->data_lock);
  435. switch (event_type) {
  436. case WMI_SCAN_EVENT_STARTED:
  437. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_STARTED\n");
  438. if (ar->scan.in_progress && ar->scan.is_roc)
  439. ieee80211_ready_on_channel(ar->hw);
  440. complete(&ar->scan.started);
  441. break;
  442. case WMI_SCAN_EVENT_COMPLETED:
  443. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_COMPLETED\n");
  444. switch (reason) {
  445. case WMI_SCAN_REASON_COMPLETED:
  446. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_COMPLETED\n");
  447. break;
  448. case WMI_SCAN_REASON_CANCELLED:
  449. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_CANCELED\n");
  450. break;
  451. case WMI_SCAN_REASON_PREEMPTED:
  452. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_PREEMPTED\n");
  453. break;
  454. case WMI_SCAN_REASON_TIMEDOUT:
  455. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_TIMEDOUT\n");
  456. break;
  457. default:
  458. break;
  459. }
  460. ar->scan_channel = NULL;
  461. if (!ar->scan.in_progress) {
  462. ath10k_warn("no scan requested, ignoring\n");
  463. break;
  464. }
  465. if (ar->scan.is_roc) {
  466. ath10k_offchan_tx_purge(ar);
  467. if (!ar->scan.aborting)
  468. ieee80211_remain_on_channel_expired(ar->hw);
  469. } else {
  470. ieee80211_scan_completed(ar->hw, ar->scan.aborting);
  471. }
  472. del_timer(&ar->scan.timeout);
  473. complete_all(&ar->scan.completed);
  474. ar->scan.in_progress = false;
  475. break;
  476. case WMI_SCAN_EVENT_BSS_CHANNEL:
  477. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_BSS_CHANNEL\n");
  478. ar->scan_channel = NULL;
  479. break;
  480. case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
  481. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_FOREIGN_CHANNEL\n");
  482. ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
  483. if (ar->scan.in_progress && ar->scan.is_roc &&
  484. ar->scan.roc_freq == freq) {
  485. complete(&ar->scan.on_channel);
  486. }
  487. break;
  488. case WMI_SCAN_EVENT_DEQUEUED:
  489. ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_DEQUEUED\n");
  490. break;
  491. case WMI_SCAN_EVENT_PREEMPTED:
  492. ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_PREEMPTED\n");
  493. break;
  494. case WMI_SCAN_EVENT_START_FAILED:
  495. ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_START_FAILED\n");
  496. break;
  497. default:
  498. break;
  499. }
  500. spin_unlock_bh(&ar->data_lock);
  501. return 0;
  502. }
  503. static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
  504. {
  505. enum ieee80211_band band;
  506. switch (phy_mode) {
  507. case MODE_11A:
  508. case MODE_11NA_HT20:
  509. case MODE_11NA_HT40:
  510. case MODE_11AC_VHT20:
  511. case MODE_11AC_VHT40:
  512. case MODE_11AC_VHT80:
  513. band = IEEE80211_BAND_5GHZ;
  514. break;
  515. case MODE_11G:
  516. case MODE_11B:
  517. case MODE_11GONLY:
  518. case MODE_11NG_HT20:
  519. case MODE_11NG_HT40:
  520. case MODE_11AC_VHT20_2G:
  521. case MODE_11AC_VHT40_2G:
  522. case MODE_11AC_VHT80_2G:
  523. default:
  524. band = IEEE80211_BAND_2GHZ;
  525. }
  526. return band;
  527. }
  528. static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
  529. {
  530. u8 rate_idx = 0;
  531. /* rate in Kbps */
  532. switch (rate) {
  533. case 1000:
  534. rate_idx = 0;
  535. break;
  536. case 2000:
  537. rate_idx = 1;
  538. break;
  539. case 5500:
  540. rate_idx = 2;
  541. break;
  542. case 11000:
  543. rate_idx = 3;
  544. break;
  545. case 6000:
  546. rate_idx = 4;
  547. break;
  548. case 9000:
  549. rate_idx = 5;
  550. break;
  551. case 12000:
  552. rate_idx = 6;
  553. break;
  554. case 18000:
  555. rate_idx = 7;
  556. break;
  557. case 24000:
  558. rate_idx = 8;
  559. break;
  560. case 36000:
  561. rate_idx = 9;
  562. break;
  563. case 48000:
  564. rate_idx = 10;
  565. break;
  566. case 54000:
  567. rate_idx = 11;
  568. break;
  569. default:
  570. break;
  571. }
  572. if (band == IEEE80211_BAND_5GHZ) {
  573. if (rate_idx > 3)
  574. /* Omit CCK rates */
  575. rate_idx -= 4;
  576. else
  577. rate_idx = 0;
  578. }
  579. return rate_idx;
  580. }
  581. static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
  582. {
  583. struct wmi_mgmt_rx_event_v1 *ev_v1;
  584. struct wmi_mgmt_rx_event_v2 *ev_v2;
  585. struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
  586. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  587. struct ieee80211_hdr *hdr;
  588. u32 rx_status;
  589. u32 channel;
  590. u32 phy_mode;
  591. u32 snr;
  592. u32 rate;
  593. u32 buf_len;
  594. u16 fc;
  595. int pull_len;
  596. if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
  597. ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
  598. ev_hdr = &ev_v2->hdr.v1;
  599. pull_len = sizeof(*ev_v2);
  600. } else {
  601. ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
  602. ev_hdr = &ev_v1->hdr;
  603. pull_len = sizeof(*ev_v1);
  604. }
  605. channel = __le32_to_cpu(ev_hdr->channel);
  606. buf_len = __le32_to_cpu(ev_hdr->buf_len);
  607. rx_status = __le32_to_cpu(ev_hdr->status);
  608. snr = __le32_to_cpu(ev_hdr->snr);
  609. phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
  610. rate = __le32_to_cpu(ev_hdr->rate);
  611. memset(status, 0, sizeof(*status));
  612. ath10k_dbg(ATH10K_DBG_MGMT,
  613. "event mgmt rx status %08x\n", rx_status);
  614. if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
  615. dev_kfree_skb(skb);
  616. return 0;
  617. }
  618. if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
  619. dev_kfree_skb(skb);
  620. return 0;
  621. }
  622. if (rx_status & WMI_RX_STATUS_ERR_CRC)
  623. status->flag |= RX_FLAG_FAILED_FCS_CRC;
  624. if (rx_status & WMI_RX_STATUS_ERR_MIC)
  625. status->flag |= RX_FLAG_MMIC_ERROR;
  626. status->band = phy_mode_to_band(phy_mode);
  627. status->freq = ieee80211_channel_to_frequency(channel, status->band);
  628. status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
  629. status->rate_idx = get_rate_idx(rate, status->band);
  630. skb_pull(skb, pull_len);
  631. hdr = (struct ieee80211_hdr *)skb->data;
  632. fc = le16_to_cpu(hdr->frame_control);
  633. if (fc & IEEE80211_FCTL_PROTECTED) {
  634. status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED |
  635. RX_FLAG_MMIC_STRIPPED;
  636. hdr->frame_control = __cpu_to_le16(fc &
  637. ~IEEE80211_FCTL_PROTECTED);
  638. }
  639. ath10k_dbg(ATH10K_DBG_MGMT,
  640. "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
  641. skb, skb->len,
  642. fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
  643. ath10k_dbg(ATH10K_DBG_MGMT,
  644. "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
  645. status->freq, status->band, status->signal,
  646. status->rate_idx);
  647. /*
  648. * packets from HTC come aligned to 4byte boundaries
  649. * because they can originally come in along with a trailer
  650. */
  651. skb_trim(skb, buf_len);
  652. ieee80211_rx(ar->hw, skb);
  653. return 0;
  654. }
  655. static int freq_to_idx(struct ath10k *ar, int freq)
  656. {
  657. struct ieee80211_supported_band *sband;
  658. int band, ch, idx = 0;
  659. for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
  660. sband = ar->hw->wiphy->bands[band];
  661. if (!sband)
  662. continue;
  663. for (ch = 0; ch < sband->n_channels; ch++, idx++)
  664. if (sband->channels[ch].center_freq == freq)
  665. goto exit;
  666. }
  667. exit:
  668. return idx;
  669. }
  670. static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
  671. {
  672. struct wmi_chan_info_event *ev;
  673. struct survey_info *survey;
  674. u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
  675. int idx;
  676. ev = (struct wmi_chan_info_event *)skb->data;
  677. err_code = __le32_to_cpu(ev->err_code);
  678. freq = __le32_to_cpu(ev->freq);
  679. cmd_flags = __le32_to_cpu(ev->cmd_flags);
  680. noise_floor = __le32_to_cpu(ev->noise_floor);
  681. rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
  682. cycle_count = __le32_to_cpu(ev->cycle_count);
  683. ath10k_dbg(ATH10K_DBG_WMI,
  684. "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
  685. err_code, freq, cmd_flags, noise_floor, rx_clear_count,
  686. cycle_count);
  687. spin_lock_bh(&ar->data_lock);
  688. if (!ar->scan.in_progress) {
  689. ath10k_warn("chan info event without a scan request?\n");
  690. goto exit;
  691. }
  692. idx = freq_to_idx(ar, freq);
  693. if (idx >= ARRAY_SIZE(ar->survey)) {
  694. ath10k_warn("chan info: invalid frequency %d (idx %d out of bounds)\n",
  695. freq, idx);
  696. goto exit;
  697. }
  698. if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
  699. /* During scanning chan info is reported twice for each
  700. * visited channel. The reported cycle count is global
  701. * and per-channel cycle count must be calculated */
  702. cycle_count -= ar->survey_last_cycle_count;
  703. rx_clear_count -= ar->survey_last_rx_clear_count;
  704. survey = &ar->survey[idx];
  705. survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
  706. survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
  707. survey->noise = noise_floor;
  708. survey->filled = SURVEY_INFO_CHANNEL_TIME |
  709. SURVEY_INFO_CHANNEL_TIME_RX |
  710. SURVEY_INFO_NOISE_DBM;
  711. }
  712. ar->survey_last_rx_clear_count = rx_clear_count;
  713. ar->survey_last_cycle_count = cycle_count;
  714. exit:
  715. spin_unlock_bh(&ar->data_lock);
  716. }
  717. static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
  718. {
  719. ath10k_dbg(ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
  720. }
  721. static void ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
  722. {
  723. ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_MESG_EVENTID\n");
  724. }
  725. static void ath10k_wmi_event_update_stats(struct ath10k *ar,
  726. struct sk_buff *skb)
  727. {
  728. struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
  729. ath10k_dbg(ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
  730. ath10k_debug_read_target_stats(ar, ev);
  731. }
  732. static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
  733. struct sk_buff *skb)
  734. {
  735. struct wmi_vdev_start_response_event *ev;
  736. ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
  737. ev = (struct wmi_vdev_start_response_event *)skb->data;
  738. if (WARN_ON(__le32_to_cpu(ev->status)))
  739. return;
  740. complete(&ar->vdev_setup_done);
  741. }
  742. static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
  743. struct sk_buff *skb)
  744. {
  745. ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
  746. complete(&ar->vdev_setup_done);
  747. }
  748. static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
  749. struct sk_buff *skb)
  750. {
  751. ath10k_dbg(ATH10K_DBG_WMI, "WMI_PEER_STA_KICKOUT_EVENTID\n");
  752. }
  753. /*
  754. * FIXME
  755. *
  756. * We don't report to mac80211 sleep state of connected
  757. * stations. Due to this mac80211 can't fill in TIM IE
  758. * correctly.
  759. *
  760. * I know of no way of getting nullfunc frames that contain
  761. * sleep transition from connected stations - these do not
  762. * seem to be sent from the target to the host. There also
  763. * doesn't seem to be a dedicated event for that. So the
  764. * only way left to do this would be to read tim_bitmap
  765. * during SWBA.
  766. *
  767. * We could probably try using tim_bitmap from SWBA to tell
  768. * mac80211 which stations are asleep and which are not. The
  769. * problem here is calling mac80211 functions so many times
  770. * could take too long and make us miss the time to submit
  771. * the beacon to the target.
  772. *
  773. * So as a workaround we try to extend the TIM IE if there
  774. * is unicast buffered for stations with aid > 7 and fill it
  775. * in ourselves.
  776. */
  777. static void ath10k_wmi_update_tim(struct ath10k *ar,
  778. struct ath10k_vif *arvif,
  779. struct sk_buff *bcn,
  780. struct wmi_bcn_info *bcn_info)
  781. {
  782. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
  783. struct ieee80211_tim_ie *tim;
  784. u8 *ies, *ie;
  785. u8 ie_len, pvm_len;
  786. /* if next SWBA has no tim_changed the tim_bitmap is garbage.
  787. * we must copy the bitmap upon change and reuse it later */
  788. if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
  789. int i;
  790. BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
  791. sizeof(bcn_info->tim_info.tim_bitmap));
  792. for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
  793. __le32 t = bcn_info->tim_info.tim_bitmap[i / 4];
  794. u32 v = __le32_to_cpu(t);
  795. arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
  796. }
  797. /* FW reports either length 0 or 16
  798. * so we calculate this on our own */
  799. arvif->u.ap.tim_len = 0;
  800. for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
  801. if (arvif->u.ap.tim_bitmap[i])
  802. arvif->u.ap.tim_len = i;
  803. arvif->u.ap.tim_len++;
  804. }
  805. ies = bcn->data;
  806. ies += ieee80211_hdrlen(hdr->frame_control);
  807. ies += 12; /* fixed parameters */
  808. ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
  809. (u8 *)skb_tail_pointer(bcn) - ies);
  810. if (!ie) {
  811. if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  812. ath10k_warn("no tim ie found;\n");
  813. return;
  814. }
  815. tim = (void *)ie + 2;
  816. ie_len = ie[1];
  817. pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
  818. if (pvm_len < arvif->u.ap.tim_len) {
  819. int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
  820. int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
  821. void *next_ie = ie + 2 + ie_len;
  822. if (skb_put(bcn, expand_size)) {
  823. memmove(next_ie + expand_size, next_ie, move_size);
  824. ie[1] += expand_size;
  825. ie_len += expand_size;
  826. pvm_len += expand_size;
  827. } else {
  828. ath10k_warn("tim expansion failed\n");
  829. }
  830. }
  831. if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
  832. ath10k_warn("tim pvm length is too great (%d)\n", pvm_len);
  833. return;
  834. }
  835. tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
  836. memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
  837. ath10k_dbg(ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
  838. tim->dtim_count, tim->dtim_period,
  839. tim->bitmap_ctrl, pvm_len);
  840. }
  841. static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
  842. struct wmi_p2p_noa_info *noa)
  843. {
  844. struct ieee80211_p2p_noa_attr *noa_attr;
  845. u8 ctwindow_oppps = noa->ctwindow_oppps;
  846. u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
  847. bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
  848. __le16 *noa_attr_len;
  849. u16 attr_len;
  850. u8 noa_descriptors = noa->num_descriptors;
  851. int i;
  852. /* P2P IE */
  853. data[0] = WLAN_EID_VENDOR_SPECIFIC;
  854. data[1] = len - 2;
  855. data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
  856. data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
  857. data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
  858. data[5] = WLAN_OUI_TYPE_WFA_P2P;
  859. /* NOA ATTR */
  860. data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
  861. noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
  862. noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
  863. noa_attr->index = noa->index;
  864. noa_attr->oppps_ctwindow = ctwindow;
  865. if (oppps)
  866. noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
  867. for (i = 0; i < noa_descriptors; i++) {
  868. noa_attr->desc[i].count =
  869. __le32_to_cpu(noa->descriptors[i].type_count);
  870. noa_attr->desc[i].duration = noa->descriptors[i].duration;
  871. noa_attr->desc[i].interval = noa->descriptors[i].interval;
  872. noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
  873. }
  874. attr_len = 2; /* index + oppps_ctwindow */
  875. attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
  876. *noa_attr_len = __cpu_to_le16(attr_len);
  877. }
  878. static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
  879. {
  880. u32 len = 0;
  881. u8 noa_descriptors = noa->num_descriptors;
  882. u8 opp_ps_info = noa->ctwindow_oppps;
  883. bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
  884. if (!noa_descriptors && !opps_enabled)
  885. return len;
  886. len += 1 + 1 + 4; /* EID + len + OUI */
  887. len += 1 + 2; /* noa attr + attr len */
  888. len += 1 + 1; /* index + oppps_ctwindow */
  889. len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
  890. return len;
  891. }
  892. static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
  893. struct sk_buff *bcn,
  894. struct wmi_bcn_info *bcn_info)
  895. {
  896. struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
  897. u8 *new_data, *old_data = arvif->u.ap.noa_data;
  898. u32 new_len;
  899. if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
  900. return;
  901. ath10k_dbg(ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
  902. if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
  903. new_len = ath10k_p2p_calc_noa_ie_len(noa);
  904. if (!new_len)
  905. goto cleanup;
  906. new_data = kmalloc(new_len, GFP_ATOMIC);
  907. if (!new_data)
  908. goto cleanup;
  909. ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
  910. spin_lock_bh(&ar->data_lock);
  911. arvif->u.ap.noa_data = new_data;
  912. arvif->u.ap.noa_len = new_len;
  913. spin_unlock_bh(&ar->data_lock);
  914. kfree(old_data);
  915. }
  916. if (arvif->u.ap.noa_data)
  917. if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
  918. memcpy(skb_put(bcn, arvif->u.ap.noa_len),
  919. arvif->u.ap.noa_data,
  920. arvif->u.ap.noa_len);
  921. return;
  922. cleanup:
  923. spin_lock_bh(&ar->data_lock);
  924. arvif->u.ap.noa_data = NULL;
  925. arvif->u.ap.noa_len = 0;
  926. spin_unlock_bh(&ar->data_lock);
  927. kfree(old_data);
  928. }
  929. static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
  930. {
  931. struct wmi_host_swba_event *ev;
  932. u32 map;
  933. int i = -1;
  934. struct wmi_bcn_info *bcn_info;
  935. struct ath10k_vif *arvif;
  936. struct sk_buff *bcn;
  937. int vdev_id = 0;
  938. ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n");
  939. ev = (struct wmi_host_swba_event *)skb->data;
  940. map = __le32_to_cpu(ev->vdev_map);
  941. ath10k_dbg(ATH10K_DBG_MGMT, "host swba:\n"
  942. "-vdev map 0x%x\n",
  943. ev->vdev_map);
  944. for (; map; map >>= 1, vdev_id++) {
  945. if (!(map & 0x1))
  946. continue;
  947. i++;
  948. if (i >= WMI_MAX_AP_VDEV) {
  949. ath10k_warn("swba has corrupted vdev map\n");
  950. break;
  951. }
  952. bcn_info = &ev->bcn_info[i];
  953. ath10k_dbg(ATH10K_DBG_MGMT,
  954. "-bcn_info[%d]:\n"
  955. "--tim_len %d\n"
  956. "--tim_mcast %d\n"
  957. "--tim_changed %d\n"
  958. "--tim_num_ps_pending %d\n"
  959. "--tim_bitmap 0x%08x%08x%08x%08x\n",
  960. i,
  961. __le32_to_cpu(bcn_info->tim_info.tim_len),
  962. __le32_to_cpu(bcn_info->tim_info.tim_mcast),
  963. __le32_to_cpu(bcn_info->tim_info.tim_changed),
  964. __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
  965. __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
  966. __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
  967. __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
  968. __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
  969. arvif = ath10k_get_arvif(ar, vdev_id);
  970. if (arvif == NULL) {
  971. ath10k_warn("no vif for vdev_id %d found\n", vdev_id);
  972. continue;
  973. }
  974. bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
  975. if (!bcn) {
  976. ath10k_warn("could not get mac80211 beacon\n");
  977. continue;
  978. }
  979. ath10k_tx_h_seq_no(bcn);
  980. ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
  981. ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
  982. spin_lock_bh(&ar->data_lock);
  983. if (arvif->beacon) {
  984. ath10k_warn("SWBA overrun on vdev %d\n",
  985. arvif->vdev_id);
  986. dev_kfree_skb_any(arvif->beacon);
  987. }
  988. arvif->beacon = bcn;
  989. ath10k_wmi_tx_beacon_nowait(arvif);
  990. spin_unlock_bh(&ar->data_lock);
  991. }
  992. }
  993. static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
  994. struct sk_buff *skb)
  995. {
  996. ath10k_dbg(ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
  997. }
  998. static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
  999. {
  1000. ath10k_dbg(ATH10K_DBG_WMI, "WMI_PHYERR_EVENTID\n");
  1001. }
  1002. static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
  1003. {
  1004. ath10k_dbg(ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
  1005. }
  1006. static void ath10k_wmi_event_profile_match(struct ath10k *ar,
  1007. struct sk_buff *skb)
  1008. {
  1009. ath10k_dbg(ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
  1010. }
  1011. static void ath10k_wmi_event_debug_print(struct ath10k *ar,
  1012. struct sk_buff *skb)
  1013. {
  1014. ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_PRINT_EVENTID\n");
  1015. }
  1016. static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
  1017. {
  1018. ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
  1019. }
  1020. static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
  1021. struct sk_buff *skb)
  1022. {
  1023. ath10k_dbg(ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
  1024. }
  1025. static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
  1026. struct sk_buff *skb)
  1027. {
  1028. ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
  1029. }
  1030. static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
  1031. struct sk_buff *skb)
  1032. {
  1033. ath10k_dbg(ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
  1034. }
  1035. static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
  1036. struct sk_buff *skb)
  1037. {
  1038. ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
  1039. }
  1040. static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
  1041. struct sk_buff *skb)
  1042. {
  1043. ath10k_dbg(ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
  1044. }
  1045. static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
  1046. struct sk_buff *skb)
  1047. {
  1048. ath10k_dbg(ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
  1049. }
  1050. static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
  1051. struct sk_buff *skb)
  1052. {
  1053. ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
  1054. }
  1055. static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
  1056. struct sk_buff *skb)
  1057. {
  1058. ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
  1059. }
  1060. static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
  1061. struct sk_buff *skb)
  1062. {
  1063. ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
  1064. }
  1065. static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
  1066. struct sk_buff *skb)
  1067. {
  1068. ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
  1069. }
  1070. static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
  1071. struct sk_buff *skb)
  1072. {
  1073. ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
  1074. }
  1075. static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
  1076. struct sk_buff *skb)
  1077. {
  1078. ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
  1079. }
  1080. static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
  1081. struct sk_buff *skb)
  1082. {
  1083. ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
  1084. }
  1085. static void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar,
  1086. struct sk_buff *skb)
  1087. {
  1088. ath10k_dbg(ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
  1089. }
  1090. static void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar,
  1091. struct sk_buff *skb)
  1092. {
  1093. ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
  1094. }
  1095. static void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar,
  1096. struct sk_buff *skb)
  1097. {
  1098. ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
  1099. }
  1100. static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
  1101. u32 num_units, u32 unit_len)
  1102. {
  1103. dma_addr_t paddr;
  1104. u32 pool_size;
  1105. int idx = ar->wmi.num_mem_chunks;
  1106. pool_size = num_units * round_up(unit_len, 4);
  1107. if (!pool_size)
  1108. return -EINVAL;
  1109. ar->wmi.mem_chunks[idx].vaddr = dma_alloc_coherent(ar->dev,
  1110. pool_size,
  1111. &paddr,
  1112. GFP_ATOMIC);
  1113. if (!ar->wmi.mem_chunks[idx].vaddr) {
  1114. ath10k_warn("failed to allocate memory chunk\n");
  1115. return -ENOMEM;
  1116. }
  1117. memset(ar->wmi.mem_chunks[idx].vaddr, 0, pool_size);
  1118. ar->wmi.mem_chunks[idx].paddr = paddr;
  1119. ar->wmi.mem_chunks[idx].len = pool_size;
  1120. ar->wmi.mem_chunks[idx].req_id = req_id;
  1121. ar->wmi.num_mem_chunks++;
  1122. return 0;
  1123. }
  1124. static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
  1125. struct sk_buff *skb)
  1126. {
  1127. struct wmi_service_ready_event *ev = (void *)skb->data;
  1128. if (skb->len < sizeof(*ev)) {
  1129. ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
  1130. skb->len, sizeof(*ev));
  1131. return;
  1132. }
  1133. ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
  1134. ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
  1135. ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
  1136. ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
  1137. ar->fw_version_major =
  1138. (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
  1139. ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
  1140. ar->fw_version_release =
  1141. (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
  1142. ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
  1143. ar->phy_capability = __le32_to_cpu(ev->phy_capability);
  1144. ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
  1145. if (ar->fw_version_build > 636)
  1146. set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
  1147. if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
  1148. ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
  1149. ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
  1150. ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
  1151. }
  1152. ar->ath_common.regulatory.current_rd =
  1153. __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
  1154. ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
  1155. sizeof(ev->wmi_service_bitmap));
  1156. if (strlen(ar->hw->wiphy->fw_version) == 0) {
  1157. snprintf(ar->hw->wiphy->fw_version,
  1158. sizeof(ar->hw->wiphy->fw_version),
  1159. "%u.%u.%u.%u",
  1160. ar->fw_version_major,
  1161. ar->fw_version_minor,
  1162. ar->fw_version_release,
  1163. ar->fw_version_build);
  1164. }
  1165. /* FIXME: it probably should be better to support this */
  1166. if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
  1167. ath10k_warn("target requested %d memory chunks; ignoring\n",
  1168. __le32_to_cpu(ev->num_mem_reqs));
  1169. }
  1170. ath10k_dbg(ATH10K_DBG_WMI,
  1171. "wmi event service ready sw_ver 0x%08x sw_ver1 0x%08x abi_ver %u phy_cap 0x%08x ht_cap 0x%08x vht_cap 0x%08x vht_supp_msc 0x%08x sys_cap_info 0x%08x mem_reqs %u num_rf_chains %u\n",
  1172. __le32_to_cpu(ev->sw_version),
  1173. __le32_to_cpu(ev->sw_version_1),
  1174. __le32_to_cpu(ev->abi_version),
  1175. __le32_to_cpu(ev->phy_capability),
  1176. __le32_to_cpu(ev->ht_cap_info),
  1177. __le32_to_cpu(ev->vht_cap_info),
  1178. __le32_to_cpu(ev->vht_supp_mcs),
  1179. __le32_to_cpu(ev->sys_cap_info),
  1180. __le32_to_cpu(ev->num_mem_reqs),
  1181. __le32_to_cpu(ev->num_rf_chains));
  1182. complete(&ar->wmi.service_ready);
  1183. }
  1184. static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
  1185. struct sk_buff *skb)
  1186. {
  1187. u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
  1188. int ret;
  1189. struct wmi_service_ready_event_10x *ev = (void *)skb->data;
  1190. if (skb->len < sizeof(*ev)) {
  1191. ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
  1192. skb->len, sizeof(*ev));
  1193. return;
  1194. }
  1195. ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
  1196. ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
  1197. ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
  1198. ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
  1199. ar->fw_version_major =
  1200. (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
  1201. ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
  1202. ar->phy_capability = __le32_to_cpu(ev->phy_capability);
  1203. ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
  1204. if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
  1205. ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
  1206. ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
  1207. ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
  1208. }
  1209. ar->ath_common.regulatory.current_rd =
  1210. __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
  1211. ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
  1212. sizeof(ev->wmi_service_bitmap));
  1213. if (strlen(ar->hw->wiphy->fw_version) == 0) {
  1214. snprintf(ar->hw->wiphy->fw_version,
  1215. sizeof(ar->hw->wiphy->fw_version),
  1216. "%u.%u",
  1217. ar->fw_version_major,
  1218. ar->fw_version_minor);
  1219. }
  1220. num_mem_reqs = __le32_to_cpu(ev->num_mem_reqs);
  1221. if (num_mem_reqs > ATH10K_MAX_MEM_REQS) {
  1222. ath10k_warn("requested memory chunks number (%d) exceeds the limit\n",
  1223. num_mem_reqs);
  1224. return;
  1225. }
  1226. if (!num_mem_reqs)
  1227. goto exit;
  1228. ath10k_dbg(ATH10K_DBG_WMI, "firmware has requested %d memory chunks\n",
  1229. num_mem_reqs);
  1230. for (i = 0; i < num_mem_reqs; ++i) {
  1231. req_id = __le32_to_cpu(ev->mem_reqs[i].req_id);
  1232. num_units = __le32_to_cpu(ev->mem_reqs[i].num_units);
  1233. unit_size = __le32_to_cpu(ev->mem_reqs[i].unit_size);
  1234. num_unit_info = __le32_to_cpu(ev->mem_reqs[i].num_unit_info);
  1235. if (num_unit_info & NUM_UNITS_IS_NUM_PEERS)
  1236. /* number of units to allocate is number of
  1237. * peers, 1 extra for self peer on target */
  1238. /* this needs to be tied, host and target
  1239. * can get out of sync */
  1240. num_units = TARGET_NUM_PEERS + 1;
  1241. else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS)
  1242. num_units = TARGET_NUM_VDEVS + 1;
  1243. ath10k_dbg(ATH10K_DBG_WMI,
  1244. "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
  1245. req_id,
  1246. __le32_to_cpu(ev->mem_reqs[i].num_units),
  1247. num_unit_info,
  1248. unit_size,
  1249. num_units);
  1250. ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
  1251. unit_size);
  1252. if (ret)
  1253. return;
  1254. }
  1255. exit:
  1256. ath10k_dbg(ATH10K_DBG_WMI,
  1257. "wmi event service ready sw_ver 0x%08x abi_ver %u phy_cap 0x%08x ht_cap 0x%08x vht_cap 0x%08x vht_supp_msc 0x%08x sys_cap_info 0x%08x mem_reqs %u num_rf_chains %u\n",
  1258. __le32_to_cpu(ev->sw_version),
  1259. __le32_to_cpu(ev->abi_version),
  1260. __le32_to_cpu(ev->phy_capability),
  1261. __le32_to_cpu(ev->ht_cap_info),
  1262. __le32_to_cpu(ev->vht_cap_info),
  1263. __le32_to_cpu(ev->vht_supp_mcs),
  1264. __le32_to_cpu(ev->sys_cap_info),
  1265. __le32_to_cpu(ev->num_mem_reqs),
  1266. __le32_to_cpu(ev->num_rf_chains));
  1267. complete(&ar->wmi.service_ready);
  1268. }
  1269. static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
  1270. {
  1271. struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
  1272. if (WARN_ON(skb->len < sizeof(*ev)))
  1273. return -EINVAL;
  1274. memcpy(ar->mac_addr, ev->mac_addr.addr, ETH_ALEN);
  1275. ath10k_dbg(ATH10K_DBG_WMI,
  1276. "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d\n",
  1277. __le32_to_cpu(ev->sw_version),
  1278. __le32_to_cpu(ev->abi_version),
  1279. ev->mac_addr.addr,
  1280. __le32_to_cpu(ev->status));
  1281. complete(&ar->wmi.unified_ready);
  1282. return 0;
  1283. }
  1284. static void ath10k_wmi_main_process_rx(struct ath10k *ar, struct sk_buff *skb)
  1285. {
  1286. struct wmi_cmd_hdr *cmd_hdr;
  1287. enum wmi_event_id id;
  1288. u16 len;
  1289. cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
  1290. id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
  1291. if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
  1292. return;
  1293. len = skb->len;
  1294. trace_ath10k_wmi_event(id, skb->data, skb->len);
  1295. switch (id) {
  1296. case WMI_MGMT_RX_EVENTID:
  1297. ath10k_wmi_event_mgmt_rx(ar, skb);
  1298. /* mgmt_rx() owns the skb now! */
  1299. return;
  1300. case WMI_SCAN_EVENTID:
  1301. ath10k_wmi_event_scan(ar, skb);
  1302. break;
  1303. case WMI_CHAN_INFO_EVENTID:
  1304. ath10k_wmi_event_chan_info(ar, skb);
  1305. break;
  1306. case WMI_ECHO_EVENTID:
  1307. ath10k_wmi_event_echo(ar, skb);
  1308. break;
  1309. case WMI_DEBUG_MESG_EVENTID:
  1310. ath10k_wmi_event_debug_mesg(ar, skb);
  1311. break;
  1312. case WMI_UPDATE_STATS_EVENTID:
  1313. ath10k_wmi_event_update_stats(ar, skb);
  1314. break;
  1315. case WMI_VDEV_START_RESP_EVENTID:
  1316. ath10k_wmi_event_vdev_start_resp(ar, skb);
  1317. break;
  1318. case WMI_VDEV_STOPPED_EVENTID:
  1319. ath10k_wmi_event_vdev_stopped(ar, skb);
  1320. break;
  1321. case WMI_PEER_STA_KICKOUT_EVENTID:
  1322. ath10k_wmi_event_peer_sta_kickout(ar, skb);
  1323. break;
  1324. case WMI_HOST_SWBA_EVENTID:
  1325. ath10k_wmi_event_host_swba(ar, skb);
  1326. break;
  1327. case WMI_TBTTOFFSET_UPDATE_EVENTID:
  1328. ath10k_wmi_event_tbttoffset_update(ar, skb);
  1329. break;
  1330. case WMI_PHYERR_EVENTID:
  1331. ath10k_wmi_event_phyerr(ar, skb);
  1332. break;
  1333. case WMI_ROAM_EVENTID:
  1334. ath10k_wmi_event_roam(ar, skb);
  1335. break;
  1336. case WMI_PROFILE_MATCH:
  1337. ath10k_wmi_event_profile_match(ar, skb);
  1338. break;
  1339. case WMI_DEBUG_PRINT_EVENTID:
  1340. ath10k_wmi_event_debug_print(ar, skb);
  1341. break;
  1342. case WMI_PDEV_QVIT_EVENTID:
  1343. ath10k_wmi_event_pdev_qvit(ar, skb);
  1344. break;
  1345. case WMI_WLAN_PROFILE_DATA_EVENTID:
  1346. ath10k_wmi_event_wlan_profile_data(ar, skb);
  1347. break;
  1348. case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
  1349. ath10k_wmi_event_rtt_measurement_report(ar, skb);
  1350. break;
  1351. case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
  1352. ath10k_wmi_event_tsf_measurement_report(ar, skb);
  1353. break;
  1354. case WMI_RTT_ERROR_REPORT_EVENTID:
  1355. ath10k_wmi_event_rtt_error_report(ar, skb);
  1356. break;
  1357. case WMI_WOW_WAKEUP_HOST_EVENTID:
  1358. ath10k_wmi_event_wow_wakeup_host(ar, skb);
  1359. break;
  1360. case WMI_DCS_INTERFERENCE_EVENTID:
  1361. ath10k_wmi_event_dcs_interference(ar, skb);
  1362. break;
  1363. case WMI_PDEV_TPC_CONFIG_EVENTID:
  1364. ath10k_wmi_event_pdev_tpc_config(ar, skb);
  1365. break;
  1366. case WMI_PDEV_FTM_INTG_EVENTID:
  1367. ath10k_wmi_event_pdev_ftm_intg(ar, skb);
  1368. break;
  1369. case WMI_GTK_OFFLOAD_STATUS_EVENTID:
  1370. ath10k_wmi_event_gtk_offload_status(ar, skb);
  1371. break;
  1372. case WMI_GTK_REKEY_FAIL_EVENTID:
  1373. ath10k_wmi_event_gtk_rekey_fail(ar, skb);
  1374. break;
  1375. case WMI_TX_DELBA_COMPLETE_EVENTID:
  1376. ath10k_wmi_event_delba_complete(ar, skb);
  1377. break;
  1378. case WMI_TX_ADDBA_COMPLETE_EVENTID:
  1379. ath10k_wmi_event_addba_complete(ar, skb);
  1380. break;
  1381. case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
  1382. ath10k_wmi_event_vdev_install_key_complete(ar, skb);
  1383. break;
  1384. case WMI_SERVICE_READY_EVENTID:
  1385. ath10k_wmi_service_ready_event_rx(ar, skb);
  1386. break;
  1387. case WMI_READY_EVENTID:
  1388. ath10k_wmi_ready_event_rx(ar, skb);
  1389. break;
  1390. default:
  1391. ath10k_warn("Unknown eventid: %d\n", id);
  1392. break;
  1393. }
  1394. dev_kfree_skb(skb);
  1395. }
  1396. static void ath10k_wmi_10x_process_rx(struct ath10k *ar, struct sk_buff *skb)
  1397. {
  1398. struct wmi_cmd_hdr *cmd_hdr;
  1399. enum wmi_10x_event_id id;
  1400. u16 len;
  1401. cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
  1402. id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
  1403. if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
  1404. return;
  1405. len = skb->len;
  1406. trace_ath10k_wmi_event(id, skb->data, skb->len);
  1407. switch (id) {
  1408. case WMI_10X_MGMT_RX_EVENTID:
  1409. ath10k_wmi_event_mgmt_rx(ar, skb);
  1410. /* mgmt_rx() owns the skb now! */
  1411. return;
  1412. case WMI_10X_SCAN_EVENTID:
  1413. ath10k_wmi_event_scan(ar, skb);
  1414. break;
  1415. case WMI_10X_CHAN_INFO_EVENTID:
  1416. ath10k_wmi_event_chan_info(ar, skb);
  1417. break;
  1418. case WMI_10X_ECHO_EVENTID:
  1419. ath10k_wmi_event_echo(ar, skb);
  1420. break;
  1421. case WMI_10X_DEBUG_MESG_EVENTID:
  1422. ath10k_wmi_event_debug_mesg(ar, skb);
  1423. break;
  1424. case WMI_10X_UPDATE_STATS_EVENTID:
  1425. ath10k_wmi_event_update_stats(ar, skb);
  1426. break;
  1427. case WMI_10X_VDEV_START_RESP_EVENTID:
  1428. ath10k_wmi_event_vdev_start_resp(ar, skb);
  1429. break;
  1430. case WMI_10X_VDEV_STOPPED_EVENTID:
  1431. ath10k_wmi_event_vdev_stopped(ar, skb);
  1432. break;
  1433. case WMI_10X_PEER_STA_KICKOUT_EVENTID:
  1434. ath10k_wmi_event_peer_sta_kickout(ar, skb);
  1435. break;
  1436. case WMI_10X_HOST_SWBA_EVENTID:
  1437. ath10k_wmi_event_host_swba(ar, skb);
  1438. break;
  1439. case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
  1440. ath10k_wmi_event_tbttoffset_update(ar, skb);
  1441. break;
  1442. case WMI_10X_PHYERR_EVENTID:
  1443. ath10k_wmi_event_phyerr(ar, skb);
  1444. break;
  1445. case WMI_10X_ROAM_EVENTID:
  1446. ath10k_wmi_event_roam(ar, skb);
  1447. break;
  1448. case WMI_10X_PROFILE_MATCH:
  1449. ath10k_wmi_event_profile_match(ar, skb);
  1450. break;
  1451. case WMI_10X_DEBUG_PRINT_EVENTID:
  1452. ath10k_wmi_event_debug_print(ar, skb);
  1453. break;
  1454. case WMI_10X_PDEV_QVIT_EVENTID:
  1455. ath10k_wmi_event_pdev_qvit(ar, skb);
  1456. break;
  1457. case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
  1458. ath10k_wmi_event_wlan_profile_data(ar, skb);
  1459. break;
  1460. case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
  1461. ath10k_wmi_event_rtt_measurement_report(ar, skb);
  1462. break;
  1463. case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
  1464. ath10k_wmi_event_tsf_measurement_report(ar, skb);
  1465. break;
  1466. case WMI_10X_RTT_ERROR_REPORT_EVENTID:
  1467. ath10k_wmi_event_rtt_error_report(ar, skb);
  1468. break;
  1469. case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
  1470. ath10k_wmi_event_wow_wakeup_host(ar, skb);
  1471. break;
  1472. case WMI_10X_DCS_INTERFERENCE_EVENTID:
  1473. ath10k_wmi_event_dcs_interference(ar, skb);
  1474. break;
  1475. case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
  1476. ath10k_wmi_event_pdev_tpc_config(ar, skb);
  1477. break;
  1478. case WMI_10X_INST_RSSI_STATS_EVENTID:
  1479. ath10k_wmi_event_inst_rssi_stats(ar, skb);
  1480. break;
  1481. case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
  1482. ath10k_wmi_event_vdev_standby_req(ar, skb);
  1483. break;
  1484. case WMI_10X_VDEV_RESUME_REQ_EVENTID:
  1485. ath10k_wmi_event_vdev_resume_req(ar, skb);
  1486. break;
  1487. case WMI_10X_SERVICE_READY_EVENTID:
  1488. ath10k_wmi_10x_service_ready_event_rx(ar, skb);
  1489. break;
  1490. case WMI_10X_READY_EVENTID:
  1491. ath10k_wmi_ready_event_rx(ar, skb);
  1492. break;
  1493. default:
  1494. ath10k_warn("Unknown eventid: %d\n", id);
  1495. break;
  1496. }
  1497. dev_kfree_skb(skb);
  1498. }
  1499. static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
  1500. {
  1501. if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
  1502. ath10k_wmi_10x_process_rx(ar, skb);
  1503. else
  1504. ath10k_wmi_main_process_rx(ar, skb);
  1505. }
  1506. /* WMI Initialization functions */
  1507. int ath10k_wmi_attach(struct ath10k *ar)
  1508. {
  1509. int ret;
  1510. if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
  1511. ath10k_warn("Firmware 10.X is not yet supported\n");
  1512. ar->wmi.cmd = &wmi_10x_cmd_map;
  1513. ret = -ENOTSUPP;
  1514. } else {
  1515. ar->wmi.cmd = &wmi_cmd_map;
  1516. ret = 0;
  1517. }
  1518. init_completion(&ar->wmi.service_ready);
  1519. init_completion(&ar->wmi.unified_ready);
  1520. init_waitqueue_head(&ar->wmi.tx_credits_wq);
  1521. return ret;
  1522. }
  1523. void ath10k_wmi_detach(struct ath10k *ar)
  1524. {
  1525. int i;
  1526. /* free the host memory chunks requested by firmware */
  1527. for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
  1528. dma_free_coherent(ar->dev,
  1529. ar->wmi.mem_chunks[i].len,
  1530. ar->wmi.mem_chunks[i].vaddr,
  1531. ar->wmi.mem_chunks[i].paddr);
  1532. }
  1533. ar->wmi.num_mem_chunks = 0;
  1534. }
  1535. int ath10k_wmi_connect_htc_service(struct ath10k *ar)
  1536. {
  1537. int status;
  1538. struct ath10k_htc_svc_conn_req conn_req;
  1539. struct ath10k_htc_svc_conn_resp conn_resp;
  1540. memset(&conn_req, 0, sizeof(conn_req));
  1541. memset(&conn_resp, 0, sizeof(conn_resp));
  1542. /* these fields are the same for all service endpoints */
  1543. conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
  1544. conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
  1545. conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
  1546. /* connect to control service */
  1547. conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
  1548. status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
  1549. if (status) {
  1550. ath10k_warn("failed to connect to WMI CONTROL service status: %d\n",
  1551. status);
  1552. return status;
  1553. }
  1554. ar->wmi.eid = conn_resp.eid;
  1555. return 0;
  1556. }
  1557. int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
  1558. u16 rd5g, u16 ctl2g, u16 ctl5g)
  1559. {
  1560. struct wmi_pdev_set_regdomain_cmd *cmd;
  1561. struct sk_buff *skb;
  1562. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1563. if (!skb)
  1564. return -ENOMEM;
  1565. cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
  1566. cmd->reg_domain = __cpu_to_le32(rd);
  1567. cmd->reg_domain_2G = __cpu_to_le32(rd2g);
  1568. cmd->reg_domain_5G = __cpu_to_le32(rd5g);
  1569. cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
  1570. cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
  1571. ath10k_dbg(ATH10K_DBG_WMI,
  1572. "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
  1573. rd, rd2g, rd5g, ctl2g, ctl5g);
  1574. return ath10k_wmi_cmd_send(ar, skb,
  1575. ar->wmi.cmd->pdev_set_regdomain_cmdid);
  1576. }
  1577. int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
  1578. const struct wmi_channel_arg *arg)
  1579. {
  1580. struct wmi_set_channel_cmd *cmd;
  1581. struct sk_buff *skb;
  1582. if (arg->passive)
  1583. return -EINVAL;
  1584. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1585. if (!skb)
  1586. return -ENOMEM;
  1587. cmd = (struct wmi_set_channel_cmd *)skb->data;
  1588. cmd->chan.mhz = __cpu_to_le32(arg->freq);
  1589. cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
  1590. cmd->chan.mode = arg->mode;
  1591. cmd->chan.min_power = arg->min_power;
  1592. cmd->chan.max_power = arg->max_power;
  1593. cmd->chan.reg_power = arg->max_reg_power;
  1594. cmd->chan.reg_classid = arg->reg_class_id;
  1595. cmd->chan.antenna_max = arg->max_antenna_gain;
  1596. ath10k_dbg(ATH10K_DBG_WMI,
  1597. "wmi set channel mode %d freq %d\n",
  1598. arg->mode, arg->freq);
  1599. return ath10k_wmi_cmd_send(ar, skb,
  1600. ar->wmi.cmd->pdev_set_channel_cmdid);
  1601. }
  1602. int ath10k_wmi_pdev_suspend_target(struct ath10k *ar)
  1603. {
  1604. struct wmi_pdev_suspend_cmd *cmd;
  1605. struct sk_buff *skb;
  1606. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1607. if (!skb)
  1608. return -ENOMEM;
  1609. cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
  1610. cmd->suspend_opt = WMI_PDEV_SUSPEND;
  1611. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_suspend_cmdid);
  1612. }
  1613. int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
  1614. {
  1615. struct sk_buff *skb;
  1616. skb = ath10k_wmi_alloc_skb(0);
  1617. if (skb == NULL)
  1618. return -ENOMEM;
  1619. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_resume_cmdid);
  1620. }
  1621. int ath10k_wmi_pdev_set_param(struct ath10k *ar, enum wmi_pdev_param id,
  1622. u32 value)
  1623. {
  1624. struct wmi_pdev_set_param_cmd *cmd;
  1625. struct sk_buff *skb;
  1626. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1627. if (!skb)
  1628. return -ENOMEM;
  1629. cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
  1630. cmd->param_id = __cpu_to_le32(id);
  1631. cmd->param_value = __cpu_to_le32(value);
  1632. ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
  1633. id, value);
  1634. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid);
  1635. }
  1636. int ath10k_wmi_cmd_init(struct ath10k *ar)
  1637. {
  1638. struct wmi_init_cmd *cmd;
  1639. struct sk_buff *buf;
  1640. struct wmi_resource_config config = {};
  1641. u32 len, val;
  1642. int i;
  1643. config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
  1644. config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
  1645. config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
  1646. config.num_offload_reorder_bufs =
  1647. __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
  1648. config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
  1649. config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
  1650. config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
  1651. config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
  1652. config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
  1653. config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
  1654. config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
  1655. config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
  1656. config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
  1657. config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
  1658. config.scan_max_pending_reqs =
  1659. __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
  1660. config.bmiss_offload_max_vdev =
  1661. __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
  1662. config.roam_offload_max_vdev =
  1663. __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
  1664. config.roam_offload_max_ap_profiles =
  1665. __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
  1666. config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
  1667. config.num_mcast_table_elems =
  1668. __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
  1669. config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
  1670. config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
  1671. config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
  1672. config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
  1673. config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
  1674. val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
  1675. config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
  1676. config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
  1677. config.gtk_offload_max_vdev =
  1678. __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
  1679. config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
  1680. config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
  1681. len = sizeof(*cmd) +
  1682. (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
  1683. buf = ath10k_wmi_alloc_skb(len);
  1684. if (!buf)
  1685. return -ENOMEM;
  1686. cmd = (struct wmi_init_cmd *)buf->data;
  1687. if (ar->wmi.num_mem_chunks == 0) {
  1688. cmd->num_host_mem_chunks = 0;
  1689. goto out;
  1690. }
  1691. ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
  1692. __cpu_to_le32(ar->wmi.num_mem_chunks));
  1693. cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
  1694. for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
  1695. cmd->host_mem_chunks[i].ptr =
  1696. __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
  1697. cmd->host_mem_chunks[i].size =
  1698. __cpu_to_le32(ar->wmi.mem_chunks[i].len);
  1699. cmd->host_mem_chunks[i].req_id =
  1700. __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
  1701. ath10k_dbg(ATH10K_DBG_WMI,
  1702. "wmi chunk %d len %d requested, addr 0x%x\n",
  1703. i,
  1704. cmd->host_mem_chunks[i].size,
  1705. cmd->host_mem_chunks[i].ptr);
  1706. }
  1707. out:
  1708. memcpy(&cmd->resource_config, &config, sizeof(config));
  1709. ath10k_dbg(ATH10K_DBG_WMI, "wmi init\n");
  1710. return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
  1711. }
  1712. static int ath10k_wmi_start_scan_calc_len(const struct wmi_start_scan_arg *arg)
  1713. {
  1714. int len;
  1715. len = sizeof(struct wmi_start_scan_cmd);
  1716. if (arg->ie_len) {
  1717. if (!arg->ie)
  1718. return -EINVAL;
  1719. if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
  1720. return -EINVAL;
  1721. len += sizeof(struct wmi_ie_data);
  1722. len += roundup(arg->ie_len, 4);
  1723. }
  1724. if (arg->n_channels) {
  1725. if (!arg->channels)
  1726. return -EINVAL;
  1727. if (arg->n_channels > ARRAY_SIZE(arg->channels))
  1728. return -EINVAL;
  1729. len += sizeof(struct wmi_chan_list);
  1730. len += sizeof(__le32) * arg->n_channels;
  1731. }
  1732. if (arg->n_ssids) {
  1733. if (!arg->ssids)
  1734. return -EINVAL;
  1735. if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
  1736. return -EINVAL;
  1737. len += sizeof(struct wmi_ssid_list);
  1738. len += sizeof(struct wmi_ssid) * arg->n_ssids;
  1739. }
  1740. if (arg->n_bssids) {
  1741. if (!arg->bssids)
  1742. return -EINVAL;
  1743. if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
  1744. return -EINVAL;
  1745. len += sizeof(struct wmi_bssid_list);
  1746. len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
  1747. }
  1748. return len;
  1749. }
  1750. int ath10k_wmi_start_scan(struct ath10k *ar,
  1751. const struct wmi_start_scan_arg *arg)
  1752. {
  1753. struct wmi_start_scan_cmd *cmd;
  1754. struct sk_buff *skb;
  1755. struct wmi_ie_data *ie;
  1756. struct wmi_chan_list *channels;
  1757. struct wmi_ssid_list *ssids;
  1758. struct wmi_bssid_list *bssids;
  1759. u32 scan_id;
  1760. u32 scan_req_id;
  1761. int off;
  1762. int len = 0;
  1763. int i;
  1764. len = ath10k_wmi_start_scan_calc_len(arg);
  1765. if (len < 0)
  1766. return len; /* len contains error code here */
  1767. skb = ath10k_wmi_alloc_skb(len);
  1768. if (!skb)
  1769. return -ENOMEM;
  1770. scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
  1771. scan_id |= arg->scan_id;
  1772. scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
  1773. scan_req_id |= arg->scan_req_id;
  1774. cmd = (struct wmi_start_scan_cmd *)skb->data;
  1775. cmd->scan_id = __cpu_to_le32(scan_id);
  1776. cmd->scan_req_id = __cpu_to_le32(scan_req_id);
  1777. cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
  1778. cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
  1779. cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
  1780. cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
  1781. cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
  1782. cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
  1783. cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
  1784. cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
  1785. cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
  1786. cmd->idle_time = __cpu_to_le32(arg->idle_time);
  1787. cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
  1788. cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
  1789. cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
  1790. /* TLV list starts after fields included in the struct */
  1791. off = sizeof(*cmd);
  1792. if (arg->n_channels) {
  1793. channels = (void *)skb->data + off;
  1794. channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
  1795. channels->num_chan = __cpu_to_le32(arg->n_channels);
  1796. for (i = 0; i < arg->n_channels; i++)
  1797. channels->channel_list[i] =
  1798. __cpu_to_le32(arg->channels[i]);
  1799. off += sizeof(*channels);
  1800. off += sizeof(__le32) * arg->n_channels;
  1801. }
  1802. if (arg->n_ssids) {
  1803. ssids = (void *)skb->data + off;
  1804. ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
  1805. ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
  1806. for (i = 0; i < arg->n_ssids; i++) {
  1807. ssids->ssids[i].ssid_len =
  1808. __cpu_to_le32(arg->ssids[i].len);
  1809. memcpy(&ssids->ssids[i].ssid,
  1810. arg->ssids[i].ssid,
  1811. arg->ssids[i].len);
  1812. }
  1813. off += sizeof(*ssids);
  1814. off += sizeof(struct wmi_ssid) * arg->n_ssids;
  1815. }
  1816. if (arg->n_bssids) {
  1817. bssids = (void *)skb->data + off;
  1818. bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
  1819. bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
  1820. for (i = 0; i < arg->n_bssids; i++)
  1821. memcpy(&bssids->bssid_list[i],
  1822. arg->bssids[i].bssid,
  1823. ETH_ALEN);
  1824. off += sizeof(*bssids);
  1825. off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
  1826. }
  1827. if (arg->ie_len) {
  1828. ie = (void *)skb->data + off;
  1829. ie->tag = __cpu_to_le32(WMI_IE_TAG);
  1830. ie->ie_len = __cpu_to_le32(arg->ie_len);
  1831. memcpy(ie->ie_data, arg->ie, arg->ie_len);
  1832. off += sizeof(*ie);
  1833. off += roundup(arg->ie_len, 4);
  1834. }
  1835. if (off != skb->len) {
  1836. dev_kfree_skb(skb);
  1837. return -EINVAL;
  1838. }
  1839. ath10k_dbg(ATH10K_DBG_WMI, "wmi start scan\n");
  1840. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->start_scan_cmdid);
  1841. }
  1842. void ath10k_wmi_start_scan_init(struct ath10k *ar,
  1843. struct wmi_start_scan_arg *arg)
  1844. {
  1845. /* setup commonly used values */
  1846. arg->scan_req_id = 1;
  1847. arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
  1848. arg->dwell_time_active = 50;
  1849. arg->dwell_time_passive = 150;
  1850. arg->min_rest_time = 50;
  1851. arg->max_rest_time = 500;
  1852. arg->repeat_probe_time = 0;
  1853. arg->probe_spacing_time = 0;
  1854. arg->idle_time = 0;
  1855. arg->max_scan_time = 5000;
  1856. arg->probe_delay = 5;
  1857. arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
  1858. | WMI_SCAN_EVENT_COMPLETED
  1859. | WMI_SCAN_EVENT_BSS_CHANNEL
  1860. | WMI_SCAN_EVENT_FOREIGN_CHANNEL
  1861. | WMI_SCAN_EVENT_DEQUEUED;
  1862. arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
  1863. arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
  1864. arg->n_bssids = 1;
  1865. arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
  1866. }
  1867. int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
  1868. {
  1869. struct wmi_stop_scan_cmd *cmd;
  1870. struct sk_buff *skb;
  1871. u32 scan_id;
  1872. u32 req_id;
  1873. if (arg->req_id > 0xFFF)
  1874. return -EINVAL;
  1875. if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
  1876. return -EINVAL;
  1877. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1878. if (!skb)
  1879. return -ENOMEM;
  1880. scan_id = arg->u.scan_id;
  1881. scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
  1882. req_id = arg->req_id;
  1883. req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
  1884. cmd = (struct wmi_stop_scan_cmd *)skb->data;
  1885. cmd->req_type = __cpu_to_le32(arg->req_type);
  1886. cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
  1887. cmd->scan_id = __cpu_to_le32(scan_id);
  1888. cmd->scan_req_id = __cpu_to_le32(req_id);
  1889. ath10k_dbg(ATH10K_DBG_WMI,
  1890. "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
  1891. arg->req_id, arg->req_type, arg->u.scan_id);
  1892. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->stop_scan_cmdid);
  1893. }
  1894. int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
  1895. enum wmi_vdev_type type,
  1896. enum wmi_vdev_subtype subtype,
  1897. const u8 macaddr[ETH_ALEN])
  1898. {
  1899. struct wmi_vdev_create_cmd *cmd;
  1900. struct sk_buff *skb;
  1901. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1902. if (!skb)
  1903. return -ENOMEM;
  1904. cmd = (struct wmi_vdev_create_cmd *)skb->data;
  1905. cmd->vdev_id = __cpu_to_le32(vdev_id);
  1906. cmd->vdev_type = __cpu_to_le32(type);
  1907. cmd->vdev_subtype = __cpu_to_le32(subtype);
  1908. memcpy(cmd->vdev_macaddr.addr, macaddr, ETH_ALEN);
  1909. ath10k_dbg(ATH10K_DBG_WMI,
  1910. "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
  1911. vdev_id, type, subtype, macaddr);
  1912. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_create_cmdid);
  1913. }
  1914. int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
  1915. {
  1916. struct wmi_vdev_delete_cmd *cmd;
  1917. struct sk_buff *skb;
  1918. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1919. if (!skb)
  1920. return -ENOMEM;
  1921. cmd = (struct wmi_vdev_delete_cmd *)skb->data;
  1922. cmd->vdev_id = __cpu_to_le32(vdev_id);
  1923. ath10k_dbg(ATH10K_DBG_WMI,
  1924. "WMI vdev delete id %d\n", vdev_id);
  1925. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_delete_cmdid);
  1926. }
  1927. static int ath10k_wmi_vdev_start_restart(struct ath10k *ar,
  1928. const struct wmi_vdev_start_request_arg *arg,
  1929. u32 cmd_id)
  1930. {
  1931. struct wmi_vdev_start_request_cmd *cmd;
  1932. struct sk_buff *skb;
  1933. const char *cmdname;
  1934. u32 flags = 0;
  1935. if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid &&
  1936. cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid)
  1937. return -EINVAL;
  1938. if (WARN_ON(arg->ssid && arg->ssid_len == 0))
  1939. return -EINVAL;
  1940. if (WARN_ON(arg->hidden_ssid && !arg->ssid))
  1941. return -EINVAL;
  1942. if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
  1943. return -EINVAL;
  1944. if (cmd_id == ar->wmi.cmd->vdev_start_request_cmdid)
  1945. cmdname = "start";
  1946. else if (cmd_id == ar->wmi.cmd->vdev_restart_request_cmdid)
  1947. cmdname = "restart";
  1948. else
  1949. return -EINVAL; /* should not happen, we already check cmd_id */
  1950. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  1951. if (!skb)
  1952. return -ENOMEM;
  1953. if (arg->hidden_ssid)
  1954. flags |= WMI_VDEV_START_HIDDEN_SSID;
  1955. if (arg->pmf_enabled)
  1956. flags |= WMI_VDEV_START_PMF_ENABLED;
  1957. cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
  1958. cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
  1959. cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
  1960. cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
  1961. cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
  1962. cmd->flags = __cpu_to_le32(flags);
  1963. cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
  1964. cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
  1965. if (arg->ssid) {
  1966. cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
  1967. memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
  1968. }
  1969. cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
  1970. cmd->chan.band_center_freq1 =
  1971. __cpu_to_le32(arg->channel.band_center_freq1);
  1972. cmd->chan.mode = arg->channel.mode;
  1973. cmd->chan.min_power = arg->channel.min_power;
  1974. cmd->chan.max_power = arg->channel.max_power;
  1975. cmd->chan.reg_power = arg->channel.max_reg_power;
  1976. cmd->chan.reg_classid = arg->channel.reg_class_id;
  1977. cmd->chan.antenna_max = arg->channel.max_antenna_gain;
  1978. ath10k_dbg(ATH10K_DBG_WMI,
  1979. "wmi vdev %s id 0x%x freq %d, mode %d, ch_flags: 0x%0X,"
  1980. "max_power: %d\n", cmdname, arg->vdev_id, arg->channel.freq,
  1981. arg->channel.mode, flags, arg->channel.max_power);
  1982. return ath10k_wmi_cmd_send(ar, skb, cmd_id);
  1983. }
  1984. int ath10k_wmi_vdev_start(struct ath10k *ar,
  1985. const struct wmi_vdev_start_request_arg *arg)
  1986. {
  1987. u32 cmd_id = ar->wmi.cmd->vdev_start_request_cmdid;
  1988. return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
  1989. }
  1990. int ath10k_wmi_vdev_restart(struct ath10k *ar,
  1991. const struct wmi_vdev_start_request_arg *arg)
  1992. {
  1993. u32 cmd_id = ar->wmi.cmd->vdev_restart_request_cmdid;
  1994. return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
  1995. }
  1996. int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
  1997. {
  1998. struct wmi_vdev_stop_cmd *cmd;
  1999. struct sk_buff *skb;
  2000. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2001. if (!skb)
  2002. return -ENOMEM;
  2003. cmd = (struct wmi_vdev_stop_cmd *)skb->data;
  2004. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2005. ath10k_dbg(ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
  2006. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_stop_cmdid);
  2007. }
  2008. int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
  2009. {
  2010. struct wmi_vdev_up_cmd *cmd;
  2011. struct sk_buff *skb;
  2012. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2013. if (!skb)
  2014. return -ENOMEM;
  2015. cmd = (struct wmi_vdev_up_cmd *)skb->data;
  2016. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2017. cmd->vdev_assoc_id = __cpu_to_le32(aid);
  2018. memcpy(&cmd->vdev_bssid.addr, bssid, 6);
  2019. ath10k_dbg(ATH10K_DBG_WMI,
  2020. "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
  2021. vdev_id, aid, bssid);
  2022. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_up_cmdid);
  2023. }
  2024. int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
  2025. {
  2026. struct wmi_vdev_down_cmd *cmd;
  2027. struct sk_buff *skb;
  2028. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2029. if (!skb)
  2030. return -ENOMEM;
  2031. cmd = (struct wmi_vdev_down_cmd *)skb->data;
  2032. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2033. ath10k_dbg(ATH10K_DBG_WMI,
  2034. "wmi mgmt vdev down id 0x%x\n", vdev_id);
  2035. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_down_cmdid);
  2036. }
  2037. int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
  2038. enum wmi_vdev_param param_id, u32 param_value)
  2039. {
  2040. struct wmi_vdev_set_param_cmd *cmd;
  2041. struct sk_buff *skb;
  2042. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2043. if (!skb)
  2044. return -ENOMEM;
  2045. cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
  2046. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2047. cmd->param_id = __cpu_to_le32(param_id);
  2048. cmd->param_value = __cpu_to_le32(param_value);
  2049. ath10k_dbg(ATH10K_DBG_WMI,
  2050. "wmi vdev id 0x%x set param %d value %d\n",
  2051. vdev_id, param_id, param_value);
  2052. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_set_param_cmdid);
  2053. }
  2054. int ath10k_wmi_vdev_install_key(struct ath10k *ar,
  2055. const struct wmi_vdev_install_key_arg *arg)
  2056. {
  2057. struct wmi_vdev_install_key_cmd *cmd;
  2058. struct sk_buff *skb;
  2059. if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
  2060. return -EINVAL;
  2061. if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
  2062. return -EINVAL;
  2063. skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->key_len);
  2064. if (!skb)
  2065. return -ENOMEM;
  2066. cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
  2067. cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
  2068. cmd->key_idx = __cpu_to_le32(arg->key_idx);
  2069. cmd->key_flags = __cpu_to_le32(arg->key_flags);
  2070. cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
  2071. cmd->key_len = __cpu_to_le32(arg->key_len);
  2072. cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
  2073. cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
  2074. if (arg->macaddr)
  2075. memcpy(cmd->peer_macaddr.addr, arg->macaddr, ETH_ALEN);
  2076. if (arg->key_data)
  2077. memcpy(cmd->key_data, arg->key_data, arg->key_len);
  2078. ath10k_dbg(ATH10K_DBG_WMI,
  2079. "wmi vdev install key idx %d cipher %d len %d\n",
  2080. arg->key_idx, arg->key_cipher, arg->key_len);
  2081. return ath10k_wmi_cmd_send(ar, skb,
  2082. ar->wmi.cmd->vdev_install_key_cmdid);
  2083. }
  2084. int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
  2085. const u8 peer_addr[ETH_ALEN])
  2086. {
  2087. struct wmi_peer_create_cmd *cmd;
  2088. struct sk_buff *skb;
  2089. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2090. if (!skb)
  2091. return -ENOMEM;
  2092. cmd = (struct wmi_peer_create_cmd *)skb->data;
  2093. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2094. memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
  2095. ath10k_dbg(ATH10K_DBG_WMI,
  2096. "wmi peer create vdev_id %d peer_addr %pM\n",
  2097. vdev_id, peer_addr);
  2098. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_create_cmdid);
  2099. }
  2100. int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
  2101. const u8 peer_addr[ETH_ALEN])
  2102. {
  2103. struct wmi_peer_delete_cmd *cmd;
  2104. struct sk_buff *skb;
  2105. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2106. if (!skb)
  2107. return -ENOMEM;
  2108. cmd = (struct wmi_peer_delete_cmd *)skb->data;
  2109. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2110. memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
  2111. ath10k_dbg(ATH10K_DBG_WMI,
  2112. "wmi peer delete vdev_id %d peer_addr %pM\n",
  2113. vdev_id, peer_addr);
  2114. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_delete_cmdid);
  2115. }
  2116. int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
  2117. const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
  2118. {
  2119. struct wmi_peer_flush_tids_cmd *cmd;
  2120. struct sk_buff *skb;
  2121. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2122. if (!skb)
  2123. return -ENOMEM;
  2124. cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
  2125. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2126. cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
  2127. memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
  2128. ath10k_dbg(ATH10K_DBG_WMI,
  2129. "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
  2130. vdev_id, peer_addr, tid_bitmap);
  2131. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_flush_tids_cmdid);
  2132. }
  2133. int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
  2134. const u8 *peer_addr, enum wmi_peer_param param_id,
  2135. u32 param_value)
  2136. {
  2137. struct wmi_peer_set_param_cmd *cmd;
  2138. struct sk_buff *skb;
  2139. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2140. if (!skb)
  2141. return -ENOMEM;
  2142. cmd = (struct wmi_peer_set_param_cmd *)skb->data;
  2143. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2144. cmd->param_id = __cpu_to_le32(param_id);
  2145. cmd->param_value = __cpu_to_le32(param_value);
  2146. memcpy(&cmd->peer_macaddr.addr, peer_addr, 6);
  2147. ath10k_dbg(ATH10K_DBG_WMI,
  2148. "wmi vdev %d peer 0x%pM set param %d value %d\n",
  2149. vdev_id, peer_addr, param_id, param_value);
  2150. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_set_param_cmdid);
  2151. }
  2152. int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
  2153. enum wmi_sta_ps_mode psmode)
  2154. {
  2155. struct wmi_sta_powersave_mode_cmd *cmd;
  2156. struct sk_buff *skb;
  2157. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2158. if (!skb)
  2159. return -ENOMEM;
  2160. cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
  2161. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2162. cmd->sta_ps_mode = __cpu_to_le32(psmode);
  2163. ath10k_dbg(ATH10K_DBG_WMI,
  2164. "wmi set powersave id 0x%x mode %d\n",
  2165. vdev_id, psmode);
  2166. return ath10k_wmi_cmd_send(ar, skb,
  2167. ar->wmi.cmd->sta_powersave_mode_cmdid);
  2168. }
  2169. int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
  2170. enum wmi_sta_powersave_param param_id,
  2171. u32 value)
  2172. {
  2173. struct wmi_sta_powersave_param_cmd *cmd;
  2174. struct sk_buff *skb;
  2175. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2176. if (!skb)
  2177. return -ENOMEM;
  2178. cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
  2179. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2180. cmd->param_id = __cpu_to_le32(param_id);
  2181. cmd->param_value = __cpu_to_le32(value);
  2182. ath10k_dbg(ATH10K_DBG_WMI,
  2183. "wmi sta ps param vdev_id 0x%x param %d value %d\n",
  2184. vdev_id, param_id, value);
  2185. return ath10k_wmi_cmd_send(ar, skb,
  2186. ar->wmi.cmd->sta_powersave_param_cmdid);
  2187. }
  2188. int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
  2189. enum wmi_ap_ps_peer_param param_id, u32 value)
  2190. {
  2191. struct wmi_ap_ps_peer_cmd *cmd;
  2192. struct sk_buff *skb;
  2193. if (!mac)
  2194. return -EINVAL;
  2195. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2196. if (!skb)
  2197. return -ENOMEM;
  2198. cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
  2199. cmd->vdev_id = __cpu_to_le32(vdev_id);
  2200. cmd->param_id = __cpu_to_le32(param_id);
  2201. cmd->param_value = __cpu_to_le32(value);
  2202. memcpy(&cmd->peer_macaddr, mac, ETH_ALEN);
  2203. ath10k_dbg(ATH10K_DBG_WMI,
  2204. "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
  2205. vdev_id, param_id, value, mac);
  2206. return ath10k_wmi_cmd_send(ar, skb,
  2207. ar->wmi.cmd->ap_ps_peer_param_cmdid);
  2208. }
  2209. int ath10k_wmi_scan_chan_list(struct ath10k *ar,
  2210. const struct wmi_scan_chan_list_arg *arg)
  2211. {
  2212. struct wmi_scan_chan_list_cmd *cmd;
  2213. struct sk_buff *skb;
  2214. struct wmi_channel_arg *ch;
  2215. struct wmi_channel *ci;
  2216. int len;
  2217. int i;
  2218. len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
  2219. skb = ath10k_wmi_alloc_skb(len);
  2220. if (!skb)
  2221. return -EINVAL;
  2222. cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
  2223. cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
  2224. for (i = 0; i < arg->n_channels; i++) {
  2225. u32 flags = 0;
  2226. ch = &arg->channels[i];
  2227. ci = &cmd->chan_info[i];
  2228. if (ch->passive)
  2229. flags |= WMI_CHAN_FLAG_PASSIVE;
  2230. if (ch->allow_ibss)
  2231. flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
  2232. if (ch->allow_ht)
  2233. flags |= WMI_CHAN_FLAG_ALLOW_HT;
  2234. if (ch->allow_vht)
  2235. flags |= WMI_CHAN_FLAG_ALLOW_VHT;
  2236. if (ch->ht40plus)
  2237. flags |= WMI_CHAN_FLAG_HT40_PLUS;
  2238. ci->mhz = __cpu_to_le32(ch->freq);
  2239. ci->band_center_freq1 = __cpu_to_le32(ch->freq);
  2240. ci->band_center_freq2 = 0;
  2241. ci->min_power = ch->min_power;
  2242. ci->max_power = ch->max_power;
  2243. ci->reg_power = ch->max_reg_power;
  2244. ci->antenna_max = ch->max_antenna_gain;
  2245. ci->antenna_max = 0;
  2246. /* mode & flags share storage */
  2247. ci->mode = ch->mode;
  2248. ci->flags |= __cpu_to_le32(flags);
  2249. }
  2250. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid);
  2251. }
  2252. int ath10k_wmi_peer_assoc(struct ath10k *ar,
  2253. const struct wmi_peer_assoc_complete_arg *arg)
  2254. {
  2255. struct wmi_peer_assoc_complete_cmd *cmd;
  2256. struct sk_buff *skb;
  2257. if (arg->peer_mpdu_density > 16)
  2258. return -EINVAL;
  2259. if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
  2260. return -EINVAL;
  2261. if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
  2262. return -EINVAL;
  2263. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2264. if (!skb)
  2265. return -ENOMEM;
  2266. cmd = (struct wmi_peer_assoc_complete_cmd *)skb->data;
  2267. cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
  2268. cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
  2269. cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
  2270. cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
  2271. cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
  2272. cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
  2273. cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
  2274. cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
  2275. cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
  2276. cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
  2277. cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
  2278. cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
  2279. cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
  2280. memcpy(cmd->peer_macaddr.addr, arg->addr, ETH_ALEN);
  2281. cmd->peer_legacy_rates.num_rates =
  2282. __cpu_to_le32(arg->peer_legacy_rates.num_rates);
  2283. memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
  2284. arg->peer_legacy_rates.num_rates);
  2285. cmd->peer_ht_rates.num_rates =
  2286. __cpu_to_le32(arg->peer_ht_rates.num_rates);
  2287. memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
  2288. arg->peer_ht_rates.num_rates);
  2289. cmd->peer_vht_rates.rx_max_rate =
  2290. __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
  2291. cmd->peer_vht_rates.rx_mcs_set =
  2292. __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
  2293. cmd->peer_vht_rates.tx_max_rate =
  2294. __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
  2295. cmd->peer_vht_rates.tx_mcs_set =
  2296. __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
  2297. ath10k_dbg(ATH10K_DBG_WMI,
  2298. "wmi peer assoc vdev %d addr %pM\n",
  2299. arg->vdev_id, arg->addr);
  2300. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_assoc_cmdid);
  2301. }
  2302. int ath10k_wmi_beacon_send_nowait(struct ath10k *ar,
  2303. const struct wmi_bcn_tx_arg *arg)
  2304. {
  2305. struct wmi_bcn_tx_cmd *cmd;
  2306. struct sk_buff *skb;
  2307. skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->bcn_len);
  2308. if (!skb)
  2309. return -ENOMEM;
  2310. cmd = (struct wmi_bcn_tx_cmd *)skb->data;
  2311. cmd->hdr.vdev_id = __cpu_to_le32(arg->vdev_id);
  2312. cmd->hdr.tx_rate = __cpu_to_le32(arg->tx_rate);
  2313. cmd->hdr.tx_power = __cpu_to_le32(arg->tx_power);
  2314. cmd->hdr.bcn_len = __cpu_to_le32(arg->bcn_len);
  2315. memcpy(cmd->bcn, arg->bcn, arg->bcn_len);
  2316. return ath10k_wmi_cmd_send_nowait(ar, skb, ar->wmi.cmd->bcn_tx_cmdid);
  2317. }
  2318. static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
  2319. const struct wmi_wmm_params_arg *arg)
  2320. {
  2321. params->cwmin = __cpu_to_le32(arg->cwmin);
  2322. params->cwmax = __cpu_to_le32(arg->cwmax);
  2323. params->aifs = __cpu_to_le32(arg->aifs);
  2324. params->txop = __cpu_to_le32(arg->txop);
  2325. params->acm = __cpu_to_le32(arg->acm);
  2326. params->no_ack = __cpu_to_le32(arg->no_ack);
  2327. }
  2328. int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
  2329. const struct wmi_pdev_set_wmm_params_arg *arg)
  2330. {
  2331. struct wmi_pdev_set_wmm_params *cmd;
  2332. struct sk_buff *skb;
  2333. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2334. if (!skb)
  2335. return -ENOMEM;
  2336. cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
  2337. ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
  2338. ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
  2339. ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
  2340. ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
  2341. ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
  2342. return ath10k_wmi_cmd_send(ar, skb,
  2343. ar->wmi.cmd->pdev_set_wmm_params_cmdid);
  2344. }
  2345. int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
  2346. {
  2347. struct wmi_request_stats_cmd *cmd;
  2348. struct sk_buff *skb;
  2349. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2350. if (!skb)
  2351. return -ENOMEM;
  2352. cmd = (struct wmi_request_stats_cmd *)skb->data;
  2353. cmd->stats_id = __cpu_to_le32(stats_id);
  2354. ath10k_dbg(ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
  2355. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->request_stats_cmdid);
  2356. }
  2357. int ath10k_wmi_force_fw_hang(struct ath10k *ar,
  2358. enum wmi_force_fw_hang_type type, u32 delay_ms)
  2359. {
  2360. struct wmi_force_fw_hang_cmd *cmd;
  2361. struct sk_buff *skb;
  2362. skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
  2363. if (!skb)
  2364. return -ENOMEM;
  2365. cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
  2366. cmd->type = __cpu_to_le32(type);
  2367. cmd->delay_ms = __cpu_to_le32(delay_ms);
  2368. ath10k_dbg(ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
  2369. type, delay_ms);
  2370. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
  2371. }