qedi_sysfs.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.h"
  10. #include "qedi_gbl.h"
  11. #include "qedi_iscsi.h"
  12. #include "qedi_dbg.h"
  13. static inline struct qedi_ctx *qedi_dev_to_hba(struct device *dev)
  14. {
  15. struct Scsi_Host *shost = class_to_shost(dev);
  16. return iscsi_host_priv(shost);
  17. }
  18. static ssize_t qedi_show_port_state(struct device *dev,
  19. struct device_attribute *attr,
  20. char *buf)
  21. {
  22. struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
  23. if (atomic_read(&qedi->link_state) == QEDI_LINK_UP)
  24. return sprintf(buf, "Online\n");
  25. else
  26. return sprintf(buf, "Linkdown\n");
  27. }
  28. static ssize_t qedi_show_speed(struct device *dev,
  29. struct device_attribute *attr, char *buf)
  30. {
  31. struct qedi_ctx *qedi = qedi_dev_to_hba(dev);
  32. struct qed_link_output if_link;
  33. qedi_ops->common->get_link(qedi->cdev, &if_link);
  34. return sprintf(buf, "%d Gbit\n", if_link.speed / 1000);
  35. }
  36. static DEVICE_ATTR(port_state, 0444, qedi_show_port_state, NULL);
  37. static DEVICE_ATTR(speed, 0444, qedi_show_speed, NULL);
  38. struct device_attribute *qedi_shost_attrs[] = {
  39. &dev_attr_port_state,
  40. &dev_attr_speed,
  41. NULL
  42. };