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_target_reset_handler(struct scsi_cmnd *);
35 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *);
36 static int zfcp_task_management_function(struct zfcp_unit *, u8,
39 static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int,
40 unsigned int, unsigned int);
42 static struct device_attribute *zfcp_sysfs_sdev_attrs[];
44 struct zfcp_data zfcp_data = {
45 .scsi_host_template = {
47 .module = THIS_MODULE,
49 .slave_alloc = zfcp_scsi_slave_alloc,
50 .slave_configure = zfcp_scsi_slave_configure,
51 .slave_destroy = zfcp_scsi_slave_destroy,
52 .queuecommand = zfcp_scsi_queuecommand,
53 .eh_abort_handler = zfcp_scsi_eh_abort_handler,
54 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
55 .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
56 .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
59 .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ,
62 .sdev_attrs = zfcp_sysfs_sdev_attrs,
63 .max_sectors = ZFCP_MAX_SECTORS,
65 .driver_version = ZFCP_VERSION,
68 /* Find start of Response Information in FCP response unit*/
70 zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
72 char *fcp_rsp_info_ptr;
75 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
77 return fcp_rsp_info_ptr;
80 /* Find start of Sense Information in FCP response unit*/
82 zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
84 char *fcp_sns_info_ptr;
87 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
88 if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)
89 fcp_sns_info_ptr = (char *) fcp_sns_info_ptr +
90 fcp_rsp_iu->fcp_rsp_len;
92 return fcp_sns_info_ptr;
96 zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd)
98 int additional_length = fcp_cmd->add_fcp_cdb_length << 2;
99 fcp_dl_t *fcp_dl_addr;
101 fcp_dl_addr = (fcp_dl_t *)
102 ((unsigned char *) fcp_cmd +
103 sizeof (struct fcp_cmnd_iu) + additional_length);
105 * fcp_dl_addr = start address of fcp_cmnd structure +
106 * size of fixed part + size of dynamically sized add_dcp_cdb field
107 * SEE FCP-2 documentation
113 zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd)
115 return *zfcp_get_fcp_dl_ptr(fcp_cmd);
119 zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl)
121 *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl;
125 * note: it's a bit-or operation not an assignment
126 * regarding the specified byte
129 set_byte(int *result, char status, char pos)
131 *result |= status << (pos * 8);
135 set_host_byte(int *result, char status)
137 set_byte(result, status, 2);
141 set_driver_byte(int *result, char status)
143 set_byte(result, status, 3);
147 zfcp_scsi_slave_alloc(struct scsi_device *sdp)
149 struct zfcp_adapter *adapter;
150 struct zfcp_unit *unit;
154 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
158 read_lock_irqsave(&zfcp_data.config_lock, flags);
159 unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun);
160 if (unit && atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED,
162 sdp->hostdata = unit;
167 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
173 * zfcp_scsi_slave_destroy - called when scsi device is removed
175 * Remove reference to associated scsi device for an zfcp_unit.
176 * Mark zfcp_unit as failed. The scsi device might be deleted via sysfs
177 * or a scan for this device might have failed.
179 static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
181 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
184 zfcp_erp_wait(unit->port->adapter);
185 atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status);
186 sdpnt->hostdata = NULL;
188 zfcp_erp_unit_failed(unit);
191 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at "
192 "address %p\n", sdpnt);
196 * called from scsi midlayer to allow finetuning of a device.
199 zfcp_scsi_slave_configure(struct scsi_device *sdp)
201 if (sdp->tagged_supported)
202 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN);
204 scsi_adjust_queue_depth(sdp, 0, 1);
209 * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function
210 * @scpnt: pointer to struct scsi_cmnd where result is set
211 * @result: result to be set in scpnt (e.g. DID_ERROR)
214 zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
216 set_host_byte(&scpnt->result, result);
217 if ((scpnt->device != NULL) && (scpnt->device->host != NULL))
218 zfcp_scsi_dbf_event_result("fail", 4,
219 (struct zfcp_adapter*) scpnt->device->host->hostdata[0],
221 /* return directly */
222 scpnt->scsi_done(scpnt);
226 * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and
227 * zfcp_scsi_command_sync
228 * @adapter: adapter where scsi command is issued
229 * @unit: unit to which scsi command is sent
230 * @scpnt: scsi command to be sent
231 * @timer: timer to be started if request is successfully initiated
233 * Note: In scsi_done function must be set in scpnt.
236 zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit,
237 struct scsi_cmnd *scpnt, int use_timer)
244 BUG_ON((adapter == NULL) || (adapter != unit->port->adapter));
245 BUG_ON(scpnt->scsi_done == NULL);
247 if (unlikely(NULL == unit)) {
248 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
253 atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) ||
254 !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) {
255 ZFCP_LOG_DEBUG("stopping SCSI I/O on unit 0x%016Lx on port "
256 "0x%016Lx on adapter %s\n",
257 unit->fcp_lun, unit->port->wwpn,
258 zfcp_get_busid_by_adapter(adapter));
259 zfcp_scsi_command_fail(scpnt, DID_ERROR);
263 tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, use_timer,
264 ZFCP_REQ_AUTO_CLEANUP);
265 if (unlikely(tmp == -EBUSY)) {
266 ZFCP_LOG_DEBUG("adapter %s not ready or unit 0x%016Lx "
267 "on port 0x%016Lx in recovery\n",
268 zfcp_get_busid_by_unit(unit),
269 unit->fcp_lun, unit->port->wwpn);
270 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
274 if (unlikely(tmp < 0)) {
275 ZFCP_LOG_DEBUG("error: initiation of Send FCP Cmnd failed\n");
276 retval = SCSI_MLQUEUE_HOST_BUSY;
284 zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt)
286 struct completion *wait = (struct completion *) scpnt->SCp.ptr;
292 * zfcp_scsi_command_sync - send a SCSI command and wait for completion
293 * @unit: unit where command is sent to
294 * @scpnt: scsi command to be sent
295 * @use_timer: indicates whether timer should be setup or not
298 * Errors are indicated in scpnt->result
301 zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt,
305 DECLARE_COMPLETION_ONSTACK(wait);
307 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */
308 scpnt->scsi_done = zfcp_scsi_command_sync_handler;
309 ret = zfcp_scsi_command_async(unit->port->adapter, unit, scpnt,
312 wait_for_completion(&wait);
314 scpnt->SCp.ptr = NULL;
320 * function: zfcp_scsi_queuecommand
322 * purpose: enqueues a SCSI command to the specified target device
324 * returns: 0 - success, SCSI command enqueued
328 zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
329 void (*done) (struct scsi_cmnd *))
331 struct zfcp_unit *unit;
332 struct zfcp_adapter *adapter;
334 /* reset the status for this request */
336 scpnt->host_scribble = NULL;
337 scpnt->scsi_done = done;
340 * figure out adapter and target device
341 * (stored there by zfcp_scsi_slave_alloc)
343 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
344 unit = (struct zfcp_unit *) scpnt->device->hostdata;
346 return zfcp_scsi_command_async(adapter, unit, scpnt, 0);
349 static struct zfcp_unit *
350 zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, unsigned int id,
353 struct zfcp_port *port;
354 struct zfcp_unit *unit, *retval = NULL;
356 list_for_each_entry(port, &adapter->port_list_head, list) {
357 if (!port->rport || (id != port->rport->scsi_target_id))
359 list_for_each_entry(unit, &port->unit_list_head, list)
360 if (lun == unit->scsi_lun) {
370 * zfcp_scsi_eh_abort_handler - abort the specified SCSI command
371 * @scpnt: pointer to scsi_cmnd to be aborted
372 * Return: SUCCESS - command has been aborted and cleaned up in internal
373 * bookkeeping, SCSI stack won't be called for aborted command
376 * We do not need to care for a SCSI command which completes normally
377 * but late during this abort routine runs. We are allowed to return
378 * late commands to the SCSI stack. It tracks the state of commands and
379 * will handle late commands. (Usually, the normal completion of late
380 * commands is ignored with respect to the running abort operation.)
382 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
384 struct Scsi_Host *scsi_host;
385 struct zfcp_adapter *adapter;
386 struct zfcp_unit *unit;
387 struct zfcp_fsf_req *fsf_req;
389 unsigned long old_req_id;
390 int retval = SUCCESS;
392 scsi_host = scpnt->device->host;
393 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
394 unit = (struct zfcp_unit *) scpnt->device->hostdata;
396 ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n",
397 scpnt, zfcp_get_busid_by_adapter(adapter));
399 /* avoid race condition between late normal completion and abort */
400 write_lock_irqsave(&adapter->abort_lock, flags);
402 /* Check whether corresponding fsf_req is still pending */
403 spin_lock(&adapter->req_list_lock);
404 fsf_req = zfcp_reqlist_find(adapter,
405 (unsigned long) scpnt->host_scribble);
406 spin_unlock(&adapter->req_list_lock);
408 write_unlock_irqrestore(&adapter->abort_lock, flags);
409 zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, NULL, 0);
414 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING;
415 old_req_id = fsf_req->req_id;
417 /* don't access old fsf_req after releasing the abort_lock */
418 write_unlock_irqrestore(&adapter->abort_lock, flags);
420 fsf_req = zfcp_fsf_abort_fcp_command(old_req_id, adapter, unit, 0);
422 ZFCP_LOG_INFO("error: initiation of Abort FCP Cmnd failed\n");
423 zfcp_scsi_dbf_event_abort("nres", adapter, scpnt, NULL,
429 __wait_event(fsf_req->completion_wq,
430 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
432 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {
433 zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, fsf_req, 0);
435 } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
436 zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, fsf_req, 0);
439 zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, fsf_req, 0);
442 zfcp_fsf_req_free(fsf_req);
447 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
450 struct zfcp_unit *unit = scpnt->device->hostdata;
456 retval = zfcp_task_management_function(unit,
457 FCP_LOGICAL_UNIT_RESET,
459 return retval ? FAILED : SUCCESS;
462 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
465 struct zfcp_unit *unit = scpnt->device->hostdata;
471 retval = zfcp_task_management_function(unit, FCP_TARGET_RESET, scpnt);
472 return retval ? FAILED : SUCCESS;
476 zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags,
477 struct scsi_cmnd *scpnt)
479 struct zfcp_adapter *adapter = unit->port->adapter;
480 struct zfcp_fsf_req *fsf_req;
483 /* issue task management function */
484 fsf_req = zfcp_fsf_send_fcp_command_task_management
485 (adapter, unit, tm_flags, 0);
487 ZFCP_LOG_INFO("error: creation of task management request "
488 "failed for unit 0x%016Lx on port 0x%016Lx on "
489 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
490 zfcp_get_busid_by_adapter(adapter));
491 zfcp_scsi_dbf_event_devreset("nres", tm_flags, unit, scpnt);
496 __wait_event(fsf_req->completion_wq,
497 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
500 * check completion status of task management function
502 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
503 zfcp_scsi_dbf_event_devreset("fail", tm_flags, unit, scpnt);
505 } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP) {
506 zfcp_scsi_dbf_event_devreset("nsup", tm_flags, unit, scpnt);
509 zfcp_scsi_dbf_event_devreset("okay", tm_flags, unit, scpnt);
511 zfcp_fsf_req_free(fsf_req);
517 * zfcp_scsi_eh_host_reset_handler - handler for host reset
519 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
521 struct zfcp_unit *unit;
522 struct zfcp_adapter *adapter;
524 unit = (struct zfcp_unit*) scpnt->device->hostdata;
525 adapter = unit->port->adapter;
527 ZFCP_LOG_NORMAL("host reset because of problems with "
528 "unit 0x%016Lx on port 0x%016Lx, adapter %s\n",
529 unit->fcp_lun, unit->port->wwpn,
530 zfcp_get_busid_by_adapter(unit->port->adapter));
532 zfcp_erp_adapter_reopen(adapter, 0);
533 zfcp_erp_wait(adapter);
539 zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
542 static unsigned int unique_id = 0;
544 if (adapter->scsi_host)
547 /* register adapter as SCSI host with mid layer of SCSI stack */
548 adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
549 sizeof (struct zfcp_adapter *));
550 if (!adapter->scsi_host) {
551 ZFCP_LOG_NORMAL("error: registration with SCSI stack failed "
553 zfcp_get_busid_by_adapter(adapter));
557 ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host);
559 /* tell the SCSI stack some characteristics of this adapter */
560 adapter->scsi_host->max_id = 1;
561 adapter->scsi_host->max_lun = 1;
562 adapter->scsi_host->max_channel = 0;
563 adapter->scsi_host->unique_id = unique_id++; /* FIXME */
564 adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH;
565 adapter->scsi_host->transportt = zfcp_data.scsi_transport_template;
568 * save a pointer to our own adapter data structure within
569 * hostdata field of SCSI host data structure
571 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
573 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
574 scsi_host_put(adapter->scsi_host);
578 atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
584 zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
586 struct Scsi_Host *shost;
587 struct zfcp_port *port;
589 shost = adapter->scsi_host;
592 read_lock_irq(&zfcp_data.config_lock);
593 list_for_each_entry(port, &adapter->port_list_head, list)
596 read_unlock_irq(&zfcp_data.config_lock);
597 fc_remove_host(shost);
598 scsi_remove_host(shost);
599 scsi_host_put(shost);
600 adapter->scsi_host = NULL;
601 atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
607 * Support functions for FC transport class
609 static struct fc_host_statistics*
610 zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
612 struct fc_host_statistics *fc_stats;
614 if (!adapter->fc_stats) {
615 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
618 adapter->fc_stats = fc_stats; /* freed in adater_dequeue */
620 memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
621 return adapter->fc_stats;
625 zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
626 struct fsf_qtcb_bottom_port *data,
627 struct fsf_qtcb_bottom_port *old)
629 fc_stats->seconds_since_last_reset = data->seconds_since_last_reset -
630 old->seconds_since_last_reset;
631 fc_stats->tx_frames = data->tx_frames - old->tx_frames;
632 fc_stats->tx_words = data->tx_words - old->tx_words;
633 fc_stats->rx_frames = data->rx_frames - old->rx_frames;
634 fc_stats->rx_words = data->rx_words - old->rx_words;
635 fc_stats->lip_count = data->lip - old->lip;
636 fc_stats->nos_count = data->nos - old->nos;
637 fc_stats->error_frames = data->error_frames - old->error_frames;
638 fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
639 fc_stats->link_failure_count = data->link_failure - old->link_failure;
640 fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
641 fc_stats->loss_of_signal_count = data->loss_of_signal -
643 fc_stats->prim_seq_protocol_err_count = data->psp_error_counts -
644 old->psp_error_counts;
645 fc_stats->invalid_tx_word_count = data->invalid_tx_words -
646 old->invalid_tx_words;
647 fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
648 fc_stats->fcp_input_requests = data->input_requests -
650 fc_stats->fcp_output_requests = data->output_requests -
651 old->output_requests;
652 fc_stats->fcp_control_requests = data->control_requests -
653 old->control_requests;
654 fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
655 fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
659 zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
660 struct fsf_qtcb_bottom_port *data)
662 fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
663 fc_stats->tx_frames = data->tx_frames;
664 fc_stats->tx_words = data->tx_words;
665 fc_stats->rx_frames = data->rx_frames;
666 fc_stats->rx_words = data->rx_words;
667 fc_stats->lip_count = data->lip;
668 fc_stats->nos_count = data->nos;
669 fc_stats->error_frames = data->error_frames;
670 fc_stats->dumped_frames = data->dumped_frames;
671 fc_stats->link_failure_count = data->link_failure;
672 fc_stats->loss_of_sync_count = data->loss_of_sync;
673 fc_stats->loss_of_signal_count = data->loss_of_signal;
674 fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
675 fc_stats->invalid_tx_word_count = data->invalid_tx_words;
676 fc_stats->invalid_crc_count = data->invalid_crcs;
677 fc_stats->fcp_input_requests = data->input_requests;
678 fc_stats->fcp_output_requests = data->output_requests;
679 fc_stats->fcp_control_requests = data->control_requests;
680 fc_stats->fcp_input_megabytes = data->input_mb;
681 fc_stats->fcp_output_megabytes = data->output_mb;
685 * zfcp_get_fc_host_stats - provide fc_host_statistics for scsi_transport_fc
687 * assumption: scsi_transport_fc synchronizes calls of
688 * get_fc_host_stats and reset_fc_host_stats
689 * (XXX to be checked otherwise introduce locking)
691 static struct fc_host_statistics *
692 zfcp_get_fc_host_stats(struct Scsi_Host *shost)
694 struct zfcp_adapter *adapter;
695 struct fc_host_statistics *fc_stats;
696 struct fsf_qtcb_bottom_port *data;
699 adapter = (struct zfcp_adapter *)shost->hostdata[0];
700 fc_stats = zfcp_init_fc_host_stats(adapter);
704 data = kzalloc(sizeof(*data), GFP_KERNEL);
708 ret = zfcp_fsf_exchange_port_data_sync(adapter, data);
711 return NULL; /* XXX return zeroed fc_stats? */
714 if (adapter->stats_reset &&
715 ((jiffies/HZ - adapter->stats_reset) <
716 data->seconds_since_last_reset)) {
717 zfcp_adjust_fc_host_stats(fc_stats, data,
718 adapter->stats_reset_data);
720 zfcp_set_fc_host_stats(fc_stats, data);
727 zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
729 struct zfcp_adapter *adapter;
730 struct fsf_qtcb_bottom_port *data, *old_data;
733 adapter = (struct zfcp_adapter *)shost->hostdata[0];
734 data = kzalloc(sizeof(*data), GFP_KERNEL);
738 ret = zfcp_fsf_exchange_port_data_sync(adapter, data);
742 adapter->stats_reset = jiffies/HZ;
743 old_data = adapter->stats_reset_data;
744 adapter->stats_reset_data = data; /* finally freed in
750 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
752 rport->dev_loss_tmo = timeout;
755 struct fc_function_template zfcp_transport_functions = {
756 .show_starget_port_id = 1,
757 .show_starget_port_name = 1,
758 .show_starget_node_name = 1,
759 .show_rport_supported_classes = 1,
760 .show_rport_maxframe_size = 1,
761 .show_rport_dev_loss_tmo = 1,
762 .show_host_node_name = 1,
763 .show_host_port_name = 1,
764 .show_host_permanent_port_name = 1,
765 .show_host_supported_classes = 1,
766 .show_host_supported_speeds = 1,
767 .show_host_maxframe_size = 1,
768 .show_host_serial_number = 1,
769 .get_fc_host_stats = zfcp_get_fc_host_stats,
770 .reset_fc_host_stats = zfcp_reset_fc_host_stats,
771 .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo,
772 /* no functions registered for following dynamic attributes but
773 directly set by LLDD */
774 .show_host_port_type = 1,
775 .show_host_speed = 1,
776 .show_host_port_id = 1,
777 .disable_target_scan = 1,
781 * ZFCP_DEFINE_SCSI_ATTR
782 * @_name: name of show attribute
783 * @_format: format string
784 * @_value: value to print
786 * Generates attribute for a unit.
788 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
789 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_attribute *attr, \
792 struct scsi_device *sdev; \
793 struct zfcp_unit *unit; \
795 sdev = to_scsi_device(dev); \
796 unit = sdev->hostdata; \
797 return sprintf(buf, _format, _value); \
800 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
802 ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit));
803 ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
804 ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
806 static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {