debug.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */
  3. /* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. */
  4. #include <linux/err.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/debugfs.h>
  7. #include "main.h"
  8. #include "bus.h"
  9. #include "debug.h"
  10. #include "pci.h"
  11. #define MMIO_REG_ACCESS_MEM_TYPE 0xFF
  12. #define MMIO_REG_RAW_ACCESS_MEM_TYPE 0xFE
  13. #if IS_ENABLED(CONFIG_IPC_LOGGING)
  14. void *cnss_ipc_log_context;
  15. void *cnss_ipc_log_long_context;
  16. #endif
  17. static int cnss_pin_connect_show(struct seq_file *s, void *data)
  18. {
  19. struct cnss_plat_data *cnss_priv = s->private;
  20. seq_puts(s, "Pin connect results\n");
  21. seq_printf(s, "FW power pin result: %04x\n",
  22. cnss_priv->pin_result.fw_pwr_pin_result);
  23. seq_printf(s, "FW PHY IO pin result: %04x\n",
  24. cnss_priv->pin_result.fw_phy_io_pin_result);
  25. seq_printf(s, "FW RF pin result: %04x\n",
  26. cnss_priv->pin_result.fw_rf_pin_result);
  27. seq_printf(s, "Host pin result: %04x\n",
  28. cnss_priv->pin_result.host_pin_result);
  29. seq_puts(s, "\n");
  30. return 0;
  31. }
  32. static int cnss_pin_connect_open(struct inode *inode, struct file *file)
  33. {
  34. return single_open(file, cnss_pin_connect_show, inode->i_private);
  35. }
  36. static const struct file_operations cnss_pin_connect_fops = {
  37. .read = seq_read,
  38. .release = single_release,
  39. .open = cnss_pin_connect_open,
  40. .owner = THIS_MODULE,
  41. .llseek = seq_lseek,
  42. };
  43. static int cnss_stats_show_state(struct seq_file *s,
  44. struct cnss_plat_data *plat_priv)
  45. {
  46. enum cnss_driver_state i;
  47. int skip = 0;
  48. unsigned long state;
  49. seq_printf(s, "\nState: 0x%lx(", plat_priv->driver_state);
  50. for (i = 0, state = plat_priv->driver_state; state != 0;
  51. state >>= 1, i++) {
  52. if (!(state & 0x1))
  53. continue;
  54. if (skip++)
  55. seq_puts(s, " | ");
  56. switch (i) {
  57. case CNSS_QMI_WLFW_CONNECTED:
  58. seq_puts(s, "QMI_WLFW_CONNECTED");
  59. continue;
  60. case CNSS_FW_MEM_READY:
  61. seq_puts(s, "FW_MEM_READY");
  62. continue;
  63. case CNSS_FW_READY:
  64. seq_puts(s, "FW_READY");
  65. continue;
  66. case CNSS_IN_COLD_BOOT_CAL:
  67. seq_puts(s, "IN_COLD_BOOT_CAL");
  68. continue;
  69. case CNSS_DRIVER_LOADING:
  70. seq_puts(s, "DRIVER_LOADING");
  71. continue;
  72. case CNSS_DRIVER_UNLOADING:
  73. seq_puts(s, "DRIVER_UNLOADING");
  74. continue;
  75. case CNSS_DRIVER_IDLE_RESTART:
  76. seq_puts(s, "IDLE_RESTART");
  77. continue;
  78. case CNSS_DRIVER_IDLE_SHUTDOWN:
  79. seq_puts(s, "IDLE_SHUTDOWN");
  80. continue;
  81. case CNSS_DRIVER_PROBED:
  82. seq_puts(s, "DRIVER_PROBED");
  83. continue;
  84. case CNSS_DRIVER_RECOVERY:
  85. seq_puts(s, "DRIVER_RECOVERY");
  86. continue;
  87. case CNSS_FW_BOOT_RECOVERY:
  88. seq_puts(s, "FW_BOOT_RECOVERY");
  89. continue;
  90. case CNSS_DEV_ERR_NOTIFY:
  91. seq_puts(s, "DEV_ERR");
  92. continue;
  93. case CNSS_DRIVER_DEBUG:
  94. seq_puts(s, "DRIVER_DEBUG");
  95. continue;
  96. case CNSS_COEX_CONNECTED:
  97. seq_puts(s, "COEX_CONNECTED");
  98. continue;
  99. case CNSS_IMS_CONNECTED:
  100. seq_puts(s, "IMS_CONNECTED");
  101. continue;
  102. case CNSS_IN_SUSPEND_RESUME:
  103. seq_puts(s, "IN_SUSPEND_RESUME");
  104. continue;
  105. case CNSS_IN_REBOOT:
  106. seq_puts(s, "IN_REBOOT");
  107. continue;
  108. case CNSS_COLD_BOOT_CAL_DONE:
  109. seq_puts(s, "COLD_BOOT_CAL_DONE");
  110. continue;
  111. case CNSS_IN_PANIC:
  112. seq_puts(s, "IN_PANIC");
  113. continue;
  114. case CNSS_QMI_DEL_SERVER:
  115. seq_puts(s, "DEL_SERVER_IN_PROGRESS");
  116. continue;
  117. case CNSS_QMI_DMS_CONNECTED:
  118. seq_puts(s, "DMS_CONNECTED");
  119. continue;
  120. case CNSS_DMS_DEL_SERVER:
  121. seq_puts(s, "DMS_DEL_SERVER");
  122. continue;
  123. case CNSS_DAEMON_CONNECTED:
  124. seq_puts(s, "DAEMON_CONNECTED");
  125. continue;
  126. case CNSS_PCI_PROBE_DONE:
  127. seq_puts(s, "PCI PROBE DONE");
  128. continue;
  129. case CNSS_DRIVER_REGISTER:
  130. seq_puts(s, "DRIVER REGISTERED");
  131. continue;
  132. case CNSS_WLAN_HW_DISABLED:
  133. seq_puts(s, "WLAN HW DISABLED");
  134. continue;
  135. case CNSS_FS_READY:
  136. seq_puts(s, "FS READY");
  137. continue;
  138. case CNSS_DRIVER_REGISTERED:
  139. seq_puts(s, "DRIVER REGISTERED");
  140. continue;
  141. }
  142. seq_printf(s, "UNKNOWN-%d", i);
  143. }
  144. seq_puts(s, ")\n");
  145. return 0;
  146. }
  147. static int cnss_stats_show_gpio_state(struct seq_file *s,
  148. struct cnss_plat_data *plat_priv)
  149. {
  150. seq_printf(s, "\nHost SOL: %d", cnss_get_host_sol_value(plat_priv));
  151. seq_printf(s, "\nDev SOL: %d", cnss_get_dev_sol_value(plat_priv));
  152. return 0;
  153. }
  154. static int cnss_stats_show(struct seq_file *s, void *data)
  155. {
  156. struct cnss_plat_data *plat_priv = s->private;
  157. cnss_stats_show_state(s, plat_priv);
  158. cnss_stats_show_gpio_state(s, plat_priv);
  159. return 0;
  160. }
  161. static int cnss_stats_open(struct inode *inode, struct file *file)
  162. {
  163. return single_open(file, cnss_stats_show, inode->i_private);
  164. }
  165. static const struct file_operations cnss_stats_fops = {
  166. .read = seq_read,
  167. .release = single_release,
  168. .open = cnss_stats_open,
  169. .owner = THIS_MODULE,
  170. .llseek = seq_lseek,
  171. };
  172. static ssize_t cnss_dev_boot_debug_write(struct file *fp,
  173. const char __user *user_buf,
  174. size_t count, loff_t *off)
  175. {
  176. struct cnss_plat_data *plat_priv =
  177. ((struct seq_file *)fp->private_data)->private;
  178. struct cnss_pci_data *pci_priv;
  179. char buf[64];
  180. char *cmd;
  181. unsigned int len = 0;
  182. char *sptr, *token;
  183. const char *delim = " ";
  184. int ret = 0;
  185. if (!plat_priv)
  186. return -ENODEV;
  187. len = min(count, sizeof(buf) - 1);
  188. if (copy_from_user(buf, user_buf, len))
  189. return -EFAULT;
  190. buf[len] = '\0';
  191. sptr = buf;
  192. token = strsep(&sptr, delim);
  193. if (!token)
  194. return -EINVAL;
  195. cmd = token;
  196. cnss_pr_dbg("Received dev_boot debug command: %s\n", cmd);
  197. if (sysfs_streq(cmd, "on")) {
  198. ret = cnss_power_on_device(plat_priv, false);
  199. } else if (sysfs_streq(cmd, "off")) {
  200. cnss_power_off_device(plat_priv);
  201. } else if (sysfs_streq(cmd, "enumerate")) {
  202. ret = cnss_pci_init(plat_priv);
  203. } else if (sysfs_streq(cmd, "powerup")) {
  204. set_bit(CNSS_DRIVER_DEBUG, &plat_priv->driver_state);
  205. ret = cnss_driver_event_post(plat_priv,
  206. CNSS_DRIVER_EVENT_POWER_UP,
  207. CNSS_EVENT_SYNC, NULL);
  208. } else if (sysfs_streq(cmd, "shutdown")) {
  209. ret = cnss_driver_event_post(plat_priv,
  210. CNSS_DRIVER_EVENT_POWER_DOWN,
  211. 0, NULL);
  212. clear_bit(CNSS_DRIVER_DEBUG, &plat_priv->driver_state);
  213. } else if (sysfs_streq(cmd, "assert_host_sol")) {
  214. ret = cnss_set_host_sol_value(plat_priv, 1);
  215. } else if (sysfs_streq(cmd, "deassert_host_sol")) {
  216. ret = cnss_set_host_sol_value(plat_priv, 0);
  217. } else if (sysfs_streq(cmd, "pdc_update")) {
  218. if (!sptr)
  219. return -EINVAL;
  220. ret = cnss_aop_send_msg(plat_priv, sptr);
  221. } else if (sysfs_streq(cmd, "dev_check")) {
  222. cnss_wlan_hw_disable_check(plat_priv);
  223. } else if (sysfs_streq(cmd, "dev_enable")) {
  224. cnss_wlan_hw_enable();
  225. } else {
  226. pci_priv = plat_priv->bus_priv;
  227. if (!pci_priv)
  228. return -ENODEV;
  229. if (sysfs_streq(cmd, "download")) {
  230. set_bit(CNSS_DRIVER_DEBUG, &plat_priv->driver_state);
  231. ret = cnss_pci_start_mhi(pci_priv);
  232. } else if (sysfs_streq(cmd, "linkup")) {
  233. ret = cnss_resume_pci_link(pci_priv);
  234. } else if (sysfs_streq(cmd, "linkdown")) {
  235. ret = cnss_suspend_pci_link(pci_priv);
  236. } else if (sysfs_streq(cmd, "assert")) {
  237. cnss_pr_info("FW Assert triggered for debug\n");
  238. ret = cnss_force_fw_assert(&pci_priv->pci_dev->dev);
  239. } else if (sysfs_streq(cmd, "set_cbc_done")) {
  240. cnss_pr_dbg("Force set cold boot cal done status\n");
  241. set_bit(CNSS_COLD_BOOT_CAL_DONE,
  242. &plat_priv->driver_state);
  243. } else {
  244. cnss_pr_err("Device boot debugfs command is invalid\n");
  245. ret = -EINVAL;
  246. }
  247. }
  248. if (ret < 0)
  249. return ret;
  250. return count;
  251. }
  252. static int cnss_dev_boot_debug_show(struct seq_file *s, void *data)
  253. {
  254. seq_puts(s, "\nUsage: echo <action> > <debugfs_path>/cnss/dev_boot\n");
  255. seq_puts(s, "<action> can be one of below:\n");
  256. seq_puts(s, "on: turn on device power, assert WLAN_EN\n");
  257. seq_puts(s, "off: de-assert WLAN_EN, turn off device power\n");
  258. seq_puts(s, "enumerate: de-assert PERST, enumerate PCIe\n");
  259. seq_puts(s, "download: download FW and do QMI handshake with FW\n");
  260. seq_puts(s, "linkup: bring up PCIe link\n");
  261. seq_puts(s, "linkdown: bring down PCIe link\n");
  262. seq_puts(s, "powerup: full power on sequence to boot device, download FW and do QMI handshake with FW\n");
  263. seq_puts(s, "shutdown: full power off sequence to shutdown device\n");
  264. seq_puts(s, "assert: trigger firmware assert\n");
  265. seq_puts(s, "set_cbc_done: Set cold boot calibration done status\n");
  266. seq_puts(s, "\npdc_update usage:");
  267. seq_puts(s, "1. echo pdc_update {class: wlan_pdc ss: <pdc_ss>, res: <vreg>.<mode>, <seq>: <val>} > <debugfs_path>/cnss/dev_boot\n");
  268. seq_puts(s, "2. echo pdc_update {class: wlan_pdc ss: <pdc_ss>, res: pdc, enable: <val>} > <debugfs_path>/cnss/dev_boot\n");
  269. return 0;
  270. }
  271. static int cnss_dev_boot_debug_open(struct inode *inode, struct file *file)
  272. {
  273. return single_open(file, cnss_dev_boot_debug_show, inode->i_private);
  274. }
  275. static const struct file_operations cnss_dev_boot_debug_fops = {
  276. .read = seq_read,
  277. .write = cnss_dev_boot_debug_write,
  278. .release = single_release,
  279. .open = cnss_dev_boot_debug_open,
  280. .owner = THIS_MODULE,
  281. .llseek = seq_lseek,
  282. };
  283. static int cnss_reg_read_debug_show(struct seq_file *s, void *data)
  284. {
  285. struct cnss_plat_data *plat_priv = s->private;
  286. mutex_lock(&plat_priv->dev_lock);
  287. if (!plat_priv->diag_reg_read_buf) {
  288. seq_puts(s, "\nUsage: echo <mem_type> <offset> <data_len> > <debugfs_path>/cnss/reg_read\n");
  289. seq_puts(s, "Use mem_type = 0xff for register read by IO access, data_len will be ignored\n");
  290. seq_puts(s, "Use mem_type = 0xfe for register read by raw IO access which skips sanity checks, data_len will be ignored\n");
  291. seq_puts(s, "Use other mem_type for register read by QMI\n");
  292. mutex_unlock(&plat_priv->dev_lock);
  293. return 0;
  294. }
  295. seq_printf(s, "\nRegister read, address: 0x%x memory type: 0x%x length: 0x%x\n\n",
  296. plat_priv->diag_reg_read_addr,
  297. plat_priv->diag_reg_read_mem_type,
  298. plat_priv->diag_reg_read_len);
  299. seq_hex_dump(s, "", DUMP_PREFIX_OFFSET, 32, 4,
  300. plat_priv->diag_reg_read_buf,
  301. plat_priv->diag_reg_read_len, false);
  302. plat_priv->diag_reg_read_len = 0;
  303. kfree(plat_priv->diag_reg_read_buf);
  304. plat_priv->diag_reg_read_buf = NULL;
  305. mutex_unlock(&plat_priv->dev_lock);
  306. return 0;
  307. }
  308. static ssize_t cnss_reg_read_debug_write(struct file *fp,
  309. const char __user *user_buf,
  310. size_t count, loff_t *off)
  311. {
  312. struct cnss_plat_data *plat_priv =
  313. ((struct seq_file *)fp->private_data)->private;
  314. char buf[64];
  315. char *sptr, *token;
  316. unsigned int len = 0;
  317. u32 reg_offset, mem_type;
  318. u32 data_len = 0, reg_val = 0;
  319. u8 *reg_buf = NULL;
  320. const char *delim = " ";
  321. int ret = 0;
  322. len = min(count, sizeof(buf) - 1);
  323. if (copy_from_user(buf, user_buf, len))
  324. return -EFAULT;
  325. buf[len] = '\0';
  326. sptr = buf;
  327. token = strsep(&sptr, delim);
  328. if (!token)
  329. return -EINVAL;
  330. if (!sptr)
  331. return -EINVAL;
  332. if (kstrtou32(token, 0, &mem_type))
  333. return -EINVAL;
  334. token = strsep(&sptr, delim);
  335. if (!token)
  336. return -EINVAL;
  337. if (!sptr)
  338. return -EINVAL;
  339. if (kstrtou32(token, 0, &reg_offset))
  340. return -EINVAL;
  341. token = strsep(&sptr, delim);
  342. if (!token)
  343. return -EINVAL;
  344. if (kstrtou32(token, 0, &data_len))
  345. return -EINVAL;
  346. if (mem_type == MMIO_REG_ACCESS_MEM_TYPE ||
  347. mem_type == MMIO_REG_RAW_ACCESS_MEM_TYPE) {
  348. ret = cnss_bus_debug_reg_read(plat_priv, reg_offset, &reg_val,
  349. mem_type ==
  350. MMIO_REG_RAW_ACCESS_MEM_TYPE);
  351. if (ret)
  352. return ret;
  353. cnss_pr_dbg("Read 0x%x from register offset 0x%x\n", reg_val,
  354. reg_offset);
  355. return count;
  356. }
  357. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  358. cnss_pr_err("Firmware is not ready yet\n");
  359. return -EINVAL;
  360. }
  361. mutex_lock(&plat_priv->dev_lock);
  362. kfree(plat_priv->diag_reg_read_buf);
  363. plat_priv->diag_reg_read_buf = NULL;
  364. reg_buf = kzalloc(data_len, GFP_KERNEL);
  365. if (!reg_buf) {
  366. mutex_unlock(&plat_priv->dev_lock);
  367. return -ENOMEM;
  368. }
  369. ret = cnss_wlfw_athdiag_read_send_sync(plat_priv, reg_offset,
  370. mem_type, data_len,
  371. reg_buf);
  372. if (ret) {
  373. kfree(reg_buf);
  374. mutex_unlock(&plat_priv->dev_lock);
  375. return ret;
  376. }
  377. plat_priv->diag_reg_read_addr = reg_offset;
  378. plat_priv->diag_reg_read_mem_type = mem_type;
  379. plat_priv->diag_reg_read_len = data_len;
  380. plat_priv->diag_reg_read_buf = reg_buf;
  381. mutex_unlock(&plat_priv->dev_lock);
  382. return count;
  383. }
  384. static int cnss_reg_read_debug_open(struct inode *inode, struct file *file)
  385. {
  386. return single_open(file, cnss_reg_read_debug_show, inode->i_private);
  387. }
  388. static const struct file_operations cnss_reg_read_debug_fops = {
  389. .read = seq_read,
  390. .write = cnss_reg_read_debug_write,
  391. .open = cnss_reg_read_debug_open,
  392. .owner = THIS_MODULE,
  393. .llseek = seq_lseek,
  394. };
  395. static int cnss_reg_write_debug_show(struct seq_file *s, void *data)
  396. {
  397. seq_puts(s, "\nUsage: echo <mem_type> <offset> <reg_val> > <debugfs_path>/cnss/reg_write\n");
  398. seq_puts(s, "Use mem_type = 0xff for register write by IO access\n");
  399. seq_puts(s, "Use mem_type = 0xfe for register write by raw IO access which skips sanity checks\n");
  400. seq_puts(s, "Use other mem_type for register write by QMI\n");
  401. return 0;
  402. }
  403. static ssize_t cnss_reg_write_debug_write(struct file *fp,
  404. const char __user *user_buf,
  405. size_t count, loff_t *off)
  406. {
  407. struct cnss_plat_data *plat_priv =
  408. ((struct seq_file *)fp->private_data)->private;
  409. char buf[64];
  410. char *sptr, *token;
  411. unsigned int len = 0;
  412. u32 reg_offset, mem_type, reg_val;
  413. const char *delim = " ";
  414. int ret = 0;
  415. len = min(count, sizeof(buf) - 1);
  416. if (copy_from_user(buf, user_buf, len))
  417. return -EFAULT;
  418. buf[len] = '\0';
  419. sptr = buf;
  420. token = strsep(&sptr, delim);
  421. if (!token)
  422. return -EINVAL;
  423. if (!sptr)
  424. return -EINVAL;
  425. if (kstrtou32(token, 0, &mem_type))
  426. return -EINVAL;
  427. token = strsep(&sptr, delim);
  428. if (!token)
  429. return -EINVAL;
  430. if (!sptr)
  431. return -EINVAL;
  432. if (kstrtou32(token, 0, &reg_offset))
  433. return -EINVAL;
  434. token = strsep(&sptr, delim);
  435. if (!token)
  436. return -EINVAL;
  437. if (kstrtou32(token, 0, &reg_val))
  438. return -EINVAL;
  439. if (mem_type == MMIO_REG_ACCESS_MEM_TYPE ||
  440. mem_type == MMIO_REG_RAW_ACCESS_MEM_TYPE) {
  441. ret = cnss_bus_debug_reg_write(plat_priv, reg_offset, reg_val,
  442. mem_type ==
  443. MMIO_REG_RAW_ACCESS_MEM_TYPE);
  444. if (ret)
  445. return ret;
  446. cnss_pr_dbg("Wrote 0x%x to register offset 0x%x\n", reg_val,
  447. reg_offset);
  448. return count;
  449. }
  450. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  451. cnss_pr_err("Firmware is not ready yet\n");
  452. return -EINVAL;
  453. }
  454. ret = cnss_wlfw_athdiag_write_send_sync(plat_priv, reg_offset, mem_type,
  455. sizeof(u32),
  456. (u8 *)&reg_val);
  457. if (ret)
  458. return ret;
  459. return count;
  460. }
  461. static int cnss_reg_write_debug_open(struct inode *inode, struct file *file)
  462. {
  463. return single_open(file, cnss_reg_write_debug_show, inode->i_private);
  464. }
  465. static const struct file_operations cnss_reg_write_debug_fops = {
  466. .read = seq_read,
  467. .write = cnss_reg_write_debug_write,
  468. .open = cnss_reg_write_debug_open,
  469. .owner = THIS_MODULE,
  470. .llseek = seq_lseek,
  471. };
  472. static ssize_t cnss_runtime_pm_debug_write(struct file *fp,
  473. const char __user *user_buf,
  474. size_t count, loff_t *off)
  475. {
  476. struct cnss_plat_data *plat_priv =
  477. ((struct seq_file *)fp->private_data)->private;
  478. struct cnss_pci_data *pci_priv;
  479. char buf[64];
  480. char *cmd;
  481. unsigned int len = 0;
  482. int ret = 0;
  483. if (!plat_priv)
  484. return -ENODEV;
  485. pci_priv = plat_priv->bus_priv;
  486. if (!pci_priv)
  487. return -ENODEV;
  488. len = min(count, sizeof(buf) - 1);
  489. if (copy_from_user(buf, user_buf, len))
  490. return -EFAULT;
  491. buf[len] = '\0';
  492. cmd = buf;
  493. if (sysfs_streq(cmd, "usage_count")) {
  494. cnss_pci_pm_runtime_show_usage_count(pci_priv);
  495. } else if (sysfs_streq(cmd, "request_resume")) {
  496. ret = cnss_pci_pm_request_resume(pci_priv);
  497. } else if (sysfs_streq(cmd, "resume")) {
  498. ret = cnss_pci_pm_runtime_resume(pci_priv);
  499. } else if (sysfs_streq(cmd, "get")) {
  500. ret = cnss_pci_pm_runtime_get(pci_priv, RTPM_ID_CNSS);
  501. } else if (sysfs_streq(cmd, "get_noresume")) {
  502. cnss_pci_pm_runtime_get_noresume(pci_priv, RTPM_ID_CNSS);
  503. } else if (sysfs_streq(cmd, "put_autosuspend")) {
  504. ret = cnss_pci_pm_runtime_put_autosuspend(pci_priv,
  505. RTPM_ID_CNSS);
  506. } else if (sysfs_streq(cmd, "put_noidle")) {
  507. cnss_pci_pm_runtime_put_noidle(pci_priv, RTPM_ID_CNSS);
  508. } else if (sysfs_streq(cmd, "mark_last_busy")) {
  509. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  510. } else if (sysfs_streq(cmd, "resume_bus")) {
  511. cnss_pci_resume_bus(pci_priv);
  512. } else if (sysfs_streq(cmd, "suspend_bus")) {
  513. cnss_pci_suspend_bus(pci_priv);
  514. } else {
  515. cnss_pr_err("Runtime PM debugfs command is invalid\n");
  516. ret = -EINVAL;
  517. }
  518. if (ret < 0)
  519. return ret;
  520. return count;
  521. }
  522. static int cnss_runtime_pm_debug_show(struct seq_file *s, void *data)
  523. {
  524. struct cnss_plat_data *plat_priv = s->private;
  525. struct cnss_pci_data *pci_priv;
  526. int i;
  527. if (!plat_priv)
  528. return -ENODEV;
  529. pci_priv = plat_priv->bus_priv;
  530. if (!pci_priv)
  531. return -ENODEV;
  532. seq_puts(s, "\nUsage: echo <action> > <debugfs_path>/cnss/runtime_pm\n");
  533. seq_puts(s, "<action> can be one of below:\n");
  534. seq_puts(s, "usage_count: get runtime PM usage count\n");
  535. seq_puts(s, "reques_resume: do async runtime PM resume\n");
  536. seq_puts(s, "resume: do sync runtime PM resume\n");
  537. seq_puts(s, "get: do runtime PM get\n");
  538. seq_puts(s, "get_noresume: do runtime PM get noresume\n");
  539. seq_puts(s, "put_noidle: do runtime PM put noidle\n");
  540. seq_puts(s, "put_autosuspend: do runtime PM put autosuspend\n");
  541. seq_puts(s, "mark_last_busy: do runtime PM mark last busy\n");
  542. seq_puts(s, "resume_bus: do bus resume only\n");
  543. seq_puts(s, "suspend_bus: do bus suspend only\n");
  544. seq_puts(s, "\nStats:\n");
  545. seq_printf(s, "%s: %u\n", "get count",
  546. atomic_read(&pci_priv->pm_stats.runtime_get));
  547. seq_printf(s, "%s: %u\n", "put count",
  548. atomic_read(&pci_priv->pm_stats.runtime_put));
  549. seq_printf(s, "%-10s%-10s%-10s%-15s%-15s\n",
  550. "id:", "get", "put", "get time(us)", "put time(us)");
  551. for (i = 0; i < RTPM_ID_MAX; i++) {
  552. seq_printf(s, "%d%-9s", i, ":");
  553. seq_printf(s, "%-10d",
  554. atomic_read(&pci_priv->pm_stats.runtime_get_id[i]));
  555. seq_printf(s, "%-10d",
  556. atomic_read(&pci_priv->pm_stats.runtime_put_id[i]));
  557. seq_printf(s, "%-15llu",
  558. pci_priv->pm_stats.runtime_get_timestamp_id[i]);
  559. seq_printf(s, "%-15llu\n",
  560. pci_priv->pm_stats.runtime_put_timestamp_id[i]);
  561. }
  562. return 0;
  563. }
  564. static int cnss_runtime_pm_debug_open(struct inode *inode, struct file *file)
  565. {
  566. return single_open(file, cnss_runtime_pm_debug_show, inode->i_private);
  567. }
  568. static const struct file_operations cnss_runtime_pm_debug_fops = {
  569. .read = seq_read,
  570. .write = cnss_runtime_pm_debug_write,
  571. .open = cnss_runtime_pm_debug_open,
  572. .owner = THIS_MODULE,
  573. .llseek = seq_lseek,
  574. };
  575. static int process_drv(struct cnss_plat_data *plat_priv, bool enabled)
  576. {
  577. if (test_bit(CNSS_QMI_WLFW_CONNECTED, &plat_priv->driver_state)) {
  578. cnss_pr_err("DRV cmd must be used before QMI ready\n");
  579. return -EINVAL;
  580. }
  581. enabled ? cnss_set_feature_list(plat_priv, CNSS_DRV_SUPPORT_V01) :
  582. cnss_clear_feature_list(plat_priv, CNSS_DRV_SUPPORT_V01);
  583. cnss_pr_info("%s DRV suspend\n", enabled ? "enable" : "disable");
  584. return 0;
  585. }
  586. static int process_quirks(struct cnss_plat_data *plat_priv, u32 val)
  587. {
  588. enum cnss_debug_quirks i;
  589. int ret = 0;
  590. unsigned long state;
  591. unsigned long quirks = 0;
  592. for (i = 0, state = val; i < QUIRK_MAX_VALUE; state >>= 1, i++) {
  593. switch (i) {
  594. case DISABLE_DRV:
  595. ret = process_drv(plat_priv, !(state & 0x1));
  596. if (!ret)
  597. quirks |= (state & 0x1) << i;
  598. continue;
  599. default:
  600. quirks |= (state & 0x1) << i;
  601. continue;
  602. }
  603. }
  604. plat_priv->ctrl_params.quirks = quirks;
  605. return 0;
  606. }
  607. static ssize_t cnss_control_params_debug_write(struct file *fp,
  608. const char __user *user_buf,
  609. size_t count, loff_t *off)
  610. {
  611. struct cnss_plat_data *plat_priv =
  612. ((struct seq_file *)fp->private_data)->private;
  613. char buf[64];
  614. char *sptr, *token;
  615. char *cmd;
  616. u32 val;
  617. unsigned int len = 0;
  618. const char *delim = " ";
  619. if (!plat_priv)
  620. return -ENODEV;
  621. len = min(count, sizeof(buf) - 1);
  622. if (copy_from_user(buf, user_buf, len))
  623. return -EFAULT;
  624. buf[len] = '\0';
  625. sptr = buf;
  626. token = strsep(&sptr, delim);
  627. if (!token)
  628. return -EINVAL;
  629. if (!sptr)
  630. return -EINVAL;
  631. cmd = token;
  632. token = strsep(&sptr, delim);
  633. if (!token)
  634. return -EINVAL;
  635. if (kstrtou32(token, 0, &val))
  636. return -EINVAL;
  637. if (strcmp(cmd, "quirks") == 0)
  638. process_quirks(plat_priv, val);
  639. else if (strcmp(cmd, "mhi_timeout") == 0)
  640. plat_priv->ctrl_params.mhi_timeout = val;
  641. else if (strcmp(cmd, "mhi_m2_timeout") == 0)
  642. plat_priv->ctrl_params.mhi_m2_timeout = val;
  643. else if (strcmp(cmd, "qmi_timeout") == 0)
  644. plat_priv->ctrl_params.qmi_timeout = val;
  645. else if (strcmp(cmd, "bdf_type") == 0)
  646. plat_priv->ctrl_params.bdf_type = val;
  647. else if (strcmp(cmd, "time_sync_period") == 0)
  648. plat_priv->ctrl_params.time_sync_period = val;
  649. else
  650. return -EINVAL;
  651. return count;
  652. }
  653. static int cnss_show_quirks_state(struct seq_file *s,
  654. struct cnss_plat_data *plat_priv)
  655. {
  656. enum cnss_debug_quirks i;
  657. int skip = 0;
  658. unsigned long state;
  659. seq_printf(s, "quirks: 0x%lx (", plat_priv->ctrl_params.quirks);
  660. for (i = 0, state = plat_priv->ctrl_params.quirks;
  661. state != 0; state >>= 1, i++) {
  662. if (!(state & 0x1))
  663. continue;
  664. if (skip++)
  665. seq_puts(s, " | ");
  666. switch (i) {
  667. case LINK_DOWN_SELF_RECOVERY:
  668. seq_puts(s, "LINK_DOWN_SELF_RECOVERY");
  669. continue;
  670. case SKIP_DEVICE_BOOT:
  671. seq_puts(s, "SKIP_DEVICE_BOOT");
  672. continue;
  673. case USE_CORE_ONLY_FW:
  674. seq_puts(s, "USE_CORE_ONLY_FW");
  675. continue;
  676. case SKIP_RECOVERY:
  677. seq_puts(s, "SKIP_RECOVERY");
  678. continue;
  679. case QMI_BYPASS:
  680. seq_puts(s, "QMI_BYPASS");
  681. continue;
  682. case ENABLE_WALTEST:
  683. seq_puts(s, "WALTEST");
  684. continue;
  685. case ENABLE_PCI_LINK_DOWN_PANIC:
  686. seq_puts(s, "PCI_LINK_DOWN_PANIC");
  687. continue;
  688. case FBC_BYPASS:
  689. seq_puts(s, "FBC_BYPASS");
  690. continue;
  691. case ENABLE_DAEMON_SUPPORT:
  692. seq_puts(s, "DAEMON_SUPPORT");
  693. continue;
  694. case DISABLE_DRV:
  695. seq_puts(s, "DISABLE_DRV");
  696. continue;
  697. case DISABLE_IO_COHERENCY:
  698. seq_puts(s, "DISABLE_IO_COHERENCY");
  699. continue;
  700. case IGNORE_PCI_LINK_FAILURE:
  701. seq_puts(s, "IGNORE_PCI_LINK_FAILURE");
  702. continue;
  703. case DISABLE_TIME_SYNC:
  704. seq_puts(s, "DISABLE_TIME_SYNC");
  705. continue;
  706. case FORCE_ONE_MSI:
  707. seq_puts(s, "FORCE_ONE_MSI");
  708. continue;
  709. default:
  710. continue;
  711. }
  712. }
  713. seq_puts(s, ")\n");
  714. return 0;
  715. }
  716. static int cnss_control_params_debug_show(struct seq_file *s, void *data)
  717. {
  718. struct cnss_plat_data *cnss_priv = s->private;
  719. seq_puts(s, "\nUsage: echo <params_name> <value> > <debugfs_path>/cnss/control_params\n");
  720. seq_puts(s, "<params_name> can be one of below:\n");
  721. seq_puts(s, "quirks: Debug quirks for driver\n");
  722. seq_puts(s, "mhi_timeout: Timeout for MHI operation in milliseconds\n");
  723. seq_puts(s, "qmi_timeout: Timeout for QMI message in milliseconds\n");
  724. seq_puts(s, "bdf_type: Type of board data file to be downloaded\n");
  725. seq_puts(s, "time_sync_period: Time period to do time sync with device in milliseconds\n");
  726. seq_puts(s, "\nCurrent value:\n");
  727. cnss_show_quirks_state(s, cnss_priv);
  728. seq_printf(s, "mhi_timeout: %u\n", cnss_priv->ctrl_params.mhi_timeout);
  729. seq_printf(s, "mhi_m2_timeout: %u\n",
  730. cnss_priv->ctrl_params.mhi_m2_timeout);
  731. seq_printf(s, "qmi_timeout: %u\n", cnss_priv->ctrl_params.qmi_timeout);
  732. seq_printf(s, "bdf_type: %u\n", cnss_priv->ctrl_params.bdf_type);
  733. seq_printf(s, "time_sync_period: %u\n",
  734. cnss_priv->ctrl_params.time_sync_period);
  735. return 0;
  736. }
  737. static int cnss_control_params_debug_open(struct inode *inode,
  738. struct file *file)
  739. {
  740. return single_open(file, cnss_control_params_debug_show,
  741. inode->i_private);
  742. }
  743. static const struct file_operations cnss_control_params_debug_fops = {
  744. .read = seq_read,
  745. .write = cnss_control_params_debug_write,
  746. .open = cnss_control_params_debug_open,
  747. .owner = THIS_MODULE,
  748. .llseek = seq_lseek,
  749. };
  750. static ssize_t cnss_dynamic_feature_write(struct file *fp,
  751. const char __user *user_buf,
  752. size_t count, loff_t *off)
  753. {
  754. struct cnss_plat_data *plat_priv =
  755. ((struct seq_file *)fp->private_data)->private;
  756. int ret = 0;
  757. u64 val;
  758. ret = kstrtou64_from_user(user_buf, count, 0, &val);
  759. if (ret)
  760. return ret;
  761. plat_priv->dynamic_feature = val;
  762. ret = cnss_wlfw_dynamic_feature_mask_send_sync(plat_priv);
  763. if (ret < 0)
  764. return ret;
  765. return count;
  766. }
  767. static int cnss_dynamic_feature_show(struct seq_file *s, void *data)
  768. {
  769. struct cnss_plat_data *cnss_priv = s->private;
  770. seq_printf(s, "dynamic_feature: 0x%llx\n", cnss_priv->dynamic_feature);
  771. return 0;
  772. }
  773. static int cnss_dynamic_feature_open(struct inode *inode,
  774. struct file *file)
  775. {
  776. return single_open(file, cnss_dynamic_feature_show,
  777. inode->i_private);
  778. }
  779. static const struct file_operations cnss_dynamic_feature_fops = {
  780. .read = seq_read,
  781. .write = cnss_dynamic_feature_write,
  782. .open = cnss_dynamic_feature_open,
  783. .owner = THIS_MODULE,
  784. .llseek = seq_lseek,
  785. };
  786. #ifdef CONFIG_DEBUG_FS
  787. #ifdef CONFIG_CNSS2_DEBUG
  788. static int cnss_create_debug_only_node(struct cnss_plat_data *plat_priv)
  789. {
  790. struct dentry *root_dentry = plat_priv->root_dentry;
  791. debugfs_create_file("dev_boot", 0600, root_dentry, plat_priv,
  792. &cnss_dev_boot_debug_fops);
  793. debugfs_create_file("reg_read", 0600, root_dentry, plat_priv,
  794. &cnss_reg_read_debug_fops);
  795. debugfs_create_file("reg_write", 0600, root_dentry, plat_priv,
  796. &cnss_reg_write_debug_fops);
  797. debugfs_create_file("runtime_pm", 0600, root_dentry, plat_priv,
  798. &cnss_runtime_pm_debug_fops);
  799. debugfs_create_file("control_params", 0600, root_dentry, plat_priv,
  800. &cnss_control_params_debug_fops);
  801. debugfs_create_file("dynamic_feature", 0600, root_dentry, plat_priv,
  802. &cnss_dynamic_feature_fops);
  803. return 0;
  804. }
  805. #else
  806. static int cnss_create_debug_only_node(struct cnss_plat_data *plat_priv)
  807. {
  808. return 0;
  809. }
  810. #endif
  811. int cnss_debugfs_create(struct cnss_plat_data *plat_priv)
  812. {
  813. int ret = 0;
  814. struct dentry *root_dentry;
  815. char name[CNSS_FS_NAME_SIZE];
  816. if (cnss_is_dual_wlan_enabled())
  817. snprintf(name, CNSS_FS_NAME_SIZE, CNSS_FS_NAME "_%d",
  818. plat_priv->plat_idx);
  819. else
  820. snprintf(name, CNSS_FS_NAME_SIZE, CNSS_FS_NAME);
  821. root_dentry = debugfs_create_dir(name, 0);
  822. if (IS_ERR(root_dentry)) {
  823. ret = PTR_ERR(root_dentry);
  824. cnss_pr_err("Unable to create debugfs %d\n", ret);
  825. goto out;
  826. }
  827. plat_priv->root_dentry = root_dentry;
  828. debugfs_create_file("pin_connect_result", 0644, root_dentry, plat_priv,
  829. &cnss_pin_connect_fops);
  830. debugfs_create_file("stats", 0644, root_dentry, plat_priv,
  831. &cnss_stats_fops);
  832. cnss_create_debug_only_node(plat_priv);
  833. out:
  834. return ret;
  835. }
  836. void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv)
  837. {
  838. debugfs_remove_recursive(plat_priv->root_dentry);
  839. }
  840. #else
  841. int cnss_debugfs_create(struct cnss_plat_data *plat_priv)
  842. {
  843. plat_priv->root_dentry = NULL;
  844. return 0;
  845. }
  846. void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv)
  847. {
  848. }
  849. #endif
  850. #if IS_ENABLED(CONFIG_IPC_LOGGING)
  851. void cnss_debug_ipc_log_print(void *log_ctx, char *process, const char *fn,
  852. const char *log_level, char *fmt, ...)
  853. {
  854. struct va_format vaf;
  855. va_list va_args;
  856. va_start(va_args, fmt);
  857. vaf.fmt = fmt;
  858. vaf.va = &va_args;
  859. if (log_level)
  860. printk("%scnss: %pV", log_level, &vaf);
  861. ipc_log_string(log_ctx, "[%s] %s: %pV", process, fn, &vaf);
  862. va_end(va_args);
  863. }
  864. static int cnss_ipc_logging_init(void)
  865. {
  866. cnss_ipc_log_context = ipc_log_context_create(CNSS_IPC_LOG_PAGES,
  867. "cnss", 0);
  868. if (!cnss_ipc_log_context) {
  869. cnss_pr_err("Unable to create IPC log context\n");
  870. return -EINVAL;
  871. }
  872. cnss_ipc_log_long_context = ipc_log_context_create(CNSS_IPC_LOG_PAGES,
  873. "cnss-long", 0);
  874. if (!cnss_ipc_log_long_context) {
  875. cnss_pr_err("Unable to create IPC long log context\n");
  876. ipc_log_context_destroy(cnss_ipc_log_context);
  877. return -EINVAL;
  878. }
  879. return 0;
  880. }
  881. static void cnss_ipc_logging_deinit(void)
  882. {
  883. if (cnss_ipc_log_long_context) {
  884. ipc_log_context_destroy(cnss_ipc_log_long_context);
  885. cnss_ipc_log_long_context = NULL;
  886. }
  887. if (cnss_ipc_log_context) {
  888. ipc_log_context_destroy(cnss_ipc_log_context);
  889. cnss_ipc_log_context = NULL;
  890. }
  891. }
  892. #else
  893. static int cnss_ipc_logging_init(void) { return 0; }
  894. static void cnss_ipc_logging_deinit(void) {}
  895. void cnss_debug_ipc_log_print(void *log_ctx, char *process, const char *fn,
  896. const char *log_level, char *fmt, ...)
  897. {
  898. struct va_format vaf;
  899. va_list va_args;
  900. va_start(va_args, fmt);
  901. vaf.fmt = fmt;
  902. vaf.va = &va_args;
  903. if (log_level)
  904. printk("%scnss: %pV", log_level, &vaf);
  905. va_end(va_args);
  906. }
  907. #endif
  908. int cnss_debug_init(void)
  909. {
  910. return cnss_ipc_logging_init();
  911. }
  912. void cnss_debug_deinit(void)
  913. {
  914. cnss_ipc_logging_deinit();
  915. }