qedi_dbg.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * QLogic iSCSI Offload Driver
  3. * Copyright (c) 2016 Cavium Inc.
  4. *
  5. * This software is available under the terms of the GNU General Public License
  6. * (GPL) Version 2, available from the file COPYING in the main directory of
  7. * this source tree.
  8. */
  9. #include "qedi_dbg.h"
  10. #include <linux/vmalloc.h>
  11. void
  12. qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
  13. const char *fmt, ...)
  14. {
  15. va_list va;
  16. struct va_format vaf;
  17. va_start(va, fmt);
  18. vaf.fmt = fmt;
  19. vaf.va = &va;
  20. if (likely(qedi) && likely(qedi->pdev))
  21. pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
  22. func, line, qedi->host_no, &vaf);
  23. else
  24. pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
  25. va_end(va);
  26. }
  27. void
  28. qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
  29. const char *fmt, ...)
  30. {
  31. va_list va;
  32. struct va_format vaf;
  33. va_start(va, fmt);
  34. vaf.fmt = fmt;
  35. vaf.va = &va;
  36. if (!(qedi_dbg_log & QEDI_LOG_WARN))
  37. goto ret;
  38. if (likely(qedi) && likely(qedi->pdev))
  39. pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
  40. func, line, qedi->host_no, &vaf);
  41. else
  42. pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
  43. ret:
  44. va_end(va);
  45. }
  46. void
  47. qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
  48. const char *fmt, ...)
  49. {
  50. va_list va;
  51. struct va_format vaf;
  52. va_start(va, fmt);
  53. vaf.fmt = fmt;
  54. vaf.va = &va;
  55. if (!(qedi_dbg_log & QEDI_LOG_NOTICE))
  56. goto ret;
  57. if (likely(qedi) && likely(qedi->pdev))
  58. pr_notice("[%s]:[%s:%d]:%d: %pV",
  59. dev_name(&qedi->pdev->dev), func, line,
  60. qedi->host_no, &vaf);
  61. else
  62. pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
  63. ret:
  64. va_end(va);
  65. }
  66. void
  67. qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
  68. u32 level, const char *fmt, ...)
  69. {
  70. va_list va;
  71. struct va_format vaf;
  72. va_start(va, fmt);
  73. vaf.fmt = fmt;
  74. vaf.va = &va;
  75. if (!(qedi_dbg_log & level))
  76. goto ret;
  77. if (likely(qedi) && likely(qedi->pdev))
  78. pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
  79. func, line, qedi->host_no, &vaf);
  80. else
  81. pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
  82. ret:
  83. va_end(va);
  84. }
  85. int
  86. qedi_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
  87. {
  88. int ret = 0;
  89. for (; iter->name; iter++) {
  90. ret = sysfs_create_bin_file(&shost->shost_gendev.kobj,
  91. iter->attr);
  92. if (ret)
  93. pr_err("Unable to create sysfs %s attr, err(%d).\n",
  94. iter->name, ret);
  95. }
  96. return ret;
  97. }
  98. void
  99. qedi_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
  100. {
  101. for (; iter->name; iter++)
  102. sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr);
  103. }