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>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_SCSI
33 /* this drivers version (do not edit !!! generated and updated by cvs) */
34 #define ZFCP_SCSI_REVISION "$Revision: 1.61 $"
36 #include <linux/blkdev.h>
40 static void zfcp_scsi_slave_destroy(struct scsi_device *sdp);
41 static int zfcp_scsi_slave_alloc(struct scsi_device *sdp);
42 static int zfcp_scsi_slave_configure(struct scsi_device *sdp);
43 static int zfcp_scsi_queuecommand(struct scsi_cmnd *,
44 void (*done) (struct scsi_cmnd *));
45 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *);
46 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *);
47 static int zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *);
48 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *);
49 static int zfcp_task_management_function(struct zfcp_unit *, u8);
51 static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int, scsi_id_t,
54 static struct device_attribute *zfcp_sysfs_sdev_attrs[];
56 struct zfcp_data zfcp_data = {
57 .scsi_host_template = {
62 slave_alloc: zfcp_scsi_slave_alloc,
63 slave_configure: zfcp_scsi_slave_configure,
64 slave_destroy: zfcp_scsi_slave_destroy,
65 queuecommand: zfcp_scsi_queuecommand,
66 eh_abort_handler: zfcp_scsi_eh_abort_handler,
67 eh_device_reset_handler: zfcp_scsi_eh_device_reset_handler,
68 eh_bus_reset_handler: zfcp_scsi_eh_bus_reset_handler,
69 eh_host_reset_handler: zfcp_scsi_eh_host_reset_handler,
70 /* FIXME(openfcp): Tune */
75 * one less? can zfcp_create_sbale cope with it?
77 sg_tablesize: ZFCP_MAX_SBALES_PER_REQ,
81 sdev_attrs: zfcp_sysfs_sdev_attrs,
83 /* rest initialised with zeros */
86 /* Find start of Response Information in FCP response unit*/
88 zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
90 char *fcp_rsp_info_ptr;
93 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
95 return fcp_rsp_info_ptr;
98 /* Find start of Sense Information in FCP response unit*/
100 zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
102 char *fcp_sns_info_ptr;
105 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
106 if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)
107 fcp_sns_info_ptr = (char *) fcp_sns_info_ptr +
108 fcp_rsp_iu->fcp_rsp_len;
110 return fcp_sns_info_ptr;
114 zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd)
116 int additional_length = fcp_cmd->add_fcp_cdb_length << 2;
117 fcp_dl_t *fcp_dl_addr;
119 fcp_dl_addr = (fcp_dl_t *)
120 ((unsigned char *) fcp_cmd +
121 sizeof (struct fcp_cmnd_iu) + additional_length);
123 * fcp_dl_addr = start address of fcp_cmnd structure +
124 * size of fixed part + size of dynamically sized add_dcp_cdb field
125 * SEE FCP-2 documentation
131 zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd)
133 return *zfcp_get_fcp_dl_ptr(fcp_cmd);
137 zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl)
139 *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl;
143 * note: it's a bit-or operation not an assignment
144 * regarding the specified byte
147 set_byte(u32 * result, char status, char pos)
149 *result |= status << (pos * 8);
153 set_host_byte(u32 * result, char status)
155 set_byte(result, status, 2);
159 set_driver_byte(u32 * result, char status)
161 set_byte(result, status, 3);
165 * function: zfcp_scsi_slave_alloc
173 zfcp_scsi_slave_alloc(struct scsi_device *sdp)
175 struct zfcp_adapter *adapter;
176 struct zfcp_unit *unit;
178 int retval = -ENODEV;
180 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
184 read_lock_irqsave(&zfcp_data.config_lock, flags);
185 unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun);
187 sdp->hostdata = unit;
192 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
198 * function: zfcp_scsi_slave_destroy
206 zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
208 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
211 sdpnt->hostdata = NULL;
215 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at "
216 "address %p\n", sdpnt);
221 * called from scsi midlayer to allow finetuning of a device.
224 zfcp_scsi_slave_configure(struct scsi_device *sdp)
226 if (sdp->tagged_supported)
227 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN);
229 scsi_adjust_queue_depth(sdp, 0, 1);
234 * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function
235 * @scpnt: pointer to struct scsi_cmnd where result is set
236 * @result: result to be set in scpnt (e.g. DID_ERROR)
239 zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
241 set_host_byte(&scpnt->result, result);
242 zfcp_cmd_dbf_event_scsi("failing", scpnt);
243 /* return directly */
244 scpnt->scsi_done(scpnt);
248 * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and
249 * zfcp_scsi_command_sync
250 * @adapter: adapter for where scsi command is issued
251 * @unit: unit to which scsi command is sent
252 * @scpnt: scsi command to be sent
254 * Note: In scsi_done function must be set in scpnt.
257 zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit,
258 struct scsi_cmnd *scpnt)
265 BUG_ON((adapter == NULL) || (adapter != unit->port->adapter));
266 BUG_ON(scpnt->scsi_done == NULL);
268 if (unlikely(NULL == unit)) {
269 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
274 atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) ||
275 !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) {
276 ZFCP_LOG_DEBUG("stopping SCSI I/O on unit 0x%016Lx on port "
277 "0x%016Lx on adapter %s\n",
278 unit->fcp_lun, unit->port->wwpn,
279 zfcp_get_busid_by_adapter(adapter));
280 zfcp_scsi_command_fail(scpnt, DID_ERROR);
285 !atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))) {
286 ZFCP_LOG_DEBUG("adapter %s not ready or unit 0x%016Lx "
287 "on port 0x%016Lx in recovery\n",
288 zfcp_get_busid_by_unit(unit),
289 unit->fcp_lun, unit->port->wwpn);
290 retval = SCSI_MLQUEUE_DEVICE_BUSY;
294 tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt,
295 ZFCP_REQ_AUTO_CLEANUP);
297 if (unlikely(tmp < 0)) {
298 ZFCP_LOG_DEBUG("error: initiation of Send FCP Cmnd failed\n");
299 retval = SCSI_MLQUEUE_HOST_BUSY;
307 zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt)
309 struct completion *wait = (struct completion *) scpnt->SCp.ptr;
315 * zfcp_scsi_command_sync - send a SCSI command and wait for completion
316 * returns 0, errors are indicated by scsi_cmnd->result
319 zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt)
321 DECLARE_COMPLETION(wait);
323 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */
324 scpnt->done = zfcp_scsi_command_sync_handler;
325 zfcp_scsi_command_async(unit->port->adapter, unit, scpnt);
326 wait_for_completion(&wait);
332 * function: zfcp_scsi_queuecommand
334 * purpose: enqueues a SCSI command to the specified target device
336 * returns: 0 - success, SCSI command enqueued
340 zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
341 void (*done) (struct scsi_cmnd *))
343 struct zfcp_unit *unit;
344 struct zfcp_adapter *adapter;
346 /* reset the status for this request */
348 scpnt->host_scribble = NULL;
349 scpnt->scsi_done = done;
352 * figure out adapter and target device
353 * (stored there by zfcp_scsi_slave_alloc)
355 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
356 unit = (struct zfcp_unit *) scpnt->device->hostdata;
358 return zfcp_scsi_command_async(adapter, unit, scpnt);
362 * function: zfcp_unit_lookup
370 static struct zfcp_unit *
371 zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id,
374 struct zfcp_port *port;
375 struct zfcp_unit *unit, *retval = NULL;
377 list_for_each_entry(port, &adapter->port_list_head, list) {
378 if (id != port->scsi_id)
380 list_for_each_entry(unit, &port->unit_list_head, list) {
381 if (lun == unit->scsi_lun) {
392 * function: zfcp_scsi_eh_abort_handler
394 * purpose: tries to abort the specified (timed out) SCSI command
396 * note: We do not need to care for a SCSI command which completes
397 * normally but late during this abort routine runs.
398 * We are allowed to return late commands to the SCSI stack.
399 * It tracks the state of commands and will handle late commands.
400 * (Usually, the normal completion of late commands is ignored with
401 * respect to the running abort operation. Grep for 'done_late'
402 * in the SCSI stacks sources.)
404 * returns: SUCCESS - command has been aborted and cleaned up in internal
406 * SCSI stack won't be called for aborted command
410 zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
412 int retval = SUCCESS;
413 struct zfcp_fsf_req *new_fsf_req, *old_fsf_req;
414 struct zfcp_adapter *adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
415 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
416 struct zfcp_port *port = unit->port;
417 struct Scsi_Host *scsi_host = scpnt->device->host;
418 union zfcp_req_data *req_data = NULL;
422 /* the components of a abort_dbf record (fixed size record) */
423 u64 dbf_scsi_cmnd = (unsigned long) scpnt;
424 char dbf_opcode[ZFCP_ABORT_DBF_LENGTH];
425 wwn_t dbf_wwn = port->wwpn;
426 fcp_lun_t dbf_fcp_lun = unit->fcp_lun;
427 u64 dbf_retries = scpnt->retries;
428 u64 dbf_allowed = scpnt->allowed;
431 u64 dbf_fsf_status = 0;
432 u64 dbf_fsf_qual[2] = { 0, 0 };
433 char dbf_result[ZFCP_ABORT_DBF_LENGTH] = { "##undef" };
435 memset(dbf_opcode, 0, ZFCP_ABORT_DBF_LENGTH);
438 min(scpnt->cmd_len, (unsigned char) ZFCP_ABORT_DBF_LENGTH));
440 ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n",
441 scpnt, zfcp_get_busid_by_adapter(adapter));
443 spin_unlock_irq(scsi_host->host_lock);
446 * Race condition between normal (late) completion and abort has
448 * The entirity of all accesses to scsi_req have to be atomic.
449 * scsi_req is usually part of the fsf_req and thus we block the
450 * release of fsf_req as long as we need to access scsi_req.
452 write_lock_irqsave(&adapter->abort_lock, flags);
455 * Check whether command has just completed and can not be aborted.
456 * Even if the command has just been completed late, we can access
457 * scpnt since the SCSI stack does not release it at least until
458 * this routine returns. (scpnt is parameter passed to this routine
459 * and must not disappear during abort even on late completion.)
461 req_data = (union zfcp_req_data *) scpnt->host_scribble;
463 ZFCP_LOG_DEBUG("req_data=%p\n", req_data);
465 ZFCP_LOG_DEBUG("late command completion overtook abort\n");
468 * Do not initiate abort but return SUCCESS.
470 write_unlock_irqrestore(&adapter->abort_lock, flags);
472 strncpy(dbf_result, "##late1", ZFCP_ABORT_DBF_LENGTH);
476 /* Figure out which fsf_req needs to be aborted. */
477 old_fsf_req = req_data->send_fcp_command_task.fsf_req;
479 dbf_fsf_req = (unsigned long) old_fsf_req;
481 (jiffies - req_data->send_fcp_command_task.start_jiffies) / HZ;
483 ZFCP_LOG_DEBUG("old_fsf_req=%p\n", old_fsf_req);
485 write_unlock_irqrestore(&adapter->abort_lock, flags);
486 ZFCP_LOG_NORMAL("bug: no old fsf request found\n");
487 ZFCP_LOG_NORMAL("req_data:\n");
488 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
489 (char *) req_data, sizeof (union zfcp_req_data));
490 ZFCP_LOG_NORMAL("scsi_cmnd:\n");
491 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
492 (char *) scpnt, sizeof (struct scsi_cmnd));
494 strncpy(dbf_result, "##bug:r", ZFCP_ABORT_DBF_LENGTH);
497 old_fsf_req->data.send_fcp_command_task.scsi_cmnd = NULL;
498 /* mark old request as being aborted */
499 old_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING;
501 * We have to collect all information (e.g. unit) needed by
502 * zfcp_fsf_abort_fcp_command before calling that routine
503 * since that routine is not allowed to access
504 * fsf_req which it is going to abort.
505 * This is because of we need to release fsf_req_list_lock
506 * before calling zfcp_fsf_abort_fcp_command.
507 * Since this lock will not be held, fsf_req may complete
508 * late and may be released meanwhile.
510 ZFCP_LOG_DEBUG("unit 0x%016Lx (%p)\n", unit->fcp_lun, unit);
513 * The 'Abort FCP Command' routine may block (call schedule)
514 * because it may wait for a free SBAL.
515 * That's why we must release the lock and enable the
517 * On the other hand we do not need the lock anymore since
518 * all critical accesses to scsi_req are done.
520 write_unlock_irqrestore(&adapter->abort_lock, flags);
521 /* call FSF routine which does the abort */
522 new_fsf_req = zfcp_fsf_abort_fcp_command((unsigned long) old_fsf_req,
524 unit, ZFCP_WAIT_FOR_SBAL);
525 ZFCP_LOG_DEBUG("new_fsf_req=%p\n", new_fsf_req);
528 ZFCP_LOG_NORMAL("error: initiation of Abort FCP Cmnd "
530 strncpy(dbf_result, "##nores", ZFCP_ABORT_DBF_LENGTH);
534 /* wait for completion of abort */
535 ZFCP_LOG_DEBUG("waiting for cleanup...\n");
539 * copying zfcp_fsf_req_wait_and_cleanup code is not really nice
541 __wait_event(new_fsf_req->completion_wq,
542 new_fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
543 status = new_fsf_req->status;
544 dbf_fsf_status = new_fsf_req->qtcb->header.fsf_status;
546 * Ralphs special debug load provides timestamps in the FSF
547 * status qualifier. This might be specified later if being
548 * useful for debugging aborts.
551 *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[0];
553 *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[2];
554 zfcp_fsf_req_cleanup(new_fsf_req);
556 retval = zfcp_fsf_req_wait_and_cleanup(new_fsf_req,
557 ZFCP_UNINTERRUPTIBLE, &status);
559 ZFCP_LOG_DEBUG("Waiting for cleanup complete, status=0x%x\n", status);
560 /* status should be valid since signals were not permitted */
561 if (status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {
563 strncpy(dbf_result, "##succ", ZFCP_ABORT_DBF_LENGTH);
564 } else if (status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
566 strncpy(dbf_result, "##late2", ZFCP_ABORT_DBF_LENGTH);
569 strncpy(dbf_result, "##fail", ZFCP_ABORT_DBF_LENGTH);
573 debug_event(adapter->abort_dbf, 1, &dbf_scsi_cmnd, sizeof (u64));
574 debug_event(adapter->abort_dbf, 1, &dbf_opcode, ZFCP_ABORT_DBF_LENGTH);
575 debug_event(adapter->abort_dbf, 1, &dbf_wwn, sizeof (wwn_t));
576 debug_event(adapter->abort_dbf, 1, &dbf_fcp_lun, sizeof (fcp_lun_t));
577 debug_event(adapter->abort_dbf, 1, &dbf_retries, sizeof (u64));
578 debug_event(adapter->abort_dbf, 1, &dbf_allowed, sizeof (u64));
579 debug_event(adapter->abort_dbf, 1, &dbf_timeout, sizeof (u64));
580 debug_event(adapter->abort_dbf, 1, &dbf_fsf_req, sizeof (u64));
581 debug_event(adapter->abort_dbf, 1, &dbf_fsf_status, sizeof (u64));
582 debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[0], sizeof (u64));
583 debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[1], sizeof (u64));
584 debug_text_event(adapter->abort_dbf, 1, dbf_result);
586 spin_lock_irq(scsi_host->host_lock);
591 * function: zfcp_scsi_eh_device_reset_handler
598 zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
601 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
602 struct Scsi_Host *scsi_host = scpnt->device->host;
604 spin_unlock_irq(scsi_host->host_lock);
607 ZFCP_LOG_NORMAL("bug: Tried reset for nonexistent unit\n");
611 ZFCP_LOG_NORMAL("resetting unit 0x%016Lx\n", unit->fcp_lun);
614 * If we do not know whether the unit supports 'logical unit reset'
615 * then try 'logical unit reset' and proceed with 'target reset'
616 * if 'logical unit reset' fails.
617 * If the unit is known not to support 'logical unit reset' then
618 * skip 'logical unit reset' and try 'target reset' immediately.
620 if (!atomic_test_mask(ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
623 zfcp_task_management_function(unit, LOGICAL_UNIT_RESET);
625 ZFCP_LOG_DEBUG("unit reset failed (unit=%p)\n", unit);
626 if (retval == -ENOTSUPP)
628 (ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
630 /* fall through and try 'target reset' next */
632 ZFCP_LOG_DEBUG("unit reset succeeded (unit=%p)\n",
634 /* avoid 'target reset' */
639 retval = zfcp_task_management_function(unit, TARGET_RESET);
641 ZFCP_LOG_DEBUG("target reset failed (unit=%p)\n", unit);
644 ZFCP_LOG_DEBUG("target reset succeeded (unit=%p)\n", unit);
648 spin_lock_irq(scsi_host->host_lock);
653 zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags)
655 struct zfcp_adapter *adapter = unit->port->adapter;
658 struct zfcp_fsf_req *fsf_req;
660 /* issue task management function */
661 fsf_req = zfcp_fsf_send_fcp_command_task_management
662 (adapter, unit, tm_flags, ZFCP_WAIT_FOR_SBAL);
664 ZFCP_LOG_INFO("error: creation of task management request "
665 "failed for unit 0x%016Lx on port 0x%016Lx on "
666 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
667 zfcp_get_busid_by_adapter(adapter));
672 retval = zfcp_fsf_req_wait_and_cleanup(fsf_req,
673 ZFCP_UNINTERRUPTIBLE, &status);
675 * check completion status of task management function
676 * (status should always be valid since no signals permitted)
678 if (status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED)
680 else if (status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP)
689 * function: zfcp_scsi_eh_bus_reset_handler
696 zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *scpnt)
699 struct zfcp_unit *unit;
700 struct Scsi_Host *scsi_host = scpnt->device->host;
702 spin_unlock_irq(scsi_host->host_lock);
704 unit = (struct zfcp_unit *) scpnt->device->hostdata;
705 ZFCP_LOG_NORMAL("bus reset because of problems with "
706 "unit 0x%016Lx\n", unit->fcp_lun);
707 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
708 zfcp_erp_wait(unit->port->adapter);
711 spin_lock_irq(scsi_host->host_lock);
716 * function: zfcp_scsi_eh_host_reset_handler
723 zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
726 struct zfcp_unit *unit;
727 struct Scsi_Host *scsi_host = scpnt->device->host;
729 spin_unlock_irq(scsi_host->host_lock);
731 unit = (struct zfcp_unit *) scpnt->device->hostdata;
732 ZFCP_LOG_NORMAL("host reset because of problems with "
733 "unit 0x%016Lx\n", unit->fcp_lun);
734 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
735 zfcp_erp_wait(unit->port->adapter);
738 spin_lock_irq(scsi_host->host_lock);
750 zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
753 static unsigned int unique_id = 0;
755 /* register adapter as SCSI host with mid layer of SCSI stack */
756 adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
757 sizeof (struct zfcp_adapter *));
758 if (!adapter->scsi_host) {
759 ZFCP_LOG_NORMAL("error: registration with SCSI stack failed "
761 zfcp_get_busid_by_adapter(adapter));
765 ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host);
767 /* tell the SCSI stack some characteristics of this adapter */
768 adapter->scsi_host->max_id = 1;
769 adapter->scsi_host->max_lun = 1;
770 adapter->scsi_host->max_channel = 0;
771 adapter->scsi_host->unique_id = unique_id++; /* FIXME */
772 adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH;
774 * Reverse mapping of the host number to avoid race condition
776 adapter->scsi_host_no = adapter->scsi_host->host_no;
779 * save a pointer to our own adapter data structure within
780 * hostdata field of SCSI host data structure
782 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
784 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
785 scsi_host_put(adapter->scsi_host);
789 atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
802 zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
804 struct Scsi_Host *shost;
806 shost = adapter->scsi_host;
809 scsi_remove_host(shost);
810 scsi_host_put(shost);
811 adapter->scsi_host = NULL;
812 adapter->scsi_host_no = 0;
813 atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
820 zfcp_fsf_start_scsi_er_timer(struct zfcp_adapter *adapter)
822 adapter->scsi_er_timer.function = zfcp_fsf_scsi_er_timeout_handler;
823 adapter->scsi_er_timer.data = (unsigned long) adapter;
824 adapter->scsi_er_timer.expires = jiffies + ZFCP_SCSI_ER_TIMEOUT;
825 add_timer(&adapter->scsi_er_timer);
830 * ZFCP_DEFINE_SCSI_ATTR
831 * @_name: name of show attribute
832 * @_format: format string
833 * @_value: value to print
835 * Generates attribute for a unit.
837 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
838 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
841 struct scsi_device *sdev; \
842 struct zfcp_unit *unit; \
844 sdev = to_scsi_device(dev); \
845 unit = sdev->hostdata; \
846 return sprintf(buf, _format, _value); \
849 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
851 ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit));
852 ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
853 ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
855 static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {