debugfs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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(struct cxl *adapter)
  15. {
  16. int slice;
  17. /* Stop the trace */
  18. cxl_p1_write(adapter, CXL_PSL_TRACE, 0x8000000000000017LL);
  19. /* Stop the slice traces */
  20. spin_lock(&adapter->afu_list_lock);
  21. for (slice = 0; slice < adapter->slices; slice++) {
  22. if (adapter->afu[slice])
  23. cxl_p1n_write(adapter->afu[slice], CXL_PSL_SLICE_TRACE, 0x8000000000000000LL);
  24. }
  25. spin_unlock(&adapter->afu_list_lock);
  26. }
  27. /* Helpers to export CXL mmaped IO registers via debugfs */
  28. static int debugfs_io_u64_get(void *data, u64 *val)
  29. {
  30. *val = in_be64((u64 __iomem *)data);
  31. return 0;
  32. }
  33. static int debugfs_io_u64_set(void *data, u64 val)
  34. {
  35. out_be64((u64 __iomem *)data, val);
  36. return 0;
  37. }
  38. DEFINE_SIMPLE_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set, "0x%016llx\n");
  39. static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
  40. struct dentry *parent, u64 __iomem *value)
  41. {
  42. return debugfs_create_file(name, mode, parent, (void __force *)value, &fops_io_x64);
  43. }
  44. int cxl_debugfs_adapter_add(struct cxl *adapter)
  45. {
  46. struct dentry *dir;
  47. char buf[32];
  48. if (!cxl_debugfs)
  49. return -ENODEV;
  50. snprintf(buf, 32, "card%i", adapter->adapter_num);
  51. dir = debugfs_create_dir(buf, cxl_debugfs);
  52. if (IS_ERR(dir))
  53. return PTR_ERR(dir);
  54. adapter->debugfs = dir;
  55. debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
  56. debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
  57. debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
  58. debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
  59. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
  60. return 0;
  61. }
  62. void cxl_debugfs_adapter_remove(struct cxl *adapter)
  63. {
  64. debugfs_remove_recursive(adapter->debugfs);
  65. }
  66. int cxl_debugfs_afu_add(struct cxl_afu *afu)
  67. {
  68. struct dentry *dir;
  69. char buf[32];
  70. if (!afu->adapter->debugfs)
  71. return -ENODEV;
  72. snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
  73. dir = debugfs_create_dir(buf, afu->adapter->debugfs);
  74. if (IS_ERR(dir))
  75. return PTR_ERR(dir);
  76. afu->debugfs = dir;
  77. debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
  78. debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
  79. debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
  80. debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
  81. debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
  82. debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
  83. debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
  84. debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
  85. debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
  86. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
  87. return 0;
  88. }
  89. void cxl_debugfs_afu_remove(struct cxl_afu *afu)
  90. {
  91. debugfs_remove_recursive(afu->debugfs);
  92. }
  93. int __init cxl_debugfs_init(void)
  94. {
  95. struct dentry *ent;
  96. ent = debugfs_create_dir("cxl", NULL);
  97. if (IS_ERR(ent))
  98. return PTR_ERR(ent);
  99. cxl_debugfs = ent;
  100. return 0;
  101. }
  102. void cxl_debugfs_exit(void)
  103. {
  104. debugfs_remove_recursive(cxl_debugfs);
  105. }