blob: b11da5c1331e3db786c4bb375ac0a5605aae622a [file] [log] [blame]
FUJITA Tomonori09345f62007-06-27 16:32:39 +09001#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 Tomonoriaebd5e42007-07-11 15:08:15 +09008#define SRP_RPORT_ROLE_INITIATOR 0
9#define SRP_RPORT_ROLE_TARGET 1
10
FUJITA Tomonori09345f62007-06-27 16:32:39 +090011struct srp_rport_identifiers {
12 u8 port_id[16];
FUJITA Tomonoriaebd5e42007-07-11 15:08:15 +090013 u8 roles;
FUJITA Tomonori09345f62007-06-27 16:32:39 +090014};
15
Bart Van Assche29c17322013-10-26 14:33:30 +020016/**
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.
Bart Van Assche93079162013-12-11 17:06:14 +010022 * @SRP_RPORT_LOST: Port is being removed.
Bart Van Assche29c17322013-10-26 14:33:30 +020023 */
24enum srp_rport_state {
25 SRP_RPORT_RUNNING,
26 SRP_RPORT_BLOCKED,
27 SRP_RPORT_FAIL_FAST,
28 SRP_RPORT_LOST,
29};
30
31/**
Bart Van Assche0c7f8212014-01-13 12:39:35 +010032 * struct srp_rport - SRP initiator or target port
33 *
34 * Fields that are relevant for SRP initiator and SRP target drivers:
35 * @dev: Device associated with this rport.
36 * @port_id: 16-byte port identifier.
37 * @roles: Role of this port - initiator or target.
38 *
39 * Fields that are only relevant for SRP initiator drivers:
40 * @lld_data: LLD private data.
41 * @mutex: Protects against concurrent rport reconnect /
42 * fast_io_fail / dev_loss_tmo activity.
43 * @state: rport state.
44 * @deleted: Whether or not srp_rport_del() has already been invoked.
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 Assche29c17322013-10-26 14:33:30 +020052 */
FUJITA Tomonori09345f62007-06-27 16:32:39 +090053struct srp_rport {
Bart Van Asschedc1bdbd2011-09-16 20:41:13 +020054 /* for initiator and target drivers */
55
FUJITA Tomonori09345f62007-06-27 16:32:39 +090056 struct device dev;
57
58 u8 port_id[16];
FUJITA Tomonoriaebd5e42007-07-11 15:08:15 +090059 u8 roles;
Bart Van Asschedc1bdbd2011-09-16 20:41:13 +020060
61 /* for initiator drivers */
62
Bart Van Assche29c17322013-10-26 14:33:30 +020063 void *lld_data;
64
65 struct mutex mutex;
66 enum srp_rport_state state;
Bart Van Assche8c64e452013-10-26 14:35:59 +020067 int reconnect_delay;
68 int failed_reconnects;
69 struct delayed_work reconnect_work;
Bart Van Assche29c17322013-10-26 14:33:30 +020070 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 Tomonori09345f62007-06-27 16:32:39 +090074};
75
Bart Van Assche29c17322013-10-26 14:33:30 +020076/**
77 * struct srp_function_template
Bart Van Assche0c7f8212014-01-13 12:39:35 +010078 *
79 * Fields that are only relevant for SRP initiator drivers:
Bart Van Assche29c17322013-10-26 14:33:30 +020080 * @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 Assche8c64e452013-10-26 14:35:59 +020084 * @reconnect_delay: If not NULL, points to the default reconnect_delay value.
Bart Van Assche29c17322013-10-26 14:33:30 +020085 * @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 Assche0c7f8212014-01-13 12:39:35 +010091 * @rport_delete: Callback function that deletes an rport.
92 *
93 * Fields that are only relevant for SRP target drivers:
94 * @tsk_mgmt_response: Callback function for sending a task management response.
95 * @it_nexus_response: Callback function for processing an IT nexus response.
Bart Van Assche29c17322013-10-26 14:33:30 +020096 */
FUJITA Tomonori09345f62007-06-27 16:32:39 +090097struct srp_function_template {
Bart Van Asschedc1bdbd2011-09-16 20:41:13 +020098 /* for initiator drivers */
Bart Van Assche29c17322013-10-26 14:33:30 +020099 bool has_rport_state;
100 bool reset_timer_if_blocked;
Bart Van Assche8c64e452013-10-26 14:35:59 +0200101 int *reconnect_delay;
Bart Van Assche29c17322013-10-26 14:33:30 +0200102 int *fast_io_fail_tmo;
103 int *dev_loss_tmo;
104 int (*reconnect)(struct srp_rport *rport);
105 void (*terminate_rport_io)(struct srp_rport *rport);
Bart Van Asschedc1bdbd2011-09-16 20:41:13 +0200106 void (*rport_delete)(struct srp_rport *rport);
FUJITA Tomonori62fe8822007-07-11 15:08:19 +0900107 /* for target drivers */
FUJITA Tomonoribfb74372007-07-11 15:08:22 +0900108 int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int);
FUJITA Tomonori62fe8822007-07-11 15:08:19 +0900109 int (* it_nexus_response)(struct Scsi_Host *, u64, int);
FUJITA Tomonori09345f62007-06-27 16:32:39 +0900110};
111
112extern struct scsi_transport_template *
113srp_attach_transport(struct srp_function_template *);
114extern void srp_release_transport(struct scsi_transport_template *);
115
Bart Van Assche9dd69a62013-10-26 14:32:30 +0200116extern void srp_rport_get(struct srp_rport *rport);
117extern void srp_rport_put(struct srp_rport *rport);
FUJITA Tomonori09345f62007-06-27 16:32:39 +0900118extern struct srp_rport *srp_rport_add(struct Scsi_Host *,
119 struct srp_rport_identifiers *);
120extern void srp_rport_del(struct srp_rport *);
Bart Van Assche8c64e452013-10-26 14:35:59 +0200121extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,
122 int dev_loss_tmo);
Bart Van Assche29c17322013-10-26 14:33:30 +0200123extern int srp_reconnect_rport(struct srp_rport *rport);
124extern void srp_start_tl_fail_timers(struct srp_rport *rport);
FUJITA Tomonori09345f62007-06-27 16:32:39 +0900125extern void srp_remove_host(struct Scsi_Host *);
Bart Van Assche93079162013-12-11 17:06:14 +0100126extern void srp_stop_rport_timers(struct srp_rport *rport);
FUJITA Tomonori09345f62007-06-27 16:32:39 +0900127
Bart Van Assche29c17322013-10-26 14:33:30 +0200128/**
129 * srp_chkready() - evaluate the transport layer state before I/O
Bart Van Assche0c7f8212014-01-13 12:39:35 +0100130 * @rport: SRP target port pointer.
Bart Van Assche29c17322013-10-26 14:33:30 +0200131 *
132 * Returns a SCSI result code that can be returned by the LLD queuecommand()
133 * implementation. The role of this function is similar to that of
134 * fc_remote_port_chkready().
135 */
136static inline int srp_chkready(struct srp_rport *rport)
137{
138 switch (rport->state) {
139 case SRP_RPORT_RUNNING:
140 case SRP_RPORT_BLOCKED:
141 default:
142 return 0;
143 case SRP_RPORT_FAIL_FAST:
144 return DID_TRANSPORT_FAILFAST << 16;
145 case SRP_RPORT_LOST:
146 return DID_NO_CONNECT << 16;
147 }
148}
149
FUJITA Tomonori09345f62007-06-27 16:32:39 +0900150#endif