Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef SCSI_TRANSPORT_SRP_H
0003 #define SCSI_TRANSPORT_SRP_H
0004 
0005 #include <linux/transport_class.h>
0006 #include <linux/types.h>
0007 #include <linux/mutex.h>
0008 
0009 #define SRP_RPORT_ROLE_INITIATOR 0
0010 #define SRP_RPORT_ROLE_TARGET 1
0011 
0012 struct srp_rport_identifiers {
0013     u8 port_id[16];
0014     u8 roles;
0015 };
0016 
0017 /**
0018  * enum srp_rport_state - SRP transport layer state
0019  * @SRP_RPORT_RUNNING:   Transport layer operational.
0020  * @SRP_RPORT_BLOCKED:   Transport layer not operational; fast I/O fail timer
0021  *                       is running and I/O has been blocked.
0022  * @SRP_RPORT_FAIL_FAST: Fast I/O fail timer has expired; fail I/O fast.
0023  * @SRP_RPORT_LOST:      Port is being removed.
0024  */
0025 enum srp_rport_state {
0026     SRP_RPORT_RUNNING,
0027     SRP_RPORT_BLOCKED,
0028     SRP_RPORT_FAIL_FAST,
0029     SRP_RPORT_LOST,
0030 };
0031 
0032 /**
0033  * struct srp_rport - SRP initiator or target port
0034  *
0035  * Fields that are relevant for SRP initiator and SRP target drivers:
0036  * @dev:               Device associated with this rport.
0037  * @port_id:           16-byte port identifier.
0038  * @roles:             Role of this port - initiator or target.
0039  *
0040  * Fields that are only relevant for SRP initiator drivers:
0041  * @lld_data:          LLD private data.
0042  * @mutex:             Protects against concurrent rport reconnect /
0043  *                     fast_io_fail / dev_loss_tmo activity.
0044  * @state:             rport state.
0045  * @reconnect_delay:   Reconnect delay in seconds.
0046  * @failed_reconnects: Number of failed reconnect attempts.
0047  * @reconnect_work:    Work structure used for scheduling reconnect attempts.
0048  * @fast_io_fail_tmo:  Fast I/O fail timeout in seconds.
0049  * @dev_loss_tmo:      Device loss timeout in seconds.
0050  * @fast_io_fail_work: Work structure used for scheduling fast I/O fail work.
0051  * @dev_loss_work:     Work structure used for scheduling device loss work.
0052  */
0053 struct srp_rport {
0054     /* for initiator and target drivers */
0055 
0056     struct device dev;
0057 
0058     u8 port_id[16];
0059     u8 roles;
0060 
0061     /* for initiator drivers */
0062 
0063     void            *lld_data;
0064 
0065     struct mutex        mutex;
0066     enum srp_rport_state    state;
0067     int         reconnect_delay;
0068     int         failed_reconnects;
0069     struct delayed_work reconnect_work;
0070     int         fast_io_fail_tmo;
0071     int         dev_loss_tmo;
0072     struct delayed_work fast_io_fail_work;
0073     struct delayed_work dev_loss_work;
0074 };
0075 
0076 /**
0077  * struct srp_function_template
0078  *
0079  * Fields that are only relevant for SRP initiator drivers:
0080  * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and
0081  *     dev_loss_tmo sysfs attribute for an rport.
0082  * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command
0083  *     timer if the device on which it has been queued is blocked.
0084  * @reconnect_delay: If not NULL, points to the default reconnect_delay value.
0085  * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value.
0086  * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value.
0087  * @reconnect: Callback function for reconnecting to the target. See also
0088  *     srp_reconnect_rport().
0089  * @terminate_rport_io: Callback function for terminating all outstanding I/O
0090  *     requests for an rport.
0091  * @rport_delete: Callback function that deletes an rport.
0092  */
0093 struct srp_function_template {
0094     /* for initiator drivers */
0095     bool has_rport_state;
0096     bool reset_timer_if_blocked;
0097     int *reconnect_delay;
0098     int *fast_io_fail_tmo;
0099     int *dev_loss_tmo;
0100     int (*reconnect)(struct srp_rport *rport);
0101     void (*terminate_rport_io)(struct srp_rport *rport);
0102     void (*rport_delete)(struct srp_rport *rport);
0103 };
0104 
0105 extern struct scsi_transport_template *
0106 srp_attach_transport(struct srp_function_template *);
0107 extern void srp_release_transport(struct scsi_transport_template *);
0108 
0109 extern void srp_rport_get(struct srp_rport *rport);
0110 extern void srp_rport_put(struct srp_rport *rport);
0111 extern struct srp_rport *srp_rport_add(struct Scsi_Host *,
0112                        struct srp_rport_identifiers *);
0113 extern void srp_rport_del(struct srp_rport *);
0114 extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,
0115              long dev_loss_tmo);
0116 int srp_parse_tmo(int *tmo, const char *buf);
0117 extern int srp_reconnect_rport(struct srp_rport *rport);
0118 extern void srp_start_tl_fail_timers(struct srp_rport *rport);
0119 extern void srp_remove_host(struct Scsi_Host *);
0120 extern void srp_stop_rport_timers(struct srp_rport *rport);
0121 enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd);
0122 
0123 /**
0124  * srp_chkready() - evaluate the transport layer state before I/O
0125  * @rport: SRP target port pointer.
0126  *
0127  * Returns a SCSI result code that can be returned by the LLD queuecommand()
0128  * implementation. The role of this function is similar to that of
0129  * fc_remote_port_chkready().
0130  */
0131 static inline int srp_chkready(struct srp_rport *rport)
0132 {
0133     switch (rport->state) {
0134     case SRP_RPORT_RUNNING:
0135     case SRP_RPORT_BLOCKED:
0136     default:
0137         return 0;
0138     case SRP_RPORT_FAIL_FAST:
0139         return DID_TRANSPORT_FAILFAST << 16;
0140     case SRP_RPORT_LOST:
0141         return DID_NO_CONNECT << 16;
0142     }
0143 }
0144 
0145 #endif