qedf_dbg.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * QLogic FCoE Offload Driver
  3. * Copyright (c) 2016-2018 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 "qedf_dbg.h"
  10. #include <linux/vmalloc.h>
  11. void
  12. qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
  13. const char *fmt, ...)
  14. {
  15. va_list va;
  16. struct va_format vaf;
  17. char nfunc[32];
  18. memset(nfunc, 0, sizeof(nfunc));
  19. memcpy(nfunc, func, sizeof(nfunc) - 1);
  20. va_start(va, fmt);
  21. vaf.fmt = fmt;
  22. vaf.va = &va;
  23. if (likely(qedf) && likely(qedf->pdev))
  24. pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
  25. nfunc, line, qedf->host_no, &vaf);
  26. else
  27. pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
  28. va_end(va);
  29. }
  30. void
  31. qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
  32. const char *fmt, ...)
  33. {
  34. va_list va;
  35. struct va_format vaf;
  36. char nfunc[32];
  37. memset(nfunc, 0, sizeof(nfunc));
  38. memcpy(nfunc, func, sizeof(nfunc) - 1);
  39. va_start(va, fmt);
  40. vaf.fmt = fmt;
  41. vaf.va = &va;
  42. if (!(qedf_debug & QEDF_LOG_WARN))
  43. goto ret;
  44. if (likely(qedf) && likely(qedf->pdev))
  45. pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
  46. nfunc, line, qedf->host_no, &vaf);
  47. else
  48. pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
  49. ret:
  50. va_end(va);
  51. }
  52. void
  53. qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
  54. const char *fmt, ...)
  55. {
  56. va_list va;
  57. struct va_format vaf;
  58. char nfunc[32];
  59. memset(nfunc, 0, sizeof(nfunc));
  60. memcpy(nfunc, func, sizeof(nfunc) - 1);
  61. va_start(va, fmt);
  62. vaf.fmt = fmt;
  63. vaf.va = &va;
  64. if (!(qedf_debug & QEDF_LOG_NOTICE))
  65. goto ret;
  66. if (likely(qedf) && likely(qedf->pdev))
  67. pr_notice("[%s]:[%s:%d]:%d: %pV",
  68. dev_name(&(qedf->pdev->dev)), nfunc, line,
  69. qedf->host_no, &vaf);
  70. else
  71. pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
  72. ret:
  73. va_end(va);
  74. }
  75. void
  76. qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
  77. u32 level, const char *fmt, ...)
  78. {
  79. va_list va;
  80. struct va_format vaf;
  81. char nfunc[32];
  82. memset(nfunc, 0, sizeof(nfunc));
  83. memcpy(nfunc, func, sizeof(nfunc) - 1);
  84. va_start(va, fmt);
  85. vaf.fmt = fmt;
  86. vaf.va = &va;
  87. if (!(qedf_debug & level))
  88. goto ret;
  89. if (likely(qedf) && likely(qedf->pdev))
  90. pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
  91. nfunc, line, qedf->host_no, &vaf);
  92. else
  93. pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
  94. ret:
  95. va_end(va);
  96. }
  97. int
  98. qedf_alloc_grc_dump_buf(u8 **buf, uint32_t len)
  99. {
  100. *buf = vmalloc(len);
  101. if (!(*buf))
  102. return -ENOMEM;
  103. memset(*buf, 0, len);
  104. return 0;
  105. }
  106. void
  107. qedf_free_grc_dump_buf(uint8_t **buf)
  108. {
  109. vfree(*buf);
  110. *buf = NULL;
  111. }
  112. int
  113. qedf_get_grc_dump(struct qed_dev *cdev, const struct qed_common_ops *common,
  114. u8 **buf, uint32_t *grcsize)
  115. {
  116. if (!*buf)
  117. return -EINVAL;
  118. return common->dbg_all_data(cdev, *buf);
  119. }
  120. void
  121. qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg)
  122. {
  123. char event_string[40];
  124. char *envp[] = {event_string, NULL};
  125. memset(event_string, 0, sizeof(event_string));
  126. switch (code) {
  127. case QEDF_UEVENT_CODE_GRCDUMP:
  128. if (msg)
  129. strscpy(event_string, msg, sizeof(event_string));
  130. else
  131. sprintf(event_string, "GRCDUMP=%u", shost->host_no);
  132. break;
  133. default:
  134. /* do nothing */
  135. break;
  136. }
  137. kobject_uevent_env(&shost->shost_gendev.kobj, KOBJ_CHANGE, envp);
  138. }
  139. int
  140. qedf_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
  141. {
  142. int ret = 0;
  143. for (; iter->name; iter++) {
  144. ret = sysfs_create_bin_file(&shost->shost_gendev.kobj,
  145. iter->attr);
  146. if (ret)
  147. pr_err("Unable to create sysfs %s attr, err(%d).\n",
  148. iter->name, ret);
  149. }
  150. return ret;
  151. }
  152. void
  153. qedf_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
  154. {
  155. for (; iter->name; iter++)
  156. sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr);
  157. }