FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 1 | #ifndef SCSI_TRANSPORT_SRP_H |
| 2 | #define SCSI_TRANSPORT_SRP_H |
| 3 | |
| 4 | #include <linux/transport_class.h> |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/mutex.h> |
| 7 | |
FUJITA Tomonori | aebd5e4 | 2007-07-11 15:08:15 +0900 | [diff] [blame] | 8 | #define SRP_RPORT_ROLE_INITIATOR 0 |
| 9 | #define SRP_RPORT_ROLE_TARGET 1 |
| 10 | |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 11 | struct srp_rport_identifiers { |
| 12 | u8 port_id[16]; |
FUJITA Tomonori | aebd5e4 | 2007-07-11 15:08:15 +0900 | [diff] [blame] | 13 | u8 roles; |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 14 | }; |
| 15 | |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 16 | /** |
| 17 | * enum srp_rport_state - SRP transport layer state |
| 18 | * @SRP_RPORT_RUNNING: Transport layer operational. |
| 19 | * @SRP_RPORT_BLOCKED: Transport layer not operational; fast I/O fail timer |
| 20 | * is running and I/O has been blocked. |
| 21 | * @SRP_RPORT_FAIL_FAST: Fast I/O fail timer has expired; fail I/O fast. |
| 22 | * @SRP_RPORT_LOST: Device loss timer has expired; port is being removed. |
| 23 | */ |
| 24 | enum srp_rport_state { |
| 25 | SRP_RPORT_RUNNING, |
| 26 | SRP_RPORT_BLOCKED, |
| 27 | SRP_RPORT_FAIL_FAST, |
| 28 | SRP_RPORT_LOST, |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * struct srp_rport |
| 33 | * @lld_data: LLD private data. |
Bart Van Assche | 8c64e45 | 2013-10-26 14:35:59 +0200 | [diff] [blame] | 34 | * @mutex: Protects against concurrent rport reconnect / fast_io_fail / |
| 35 | * dev_loss_tmo activity. |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 36 | */ |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 37 | struct srp_rport { |
Bart Van Assche | dc1bdbd | 2011-09-16 20:41:13 +0200 | [diff] [blame] | 38 | /* for initiator and target drivers */ |
| 39 | |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 40 | struct device dev; |
| 41 | |
| 42 | u8 port_id[16]; |
FUJITA Tomonori | aebd5e4 | 2007-07-11 15:08:15 +0900 | [diff] [blame] | 43 | u8 roles; |
Bart Van Assche | dc1bdbd | 2011-09-16 20:41:13 +0200 | [diff] [blame] | 44 | |
| 45 | /* for initiator drivers */ |
| 46 | |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 47 | void *lld_data; |
| 48 | |
| 49 | struct mutex mutex; |
| 50 | enum srp_rport_state state; |
| 51 | bool deleted; |
Bart Van Assche | 8c64e45 | 2013-10-26 14:35:59 +0200 | [diff] [blame] | 52 | int reconnect_delay; |
| 53 | int failed_reconnects; |
| 54 | struct delayed_work reconnect_work; |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 55 | int fast_io_fail_tmo; |
| 56 | int dev_loss_tmo; |
| 57 | struct delayed_work fast_io_fail_work; |
| 58 | struct delayed_work dev_loss_work; |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 59 | }; |
| 60 | |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 61 | /** |
| 62 | * struct srp_function_template |
| 63 | * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and |
| 64 | * dev_loss_tmo sysfs attribute for an rport. |
| 65 | * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command |
| 66 | * timer if the device on which it has been queued is blocked. |
Bart Van Assche | 8c64e45 | 2013-10-26 14:35:59 +0200 | [diff] [blame] | 67 | * @reconnect_delay: If not NULL, points to the default reconnect_delay value. |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 68 | * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value. |
| 69 | * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value. |
| 70 | * @reconnect: Callback function for reconnecting to the target. See also |
| 71 | * srp_reconnect_rport(). |
| 72 | * @terminate_rport_io: Callback function for terminating all outstanding I/O |
| 73 | * requests for an rport. |
| 74 | */ |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 75 | struct srp_function_template { |
Bart Van Assche | dc1bdbd | 2011-09-16 20:41:13 +0200 | [diff] [blame] | 76 | /* for initiator drivers */ |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 77 | bool has_rport_state; |
| 78 | bool reset_timer_if_blocked; |
Bart Van Assche | 8c64e45 | 2013-10-26 14:35:59 +0200 | [diff] [blame] | 79 | int *reconnect_delay; |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 80 | int *fast_io_fail_tmo; |
| 81 | int *dev_loss_tmo; |
| 82 | int (*reconnect)(struct srp_rport *rport); |
| 83 | void (*terminate_rport_io)(struct srp_rport *rport); |
Bart Van Assche | dc1bdbd | 2011-09-16 20:41:13 +0200 | [diff] [blame] | 84 | void (*rport_delete)(struct srp_rport *rport); |
FUJITA Tomonori | 62fe882 | 2007-07-11 15:08:19 +0900 | [diff] [blame] | 85 | /* for target drivers */ |
FUJITA Tomonori | bfb7437 | 2007-07-11 15:08:22 +0900 | [diff] [blame] | 86 | int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int); |
FUJITA Tomonori | 62fe882 | 2007-07-11 15:08:19 +0900 | [diff] [blame] | 87 | int (* it_nexus_response)(struct Scsi_Host *, u64, int); |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | extern struct scsi_transport_template * |
| 91 | srp_attach_transport(struct srp_function_template *); |
| 92 | extern void srp_release_transport(struct scsi_transport_template *); |
| 93 | |
Bart Van Assche | 9dd69a6 | 2013-10-26 14:32:30 +0200 | [diff] [blame] | 94 | extern void srp_rport_get(struct srp_rport *rport); |
| 95 | extern void srp_rport_put(struct srp_rport *rport); |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 96 | extern struct srp_rport *srp_rport_add(struct Scsi_Host *, |
| 97 | struct srp_rport_identifiers *); |
| 98 | extern void srp_rport_del(struct srp_rport *); |
Bart Van Assche | 8c64e45 | 2013-10-26 14:35:59 +0200 | [diff] [blame] | 99 | extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, |
| 100 | int dev_loss_tmo); |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 101 | extern int srp_reconnect_rport(struct srp_rport *rport); |
| 102 | extern void srp_start_tl_fail_timers(struct srp_rport *rport); |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 103 | extern void srp_remove_host(struct Scsi_Host *); |
| 104 | |
Bart Van Assche | 29c1732 | 2013-10-26 14:33:30 +0200 | [diff] [blame] | 105 | /** |
| 106 | * srp_chkready() - evaluate the transport layer state before I/O |
| 107 | * |
| 108 | * Returns a SCSI result code that can be returned by the LLD queuecommand() |
| 109 | * implementation. The role of this function is similar to that of |
| 110 | * fc_remote_port_chkready(). |
| 111 | */ |
| 112 | static inline int srp_chkready(struct srp_rport *rport) |
| 113 | { |
| 114 | switch (rport->state) { |
| 115 | case SRP_RPORT_RUNNING: |
| 116 | case SRP_RPORT_BLOCKED: |
| 117 | default: |
| 118 | return 0; |
| 119 | case SRP_RPORT_FAIL_FAST: |
| 120 | return DID_TRANSPORT_FAILFAST << 16; |
| 121 | case SRP_RPORT_LOST: |
| 122 | return DID_NO_CONNECT << 16; |
| 123 | } |
| 124 | } |
| 125 | |
FUJITA Tomonori | 09345f6 | 2007-06-27 16:32:39 +0900 | [diff] [blame] | 126 | #endif |