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