/* SPDX-License-Identifier: GPL-2.0 */1#ifndef SCSI_TRANSPORT_SRP_H2#define SCSI_TRANSPORT_SRP_H34#include <linux/transport_class.h>5#include <linux/types.h>6#include <linux/mutex.h>78#define SRP_RPORT_ROLE_INITIATOR 09#define SRP_RPORT_ROLE_TARGET 11011struct srp_rport_identifiers {12u8 port_id[16];13u8 roles;14};1516/**17* enum srp_rport_state - SRP transport layer state18* @SRP_RPORT_RUNNING: Transport layer operational.19* @SRP_RPORT_BLOCKED: Transport layer not operational; fast I/O fail timer20* 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: Port is being removed.23*/24enum srp_rport_state {25SRP_RPORT_RUNNING,26SRP_RPORT_BLOCKED,27SRP_RPORT_FAIL_FAST,28SRP_RPORT_LOST,29};3031/**32* struct srp_rport - SRP initiator or target port33*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* @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.51*/52struct srp_rport {53/* for initiator and target drivers */5455struct device dev;5657u8 port_id[16];58u8 roles;5960/* for initiator drivers */6162void *lld_data;6364struct mutex mutex;65enum srp_rport_state state;66int reconnect_delay;67int failed_reconnects;68struct delayed_work reconnect_work;69int fast_io_fail_tmo;70int dev_loss_tmo;71struct delayed_work fast_io_fail_work;72struct delayed_work dev_loss_work;73};7475/**76* struct srp_function_template - template for SRP initiator drivers77*78* Fields that are only relevant for SRP initiator drivers:79* @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and80* dev_loss_tmo sysfs attribute for an rport.81* @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command82* timer if the device on which it has been queued is blocked.83* @reconnect_delay: If not NULL, points to the default reconnect_delay value.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 also87* srp_reconnect_rport().88* @terminate_rport_io: Callback function for terminating all outstanding I/O89* requests for an rport.90* @rport_delete: Callback function that deletes an rport.91*/92struct srp_function_template {93/* for initiator drivers */94bool has_rport_state;95bool reset_timer_if_blocked;96int *reconnect_delay;97int *fast_io_fail_tmo;98int *dev_loss_tmo;99int (*reconnect)(struct srp_rport *rport);100void (*terminate_rport_io)(struct srp_rport *rport);101void (*rport_delete)(struct srp_rport *rport);102};103104extern struct scsi_transport_template *105srp_attach_transport(struct srp_function_template *);106extern void srp_release_transport(struct scsi_transport_template *);107108extern void srp_rport_get(struct srp_rport *rport);109extern void srp_rport_put(struct srp_rport *rport);110extern struct srp_rport *srp_rport_add(struct Scsi_Host *,111struct srp_rport_identifiers *);112extern void srp_rport_del(struct srp_rport *);113extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,114long dev_loss_tmo);115int srp_parse_tmo(int *tmo, const char *buf);116extern int srp_reconnect_rport(struct srp_rport *rport);117extern void srp_start_tl_fail_timers(struct srp_rport *rport);118extern void srp_remove_host(struct Scsi_Host *);119extern void srp_stop_rport_timers(struct srp_rport *rport);120enum scsi_timeout_action srp_timed_out(struct scsi_cmnd *scmd);121122/**123* srp_chkready() - evaluate the transport layer state before I/O124* @rport: SRP target port pointer.125*126* Returns: a SCSI result code that can be returned by the LLD queuecommand()127* implementation. The role of this function is similar to that of128* fc_remote_port_chkready().129*/130static inline int srp_chkready(struct srp_rport *rport)131{132switch (rport->state) {133case SRP_RPORT_RUNNING:134case SRP_RPORT_BLOCKED:135default:136return 0;137case SRP_RPORT_FAIL_FAST:138return DID_TRANSPORT_FAILFAST << 16;139case SRP_RPORT_LOST:140return DID_NO_CONNECT << 16;141}142}143144#endif145146147