scsi_transport_srp.h 3.5 KB

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