fw-dbg.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program;
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <linuxwifi@intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  34. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  35. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/devcoredump.h>
  66. #include "fw-dbg.h"
  67. #include "iwl-io.h"
  68. #include "mvm.h"
  69. #include "iwl-prph.h"
  70. #include "iwl-csr.h"
  71. #define RADIO_REG_MAX_READ 0x2ad
  72. static void iwl_mvm_read_radio_reg(struct iwl_mvm *mvm,
  73. struct iwl_fw_error_dump_data **dump_data)
  74. {
  75. u8 *pos = (void *)(*dump_data)->data;
  76. unsigned long flags;
  77. int i;
  78. if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
  79. return;
  80. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RADIO_REG);
  81. (*dump_data)->len = cpu_to_le32(RADIO_REG_MAX_READ);
  82. for (i = 0; i < RADIO_REG_MAX_READ; i++) {
  83. u32 rd_cmd = RADIO_RSP_RD_CMD;
  84. rd_cmd |= i << RADIO_RSP_ADDR_POS;
  85. iwl_write_prph_no_grab(mvm->trans, RSP_RADIO_CMD, rd_cmd);
  86. *pos = (u8)iwl_read_prph_no_grab(mvm->trans, RSP_RADIO_RDDAT);
  87. pos++;
  88. }
  89. *dump_data = iwl_fw_error_next_data(*dump_data);
  90. iwl_trans_release_nic_access(mvm->trans, &flags);
  91. }
  92. static void iwl_mvm_dump_rxf(struct iwl_mvm *mvm,
  93. struct iwl_fw_error_dump_data **dump_data,
  94. int size, u32 offset, int fifo_num)
  95. {
  96. struct iwl_fw_error_dump_fifo *fifo_hdr;
  97. u32 *fifo_data;
  98. u32 fifo_len;
  99. int i;
  100. fifo_hdr = (void *)(*dump_data)->data;
  101. fifo_data = (void *)fifo_hdr->data;
  102. fifo_len = size;
  103. /* No need to try to read the data if the length is 0 */
  104. if (fifo_len == 0)
  105. return;
  106. /* Add a TLV for the RXF */
  107. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
  108. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  109. fifo_hdr->fifo_num = cpu_to_le32(fifo_num);
  110. fifo_hdr->available_bytes =
  111. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  112. RXF_RD_D_SPACE + offset));
  113. fifo_hdr->wr_ptr =
  114. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  115. RXF_RD_WR_PTR + offset));
  116. fifo_hdr->rd_ptr =
  117. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  118. RXF_RD_RD_PTR + offset));
  119. fifo_hdr->fence_ptr =
  120. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  121. RXF_RD_FENCE_PTR + offset));
  122. fifo_hdr->fence_mode =
  123. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  124. RXF_SET_FENCE_MODE + offset));
  125. /* Lock fence */
  126. iwl_trans_write_prph(mvm->trans, RXF_SET_FENCE_MODE + offset, 0x1);
  127. /* Set fence pointer to the same place like WR pointer */
  128. iwl_trans_write_prph(mvm->trans, RXF_LD_WR2FENCE + offset, 0x1);
  129. /* Set fence offset */
  130. iwl_trans_write_prph(mvm->trans,
  131. RXF_LD_FENCE_OFFSET_ADDR + offset, 0x0);
  132. /* Read FIFO */
  133. fifo_len /= sizeof(u32); /* Size in DWORDS */
  134. for (i = 0; i < fifo_len; i++)
  135. fifo_data[i] = iwl_trans_read_prph(mvm->trans,
  136. RXF_FIFO_RD_FENCE_INC +
  137. offset);
  138. *dump_data = iwl_fw_error_next_data(*dump_data);
  139. }
  140. static void iwl_mvm_dump_txf(struct iwl_mvm *mvm,
  141. struct iwl_fw_error_dump_data **dump_data,
  142. int size, u32 offset, int fifo_num)
  143. {
  144. struct iwl_fw_error_dump_fifo *fifo_hdr;
  145. u32 *fifo_data;
  146. u32 fifo_len;
  147. int i;
  148. fifo_hdr = (void *)(*dump_data)->data;
  149. fifo_data = (void *)fifo_hdr->data;
  150. fifo_len = size;
  151. /* No need to try to read the data if the length is 0 */
  152. if (fifo_len == 0)
  153. return;
  154. /* Add a TLV for the FIFO */
  155. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
  156. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  157. fifo_hdr->fifo_num = cpu_to_le32(fifo_num);
  158. fifo_hdr->available_bytes =
  159. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  160. TXF_FIFO_ITEM_CNT + offset));
  161. fifo_hdr->wr_ptr =
  162. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  163. TXF_WR_PTR + offset));
  164. fifo_hdr->rd_ptr =
  165. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  166. TXF_RD_PTR + offset));
  167. fifo_hdr->fence_ptr =
  168. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  169. TXF_FENCE_PTR + offset));
  170. fifo_hdr->fence_mode =
  171. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  172. TXF_LOCK_FENCE + offset));
  173. /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
  174. iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR + offset,
  175. TXF_WR_PTR + offset);
  176. /* Dummy-read to advance the read pointer to the head */
  177. iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA + offset);
  178. /* Read FIFO */
  179. fifo_len /= sizeof(u32); /* Size in DWORDS */
  180. for (i = 0; i < fifo_len; i++)
  181. fifo_data[i] = iwl_trans_read_prph(mvm->trans,
  182. TXF_READ_MODIFY_DATA +
  183. offset);
  184. *dump_data = iwl_fw_error_next_data(*dump_data);
  185. }
  186. static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
  187. struct iwl_fw_error_dump_data **dump_data)
  188. {
  189. struct iwl_fw_error_dump_fifo *fifo_hdr;
  190. struct iwl_mvm_shared_mem_cfg *cfg = &mvm->smem_cfg;
  191. u32 *fifo_data;
  192. u32 fifo_len;
  193. unsigned long flags;
  194. int i, j;
  195. if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
  196. return;
  197. /* Pull RXF1 */
  198. iwl_mvm_dump_rxf(mvm, dump_data, cfg->lmac[0].rxfifo1_size, 0, 0);
  199. /* Pull RXF2 */
  200. iwl_mvm_dump_rxf(mvm, dump_data, cfg->rxfifo2_size,
  201. RXF_DIFF_FROM_PREV, 1);
  202. /* Pull LMAC2 RXF1 */
  203. if (mvm->smem_cfg.num_lmacs > 1)
  204. iwl_mvm_dump_rxf(mvm, dump_data, cfg->lmac[1].rxfifo1_size,
  205. LMAC2_PRPH_OFFSET, 2);
  206. /* Pull TXF data from LMAC1 */
  207. for (i = 0; i < mvm->smem_cfg.num_txfifo_entries; i++) {
  208. /* Mark the number of TXF we're pulling now */
  209. iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
  210. iwl_mvm_dump_txf(mvm, dump_data, cfg->lmac[0].txfifo_size[i],
  211. 0, i);
  212. }
  213. /* Pull TXF data from LMAC2 */
  214. if (mvm->smem_cfg.num_lmacs > 1) {
  215. for (i = 0; i < mvm->smem_cfg.num_txfifo_entries; i++) {
  216. /* Mark the number of TXF we're pulling now */
  217. iwl_trans_write_prph(mvm->trans,
  218. TXF_LARC_NUM + LMAC2_PRPH_OFFSET,
  219. i);
  220. iwl_mvm_dump_txf(mvm, dump_data,
  221. cfg->lmac[1].txfifo_size[i],
  222. LMAC2_PRPH_OFFSET,
  223. i + cfg->num_txfifo_entries);
  224. }
  225. }
  226. if (fw_has_capa(&mvm->fw->ucode_capa,
  227. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
  228. /* Pull UMAC internal TXF data from all TXFs */
  229. for (i = 0;
  230. i < ARRAY_SIZE(mvm->smem_cfg.internal_txfifo_size);
  231. i++) {
  232. fifo_hdr = (void *)(*dump_data)->data;
  233. fifo_data = (void *)fifo_hdr->data;
  234. fifo_len = mvm->smem_cfg.internal_txfifo_size[i];
  235. /* No need to try to read the data if the length is 0 */
  236. if (fifo_len == 0)
  237. continue;
  238. /* Add a TLV for the internal FIFOs */
  239. (*dump_data)->type =
  240. cpu_to_le32(IWL_FW_ERROR_DUMP_INTERNAL_TXF);
  241. (*dump_data)->len =
  242. cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  243. fifo_hdr->fifo_num = cpu_to_le32(i);
  244. /* Mark the number of TXF we're pulling now */
  245. iwl_trans_write_prph(mvm->trans, TXF_CPU2_NUM, i +
  246. mvm->smem_cfg.num_txfifo_entries);
  247. fifo_hdr->available_bytes =
  248. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  249. TXF_CPU2_FIFO_ITEM_CNT));
  250. fifo_hdr->wr_ptr =
  251. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  252. TXF_CPU2_WR_PTR));
  253. fifo_hdr->rd_ptr =
  254. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  255. TXF_CPU2_RD_PTR));
  256. fifo_hdr->fence_ptr =
  257. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  258. TXF_CPU2_FENCE_PTR));
  259. fifo_hdr->fence_mode =
  260. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  261. TXF_CPU2_LOCK_FENCE));
  262. /* Set TXF_CPU2_READ_MODIFY_ADDR to TXF_CPU2_WR_PTR */
  263. iwl_trans_write_prph(mvm->trans,
  264. TXF_CPU2_READ_MODIFY_ADDR,
  265. TXF_CPU2_WR_PTR);
  266. /* Dummy-read to advance the read pointer to head */
  267. iwl_trans_read_prph(mvm->trans,
  268. TXF_CPU2_READ_MODIFY_DATA);
  269. /* Read FIFO */
  270. fifo_len /= sizeof(u32); /* Size in DWORDS */
  271. for (j = 0; j < fifo_len; j++)
  272. fifo_data[j] =
  273. iwl_trans_read_prph(mvm->trans,
  274. TXF_CPU2_READ_MODIFY_DATA);
  275. *dump_data = iwl_fw_error_next_data(*dump_data);
  276. }
  277. }
  278. iwl_trans_release_nic_access(mvm->trans, &flags);
  279. }
  280. void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
  281. {
  282. if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert)
  283. return;
  284. kfree(mvm->fw_dump_desc);
  285. mvm->fw_dump_desc = NULL;
  286. }
  287. #define IWL8260_ICCM_OFFSET 0x44000 /* Only for B-step */
  288. #define IWL8260_ICCM_LEN 0xC000 /* Only for B-step */
  289. struct iwl_prph_range {
  290. u32 start, end;
  291. };
  292. static const struct iwl_prph_range iwl_prph_dump_addr_comm[] = {
  293. { .start = 0x00a00000, .end = 0x00a00000 },
  294. { .start = 0x00a0000c, .end = 0x00a00024 },
  295. { .start = 0x00a0002c, .end = 0x00a0003c },
  296. { .start = 0x00a00410, .end = 0x00a00418 },
  297. { .start = 0x00a00420, .end = 0x00a00420 },
  298. { .start = 0x00a00428, .end = 0x00a00428 },
  299. { .start = 0x00a00430, .end = 0x00a0043c },
  300. { .start = 0x00a00444, .end = 0x00a00444 },
  301. { .start = 0x00a004c0, .end = 0x00a004cc },
  302. { .start = 0x00a004d8, .end = 0x00a004d8 },
  303. { .start = 0x00a004e0, .end = 0x00a004f0 },
  304. { .start = 0x00a00840, .end = 0x00a00840 },
  305. { .start = 0x00a00850, .end = 0x00a00858 },
  306. { .start = 0x00a01004, .end = 0x00a01008 },
  307. { .start = 0x00a01010, .end = 0x00a01010 },
  308. { .start = 0x00a01018, .end = 0x00a01018 },
  309. { .start = 0x00a01024, .end = 0x00a01024 },
  310. { .start = 0x00a0102c, .end = 0x00a01034 },
  311. { .start = 0x00a0103c, .end = 0x00a01040 },
  312. { .start = 0x00a01048, .end = 0x00a01094 },
  313. { .start = 0x00a01c00, .end = 0x00a01c20 },
  314. { .start = 0x00a01c58, .end = 0x00a01c58 },
  315. { .start = 0x00a01c7c, .end = 0x00a01c7c },
  316. { .start = 0x00a01c28, .end = 0x00a01c54 },
  317. { .start = 0x00a01c5c, .end = 0x00a01c5c },
  318. { .start = 0x00a01c60, .end = 0x00a01cdc },
  319. { .start = 0x00a01ce0, .end = 0x00a01d0c },
  320. { .start = 0x00a01d18, .end = 0x00a01d20 },
  321. { .start = 0x00a01d2c, .end = 0x00a01d30 },
  322. { .start = 0x00a01d40, .end = 0x00a01d5c },
  323. { .start = 0x00a01d80, .end = 0x00a01d80 },
  324. { .start = 0x00a01d98, .end = 0x00a01d9c },
  325. { .start = 0x00a01da8, .end = 0x00a01da8 },
  326. { .start = 0x00a01db8, .end = 0x00a01df4 },
  327. { .start = 0x00a01dc0, .end = 0x00a01dfc },
  328. { .start = 0x00a01e00, .end = 0x00a01e2c },
  329. { .start = 0x00a01e40, .end = 0x00a01e60 },
  330. { .start = 0x00a01e68, .end = 0x00a01e6c },
  331. { .start = 0x00a01e74, .end = 0x00a01e74 },
  332. { .start = 0x00a01e84, .end = 0x00a01e90 },
  333. { .start = 0x00a01e9c, .end = 0x00a01ec4 },
  334. { .start = 0x00a01ed0, .end = 0x00a01ee0 },
  335. { .start = 0x00a01f00, .end = 0x00a01f1c },
  336. { .start = 0x00a01f44, .end = 0x00a01ffc },
  337. { .start = 0x00a02000, .end = 0x00a02048 },
  338. { .start = 0x00a02068, .end = 0x00a020f0 },
  339. { .start = 0x00a02100, .end = 0x00a02118 },
  340. { .start = 0x00a02140, .end = 0x00a0214c },
  341. { .start = 0x00a02168, .end = 0x00a0218c },
  342. { .start = 0x00a021c0, .end = 0x00a021c0 },
  343. { .start = 0x00a02400, .end = 0x00a02410 },
  344. { .start = 0x00a02418, .end = 0x00a02420 },
  345. { .start = 0x00a02428, .end = 0x00a0242c },
  346. { .start = 0x00a02434, .end = 0x00a02434 },
  347. { .start = 0x00a02440, .end = 0x00a02460 },
  348. { .start = 0x00a02468, .end = 0x00a024b0 },
  349. { .start = 0x00a024c8, .end = 0x00a024cc },
  350. { .start = 0x00a02500, .end = 0x00a02504 },
  351. { .start = 0x00a0250c, .end = 0x00a02510 },
  352. { .start = 0x00a02540, .end = 0x00a02554 },
  353. { .start = 0x00a02580, .end = 0x00a025f4 },
  354. { .start = 0x00a02600, .end = 0x00a0260c },
  355. { .start = 0x00a02648, .end = 0x00a02650 },
  356. { .start = 0x00a02680, .end = 0x00a02680 },
  357. { .start = 0x00a026c0, .end = 0x00a026d0 },
  358. { .start = 0x00a02700, .end = 0x00a0270c },
  359. { .start = 0x00a02804, .end = 0x00a02804 },
  360. { .start = 0x00a02818, .end = 0x00a0281c },
  361. { .start = 0x00a02c00, .end = 0x00a02db4 },
  362. { .start = 0x00a02df4, .end = 0x00a02fb0 },
  363. { .start = 0x00a03000, .end = 0x00a03014 },
  364. { .start = 0x00a0301c, .end = 0x00a0302c },
  365. { .start = 0x00a03034, .end = 0x00a03038 },
  366. { .start = 0x00a03040, .end = 0x00a03048 },
  367. { .start = 0x00a03060, .end = 0x00a03068 },
  368. { .start = 0x00a03070, .end = 0x00a03074 },
  369. { .start = 0x00a0307c, .end = 0x00a0307c },
  370. { .start = 0x00a03080, .end = 0x00a03084 },
  371. { .start = 0x00a0308c, .end = 0x00a03090 },
  372. { .start = 0x00a03098, .end = 0x00a03098 },
  373. { .start = 0x00a030a0, .end = 0x00a030a0 },
  374. { .start = 0x00a030a8, .end = 0x00a030b4 },
  375. { .start = 0x00a030bc, .end = 0x00a030bc },
  376. { .start = 0x00a030c0, .end = 0x00a0312c },
  377. { .start = 0x00a03c00, .end = 0x00a03c5c },
  378. { .start = 0x00a04400, .end = 0x00a04454 },
  379. { .start = 0x00a04460, .end = 0x00a04474 },
  380. { .start = 0x00a044c0, .end = 0x00a044ec },
  381. { .start = 0x00a04500, .end = 0x00a04504 },
  382. { .start = 0x00a04510, .end = 0x00a04538 },
  383. { .start = 0x00a04540, .end = 0x00a04548 },
  384. { .start = 0x00a04560, .end = 0x00a0457c },
  385. { .start = 0x00a04590, .end = 0x00a04598 },
  386. { .start = 0x00a045c0, .end = 0x00a045f4 },
  387. };
  388. static const struct iwl_prph_range iwl_prph_dump_addr_9000[] = {
  389. { .start = 0x00a05c00, .end = 0x00a05c18 },
  390. { .start = 0x00a05400, .end = 0x00a056e8 },
  391. { .start = 0x00a08000, .end = 0x00a098bc },
  392. { .start = 0x00a02400, .end = 0x00a02758 },
  393. };
  394. static void _iwl_read_prph_block(struct iwl_trans *trans, u32 start,
  395. u32 len_bytes, __le32 *data)
  396. {
  397. u32 i;
  398. for (i = 0; i < len_bytes; i += 4)
  399. *data++ = cpu_to_le32(iwl_read_prph_no_grab(trans, start + i));
  400. }
  401. static bool iwl_read_prph_block(struct iwl_trans *trans, u32 start,
  402. u32 len_bytes, __le32 *data)
  403. {
  404. unsigned long flags;
  405. bool success = false;
  406. if (iwl_trans_grab_nic_access(trans, &flags)) {
  407. success = true;
  408. _iwl_read_prph_block(trans, start, len_bytes, data);
  409. iwl_trans_release_nic_access(trans, &flags);
  410. }
  411. return success;
  412. }
  413. static void iwl_dump_prph(struct iwl_trans *trans,
  414. struct iwl_fw_error_dump_data **data,
  415. const struct iwl_prph_range *iwl_prph_dump_addr,
  416. u32 range_len)
  417. {
  418. struct iwl_fw_error_dump_prph *prph;
  419. unsigned long flags;
  420. u32 i;
  421. if (!iwl_trans_grab_nic_access(trans, &flags))
  422. return;
  423. for (i = 0; i < range_len; i++) {
  424. /* The range includes both boundaries */
  425. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  426. iwl_prph_dump_addr[i].start + 4;
  427. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
  428. (*data)->len = cpu_to_le32(sizeof(*prph) +
  429. num_bytes_in_chunk);
  430. prph = (void *)(*data)->data;
  431. prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
  432. _iwl_read_prph_block(trans, iwl_prph_dump_addr[i].start,
  433. /* our range is inclusive, hence + 4 */
  434. iwl_prph_dump_addr[i].end -
  435. iwl_prph_dump_addr[i].start + 4,
  436. (void *)prph->data);
  437. *data = iwl_fw_error_next_data(*data);
  438. }
  439. iwl_trans_release_nic_access(trans, &flags);
  440. }
  441. /*
  442. * alloc_sgtable - allocates scallerlist table in the given size,
  443. * fills it with pages and returns it
  444. * @size: the size (in bytes) of the table
  445. */
  446. static struct scatterlist *alloc_sgtable(int size)
  447. {
  448. int alloc_size, nents, i;
  449. struct page *new_page;
  450. struct scatterlist *iter;
  451. struct scatterlist *table;
  452. nents = DIV_ROUND_UP(size, PAGE_SIZE);
  453. table = kcalloc(nents, sizeof(*table), GFP_KERNEL);
  454. if (!table)
  455. return NULL;
  456. sg_init_table(table, nents);
  457. iter = table;
  458. for_each_sg(table, iter, sg_nents(table), i) {
  459. new_page = alloc_page(GFP_KERNEL);
  460. if (!new_page) {
  461. /* release all previous allocated pages in the table */
  462. iter = table;
  463. for_each_sg(table, iter, sg_nents(table), i) {
  464. new_page = sg_page(iter);
  465. if (new_page)
  466. __free_page(new_page);
  467. }
  468. return NULL;
  469. }
  470. alloc_size = min_t(int, size, PAGE_SIZE);
  471. size -= PAGE_SIZE;
  472. sg_set_page(iter, new_page, alloc_size, 0);
  473. }
  474. return table;
  475. }
  476. void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
  477. {
  478. struct iwl_fw_error_dump_file *dump_file;
  479. struct iwl_fw_error_dump_data *dump_data;
  480. struct iwl_fw_error_dump_info *dump_info;
  481. struct iwl_fw_error_dump_mem *dump_mem;
  482. struct iwl_fw_error_dump_trigger_desc *dump_trig;
  483. struct iwl_mvm_dump_ptrs *fw_error_dump;
  484. struct scatterlist *sg_dump_data;
  485. u32 sram_len, sram_ofs;
  486. const struct iwl_fw_dbg_mem_seg_tlv *fw_dbg_mem = mvm->fw->dbg_mem_tlv;
  487. u32 file_len, fifo_data_len = 0, prph_len = 0, radio_len = 0;
  488. u32 smem_len = mvm->fw->n_dbg_mem_tlv ? 0 : mvm->cfg->smem_len;
  489. u32 sram2_len = mvm->fw->n_dbg_mem_tlv ? 0 : mvm->cfg->dccm2_len;
  490. bool monitor_dump_only = false;
  491. int i;
  492. if (!IWL_MVM_COLLECT_FW_ERR_DUMP &&
  493. !mvm->trans->dbg_dest_tlv)
  494. return;
  495. lockdep_assert_held(&mvm->mutex);
  496. /* there's no point in fw dump if the bus is dead */
  497. if (test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
  498. IWL_ERR(mvm, "Skip fw error dump since bus is dead\n");
  499. goto out;
  500. }
  501. if (mvm->fw_dump_trig &&
  502. mvm->fw_dump_trig->mode & IWL_FW_DBG_TRIGGER_MONITOR_ONLY)
  503. monitor_dump_only = true;
  504. fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
  505. if (!fw_error_dump)
  506. goto out;
  507. /* SRAM - include stack CCM if driver knows the values for it */
  508. if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
  509. const struct fw_img *img;
  510. img = &mvm->fw->img[mvm->cur_ucode];
  511. sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  512. sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  513. } else {
  514. sram_ofs = mvm->cfg->dccm_offset;
  515. sram_len = mvm->cfg->dccm_len;
  516. }
  517. /* reading RXF/TXF sizes */
  518. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  519. struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->smem_cfg;
  520. fifo_data_len = 0;
  521. /* Count RXF2 size */
  522. if (mem_cfg->rxfifo2_size) {
  523. /* Add header info */
  524. fifo_data_len += mem_cfg->rxfifo2_size +
  525. sizeof(*dump_data) +
  526. sizeof(struct iwl_fw_error_dump_fifo);
  527. }
  528. /* Count RXF1 sizes */
  529. for (i = 0; i < mem_cfg->num_lmacs; i++) {
  530. if (!mem_cfg->lmac[i].rxfifo1_size)
  531. continue;
  532. /* Add header info */
  533. fifo_data_len += mem_cfg->lmac[i].rxfifo1_size +
  534. sizeof(*dump_data) +
  535. sizeof(struct iwl_fw_error_dump_fifo);
  536. }
  537. /* Count TXF sizes */
  538. for (i = 0; i < mem_cfg->num_lmacs; i++) {
  539. int j;
  540. for (j = 0; j < mem_cfg->num_txfifo_entries; j++) {
  541. if (!mem_cfg->lmac[i].txfifo_size[j])
  542. continue;
  543. /* Add header info */
  544. fifo_data_len +=
  545. mem_cfg->lmac[i].txfifo_size[j] +
  546. sizeof(*dump_data) +
  547. sizeof(struct iwl_fw_error_dump_fifo);
  548. }
  549. }
  550. if (fw_has_capa(&mvm->fw->ucode_capa,
  551. IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
  552. for (i = 0;
  553. i < ARRAY_SIZE(mem_cfg->internal_txfifo_size);
  554. i++) {
  555. if (!mem_cfg->internal_txfifo_size[i])
  556. continue;
  557. /* Add header info */
  558. fifo_data_len +=
  559. mem_cfg->internal_txfifo_size[i] +
  560. sizeof(*dump_data) +
  561. sizeof(struct iwl_fw_error_dump_fifo);
  562. }
  563. }
  564. /* Make room for PRPH registers */
  565. for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr_comm); i++) {
  566. /* The range includes both boundaries */
  567. int num_bytes_in_chunk =
  568. iwl_prph_dump_addr_comm[i].end -
  569. iwl_prph_dump_addr_comm[i].start + 4;
  570. prph_len += sizeof(*dump_data) +
  571. sizeof(struct iwl_fw_error_dump_prph) +
  572. num_bytes_in_chunk;
  573. }
  574. if (mvm->cfg->mq_rx_supported) {
  575. for (i = 0; i <
  576. ARRAY_SIZE(iwl_prph_dump_addr_9000); i++) {
  577. /* The range includes both boundaries */
  578. int num_bytes_in_chunk =
  579. iwl_prph_dump_addr_9000[i].end -
  580. iwl_prph_dump_addr_9000[i].start + 4;
  581. prph_len += sizeof(*dump_data) +
  582. sizeof(struct iwl_fw_error_dump_prph) +
  583. num_bytes_in_chunk;
  584. }
  585. }
  586. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  587. radio_len = sizeof(*dump_data) + RADIO_REG_MAX_READ;
  588. }
  589. file_len = sizeof(*dump_file) +
  590. sizeof(*dump_data) * 2 +
  591. fifo_data_len +
  592. prph_len +
  593. radio_len +
  594. sizeof(*dump_info);
  595. /* Make room for the SMEM, if it exists */
  596. if (smem_len)
  597. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
  598. /* Make room for the secondary SRAM, if it exists */
  599. if (sram2_len)
  600. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
  601. /* Make room for MEM segments */
  602. for (i = 0; i < mvm->fw->n_dbg_mem_tlv; i++) {
  603. file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
  604. le32_to_cpu(fw_dbg_mem[i].len);
  605. }
  606. /* Make room for fw's virtual image pages, if it exists */
  607. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
  608. mvm->fw_paging_db[0].fw_paging_block)
  609. file_len += mvm->num_of_paging_blk *
  610. (sizeof(*dump_data) +
  611. sizeof(struct iwl_fw_error_dump_paging) +
  612. PAGING_BLOCK_SIZE);
  613. /* If we only want a monitor dump, reset the file length */
  614. if (monitor_dump_only) {
  615. file_len = sizeof(*dump_file) + sizeof(*dump_data) +
  616. sizeof(*dump_info);
  617. }
  618. /*
  619. * In 8000 HW family B-step include the ICCM (which resides separately)
  620. */
  621. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  622. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP)
  623. file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
  624. IWL8260_ICCM_LEN;
  625. if (mvm->fw_dump_desc)
  626. file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
  627. mvm->fw_dump_desc->len;
  628. if (!mvm->fw->n_dbg_mem_tlv)
  629. file_len += sram_len + sizeof(*dump_mem);
  630. dump_file = vzalloc(file_len);
  631. if (!dump_file) {
  632. kfree(fw_error_dump);
  633. goto out;
  634. }
  635. fw_error_dump->op_mode_ptr = dump_file;
  636. dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
  637. dump_data = (void *)dump_file->data;
  638. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
  639. dump_data->len = cpu_to_le32(sizeof(*dump_info));
  640. dump_info = (void *)dump_data->data;
  641. dump_info->device_family =
  642. mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
  643. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
  644. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
  645. dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
  646. memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
  647. sizeof(dump_info->fw_human_readable));
  648. strncpy(dump_info->dev_human_readable, mvm->cfg->name,
  649. sizeof(dump_info->dev_human_readable));
  650. strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
  651. sizeof(dump_info->bus_human_readable));
  652. dump_data = iwl_fw_error_next_data(dump_data);
  653. /* We only dump the FIFOs if the FW is in error state */
  654. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  655. iwl_mvm_dump_fifos(mvm, &dump_data);
  656. if (radio_len)
  657. iwl_mvm_read_radio_reg(mvm, &dump_data);
  658. }
  659. if (mvm->fw_dump_desc) {
  660. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
  661. dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
  662. mvm->fw_dump_desc->len);
  663. dump_trig = (void *)dump_data->data;
  664. memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
  665. sizeof(*dump_trig) + mvm->fw_dump_desc->len);
  666. dump_data = iwl_fw_error_next_data(dump_data);
  667. }
  668. /* In case we only want monitor dump, skip to dump trasport data */
  669. if (monitor_dump_only)
  670. goto dump_trans_data;
  671. if (!mvm->fw->n_dbg_mem_tlv) {
  672. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  673. dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
  674. dump_mem = (void *)dump_data->data;
  675. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  676. dump_mem->offset = cpu_to_le32(sram_ofs);
  677. iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
  678. sram_len);
  679. dump_data = iwl_fw_error_next_data(dump_data);
  680. }
  681. for (i = 0; i < mvm->fw->n_dbg_mem_tlv; i++) {
  682. u32 len = le32_to_cpu(fw_dbg_mem[i].len);
  683. u32 ofs = le32_to_cpu(fw_dbg_mem[i].ofs);
  684. bool success;
  685. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  686. dump_data->len = cpu_to_le32(len + sizeof(*dump_mem));
  687. dump_mem = (void *)dump_data->data;
  688. dump_mem->type = fw_dbg_mem[i].data_type;
  689. dump_mem->offset = cpu_to_le32(ofs);
  690. switch (dump_mem->type & cpu_to_le32(FW_DBG_MEM_TYPE_MASK)) {
  691. case cpu_to_le32(FW_DBG_MEM_TYPE_REGULAR):
  692. iwl_trans_read_mem_bytes(mvm->trans, ofs,
  693. dump_mem->data,
  694. len);
  695. success = true;
  696. break;
  697. case cpu_to_le32(FW_DBG_MEM_TYPE_PRPH):
  698. success = iwl_read_prph_block(mvm->trans, ofs, len,
  699. (void *)dump_mem->data);
  700. break;
  701. default:
  702. /*
  703. * shouldn't get here, we ignored this kind
  704. * of TLV earlier during the TLV parsing?!
  705. */
  706. WARN_ON(1);
  707. success = false;
  708. }
  709. if (success)
  710. dump_data = iwl_fw_error_next_data(dump_data);
  711. }
  712. if (smem_len) {
  713. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  714. dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
  715. dump_mem = (void *)dump_data->data;
  716. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
  717. dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
  718. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
  719. dump_mem->data, smem_len);
  720. dump_data = iwl_fw_error_next_data(dump_data);
  721. }
  722. if (sram2_len) {
  723. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  724. dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
  725. dump_mem = (void *)dump_data->data;
  726. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  727. dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
  728. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
  729. dump_mem->data, sram2_len);
  730. dump_data = iwl_fw_error_next_data(dump_data);
  731. }
  732. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  733. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP) {
  734. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  735. dump_data->len = cpu_to_le32(IWL8260_ICCM_LEN +
  736. sizeof(*dump_mem));
  737. dump_mem = (void *)dump_data->data;
  738. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  739. dump_mem->offset = cpu_to_le32(IWL8260_ICCM_OFFSET);
  740. iwl_trans_read_mem_bytes(mvm->trans, IWL8260_ICCM_OFFSET,
  741. dump_mem->data, IWL8260_ICCM_LEN);
  742. dump_data = iwl_fw_error_next_data(dump_data);
  743. }
  744. /* Dump fw's virtual image */
  745. if (mvm->fw->img[mvm->cur_ucode].paging_mem_size &&
  746. mvm->fw_paging_db[0].fw_paging_block) {
  747. for (i = 1; i < mvm->num_of_paging_blk + 1; i++) {
  748. struct iwl_fw_error_dump_paging *paging;
  749. struct page *pages =
  750. mvm->fw_paging_db[i].fw_paging_block;
  751. dma_addr_t addr = mvm->fw_paging_db[i].fw_paging_phys;
  752. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PAGING);
  753. dump_data->len = cpu_to_le32(sizeof(*paging) +
  754. PAGING_BLOCK_SIZE);
  755. paging = (void *)dump_data->data;
  756. paging->index = cpu_to_le32(i);
  757. dma_sync_single_for_cpu(mvm->trans->dev, addr,
  758. PAGING_BLOCK_SIZE,
  759. DMA_BIDIRECTIONAL);
  760. memcpy(paging->data, page_address(pages),
  761. PAGING_BLOCK_SIZE);
  762. dump_data = iwl_fw_error_next_data(dump_data);
  763. }
  764. }
  765. if (prph_len) {
  766. iwl_dump_prph(mvm->trans, &dump_data,
  767. iwl_prph_dump_addr_comm,
  768. ARRAY_SIZE(iwl_prph_dump_addr_comm));
  769. if (mvm->cfg->mq_rx_supported)
  770. iwl_dump_prph(mvm->trans, &dump_data,
  771. iwl_prph_dump_addr_9000,
  772. ARRAY_SIZE(iwl_prph_dump_addr_9000));
  773. }
  774. dump_trans_data:
  775. fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans,
  776. mvm->fw_dump_trig);
  777. fw_error_dump->op_mode_len = file_len;
  778. if (fw_error_dump->trans_ptr)
  779. file_len += fw_error_dump->trans_ptr->len;
  780. dump_file->file_len = cpu_to_le32(file_len);
  781. sg_dump_data = alloc_sgtable(file_len);
  782. if (sg_dump_data) {
  783. sg_pcopy_from_buffer(sg_dump_data,
  784. sg_nents(sg_dump_data),
  785. fw_error_dump->op_mode_ptr,
  786. fw_error_dump->op_mode_len, 0);
  787. if (fw_error_dump->trans_ptr)
  788. sg_pcopy_from_buffer(sg_dump_data,
  789. sg_nents(sg_dump_data),
  790. fw_error_dump->trans_ptr->data,
  791. fw_error_dump->trans_ptr->len,
  792. fw_error_dump->op_mode_len);
  793. dev_coredumpsg(mvm->trans->dev, sg_dump_data, file_len,
  794. GFP_KERNEL);
  795. }
  796. vfree(fw_error_dump->op_mode_ptr);
  797. vfree(fw_error_dump->trans_ptr);
  798. kfree(fw_error_dump);
  799. out:
  800. iwl_mvm_free_fw_dump_desc(mvm);
  801. mvm->fw_dump_trig = NULL;
  802. clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
  803. }
  804. const struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
  805. .trig_desc = {
  806. .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
  807. },
  808. };
  809. int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
  810. const struct iwl_mvm_dump_desc *desc,
  811. const struct iwl_fw_dbg_trigger_tlv *trigger)
  812. {
  813. unsigned int delay = 0;
  814. if (trigger)
  815. delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
  816. if (test_and_set_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status))
  817. return -EBUSY;
  818. if (WARN_ON(mvm->fw_dump_desc))
  819. iwl_mvm_free_fw_dump_desc(mvm);
  820. IWL_WARN(mvm, "Collecting data: trigger %d fired.\n",
  821. le32_to_cpu(desc->trig_desc.type));
  822. mvm->fw_dump_desc = desc;
  823. mvm->fw_dump_trig = trigger;
  824. queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay);
  825. return 0;
  826. }
  827. int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
  828. const char *str, size_t len,
  829. const struct iwl_fw_dbg_trigger_tlv *trigger)
  830. {
  831. struct iwl_mvm_dump_desc *desc;
  832. desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
  833. if (!desc)
  834. return -ENOMEM;
  835. desc->len = len;
  836. desc->trig_desc.type = cpu_to_le32(trig);
  837. memcpy(desc->trig_desc.data, str, len);
  838. return iwl_mvm_fw_dbg_collect_desc(mvm, desc, trigger);
  839. }
  840. int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
  841. struct iwl_fw_dbg_trigger_tlv *trigger,
  842. const char *fmt, ...)
  843. {
  844. u16 occurrences = le16_to_cpu(trigger->occurrences);
  845. int ret, len = 0;
  846. char buf[64];
  847. if (!occurrences)
  848. return 0;
  849. if (fmt) {
  850. va_list ap;
  851. buf[sizeof(buf) - 1] = '\0';
  852. va_start(ap, fmt);
  853. vsnprintf(buf, sizeof(buf), fmt, ap);
  854. va_end(ap);
  855. /* check for truncation */
  856. if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
  857. buf[sizeof(buf) - 1] = '\0';
  858. len = strlen(buf) + 1;
  859. }
  860. ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf, len,
  861. trigger);
  862. if (ret)
  863. return ret;
  864. trigger->occurrences = cpu_to_le16(occurrences - 1);
  865. return 0;
  866. }
  867. static inline void iwl_mvm_restart_early_start(struct iwl_mvm *mvm)
  868. {
  869. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  870. iwl_clear_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
  871. else
  872. iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 1);
  873. }
  874. int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, u8 conf_id)
  875. {
  876. u8 *ptr;
  877. int ret;
  878. int i;
  879. if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
  880. "Invalid configuration %d\n", conf_id))
  881. return -EINVAL;
  882. /* EARLY START - firmware's configuration is hard coded */
  883. if ((!mvm->fw->dbg_conf_tlv[conf_id] ||
  884. !mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds) &&
  885. conf_id == FW_DBG_START_FROM_ALIVE) {
  886. iwl_mvm_restart_early_start(mvm);
  887. return 0;
  888. }
  889. if (!mvm->fw->dbg_conf_tlv[conf_id])
  890. return -EINVAL;
  891. if (mvm->fw_dbg_conf != FW_DBG_INVALID)
  892. IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
  893. mvm->fw_dbg_conf);
  894. /* Send all HCMDs for configuring the FW debug */
  895. ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
  896. for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
  897. struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
  898. ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
  899. le16_to_cpu(cmd->len), cmd->data);
  900. if (ret)
  901. return ret;
  902. ptr += sizeof(*cmd);
  903. ptr += le16_to_cpu(cmd->len);
  904. }
  905. mvm->fw_dbg_conf = conf_id;
  906. return 0;
  907. }