qedf_attr.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * QLogic FCoE Offload Driver
  4. * Copyright (c) 2016-2018 Cavium Inc.
  5. */
  6. #include "qedf.h"
  7. inline bool qedf_is_vport(struct qedf_ctx *qedf)
  8. {
  9. return qedf->lport->vport != NULL;
  10. }
  11. /* Get base qedf for physical port from vport */
  12. static struct qedf_ctx *qedf_get_base_qedf(struct qedf_ctx *qedf)
  13. {
  14. struct fc_lport *lport;
  15. struct fc_lport *base_lport;
  16. if (!(qedf_is_vport(qedf)))
  17. return NULL;
  18. lport = qedf->lport;
  19. base_lport = shost_priv(vport_to_shost(lport->vport));
  20. return lport_priv(base_lport);
  21. }
  22. static ssize_t fcoe_mac_show(struct device *dev,
  23. struct device_attribute *attr, char *buf)
  24. {
  25. struct fc_lport *lport = shost_priv(class_to_shost(dev));
  26. u32 port_id;
  27. u8 lport_src_id[3];
  28. u8 fcoe_mac[6];
  29. port_id = fc_host_port_id(lport->host);
  30. lport_src_id[2] = (port_id & 0x000000FF);
  31. lport_src_id[1] = (port_id & 0x0000FF00) >> 8;
  32. lport_src_id[0] = (port_id & 0x00FF0000) >> 16;
  33. fc_fcoe_set_mac(fcoe_mac, lport_src_id);
  34. return scnprintf(buf, PAGE_SIZE, "%pM\n", fcoe_mac);
  35. }
  36. static ssize_t fka_period_show(struct device *dev,
  37. struct device_attribute *attr, char *buf)
  38. {
  39. struct fc_lport *lport = shost_priv(class_to_shost(dev));
  40. struct qedf_ctx *qedf = lport_priv(lport);
  41. int fka_period = -1;
  42. if (qedf_is_vport(qedf))
  43. qedf = qedf_get_base_qedf(qedf);
  44. if (qedf->ctlr.sel_fcf)
  45. fka_period = qedf->ctlr.sel_fcf->fka_period;
  46. return scnprintf(buf, PAGE_SIZE, "%d\n", fka_period);
  47. }
  48. static DEVICE_ATTR_RO(fcoe_mac);
  49. static DEVICE_ATTR_RO(fka_period);
  50. static struct attribute *qedf_host_attrs[] = {
  51. &dev_attr_fcoe_mac.attr,
  52. &dev_attr_fka_period.attr,
  53. NULL,
  54. };
  55. static const struct attribute_group qedf_host_attr_group = {
  56. .attrs = qedf_host_attrs
  57. };
  58. const struct attribute_group *qedf_host_groups[] = {
  59. &qedf_host_attr_group,
  60. NULL
  61. };
  62. extern const struct qed_fcoe_ops *qed_ops;
  63. void qedf_capture_grc_dump(struct qedf_ctx *qedf)
  64. {
  65. struct qedf_ctx *base_qedf;
  66. /* Make sure we use the base qedf to take the GRC dump */
  67. if (qedf_is_vport(qedf))
  68. base_qedf = qedf_get_base_qedf(qedf);
  69. else
  70. base_qedf = qedf;
  71. if (test_bit(QEDF_GRCDUMP_CAPTURE, &base_qedf->flags)) {
  72. QEDF_INFO(&(base_qedf->dbg_ctx), QEDF_LOG_INFO,
  73. "GRC Dump already captured.\n");
  74. return;
  75. }
  76. qedf_get_grc_dump(base_qedf->cdev, qed_ops->common,
  77. &base_qedf->grcdump, &base_qedf->grcdump_size);
  78. QEDF_ERR(&(base_qedf->dbg_ctx), "GRC Dump captured.\n");
  79. set_bit(QEDF_GRCDUMP_CAPTURE, &base_qedf->flags);
  80. qedf_uevent_emit(base_qedf->lport->host, QEDF_UEVENT_CODE_GRCDUMP,
  81. NULL);
  82. }
  83. static ssize_t
  84. qedf_sysfs_read_grcdump(struct file *filep, struct kobject *kobj,
  85. struct bin_attribute *ba, char *buf, loff_t off,
  86. size_t count)
  87. {
  88. ssize_t ret = 0;
  89. struct fc_lport *lport = shost_priv(dev_to_shost(container_of(kobj,
  90. struct device, kobj)));
  91. struct qedf_ctx *qedf = lport_priv(lport);
  92. if (test_bit(QEDF_GRCDUMP_CAPTURE, &qedf->flags)) {
  93. ret = memory_read_from_buffer(buf, count, &off,
  94. qedf->grcdump, qedf->grcdump_size);
  95. } else {
  96. QEDF_ERR(&(qedf->dbg_ctx), "GRC Dump not captured!\n");
  97. }
  98. return ret;
  99. }
  100. static ssize_t
  101. qedf_sysfs_write_grcdump(struct file *filep, struct kobject *kobj,
  102. struct bin_attribute *ba, char *buf, loff_t off,
  103. size_t count)
  104. {
  105. struct fc_lport *lport = NULL;
  106. struct qedf_ctx *qedf = NULL;
  107. long reading;
  108. int ret = 0;
  109. if (off != 0)
  110. return ret;
  111. lport = shost_priv(dev_to_shost(container_of(kobj,
  112. struct device, kobj)));
  113. qedf = lport_priv(lport);
  114. buf[1] = 0;
  115. ret = kstrtol(buf, 10, &reading);
  116. if (ret) {
  117. QEDF_ERR(&(qedf->dbg_ctx), "Invalid input, err(%d)\n", ret);
  118. return ret;
  119. }
  120. switch (reading) {
  121. case 0:
  122. memset(qedf->grcdump, 0, qedf->grcdump_size);
  123. clear_bit(QEDF_GRCDUMP_CAPTURE, &qedf->flags);
  124. break;
  125. case 1:
  126. qedf_capture_grc_dump(qedf);
  127. break;
  128. }
  129. return count;
  130. }
  131. static struct bin_attribute sysfs_grcdump_attr = {
  132. .attr = {
  133. .name = "grcdump",
  134. .mode = S_IRUSR | S_IWUSR,
  135. },
  136. .size = 0,
  137. .read = qedf_sysfs_read_grcdump,
  138. .write = qedf_sysfs_write_grcdump,
  139. };
  140. static struct sysfs_bin_attrs bin_file_entries[] = {
  141. {"grcdump", &sysfs_grcdump_attr},
  142. {NULL},
  143. };
  144. void qedf_create_sysfs_ctx_attr(struct qedf_ctx *qedf)
  145. {
  146. qedf_create_sysfs_attr(qedf->lport->host, bin_file_entries);
  147. }
  148. void qedf_remove_sysfs_ctx_attr(struct qedf_ctx *qedf)
  149. {
  150. qedf_remove_sysfs_attr(qedf->lport->host, bin_file_entries);
  151. }