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 void zfcp_scsi_slave_destroy(struct scsi_device
*sdev
)
37 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
39 /* if previous slave_alloc returned early, there is nothing to do */
43 zfcp_erp_lun_shutdown_wait(sdev
, "scssd_1");
44 put_device(&zfcp_sdev
->port
->dev
);
47 static int zfcp_scsi_slave_configure(struct scsi_device
*sdp
)
49 if (sdp
->tagged_supported
)
50 scsi_change_queue_depth(sdp
, default_depth
);
54 static void zfcp_scsi_command_fail(struct scsi_cmnd
*scpnt
, int result
)
56 set_host_byte(scpnt
, result
);
57 zfcp_dbf_scsi_fail_send(scpnt
);
58 scpnt
->scsi_done(scpnt
);
62 int zfcp_scsi_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*scpnt
)
64 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
65 struct fc_rport
*rport
= starget_to_rport(scsi_target(scpnt
->device
));
66 int status
, scsi_result
, ret
;
68 /* reset the status for this request */
70 scpnt
->host_scribble
= NULL
;
72 scsi_result
= fc_remote_port_chkready(rport
);
73 if (unlikely(scsi_result
)) {
74 scpnt
->result
= scsi_result
;
75 zfcp_dbf_scsi_fail_send(scpnt
);
76 scpnt
->scsi_done(scpnt
);
80 status
= atomic_read(&zfcp_sdev
->status
);
81 if (unlikely(status
& ZFCP_STATUS_COMMON_ERP_FAILED
) &&
82 !(atomic_read(&zfcp_sdev
->port
->status
) &
83 ZFCP_STATUS_COMMON_ERP_FAILED
)) {
84 /* only LUN access denied, but port is good
85 * not covered by FC transport, have to fail here */
86 zfcp_scsi_command_fail(scpnt
, DID_ERROR
);
90 if (unlikely(!(status
& ZFCP_STATUS_COMMON_UNBLOCKED
))) {
91 /* This could be either
92 * open LUN pending: this is temporary, will result in
93 * open LUN or ERP_FAILED, so retry command
94 * call to rport_delete pending: mimic retry from
95 * fc_remote_port_chkready until rport is BLOCKED
97 zfcp_scsi_command_fail(scpnt
, DID_IMM_RETRY
);
101 ret
= zfcp_fsf_fcp_cmnd(scpnt
);
102 if (unlikely(ret
== -EBUSY
))
103 return SCSI_MLQUEUE_DEVICE_BUSY
;
104 else if (unlikely(ret
< 0))
105 return SCSI_MLQUEUE_HOST_BUSY
;
110 static int zfcp_scsi_slave_alloc(struct scsi_device
*sdev
)
112 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
113 struct zfcp_adapter
*adapter
=
114 (struct zfcp_adapter
*) sdev
->host
->hostdata
[0];
115 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
116 struct zfcp_port
*port
;
117 struct zfcp_unit
*unit
;
118 int npiv
= adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
;
120 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
124 unit
= zfcp_unit_find(port
, zfcp_scsi_dev_lun(sdev
));
126 put_device(&unit
->dev
);
128 if (!unit
&& !(allow_lun_scan
&& npiv
)) {
129 put_device(&port
->dev
);
133 zfcp_sdev
->port
= port
;
134 zfcp_sdev
->latencies
.write
.channel
.min
= 0xFFFFFFFF;
135 zfcp_sdev
->latencies
.write
.fabric
.min
= 0xFFFFFFFF;
136 zfcp_sdev
->latencies
.read
.channel
.min
= 0xFFFFFFFF;
137 zfcp_sdev
->latencies
.read
.fabric
.min
= 0xFFFFFFFF;
138 zfcp_sdev
->latencies
.cmd
.channel
.min
= 0xFFFFFFFF;
139 zfcp_sdev
->latencies
.cmd
.fabric
.min
= 0xFFFFFFFF;
140 spin_lock_init(&zfcp_sdev
->latencies
.lock
);
142 zfcp_erp_set_lun_status(sdev
, ZFCP_STATUS_COMMON_RUNNING
);
143 zfcp_erp_lun_reopen(sdev
, 0, "scsla_1");
144 zfcp_erp_wait(port
->adapter
);
149 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd
*scpnt
)
151 struct Scsi_Host
*scsi_host
= scpnt
->device
->host
;
152 struct zfcp_adapter
*adapter
=
153 (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
154 struct zfcp_fsf_req
*old_req
, *abrt_req
;
156 unsigned long old_reqid
= (unsigned long) scpnt
->host_scribble
;
157 int retval
= SUCCESS
, ret
;
161 /* avoid race condition between late normal completion and abort */
162 write_lock_irqsave(&adapter
->abort_lock
, flags
);
164 old_req
= zfcp_reqlist_find(adapter
->req_list
, old_reqid
);
166 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
167 zfcp_dbf_scsi_abort("abrt_or", scpnt
, NULL
);
168 return FAILED
; /* completion could be in progress */
170 old_req
->data
= NULL
;
172 /* don't access old fsf_req after releasing the abort_lock */
173 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
176 abrt_req
= zfcp_fsf_abort_fcp_cmnd(scpnt
);
180 zfcp_erp_wait(adapter
);
181 ret
= fc_block_scsi_eh(scpnt
);
183 zfcp_dbf_scsi_abort("abrt_bl", scpnt
, NULL
);
186 if (!(atomic_read(&adapter
->status
) &
187 ZFCP_STATUS_COMMON_RUNNING
)) {
188 zfcp_dbf_scsi_abort("abrt_ru", scpnt
, NULL
);
193 zfcp_dbf_scsi_abort("abrt_ar", scpnt
, NULL
);
197 wait_for_completion(&abrt_req
->completion
);
199 if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED
)
201 else if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED
)
207 zfcp_dbf_scsi_abort(dbf_tag
, scpnt
, abrt_req
);
208 zfcp_fsf_req_free(abrt_req
);
212 static int zfcp_task_mgmt_function(struct scsi_cmnd
*scpnt
, u8 tm_flags
)
214 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
215 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
216 struct zfcp_fsf_req
*fsf_req
= NULL
;
217 int retval
= SUCCESS
, ret
;
221 fsf_req
= zfcp_fsf_fcp_task_mgmt(scpnt
, tm_flags
);
225 zfcp_erp_wait(adapter
);
226 ret
= fc_block_scsi_eh(scpnt
);
230 if (!(atomic_read(&adapter
->status
) &
231 ZFCP_STATUS_COMMON_RUNNING
)) {
232 zfcp_dbf_scsi_devreset("nres", scpnt
, tm_flags
);
239 wait_for_completion(&fsf_req
->completion
);
241 if (fsf_req
->status
& ZFCP_STATUS_FSFREQ_TMFUNCFAILED
) {
242 zfcp_dbf_scsi_devreset("fail", scpnt
, tm_flags
);
245 zfcp_dbf_scsi_devreset("okay", scpnt
, tm_flags
);
247 zfcp_fsf_req_free(fsf_req
);
251 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd
*scpnt
)
253 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_LUN_RESET
);
256 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd
*scpnt
)
258 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_TGT_RESET
);
261 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd
*scpnt
)
263 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
264 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
267 zfcp_erp_adapter_reopen(adapter
, 0, "schrh_1");
268 zfcp_erp_wait(adapter
);
269 ret
= fc_block_scsi_eh(scpnt
);
276 struct scsi_transport_template
*zfcp_scsi_transport_template
;
278 static struct scsi_host_template zfcp_scsi_host_template
= {
279 .module
= THIS_MODULE
,
281 .queuecommand
= zfcp_scsi_queuecommand
,
282 .eh_abort_handler
= zfcp_scsi_eh_abort_handler
,
283 .eh_device_reset_handler
= zfcp_scsi_eh_device_reset_handler
,
284 .eh_target_reset_handler
= zfcp_scsi_eh_target_reset_handler
,
285 .eh_host_reset_handler
= zfcp_scsi_eh_host_reset_handler
,
286 .slave_alloc
= zfcp_scsi_slave_alloc
,
287 .slave_configure
= zfcp_scsi_slave_configure
,
288 .slave_destroy
= zfcp_scsi_slave_destroy
,
289 .change_queue_depth
= scsi_change_queue_depth
,
293 .sg_tablesize
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
294 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2),
295 /* GCD, adjusted later */
296 .max_sectors
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
297 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2) * 8,
298 /* GCD, adjusted later */
299 .dma_boundary
= ZFCP_QDIO_SBALE_LEN
- 1,
302 .shost_attrs
= zfcp_sysfs_shost_attrs
,
303 .sdev_attrs
= zfcp_sysfs_sdev_attrs
,
304 .track_queue_depth
= 1,
308 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
309 * @adapter: The zfcp adapter to register with the SCSI midlayer
311 int zfcp_scsi_adapter_register(struct zfcp_adapter
*adapter
)
313 struct ccw_dev_id dev_id
;
315 if (adapter
->scsi_host
)
318 ccw_device_get_id(adapter
->ccw_device
, &dev_id
);
319 /* register adapter as SCSI host with mid layer of SCSI stack */
320 adapter
->scsi_host
= scsi_host_alloc(&zfcp_scsi_host_template
,
321 sizeof (struct zfcp_adapter
*));
322 if (!adapter
->scsi_host
) {
323 dev_err(&adapter
->ccw_device
->dev
,
324 "Registering the FCP device with the "
325 "SCSI stack failed\n");
329 /* tell the SCSI stack some characteristics of this adapter */
330 adapter
->scsi_host
->max_id
= 511;
331 adapter
->scsi_host
->max_lun
= 0xFFFFFFFF;
332 adapter
->scsi_host
->max_channel
= 0;
333 adapter
->scsi_host
->unique_id
= dev_id
.devno
;
334 adapter
->scsi_host
->max_cmd_len
= 16; /* in struct fcp_cmnd */
335 adapter
->scsi_host
->transportt
= zfcp_scsi_transport_template
;
337 adapter
->scsi_host
->hostdata
[0] = (unsigned long) adapter
;
339 if (scsi_add_host(adapter
->scsi_host
, &adapter
->ccw_device
->dev
)) {
340 scsi_host_put(adapter
->scsi_host
);
348 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
349 * @adapter: The zfcp adapter to unregister.
351 void zfcp_scsi_adapter_unregister(struct zfcp_adapter
*adapter
)
353 struct Scsi_Host
*shost
;
354 struct zfcp_port
*port
;
356 shost
= adapter
->scsi_host
;
360 read_lock_irq(&adapter
->port_list_lock
);
361 list_for_each_entry(port
, &adapter
->port_list
, list
)
363 read_unlock_irq(&adapter
->port_list_lock
);
365 fc_remove_host(shost
);
366 scsi_remove_host(shost
);
367 scsi_host_put(shost
);
368 adapter
->scsi_host
= NULL
;
371 static struct fc_host_statistics
*
372 zfcp_init_fc_host_stats(struct zfcp_adapter
*adapter
)
374 struct fc_host_statistics
*fc_stats
;
376 if (!adapter
->fc_stats
) {
377 fc_stats
= kmalloc(sizeof(*fc_stats
), GFP_KERNEL
);
380 adapter
->fc_stats
= fc_stats
; /* freed in adapter_release */
382 memset(adapter
->fc_stats
, 0, sizeof(*adapter
->fc_stats
));
383 return adapter
->fc_stats
;
386 static void zfcp_adjust_fc_host_stats(struct fc_host_statistics
*fc_stats
,
387 struct fsf_qtcb_bottom_port
*data
,
388 struct fsf_qtcb_bottom_port
*old
)
390 fc_stats
->seconds_since_last_reset
=
391 data
->seconds_since_last_reset
- old
->seconds_since_last_reset
;
392 fc_stats
->tx_frames
= data
->tx_frames
- old
->tx_frames
;
393 fc_stats
->tx_words
= data
->tx_words
- old
->tx_words
;
394 fc_stats
->rx_frames
= data
->rx_frames
- old
->rx_frames
;
395 fc_stats
->rx_words
= data
->rx_words
- old
->rx_words
;
396 fc_stats
->lip_count
= data
->lip
- old
->lip
;
397 fc_stats
->nos_count
= data
->nos
- old
->nos
;
398 fc_stats
->error_frames
= data
->error_frames
- old
->error_frames
;
399 fc_stats
->dumped_frames
= data
->dumped_frames
- old
->dumped_frames
;
400 fc_stats
->link_failure_count
= data
->link_failure
- old
->link_failure
;
401 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
- old
->loss_of_sync
;
402 fc_stats
->loss_of_signal_count
=
403 data
->loss_of_signal
- old
->loss_of_signal
;
404 fc_stats
->prim_seq_protocol_err_count
=
405 data
->psp_error_counts
- old
->psp_error_counts
;
406 fc_stats
->invalid_tx_word_count
=
407 data
->invalid_tx_words
- old
->invalid_tx_words
;
408 fc_stats
->invalid_crc_count
= data
->invalid_crcs
- old
->invalid_crcs
;
409 fc_stats
->fcp_input_requests
=
410 data
->input_requests
- old
->input_requests
;
411 fc_stats
->fcp_output_requests
=
412 data
->output_requests
- old
->output_requests
;
413 fc_stats
->fcp_control_requests
=
414 data
->control_requests
- old
->control_requests
;
415 fc_stats
->fcp_input_megabytes
= data
->input_mb
- old
->input_mb
;
416 fc_stats
->fcp_output_megabytes
= data
->output_mb
- old
->output_mb
;
419 static void zfcp_set_fc_host_stats(struct fc_host_statistics
*fc_stats
,
420 struct fsf_qtcb_bottom_port
*data
)
422 fc_stats
->seconds_since_last_reset
= data
->seconds_since_last_reset
;
423 fc_stats
->tx_frames
= data
->tx_frames
;
424 fc_stats
->tx_words
= data
->tx_words
;
425 fc_stats
->rx_frames
= data
->rx_frames
;
426 fc_stats
->rx_words
= data
->rx_words
;
427 fc_stats
->lip_count
= data
->lip
;
428 fc_stats
->nos_count
= data
->nos
;
429 fc_stats
->error_frames
= data
->error_frames
;
430 fc_stats
->dumped_frames
= data
->dumped_frames
;
431 fc_stats
->link_failure_count
= data
->link_failure
;
432 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
;
433 fc_stats
->loss_of_signal_count
= data
->loss_of_signal
;
434 fc_stats
->prim_seq_protocol_err_count
= data
->psp_error_counts
;
435 fc_stats
->invalid_tx_word_count
= data
->invalid_tx_words
;
436 fc_stats
->invalid_crc_count
= data
->invalid_crcs
;
437 fc_stats
->fcp_input_requests
= data
->input_requests
;
438 fc_stats
->fcp_output_requests
= data
->output_requests
;
439 fc_stats
->fcp_control_requests
= data
->control_requests
;
440 fc_stats
->fcp_input_megabytes
= data
->input_mb
;
441 fc_stats
->fcp_output_megabytes
= data
->output_mb
;
444 static struct fc_host_statistics
*zfcp_get_fc_host_stats(struct Scsi_Host
*host
)
446 struct zfcp_adapter
*adapter
;
447 struct fc_host_statistics
*fc_stats
;
448 struct fsf_qtcb_bottom_port
*data
;
451 adapter
= (struct zfcp_adapter
*)host
->hostdata
[0];
452 fc_stats
= zfcp_init_fc_host_stats(adapter
);
456 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
460 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
466 if (adapter
->stats_reset
&&
467 ((jiffies
/HZ
- adapter
->stats_reset
) <
468 data
->seconds_since_last_reset
))
469 zfcp_adjust_fc_host_stats(fc_stats
, data
,
470 adapter
->stats_reset_data
);
472 zfcp_set_fc_host_stats(fc_stats
, data
);
478 static void zfcp_reset_fc_host_stats(struct Scsi_Host
*shost
)
480 struct zfcp_adapter
*adapter
;
481 struct fsf_qtcb_bottom_port
*data
;
484 adapter
= (struct zfcp_adapter
*)shost
->hostdata
[0];
485 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
489 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
493 adapter
->stats_reset
= jiffies
/HZ
;
494 kfree(adapter
->stats_reset_data
);
495 adapter
->stats_reset_data
= data
; /* finally freed in
500 static void zfcp_get_host_port_state(struct Scsi_Host
*shost
)
502 struct zfcp_adapter
*adapter
=
503 (struct zfcp_adapter
*)shost
->hostdata
[0];
504 int status
= atomic_read(&adapter
->status
);
506 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
507 !(status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
))
508 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
509 else if (status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
)
510 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
511 else if (status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
512 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
514 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
517 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
519 rport
->dev_loss_tmo
= timeout
;
523 * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
524 * @rport: The FC rport where to teminate I/O
526 * Abort all pending SCSI commands for a port by closing the
527 * port. Using a reopen avoids a conflict with a shutdown
528 * overwriting a reopen. The "forced" ensures that a disappeared port
529 * is not opened again as valid due to the cached plogi data in
532 static void zfcp_scsi_terminate_rport_io(struct fc_rport
*rport
)
534 struct zfcp_port
*port
;
535 struct Scsi_Host
*shost
= rport_to_shost(rport
);
536 struct zfcp_adapter
*adapter
=
537 (struct zfcp_adapter
*)shost
->hostdata
[0];
539 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
542 zfcp_erp_port_forced_reopen(port
, 0, "sctrpi1");
543 put_device(&port
->dev
);
547 static void zfcp_scsi_rport_register(struct zfcp_port
*port
)
549 struct fc_rport_identifiers ids
;
550 struct fc_rport
*rport
;
555 ids
.node_name
= port
->wwnn
;
556 ids
.port_name
= port
->wwpn
;
557 ids
.port_id
= port
->d_id
;
558 ids
.roles
= FC_RPORT_ROLE_FCP_TARGET
;
560 rport
= fc_remote_port_add(port
->adapter
->scsi_host
, 0, &ids
);
562 dev_err(&port
->adapter
->ccw_device
->dev
,
563 "Registering port 0x%016Lx failed\n",
564 (unsigned long long)port
->wwpn
);
568 rport
->maxframe_size
= port
->maxframe_size
;
569 rport
->supported_classes
= port
->supported_classes
;
571 port
->starget_id
= rport
->scsi_target_id
;
573 zfcp_unit_queue_scsi_scan(port
);
576 static void zfcp_scsi_rport_block(struct zfcp_port
*port
)
578 struct fc_rport
*rport
= port
->rport
;
581 fc_remote_port_delete(rport
);
586 void zfcp_scsi_schedule_rport_register(struct zfcp_port
*port
)
588 get_device(&port
->dev
);
589 port
->rport_task
= RPORT_ADD
;
591 if (!queue_work(port
->adapter
->work_queue
, &port
->rport_work
))
592 put_device(&port
->dev
);
595 void zfcp_scsi_schedule_rport_block(struct zfcp_port
*port
)
597 get_device(&port
->dev
);
598 port
->rport_task
= RPORT_DEL
;
600 if (port
->rport
&& queue_work(port
->adapter
->work_queue
,
604 put_device(&port
->dev
);
607 void zfcp_scsi_schedule_rports_block(struct zfcp_adapter
*adapter
)
610 struct zfcp_port
*port
;
612 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
613 list_for_each_entry(port
, &adapter
->port_list
, list
)
614 zfcp_scsi_schedule_rport_block(port
);
615 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
618 void zfcp_scsi_rport_work(struct work_struct
*work
)
620 struct zfcp_port
*port
= container_of(work
, struct zfcp_port
,
623 while (port
->rport_task
) {
624 if (port
->rport_task
== RPORT_ADD
) {
625 port
->rport_task
= RPORT_NONE
;
626 zfcp_scsi_rport_register(port
);
628 port
->rport_task
= RPORT_NONE
;
629 zfcp_scsi_rport_block(port
);
633 put_device(&port
->dev
);
637 * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
638 * @adapter: The adapter where to configure DIF/DIX for the SCSI host
640 void zfcp_scsi_set_prot(struct zfcp_adapter
*adapter
)
642 unsigned int mask
= 0;
643 unsigned int data_div
;
644 struct Scsi_Host
*shost
= adapter
->scsi_host
;
646 data_div
= atomic_read(&adapter
->status
) &
647 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED
;
650 adapter
->adapter_features
& FSF_FEATURE_DIF_PROT_TYPE1
)
651 mask
|= SHOST_DIF_TYPE1_PROTECTION
;
653 if (enable_dif
&& data_div
&&
654 adapter
->adapter_features
& FSF_FEATURE_DIX_PROT_TCPIP
) {
655 mask
|= SHOST_DIX_TYPE1_PROTECTION
;
656 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_IP
);
657 shost
->sg_prot_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
658 shost
->sg_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
659 shost
->max_sectors
= shost
->sg_tablesize
* 8;
662 scsi_host_set_prot(shost
, mask
);
666 * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
667 * @scmd: The SCSI command to report the error for
668 * @ascq: The ASCQ to put in the sense buffer
670 * See the error handling in sd_done for the sense codes used here.
671 * Set DID_SOFT_ERROR to retry the request, if possible.
673 void zfcp_scsi_dif_sense_error(struct scsi_cmnd
*scmd
, int ascq
)
675 scsi_build_sense_buffer(1, scmd
->sense_buffer
,
676 ILLEGAL_REQUEST
, 0x10, ascq
);
677 set_driver_byte(scmd
, DRIVER_SENSE
);
678 scmd
->result
|= SAM_STAT_CHECK_CONDITION
;
679 set_host_byte(scmd
, DID_SOFT_ERROR
);
682 struct fc_function_template zfcp_transport_functions
= {
683 .show_starget_port_id
= 1,
684 .show_starget_port_name
= 1,
685 .show_starget_node_name
= 1,
686 .show_rport_supported_classes
= 1,
687 .show_rport_maxframe_size
= 1,
688 .show_rport_dev_loss_tmo
= 1,
689 .show_host_node_name
= 1,
690 .show_host_port_name
= 1,
691 .show_host_permanent_port_name
= 1,
692 .show_host_supported_classes
= 1,
693 .show_host_supported_fc4s
= 1,
694 .show_host_supported_speeds
= 1,
695 .show_host_maxframe_size
= 1,
696 .show_host_serial_number
= 1,
697 .get_fc_host_stats
= zfcp_get_fc_host_stats
,
698 .reset_fc_host_stats
= zfcp_reset_fc_host_stats
,
699 .set_rport_dev_loss_tmo
= zfcp_set_rport_dev_loss_tmo
,
700 .get_host_port_state
= zfcp_get_host_port_state
,
701 .terminate_rport_io
= zfcp_scsi_terminate_rport_io
,
702 .show_host_port_state
= 1,
703 .show_host_active_fc4s
= 1,
704 .bsg_request
= zfcp_fc_exec_bsg_job
,
705 .bsg_timeout
= zfcp_fc_timeout_bsg_job
,
706 /* no functions registered for following dynamic attributes but
707 directly set by LLDD */
708 .show_host_port_type
= 1,
709 .show_host_symbolic_name
= 1,
710 .show_host_speed
= 1,
711 .show_host_port_id
= 1,
712 .dd_bsg_size
= sizeof(struct zfcp_fsf_ct_els
),