wmi.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854
  1. /*
  2. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  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/moduleparam.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/if_arp.h>
  20. #include "wil6210.h"
  21. #include "txrx.h"
  22. #include "wmi.h"
  23. #include "trace.h"
  24. static uint max_assoc_sta = WIL6210_MAX_CID;
  25. module_param(max_assoc_sta, uint, 0644);
  26. MODULE_PARM_DESC(max_assoc_sta, " Max number of stations associated to the AP");
  27. int agg_wsize; /* = 0; */
  28. module_param(agg_wsize, int, 0644);
  29. MODULE_PARM_DESC(agg_wsize, " Window size for Tx Block Ack after connect;"
  30. " 0 - use default; < 0 - don't auto-establish");
  31. u8 led_id = WIL_LED_INVALID_ID;
  32. module_param(led_id, byte, 0444);
  33. MODULE_PARM_DESC(led_id,
  34. " 60G device led enablement. Set the led ID (0-2) to enable");
  35. #define WIL_WAIT_FOR_SUSPEND_RESUME_COMP 200
  36. #define WIL_WMI_CALL_GENERAL_TO_MS 100
  37. /**
  38. * WMI event receiving - theory of operations
  39. *
  40. * When firmware about to report WMI event, it fills memory area
  41. * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for
  42. * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler.
  43. *
  44. * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the
  45. * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up
  46. * and handles events within the @wmi_event_worker. Every event get detached
  47. * from list, processed and deleted.
  48. *
  49. * Purpose for this mechanism is to release IRQ thread; otherwise,
  50. * if WMI event handling involves another WMI command flow, this 2-nd flow
  51. * won't be completed because of blocked IRQ thread.
  52. */
  53. /**
  54. * Addressing - theory of operations
  55. *
  56. * There are several buses present on the WIL6210 card.
  57. * Same memory areas are visible at different address on
  58. * the different busses. There are 3 main bus masters:
  59. * - MAC CPU (ucode)
  60. * - User CPU (firmware)
  61. * - AHB (host)
  62. *
  63. * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing
  64. * AHB addresses starting from 0x880000
  65. *
  66. * Internally, firmware uses addresses that allow faster access but
  67. * are invisible from the host. To read from these addresses, alternative
  68. * AHB address must be used.
  69. */
  70. /**
  71. * @sparrow_fw_mapping provides memory remapping table for sparrow
  72. *
  73. * array size should be in sync with the declaration in the wil6210.h
  74. *
  75. * Sparrow memory mapping:
  76. * Linker address PCI/Host address
  77. * 0x880000 .. 0xa80000 2Mb BAR0
  78. * 0x800000 .. 0x808000 0x900000 .. 0x908000 32k DCCM
  79. * 0x840000 .. 0x860000 0x908000 .. 0x928000 128k PERIPH
  80. */
  81. const struct fw_map sparrow_fw_mapping[] = {
  82. /* FW code RAM 256k */
  83. {0x000000, 0x040000, 0x8c0000, "fw_code", true},
  84. /* FW data RAM 32k */
  85. {0x800000, 0x808000, 0x900000, "fw_data", true},
  86. /* periph data 128k */
  87. {0x840000, 0x860000, 0x908000, "fw_peri", true},
  88. /* various RGF 40k */
  89. {0x880000, 0x88a000, 0x880000, "rgf", true},
  90. /* AGC table 4k */
  91. {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true},
  92. /* Pcie_ext_rgf 4k */
  93. {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true},
  94. /* mac_ext_rgf 512b */
  95. {0x88c000, 0x88c200, 0x88c000, "mac_rgf_ext", true},
  96. /* upper area 548k */
  97. {0x8c0000, 0x949000, 0x8c0000, "upper", true},
  98. /* UCODE areas - accessible by debugfs blobs but not by
  99. * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas!
  100. */
  101. /* ucode code RAM 128k */
  102. {0x000000, 0x020000, 0x920000, "uc_code", false},
  103. /* ucode data RAM 16k */
  104. {0x800000, 0x804000, 0x940000, "uc_data", false},
  105. };
  106. /**
  107. * @sparrow_d0_mac_rgf_ext - mac_rgf_ext section for Sparrow D0
  108. * it is a bit larger to support extra features
  109. */
  110. const struct fw_map sparrow_d0_mac_rgf_ext = {
  111. 0x88c000, 0x88c500, 0x88c000, "mac_rgf_ext", true
  112. };
  113. /**
  114. * @talyn_fw_mapping provides memory remapping table for Talyn
  115. *
  116. * array size should be in sync with the declaration in the wil6210.h
  117. *
  118. * Talyn memory mapping:
  119. * Linker address PCI/Host address
  120. * 0x880000 .. 0xc80000 4Mb BAR0
  121. * 0x800000 .. 0x820000 0xa00000 .. 0xa20000 128k DCCM
  122. * 0x840000 .. 0x858000 0xa20000 .. 0xa38000 96k PERIPH
  123. */
  124. const struct fw_map talyn_fw_mapping[] = {
  125. /* FW code RAM 1M */
  126. {0x000000, 0x100000, 0x900000, "fw_code", true},
  127. /* FW data RAM 128k */
  128. {0x800000, 0x820000, 0xa00000, "fw_data", true},
  129. /* periph. data RAM 96k */
  130. {0x840000, 0x858000, 0xa20000, "fw_peri", true},
  131. /* various RGF 40k */
  132. {0x880000, 0x88a000, 0x880000, "rgf", true},
  133. /* AGC table 4k */
  134. {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true},
  135. /* Pcie_ext_rgf 4k */
  136. {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true},
  137. /* mac_ext_rgf 1344b */
  138. {0x88c000, 0x88c540, 0x88c000, "mac_rgf_ext", true},
  139. /* ext USER RGF 4k */
  140. {0x88d000, 0x88e000, 0x88d000, "ext_user_rgf", true},
  141. /* OTP 4k */
  142. {0x8a0000, 0x8a1000, 0x8a0000, "otp", true},
  143. /* DMA EXT RGF 64k */
  144. {0x8b0000, 0x8c0000, 0x8b0000, "dma_ext_rgf", true},
  145. /* upper area 1536k */
  146. {0x900000, 0xa80000, 0x900000, "upper", true},
  147. /* UCODE areas - accessible by debugfs blobs but not by
  148. * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas!
  149. */
  150. /* ucode code RAM 256k */
  151. {0x000000, 0x040000, 0xa38000, "uc_code", false},
  152. /* ucode data RAM 32k */
  153. {0x800000, 0x808000, 0xa78000, "uc_data", false},
  154. };
  155. struct fw_map fw_mapping[MAX_FW_MAPPING_TABLE_SIZE];
  156. struct blink_on_off_time led_blink_time[] = {
  157. {WIL_LED_BLINK_ON_SLOW_MS, WIL_LED_BLINK_OFF_SLOW_MS},
  158. {WIL_LED_BLINK_ON_MED_MS, WIL_LED_BLINK_OFF_MED_MS},
  159. {WIL_LED_BLINK_ON_FAST_MS, WIL_LED_BLINK_OFF_FAST_MS},
  160. };
  161. u8 led_polarity = LED_POLARITY_LOW_ACTIVE;
  162. /**
  163. * return AHB address for given firmware internal (linker) address
  164. * @x - internal address
  165. * If address have no valid AHB mapping, return 0
  166. */
  167. static u32 wmi_addr_remap(u32 x)
  168. {
  169. uint i;
  170. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  171. if (fw_mapping[i].fw &&
  172. ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to)))
  173. return x + fw_mapping[i].host - fw_mapping[i].from;
  174. }
  175. return 0;
  176. }
  177. /**
  178. * find fw_mapping entry by section name
  179. * @section - section name
  180. *
  181. * Return pointer to section or NULL if not found
  182. */
  183. struct fw_map *wil_find_fw_mapping(const char *section)
  184. {
  185. int i;
  186. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++)
  187. if (fw_mapping[i].name &&
  188. !strcmp(section, fw_mapping[i].name))
  189. return &fw_mapping[i];
  190. return NULL;
  191. }
  192. /**
  193. * Check address validity for WMI buffer; remap if needed
  194. * @ptr - internal (linker) fw/ucode address
  195. * @size - if non zero, validate the block does not
  196. * exceed the device memory (bar)
  197. *
  198. * Valid buffer should be DWORD aligned
  199. *
  200. * return address for accessing buffer from the host;
  201. * if buffer is not valid, return NULL.
  202. */
  203. void __iomem *wmi_buffer_block(struct wil6210_priv *wil, __le32 ptr_, u32 size)
  204. {
  205. u32 off;
  206. u32 ptr = le32_to_cpu(ptr_);
  207. if (ptr % 4)
  208. return NULL;
  209. ptr = wmi_addr_remap(ptr);
  210. if (ptr < WIL6210_FW_HOST_OFF)
  211. return NULL;
  212. off = HOSTADDR(ptr);
  213. if (off > wil->bar_size - 4)
  214. return NULL;
  215. if (size && ((off + size > wil->bar_size) || (off + size < off)))
  216. return NULL;
  217. return wil->csr + off;
  218. }
  219. void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_)
  220. {
  221. return wmi_buffer_block(wil, ptr_, 0);
  222. }
  223. /**
  224. * Check address validity
  225. */
  226. void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr)
  227. {
  228. u32 off;
  229. if (ptr % 4)
  230. return NULL;
  231. if (ptr < WIL6210_FW_HOST_OFF)
  232. return NULL;
  233. off = HOSTADDR(ptr);
  234. if (off > wil->bar_size - 4)
  235. return NULL;
  236. return wil->csr + off;
  237. }
  238. int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
  239. struct wil6210_mbox_hdr *hdr)
  240. {
  241. void __iomem *src = wmi_buffer(wil, ptr);
  242. if (!src)
  243. return -EINVAL;
  244. wil_memcpy_fromio_32(hdr, src, sizeof(*hdr));
  245. return 0;
  246. }
  247. static const char *cmdid2name(u16 cmdid)
  248. {
  249. switch (cmdid) {
  250. case WMI_NOTIFY_REQ_CMDID:
  251. return "WMI_NOTIFY_REQ_CMD";
  252. case WMI_START_SCAN_CMDID:
  253. return "WMI_START_SCAN_CMD";
  254. case WMI_CONNECT_CMDID:
  255. return "WMI_CONNECT_CMD";
  256. case WMI_DISCONNECT_CMDID:
  257. return "WMI_DISCONNECT_CMD";
  258. case WMI_SW_TX_REQ_CMDID:
  259. return "WMI_SW_TX_REQ_CMD";
  260. case WMI_GET_RF_SECTOR_PARAMS_CMDID:
  261. return "WMI_GET_RF_SECTOR_PARAMS_CMD";
  262. case WMI_SET_RF_SECTOR_PARAMS_CMDID:
  263. return "WMI_SET_RF_SECTOR_PARAMS_CMD";
  264. case WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID:
  265. return "WMI_GET_SELECTED_RF_SECTOR_INDEX_CMD";
  266. case WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID:
  267. return "WMI_SET_SELECTED_RF_SECTOR_INDEX_CMD";
  268. case WMI_BRP_SET_ANT_LIMIT_CMDID:
  269. return "WMI_BRP_SET_ANT_LIMIT_CMD";
  270. case WMI_TOF_SESSION_START_CMDID:
  271. return "WMI_TOF_SESSION_START_CMD";
  272. case WMI_AOA_MEAS_CMDID:
  273. return "WMI_AOA_MEAS_CMD";
  274. case WMI_PMC_CMDID:
  275. return "WMI_PMC_CMD";
  276. case WMI_TOF_GET_TX_RX_OFFSET_CMDID:
  277. return "WMI_TOF_GET_TX_RX_OFFSET_CMD";
  278. case WMI_TOF_SET_TX_RX_OFFSET_CMDID:
  279. return "WMI_TOF_SET_TX_RX_OFFSET_CMD";
  280. case WMI_VRING_CFG_CMDID:
  281. return "WMI_VRING_CFG_CMD";
  282. case WMI_BCAST_VRING_CFG_CMDID:
  283. return "WMI_BCAST_VRING_CFG_CMD";
  284. case WMI_TRAFFIC_SUSPEND_CMDID:
  285. return "WMI_TRAFFIC_SUSPEND_CMD";
  286. case WMI_TRAFFIC_RESUME_CMDID:
  287. return "WMI_TRAFFIC_RESUME_CMD";
  288. case WMI_ECHO_CMDID:
  289. return "WMI_ECHO_CMD";
  290. case WMI_SET_MAC_ADDRESS_CMDID:
  291. return "WMI_SET_MAC_ADDRESS_CMD";
  292. case WMI_LED_CFG_CMDID:
  293. return "WMI_LED_CFG_CMD";
  294. case WMI_PCP_START_CMDID:
  295. return "WMI_PCP_START_CMD";
  296. case WMI_PCP_STOP_CMDID:
  297. return "WMI_PCP_STOP_CMD";
  298. case WMI_SET_SSID_CMDID:
  299. return "WMI_SET_SSID_CMD";
  300. case WMI_GET_SSID_CMDID:
  301. return "WMI_GET_SSID_CMD";
  302. case WMI_SET_PCP_CHANNEL_CMDID:
  303. return "WMI_SET_PCP_CHANNEL_CMD";
  304. case WMI_GET_PCP_CHANNEL_CMDID:
  305. return "WMI_GET_PCP_CHANNEL_CMD";
  306. case WMI_P2P_CFG_CMDID:
  307. return "WMI_P2P_CFG_CMD";
  308. case WMI_PORT_ALLOCATE_CMDID:
  309. return "WMI_PORT_ALLOCATE_CMD";
  310. case WMI_PORT_DELETE_CMDID:
  311. return "WMI_PORT_DELETE_CMD";
  312. case WMI_START_LISTEN_CMDID:
  313. return "WMI_START_LISTEN_CMD";
  314. case WMI_START_SEARCH_CMDID:
  315. return "WMI_START_SEARCH_CMD";
  316. case WMI_DISCOVERY_STOP_CMDID:
  317. return "WMI_DISCOVERY_STOP_CMD";
  318. case WMI_DELETE_CIPHER_KEY_CMDID:
  319. return "WMI_DELETE_CIPHER_KEY_CMD";
  320. case WMI_ADD_CIPHER_KEY_CMDID:
  321. return "WMI_ADD_CIPHER_KEY_CMD";
  322. case WMI_SET_APPIE_CMDID:
  323. return "WMI_SET_APPIE_CMD";
  324. case WMI_CFG_RX_CHAIN_CMDID:
  325. return "WMI_CFG_RX_CHAIN_CMD";
  326. case WMI_TEMP_SENSE_CMDID:
  327. return "WMI_TEMP_SENSE_CMD";
  328. case WMI_DEL_STA_CMDID:
  329. return "WMI_DEL_STA_CMD";
  330. case WMI_DISCONNECT_STA_CMDID:
  331. return "WMI_DISCONNECT_STA_CMD";
  332. case WMI_VRING_BA_EN_CMDID:
  333. return "WMI_VRING_BA_EN_CMD";
  334. case WMI_VRING_BA_DIS_CMDID:
  335. return "WMI_VRING_BA_DIS_CMD";
  336. case WMI_RCP_DELBA_CMDID:
  337. return "WMI_RCP_DELBA_CMD";
  338. case WMI_RCP_ADDBA_RESP_CMDID:
  339. return "WMI_RCP_ADDBA_RESP_CMD";
  340. case WMI_PS_DEV_PROFILE_CFG_CMDID:
  341. return "WMI_PS_DEV_PROFILE_CFG_CMD";
  342. case WMI_SET_MGMT_RETRY_LIMIT_CMDID:
  343. return "WMI_SET_MGMT_RETRY_LIMIT_CMD";
  344. case WMI_GET_MGMT_RETRY_LIMIT_CMDID:
  345. return "WMI_GET_MGMT_RETRY_LIMIT_CMD";
  346. case WMI_ABORT_SCAN_CMDID:
  347. return "WMI_ABORT_SCAN_CMD";
  348. case WMI_NEW_STA_CMDID:
  349. return "WMI_NEW_STA_CMD";
  350. case WMI_SET_THERMAL_THROTTLING_CFG_CMDID:
  351. return "WMI_SET_THERMAL_THROTTLING_CFG_CMD";
  352. case WMI_GET_THERMAL_THROTTLING_CFG_CMDID:
  353. return "WMI_GET_THERMAL_THROTTLING_CFG_CMD";
  354. case WMI_LINK_MAINTAIN_CFG_WRITE_CMDID:
  355. return "WMI_LINK_MAINTAIN_CFG_WRITE_CMD";
  356. case WMI_LO_POWER_CALIB_FROM_OTP_CMDID:
  357. return "WMI_LO_POWER_CALIB_FROM_OTP_CMD";
  358. case WMI_START_SCHED_SCAN_CMDID:
  359. return "WMI_START_SCHED_SCAN_CMD";
  360. case WMI_STOP_SCHED_SCAN_CMDID:
  361. return "WMI_STOP_SCHED_SCAN_CMD";
  362. default:
  363. return "Untracked CMD";
  364. }
  365. }
  366. static const char *eventid2name(u16 eventid)
  367. {
  368. switch (eventid) {
  369. case WMI_NOTIFY_REQ_DONE_EVENTID:
  370. return "WMI_NOTIFY_REQ_DONE_EVENT";
  371. case WMI_DISCONNECT_EVENTID:
  372. return "WMI_DISCONNECT_EVENT";
  373. case WMI_SW_TX_COMPLETE_EVENTID:
  374. return "WMI_SW_TX_COMPLETE_EVENT";
  375. case WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID:
  376. return "WMI_GET_RF_SECTOR_PARAMS_DONE_EVENT";
  377. case WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID:
  378. return "WMI_SET_RF_SECTOR_PARAMS_DONE_EVENT";
  379. case WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID:
  380. return "WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENT";
  381. case WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID:
  382. return "WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENT";
  383. case WMI_BRP_SET_ANT_LIMIT_EVENTID:
  384. return "WMI_BRP_SET_ANT_LIMIT_EVENT";
  385. case WMI_FW_READY_EVENTID:
  386. return "WMI_FW_READY_EVENT";
  387. case WMI_TRAFFIC_RESUME_EVENTID:
  388. return "WMI_TRAFFIC_RESUME_EVENT";
  389. case WMI_TOF_GET_TX_RX_OFFSET_EVENTID:
  390. return "WMI_TOF_GET_TX_RX_OFFSET_EVENT";
  391. case WMI_TOF_SET_TX_RX_OFFSET_EVENTID:
  392. return "WMI_TOF_SET_TX_RX_OFFSET_EVENT";
  393. case WMI_VRING_CFG_DONE_EVENTID:
  394. return "WMI_VRING_CFG_DONE_EVENT";
  395. case WMI_READY_EVENTID:
  396. return "WMI_READY_EVENT";
  397. case WMI_RX_MGMT_PACKET_EVENTID:
  398. return "WMI_RX_MGMT_PACKET_EVENT";
  399. case WMI_TX_MGMT_PACKET_EVENTID:
  400. return "WMI_TX_MGMT_PACKET_EVENT";
  401. case WMI_SCAN_COMPLETE_EVENTID:
  402. return "WMI_SCAN_COMPLETE_EVENT";
  403. case WMI_ACS_PASSIVE_SCAN_COMPLETE_EVENTID:
  404. return "WMI_ACS_PASSIVE_SCAN_COMPLETE_EVENT";
  405. case WMI_CONNECT_EVENTID:
  406. return "WMI_CONNECT_EVENT";
  407. case WMI_EAPOL_RX_EVENTID:
  408. return "WMI_EAPOL_RX_EVENT";
  409. case WMI_BA_STATUS_EVENTID:
  410. return "WMI_BA_STATUS_EVENT";
  411. case WMI_RCP_ADDBA_REQ_EVENTID:
  412. return "WMI_RCP_ADDBA_REQ_EVENT";
  413. case WMI_DELBA_EVENTID:
  414. return "WMI_DELBA_EVENT";
  415. case WMI_VRING_EN_EVENTID:
  416. return "WMI_VRING_EN_EVENT";
  417. case WMI_DATA_PORT_OPEN_EVENTID:
  418. return "WMI_DATA_PORT_OPEN_EVENT";
  419. case WMI_AOA_MEAS_EVENTID:
  420. return "WMI_AOA_MEAS_EVENT";
  421. case WMI_TOF_SESSION_END_EVENTID:
  422. return "WMI_TOF_SESSION_END_EVENT";
  423. case WMI_TOF_GET_CAPABILITIES_EVENTID:
  424. return "WMI_TOF_GET_CAPABILITIES_EVENT";
  425. case WMI_TOF_SET_LCR_EVENTID:
  426. return "WMI_TOF_SET_LCR_EVENT";
  427. case WMI_TOF_SET_LCI_EVENTID:
  428. return "WMI_TOF_SET_LCI_EVENT";
  429. case WMI_TOF_FTM_PER_DEST_RES_EVENTID:
  430. return "WMI_TOF_FTM_PER_DEST_RES_EVENT";
  431. case WMI_TOF_CHANNEL_INFO_EVENTID:
  432. return "WMI_TOF_CHANNEL_INFO_EVENT";
  433. case WMI_TRAFFIC_SUSPEND_EVENTID:
  434. return "WMI_TRAFFIC_SUSPEND_EVENT";
  435. case WMI_ECHO_RSP_EVENTID:
  436. return "WMI_ECHO_RSP_EVENT";
  437. case WMI_LED_CFG_DONE_EVENTID:
  438. return "WMI_LED_CFG_DONE_EVENT";
  439. case WMI_PCP_STARTED_EVENTID:
  440. return "WMI_PCP_STARTED_EVENT";
  441. case WMI_PCP_STOPPED_EVENTID:
  442. return "WMI_PCP_STOPPED_EVENT";
  443. case WMI_GET_SSID_EVENTID:
  444. return "WMI_GET_SSID_EVENT";
  445. case WMI_GET_PCP_CHANNEL_EVENTID:
  446. return "WMI_GET_PCP_CHANNEL_EVENT";
  447. case WMI_P2P_CFG_DONE_EVENTID:
  448. return "WMI_P2P_CFG_DONE_EVENT";
  449. case WMI_PORT_ALLOCATED_EVENTID:
  450. return "WMI_PORT_ALLOCATED_EVENT";
  451. case WMI_PORT_DELETED_EVENTID:
  452. return "WMI_PORT_DELETED_EVENT";
  453. case WMI_LISTEN_STARTED_EVENTID:
  454. return "WMI_LISTEN_STARTED_EVENT";
  455. case WMI_SEARCH_STARTED_EVENTID:
  456. return "WMI_SEARCH_STARTED_EVENT";
  457. case WMI_DISCOVERY_STOPPED_EVENTID:
  458. return "WMI_DISCOVERY_STOPPED_EVENT";
  459. case WMI_CFG_RX_CHAIN_DONE_EVENTID:
  460. return "WMI_CFG_RX_CHAIN_DONE_EVENT";
  461. case WMI_TEMP_SENSE_DONE_EVENTID:
  462. return "WMI_TEMP_SENSE_DONE_EVENT";
  463. case WMI_RCP_ADDBA_RESP_SENT_EVENTID:
  464. return "WMI_RCP_ADDBA_RESP_SENT_EVENT";
  465. case WMI_PS_DEV_PROFILE_CFG_EVENTID:
  466. return "WMI_PS_DEV_PROFILE_CFG_EVENT";
  467. case WMI_SET_MGMT_RETRY_LIMIT_EVENTID:
  468. return "WMI_SET_MGMT_RETRY_LIMIT_EVENT";
  469. case WMI_GET_MGMT_RETRY_LIMIT_EVENTID:
  470. return "WMI_GET_MGMT_RETRY_LIMIT_EVENT";
  471. case WMI_SET_THERMAL_THROTTLING_CFG_EVENTID:
  472. return "WMI_SET_THERMAL_THROTTLING_CFG_EVENT";
  473. case WMI_GET_THERMAL_THROTTLING_CFG_EVENTID:
  474. return "WMI_GET_THERMAL_THROTTLING_CFG_EVENT";
  475. case WMI_LINK_MAINTAIN_CFG_WRITE_DONE_EVENTID:
  476. return "WMI_LINK_MAINTAIN_CFG_WRITE_DONE_EVENT";
  477. case WMI_LO_POWER_CALIB_FROM_OTP_EVENTID:
  478. return "WMI_LO_POWER_CALIB_FROM_OTP_EVENT";
  479. case WMI_START_SCHED_SCAN_EVENTID:
  480. return "WMI_START_SCHED_SCAN_EVENT";
  481. case WMI_STOP_SCHED_SCAN_EVENTID:
  482. return "WMI_STOP_SCHED_SCAN_EVENT";
  483. case WMI_SCHED_SCAN_RESULT_EVENTID:
  484. return "WMI_SCHED_SCAN_RESULT_EVENT";
  485. default:
  486. return "Untracked EVENT";
  487. }
  488. }
  489. static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, u8 mid,
  490. void *buf, u16 len)
  491. {
  492. struct {
  493. struct wil6210_mbox_hdr hdr;
  494. struct wmi_cmd_hdr wmi;
  495. } __packed cmd = {
  496. .hdr = {
  497. .type = WIL_MBOX_HDR_TYPE_WMI,
  498. .flags = 0,
  499. .len = cpu_to_le16(sizeof(cmd.wmi) + len),
  500. },
  501. .wmi = {
  502. .mid = mid,
  503. .command_id = cpu_to_le16(cmdid),
  504. },
  505. };
  506. struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx;
  507. struct wil6210_mbox_ring_desc d_head;
  508. u32 next_head;
  509. void __iomem *dst;
  510. void __iomem *head = wmi_addr(wil, r->head);
  511. uint retry;
  512. int rc = 0;
  513. if (len > r->entry_size - sizeof(cmd)) {
  514. wil_err(wil, "WMI size too large: %d bytes, max is %d\n",
  515. (int)(sizeof(cmd) + len), r->entry_size);
  516. return -ERANGE;
  517. }
  518. might_sleep();
  519. if (!test_bit(wil_status_fwready, wil->status)) {
  520. wil_err(wil, "WMI: cannot send command while FW not ready\n");
  521. return -EAGAIN;
  522. }
  523. /* Allow sending only suspend / resume commands during susepnd flow */
  524. if ((test_bit(wil_status_suspending, wil->status) ||
  525. test_bit(wil_status_suspended, wil->status) ||
  526. test_bit(wil_status_resuming, wil->status)) &&
  527. ((cmdid != WMI_TRAFFIC_SUSPEND_CMDID) &&
  528. (cmdid != WMI_TRAFFIC_RESUME_CMDID))) {
  529. wil_err(wil, "WMI: reject send_command during suspend\n");
  530. return -EINVAL;
  531. }
  532. if (!head) {
  533. wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head);
  534. return -EINVAL;
  535. }
  536. wil_halp_vote(wil);
  537. /* read Tx head till it is not busy */
  538. for (retry = 5; retry > 0; retry--) {
  539. wil_memcpy_fromio_32(&d_head, head, sizeof(d_head));
  540. if (d_head.sync == 0)
  541. break;
  542. msleep(20);
  543. }
  544. if (d_head.sync != 0) {
  545. wil_err(wil, "WMI head busy\n");
  546. rc = -EBUSY;
  547. goto out;
  548. }
  549. /* next head */
  550. next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size);
  551. wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head);
  552. /* wait till FW finish with previous command */
  553. for (retry = 5; retry > 0; retry--) {
  554. if (!test_bit(wil_status_fwready, wil->status)) {
  555. wil_err(wil, "WMI: cannot send command while FW not ready\n");
  556. rc = -EAGAIN;
  557. goto out;
  558. }
  559. r->tail = wil_r(wil, RGF_MBOX +
  560. offsetof(struct wil6210_mbox_ctl, tx.tail));
  561. if (next_head != r->tail)
  562. break;
  563. msleep(20);
  564. }
  565. if (next_head == r->tail) {
  566. wil_err(wil, "WMI ring full\n");
  567. rc = -EBUSY;
  568. goto out;
  569. }
  570. dst = wmi_buffer(wil, d_head.addr);
  571. if (!dst) {
  572. wil_err(wil, "invalid WMI buffer: 0x%08x\n",
  573. le32_to_cpu(d_head.addr));
  574. rc = -EAGAIN;
  575. goto out;
  576. }
  577. cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq);
  578. /* set command */
  579. wil_dbg_wmi(wil, "sending %s (0x%04x) [%d] mid %d\n",
  580. cmdid2name(cmdid), cmdid, len, mid);
  581. wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd,
  582. sizeof(cmd), true);
  583. wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf,
  584. len, true);
  585. wil_memcpy_toio_32(dst, &cmd, sizeof(cmd));
  586. wil_memcpy_toio_32(dst + sizeof(cmd), buf, len);
  587. /* mark entry as full */
  588. wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1);
  589. /* advance next ptr */
  590. wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head),
  591. r->head = next_head);
  592. trace_wil6210_wmi_cmd(&cmd.wmi, buf, len);
  593. /* interrupt to FW */
  594. wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS),
  595. SW_INT_MBOX);
  596. out:
  597. wil_halp_unvote(wil);
  598. return rc;
  599. }
  600. int wmi_send(struct wil6210_priv *wil, u16 cmdid, u8 mid, void *buf, u16 len)
  601. {
  602. int rc;
  603. mutex_lock(&wil->wmi_mutex);
  604. rc = __wmi_send(wil, cmdid, mid, buf, len);
  605. mutex_unlock(&wil->wmi_mutex);
  606. return rc;
  607. }
  608. /*=== Event handlers ===*/
  609. static void wmi_evt_ready(struct wil6210_vif *vif, int id, void *d, int len)
  610. {
  611. struct wil6210_priv *wil = vif_to_wil(vif);
  612. struct wiphy *wiphy = wil_to_wiphy(wil);
  613. struct wmi_ready_event *evt = d;
  614. wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n",
  615. wil->fw_version, le32_to_cpu(evt->sw_version),
  616. evt->mac, evt->numof_additional_mids);
  617. if (evt->numof_additional_mids + 1 < wil->max_vifs) {
  618. wil_err(wil, "FW does not support enough MIDs (need %d)",
  619. wil->max_vifs - 1);
  620. return; /* FW load will fail after timeout */
  621. }
  622. /* ignore MAC address, we already have it from the boot loader */
  623. strlcpy(wiphy->fw_version, wil->fw_version, sizeof(wiphy->fw_version));
  624. if (len > offsetof(struct wmi_ready_event, rfc_read_calib_result)) {
  625. wil_dbg_wmi(wil, "rfc calibration result %d\n",
  626. evt->rfc_read_calib_result);
  627. wil->fw_calib_result = evt->rfc_read_calib_result;
  628. }
  629. wil_set_recovery_state(wil, fw_recovery_idle);
  630. set_bit(wil_status_fwready, wil->status);
  631. /* let the reset sequence continue */
  632. complete(&wil->wmi_ready);
  633. }
  634. static void wmi_evt_rx_mgmt(struct wil6210_vif *vif, int id, void *d, int len)
  635. {
  636. struct wil6210_priv *wil = vif_to_wil(vif);
  637. struct wmi_rx_mgmt_packet_event *data = d;
  638. struct wiphy *wiphy = wil_to_wiphy(wil);
  639. struct ieee80211_mgmt *rx_mgmt_frame =
  640. (struct ieee80211_mgmt *)data->payload;
  641. int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload);
  642. int ch_no;
  643. u32 freq;
  644. struct ieee80211_channel *channel;
  645. s32 signal;
  646. __le16 fc;
  647. u32 d_len;
  648. u16 d_status;
  649. if (flen < 0) {
  650. wil_err(wil, "MGMT Rx: short event, len %d\n", len);
  651. return;
  652. }
  653. d_len = le32_to_cpu(data->info.len);
  654. if (d_len != flen) {
  655. wil_err(wil,
  656. "MGMT Rx: length mismatch, d_len %d should be %d\n",
  657. d_len, flen);
  658. return;
  659. }
  660. ch_no = data->info.channel + 1;
  661. freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
  662. channel = ieee80211_get_channel(wiphy, freq);
  663. if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
  664. signal = 100 * data->info.rssi;
  665. else
  666. signal = data->info.sqi;
  667. d_status = le16_to_cpu(data->info.status);
  668. fc = rx_mgmt_frame->frame_control;
  669. wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d RSSI %d SQI %d%%\n",
  670. data->info.channel, data->info.mcs, data->info.rssi,
  671. data->info.sqi);
  672. wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len,
  673. le16_to_cpu(fc));
  674. wil_dbg_wmi(wil, "qid %d mid %d cid %d\n",
  675. data->info.qid, data->info.mid, data->info.cid);
  676. wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
  677. d_len, true);
  678. if (!channel) {
  679. wil_err(wil, "Frame on unsupported channel\n");
  680. return;
  681. }
  682. if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) {
  683. struct cfg80211_bss *bss;
  684. u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp);
  685. u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info);
  686. u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int);
  687. const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable;
  688. size_t ie_len = d_len - offsetof(struct ieee80211_mgmt,
  689. u.beacon.variable);
  690. wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
  691. wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf);
  692. wil_dbg_wmi(wil, "Beacon interval : %d\n", bi);
  693. wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf,
  694. ie_len, true);
  695. wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
  696. bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame,
  697. d_len, signal, GFP_KERNEL);
  698. if (bss) {
  699. wil_dbg_wmi(wil, "Added BSS %pM\n",
  700. rx_mgmt_frame->bssid);
  701. cfg80211_put_bss(wiphy, bss);
  702. } else {
  703. wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
  704. }
  705. } else {
  706. mutex_lock(&wil->vif_mutex);
  707. cfg80211_rx_mgmt(vif_to_radio_wdev(wil, vif), freq, signal,
  708. (void *)rx_mgmt_frame, d_len, 0);
  709. mutex_unlock(&wil->vif_mutex);
  710. }
  711. }
  712. static void wmi_evt_tx_mgmt(struct wil6210_vif *vif, int id, void *d, int len)
  713. {
  714. struct wmi_tx_mgmt_packet_event *data = d;
  715. struct ieee80211_mgmt *mgmt_frame =
  716. (struct ieee80211_mgmt *)data->payload;
  717. int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload);
  718. wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame,
  719. flen, true);
  720. }
  721. static void wmi_evt_scan_complete(struct wil6210_vif *vif, int id,
  722. void *d, int len)
  723. {
  724. struct wil6210_priv *wil = vif_to_wil(vif);
  725. mutex_lock(&wil->vif_mutex);
  726. if (vif->scan_request) {
  727. struct wmi_scan_complete_event *data = d;
  728. int status = le32_to_cpu(data->status);
  729. struct cfg80211_scan_info info = {
  730. .aborted = ((status != WMI_SCAN_SUCCESS) &&
  731. (status != WMI_SCAN_ABORT_REJECTED)),
  732. };
  733. wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status);
  734. wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n",
  735. vif->scan_request, info.aborted);
  736. del_timer_sync(&vif->scan_timer);
  737. cfg80211_scan_done(vif->scan_request, &info);
  738. if (vif->mid == 0)
  739. wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
  740. vif->scan_request = NULL;
  741. wake_up_interruptible(&wil->wq);
  742. if (vif->p2p.pending_listen_wdev) {
  743. wil_dbg_misc(wil, "Scheduling delayed listen\n");
  744. schedule_work(&vif->p2p.delayed_listen_work);
  745. }
  746. } else {
  747. wil_err(wil, "SCAN_COMPLETE while not scanning\n");
  748. }
  749. mutex_unlock(&wil->vif_mutex);
  750. }
  751. static void wmi_evt_connect(struct wil6210_vif *vif, int id, void *d, int len)
  752. {
  753. struct wil6210_priv *wil = vif_to_wil(vif);
  754. struct net_device *ndev = vif_to_ndev(vif);
  755. struct wireless_dev *wdev = vif_to_wdev(vif);
  756. struct wmi_connect_event *evt = d;
  757. int ch; /* channel number */
  758. struct station_info *sinfo;
  759. u8 *assoc_req_ie, *assoc_resp_ie;
  760. size_t assoc_req_ielen, assoc_resp_ielen;
  761. /* capinfo(u16) + listen_interval(u16) + IEs */
  762. const size_t assoc_req_ie_offset = sizeof(u16) * 2;
  763. /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
  764. const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
  765. int rc;
  766. if (len < sizeof(*evt)) {
  767. wil_err(wil, "Connect event too short : %d bytes\n", len);
  768. return;
  769. }
  770. if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len +
  771. evt->assoc_resp_len) {
  772. wil_err(wil,
  773. "Connect event corrupted : %d != %d + %d + %d + %d\n",
  774. len, (int)sizeof(*evt), evt->beacon_ie_len,
  775. evt->assoc_req_len, evt->assoc_resp_len);
  776. return;
  777. }
  778. if (evt->cid >= WIL6210_MAX_CID) {
  779. wil_err(wil, "Connect CID invalid : %d\n", evt->cid);
  780. return;
  781. }
  782. ch = evt->channel + 1;
  783. wil_info(wil, "Connect %pM channel [%d] cid %d aid %d\n",
  784. evt->bssid, ch, evt->cid, evt->aid);
  785. wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1,
  786. evt->assoc_info, len - sizeof(*evt), true);
  787. /* figure out IE's */
  788. assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len +
  789. assoc_req_ie_offset];
  790. assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset;
  791. if (evt->assoc_req_len <= assoc_req_ie_offset) {
  792. assoc_req_ie = NULL;
  793. assoc_req_ielen = 0;
  794. }
  795. assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len +
  796. evt->assoc_req_len +
  797. assoc_resp_ie_offset];
  798. assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset;
  799. if (evt->assoc_resp_len <= assoc_resp_ie_offset) {
  800. assoc_resp_ie = NULL;
  801. assoc_resp_ielen = 0;
  802. }
  803. if (test_bit(wil_status_resetting, wil->status) ||
  804. !test_bit(wil_status_fwready, wil->status)) {
  805. wil_err(wil, "status_resetting, cancel connect event, CID %d\n",
  806. evt->cid);
  807. /* no need for cleanup, wil_reset will do that */
  808. return;
  809. }
  810. mutex_lock(&wil->mutex);
  811. if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
  812. (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
  813. if (!test_bit(wil_vif_fwconnecting, vif->status)) {
  814. wil_err(wil, "Not in connecting state\n");
  815. mutex_unlock(&wil->mutex);
  816. return;
  817. }
  818. del_timer_sync(&vif->connect_timer);
  819. } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
  820. (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
  821. if (wil->sta[evt->cid].status != wil_sta_unused) {
  822. wil_err(wil, "AP: Invalid status %d for CID %d\n",
  823. wil->sta[evt->cid].status, evt->cid);
  824. mutex_unlock(&wil->mutex);
  825. return;
  826. }
  827. }
  828. ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid);
  829. wil->sta[evt->cid].mid = vif->mid;
  830. wil->sta[evt->cid].status = wil_sta_conn_pending;
  831. rc = wil_tx_init(vif, evt->cid);
  832. if (rc) {
  833. wil_err(wil, "config tx vring failed for CID %d, rc (%d)\n",
  834. evt->cid, rc);
  835. wmi_disconnect_sta(vif, wil->sta[evt->cid].addr,
  836. WLAN_REASON_UNSPECIFIED, false, false);
  837. } else {
  838. wil_info(wil, "successful connection to CID %d\n", evt->cid);
  839. }
  840. if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
  841. (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
  842. if (rc) {
  843. netif_carrier_off(ndev);
  844. wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
  845. wil_err(wil, "cfg80211_connect_result with failure\n");
  846. cfg80211_connect_result(ndev, evt->bssid, NULL, 0,
  847. NULL, 0,
  848. WLAN_STATUS_UNSPECIFIED_FAILURE,
  849. GFP_KERNEL);
  850. goto out;
  851. } else {
  852. struct wiphy *wiphy = wil_to_wiphy(wil);
  853. cfg80211_ref_bss(wiphy, vif->bss);
  854. cfg80211_connect_bss(ndev, evt->bssid, vif->bss,
  855. assoc_req_ie, assoc_req_ielen,
  856. assoc_resp_ie, assoc_resp_ielen,
  857. WLAN_STATUS_SUCCESS, GFP_KERNEL,
  858. NL80211_TIMEOUT_UNSPECIFIED);
  859. }
  860. vif->bss = NULL;
  861. } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
  862. (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
  863. if (rc) {
  864. if (disable_ap_sme)
  865. /* notify new_sta has failed */
  866. cfg80211_del_sta(ndev, evt->bssid, GFP_KERNEL);
  867. goto out;
  868. }
  869. sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
  870. if (!sinfo) {
  871. rc = -ENOMEM;
  872. goto out;
  873. }
  874. sinfo->generation = wil->sinfo_gen++;
  875. if (assoc_req_ie) {
  876. sinfo->assoc_req_ies = assoc_req_ie;
  877. sinfo->assoc_req_ies_len = assoc_req_ielen;
  878. }
  879. cfg80211_new_sta(ndev, evt->bssid, sinfo, GFP_KERNEL);
  880. kfree(sinfo);
  881. } else {
  882. wil_err(wil, "unhandled iftype %d for CID %d\n", wdev->iftype,
  883. evt->cid);
  884. goto out;
  885. }
  886. wil->sta[evt->cid].status = wil_sta_connected;
  887. wil->sta[evt->cid].aid = evt->aid;
  888. if (!test_and_set_bit(wil_vif_fwconnected, vif->status))
  889. atomic_inc(&wil->connected_vifs);
  890. wil_update_net_queues_bh(wil, vif, NULL, false);
  891. out:
  892. if (rc) {
  893. wil->sta[evt->cid].status = wil_sta_unused;
  894. wil->sta[evt->cid].mid = U8_MAX;
  895. }
  896. clear_bit(wil_vif_fwconnecting, vif->status);
  897. mutex_unlock(&wil->mutex);
  898. }
  899. static void wmi_evt_disconnect(struct wil6210_vif *vif, int id,
  900. void *d, int len)
  901. {
  902. struct wil6210_priv *wil = vif_to_wil(vif);
  903. struct wmi_disconnect_event *evt = d;
  904. u16 reason_code = le16_to_cpu(evt->protocol_reason_status);
  905. wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
  906. evt->bssid, reason_code, evt->disconnect_reason);
  907. wil->sinfo_gen++;
  908. if (test_bit(wil_status_resetting, wil->status) ||
  909. !test_bit(wil_status_fwready, wil->status)) {
  910. wil_err(wil, "status_resetting, cancel disconnect event\n");
  911. /* no need for cleanup, wil_reset will do that */
  912. return;
  913. }
  914. mutex_lock(&wil->mutex);
  915. wil6210_disconnect(vif, evt->bssid, reason_code, true);
  916. mutex_unlock(&wil->mutex);
  917. }
  918. /*
  919. * Firmware reports EAPOL frame using WME event.
  920. * Reconstruct Ethernet frame and deliver it via normal Rx
  921. */
  922. static void wmi_evt_eapol_rx(struct wil6210_vif *vif, int id, void *d, int len)
  923. {
  924. struct wil6210_priv *wil = vif_to_wil(vif);
  925. struct net_device *ndev = vif_to_ndev(vif);
  926. struct wmi_eapol_rx_event *evt = d;
  927. u16 eapol_len = le16_to_cpu(evt->eapol_len);
  928. int sz = eapol_len + ETH_HLEN;
  929. struct sk_buff *skb;
  930. struct ethhdr *eth;
  931. int cid;
  932. struct wil_net_stats *stats = NULL;
  933. wil_dbg_wmi(wil, "EAPOL len %d from %pM MID %d\n", eapol_len,
  934. evt->src_mac, vif->mid);
  935. cid = wil_find_cid(wil, vif->mid, evt->src_mac);
  936. if (cid >= 0)
  937. stats = &wil->sta[cid].stats;
  938. if (eapol_len > 196) { /* TODO: revisit size limit */
  939. wil_err(wil, "EAPOL too large\n");
  940. return;
  941. }
  942. skb = alloc_skb(sz, GFP_KERNEL);
  943. if (!skb) {
  944. wil_err(wil, "Failed to allocate skb\n");
  945. return;
  946. }
  947. eth = skb_put(skb, ETH_HLEN);
  948. ether_addr_copy(eth->h_dest, ndev->dev_addr);
  949. ether_addr_copy(eth->h_source, evt->src_mac);
  950. eth->h_proto = cpu_to_be16(ETH_P_PAE);
  951. skb_put_data(skb, evt->eapol, eapol_len);
  952. skb->protocol = eth_type_trans(skb, ndev);
  953. if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
  954. ndev->stats.rx_packets++;
  955. ndev->stats.rx_bytes += sz;
  956. if (stats) {
  957. stats->rx_packets++;
  958. stats->rx_bytes += sz;
  959. }
  960. } else {
  961. ndev->stats.rx_dropped++;
  962. if (stats)
  963. stats->rx_dropped++;
  964. }
  965. }
  966. static void wmi_evt_vring_en(struct wil6210_vif *vif, int id, void *d, int len)
  967. {
  968. struct wil6210_priv *wil = vif_to_wil(vif);
  969. struct wmi_vring_en_event *evt = d;
  970. u8 vri = evt->vring_index;
  971. struct wireless_dev *wdev = vif_to_wdev(vif);
  972. wil_dbg_wmi(wil, "Enable vring %d MID %d\n", vri, vif->mid);
  973. if (vri >= ARRAY_SIZE(wil->vring_tx)) {
  974. wil_err(wil, "Enable for invalid vring %d\n", vri);
  975. return;
  976. }
  977. if (wdev->iftype != NL80211_IFTYPE_AP || !disable_ap_sme)
  978. /* in AP mode with disable_ap_sme, this is done by
  979. * wil_cfg80211_change_station()
  980. */
  981. wil->vring_tx_data[vri].dot1x_open = true;
  982. if (vri == vif->bcast_vring) /* no BA for bcast */
  983. return;
  984. if (agg_wsize >= 0)
  985. wil_addba_tx_request(wil, vri, agg_wsize);
  986. }
  987. static void wmi_evt_ba_status(struct wil6210_vif *vif, int id,
  988. void *d, int len)
  989. {
  990. struct wil6210_priv *wil = vif_to_wil(vif);
  991. struct wmi_ba_status_event *evt = d;
  992. struct vring_tx_data *txdata;
  993. wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n",
  994. evt->ringid,
  995. evt->status == WMI_BA_AGREED ? "OK" : "N/A",
  996. evt->agg_wsize, __le16_to_cpu(evt->ba_timeout),
  997. evt->amsdu ? "+" : "-");
  998. if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
  999. wil_err(wil, "invalid ring id %d\n", evt->ringid);
  1000. return;
  1001. }
  1002. if (evt->status != WMI_BA_AGREED) {
  1003. evt->ba_timeout = 0;
  1004. evt->agg_wsize = 0;
  1005. evt->amsdu = 0;
  1006. }
  1007. txdata = &wil->vring_tx_data[evt->ringid];
  1008. txdata->agg_timeout = le16_to_cpu(evt->ba_timeout);
  1009. txdata->agg_wsize = evt->agg_wsize;
  1010. txdata->agg_amsdu = evt->amsdu;
  1011. txdata->addba_in_progress = false;
  1012. }
  1013. static void wmi_evt_addba_rx_req(struct wil6210_vif *vif, int id,
  1014. void *d, int len)
  1015. {
  1016. struct wil6210_priv *wil = vif_to_wil(vif);
  1017. struct wmi_rcp_addba_req_event *evt = d;
  1018. wil_addba_rx_request(wil, vif->mid, evt->cidxtid, evt->dialog_token,
  1019. evt->ba_param_set, evt->ba_timeout,
  1020. evt->ba_seq_ctrl);
  1021. }
  1022. static void wmi_evt_delba(struct wil6210_vif *vif, int id, void *d, int len)
  1023. __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
  1024. {
  1025. struct wil6210_priv *wil = vif_to_wil(vif);
  1026. struct wmi_delba_event *evt = d;
  1027. u8 cid, tid;
  1028. u16 reason = __le16_to_cpu(evt->reason);
  1029. struct wil_sta_info *sta;
  1030. struct wil_tid_ampdu_rx *r;
  1031. might_sleep();
  1032. parse_cidxtid(evt->cidxtid, &cid, &tid);
  1033. wil_dbg_wmi(wil, "DELBA MID %d CID %d TID %d from %s reason %d\n",
  1034. vif->mid, cid, tid,
  1035. evt->from_initiator ? "originator" : "recipient",
  1036. reason);
  1037. if (!evt->from_initiator) {
  1038. int i;
  1039. /* find Tx vring it belongs to */
  1040. for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
  1041. if ((wil->vring2cid_tid[i][0] == cid) &&
  1042. (wil->vring2cid_tid[i][1] == tid)) {
  1043. struct vring_tx_data *txdata =
  1044. &wil->vring_tx_data[i];
  1045. wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i);
  1046. txdata->agg_timeout = 0;
  1047. txdata->agg_wsize = 0;
  1048. txdata->addba_in_progress = false;
  1049. break; /* max. 1 matching ring */
  1050. }
  1051. }
  1052. if (i >= ARRAY_SIZE(wil->vring2cid_tid))
  1053. wil_err(wil, "DELBA: unable to find Tx vring\n");
  1054. return;
  1055. }
  1056. sta = &wil->sta[cid];
  1057. spin_lock_bh(&sta->tid_rx_lock);
  1058. r = sta->tid_rx[tid];
  1059. sta->tid_rx[tid] = NULL;
  1060. wil_tid_ampdu_rx_free(wil, r);
  1061. spin_unlock_bh(&sta->tid_rx_lock);
  1062. }
  1063. static void
  1064. wmi_evt_sched_scan_result(struct wil6210_vif *vif, int id, void *d, int len)
  1065. {
  1066. struct wil6210_priv *wil = vif_to_wil(vif);
  1067. struct wmi_sched_scan_result_event *data = d;
  1068. struct wiphy *wiphy = wil_to_wiphy(wil);
  1069. struct ieee80211_mgmt *rx_mgmt_frame =
  1070. (struct ieee80211_mgmt *)data->payload;
  1071. int flen = len - offsetof(struct wmi_sched_scan_result_event, payload);
  1072. int ch_no;
  1073. u32 freq;
  1074. struct ieee80211_channel *channel;
  1075. s32 signal;
  1076. __le16 fc;
  1077. u32 d_len;
  1078. struct cfg80211_bss *bss;
  1079. if (flen < 0) {
  1080. wil_err(wil, "sched scan result event too short, len %d\n",
  1081. len);
  1082. return;
  1083. }
  1084. d_len = le32_to_cpu(data->info.len);
  1085. if (d_len != flen) {
  1086. wil_err(wil,
  1087. "sched scan result length mismatch, d_len %d should be %d\n",
  1088. d_len, flen);
  1089. return;
  1090. }
  1091. fc = rx_mgmt_frame->frame_control;
  1092. if (!ieee80211_is_probe_resp(fc)) {
  1093. wil_err(wil, "sched scan result invalid frame, fc 0x%04x\n",
  1094. fc);
  1095. return;
  1096. }
  1097. ch_no = data->info.channel + 1;
  1098. freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
  1099. channel = ieee80211_get_channel(wiphy, freq);
  1100. if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
  1101. signal = 100 * data->info.rssi;
  1102. else
  1103. signal = data->info.sqi;
  1104. wil_dbg_wmi(wil, "sched scan result: channel %d MCS %d RSSI %d\n",
  1105. data->info.channel, data->info.mcs, data->info.rssi);
  1106. wil_dbg_wmi(wil, "len %d qid %d mid %d cid %d\n",
  1107. d_len, data->info.qid, data->info.mid, data->info.cid);
  1108. wil_hex_dump_wmi("PROBE ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
  1109. d_len, true);
  1110. if (!channel) {
  1111. wil_err(wil, "Frame on unsupported channel\n");
  1112. return;
  1113. }
  1114. bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame,
  1115. d_len, signal, GFP_KERNEL);
  1116. if (bss) {
  1117. wil_dbg_wmi(wil, "Added BSS %pM\n", rx_mgmt_frame->bssid);
  1118. cfg80211_put_bss(wiphy, bss);
  1119. } else {
  1120. wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
  1121. }
  1122. cfg80211_sched_scan_results(wiphy, 0);
  1123. }
  1124. /**
  1125. * Some events are ignored for purpose; and need not be interpreted as
  1126. * "unhandled events"
  1127. */
  1128. static void wmi_evt_ignore(struct wil6210_vif *vif, int id, void *d, int len)
  1129. {
  1130. struct wil6210_priv *wil = vif_to_wil(vif);
  1131. wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len);
  1132. }
  1133. static const struct {
  1134. int eventid;
  1135. void (*handler)(struct wil6210_vif *vif,
  1136. int eventid, void *data, int data_len);
  1137. } wmi_evt_handlers[] = {
  1138. {WMI_READY_EVENTID, wmi_evt_ready},
  1139. {WMI_FW_READY_EVENTID, wmi_evt_ignore},
  1140. {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
  1141. {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt},
  1142. {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
  1143. {WMI_CONNECT_EVENTID, wmi_evt_connect},
  1144. {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
  1145. {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
  1146. {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
  1147. {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req},
  1148. {WMI_DELBA_EVENTID, wmi_evt_delba},
  1149. {WMI_VRING_EN_EVENTID, wmi_evt_vring_en},
  1150. {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore},
  1151. {WMI_SCHED_SCAN_RESULT_EVENTID, wmi_evt_sched_scan_result},
  1152. };
  1153. /*
  1154. * Run in IRQ context
  1155. * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
  1156. * that will be eventually handled by the @wmi_event_worker in the thread
  1157. * context of thread "wil6210_wmi"
  1158. */
  1159. void wmi_recv_cmd(struct wil6210_priv *wil)
  1160. {
  1161. struct wil6210_mbox_ring_desc d_tail;
  1162. struct wil6210_mbox_hdr hdr;
  1163. struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
  1164. struct pending_wmi_event *evt;
  1165. u8 *cmd;
  1166. void __iomem *src;
  1167. ulong flags;
  1168. unsigned n;
  1169. unsigned int num_immed_reply = 0;
  1170. if (!test_bit(wil_status_mbox_ready, wil->status)) {
  1171. wil_err(wil, "Reset in progress. Cannot handle WMI event\n");
  1172. return;
  1173. }
  1174. if (test_bit(wil_status_suspended, wil->status)) {
  1175. wil_err(wil, "suspended. cannot handle WMI event\n");
  1176. return;
  1177. }
  1178. for (n = 0;; n++) {
  1179. u16 len;
  1180. bool q;
  1181. bool immed_reply = false;
  1182. r->head = wil_r(wil, RGF_MBOX +
  1183. offsetof(struct wil6210_mbox_ctl, rx.head));
  1184. if (r->tail == r->head)
  1185. break;
  1186. wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
  1187. r->head, r->tail);
  1188. /* read cmd descriptor from tail */
  1189. wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
  1190. sizeof(struct wil6210_mbox_ring_desc));
  1191. if (d_tail.sync == 0) {
  1192. wil_err(wil, "Mbox evt not owned by FW?\n");
  1193. break;
  1194. }
  1195. /* read cmd header from descriptor */
  1196. if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
  1197. wil_err(wil, "Mbox evt at 0x%08x?\n",
  1198. le32_to_cpu(d_tail.addr));
  1199. break;
  1200. }
  1201. len = le16_to_cpu(hdr.len);
  1202. wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
  1203. le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
  1204. hdr.flags);
  1205. /* read cmd buffer from descriptor */
  1206. src = wmi_buffer(wil, d_tail.addr) +
  1207. sizeof(struct wil6210_mbox_hdr);
  1208. evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
  1209. event.wmi) + len, 4),
  1210. GFP_KERNEL);
  1211. if (!evt)
  1212. break;
  1213. evt->event.hdr = hdr;
  1214. cmd = (void *)&evt->event.wmi;
  1215. wil_memcpy_fromio_32(cmd, src, len);
  1216. /* mark entry as empty */
  1217. wil_w(wil, r->tail +
  1218. offsetof(struct wil6210_mbox_ring_desc, sync), 0);
  1219. /* indicate */
  1220. if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
  1221. (len >= sizeof(struct wmi_cmd_hdr))) {
  1222. struct wmi_cmd_hdr *wmi = &evt->event.wmi;
  1223. u16 id = le16_to_cpu(wmi->command_id);
  1224. u8 mid = wmi->mid;
  1225. u32 tstamp = le32_to_cpu(wmi->fw_timestamp);
  1226. if (test_bit(wil_status_resuming, wil->status)) {
  1227. if (id == WMI_TRAFFIC_RESUME_EVENTID)
  1228. clear_bit(wil_status_resuming,
  1229. wil->status);
  1230. else
  1231. wil_err(wil,
  1232. "WMI evt %d while resuming\n",
  1233. id);
  1234. }
  1235. spin_lock_irqsave(&wil->wmi_ev_lock, flags);
  1236. if (wil->reply_id && wil->reply_id == id &&
  1237. wil->reply_mid == mid) {
  1238. if (wil->reply_buf) {
  1239. memcpy(wil->reply_buf, wmi,
  1240. min(len, wil->reply_size));
  1241. immed_reply = true;
  1242. }
  1243. if (id == WMI_TRAFFIC_SUSPEND_EVENTID) {
  1244. wil_dbg_wmi(wil,
  1245. "set suspend_resp_rcvd\n");
  1246. wil->suspend_resp_rcvd = true;
  1247. }
  1248. }
  1249. spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
  1250. wil_dbg_wmi(wil, "recv %s (0x%04x) MID %d @%d msec\n",
  1251. eventid2name(id), id, wmi->mid, tstamp);
  1252. trace_wil6210_wmi_event(wmi, &wmi[1],
  1253. len - sizeof(*wmi));
  1254. }
  1255. wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
  1256. &evt->event.hdr, sizeof(hdr) + len, true);
  1257. /* advance tail */
  1258. r->tail = r->base + ((r->tail - r->base +
  1259. sizeof(struct wil6210_mbox_ring_desc)) % r->size);
  1260. wil_w(wil, RGF_MBOX +
  1261. offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail);
  1262. if (immed_reply) {
  1263. wil_dbg_wmi(wil, "recv_cmd: Complete WMI 0x%04x\n",
  1264. wil->reply_id);
  1265. kfree(evt);
  1266. num_immed_reply++;
  1267. complete(&wil->wmi_call);
  1268. } else {
  1269. /* add to the pending list */
  1270. spin_lock_irqsave(&wil->wmi_ev_lock, flags);
  1271. list_add_tail(&evt->list, &wil->pending_wmi_ev);
  1272. spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
  1273. q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
  1274. wil_dbg_wmi(wil, "queue_work -> %d\n", q);
  1275. }
  1276. }
  1277. /* normally, 1 event per IRQ should be processed */
  1278. wil_dbg_wmi(wil, "recv_cmd: -> %d events queued, %d completed\n",
  1279. n - num_immed_reply, num_immed_reply);
  1280. }
  1281. int wmi_call(struct wil6210_priv *wil, u16 cmdid, u8 mid, void *buf, u16 len,
  1282. u16 reply_id, void *reply, u16 reply_size, int to_msec)
  1283. {
  1284. int rc;
  1285. unsigned long remain;
  1286. mutex_lock(&wil->wmi_mutex);
  1287. spin_lock(&wil->wmi_ev_lock);
  1288. wil->reply_id = reply_id;
  1289. wil->reply_mid = mid;
  1290. wil->reply_buf = reply;
  1291. wil->reply_size = reply_size;
  1292. reinit_completion(&wil->wmi_call);
  1293. spin_unlock(&wil->wmi_ev_lock);
  1294. rc = __wmi_send(wil, cmdid, mid, buf, len);
  1295. if (rc)
  1296. goto out;
  1297. remain = wait_for_completion_timeout(&wil->wmi_call,
  1298. msecs_to_jiffies(to_msec));
  1299. if (0 == remain) {
  1300. wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
  1301. cmdid, reply_id, to_msec);
  1302. rc = -ETIME;
  1303. } else {
  1304. wil_dbg_wmi(wil,
  1305. "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
  1306. cmdid, reply_id,
  1307. to_msec - jiffies_to_msecs(remain));
  1308. }
  1309. out:
  1310. spin_lock(&wil->wmi_ev_lock);
  1311. wil->reply_id = 0;
  1312. wil->reply_mid = U8_MAX;
  1313. wil->reply_buf = NULL;
  1314. wil->reply_size = 0;
  1315. spin_unlock(&wil->wmi_ev_lock);
  1316. mutex_unlock(&wil->wmi_mutex);
  1317. return rc;
  1318. }
  1319. int wmi_echo(struct wil6210_priv *wil)
  1320. {
  1321. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1322. struct wmi_echo_cmd cmd = {
  1323. .value = cpu_to_le32(0x12345678),
  1324. };
  1325. return wmi_call(wil, WMI_ECHO_CMDID, vif->mid, &cmd, sizeof(cmd),
  1326. WMI_ECHO_RSP_EVENTID, NULL, 0, 50);
  1327. }
  1328. int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
  1329. {
  1330. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1331. struct wmi_set_mac_address_cmd cmd;
  1332. ether_addr_copy(cmd.mac, addr);
  1333. wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
  1334. return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, vif->mid,
  1335. &cmd, sizeof(cmd));
  1336. }
  1337. int wmi_led_cfg(struct wil6210_priv *wil, bool enable)
  1338. {
  1339. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1340. int rc = 0;
  1341. struct wmi_led_cfg_cmd cmd = {
  1342. .led_mode = enable,
  1343. .id = led_id,
  1344. .slow_blink_cfg.blink_on =
  1345. cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms),
  1346. .slow_blink_cfg.blink_off =
  1347. cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms),
  1348. .medium_blink_cfg.blink_on =
  1349. cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms),
  1350. .medium_blink_cfg.blink_off =
  1351. cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms),
  1352. .fast_blink_cfg.blink_on =
  1353. cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms),
  1354. .fast_blink_cfg.blink_off =
  1355. cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms),
  1356. .led_polarity = led_polarity,
  1357. };
  1358. struct {
  1359. struct wmi_cmd_hdr wmi;
  1360. struct wmi_led_cfg_done_event evt;
  1361. } __packed reply = {
  1362. .evt = {.status = cpu_to_le32(WMI_FW_STATUS_FAILURE)},
  1363. };
  1364. if (led_id == WIL_LED_INVALID_ID)
  1365. goto out;
  1366. if (led_id > WIL_LED_MAX_ID) {
  1367. wil_err(wil, "Invalid led id %d\n", led_id);
  1368. rc = -EINVAL;
  1369. goto out;
  1370. }
  1371. wil_dbg_wmi(wil,
  1372. "%s led %d\n",
  1373. enable ? "enabling" : "disabling", led_id);
  1374. rc = wmi_call(wil, WMI_LED_CFG_CMDID, vif->mid, &cmd, sizeof(cmd),
  1375. WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply),
  1376. 100);
  1377. if (rc)
  1378. goto out;
  1379. if (reply.evt.status) {
  1380. wil_err(wil, "led %d cfg failed with status %d\n",
  1381. led_id, le32_to_cpu(reply.evt.status));
  1382. rc = -EINVAL;
  1383. }
  1384. out:
  1385. return rc;
  1386. }
  1387. int wmi_pcp_start(struct wil6210_vif *vif,
  1388. int bi, u8 wmi_nettype, u8 chan, u8 hidden_ssid, u8 is_go)
  1389. {
  1390. struct wil6210_priv *wil = vif_to_wil(vif);
  1391. int rc;
  1392. struct wmi_pcp_start_cmd cmd = {
  1393. .bcon_interval = cpu_to_le16(bi),
  1394. .network_type = wmi_nettype,
  1395. .disable_sec_offload = 1,
  1396. .channel = chan - 1,
  1397. .pcp_max_assoc_sta = max_assoc_sta,
  1398. .hidden_ssid = hidden_ssid,
  1399. .is_go = is_go,
  1400. .ap_sme_offload_mode = disable_ap_sme ?
  1401. WMI_AP_SME_OFFLOAD_PARTIAL :
  1402. WMI_AP_SME_OFFLOAD_FULL,
  1403. .abft_len = wil->abft_len,
  1404. };
  1405. struct {
  1406. struct wmi_cmd_hdr wmi;
  1407. struct wmi_pcp_started_event evt;
  1408. } __packed reply = {
  1409. .evt = {.status = WMI_FW_STATUS_FAILURE},
  1410. };
  1411. if (!vif->privacy)
  1412. cmd.disable_sec = 1;
  1413. if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) ||
  1414. (cmd.pcp_max_assoc_sta <= 0)) {
  1415. wil_info(wil,
  1416. "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n",
  1417. max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID);
  1418. cmd.pcp_max_assoc_sta = WIL6210_MAX_CID;
  1419. }
  1420. if (disable_ap_sme &&
  1421. !test_bit(WMI_FW_CAPABILITY_AP_SME_OFFLOAD_PARTIAL,
  1422. wil->fw_capabilities)) {
  1423. wil_err(wil, "disable_ap_sme not supported by FW\n");
  1424. return -EOPNOTSUPP;
  1425. }
  1426. /*
  1427. * Processing time may be huge, in case of secure AP it takes about
  1428. * 3500ms for FW to start AP
  1429. */
  1430. rc = wmi_call(wil, WMI_PCP_START_CMDID, vif->mid, &cmd, sizeof(cmd),
  1431. WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
  1432. if (rc)
  1433. return rc;
  1434. if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
  1435. rc = -EINVAL;
  1436. if (wmi_nettype != WMI_NETTYPE_P2P)
  1437. /* Don't fail due to error in the led configuration */
  1438. wmi_led_cfg(wil, true);
  1439. return rc;
  1440. }
  1441. int wmi_pcp_stop(struct wil6210_vif *vif)
  1442. {
  1443. struct wil6210_priv *wil = vif_to_wil(vif);
  1444. int rc;
  1445. rc = wmi_led_cfg(wil, false);
  1446. if (rc)
  1447. return rc;
  1448. return wmi_call(wil, WMI_PCP_STOP_CMDID, vif->mid, NULL, 0,
  1449. WMI_PCP_STOPPED_EVENTID, NULL, 0, 20);
  1450. }
  1451. int wmi_set_ssid(struct wil6210_vif *vif, u8 ssid_len, const void *ssid)
  1452. {
  1453. struct wil6210_priv *wil = vif_to_wil(vif);
  1454. struct wmi_set_ssid_cmd cmd = {
  1455. .ssid_len = cpu_to_le32(ssid_len),
  1456. };
  1457. if (ssid_len > sizeof(cmd.ssid))
  1458. return -EINVAL;
  1459. memcpy(cmd.ssid, ssid, ssid_len);
  1460. return wmi_send(wil, WMI_SET_SSID_CMDID, vif->mid, &cmd, sizeof(cmd));
  1461. }
  1462. int wmi_get_ssid(struct wil6210_vif *vif, u8 *ssid_len, void *ssid)
  1463. {
  1464. struct wil6210_priv *wil = vif_to_wil(vif);
  1465. int rc;
  1466. struct {
  1467. struct wmi_cmd_hdr wmi;
  1468. struct wmi_set_ssid_cmd cmd;
  1469. } __packed reply;
  1470. int len; /* reply.cmd.ssid_len in CPU order */
  1471. memset(&reply, 0, sizeof(reply));
  1472. rc = wmi_call(wil, WMI_GET_SSID_CMDID, vif->mid, NULL, 0,
  1473. WMI_GET_SSID_EVENTID, &reply, sizeof(reply), 20);
  1474. if (rc)
  1475. return rc;
  1476. len = le32_to_cpu(reply.cmd.ssid_len);
  1477. if (len > sizeof(reply.cmd.ssid))
  1478. return -EINVAL;
  1479. *ssid_len = len;
  1480. memcpy(ssid, reply.cmd.ssid, len);
  1481. return 0;
  1482. }
  1483. int wmi_set_channel(struct wil6210_priv *wil, int channel)
  1484. {
  1485. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1486. struct wmi_set_pcp_channel_cmd cmd = {
  1487. .channel = channel - 1,
  1488. };
  1489. return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, vif->mid,
  1490. &cmd, sizeof(cmd));
  1491. }
  1492. int wmi_get_channel(struct wil6210_priv *wil, int *channel)
  1493. {
  1494. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1495. int rc;
  1496. struct {
  1497. struct wmi_cmd_hdr wmi;
  1498. struct wmi_set_pcp_channel_cmd cmd;
  1499. } __packed reply;
  1500. memset(&reply, 0, sizeof(reply));
  1501. rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, vif->mid, NULL, 0,
  1502. WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20);
  1503. if (rc)
  1504. return rc;
  1505. if (reply.cmd.channel > 3)
  1506. return -EINVAL;
  1507. *channel = reply.cmd.channel + 1;
  1508. return 0;
  1509. }
  1510. int wmi_p2p_cfg(struct wil6210_vif *vif, int channel, int bi)
  1511. {
  1512. struct wil6210_priv *wil = vif_to_wil(vif);
  1513. int rc;
  1514. struct wmi_p2p_cfg_cmd cmd = {
  1515. .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER,
  1516. .bcon_interval = cpu_to_le16(bi),
  1517. .channel = channel - 1,
  1518. };
  1519. struct {
  1520. struct wmi_cmd_hdr wmi;
  1521. struct wmi_p2p_cfg_done_event evt;
  1522. } __packed reply = {
  1523. .evt = {.status = WMI_FW_STATUS_FAILURE},
  1524. };
  1525. wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n");
  1526. rc = wmi_call(wil, WMI_P2P_CFG_CMDID, vif->mid, &cmd, sizeof(cmd),
  1527. WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300);
  1528. if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
  1529. wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status);
  1530. rc = -EINVAL;
  1531. }
  1532. return rc;
  1533. }
  1534. int wmi_start_listen(struct wil6210_vif *vif)
  1535. {
  1536. struct wil6210_priv *wil = vif_to_wil(vif);
  1537. int rc;
  1538. struct {
  1539. struct wmi_cmd_hdr wmi;
  1540. struct wmi_listen_started_event evt;
  1541. } __packed reply = {
  1542. .evt = {.status = WMI_FW_STATUS_FAILURE},
  1543. };
  1544. wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n");
  1545. rc = wmi_call(wil, WMI_START_LISTEN_CMDID, vif->mid, NULL, 0,
  1546. WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300);
  1547. if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
  1548. wil_err(wil, "device failed to start listen. status %d\n",
  1549. reply.evt.status);
  1550. rc = -EINVAL;
  1551. }
  1552. return rc;
  1553. }
  1554. int wmi_start_search(struct wil6210_vif *vif)
  1555. {
  1556. struct wil6210_priv *wil = vif_to_wil(vif);
  1557. int rc;
  1558. struct {
  1559. struct wmi_cmd_hdr wmi;
  1560. struct wmi_search_started_event evt;
  1561. } __packed reply = {
  1562. .evt = {.status = WMI_FW_STATUS_FAILURE},
  1563. };
  1564. wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n");
  1565. rc = wmi_call(wil, WMI_START_SEARCH_CMDID, vif->mid, NULL, 0,
  1566. WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300);
  1567. if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
  1568. wil_err(wil, "device failed to start search. status %d\n",
  1569. reply.evt.status);
  1570. rc = -EINVAL;
  1571. }
  1572. return rc;
  1573. }
  1574. int wmi_stop_discovery(struct wil6210_vif *vif)
  1575. {
  1576. struct wil6210_priv *wil = vif_to_wil(vif);
  1577. int rc;
  1578. wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n");
  1579. rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, vif->mid, NULL, 0,
  1580. WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100);
  1581. if (rc)
  1582. wil_err(wil, "Failed to stop discovery\n");
  1583. return rc;
  1584. }
  1585. int wmi_del_cipher_key(struct wil6210_vif *vif, u8 key_index,
  1586. const void *mac_addr, int key_usage)
  1587. {
  1588. struct wil6210_priv *wil = vif_to_wil(vif);
  1589. struct wmi_delete_cipher_key_cmd cmd = {
  1590. .key_index = key_index,
  1591. };
  1592. if (mac_addr)
  1593. memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
  1594. return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, vif->mid,
  1595. &cmd, sizeof(cmd));
  1596. }
  1597. int wmi_add_cipher_key(struct wil6210_vif *vif, u8 key_index,
  1598. const void *mac_addr, int key_len, const void *key,
  1599. int key_usage)
  1600. {
  1601. struct wil6210_priv *wil = vif_to_wil(vif);
  1602. struct wmi_add_cipher_key_cmd cmd = {
  1603. .key_index = key_index,
  1604. .key_usage = key_usage,
  1605. .key_len = key_len,
  1606. };
  1607. if (!key || (key_len > sizeof(cmd.key)))
  1608. return -EINVAL;
  1609. memcpy(cmd.key, key, key_len);
  1610. if (mac_addr)
  1611. memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
  1612. return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, vif->mid,
  1613. &cmd, sizeof(cmd));
  1614. }
  1615. int wmi_set_ie(struct wil6210_vif *vif, u8 type, u16 ie_len, const void *ie)
  1616. {
  1617. struct wil6210_priv *wil = vif_to_wil(vif);
  1618. static const char *const names[] = {
  1619. [WMI_FRAME_BEACON] = "BEACON",
  1620. [WMI_FRAME_PROBE_REQ] = "PROBE_REQ",
  1621. [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP",
  1622. [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ",
  1623. [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP",
  1624. };
  1625. int rc;
  1626. u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
  1627. struct wmi_set_appie_cmd *cmd;
  1628. if (len < ie_len) {
  1629. rc = -EINVAL;
  1630. goto out;
  1631. }
  1632. cmd = kzalloc(len, GFP_KERNEL);
  1633. if (!cmd) {
  1634. rc = -ENOMEM;
  1635. goto out;
  1636. }
  1637. if (!ie)
  1638. ie_len = 0;
  1639. cmd->mgmt_frm_type = type;
  1640. /* BUG: FW API define ieLen as u8. Will fix FW */
  1641. cmd->ie_len = cpu_to_le16(ie_len);
  1642. memcpy(cmd->ie_info, ie, ie_len);
  1643. rc = wmi_send(wil, WMI_SET_APPIE_CMDID, vif->mid, cmd, len);
  1644. kfree(cmd);
  1645. out:
  1646. if (rc) {
  1647. const char *name = type < ARRAY_SIZE(names) ?
  1648. names[type] : "??";
  1649. wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc);
  1650. }
  1651. return rc;
  1652. }
  1653. /**
  1654. * wmi_rxon - turn radio on/off
  1655. * @on: turn on if true, off otherwise
  1656. *
  1657. * Only switch radio. Channel should be set separately.
  1658. * No timeout for rxon - radio turned on forever unless some other call
  1659. * turns it off
  1660. */
  1661. int wmi_rxon(struct wil6210_priv *wil, bool on)
  1662. {
  1663. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1664. int rc;
  1665. struct {
  1666. struct wmi_cmd_hdr wmi;
  1667. struct wmi_listen_started_event evt;
  1668. } __packed reply = {
  1669. .evt = {.status = WMI_FW_STATUS_FAILURE},
  1670. };
  1671. wil_info(wil, "(%s)\n", on ? "on" : "off");
  1672. if (on) {
  1673. rc = wmi_call(wil, WMI_START_LISTEN_CMDID, vif->mid, NULL, 0,
  1674. WMI_LISTEN_STARTED_EVENTID,
  1675. &reply, sizeof(reply), 100);
  1676. if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
  1677. rc = -EINVAL;
  1678. } else {
  1679. rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, vif->mid, NULL, 0,
  1680. WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20);
  1681. }
  1682. return rc;
  1683. }
  1684. int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
  1685. {
  1686. struct net_device *ndev = wil->main_ndev;
  1687. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  1688. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1689. struct wmi_cfg_rx_chain_cmd cmd = {
  1690. .action = WMI_RX_CHAIN_ADD,
  1691. .rx_sw_ring = {
  1692. .max_mpdu_size = cpu_to_le16(
  1693. wil_mtu2macbuf(wil->rx_buf_len)),
  1694. .ring_mem_base = cpu_to_le64(vring->pa),
  1695. .ring_size = cpu_to_le16(vring->size),
  1696. },
  1697. .mid = 0, /* TODO - what is it? */
  1698. .decap_trans_type = WMI_DECAP_TYPE_802_3,
  1699. .reorder_type = WMI_RX_SW_REORDER,
  1700. .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh),
  1701. };
  1702. struct {
  1703. struct wmi_cmd_hdr wmi;
  1704. struct wmi_cfg_rx_chain_done_event evt;
  1705. } __packed evt;
  1706. int rc;
  1707. memset(&evt, 0, sizeof(evt));
  1708. if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
  1709. struct ieee80211_channel *ch = wil->monitor_chandef.chan;
  1710. cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
  1711. if (ch)
  1712. cmd.sniffer_cfg.channel = ch->hw_value - 1;
  1713. cmd.sniffer_cfg.phy_info_mode =
  1714. cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP);
  1715. cmd.sniffer_cfg.phy_support =
  1716. cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
  1717. ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS);
  1718. } else {
  1719. /* Initialize offload (in non-sniffer mode).
  1720. * Linux IP stack always calculates IP checksum
  1721. * HW always calculate TCP/UDP checksum
  1722. */
  1723. cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
  1724. }
  1725. if (rx_align_2)
  1726. cmd.l2_802_3_offload_ctrl |=
  1727. L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK;
  1728. /* typical time for secure PCP is 840ms */
  1729. rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, vif->mid, &cmd, sizeof(cmd),
  1730. WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
  1731. if (rc)
  1732. return rc;
  1733. if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
  1734. rc = -EINVAL;
  1735. vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
  1736. wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
  1737. le32_to_cpu(evt.evt.status), vring->hwtail);
  1738. return rc;
  1739. }
  1740. int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf)
  1741. {
  1742. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1743. int rc;
  1744. struct wmi_temp_sense_cmd cmd = {
  1745. .measure_baseband_en = cpu_to_le32(!!t_bb),
  1746. .measure_rf_en = cpu_to_le32(!!t_rf),
  1747. .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW),
  1748. };
  1749. struct {
  1750. struct wmi_cmd_hdr wmi;
  1751. struct wmi_temp_sense_done_event evt;
  1752. } __packed reply;
  1753. memset(&reply, 0, sizeof(reply));
  1754. rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, vif->mid, &cmd, sizeof(cmd),
  1755. WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100);
  1756. if (rc)
  1757. return rc;
  1758. if (t_bb)
  1759. *t_bb = le32_to_cpu(reply.evt.baseband_t1000);
  1760. if (t_rf)
  1761. *t_rf = le32_to_cpu(reply.evt.rf_t1000);
  1762. return 0;
  1763. }
  1764. int wmi_disconnect_sta(struct wil6210_vif *vif, const u8 *mac,
  1765. u16 reason, bool full_disconnect, bool del_sta)
  1766. {
  1767. struct wil6210_priv *wil = vif_to_wil(vif);
  1768. int rc;
  1769. u16 reason_code;
  1770. struct wmi_disconnect_sta_cmd disc_sta_cmd = {
  1771. .disconnect_reason = cpu_to_le16(reason),
  1772. };
  1773. struct wmi_del_sta_cmd del_sta_cmd = {
  1774. .disconnect_reason = cpu_to_le16(reason),
  1775. };
  1776. struct {
  1777. struct wmi_cmd_hdr wmi;
  1778. struct wmi_disconnect_event evt;
  1779. } __packed reply;
  1780. wil_dbg_wmi(wil, "disconnect_sta: (%pM, reason %d)\n", mac, reason);
  1781. memset(&reply, 0, sizeof(reply));
  1782. vif->locally_generated_disc = true;
  1783. if (del_sta) {
  1784. ether_addr_copy(del_sta_cmd.dst_mac, mac);
  1785. rc = wmi_call(wil, WMI_DEL_STA_CMDID, vif->mid, &del_sta_cmd,
  1786. sizeof(del_sta_cmd), WMI_DISCONNECT_EVENTID,
  1787. &reply, sizeof(reply), 1000);
  1788. } else {
  1789. ether_addr_copy(disc_sta_cmd.dst_mac, mac);
  1790. rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, vif->mid,
  1791. &disc_sta_cmd, sizeof(disc_sta_cmd),
  1792. WMI_DISCONNECT_EVENTID,
  1793. &reply, sizeof(reply), 1000);
  1794. }
  1795. /* failure to disconnect in reasonable time treated as FW error */
  1796. if (rc) {
  1797. wil_fw_error_recovery(wil);
  1798. return rc;
  1799. }
  1800. if (full_disconnect) {
  1801. /* call event handler manually after processing wmi_call,
  1802. * to avoid deadlock - disconnect event handler acquires
  1803. * wil->mutex while it is already held here
  1804. */
  1805. reason_code = le16_to_cpu(reply.evt.protocol_reason_status);
  1806. wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
  1807. reply.evt.bssid, reason_code,
  1808. reply.evt.disconnect_reason);
  1809. wil->sinfo_gen++;
  1810. wil6210_disconnect(vif, reply.evt.bssid, reason_code, true);
  1811. }
  1812. return 0;
  1813. }
  1814. int wmi_addba(struct wil6210_priv *wil, u8 mid,
  1815. u8 ringid, u8 size, u16 timeout)
  1816. {
  1817. struct wmi_vring_ba_en_cmd cmd = {
  1818. .ringid = ringid,
  1819. .agg_max_wsize = size,
  1820. .ba_timeout = cpu_to_le16(timeout),
  1821. .amsdu = 0,
  1822. };
  1823. wil_dbg_wmi(wil, "addba: (ring %d size %d timeout %d)\n", ringid, size,
  1824. timeout);
  1825. return wmi_send(wil, WMI_VRING_BA_EN_CMDID, mid, &cmd, sizeof(cmd));
  1826. }
  1827. int wmi_delba_tx(struct wil6210_priv *wil, u8 mid, u8 ringid, u16 reason)
  1828. {
  1829. struct wmi_vring_ba_dis_cmd cmd = {
  1830. .ringid = ringid,
  1831. .reason = cpu_to_le16(reason),
  1832. };
  1833. wil_dbg_wmi(wil, "delba_tx: (ring %d reason %d)\n", ringid, reason);
  1834. return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, mid, &cmd, sizeof(cmd));
  1835. }
  1836. int wmi_delba_rx(struct wil6210_priv *wil, u8 mid, u8 cidxtid, u16 reason)
  1837. {
  1838. struct wmi_rcp_delba_cmd cmd = {
  1839. .cidxtid = cidxtid,
  1840. .reason = cpu_to_le16(reason),
  1841. };
  1842. wil_dbg_wmi(wil, "delba_rx: (CID %d TID %d reason %d)\n", cidxtid & 0xf,
  1843. (cidxtid >> 4) & 0xf, reason);
  1844. return wmi_send(wil, WMI_RCP_DELBA_CMDID, mid, &cmd, sizeof(cmd));
  1845. }
  1846. int wmi_addba_rx_resp(struct wil6210_priv *wil,
  1847. u8 mid, u8 cid, u8 tid, u8 token,
  1848. u16 status, bool amsdu, u16 agg_wsize, u16 timeout)
  1849. {
  1850. int rc;
  1851. struct wmi_rcp_addba_resp_cmd cmd = {
  1852. .cidxtid = mk_cidxtid(cid, tid),
  1853. .dialog_token = token,
  1854. .status_code = cpu_to_le16(status),
  1855. /* bit 0: A-MSDU supported
  1856. * bit 1: policy (should be 0 for us)
  1857. * bits 2..5: TID
  1858. * bits 6..15: buffer size
  1859. */
  1860. .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
  1861. (agg_wsize << 6)),
  1862. .ba_timeout = cpu_to_le16(timeout),
  1863. };
  1864. struct {
  1865. struct wmi_cmd_hdr wmi;
  1866. struct wmi_rcp_addba_resp_sent_event evt;
  1867. } __packed reply = {
  1868. .evt = {.status = cpu_to_le16(WMI_FW_STATUS_FAILURE)},
  1869. };
  1870. wil_dbg_wmi(wil,
  1871. "ADDBA response for MID %d CID %d TID %d size %d timeout %d status %d AMSDU%s\n",
  1872. mid, cid, tid, agg_wsize,
  1873. timeout, status, amsdu ? "+" : "-");
  1874. rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, mid, &cmd, sizeof(cmd),
  1875. WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply),
  1876. 100);
  1877. if (rc)
  1878. return rc;
  1879. if (reply.evt.status) {
  1880. wil_err(wil, "ADDBA response failed with status %d\n",
  1881. le16_to_cpu(reply.evt.status));
  1882. rc = -EINVAL;
  1883. }
  1884. return rc;
  1885. }
  1886. int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil,
  1887. enum wmi_ps_profile_type ps_profile)
  1888. {
  1889. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1890. int rc;
  1891. struct wmi_ps_dev_profile_cfg_cmd cmd = {
  1892. .ps_profile = ps_profile,
  1893. };
  1894. struct {
  1895. struct wmi_cmd_hdr wmi;
  1896. struct wmi_ps_dev_profile_cfg_event evt;
  1897. } __packed reply = {
  1898. .evt = {.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR)},
  1899. };
  1900. u32 status;
  1901. wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile);
  1902. rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, vif->mid,
  1903. &cmd, sizeof(cmd),
  1904. WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply),
  1905. 100);
  1906. if (rc)
  1907. return rc;
  1908. status = le32_to_cpu(reply.evt.status);
  1909. if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) {
  1910. wil_err(wil, "ps dev profile cfg failed with status %d\n",
  1911. status);
  1912. rc = -EINVAL;
  1913. }
  1914. return rc;
  1915. }
  1916. int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short)
  1917. {
  1918. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1919. int rc;
  1920. struct wmi_set_mgmt_retry_limit_cmd cmd = {
  1921. .mgmt_retry_limit = retry_short,
  1922. };
  1923. struct {
  1924. struct wmi_cmd_hdr wmi;
  1925. struct wmi_set_mgmt_retry_limit_event evt;
  1926. } __packed reply = {
  1927. .evt = {.status = WMI_FW_STATUS_FAILURE},
  1928. };
  1929. wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short);
  1930. if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
  1931. return -ENOTSUPP;
  1932. rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, vif->mid,
  1933. &cmd, sizeof(cmd),
  1934. WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
  1935. 100);
  1936. if (rc)
  1937. return rc;
  1938. if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
  1939. wil_err(wil, "set mgmt retry limit failed with status %d\n",
  1940. reply.evt.status);
  1941. rc = -EINVAL;
  1942. }
  1943. return rc;
  1944. }
  1945. int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short)
  1946. {
  1947. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1948. int rc;
  1949. struct {
  1950. struct wmi_cmd_hdr wmi;
  1951. struct wmi_get_mgmt_retry_limit_event evt;
  1952. } __packed reply;
  1953. wil_dbg_wmi(wil, "getting mgmt retry short\n");
  1954. if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
  1955. return -ENOTSUPP;
  1956. memset(&reply, 0, sizeof(reply));
  1957. rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, vif->mid, NULL, 0,
  1958. WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
  1959. 100);
  1960. if (rc)
  1961. return rc;
  1962. if (retry_short)
  1963. *retry_short = reply.evt.mgmt_retry_limit;
  1964. return 0;
  1965. }
  1966. int wmi_abort_scan(struct wil6210_vif *vif)
  1967. {
  1968. struct wil6210_priv *wil = vif_to_wil(vif);
  1969. int rc;
  1970. wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n");
  1971. rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, vif->mid, NULL, 0);
  1972. if (rc)
  1973. wil_err(wil, "Failed to abort scan (%d)\n", rc);
  1974. return rc;
  1975. }
  1976. int wmi_new_sta(struct wil6210_vif *vif, const u8 *mac, u8 aid)
  1977. {
  1978. struct wil6210_priv *wil = vif_to_wil(vif);
  1979. int rc;
  1980. struct wmi_new_sta_cmd cmd = {
  1981. .aid = aid,
  1982. };
  1983. wil_dbg_wmi(wil, "new sta %pM, aid %d\n", mac, aid);
  1984. ether_addr_copy(cmd.dst_mac, mac);
  1985. rc = wmi_send(wil, WMI_NEW_STA_CMDID, vif->mid, &cmd, sizeof(cmd));
  1986. if (rc)
  1987. wil_err(wil, "Failed to send new sta (%d)\n", rc);
  1988. return rc;
  1989. }
  1990. void wmi_event_flush(struct wil6210_priv *wil)
  1991. {
  1992. ulong flags;
  1993. struct pending_wmi_event *evt, *t;
  1994. wil_dbg_wmi(wil, "event_flush\n");
  1995. spin_lock_irqsave(&wil->wmi_ev_lock, flags);
  1996. list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
  1997. list_del(&evt->list);
  1998. kfree(evt);
  1999. }
  2000. spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
  2001. }
  2002. static const char *suspend_status2name(u8 status)
  2003. {
  2004. switch (status) {
  2005. case WMI_TRAFFIC_SUSPEND_REJECTED_LINK_NOT_IDLE:
  2006. return "LINK_NOT_IDLE";
  2007. default:
  2008. return "Untracked status";
  2009. }
  2010. }
  2011. int wmi_suspend(struct wil6210_priv *wil)
  2012. {
  2013. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  2014. int rc;
  2015. struct wmi_traffic_suspend_cmd cmd = {
  2016. .wakeup_trigger = wil->wakeup_trigger,
  2017. };
  2018. struct {
  2019. struct wmi_cmd_hdr wmi;
  2020. struct wmi_traffic_suspend_event evt;
  2021. } __packed reply = {
  2022. .evt = {.status = WMI_TRAFFIC_SUSPEND_REJECTED_LINK_NOT_IDLE},
  2023. };
  2024. u32 suspend_to = WIL_WAIT_FOR_SUSPEND_RESUME_COMP;
  2025. wil->suspend_resp_rcvd = false;
  2026. wil->suspend_resp_comp = false;
  2027. rc = wmi_call(wil, WMI_TRAFFIC_SUSPEND_CMDID, vif->mid,
  2028. &cmd, sizeof(cmd),
  2029. WMI_TRAFFIC_SUSPEND_EVENTID, &reply, sizeof(reply),
  2030. suspend_to);
  2031. if (rc) {
  2032. wil_err(wil, "wmi_call for suspend req failed, rc=%d\n", rc);
  2033. if (rc == -ETIME)
  2034. /* wmi_call TO */
  2035. wil->suspend_stats.rejected_by_device++;
  2036. else
  2037. wil->suspend_stats.rejected_by_host++;
  2038. goto out;
  2039. }
  2040. wil_dbg_wmi(wil, "waiting for suspend_response_completed\n");
  2041. rc = wait_event_interruptible_timeout(wil->wq,
  2042. wil->suspend_resp_comp,
  2043. msecs_to_jiffies(suspend_to));
  2044. if (rc == 0) {
  2045. wil_err(wil, "TO waiting for suspend_response_completed\n");
  2046. if (wil->suspend_resp_rcvd)
  2047. /* Device responded but we TO due to another reason */
  2048. wil->suspend_stats.rejected_by_host++;
  2049. else
  2050. wil->suspend_stats.rejected_by_device++;
  2051. rc = -EBUSY;
  2052. goto out;
  2053. }
  2054. wil_dbg_wmi(wil, "suspend_response_completed rcvd\n");
  2055. if (reply.evt.status != WMI_TRAFFIC_SUSPEND_APPROVED) {
  2056. wil_dbg_pm(wil, "device rejected the suspend, %s\n",
  2057. suspend_status2name(reply.evt.status));
  2058. wil->suspend_stats.rejected_by_device++;
  2059. }
  2060. rc = reply.evt.status;
  2061. out:
  2062. wil->suspend_resp_rcvd = false;
  2063. wil->suspend_resp_comp = false;
  2064. return rc;
  2065. }
  2066. static void resume_triggers2string(u32 triggers, char *string, int str_size)
  2067. {
  2068. string[0] = '\0';
  2069. if (!triggers) {
  2070. strlcat(string, " UNKNOWN", str_size);
  2071. return;
  2072. }
  2073. if (triggers & WMI_RESUME_TRIGGER_HOST)
  2074. strlcat(string, " HOST", str_size);
  2075. if (triggers & WMI_RESUME_TRIGGER_UCAST_RX)
  2076. strlcat(string, " UCAST_RX", str_size);
  2077. if (triggers & WMI_RESUME_TRIGGER_BCAST_RX)
  2078. strlcat(string, " BCAST_RX", str_size);
  2079. if (triggers & WMI_RESUME_TRIGGER_WMI_EVT)
  2080. strlcat(string, " WMI_EVT", str_size);
  2081. }
  2082. int wmi_resume(struct wil6210_priv *wil)
  2083. {
  2084. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  2085. int rc;
  2086. char string[100];
  2087. struct {
  2088. struct wmi_cmd_hdr wmi;
  2089. struct wmi_traffic_resume_event evt;
  2090. } __packed reply = {
  2091. .evt = {.status = WMI_TRAFFIC_RESUME_FAILED,
  2092. .resume_triggers =
  2093. cpu_to_le32(WMI_RESUME_TRIGGER_UNKNOWN)},
  2094. };
  2095. rc = wmi_call(wil, WMI_TRAFFIC_RESUME_CMDID, vif->mid, NULL, 0,
  2096. WMI_TRAFFIC_RESUME_EVENTID, &reply, sizeof(reply),
  2097. WIL_WAIT_FOR_SUSPEND_RESUME_COMP);
  2098. if (rc)
  2099. return rc;
  2100. resume_triggers2string(le32_to_cpu(reply.evt.resume_triggers), string,
  2101. sizeof(string));
  2102. wil_dbg_pm(wil, "device resume %s, resume triggers:%s (0x%x)\n",
  2103. reply.evt.status ? "failed" : "passed", string,
  2104. le32_to_cpu(reply.evt.resume_triggers));
  2105. return reply.evt.status;
  2106. }
  2107. int wmi_port_allocate(struct wil6210_priv *wil, u8 mid,
  2108. const u8 *mac, enum nl80211_iftype iftype)
  2109. {
  2110. int rc;
  2111. struct wmi_port_allocate_cmd cmd = {
  2112. .mid = mid,
  2113. };
  2114. struct {
  2115. struct wmi_cmd_hdr wmi;
  2116. struct wmi_port_allocated_event evt;
  2117. } __packed reply = {
  2118. .evt = {.status = WMI_FW_STATUS_FAILURE},
  2119. };
  2120. wil_dbg_misc(wil, "port allocate, mid %d iftype %d, mac %pM\n",
  2121. mid, iftype, mac);
  2122. ether_addr_copy(cmd.mac, mac);
  2123. switch (iftype) {
  2124. case NL80211_IFTYPE_STATION:
  2125. cmd.port_role = WMI_PORT_STA;
  2126. break;
  2127. case NL80211_IFTYPE_AP:
  2128. cmd.port_role = WMI_PORT_AP;
  2129. break;
  2130. case NL80211_IFTYPE_P2P_CLIENT:
  2131. cmd.port_role = WMI_PORT_P2P_CLIENT;
  2132. break;
  2133. case NL80211_IFTYPE_P2P_GO:
  2134. cmd.port_role = WMI_PORT_P2P_GO;
  2135. break;
  2136. /* what about monitor??? */
  2137. default:
  2138. wil_err(wil, "unsupported iftype: %d\n", iftype);
  2139. return -EINVAL;
  2140. }
  2141. rc = wmi_call(wil, WMI_PORT_ALLOCATE_CMDID, mid,
  2142. &cmd, sizeof(cmd),
  2143. WMI_PORT_ALLOCATED_EVENTID, &reply,
  2144. sizeof(reply), 300);
  2145. if (rc) {
  2146. wil_err(wil, "failed to allocate port, status %d\n", rc);
  2147. return rc;
  2148. }
  2149. if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
  2150. wil_err(wil, "WMI_PORT_ALLOCATE returned status %d\n",
  2151. reply.evt.status);
  2152. return -EINVAL;
  2153. }
  2154. return 0;
  2155. }
  2156. int wmi_port_delete(struct wil6210_priv *wil, u8 mid)
  2157. {
  2158. int rc;
  2159. struct wmi_port_delete_cmd cmd = {
  2160. .mid = mid,
  2161. };
  2162. struct {
  2163. struct wmi_cmd_hdr wmi;
  2164. struct wmi_port_deleted_event evt;
  2165. } __packed reply = {
  2166. .evt = {.status = WMI_FW_STATUS_FAILURE},
  2167. };
  2168. wil_dbg_misc(wil, "port delete, mid %d\n", mid);
  2169. rc = wmi_call(wil, WMI_PORT_DELETE_CMDID, mid,
  2170. &cmd, sizeof(cmd),
  2171. WMI_PORT_DELETED_EVENTID, &reply,
  2172. sizeof(reply), 2000);
  2173. if (rc) {
  2174. wil_err(wil, "failed to delete port, status %d\n", rc);
  2175. return rc;
  2176. }
  2177. if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
  2178. wil_err(wil, "WMI_PORT_DELETE returned status %d\n",
  2179. reply.evt.status);
  2180. return -EINVAL;
  2181. }
  2182. return 0;
  2183. }
  2184. static bool wmi_evt_call_handler(struct wil6210_vif *vif, int id,
  2185. void *d, int len)
  2186. {
  2187. uint i;
  2188. for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
  2189. if (wmi_evt_handlers[i].eventid == id) {
  2190. wmi_evt_handlers[i].handler(vif, id, d, len);
  2191. return true;
  2192. }
  2193. }
  2194. return false;
  2195. }
  2196. static void wmi_event_handle(struct wil6210_priv *wil,
  2197. struct wil6210_mbox_hdr *hdr)
  2198. {
  2199. u16 len = le16_to_cpu(hdr->len);
  2200. struct wil6210_vif *vif;
  2201. if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
  2202. (len >= sizeof(struct wmi_cmd_hdr))) {
  2203. struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]);
  2204. void *evt_data = (void *)(&wmi[1]);
  2205. u16 id = le16_to_cpu(wmi->command_id);
  2206. u8 mid = wmi->mid;
  2207. wil_dbg_wmi(wil, "Handle %s (0x%04x) (reply_id 0x%04x,%d)\n",
  2208. eventid2name(id), id, wil->reply_id,
  2209. wil->reply_mid);
  2210. if (mid == MID_BROADCAST)
  2211. mid = 0;
  2212. if (mid >= wil->max_vifs) {
  2213. wil_dbg_wmi(wil, "invalid mid %d, event skipped\n",
  2214. mid);
  2215. return;
  2216. }
  2217. vif = wil->vifs[mid];
  2218. if (!vif) {
  2219. wil_dbg_wmi(wil, "event for empty VIF(%d), skipped\n",
  2220. mid);
  2221. return;
  2222. }
  2223. /* check if someone waits for this event */
  2224. if (wil->reply_id && wil->reply_id == id &&
  2225. wil->reply_mid == mid) {
  2226. WARN_ON(wil->reply_buf);
  2227. wmi_evt_call_handler(vif, id, evt_data,
  2228. len - sizeof(*wmi));
  2229. wil_dbg_wmi(wil, "event_handle: Complete WMI 0x%04x\n",
  2230. id);
  2231. complete(&wil->wmi_call);
  2232. return;
  2233. }
  2234. /* unsolicited event */
  2235. /* search for handler */
  2236. if (!wmi_evt_call_handler(vif, id, evt_data,
  2237. len - sizeof(*wmi))) {
  2238. wil_info(wil, "Unhandled event 0x%04x\n", id);
  2239. }
  2240. } else {
  2241. wil_err(wil, "Unknown event type\n");
  2242. print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
  2243. hdr, sizeof(*hdr) + len, true);
  2244. }
  2245. }
  2246. /*
  2247. * Retrieve next WMI event from the pending list
  2248. */
  2249. static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
  2250. {
  2251. ulong flags;
  2252. struct list_head *ret = NULL;
  2253. spin_lock_irqsave(&wil->wmi_ev_lock, flags);
  2254. if (!list_empty(&wil->pending_wmi_ev)) {
  2255. ret = wil->pending_wmi_ev.next;
  2256. list_del(ret);
  2257. }
  2258. spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
  2259. return ret;
  2260. }
  2261. /*
  2262. * Handler for the WMI events
  2263. */
  2264. void wmi_event_worker(struct work_struct *work)
  2265. {
  2266. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  2267. wmi_event_worker);
  2268. struct pending_wmi_event *evt;
  2269. struct list_head *lh;
  2270. wil_dbg_wmi(wil, "event_worker: Start\n");
  2271. while ((lh = next_wmi_ev(wil)) != NULL) {
  2272. evt = list_entry(lh, struct pending_wmi_event, list);
  2273. wmi_event_handle(wil, &evt->event.hdr);
  2274. kfree(evt);
  2275. }
  2276. wil_dbg_wmi(wil, "event_worker: Finished\n");
  2277. }
  2278. bool wil_is_wmi_idle(struct wil6210_priv *wil)
  2279. {
  2280. ulong flags;
  2281. struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
  2282. bool rc = false;
  2283. spin_lock_irqsave(&wil->wmi_ev_lock, flags);
  2284. /* Check if there are pending WMI events in the events queue */
  2285. if (!list_empty(&wil->pending_wmi_ev)) {
  2286. wil_dbg_pm(wil, "Pending WMI events in queue\n");
  2287. goto out;
  2288. }
  2289. /* Check if there is a pending WMI call */
  2290. if (wil->reply_id) {
  2291. wil_dbg_pm(wil, "Pending WMI call\n");
  2292. goto out;
  2293. }
  2294. /* Check if there are pending RX events in mbox */
  2295. r->head = wil_r(wil, RGF_MBOX +
  2296. offsetof(struct wil6210_mbox_ctl, rx.head));
  2297. if (r->tail != r->head)
  2298. wil_dbg_pm(wil, "Pending WMI mbox events\n");
  2299. else
  2300. rc = true;
  2301. out:
  2302. spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
  2303. return rc;
  2304. }
  2305. static void
  2306. wmi_sched_scan_set_ssids(struct wil6210_priv *wil,
  2307. struct wmi_start_sched_scan_cmd *cmd,
  2308. struct cfg80211_ssid *ssids, int n_ssids,
  2309. struct cfg80211_match_set *match_sets,
  2310. int n_match_sets)
  2311. {
  2312. int i;
  2313. if (n_match_sets > WMI_MAX_PNO_SSID_NUM) {
  2314. wil_dbg_wmi(wil, "too many match sets (%d), use first %d\n",
  2315. n_match_sets, WMI_MAX_PNO_SSID_NUM);
  2316. n_match_sets = WMI_MAX_PNO_SSID_NUM;
  2317. }
  2318. cmd->num_of_ssids = n_match_sets;
  2319. for (i = 0; i < n_match_sets; i++) {
  2320. struct wmi_sched_scan_ssid_match *wmi_match =
  2321. &cmd->ssid_for_match[i];
  2322. struct cfg80211_match_set *cfg_match = &match_sets[i];
  2323. int j;
  2324. wmi_match->ssid_len = cfg_match->ssid.ssid_len;
  2325. memcpy(wmi_match->ssid, cfg_match->ssid.ssid,
  2326. min_t(u8, wmi_match->ssid_len, WMI_MAX_SSID_LEN));
  2327. wmi_match->rssi_threshold = S8_MIN;
  2328. if (cfg_match->rssi_thold >= S8_MIN &&
  2329. cfg_match->rssi_thold <= S8_MAX)
  2330. wmi_match->rssi_threshold = cfg_match->rssi_thold;
  2331. for (j = 0; j < n_ssids; j++)
  2332. if (wmi_match->ssid_len == ssids[j].ssid_len &&
  2333. memcmp(wmi_match->ssid, ssids[j].ssid,
  2334. wmi_match->ssid_len) == 0)
  2335. wmi_match->add_ssid_to_probe = true;
  2336. }
  2337. }
  2338. static void
  2339. wmi_sched_scan_set_channels(struct wil6210_priv *wil,
  2340. struct wmi_start_sched_scan_cmd *cmd,
  2341. u32 n_channels,
  2342. struct ieee80211_channel **channels)
  2343. {
  2344. int i;
  2345. if (n_channels > WMI_MAX_CHANNEL_NUM) {
  2346. wil_dbg_wmi(wil, "too many channels (%d), use first %d\n",
  2347. n_channels, WMI_MAX_CHANNEL_NUM);
  2348. n_channels = WMI_MAX_CHANNEL_NUM;
  2349. }
  2350. cmd->num_of_channels = n_channels;
  2351. for (i = 0; i < n_channels; i++) {
  2352. struct ieee80211_channel *cfg_chan = channels[i];
  2353. cmd->channel_list[i] = cfg_chan->hw_value - 1;
  2354. }
  2355. }
  2356. static void
  2357. wmi_sched_scan_set_plans(struct wil6210_priv *wil,
  2358. struct wmi_start_sched_scan_cmd *cmd,
  2359. struct cfg80211_sched_scan_plan *scan_plans,
  2360. int n_scan_plans)
  2361. {
  2362. int i;
  2363. if (n_scan_plans > WMI_MAX_PLANS_NUM) {
  2364. wil_dbg_wmi(wil, "too many plans (%d), use first %d\n",
  2365. n_scan_plans, WMI_MAX_PLANS_NUM);
  2366. n_scan_plans = WMI_MAX_PLANS_NUM;
  2367. }
  2368. for (i = 0; i < n_scan_plans; i++) {
  2369. struct cfg80211_sched_scan_plan *cfg_plan = &scan_plans[i];
  2370. cmd->scan_plans[i].interval_sec =
  2371. cpu_to_le16(cfg_plan->interval);
  2372. cmd->scan_plans[i].num_of_iterations =
  2373. cpu_to_le16(cfg_plan->iterations);
  2374. }
  2375. }
  2376. int wmi_start_sched_scan(struct wil6210_priv *wil,
  2377. struct cfg80211_sched_scan_request *request)
  2378. {
  2379. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  2380. int rc;
  2381. struct wmi_start_sched_scan_cmd cmd = {
  2382. .min_rssi_threshold = S8_MIN,
  2383. .initial_delay_sec = cpu_to_le16(request->delay),
  2384. };
  2385. struct {
  2386. struct wmi_cmd_hdr wmi;
  2387. struct wmi_start_sched_scan_event evt;
  2388. } __packed reply = {
  2389. .evt = {.result = WMI_PNO_REJECT},
  2390. };
  2391. if (!test_bit(WMI_FW_CAPABILITY_PNO, wil->fw_capabilities))
  2392. return -ENOTSUPP;
  2393. if (request->min_rssi_thold >= S8_MIN &&
  2394. request->min_rssi_thold <= S8_MAX)
  2395. cmd.min_rssi_threshold = request->min_rssi_thold;
  2396. wmi_sched_scan_set_ssids(wil, &cmd, request->ssids, request->n_ssids,
  2397. request->match_sets, request->n_match_sets);
  2398. wmi_sched_scan_set_channels(wil, &cmd,
  2399. request->n_channels, request->channels);
  2400. wmi_sched_scan_set_plans(wil, &cmd,
  2401. request->scan_plans, request->n_scan_plans);
  2402. rc = wmi_call(wil, WMI_START_SCHED_SCAN_CMDID, vif->mid,
  2403. &cmd, sizeof(cmd),
  2404. WMI_START_SCHED_SCAN_EVENTID, &reply, sizeof(reply),
  2405. WIL_WMI_CALL_GENERAL_TO_MS);
  2406. if (rc)
  2407. return rc;
  2408. if (reply.evt.result != WMI_PNO_SUCCESS) {
  2409. wil_err(wil, "start sched scan failed, result %d\n",
  2410. reply.evt.result);
  2411. return -EINVAL;
  2412. }
  2413. return 0;
  2414. }
  2415. int wmi_stop_sched_scan(struct wil6210_priv *wil)
  2416. {
  2417. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  2418. int rc;
  2419. struct {
  2420. struct wmi_cmd_hdr wmi;
  2421. struct wmi_stop_sched_scan_event evt;
  2422. } __packed reply = {
  2423. .evt = {.result = WMI_PNO_REJECT},
  2424. };
  2425. if (!test_bit(WMI_FW_CAPABILITY_PNO, wil->fw_capabilities))
  2426. return -ENOTSUPP;
  2427. rc = wmi_call(wil, WMI_STOP_SCHED_SCAN_CMDID, vif->mid, NULL, 0,
  2428. WMI_STOP_SCHED_SCAN_EVENTID, &reply, sizeof(reply),
  2429. WIL_WMI_CALL_GENERAL_TO_MS);
  2430. if (rc)
  2431. return rc;
  2432. if (reply.evt.result != WMI_PNO_SUCCESS) {
  2433. wil_err(wil, "stop sched scan failed, result %d\n",
  2434. reply.evt.result);
  2435. return -EINVAL;
  2436. }
  2437. return 0;
  2438. }
  2439. int wmi_mgmt_tx(struct wil6210_vif *vif, const u8 *buf, size_t len)
  2440. {
  2441. size_t total;
  2442. struct wil6210_priv *wil = vif_to_wil(vif);
  2443. struct ieee80211_mgmt *mgmt_frame = (void *)buf;
  2444. struct wmi_sw_tx_req_cmd *cmd;
  2445. struct {
  2446. struct wmi_cmd_hdr wmi;
  2447. struct wmi_sw_tx_complete_event evt;
  2448. } __packed evt = {
  2449. .evt = {.status = WMI_FW_STATUS_FAILURE},
  2450. };
  2451. int rc;
  2452. wil_dbg_misc(wil, "mgmt_tx mid %d\n", vif->mid);
  2453. wil_hex_dump_misc("mgmt tx frame ", DUMP_PREFIX_OFFSET, 16, 1, buf,
  2454. len, true);
  2455. if (len < sizeof(struct ieee80211_hdr_3addr))
  2456. return -EINVAL;
  2457. total = sizeof(*cmd) + len;
  2458. if (total < len) {
  2459. wil_err(wil, "mgmt_tx invalid len %zu\n", len);
  2460. return -EINVAL;
  2461. }
  2462. cmd = kmalloc(total, GFP_KERNEL);
  2463. if (!cmd)
  2464. return -ENOMEM;
  2465. memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
  2466. cmd->len = cpu_to_le16(len);
  2467. memcpy(cmd->payload, buf, len);
  2468. rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, vif->mid, cmd, total,
  2469. WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
  2470. if (!rc && evt.evt.status != WMI_FW_STATUS_SUCCESS) {
  2471. wil_err(wil, "mgmt_tx failed with status %d\n", evt.evt.status);
  2472. rc = -EINVAL;
  2473. }
  2474. kfree(cmd);
  2475. return rc;
  2476. }