debugfs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright 2014 IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/debugfs.h>
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include "cxl.h"
  13. static struct dentry *cxl_debugfs;
  14. void cxl_stop_trace_psl9(struct cxl *adapter)
  15. {
  16. /* Stop the trace */
  17. cxl_p1_write(adapter, CXL_PSL9_TRACECFG, 0x4480000000000000ULL);
  18. }
  19. void cxl_stop_trace_psl8(struct cxl *adapter)
  20. {
  21. int slice;
  22. /* Stop the trace */
  23. cxl_p1_write(adapter, CXL_PSL_TRACE, 0x8000000000000017LL);
  24. /* Stop the slice traces */
  25. spin_lock(&adapter->afu_list_lock);
  26. for (slice = 0; slice < adapter->slices; slice++) {
  27. if (adapter->afu[slice])
  28. cxl_p1n_write(adapter->afu[slice], CXL_PSL_SLICE_TRACE, 0x8000000000000000LL);
  29. }
  30. spin_unlock(&adapter->afu_list_lock);
  31. }
  32. /* Helpers to export CXL mmaped IO registers via debugfs */
  33. static int debugfs_io_u64_get(void *data, u64 *val)
  34. {
  35. *val = in_be64((u64 __iomem *)data);
  36. return 0;
  37. }
  38. static int debugfs_io_u64_set(void *data, u64 val)
  39. {
  40. out_be64((u64 __iomem *)data, val);
  41. return 0;
  42. }
  43. DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
  44. "0x%016llx\n");
  45. static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
  46. struct dentry *parent, u64 __iomem *value)
  47. {
  48. return debugfs_create_file_unsafe(name, mode, parent,
  49. (void __force *)value, &fops_io_x64);
  50. }
  51. void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
  52. {
  53. debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR1));
  54. debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR2));
  55. debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL));
  56. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG));
  57. }
  58. void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
  59. {
  60. debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
  61. debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
  62. debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
  63. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
  64. }
  65. void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir)
  66. {
  67. debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC));
  68. }
  69. int cxl_debugfs_adapter_add(struct cxl *adapter)
  70. {
  71. struct dentry *dir;
  72. char buf[32];
  73. if (!cxl_debugfs)
  74. return -ENODEV;
  75. snprintf(buf, 32, "card%i", adapter->adapter_num);
  76. dir = debugfs_create_dir(buf, cxl_debugfs);
  77. if (IS_ERR(dir))
  78. return PTR_ERR(dir);
  79. adapter->debugfs = dir;
  80. debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
  81. if (adapter->native->sl_ops->debugfs_add_adapter_regs)
  82. adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
  83. return 0;
  84. }
  85. void cxl_debugfs_adapter_remove(struct cxl *adapter)
  86. {
  87. debugfs_remove_recursive(adapter->debugfs);
  88. }
  89. void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
  90. {
  91. debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
  92. }
  93. void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
  94. {
  95. debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
  96. debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
  97. debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
  98. debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
  99. debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
  100. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
  101. }
  102. int cxl_debugfs_afu_add(struct cxl_afu *afu)
  103. {
  104. struct dentry *dir;
  105. char buf[32];
  106. if (!afu->adapter->debugfs)
  107. return -ENODEV;
  108. snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
  109. dir = debugfs_create_dir(buf, afu->adapter->debugfs);
  110. if (IS_ERR(dir))
  111. return PTR_ERR(dir);
  112. afu->debugfs = dir;
  113. debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
  114. debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
  115. debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
  116. debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
  117. if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
  118. afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
  119. return 0;
  120. }
  121. void cxl_debugfs_afu_remove(struct cxl_afu *afu)
  122. {
  123. debugfs_remove_recursive(afu->debugfs);
  124. }
  125. int __init cxl_debugfs_init(void)
  126. {
  127. struct dentry *ent;
  128. if (!cpu_has_feature(CPU_FTR_HVMODE))
  129. return 0;
  130. ent = debugfs_create_dir("cxl", NULL);
  131. if (IS_ERR(ent))
  132. return PTR_ERR(ent);
  133. cxl_debugfs = ent;
  134. return 0;
  135. }
  136. void cxl_debugfs_exit(void)
  137. {
  138. debugfs_remove_recursive(cxl_debugfs);
  139. }