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
,
38 scsi_adjust_queue_depth(sdev
, depth
);
39 return sdev
->queue_depth
;
42 static void zfcp_scsi_slave_destroy(struct scsi_device
*sdev
)
44 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
46 /* if previous slave_alloc returned early, there is nothing to do */
50 zfcp_erp_lun_shutdown_wait(sdev
, "scssd_1");
51 put_device(&zfcp_sdev
->port
->dev
);
54 static int zfcp_scsi_slave_configure(struct scsi_device
*sdp
)
56 if (sdp
->tagged_supported
)
57 scsi_adjust_queue_depth(sdp
, default_depth
);
61 static void zfcp_scsi_command_fail(struct scsi_cmnd
*scpnt
, int result
)
63 set_host_byte(scpnt
, result
);
64 zfcp_dbf_scsi_fail_send(scpnt
);
65 scpnt
->scsi_done(scpnt
);
69 int zfcp_scsi_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*scpnt
)
71 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
72 struct fc_rport
*rport
= starget_to_rport(scsi_target(scpnt
->device
));
73 int status
, scsi_result
, ret
;
75 /* reset the status for this request */
77 scpnt
->host_scribble
= NULL
;
79 scsi_result
= fc_remote_port_chkready(rport
);
80 if (unlikely(scsi_result
)) {
81 scpnt
->result
= scsi_result
;
82 zfcp_dbf_scsi_fail_send(scpnt
);
83 scpnt
->scsi_done(scpnt
);
87 status
= atomic_read(&zfcp_sdev
->status
);
88 if (unlikely(status
& ZFCP_STATUS_COMMON_ERP_FAILED
) &&
89 !(atomic_read(&zfcp_sdev
->port
->status
) &
90 ZFCP_STATUS_COMMON_ERP_FAILED
)) {
91 /* only LUN access denied, but port is good
92 * not covered by FC transport, have to fail here */
93 zfcp_scsi_command_fail(scpnt
, DID_ERROR
);
97 if (unlikely(!(status
& ZFCP_STATUS_COMMON_UNBLOCKED
))) {
98 /* This could be either
99 * open LUN pending: this is temporary, will result in
100 * open LUN or ERP_FAILED, so retry command
101 * call to rport_delete pending: mimic retry from
102 * fc_remote_port_chkready until rport is BLOCKED
104 zfcp_scsi_command_fail(scpnt
, DID_IMM_RETRY
);
108 ret
= zfcp_fsf_fcp_cmnd(scpnt
);
109 if (unlikely(ret
== -EBUSY
))
110 return SCSI_MLQUEUE_DEVICE_BUSY
;
111 else if (unlikely(ret
< 0))
112 return SCSI_MLQUEUE_HOST_BUSY
;
117 static int zfcp_scsi_slave_alloc(struct scsi_device
*sdev
)
119 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
120 struct zfcp_adapter
*adapter
=
121 (struct zfcp_adapter
*) sdev
->host
->hostdata
[0];
122 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
123 struct zfcp_port
*port
;
124 struct zfcp_unit
*unit
;
125 int npiv
= adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
;
127 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
131 unit
= zfcp_unit_find(port
, zfcp_scsi_dev_lun(sdev
));
133 put_device(&unit
->dev
);
135 if (!unit
&& !(allow_lun_scan
&& npiv
)) {
136 put_device(&port
->dev
);
140 zfcp_sdev
->port
= port
;
141 zfcp_sdev
->latencies
.write
.channel
.min
= 0xFFFFFFFF;
142 zfcp_sdev
->latencies
.write
.fabric
.min
= 0xFFFFFFFF;
143 zfcp_sdev
->latencies
.read
.channel
.min
= 0xFFFFFFFF;
144 zfcp_sdev
->latencies
.read
.fabric
.min
= 0xFFFFFFFF;
145 zfcp_sdev
->latencies
.cmd
.channel
.min
= 0xFFFFFFFF;
146 zfcp_sdev
->latencies
.cmd
.fabric
.min
= 0xFFFFFFFF;
147 spin_lock_init(&zfcp_sdev
->latencies
.lock
);
149 zfcp_erp_set_lun_status(sdev
, ZFCP_STATUS_COMMON_RUNNING
);
150 zfcp_erp_lun_reopen(sdev
, 0, "scsla_1");
151 zfcp_erp_wait(port
->adapter
);
156 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd
*scpnt
)
158 struct Scsi_Host
*scsi_host
= scpnt
->device
->host
;
159 struct zfcp_adapter
*adapter
=
160 (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
161 struct zfcp_fsf_req
*old_req
, *abrt_req
;
163 unsigned long old_reqid
= (unsigned long) scpnt
->host_scribble
;
164 int retval
= SUCCESS
, ret
;
168 /* avoid race condition between late normal completion and abort */
169 write_lock_irqsave(&adapter
->abort_lock
, flags
);
171 old_req
= zfcp_reqlist_find(adapter
->req_list
, old_reqid
);
173 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
174 zfcp_dbf_scsi_abort("abrt_or", scpnt
, NULL
);
175 return FAILED
; /* completion could be in progress */
177 old_req
->data
= NULL
;
179 /* don't access old fsf_req after releasing the abort_lock */
180 write_unlock_irqrestore(&adapter
->abort_lock
, flags
);
183 abrt_req
= zfcp_fsf_abort_fcp_cmnd(scpnt
);
187 zfcp_erp_wait(adapter
);
188 ret
= fc_block_scsi_eh(scpnt
);
190 zfcp_dbf_scsi_abort("abrt_bl", scpnt
, NULL
);
193 if (!(atomic_read(&adapter
->status
) &
194 ZFCP_STATUS_COMMON_RUNNING
)) {
195 zfcp_dbf_scsi_abort("abrt_ru", scpnt
, NULL
);
200 zfcp_dbf_scsi_abort("abrt_ar", scpnt
, NULL
);
204 wait_for_completion(&abrt_req
->completion
);
206 if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED
)
208 else if (abrt_req
->status
& ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED
)
214 zfcp_dbf_scsi_abort(dbf_tag
, scpnt
, abrt_req
);
215 zfcp_fsf_req_free(abrt_req
);
219 static int zfcp_task_mgmt_function(struct scsi_cmnd
*scpnt
, u8 tm_flags
)
221 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
222 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
223 struct zfcp_fsf_req
*fsf_req
= NULL
;
224 int retval
= SUCCESS
, ret
;
228 fsf_req
= zfcp_fsf_fcp_task_mgmt(scpnt
, tm_flags
);
232 zfcp_erp_wait(adapter
);
233 ret
= fc_block_scsi_eh(scpnt
);
237 if (!(atomic_read(&adapter
->status
) &
238 ZFCP_STATUS_COMMON_RUNNING
)) {
239 zfcp_dbf_scsi_devreset("nres", scpnt
, tm_flags
);
246 wait_for_completion(&fsf_req
->completion
);
248 if (fsf_req
->status
& ZFCP_STATUS_FSFREQ_TMFUNCFAILED
) {
249 zfcp_dbf_scsi_devreset("fail", scpnt
, tm_flags
);
252 zfcp_dbf_scsi_devreset("okay", scpnt
, tm_flags
);
254 zfcp_fsf_req_free(fsf_req
);
258 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd
*scpnt
)
260 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_LUN_RESET
);
263 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd
*scpnt
)
265 return zfcp_task_mgmt_function(scpnt
, FCP_TMF_TGT_RESET
);
268 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd
*scpnt
)
270 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(scpnt
->device
);
271 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
274 zfcp_erp_adapter_reopen(adapter
, 0, "schrh_1");
275 zfcp_erp_wait(adapter
);
276 ret
= fc_block_scsi_eh(scpnt
);
283 struct scsi_transport_template
*zfcp_scsi_transport_template
;
285 static struct scsi_host_template zfcp_scsi_host_template
= {
286 .module
= THIS_MODULE
,
288 .queuecommand
= zfcp_scsi_queuecommand
,
289 .eh_abort_handler
= zfcp_scsi_eh_abort_handler
,
290 .eh_device_reset_handler
= zfcp_scsi_eh_device_reset_handler
,
291 .eh_target_reset_handler
= zfcp_scsi_eh_target_reset_handler
,
292 .eh_host_reset_handler
= zfcp_scsi_eh_host_reset_handler
,
293 .slave_alloc
= zfcp_scsi_slave_alloc
,
294 .slave_configure
= zfcp_scsi_slave_configure
,
295 .slave_destroy
= zfcp_scsi_slave_destroy
,
296 .change_queue_depth
= zfcp_scsi_change_queue_depth
,
300 .sg_tablesize
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
301 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2),
302 /* GCD, adjusted later */
303 .max_sectors
= (((QDIO_MAX_ELEMENTS_PER_BUFFER
- 1)
304 * ZFCP_QDIO_MAX_SBALS_PER_REQ
) - 2) * 8,
305 /* GCD, adjusted later */
306 .dma_boundary
= ZFCP_QDIO_SBALE_LEN
- 1,
309 .shost_attrs
= zfcp_sysfs_shost_attrs
,
310 .sdev_attrs
= zfcp_sysfs_sdev_attrs
,
311 .track_queue_depth
= 1,
315 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
316 * @adapter: The zfcp adapter to register with the SCSI midlayer
318 int zfcp_scsi_adapter_register(struct zfcp_adapter
*adapter
)
320 struct ccw_dev_id dev_id
;
322 if (adapter
->scsi_host
)
325 ccw_device_get_id(adapter
->ccw_device
, &dev_id
);
326 /* register adapter as SCSI host with mid layer of SCSI stack */
327 adapter
->scsi_host
= scsi_host_alloc(&zfcp_scsi_host_template
,
328 sizeof (struct zfcp_adapter
*));
329 if (!adapter
->scsi_host
) {
330 dev_err(&adapter
->ccw_device
->dev
,
331 "Registering the FCP device with the "
332 "SCSI stack failed\n");
336 /* tell the SCSI stack some characteristics of this adapter */
337 adapter
->scsi_host
->max_id
= 511;
338 adapter
->scsi_host
->max_lun
= 0xFFFFFFFF;
339 adapter
->scsi_host
->max_channel
= 0;
340 adapter
->scsi_host
->unique_id
= dev_id
.devno
;
341 adapter
->scsi_host
->max_cmd_len
= 16; /* in struct fcp_cmnd */
342 adapter
->scsi_host
->transportt
= zfcp_scsi_transport_template
;
344 adapter
->scsi_host
->hostdata
[0] = (unsigned long) adapter
;
346 if (scsi_add_host(adapter
->scsi_host
, &adapter
->ccw_device
->dev
)) {
347 scsi_host_put(adapter
->scsi_host
);
355 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
356 * @adapter: The zfcp adapter to unregister.
358 void zfcp_scsi_adapter_unregister(struct zfcp_adapter
*adapter
)
360 struct Scsi_Host
*shost
;
361 struct zfcp_port
*port
;
363 shost
= adapter
->scsi_host
;
367 read_lock_irq(&adapter
->port_list_lock
);
368 list_for_each_entry(port
, &adapter
->port_list
, list
)
370 read_unlock_irq(&adapter
->port_list_lock
);
372 fc_remove_host(shost
);
373 scsi_remove_host(shost
);
374 scsi_host_put(shost
);
375 adapter
->scsi_host
= NULL
;
378 static struct fc_host_statistics
*
379 zfcp_init_fc_host_stats(struct zfcp_adapter
*adapter
)
381 struct fc_host_statistics
*fc_stats
;
383 if (!adapter
->fc_stats
) {
384 fc_stats
= kmalloc(sizeof(*fc_stats
), GFP_KERNEL
);
387 adapter
->fc_stats
= fc_stats
; /* freed in adapter_release */
389 memset(adapter
->fc_stats
, 0, sizeof(*adapter
->fc_stats
));
390 return adapter
->fc_stats
;
393 static void zfcp_adjust_fc_host_stats(struct fc_host_statistics
*fc_stats
,
394 struct fsf_qtcb_bottom_port
*data
,
395 struct fsf_qtcb_bottom_port
*old
)
397 fc_stats
->seconds_since_last_reset
=
398 data
->seconds_since_last_reset
- old
->seconds_since_last_reset
;
399 fc_stats
->tx_frames
= data
->tx_frames
- old
->tx_frames
;
400 fc_stats
->tx_words
= data
->tx_words
- old
->tx_words
;
401 fc_stats
->rx_frames
= data
->rx_frames
- old
->rx_frames
;
402 fc_stats
->rx_words
= data
->rx_words
- old
->rx_words
;
403 fc_stats
->lip_count
= data
->lip
- old
->lip
;
404 fc_stats
->nos_count
= data
->nos
- old
->nos
;
405 fc_stats
->error_frames
= data
->error_frames
- old
->error_frames
;
406 fc_stats
->dumped_frames
= data
->dumped_frames
- old
->dumped_frames
;
407 fc_stats
->link_failure_count
= data
->link_failure
- old
->link_failure
;
408 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
- old
->loss_of_sync
;
409 fc_stats
->loss_of_signal_count
=
410 data
->loss_of_signal
- old
->loss_of_signal
;
411 fc_stats
->prim_seq_protocol_err_count
=
412 data
->psp_error_counts
- old
->psp_error_counts
;
413 fc_stats
->invalid_tx_word_count
=
414 data
->invalid_tx_words
- old
->invalid_tx_words
;
415 fc_stats
->invalid_crc_count
= data
->invalid_crcs
- old
->invalid_crcs
;
416 fc_stats
->fcp_input_requests
=
417 data
->input_requests
- old
->input_requests
;
418 fc_stats
->fcp_output_requests
=
419 data
->output_requests
- old
->output_requests
;
420 fc_stats
->fcp_control_requests
=
421 data
->control_requests
- old
->control_requests
;
422 fc_stats
->fcp_input_megabytes
= data
->input_mb
- old
->input_mb
;
423 fc_stats
->fcp_output_megabytes
= data
->output_mb
- old
->output_mb
;
426 static void zfcp_set_fc_host_stats(struct fc_host_statistics
*fc_stats
,
427 struct fsf_qtcb_bottom_port
*data
)
429 fc_stats
->seconds_since_last_reset
= data
->seconds_since_last_reset
;
430 fc_stats
->tx_frames
= data
->tx_frames
;
431 fc_stats
->tx_words
= data
->tx_words
;
432 fc_stats
->rx_frames
= data
->rx_frames
;
433 fc_stats
->rx_words
= data
->rx_words
;
434 fc_stats
->lip_count
= data
->lip
;
435 fc_stats
->nos_count
= data
->nos
;
436 fc_stats
->error_frames
= data
->error_frames
;
437 fc_stats
->dumped_frames
= data
->dumped_frames
;
438 fc_stats
->link_failure_count
= data
->link_failure
;
439 fc_stats
->loss_of_sync_count
= data
->loss_of_sync
;
440 fc_stats
->loss_of_signal_count
= data
->loss_of_signal
;
441 fc_stats
->prim_seq_protocol_err_count
= data
->psp_error_counts
;
442 fc_stats
->invalid_tx_word_count
= data
->invalid_tx_words
;
443 fc_stats
->invalid_crc_count
= data
->invalid_crcs
;
444 fc_stats
->fcp_input_requests
= data
->input_requests
;
445 fc_stats
->fcp_output_requests
= data
->output_requests
;
446 fc_stats
->fcp_control_requests
= data
->control_requests
;
447 fc_stats
->fcp_input_megabytes
= data
->input_mb
;
448 fc_stats
->fcp_output_megabytes
= data
->output_mb
;
451 static struct fc_host_statistics
*zfcp_get_fc_host_stats(struct Scsi_Host
*host
)
453 struct zfcp_adapter
*adapter
;
454 struct fc_host_statistics
*fc_stats
;
455 struct fsf_qtcb_bottom_port
*data
;
458 adapter
= (struct zfcp_adapter
*)host
->hostdata
[0];
459 fc_stats
= zfcp_init_fc_host_stats(adapter
);
463 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
467 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
473 if (adapter
->stats_reset
&&
474 ((jiffies
/HZ
- adapter
->stats_reset
) <
475 data
->seconds_since_last_reset
))
476 zfcp_adjust_fc_host_stats(fc_stats
, data
,
477 adapter
->stats_reset_data
);
479 zfcp_set_fc_host_stats(fc_stats
, data
);
485 static void zfcp_reset_fc_host_stats(struct Scsi_Host
*shost
)
487 struct zfcp_adapter
*adapter
;
488 struct fsf_qtcb_bottom_port
*data
;
491 adapter
= (struct zfcp_adapter
*)shost
->hostdata
[0];
492 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
496 ret
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, data
);
500 adapter
->stats_reset
= jiffies
/HZ
;
501 kfree(adapter
->stats_reset_data
);
502 adapter
->stats_reset_data
= data
; /* finally freed in
507 static void zfcp_get_host_port_state(struct Scsi_Host
*shost
)
509 struct zfcp_adapter
*adapter
=
510 (struct zfcp_adapter
*)shost
->hostdata
[0];
511 int status
= atomic_read(&adapter
->status
);
513 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
514 !(status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
))
515 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
516 else if (status
& ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
)
517 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
518 else if (status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
519 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
521 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
524 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
526 rport
->dev_loss_tmo
= timeout
;
530 * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
531 * @rport: The FC rport where to teminate I/O
533 * Abort all pending SCSI commands for a port by closing the
534 * port. Using a reopen avoids a conflict with a shutdown
535 * overwriting a reopen. The "forced" ensures that a disappeared port
536 * is not opened again as valid due to the cached plogi data in
539 static void zfcp_scsi_terminate_rport_io(struct fc_rport
*rport
)
541 struct zfcp_port
*port
;
542 struct Scsi_Host
*shost
= rport_to_shost(rport
);
543 struct zfcp_adapter
*adapter
=
544 (struct zfcp_adapter
*)shost
->hostdata
[0];
546 port
= zfcp_get_port_by_wwpn(adapter
, rport
->port_name
);
549 zfcp_erp_port_forced_reopen(port
, 0, "sctrpi1");
550 put_device(&port
->dev
);
554 static void zfcp_scsi_rport_register(struct zfcp_port
*port
)
556 struct fc_rport_identifiers ids
;
557 struct fc_rport
*rport
;
562 ids
.node_name
= port
->wwnn
;
563 ids
.port_name
= port
->wwpn
;
564 ids
.port_id
= port
->d_id
;
565 ids
.roles
= FC_RPORT_ROLE_FCP_TARGET
;
567 rport
= fc_remote_port_add(port
->adapter
->scsi_host
, 0, &ids
);
569 dev_err(&port
->adapter
->ccw_device
->dev
,
570 "Registering port 0x%016Lx failed\n",
571 (unsigned long long)port
->wwpn
);
575 rport
->maxframe_size
= port
->maxframe_size
;
576 rport
->supported_classes
= port
->supported_classes
;
578 port
->starget_id
= rport
->scsi_target_id
;
580 zfcp_unit_queue_scsi_scan(port
);
583 static void zfcp_scsi_rport_block(struct zfcp_port
*port
)
585 struct fc_rport
*rport
= port
->rport
;
588 fc_remote_port_delete(rport
);
593 void zfcp_scsi_schedule_rport_register(struct zfcp_port
*port
)
595 get_device(&port
->dev
);
596 port
->rport_task
= RPORT_ADD
;
598 if (!queue_work(port
->adapter
->work_queue
, &port
->rport_work
))
599 put_device(&port
->dev
);
602 void zfcp_scsi_schedule_rport_block(struct zfcp_port
*port
)
604 get_device(&port
->dev
);
605 port
->rport_task
= RPORT_DEL
;
607 if (port
->rport
&& queue_work(port
->adapter
->work_queue
,
611 put_device(&port
->dev
);
614 void zfcp_scsi_schedule_rports_block(struct zfcp_adapter
*adapter
)
617 struct zfcp_port
*port
;
619 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
620 list_for_each_entry(port
, &adapter
->port_list
, list
)
621 zfcp_scsi_schedule_rport_block(port
);
622 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
625 void zfcp_scsi_rport_work(struct work_struct
*work
)
627 struct zfcp_port
*port
= container_of(work
, struct zfcp_port
,
630 while (port
->rport_task
) {
631 if (port
->rport_task
== RPORT_ADD
) {
632 port
->rport_task
= RPORT_NONE
;
633 zfcp_scsi_rport_register(port
);
635 port
->rport_task
= RPORT_NONE
;
636 zfcp_scsi_rport_block(port
);
640 put_device(&port
->dev
);
644 * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
645 * @adapter: The adapter where to configure DIF/DIX for the SCSI host
647 void zfcp_scsi_set_prot(struct zfcp_adapter
*adapter
)
649 unsigned int mask
= 0;
650 unsigned int data_div
;
651 struct Scsi_Host
*shost
= adapter
->scsi_host
;
653 data_div
= atomic_read(&adapter
->status
) &
654 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED
;
657 adapter
->adapter_features
& FSF_FEATURE_DIF_PROT_TYPE1
)
658 mask
|= SHOST_DIF_TYPE1_PROTECTION
;
660 if (enable_dif
&& data_div
&&
661 adapter
->adapter_features
& FSF_FEATURE_DIX_PROT_TCPIP
) {
662 mask
|= SHOST_DIX_TYPE1_PROTECTION
;
663 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_IP
);
664 shost
->sg_prot_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
665 shost
->sg_tablesize
= adapter
->qdio
->max_sbale_per_req
/ 2;
666 shost
->max_sectors
= shost
->sg_tablesize
* 8;
669 scsi_host_set_prot(shost
, mask
);
673 * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
674 * @scmd: The SCSI command to report the error for
675 * @ascq: The ASCQ to put in the sense buffer
677 * See the error handling in sd_done for the sense codes used here.
678 * Set DID_SOFT_ERROR to retry the request, if possible.
680 void zfcp_scsi_dif_sense_error(struct scsi_cmnd
*scmd
, int ascq
)
682 scsi_build_sense_buffer(1, scmd
->sense_buffer
,
683 ILLEGAL_REQUEST
, 0x10, ascq
);
684 set_driver_byte(scmd
, DRIVER_SENSE
);
685 scmd
->result
|= SAM_STAT_CHECK_CONDITION
;
686 set_host_byte(scmd
, DID_SOFT_ERROR
);
689 struct fc_function_template zfcp_transport_functions
= {
690 .show_starget_port_id
= 1,
691 .show_starget_port_name
= 1,
692 .show_starget_node_name
= 1,
693 .show_rport_supported_classes
= 1,
694 .show_rport_maxframe_size
= 1,
695 .show_rport_dev_loss_tmo
= 1,
696 .show_host_node_name
= 1,
697 .show_host_port_name
= 1,
698 .show_host_permanent_port_name
= 1,
699 .show_host_supported_classes
= 1,
700 .show_host_supported_fc4s
= 1,
701 .show_host_supported_speeds
= 1,
702 .show_host_maxframe_size
= 1,
703 .show_host_serial_number
= 1,
704 .get_fc_host_stats
= zfcp_get_fc_host_stats
,
705 .reset_fc_host_stats
= zfcp_reset_fc_host_stats
,
706 .set_rport_dev_loss_tmo
= zfcp_set_rport_dev_loss_tmo
,
707 .get_host_port_state
= zfcp_get_host_port_state
,
708 .terminate_rport_io
= zfcp_scsi_terminate_rport_io
,
709 .show_host_port_state
= 1,
710 .show_host_active_fc4s
= 1,
711 .bsg_request
= zfcp_fc_exec_bsg_job
,
712 .bsg_timeout
= zfcp_fc_timeout_bsg_job
,
713 /* no functions registered for following dynamic attributes but
714 directly set by LLDD */
715 .show_host_port_type
= 1,
716 .show_host_symbolic_name
= 1,
717 .show_host_speed
= 1,
718 .show_host_port_id
= 1,
719 .dd_bsg_size
= sizeof(struct zfcp_fsf_ct_els
),