Merge branch 'hash' of git://ftp.sciencehorizons.net/linux
[linux-2.6-block.git] / include / scsi / scsi_transport_srp.h
CommitLineData
09345f65
FT
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
aebd5e47
FT
8#define SRP_RPORT_ROLE_INITIATOR 0
9#define SRP_RPORT_ROLE_TARGET 1
10
09345f65
FT
11struct srp_rport_identifiers {
12 u8 port_id[16];
aebd5e47 13 u8 roles;
09345f65
FT
14};
15
29c17324
BVA
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.
93079162 22 * @SRP_RPORT_LOST: Port is being removed.
29c17324
BVA
23 */
24enum srp_rport_state {
25 SRP_RPORT_RUNNING,
26 SRP_RPORT_BLOCKED,
27 SRP_RPORT_FAIL_FAST,
28 SRP_RPORT_LOST,
29};
30
31/**
0c7f8218
BVA
32 * 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.
0c7f8218
BVA
44 * @reconnect_delay: Reconnect delay in seconds.
45 * @failed_reconnects: Number of failed reconnect attempts.
46 * @reconnect_work: Work structure used for scheduling reconnect attempts.
47 * @fast_io_fail_tmo: Fast I/O fail timeout in seconds.
48 * @dev_loss_tmo: Device loss timeout in seconds.
49 * @fast_io_fail_work: Work structure used for scheduling fast I/O fail work.
50 * @dev_loss_work: Work structure used for scheduling device loss work.
29c17324 51 */
09345f65 52struct srp_rport {
dc1bdbd9
BVA
53 /* for initiator and target drivers */
54
09345f65
FT
55 struct device dev;
56
57 u8 port_id[16];
aebd5e47 58 u8 roles;
dc1bdbd9
BVA
59
60 /* for initiator drivers */
61
29c17324
BVA
62 void *lld_data;
63
64 struct mutex mutex;
65 enum srp_rport_state state;
8c64e453
BVA
66 int reconnect_delay;
67 int failed_reconnects;
68 struct delayed_work reconnect_work;
29c17324
BVA
69 int fast_io_fail_tmo;
70 int dev_loss_tmo;
71 struct delayed_work fast_io_fail_work;
72 struct delayed_work dev_loss_work;
09345f65
FT
73};
74
29c17324
BVA
75/**
76 * struct srp_function_template
0c7f8218
BVA
77 *
78 * Fields that are only relevant for SRP initiator drivers:
29c17324
BVA
79 * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and
80 * dev_loss_tmo sysfs attribute for an rport.
81 * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command
82 * timer if the device on which it has been queued is blocked.
8c64e453 83 * @reconnect_delay: If not NULL, points to the default reconnect_delay value.
29c17324
BVA
84 * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value.
85 * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value.
86 * @reconnect: Callback function for reconnecting to the target. See also
87 * srp_reconnect_rport().
88 * @terminate_rport_io: Callback function for terminating all outstanding I/O
89 * requests for an rport.
0c7f8218
BVA
90 * @rport_delete: Callback function that deletes an rport.
91 *
92 * Fields that are only relevant for SRP target drivers:
93 * @tsk_mgmt_response: Callback function for sending a task management response.
94 * @it_nexus_response: Callback function for processing an IT nexus response.
29c17324 95 */
09345f65 96struct srp_function_template {
dc1bdbd9 97 /* for initiator drivers */
29c17324
BVA
98 bool has_rport_state;
99 bool reset_timer_if_blocked;
8c64e453 100 int *reconnect_delay;
29c17324
BVA
101 int *fast_io_fail_tmo;
102 int *dev_loss_tmo;
103 int (*reconnect)(struct srp_rport *rport);
104 void (*terminate_rport_io)(struct srp_rport *rport);
dc1bdbd9 105 void (*rport_delete)(struct srp_rport *rport);
62fe8826 106 /* for target drivers */
bfb74374 107 int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int);
62fe8826 108 int (* it_nexus_response)(struct Scsi_Host *, u64, int);
09345f65
FT
109};
110
111extern struct scsi_transport_template *
112srp_attach_transport(struct srp_function_template *);
113extern void srp_release_transport(struct scsi_transport_template *);
114
9dd69a60
BVA
115extern void srp_rport_get(struct srp_rport *rport);
116extern void srp_rport_put(struct srp_rport *rport);
09345f65
FT
117extern struct srp_rport *srp_rport_add(struct Scsi_Host *,
118 struct srp_rport_identifiers *);
119extern void srp_rport_del(struct srp_rport *);
8c64e453
BVA
120extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,
121 int dev_loss_tmo);
3fdf70ac 122int srp_parse_tmo(int *tmo, const char *buf);
29c17324
BVA
123extern int srp_reconnect_rport(struct srp_rport *rport);
124extern void srp_start_tl_fail_timers(struct srp_rport *rport);
09345f65 125extern void srp_remove_host(struct Scsi_Host *);
93079162 126extern void srp_stop_rport_timers(struct srp_rport *rport);
09345f65 127
29c17324
BVA
128/**
129 * srp_chkready() - evaluate the transport layer state before I/O
0c7f8218 130 * @rport: SRP target port pointer.
29c17324
BVA
131 *
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
09345f65 150#endif