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