scsi_transport_srp.h 5.0 KB

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