3 * linux/drivers/s390/scsi/zfcp_scsi.c
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_SCSI
34 #define ZFCP_SCSI_REVISION "$Revision: 1.74 $"
38 static void zfcp_scsi_slave_destroy(struct scsi_device *sdp);
39 static int zfcp_scsi_slave_alloc(struct scsi_device *sdp);
40 static int zfcp_scsi_slave_configure(struct scsi_device *sdp);
41 static int zfcp_scsi_queuecommand(struct scsi_cmnd *,
42 void (*done) (struct scsi_cmnd *));
43 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *);
44 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *);
45 static int zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *);
46 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *);
47 static int zfcp_task_management_function(struct zfcp_unit *, u8);
49 static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int, scsi_id_t,
51 static struct zfcp_port *zfcp_port_lookup(struct zfcp_adapter *, int,
54 static struct device_attribute *zfcp_sysfs_sdev_attrs[];
56 struct scsi_transport_template *zfcp_transport_template;
58 struct zfcp_data zfcp_data = {
59 .scsi_host_template = {
64 slave_alloc: zfcp_scsi_slave_alloc,
65 slave_configure: zfcp_scsi_slave_configure,
66 slave_destroy: zfcp_scsi_slave_destroy,
67 queuecommand: zfcp_scsi_queuecommand,
68 eh_abort_handler: zfcp_scsi_eh_abort_handler,
69 eh_device_reset_handler: zfcp_scsi_eh_device_reset_handler,
70 eh_bus_reset_handler: zfcp_scsi_eh_bus_reset_handler,
71 eh_host_reset_handler: zfcp_scsi_eh_host_reset_handler,
72 /* FIXME(openfcp): Tune */
77 * one less? can zfcp_create_sbale cope with it?
79 sg_tablesize: ZFCP_MAX_SBALES_PER_REQ,
83 sdev_attrs: zfcp_sysfs_sdev_attrs,
85 .driver_version = ZFCP_VERSION,
86 /* rest initialised with zeros */
89 /* Find start of Response Information in FCP response unit*/
91 zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
93 char *fcp_rsp_info_ptr;
96 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
98 return fcp_rsp_info_ptr;
101 /* Find start of Sense Information in FCP response unit*/
103 zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
105 char *fcp_sns_info_ptr;
108 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
109 if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)
110 fcp_sns_info_ptr = (char *) fcp_sns_info_ptr +
111 fcp_rsp_iu->fcp_rsp_len;
113 return fcp_sns_info_ptr;
117 zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd)
119 int additional_length = fcp_cmd->add_fcp_cdb_length << 2;
120 fcp_dl_t *fcp_dl_addr;
122 fcp_dl_addr = (fcp_dl_t *)
123 ((unsigned char *) fcp_cmd +
124 sizeof (struct fcp_cmnd_iu) + additional_length);
126 * fcp_dl_addr = start address of fcp_cmnd structure +
127 * size of fixed part + size of dynamically sized add_dcp_cdb field
128 * SEE FCP-2 documentation
134 zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd)
136 return *zfcp_get_fcp_dl_ptr(fcp_cmd);
140 zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl)
142 *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl;
146 * note: it's a bit-or operation not an assignment
147 * regarding the specified byte
150 set_byte(u32 * result, char status, char pos)
152 *result |= status << (pos * 8);
156 set_host_byte(u32 * result, char status)
158 set_byte(result, status, 2);
162 set_driver_byte(u32 * result, char status)
164 set_byte(result, status, 3);
168 * function: zfcp_scsi_slave_alloc
176 zfcp_scsi_slave_alloc(struct scsi_device *sdp)
178 struct zfcp_adapter *adapter;
179 struct zfcp_unit *unit;
181 int retval = -ENODEV;
183 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
187 read_lock_irqsave(&zfcp_data.config_lock, flags);
188 unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun);
190 sdp->hostdata = unit;
195 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
201 * function: zfcp_scsi_slave_destroy
209 zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
211 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
214 sdpnt->hostdata = NULL;
218 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at "
219 "address %p\n", sdpnt);
224 * called from scsi midlayer to allow finetuning of a device.
227 zfcp_scsi_slave_configure(struct scsi_device *sdp)
229 if (sdp->tagged_supported)
230 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN);
232 scsi_adjust_queue_depth(sdp, 0, 1);
237 * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function
238 * @scpnt: pointer to struct scsi_cmnd where result is set
239 * @result: result to be set in scpnt (e.g. DID_ERROR)
242 zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
244 set_host_byte(&scpnt->result, result);
245 zfcp_cmd_dbf_event_scsi("failing", scpnt);
246 /* return directly */
247 scpnt->scsi_done(scpnt);
251 * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and
252 * zfcp_scsi_command_sync
253 * @adapter: adapter where scsi command is issued
254 * @unit: unit to which scsi command is sent
255 * @scpnt: scsi command to be sent
256 * @timer: timer to be started if request is successfully initiated
258 * Note: In scsi_done function must be set in scpnt.
261 zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit,
262 struct scsi_cmnd *scpnt, struct timer_list *timer)
269 BUG_ON((adapter == NULL) || (adapter != unit->port->adapter));
270 BUG_ON(scpnt->scsi_done == NULL);
272 if (unlikely(NULL == unit)) {
273 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
278 atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) ||
279 !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) {
280 ZFCP_LOG_DEBUG("stopping SCSI I/O on unit 0x%016Lx on port "
281 "0x%016Lx on adapter %s\n",
282 unit->fcp_lun, unit->port->wwpn,
283 zfcp_get_busid_by_adapter(adapter));
284 zfcp_scsi_command_fail(scpnt, DID_ERROR);
289 !atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))) {
290 ZFCP_LOG_DEBUG("adapter %s not ready or unit 0x%016Lx "
291 "on port 0x%016Lx in recovery\n",
292 zfcp_get_busid_by_unit(unit),
293 unit->fcp_lun, unit->port->wwpn);
294 retval = SCSI_MLQUEUE_DEVICE_BUSY;
298 tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, timer,
299 ZFCP_REQ_AUTO_CLEANUP);
301 if (unlikely(tmp < 0)) {
302 ZFCP_LOG_DEBUG("error: initiation of Send FCP Cmnd failed\n");
303 retval = SCSI_MLQUEUE_HOST_BUSY;
311 zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt)
313 struct completion *wait = (struct completion *) scpnt->SCp.ptr;
319 * zfcp_scsi_command_sync - send a SCSI command and wait for completion
320 * @unit: unit where command is sent to
321 * @scpnt: scsi command to be sent
322 * @timer: timer to be started if request is successfully initiated
325 * Errors are indicated in scpnt->result
328 zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt,
329 struct timer_list *timer)
332 DECLARE_COMPLETION(wait);
334 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */
335 scpnt->scsi_done = zfcp_scsi_command_sync_handler;
336 ret = zfcp_scsi_command_async(unit->port->adapter, unit, scpnt, timer);
338 wait_for_completion(&wait);
340 scpnt->SCp.ptr = NULL;
346 * function: zfcp_scsi_queuecommand
348 * purpose: enqueues a SCSI command to the specified target device
350 * returns: 0 - success, SCSI command enqueued
354 zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
355 void (*done) (struct scsi_cmnd *))
357 struct zfcp_unit *unit;
358 struct zfcp_adapter *adapter;
360 /* reset the status for this request */
362 scpnt->host_scribble = NULL;
363 scpnt->scsi_done = done;
366 * figure out adapter and target device
367 * (stored there by zfcp_scsi_slave_alloc)
369 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
370 unit = (struct zfcp_unit *) scpnt->device->hostdata;
372 return zfcp_scsi_command_async(adapter, unit, scpnt, NULL);
376 * function: zfcp_unit_lookup
384 static struct zfcp_unit *
385 zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id,
388 struct zfcp_port *port;
389 struct zfcp_unit *unit, *retval = NULL;
391 list_for_each_entry(port, &adapter->port_list_head, list) {
392 if (id != port->scsi_id)
394 list_for_each_entry(unit, &port->unit_list_head, list) {
395 if (lun == unit->scsi_lun) {
405 static struct zfcp_port *
406 zfcp_port_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id)
408 struct zfcp_port *port;
410 list_for_each_entry(port, &adapter->port_list_head, list) {
411 if (id == port->scsi_id)
414 return (struct zfcp_port *) NULL;
418 * function: zfcp_scsi_eh_abort_handler
420 * purpose: tries to abort the specified (timed out) SCSI command
422 * note: We do not need to care for a SCSI command which completes
423 * normally but late during this abort routine runs.
424 * We are allowed to return late commands to the SCSI stack.
425 * It tracks the state of commands and will handle late commands.
426 * (Usually, the normal completion of late commands is ignored with
427 * respect to the running abort operation. Grep for 'done_late'
428 * in the SCSI stacks sources.)
430 * returns: SUCCESS - command has been aborted and cleaned up in internal
432 * SCSI stack won't be called for aborted command
436 __zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
438 int retval = SUCCESS;
439 struct zfcp_fsf_req *new_fsf_req, *old_fsf_req;
440 struct zfcp_adapter *adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
441 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
442 struct zfcp_port *port = unit->port;
443 struct Scsi_Host *scsi_host = scpnt->device->host;
444 union zfcp_req_data *req_data = NULL;
448 /* the components of a abort_dbf record (fixed size record) */
449 u64 dbf_scsi_cmnd = (unsigned long) scpnt;
450 char dbf_opcode[ZFCP_ABORT_DBF_LENGTH];
451 wwn_t dbf_wwn = port->wwpn;
452 fcp_lun_t dbf_fcp_lun = unit->fcp_lun;
453 u64 dbf_retries = scpnt->retries;
454 u64 dbf_allowed = scpnt->allowed;
457 u64 dbf_fsf_status = 0;
458 u64 dbf_fsf_qual[2] = { 0, 0 };
459 char dbf_result[ZFCP_ABORT_DBF_LENGTH] = "##undef";
461 memset(dbf_opcode, 0, ZFCP_ABORT_DBF_LENGTH);
464 min(scpnt->cmd_len, (unsigned char) ZFCP_ABORT_DBF_LENGTH));
466 ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n",
467 scpnt, zfcp_get_busid_by_adapter(adapter));
469 spin_unlock_irq(scsi_host->host_lock);
472 * Race condition between normal (late) completion and abort has
474 * The entirity of all accesses to scsi_req have to be atomic.
475 * scsi_req is usually part of the fsf_req and thus we block the
476 * release of fsf_req as long as we need to access scsi_req.
478 write_lock_irqsave(&adapter->abort_lock, flags);
481 * Check whether command has just completed and can not be aborted.
482 * Even if the command has just been completed late, we can access
483 * scpnt since the SCSI stack does not release it at least until
484 * this routine returns. (scpnt is parameter passed to this routine
485 * and must not disappear during abort even on late completion.)
487 req_data = (union zfcp_req_data *) scpnt->host_scribble;
489 ZFCP_LOG_DEBUG("req_data=%p\n", req_data);
491 ZFCP_LOG_DEBUG("late command completion overtook abort\n");
494 * Do not initiate abort but return SUCCESS.
496 write_unlock_irqrestore(&adapter->abort_lock, flags);
498 strncpy(dbf_result, "##late1", ZFCP_ABORT_DBF_LENGTH);
502 /* Figure out which fsf_req needs to be aborted. */
503 old_fsf_req = req_data->send_fcp_command_task.fsf_req;
505 dbf_fsf_req = (unsigned long) old_fsf_req;
507 (jiffies - req_data->send_fcp_command_task.start_jiffies) / HZ;
509 ZFCP_LOG_DEBUG("old_fsf_req=%p\n", old_fsf_req);
511 write_unlock_irqrestore(&adapter->abort_lock, flags);
512 ZFCP_LOG_NORMAL("bug: no old fsf request found\n");
513 ZFCP_LOG_NORMAL("req_data:\n");
514 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
515 (char *) req_data, sizeof (union zfcp_req_data));
516 ZFCP_LOG_NORMAL("scsi_cmnd:\n");
517 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
518 (char *) scpnt, sizeof (struct scsi_cmnd));
520 strncpy(dbf_result, "##bug:r", ZFCP_ABORT_DBF_LENGTH);
523 old_fsf_req->data.send_fcp_command_task.scsi_cmnd = NULL;
524 /* mark old request as being aborted */
525 old_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING;
527 * We have to collect all information (e.g. unit) needed by
528 * zfcp_fsf_abort_fcp_command before calling that routine
529 * since that routine is not allowed to access
530 * fsf_req which it is going to abort.
531 * This is because of we need to release fsf_req_list_lock
532 * before calling zfcp_fsf_abort_fcp_command.
533 * Since this lock will not be held, fsf_req may complete
534 * late and may be released meanwhile.
536 ZFCP_LOG_DEBUG("unit 0x%016Lx (%p)\n", unit->fcp_lun, unit);
539 * We block (call schedule)
540 * That's why we must release the lock and enable the
542 * On the other hand we do not need the lock anymore since
543 * all critical accesses to scsi_req are done.
545 write_unlock_irqrestore(&adapter->abort_lock, flags);
546 /* call FSF routine which does the abort */
547 new_fsf_req = zfcp_fsf_abort_fcp_command((unsigned long) old_fsf_req,
549 ZFCP_LOG_DEBUG("new_fsf_req=%p\n", new_fsf_req);
552 ZFCP_LOG_NORMAL("error: initiation of Abort FCP Cmnd "
554 strncpy(dbf_result, "##nores", ZFCP_ABORT_DBF_LENGTH);
558 /* wait for completion of abort */
559 ZFCP_LOG_DEBUG("waiting for cleanup...\n");
563 * copying zfcp_fsf_req_wait_and_cleanup code is not really nice
565 __wait_event(new_fsf_req->completion_wq,
566 new_fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
567 status = new_fsf_req->status;
568 dbf_fsf_status = new_fsf_req->qtcb->header.fsf_status;
570 * Ralphs special debug load provides timestamps in the FSF
571 * status qualifier. This might be specified later if being
572 * useful for debugging aborts.
575 *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[0];
577 *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[2];
578 zfcp_fsf_req_free(new_fsf_req);
580 retval = zfcp_fsf_req_wait_and_cleanup(new_fsf_req,
581 ZFCP_UNINTERRUPTIBLE, &status);
583 ZFCP_LOG_DEBUG("Waiting for cleanup complete, status=0x%x\n", status);
584 /* status should be valid since signals were not permitted */
585 if (status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {
587 strncpy(dbf_result, "##succ", ZFCP_ABORT_DBF_LENGTH);
588 } else if (status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
590 strncpy(dbf_result, "##late2", ZFCP_ABORT_DBF_LENGTH);
593 strncpy(dbf_result, "##fail", ZFCP_ABORT_DBF_LENGTH);
597 debug_event(adapter->abort_dbf, 1, &dbf_scsi_cmnd, sizeof (u64));
598 debug_event(adapter->abort_dbf, 1, &dbf_opcode, ZFCP_ABORT_DBF_LENGTH);
599 debug_event(adapter->abort_dbf, 1, &dbf_wwn, sizeof (wwn_t));
600 debug_event(adapter->abort_dbf, 1, &dbf_fcp_lun, sizeof (fcp_lun_t));
601 debug_event(adapter->abort_dbf, 1, &dbf_retries, sizeof (u64));
602 debug_event(adapter->abort_dbf, 1, &dbf_allowed, sizeof (u64));
603 debug_event(adapter->abort_dbf, 1, &dbf_timeout, sizeof (u64));
604 debug_event(adapter->abort_dbf, 1, &dbf_fsf_req, sizeof (u64));
605 debug_event(adapter->abort_dbf, 1, &dbf_fsf_status, sizeof (u64));
606 debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[0], sizeof (u64));
607 debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[1], sizeof (u64));
608 debug_text_event(adapter->abort_dbf, 1, dbf_result);
610 spin_lock_irq(scsi_host->host_lock);
615 zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
618 struct Scsi_Host *scsi_host = scpnt->device->host;
619 spin_lock_irq(scsi_host->host_lock);
620 rc = __zfcp_scsi_eh_abort_handler(scpnt);
621 spin_unlock_irq(scsi_host->host_lock);
626 * function: zfcp_scsi_eh_device_reset_handler
633 zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
636 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
637 struct Scsi_Host *scsi_host = scpnt->device->host;
640 ZFCP_LOG_NORMAL("bug: Tried reset for nonexistent unit\n");
644 ZFCP_LOG_NORMAL("resetting unit 0x%016Lx\n", unit->fcp_lun);
647 * If we do not know whether the unit supports 'logical unit reset'
648 * then try 'logical unit reset' and proceed with 'target reset'
649 * if 'logical unit reset' fails.
650 * If the unit is known not to support 'logical unit reset' then
651 * skip 'logical unit reset' and try 'target reset' immediately.
653 if (!atomic_test_mask(ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
656 zfcp_task_management_function(unit, FCP_LOGICAL_UNIT_RESET);
658 ZFCP_LOG_DEBUG("unit reset failed (unit=%p)\n", unit);
659 if (retval == -ENOTSUPP)
661 (ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
663 /* fall through and try 'target reset' next */
665 ZFCP_LOG_DEBUG("unit reset succeeded (unit=%p)\n",
667 /* avoid 'target reset' */
672 retval = zfcp_task_management_function(unit, FCP_TARGET_RESET);
674 ZFCP_LOG_DEBUG("target reset failed (unit=%p)\n", unit);
677 ZFCP_LOG_DEBUG("target reset succeeded (unit=%p)\n", unit);
685 zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags)
687 struct zfcp_adapter *adapter = unit->port->adapter;
690 struct zfcp_fsf_req *fsf_req;
692 /* issue task management function */
693 fsf_req = zfcp_fsf_send_fcp_command_task_management
694 (adapter, unit, tm_flags, 0);
696 ZFCP_LOG_INFO("error: creation of task management request "
697 "failed for unit 0x%016Lx on port 0x%016Lx on "
698 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
699 zfcp_get_busid_by_adapter(adapter));
704 retval = zfcp_fsf_req_wait_and_cleanup(fsf_req,
705 ZFCP_UNINTERRUPTIBLE, &status);
707 * check completion status of task management function
708 * (status should always be valid since no signals permitted)
710 if (status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED)
712 else if (status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP)
721 * function: zfcp_scsi_eh_bus_reset_handler
728 zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *scpnt)
731 struct zfcp_unit *unit;
732 struct Scsi_Host *scsi_host = scpnt->device->host;
734 unit = (struct zfcp_unit *) scpnt->device->hostdata;
735 ZFCP_LOG_NORMAL("bus reset because of problems with "
736 "unit 0x%016Lx\n", unit->fcp_lun);
737 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
738 zfcp_erp_wait(unit->port->adapter);
745 * function: zfcp_scsi_eh_host_reset_handler
752 zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
755 struct zfcp_unit *unit;
756 struct Scsi_Host *scsi_host = scpnt->device->host;
758 unit = (struct zfcp_unit *) scpnt->device->hostdata;
759 ZFCP_LOG_NORMAL("host reset because of problems with "
760 "unit 0x%016Lx\n", unit->fcp_lun);
761 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
762 zfcp_erp_wait(unit->port->adapter);
776 zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
779 static unsigned int unique_id = 0;
781 /* register adapter as SCSI host with mid layer of SCSI stack */
782 adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
783 sizeof (struct zfcp_adapter *));
784 if (!adapter->scsi_host) {
785 ZFCP_LOG_NORMAL("error: registration with SCSI stack failed "
787 zfcp_get_busid_by_adapter(adapter));
791 ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host);
793 /* tell the SCSI stack some characteristics of this adapter */
794 adapter->scsi_host->max_id = 1;
795 adapter->scsi_host->max_lun = 1;
796 adapter->scsi_host->max_channel = 0;
797 adapter->scsi_host->unique_id = unique_id++; /* FIXME */
798 adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH;
799 adapter->scsi_host->transportt = zfcp_transport_template;
801 * Reverse mapping of the host number to avoid race condition
803 adapter->scsi_host_no = adapter->scsi_host->host_no;
806 * save a pointer to our own adapter data structure within
807 * hostdata field of SCSI host data structure
809 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
811 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
812 scsi_host_put(adapter->scsi_host);
816 atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
829 zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
831 struct Scsi_Host *shost;
833 shost = adapter->scsi_host;
836 scsi_remove_host(shost);
837 scsi_host_put(shost);
838 adapter->scsi_host = NULL;
839 adapter->scsi_host_no = 0;
840 atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
847 zfcp_fsf_start_scsi_er_timer(struct zfcp_adapter *adapter)
849 adapter->scsi_er_timer.function = zfcp_fsf_scsi_er_timeout_handler;
850 adapter->scsi_er_timer.data = (unsigned long) adapter;
851 adapter->scsi_er_timer.expires = jiffies + ZFCP_SCSI_ER_TIMEOUT;
852 add_timer(&adapter->scsi_er_timer);
856 * Support functions for FC transport class
859 zfcp_get_port_id(struct scsi_target *starget)
861 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
862 struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
863 struct zfcp_port *port;
866 read_lock_irqsave(&zfcp_data.config_lock, flags);
867 port = zfcp_port_lookup(adapter, starget->channel, starget->id);
869 fc_starget_port_id(starget) = port->d_id;
871 fc_starget_port_id(starget) = -1;
872 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
876 zfcp_get_port_name(struct scsi_target *starget)
878 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
879 struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
880 struct zfcp_port *port;
883 read_lock_irqsave(&zfcp_data.config_lock, flags);
884 port = zfcp_port_lookup(adapter, starget->channel, starget->id);
886 fc_starget_port_name(starget) = port->wwpn;
888 fc_starget_port_name(starget) = -1;
889 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
893 zfcp_get_node_name(struct scsi_target *starget)
895 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
896 struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
897 struct zfcp_port *port;
900 read_lock_irqsave(&zfcp_data.config_lock, flags);
901 port = zfcp_port_lookup(adapter, starget->channel, starget->id);
903 fc_starget_node_name(starget) = port->wwnn;
905 fc_starget_node_name(starget) = -1;
906 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
909 struct fc_function_template zfcp_transport_functions = {
910 .get_starget_port_id = zfcp_get_port_id,
911 .get_starget_port_name = zfcp_get_port_name,
912 .get_starget_node_name = zfcp_get_node_name,
913 .show_starget_port_id = 1,
914 .show_starget_port_name = 1,
915 .show_starget_node_name = 1,
919 * ZFCP_DEFINE_SCSI_ATTR
920 * @_name: name of show attribute
921 * @_format: format string
922 * @_value: value to print
924 * Generates attribute for a unit.
926 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
927 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
930 struct scsi_device *sdev; \
931 struct zfcp_unit *unit; \
933 sdev = to_scsi_device(dev); \
934 unit = sdev->hostdata; \
935 return sprintf(buf, _format, _value); \
938 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
940 ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit));
941 ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
942 ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
944 static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {