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