debug.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */
  3. /* Copyright (c) 2022 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. root_dentry = debugfs_create_dir("cnss", 0);
  816. if (IS_ERR(root_dentry)) {
  817. ret = PTR_ERR(root_dentry);
  818. cnss_pr_err("Unable to create debugfs %d\n", ret);
  819. goto out;
  820. }
  821. plat_priv->root_dentry = root_dentry;
  822. debugfs_create_file("pin_connect_result", 0644, root_dentry, plat_priv,
  823. &cnss_pin_connect_fops);
  824. debugfs_create_file("stats", 0644, root_dentry, plat_priv,
  825. &cnss_stats_fops);
  826. cnss_create_debug_only_node(plat_priv);
  827. out:
  828. return ret;
  829. }
  830. void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv)
  831. {
  832. debugfs_remove_recursive(plat_priv->root_dentry);
  833. }
  834. #else
  835. int cnss_debugfs_create(struct cnss_plat_data *plat_priv)
  836. {
  837. plat_priv->root_dentry = NULL;
  838. return 0;
  839. }
  840. void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv)
  841. {
  842. }
  843. #endif
  844. #if IS_ENABLED(CONFIG_IPC_LOGGING)
  845. void cnss_debug_ipc_log_print(void *log_ctx, char *process, const char *fn,
  846. const char *log_level, char *fmt, ...)
  847. {
  848. struct va_format vaf;
  849. va_list va_args;
  850. va_start(va_args, fmt);
  851. vaf.fmt = fmt;
  852. vaf.va = &va_args;
  853. if (log_level)
  854. printk("%scnss: %pV", log_level, &vaf);
  855. ipc_log_string(log_ctx, "[%s] %s: %pV", process, fn, &vaf);
  856. va_end(va_args);
  857. }
  858. static int cnss_ipc_logging_init(void)
  859. {
  860. cnss_ipc_log_context = ipc_log_context_create(CNSS_IPC_LOG_PAGES,
  861. "cnss", 0);
  862. if (!cnss_ipc_log_context) {
  863. cnss_pr_err("Unable to create IPC log context\n");
  864. return -EINVAL;
  865. }
  866. cnss_ipc_log_long_context = ipc_log_context_create(CNSS_IPC_LOG_PAGES,
  867. "cnss-long", 0);
  868. if (!cnss_ipc_log_long_context) {
  869. cnss_pr_err("Unable to create IPC long log context\n");
  870. ipc_log_context_destroy(cnss_ipc_log_context);
  871. return -EINVAL;
  872. }
  873. return 0;
  874. }
  875. static void cnss_ipc_logging_deinit(void)
  876. {
  877. if (cnss_ipc_log_long_context) {
  878. ipc_log_context_destroy(cnss_ipc_log_long_context);
  879. cnss_ipc_log_long_context = NULL;
  880. }
  881. if (cnss_ipc_log_context) {
  882. ipc_log_context_destroy(cnss_ipc_log_context);
  883. cnss_ipc_log_context = NULL;
  884. }
  885. }
  886. #else
  887. static int cnss_ipc_logging_init(void) { return 0; }
  888. static void cnss_ipc_logging_deinit(void) {}
  889. void cnss_debug_ipc_log_print(void *log_ctx, char *process, const char *fn,
  890. const char *log_level, char *fmt, ...)
  891. {
  892. struct va_format vaf;
  893. va_list va_args;
  894. va_start(va_args, fmt);
  895. vaf.fmt = fmt;
  896. vaf.va = &va_args;
  897. if (log_level)
  898. printk("%scnss: %pV", log_level, &vaf);
  899. va_end(va_args);
  900. }
  901. #endif
  902. int cnss_debug_init(void)
  903. {
  904. return cnss_ipc_logging_init();
  905. }
  906. void cnss_debug_deinit(void)
  907. {
  908. cnss_ipc_logging_deinit();
  909. }