debugfs.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 "client.h"
  23. #include "hw.h"
  24. static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
  25. size_t cnt, loff_t *ppos)
  26. {
  27. struct mei_device *dev = fp->private_data;
  28. struct mei_me_client *me_cl;
  29. size_t bufsz = 1;
  30. char *buf;
  31. int i = 0;
  32. int pos = 0;
  33. int ret;
  34. #define HDR \
  35. " |id|fix| UUID |con|msg len|sb|refc|\n"
  36. down_read(&dev->me_clients_rwsem);
  37. list_for_each_entry(me_cl, &dev->me_clients, list)
  38. bufsz++;
  39. bufsz *= sizeof(HDR) + 1;
  40. buf = kzalloc(bufsz, GFP_KERNEL);
  41. if (!buf) {
  42. up_read(&dev->me_clients_rwsem);
  43. return -ENOMEM;
  44. }
  45. pos += scnprintf(buf + pos, bufsz - pos, HDR);
  46. /* if the driver is not enabled the list won't be consistent */
  47. if (dev->dev_state != MEI_DEV_ENABLED)
  48. goto out;
  49. list_for_each_entry(me_cl, &dev->me_clients, list) {
  50. if (mei_me_cl_get(me_cl)) {
  51. pos += scnprintf(buf + pos, bufsz - pos,
  52. "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
  53. i++, me_cl->client_id,
  54. me_cl->props.fixed_address,
  55. &me_cl->props.protocol_name,
  56. me_cl->props.max_number_of_connections,
  57. me_cl->props.max_msg_length,
  58. me_cl->props.single_recv_buf,
  59. atomic_read(&me_cl->refcnt.refcount));
  60. mei_me_cl_put(me_cl);
  61. }
  62. }
  63. out:
  64. up_read(&dev->me_clients_rwsem);
  65. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  66. kfree(buf);
  67. return ret;
  68. }
  69. static const struct file_operations mei_dbgfs_fops_meclients = {
  70. .open = simple_open,
  71. .read = mei_dbgfs_read_meclients,
  72. .llseek = generic_file_llseek,
  73. };
  74. static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf,
  75. size_t cnt, loff_t *ppos)
  76. {
  77. struct mei_device *dev = fp->private_data;
  78. struct mei_cl *cl;
  79. const size_t bufsz = 1024;
  80. char *buf;
  81. int i = 0;
  82. int pos = 0;
  83. int ret;
  84. if (!dev)
  85. return -ENODEV;
  86. buf = kzalloc(bufsz, GFP_KERNEL);
  87. if (!buf)
  88. return -ENOMEM;
  89. pos += scnprintf(buf + pos, bufsz - pos,
  90. " |me|host|state|rd|wr|\n");
  91. mutex_lock(&dev->device_lock);
  92. /* if the driver is not enabled the list won't be consistent */
  93. if (dev->dev_state != MEI_DEV_ENABLED)
  94. goto out;
  95. list_for_each_entry(cl, &dev->file_list, link) {
  96. pos += scnprintf(buf + pos, bufsz - pos,
  97. "%2d|%2d|%4d|%5d|%2d|%2d|\n",
  98. i, mei_cl_me_id(cl), cl->host_client_id, cl->state,
  99. !list_empty(&cl->rd_completed), cl->writing_state);
  100. i++;
  101. }
  102. out:
  103. mutex_unlock(&dev->device_lock);
  104. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  105. kfree(buf);
  106. return ret;
  107. }
  108. static const struct file_operations mei_dbgfs_fops_active = {
  109. .open = simple_open,
  110. .read = mei_dbgfs_read_active,
  111. .llseek = generic_file_llseek,
  112. };
  113. static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf,
  114. size_t cnt, loff_t *ppos)
  115. {
  116. struct mei_device *dev = fp->private_data;
  117. const size_t bufsz = 1024;
  118. char *buf = kzalloc(bufsz, GFP_KERNEL);
  119. int pos = 0;
  120. int ret;
  121. if (!buf)
  122. return -ENOMEM;
  123. pos += scnprintf(buf + pos, bufsz - pos, "dev: %s\n",
  124. mei_dev_state_str(dev->dev_state));
  125. pos += scnprintf(buf + pos, bufsz - pos, "hbm: %s\n",
  126. mei_hbm_state_str(dev->hbm_state));
  127. if (dev->hbm_state == MEI_HBM_STARTED) {
  128. pos += scnprintf(buf + pos, bufsz - pos, "hbm features:\n");
  129. pos += scnprintf(buf + pos, bufsz - pos, "\tPG: %01d\n",
  130. dev->hbm_f_pg_supported);
  131. }
  132. pos += scnprintf(buf + pos, bufsz - pos, "pg: %s, %s\n",
  133. mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
  134. mei_pg_state_str(mei_pg_state(dev)));
  135. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  136. kfree(buf);
  137. return ret;
  138. }
  139. static const struct file_operations mei_dbgfs_fops_devstate = {
  140. .open = simple_open,
  141. .read = mei_dbgfs_read_devstate,
  142. .llseek = generic_file_llseek,
  143. };
  144. /**
  145. * mei_dbgfs_deregister - Remove the debugfs files and directories
  146. *
  147. * @dev: the mei device structure
  148. */
  149. void mei_dbgfs_deregister(struct mei_device *dev)
  150. {
  151. if (!dev->dbgfs_dir)
  152. return;
  153. debugfs_remove_recursive(dev->dbgfs_dir);
  154. dev->dbgfs_dir = NULL;
  155. }
  156. /**
  157. * mei_dbgfs_register - Add the debugfs files
  158. *
  159. * @dev: the mei device structure
  160. * @name: the mei device name
  161. *
  162. * Return: 0 on success, <0 on failure.
  163. */
  164. int mei_dbgfs_register(struct mei_device *dev, const char *name)
  165. {
  166. struct dentry *dir, *f;
  167. dir = debugfs_create_dir(name, NULL);
  168. if (!dir)
  169. return -ENOMEM;
  170. f = debugfs_create_file("meclients", S_IRUSR, dir,
  171. dev, &mei_dbgfs_fops_meclients);
  172. if (!f) {
  173. dev_err(dev->dev, "meclients: registration failed\n");
  174. goto err;
  175. }
  176. f = debugfs_create_file("active", S_IRUSR, dir,
  177. dev, &mei_dbgfs_fops_active);
  178. if (!f) {
  179. dev_err(dev->dev, "meclients: registration failed\n");
  180. goto err;
  181. }
  182. f = debugfs_create_file("devstate", S_IRUSR, dir,
  183. dev, &mei_dbgfs_fops_devstate);
  184. if (!f) {
  185. dev_err(dev->dev, "devstate: registration failed\n");
  186. goto err;
  187. }
  188. f = debugfs_create_bool("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
  189. &dev->allow_fixed_address);
  190. if (!f) {
  191. dev_err(dev->dev, "allow_fixed_address: registration failed\n");
  192. goto err;
  193. }
  194. dev->dbgfs_dir = dir;
  195. return 0;
  196. err:
  197. mei_dbgfs_deregister(dev);
  198. return -ENODEV;
  199. }