Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * zfcp device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Interface to Linux SCSI midlayer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright IBM Corp. 2002, 2020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define KMSG_COMPONENT "zfcp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <scsi/fc/fc_fcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "zfcp_ext.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "zfcp_dbf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "zfcp_fc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "zfcp_reqlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static unsigned int default_depth = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) module_param_named(queue_depth, default_depth, uint, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static bool enable_dif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) module_param_named(dif, enable_dif, bool, 0400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) MODULE_PARM_DESC(dif, "Enable DIF data integrity support (default off)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) bool zfcp_experimental_dix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) module_param_named(dix, zfcp_experimental_dix, bool, 0400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) MODULE_PARM_DESC(dix, "Enable experimental DIX (data integrity extension) support which implies DIF support (default off)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static bool allow_lun_scan = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) module_param(allow_lun_scan, bool, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) MODULE_PARM_DESC(allow_lun_scan, "For NPIV, scan and attach all storage LUNs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static void zfcp_scsi_slave_destroy(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* if previous slave_alloc returned early, there is nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!zfcp_sdev->port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	zfcp_erp_lun_shutdown_wait(sdev, "scssd_1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	put_device(&zfcp_sdev->port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (sdp->tagged_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		scsi_change_queue_depth(sdp, default_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	set_host_byte(scpnt, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	zfcp_dbf_scsi_fail_send(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	scpnt->scsi_done(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) int zfcp_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct fc_rport *rport = starget_to_rport(scsi_target(scpnt->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int    status, scsi_result, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* reset the status for this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	scpnt->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	scpnt->host_scribble = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	scsi_result = fc_remote_port_chkready(rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (unlikely(scsi_result)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		scpnt->result = scsi_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		zfcp_dbf_scsi_fail_send(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		scpnt->scsi_done(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	status = atomic_read(&zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (unlikely(status & ZFCP_STATUS_COMMON_ERP_FAILED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		     !(atomic_read(&zfcp_sdev->port->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		       ZFCP_STATUS_COMMON_ERP_FAILED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		/* only LUN access denied, but port is good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		 * not covered by FC transport, have to fail here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		zfcp_scsi_command_fail(scpnt, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (unlikely(!(status & ZFCP_STATUS_COMMON_UNBLOCKED))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		/* This could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		 * call to rport_delete pending: mimic retry from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		 * 	fc_remote_port_chkready until rport is BLOCKED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ret = zfcp_fsf_fcp_cmnd(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (unlikely(ret == -EBUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return SCSI_MLQUEUE_DEVICE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	else if (unlikely(ret < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int zfcp_scsi_slave_alloc(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct zfcp_adapter *adapter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		(struct zfcp_adapter *) sdev->host->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct zfcp_unit *unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int npiv = adapter->connection_features & FSF_FEATURE_NPIV_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	zfcp_sdev->erp_action.adapter = adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	zfcp_sdev->erp_action.sdev = sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	zfcp_sdev->erp_action.port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	mutex_lock(&zfcp_sysfs_port_units_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (zfcp_sysfs_port_is_removing(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		/* port is already gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		mutex_unlock(&zfcp_sysfs_port_units_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		put_device(&port->dev); /* undo zfcp_get_port_by_wwpn() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	mutex_unlock(&zfcp_sysfs_port_units_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		put_device(&unit->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!unit && !(allow_lun_scan && npiv)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	zfcp_sdev->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	zfcp_sdev->latencies.write.channel.min = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	zfcp_sdev->latencies.write.fabric.min = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	zfcp_sdev->latencies.read.channel.min = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	zfcp_sdev->latencies.read.fabric.min = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	zfcp_sdev->latencies.cmd.channel.min = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	zfcp_sdev->latencies.cmd.fabric.min = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	spin_lock_init(&zfcp_sdev->latencies.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	zfcp_erp_lun_reopen(sdev, 0, "scsla_1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	zfcp_erp_wait(port->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct Scsi_Host *scsi_host = scpnt->device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct zfcp_adapter *adapter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		(struct zfcp_adapter *) scsi_host->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct zfcp_fsf_req *old_req, *abrt_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	unsigned long old_reqid = (unsigned long) scpnt->host_scribble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int retval = SUCCESS, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int retry = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	char *dbf_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* avoid race condition between late normal completion and abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	write_lock_irqsave(&adapter->abort_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	old_req = zfcp_reqlist_find(adapter->req_list, old_reqid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (!old_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		write_unlock_irqrestore(&adapter->abort_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		zfcp_dbf_scsi_abort("abrt_or", scpnt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return FAILED; /* completion could be in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	old_req->data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	/* don't access old fsf_req after releasing the abort_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	write_unlock_irqrestore(&adapter->abort_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	while (retry--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		abrt_req = zfcp_fsf_abort_fcp_cmnd(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (abrt_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		zfcp_dbf_scsi_abort("abrt_wt", scpnt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		ret = fc_block_scsi_eh(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			zfcp_dbf_scsi_abort("abrt_bl", scpnt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (!(atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		      ZFCP_STATUS_COMMON_RUNNING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			zfcp_dbf_scsi_abort("abrt_ru", scpnt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (!abrt_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		zfcp_dbf_scsi_abort("abrt_ar", scpnt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	wait_for_completion(&abrt_req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		dbf_tag = "abrt_ok";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		dbf_tag = "abrt_nn";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		dbf_tag = "abrt_fa";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		retval = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	zfcp_dbf_scsi_abort(dbf_tag, scpnt, abrt_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	zfcp_fsf_req_free(abrt_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct zfcp_scsi_req_filter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	u8 tmf_scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	u32 lun_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	u32 port_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void zfcp_scsi_forget_cmnd(struct zfcp_fsf_req *old_req, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct zfcp_scsi_req_filter *filter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		(struct zfcp_scsi_req_filter *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/* already aborted - prevent side-effects - or not a SCSI command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (old_req->data == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	    zfcp_fsf_req_is_status_read_buffer(old_req) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	    old_req->qtcb->header.fsf_command != FSF_QTCB_FCP_CMND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/* (tmf_scope == FCP_TMF_TGT_RESET || tmf_scope == FCP_TMF_LUN_RESET) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (old_req->qtcb->header.port_handle != filter->port_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (filter->tmf_scope == FCP_TMF_LUN_RESET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	    old_req->qtcb->header.lun_handle != filter->lun_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	zfcp_dbf_scsi_nullcmnd((struct scsi_cmnd *)old_req->data, old_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	old_req->data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static void zfcp_scsi_forget_cmnds(struct zfcp_scsi_dev *zsdev, u8 tm_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct zfcp_adapter *adapter = zsdev->port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct zfcp_scsi_req_filter filter = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		.tmf_scope = FCP_TMF_TGT_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		.port_handle = zsdev->port->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (tm_flags == FCP_TMF_LUN_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		filter.tmf_scope = FCP_TMF_LUN_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		filter.lun_handle = zsdev->lun_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * abort_lock secures against other processings - in the abort-function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 * and normal cmnd-handler - of (struct zfcp_fsf_req *)->data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	write_lock_irqsave(&adapter->abort_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	zfcp_reqlist_apply_for_all(adapter->req_list, zfcp_scsi_forget_cmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				   &filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	write_unlock_irqrestore(&adapter->abort_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  * zfcp_scsi_task_mgmt_function() - Send a task management function (sync).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * @sdev: Pointer to SCSI device to send the task management command to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * @tm_flags: Task management flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  *	      here we only handle %FCP_TMF_TGT_RESET or %FCP_TMF_LUN_RESET.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int zfcp_scsi_task_mgmt_function(struct scsi_device *sdev, u8 tm_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	struct zfcp_fsf_req *fsf_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	int retval = SUCCESS, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	int retry = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	while (retry--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		fsf_req = zfcp_fsf_fcp_task_mgmt(sdev, tm_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		if (fsf_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		zfcp_dbf_scsi_devreset("wait", sdev, tm_flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		ret = fc_block_rport(rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			zfcp_dbf_scsi_devreset("fiof", sdev, tm_flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		if (!(atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		      ZFCP_STATUS_COMMON_RUNNING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			zfcp_dbf_scsi_devreset("nres", sdev, tm_flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (!fsf_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		zfcp_dbf_scsi_devreset("reqf", sdev, tm_flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	wait_for_completion(&fsf_req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		zfcp_dbf_scsi_devreset("fail", sdev, tm_flags, fsf_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		retval = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		zfcp_dbf_scsi_devreset("okay", sdev, tm_flags, fsf_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		zfcp_scsi_forget_cmnds(zfcp_sdev, tm_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	zfcp_fsf_req_free(fsf_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	struct scsi_device *sdev = scpnt->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	return zfcp_scsi_task_mgmt_function(sdev, FCP_TMF_LUN_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct scsi_target *starget = scsi_target(scpnt->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	struct fc_rport *rport = starget_to_rport(starget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	struct Scsi_Host *shost = rport_to_shost(rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct scsi_device *sdev = NULL, *tmp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	struct zfcp_adapter *adapter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		(struct zfcp_adapter *)shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	shost_for_each_device(tmp_sdev, shost) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		if (tmp_sdev->id == starget->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			sdev = tmp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (!sdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		ret = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		zfcp_dbf_scsi_eh("tr_nosd", adapter, starget->id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	ret = zfcp_scsi_task_mgmt_function(sdev, FCP_TMF_TGT_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	/* release reference from above shost_for_each_device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		scsi_device_put(tmp_sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	int ret = SUCCESS, fc_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		zfcp_erp_port_forced_reopen_all(adapter, 0, "schrh_p");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	zfcp_erp_adapter_reopen(adapter, 0, "schrh_1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	fc_ret = fc_block_scsi_eh(scpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (fc_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		ret = fc_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	zfcp_dbf_scsi_eh("schrh_r", adapter, ~0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * zfcp_scsi_sysfs_host_reset() - Support scsi_host sysfs attribute host_reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  * @shost: Pointer to Scsi_Host to perform action on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * @reset_type: We support %SCSI_ADAPTER_RESET but not %SCSI_FIRMWARE_RESET.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * Return: 0 on %SCSI_ADAPTER_RESET, -%EOPNOTSUPP otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * This is similar to zfcp_sysfs_adapter_failed_store().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static int zfcp_scsi_sysfs_host_reset(struct Scsi_Host *shost, int reset_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct zfcp_adapter *adapter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		(struct zfcp_adapter *)shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (reset_type != SCSI_ADAPTER_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		zfcp_dbf_scsi_eh("scshr_n", adapter, ~0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	zfcp_erp_adapter_reset_sync(adapter, "scshr_y");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct scsi_transport_template *zfcp_scsi_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static struct scsi_host_template zfcp_scsi_host_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	.module			 = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	.name			 = "zfcp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	.queuecommand		 = zfcp_scsi_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	.eh_timed_out		 = fc_eh_timed_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	.eh_abort_handler	 = zfcp_scsi_eh_abort_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	.eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	.eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	.eh_host_reset_handler	 = zfcp_scsi_eh_host_reset_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	.slave_alloc		 = zfcp_scsi_slave_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	.slave_configure	 = zfcp_scsi_slave_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	.slave_destroy		 = zfcp_scsi_slave_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	.change_queue_depth	 = scsi_change_queue_depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	.host_reset		 = zfcp_scsi_sysfs_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	.proc_name		 = "zfcp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	.can_queue		 = 4096,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	.this_id		 = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	.sg_tablesize		 = (((QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 				     * ZFCP_QDIO_MAX_SBALS_PER_REQ) - 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 				   /* GCD, adjusted later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.max_sectors		 = (((QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 				     * ZFCP_QDIO_MAX_SBALS_PER_REQ) - 2) * 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 				   /* GCD, adjusted later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	/* report size limit per scatter-gather segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	.max_segment_size	 = ZFCP_QDIO_SBALE_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	.dma_boundary		 = ZFCP_QDIO_SBALE_LEN - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	.shost_attrs		 = zfcp_sysfs_shost_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	.sdev_attrs		 = zfcp_sysfs_sdev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	.track_queue_depth	 = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	.supported_mode		 = MODE_INITIATOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  * zfcp_scsi_adapter_register() - Allocate and register SCSI and FC host with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  *				  SCSI midlayer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  * @adapter: The zfcp adapter to register with the SCSI midlayer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  * Allocates the SCSI host object for the given adapter, sets basic properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  * (such as the transport template, QDIO limits, ...), and registers it with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  * the midlayer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * During registration with the midlayer the corresponding FC host object for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  * the referenced transport class is also implicitely allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  * Upon success adapter->scsi_host is set, and upon failure it remains NULL. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  * adapter->scsi_host is already set, nothing is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * * 0	     - Allocation and registration was successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  * * -EEXIST - SCSI and FC host did already exist, nothing was done, nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  *	       was changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  * * -EIO    - Allocation or registration failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) int zfcp_scsi_adapter_register(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	struct ccw_dev_id dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	if (adapter->scsi_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	ccw_device_get_id(adapter->ccw_device, &dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	/* register adapter as SCSI host with mid layer of SCSI stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	adapter->scsi_host = scsi_host_alloc(&zfcp_scsi_host_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 					     sizeof (struct zfcp_adapter *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if (!adapter->scsi_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	/* tell the SCSI stack some characteristics of this adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	adapter->scsi_host->max_id = 511;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	adapter->scsi_host->max_lun = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	adapter->scsi_host->max_channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	adapter->scsi_host->unique_id = dev_id.devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	adapter->scsi_host->transportt = zfcp_scsi_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	/* make all basic properties known at registration time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	zfcp_qdio_shost_update(adapter, adapter->qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	zfcp_scsi_set_prot(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		scsi_host_put(adapter->scsi_host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	adapter->scsi_host = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	dev_err(&adapter->ccw_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		"Registering the FCP device with the SCSI stack failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * @adapter: The zfcp adapter to unregister.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) void zfcp_scsi_adapter_unregister(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	shost = adapter->scsi_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	if (!shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	read_lock_irq(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	list_for_each_entry(port, &adapter->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		port->rport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	read_unlock_irq(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	fc_remove_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	scsi_remove_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	adapter->scsi_host = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static struct fc_host_statistics*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) zfcp_scsi_init_fc_host_stats(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	struct fc_host_statistics *fc_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	if (!adapter->fc_stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		if (!fc_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		adapter->fc_stats = fc_stats; /* freed in adapter_release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	return adapter->fc_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static void zfcp_scsi_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 					   struct fsf_qtcb_bottom_port *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 					   struct fsf_qtcb_bottom_port *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	fc_stats->seconds_since_last_reset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		data->seconds_since_last_reset - old->seconds_since_last_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	fc_stats->tx_frames = data->tx_frames - old->tx_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	fc_stats->tx_words = data->tx_words - old->tx_words;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	fc_stats->rx_frames = data->rx_frames - old->rx_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	fc_stats->rx_words = data->rx_words - old->rx_words;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	fc_stats->lip_count = data->lip - old->lip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	fc_stats->nos_count = data->nos - old->nos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	fc_stats->error_frames = data->error_frames - old->error_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	fc_stats->link_failure_count = data->link_failure - old->link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	fc_stats->loss_of_signal_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		data->loss_of_signal - old->loss_of_signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	fc_stats->prim_seq_protocol_err_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		data->psp_error_counts - old->psp_error_counts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	fc_stats->invalid_tx_word_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		data->invalid_tx_words - old->invalid_tx_words;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	fc_stats->fcp_input_requests =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		data->input_requests - old->input_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	fc_stats->fcp_output_requests =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		data->output_requests - old->output_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	fc_stats->fcp_control_requests =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		data->control_requests - old->control_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static void zfcp_scsi_set_fc_host_stats(struct fc_host_statistics *fc_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 					struct fsf_qtcb_bottom_port *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	fc_stats->tx_frames = data->tx_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	fc_stats->tx_words = data->tx_words;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	fc_stats->rx_frames = data->rx_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	fc_stats->rx_words = data->rx_words;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	fc_stats->lip_count = data->lip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	fc_stats->nos_count = data->nos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	fc_stats->error_frames = data->error_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	fc_stats->dumped_frames = data->dumped_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	fc_stats->link_failure_count = data->link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	fc_stats->loss_of_sync_count = data->loss_of_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	fc_stats->loss_of_signal_count = data->loss_of_signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	fc_stats->invalid_tx_word_count = data->invalid_tx_words;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	fc_stats->invalid_crc_count = data->invalid_crcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	fc_stats->fcp_input_requests = data->input_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	fc_stats->fcp_output_requests = data->output_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	fc_stats->fcp_control_requests = data->control_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	fc_stats->fcp_input_megabytes = data->input_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	fc_stats->fcp_output_megabytes = data->output_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) static struct fc_host_statistics *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) zfcp_scsi_get_fc_host_stats(struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	struct zfcp_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	struct fc_host_statistics *fc_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	struct fsf_qtcb_bottom_port *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	adapter = (struct zfcp_adapter *)host->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	fc_stats = zfcp_scsi_init_fc_host_stats(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	if (!fc_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	if (ret != 0 && ret != -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	if (adapter->stats_reset &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	    ((jiffies/HZ - adapter->stats_reset) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	     data->seconds_since_last_reset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		zfcp_scsi_adjust_fc_host_stats(fc_stats, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 					       adapter->stats_reset_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		zfcp_scsi_set_fc_host_stats(fc_stats, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	return fc_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static void zfcp_scsi_reset_fc_host_stats(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	struct zfcp_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	struct fsf_qtcb_bottom_port *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	adapter = (struct zfcp_adapter *)shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	if (ret != 0 && ret != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		adapter->stats_reset = jiffies/HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		kfree(adapter->stats_reset_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		adapter->stats_reset_data = data; /* finally freed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 						     adapter_release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static void zfcp_scsi_get_host_port_state(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	struct zfcp_adapter *adapter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		(struct zfcp_adapter *)shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	int status = atomic_read(&adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	    !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	else if (status & ZFCP_STATUS_COMMON_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static void zfcp_scsi_set_rport_dev_loss_tmo(struct fc_rport *rport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 					     u32 timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	rport->dev_loss_tmo = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)  * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)  * @rport: The FC rport where to teminate I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)  * Abort all pending SCSI commands for a port by closing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)  * port. Using a reopen avoids a conflict with a shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  * overwriting a reopen. The "forced" ensures that a disappeared port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)  * is not opened again as valid due to the cached plogi data in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)  * non-NPIV mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	struct Scsi_Host *shost = rport_to_shost(rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	struct zfcp_adapter *adapter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		(struct zfcp_adapter *)shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	if (port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		zfcp_erp_port_forced_reopen(port, 0, "sctrpi1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		zfcp_erp_port_forced_no_port_dbf(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 			"sctrpin", adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 			rport->port_name /* zfcp_scsi_rport_register */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 			rport->port_id /* zfcp_scsi_rport_register */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) static void zfcp_scsi_rport_register(struct zfcp_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	struct fc_rport_identifiers ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	struct fc_rport *rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	if (port->rport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	ids.node_name = port->wwnn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	ids.port_name = port->wwpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	ids.port_id = port->d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	ids.roles = FC_RPORT_ROLE_FCP_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	zfcp_dbf_rec_trig_lock("scpaddy", port->adapter, port, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 			       ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 			       ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	if (!rport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		dev_err(&port->adapter->ccw_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 			"Registering port 0x%016Lx failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 			(unsigned long long)port->wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	rport->maxframe_size = port->maxframe_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	rport->supported_classes = port->supported_classes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	port->rport = rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	port->starget_id = rport->scsi_target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	zfcp_unit_queue_scsi_scan(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static void zfcp_scsi_rport_block(struct zfcp_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	struct fc_rport *rport = port->rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	if (rport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 		zfcp_dbf_rec_trig_lock("scpdely", port->adapter, port, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 				       ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 				       ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 		fc_remote_port_delete(rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 		port->rport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	get_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	port->rport_task = RPORT_ADD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	if (!queue_work(port->adapter->work_queue, &port->rport_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	get_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	port->rport_task = RPORT_DEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	if (port->rport && queue_work(port->adapter->work_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 				      &port->rport_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	read_lock_irqsave(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	list_for_each_entry(port, &adapter->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 		zfcp_scsi_schedule_rport_block(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	read_unlock_irqrestore(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) void zfcp_scsi_rport_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	struct zfcp_port *port = container_of(work, struct zfcp_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 					      rport_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	set_worker_desc("zrp%c-%16llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 			(port->rport_task == RPORT_ADD) ? 'a' : 'd',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 			port->wwpn); /* < WORKER_DESC_LEN=24 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	while (port->rport_task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 		if (port->rport_task == RPORT_ADD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 			port->rport_task = RPORT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 			zfcp_scsi_rport_register(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 			port->rport_task = RPORT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 			zfcp_scsi_rport_block(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)  * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)  * @adapter: The adapter where to configure DIF/DIX for the SCSI host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) void zfcp_scsi_set_prot(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	unsigned int mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	unsigned int data_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	struct Scsi_Host *shost = adapter->scsi_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	data_div = atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		   ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	if ((enable_dif || zfcp_experimental_dix) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	    adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		mask |= SHOST_DIF_TYPE1_PROTECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	if (zfcp_experimental_dix && data_div &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	    adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		mask |= SHOST_DIX_TYPE1_PROTECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 		shost->sg_prot_tablesize = adapter->qdio->max_sbale_per_req / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 		shost->sg_tablesize = adapter->qdio->max_sbale_per_req / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 		shost->max_sectors = shost->sg_tablesize * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	scsi_host_set_prot(shost, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)  * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)  * @scmd: The SCSI command to report the error for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)  * @ascq: The ASCQ to put in the sense buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)  * See the error handling in sd_done for the sense codes used here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)  * Set DID_SOFT_ERROR to retry the request, if possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	scsi_build_sense_buffer(1, scmd->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 				ILLEGAL_REQUEST, 0x10, ascq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	set_driver_byte(scmd, DRIVER_SENSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	scmd->result |= SAM_STAT_CHECK_CONDITION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	set_host_byte(scmd, DID_SOFT_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) void zfcp_scsi_shost_update_config_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	struct zfcp_adapter *const adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	const struct fsf_qtcb_bottom_config *const bottom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	const bool bottom_incomplete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	struct Scsi_Host *const shost = adapter->scsi_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	const struct fc_els_flogi *nsp, *plogi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 	if (shost == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	snprintf(fc_host_firmware_version(shost), FC_VERSION_STRING_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 		 "0x%08x", bottom->lic_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 		snprintf(fc_host_hardware_version(shost),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 			 FC_VERSION_STRING_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 			 "0x%08x", bottom->hardware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 		memcpy(fc_host_serial_number(shost), bottom->serial_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 		       min(FC_SERIAL_NUMBER_SIZE, 17));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 		EBCASC(fc_host_serial_number(shost),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 		       min(FC_SERIAL_NUMBER_SIZE, 17));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 	/* adjust pointers for missing command code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 	nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 					- sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 					- sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 	snprintf(fc_host_manufacturer(shost), FC_SERIAL_NUMBER_SIZE, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 		 "IBM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	zfcp_scsi_set_prot(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 	/* do not evaluate invalid fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 	if (bottom_incomplete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 	fc_host_port_id(shost) = ntoh24(bottom->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 	fc_host_speed(shost) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 		zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 	snprintf(fc_host_model(shost), FC_SYMBOLIC_NAME_SIZE, "0x%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 		 bottom->adapter_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	switch (bottom->fc_topology) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 	case FSF_TOPO_P2P:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 		fc_host_port_type(shost) = FC_PORTTYPE_PTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 		fc_host_fabric_name(shost) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 	case FSF_TOPO_FABRIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) 		fc_host_fabric_name(shost) = be64_to_cpu(plogi->fl_wwnn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 		if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 			fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 			fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	case FSF_TOPO_AL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 		fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) 		fc_host_fabric_name(shost) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) void zfcp_scsi_shost_update_port_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) 	struct zfcp_adapter *const adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) 	const struct fsf_qtcb_bottom_port *const bottom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) 	struct Scsi_Host *const shost = adapter->scsi_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) 	if (shost == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) 	fc_host_permanent_port_name(shost) = bottom->wwpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) 	fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) 	fc_host_supported_speeds(shost) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) 		zfcp_fsf_convert_portspeed(bottom->supported_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) 	memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) 	       FC_FC4_LIST_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) 	memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) 	       FC_FC4_LIST_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) struct fc_function_template zfcp_transport_functions = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) 	.show_starget_port_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) 	.show_starget_port_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) 	.show_starget_node_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) 	.show_rport_supported_classes = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) 	.show_rport_maxframe_size = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) 	.show_rport_dev_loss_tmo = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) 	.show_host_node_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) 	.show_host_port_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) 	.show_host_permanent_port_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) 	.show_host_supported_classes = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) 	.show_host_supported_fc4s = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) 	.show_host_supported_speeds = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) 	.show_host_maxframe_size = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) 	.show_host_serial_number = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) 	.show_host_manufacturer = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) 	.show_host_model = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) 	.show_host_hardware_version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) 	.show_host_firmware_version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) 	.get_fc_host_stats = zfcp_scsi_get_fc_host_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) 	.reset_fc_host_stats = zfcp_scsi_reset_fc_host_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) 	.set_rport_dev_loss_tmo = zfcp_scsi_set_rport_dev_loss_tmo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) 	.get_host_port_state = zfcp_scsi_get_host_port_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) 	.terminate_rport_io = zfcp_scsi_terminate_rport_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) 	.show_host_port_state = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) 	.show_host_active_fc4s = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) 	.bsg_request = zfcp_fc_exec_bsg_job,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) 	.bsg_timeout = zfcp_fc_timeout_bsg_job,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) 	/* no functions registered for following dynamic attributes but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) 	   directly set by LLDD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) 	.show_host_port_type = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) 	.show_host_symbolic_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) 	.show_host_speed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) 	.show_host_port_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) 	.show_host_fabric_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) 	.dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) };