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