debugfs.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. pos += scnprintf(buf + pos, bufsz - pos, "\tDC: %01d\n",
  132. dev->hbm_f_dc_supported);
  133. pos += scnprintf(buf + pos, bufsz - pos, "\tDOT: %01d\n",
  134. dev->hbm_f_dot_supported);
  135. pos += scnprintf(buf + pos, bufsz - pos, "\tEV: %01d\n",
  136. dev->hbm_f_ev_supported);
  137. }
  138. pos += scnprintf(buf + pos, bufsz - pos, "pg: %s, %s\n",
  139. mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
  140. mei_pg_state_str(mei_pg_state(dev)));
  141. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  142. kfree(buf);
  143. return ret;
  144. }
  145. static const struct file_operations mei_dbgfs_fops_devstate = {
  146. .open = simple_open,
  147. .read = mei_dbgfs_read_devstate,
  148. .llseek = generic_file_llseek,
  149. };
  150. /**
  151. * mei_dbgfs_deregister - Remove the debugfs files and directories
  152. *
  153. * @dev: the mei device structure
  154. */
  155. void mei_dbgfs_deregister(struct mei_device *dev)
  156. {
  157. if (!dev->dbgfs_dir)
  158. return;
  159. debugfs_remove_recursive(dev->dbgfs_dir);
  160. dev->dbgfs_dir = NULL;
  161. }
  162. /**
  163. * mei_dbgfs_register - Add the debugfs files
  164. *
  165. * @dev: the mei device structure
  166. * @name: the mei device name
  167. *
  168. * Return: 0 on success, <0 on failure.
  169. */
  170. int mei_dbgfs_register(struct mei_device *dev, const char *name)
  171. {
  172. struct dentry *dir, *f;
  173. dir = debugfs_create_dir(name, NULL);
  174. if (!dir)
  175. return -ENOMEM;
  176. dev->dbgfs_dir = dir;
  177. f = debugfs_create_file("meclients", S_IRUSR, dir,
  178. dev, &mei_dbgfs_fops_meclients);
  179. if (!f) {
  180. dev_err(dev->dev, "meclients: registration failed\n");
  181. goto err;
  182. }
  183. f = debugfs_create_file("active", S_IRUSR, dir,
  184. dev, &mei_dbgfs_fops_active);
  185. if (!f) {
  186. dev_err(dev->dev, "active: registration failed\n");
  187. goto err;
  188. }
  189. f = debugfs_create_file("devstate", S_IRUSR, dir,
  190. dev, &mei_dbgfs_fops_devstate);
  191. if (!f) {
  192. dev_err(dev->dev, "devstate: registration failed\n");
  193. goto err;
  194. }
  195. f = debugfs_create_bool("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
  196. &dev->allow_fixed_address);
  197. if (!f) {
  198. dev_err(dev->dev, "allow_fixed_address: registration failed\n");
  199. goto err;
  200. }
  201. return 0;
  202. err:
  203. mei_dbgfs_deregister(dev);
  204. return -ENODEV;
  205. }