Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 1 | /* |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2 | * zfcp device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 4 | * Interface to Linux SCSI midlayer. |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 5 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 6 | * Copyright IBM Corp. 2002, 2010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 9 | #define KMSG_COMPONENT "zfcp" |
| 10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 11 | |
Heiko Carstens | 3a4c5d5 | 2011-07-30 09:25:15 +0200 | [diff] [blame] | 12 | #include <linux/module.h> |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 13 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 15 | #include <scsi/fc/fc_fcp.h> |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 16 | #include <scsi/scsi_eh.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 17 | #include <linux/atomic.h> |
Christof Schmitt | dcd20e2 | 2009-08-18 15:43:08 +0200 | [diff] [blame] | 18 | #include "zfcp_ext.h" |
| 19 | #include "zfcp_dbf.h" |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 20 | #include "zfcp_fc.h" |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 21 | #include "zfcp_reqlist.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Christof Schmitt | a40a1ba | 2009-05-15 13:18:16 +0200 | [diff] [blame] | 23 | static unsigned int default_depth = 32; |
| 24 | module_param_named(queue_depth, default_depth, uint, 0600); |
| 25 | MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices"); |
| 26 | |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 27 | static bool enable_dif; |
Steffen Maier | cc405ac | 2011-08-15 14:40:30 +0200 | [diff] [blame] | 28 | module_param_named(dif, enable_dif, bool, 0400); |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 29 | MODULE_PARM_DESC(dif, "Enable DIF/DIX data integrity support"); |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 30 | |
Christof Schmitt | 0d81b4e | 2010-12-08 17:30:46 +0100 | [diff] [blame] | 31 | static bool allow_lun_scan = 1; |
| 32 | module_param(allow_lun_scan, bool, 0600); |
| 33 | MODULE_PARM_DESC(allow_lun_scan, "For NPIV, scan and attach all storage LUNs"); |
| 34 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 35 | static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth, |
| 36 | int reason) |
Christof Schmitt | a40a1ba | 2009-05-15 13:18:16 +0200 | [diff] [blame] | 37 | { |
Christof Schmitt | 42e62a7 | 2009-10-15 17:47:11 -0700 | [diff] [blame] | 38 | switch (reason) { |
| 39 | case SCSI_QDEPTH_DEFAULT: |
| 40 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); |
| 41 | break; |
| 42 | case SCSI_QDEPTH_QFULL: |
| 43 | scsi_track_queue_full(sdev, depth); |
| 44 | break; |
| 45 | case SCSI_QDEPTH_RAMP_UP: |
| 46 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); |
| 47 | break; |
| 48 | default: |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 49 | return -EOPNOTSUPP; |
Christof Schmitt | 42e62a7 | 2009-10-15 17:47:11 -0700 | [diff] [blame] | 50 | } |
Christof Schmitt | a40a1ba | 2009-05-15 13:18:16 +0200 | [diff] [blame] | 51 | return sdev->queue_depth; |
| 52 | } |
| 53 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 54 | static void zfcp_scsi_slave_destroy(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 56 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
| 57 | |
Steffen Maier | 44f747f | 2011-11-18 20:00:40 +0100 | [diff] [blame] | 58 | /* if previous slave_alloc returned early, there is nothing to do */ |
| 59 | if (!zfcp_sdev->port) |
| 60 | return; |
| 61 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 62 | zfcp_erp_lun_shutdown_wait(sdev, "scssd_1"); |
| 63 | put_device(&zfcp_sdev->port->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 66 | static int zfcp_scsi_slave_configure(struct scsi_device *sdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | if (sdp->tagged_supported) |
Christof Schmitt | a40a1ba | 2009-05-15 13:18:16 +0200 | [diff] [blame] | 69 | scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, default_depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | else |
| 71 | scsi_adjust_queue_depth(sdp, 0, 1); |
| 72 | return 0; |
| 73 | } |
| 74 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 75 | static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 77 | set_host_byte(scpnt, result); |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 78 | zfcp_dbf_scsi_fail_send(scpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | scpnt->scsi_done(scpnt); |
| 80 | } |
| 81 | |
Christof Schmitt | e55f875 | 2010-11-18 14:53:18 +0100 | [diff] [blame] | 82 | static |
| 83 | int zfcp_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 85 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 86 | struct fc_rport *rport = starget_to_rport(scsi_target(scpnt->device)); |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 87 | int status, scsi_result, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | /* reset the status for this request */ |
| 90 | scpnt->result = 0; |
| 91 | scpnt->host_scribble = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 93 | scsi_result = fc_remote_port_chkready(rport); |
| 94 | if (unlikely(scsi_result)) { |
| 95 | scpnt->result = scsi_result; |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 96 | zfcp_dbf_scsi_fail_send(scpnt); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 97 | scpnt->scsi_done(scpnt); |
| 98 | return 0; |
| 99 | } |
| 100 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 101 | status = atomic_read(&zfcp_sdev->status); |
Christof Schmitt | 8830271 | 2009-11-24 16:54:07 +0100 | [diff] [blame] | 102 | if (unlikely(status & ZFCP_STATUS_COMMON_ERP_FAILED) && |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 103 | !(atomic_read(&zfcp_sdev->port->status) & |
Christof Schmitt | 8830271 | 2009-11-24 16:54:07 +0100 | [diff] [blame] | 104 | ZFCP_STATUS_COMMON_ERP_FAILED)) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 105 | /* only LUN access denied, but port is good |
Christof Schmitt | 8830271 | 2009-11-24 16:54:07 +0100 | [diff] [blame] | 106 | * not covered by FC transport, have to fail here */ |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 107 | zfcp_scsi_command_fail(scpnt, DID_ERROR); |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 108 | return 0; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Christof Schmitt | 8830271 | 2009-11-24 16:54:07 +0100 | [diff] [blame] | 111 | if (unlikely(!(status & ZFCP_STATUS_COMMON_UNBLOCKED))) { |
| 112 | /* This could be either |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 113 | * open LUN pending: this is temporary, will result in |
| 114 | * open LUN or ERP_FAILED, so retry command |
Christof Schmitt | 8830271 | 2009-11-24 16:54:07 +0100 | [diff] [blame] | 115 | * call to rport_delete pending: mimic retry from |
| 116 | * fc_remote_port_chkready until rport is BLOCKED |
| 117 | */ |
| 118 | zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY); |
| 119 | return 0; |
| 120 | } |
| 121 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 122 | ret = zfcp_fsf_fcp_cmnd(scpnt); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 123 | if (unlikely(ret == -EBUSY)) |
Swen Schillig | f7a65e9 | 2008-11-27 11:44:07 +0100 | [diff] [blame] | 124 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 125 | else if (unlikely(ret < 0)) |
| 126 | return SCSI_MLQUEUE_HOST_BUSY; |
| 127 | |
| 128 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 131 | static int zfcp_scsi_slave_alloc(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 133 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
| 134 | struct zfcp_adapter *adapter = |
| 135 | (struct zfcp_adapter *) sdev->host->hostdata[0]; |
| 136 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | struct zfcp_port *port; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 138 | struct zfcp_unit *unit; |
Christof Schmitt | 0d81b4e | 2010-12-08 17:30:46 +0100 | [diff] [blame] | 139 | int npiv = adapter->connection_features & FSF_FEATURE_NPIV_MODE; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 140 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 141 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
| 142 | if (!port) |
| 143 | return -ENXIO; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 144 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 145 | unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev)); |
| 146 | if (unit) |
| 147 | put_device(&unit->dev); |
Christof Schmitt | f8210e3 | 2010-09-08 14:39:56 +0200 | [diff] [blame] | 148 | |
Christof Schmitt | 0d81b4e | 2010-12-08 17:30:46 +0100 | [diff] [blame] | 149 | if (!unit && !(allow_lun_scan && npiv)) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 150 | put_device(&port->dev); |
| 151 | return -ENXIO; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 152 | } |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 153 | |
| 154 | zfcp_sdev->port = port; |
| 155 | zfcp_sdev->latencies.write.channel.min = 0xFFFFFFFF; |
| 156 | zfcp_sdev->latencies.write.fabric.min = 0xFFFFFFFF; |
| 157 | zfcp_sdev->latencies.read.channel.min = 0xFFFFFFFF; |
| 158 | zfcp_sdev->latencies.read.fabric.min = 0xFFFFFFFF; |
| 159 | zfcp_sdev->latencies.cmd.channel.min = 0xFFFFFFFF; |
| 160 | zfcp_sdev->latencies.cmd.fabric.min = 0xFFFFFFFF; |
| 161 | spin_lock_init(&zfcp_sdev->latencies.lock); |
| 162 | |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 163 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 164 | zfcp_erp_lun_reopen(sdev, 0, "scsla_1"); |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 165 | zfcp_erp_wait(port->adapter); |
| 166 | |
| 167 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 170 | static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 172 | struct Scsi_Host *scsi_host = scpnt->device->host; |
| 173 | struct zfcp_adapter *adapter = |
| 174 | (struct zfcp_adapter *) scsi_host->hostdata[0]; |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 175 | struct zfcp_fsf_req *old_req, *abrt_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | unsigned long flags; |
Christof Schmitt | a11a52b | 2009-07-13 15:06:14 +0200 | [diff] [blame] | 177 | unsigned long old_reqid = (unsigned long) scpnt->host_scribble; |
Christof Schmitt | a1dbfdd | 2010-03-24 16:50:31 +0100 | [diff] [blame] | 178 | int retval = SUCCESS, ret; |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 179 | int retry = 3; |
Christof Schmitt | a11a52b | 2009-07-13 15:06:14 +0200 | [diff] [blame] | 180 | char *dbf_tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 182 | /* avoid race condition between late normal completion and abort */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | write_lock_irqsave(&adapter->abort_lock, flags); |
| 184 | |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 185 | old_req = zfcp_reqlist_find(adapter->req_list, old_reqid); |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 186 | if (!old_req) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 188 | zfcp_dbf_scsi_abort("abrt_or", scpnt, NULL); |
Christof Schmitt | c6936e7 | 2009-04-17 15:08:11 +0200 | [diff] [blame] | 189 | return FAILED; /* completion could be in progress */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 191 | old_req->data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 193 | /* don't access old fsf_req after releasing the abort_lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 195 | |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 196 | while (retry--) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 197 | abrt_req = zfcp_fsf_abort_fcp_cmnd(scpnt); |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 198 | if (abrt_req) |
| 199 | break; |
| 200 | |
| 201 | zfcp_erp_wait(adapter); |
Christof Schmitt | a1dbfdd | 2010-03-24 16:50:31 +0100 | [diff] [blame] | 202 | ret = fc_block_scsi_eh(scpnt); |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 203 | if (ret) { |
| 204 | zfcp_dbf_scsi_abort("abrt_bl", scpnt, NULL); |
Christof Schmitt | a1dbfdd | 2010-03-24 16:50:31 +0100 | [diff] [blame] | 205 | return ret; |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 206 | } |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 207 | if (!(atomic_read(&adapter->status) & |
| 208 | ZFCP_STATUS_COMMON_RUNNING)) { |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 209 | zfcp_dbf_scsi_abort("abrt_ru", scpnt, NULL); |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 210 | return SUCCESS; |
| 211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 213 | if (!abrt_req) { |
| 214 | zfcp_dbf_scsi_abort("abrt_ar", scpnt, NULL); |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 215 | return FAILED; |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Swen Schillig | 058b864 | 2009-08-18 15:43:14 +0200 | [diff] [blame] | 218 | wait_for_completion(&abrt_req->completion); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 219 | |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 220 | if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 221 | dbf_tag = "abrt_ok"; |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 222 | else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 223 | dbf_tag = "abrt_nn"; |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 224 | else { |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 225 | dbf_tag = "abrt_fa"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | retval = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 228 | zfcp_dbf_scsi_abort(dbf_tag, scpnt, abrt_req); |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 229 | zfcp_fsf_req_free(abrt_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return retval; |
| 231 | } |
| 232 | |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 233 | static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 235 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); |
| 236 | struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 237 | struct zfcp_fsf_req *fsf_req = NULL; |
Christof Schmitt | a1dbfdd | 2010-03-24 16:50:31 +0100 | [diff] [blame] | 238 | int retval = SUCCESS, ret; |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 239 | int retry = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 241 | while (retry--) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 242 | fsf_req = zfcp_fsf_fcp_task_mgmt(scpnt, tm_flags); |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 243 | if (fsf_req) |
| 244 | break; |
| 245 | |
| 246 | zfcp_erp_wait(adapter); |
Christof Schmitt | a1dbfdd | 2010-03-24 16:50:31 +0100 | [diff] [blame] | 247 | ret = fc_block_scsi_eh(scpnt); |
| 248 | if (ret) |
| 249 | return ret; |
| 250 | |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 251 | if (!(atomic_read(&adapter->status) & |
| 252 | ZFCP_STATUS_COMMON_RUNNING)) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 253 | zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags); |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 254 | return SUCCESS; |
| 255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
Christof Schmitt | 63caf36 | 2009-03-02 13:09:00 +0100 | [diff] [blame] | 257 | if (!fsf_req) |
| 258 | return FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Swen Schillig | 058b864 | 2009-08-18 15:43:14 +0200 | [diff] [blame] | 260 | wait_for_completion(&fsf_req->completion); |
Andreas Herrmann | 77eb169 | 2005-09-13 21:48:33 +0200 | [diff] [blame] | 261 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 262 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 263 | zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 264 | retval = FAILED; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 265 | } else |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 266 | zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags); |
Andreas Herrmann | 77eb169 | 2005-09-13 21:48:33 +0200 | [diff] [blame] | 267 | |
| 268 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | return retval; |
| 270 | } |
| 271 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 272 | static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt) |
| 273 | { |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 274 | return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt) |
| 278 | { |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 279 | return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 282 | static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 284 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); |
| 285 | struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; |
Christof Schmitt | a1dbfdd | 2010-03-24 16:50:31 +0100 | [diff] [blame] | 286 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 288 | zfcp_erp_adapter_reopen(adapter, 0, "schrh_1"); |
Andreas Herrmann | 8165428 | 2006-09-18 22:30:36 +0200 | [diff] [blame] | 289 | zfcp_erp_wait(adapter); |
Christof Schmitt | a1dbfdd | 2010-03-24 16:50:31 +0100 | [diff] [blame] | 290 | ret = fc_block_scsi_eh(scpnt); |
| 291 | if (ret) |
| 292 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Andreas Herrmann | 810f1e3e | 2005-09-13 21:49:52 +0200 | [diff] [blame] | 294 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Christof Schmitt | 1947c72 | 2011-02-22 19:54:46 +0100 | [diff] [blame] | 297 | struct scsi_transport_template *zfcp_scsi_transport_template; |
| 298 | |
| 299 | static struct scsi_host_template zfcp_scsi_host_template = { |
| 300 | .module = THIS_MODULE, |
| 301 | .name = "zfcp", |
| 302 | .queuecommand = zfcp_scsi_queuecommand, |
| 303 | .eh_abort_handler = zfcp_scsi_eh_abort_handler, |
| 304 | .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler, |
| 305 | .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler, |
| 306 | .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler, |
| 307 | .slave_alloc = zfcp_scsi_slave_alloc, |
| 308 | .slave_configure = zfcp_scsi_slave_configure, |
| 309 | .slave_destroy = zfcp_scsi_slave_destroy, |
| 310 | .change_queue_depth = zfcp_scsi_change_queue_depth, |
| 311 | .proc_name = "zfcp", |
| 312 | .can_queue = 4096, |
| 313 | .this_id = -1, |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 314 | .sg_tablesize = 1, /* adjusted later */ |
| 315 | .max_sectors = 8, /* adjusted later */ |
Christof Schmitt | 1947c72 | 2011-02-22 19:54:46 +0100 | [diff] [blame] | 316 | .dma_boundary = ZFCP_QDIO_SBALE_LEN - 1, |
| 317 | .cmd_per_lun = 1, |
| 318 | .use_clustering = 1, |
| 319 | .shost_attrs = zfcp_sysfs_shost_attrs, |
| 320 | .sdev_attrs = zfcp_sysfs_sdev_attrs, |
| 321 | }; |
| 322 | |
| 323 | /** |
| 324 | * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer |
| 325 | * @adapter: The zfcp adapter to register with the SCSI midlayer |
| 326 | */ |
| 327 | int zfcp_scsi_adapter_register(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 329 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Michael Loehr | 9f28745 | 2007-05-09 11:01:24 +0200 | [diff] [blame] | 331 | if (adapter->scsi_host) |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 332 | return 0; |
Michael Loehr | 9f28745 | 2007-05-09 11:01:24 +0200 | [diff] [blame] | 333 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 334 | ccw_device_get_id(adapter->ccw_device, &dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* register adapter as SCSI host with mid layer of SCSI stack */ |
Christof Schmitt | 1947c72 | 2011-02-22 19:54:46 +0100 | [diff] [blame] | 336 | adapter->scsi_host = scsi_host_alloc(&zfcp_scsi_host_template, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | sizeof (struct zfcp_adapter *)); |
| 338 | if (!adapter->scsi_host) { |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 339 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 340 | "Registering the FCP device with the " |
| 341 | "SCSI stack failed\n"); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 342 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | /* tell the SCSI stack some characteristics of this adapter */ |
Christof Schmitt | f8210e3 | 2010-09-08 14:39:56 +0200 | [diff] [blame] | 346 | adapter->scsi_host->max_id = 511; |
| 347 | adapter->scsi_host->max_lun = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | adapter->scsi_host->max_channel = 0; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 349 | adapter->scsi_host->unique_id = dev_id.devno; |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 350 | adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */ |
Christof Schmitt | 1947c72 | 2011-02-22 19:54:46 +0100 | [diff] [blame] | 351 | adapter->scsi_host->transportt = zfcp_scsi_transport_template; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | adapter->scsi_host->hostdata[0] = (unsigned long) adapter; |
| 354 | |
| 355 | if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) { |
| 356 | scsi_host_put(adapter->scsi_host); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 357 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 359 | |
| 360 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Christof Schmitt | 1947c72 | 2011-02-22 19:54:46 +0100 | [diff] [blame] | 363 | /** |
| 364 | * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer |
| 365 | * @adapter: The zfcp adapter to unregister. |
| 366 | */ |
| 367 | void zfcp_scsi_adapter_unregister(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
| 369 | struct Scsi_Host *shost; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 370 | struct zfcp_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | shost = adapter->scsi_host; |
| 373 | if (!shost) |
| 374 | return; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 375 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 376 | read_lock_irq(&adapter->port_list_lock); |
| 377 | list_for_each_entry(port, &adapter->port_list, list) |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 378 | port->rport = NULL; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 379 | read_unlock_irq(&adapter->port_list_lock); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 380 | |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 381 | fc_remove_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | scsi_remove_host(shost); |
| 383 | scsi_host_put(shost); |
| 384 | adapter->scsi_host = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 387 | static struct fc_host_statistics* |
| 388 | zfcp_init_fc_host_stats(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 390 | struct fc_host_statistics *fc_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 392 | if (!adapter->fc_stats) { |
| 393 | fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL); |
| 394 | if (!fc_stats) |
| 395 | return NULL; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 396 | adapter->fc_stats = fc_stats; /* freed in adapter_release */ |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 397 | } |
| 398 | memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats)); |
| 399 | return adapter->fc_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 402 | static void zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats, |
| 403 | struct fsf_qtcb_bottom_port *data, |
| 404 | struct fsf_qtcb_bottom_port *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 406 | fc_stats->seconds_since_last_reset = |
| 407 | data->seconds_since_last_reset - old->seconds_since_last_reset; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 408 | fc_stats->tx_frames = data->tx_frames - old->tx_frames; |
| 409 | fc_stats->tx_words = data->tx_words - old->tx_words; |
| 410 | fc_stats->rx_frames = data->rx_frames - old->rx_frames; |
| 411 | fc_stats->rx_words = data->rx_words - old->rx_words; |
| 412 | fc_stats->lip_count = data->lip - old->lip; |
| 413 | fc_stats->nos_count = data->nos - old->nos; |
| 414 | fc_stats->error_frames = data->error_frames - old->error_frames; |
| 415 | fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames; |
| 416 | fc_stats->link_failure_count = data->link_failure - old->link_failure; |
| 417 | 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] | 418 | fc_stats->loss_of_signal_count = |
| 419 | data->loss_of_signal - old->loss_of_signal; |
| 420 | fc_stats->prim_seq_protocol_err_count = |
| 421 | data->psp_error_counts - old->psp_error_counts; |
| 422 | fc_stats->invalid_tx_word_count = |
| 423 | data->invalid_tx_words - old->invalid_tx_words; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 424 | fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 425 | fc_stats->fcp_input_requests = |
| 426 | data->input_requests - old->input_requests; |
| 427 | fc_stats->fcp_output_requests = |
| 428 | data->output_requests - old->output_requests; |
| 429 | fc_stats->fcp_control_requests = |
| 430 | data->control_requests - old->control_requests; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 431 | fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb; |
| 432 | fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 435 | static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats, |
| 436 | struct fsf_qtcb_bottom_port *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 438 | fc_stats->seconds_since_last_reset = data->seconds_since_last_reset; |
| 439 | fc_stats->tx_frames = data->tx_frames; |
| 440 | fc_stats->tx_words = data->tx_words; |
| 441 | fc_stats->rx_frames = data->rx_frames; |
| 442 | fc_stats->rx_words = data->rx_words; |
| 443 | fc_stats->lip_count = data->lip; |
| 444 | fc_stats->nos_count = data->nos; |
| 445 | fc_stats->error_frames = data->error_frames; |
| 446 | fc_stats->dumped_frames = data->dumped_frames; |
| 447 | fc_stats->link_failure_count = data->link_failure; |
| 448 | fc_stats->loss_of_sync_count = data->loss_of_sync; |
| 449 | fc_stats->loss_of_signal_count = data->loss_of_signal; |
| 450 | fc_stats->prim_seq_protocol_err_count = data->psp_error_counts; |
| 451 | fc_stats->invalid_tx_word_count = data->invalid_tx_words; |
| 452 | fc_stats->invalid_crc_count = data->invalid_crcs; |
| 453 | fc_stats->fcp_input_requests = data->input_requests; |
| 454 | fc_stats->fcp_output_requests = data->output_requests; |
| 455 | fc_stats->fcp_control_requests = data->control_requests; |
| 456 | fc_stats->fcp_input_megabytes = data->input_mb; |
| 457 | fc_stats->fcp_output_megabytes = data->output_mb; |
| 458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 460 | static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host) |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 461 | { |
| 462 | struct zfcp_adapter *adapter; |
| 463 | struct fc_host_statistics *fc_stats; |
| 464 | struct fsf_qtcb_bottom_port *data; |
| 465 | int ret; |
| 466 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 467 | adapter = (struct zfcp_adapter *)host->hostdata[0]; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 468 | fc_stats = zfcp_init_fc_host_stats(adapter); |
| 469 | if (!fc_stats) |
| 470 | return NULL; |
| 471 | |
Andreas Herrmann | ec4081c | 2006-05-22 18:17:30 +0200 | [diff] [blame] | 472 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 473 | if (!data) |
| 474 | return NULL; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 475 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 476 | ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 477 | if (ret) { |
| 478 | kfree(data); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 479 | return NULL; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | if (adapter->stats_reset && |
| 483 | ((jiffies/HZ - adapter->stats_reset) < |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 484 | data->seconds_since_last_reset)) |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 485 | zfcp_adjust_fc_host_stats(fc_stats, data, |
| 486 | adapter->stats_reset_data); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 487 | else |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 488 | zfcp_set_fc_host_stats(fc_stats, data); |
| 489 | |
| 490 | kfree(data); |
| 491 | return fc_stats; |
| 492 | } |
| 493 | |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 494 | static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost) |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 495 | { |
| 496 | struct zfcp_adapter *adapter; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 497 | struct fsf_qtcb_bottom_port *data; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 498 | int ret; |
| 499 | |
| 500 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
Andreas Herrmann | ec4081c | 2006-05-22 18:17:30 +0200 | [diff] [blame] | 501 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 502 | if (!data) |
| 503 | return; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 504 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 505 | ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 506 | if (ret) |
Heiko Carstens | 83f6d6d | 2007-08-08 10:47:02 +0200 | [diff] [blame] | 507 | kfree(data); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 508 | else { |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 509 | adapter->stats_reset = jiffies/HZ; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 510 | kfree(adapter->stats_reset_data); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 511 | adapter->stats_reset_data = data; /* finally freed in |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 512 | adapter_release */ |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Sven Schuetz | 85a8239 | 2008-06-10 18:20:59 +0200 | [diff] [blame] | 516 | static void zfcp_get_host_port_state(struct Scsi_Host *shost) |
| 517 | { |
| 518 | struct zfcp_adapter *adapter = |
| 519 | (struct zfcp_adapter *)shost->hostdata[0]; |
| 520 | int status = atomic_read(&adapter->status); |
| 521 | |
| 522 | if ((status & ZFCP_STATUS_COMMON_RUNNING) && |
| 523 | !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)) |
| 524 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; |
| 525 | else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) |
| 526 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; |
| 527 | else if (status & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 528 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; |
| 529 | else |
| 530 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; |
| 531 | } |
| 532 | |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 533 | static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout) |
| 534 | { |
| 535 | rport->dev_loss_tmo = timeout; |
| 536 | } |
| 537 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 538 | /** |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 539 | * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport |
| 540 | * @rport: The FC rport where to teminate I/O |
| 541 | * |
| 542 | * Abort all pending SCSI commands for a port by closing the |
Christof Schmitt | 835dc29 | 2010-07-08 09:53:08 +0200 | [diff] [blame] | 543 | * port. Using a reopen avoids a conflict with a shutdown |
| 544 | * overwriting a reopen. The "forced" ensures that a disappeared port |
| 545 | * is not opened again as valid due to the cached plogi data in |
| 546 | * non-NPIV mode. |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 547 | */ |
| 548 | static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport) |
| 549 | { |
Christof Schmitt | 7093293 | 2009-04-17 15:08:15 +0200 | [diff] [blame] | 550 | struct zfcp_port *port; |
Swen Schillig | ea945ff | 2009-08-18 15:43:24 +0200 | [diff] [blame] | 551 | struct Scsi_Host *shost = rport_to_shost(rport); |
| 552 | struct zfcp_adapter *adapter = |
| 553 | (struct zfcp_adapter *)shost->hostdata[0]; |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 554 | |
Swen Schillig | ea945ff | 2009-08-18 15:43:24 +0200 | [diff] [blame] | 555 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
Christof Schmitt | 7093293 | 2009-04-17 15:08:15 +0200 | [diff] [blame] | 556 | |
| 557 | if (port) { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 558 | zfcp_erp_port_forced_reopen(port, 0, "sctrpi1"); |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 559 | put_device(&port->dev); |
Christof Schmitt | 7093293 | 2009-04-17 15:08:15 +0200 | [diff] [blame] | 560 | } |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static void zfcp_scsi_rport_register(struct zfcp_port *port) |
| 564 | { |
| 565 | struct fc_rport_identifiers ids; |
| 566 | struct fc_rport *rport; |
| 567 | |
Christof Schmitt | 379d6bf | 2009-07-13 15:06:11 +0200 | [diff] [blame] | 568 | if (port->rport) |
| 569 | return; |
| 570 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 571 | ids.node_name = port->wwnn; |
| 572 | ids.port_name = port->wwpn; |
| 573 | ids.port_id = port->d_id; |
| 574 | ids.roles = FC_RPORT_ROLE_FCP_TARGET; |
| 575 | |
| 576 | rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids); |
| 577 | if (!rport) { |
| 578 | dev_err(&port->adapter->ccw_device->dev, |
| 579 | "Registering port 0x%016Lx failed\n", |
| 580 | (unsigned long long)port->wwpn); |
| 581 | return; |
| 582 | } |
| 583 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 584 | rport->maxframe_size = port->maxframe_size; |
| 585 | rport->supported_classes = port->supported_classes; |
| 586 | port->rport = rport; |
Christof Schmitt | 1bf3ff0 | 2010-07-16 15:37:35 +0200 | [diff] [blame] | 587 | port->starget_id = rport->scsi_target_id; |
Christof Schmitt | 5a7de55 | 2010-07-08 09:53:07 +0200 | [diff] [blame] | 588 | |
Christof Schmitt | 1daa4eb | 2010-09-08 14:39:52 +0200 | [diff] [blame] | 589 | zfcp_unit_queue_scsi_scan(port); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | static void zfcp_scsi_rport_block(struct zfcp_port *port) |
| 593 | { |
Christof Schmitt | 7093293 | 2009-04-17 15:08:15 +0200 | [diff] [blame] | 594 | struct fc_rport *rport = port->rport; |
| 595 | |
Christof Schmitt | 379d6bf | 2009-07-13 15:06:11 +0200 | [diff] [blame] | 596 | if (rport) { |
Christof Schmitt | 7093293 | 2009-04-17 15:08:15 +0200 | [diff] [blame] | 597 | fc_remote_port_delete(rport); |
Christof Schmitt | 379d6bf | 2009-07-13 15:06:11 +0200 | [diff] [blame] | 598 | port->rport = NULL; |
| 599 | } |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void zfcp_scsi_schedule_rport_register(struct zfcp_port *port) |
| 603 | { |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 604 | get_device(&port->dev); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 605 | port->rport_task = RPORT_ADD; |
| 606 | |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 607 | if (!queue_work(port->adapter->work_queue, &port->rport_work)) |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 608 | put_device(&port->dev); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | void zfcp_scsi_schedule_rport_block(struct zfcp_port *port) |
| 612 | { |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 613 | get_device(&port->dev); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 614 | port->rport_task = RPORT_DEL; |
| 615 | |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 616 | if (port->rport && queue_work(port->adapter->work_queue, |
| 617 | &port->rport_work)) |
Swen Schillig | a67417a | 2009-08-18 15:43:06 +0200 | [diff] [blame] | 618 | return; |
| 619 | |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 620 | put_device(&port->dev); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter) |
| 624 | { |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 625 | unsigned long flags; |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 626 | struct zfcp_port *port; |
| 627 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 628 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 629 | list_for_each_entry(port, &adapter->port_list, list) |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 630 | zfcp_scsi_schedule_rport_block(port); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 631 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | void zfcp_scsi_rport_work(struct work_struct *work) |
| 635 | { |
| 636 | struct zfcp_port *port = container_of(work, struct zfcp_port, |
| 637 | rport_work); |
| 638 | |
| 639 | while (port->rport_task) { |
| 640 | if (port->rport_task == RPORT_ADD) { |
| 641 | port->rport_task = RPORT_NONE; |
| 642 | zfcp_scsi_rport_register(port); |
| 643 | } else { |
| 644 | port->rport_task = RPORT_NONE; |
| 645 | zfcp_scsi_rport_block(port); |
| 646 | } |
| 647 | } |
| 648 | |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 649 | put_device(&port->dev); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 650 | } |
| 651 | |
Christof Schmitt | 5a7de55 | 2010-07-08 09:53:07 +0200 | [diff] [blame] | 652 | /** |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 653 | * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host |
| 654 | * @adapter: The adapter where to configure DIF/DIX for the SCSI host |
| 655 | */ |
| 656 | void zfcp_scsi_set_prot(struct zfcp_adapter *adapter) |
| 657 | { |
| 658 | unsigned int mask = 0; |
| 659 | unsigned int data_div; |
| 660 | struct Scsi_Host *shost = adapter->scsi_host; |
| 661 | |
| 662 | data_div = atomic_read(&adapter->status) & |
| 663 | ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED; |
| 664 | |
| 665 | if (enable_dif && |
| 666 | adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1) |
| 667 | mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 668 | |
| 669 | if (enable_dif && data_div && |
| 670 | adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) { |
| 671 | mask |= SHOST_DIX_TYPE1_PROTECTION; |
| 672 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP); |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 673 | shost->sg_prot_tablesize = adapter->qdio->max_sbale_per_req / 2; |
| 674 | shost->sg_tablesize = adapter->qdio->max_sbale_per_req / 2; |
| 675 | shost->max_sectors = shost->sg_tablesize * 8; |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | scsi_host_set_prot(shost, mask); |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error |
| 683 | * @scmd: The SCSI command to report the error for |
| 684 | * @ascq: The ASCQ to put in the sense buffer |
| 685 | * |
| 686 | * See the error handling in sd_done for the sense codes used here. |
| 687 | * Set DID_SOFT_ERROR to retry the request, if possible. |
| 688 | */ |
| 689 | void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq) |
| 690 | { |
| 691 | scsi_build_sense_buffer(1, scmd->sense_buffer, |
| 692 | ILLEGAL_REQUEST, 0x10, ascq); |
| 693 | set_driver_byte(scmd, DRIVER_SENSE); |
| 694 | scmd->result |= SAM_STAT_CHECK_CONDITION; |
| 695 | set_host_byte(scmd, DID_SOFT_ERROR); |
| 696 | } |
| 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | struct fc_function_template zfcp_transport_functions = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | .show_starget_port_id = 1, |
| 700 | .show_starget_port_name = 1, |
| 701 | .show_starget_node_name = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 702 | .show_rport_supported_classes = 1, |
Ralph Wuerthner | 75bfc28 | 2006-05-22 18:24:33 +0200 | [diff] [blame] | 703 | .show_rport_maxframe_size = 1, |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 704 | .show_rport_dev_loss_tmo = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 705 | .show_host_node_name = 1, |
| 706 | .show_host_port_name = 1, |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 707 | .show_host_permanent_port_name = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 708 | .show_host_supported_classes = 1, |
Christof Schmitt | 0fdd213 | 2009-11-24 16:54:17 +0100 | [diff] [blame] | 709 | .show_host_supported_fc4s = 1, |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 710 | .show_host_supported_speeds = 1, |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 711 | .show_host_maxframe_size = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 712 | .show_host_serial_number = 1, |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 713 | .get_fc_host_stats = zfcp_get_fc_host_stats, |
| 714 | .reset_fc_host_stats = zfcp_reset_fc_host_stats, |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 715 | .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo, |
Sven Schuetz | 85a8239 | 2008-06-10 18:20:59 +0200 | [diff] [blame] | 716 | .get_host_port_state = zfcp_get_host_port_state, |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 717 | .terminate_rport_io = zfcp_scsi_terminate_rport_io, |
Sven Schuetz | 85a8239 | 2008-06-10 18:20:59 +0200 | [diff] [blame] | 718 | .show_host_port_state = 1, |
Christof Schmitt | 0fdd213 | 2009-11-24 16:54:17 +0100 | [diff] [blame] | 719 | .show_host_active_fc4s = 1, |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 720 | .bsg_request = zfcp_fc_exec_bsg_job, |
Swen Schillig | 491ca44 | 2010-01-14 17:19:01 +0100 | [diff] [blame] | 721 | .bsg_timeout = zfcp_fc_timeout_bsg_job, |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 722 | /* no functions registered for following dynamic attributes but |
| 723 | directly set by LLDD */ |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 724 | .show_host_port_type = 1, |
Christof Schmitt | 038d944 | 2011-02-22 19:54:48 +0100 | [diff] [blame] | 725 | .show_host_symbolic_name = 1, |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 726 | .show_host_speed = 1, |
| 727 | .show_host_port_id = 1, |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 728 | .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | }; |