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