18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * zfcp device driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Interface to Linux SCSI midlayer. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2002, 2020 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define KMSG_COMPONENT "zfcp" 118c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/module.h> 148c2ecf20Sopenharmony_ci#include <linux/types.h> 158c2ecf20Sopenharmony_ci#include <linux/slab.h> 168c2ecf20Sopenharmony_ci#include <scsi/fc/fc_fcp.h> 178c2ecf20Sopenharmony_ci#include <scsi/scsi_eh.h> 188c2ecf20Sopenharmony_ci#include <linux/atomic.h> 198c2ecf20Sopenharmony_ci#include "zfcp_ext.h" 208c2ecf20Sopenharmony_ci#include "zfcp_dbf.h" 218c2ecf20Sopenharmony_ci#include "zfcp_fc.h" 228c2ecf20Sopenharmony_ci#include "zfcp_reqlist.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic unsigned int default_depth = 32; 258c2ecf20Sopenharmony_cimodule_param_named(queue_depth, default_depth, uint, 0600); 268c2ecf20Sopenharmony_ciMODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices"); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic bool enable_dif; 298c2ecf20Sopenharmony_cimodule_param_named(dif, enable_dif, bool, 0400); 308c2ecf20Sopenharmony_ciMODULE_PARM_DESC(dif, "Enable DIF data integrity support (default off)"); 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cibool zfcp_experimental_dix; 338c2ecf20Sopenharmony_cimodule_param_named(dix, zfcp_experimental_dix, bool, 0400); 348c2ecf20Sopenharmony_ciMODULE_PARM_DESC(dix, "Enable experimental DIX (data integrity extension) support which implies DIF support (default off)"); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic bool allow_lun_scan = true; 378c2ecf20Sopenharmony_cimodule_param(allow_lun_scan, bool, 0600); 388c2ecf20Sopenharmony_ciMODULE_PARM_DESC(allow_lun_scan, "For NPIV, scan and attach all storage LUNs"); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic void zfcp_scsi_slave_destroy(struct scsi_device *sdev) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci /* if previous slave_alloc returned early, there is nothing to do */ 458c2ecf20Sopenharmony_ci if (!zfcp_sdev->port) 468c2ecf20Sopenharmony_ci return; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci zfcp_erp_lun_shutdown_wait(sdev, "scssd_1"); 498c2ecf20Sopenharmony_ci put_device(&zfcp_sdev->port->dev); 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic int zfcp_scsi_slave_configure(struct scsi_device *sdp) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci if (sdp->tagged_supported) 558c2ecf20Sopenharmony_ci scsi_change_queue_depth(sdp, default_depth); 568c2ecf20Sopenharmony_ci return 0; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci set_host_byte(scpnt, result); 628c2ecf20Sopenharmony_ci zfcp_dbf_scsi_fail_send(scpnt); 638c2ecf20Sopenharmony_ci scpnt->scsi_done(scpnt); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic 678c2ecf20Sopenharmony_ciint zfcp_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scpnt) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); 708c2ecf20Sopenharmony_ci struct fc_rport *rport = starget_to_rport(scsi_target(scpnt->device)); 718c2ecf20Sopenharmony_ci int status, scsi_result, ret; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci /* reset the status for this request */ 748c2ecf20Sopenharmony_ci scpnt->result = 0; 758c2ecf20Sopenharmony_ci scpnt->host_scribble = NULL; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci scsi_result = fc_remote_port_chkready(rport); 788c2ecf20Sopenharmony_ci if (unlikely(scsi_result)) { 798c2ecf20Sopenharmony_ci scpnt->result = scsi_result; 808c2ecf20Sopenharmony_ci zfcp_dbf_scsi_fail_send(scpnt); 818c2ecf20Sopenharmony_ci scpnt->scsi_done(scpnt); 828c2ecf20Sopenharmony_ci return 0; 838c2ecf20Sopenharmony_ci } 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci status = atomic_read(&zfcp_sdev->status); 868c2ecf20Sopenharmony_ci if (unlikely(status & ZFCP_STATUS_COMMON_ERP_FAILED) && 878c2ecf20Sopenharmony_ci !(atomic_read(&zfcp_sdev->port->status) & 888c2ecf20Sopenharmony_ci ZFCP_STATUS_COMMON_ERP_FAILED)) { 898c2ecf20Sopenharmony_ci /* only LUN access denied, but port is good 908c2ecf20Sopenharmony_ci * not covered by FC transport, have to fail here */ 918c2ecf20Sopenharmony_ci zfcp_scsi_command_fail(scpnt, DID_ERROR); 928c2ecf20Sopenharmony_ci return 0; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci if (unlikely(!(status & ZFCP_STATUS_COMMON_UNBLOCKED))) { 968c2ecf20Sopenharmony_ci /* This could be 978c2ecf20Sopenharmony_ci * call to rport_delete pending: mimic retry from 988c2ecf20Sopenharmony_ci * fc_remote_port_chkready until rport is BLOCKED 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_ci zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY); 1018c2ecf20Sopenharmony_ci return 0; 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci ret = zfcp_fsf_fcp_cmnd(scpnt); 1058c2ecf20Sopenharmony_ci if (unlikely(ret == -EBUSY)) 1068c2ecf20Sopenharmony_ci return SCSI_MLQUEUE_DEVICE_BUSY; 1078c2ecf20Sopenharmony_ci else if (unlikely(ret < 0)) 1088c2ecf20Sopenharmony_ci return SCSI_MLQUEUE_HOST_BUSY; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci return ret; 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic int zfcp_scsi_slave_alloc(struct scsi_device *sdev) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); 1168c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = 1178c2ecf20Sopenharmony_ci (struct zfcp_adapter *) sdev->host->hostdata[0]; 1188c2ecf20Sopenharmony_ci struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); 1198c2ecf20Sopenharmony_ci struct zfcp_port *port; 1208c2ecf20Sopenharmony_ci struct zfcp_unit *unit; 1218c2ecf20Sopenharmony_ci int npiv = adapter->connection_features & FSF_FEATURE_NPIV_MODE; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci zfcp_sdev->erp_action.adapter = adapter; 1248c2ecf20Sopenharmony_ci zfcp_sdev->erp_action.sdev = sdev; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci port = zfcp_get_port_by_wwpn(adapter, rport->port_name); 1278c2ecf20Sopenharmony_ci if (!port) 1288c2ecf20Sopenharmony_ci return -ENXIO; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci zfcp_sdev->erp_action.port = port; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci mutex_lock(&zfcp_sysfs_port_units_mutex); 1338c2ecf20Sopenharmony_ci if (zfcp_sysfs_port_is_removing(port)) { 1348c2ecf20Sopenharmony_ci /* port is already gone */ 1358c2ecf20Sopenharmony_ci mutex_unlock(&zfcp_sysfs_port_units_mutex); 1368c2ecf20Sopenharmony_ci put_device(&port->dev); /* undo zfcp_get_port_by_wwpn() */ 1378c2ecf20Sopenharmony_ci return -ENXIO; 1388c2ecf20Sopenharmony_ci } 1398c2ecf20Sopenharmony_ci mutex_unlock(&zfcp_sysfs_port_units_mutex); 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev)); 1428c2ecf20Sopenharmony_ci if (unit) 1438c2ecf20Sopenharmony_ci put_device(&unit->dev); 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci if (!unit && !(allow_lun_scan && npiv)) { 1468c2ecf20Sopenharmony_ci put_device(&port->dev); 1478c2ecf20Sopenharmony_ci return -ENXIO; 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci zfcp_sdev->port = port; 1518c2ecf20Sopenharmony_ci zfcp_sdev->latencies.write.channel.min = 0xFFFFFFFF; 1528c2ecf20Sopenharmony_ci zfcp_sdev->latencies.write.fabric.min = 0xFFFFFFFF; 1538c2ecf20Sopenharmony_ci zfcp_sdev->latencies.read.channel.min = 0xFFFFFFFF; 1548c2ecf20Sopenharmony_ci zfcp_sdev->latencies.read.fabric.min = 0xFFFFFFFF; 1558c2ecf20Sopenharmony_ci zfcp_sdev->latencies.cmd.channel.min = 0xFFFFFFFF; 1568c2ecf20Sopenharmony_ci zfcp_sdev->latencies.cmd.fabric.min = 0xFFFFFFFF; 1578c2ecf20Sopenharmony_ci spin_lock_init(&zfcp_sdev->latencies.lock); 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING); 1608c2ecf20Sopenharmony_ci zfcp_erp_lun_reopen(sdev, 0, "scsla_1"); 1618c2ecf20Sopenharmony_ci zfcp_erp_wait(port->adapter); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci return 0; 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistatic int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci struct Scsi_Host *scsi_host = scpnt->device->host; 1698c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = 1708c2ecf20Sopenharmony_ci (struct zfcp_adapter *) scsi_host->hostdata[0]; 1718c2ecf20Sopenharmony_ci struct zfcp_fsf_req *old_req, *abrt_req; 1728c2ecf20Sopenharmony_ci unsigned long flags; 1738c2ecf20Sopenharmony_ci unsigned long old_reqid = (unsigned long) scpnt->host_scribble; 1748c2ecf20Sopenharmony_ci int retval = SUCCESS, ret; 1758c2ecf20Sopenharmony_ci int retry = 3; 1768c2ecf20Sopenharmony_ci char *dbf_tag; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci /* avoid race condition between late normal completion and abort */ 1798c2ecf20Sopenharmony_ci write_lock_irqsave(&adapter->abort_lock, flags); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci old_req = zfcp_reqlist_find(adapter->req_list, old_reqid); 1828c2ecf20Sopenharmony_ci if (!old_req) { 1838c2ecf20Sopenharmony_ci write_unlock_irqrestore(&adapter->abort_lock, flags); 1848c2ecf20Sopenharmony_ci zfcp_dbf_scsi_abort("abrt_or", scpnt, NULL); 1858c2ecf20Sopenharmony_ci return FAILED; /* completion could be in progress */ 1868c2ecf20Sopenharmony_ci } 1878c2ecf20Sopenharmony_ci old_req->data = NULL; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci /* don't access old fsf_req after releasing the abort_lock */ 1908c2ecf20Sopenharmony_ci write_unlock_irqrestore(&adapter->abort_lock, flags); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci while (retry--) { 1938c2ecf20Sopenharmony_ci abrt_req = zfcp_fsf_abort_fcp_cmnd(scpnt); 1948c2ecf20Sopenharmony_ci if (abrt_req) 1958c2ecf20Sopenharmony_ci break; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci zfcp_dbf_scsi_abort("abrt_wt", scpnt, NULL); 1988c2ecf20Sopenharmony_ci zfcp_erp_wait(adapter); 1998c2ecf20Sopenharmony_ci ret = fc_block_scsi_eh(scpnt); 2008c2ecf20Sopenharmony_ci if (ret) { 2018c2ecf20Sopenharmony_ci zfcp_dbf_scsi_abort("abrt_bl", scpnt, NULL); 2028c2ecf20Sopenharmony_ci return ret; 2038c2ecf20Sopenharmony_ci } 2048c2ecf20Sopenharmony_ci if (!(atomic_read(&adapter->status) & 2058c2ecf20Sopenharmony_ci ZFCP_STATUS_COMMON_RUNNING)) { 2068c2ecf20Sopenharmony_ci zfcp_dbf_scsi_abort("abrt_ru", scpnt, NULL); 2078c2ecf20Sopenharmony_ci return SUCCESS; 2088c2ecf20Sopenharmony_ci } 2098c2ecf20Sopenharmony_ci } 2108c2ecf20Sopenharmony_ci if (!abrt_req) { 2118c2ecf20Sopenharmony_ci zfcp_dbf_scsi_abort("abrt_ar", scpnt, NULL); 2128c2ecf20Sopenharmony_ci return FAILED; 2138c2ecf20Sopenharmony_ci } 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci wait_for_completion(&abrt_req->completion); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) 2188c2ecf20Sopenharmony_ci dbf_tag = "abrt_ok"; 2198c2ecf20Sopenharmony_ci else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) 2208c2ecf20Sopenharmony_ci dbf_tag = "abrt_nn"; 2218c2ecf20Sopenharmony_ci else { 2228c2ecf20Sopenharmony_ci dbf_tag = "abrt_fa"; 2238c2ecf20Sopenharmony_ci retval = FAILED; 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci zfcp_dbf_scsi_abort(dbf_tag, scpnt, abrt_req); 2268c2ecf20Sopenharmony_ci zfcp_fsf_req_free(abrt_req); 2278c2ecf20Sopenharmony_ci return retval; 2288c2ecf20Sopenharmony_ci} 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistruct zfcp_scsi_req_filter { 2318c2ecf20Sopenharmony_ci u8 tmf_scope; 2328c2ecf20Sopenharmony_ci u32 lun_handle; 2338c2ecf20Sopenharmony_ci u32 port_handle; 2348c2ecf20Sopenharmony_ci}; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_cistatic void zfcp_scsi_forget_cmnd(struct zfcp_fsf_req *old_req, void *data) 2378c2ecf20Sopenharmony_ci{ 2388c2ecf20Sopenharmony_ci struct zfcp_scsi_req_filter *filter = 2398c2ecf20Sopenharmony_ci (struct zfcp_scsi_req_filter *)data; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci /* already aborted - prevent side-effects - or not a SCSI command */ 2428c2ecf20Sopenharmony_ci if (old_req->data == NULL || 2438c2ecf20Sopenharmony_ci zfcp_fsf_req_is_status_read_buffer(old_req) || 2448c2ecf20Sopenharmony_ci old_req->qtcb->header.fsf_command != FSF_QTCB_FCP_CMND) 2458c2ecf20Sopenharmony_ci return; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci /* (tmf_scope == FCP_TMF_TGT_RESET || tmf_scope == FCP_TMF_LUN_RESET) */ 2488c2ecf20Sopenharmony_ci if (old_req->qtcb->header.port_handle != filter->port_handle) 2498c2ecf20Sopenharmony_ci return; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci if (filter->tmf_scope == FCP_TMF_LUN_RESET && 2528c2ecf20Sopenharmony_ci old_req->qtcb->header.lun_handle != filter->lun_handle) 2538c2ecf20Sopenharmony_ci return; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci zfcp_dbf_scsi_nullcmnd((struct scsi_cmnd *)old_req->data, old_req); 2568c2ecf20Sopenharmony_ci old_req->data = NULL; 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic void zfcp_scsi_forget_cmnds(struct zfcp_scsi_dev *zsdev, u8 tm_flags) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = zsdev->port->adapter; 2628c2ecf20Sopenharmony_ci struct zfcp_scsi_req_filter filter = { 2638c2ecf20Sopenharmony_ci .tmf_scope = FCP_TMF_TGT_RESET, 2648c2ecf20Sopenharmony_ci .port_handle = zsdev->port->handle, 2658c2ecf20Sopenharmony_ci }; 2668c2ecf20Sopenharmony_ci unsigned long flags; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci if (tm_flags == FCP_TMF_LUN_RESET) { 2698c2ecf20Sopenharmony_ci filter.tmf_scope = FCP_TMF_LUN_RESET; 2708c2ecf20Sopenharmony_ci filter.lun_handle = zsdev->lun_handle; 2718c2ecf20Sopenharmony_ci } 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci /* 2748c2ecf20Sopenharmony_ci * abort_lock secures against other processings - in the abort-function 2758c2ecf20Sopenharmony_ci * and normal cmnd-handler - of (struct zfcp_fsf_req *)->data 2768c2ecf20Sopenharmony_ci */ 2778c2ecf20Sopenharmony_ci write_lock_irqsave(&adapter->abort_lock, flags); 2788c2ecf20Sopenharmony_ci zfcp_reqlist_apply_for_all(adapter->req_list, zfcp_scsi_forget_cmnd, 2798c2ecf20Sopenharmony_ci &filter); 2808c2ecf20Sopenharmony_ci write_unlock_irqrestore(&adapter->abort_lock, flags); 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci/** 2848c2ecf20Sopenharmony_ci * zfcp_scsi_task_mgmt_function() - Send a task management function (sync). 2858c2ecf20Sopenharmony_ci * @sdev: Pointer to SCSI device to send the task management command to. 2868c2ecf20Sopenharmony_ci * @tm_flags: Task management flags, 2878c2ecf20Sopenharmony_ci * here we only handle %FCP_TMF_TGT_RESET or %FCP_TMF_LUN_RESET. 2888c2ecf20Sopenharmony_ci */ 2898c2ecf20Sopenharmony_cistatic int zfcp_scsi_task_mgmt_function(struct scsi_device *sdev, u8 tm_flags) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); 2928c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; 2938c2ecf20Sopenharmony_ci struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); 2948c2ecf20Sopenharmony_ci struct zfcp_fsf_req *fsf_req = NULL; 2958c2ecf20Sopenharmony_ci int retval = SUCCESS, ret; 2968c2ecf20Sopenharmony_ci int retry = 3; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci while (retry--) { 2998c2ecf20Sopenharmony_ci fsf_req = zfcp_fsf_fcp_task_mgmt(sdev, tm_flags); 3008c2ecf20Sopenharmony_ci if (fsf_req) 3018c2ecf20Sopenharmony_ci break; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci zfcp_dbf_scsi_devreset("wait", sdev, tm_flags, NULL); 3048c2ecf20Sopenharmony_ci zfcp_erp_wait(adapter); 3058c2ecf20Sopenharmony_ci ret = fc_block_rport(rport); 3068c2ecf20Sopenharmony_ci if (ret) { 3078c2ecf20Sopenharmony_ci zfcp_dbf_scsi_devreset("fiof", sdev, tm_flags, NULL); 3088c2ecf20Sopenharmony_ci return ret; 3098c2ecf20Sopenharmony_ci } 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci if (!(atomic_read(&adapter->status) & 3128c2ecf20Sopenharmony_ci ZFCP_STATUS_COMMON_RUNNING)) { 3138c2ecf20Sopenharmony_ci zfcp_dbf_scsi_devreset("nres", sdev, tm_flags, NULL); 3148c2ecf20Sopenharmony_ci return SUCCESS; 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci } 3178c2ecf20Sopenharmony_ci if (!fsf_req) { 3188c2ecf20Sopenharmony_ci zfcp_dbf_scsi_devreset("reqf", sdev, tm_flags, NULL); 3198c2ecf20Sopenharmony_ci return FAILED; 3208c2ecf20Sopenharmony_ci } 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci wait_for_completion(&fsf_req->completion); 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) { 3258c2ecf20Sopenharmony_ci zfcp_dbf_scsi_devreset("fail", sdev, tm_flags, fsf_req); 3268c2ecf20Sopenharmony_ci retval = FAILED; 3278c2ecf20Sopenharmony_ci } else { 3288c2ecf20Sopenharmony_ci zfcp_dbf_scsi_devreset("okay", sdev, tm_flags, fsf_req); 3298c2ecf20Sopenharmony_ci zfcp_scsi_forget_cmnds(zfcp_sdev, tm_flags); 3308c2ecf20Sopenharmony_ci } 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci zfcp_fsf_req_free(fsf_req); 3338c2ecf20Sopenharmony_ci return retval; 3348c2ecf20Sopenharmony_ci} 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cistatic int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt) 3378c2ecf20Sopenharmony_ci{ 3388c2ecf20Sopenharmony_ci struct scsi_device *sdev = scpnt->device; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci return zfcp_scsi_task_mgmt_function(sdev, FCP_TMF_LUN_RESET); 3418c2ecf20Sopenharmony_ci} 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_cistatic int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci struct scsi_target *starget = scsi_target(scpnt->device); 3468c2ecf20Sopenharmony_ci struct fc_rport *rport = starget_to_rport(starget); 3478c2ecf20Sopenharmony_ci struct Scsi_Host *shost = rport_to_shost(rport); 3488c2ecf20Sopenharmony_ci struct scsi_device *sdev = NULL, *tmp_sdev; 3498c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = 3508c2ecf20Sopenharmony_ci (struct zfcp_adapter *)shost->hostdata[0]; 3518c2ecf20Sopenharmony_ci int ret; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci shost_for_each_device(tmp_sdev, shost) { 3548c2ecf20Sopenharmony_ci if (tmp_sdev->id == starget->id) { 3558c2ecf20Sopenharmony_ci sdev = tmp_sdev; 3568c2ecf20Sopenharmony_ci break; 3578c2ecf20Sopenharmony_ci } 3588c2ecf20Sopenharmony_ci } 3598c2ecf20Sopenharmony_ci if (!sdev) { 3608c2ecf20Sopenharmony_ci ret = FAILED; 3618c2ecf20Sopenharmony_ci zfcp_dbf_scsi_eh("tr_nosd", adapter, starget->id, ret); 3628c2ecf20Sopenharmony_ci return ret; 3638c2ecf20Sopenharmony_ci } 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci ret = zfcp_scsi_task_mgmt_function(sdev, FCP_TMF_TGT_RESET); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci /* release reference from above shost_for_each_device */ 3688c2ecf20Sopenharmony_ci if (sdev) 3698c2ecf20Sopenharmony_ci scsi_device_put(tmp_sdev); 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci return ret; 3728c2ecf20Sopenharmony_ci} 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_cistatic int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) 3758c2ecf20Sopenharmony_ci{ 3768c2ecf20Sopenharmony_ci struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); 3778c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; 3788c2ecf20Sopenharmony_ci int ret = SUCCESS, fc_ret; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) { 3818c2ecf20Sopenharmony_ci zfcp_erp_port_forced_reopen_all(adapter, 0, "schrh_p"); 3828c2ecf20Sopenharmony_ci zfcp_erp_wait(adapter); 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci zfcp_erp_adapter_reopen(adapter, 0, "schrh_1"); 3858c2ecf20Sopenharmony_ci zfcp_erp_wait(adapter); 3868c2ecf20Sopenharmony_ci fc_ret = fc_block_scsi_eh(scpnt); 3878c2ecf20Sopenharmony_ci if (fc_ret) 3888c2ecf20Sopenharmony_ci ret = fc_ret; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci zfcp_dbf_scsi_eh("schrh_r", adapter, ~0, ret); 3918c2ecf20Sopenharmony_ci return ret; 3928c2ecf20Sopenharmony_ci} 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci/** 3958c2ecf20Sopenharmony_ci * zfcp_scsi_sysfs_host_reset() - Support scsi_host sysfs attribute host_reset. 3968c2ecf20Sopenharmony_ci * @shost: Pointer to Scsi_Host to perform action on. 3978c2ecf20Sopenharmony_ci * @reset_type: We support %SCSI_ADAPTER_RESET but not %SCSI_FIRMWARE_RESET. 3988c2ecf20Sopenharmony_ci * 3998c2ecf20Sopenharmony_ci * Return: 0 on %SCSI_ADAPTER_RESET, -%EOPNOTSUPP otherwise. 4008c2ecf20Sopenharmony_ci * 4018c2ecf20Sopenharmony_ci * This is similar to zfcp_sysfs_adapter_failed_store(). 4028c2ecf20Sopenharmony_ci */ 4038c2ecf20Sopenharmony_cistatic int zfcp_scsi_sysfs_host_reset(struct Scsi_Host *shost, int reset_type) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = 4068c2ecf20Sopenharmony_ci (struct zfcp_adapter *)shost->hostdata[0]; 4078c2ecf20Sopenharmony_ci int ret = 0; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci if (reset_type != SCSI_ADAPTER_RESET) { 4108c2ecf20Sopenharmony_ci ret = -EOPNOTSUPP; 4118c2ecf20Sopenharmony_ci zfcp_dbf_scsi_eh("scshr_n", adapter, ~0, ret); 4128c2ecf20Sopenharmony_ci return ret; 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci zfcp_erp_adapter_reset_sync(adapter, "scshr_y"); 4168c2ecf20Sopenharmony_ci return ret; 4178c2ecf20Sopenharmony_ci} 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_cistruct scsi_transport_template *zfcp_scsi_transport_template; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_cistatic struct scsi_host_template zfcp_scsi_host_template = { 4228c2ecf20Sopenharmony_ci .module = THIS_MODULE, 4238c2ecf20Sopenharmony_ci .name = "zfcp", 4248c2ecf20Sopenharmony_ci .queuecommand = zfcp_scsi_queuecommand, 4258c2ecf20Sopenharmony_ci .eh_timed_out = fc_eh_timed_out, 4268c2ecf20Sopenharmony_ci .eh_abort_handler = zfcp_scsi_eh_abort_handler, 4278c2ecf20Sopenharmony_ci .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler, 4288c2ecf20Sopenharmony_ci .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler, 4298c2ecf20Sopenharmony_ci .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler, 4308c2ecf20Sopenharmony_ci .slave_alloc = zfcp_scsi_slave_alloc, 4318c2ecf20Sopenharmony_ci .slave_configure = zfcp_scsi_slave_configure, 4328c2ecf20Sopenharmony_ci .slave_destroy = zfcp_scsi_slave_destroy, 4338c2ecf20Sopenharmony_ci .change_queue_depth = scsi_change_queue_depth, 4348c2ecf20Sopenharmony_ci .host_reset = zfcp_scsi_sysfs_host_reset, 4358c2ecf20Sopenharmony_ci .proc_name = "zfcp", 4368c2ecf20Sopenharmony_ci .can_queue = 4096, 4378c2ecf20Sopenharmony_ci .this_id = -1, 4388c2ecf20Sopenharmony_ci .sg_tablesize = (((QDIO_MAX_ELEMENTS_PER_BUFFER - 1) 4398c2ecf20Sopenharmony_ci * ZFCP_QDIO_MAX_SBALS_PER_REQ) - 2), 4408c2ecf20Sopenharmony_ci /* GCD, adjusted later */ 4418c2ecf20Sopenharmony_ci .max_sectors = (((QDIO_MAX_ELEMENTS_PER_BUFFER - 1) 4428c2ecf20Sopenharmony_ci * ZFCP_QDIO_MAX_SBALS_PER_REQ) - 2) * 8, 4438c2ecf20Sopenharmony_ci /* GCD, adjusted later */ 4448c2ecf20Sopenharmony_ci /* report size limit per scatter-gather segment */ 4458c2ecf20Sopenharmony_ci .max_segment_size = ZFCP_QDIO_SBALE_LEN, 4468c2ecf20Sopenharmony_ci .dma_boundary = ZFCP_QDIO_SBALE_LEN - 1, 4478c2ecf20Sopenharmony_ci .shost_attrs = zfcp_sysfs_shost_attrs, 4488c2ecf20Sopenharmony_ci .sdev_attrs = zfcp_sysfs_sdev_attrs, 4498c2ecf20Sopenharmony_ci .track_queue_depth = 1, 4508c2ecf20Sopenharmony_ci .supported_mode = MODE_INITIATOR, 4518c2ecf20Sopenharmony_ci}; 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci/** 4548c2ecf20Sopenharmony_ci * zfcp_scsi_adapter_register() - Allocate and register SCSI and FC host with 4558c2ecf20Sopenharmony_ci * SCSI midlayer 4568c2ecf20Sopenharmony_ci * @adapter: The zfcp adapter to register with the SCSI midlayer 4578c2ecf20Sopenharmony_ci * 4588c2ecf20Sopenharmony_ci * Allocates the SCSI host object for the given adapter, sets basic properties 4598c2ecf20Sopenharmony_ci * (such as the transport template, QDIO limits, ...), and registers it with 4608c2ecf20Sopenharmony_ci * the midlayer. 4618c2ecf20Sopenharmony_ci * 4628c2ecf20Sopenharmony_ci * During registration with the midlayer the corresponding FC host object for 4638c2ecf20Sopenharmony_ci * the referenced transport class is also implicitely allocated. 4648c2ecf20Sopenharmony_ci * 4658c2ecf20Sopenharmony_ci * Upon success adapter->scsi_host is set, and upon failure it remains NULL. If 4668c2ecf20Sopenharmony_ci * adapter->scsi_host is already set, nothing is done. 4678c2ecf20Sopenharmony_ci * 4688c2ecf20Sopenharmony_ci * Return: 4698c2ecf20Sopenharmony_ci * * 0 - Allocation and registration was successful 4708c2ecf20Sopenharmony_ci * * -EEXIST - SCSI and FC host did already exist, nothing was done, nothing 4718c2ecf20Sopenharmony_ci * was changed 4728c2ecf20Sopenharmony_ci * * -EIO - Allocation or registration failed 4738c2ecf20Sopenharmony_ci */ 4748c2ecf20Sopenharmony_ciint zfcp_scsi_adapter_register(struct zfcp_adapter *adapter) 4758c2ecf20Sopenharmony_ci{ 4768c2ecf20Sopenharmony_ci struct ccw_dev_id dev_id; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci if (adapter->scsi_host) 4798c2ecf20Sopenharmony_ci return -EEXIST; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci ccw_device_get_id(adapter->ccw_device, &dev_id); 4828c2ecf20Sopenharmony_ci /* register adapter as SCSI host with mid layer of SCSI stack */ 4838c2ecf20Sopenharmony_ci adapter->scsi_host = scsi_host_alloc(&zfcp_scsi_host_template, 4848c2ecf20Sopenharmony_ci sizeof (struct zfcp_adapter *)); 4858c2ecf20Sopenharmony_ci if (!adapter->scsi_host) 4868c2ecf20Sopenharmony_ci goto err_out; 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci /* tell the SCSI stack some characteristics of this adapter */ 4898c2ecf20Sopenharmony_ci adapter->scsi_host->max_id = 511; 4908c2ecf20Sopenharmony_ci adapter->scsi_host->max_lun = 0xFFFFFFFF; 4918c2ecf20Sopenharmony_ci adapter->scsi_host->max_channel = 0; 4928c2ecf20Sopenharmony_ci adapter->scsi_host->unique_id = dev_id.devno; 4938c2ecf20Sopenharmony_ci adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */ 4948c2ecf20Sopenharmony_ci adapter->scsi_host->transportt = zfcp_scsi_transport_template; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci /* make all basic properties known at registration time */ 4978c2ecf20Sopenharmony_ci zfcp_qdio_shost_update(adapter, adapter->qdio); 4988c2ecf20Sopenharmony_ci zfcp_scsi_set_prot(adapter); 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci adapter->scsi_host->hostdata[0] = (unsigned long) adapter; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) { 5038c2ecf20Sopenharmony_ci scsi_host_put(adapter->scsi_host); 5048c2ecf20Sopenharmony_ci goto err_out; 5058c2ecf20Sopenharmony_ci } 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci return 0; 5088c2ecf20Sopenharmony_cierr_out: 5098c2ecf20Sopenharmony_ci adapter->scsi_host = NULL; 5108c2ecf20Sopenharmony_ci dev_err(&adapter->ccw_device->dev, 5118c2ecf20Sopenharmony_ci "Registering the FCP device with the SCSI stack failed\n"); 5128c2ecf20Sopenharmony_ci return -EIO; 5138c2ecf20Sopenharmony_ci} 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci/** 5168c2ecf20Sopenharmony_ci * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer 5178c2ecf20Sopenharmony_ci * @adapter: The zfcp adapter to unregister. 5188c2ecf20Sopenharmony_ci */ 5198c2ecf20Sopenharmony_civoid zfcp_scsi_adapter_unregister(struct zfcp_adapter *adapter) 5208c2ecf20Sopenharmony_ci{ 5218c2ecf20Sopenharmony_ci struct Scsi_Host *shost; 5228c2ecf20Sopenharmony_ci struct zfcp_port *port; 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci shost = adapter->scsi_host; 5258c2ecf20Sopenharmony_ci if (!shost) 5268c2ecf20Sopenharmony_ci return; 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci read_lock_irq(&adapter->port_list_lock); 5298c2ecf20Sopenharmony_ci list_for_each_entry(port, &adapter->port_list, list) 5308c2ecf20Sopenharmony_ci port->rport = NULL; 5318c2ecf20Sopenharmony_ci read_unlock_irq(&adapter->port_list_lock); 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci fc_remove_host(shost); 5348c2ecf20Sopenharmony_ci scsi_remove_host(shost); 5358c2ecf20Sopenharmony_ci scsi_host_put(shost); 5368c2ecf20Sopenharmony_ci adapter->scsi_host = NULL; 5378c2ecf20Sopenharmony_ci} 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_cistatic struct fc_host_statistics* 5408c2ecf20Sopenharmony_cizfcp_scsi_init_fc_host_stats(struct zfcp_adapter *adapter) 5418c2ecf20Sopenharmony_ci{ 5428c2ecf20Sopenharmony_ci struct fc_host_statistics *fc_stats; 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci if (!adapter->fc_stats) { 5458c2ecf20Sopenharmony_ci fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL); 5468c2ecf20Sopenharmony_ci if (!fc_stats) 5478c2ecf20Sopenharmony_ci return NULL; 5488c2ecf20Sopenharmony_ci adapter->fc_stats = fc_stats; /* freed in adapter_release */ 5498c2ecf20Sopenharmony_ci } 5508c2ecf20Sopenharmony_ci memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats)); 5518c2ecf20Sopenharmony_ci return adapter->fc_stats; 5528c2ecf20Sopenharmony_ci} 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_cistatic void zfcp_scsi_adjust_fc_host_stats(struct fc_host_statistics *fc_stats, 5558c2ecf20Sopenharmony_ci struct fsf_qtcb_bottom_port *data, 5568c2ecf20Sopenharmony_ci struct fsf_qtcb_bottom_port *old) 5578c2ecf20Sopenharmony_ci{ 5588c2ecf20Sopenharmony_ci fc_stats->seconds_since_last_reset = 5598c2ecf20Sopenharmony_ci data->seconds_since_last_reset - old->seconds_since_last_reset; 5608c2ecf20Sopenharmony_ci fc_stats->tx_frames = data->tx_frames - old->tx_frames; 5618c2ecf20Sopenharmony_ci fc_stats->tx_words = data->tx_words - old->tx_words; 5628c2ecf20Sopenharmony_ci fc_stats->rx_frames = data->rx_frames - old->rx_frames; 5638c2ecf20Sopenharmony_ci fc_stats->rx_words = data->rx_words - old->rx_words; 5648c2ecf20Sopenharmony_ci fc_stats->lip_count = data->lip - old->lip; 5658c2ecf20Sopenharmony_ci fc_stats->nos_count = data->nos - old->nos; 5668c2ecf20Sopenharmony_ci fc_stats->error_frames = data->error_frames - old->error_frames; 5678c2ecf20Sopenharmony_ci fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames; 5688c2ecf20Sopenharmony_ci fc_stats->link_failure_count = data->link_failure - old->link_failure; 5698c2ecf20Sopenharmony_ci fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync; 5708c2ecf20Sopenharmony_ci fc_stats->loss_of_signal_count = 5718c2ecf20Sopenharmony_ci data->loss_of_signal - old->loss_of_signal; 5728c2ecf20Sopenharmony_ci fc_stats->prim_seq_protocol_err_count = 5738c2ecf20Sopenharmony_ci data->psp_error_counts - old->psp_error_counts; 5748c2ecf20Sopenharmony_ci fc_stats->invalid_tx_word_count = 5758c2ecf20Sopenharmony_ci data->invalid_tx_words - old->invalid_tx_words; 5768c2ecf20Sopenharmony_ci fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs; 5778c2ecf20Sopenharmony_ci fc_stats->fcp_input_requests = 5788c2ecf20Sopenharmony_ci data->input_requests - old->input_requests; 5798c2ecf20Sopenharmony_ci fc_stats->fcp_output_requests = 5808c2ecf20Sopenharmony_ci data->output_requests - old->output_requests; 5818c2ecf20Sopenharmony_ci fc_stats->fcp_control_requests = 5828c2ecf20Sopenharmony_ci data->control_requests - old->control_requests; 5838c2ecf20Sopenharmony_ci fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb; 5848c2ecf20Sopenharmony_ci fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb; 5858c2ecf20Sopenharmony_ci} 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_cistatic void zfcp_scsi_set_fc_host_stats(struct fc_host_statistics *fc_stats, 5888c2ecf20Sopenharmony_ci struct fsf_qtcb_bottom_port *data) 5898c2ecf20Sopenharmony_ci{ 5908c2ecf20Sopenharmony_ci fc_stats->seconds_since_last_reset = data->seconds_since_last_reset; 5918c2ecf20Sopenharmony_ci fc_stats->tx_frames = data->tx_frames; 5928c2ecf20Sopenharmony_ci fc_stats->tx_words = data->tx_words; 5938c2ecf20Sopenharmony_ci fc_stats->rx_frames = data->rx_frames; 5948c2ecf20Sopenharmony_ci fc_stats->rx_words = data->rx_words; 5958c2ecf20Sopenharmony_ci fc_stats->lip_count = data->lip; 5968c2ecf20Sopenharmony_ci fc_stats->nos_count = data->nos; 5978c2ecf20Sopenharmony_ci fc_stats->error_frames = data->error_frames; 5988c2ecf20Sopenharmony_ci fc_stats->dumped_frames = data->dumped_frames; 5998c2ecf20Sopenharmony_ci fc_stats->link_failure_count = data->link_failure; 6008c2ecf20Sopenharmony_ci fc_stats->loss_of_sync_count = data->loss_of_sync; 6018c2ecf20Sopenharmony_ci fc_stats->loss_of_signal_count = data->loss_of_signal; 6028c2ecf20Sopenharmony_ci fc_stats->prim_seq_protocol_err_count = data->psp_error_counts; 6038c2ecf20Sopenharmony_ci fc_stats->invalid_tx_word_count = data->invalid_tx_words; 6048c2ecf20Sopenharmony_ci fc_stats->invalid_crc_count = data->invalid_crcs; 6058c2ecf20Sopenharmony_ci fc_stats->fcp_input_requests = data->input_requests; 6068c2ecf20Sopenharmony_ci fc_stats->fcp_output_requests = data->output_requests; 6078c2ecf20Sopenharmony_ci fc_stats->fcp_control_requests = data->control_requests; 6088c2ecf20Sopenharmony_ci fc_stats->fcp_input_megabytes = data->input_mb; 6098c2ecf20Sopenharmony_ci fc_stats->fcp_output_megabytes = data->output_mb; 6108c2ecf20Sopenharmony_ci} 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_cistatic struct fc_host_statistics * 6138c2ecf20Sopenharmony_cizfcp_scsi_get_fc_host_stats(struct Scsi_Host *host) 6148c2ecf20Sopenharmony_ci{ 6158c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter; 6168c2ecf20Sopenharmony_ci struct fc_host_statistics *fc_stats; 6178c2ecf20Sopenharmony_ci struct fsf_qtcb_bottom_port *data; 6188c2ecf20Sopenharmony_ci int ret; 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci adapter = (struct zfcp_adapter *)host->hostdata[0]; 6218c2ecf20Sopenharmony_ci fc_stats = zfcp_scsi_init_fc_host_stats(adapter); 6228c2ecf20Sopenharmony_ci if (!fc_stats) 6238c2ecf20Sopenharmony_ci return NULL; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci data = kzalloc(sizeof(*data), GFP_KERNEL); 6268c2ecf20Sopenharmony_ci if (!data) 6278c2ecf20Sopenharmony_ci return NULL; 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data); 6308c2ecf20Sopenharmony_ci if (ret != 0 && ret != -EAGAIN) { 6318c2ecf20Sopenharmony_ci kfree(data); 6328c2ecf20Sopenharmony_ci return NULL; 6338c2ecf20Sopenharmony_ci } 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci if (adapter->stats_reset && 6368c2ecf20Sopenharmony_ci ((jiffies/HZ - adapter->stats_reset) < 6378c2ecf20Sopenharmony_ci data->seconds_since_last_reset)) 6388c2ecf20Sopenharmony_ci zfcp_scsi_adjust_fc_host_stats(fc_stats, data, 6398c2ecf20Sopenharmony_ci adapter->stats_reset_data); 6408c2ecf20Sopenharmony_ci else 6418c2ecf20Sopenharmony_ci zfcp_scsi_set_fc_host_stats(fc_stats, data); 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci kfree(data); 6448c2ecf20Sopenharmony_ci return fc_stats; 6458c2ecf20Sopenharmony_ci} 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_cistatic void zfcp_scsi_reset_fc_host_stats(struct Scsi_Host *shost) 6488c2ecf20Sopenharmony_ci{ 6498c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter; 6508c2ecf20Sopenharmony_ci struct fsf_qtcb_bottom_port *data; 6518c2ecf20Sopenharmony_ci int ret; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci adapter = (struct zfcp_adapter *)shost->hostdata[0]; 6548c2ecf20Sopenharmony_ci data = kzalloc(sizeof(*data), GFP_KERNEL); 6558c2ecf20Sopenharmony_ci if (!data) 6568c2ecf20Sopenharmony_ci return; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data); 6598c2ecf20Sopenharmony_ci if (ret != 0 && ret != -EAGAIN) 6608c2ecf20Sopenharmony_ci kfree(data); 6618c2ecf20Sopenharmony_ci else { 6628c2ecf20Sopenharmony_ci adapter->stats_reset = jiffies/HZ; 6638c2ecf20Sopenharmony_ci kfree(adapter->stats_reset_data); 6648c2ecf20Sopenharmony_ci adapter->stats_reset_data = data; /* finally freed in 6658c2ecf20Sopenharmony_ci adapter_release */ 6668c2ecf20Sopenharmony_ci } 6678c2ecf20Sopenharmony_ci} 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_cistatic void zfcp_scsi_get_host_port_state(struct Scsi_Host *shost) 6708c2ecf20Sopenharmony_ci{ 6718c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = 6728c2ecf20Sopenharmony_ci (struct zfcp_adapter *)shost->hostdata[0]; 6738c2ecf20Sopenharmony_ci int status = atomic_read(&adapter->status); 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci if ((status & ZFCP_STATUS_COMMON_RUNNING) && 6768c2ecf20Sopenharmony_ci !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)) 6778c2ecf20Sopenharmony_ci fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; 6788c2ecf20Sopenharmony_ci else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) 6798c2ecf20Sopenharmony_ci fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 6808c2ecf20Sopenharmony_ci else if (status & ZFCP_STATUS_COMMON_ERP_FAILED) 6818c2ecf20Sopenharmony_ci fc_host_port_state(shost) = FC_PORTSTATE_ERROR; 6828c2ecf20Sopenharmony_ci else 6838c2ecf20Sopenharmony_ci fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; 6848c2ecf20Sopenharmony_ci} 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_cistatic void zfcp_scsi_set_rport_dev_loss_tmo(struct fc_rport *rport, 6878c2ecf20Sopenharmony_ci u32 timeout) 6888c2ecf20Sopenharmony_ci{ 6898c2ecf20Sopenharmony_ci rport->dev_loss_tmo = timeout; 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci/** 6938c2ecf20Sopenharmony_ci * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport 6948c2ecf20Sopenharmony_ci * @rport: The FC rport where to teminate I/O 6958c2ecf20Sopenharmony_ci * 6968c2ecf20Sopenharmony_ci * Abort all pending SCSI commands for a port by closing the 6978c2ecf20Sopenharmony_ci * port. Using a reopen avoids a conflict with a shutdown 6988c2ecf20Sopenharmony_ci * overwriting a reopen. The "forced" ensures that a disappeared port 6998c2ecf20Sopenharmony_ci * is not opened again as valid due to the cached plogi data in 7008c2ecf20Sopenharmony_ci * non-NPIV mode. 7018c2ecf20Sopenharmony_ci */ 7028c2ecf20Sopenharmony_cistatic void zfcp_scsi_terminate_rport_io(struct fc_rport *rport) 7038c2ecf20Sopenharmony_ci{ 7048c2ecf20Sopenharmony_ci struct zfcp_port *port; 7058c2ecf20Sopenharmony_ci struct Scsi_Host *shost = rport_to_shost(rport); 7068c2ecf20Sopenharmony_ci struct zfcp_adapter *adapter = 7078c2ecf20Sopenharmony_ci (struct zfcp_adapter *)shost->hostdata[0]; 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci port = zfcp_get_port_by_wwpn(adapter, rport->port_name); 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci if (port) { 7128c2ecf20Sopenharmony_ci zfcp_erp_port_forced_reopen(port, 0, "sctrpi1"); 7138c2ecf20Sopenharmony_ci put_device(&port->dev); 7148c2ecf20Sopenharmony_ci } else { 7158c2ecf20Sopenharmony_ci zfcp_erp_port_forced_no_port_dbf( 7168c2ecf20Sopenharmony_ci "sctrpin", adapter, 7178c2ecf20Sopenharmony_ci rport->port_name /* zfcp_scsi_rport_register */, 7188c2ecf20Sopenharmony_ci rport->port_id /* zfcp_scsi_rport_register */); 7198c2ecf20Sopenharmony_ci } 7208c2ecf20Sopenharmony_ci} 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_cistatic void zfcp_scsi_rport_register(struct zfcp_port *port) 7238c2ecf20Sopenharmony_ci{ 7248c2ecf20Sopenharmony_ci struct fc_rport_identifiers ids; 7258c2ecf20Sopenharmony_ci struct fc_rport *rport; 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci if (port->rport) 7288c2ecf20Sopenharmony_ci return; 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci ids.node_name = port->wwnn; 7318c2ecf20Sopenharmony_ci ids.port_name = port->wwpn; 7328c2ecf20Sopenharmony_ci ids.port_id = port->d_id; 7338c2ecf20Sopenharmony_ci ids.roles = FC_RPORT_ROLE_FCP_TARGET; 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci zfcp_dbf_rec_trig_lock("scpaddy", port->adapter, port, NULL, 7368c2ecf20Sopenharmony_ci ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD, 7378c2ecf20Sopenharmony_ci ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD); 7388c2ecf20Sopenharmony_ci rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids); 7398c2ecf20Sopenharmony_ci if (!rport) { 7408c2ecf20Sopenharmony_ci dev_err(&port->adapter->ccw_device->dev, 7418c2ecf20Sopenharmony_ci "Registering port 0x%016Lx failed\n", 7428c2ecf20Sopenharmony_ci (unsigned long long)port->wwpn); 7438c2ecf20Sopenharmony_ci return; 7448c2ecf20Sopenharmony_ci } 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci rport->maxframe_size = port->maxframe_size; 7478c2ecf20Sopenharmony_ci rport->supported_classes = port->supported_classes; 7488c2ecf20Sopenharmony_ci port->rport = rport; 7498c2ecf20Sopenharmony_ci port->starget_id = rport->scsi_target_id; 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci zfcp_unit_queue_scsi_scan(port); 7528c2ecf20Sopenharmony_ci} 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_cistatic void zfcp_scsi_rport_block(struct zfcp_port *port) 7558c2ecf20Sopenharmony_ci{ 7568c2ecf20Sopenharmony_ci struct fc_rport *rport = port->rport; 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci if (rport) { 7598c2ecf20Sopenharmony_ci zfcp_dbf_rec_trig_lock("scpdely", port->adapter, port, NULL, 7608c2ecf20Sopenharmony_ci ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL, 7618c2ecf20Sopenharmony_ci ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL); 7628c2ecf20Sopenharmony_ci fc_remote_port_delete(rport); 7638c2ecf20Sopenharmony_ci port->rport = NULL; 7648c2ecf20Sopenharmony_ci } 7658c2ecf20Sopenharmony_ci} 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_civoid zfcp_scsi_schedule_rport_register(struct zfcp_port *port) 7688c2ecf20Sopenharmony_ci{ 7698c2ecf20Sopenharmony_ci get_device(&port->dev); 7708c2ecf20Sopenharmony_ci port->rport_task = RPORT_ADD; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci if (!queue_work(port->adapter->work_queue, &port->rport_work)) 7738c2ecf20Sopenharmony_ci put_device(&port->dev); 7748c2ecf20Sopenharmony_ci} 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_civoid zfcp_scsi_schedule_rport_block(struct zfcp_port *port) 7778c2ecf20Sopenharmony_ci{ 7788c2ecf20Sopenharmony_ci get_device(&port->dev); 7798c2ecf20Sopenharmony_ci port->rport_task = RPORT_DEL; 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci if (port->rport && queue_work(port->adapter->work_queue, 7828c2ecf20Sopenharmony_ci &port->rport_work)) 7838c2ecf20Sopenharmony_ci return; 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci put_device(&port->dev); 7868c2ecf20Sopenharmony_ci} 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_civoid zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter) 7898c2ecf20Sopenharmony_ci{ 7908c2ecf20Sopenharmony_ci unsigned long flags; 7918c2ecf20Sopenharmony_ci struct zfcp_port *port; 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci read_lock_irqsave(&adapter->port_list_lock, flags); 7948c2ecf20Sopenharmony_ci list_for_each_entry(port, &adapter->port_list, list) 7958c2ecf20Sopenharmony_ci zfcp_scsi_schedule_rport_block(port); 7968c2ecf20Sopenharmony_ci read_unlock_irqrestore(&adapter->port_list_lock, flags); 7978c2ecf20Sopenharmony_ci} 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_civoid zfcp_scsi_rport_work(struct work_struct *work) 8008c2ecf20Sopenharmony_ci{ 8018c2ecf20Sopenharmony_ci struct zfcp_port *port = container_of(work, struct zfcp_port, 8028c2ecf20Sopenharmony_ci rport_work); 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci set_worker_desc("zrp%c-%16llx", 8058c2ecf20Sopenharmony_ci (port->rport_task == RPORT_ADD) ? 'a' : 'd', 8068c2ecf20Sopenharmony_ci port->wwpn); /* < WORKER_DESC_LEN=24 */ 8078c2ecf20Sopenharmony_ci while (port->rport_task) { 8088c2ecf20Sopenharmony_ci if (port->rport_task == RPORT_ADD) { 8098c2ecf20Sopenharmony_ci port->rport_task = RPORT_NONE; 8108c2ecf20Sopenharmony_ci zfcp_scsi_rport_register(port); 8118c2ecf20Sopenharmony_ci } else { 8128c2ecf20Sopenharmony_ci port->rport_task = RPORT_NONE; 8138c2ecf20Sopenharmony_ci zfcp_scsi_rport_block(port); 8148c2ecf20Sopenharmony_ci } 8158c2ecf20Sopenharmony_ci } 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci put_device(&port->dev); 8188c2ecf20Sopenharmony_ci} 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci/** 8218c2ecf20Sopenharmony_ci * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host 8228c2ecf20Sopenharmony_ci * @adapter: The adapter where to configure DIF/DIX for the SCSI host 8238c2ecf20Sopenharmony_ci */ 8248c2ecf20Sopenharmony_civoid zfcp_scsi_set_prot(struct zfcp_adapter *adapter) 8258c2ecf20Sopenharmony_ci{ 8268c2ecf20Sopenharmony_ci unsigned int mask = 0; 8278c2ecf20Sopenharmony_ci unsigned int data_div; 8288c2ecf20Sopenharmony_ci struct Scsi_Host *shost = adapter->scsi_host; 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci data_div = atomic_read(&adapter->status) & 8318c2ecf20Sopenharmony_ci ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED; 8328c2ecf20Sopenharmony_ci 8338c2ecf20Sopenharmony_ci if ((enable_dif || zfcp_experimental_dix) && 8348c2ecf20Sopenharmony_ci adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1) 8358c2ecf20Sopenharmony_ci mask |= SHOST_DIF_TYPE1_PROTECTION; 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci if (zfcp_experimental_dix && data_div && 8388c2ecf20Sopenharmony_ci adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) { 8398c2ecf20Sopenharmony_ci mask |= SHOST_DIX_TYPE1_PROTECTION; 8408c2ecf20Sopenharmony_ci scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP); 8418c2ecf20Sopenharmony_ci shost->sg_prot_tablesize = adapter->qdio->max_sbale_per_req / 2; 8428c2ecf20Sopenharmony_ci shost->sg_tablesize = adapter->qdio->max_sbale_per_req / 2; 8438c2ecf20Sopenharmony_ci shost->max_sectors = shost->sg_tablesize * 8; 8448c2ecf20Sopenharmony_ci } 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_ci scsi_host_set_prot(shost, mask); 8478c2ecf20Sopenharmony_ci} 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci/** 8508c2ecf20Sopenharmony_ci * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error 8518c2ecf20Sopenharmony_ci * @scmd: The SCSI command to report the error for 8528c2ecf20Sopenharmony_ci * @ascq: The ASCQ to put in the sense buffer 8538c2ecf20Sopenharmony_ci * 8548c2ecf20Sopenharmony_ci * See the error handling in sd_done for the sense codes used here. 8558c2ecf20Sopenharmony_ci * Set DID_SOFT_ERROR to retry the request, if possible. 8568c2ecf20Sopenharmony_ci */ 8578c2ecf20Sopenharmony_civoid zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq) 8588c2ecf20Sopenharmony_ci{ 8598c2ecf20Sopenharmony_ci scsi_build_sense_buffer(1, scmd->sense_buffer, 8608c2ecf20Sopenharmony_ci ILLEGAL_REQUEST, 0x10, ascq); 8618c2ecf20Sopenharmony_ci set_driver_byte(scmd, DRIVER_SENSE); 8628c2ecf20Sopenharmony_ci scmd->result |= SAM_STAT_CHECK_CONDITION; 8638c2ecf20Sopenharmony_ci set_host_byte(scmd, DID_SOFT_ERROR); 8648c2ecf20Sopenharmony_ci} 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_civoid zfcp_scsi_shost_update_config_data( 8678c2ecf20Sopenharmony_ci struct zfcp_adapter *const adapter, 8688c2ecf20Sopenharmony_ci const struct fsf_qtcb_bottom_config *const bottom, 8698c2ecf20Sopenharmony_ci const bool bottom_incomplete) 8708c2ecf20Sopenharmony_ci{ 8718c2ecf20Sopenharmony_ci struct Scsi_Host *const shost = adapter->scsi_host; 8728c2ecf20Sopenharmony_ci const struct fc_els_flogi *nsp, *plogi; 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci if (shost == NULL) 8758c2ecf20Sopenharmony_ci return; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci snprintf(fc_host_firmware_version(shost), FC_VERSION_STRING_SIZE, 8788c2ecf20Sopenharmony_ci "0x%08x", bottom->lic_version); 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { 8818c2ecf20Sopenharmony_ci snprintf(fc_host_hardware_version(shost), 8828c2ecf20Sopenharmony_ci FC_VERSION_STRING_SIZE, 8838c2ecf20Sopenharmony_ci "0x%08x", bottom->hardware_version); 8848c2ecf20Sopenharmony_ci memcpy(fc_host_serial_number(shost), bottom->serial_number, 8858c2ecf20Sopenharmony_ci min(FC_SERIAL_NUMBER_SIZE, 17)); 8868c2ecf20Sopenharmony_ci EBCASC(fc_host_serial_number(shost), 8878c2ecf20Sopenharmony_ci min(FC_SERIAL_NUMBER_SIZE, 17)); 8888c2ecf20Sopenharmony_ci } 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci /* adjust pointers for missing command code */ 8918c2ecf20Sopenharmony_ci nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param 8928c2ecf20Sopenharmony_ci - sizeof(u32)); 8938c2ecf20Sopenharmony_ci plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload 8948c2ecf20Sopenharmony_ci - sizeof(u32)); 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ci snprintf(fc_host_manufacturer(shost), FC_SERIAL_NUMBER_SIZE, "%s", 8978c2ecf20Sopenharmony_ci "IBM"); 8988c2ecf20Sopenharmony_ci fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn); 8998c2ecf20Sopenharmony_ci fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn); 9008c2ecf20Sopenharmony_ci fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_ci zfcp_scsi_set_prot(adapter); 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci /* do not evaluate invalid fields */ 9058c2ecf20Sopenharmony_ci if (bottom_incomplete) 9068c2ecf20Sopenharmony_ci return; 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci fc_host_port_id(shost) = ntoh24(bottom->s_id); 9098c2ecf20Sopenharmony_ci fc_host_speed(shost) = 9108c2ecf20Sopenharmony_ci zfcp_fsf_convert_portspeed(bottom->fc_link_speed); 9118c2ecf20Sopenharmony_ci 9128c2ecf20Sopenharmony_ci snprintf(fc_host_model(shost), FC_SYMBOLIC_NAME_SIZE, "0x%04x", 9138c2ecf20Sopenharmony_ci bottom->adapter_type); 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci switch (bottom->fc_topology) { 9168c2ecf20Sopenharmony_ci case FSF_TOPO_P2P: 9178c2ecf20Sopenharmony_ci fc_host_port_type(shost) = FC_PORTTYPE_PTP; 9188c2ecf20Sopenharmony_ci fc_host_fabric_name(shost) = 0; 9198c2ecf20Sopenharmony_ci break; 9208c2ecf20Sopenharmony_ci case FSF_TOPO_FABRIC: 9218c2ecf20Sopenharmony_ci fc_host_fabric_name(shost) = be64_to_cpu(plogi->fl_wwnn); 9228c2ecf20Sopenharmony_ci if (bottom->connection_features & FSF_FEATURE_NPIV_MODE) 9238c2ecf20Sopenharmony_ci fc_host_port_type(shost) = FC_PORTTYPE_NPIV; 9248c2ecf20Sopenharmony_ci else 9258c2ecf20Sopenharmony_ci fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 9268c2ecf20Sopenharmony_ci break; 9278c2ecf20Sopenharmony_ci case FSF_TOPO_AL: 9288c2ecf20Sopenharmony_ci fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; 9298c2ecf20Sopenharmony_ci fallthrough; 9308c2ecf20Sopenharmony_ci default: 9318c2ecf20Sopenharmony_ci fc_host_fabric_name(shost) = 0; 9328c2ecf20Sopenharmony_ci break; 9338c2ecf20Sopenharmony_ci } 9348c2ecf20Sopenharmony_ci} 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_civoid zfcp_scsi_shost_update_port_data( 9378c2ecf20Sopenharmony_ci struct zfcp_adapter *const adapter, 9388c2ecf20Sopenharmony_ci const struct fsf_qtcb_bottom_port *const bottom) 9398c2ecf20Sopenharmony_ci{ 9408c2ecf20Sopenharmony_ci struct Scsi_Host *const shost = adapter->scsi_host; 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci if (shost == NULL) 9438c2ecf20Sopenharmony_ci return; 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci fc_host_permanent_port_name(shost) = bottom->wwpn; 9468c2ecf20Sopenharmony_ci fc_host_maxframe_size(shost) = bottom->maximum_frame_size; 9478c2ecf20Sopenharmony_ci fc_host_supported_speeds(shost) = 9488c2ecf20Sopenharmony_ci zfcp_fsf_convert_portspeed(bottom->supported_speed); 9498c2ecf20Sopenharmony_ci memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types, 9508c2ecf20Sopenharmony_ci FC_FC4_LIST_SIZE); 9518c2ecf20Sopenharmony_ci memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types, 9528c2ecf20Sopenharmony_ci FC_FC4_LIST_SIZE); 9538c2ecf20Sopenharmony_ci} 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_cistruct fc_function_template zfcp_transport_functions = { 9568c2ecf20Sopenharmony_ci .show_starget_port_id = 1, 9578c2ecf20Sopenharmony_ci .show_starget_port_name = 1, 9588c2ecf20Sopenharmony_ci .show_starget_node_name = 1, 9598c2ecf20Sopenharmony_ci .show_rport_supported_classes = 1, 9608c2ecf20Sopenharmony_ci .show_rport_maxframe_size = 1, 9618c2ecf20Sopenharmony_ci .show_rport_dev_loss_tmo = 1, 9628c2ecf20Sopenharmony_ci .show_host_node_name = 1, 9638c2ecf20Sopenharmony_ci .show_host_port_name = 1, 9648c2ecf20Sopenharmony_ci .show_host_permanent_port_name = 1, 9658c2ecf20Sopenharmony_ci .show_host_supported_classes = 1, 9668c2ecf20Sopenharmony_ci .show_host_supported_fc4s = 1, 9678c2ecf20Sopenharmony_ci .show_host_supported_speeds = 1, 9688c2ecf20Sopenharmony_ci .show_host_maxframe_size = 1, 9698c2ecf20Sopenharmony_ci .show_host_serial_number = 1, 9708c2ecf20Sopenharmony_ci .show_host_manufacturer = 1, 9718c2ecf20Sopenharmony_ci .show_host_model = 1, 9728c2ecf20Sopenharmony_ci .show_host_hardware_version = 1, 9738c2ecf20Sopenharmony_ci .show_host_firmware_version = 1, 9748c2ecf20Sopenharmony_ci .get_fc_host_stats = zfcp_scsi_get_fc_host_stats, 9758c2ecf20Sopenharmony_ci .reset_fc_host_stats = zfcp_scsi_reset_fc_host_stats, 9768c2ecf20Sopenharmony_ci .set_rport_dev_loss_tmo = zfcp_scsi_set_rport_dev_loss_tmo, 9778c2ecf20Sopenharmony_ci .get_host_port_state = zfcp_scsi_get_host_port_state, 9788c2ecf20Sopenharmony_ci .terminate_rport_io = zfcp_scsi_terminate_rport_io, 9798c2ecf20Sopenharmony_ci .show_host_port_state = 1, 9808c2ecf20Sopenharmony_ci .show_host_active_fc4s = 1, 9818c2ecf20Sopenharmony_ci .bsg_request = zfcp_fc_exec_bsg_job, 9828c2ecf20Sopenharmony_ci .bsg_timeout = zfcp_fc_timeout_bsg_job, 9838c2ecf20Sopenharmony_ci /* no functions registered for following dynamic attributes but 9848c2ecf20Sopenharmony_ci directly set by LLDD */ 9858c2ecf20Sopenharmony_ci .show_host_port_type = 1, 9868c2ecf20Sopenharmony_ci .show_host_symbolic_name = 1, 9878c2ecf20Sopenharmony_ci .show_host_speed = 1, 9888c2ecf20Sopenharmony_ci .show_host_port_id = 1, 9898c2ecf20Sopenharmony_ci .show_host_fabric_name = 1, 9908c2ecf20Sopenharmony_ci .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els), 9918c2ecf20Sopenharmony_ci}; 992