debugfs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2012-2022, Intel Corporation. All rights reserved
  4. * Intel Management Engine Interface (Intel MEI) Linux driver
  5. */
  6. #include <linux/slab.h>
  7. #include <linux/kernel.h>
  8. #include <linux/device.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/seq_file.h>
  11. #include <linux/mei.h>
  12. #include "mei_dev.h"
  13. #include "client.h"
  14. #include "hw.h"
  15. static int mei_dbgfs_meclients_show(struct seq_file *m, void *unused)
  16. {
  17. struct mei_device *dev = m->private;
  18. struct mei_me_client *me_cl;
  19. int i = 0;
  20. if (!dev)
  21. return -ENODEV;
  22. down_read(&dev->me_clients_rwsem);
  23. seq_puts(m, " |id|fix| UUID |con|msg len|sb|refc|vt|\n");
  24. /* if the driver is not enabled the list won't be consistent */
  25. if (dev->dev_state != MEI_DEV_ENABLED)
  26. goto out;
  27. list_for_each_entry(me_cl, &dev->me_clients, list) {
  28. if (!mei_me_cl_get(me_cl))
  29. continue;
  30. seq_printf(m, "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|%2d|\n",
  31. i++, me_cl->client_id,
  32. me_cl->props.fixed_address,
  33. &me_cl->props.protocol_name,
  34. me_cl->props.max_number_of_connections,
  35. me_cl->props.max_msg_length,
  36. me_cl->props.single_recv_buf,
  37. kref_read(&me_cl->refcnt),
  38. me_cl->props.vt_supported);
  39. mei_me_cl_put(me_cl);
  40. }
  41. out:
  42. up_read(&dev->me_clients_rwsem);
  43. return 0;
  44. }
  45. DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_meclients);
  46. static int mei_dbgfs_active_show(struct seq_file *m, void *unused)
  47. {
  48. struct mei_device *dev = m->private;
  49. struct mei_cl *cl;
  50. int i = 0;
  51. if (!dev)
  52. return -ENODEV;
  53. mutex_lock(&dev->device_lock);
  54. seq_puts(m, " |me|host|state|rd|wr|wrq\n");
  55. /* if the driver is not enabled the list won't be consistent */
  56. if (dev->dev_state != MEI_DEV_ENABLED)
  57. goto out;
  58. list_for_each_entry(cl, &dev->file_list, link) {
  59. seq_printf(m, "%3d|%2d|%4d|%5d|%2d|%2d|%3u\n",
  60. i, mei_cl_me_id(cl), cl->host_client_id, cl->state,
  61. !list_empty(&cl->rd_completed), cl->writing_state,
  62. cl->tx_cb_queued);
  63. i++;
  64. }
  65. out:
  66. mutex_unlock(&dev->device_lock);
  67. return 0;
  68. }
  69. DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_active);
  70. static const char *mei_dev_pxp_mode_str(enum mei_dev_pxp_mode state)
  71. {
  72. #define MEI_PXP_MODE(state) case MEI_DEV_PXP_##state: return #state
  73. switch (state) {
  74. MEI_PXP_MODE(DEFAULT);
  75. MEI_PXP_MODE(INIT);
  76. MEI_PXP_MODE(SETUP);
  77. MEI_PXP_MODE(READY);
  78. default:
  79. return "unknown";
  80. }
  81. #undef MEI_PXP_MODE
  82. }
  83. static int mei_dbgfs_devstate_show(struct seq_file *m, void *unused)
  84. {
  85. struct mei_device *dev = m->private;
  86. seq_printf(m, "dev: %s\n", mei_dev_state_str(dev->dev_state));
  87. seq_printf(m, "hbm: %s\n", mei_hbm_state_str(dev->hbm_state));
  88. if (dev->hbm_state >= MEI_HBM_ENUM_CLIENTS &&
  89. dev->hbm_state <= MEI_HBM_STARTED) {
  90. seq_puts(m, "hbm features:\n");
  91. seq_printf(m, "\tPG: %01d\n", dev->hbm_f_pg_supported);
  92. seq_printf(m, "\tDC: %01d\n", dev->hbm_f_dc_supported);
  93. seq_printf(m, "\tIE: %01d\n", dev->hbm_f_ie_supported);
  94. seq_printf(m, "\tDOT: %01d\n", dev->hbm_f_dot_supported);
  95. seq_printf(m, "\tEV: %01d\n", dev->hbm_f_ev_supported);
  96. seq_printf(m, "\tFA: %01d\n", dev->hbm_f_fa_supported);
  97. seq_printf(m, "\tOS: %01d\n", dev->hbm_f_os_supported);
  98. seq_printf(m, "\tDR: %01d\n", dev->hbm_f_dr_supported);
  99. seq_printf(m, "\tVT: %01d\n", dev->hbm_f_vt_supported);
  100. seq_printf(m, "\tCAP: %01d\n", dev->hbm_f_cap_supported);
  101. seq_printf(m, "\tCD: %01d\n", dev->hbm_f_cd_supported);
  102. }
  103. seq_printf(m, "pg: %s, %s\n",
  104. mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
  105. mei_pg_state_str(mei_pg_state(dev)));
  106. seq_printf(m, "pxp: %s\n", mei_dev_pxp_mode_str(dev->pxp_mode));
  107. return 0;
  108. }
  109. DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_devstate);
  110. static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
  111. const char __user *user_buf,
  112. size_t count, loff_t *ppos)
  113. {
  114. struct mei_device *dev;
  115. int ret;
  116. dev = container_of(file->private_data,
  117. struct mei_device, allow_fixed_address);
  118. ret = debugfs_write_file_bool(file, user_buf, count, ppos);
  119. if (ret < 0)
  120. return ret;
  121. dev->override_fixed_address = true;
  122. return ret;
  123. }
  124. static const struct file_operations mei_dbgfs_allow_fa_fops = {
  125. .open = simple_open,
  126. .read = debugfs_read_file_bool,
  127. .write = mei_dbgfs_write_allow_fa,
  128. .llseek = generic_file_llseek,
  129. };
  130. /**
  131. * mei_dbgfs_deregister - Remove the debugfs files and directories
  132. *
  133. * @dev: the mei device structure
  134. */
  135. void mei_dbgfs_deregister(struct mei_device *dev)
  136. {
  137. if (!dev->dbgfs_dir)
  138. return;
  139. debugfs_remove_recursive(dev->dbgfs_dir);
  140. dev->dbgfs_dir = NULL;
  141. }
  142. /**
  143. * mei_dbgfs_register - Add the debugfs files
  144. *
  145. * @dev: the mei device structure
  146. * @name: the mei device name
  147. */
  148. void mei_dbgfs_register(struct mei_device *dev, const char *name)
  149. {
  150. struct dentry *dir;
  151. dir = debugfs_create_dir(name, NULL);
  152. dev->dbgfs_dir = dir;
  153. debugfs_create_file("meclients", S_IRUSR, dir, dev,
  154. &mei_dbgfs_meclients_fops);
  155. debugfs_create_file("active", S_IRUSR, dir, dev,
  156. &mei_dbgfs_active_fops);
  157. debugfs_create_file("devstate", S_IRUSR, dir, dev,
  158. &mei_dbgfs_devstate_fops);
  159. debugfs_create_file("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
  160. &dev->allow_fixed_address,
  161. &mei_dbgfs_allow_fa_fops);
  162. }