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,
50 static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int, scsi_id_t,
53 static struct device_attribute *zfcp_sysfs_sdev_attrs[];
55 struct scsi_transport_template *zfcp_transport_template;
57 struct zfcp_data zfcp_data = {
58 .scsi_host_template = {
63 slave_alloc: zfcp_scsi_slave_alloc,
64 slave_configure: zfcp_scsi_slave_configure,
65 slave_destroy: zfcp_scsi_slave_destroy,
66 queuecommand: zfcp_scsi_queuecommand,
67 eh_abort_handler: zfcp_scsi_eh_abort_handler,
68 eh_device_reset_handler: zfcp_scsi_eh_device_reset_handler,
69 eh_bus_reset_handler: zfcp_scsi_eh_bus_reset_handler,
70 eh_host_reset_handler: zfcp_scsi_eh_host_reset_handler,
71 /* FIXME(openfcp): Tune */
76 * one less? can zfcp_create_sbale cope with it?
78 sg_tablesize: ZFCP_MAX_SBALES_PER_REQ,
82 sdev_attrs: zfcp_sysfs_sdev_attrs,
84 .driver_version = ZFCP_VERSION,
85 /* rest initialised with zeros */
88 /* Find start of Response Information in FCP response unit*/
90 zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
92 char *fcp_rsp_info_ptr;
95 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
97 return fcp_rsp_info_ptr;
100 /* Find start of Sense Information in FCP response unit*/
102 zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
104 char *fcp_sns_info_ptr;
107 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
108 if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)
109 fcp_sns_info_ptr = (char *) fcp_sns_info_ptr +
110 fcp_rsp_iu->fcp_rsp_len;
112 return fcp_sns_info_ptr;
116 zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd)
118 int additional_length = fcp_cmd->add_fcp_cdb_length << 2;
119 fcp_dl_t *fcp_dl_addr;
121 fcp_dl_addr = (fcp_dl_t *)
122 ((unsigned char *) fcp_cmd +
123 sizeof (struct fcp_cmnd_iu) + additional_length);
125 * fcp_dl_addr = start address of fcp_cmnd structure +
126 * size of fixed part + size of dynamically sized add_dcp_cdb field
127 * SEE FCP-2 documentation
133 zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd)
135 return *zfcp_get_fcp_dl_ptr(fcp_cmd);
139 zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl)
141 *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl;
145 * note: it's a bit-or operation not an assignment
146 * regarding the specified byte
149 set_byte(u32 * result, char status, char pos)
151 *result |= status << (pos * 8);
155 set_host_byte(u32 * result, char status)
157 set_byte(result, status, 2);
161 set_driver_byte(u32 * result, char status)
163 set_byte(result, status, 3);
167 * function: zfcp_scsi_slave_alloc
175 zfcp_scsi_slave_alloc(struct scsi_device *sdp)
177 struct zfcp_adapter *adapter;
178 struct zfcp_unit *unit;
182 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
186 read_lock_irqsave(&zfcp_data.config_lock, flags);
187 unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun);
189 sdp->hostdata = unit;
194 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
200 * function: zfcp_scsi_slave_destroy
208 zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
210 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
213 sdpnt->hostdata = NULL;
217 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at "
218 "address %p\n", sdpnt);
223 * called from scsi midlayer to allow finetuning of a device.
226 zfcp_scsi_slave_configure(struct scsi_device *sdp)
228 if (sdp->tagged_supported)
229 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN);
231 scsi_adjust_queue_depth(sdp, 0, 1);
236 * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function
237 * @scpnt: pointer to struct scsi_cmnd where result is set
238 * @result: result to be set in scpnt (e.g. DID_ERROR)
241 zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
243 set_host_byte(&scpnt->result, result);
244 if ((scpnt->device != NULL) && (scpnt->device->host != NULL))
245 zfcp_scsi_dbf_event_result("fail", 4,
246 (struct zfcp_adapter*) scpnt->device->host->hostdata[0],
248 /* return directly */
249 scpnt->scsi_done(scpnt);
253 * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and
254 * zfcp_scsi_command_sync
255 * @adapter: adapter where scsi command is issued
256 * @unit: unit to which scsi command is sent
257 * @scpnt: scsi command to be sent
258 * @timer: timer to be started if request is successfully initiated
260 * Note: In scsi_done function must be set in scpnt.
263 zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit,
264 struct scsi_cmnd *scpnt, struct timer_list *timer)
271 BUG_ON((adapter == NULL) || (adapter != unit->port->adapter));
272 BUG_ON(scpnt->scsi_done == NULL);
274 if (unlikely(NULL == unit)) {
275 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
280 atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) ||
281 !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) {
282 ZFCP_LOG_DEBUG("stopping SCSI I/O on unit 0x%016Lx on port "
283 "0x%016Lx on adapter %s\n",
284 unit->fcp_lun, unit->port->wwpn,
285 zfcp_get_busid_by_adapter(adapter));
286 zfcp_scsi_command_fail(scpnt, DID_ERROR);
291 !atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))) {
292 ZFCP_LOG_DEBUG("adapter %s not ready or unit 0x%016Lx "
293 "on port 0x%016Lx in recovery\n",
294 zfcp_get_busid_by_unit(unit),
295 unit->fcp_lun, unit->port->wwpn);
296 retval = SCSI_MLQUEUE_DEVICE_BUSY;
300 tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, timer,
301 ZFCP_REQ_AUTO_CLEANUP);
303 if (unlikely(tmp < 0)) {
304 ZFCP_LOG_DEBUG("error: initiation of Send FCP Cmnd failed\n");
305 retval = SCSI_MLQUEUE_HOST_BUSY;
313 zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt)
315 struct completion *wait = (struct completion *) scpnt->SCp.ptr;
321 * zfcp_scsi_command_sync - send a SCSI command and wait for completion
322 * @unit: unit where command is sent to
323 * @scpnt: scsi command to be sent
324 * @timer: timer to be started if request is successfully initiated
327 * Errors are indicated in scpnt->result
330 zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt,
331 struct timer_list *timer)
334 DECLARE_COMPLETION(wait);
336 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */
337 scpnt->scsi_done = zfcp_scsi_command_sync_handler;
338 ret = zfcp_scsi_command_async(unit->port->adapter, unit, scpnt, timer);
340 wait_for_completion(&wait);
342 scpnt->SCp.ptr = NULL;
348 * function: zfcp_scsi_queuecommand
350 * purpose: enqueues a SCSI command to the specified target device
352 * returns: 0 - success, SCSI command enqueued
356 zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
357 void (*done) (struct scsi_cmnd *))
359 struct zfcp_unit *unit;
360 struct zfcp_adapter *adapter;
362 /* reset the status for this request */
364 scpnt->host_scribble = NULL;
365 scpnt->scsi_done = done;
368 * figure out adapter and target device
369 * (stored there by zfcp_scsi_slave_alloc)
371 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
372 unit = (struct zfcp_unit *) scpnt->device->hostdata;
374 return zfcp_scsi_command_async(adapter, unit, scpnt, NULL);
378 * function: zfcp_unit_lookup
386 static struct zfcp_unit *
387 zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id,
390 struct zfcp_port *port;
391 struct zfcp_unit *unit, *retval = NULL;
393 list_for_each_entry(port, &adapter->port_list_head, list) {
394 if (!port->rport || (id != port->rport->scsi_target_id))
396 list_for_each_entry(unit, &port->unit_list_head, list) {
397 if (lun == unit->scsi_lun) {
408 * zfcp_scsi_eh_abort_handler - abort the specified SCSI command
409 * @scpnt: pointer to scsi_cmnd to be aborted
410 * Return: SUCCESS - command has been aborted and cleaned up in internal
411 * bookkeeping, SCSI stack won't be called for aborted command
414 * We do not need to care for a SCSI command which completes normally
415 * but late during this abort routine runs. We are allowed to return
416 * late commands to the SCSI stack. It tracks the state of commands and
417 * will handle late commands. (Usually, the normal completion of late
418 * commands is ignored with respect to the running abort operation.)
421 zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
423 struct Scsi_Host *scsi_host;
424 struct zfcp_adapter *adapter;
425 struct zfcp_unit *unit;
426 int retval = SUCCESS;
427 struct zfcp_fsf_req *new_fsf_req = NULL;
428 struct zfcp_fsf_req *old_fsf_req;
431 scsi_host = scpnt->device->host;
432 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
433 unit = (struct zfcp_unit *) scpnt->device->hostdata;
435 ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n",
436 scpnt, zfcp_get_busid_by_adapter(adapter));
438 /* avoid race condition between late normal completion and abort */
439 write_lock_irqsave(&adapter->abort_lock, flags);
442 * Check whether command has just completed and can not be aborted.
443 * Even if the command has just been completed late, we can access
444 * scpnt since the SCSI stack does not release it at least until
445 * this routine returns. (scpnt is parameter passed to this routine
446 * and must not disappear during abort even on late completion.)
448 old_fsf_req = (struct zfcp_fsf_req *) scpnt->host_scribble;
450 write_unlock_irqrestore(&adapter->abort_lock, flags);
451 zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, new_fsf_req);
455 old_fsf_req->data = 0;
456 old_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING;
458 /* don't access old_fsf_req after releasing the abort_lock */
459 write_unlock_irqrestore(&adapter->abort_lock, flags);
460 /* call FSF routine which does the abort */
461 new_fsf_req = zfcp_fsf_abort_fcp_command((unsigned long) old_fsf_req,
464 ZFCP_LOG_INFO("error: initiation of Abort FCP Cmnd failed\n");
469 /* wait for completion of abort */
470 __wait_event(new_fsf_req->completion_wq,
471 new_fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
473 /* status should be valid since signals were not permitted */
474 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {
475 zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, new_fsf_req);
477 } else if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
478 zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, new_fsf_req);
481 zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, new_fsf_req);
484 zfcp_fsf_req_free(new_fsf_req);
490 * function: zfcp_scsi_eh_device_reset_handler
497 zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
500 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
503 ZFCP_LOG_NORMAL("bug: Tried reset for nonexistent unit\n");
507 ZFCP_LOG_NORMAL("resetting unit 0x%016Lx\n", unit->fcp_lun);
510 * If we do not know whether the unit supports 'logical unit reset'
511 * then try 'logical unit reset' and proceed with 'target reset'
512 * if 'logical unit reset' fails.
513 * If the unit is known not to support 'logical unit reset' then
514 * skip 'logical unit reset' and try 'target reset' immediately.
516 if (!atomic_test_mask(ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
518 retval = zfcp_task_management_function(unit,
519 FCP_LOGICAL_UNIT_RESET,
522 ZFCP_LOG_DEBUG("unit reset failed (unit=%p)\n", unit);
523 if (retval == -ENOTSUPP)
525 (ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
527 /* fall through and try 'target reset' next */
529 ZFCP_LOG_DEBUG("unit reset succeeded (unit=%p)\n",
531 /* avoid 'target reset' */
536 retval = zfcp_task_management_function(unit, FCP_TARGET_RESET, scpnt);
538 ZFCP_LOG_DEBUG("target reset failed (unit=%p)\n", unit);
541 ZFCP_LOG_DEBUG("target reset succeeded (unit=%p)\n", unit);
549 zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags,
550 struct scsi_cmnd *scpnt)
552 struct zfcp_adapter *adapter = unit->port->adapter;
553 struct zfcp_fsf_req *fsf_req;
556 /* issue task management function */
557 fsf_req = zfcp_fsf_send_fcp_command_task_management
558 (adapter, unit, tm_flags, 0);
560 ZFCP_LOG_INFO("error: creation of task management request "
561 "failed for unit 0x%016Lx on port 0x%016Lx on "
562 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
563 zfcp_get_busid_by_adapter(adapter));
564 zfcp_scsi_dbf_event_devreset("nres", tm_flags, unit, scpnt);
569 __wait_event(fsf_req->completion_wq,
570 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
573 * check completion status of task management function
575 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
576 zfcp_scsi_dbf_event_devreset("fail", tm_flags, unit, scpnt);
578 } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP) {
579 zfcp_scsi_dbf_event_devreset("nsup", tm_flags, unit, scpnt);
582 zfcp_scsi_dbf_event_devreset("okay", tm_flags, unit, scpnt);
584 zfcp_fsf_req_free(fsf_req);
590 * zfcp_scsi_eh_bus_reset_handler - reset bus (reopen adapter)
593 zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *scpnt)
595 struct zfcp_unit *unit = (struct zfcp_unit*) scpnt->device->hostdata;
596 struct zfcp_adapter *adapter = unit->port->adapter;
598 ZFCP_LOG_NORMAL("bus reset because of problems with "
599 "unit 0x%016Lx\n", unit->fcp_lun);
600 zfcp_erp_adapter_reopen(adapter, 0);
601 zfcp_erp_wait(adapter);
607 * zfcp_scsi_eh_host_reset_handler - reset host (reopen adapter)
610 zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
612 struct zfcp_unit *unit = (struct zfcp_unit*) scpnt->device->hostdata;
613 struct zfcp_adapter *adapter = unit->port->adapter;
615 ZFCP_LOG_NORMAL("host reset because of problems with "
616 "unit 0x%016Lx\n", unit->fcp_lun);
617 zfcp_erp_adapter_reopen(adapter, 0);
618 zfcp_erp_wait(adapter);
631 zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
634 static unsigned int unique_id = 0;
636 /* register adapter as SCSI host with mid layer of SCSI stack */
637 adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
638 sizeof (struct zfcp_adapter *));
639 if (!adapter->scsi_host) {
640 ZFCP_LOG_NORMAL("error: registration with SCSI stack failed "
642 zfcp_get_busid_by_adapter(adapter));
646 ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host);
648 /* tell the SCSI stack some characteristics of this adapter */
649 adapter->scsi_host->max_id = 1;
650 adapter->scsi_host->max_lun = 1;
651 adapter->scsi_host->max_channel = 0;
652 adapter->scsi_host->unique_id = unique_id++; /* FIXME */
653 adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH;
654 adapter->scsi_host->transportt = zfcp_transport_template;
656 * Reverse mapping of the host number to avoid race condition
658 adapter->scsi_host_no = adapter->scsi_host->host_no;
661 * save a pointer to our own adapter data structure within
662 * hostdata field of SCSI host data structure
664 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
666 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
667 scsi_host_put(adapter->scsi_host);
671 atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
684 zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
686 struct Scsi_Host *shost;
687 struct zfcp_port *port;
689 shost = adapter->scsi_host;
692 read_lock_irq(&zfcp_data.config_lock);
693 list_for_each_entry(port, &adapter->port_list_head, list)
696 read_unlock_irq(&zfcp_data.config_lock);
697 fc_remove_host(shost);
698 scsi_remove_host(shost);
699 scsi_host_put(shost);
700 adapter->scsi_host = NULL;
701 adapter->scsi_host_no = 0;
702 atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
709 zfcp_fsf_start_scsi_er_timer(struct zfcp_adapter *adapter)
711 adapter->scsi_er_timer.function = zfcp_fsf_scsi_er_timeout_handler;
712 adapter->scsi_er_timer.data = (unsigned long) adapter;
713 adapter->scsi_er_timer.expires = jiffies + ZFCP_SCSI_ER_TIMEOUT;
714 add_timer(&adapter->scsi_er_timer);
718 * Support functions for FC transport class
720 static struct fc_host_statistics*
721 zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
723 struct fc_host_statistics *fc_stats;
725 if (!adapter->fc_stats) {
726 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
729 adapter->fc_stats = fc_stats; /* freed in adater_dequeue */
731 memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
732 return adapter->fc_stats;
736 zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
737 struct fsf_qtcb_bottom_port *data,
738 struct fsf_qtcb_bottom_port *old)
740 fc_stats->seconds_since_last_reset = data->seconds_since_last_reset -
741 old->seconds_since_last_reset;
742 fc_stats->tx_frames = data->tx_frames - old->tx_frames;
743 fc_stats->tx_words = data->tx_words - old->tx_words;
744 fc_stats->rx_frames = data->rx_frames - old->rx_frames;
745 fc_stats->rx_words = data->rx_words - old->rx_words;
746 fc_stats->lip_count = data->lip - old->lip;
747 fc_stats->nos_count = data->nos - old->nos;
748 fc_stats->error_frames = data->error_frames - old->error_frames;
749 fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
750 fc_stats->link_failure_count = data->link_failure - old->link_failure;
751 fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
752 fc_stats->loss_of_signal_count = data->loss_of_signal -
754 fc_stats->prim_seq_protocol_err_count = data->psp_error_counts -
755 old->psp_error_counts;
756 fc_stats->invalid_tx_word_count = data->invalid_tx_words -
757 old->invalid_tx_words;
758 fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
759 fc_stats->fcp_input_requests = data->input_requests -
761 fc_stats->fcp_output_requests = data->output_requests -
762 old->output_requests;
763 fc_stats->fcp_control_requests = data->control_requests -
764 old->control_requests;
765 fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
766 fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
770 zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
771 struct fsf_qtcb_bottom_port *data)
773 fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
774 fc_stats->tx_frames = data->tx_frames;
775 fc_stats->tx_words = data->tx_words;
776 fc_stats->rx_frames = data->rx_frames;
777 fc_stats->rx_words = data->rx_words;
778 fc_stats->lip_count = data->lip;
779 fc_stats->nos_count = data->nos;
780 fc_stats->error_frames = data->error_frames;
781 fc_stats->dumped_frames = data->dumped_frames;
782 fc_stats->link_failure_count = data->link_failure;
783 fc_stats->loss_of_sync_count = data->loss_of_sync;
784 fc_stats->loss_of_signal_count = data->loss_of_signal;
785 fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
786 fc_stats->invalid_tx_word_count = data->invalid_tx_words;
787 fc_stats->invalid_crc_count = data->invalid_crcs;
788 fc_stats->fcp_input_requests = data->input_requests;
789 fc_stats->fcp_output_requests = data->output_requests;
790 fc_stats->fcp_control_requests = data->control_requests;
791 fc_stats->fcp_input_megabytes = data->input_mb;
792 fc_stats->fcp_output_megabytes = data->output_mb;
796 * zfcp_get_fc_host_stats - provide fc_host_statistics for scsi_transport_fc
798 * assumption: scsi_transport_fc synchronizes calls of
799 * get_fc_host_stats and reset_fc_host_stats
800 * (XXX to be checked otherwise introduce locking)
802 static struct fc_host_statistics *
803 zfcp_get_fc_host_stats(struct Scsi_Host *shost)
805 struct zfcp_adapter *adapter;
806 struct fc_host_statistics *fc_stats;
807 struct fsf_qtcb_bottom_port *data;
810 adapter = (struct zfcp_adapter *)shost->hostdata[0];
811 fc_stats = zfcp_init_fc_host_stats(adapter);
815 data = kmalloc(sizeof(*data), GFP_KERNEL);
818 memset(data, 0, sizeof(*data));
820 ret = zfcp_fsf_exchange_port_data(NULL, adapter, data);
823 return NULL; /* XXX return zeroed fc_stats? */
826 if (adapter->stats_reset &&
827 ((jiffies/HZ - adapter->stats_reset) <
828 data->seconds_since_last_reset)) {
829 zfcp_adjust_fc_host_stats(fc_stats, data,
830 adapter->stats_reset_data);
832 zfcp_set_fc_host_stats(fc_stats, data);
839 zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
841 struct zfcp_adapter *adapter;
842 struct fsf_qtcb_bottom_port *data, *old_data;
845 adapter = (struct zfcp_adapter *)shost->hostdata[0];
846 data = kmalloc(sizeof(*data), GFP_KERNEL);
849 memset(data, 0, sizeof(*data));
851 ret = zfcp_fsf_exchange_port_data(NULL, adapter, data);
853 adapter->stats_reset = jiffies/HZ;
854 old_data = adapter->stats_reset_data;
855 adapter->stats_reset_data = data; /* finally freed in
861 struct fc_function_template zfcp_transport_functions = {
862 .show_starget_port_id = 1,
863 .show_starget_port_name = 1,
864 .show_starget_node_name = 1,
865 .show_rport_supported_classes = 1,
866 .show_host_node_name = 1,
867 .show_host_port_name = 1,
868 .show_host_permanent_port_name = 1,
869 .show_host_supported_classes = 1,
870 .show_host_supported_speeds = 1,
871 .show_host_maxframe_size = 1,
872 .show_host_serial_number = 1,
873 .get_fc_host_stats = zfcp_get_fc_host_stats,
874 .reset_fc_host_stats = zfcp_reset_fc_host_stats,
875 /* no functions registered for following dynamic attributes but
876 directly set by LLDD */
877 .show_host_port_type = 1,
878 .show_host_speed = 1,
879 .show_host_port_id = 1,
883 * ZFCP_DEFINE_SCSI_ATTR
884 * @_name: name of show attribute
885 * @_format: format string
886 * @_value: value to print
888 * Generates attribute for a unit.
890 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
891 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_attribute *attr, \
894 struct scsi_device *sdev; \
895 struct zfcp_unit *unit; \
897 sdev = to_scsi_device(dev); \
898 unit = sdev->hostdata; \
899 return sprintf(buf, _format, _value); \
902 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
904 ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit));
905 ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
906 ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
908 static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {