18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef SCSI_TRANSPORT_SRP_H 38c2ecf20Sopenharmony_ci#define SCSI_TRANSPORT_SRP_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/transport_class.h> 68c2ecf20Sopenharmony_ci#include <linux/types.h> 78c2ecf20Sopenharmony_ci#include <linux/mutex.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define SRP_RPORT_ROLE_INITIATOR 0 108c2ecf20Sopenharmony_ci#define SRP_RPORT_ROLE_TARGET 1 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct srp_rport_identifiers { 138c2ecf20Sopenharmony_ci u8 port_id[16]; 148c2ecf20Sopenharmony_ci u8 roles; 158c2ecf20Sopenharmony_ci}; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/** 188c2ecf20Sopenharmony_ci * enum srp_rport_state - SRP transport layer state 198c2ecf20Sopenharmony_ci * @SRP_RPORT_RUNNING: Transport layer operational. 208c2ecf20Sopenharmony_ci * @SRP_RPORT_BLOCKED: Transport layer not operational; fast I/O fail timer 218c2ecf20Sopenharmony_ci * is running and I/O has been blocked. 228c2ecf20Sopenharmony_ci * @SRP_RPORT_FAIL_FAST: Fast I/O fail timer has expired; fail I/O fast. 238c2ecf20Sopenharmony_ci * @SRP_RPORT_LOST: Port is being removed. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_cienum srp_rport_state { 268c2ecf20Sopenharmony_ci SRP_RPORT_RUNNING, 278c2ecf20Sopenharmony_ci SRP_RPORT_BLOCKED, 288c2ecf20Sopenharmony_ci SRP_RPORT_FAIL_FAST, 298c2ecf20Sopenharmony_ci SRP_RPORT_LOST, 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/** 338c2ecf20Sopenharmony_ci * struct srp_rport - SRP initiator or target port 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * Fields that are relevant for SRP initiator and SRP target drivers: 368c2ecf20Sopenharmony_ci * @dev: Device associated with this rport. 378c2ecf20Sopenharmony_ci * @port_id: 16-byte port identifier. 388c2ecf20Sopenharmony_ci * @roles: Role of this port - initiator or target. 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * Fields that are only relevant for SRP initiator drivers: 418c2ecf20Sopenharmony_ci * @lld_data: LLD private data. 428c2ecf20Sopenharmony_ci * @mutex: Protects against concurrent rport reconnect / 438c2ecf20Sopenharmony_ci * fast_io_fail / dev_loss_tmo activity. 448c2ecf20Sopenharmony_ci * @state: rport state. 458c2ecf20Sopenharmony_ci * @reconnect_delay: Reconnect delay in seconds. 468c2ecf20Sopenharmony_ci * @failed_reconnects: Number of failed reconnect attempts. 478c2ecf20Sopenharmony_ci * @reconnect_work: Work structure used for scheduling reconnect attempts. 488c2ecf20Sopenharmony_ci * @fast_io_fail_tmo: Fast I/O fail timeout in seconds. 498c2ecf20Sopenharmony_ci * @dev_loss_tmo: Device loss timeout in seconds. 508c2ecf20Sopenharmony_ci * @fast_io_fail_work: Work structure used for scheduling fast I/O fail work. 518c2ecf20Sopenharmony_ci * @dev_loss_work: Work structure used for scheduling device loss work. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_cistruct srp_rport { 548c2ecf20Sopenharmony_ci /* for initiator and target drivers */ 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci struct device dev; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci u8 port_id[16]; 598c2ecf20Sopenharmony_ci u8 roles; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci /* for initiator drivers */ 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci void *lld_data; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci struct mutex mutex; 668c2ecf20Sopenharmony_ci enum srp_rport_state state; 678c2ecf20Sopenharmony_ci int reconnect_delay; 688c2ecf20Sopenharmony_ci int failed_reconnects; 698c2ecf20Sopenharmony_ci struct delayed_work reconnect_work; 708c2ecf20Sopenharmony_ci int fast_io_fail_tmo; 718c2ecf20Sopenharmony_ci int dev_loss_tmo; 728c2ecf20Sopenharmony_ci struct delayed_work fast_io_fail_work; 738c2ecf20Sopenharmony_ci struct delayed_work dev_loss_work; 748c2ecf20Sopenharmony_ci}; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/** 778c2ecf20Sopenharmony_ci * struct srp_function_template 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * Fields that are only relevant for SRP initiator drivers: 808c2ecf20Sopenharmony_ci * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and 818c2ecf20Sopenharmony_ci * dev_loss_tmo sysfs attribute for an rport. 828c2ecf20Sopenharmony_ci * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command 838c2ecf20Sopenharmony_ci * timer if the device on which it has been queued is blocked. 848c2ecf20Sopenharmony_ci * @reconnect_delay: If not NULL, points to the default reconnect_delay value. 858c2ecf20Sopenharmony_ci * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value. 868c2ecf20Sopenharmony_ci * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value. 878c2ecf20Sopenharmony_ci * @reconnect: Callback function for reconnecting to the target. See also 888c2ecf20Sopenharmony_ci * srp_reconnect_rport(). 898c2ecf20Sopenharmony_ci * @terminate_rport_io: Callback function for terminating all outstanding I/O 908c2ecf20Sopenharmony_ci * requests for an rport. 918c2ecf20Sopenharmony_ci * @rport_delete: Callback function that deletes an rport. 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_cistruct srp_function_template { 948c2ecf20Sopenharmony_ci /* for initiator drivers */ 958c2ecf20Sopenharmony_ci bool has_rport_state; 968c2ecf20Sopenharmony_ci bool reset_timer_if_blocked; 978c2ecf20Sopenharmony_ci int *reconnect_delay; 988c2ecf20Sopenharmony_ci int *fast_io_fail_tmo; 998c2ecf20Sopenharmony_ci int *dev_loss_tmo; 1008c2ecf20Sopenharmony_ci int (*reconnect)(struct srp_rport *rport); 1018c2ecf20Sopenharmony_ci void (*terminate_rport_io)(struct srp_rport *rport); 1028c2ecf20Sopenharmony_ci void (*rport_delete)(struct srp_rport *rport); 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciextern struct scsi_transport_template * 1068c2ecf20Sopenharmony_cisrp_attach_transport(struct srp_function_template *); 1078c2ecf20Sopenharmony_ciextern void srp_release_transport(struct scsi_transport_template *); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ciextern void srp_rport_get(struct srp_rport *rport); 1108c2ecf20Sopenharmony_ciextern void srp_rport_put(struct srp_rport *rport); 1118c2ecf20Sopenharmony_ciextern struct srp_rport *srp_rport_add(struct Scsi_Host *, 1128c2ecf20Sopenharmony_ci struct srp_rport_identifiers *); 1138c2ecf20Sopenharmony_ciextern void srp_rport_del(struct srp_rport *); 1148c2ecf20Sopenharmony_ciextern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, 1158c2ecf20Sopenharmony_ci long dev_loss_tmo); 1168c2ecf20Sopenharmony_ciint srp_parse_tmo(int *tmo, const char *buf); 1178c2ecf20Sopenharmony_ciextern int srp_reconnect_rport(struct srp_rport *rport); 1188c2ecf20Sopenharmony_ciextern void srp_start_tl_fail_timers(struct srp_rport *rport); 1198c2ecf20Sopenharmony_ciextern void srp_remove_host(struct Scsi_Host *); 1208c2ecf20Sopenharmony_ciextern void srp_stop_rport_timers(struct srp_rport *rport); 1218c2ecf20Sopenharmony_cienum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/** 1248c2ecf20Sopenharmony_ci * srp_chkready() - evaluate the transport layer state before I/O 1258c2ecf20Sopenharmony_ci * @rport: SRP target port pointer. 1268c2ecf20Sopenharmony_ci * 1278c2ecf20Sopenharmony_ci * Returns a SCSI result code that can be returned by the LLD queuecommand() 1288c2ecf20Sopenharmony_ci * implementation. The role of this function is similar to that of 1298c2ecf20Sopenharmony_ci * fc_remote_port_chkready(). 1308c2ecf20Sopenharmony_ci */ 1318c2ecf20Sopenharmony_cistatic inline int srp_chkready(struct srp_rport *rport) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci switch (rport->state) { 1348c2ecf20Sopenharmony_ci case SRP_RPORT_RUNNING: 1358c2ecf20Sopenharmony_ci case SRP_RPORT_BLOCKED: 1368c2ecf20Sopenharmony_ci default: 1378c2ecf20Sopenharmony_ci return 0; 1388c2ecf20Sopenharmony_ci case SRP_RPORT_FAIL_FAST: 1398c2ecf20Sopenharmony_ci return DID_TRANSPORT_FAILFAST << 16; 1408c2ecf20Sopenharmony_ci case SRP_RPORT_LOST: 1418c2ecf20Sopenharmony_ci return DID_NO_CONNECT << 16; 1428c2ecf20Sopenharmony_ci } 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#endif 146