debugfs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. *
  3. * Intel Management Engine Interface (Intel MEI) Linux driver
  4. * Copyright (c) 2012-2013, Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. */
  16. #include <linux/slab.h>
  17. #include <linux/kernel.h>
  18. #include <linux/device.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/mei.h>
  21. #include "mei_dev.h"
  22. #include "hw.h"
  23. static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
  24. size_t cnt, loff_t *ppos)
  25. {
  26. struct mei_device *dev = fp->private_data;
  27. struct mei_me_client *me_cl;
  28. size_t bufsz = 1;
  29. char *buf;
  30. int i = 0;
  31. int pos = 0;
  32. int ret;
  33. #define HDR " |id|fix| UUID |con|msg len|sb|\n"
  34. mutex_lock(&dev->device_lock);
  35. list_for_each_entry(me_cl, &dev->me_clients, list)
  36. bufsz++;
  37. bufsz *= sizeof(HDR) + 1;
  38. buf = kzalloc(bufsz, GFP_KERNEL);
  39. if (!buf) {
  40. mutex_unlock(&dev->device_lock);
  41. return -ENOMEM;
  42. }
  43. pos += scnprintf(buf + pos, bufsz - pos, HDR);
  44. /* if the driver is not enabled the list won't be consistent */
  45. if (dev->dev_state != MEI_DEV_ENABLED)
  46. goto out;
  47. list_for_each_entry(me_cl, &dev->me_clients, list) {
  48. pos += scnprintf(buf + pos, bufsz - pos,
  49. "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|\n",
  50. i++, me_cl->client_id,
  51. me_cl->props.fixed_address,
  52. &me_cl->props.protocol_name,
  53. me_cl->props.max_number_of_connections,
  54. me_cl->props.max_msg_length,
  55. me_cl->props.single_recv_buf);
  56. }
  57. out:
  58. mutex_unlock(&dev->device_lock);
  59. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  60. kfree(buf);
  61. return ret;
  62. }
  63. static const struct file_operations mei_dbgfs_fops_meclients = {
  64. .open = simple_open,
  65. .read = mei_dbgfs_read_meclients,
  66. .llseek = generic_file_llseek,
  67. };
  68. static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf,
  69. size_t cnt, loff_t *ppos)
  70. {
  71. struct mei_device *dev = fp->private_data;
  72. struct mei_cl *cl;
  73. const size_t bufsz = 1024;
  74. char *buf;
  75. int i = 0;
  76. int pos = 0;
  77. int ret;
  78. if (!dev)
  79. return -ENODEV;
  80. buf = kzalloc(bufsz, GFP_KERNEL);
  81. if (!buf)
  82. return -ENOMEM;
  83. pos += scnprintf(buf + pos, bufsz - pos,
  84. " |me|host|state|rd|wr|\n");
  85. mutex_lock(&dev->device_lock);
  86. /* if the driver is not enabled the list won't be consistent */
  87. if (dev->dev_state != MEI_DEV_ENABLED)
  88. goto out;
  89. list_for_each_entry(cl, &dev->file_list, link) {
  90. pos += scnprintf(buf + pos, bufsz - pos,
  91. "%2d|%2d|%4d|%5d|%2d|%2d|\n",
  92. i, cl->me_client_id, cl->host_client_id, cl->state,
  93. cl->reading_state, cl->writing_state);
  94. i++;
  95. }
  96. out:
  97. mutex_unlock(&dev->device_lock);
  98. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  99. kfree(buf);
  100. return ret;
  101. }
  102. static const struct file_operations mei_dbgfs_fops_active = {
  103. .open = simple_open,
  104. .read = mei_dbgfs_read_active,
  105. .llseek = generic_file_llseek,
  106. };
  107. static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf,
  108. size_t cnt, loff_t *ppos)
  109. {
  110. struct mei_device *dev = fp->private_data;
  111. const size_t bufsz = 1024;
  112. char *buf = kzalloc(bufsz, GFP_KERNEL);
  113. int pos = 0;
  114. int ret;
  115. if (!buf)
  116. return -ENOMEM;
  117. pos += scnprintf(buf + pos, bufsz - pos, "dev: %s\n",
  118. mei_dev_state_str(dev->dev_state));
  119. pos += scnprintf(buf + pos, bufsz - pos, "hbm: %s\n",
  120. mei_hbm_state_str(dev->hbm_state));
  121. pos += scnprintf(buf + pos, bufsz - pos, "pg: %s, %s\n",
  122. mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
  123. mei_pg_state_str(mei_pg_state(dev)));
  124. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  125. kfree(buf);
  126. return ret;
  127. }
  128. static const struct file_operations mei_dbgfs_fops_devstate = {
  129. .open = simple_open,
  130. .read = mei_dbgfs_read_devstate,
  131. .llseek = generic_file_llseek,
  132. };
  133. /**
  134. * mei_dbgfs_deregister - Remove the debugfs files and directories
  135. *
  136. * @dev: the mei device structure
  137. */
  138. void mei_dbgfs_deregister(struct mei_device *dev)
  139. {
  140. if (!dev->dbgfs_dir)
  141. return;
  142. debugfs_remove_recursive(dev->dbgfs_dir);
  143. dev->dbgfs_dir = NULL;
  144. }
  145. /**
  146. * mei_dbgfs_register - Add the debugfs files
  147. *
  148. * @dev: the mei device structure
  149. * @name: the mei device name
  150. *
  151. * Return: 0 on success, <0 on failure.
  152. */
  153. int mei_dbgfs_register(struct mei_device *dev, const char *name)
  154. {
  155. struct dentry *dir, *f;
  156. dir = debugfs_create_dir(name, NULL);
  157. if (!dir)
  158. return -ENOMEM;
  159. f = debugfs_create_file("meclients", S_IRUSR, dir,
  160. dev, &mei_dbgfs_fops_meclients);
  161. if (!f) {
  162. dev_err(dev->dev, "meclients: registration failed\n");
  163. goto err;
  164. }
  165. f = debugfs_create_file("active", S_IRUSR, dir,
  166. dev, &mei_dbgfs_fops_active);
  167. if (!f) {
  168. dev_err(dev->dev, "meclients: registration failed\n");
  169. goto err;
  170. }
  171. f = debugfs_create_file("devstate", S_IRUSR, dir,
  172. dev, &mei_dbgfs_fops_devstate);
  173. if (!f) {
  174. dev_err(dev->dev, "devstate: registration failed\n");
  175. goto err;
  176. }
  177. dev->dbgfs_dir = dir;
  178. return 0;
  179. err:
  180. mei_dbgfs_deregister(dev);
  181. return -ENODEV;
  182. }