scsi_transport_srp.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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: Device loss timer has expired; 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
  28. * @lld_data: LLD private data.
  29. * @mutex: Protects against concurrent rport reconnect / fast_io_fail /
  30. * dev_loss_tmo activity.
  31. */
  32. struct srp_rport {
  33. /* for initiator and target drivers */
  34. struct device dev;
  35. u8 port_id[16];
  36. u8 roles;
  37. /* for initiator drivers */
  38. void *lld_data;
  39. struct mutex mutex;
  40. enum srp_rport_state state;
  41. bool deleted;
  42. int reconnect_delay;
  43. int failed_reconnects;
  44. struct delayed_work reconnect_work;
  45. int fast_io_fail_tmo;
  46. int dev_loss_tmo;
  47. struct delayed_work fast_io_fail_work;
  48. struct delayed_work dev_loss_work;
  49. };
  50. /**
  51. * struct srp_function_template
  52. * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and
  53. * dev_loss_tmo sysfs attribute for an rport.
  54. * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command
  55. * timer if the device on which it has been queued is blocked.
  56. * @reconnect_delay: If not NULL, points to the default reconnect_delay value.
  57. * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value.
  58. * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value.
  59. * @reconnect: Callback function for reconnecting to the target. See also
  60. * srp_reconnect_rport().
  61. * @terminate_rport_io: Callback function for terminating all outstanding I/O
  62. * requests for an rport.
  63. */
  64. struct srp_function_template {
  65. /* for initiator drivers */
  66. bool has_rport_state;
  67. bool reset_timer_if_blocked;
  68. int *reconnect_delay;
  69. int *fast_io_fail_tmo;
  70. int *dev_loss_tmo;
  71. int (*reconnect)(struct srp_rport *rport);
  72. void (*terminate_rport_io)(struct srp_rport *rport);
  73. void (*rport_delete)(struct srp_rport *rport);
  74. /* for target drivers */
  75. int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int);
  76. int (* it_nexus_response)(struct Scsi_Host *, u64, int);
  77. };
  78. extern struct scsi_transport_template *
  79. srp_attach_transport(struct srp_function_template *);
  80. extern void srp_release_transport(struct scsi_transport_template *);
  81. extern void srp_rport_get(struct srp_rport *rport);
  82. extern void srp_rport_put(struct srp_rport *rport);
  83. extern struct srp_rport *srp_rport_add(struct Scsi_Host *,
  84. struct srp_rport_identifiers *);
  85. extern void srp_rport_del(struct srp_rport *);
  86. extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,
  87. int dev_loss_tmo);
  88. extern int srp_reconnect_rport(struct srp_rport *rport);
  89. extern void srp_start_tl_fail_timers(struct srp_rport *rport);
  90. extern void srp_remove_host(struct Scsi_Host *);
  91. /**
  92. * srp_chkready() - evaluate the transport layer state before I/O
  93. *
  94. * Returns a SCSI result code that can be returned by the LLD queuecommand()
  95. * implementation. The role of this function is similar to that of
  96. * fc_remote_port_chkready().
  97. */
  98. static inline int srp_chkready(struct srp_rport *rport)
  99. {
  100. switch (rport->state) {
  101. case SRP_RPORT_RUNNING:
  102. case SRP_RPORT_BLOCKED:
  103. default:
  104. return 0;
  105. case SRP_RPORT_FAIL_FAST:
  106. return DID_TRANSPORT_FAILFAST << 16;
  107. case SRP_RPORT_LOST:
  108. return DID_NO_CONNECT << 16;
  109. }
  110. }
  111. #endif