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