wmi.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /*
  2. * Copyright (c) 2012 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/etherdevice.h>
  17. #include <linux/if_arp.h>
  18. #include "wil6210.h"
  19. #include "txrx.h"
  20. #include "wmi.h"
  21. #include "trace.h"
  22. /**
  23. * WMI event receiving - theory of operations
  24. *
  25. * When firmware about to report WMI event, it fills memory area
  26. * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for
  27. * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler.
  28. *
  29. * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the
  30. * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up
  31. * and handles events within the @wmi_event_worker. Every event get detached
  32. * from list, processed and deleted.
  33. *
  34. * Purpose for this mechanism is to release IRQ thread; otherwise,
  35. * if WMI event handling involves another WMI command flow, this 2-nd flow
  36. * won't be completed because of blocked IRQ thread.
  37. */
  38. /**
  39. * Addressing - theory of operations
  40. *
  41. * There are several buses present on the WIL6210 card.
  42. * Same memory areas are visible at different address on
  43. * the different busses. There are 3 main bus masters:
  44. * - MAC CPU (ucode)
  45. * - User CPU (firmware)
  46. * - AHB (host)
  47. *
  48. * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing
  49. * AHB addresses starting from 0x880000
  50. *
  51. * Internally, firmware uses addresses that allows faster access but
  52. * are invisible from the host. To read from these addresses, alternative
  53. * AHB address must be used.
  54. *
  55. * Memory mapping
  56. * Linker address PCI/Host address
  57. * 0x880000 .. 0xa80000 2Mb BAR0
  58. * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM
  59. * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH
  60. */
  61. /**
  62. * @fw_mapping provides memory remapping table
  63. */
  64. static const struct {
  65. u32 from; /* linker address - from, inclusive */
  66. u32 to; /* linker address - to, exclusive */
  67. u32 host; /* PCI/Host address - BAR0 + 0x880000 */
  68. } fw_mapping[] = {
  69. {0x000000, 0x040000, 0x8c0000}, /* FW code RAM 256k */
  70. {0x800000, 0x808000, 0x900000}, /* FW data RAM 32k */
  71. {0x840000, 0x860000, 0x908000}, /* peripheral data RAM 128k/96k used */
  72. {0x880000, 0x88a000, 0x880000}, /* various RGF */
  73. {0x88b000, 0x88c000, 0x88b000}, /* Pcie_ext_rgf */
  74. {0x8c0000, 0x949000, 0x8c0000}, /* trivial mapping for upper area */
  75. /*
  76. * 920000..930000 ucode code RAM
  77. * 930000..932000 ucode data RAM
  78. * 932000..949000 back-door debug data
  79. */
  80. };
  81. /**
  82. * return AHB address for given firmware/ucode internal (linker) address
  83. * @x - internal address
  84. * If address have no valid AHB mapping, return 0
  85. */
  86. static u32 wmi_addr_remap(u32 x)
  87. {
  88. uint i;
  89. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  90. if ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to))
  91. return x + fw_mapping[i].host - fw_mapping[i].from;
  92. }
  93. return 0;
  94. }
  95. /**
  96. * Check address validity for WMI buffer; remap if needed
  97. * @ptr - internal (linker) fw/ucode address
  98. *
  99. * Valid buffer should be DWORD aligned
  100. *
  101. * return address for accessing buffer from the host;
  102. * if buffer is not valid, return NULL.
  103. */
  104. void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_)
  105. {
  106. u32 off;
  107. u32 ptr = le32_to_cpu(ptr_);
  108. if (ptr % 4)
  109. return NULL;
  110. ptr = wmi_addr_remap(ptr);
  111. if (ptr < WIL6210_FW_HOST_OFF)
  112. return NULL;
  113. off = HOSTADDR(ptr);
  114. if (off > WIL6210_MEM_SIZE - 4)
  115. return NULL;
  116. return wil->csr + off;
  117. }
  118. /**
  119. * Check address validity
  120. */
  121. void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr)
  122. {
  123. u32 off;
  124. if (ptr % 4)
  125. return NULL;
  126. if (ptr < WIL6210_FW_HOST_OFF)
  127. return NULL;
  128. off = HOSTADDR(ptr);
  129. if (off > WIL6210_MEM_SIZE - 4)
  130. return NULL;
  131. return wil->csr + off;
  132. }
  133. int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
  134. struct wil6210_mbox_hdr *hdr)
  135. {
  136. void __iomem *src = wmi_buffer(wil, ptr);
  137. if (!src)
  138. return -EINVAL;
  139. wil_memcpy_fromio_32(hdr, src, sizeof(*hdr));
  140. return 0;
  141. }
  142. static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
  143. {
  144. struct {
  145. struct wil6210_mbox_hdr hdr;
  146. struct wil6210_mbox_hdr_wmi wmi;
  147. } __packed cmd = {
  148. .hdr = {
  149. .type = WIL_MBOX_HDR_TYPE_WMI,
  150. .flags = 0,
  151. .len = cpu_to_le16(sizeof(cmd.wmi) + len),
  152. },
  153. .wmi = {
  154. .mid = 0,
  155. .id = cpu_to_le16(cmdid),
  156. },
  157. };
  158. struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx;
  159. struct wil6210_mbox_ring_desc d_head;
  160. u32 next_head;
  161. void __iomem *dst;
  162. void __iomem *head = wmi_addr(wil, r->head);
  163. uint retry;
  164. if (sizeof(cmd) + len > r->entry_size) {
  165. wil_err(wil, "WMI size too large: %d bytes, max is %d\n",
  166. (int)(sizeof(cmd) + len), r->entry_size);
  167. return -ERANGE;
  168. }
  169. might_sleep();
  170. if (!test_bit(wil_status_fwready, &wil->status)) {
  171. wil_err(wil, "WMI: cannot send command while FW not ready\n");
  172. return -EAGAIN;
  173. }
  174. if (!head) {
  175. wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head);
  176. return -EINVAL;
  177. }
  178. /* read Tx head till it is not busy */
  179. for (retry = 5; retry > 0; retry--) {
  180. wil_memcpy_fromio_32(&d_head, head, sizeof(d_head));
  181. if (d_head.sync == 0)
  182. break;
  183. msleep(20);
  184. }
  185. if (d_head.sync != 0) {
  186. wil_err(wil, "WMI head busy\n");
  187. return -EBUSY;
  188. }
  189. /* next head */
  190. next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size);
  191. wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head);
  192. /* wait till FW finish with previous command */
  193. for (retry = 5; retry > 0; retry--) {
  194. r->tail = ioread32(wil->csr + HOST_MBOX +
  195. offsetof(struct wil6210_mbox_ctl, tx.tail));
  196. if (next_head != r->tail)
  197. break;
  198. msleep(20);
  199. }
  200. if (next_head == r->tail) {
  201. wil_err(wil, "WMI ring full\n");
  202. return -EBUSY;
  203. }
  204. dst = wmi_buffer(wil, d_head.addr);
  205. if (!dst) {
  206. wil_err(wil, "invalid WMI buffer: 0x%08x\n",
  207. le32_to_cpu(d_head.addr));
  208. return -EINVAL;
  209. }
  210. cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq);
  211. /* set command */
  212. wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len);
  213. wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd,
  214. sizeof(cmd), true);
  215. wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf,
  216. len, true);
  217. wil_memcpy_toio_32(dst, &cmd, sizeof(cmd));
  218. wil_memcpy_toio_32(dst + sizeof(cmd), buf, len);
  219. /* mark entry as full */
  220. iowrite32(1, wil->csr + HOSTADDR(r->head) +
  221. offsetof(struct wil6210_mbox_ring_desc, sync));
  222. /* advance next ptr */
  223. iowrite32(r->head = next_head, wil->csr + HOST_MBOX +
  224. offsetof(struct wil6210_mbox_ctl, tx.head));
  225. trace_wil6210_wmi_cmd(&cmd.wmi, buf, len);
  226. /* interrupt to FW */
  227. iowrite32(SW_INT_MBOX, wil->csr + HOST_SW_INT);
  228. return 0;
  229. }
  230. int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
  231. {
  232. int rc;
  233. mutex_lock(&wil->wmi_mutex);
  234. rc = __wmi_send(wil, cmdid, buf, len);
  235. mutex_unlock(&wil->wmi_mutex);
  236. return rc;
  237. }
  238. /*=== Event handlers ===*/
  239. static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len)
  240. {
  241. struct net_device *ndev = wil_to_ndev(wil);
  242. struct wireless_dev *wdev = wil->wdev;
  243. struct wmi_ready_event *evt = d;
  244. wil->fw_version = le32_to_cpu(evt->sw_version);
  245. wil->n_mids = evt->numof_additional_mids;
  246. wil_info(wil, "FW ver. %d; MAC %pM; %d MID's\n", wil->fw_version,
  247. evt->mac, wil->n_mids);
  248. if (!is_valid_ether_addr(ndev->dev_addr)) {
  249. memcpy(ndev->dev_addr, evt->mac, ETH_ALEN);
  250. memcpy(ndev->perm_addr, evt->mac, ETH_ALEN);
  251. }
  252. snprintf(wdev->wiphy->fw_version, sizeof(wdev->wiphy->fw_version),
  253. "%d", wil->fw_version);
  254. }
  255. static void wmi_evt_fw_ready(struct wil6210_priv *wil, int id, void *d,
  256. int len)
  257. {
  258. wil_dbg_wmi(wil, "WMI: got FW ready event\n");
  259. set_bit(wil_status_fwready, &wil->status);
  260. /* reuse wmi_ready for the firmware ready indication */
  261. complete(&wil->wmi_ready);
  262. }
  263. static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
  264. {
  265. struct wmi_rx_mgmt_packet_event *data = d;
  266. struct wiphy *wiphy = wil_to_wiphy(wil);
  267. struct ieee80211_mgmt *rx_mgmt_frame =
  268. (struct ieee80211_mgmt *)data->payload;
  269. int ch_no = data->info.channel+1;
  270. u32 freq = ieee80211_channel_to_frequency(ch_no,
  271. IEEE80211_BAND_60GHZ);
  272. struct ieee80211_channel *channel = ieee80211_get_channel(wiphy, freq);
  273. s32 signal = data->info.sqi;
  274. __le16 fc = rx_mgmt_frame->frame_control;
  275. u32 d_len = le32_to_cpu(data->info.len);
  276. u16 d_status = le16_to_cpu(data->info.status);
  277. wil_dbg_wmi(wil, "MGMT: channel %d MCS %d SNR %d SQI %d%%\n",
  278. data->info.channel, data->info.mcs, data->info.snr,
  279. data->info.sqi);
  280. wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len,
  281. le16_to_cpu(fc));
  282. wil_dbg_wmi(wil, "qid %d mid %d cid %d\n",
  283. data->info.qid, data->info.mid, data->info.cid);
  284. if (!channel) {
  285. wil_err(wil, "Frame on unsupported channel\n");
  286. return;
  287. }
  288. if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) {
  289. struct cfg80211_bss *bss;
  290. u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp);
  291. u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info);
  292. u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int);
  293. const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable;
  294. size_t ie_len = d_len - offsetof(struct ieee80211_mgmt,
  295. u.beacon.variable);
  296. wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
  297. wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf);
  298. wil_dbg_wmi(wil, "Beacon interval : %d\n", bi);
  299. wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf,
  300. ie_len, true);
  301. bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame,
  302. d_len, signal, GFP_KERNEL);
  303. if (bss) {
  304. wil_dbg_wmi(wil, "Added BSS %pM\n",
  305. rx_mgmt_frame->bssid);
  306. cfg80211_put_bss(wiphy, bss);
  307. } else {
  308. wil_err(wil, "cfg80211_inform_bss() failed\n");
  309. }
  310. } else {
  311. cfg80211_rx_mgmt(wil->wdev, freq, signal,
  312. (void *)rx_mgmt_frame, d_len, 0, GFP_KERNEL);
  313. }
  314. }
  315. static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id,
  316. void *d, int len)
  317. {
  318. if (wil->scan_request) {
  319. struct wmi_scan_complete_event *data = d;
  320. bool aborted = (data->status != WMI_SCAN_SUCCESS);
  321. wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", data->status);
  322. wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n",
  323. wil->scan_request, aborted);
  324. del_timer_sync(&wil->scan_timer);
  325. cfg80211_scan_done(wil->scan_request, aborted);
  326. wil->scan_request = NULL;
  327. } else {
  328. wil_err(wil, "SCAN_COMPLETE while not scanning\n");
  329. }
  330. }
  331. static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len)
  332. {
  333. struct net_device *ndev = wil_to_ndev(wil);
  334. struct wireless_dev *wdev = wil->wdev;
  335. struct wmi_connect_event *evt = d;
  336. int ch; /* channel number */
  337. struct station_info sinfo;
  338. u8 *assoc_req_ie, *assoc_resp_ie;
  339. size_t assoc_req_ielen, assoc_resp_ielen;
  340. /* capinfo(u16) + listen_interval(u16) + IEs */
  341. const size_t assoc_req_ie_offset = sizeof(u16) * 2;
  342. /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
  343. const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
  344. if (len < sizeof(*evt)) {
  345. wil_err(wil, "Connect event too short : %d bytes\n", len);
  346. return;
  347. }
  348. if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len +
  349. evt->assoc_resp_len) {
  350. wil_err(wil,
  351. "Connect event corrupted : %d != %d + %d + %d + %d\n",
  352. len, (int)sizeof(*evt), evt->beacon_ie_len,
  353. evt->assoc_req_len, evt->assoc_resp_len);
  354. return;
  355. }
  356. if (evt->cid >= WIL6210_MAX_CID) {
  357. wil_err(wil, "Connect CID invalid : %d\n", evt->cid);
  358. return;
  359. }
  360. ch = evt->channel + 1;
  361. wil_dbg_wmi(wil, "Connect %pM channel [%d] cid %d\n",
  362. evt->bssid, ch, evt->cid);
  363. wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1,
  364. evt->assoc_info, len - sizeof(*evt), true);
  365. /* figure out IE's */
  366. assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len +
  367. assoc_req_ie_offset];
  368. assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset;
  369. if (evt->assoc_req_len <= assoc_req_ie_offset) {
  370. assoc_req_ie = NULL;
  371. assoc_req_ielen = 0;
  372. }
  373. assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len +
  374. evt->assoc_req_len +
  375. assoc_resp_ie_offset];
  376. assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset;
  377. if (evt->assoc_resp_len <= assoc_resp_ie_offset) {
  378. assoc_resp_ie = NULL;
  379. assoc_resp_ielen = 0;
  380. }
  381. if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
  382. (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
  383. if (!test_bit(wil_status_fwconnecting, &wil->status)) {
  384. wil_err(wil, "Not in connecting state\n");
  385. return;
  386. }
  387. del_timer_sync(&wil->connect_timer);
  388. cfg80211_connect_result(ndev, evt->bssid,
  389. assoc_req_ie, assoc_req_ielen,
  390. assoc_resp_ie, assoc_resp_ielen,
  391. WLAN_STATUS_SUCCESS, GFP_KERNEL);
  392. } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
  393. (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
  394. memset(&sinfo, 0, sizeof(sinfo));
  395. sinfo.generation = wil->sinfo_gen++;
  396. if (assoc_req_ie) {
  397. sinfo.assoc_req_ies = assoc_req_ie;
  398. sinfo.assoc_req_ies_len = assoc_req_ielen;
  399. sinfo.filled |= STATION_INFO_ASSOC_REQ_IES;
  400. }
  401. cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL);
  402. }
  403. clear_bit(wil_status_fwconnecting, &wil->status);
  404. set_bit(wil_status_fwconnected, &wil->status);
  405. /* FIXME FW can transmit only ucast frames to peer */
  406. /* FIXME real ring_id instead of hard coded 0 */
  407. memcpy(wil->sta[evt->cid].addr, evt->bssid, ETH_ALEN);
  408. wil->sta[evt->cid].status = wil_sta_conn_pending;
  409. wil->pending_connect_cid = evt->cid;
  410. queue_work(wil->wmi_wq_conn, &wil->connect_worker);
  411. }
  412. static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
  413. void *d, int len)
  414. {
  415. struct wmi_disconnect_event *evt = d;
  416. wil_dbg_wmi(wil, "Disconnect %pM reason %d proto %d wmi\n",
  417. evt->bssid,
  418. evt->protocol_reason_status, evt->disconnect_reason);
  419. wil->sinfo_gen++;
  420. mutex_lock(&wil->mutex);
  421. wil6210_disconnect(wil, evt->bssid);
  422. mutex_unlock(&wil->mutex);
  423. }
  424. static void wmi_evt_notify(struct wil6210_priv *wil, int id, void *d, int len)
  425. {
  426. struct wmi_notify_req_done_event *evt = d;
  427. if (len < sizeof(*evt)) {
  428. wil_err(wil, "Short NOTIFY event\n");
  429. return;
  430. }
  431. wil->stats.tsf = le64_to_cpu(evt->tsf);
  432. wil->stats.snr = le32_to_cpu(evt->snr_val);
  433. wil->stats.bf_mcs = le16_to_cpu(evt->bf_mcs);
  434. wil->stats.my_rx_sector = le16_to_cpu(evt->my_rx_sector);
  435. wil->stats.my_tx_sector = le16_to_cpu(evt->my_tx_sector);
  436. wil->stats.peer_rx_sector = le16_to_cpu(evt->other_rx_sector);
  437. wil->stats.peer_tx_sector = le16_to_cpu(evt->other_tx_sector);
  438. wil_dbg_wmi(wil, "Link status, MCS %d TSF 0x%016llx\n"
  439. "BF status 0x%08x SNR 0x%08x SQI %d%%\n"
  440. "Tx Tpt %d goodput %d Rx goodput %d\n"
  441. "Sectors(rx:tx) my %d:%d peer %d:%d\n",
  442. wil->stats.bf_mcs, wil->stats.tsf, evt->status,
  443. wil->stats.snr, evt->sqi, le32_to_cpu(evt->tx_tpt),
  444. le32_to_cpu(evt->tx_goodput), le32_to_cpu(evt->rx_goodput),
  445. wil->stats.my_rx_sector, wil->stats.my_tx_sector,
  446. wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
  447. }
  448. /*
  449. * Firmware reports EAPOL frame using WME event.
  450. * Reconstruct Ethernet frame and deliver it via normal Rx
  451. */
  452. static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id,
  453. void *d, int len)
  454. {
  455. struct net_device *ndev = wil_to_ndev(wil);
  456. struct wmi_eapol_rx_event *evt = d;
  457. u16 eapol_len = le16_to_cpu(evt->eapol_len);
  458. int sz = eapol_len + ETH_HLEN;
  459. struct sk_buff *skb;
  460. struct ethhdr *eth;
  461. int cid;
  462. struct wil_net_stats *stats = NULL;
  463. wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len,
  464. evt->src_mac);
  465. cid = wil_find_cid(wil, evt->src_mac);
  466. if (cid >= 0)
  467. stats = &wil->sta[cid].stats;
  468. if (eapol_len > 196) { /* TODO: revisit size limit */
  469. wil_err(wil, "EAPOL too large\n");
  470. return;
  471. }
  472. skb = alloc_skb(sz, GFP_KERNEL);
  473. if (!skb) {
  474. wil_err(wil, "Failed to allocate skb\n");
  475. return;
  476. }
  477. eth = (struct ethhdr *)skb_put(skb, ETH_HLEN);
  478. memcpy(eth->h_dest, ndev->dev_addr, ETH_ALEN);
  479. memcpy(eth->h_source, evt->src_mac, ETH_ALEN);
  480. eth->h_proto = cpu_to_be16(ETH_P_PAE);
  481. memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len);
  482. skb->protocol = eth_type_trans(skb, ndev);
  483. if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
  484. ndev->stats.rx_packets++;
  485. ndev->stats.rx_bytes += sz;
  486. if (stats) {
  487. stats->rx_packets++;
  488. stats->rx_bytes += sz;
  489. }
  490. } else {
  491. ndev->stats.rx_dropped++;
  492. if (stats)
  493. stats->rx_dropped++;
  494. }
  495. }
  496. static void wmi_evt_linkup(struct wil6210_priv *wil, int id, void *d, int len)
  497. {
  498. struct net_device *ndev = wil_to_ndev(wil);
  499. struct wmi_data_port_open_event *evt = d;
  500. u8 cid = evt->cid;
  501. wil_dbg_wmi(wil, "Link UP for CID %d\n", cid);
  502. if (cid >= ARRAY_SIZE(wil->sta)) {
  503. wil_err(wil, "Link UP for invalid CID %d\n", cid);
  504. return;
  505. }
  506. wil->sta[cid].data_port_open = true;
  507. netif_carrier_on(ndev);
  508. }
  509. static void wmi_evt_linkdown(struct wil6210_priv *wil, int id, void *d, int len)
  510. {
  511. struct net_device *ndev = wil_to_ndev(wil);
  512. struct wmi_wbe_link_down_event *evt = d;
  513. u8 cid = evt->cid;
  514. wil_dbg_wmi(wil, "Link DOWN for CID %d, reason %d\n",
  515. cid, le32_to_cpu(evt->reason));
  516. if (cid >= ARRAY_SIZE(wil->sta)) {
  517. wil_err(wil, "Link DOWN for invalid CID %d\n", cid);
  518. return;
  519. }
  520. wil->sta[cid].data_port_open = false;
  521. netif_carrier_off(ndev);
  522. }
  523. static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d,
  524. int len)
  525. {
  526. struct wmi_vring_ba_status_event *evt = d;
  527. struct wil_sta_info *sta;
  528. uint i, cid;
  529. /* TODO: use Rx BA status, not Tx one */
  530. wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d\n",
  531. evt->ringid,
  532. evt->status == WMI_BA_AGREED ? "OK" : "N/A",
  533. evt->agg_wsize, __le16_to_cpu(evt->ba_timeout));
  534. if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
  535. wil_err(wil, "invalid ring id %d\n", evt->ringid);
  536. return;
  537. }
  538. cid = wil->vring2cid_tid[evt->ringid][0];
  539. if (cid >= WIL6210_MAX_CID) {
  540. wil_err(wil, "invalid CID %d for vring %d\n", cid, evt->ringid);
  541. return;
  542. }
  543. sta = &wil->sta[cid];
  544. if (sta->status == wil_sta_unused) {
  545. wil_err(wil, "CID %d unused\n", cid);
  546. return;
  547. }
  548. wil_dbg_wmi(wil, "BACK for CID %d %pM\n", cid, sta->addr);
  549. for (i = 0; i < WIL_STA_TID_NUM; i++) {
  550. struct wil_tid_ampdu_rx *r = sta->tid_rx[i];
  551. sta->tid_rx[i] = NULL;
  552. wil_tid_ampdu_rx_free(wil, r);
  553. if ((evt->status == WMI_BA_AGREED) && evt->agg_wsize)
  554. sta->tid_rx[i] = wil_tid_ampdu_rx_alloc(wil,
  555. evt->agg_wsize, 0);
  556. }
  557. }
  558. static const struct {
  559. int eventid;
  560. void (*handler)(struct wil6210_priv *wil, int eventid,
  561. void *data, int data_len);
  562. } wmi_evt_handlers[] = {
  563. {WMI_READY_EVENTID, wmi_evt_ready},
  564. {WMI_FW_READY_EVENTID, wmi_evt_fw_ready},
  565. {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
  566. {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
  567. {WMI_CONNECT_EVENTID, wmi_evt_connect},
  568. {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
  569. {WMI_NOTIFY_REQ_DONE_EVENTID, wmi_evt_notify},
  570. {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
  571. {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_linkup},
  572. {WMI_WBE_LINKDOWN_EVENTID, wmi_evt_linkdown},
  573. {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
  574. };
  575. /*
  576. * Run in IRQ context
  577. * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
  578. * that will be eventually handled by the @wmi_event_worker in the thread
  579. * context of thread "wil6210_wmi"
  580. */
  581. void wmi_recv_cmd(struct wil6210_priv *wil)
  582. {
  583. struct wil6210_mbox_ring_desc d_tail;
  584. struct wil6210_mbox_hdr hdr;
  585. struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
  586. struct pending_wmi_event *evt;
  587. u8 *cmd;
  588. void __iomem *src;
  589. ulong flags;
  590. unsigned n;
  591. if (!test_bit(wil_status_reset_done, &wil->status)) {
  592. wil_err(wil, "Reset not completed\n");
  593. return;
  594. }
  595. for (n = 0;; n++) {
  596. u16 len;
  597. bool q;
  598. r->head = ioread32(wil->csr + HOST_MBOX +
  599. offsetof(struct wil6210_mbox_ctl, rx.head));
  600. if (r->tail == r->head)
  601. break;
  602. wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
  603. r->head, r->tail);
  604. /* read cmd descriptor from tail */
  605. wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
  606. sizeof(struct wil6210_mbox_ring_desc));
  607. if (d_tail.sync == 0) {
  608. wil_err(wil, "Mbox evt not owned by FW?\n");
  609. break;
  610. }
  611. /* read cmd header from descriptor */
  612. if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
  613. wil_err(wil, "Mbox evt at 0x%08x?\n",
  614. le32_to_cpu(d_tail.addr));
  615. break;
  616. }
  617. len = le16_to_cpu(hdr.len);
  618. wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
  619. le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
  620. hdr.flags);
  621. /* read cmd buffer from descriptor */
  622. src = wmi_buffer(wil, d_tail.addr) +
  623. sizeof(struct wil6210_mbox_hdr);
  624. evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
  625. event.wmi) + len, 4),
  626. GFP_KERNEL);
  627. if (!evt)
  628. break;
  629. evt->event.hdr = hdr;
  630. cmd = (void *)&evt->event.wmi;
  631. wil_memcpy_fromio_32(cmd, src, len);
  632. /* mark entry as empty */
  633. iowrite32(0, wil->csr + HOSTADDR(r->tail) +
  634. offsetof(struct wil6210_mbox_ring_desc, sync));
  635. /* indicate */
  636. if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
  637. (len >= sizeof(struct wil6210_mbox_hdr_wmi))) {
  638. struct wil6210_mbox_hdr_wmi *wmi = &evt->event.wmi;
  639. u16 id = le16_to_cpu(wmi->id);
  640. u32 tstamp = le32_to_cpu(wmi->timestamp);
  641. wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n",
  642. id, wmi->mid, tstamp);
  643. trace_wil6210_wmi_event(wmi, &wmi[1],
  644. len - sizeof(*wmi));
  645. }
  646. wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
  647. &evt->event.hdr, sizeof(hdr) + len, true);
  648. /* advance tail */
  649. r->tail = r->base + ((r->tail - r->base +
  650. sizeof(struct wil6210_mbox_ring_desc)) % r->size);
  651. iowrite32(r->tail, wil->csr + HOST_MBOX +
  652. offsetof(struct wil6210_mbox_ctl, rx.tail));
  653. /* add to the pending list */
  654. spin_lock_irqsave(&wil->wmi_ev_lock, flags);
  655. list_add_tail(&evt->list, &wil->pending_wmi_ev);
  656. spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
  657. q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
  658. wil_dbg_wmi(wil, "queue_work -> %d\n", q);
  659. }
  660. /* normally, 1 event per IRQ should be processed */
  661. wil_dbg_wmi(wil, "%s -> %d events queued\n", __func__, n);
  662. }
  663. int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
  664. u16 reply_id, void *reply, u8 reply_size, int to_msec)
  665. {
  666. int rc;
  667. int remain;
  668. mutex_lock(&wil->wmi_mutex);
  669. rc = __wmi_send(wil, cmdid, buf, len);
  670. if (rc)
  671. goto out;
  672. wil->reply_id = reply_id;
  673. wil->reply_buf = reply;
  674. wil->reply_size = reply_size;
  675. remain = wait_for_completion_timeout(&wil->wmi_ready,
  676. msecs_to_jiffies(to_msec));
  677. if (0 == remain) {
  678. wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
  679. cmdid, reply_id, to_msec);
  680. rc = -ETIME;
  681. } else {
  682. wil_dbg_wmi(wil,
  683. "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
  684. cmdid, reply_id,
  685. to_msec - jiffies_to_msecs(remain));
  686. }
  687. wil->reply_id = 0;
  688. wil->reply_buf = NULL;
  689. wil->reply_size = 0;
  690. out:
  691. mutex_unlock(&wil->wmi_mutex);
  692. return rc;
  693. }
  694. int wmi_echo(struct wil6210_priv *wil)
  695. {
  696. struct wmi_echo_cmd cmd = {
  697. .value = cpu_to_le32(0x12345678),
  698. };
  699. return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd),
  700. WMI_ECHO_RSP_EVENTID, NULL, 0, 20);
  701. }
  702. int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
  703. {
  704. struct wmi_set_mac_address_cmd cmd;
  705. memcpy(cmd.mac, addr, ETH_ALEN);
  706. wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
  707. return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd));
  708. }
  709. int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype, u8 chan)
  710. {
  711. int rc;
  712. struct wmi_pcp_start_cmd cmd = {
  713. .bcon_interval = cpu_to_le16(bi),
  714. .network_type = wmi_nettype,
  715. .disable_sec_offload = 1,
  716. .channel = chan - 1,
  717. .pcp_max_assoc_sta = WIL6210_MAX_CID,
  718. };
  719. struct {
  720. struct wil6210_mbox_hdr_wmi wmi;
  721. struct wmi_pcp_started_event evt;
  722. } __packed reply;
  723. if (!wil->secure_pcp)
  724. cmd.disable_sec = 1;
  725. /*
  726. * Processing time may be huge, in case of secure AP it takes about
  727. * 3500ms for FW to start AP
  728. */
  729. rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd),
  730. WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
  731. if (rc)
  732. return rc;
  733. if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
  734. rc = -EINVAL;
  735. return rc;
  736. }
  737. int wmi_pcp_stop(struct wil6210_priv *wil)
  738. {
  739. return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0,
  740. WMI_PCP_STOPPED_EVENTID, NULL, 0, 20);
  741. }
  742. int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid)
  743. {
  744. struct wmi_set_ssid_cmd cmd = {
  745. .ssid_len = cpu_to_le32(ssid_len),
  746. };
  747. if (ssid_len > sizeof(cmd.ssid))
  748. return -EINVAL;
  749. memcpy(cmd.ssid, ssid, ssid_len);
  750. return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd));
  751. }
  752. int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid)
  753. {
  754. int rc;
  755. struct {
  756. struct wil6210_mbox_hdr_wmi wmi;
  757. struct wmi_set_ssid_cmd cmd;
  758. } __packed reply;
  759. int len; /* reply.cmd.ssid_len in CPU order */
  760. rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID,
  761. &reply, sizeof(reply), 20);
  762. if (rc)
  763. return rc;
  764. len = le32_to_cpu(reply.cmd.ssid_len);
  765. if (len > sizeof(reply.cmd.ssid))
  766. return -EINVAL;
  767. *ssid_len = len;
  768. memcpy(ssid, reply.cmd.ssid, len);
  769. return 0;
  770. }
  771. int wmi_set_channel(struct wil6210_priv *wil, int channel)
  772. {
  773. struct wmi_set_pcp_channel_cmd cmd = {
  774. .channel = channel - 1,
  775. };
  776. return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd));
  777. }
  778. int wmi_get_channel(struct wil6210_priv *wil, int *channel)
  779. {
  780. int rc;
  781. struct {
  782. struct wil6210_mbox_hdr_wmi wmi;
  783. struct wmi_set_pcp_channel_cmd cmd;
  784. } __packed reply;
  785. rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0,
  786. WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20);
  787. if (rc)
  788. return rc;
  789. if (reply.cmd.channel > 3)
  790. return -EINVAL;
  791. *channel = reply.cmd.channel + 1;
  792. return 0;
  793. }
  794. int wmi_p2p_cfg(struct wil6210_priv *wil, int channel)
  795. {
  796. struct wmi_p2p_cfg_cmd cmd = {
  797. .discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD,
  798. .channel = channel - 1,
  799. };
  800. return wmi_send(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd));
  801. }
  802. int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index,
  803. const void *mac_addr)
  804. {
  805. struct wmi_delete_cipher_key_cmd cmd = {
  806. .key_index = key_index,
  807. };
  808. if (mac_addr)
  809. memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
  810. return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
  811. }
  812. int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index,
  813. const void *mac_addr, int key_len, const void *key)
  814. {
  815. struct wmi_add_cipher_key_cmd cmd = {
  816. .key_index = key_index,
  817. .key_usage = WMI_KEY_USE_PAIRWISE,
  818. .key_len = key_len,
  819. };
  820. if (!key || (key_len > sizeof(cmd.key)))
  821. return -EINVAL;
  822. memcpy(cmd.key, key, key_len);
  823. if (mac_addr)
  824. memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
  825. return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
  826. }
  827. int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie)
  828. {
  829. int rc;
  830. u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
  831. struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL);
  832. if (!cmd)
  833. return -ENOMEM;
  834. cmd->mgmt_frm_type = type;
  835. /* BUG: FW API define ieLen as u8. Will fix FW */
  836. cmd->ie_len = cpu_to_le16(ie_len);
  837. memcpy(cmd->ie_info, ie, ie_len);
  838. rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len);
  839. kfree(cmd);
  840. return rc;
  841. }
  842. /**
  843. * wmi_rxon - turn radio on/off
  844. * @on: turn on if true, off otherwise
  845. *
  846. * Only switch radio. Channel should be set separately.
  847. * No timeout for rxon - radio turned on forever unless some other call
  848. * turns it off
  849. */
  850. int wmi_rxon(struct wil6210_priv *wil, bool on)
  851. {
  852. int rc;
  853. struct {
  854. struct wil6210_mbox_hdr_wmi wmi;
  855. struct wmi_listen_started_event evt;
  856. } __packed reply;
  857. wil_info(wil, "%s(%s)\n", __func__, on ? "on" : "off");
  858. if (on) {
  859. rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
  860. WMI_LISTEN_STARTED_EVENTID,
  861. &reply, sizeof(reply), 100);
  862. if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
  863. rc = -EINVAL;
  864. } else {
  865. rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
  866. WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20);
  867. }
  868. return rc;
  869. }
  870. int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
  871. {
  872. struct wireless_dev *wdev = wil->wdev;
  873. struct net_device *ndev = wil_to_ndev(wil);
  874. struct wmi_cfg_rx_chain_cmd cmd = {
  875. .action = WMI_RX_CHAIN_ADD,
  876. .rx_sw_ring = {
  877. .max_mpdu_size = cpu_to_le16(RX_BUF_LEN),
  878. .ring_mem_base = cpu_to_le64(vring->pa),
  879. .ring_size = cpu_to_le16(vring->size),
  880. },
  881. .mid = 0, /* TODO - what is it? */
  882. .decap_trans_type = WMI_DECAP_TYPE_802_3,
  883. .reorder_type = WMI_RX_SW_REORDER,
  884. };
  885. struct {
  886. struct wil6210_mbox_hdr_wmi wmi;
  887. struct wmi_cfg_rx_chain_done_event evt;
  888. } __packed evt;
  889. int rc;
  890. if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
  891. struct ieee80211_channel *ch = wdev->preset_chandef.chan;
  892. cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
  893. if (ch)
  894. cmd.sniffer_cfg.channel = ch->hw_value - 1;
  895. cmd.sniffer_cfg.phy_info_mode =
  896. cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP);
  897. cmd.sniffer_cfg.phy_support =
  898. cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
  899. ? WMI_SNIFFER_CP : WMI_SNIFFER_DP);
  900. } else {
  901. /* Initialize offload (in non-sniffer mode).
  902. * Linux IP stack always calculates IP checksum
  903. * HW always calculate TCP/UDP checksum
  904. */
  905. cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
  906. }
  907. /* typical time for secure PCP is 840ms */
  908. rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd),
  909. WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
  910. if (rc)
  911. return rc;
  912. vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
  913. wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
  914. le32_to_cpu(evt.evt.status), vring->hwtail);
  915. if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
  916. rc = -EINVAL;
  917. return rc;
  918. }
  919. int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_m, u32 *t_r)
  920. {
  921. int rc;
  922. struct wmi_temp_sense_cmd cmd = {
  923. .measure_marlon_m_en = cpu_to_le32(!!t_m),
  924. .measure_marlon_r_en = cpu_to_le32(!!t_r),
  925. };
  926. struct {
  927. struct wil6210_mbox_hdr_wmi wmi;
  928. struct wmi_temp_sense_done_event evt;
  929. } __packed reply;
  930. rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd),
  931. WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100);
  932. if (rc)
  933. return rc;
  934. if (t_m)
  935. *t_m = le32_to_cpu(reply.evt.marlon_m_t1000);
  936. if (t_r)
  937. *t_r = le32_to_cpu(reply.evt.marlon_r_t1000);
  938. return 0;
  939. }
  940. int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac, u16 reason)
  941. {
  942. struct wmi_disconnect_sta_cmd cmd = {
  943. .disconnect_reason = cpu_to_le16(reason),
  944. };
  945. memcpy(cmd.dst_mac, mac, ETH_ALEN);
  946. wil_dbg_wmi(wil, "%s(%pM, reason %d)\n", __func__, mac, reason);
  947. return wmi_send(wil, WMI_DISCONNECT_STA_CMDID, &cmd, sizeof(cmd));
  948. }
  949. void wmi_event_flush(struct wil6210_priv *wil)
  950. {
  951. struct pending_wmi_event *evt, *t;
  952. wil_dbg_wmi(wil, "%s()\n", __func__);
  953. list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
  954. list_del(&evt->list);
  955. kfree(evt);
  956. }
  957. }
  958. static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id,
  959. void *d, int len)
  960. {
  961. uint i;
  962. for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
  963. if (wmi_evt_handlers[i].eventid == id) {
  964. wmi_evt_handlers[i].handler(wil, id, d, len);
  965. return true;
  966. }
  967. }
  968. return false;
  969. }
  970. static void wmi_event_handle(struct wil6210_priv *wil,
  971. struct wil6210_mbox_hdr *hdr)
  972. {
  973. u16 len = le16_to_cpu(hdr->len);
  974. if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
  975. (len >= sizeof(struct wil6210_mbox_hdr_wmi))) {
  976. struct wil6210_mbox_hdr_wmi *wmi = (void *)(&hdr[1]);
  977. void *evt_data = (void *)(&wmi[1]);
  978. u16 id = le16_to_cpu(wmi->id);
  979. /* check if someone waits for this event */
  980. if (wil->reply_id && wil->reply_id == id) {
  981. if (wil->reply_buf) {
  982. memcpy(wil->reply_buf, wmi,
  983. min(len, wil->reply_size));
  984. } else {
  985. wmi_evt_call_handler(wil, id, evt_data,
  986. len - sizeof(*wmi));
  987. }
  988. wil_dbg_wmi(wil, "Complete WMI 0x%04x\n", id);
  989. complete(&wil->wmi_ready);
  990. return;
  991. }
  992. /* unsolicited event */
  993. /* search for handler */
  994. if (!wmi_evt_call_handler(wil, id, evt_data,
  995. len - sizeof(*wmi))) {
  996. wil_err(wil, "Unhandled event 0x%04x\n", id);
  997. }
  998. } else {
  999. wil_err(wil, "Unknown event type\n");
  1000. print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
  1001. hdr, sizeof(*hdr) + len, true);
  1002. }
  1003. }
  1004. /*
  1005. * Retrieve next WMI event from the pending list
  1006. */
  1007. static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
  1008. {
  1009. ulong flags;
  1010. struct list_head *ret = NULL;
  1011. spin_lock_irqsave(&wil->wmi_ev_lock, flags);
  1012. if (!list_empty(&wil->pending_wmi_ev)) {
  1013. ret = wil->pending_wmi_ev.next;
  1014. list_del(ret);
  1015. }
  1016. spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
  1017. return ret;
  1018. }
  1019. /*
  1020. * Handler for the WMI events
  1021. */
  1022. void wmi_event_worker(struct work_struct *work)
  1023. {
  1024. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  1025. wmi_event_worker);
  1026. struct pending_wmi_event *evt;
  1027. struct list_head *lh;
  1028. while ((lh = next_wmi_ev(wil)) != NULL) {
  1029. evt = list_entry(lh, struct pending_wmi_event, list);
  1030. wmi_event_handle(wil, &evt->event.hdr);
  1031. kfree(evt);
  1032. }
  1033. }