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