Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 1 | /* |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 2 | * This file is part of the zfcp device driver for |
| 3 | * FCP adapters for IBM System z9 and zSeries. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 5 | * (C) Copyright IBM Corp. 2002, 2006 |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_SCSI |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "zfcp_ext.h" |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 25 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | static void zfcp_scsi_slave_destroy(struct scsi_device *sdp); |
| 28 | static int zfcp_scsi_slave_alloc(struct scsi_device *sdp); |
| 29 | static int zfcp_scsi_slave_configure(struct scsi_device *sdp); |
| 30 | static int zfcp_scsi_queuecommand(struct scsi_cmnd *, |
| 31 | void (*done) (struct scsi_cmnd *)); |
| 32 | static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *); |
| 33 | static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *); |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 34 | static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 36 | static int zfcp_task_management_function(struct zfcp_unit *, u8, |
| 37 | struct scsi_cmnd *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 39 | static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int, |
| 40 | unsigned int, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | static struct device_attribute *zfcp_sysfs_sdev_attrs[]; |
Swen Schillig | 6d9d63b | 2008-04-24 19:35:54 +0200 | [diff] [blame] | 43 | static struct device_attribute *zfcp_a_stats_attrs[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | struct zfcp_data zfcp_data = { |
| 46 | .scsi_host_template = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 47 | .name = ZFCP_NAME, |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 48 | .module = THIS_MODULE, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 49 | .proc_name = "zfcp", |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 50 | .slave_alloc = zfcp_scsi_slave_alloc, |
| 51 | .slave_configure = zfcp_scsi_slave_configure, |
| 52 | .slave_destroy = zfcp_scsi_slave_destroy, |
| 53 | .queuecommand = zfcp_scsi_queuecommand, |
| 54 | .eh_abort_handler = zfcp_scsi_eh_abort_handler, |
| 55 | .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler, |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 56 | .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 57 | .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler, |
| 58 | .can_queue = 4096, |
| 59 | .this_id = -1, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 60 | .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ, |
| 61 | .cmd_per_lun = 1, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 62 | .use_clustering = 1, |
| 63 | .sdev_attrs = zfcp_sysfs_sdev_attrs, |
Swen Schillig | 8d1a006 | 2006-10-12 11:43:44 +0200 | [diff] [blame] | 64 | .max_sectors = ZFCP_MAX_SECTORS, |
Swen Schillig | 6d9d63b | 2008-04-24 19:35:54 +0200 | [diff] [blame] | 65 | .shost_attrs = zfcp_a_stats_attrs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }, |
| 67 | .driver_version = ZFCP_VERSION, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /* Find start of Response Information in FCP response unit*/ |
| 71 | char * |
| 72 | zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu) |
| 73 | { |
| 74 | char *fcp_rsp_info_ptr; |
| 75 | |
| 76 | fcp_rsp_info_ptr = |
| 77 | (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu)); |
| 78 | |
| 79 | return fcp_rsp_info_ptr; |
| 80 | } |
| 81 | |
| 82 | /* Find start of Sense Information in FCP response unit*/ |
| 83 | char * |
| 84 | zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu) |
| 85 | { |
| 86 | char *fcp_sns_info_ptr; |
| 87 | |
| 88 | fcp_sns_info_ptr = |
| 89 | (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu)); |
| 90 | if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid) |
| 91 | fcp_sns_info_ptr = (char *) fcp_sns_info_ptr + |
| 92 | fcp_rsp_iu->fcp_rsp_len; |
| 93 | |
| 94 | return fcp_sns_info_ptr; |
| 95 | } |
| 96 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 97 | static fcp_dl_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd) |
| 99 | { |
| 100 | int additional_length = fcp_cmd->add_fcp_cdb_length << 2; |
| 101 | fcp_dl_t *fcp_dl_addr; |
| 102 | |
| 103 | fcp_dl_addr = (fcp_dl_t *) |
| 104 | ((unsigned char *) fcp_cmd + |
| 105 | sizeof (struct fcp_cmnd_iu) + additional_length); |
| 106 | /* |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 107 | * fcp_dl_addr = start address of fcp_cmnd structure + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * size of fixed part + size of dynamically sized add_dcp_cdb field |
| 109 | * SEE FCP-2 documentation |
| 110 | */ |
| 111 | return fcp_dl_addr; |
| 112 | } |
| 113 | |
| 114 | fcp_dl_t |
| 115 | zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd) |
| 116 | { |
| 117 | return *zfcp_get_fcp_dl_ptr(fcp_cmd); |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl) |
| 122 | { |
| 123 | *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * note: it's a bit-or operation not an assignment |
| 128 | * regarding the specified byte |
| 129 | */ |
| 130 | static inline void |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 131 | set_byte(int *result, char status, char pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
| 133 | *result |= status << (pos * 8); |
| 134 | } |
| 135 | |
| 136 | void |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 137 | set_host_byte(int *result, char status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
| 139 | set_byte(result, status, 2); |
| 140 | } |
| 141 | |
| 142 | void |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 143 | set_driver_byte(int *result, char status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
| 145 | set_byte(result, status, 3); |
| 146 | } |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | static int |
| 149 | zfcp_scsi_slave_alloc(struct scsi_device *sdp) |
| 150 | { |
| 151 | struct zfcp_adapter *adapter; |
| 152 | struct zfcp_unit *unit; |
| 153 | unsigned long flags; |
Andreas Herrmann | fb121b0 | 2005-12-01 02:49:29 +0100 | [diff] [blame] | 154 | int retval = -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | adapter = (struct zfcp_adapter *) sdp->host->hostdata[0]; |
| 157 | if (!adapter) |
| 158 | goto out; |
| 159 | |
| 160 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 161 | unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun); |
Andreas Herrmann | ad58f7d | 2006-03-10 00:56:16 +0100 | [diff] [blame] | 162 | if (unit && atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED, |
| 163 | &unit->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | sdp->hostdata = unit; |
| 165 | unit->device = sdp; |
| 166 | zfcp_unit_get(unit); |
| 167 | retval = 0; |
| 168 | } |
| 169 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 170 | out: |
| 171 | return retval; |
| 172 | } |
| 173 | |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 174 | /** |
| 175 | * zfcp_scsi_slave_destroy - called when scsi device is removed |
| 176 | * |
| 177 | * Remove reference to associated scsi device for an zfcp_unit. |
| 178 | * Mark zfcp_unit as failed. The scsi device might be deleted via sysfs |
| 179 | * or a scan for this device might have failed. |
| 180 | */ |
| 181 | static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
| 183 | struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata; |
| 184 | |
| 185 | if (unit) { |
Andreas Herrmann | ad58f7d | 2006-03-10 00:56:16 +0100 | [diff] [blame] | 186 | atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | sdpnt->hostdata = NULL; |
| 188 | unit->device = NULL; |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 189 | zfcp_erp_unit_failed(unit, 12, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | zfcp_unit_put(unit); |
Christof Schmitt | 6b76a72 | 2007-08-28 09:30:59 +0200 | [diff] [blame] | 191 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at " |
| 193 | "address %p\n", sdpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 196 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | * called from scsi midlayer to allow finetuning of a device. |
| 198 | */ |
| 199 | static int |
| 200 | zfcp_scsi_slave_configure(struct scsi_device *sdp) |
| 201 | { |
| 202 | if (sdp->tagged_supported) |
| 203 | scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN); |
| 204 | else |
| 205 | scsi_adjust_queue_depth(sdp, 0, 1); |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function |
| 211 | * @scpnt: pointer to struct scsi_cmnd where result is set |
| 212 | * @result: result to be set in scpnt (e.g. DID_ERROR) |
| 213 | */ |
| 214 | static void |
| 215 | zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result) |
| 216 | { |
| 217 | set_host_byte(&scpnt->result, result); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 218 | if ((scpnt->device != NULL) && (scpnt->device->host != NULL)) |
| 219 | zfcp_scsi_dbf_event_result("fail", 4, |
| 220 | (struct zfcp_adapter*) scpnt->device->host->hostdata[0], |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 221 | scpnt, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | /* return directly */ |
| 223 | scpnt->scsi_done(scpnt); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and |
| 228 | * zfcp_scsi_command_sync |
| 229 | * @adapter: adapter where scsi command is issued |
| 230 | * @unit: unit to which scsi command is sent |
| 231 | * @scpnt: scsi command to be sent |
| 232 | * @timer: timer to be started if request is successfully initiated |
| 233 | * |
| 234 | * Note: In scsi_done function must be set in scpnt. |
| 235 | */ |
| 236 | int |
| 237 | zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 238 | struct scsi_cmnd *scpnt, int use_timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
| 240 | int tmp; |
| 241 | int retval; |
| 242 | |
| 243 | retval = 0; |
| 244 | |
| 245 | BUG_ON((adapter == NULL) || (adapter != unit->port->adapter)); |
| 246 | BUG_ON(scpnt->scsi_done == NULL); |
| 247 | |
| 248 | if (unlikely(NULL == unit)) { |
| 249 | zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT); |
| 250 | goto out; |
| 251 | } |
| 252 | |
| 253 | if (unlikely( |
| 254 | atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) || |
| 255 | !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) { |
| 256 | ZFCP_LOG_DEBUG("stopping SCSI I/O on unit 0x%016Lx on port " |
| 257 | "0x%016Lx on adapter %s\n", |
| 258 | unit->fcp_lun, unit->port->wwpn, |
| 259 | zfcp_get_busid_by_adapter(adapter)); |
| 260 | zfcp_scsi_command_fail(scpnt, DID_ERROR); |
| 261 | goto out; |
| 262 | } |
| 263 | |
Christof Schmitt | ba17242 | 2007-12-20 12:30:26 +0100 | [diff] [blame] | 264 | tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, use_timer, |
| 265 | ZFCP_REQ_AUTO_CLEANUP); |
| 266 | if (unlikely(tmp == -EBUSY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | ZFCP_LOG_DEBUG("adapter %s not ready or unit 0x%016Lx " |
| 268 | "on port 0x%016Lx in recovery\n", |
| 269 | zfcp_get_busid_by_unit(unit), |
| 270 | unit->fcp_lun, unit->port->wwpn); |
Andreas Herrmann | ad58f7d | 2006-03-10 00:56:16 +0100 | [diff] [blame] | 271 | zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | goto out; |
| 273 | } |
| 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (unlikely(tmp < 0)) { |
| 276 | ZFCP_LOG_DEBUG("error: initiation of Send FCP Cmnd failed\n"); |
| 277 | retval = SCSI_MLQUEUE_HOST_BUSY; |
| 278 | } |
| 279 | |
| 280 | out: |
| 281 | return retval; |
| 282 | } |
| 283 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 284 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt) |
| 286 | { |
| 287 | struct completion *wait = (struct completion *) scpnt->SCp.ptr; |
| 288 | complete(wait); |
| 289 | } |
| 290 | |
| 291 | |
| 292 | /** |
| 293 | * zfcp_scsi_command_sync - send a SCSI command and wait for completion |
| 294 | * @unit: unit where command is sent to |
| 295 | * @scpnt: scsi command to be sent |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 296 | * @use_timer: indicates whether timer should be setup or not |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | * Return: 0 |
| 298 | * |
| 299 | * Errors are indicated in scpnt->result |
| 300 | */ |
| 301 | int |
| 302 | zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 303 | int use_timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
| 305 | int ret; |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 306 | DECLARE_COMPLETION_ONSTACK(wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | scpnt->SCp.ptr = (void *) &wait; /* silent re-use */ |
| 309 | scpnt->scsi_done = zfcp_scsi_command_sync_handler; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 310 | ret = zfcp_scsi_command_async(unit->port->adapter, unit, scpnt, |
| 311 | use_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (ret == 0) |
| 313 | wait_for_completion(&wait); |
| 314 | |
| 315 | scpnt->SCp.ptr = NULL; |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * function: zfcp_scsi_queuecommand |
| 322 | * |
| 323 | * purpose: enqueues a SCSI command to the specified target device |
| 324 | * |
| 325 | * returns: 0 - success, SCSI command enqueued |
| 326 | * !0 - failure |
| 327 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 328 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt, |
| 330 | void (*done) (struct scsi_cmnd *)) |
| 331 | { |
| 332 | struct zfcp_unit *unit; |
| 333 | struct zfcp_adapter *adapter; |
| 334 | |
| 335 | /* reset the status for this request */ |
| 336 | scpnt->result = 0; |
| 337 | scpnt->host_scribble = NULL; |
| 338 | scpnt->scsi_done = done; |
| 339 | |
| 340 | /* |
| 341 | * figure out adapter and target device |
| 342 | * (stored there by zfcp_scsi_slave_alloc) |
| 343 | */ |
| 344 | adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0]; |
| 345 | unit = (struct zfcp_unit *) scpnt->device->hostdata; |
| 346 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 347 | return zfcp_scsi_command_async(adapter, unit, scpnt, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | static struct zfcp_unit * |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 351 | zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, unsigned int id, |
| 352 | unsigned int lun) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
| 354 | struct zfcp_port *port; |
| 355 | struct zfcp_unit *unit, *retval = NULL; |
| 356 | |
| 357 | list_for_each_entry(port, &adapter->port_list_head, list) { |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 358 | if (!port->rport || (id != port->rport->scsi_target_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | continue; |
Christof Schmitt | 6b76a72 | 2007-08-28 09:30:59 +0200 | [diff] [blame] | 360 | list_for_each_entry(unit, &port->unit_list_head, list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | if (lun == unit->scsi_lun) { |
| 362 | retval = unit; |
| 363 | goto out; |
| 364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | out: |
| 367 | return retval; |
| 368 | } |
| 369 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 370 | /** |
| 371 | * zfcp_scsi_eh_abort_handler - abort the specified SCSI command |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 372 | * @scpnt: pointer to scsi_cmnd to be aborted |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 373 | * Return: SUCCESS - command has been aborted and cleaned up in internal |
| 374 | * bookkeeping, SCSI stack won't be called for aborted command |
| 375 | * FAILED - otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | * |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 377 | * We do not need to care for a SCSI command which completes normally |
| 378 | * but late during this abort routine runs. We are allowed to return |
| 379 | * late commands to the SCSI stack. It tracks the state of commands and |
| 380 | * will handle late commands. (Usually, the normal completion of late |
| 381 | * commands is ignored with respect to the running abort operation.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 383 | static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 385 | struct Scsi_Host *scsi_host; |
| 386 | struct zfcp_adapter *adapter; |
| 387 | struct zfcp_unit *unit; |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 388 | struct zfcp_fsf_req *fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | unsigned long flags; |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 390 | unsigned long old_req_id; |
| 391 | int retval = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 393 | scsi_host = scpnt->device->host; |
| 394 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
| 395 | unit = (struct zfcp_unit *) scpnt->device->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n", |
| 398 | scpnt, zfcp_get_busid_by_adapter(adapter)); |
| 399 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 400 | /* avoid race condition between late normal completion and abort */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | write_lock_irqsave(&adapter->abort_lock, flags); |
| 402 | |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 403 | /* Check whether corresponding fsf_req is still pending */ |
| 404 | spin_lock(&adapter->req_list_lock); |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 405 | fsf_req = zfcp_reqlist_find(adapter, |
| 406 | (unsigned long) scpnt->host_scribble); |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 407 | spin_unlock(&adapter->req_list_lock); |
| 408 | if (!fsf_req) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 410 | zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, NULL, 0); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 411 | retval = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | goto out; |
| 413 | } |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 414 | fsf_req->data = 0; |
| 415 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING; |
| 416 | old_req_id = fsf_req->req_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 418 | /* don't access old fsf_req after releasing the abort_lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 420 | |
| 421 | fsf_req = zfcp_fsf_abort_fcp_command(old_req_id, adapter, unit, 0); |
| 422 | if (!fsf_req) { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 423 | ZFCP_LOG_INFO("error: initiation of Abort FCP Cmnd failed\n"); |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 424 | zfcp_scsi_dbf_event_abort("nres", adapter, scpnt, NULL, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 425 | old_req_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | retval = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | goto out; |
| 428 | } |
| 429 | |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 430 | __wait_event(fsf_req->completion_wq, |
| 431 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 432 | |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 433 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) { |
| 434 | zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, fsf_req, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | retval = SUCCESS; |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 436 | } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) { |
| 437 | zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, fsf_req, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | retval = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } else { |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 440 | zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, fsf_req, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | retval = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 443 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | return retval; |
| 446 | } |
| 447 | |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 448 | static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
| 450 | int retval; |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 451 | struct zfcp_unit *unit = scpnt->device->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (!unit) { |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 454 | WARN_ON(1); |
| 455 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 457 | retval = zfcp_task_management_function(unit, |
| 458 | FCP_LOGICAL_UNIT_RESET, |
| 459 | scpnt); |
| 460 | return retval ? FAILED : SUCCESS; |
| 461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 463 | static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt) |
| 464 | { |
| 465 | int retval; |
| 466 | struct zfcp_unit *unit = scpnt->device->hostdata; |
| 467 | |
| 468 | if (!unit) { |
| 469 | WARN_ON(1); |
| 470 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 472 | retval = zfcp_task_management_function(unit, FCP_TARGET_RESET, scpnt); |
Christof Schmitt | 74b2e04 | 2008-03-03 12:19:28 +0100 | [diff] [blame] | 473 | return retval ? FAILED : SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static int |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 477 | zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags, |
| 478 | struct scsi_cmnd *scpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | struct zfcp_adapter *adapter = unit->port->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | struct zfcp_fsf_req *fsf_req; |
Andreas Herrmann | 77eb169 | 2005-09-13 21:48:33 +0200 | [diff] [blame] | 482 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | /* issue task management function */ |
| 485 | fsf_req = zfcp_fsf_send_fcp_command_task_management |
| 486 | (adapter, unit, tm_flags, 0); |
| 487 | if (!fsf_req) { |
| 488 | ZFCP_LOG_INFO("error: creation of task management request " |
| 489 | "failed for unit 0x%016Lx on port 0x%016Lx on " |
| 490 | "adapter %s\n", unit->fcp_lun, unit->port->wwpn, |
| 491 | zfcp_get_busid_by_adapter(adapter)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 492 | zfcp_scsi_dbf_event_devreset("nres", tm_flags, unit, scpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | retval = -ENOMEM; |
| 494 | goto out; |
| 495 | } |
| 496 | |
Andreas Herrmann | 77eb169 | 2005-09-13 21:48:33 +0200 | [diff] [blame] | 497 | __wait_event(fsf_req->completion_wq, |
| 498 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 499 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 500 | /* |
| 501 | * check completion status of task management function |
| 502 | */ |
| 503 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) { |
| 504 | zfcp_scsi_dbf_event_devreset("fail", tm_flags, unit, scpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | retval = -EIO; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 506 | } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP) { |
| 507 | zfcp_scsi_dbf_event_devreset("nsup", tm_flags, unit, scpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | retval = -ENOTSUPP; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 509 | } else |
| 510 | zfcp_scsi_dbf_event_devreset("okay", tm_flags, unit, scpnt); |
Andreas Herrmann | 77eb169 | 2005-09-13 21:48:33 +0200 | [diff] [blame] | 511 | |
| 512 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | out: |
| 514 | return retval; |
| 515 | } |
| 516 | |
Andreas Herrmann | 810f1e3e | 2005-09-13 21:49:52 +0200 | [diff] [blame] | 517 | /** |
Christof Schmitt | a11b474 | 2007-11-05 12:37:43 +0100 | [diff] [blame] | 518 | * zfcp_scsi_eh_host_reset_handler - handler for host reset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 520 | static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 522 | struct zfcp_unit *unit; |
| 523 | struct zfcp_adapter *adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 525 | unit = (struct zfcp_unit*) scpnt->device->hostdata; |
| 526 | adapter = unit->port->adapter; |
| 527 | |
Christof Schmitt | a11b474 | 2007-11-05 12:37:43 +0100 | [diff] [blame] | 528 | ZFCP_LOG_NORMAL("host reset because of problems with " |
Christof Schmitt | 345bfea | 2007-11-05 12:37:44 +0100 | [diff] [blame] | 529 | "unit 0x%016Lx on port 0x%016Lx, adapter %s\n", |
| 530 | unit->fcp_lun, unit->port->wwpn, |
| 531 | zfcp_get_busid_by_adapter(unit->port->adapter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 533 | zfcp_erp_adapter_reopen(adapter, 0, 141, scpnt); |
Andreas Herrmann | 8165428 | 2006-09-18 22:30:36 +0200 | [diff] [blame] | 534 | zfcp_erp_wait(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Andreas Herrmann | 810f1e3e | 2005-09-13 21:49:52 +0200 | [diff] [blame] | 536 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | int |
| 540 | zfcp_adapter_scsi_register(struct zfcp_adapter *adapter) |
| 541 | { |
| 542 | int retval = 0; |
| 543 | static unsigned int unique_id = 0; |
| 544 | |
Michael Loehr | 9f28745 | 2007-05-09 11:01:24 +0200 | [diff] [blame] | 545 | if (adapter->scsi_host) |
| 546 | goto out; |
| 547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | /* register adapter as SCSI host with mid layer of SCSI stack */ |
| 549 | adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template, |
| 550 | sizeof (struct zfcp_adapter *)); |
| 551 | if (!adapter->scsi_host) { |
| 552 | ZFCP_LOG_NORMAL("error: registration with SCSI stack failed " |
| 553 | "for adapter %s ", |
| 554 | zfcp_get_busid_by_adapter(adapter)); |
| 555 | retval = -EIO; |
| 556 | goto out; |
| 557 | } |
| 558 | ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host); |
| 559 | |
| 560 | /* tell the SCSI stack some characteristics of this adapter */ |
| 561 | adapter->scsi_host->max_id = 1; |
| 562 | adapter->scsi_host->max_lun = 1; |
| 563 | adapter->scsi_host->max_channel = 0; |
| 564 | adapter->scsi_host->unique_id = unique_id++; /* FIXME */ |
| 565 | adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH; |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 566 | adapter->scsi_host->transportt = zfcp_data.scsi_transport_template; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | /* |
| 569 | * save a pointer to our own adapter data structure within |
| 570 | * hostdata field of SCSI host data structure |
| 571 | */ |
| 572 | adapter->scsi_host->hostdata[0] = (unsigned long) adapter; |
| 573 | |
| 574 | if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) { |
| 575 | scsi_host_put(adapter->scsi_host); |
| 576 | retval = -EIO; |
| 577 | goto out; |
| 578 | } |
| 579 | atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status); |
| 580 | out: |
| 581 | return retval; |
| 582 | } |
| 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | void |
| 585 | zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter) |
| 586 | { |
| 587 | struct Scsi_Host *shost; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 588 | struct zfcp_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
| 590 | shost = adapter->scsi_host; |
| 591 | if (!shost) |
| 592 | return; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 593 | read_lock_irq(&zfcp_data.config_lock); |
| 594 | list_for_each_entry(port, &adapter->port_list_head, list) |
| 595 | if (port->rport) |
| 596 | port->rport = NULL; |
| 597 | read_unlock_irq(&zfcp_data.config_lock); |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 598 | fc_remove_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | scsi_remove_host(shost); |
| 600 | scsi_host_put(shost); |
| 601 | adapter->scsi_host = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status); |
| 603 | |
| 604 | return; |
| 605 | } |
| 606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | /* |
| 608 | * Support functions for FC transport class |
| 609 | */ |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 610 | static struct fc_host_statistics* |
| 611 | zfcp_init_fc_host_stats(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 613 | struct fc_host_statistics *fc_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 615 | if (!adapter->fc_stats) { |
| 616 | fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL); |
| 617 | if (!fc_stats) |
| 618 | return NULL; |
| 619 | adapter->fc_stats = fc_stats; /* freed in adater_dequeue */ |
| 620 | } |
| 621 | memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats)); |
| 622 | return adapter->fc_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static void |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 626 | zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats, |
| 627 | struct fsf_qtcb_bottom_port *data, |
| 628 | struct fsf_qtcb_bottom_port *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 630 | fc_stats->seconds_since_last_reset = data->seconds_since_last_reset - |
| 631 | old->seconds_since_last_reset; |
| 632 | fc_stats->tx_frames = data->tx_frames - old->tx_frames; |
| 633 | fc_stats->tx_words = data->tx_words - old->tx_words; |
| 634 | fc_stats->rx_frames = data->rx_frames - old->rx_frames; |
| 635 | fc_stats->rx_words = data->rx_words - old->rx_words; |
| 636 | fc_stats->lip_count = data->lip - old->lip; |
| 637 | fc_stats->nos_count = data->nos - old->nos; |
| 638 | fc_stats->error_frames = data->error_frames - old->error_frames; |
| 639 | fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames; |
| 640 | fc_stats->link_failure_count = data->link_failure - old->link_failure; |
| 641 | fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync; |
| 642 | fc_stats->loss_of_signal_count = data->loss_of_signal - |
| 643 | old->loss_of_signal; |
| 644 | fc_stats->prim_seq_protocol_err_count = data->psp_error_counts - |
| 645 | old->psp_error_counts; |
| 646 | fc_stats->invalid_tx_word_count = data->invalid_tx_words - |
| 647 | old->invalid_tx_words; |
| 648 | fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs; |
| 649 | fc_stats->fcp_input_requests = data->input_requests - |
| 650 | old->input_requests; |
| 651 | fc_stats->fcp_output_requests = data->output_requests - |
| 652 | old->output_requests; |
| 653 | fc_stats->fcp_control_requests = data->control_requests - |
| 654 | old->control_requests; |
| 655 | fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb; |
| 656 | fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static void |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 660 | zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats, |
| 661 | struct fsf_qtcb_bottom_port *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 663 | fc_stats->seconds_since_last_reset = data->seconds_since_last_reset; |
| 664 | fc_stats->tx_frames = data->tx_frames; |
| 665 | fc_stats->tx_words = data->tx_words; |
| 666 | fc_stats->rx_frames = data->rx_frames; |
| 667 | fc_stats->rx_words = data->rx_words; |
| 668 | fc_stats->lip_count = data->lip; |
| 669 | fc_stats->nos_count = data->nos; |
| 670 | fc_stats->error_frames = data->error_frames; |
| 671 | fc_stats->dumped_frames = data->dumped_frames; |
| 672 | fc_stats->link_failure_count = data->link_failure; |
| 673 | fc_stats->loss_of_sync_count = data->loss_of_sync; |
| 674 | fc_stats->loss_of_signal_count = data->loss_of_signal; |
| 675 | fc_stats->prim_seq_protocol_err_count = data->psp_error_counts; |
| 676 | fc_stats->invalid_tx_word_count = data->invalid_tx_words; |
| 677 | fc_stats->invalid_crc_count = data->invalid_crcs; |
| 678 | fc_stats->fcp_input_requests = data->input_requests; |
| 679 | fc_stats->fcp_output_requests = data->output_requests; |
| 680 | fc_stats->fcp_control_requests = data->control_requests; |
| 681 | fc_stats->fcp_input_megabytes = data->input_mb; |
| 682 | fc_stats->fcp_output_megabytes = data->output_mb; |
| 683 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 685 | /** |
| 686 | * zfcp_get_fc_host_stats - provide fc_host_statistics for scsi_transport_fc |
| 687 | * |
| 688 | * assumption: scsi_transport_fc synchronizes calls of |
| 689 | * get_fc_host_stats and reset_fc_host_stats |
| 690 | * (XXX to be checked otherwise introduce locking) |
| 691 | */ |
| 692 | static struct fc_host_statistics * |
| 693 | zfcp_get_fc_host_stats(struct Scsi_Host *shost) |
| 694 | { |
| 695 | struct zfcp_adapter *adapter; |
| 696 | struct fc_host_statistics *fc_stats; |
| 697 | struct fsf_qtcb_bottom_port *data; |
| 698 | int ret; |
| 699 | |
| 700 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
| 701 | fc_stats = zfcp_init_fc_host_stats(adapter); |
| 702 | if (!fc_stats) |
| 703 | return NULL; |
| 704 | |
Andreas Herrmann | ec4081c | 2006-05-22 18:17:30 +0200 | [diff] [blame] | 705 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 706 | if (!data) |
| 707 | return NULL; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 708 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 709 | ret = zfcp_fsf_exchange_port_data_sync(adapter, data); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 710 | if (ret) { |
| 711 | kfree(data); |
| 712 | return NULL; /* XXX return zeroed fc_stats? */ |
| 713 | } |
| 714 | |
| 715 | if (adapter->stats_reset && |
| 716 | ((jiffies/HZ - adapter->stats_reset) < |
| 717 | data->seconds_since_last_reset)) { |
| 718 | zfcp_adjust_fc_host_stats(fc_stats, data, |
| 719 | adapter->stats_reset_data); |
| 720 | } else |
| 721 | zfcp_set_fc_host_stats(fc_stats, data); |
| 722 | |
| 723 | kfree(data); |
| 724 | return fc_stats; |
| 725 | } |
| 726 | |
| 727 | static void |
| 728 | zfcp_reset_fc_host_stats(struct Scsi_Host *shost) |
| 729 | { |
| 730 | struct zfcp_adapter *adapter; |
| 731 | struct fsf_qtcb_bottom_port *data, *old_data; |
| 732 | int ret; |
| 733 | |
| 734 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
Andreas Herrmann | ec4081c | 2006-05-22 18:17:30 +0200 | [diff] [blame] | 735 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 736 | if (!data) |
| 737 | return; |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 738 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 739 | ret = zfcp_fsf_exchange_port_data_sync(adapter, data); |
Heiko Carstens | 83f6d6d | 2007-08-08 10:47:02 +0200 | [diff] [blame] | 740 | if (ret) { |
| 741 | kfree(data); |
| 742 | } else { |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 743 | adapter->stats_reset = jiffies/HZ; |
| 744 | old_data = adapter->stats_reset_data; |
| 745 | adapter->stats_reset_data = data; /* finally freed in |
| 746 | adater_dequeue */ |
| 747 | kfree(old_data); |
| 748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 751 | static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout) |
| 752 | { |
| 753 | rport->dev_loss_tmo = timeout; |
| 754 | } |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | struct fc_function_template zfcp_transport_functions = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | .show_starget_port_id = 1, |
| 758 | .show_starget_port_name = 1, |
| 759 | .show_starget_node_name = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 760 | .show_rport_supported_classes = 1, |
Ralph Wuerthner | 75bfc28 | 2006-05-22 18:24:33 +0200 | [diff] [blame] | 761 | .show_rport_maxframe_size = 1, |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 762 | .show_rport_dev_loss_tmo = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 763 | .show_host_node_name = 1, |
| 764 | .show_host_port_name = 1, |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 765 | .show_host_permanent_port_name = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 766 | .show_host_supported_classes = 1, |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 767 | .show_host_supported_speeds = 1, |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 768 | .show_host_maxframe_size = 1, |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 769 | .show_host_serial_number = 1, |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 770 | .get_fc_host_stats = zfcp_get_fc_host_stats, |
| 771 | .reset_fc_host_stats = zfcp_reset_fc_host_stats, |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 772 | .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo, |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 773 | /* no functions registered for following dynamic attributes but |
| 774 | directly set by LLDD */ |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 775 | .show_host_port_type = 1, |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 776 | .show_host_speed = 1, |
| 777 | .show_host_port_id = 1, |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 778 | .disable_target_scan = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | /** |
| 782 | * ZFCP_DEFINE_SCSI_ATTR |
| 783 | * @_name: name of show attribute |
| 784 | * @_format: format string |
| 785 | * @_value: value to print |
| 786 | * |
| 787 | * Generates attribute for a unit. |
| 788 | */ |
| 789 | #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \ |
Yani Ioannou | 10523b3 | 2005-05-17 06:43:37 -0400 | [diff] [blame] | 790 | static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | char *buf) \ |
| 792 | { \ |
| 793 | struct scsi_device *sdev; \ |
| 794 | struct zfcp_unit *unit; \ |
| 795 | \ |
| 796 | sdev = to_scsi_device(dev); \ |
| 797 | unit = sdev->hostdata; \ |
| 798 | return sprintf(buf, _format, _value); \ |
| 799 | } \ |
| 800 | \ |
| 801 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL); |
| 802 | |
| 803 | ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit)); |
| 804 | ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn); |
| 805 | ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun); |
| 806 | |
| 807 | static struct device_attribute *zfcp_sysfs_sdev_attrs[] = { |
| 808 | &dev_attr_fcp_lun, |
| 809 | &dev_attr_wwpn, |
| 810 | &dev_attr_hba_id, |
| 811 | NULL |
| 812 | }; |
| 813 | |
Swen Schillig | 6d9d63b | 2008-04-24 19:35:54 +0200 | [diff] [blame] | 814 | static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev, |
| 815 | struct device_attribute *attr, |
| 816 | char *buf) |
| 817 | { |
| 818 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
| 819 | struct fsf_qtcb_bottom_port *qtcb_port; |
| 820 | int retval; |
| 821 | struct zfcp_adapter *adapter; |
| 822 | |
| 823 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
| 824 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
| 825 | return -EOPNOTSUPP; |
| 826 | |
| 827 | qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL); |
| 828 | if (!qtcb_port) |
| 829 | return -ENOMEM; |
| 830 | |
| 831 | retval = zfcp_fsf_exchange_port_data_sync(adapter, qtcb_port); |
| 832 | if (!retval) |
| 833 | retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util, |
| 834 | qtcb_port->cb_util, qtcb_port->a_util); |
| 835 | kfree(qtcb_port); |
| 836 | return retval; |
| 837 | } |
| 838 | |
| 839 | static int zfcp_sysfs_adapter_ex_config(struct device *dev, |
| 840 | struct fsf_statistics_info *stat_inf) |
| 841 | { |
| 842 | int retval; |
| 843 | struct fsf_qtcb_bottom_config *qtcb_config; |
| 844 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
| 845 | struct zfcp_adapter *adapter; |
| 846 | |
| 847 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
| 848 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
| 849 | return -EOPNOTSUPP; |
| 850 | |
| 851 | qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config), |
| 852 | GFP_KERNEL); |
| 853 | if (!qtcb_config) |
| 854 | return -ENOMEM; |
| 855 | |
| 856 | retval = zfcp_fsf_exchange_config_data_sync(adapter, qtcb_config); |
| 857 | if (!retval) |
| 858 | *stat_inf = qtcb_config->stat_info; |
| 859 | |
| 860 | kfree(qtcb_config); |
| 861 | return retval; |
| 862 | } |
| 863 | |
| 864 | static ssize_t zfcp_sysfs_adapter_request_show(struct device *dev, |
| 865 | struct device_attribute *attr, |
| 866 | char *buf) |
| 867 | { |
| 868 | struct fsf_statistics_info stat_info; |
| 869 | int retval; |
| 870 | |
| 871 | retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); |
| 872 | if (retval) |
| 873 | return retval; |
| 874 | |
| 875 | return sprintf(buf, "%llu %llu %llu\n", |
| 876 | (unsigned long long) stat_info.input_req, |
| 877 | (unsigned long long) stat_info.output_req, |
| 878 | (unsigned long long) stat_info.control_req); |
| 879 | } |
| 880 | |
| 881 | static ssize_t zfcp_sysfs_adapter_mb_show(struct device *dev, |
| 882 | struct device_attribute *attr, |
| 883 | char *buf) |
| 884 | { |
| 885 | struct fsf_statistics_info stat_info; |
| 886 | int retval; |
| 887 | |
| 888 | retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); |
| 889 | if (retval) |
| 890 | return retval; |
| 891 | |
| 892 | return sprintf(buf, "%llu %llu\n", |
| 893 | (unsigned long long) stat_info.input_mb, |
| 894 | (unsigned long long) stat_info.output_mb); |
| 895 | } |
| 896 | |
| 897 | static ssize_t zfcp_sysfs_adapter_sec_active_show(struct device *dev, |
| 898 | struct device_attribute *attr, |
| 899 | char *buf) |
| 900 | { |
| 901 | struct fsf_statistics_info stat_info; |
| 902 | int retval; |
| 903 | |
| 904 | retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); |
| 905 | if (retval) |
| 906 | return retval; |
| 907 | |
| 908 | return sprintf(buf, "%llu\n", |
| 909 | (unsigned long long) stat_info.seconds_act); |
| 910 | } |
| 911 | |
| 912 | static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL); |
| 913 | static DEVICE_ATTR(requests, S_IRUGO, zfcp_sysfs_adapter_request_show, NULL); |
| 914 | static DEVICE_ATTR(megabytes, S_IRUGO, zfcp_sysfs_adapter_mb_show, NULL); |
| 915 | static DEVICE_ATTR(seconds_active, S_IRUGO, |
| 916 | zfcp_sysfs_adapter_sec_active_show, NULL); |
| 917 | |
| 918 | static struct device_attribute *zfcp_a_stats_attrs[] = { |
| 919 | &dev_attr_utilization, |
| 920 | &dev_attr_requests, |
| 921 | &dev_attr_megabytes, |
| 922 | &dev_attr_seconds_active, |
| 923 | NULL |
| 924 | }; |
| 925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | #undef ZFCP_LOG_AREA |