scsi_transport_srp.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef SCSI_TRANSPORT_SRP_H
  3. #define SCSI_TRANSPORT_SRP_H
  4. #include <linux/transport_class.h>
  5. #include <linux/types.h>
  6. #include <linux/mutex.h>
  7. #define SRP_RPORT_ROLE_INITIATOR 0
  8. #define SRP_RPORT_ROLE_TARGET 1
  9. struct srp_rport_identifiers {
  10. u8 port_id[16];
  11. u8 roles;
  12. };
  13. /**
  14. * enum srp_rport_state - SRP transport layer state
  15. * @SRP_RPORT_RUNNING: Transport layer operational.
  16. * @SRP_RPORT_BLOCKED: Transport layer not operational; fast I/O fail timer
  17. * is running and I/O has been blocked.
  18. * @SRP_RPORT_FAIL_FAST: Fast I/O fail timer has expired; fail I/O fast.
  19. * @SRP_RPORT_LOST: Port is being removed.
  20. */
  21. enum srp_rport_state {
  22. SRP_RPORT_RUNNING,
  23. SRP_RPORT_BLOCKED,
  24. SRP_RPORT_FAIL_FAST,
  25. SRP_RPORT_LOST,
  26. };
  27. /**
  28. * struct srp_rport - SRP initiator or target port
  29. *
  30. * Fields that are relevant for SRP initiator and SRP target drivers:
  31. * @dev: Device associated with this rport.
  32. * @port_id: 16-byte port identifier.
  33. * @roles: Role of this port - initiator or target.
  34. *
  35. * Fields that are only relevant for SRP initiator drivers:
  36. * @lld_data: LLD private data.
  37. * @mutex: Protects against concurrent rport reconnect /
  38. * fast_io_fail / dev_loss_tmo activity.
  39. * @state: rport state.
  40. * @reconnect_delay: Reconnect delay in seconds.
  41. * @failed_reconnects: Number of failed reconnect attempts.
  42. * @reconnect_work: Work structure used for scheduling reconnect attempts.
  43. * @fast_io_fail_tmo: Fast I/O fail timeout in seconds.
  44. * @dev_loss_tmo: Device loss timeout in seconds.
  45. * @fast_io_fail_work: Work structure used for scheduling fast I/O fail work.
  46. * @dev_loss_work: Work structure used for scheduling device loss work.
  47. */
  48. struct srp_rport {
  49. /* for initiator and target drivers */
  50. struct device dev;
  51. u8 port_id[16];
  52. u8 roles;
  53. /* for initiator drivers */
  54. void *lld_data;
  55. struct mutex mutex;
  56. enum srp_rport_state state;
  57. int reconnect_delay;
  58. int failed_reconnects;
  59. struct delayed_work reconnect_work;
  60. int fast_io_fail_tmo;
  61. int dev_loss_tmo;
  62. struct delayed_work fast_io_fail_work;
  63. struct delayed_work dev_loss_work;
  64. };
  65. /**
  66. * struct srp_function_template
  67. *
  68. * Fields that are only relevant for SRP initiator drivers:
  69. * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and
  70. * dev_loss_tmo sysfs attribute for an rport.
  71. * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command
  72. * timer if the device on which it has been queued is blocked.
  73. * @reconnect_delay: If not NULL, points to the default reconnect_delay value.
  74. * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value.
  75. * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value.
  76. * @reconnect: Callback function for reconnecting to the target. See also
  77. * srp_reconnect_rport().
  78. * @terminate_rport_io: Callback function for terminating all outstanding I/O
  79. * requests for an rport.
  80. * @rport_delete: Callback function that deletes an rport.
  81. */
  82. struct srp_function_template {
  83. /* for initiator drivers */
  84. bool has_rport_state;
  85. bool reset_timer_if_blocked;
  86. int *reconnect_delay;
  87. int *fast_io_fail_tmo;
  88. int *dev_loss_tmo;
  89. int (*reconnect)(struct srp_rport *rport);
  90. void (*terminate_rport_io)(struct srp_rport *rport);
  91. void (*rport_delete)(struct srp_rport *rport);
  92. };
  93. extern struct scsi_transport_template *
  94. srp_attach_transport(struct srp_function_template *);
  95. extern void srp_release_transport(struct scsi_transport_template *);
  96. extern void srp_rport_get(struct srp_rport *rport);
  97. extern void srp_rport_put(struct srp_rport *rport);
  98. extern struct srp_rport *srp_rport_add(struct Scsi_Host *,
  99. struct srp_rport_identifiers *);
  100. extern void srp_rport_del(struct srp_rport *);
  101. extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,
  102. long dev_loss_tmo);
  103. int srp_parse_tmo(int *tmo, const char *buf);
  104. extern int srp_reconnect_rport(struct srp_rport *rport);
  105. extern void srp_start_tl_fail_timers(struct srp_rport *rport);
  106. extern void srp_remove_host(struct Scsi_Host *);
  107. extern void srp_stop_rport_timers(struct srp_rport *rport);
  108. enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd);
  109. /**
  110. * srp_chkready() - evaluate the transport layer state before I/O
  111. * @rport: SRP target port pointer.
  112. *
  113. * Returns a SCSI result code that can be returned by the LLD queuecommand()
  114. * implementation. The role of this function is similar to that of
  115. * fc_remote_port_chkready().
  116. */
  117. static inline int srp_chkready(struct srp_rport *rport)
  118. {
  119. switch (rport->state) {
  120. case SRP_RPORT_RUNNING:
  121. case SRP_RPORT_BLOCKED:
  122. default:
  123. return 0;
  124. case SRP_RPORT_FAIL_FAST:
  125. return DID_TRANSPORT_FAILFAST << 16;
  126. case SRP_RPORT_LOST:
  127. return DID_NO_CONNECT << 16;
  128. }
  129. }
  130. #endif