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