4 * Interface to Linux SCSI midlayer.
6 * Copyright IBM Corp. 2002, 2013
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
))) {
112 /* This could be either
113 * open LUN pending: this is temporary, will result in
114 * open LUN or ERP_FAILED, so retry command
115 * call to rport_delete pending: mimic retry from
116 * fc_remote_port_chkready until rport is BLOCKED
118 zfcp_scsi_command_fail(scpnt
, DID_IMM_RETRY
);
122 ret
= zfcp_fsf_fcp_cmnd(scpnt
);
123 if (unlikely(ret
== -EBUSY
))
124 return SCSI_MLQUEUE_DEVICE_BUSY
;
125 else if (unlikely(ret
< 0))
126 return SCSI_MLQUEUE_HOST_BUSY
;
131 static int zfcp_scsi_slave_alloc(struct scsi_device
*sdev
)
133 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
134 struct zfcp_adapter
*adapter
=
135 (struct zfcp_adapter
*) sdev
->host
->hostdata
[0];
136 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
137 struct zfcp_port
*port
;
138 struct zfcp_unit
*unit
;
139 int npiv
= adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
;
141 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
145 unit
= zfcp_unit_find(port
, zfcp_scsi_dev_lun(sdev
));
147 put_device(&unit
->dev
);
149 if (!unit
&& !(allow_lun_scan
&& npiv
)) {
150 put_device(&port
->dev
);
154 zfcp_sdev
->port
= port
;
155 zfcp_sdev
->latencies
.write
.channel
.min
= 0xFFFFFFFF;
156 zfcp_sdev
->latencies
.write
.fabric
.min
= 0xFFFFFFFF;
157 zfcp_sdev
->latencies
.read
.channel
.min
= 0xFFFFFFFF;
158 zfcp_sdev
->latencies
.read
.fabric
.min
= 0xFFFFFFFF;
159 zfcp_sdev
->latencies
.cmd
.channel
.min
= 0xFFFFFFFF;
160 zfcp_sdev
->latencies
.cmd
.fabric
.min
= 0xFFFFFFFF;
161 spin_lock_init(&zfcp_sdev
->latencies
.lock
);
163 zfcp_erp_set_lun_status(sdev
, ZFCP_STATUS_COMMON_RUNNING
);
164 zfcp_erp_lun_reopen(sdev
, 0, "scsla_1");
165 zfcp_erp_wait(port
->adapter
);
170 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd
*scpnt
)
172 struct Scsi_Host
*scsi_host
= scpnt
->device
->host
;
173 struct zfcp_adapter
*adapter
=
174 (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
175 struct zfcp_fsf_req
*old_req
, *abrt_req
;
177 unsigned long old_reqid
= (unsigned long) scpnt
->host_scribble
;
178 int retval
= SUCCESS
, ret
;
182 /* avoid race condition between late normal completion and abort */
183 write_lock_irqsave(&adapter
->abort_lock
, flags
);
185 old_req
= zfcp_reqlist_find(adapter
->req_list
, old_reqid
);
187 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
188 zfcp_dbf_scsi_abort("abrt_or", scpnt
, NULL
);
189 return FAILED
; /* completion could be in progress */
191 old_req
->data
= NULL
;
193 /* don't access old fsf_req after releasing the abort_lock */
194 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
197 abrt_req
= zfcp_fsf_abort_fcp_cmnd(scpnt
);
201 zfcp_erp_wait(adapter
);
202 ret
= fc_block_scsi_eh(scpnt
);
204 zfcp_dbf_scsi_abort("abrt_bl", scpnt
, NULL
);
207 if (!(atomic_read(&adapter
->status
) &
208 ZFCP_STATUS_COMMON_RUNNING
)) {
209 zfcp_dbf_scsi_abort("abrt_ru", scpnt
, NULL
);
214 zfcp_dbf_scsi_abort("abrt_ar", scpnt
, NULL
);
218 wait_for_completion(&abrt_req
->completion
);
220 if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED
)
222 else if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED
)
228 zfcp_dbf_scsi_abort(dbf_tag
, scpnt
, abrt_req
);
229 zfcp_fsf_req_free(abrt_req
);
233 static int zfcp_task_mgmt_function(struct scsi_cmnd
*scpnt
, u8 tm_flags
)
235 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
236 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
237 struct zfcp_fsf_req
*fsf_req
= NULL
;
238 int retval
= SUCCESS
, ret
;
242 fsf_req
= zfcp_fsf_fcp_task_mgmt(scpnt
, tm_flags
);
246 zfcp_erp_wait(adapter
);
247 ret
= fc_block_scsi_eh(scpnt
);
251 if (!(atomic_read(&adapter
->status
) &
252 ZFCP_STATUS_COMMON_RUNNING
)) {
253 zfcp_dbf_scsi_devreset("nres", scpnt
, tm_flags
);
260 wait_for_completion(&fsf_req
->completion
);
262 if (fsf_req
->status
& ZFCP_STATUS_FSFREQ_TMFUNCFAILED
) {
263 zfcp_dbf_scsi_devreset("fail", scpnt
, tm_flags
);
266 zfcp_dbf_scsi_devreset("okay", scpnt
, tm_flags
);
268 zfcp_fsf_req_free(fsf_req
);
272 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd
*scpnt
)
274 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_LUN_RESET
);
277 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd
*scpnt
)
279 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_TGT_RESET
);
282 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd
*scpnt
)
284 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
285 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
288 zfcp_erp_adapter_reopen(adapter
, 0, "schrh_1");
289 zfcp_erp_wait(adapter
);
290 ret
= fc_block_scsi_eh(scpnt
);
297 struct scsi_transport_template
*zfcp_scsi_transport_template
;
299 static struct scsi_host_template zfcp_scsi_host_template
= {
300 .module
= THIS_MODULE
,
302 .queuecommand
= zfcp_scsi_queuecommand
,
303 .eh_abort_handler
= zfcp_scsi_eh_abort_handler
,
304 .eh_device_reset_handler
= zfcp_scsi_eh_device_reset_handler
,
305 .eh_target_reset_handler
= zfcp_scsi_eh_target_reset_handler
,
306 .eh_host_reset_handler
= zfcp_scsi_eh_host_reset_handler
,
307 .slave_alloc
= zfcp_scsi_slave_alloc
,
308 .slave_configure
= zfcp_scsi_slave_configure
,
309 .slave_destroy
= zfcp_scsi_slave_destroy
,
310 .change_queue_depth
= zfcp_scsi_change_queue_depth
,
314 .sg_tablesize
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
315 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2),
316 /* GCD, adjusted later */
317 .max_sectors
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
318 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2) * 8,
319 /* GCD, adjusted later */
320 .dma_boundary
= ZFCP_QDIO_SBALE_LEN
- 1,
323 .shost_attrs
= zfcp_sysfs_shost_attrs
,
324 .sdev_attrs
= zfcp_sysfs_sdev_attrs
,
328 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
329 * @adapter: The zfcp adapter to register with the SCSI midlayer
331 int zfcp_scsi_adapter_register(struct zfcp_adapter
*adapter
)
333 struct ccw_dev_id dev_id
;
335 if (adapter
->scsi_host
)
338 ccw_device_get_id(adapter
->ccw_device
, &dev_id
);
339 /* register adapter as SCSI host with mid layer of SCSI stack */
340 adapter
->scsi_host
= scsi_host_alloc(&zfcp_scsi_host_template
,
341 sizeof (struct zfcp_adapter
*));
342 if (!adapter
->scsi_host
) {
343 dev_err(&adapter
->ccw_device
->dev
,
344 "Registering the FCP device with the "
345 "SCSI stack failed\n");
349 /* tell the SCSI stack some characteristics of this adapter */
350 adapter
->scsi_host
->max_id
= 511;
351 adapter
->scsi_host
->max_lun
= 0xFFFFFFFF;
352 adapter
->scsi_host
->max_channel
= 0;
353 adapter
->scsi_host
->unique_id
= dev_id
.devno
;
354 adapter
->scsi_host
->max_cmd_len
= 16; /* in struct fcp_cmnd */
355 adapter
->scsi_host
->transportt
= zfcp_scsi_transport_template
;
357 adapter
->scsi_host
->hostdata
[0] = (unsigned long) adapter
;
359 if (scsi_add_host(adapter
->scsi_host
, &adapter
->ccw_device
->dev
)) {
360 scsi_host_put(adapter
->scsi_host
);
368 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
369 * @adapter: The zfcp adapter to unregister.
371 void zfcp_scsi_adapter_unregister(struct zfcp_adapter
*adapter
)
373 struct Scsi_Host
*shost
;
374 struct zfcp_port
*port
;
376 shost
= adapter
->scsi_host
;
380 read_lock_irq(&adapter
->port_list_lock
);
381 list_for_each_entry(port
, &adapter
->port_list
, list
)
383 read_unlock_irq(&adapter
->port_list_lock
);
385 fc_remove_host(shost
);
386 scsi_remove_host(shost
);
387 scsi_host_put(shost
);
388 adapter
->scsi_host
= NULL
;
391 static struct fc_host_statistics
*
392 zfcp_init_fc_host_stats(struct zfcp_adapter
*adapter
)
394 struct fc_host_statistics
*fc_stats
;
396 if (!adapter
->fc_stats
) {
397 fc_stats
= kmalloc(sizeof(*fc_stats
), GFP_KERNEL
);
400 adapter
->fc_stats
= fc_stats
; /* freed in adapter_release */
402 memset(adapter
->fc_stats
, 0, sizeof(*adapter
->fc_stats
));
403 return adapter
->fc_stats
;
406 static void zfcp_adjust_fc_host_stats(struct fc_host_statistics
*fc_stats
,
407 struct fsf_qtcb_bottom_port
*data
,
408 struct fsf_qtcb_bottom_port
*old
)
410 fc_stats
->seconds_since_last_reset
=
411 data
->seconds_since_last_reset
- old
->seconds_since_last_reset
;
412 fc_stats
->tx_frames
= data
->tx_frames
- old
->tx_frames
;
413 fc_stats
->tx_words
= data
->tx_words
- old
->tx_words
;
414 fc_stats
->rx_frames
= data
->rx_frames
- old
->rx_frames
;
415 fc_stats
->rx_words
= data
->rx_words
- old
->rx_words
;
416 fc_stats
->lip_count
= data
->lip
- old
->lip
;
417 fc_stats
->nos_count
= data
->nos
- old
->nos
;
418 fc_stats
->error_frames
= data
->error_frames
- old
->error_frames
;
419 fc_stats
->dumped_frames
= data
->dumped_frames
- old
->dumped_frames
;
420 fc_stats
->link_failure_count
= data
->link_failure
- old
->link_failure
;
421 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
- old
->loss_of_sync
;
422 fc_stats
->loss_of_signal_count
=
423 data
->loss_of_signal
- old
->loss_of_signal
;
424 fc_stats
->prim_seq_protocol_err_count
=
425 data
->psp_error_counts
- old
->psp_error_counts
;
426 fc_stats
->invalid_tx_word_count
=
427 data
->invalid_tx_words
- old
->invalid_tx_words
;
428 fc_stats
->invalid_crc_count
= data
->invalid_crcs
- old
->invalid_crcs
;
429 fc_stats
->fcp_input_requests
=
430 data
->input_requests
- old
->input_requests
;
431 fc_stats
->fcp_output_requests
=
432 data
->output_requests
- old
->output_requests
;
433 fc_stats
->fcp_control_requests
=
434 data
->control_requests
- old
->control_requests
;
435 fc_stats
->fcp_input_megabytes
= data
->input_mb
- old
->input_mb
;
436 fc_stats
->fcp_output_megabytes
= data
->output_mb
- old
->output_mb
;
439 static void zfcp_set_fc_host_stats(struct fc_host_statistics
*fc_stats
,
440 struct fsf_qtcb_bottom_port
*data
)
442 fc_stats
->seconds_since_last_reset
= data
->seconds_since_last_reset
;
443 fc_stats
->tx_frames
= data
->tx_frames
;
444 fc_stats
->tx_words
= data
->tx_words
;
445 fc_stats
->rx_frames
= data
->rx_frames
;
446 fc_stats
->rx_words
= data
->rx_words
;
447 fc_stats
->lip_count
= data
->lip
;
448 fc_stats
->nos_count
= data
->nos
;
449 fc_stats
->error_frames
= data
->error_frames
;
450 fc_stats
->dumped_frames
= data
->dumped_frames
;
451 fc_stats
->link_failure_count
= data
->link_failure
;
452 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
;
453 fc_stats
->loss_of_signal_count
= data
->loss_of_signal
;
454 fc_stats
->prim_seq_protocol_err_count
= data
->psp_error_counts
;
455 fc_stats
->invalid_tx_word_count
= data
->invalid_tx_words
;
456 fc_stats
->invalid_crc_count
= data
->invalid_crcs
;
457 fc_stats
->fcp_input_requests
= data
->input_requests
;
458 fc_stats
->fcp_output_requests
= data
->output_requests
;
459 fc_stats
->fcp_control_requests
= data
->control_requests
;
460 fc_stats
->fcp_input_megabytes
= data
->input_mb
;
461 fc_stats
->fcp_output_megabytes
= data
->output_mb
;
464 static struct fc_host_statistics
*zfcp_get_fc_host_stats(struct Scsi_Host
*host
)
466 struct zfcp_adapter
*adapter
;
467 struct fc_host_statistics
*fc_stats
;
468 struct fsf_qtcb_bottom_port
*data
;
471 adapter
= (struct zfcp_adapter
*)host
->hostdata
[0];
472 fc_stats
= zfcp_init_fc_host_stats(adapter
);
476 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
480 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
486 if (adapter
->stats_reset
&&
487 ((jiffies
/HZ
- adapter
->stats_reset
) <
488 data
->seconds_since_last_reset
))
489 zfcp_adjust_fc_host_stats(fc_stats
, data
,
490 adapter
->stats_reset_data
);
492 zfcp_set_fc_host_stats(fc_stats
, data
);
498 static void zfcp_reset_fc_host_stats(struct Scsi_Host
*shost
)
500 struct zfcp_adapter
*adapter
;
501 struct fsf_qtcb_bottom_port
*data
;
504 adapter
= (struct zfcp_adapter
*)shost
->hostdata
[0];
505 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
509 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
513 adapter
->stats_reset
= jiffies
/HZ
;
514 kfree(adapter
->stats_reset_data
);
515 adapter
->stats_reset_data
= data
; /* finally freed in
520 static void zfcp_get_host_port_state(struct Scsi_Host
*shost
)
522 struct zfcp_adapter
*adapter
=
523 (struct zfcp_adapter
*)shost
->hostdata
[0];
524 int status
= atomic_read(&adapter
->status
);
526 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
527 !(status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
))
528 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
529 else if (status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
)
530 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
531 else if (status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
532 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
534 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
537 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
539 rport
->dev_loss_tmo
= timeout
;
543 * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
544 * @rport: The FC rport where to teminate I/O
546 * Abort all pending SCSI commands for a port by closing the
547 * port. Using a reopen avoids a conflict with a shutdown
548 * overwriting a reopen. The "forced" ensures that a disappeared port
549 * is not opened again as valid due to the cached plogi data in
552 static void zfcp_scsi_terminate_rport_io(struct fc_rport
*rport
)
554 struct zfcp_port
*port
;
555 struct Scsi_Host
*shost
= rport_to_shost(rport
);
556 struct zfcp_adapter
*adapter
=
557 (struct zfcp_adapter
*)shost
->hostdata
[0];
559 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
562 zfcp_erp_port_forced_reopen(port
, 0, "sctrpi1");
563 put_device(&port
->dev
);
567 static void zfcp_scsi_rport_register(struct zfcp_port
*port
)
569 struct fc_rport_identifiers ids
;
570 struct fc_rport
*rport
;
575 ids
.node_name
= port
->wwnn
;
576 ids
.port_name
= port
->wwpn
;
577 ids
.port_id
= port
->d_id
;
578 ids
.roles
= FC_RPORT_ROLE_FCP_TARGET
;
580 rport
= fc_remote_port_add(port
->adapter
->scsi_host
, 0, &ids
);
582 dev_err(&port
->adapter
->ccw_device
->dev
,
583 "Registering port 0x%016Lx failed\n",
584 (unsigned long long)port
->wwpn
);
588 rport
->maxframe_size
= port
->maxframe_size
;
589 rport
->supported_classes
= port
->supported_classes
;
591 port
->starget_id
= rport
->scsi_target_id
;
593 zfcp_unit_queue_scsi_scan(port
);
596 static void zfcp_scsi_rport_block(struct zfcp_port
*port
)
598 struct fc_rport
*rport
= port
->rport
;
601 fc_remote_port_delete(rport
);
606 void zfcp_scsi_schedule_rport_register(struct zfcp_port
*port
)
608 get_device(&port
->dev
);
609 port
->rport_task
= RPORT_ADD
;
611 if (!queue_work(port
->adapter
->work_queue
, &port
->rport_work
))
612 put_device(&port
->dev
);
615 void zfcp_scsi_schedule_rport_block(struct zfcp_port
*port
)
617 get_device(&port
->dev
);
618 port
->rport_task
= RPORT_DEL
;
620 if (port
->rport
&& queue_work(port
->adapter
->work_queue
,
624 put_device(&port
->dev
);
627 void zfcp_scsi_schedule_rports_block(struct zfcp_adapter
*adapter
)
630 struct zfcp_port
*port
;
632 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
633 list_for_each_entry(port
, &adapter
->port_list
, list
)
634 zfcp_scsi_schedule_rport_block(port
);
635 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
638 void zfcp_scsi_rport_work(struct work_struct
*work
)
640 struct zfcp_port
*port
= container_of(work
, struct zfcp_port
,
643 while (port
->rport_task
) {
644 if (port
->rport_task
== RPORT_ADD
) {
645 port
->rport_task
= RPORT_NONE
;
646 zfcp_scsi_rport_register(port
);
648 port
->rport_task
= RPORT_NONE
;
649 zfcp_scsi_rport_block(port
);
653 put_device(&port
->dev
);
657 * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
658 * @adapter: The adapter where to configure DIF/DIX for the SCSI host
660 void zfcp_scsi_set_prot(struct zfcp_adapter
*adapter
)
662 unsigned int mask
= 0;
663 unsigned int data_div
;
664 struct Scsi_Host
*shost
= adapter
->scsi_host
;
666 data_div
= atomic_read(&adapter
->status
) &
667 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED
;
670 adapter
->adapter_features
& FSF_FEATURE_DIF_PROT_TYPE1
)
671 mask
|= SHOST_DIF_TYPE1_PROTECTION
;
673 if (enable_dif
&& data_div
&&
674 adapter
->adapter_features
& FSF_FEATURE_DIX_PROT_TCPIP
) {
675 mask
|= SHOST_DIX_TYPE1_PROTECTION
;
676 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_IP
);
677 shost
->sg_prot_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
678 shost
->sg_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
679 shost
->max_sectors
= shost
->sg_tablesize
* 8;
682 scsi_host_set_prot(shost
, mask
);
686 * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
687 * @scmd: The SCSI command to report the error for
688 * @ascq: The ASCQ to put in the sense buffer
690 * See the error handling in sd_done for the sense codes used here.
691 * Set DID_SOFT_ERROR to retry the request, if possible.
693 void zfcp_scsi_dif_sense_error(struct scsi_cmnd
*scmd
, int ascq
)
695 scsi_build_sense_buffer(1, scmd
->sense_buffer
,
696 ILLEGAL_REQUEST
, 0x10, ascq
);
697 set_driver_byte(scmd
, DRIVER_SENSE
);
698 scmd
->result
|= SAM_STAT_CHECK_CONDITION
;
699 set_host_byte(scmd
, DID_SOFT_ERROR
);
702 struct fc_function_template zfcp_transport_functions
= {
703 .show_starget_port_id
= 1,
704 .show_starget_port_name
= 1,
705 .show_starget_node_name
= 1,
706 .show_rport_supported_classes
= 1,
707 .show_rport_maxframe_size
= 1,
708 .show_rport_dev_loss_tmo
= 1,
709 .show_host_node_name
= 1,
710 .show_host_port_name
= 1,
711 .show_host_permanent_port_name
= 1,
712 .show_host_supported_classes
= 1,
713 .show_host_supported_fc4s
= 1,
714 .show_host_supported_speeds
= 1,
715 .show_host_maxframe_size
= 1,
716 .show_host_serial_number
= 1,
717 .get_fc_host_stats
= zfcp_get_fc_host_stats
,
718 .reset_fc_host_stats
= zfcp_reset_fc_host_stats
,
719 .set_rport_dev_loss_tmo
= zfcp_set_rport_dev_loss_tmo
,
720 .get_host_port_state
= zfcp_get_host_port_state
,
721 .terminate_rport_io
= zfcp_scsi_terminate_rport_io
,
722 .show_host_port_state
= 1,
723 .show_host_active_fc4s
= 1,
724 .bsg_request
= zfcp_fc_exec_bsg_job
,
725 .bsg_timeout
= zfcp_fc_timeout_bsg_job
,
726 /* no functions registered for following dynamic attributes but
727 directly set by LLDD */
728 .show_host_port_type
= 1,
729 .show_host_symbolic_name
= 1,
730 .show_host_speed
= 1,
731 .show_host_port_id
= 1,
732 .dd_bsg_size
= sizeof(struct zfcp_fsf_ct_els
),