2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_SCSI
25 #include <asm/atomic.h>
27 static void zfcp_scsi_slave_destroy(struct scsi_device *sdp);
28 static int zfcp_scsi_slave_alloc(struct scsi_device *sdp);
29 static int zfcp_scsi_slave_configure(struct scsi_device *sdp);
30 static int zfcp_scsi_queuecommand(struct scsi_cmnd *,
31 void (*done) (struct scsi_cmnd *));
32 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *);
33 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *);
34 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *);
35 static int zfcp_task_management_function(struct zfcp_unit *, u8,
38 static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int,
39 unsigned int, unsigned int);
41 static struct device_attribute *zfcp_sysfs_sdev_attrs[];
43 struct zfcp_data zfcp_data = {
44 .scsi_host_template = {
46 .module = THIS_MODULE,
48 .slave_alloc = zfcp_scsi_slave_alloc,
49 .slave_configure = zfcp_scsi_slave_configure,
50 .slave_destroy = zfcp_scsi_slave_destroy,
51 .queuecommand = zfcp_scsi_queuecommand,
52 .eh_abort_handler = zfcp_scsi_eh_abort_handler,
53 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
54 .eh_bus_reset_handler = zfcp_scsi_eh_host_reset_handler,
55 .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
58 .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ,
61 .sdev_attrs = zfcp_sysfs_sdev_attrs,
62 .max_sectors = ZFCP_MAX_SECTORS,
64 .driver_version = ZFCP_VERSION,
67 /* Find start of Response Information in FCP response unit*/
69 zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
71 char *fcp_rsp_info_ptr;
74 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
76 return fcp_rsp_info_ptr;
79 /* Find start of Sense Information in FCP response unit*/
81 zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
83 char *fcp_sns_info_ptr;
86 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
87 if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)
88 fcp_sns_info_ptr = (char *) fcp_sns_info_ptr +
89 fcp_rsp_iu->fcp_rsp_len;
91 return fcp_sns_info_ptr;
95 zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd)
97 int additional_length = fcp_cmd->add_fcp_cdb_length << 2;
98 fcp_dl_t *fcp_dl_addr;
100 fcp_dl_addr = (fcp_dl_t *)
101 ((unsigned char *) fcp_cmd +
102 sizeof (struct fcp_cmnd_iu) + additional_length);
104 * fcp_dl_addr = start address of fcp_cmnd structure +
105 * size of fixed part + size of dynamically sized add_dcp_cdb field
106 * SEE FCP-2 documentation
112 zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd)
114 return *zfcp_get_fcp_dl_ptr(fcp_cmd);
118 zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl)
120 *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl;
124 * note: it's a bit-or operation not an assignment
125 * regarding the specified byte
128 set_byte(int *result, char status, char pos)
130 *result |= status << (pos * 8);
134 set_host_byte(int *result, char status)
136 set_byte(result, status, 2);
140 set_driver_byte(int *result, char status)
142 set_byte(result, status, 3);
146 zfcp_scsi_slave_alloc(struct scsi_device *sdp)
148 struct zfcp_adapter *adapter;
149 struct zfcp_unit *unit;
153 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
157 read_lock_irqsave(&zfcp_data.config_lock, flags);
158 unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun);
159 if (unit && atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED,
161 sdp->hostdata = unit;
166 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
172 * zfcp_scsi_slave_destroy - called when scsi device is removed
174 * Remove reference to associated scsi device for an zfcp_unit.
175 * Mark zfcp_unit as failed. The scsi device might be deleted via sysfs
176 * or a scan for this device might have failed.
178 static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
180 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
183 zfcp_erp_wait(unit->port->adapter);
184 wait_event(unit->scsi_scan_wq,
185 atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
186 &unit->status) == 0);
187 atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status);
188 sdpnt->hostdata = NULL;
190 zfcp_erp_unit_failed(unit);
193 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at "
194 "address %p\n", sdpnt);
199 * called from scsi midlayer to allow finetuning of a device.
202 zfcp_scsi_slave_configure(struct scsi_device *sdp)
204 if (sdp->tagged_supported)
205 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN);
207 scsi_adjust_queue_depth(sdp, 0, 1);
212 * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function
213 * @scpnt: pointer to struct scsi_cmnd where result is set
214 * @result: result to be set in scpnt (e.g. DID_ERROR)
217 zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
219 set_host_byte(&scpnt->result, result);
220 if ((scpnt->device != NULL) && (scpnt->device->host != NULL))
221 zfcp_scsi_dbf_event_result("fail", 4,
222 (struct zfcp_adapter*) scpnt->device->host->hostdata[0],
224 /* return directly */
225 scpnt->scsi_done(scpnt);
229 * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and
230 * zfcp_scsi_command_sync
231 * @adapter: adapter where scsi command is issued
232 * @unit: unit to which scsi command is sent
233 * @scpnt: scsi command to be sent
234 * @timer: timer to be started if request is successfully initiated
236 * Note: In scsi_done function must be set in scpnt.
239 zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit,
240 struct scsi_cmnd *scpnt, int use_timer)
247 BUG_ON((adapter == NULL) || (adapter != unit->port->adapter));
248 BUG_ON(scpnt->scsi_done == NULL);
250 if (unlikely(NULL == unit)) {
251 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
256 atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) ||
257 !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) {
258 ZFCP_LOG_DEBUG("stopping SCSI I/O on unit 0x%016Lx on port "
259 "0x%016Lx on adapter %s\n",
260 unit->fcp_lun, unit->port->wwpn,
261 zfcp_get_busid_by_adapter(adapter));
262 zfcp_scsi_command_fail(scpnt, DID_ERROR);
267 !atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))) {
268 ZFCP_LOG_DEBUG("adapter %s not ready or unit 0x%016Lx "
269 "on port 0x%016Lx in recovery\n",
270 zfcp_get_busid_by_unit(unit),
271 unit->fcp_lun, unit->port->wwpn);
272 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
276 tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, use_timer,
277 ZFCP_REQ_AUTO_CLEANUP);
279 if (unlikely(tmp < 0)) {
280 ZFCP_LOG_DEBUG("error: initiation of Send FCP Cmnd failed\n");
281 retval = SCSI_MLQUEUE_HOST_BUSY;
289 zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt)
291 struct completion *wait = (struct completion *) scpnt->SCp.ptr;
297 * zfcp_scsi_command_sync - send a SCSI command and wait for completion
298 * @unit: unit where command is sent to
299 * @scpnt: scsi command to be sent
300 * @use_timer: indicates whether timer should be setup or not
303 * Errors are indicated in scpnt->result
306 zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt,
310 DECLARE_COMPLETION_ONSTACK(wait);
312 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */
313 scpnt->scsi_done = zfcp_scsi_command_sync_handler;
314 ret = zfcp_scsi_command_async(unit->port->adapter, unit, scpnt,
317 wait_for_completion(&wait);
319 scpnt->SCp.ptr = NULL;
325 * function: zfcp_scsi_queuecommand
327 * purpose: enqueues a SCSI command to the specified target device
329 * returns: 0 - success, SCSI command enqueued
333 zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
334 void (*done) (struct scsi_cmnd *))
336 struct zfcp_unit *unit;
337 struct zfcp_adapter *adapter;
339 /* reset the status for this request */
341 scpnt->host_scribble = NULL;
342 scpnt->scsi_done = done;
345 * figure out adapter and target device
346 * (stored there by zfcp_scsi_slave_alloc)
348 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
349 unit = (struct zfcp_unit *) scpnt->device->hostdata;
351 return zfcp_scsi_command_async(adapter, unit, scpnt, 0);
354 static struct zfcp_unit *
355 zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, unsigned int id,
358 struct zfcp_port *port;
359 struct zfcp_unit *unit, *retval = NULL;
361 list_for_each_entry(port, &adapter->port_list_head, list) {
362 if (!port->rport || (id != port->rport->scsi_target_id))
364 list_for_each_entry(unit, &port->unit_list_head, list) {
365 if (lun == unit->scsi_lun) {
376 * zfcp_scsi_eh_abort_handler - abort the specified SCSI command
377 * @scpnt: pointer to scsi_cmnd to be aborted
378 * Return: SUCCESS - command has been aborted and cleaned up in internal
379 * bookkeeping, SCSI stack won't be called for aborted command
382 * We do not need to care for a SCSI command which completes normally
383 * but late during this abort routine runs. We are allowed to return
384 * late commands to the SCSI stack. It tracks the state of commands and
385 * will handle late commands. (Usually, the normal completion of late
386 * commands is ignored with respect to the running abort operation.)
388 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
390 struct Scsi_Host *scsi_host;
391 struct zfcp_adapter *adapter;
392 struct zfcp_unit *unit;
393 struct zfcp_fsf_req *fsf_req;
395 unsigned long old_req_id;
396 int retval = SUCCESS;
398 scsi_host = scpnt->device->host;
399 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
400 unit = (struct zfcp_unit *) scpnt->device->hostdata;
402 ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n",
403 scpnt, zfcp_get_busid_by_adapter(adapter));
405 /* avoid race condition between late normal completion and abort */
406 write_lock_irqsave(&adapter->abort_lock, flags);
408 /* Check whether corresponding fsf_req is still pending */
409 spin_lock(&adapter->req_list_lock);
410 fsf_req = zfcp_reqlist_find(adapter,
411 (unsigned long) scpnt->host_scribble);
412 spin_unlock(&adapter->req_list_lock);
414 write_unlock_irqrestore(&adapter->abort_lock, flags);
415 zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, NULL, 0);
420 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING;
421 old_req_id = fsf_req->req_id;
423 /* don't access old fsf_req after releasing the abort_lock */
424 write_unlock_irqrestore(&adapter->abort_lock, flags);
426 fsf_req = zfcp_fsf_abort_fcp_command(old_req_id, adapter, unit, 0);
428 ZFCP_LOG_INFO("error: initiation of Abort FCP Cmnd failed\n");
429 zfcp_scsi_dbf_event_abort("nres", adapter, scpnt, NULL,
435 __wait_event(fsf_req->completion_wq,
436 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
438 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {
439 zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, fsf_req, 0);
441 } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
442 zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, fsf_req, 0);
445 zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, fsf_req, 0);
448 zfcp_fsf_req_free(fsf_req);
454 zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
457 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
460 ZFCP_LOG_NORMAL("bug: Tried reset for nonexistent unit\n");
464 ZFCP_LOG_NORMAL("resetting unit 0x%016Lx\n", unit->fcp_lun);
467 * If we do not know whether the unit supports 'logical unit reset'
468 * then try 'logical unit reset' and proceed with 'target reset'
469 * if 'logical unit reset' fails.
470 * If the unit is known not to support 'logical unit reset' then
471 * skip 'logical unit reset' and try 'target reset' immediately.
473 if (!atomic_test_mask(ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
475 retval = zfcp_task_management_function(unit,
476 FCP_LOGICAL_UNIT_RESET,
479 ZFCP_LOG_DEBUG("unit reset failed (unit=%p)\n", unit);
480 if (retval == -ENOTSUPP)
482 (ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
484 /* fall through and try 'target reset' next */
486 ZFCP_LOG_DEBUG("unit reset succeeded (unit=%p)\n",
488 /* avoid 'target reset' */
493 retval = zfcp_task_management_function(unit, FCP_TARGET_RESET, scpnt);
495 ZFCP_LOG_DEBUG("target reset failed (unit=%p)\n", unit);
498 ZFCP_LOG_DEBUG("target reset succeeded (unit=%p)\n", unit);
506 zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags,
507 struct scsi_cmnd *scpnt)
509 struct zfcp_adapter *adapter = unit->port->adapter;
510 struct zfcp_fsf_req *fsf_req;
513 /* issue task management function */
514 fsf_req = zfcp_fsf_send_fcp_command_task_management
515 (adapter, unit, tm_flags, 0);
517 ZFCP_LOG_INFO("error: creation of task management request "
518 "failed for unit 0x%016Lx on port 0x%016Lx on "
519 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
520 zfcp_get_busid_by_adapter(adapter));
521 zfcp_scsi_dbf_event_devreset("nres", tm_flags, unit, scpnt);
526 __wait_event(fsf_req->completion_wq,
527 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
530 * check completion status of task management function
532 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
533 zfcp_scsi_dbf_event_devreset("fail", tm_flags, unit, scpnt);
535 } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP) {
536 zfcp_scsi_dbf_event_devreset("nsup", tm_flags, unit, scpnt);
539 zfcp_scsi_dbf_event_devreset("okay", tm_flags, unit, scpnt);
541 zfcp_fsf_req_free(fsf_req);
547 * zfcp_scsi_eh_host_reset_handler - handler for host and bus reset
549 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
551 struct zfcp_unit *unit;
552 struct zfcp_adapter *adapter;
554 unit = (struct zfcp_unit*) scpnt->device->hostdata;
555 adapter = unit->port->adapter;
557 ZFCP_LOG_NORMAL("host/bus reset because of problems with "
558 "unit 0x%016Lx\n", unit->fcp_lun);
560 zfcp_erp_adapter_reopen(adapter, 0);
561 zfcp_erp_wait(adapter);
567 zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
570 static unsigned int unique_id = 0;
572 /* register adapter as SCSI host with mid layer of SCSI stack */
573 adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
574 sizeof (struct zfcp_adapter *));
575 if (!adapter->scsi_host) {
576 ZFCP_LOG_NORMAL("error: registration with SCSI stack failed "
578 zfcp_get_busid_by_adapter(adapter));
582 ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host);
584 /* tell the SCSI stack some characteristics of this adapter */
585 adapter->scsi_host->max_id = 1;
586 adapter->scsi_host->max_lun = 1;
587 adapter->scsi_host->max_channel = 0;
588 adapter->scsi_host->unique_id = unique_id++; /* FIXME */
589 adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH;
590 adapter->scsi_host->transportt = zfcp_data.scsi_transport_template;
593 * save a pointer to our own adapter data structure within
594 * hostdata field of SCSI host data structure
596 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
598 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
599 scsi_host_put(adapter->scsi_host);
603 atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
609 zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
611 struct Scsi_Host *shost;
612 struct zfcp_port *port;
614 shost = adapter->scsi_host;
617 read_lock_irq(&zfcp_data.config_lock);
618 list_for_each_entry(port, &adapter->port_list_head, list)
621 read_unlock_irq(&zfcp_data.config_lock);
622 fc_remove_host(shost);
623 scsi_remove_host(shost);
624 scsi_host_put(shost);
625 adapter->scsi_host = NULL;
626 atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
632 * Support functions for FC transport class
634 static struct fc_host_statistics*
635 zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
637 struct fc_host_statistics *fc_stats;
639 if (!adapter->fc_stats) {
640 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
643 adapter->fc_stats = fc_stats; /* freed in adater_dequeue */
645 memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
646 return adapter->fc_stats;
650 zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
651 struct fsf_qtcb_bottom_port *data,
652 struct fsf_qtcb_bottom_port *old)
654 fc_stats->seconds_since_last_reset = data->seconds_since_last_reset -
655 old->seconds_since_last_reset;
656 fc_stats->tx_frames = data->tx_frames - old->tx_frames;
657 fc_stats->tx_words = data->tx_words - old->tx_words;
658 fc_stats->rx_frames = data->rx_frames - old->rx_frames;
659 fc_stats->rx_words = data->rx_words - old->rx_words;
660 fc_stats->lip_count = data->lip - old->lip;
661 fc_stats->nos_count = data->nos - old->nos;
662 fc_stats->error_frames = data->error_frames - old->error_frames;
663 fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
664 fc_stats->link_failure_count = data->link_failure - old->link_failure;
665 fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
666 fc_stats->loss_of_signal_count = data->loss_of_signal -
668 fc_stats->prim_seq_protocol_err_count = data->psp_error_counts -
669 old->psp_error_counts;
670 fc_stats->invalid_tx_word_count = data->invalid_tx_words -
671 old->invalid_tx_words;
672 fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
673 fc_stats->fcp_input_requests = data->input_requests -
675 fc_stats->fcp_output_requests = data->output_requests -
676 old->output_requests;
677 fc_stats->fcp_control_requests = data->control_requests -
678 old->control_requests;
679 fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
680 fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
684 zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
685 struct fsf_qtcb_bottom_port *data)
687 fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
688 fc_stats->tx_frames = data->tx_frames;
689 fc_stats->tx_words = data->tx_words;
690 fc_stats->rx_frames = data->rx_frames;
691 fc_stats->rx_words = data->rx_words;
692 fc_stats->lip_count = data->lip;
693 fc_stats->nos_count = data->nos;
694 fc_stats->error_frames = data->error_frames;
695 fc_stats->dumped_frames = data->dumped_frames;
696 fc_stats->link_failure_count = data->link_failure;
697 fc_stats->loss_of_sync_count = data->loss_of_sync;
698 fc_stats->loss_of_signal_count = data->loss_of_signal;
699 fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
700 fc_stats->invalid_tx_word_count = data->invalid_tx_words;
701 fc_stats->invalid_crc_count = data->invalid_crcs;
702 fc_stats->fcp_input_requests = data->input_requests;
703 fc_stats->fcp_output_requests = data->output_requests;
704 fc_stats->fcp_control_requests = data->control_requests;
705 fc_stats->fcp_input_megabytes = data->input_mb;
706 fc_stats->fcp_output_megabytes = data->output_mb;
710 * zfcp_get_fc_host_stats - provide fc_host_statistics for scsi_transport_fc
712 * assumption: scsi_transport_fc synchronizes calls of
713 * get_fc_host_stats and reset_fc_host_stats
714 * (XXX to be checked otherwise introduce locking)
716 static struct fc_host_statistics *
717 zfcp_get_fc_host_stats(struct Scsi_Host *shost)
719 struct zfcp_adapter *adapter;
720 struct fc_host_statistics *fc_stats;
721 struct fsf_qtcb_bottom_port *data;
724 adapter = (struct zfcp_adapter *)shost->hostdata[0];
725 fc_stats = zfcp_init_fc_host_stats(adapter);
729 data = kzalloc(sizeof(*data), GFP_KERNEL);
733 ret = zfcp_fsf_exchange_port_data(NULL, adapter, data);
736 return NULL; /* XXX return zeroed fc_stats? */
739 if (adapter->stats_reset &&
740 ((jiffies/HZ - adapter->stats_reset) <
741 data->seconds_since_last_reset)) {
742 zfcp_adjust_fc_host_stats(fc_stats, data,
743 adapter->stats_reset_data);
745 zfcp_set_fc_host_stats(fc_stats, data);
752 zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
754 struct zfcp_adapter *adapter;
755 struct fsf_qtcb_bottom_port *data, *old_data;
758 adapter = (struct zfcp_adapter *)shost->hostdata[0];
759 data = kzalloc(sizeof(*data), GFP_KERNEL);
763 ret = zfcp_fsf_exchange_port_data(NULL, adapter, data);
765 adapter->stats_reset = jiffies/HZ;
766 old_data = adapter->stats_reset_data;
767 adapter->stats_reset_data = data; /* finally freed in
773 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
775 rport->dev_loss_tmo = timeout;
778 struct fc_function_template zfcp_transport_functions = {
779 .show_starget_port_id = 1,
780 .show_starget_port_name = 1,
781 .show_starget_node_name = 1,
782 .show_rport_supported_classes = 1,
783 .show_rport_maxframe_size = 1,
784 .show_rport_dev_loss_tmo = 1,
785 .show_host_node_name = 1,
786 .show_host_port_name = 1,
787 .show_host_permanent_port_name = 1,
788 .show_host_supported_classes = 1,
789 .show_host_supported_speeds = 1,
790 .show_host_maxframe_size = 1,
791 .show_host_serial_number = 1,
792 .get_fc_host_stats = zfcp_get_fc_host_stats,
793 .reset_fc_host_stats = zfcp_reset_fc_host_stats,
794 .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo,
795 /* no functions registered for following dynamic attributes but
796 directly set by LLDD */
797 .show_host_port_type = 1,
798 .show_host_speed = 1,
799 .show_host_port_id = 1,
803 * ZFCP_DEFINE_SCSI_ATTR
804 * @_name: name of show attribute
805 * @_format: format string
806 * @_value: value to print
808 * Generates attribute for a unit.
810 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
811 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_attribute *attr, \
814 struct scsi_device *sdev; \
815 struct zfcp_unit *unit; \
817 sdev = to_scsi_device(dev); \
818 unit = sdev->hostdata; \
819 return sprintf(buf, _format, _value); \
822 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
824 ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit));
825 ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
826 ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
828 static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {