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