4 * Interface to Linux SCSI midlayer.
6 * Copyright IBM Corp. 2002, 2016
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/slab.h>
15 #include <scsi/fc/fc_fcp.h>
16 #include <scsi/scsi_eh.h>
17 #include <linux/atomic.h>
21 #include "zfcp_reqlist.h"
23 static unsigned int default_depth
= 32;
24 module_param_named(queue_depth
, default_depth
, uint
, 0600);
25 MODULE_PARM_DESC(queue_depth
, "Default queue depth for new SCSI devices");
27 static bool enable_dif
;
28 module_param_named(dif
, enable_dif
, bool, 0400);
29 MODULE_PARM_DESC(dif
, "Enable DIF/DIX data integrity support");
31 static bool allow_lun_scan
= 1;
32 module_param(allow_lun_scan
, bool, 0600);
33 MODULE_PARM_DESC(allow_lun_scan
, "For NPIV, scan and attach all storage LUNs");
35 static int zfcp_scsi_change_queue_depth(struct scsi_device
*sdev
, int depth
,
39 case SCSI_QDEPTH_DEFAULT
:
40 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), depth
);
42 case SCSI_QDEPTH_QFULL
:
43 scsi_track_queue_full(sdev
, depth
);
45 case SCSI_QDEPTH_RAMP_UP
:
46 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), depth
);
51 return sdev
->queue_depth
;
54 static void zfcp_scsi_slave_destroy(struct scsi_device
*sdev
)
56 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
58 /* if previous slave_alloc returned early, there is nothing to do */
62 zfcp_erp_lun_shutdown_wait(sdev
, "scssd_1");
63 put_device(&zfcp_sdev
->port
->dev
);
66 static int zfcp_scsi_slave_configure(struct scsi_device
*sdp
)
68 if (sdp
->tagged_supported
)
69 scsi_adjust_queue_depth(sdp
, MSG_SIMPLE_TAG
, default_depth
);
71 scsi_adjust_queue_depth(sdp
, 0, 1);
75 static void zfcp_scsi_command_fail(struct scsi_cmnd
*scpnt
, int result
)
77 set_host_byte(scpnt
, result
);
78 zfcp_dbf_scsi_fail_send(scpnt
);
79 scpnt
->scsi_done(scpnt
);
83 int zfcp_scsi_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*scpnt
)
85 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
86 struct fc_rport
*rport
= starget_to_rport(scsi_target(scpnt
->device
));
87 int status
, scsi_result
, ret
;
89 /* reset the status for this request */
91 scpnt
->host_scribble
= NULL
;
93 scsi_result
= fc_remote_port_chkready(rport
);
94 if (unlikely(scsi_result
)) {
95 scpnt
->result
= scsi_result
;
96 zfcp_dbf_scsi_fail_send(scpnt
);
97 scpnt
->scsi_done(scpnt
);
101 status
= atomic_read(&zfcp_sdev
->status
);
102 if (unlikely(status
& ZFCP_STATUS_COMMON_ERP_FAILED
) &&
103 !(atomic_read(&zfcp_sdev
->port
->status
) &
104 ZFCP_STATUS_COMMON_ERP_FAILED
)) {
105 /* only LUN access denied, but port is good
106 * not covered by FC transport, have to fail here */
107 zfcp_scsi_command_fail(scpnt
, DID_ERROR
);
111 if (unlikely(!(status
& ZFCP_STATUS_COMMON_UNBLOCKED
))) {
113 * call to rport_delete pending: mimic retry from
114 * fc_remote_port_chkready until rport is BLOCKED
116 zfcp_scsi_command_fail(scpnt
, DID_IMM_RETRY
);
120 ret
= zfcp_fsf_fcp_cmnd(scpnt
);
121 if (unlikely(ret
== -EBUSY
))
122 return SCSI_MLQUEUE_DEVICE_BUSY
;
123 else if (unlikely(ret
< 0))
124 return SCSI_MLQUEUE_HOST_BUSY
;
129 static int zfcp_scsi_slave_alloc(struct scsi_device
*sdev
)
131 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
132 struct zfcp_adapter
*adapter
=
133 (struct zfcp_adapter
*) sdev
->host
->hostdata
[0];
134 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
135 struct zfcp_port
*port
;
136 struct zfcp_unit
*unit
;
137 int npiv
= adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
;
139 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
143 unit
= zfcp_unit_find(port
, zfcp_scsi_dev_lun(sdev
));
145 put_device(&unit
->dev
);
147 if (!unit
&& !(allow_lun_scan
&& npiv
)) {
148 put_device(&port
->dev
);
152 zfcp_sdev
->port
= port
;
153 zfcp_sdev
->latencies
.write
.channel
.min
= 0xFFFFFFFF;
154 zfcp_sdev
->latencies
.write
.fabric
.min
= 0xFFFFFFFF;
155 zfcp_sdev
->latencies
.read
.channel
.min
= 0xFFFFFFFF;
156 zfcp_sdev
->latencies
.read
.fabric
.min
= 0xFFFFFFFF;
157 zfcp_sdev
->latencies
.cmd
.channel
.min
= 0xFFFFFFFF;
158 zfcp_sdev
->latencies
.cmd
.fabric
.min
= 0xFFFFFFFF;
159 spin_lock_init(&zfcp_sdev
->latencies
.lock
);
161 zfcp_erp_set_lun_status(sdev
, ZFCP_STATUS_COMMON_RUNNING
);
162 zfcp_erp_lun_reopen(sdev
, 0, "scsla_1");
163 zfcp_erp_wait(port
->adapter
);
168 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd
*scpnt
)
170 struct Scsi_Host
*scsi_host
= scpnt
->device
->host
;
171 struct zfcp_adapter
*adapter
=
172 (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
173 struct zfcp_fsf_req
*old_req
, *abrt_req
;
175 unsigned long old_reqid
= (unsigned long) scpnt
->host_scribble
;
176 int retval
= SUCCESS
, ret
;
180 /* avoid race condition between late normal completion and abort */
181 write_lock_irqsave(&adapter
->abort_lock
, flags
);
183 old_req
= zfcp_reqlist_find(adapter
->req_list
, old_reqid
);
185 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
186 zfcp_dbf_scsi_abort("abrt_or", scpnt
, NULL
);
187 return FAILED
; /* completion could be in progress */
189 old_req
->data
= NULL
;
191 /* don't access old fsf_req after releasing the abort_lock */
192 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
195 abrt_req
= zfcp_fsf_abort_fcp_cmnd(scpnt
);
199 zfcp_erp_wait(adapter
);
200 ret
= fc_block_scsi_eh(scpnt
);
202 zfcp_dbf_scsi_abort("abrt_bl", scpnt
, NULL
);
205 if (!(atomic_read(&adapter
->status
) &
206 ZFCP_STATUS_COMMON_RUNNING
)) {
207 zfcp_dbf_scsi_abort("abrt_ru", scpnt
, NULL
);
212 zfcp_dbf_scsi_abort("abrt_ar", scpnt
, NULL
);
216 wait_for_completion(&abrt_req
->completion
);
218 if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED
)
220 else if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED
)
226 zfcp_dbf_scsi_abort(dbf_tag
, scpnt
, abrt_req
);
227 zfcp_fsf_req_free(abrt_req
);
231 struct zfcp_scsi_req_filter
{
237 static void zfcp_scsi_forget_cmnd(struct zfcp_fsf_req
*old_req
, void *data
)
239 struct zfcp_scsi_req_filter
*filter
=
240 (struct zfcp_scsi_req_filter
*)data
;
242 /* already aborted - prevent side-effects - or not a SCSI command */
243 if (old_req
->data
== NULL
|| old_req
->fsf_command
!= FSF_QTCB_FCP_CMND
)
246 /* (tmf_scope == FCP_TMF_TGT_RESET || tmf_scope == FCP_TMF_LUN_RESET) */
247 if (old_req
->qtcb
->header
.port_handle
!= filter
->port_handle
)
250 if (filter
->tmf_scope
== FCP_TMF_LUN_RESET
&&
251 old_req
->qtcb
->header
.lun_handle
!= filter
->lun_handle
)
254 zfcp_dbf_scsi_nullcmnd((struct scsi_cmnd
*)old_req
->data
, old_req
);
255 old_req
->data
= NULL
;
258 static void zfcp_scsi_forget_cmnds(struct zfcp_scsi_dev
*zsdev
, u8 tm_flags
)
260 struct zfcp_adapter
*adapter
= zsdev
->port
->adapter
;
261 struct zfcp_scsi_req_filter filter
= {
262 .tmf_scope
= FCP_TMF_TGT_RESET
,
263 .port_handle
= zsdev
->port
->handle
,
267 if (tm_flags
== FCP_TMF_LUN_RESET
) {
268 filter
.tmf_scope
= FCP_TMF_LUN_RESET
;
269 filter
.lun_handle
= zsdev
->lun_handle
;
273 * abort_lock secures against other processings - in the abort-function
274 * and normal cmnd-handler - of (struct zfcp_fsf_req *)->data
276 write_lock_irqsave(&adapter
->abort_lock
, flags
);
277 zfcp_reqlist_apply_for_all(adapter
->req_list
, zfcp_scsi_forget_cmnd
,
279 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
282 static int zfcp_task_mgmt_function(struct scsi_cmnd
*scpnt
, u8 tm_flags
)
284 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
285 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
286 struct zfcp_fsf_req
*fsf_req
= NULL
;
287 int retval
= SUCCESS
, ret
;
291 fsf_req
= zfcp_fsf_fcp_task_mgmt(scpnt
, tm_flags
);
295 zfcp_erp_wait(adapter
);
296 ret
= fc_block_scsi_eh(scpnt
);
298 zfcp_dbf_scsi_devreset("fiof", scpnt
, tm_flags
);
302 if (!(atomic_read(&adapter
->status
) &
303 ZFCP_STATUS_COMMON_RUNNING
)) {
304 zfcp_dbf_scsi_devreset("nres", scpnt
, tm_flags
);
309 zfcp_dbf_scsi_devreset("reqf", scpnt
, tm_flags
);
313 wait_for_completion(&fsf_req
->completion
);
315 if (fsf_req
->status
& ZFCP_STATUS_FSFREQ_TMFUNCFAILED
) {
316 zfcp_dbf_scsi_devreset("fail", scpnt
, tm_flags
);
319 zfcp_dbf_scsi_devreset("okay", scpnt
, tm_flags
);
320 zfcp_scsi_forget_cmnds(zfcp_sdev
, tm_flags
);
323 zfcp_fsf_req_free(fsf_req
);
327 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd
*scpnt
)
329 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_LUN_RESET
);
332 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd
*scpnt
)
334 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_TGT_RESET
);
337 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd
*scpnt
)
339 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
340 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
343 zfcp_erp_adapter_reopen(adapter
, 0, "schrh_1");
344 zfcp_erp_wait(adapter
);
345 ret
= fc_block_scsi_eh(scpnt
);
352 struct scsi_transport_template
*zfcp_scsi_transport_template
;
354 static struct scsi_host_template zfcp_scsi_host_template
= {
355 .module
= THIS_MODULE
,
357 .queuecommand
= zfcp_scsi_queuecommand
,
358 .eh_abort_handler
= zfcp_scsi_eh_abort_handler
,
359 .eh_device_reset_handler
= zfcp_scsi_eh_device_reset_handler
,
360 .eh_target_reset_handler
= zfcp_scsi_eh_target_reset_handler
,
361 .eh_host_reset_handler
= zfcp_scsi_eh_host_reset_handler
,
362 .slave_alloc
= zfcp_scsi_slave_alloc
,
363 .slave_configure
= zfcp_scsi_slave_configure
,
364 .slave_destroy
= zfcp_scsi_slave_destroy
,
365 .change_queue_depth
= zfcp_scsi_change_queue_depth
,
369 .sg_tablesize
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
370 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2),
371 /* GCD, adjusted later */
372 .max_sectors
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
373 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2) * 8,
374 /* GCD, adjusted later */
375 .dma_boundary
= ZFCP_QDIO_SBALE_LEN
- 1,
378 .shost_attrs
= zfcp_sysfs_shost_attrs
,
379 .sdev_attrs
= zfcp_sysfs_sdev_attrs
,
383 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
384 * @adapter: The zfcp adapter to register with the SCSI midlayer
386 int zfcp_scsi_adapter_register(struct zfcp_adapter
*adapter
)
388 struct ccw_dev_id dev_id
;
390 if (adapter
->scsi_host
)
393 ccw_device_get_id(adapter
->ccw_device
, &dev_id
);
394 /* register adapter as SCSI host with mid layer of SCSI stack */
395 adapter
->scsi_host
= scsi_host_alloc(&zfcp_scsi_host_template
,
396 sizeof (struct zfcp_adapter
*));
397 if (!adapter
->scsi_host
) {
398 dev_err(&adapter
->ccw_device
->dev
,
399 "Registering the FCP device with the "
400 "SCSI stack failed\n");
404 /* tell the SCSI stack some characteristics of this adapter */
405 adapter
->scsi_host
->max_id
= 511;
406 adapter
->scsi_host
->max_lun
= 0xFFFFFFFF;
407 adapter
->scsi_host
->max_channel
= 0;
408 adapter
->scsi_host
->unique_id
= dev_id
.devno
;
409 adapter
->scsi_host
->max_cmd_len
= 16; /* in struct fcp_cmnd */
410 adapter
->scsi_host
->transportt
= zfcp_scsi_transport_template
;
412 adapter
->scsi_host
->hostdata
[0] = (unsigned long) adapter
;
414 if (scsi_add_host(adapter
->scsi_host
, &adapter
->ccw_device
->dev
)) {
415 scsi_host_put(adapter
->scsi_host
);
423 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
424 * @adapter: The zfcp adapter to unregister.
426 void zfcp_scsi_adapter_unregister(struct zfcp_adapter
*adapter
)
428 struct Scsi_Host
*shost
;
429 struct zfcp_port
*port
;
431 shost
= adapter
->scsi_host
;
435 read_lock_irq(&adapter
->port_list_lock
);
436 list_for_each_entry(port
, &adapter
->port_list
, list
)
438 read_unlock_irq(&adapter
->port_list_lock
);
440 fc_remove_host(shost
);
441 scsi_remove_host(shost
);
442 scsi_host_put(shost
);
443 adapter
->scsi_host
= NULL
;
446 static struct fc_host_statistics
*
447 zfcp_init_fc_host_stats(struct zfcp_adapter
*adapter
)
449 struct fc_host_statistics
*fc_stats
;
451 if (!adapter
->fc_stats
) {
452 fc_stats
= kmalloc(sizeof(*fc_stats
), GFP_KERNEL
);
455 adapter
->fc_stats
= fc_stats
; /* freed in adapter_release */
457 memset(adapter
->fc_stats
, 0, sizeof(*adapter
->fc_stats
));
458 return adapter
->fc_stats
;
461 static void zfcp_adjust_fc_host_stats(struct fc_host_statistics
*fc_stats
,
462 struct fsf_qtcb_bottom_port
*data
,
463 struct fsf_qtcb_bottom_port
*old
)
465 fc_stats
->seconds_since_last_reset
=
466 data
->seconds_since_last_reset
- old
->seconds_since_last_reset
;
467 fc_stats
->tx_frames
= data
->tx_frames
- old
->tx_frames
;
468 fc_stats
->tx_words
= data
->tx_words
- old
->tx_words
;
469 fc_stats
->rx_frames
= data
->rx_frames
- old
->rx_frames
;
470 fc_stats
->rx_words
= data
->rx_words
- old
->rx_words
;
471 fc_stats
->lip_count
= data
->lip
- old
->lip
;
472 fc_stats
->nos_count
= data
->nos
- old
->nos
;
473 fc_stats
->error_frames
= data
->error_frames
- old
->error_frames
;
474 fc_stats
->dumped_frames
= data
->dumped_frames
- old
->dumped_frames
;
475 fc_stats
->link_failure_count
= data
->link_failure
- old
->link_failure
;
476 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
- old
->loss_of_sync
;
477 fc_stats
->loss_of_signal_count
=
478 data
->loss_of_signal
- old
->loss_of_signal
;
479 fc_stats
->prim_seq_protocol_err_count
=
480 data
->psp_error_counts
- old
->psp_error_counts
;
481 fc_stats
->invalid_tx_word_count
=
482 data
->invalid_tx_words
- old
->invalid_tx_words
;
483 fc_stats
->invalid_crc_count
= data
->invalid_crcs
- old
->invalid_crcs
;
484 fc_stats
->fcp_input_requests
=
485 data
->input_requests
- old
->input_requests
;
486 fc_stats
->fcp_output_requests
=
487 data
->output_requests
- old
->output_requests
;
488 fc_stats
->fcp_control_requests
=
489 data
->control_requests
- old
->control_requests
;
490 fc_stats
->fcp_input_megabytes
= data
->input_mb
- old
->input_mb
;
491 fc_stats
->fcp_output_megabytes
= data
->output_mb
- old
->output_mb
;
494 static void zfcp_set_fc_host_stats(struct fc_host_statistics
*fc_stats
,
495 struct fsf_qtcb_bottom_port
*data
)
497 fc_stats
->seconds_since_last_reset
= data
->seconds_since_last_reset
;
498 fc_stats
->tx_frames
= data
->tx_frames
;
499 fc_stats
->tx_words
= data
->tx_words
;
500 fc_stats
->rx_frames
= data
->rx_frames
;
501 fc_stats
->rx_words
= data
->rx_words
;
502 fc_stats
->lip_count
= data
->lip
;
503 fc_stats
->nos_count
= data
->nos
;
504 fc_stats
->error_frames
= data
->error_frames
;
505 fc_stats
->dumped_frames
= data
->dumped_frames
;
506 fc_stats
->link_failure_count
= data
->link_failure
;
507 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
;
508 fc_stats
->loss_of_signal_count
= data
->loss_of_signal
;
509 fc_stats
->prim_seq_protocol_err_count
= data
->psp_error_counts
;
510 fc_stats
->invalid_tx_word_count
= data
->invalid_tx_words
;
511 fc_stats
->invalid_crc_count
= data
->invalid_crcs
;
512 fc_stats
->fcp_input_requests
= data
->input_requests
;
513 fc_stats
->fcp_output_requests
= data
->output_requests
;
514 fc_stats
->fcp_control_requests
= data
->control_requests
;
515 fc_stats
->fcp_input_megabytes
= data
->input_mb
;
516 fc_stats
->fcp_output_megabytes
= data
->output_mb
;
519 static struct fc_host_statistics
*zfcp_get_fc_host_stats(struct Scsi_Host
*host
)
521 struct zfcp_adapter
*adapter
;
522 struct fc_host_statistics
*fc_stats
;
523 struct fsf_qtcb_bottom_port
*data
;
526 adapter
= (struct zfcp_adapter
*)host
->hostdata
[0];
527 fc_stats
= zfcp_init_fc_host_stats(adapter
);
531 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
535 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
541 if (adapter
->stats_reset
&&
542 ((jiffies
/HZ
- adapter
->stats_reset
) <
543 data
->seconds_since_last_reset
))
544 zfcp_adjust_fc_host_stats(fc_stats
, data
,
545 adapter
->stats_reset_data
);
547 zfcp_set_fc_host_stats(fc_stats
, data
);
553 static void zfcp_reset_fc_host_stats(struct Scsi_Host
*shost
)
555 struct zfcp_adapter
*adapter
;
556 struct fsf_qtcb_bottom_port
*data
;
559 adapter
= (struct zfcp_adapter
*)shost
->hostdata
[0];
560 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
564 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
568 adapter
->stats_reset
= jiffies
/HZ
;
569 kfree(adapter
->stats_reset_data
);
570 adapter
->stats_reset_data
= data
; /* finally freed in
575 static void zfcp_get_host_port_state(struct Scsi_Host
*shost
)
577 struct zfcp_adapter
*adapter
=
578 (struct zfcp_adapter
*)shost
->hostdata
[0];
579 int status
= atomic_read(&adapter
->status
);
581 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
582 !(status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
))
583 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
584 else if (status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
)
585 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
586 else if (status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
587 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
589 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
592 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
594 rport
->dev_loss_tmo
= timeout
;
598 * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
599 * @rport: The FC rport where to teminate I/O
601 * Abort all pending SCSI commands for a port by closing the
602 * port. Using a reopen avoids a conflict with a shutdown
603 * overwriting a reopen. The "forced" ensures that a disappeared port
604 * is not opened again as valid due to the cached plogi data in
607 static void zfcp_scsi_terminate_rport_io(struct fc_rport
*rport
)
609 struct zfcp_port
*port
;
610 struct Scsi_Host
*shost
= rport_to_shost(rport
);
611 struct zfcp_adapter
*adapter
=
612 (struct zfcp_adapter
*)shost
->hostdata
[0];
614 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
617 zfcp_erp_port_forced_reopen(port
, 0, "sctrpi1");
618 put_device(&port
->dev
);
622 static void zfcp_scsi_rport_register(struct zfcp_port
*port
)
624 struct fc_rport_identifiers ids
;
625 struct fc_rport
*rport
;
630 ids
.node_name
= port
->wwnn
;
631 ids
.port_name
= port
->wwpn
;
632 ids
.port_id
= port
->d_id
;
633 ids
.roles
= FC_RPORT_ROLE_FCP_TARGET
;
635 zfcp_dbf_rec_trig("scpaddy", port
->adapter
, port
, NULL
,
636 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD
,
637 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD
);
638 rport
= fc_remote_port_add(port
->adapter
->scsi_host
, 0, &ids
);
640 dev_err(&port
->adapter
->ccw_device
->dev
,
641 "Registering port 0x%016Lx failed\n",
642 (unsigned long long)port
->wwpn
);
646 rport
->maxframe_size
= port
->maxframe_size
;
647 rport
->supported_classes
= port
->supported_classes
;
649 port
->starget_id
= rport
->scsi_target_id
;
651 zfcp_unit_queue_scsi_scan(port
);
654 static void zfcp_scsi_rport_block(struct zfcp_port
*port
)
656 struct fc_rport
*rport
= port
->rport
;
659 zfcp_dbf_rec_trig("scpdely", port
->adapter
, port
, NULL
,
660 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL
,
661 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL
);
662 fc_remote_port_delete(rport
);
667 void zfcp_scsi_schedule_rport_register(struct zfcp_port
*port
)
669 get_device(&port
->dev
);
670 port
->rport_task
= RPORT_ADD
;
672 if (!queue_work(port
->adapter
->work_queue
, &port
->rport_work
))
673 put_device(&port
->dev
);
676 void zfcp_scsi_schedule_rport_block(struct zfcp_port
*port
)
678 get_device(&port
->dev
);
679 port
->rport_task
= RPORT_DEL
;
681 if (port
->rport
&& queue_work(port
->adapter
->work_queue
,
685 put_device(&port
->dev
);
688 void zfcp_scsi_schedule_rports_block(struct zfcp_adapter
*adapter
)
691 struct zfcp_port
*port
;
693 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
694 list_for_each_entry(port
, &adapter
->port_list
, list
)
695 zfcp_scsi_schedule_rport_block(port
);
696 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
699 void zfcp_scsi_rport_work(struct work_struct
*work
)
701 struct zfcp_port
*port
= container_of(work
, struct zfcp_port
,
704 while (port
->rport_task
) {
705 if (port
->rport_task
== RPORT_ADD
) {
706 port
->rport_task
= RPORT_NONE
;
707 zfcp_scsi_rport_register(port
);
709 port
->rport_task
= RPORT_NONE
;
710 zfcp_scsi_rport_block(port
);
714 put_device(&port
->dev
);
718 * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
719 * @adapter: The adapter where to configure DIF/DIX for the SCSI host
721 void zfcp_scsi_set_prot(struct zfcp_adapter
*adapter
)
723 unsigned int mask
= 0;
724 unsigned int data_div
;
725 struct Scsi_Host
*shost
= adapter
->scsi_host
;
727 data_div
= atomic_read(&adapter
->status
) &
728 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED
;
731 adapter
->adapter_features
& FSF_FEATURE_DIF_PROT_TYPE1
)
732 mask
|= SHOST_DIF_TYPE1_PROTECTION
;
734 if (enable_dif
&& data_div
&&
735 adapter
->adapter_features
& FSF_FEATURE_DIX_PROT_TCPIP
) {
736 mask
|= SHOST_DIX_TYPE1_PROTECTION
;
737 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_IP
);
738 shost
->sg_prot_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
739 shost
->sg_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
740 shost
->max_sectors
= shost
->sg_tablesize
* 8;
743 scsi_host_set_prot(shost
, mask
);
747 * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
748 * @scmd: The SCSI command to report the error for
749 * @ascq: The ASCQ to put in the sense buffer
751 * See the error handling in sd_done for the sense codes used here.
752 * Set DID_SOFT_ERROR to retry the request, if possible.
754 void zfcp_scsi_dif_sense_error(struct scsi_cmnd
*scmd
, int ascq
)
756 scsi_build_sense_buffer(1, scmd
->sense_buffer
,
757 ILLEGAL_REQUEST
, 0x10, ascq
);
758 set_driver_byte(scmd
, DRIVER_SENSE
);
759 scmd
->result
|= SAM_STAT_CHECK_CONDITION
;
760 set_host_byte(scmd
, DID_SOFT_ERROR
);
763 struct fc_function_template zfcp_transport_functions
= {
764 .show_starget_port_id
= 1,
765 .show_starget_port_name
= 1,
766 .show_starget_node_name
= 1,
767 .show_rport_supported_classes
= 1,
768 .show_rport_maxframe_size
= 1,
769 .show_rport_dev_loss_tmo
= 1,
770 .show_host_node_name
= 1,
771 .show_host_port_name
= 1,
772 .show_host_permanent_port_name
= 1,
773 .show_host_supported_classes
= 1,
774 .show_host_supported_fc4s
= 1,
775 .show_host_supported_speeds
= 1,
776 .show_host_maxframe_size
= 1,
777 .show_host_serial_number
= 1,
778 .get_fc_host_stats
= zfcp_get_fc_host_stats
,
779 .reset_fc_host_stats
= zfcp_reset_fc_host_stats
,
780 .set_rport_dev_loss_tmo
= zfcp_set_rport_dev_loss_tmo
,
781 .get_host_port_state
= zfcp_get_host_port_state
,
782 .terminate_rport_io
= zfcp_scsi_terminate_rport_io
,
783 .show_host_port_state
= 1,
784 .show_host_active_fc4s
= 1,
785 .bsg_request
= zfcp_fc_exec_bsg_job
,
786 .bsg_timeout
= zfcp_fc_timeout_bsg_job
,
787 /* no functions registered for following dynamic attributes but
788 directly set by LLDD */
789 .show_host_port_type
= 1,
790 .show_host_symbolic_name
= 1,
791 .show_host_speed
= 1,
792 .show_host_port_id
= 1,
793 .dd_bsg_size
= sizeof(struct zfcp_fsf_ct_els
),