qedf_attr.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.h"
  10. inline bool qedf_is_vport(struct qedf_ctx *qedf)
  11. {
  12. return qedf->lport->vport != NULL;
  13. }
  14. /* Get base qedf for physical port from vport */
  15. static struct qedf_ctx *qedf_get_base_qedf(struct qedf_ctx *qedf)
  16. {
  17. struct fc_lport *lport;
  18. struct fc_lport *base_lport;
  19. if (!(qedf_is_vport(qedf)))
  20. return NULL;
  21. lport = qedf->lport;
  22. base_lport = shost_priv(vport_to_shost(lport->vport));
  23. return lport_priv(base_lport);
  24. }
  25. static ssize_t
  26. qedf_fcoe_mac_show(struct device *dev,
  27. struct device_attribute *attr, char *buf)
  28. {
  29. struct fc_lport *lport = shost_priv(class_to_shost(dev));
  30. u32 port_id;
  31. u8 lport_src_id[3];
  32. u8 fcoe_mac[6];
  33. port_id = fc_host_port_id(lport->host);
  34. lport_src_id[2] = (port_id & 0x000000FF);
  35. lport_src_id[1] = (port_id & 0x0000FF00) >> 8;
  36. lport_src_id[0] = (port_id & 0x00FF0000) >> 16;
  37. fc_fcoe_set_mac(fcoe_mac, lport_src_id);
  38. return scnprintf(buf, PAGE_SIZE, "%pM\n", fcoe_mac);
  39. }
  40. static ssize_t
  41. qedf_fka_period_show(struct device *dev,
  42. struct device_attribute *attr, char *buf)
  43. {
  44. struct fc_lport *lport = shost_priv(class_to_shost(dev));
  45. struct qedf_ctx *qedf = lport_priv(lport);
  46. int fka_period = -1;
  47. if (qedf_is_vport(qedf))
  48. qedf = qedf_get_base_qedf(qedf);
  49. if (qedf->ctlr.sel_fcf)
  50. fka_period = qedf->ctlr.sel_fcf->fka_period;
  51. return scnprintf(buf, PAGE_SIZE, "%d\n", fka_period);
  52. }
  53. static DEVICE_ATTR(fcoe_mac, S_IRUGO, qedf_fcoe_mac_show, NULL);
  54. static DEVICE_ATTR(fka_period, S_IRUGO, qedf_fka_period_show, NULL);
  55. struct device_attribute *qedf_host_attrs[] = {
  56. &dev_attr_fcoe_mac,
  57. &dev_attr_fka_period,
  58. NULL,
  59. };
  60. extern const struct qed_fcoe_ops *qed_ops;
  61. void qedf_capture_grc_dump(struct qedf_ctx *qedf)
  62. {
  63. struct qedf_ctx *base_qedf;
  64. /* Make sure we use the base qedf to take the GRC dump */
  65. if (qedf_is_vport(qedf))
  66. base_qedf = qedf_get_base_qedf(qedf);
  67. else
  68. base_qedf = qedf;
  69. if (test_bit(QEDF_GRCDUMP_CAPTURE, &base_qedf->flags)) {
  70. QEDF_INFO(&(base_qedf->dbg_ctx), QEDF_LOG_INFO,
  71. "GRC Dump already captured.\n");
  72. return;
  73. }
  74. qedf_get_grc_dump(base_qedf->cdev, qed_ops->common,
  75. &base_qedf->grcdump, &base_qedf->grcdump_size);
  76. QEDF_ERR(&(base_qedf->dbg_ctx), "GRC Dump captured.\n");
  77. set_bit(QEDF_GRCDUMP_CAPTURE, &base_qedf->flags);
  78. qedf_uevent_emit(base_qedf->lport->host, QEDF_UEVENT_CODE_GRCDUMP,
  79. NULL);
  80. }
  81. static ssize_t
  82. qedf_sysfs_read_grcdump(struct file *filep, struct kobject *kobj,
  83. struct bin_attribute *ba, char *buf, loff_t off,
  84. size_t count)
  85. {
  86. ssize_t ret = 0;
  87. struct fc_lport *lport = shost_priv(dev_to_shost(container_of(kobj,
  88. struct device, kobj)));
  89. struct qedf_ctx *qedf = lport_priv(lport);
  90. if (test_bit(QEDF_GRCDUMP_CAPTURE, &qedf->flags)) {
  91. ret = memory_read_from_buffer(buf, count, &off,
  92. qedf->grcdump, qedf->grcdump_size);
  93. } else {
  94. QEDF_ERR(&(qedf->dbg_ctx), "GRC Dump not captured!\n");
  95. }
  96. return ret;
  97. }
  98. static ssize_t
  99. qedf_sysfs_write_grcdump(struct file *filep, struct kobject *kobj,
  100. struct bin_attribute *ba, char *buf, loff_t off,
  101. size_t count)
  102. {
  103. struct fc_lport *lport = NULL;
  104. struct qedf_ctx *qedf = NULL;
  105. long reading;
  106. int ret = 0;
  107. char msg[40];
  108. if (off != 0)
  109. return ret;
  110. lport = shost_priv(dev_to_shost(container_of(kobj,
  111. struct device, kobj)));
  112. qedf = lport_priv(lport);
  113. buf[1] = 0;
  114. ret = kstrtol(buf, 10, &reading);
  115. if (ret) {
  116. QEDF_ERR(&(qedf->dbg_ctx), "Invalid input, err(%d)\n", ret);
  117. return ret;
  118. }
  119. memset(msg, 0, sizeof(msg));
  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. }