4 * Interface to Linux SCSI midlayer.
6 * Copyright IBM Corporation 2002, 2010
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
;
29 #ifdef CONFIG_ZFCP_DIF
30 module_param_named(dif
, enable_dif
, bool, 0600);
31 MODULE_PARM_DESC(dif
, "Enable DIF/DIX data integrity support");
34 static bool allow_lun_scan
= 1;
35 module_param(allow_lun_scan
, bool, 0600);
36 MODULE_PARM_DESC(allow_lun_scan
, "For NPIV, scan and attach all storage LUNs");
38 static int zfcp_scsi_change_queue_depth(struct scsi_device
*sdev
, int depth
,
42 case SCSI_QDEPTH_DEFAULT
:
43 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), depth
);
45 case SCSI_QDEPTH_QFULL
:
46 scsi_track_queue_full(sdev
, depth
);
48 case SCSI_QDEPTH_RAMP_UP
:
49 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), depth
);
54 return sdev
->queue_depth
;
57 static void zfcp_scsi_slave_destroy(struct scsi_device
*sdev
)
59 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
61 zfcp_erp_lun_shutdown_wait(sdev
, "scssd_1");
62 put_device(&zfcp_sdev
->port
->dev
);
65 static int zfcp_scsi_slave_configure(struct scsi_device
*sdp
)
67 if (sdp
->tagged_supported
)
68 scsi_adjust_queue_depth(sdp
, MSG_SIMPLE_TAG
, default_depth
);
70 scsi_adjust_queue_depth(sdp
, 0, 1);
74 static void zfcp_scsi_command_fail(struct scsi_cmnd
*scpnt
, int result
)
76 set_host_byte(scpnt
, result
);
77 zfcp_dbf_scsi_fail_send(scpnt
);
78 scpnt
->scsi_done(scpnt
);
82 int zfcp_scsi_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*scpnt
)
84 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
85 struct fc_rport
*rport
= starget_to_rport(scsi_target(scpnt
->device
));
86 int status
, scsi_result
, ret
;
88 /* reset the status for this request */
90 scpnt
->host_scribble
= NULL
;
92 scsi_result
= fc_remote_port_chkready(rport
);
93 if (unlikely(scsi_result
)) {
94 scpnt
->result
= scsi_result
;
95 zfcp_dbf_scsi_fail_send(scpnt
);
96 scpnt
->scsi_done(scpnt
);
100 status
= atomic_read(&zfcp_sdev
->status
);
101 if (unlikely(status
& ZFCP_STATUS_COMMON_ERP_FAILED
) &&
102 !(atomic_read(&zfcp_sdev
->port
->status
) &
103 ZFCP_STATUS_COMMON_ERP_FAILED
)) {
104 /* only LUN access denied, but port is good
105 * not covered by FC transport, have to fail here */
106 zfcp_scsi_command_fail(scpnt
, DID_ERROR
);
110 if (unlikely(!(status
& ZFCP_STATUS_COMMON_UNBLOCKED
))) {
111 /* This could be either
112 * open LUN pending: this is temporary, will result in
113 * open LUN or ERP_FAILED, so retry command
114 * call to rport_delete pending: mimic retry from
115 * fc_remote_port_chkready until rport is BLOCKED
117 zfcp_scsi_command_fail(scpnt
, DID_IMM_RETRY
);
121 ret
= zfcp_fsf_fcp_cmnd(scpnt
);
122 if (unlikely(ret
== -EBUSY
))
123 return SCSI_MLQUEUE_DEVICE_BUSY
;
124 else if (unlikely(ret
< 0))
125 return SCSI_MLQUEUE_HOST_BUSY
;
130 static int zfcp_scsi_slave_alloc(struct scsi_device
*sdev
)
132 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
133 struct zfcp_adapter
*adapter
=
134 (struct zfcp_adapter
*) sdev
->host
->hostdata
[0];
135 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
136 struct zfcp_port
*port
;
137 struct zfcp_unit
*unit
;
138 int npiv
= adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
;
140 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
144 unit
= zfcp_unit_find(port
, zfcp_scsi_dev_lun(sdev
));
146 put_device(&unit
->dev
);
148 if (!unit
&& !(allow_lun_scan
&& npiv
)) {
149 put_device(&port
->dev
);
153 zfcp_sdev
->port
= port
;
154 zfcp_sdev
->latencies
.write
.channel
.min
= 0xFFFFFFFF;
155 zfcp_sdev
->latencies
.write
.fabric
.min
= 0xFFFFFFFF;
156 zfcp_sdev
->latencies
.read
.channel
.min
= 0xFFFFFFFF;
157 zfcp_sdev
->latencies
.read
.fabric
.min
= 0xFFFFFFFF;
158 zfcp_sdev
->latencies
.cmd
.channel
.min
= 0xFFFFFFFF;
159 zfcp_sdev
->latencies
.cmd
.fabric
.min
= 0xFFFFFFFF;
160 spin_lock_init(&zfcp_sdev
->latencies
.lock
);
162 zfcp_erp_set_lun_status(sdev
, ZFCP_STATUS_COMMON_RUNNING
);
163 zfcp_erp_lun_reopen(sdev
, 0, "scsla_1");
164 zfcp_erp_wait(port
->adapter
);
169 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd
*scpnt
)
171 struct Scsi_Host
*scsi_host
= scpnt
->device
->host
;
172 struct zfcp_adapter
*adapter
=
173 (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
174 struct zfcp_fsf_req
*old_req
, *abrt_req
;
176 unsigned long old_reqid
= (unsigned long) scpnt
->host_scribble
;
177 int retval
= SUCCESS
, ret
;
181 /* avoid race condition between late normal completion and abort */
182 write_lock_irqsave(&adapter
->abort_lock
, flags
);
184 old_req
= zfcp_reqlist_find(adapter
->req_list
, old_reqid
);
186 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
187 zfcp_dbf_scsi_abort("abrt_or", scpnt
, NULL
);
188 return FAILED
; /* completion could be in progress */
190 old_req
->data
= NULL
;
192 /* don't access old fsf_req after releasing the abort_lock */
193 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
196 abrt_req
= zfcp_fsf_abort_fcp_cmnd(scpnt
);
200 zfcp_erp_wait(adapter
);
201 ret
= fc_block_scsi_eh(scpnt
);
203 zfcp_dbf_scsi_abort("abrt_bl", scpnt
, NULL
);
206 if (!(atomic_read(&adapter
->status
) &
207 ZFCP_STATUS_COMMON_RUNNING
)) {
208 zfcp_dbf_scsi_abort("abrt_ru", scpnt
, NULL
);
213 zfcp_dbf_scsi_abort("abrt_ar", scpnt
, NULL
);
217 wait_for_completion(&abrt_req
->completion
);
219 if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED
)
221 else if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED
)
227 zfcp_dbf_scsi_abort(dbf_tag
, scpnt
, abrt_req
);
228 zfcp_fsf_req_free(abrt_req
);
232 static int zfcp_task_mgmt_function(struct scsi_cmnd
*scpnt
, u8 tm_flags
)
234 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
235 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
236 struct zfcp_fsf_req
*fsf_req
= NULL
;
237 int retval
= SUCCESS
, ret
;
241 fsf_req
= zfcp_fsf_fcp_task_mgmt(scpnt
, tm_flags
);
245 zfcp_erp_wait(adapter
);
246 ret
= fc_block_scsi_eh(scpnt
);
250 if (!(atomic_read(&adapter
->status
) &
251 ZFCP_STATUS_COMMON_RUNNING
)) {
252 zfcp_dbf_scsi_devreset("nres", scpnt
, tm_flags
);
259 wait_for_completion(&fsf_req
->completion
);
261 if (fsf_req
->status
& ZFCP_STATUS_FSFREQ_TMFUNCFAILED
) {
262 zfcp_dbf_scsi_devreset("fail", scpnt
, tm_flags
);
265 zfcp_dbf_scsi_devreset("okay", scpnt
, tm_flags
);
267 zfcp_fsf_req_free(fsf_req
);
271 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd
*scpnt
)
273 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_LUN_RESET
);
276 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd
*scpnt
)
278 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_TGT_RESET
);
281 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd
*scpnt
)
283 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
284 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
287 zfcp_erp_adapter_reopen(adapter
, 0, "schrh_1");
288 zfcp_erp_wait(adapter
);
289 ret
= fc_block_scsi_eh(scpnt
);
296 struct scsi_transport_template
*zfcp_scsi_transport_template
;
298 static struct scsi_host_template zfcp_scsi_host_template
= {
299 .module
= THIS_MODULE
,
301 .queuecommand
= zfcp_scsi_queuecommand
,
302 .eh_abort_handler
= zfcp_scsi_eh_abort_handler
,
303 .eh_device_reset_handler
= zfcp_scsi_eh_device_reset_handler
,
304 .eh_target_reset_handler
= zfcp_scsi_eh_target_reset_handler
,
305 .eh_host_reset_handler
= zfcp_scsi_eh_host_reset_handler
,
306 .slave_alloc
= zfcp_scsi_slave_alloc
,
307 .slave_configure
= zfcp_scsi_slave_configure
,
308 .slave_destroy
= zfcp_scsi_slave_destroy
,
309 .change_queue_depth
= zfcp_scsi_change_queue_depth
,
313 .sg_tablesize
= ZFCP_QDIO_MAX_SBALES_PER_REQ
,
314 .max_sectors
= (ZFCP_QDIO_MAX_SBALES_PER_REQ
* 8),
315 .dma_boundary
= ZFCP_QDIO_SBALE_LEN
- 1,
318 .shost_attrs
= zfcp_sysfs_shost_attrs
,
319 .sdev_attrs
= zfcp_sysfs_sdev_attrs
,
323 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
324 * @adapter: The zfcp adapter to register with the SCSI midlayer
326 int zfcp_scsi_adapter_register(struct zfcp_adapter
*adapter
)
328 struct ccw_dev_id dev_id
;
330 if (adapter
->scsi_host
)
333 ccw_device_get_id(adapter
->ccw_device
, &dev_id
);
334 /* register adapter as SCSI host with mid layer of SCSI stack */
335 adapter
->scsi_host
= scsi_host_alloc(&zfcp_scsi_host_template
,
336 sizeof (struct zfcp_adapter
*));
337 if (!adapter
->scsi_host
) {
338 dev_err(&adapter
->ccw_device
->dev
,
339 "Registering the FCP device with the "
340 "SCSI stack failed\n");
344 /* tell the SCSI stack some characteristics of this adapter */
345 adapter
->scsi_host
->max_id
= 511;
346 adapter
->scsi_host
->max_lun
= 0xFFFFFFFF;
347 adapter
->scsi_host
->max_channel
= 0;
348 adapter
->scsi_host
->unique_id
= dev_id
.devno
;
349 adapter
->scsi_host
->max_cmd_len
= 16; /* in struct fcp_cmnd */
350 adapter
->scsi_host
->transportt
= zfcp_scsi_transport_template
;
352 adapter
->scsi_host
->hostdata
[0] = (unsigned long) adapter
;
354 if (scsi_add_host(adapter
->scsi_host
, &adapter
->ccw_device
->dev
)) {
355 scsi_host_put(adapter
->scsi_host
);
363 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
364 * @adapter: The zfcp adapter to unregister.
366 void zfcp_scsi_adapter_unregister(struct zfcp_adapter
*adapter
)
368 struct Scsi_Host
*shost
;
369 struct zfcp_port
*port
;
371 shost
= adapter
->scsi_host
;
375 read_lock_irq(&adapter
->port_list_lock
);
376 list_for_each_entry(port
, &adapter
->port_list
, list
)
378 read_unlock_irq(&adapter
->port_list_lock
);
380 fc_remove_host(shost
);
381 scsi_remove_host(shost
);
382 scsi_host_put(shost
);
383 adapter
->scsi_host
= NULL
;
386 static struct fc_host_statistics
*
387 zfcp_init_fc_host_stats(struct zfcp_adapter
*adapter
)
389 struct fc_host_statistics
*fc_stats
;
391 if (!adapter
->fc_stats
) {
392 fc_stats
= kmalloc(sizeof(*fc_stats
), GFP_KERNEL
);
395 adapter
->fc_stats
= fc_stats
; /* freed in adapter_release */
397 memset(adapter
->fc_stats
, 0, sizeof(*adapter
->fc_stats
));
398 return adapter
->fc_stats
;
401 static void zfcp_adjust_fc_host_stats(struct fc_host_statistics
*fc_stats
,
402 struct fsf_qtcb_bottom_port
*data
,
403 struct fsf_qtcb_bottom_port
*old
)
405 fc_stats
->seconds_since_last_reset
=
406 data
->seconds_since_last_reset
- old
->seconds_since_last_reset
;
407 fc_stats
->tx_frames
= data
->tx_frames
- old
->tx_frames
;
408 fc_stats
->tx_words
= data
->tx_words
- old
->tx_words
;
409 fc_stats
->rx_frames
= data
->rx_frames
- old
->rx_frames
;
410 fc_stats
->rx_words
= data
->rx_words
- old
->rx_words
;
411 fc_stats
->lip_count
= data
->lip
- old
->lip
;
412 fc_stats
->nos_count
= data
->nos
- old
->nos
;
413 fc_stats
->error_frames
= data
->error_frames
- old
->error_frames
;
414 fc_stats
->dumped_frames
= data
->dumped_frames
- old
->dumped_frames
;
415 fc_stats
->link_failure_count
= data
->link_failure
- old
->link_failure
;
416 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
- old
->loss_of_sync
;
417 fc_stats
->loss_of_signal_count
=
418 data
->loss_of_signal
- old
->loss_of_signal
;
419 fc_stats
->prim_seq_protocol_err_count
=
420 data
->psp_error_counts
- old
->psp_error_counts
;
421 fc_stats
->invalid_tx_word_count
=
422 data
->invalid_tx_words
- old
->invalid_tx_words
;
423 fc_stats
->invalid_crc_count
= data
->invalid_crcs
- old
->invalid_crcs
;
424 fc_stats
->fcp_input_requests
=
425 data
->input_requests
- old
->input_requests
;
426 fc_stats
->fcp_output_requests
=
427 data
->output_requests
- old
->output_requests
;
428 fc_stats
->fcp_control_requests
=
429 data
->control_requests
- old
->control_requests
;
430 fc_stats
->fcp_input_megabytes
= data
->input_mb
- old
->input_mb
;
431 fc_stats
->fcp_output_megabytes
= data
->output_mb
- old
->output_mb
;
434 static void zfcp_set_fc_host_stats(struct fc_host_statistics
*fc_stats
,
435 struct fsf_qtcb_bottom_port
*data
)
437 fc_stats
->seconds_since_last_reset
= data
->seconds_since_last_reset
;
438 fc_stats
->tx_frames
= data
->tx_frames
;
439 fc_stats
->tx_words
= data
->tx_words
;
440 fc_stats
->rx_frames
= data
->rx_frames
;
441 fc_stats
->rx_words
= data
->rx_words
;
442 fc_stats
->lip_count
= data
->lip
;
443 fc_stats
->nos_count
= data
->nos
;
444 fc_stats
->error_frames
= data
->error_frames
;
445 fc_stats
->dumped_frames
= data
->dumped_frames
;
446 fc_stats
->link_failure_count
= data
->link_failure
;
447 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
;
448 fc_stats
->loss_of_signal_count
= data
->loss_of_signal
;
449 fc_stats
->prim_seq_protocol_err_count
= data
->psp_error_counts
;
450 fc_stats
->invalid_tx_word_count
= data
->invalid_tx_words
;
451 fc_stats
->invalid_crc_count
= data
->invalid_crcs
;
452 fc_stats
->fcp_input_requests
= data
->input_requests
;
453 fc_stats
->fcp_output_requests
= data
->output_requests
;
454 fc_stats
->fcp_control_requests
= data
->control_requests
;
455 fc_stats
->fcp_input_megabytes
= data
->input_mb
;
456 fc_stats
->fcp_output_megabytes
= data
->output_mb
;
459 static struct fc_host_statistics
*zfcp_get_fc_host_stats(struct Scsi_Host
*host
)
461 struct zfcp_adapter
*adapter
;
462 struct fc_host_statistics
*fc_stats
;
463 struct fsf_qtcb_bottom_port
*data
;
466 adapter
= (struct zfcp_adapter
*)host
->hostdata
[0];
467 fc_stats
= zfcp_init_fc_host_stats(adapter
);
471 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
475 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
481 if (adapter
->stats_reset
&&
482 ((jiffies
/HZ
- adapter
->stats_reset
) <
483 data
->seconds_since_last_reset
))
484 zfcp_adjust_fc_host_stats(fc_stats
, data
,
485 adapter
->stats_reset_data
);
487 zfcp_set_fc_host_stats(fc_stats
, data
);
493 static void zfcp_reset_fc_host_stats(struct Scsi_Host
*shost
)
495 struct zfcp_adapter
*adapter
;
496 struct fsf_qtcb_bottom_port
*data
;
499 adapter
= (struct zfcp_adapter
*)shost
->hostdata
[0];
500 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
504 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
508 adapter
->stats_reset
= jiffies
/HZ
;
509 kfree(adapter
->stats_reset_data
);
510 adapter
->stats_reset_data
= data
; /* finally freed in
515 static void zfcp_get_host_port_state(struct Scsi_Host
*shost
)
517 struct zfcp_adapter
*adapter
=
518 (struct zfcp_adapter
*)shost
->hostdata
[0];
519 int status
= atomic_read(&adapter
->status
);
521 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
522 !(status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
))
523 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
524 else if (status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
)
525 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
526 else if (status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
527 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
529 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
532 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
534 rport
->dev_loss_tmo
= timeout
;
538 * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
539 * @rport: The FC rport where to teminate I/O
541 * Abort all pending SCSI commands for a port by closing the
542 * port. Using a reopen avoids a conflict with a shutdown
543 * overwriting a reopen. The "forced" ensures that a disappeared port
544 * is not opened again as valid due to the cached plogi data in
547 static void zfcp_scsi_terminate_rport_io(struct fc_rport
*rport
)
549 struct zfcp_port
*port
;
550 struct Scsi_Host
*shost
= rport_to_shost(rport
);
551 struct zfcp_adapter
*adapter
=
552 (struct zfcp_adapter
*)shost
->hostdata
[0];
554 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
557 zfcp_erp_port_forced_reopen(port
, 0, "sctrpi1");
558 put_device(&port
->dev
);
562 static void zfcp_scsi_rport_register(struct zfcp_port
*port
)
564 struct fc_rport_identifiers ids
;
565 struct fc_rport
*rport
;
570 ids
.node_name
= port
->wwnn
;
571 ids
.port_name
= port
->wwpn
;
572 ids
.port_id
= port
->d_id
;
573 ids
.roles
= FC_RPORT_ROLE_FCP_TARGET
;
575 rport
= fc_remote_port_add(port
->adapter
->scsi_host
, 0, &ids
);
577 dev_err(&port
->adapter
->ccw_device
->dev
,
578 "Registering port 0x%016Lx failed\n",
579 (unsigned long long)port
->wwpn
);
583 rport
->maxframe_size
= port
->maxframe_size
;
584 rport
->supported_classes
= port
->supported_classes
;
586 port
->starget_id
= rport
->scsi_target_id
;
588 zfcp_unit_queue_scsi_scan(port
);
591 static void zfcp_scsi_rport_block(struct zfcp_port
*port
)
593 struct fc_rport
*rport
= port
->rport
;
596 fc_remote_port_delete(rport
);
601 void zfcp_scsi_schedule_rport_register(struct zfcp_port
*port
)
603 get_device(&port
->dev
);
604 port
->rport_task
= RPORT_ADD
;
606 if (!queue_work(port
->adapter
->work_queue
, &port
->rport_work
))
607 put_device(&port
->dev
);
610 void zfcp_scsi_schedule_rport_block(struct zfcp_port
*port
)
612 get_device(&port
->dev
);
613 port
->rport_task
= RPORT_DEL
;
615 if (port
->rport
&& queue_work(port
->adapter
->work_queue
,
619 put_device(&port
->dev
);
622 void zfcp_scsi_schedule_rports_block(struct zfcp_adapter
*adapter
)
625 struct zfcp_port
*port
;
627 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
628 list_for_each_entry(port
, &adapter
->port_list
, list
)
629 zfcp_scsi_schedule_rport_block(port
);
630 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
633 void zfcp_scsi_rport_work(struct work_struct
*work
)
635 struct zfcp_port
*port
= container_of(work
, struct zfcp_port
,
638 while (port
->rport_task
) {
639 if (port
->rport_task
== RPORT_ADD
) {
640 port
->rport_task
= RPORT_NONE
;
641 zfcp_scsi_rport_register(port
);
643 port
->rport_task
= RPORT_NONE
;
644 zfcp_scsi_rport_block(port
);
648 put_device(&port
->dev
);
652 * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
653 * @adapter: The adapter where to configure DIF/DIX for the SCSI host
655 void zfcp_scsi_set_prot(struct zfcp_adapter
*adapter
)
657 unsigned int mask
= 0;
658 unsigned int data_div
;
659 struct Scsi_Host
*shost
= adapter
->scsi_host
;
661 data_div
= atomic_read(&adapter
->status
) &
662 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED
;
665 adapter
->adapter_features
& FSF_FEATURE_DIF_PROT_TYPE1
)
666 mask
|= SHOST_DIF_TYPE1_PROTECTION
;
668 if (enable_dif
&& data_div
&&
669 adapter
->adapter_features
& FSF_FEATURE_DIX_PROT_TCPIP
) {
670 mask
|= SHOST_DIX_TYPE1_PROTECTION
;
671 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_IP
);
672 shost
->sg_prot_tablesize
= ZFCP_QDIO_MAX_SBALES_PER_REQ
/ 2;
673 shost
->sg_tablesize
= ZFCP_QDIO_MAX_SBALES_PER_REQ
/ 2;
674 shost
->max_sectors
= ZFCP_QDIO_MAX_SBALES_PER_REQ
* 8 / 2;
677 scsi_host_set_prot(shost
, mask
);
681 * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
682 * @scmd: The SCSI command to report the error for
683 * @ascq: The ASCQ to put in the sense buffer
685 * See the error handling in sd_done for the sense codes used here.
686 * Set DID_SOFT_ERROR to retry the request, if possible.
688 void zfcp_scsi_dif_sense_error(struct scsi_cmnd
*scmd
, int ascq
)
690 scsi_build_sense_buffer(1, scmd
->sense_buffer
,
691 ILLEGAL_REQUEST
, 0x10, ascq
);
692 set_driver_byte(scmd
, DRIVER_SENSE
);
693 scmd
->result
|= SAM_STAT_CHECK_CONDITION
;
694 set_host_byte(scmd
, DID_SOFT_ERROR
);
697 struct fc_function_template zfcp_transport_functions
= {
698 .show_starget_port_id
= 1,
699 .show_starget_port_name
= 1,
700 .show_starget_node_name
= 1,
701 .show_rport_supported_classes
= 1,
702 .show_rport_maxframe_size
= 1,
703 .show_rport_dev_loss_tmo
= 1,
704 .show_host_node_name
= 1,
705 .show_host_port_name
= 1,
706 .show_host_permanent_port_name
= 1,
707 .show_host_supported_classes
= 1,
708 .show_host_supported_fc4s
= 1,
709 .show_host_supported_speeds
= 1,
710 .show_host_maxframe_size
= 1,
711 .show_host_serial_number
= 1,
712 .get_fc_host_stats
= zfcp_get_fc_host_stats
,
713 .reset_fc_host_stats
= zfcp_reset_fc_host_stats
,
714 .set_rport_dev_loss_tmo
= zfcp_set_rport_dev_loss_tmo
,
715 .get_host_port_state
= zfcp_get_host_port_state
,
716 .terminate_rport_io
= zfcp_scsi_terminate_rport_io
,
717 .show_host_port_state
= 1,
718 .show_host_active_fc4s
= 1,
719 .bsg_request
= zfcp_fc_exec_bsg_job
,
720 .bsg_timeout
= zfcp_fc_timeout_bsg_job
,
721 /* no functions registered for following dynamic attributes but
722 directly set by LLDD */
723 .show_host_port_type
= 1,
724 .show_host_symbolic_name
= 1,
725 .show_host_speed
= 1,
726 .show_host_port_id
= 1,
727 .dd_bsg_size
= sizeof(struct zfcp_fsf_ct_els
),