]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/s390/scsi/zfcp_scsi.c
scsi: avoid ->change_queue_depth indirection for queue full tracking
[mirror_ubuntu-bionic-kernel.git] / drivers / s390 / scsi / zfcp_scsi.c
1 /*
2 * zfcp device driver
3 *
4 * Interface to Linux SCSI midlayer.
5 *
6 * Copyright IBM Corp. 2002, 2013
7 */
8
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
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>
18 #include "zfcp_ext.h"
19 #include "zfcp_dbf.h"
20 #include "zfcp_fc.h"
21 #include "zfcp_reqlist.h"
22
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");
26
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");
30
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");
34
35 static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth,
36 int reason)
37 {
38 scsi_adjust_queue_depth(sdev, depth);
39 return sdev->queue_depth;
40 }
41
42 static void zfcp_scsi_slave_destroy(struct scsi_device *sdev)
43 {
44 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
45
46 /* if previous slave_alloc returned early, there is nothing to do */
47 if (!zfcp_sdev->port)
48 return;
49
50 zfcp_erp_lun_shutdown_wait(sdev, "scssd_1");
51 put_device(&zfcp_sdev->port->dev);
52 }
53
54 static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
55 {
56 if (sdp->tagged_supported)
57 scsi_adjust_queue_depth(sdp, default_depth);
58 return 0;
59 }
60
61 static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
62 {
63 set_host_byte(scpnt, result);
64 zfcp_dbf_scsi_fail_send(scpnt);
65 scpnt->scsi_done(scpnt);
66 }
67
68 static
69 int zfcp_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scpnt)
70 {
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;
74
75 /* reset the status for this request */
76 scpnt->result = 0;
77 scpnt->host_scribble = NULL;
78
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);
84 return 0;
85 }
86
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);
94 return 0;
95 }
96
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
103 */
104 zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY);
105 return 0;
106 }
107
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;
113
114 return ret;
115 }
116
117 static int zfcp_scsi_slave_alloc(struct scsi_device *sdev)
118 {
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;
126
127 port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
128 if (!port)
129 return -ENXIO;
130
131 unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev));
132 if (unit)
133 put_device(&unit->dev);
134
135 if (!unit && !(allow_lun_scan && npiv)) {
136 put_device(&port->dev);
137 return -ENXIO;
138 }
139
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);
148
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);
152
153 return 0;
154 }
155
156 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
157 {
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;
162 unsigned long flags;
163 unsigned long old_reqid = (unsigned long) scpnt->host_scribble;
164 int retval = SUCCESS, ret;
165 int retry = 3;
166 char *dbf_tag;
167
168 /* avoid race condition between late normal completion and abort */
169 write_lock_irqsave(&adapter->abort_lock, flags);
170
171 old_req = zfcp_reqlist_find(adapter->req_list, old_reqid);
172 if (!old_req) {
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 */
176 }
177 old_req->data = NULL;
178
179 /* don't access old fsf_req after releasing the abort_lock */
180 write_unlock_irqrestore(&adapter->abort_lock, flags);
181
182 while (retry--) {
183 abrt_req = zfcp_fsf_abort_fcp_cmnd(scpnt);
184 if (abrt_req)
185 break;
186
187 zfcp_erp_wait(adapter);
188 ret = fc_block_scsi_eh(scpnt);
189 if (ret) {
190 zfcp_dbf_scsi_abort("abrt_bl", scpnt, NULL);
191 return ret;
192 }
193 if (!(atomic_read(&adapter->status) &
194 ZFCP_STATUS_COMMON_RUNNING)) {
195 zfcp_dbf_scsi_abort("abrt_ru", scpnt, NULL);
196 return SUCCESS;
197 }
198 }
199 if (!abrt_req) {
200 zfcp_dbf_scsi_abort("abrt_ar", scpnt, NULL);
201 return FAILED;
202 }
203
204 wait_for_completion(&abrt_req->completion);
205
206 if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED)
207 dbf_tag = "abrt_ok";
208 else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED)
209 dbf_tag = "abrt_nn";
210 else {
211 dbf_tag = "abrt_fa";
212 retval = FAILED;
213 }
214 zfcp_dbf_scsi_abort(dbf_tag, scpnt, abrt_req);
215 zfcp_fsf_req_free(abrt_req);
216 return retval;
217 }
218
219 static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
220 {
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;
225 int retry = 3;
226
227 while (retry--) {
228 fsf_req = zfcp_fsf_fcp_task_mgmt(scpnt, tm_flags);
229 if (fsf_req)
230 break;
231
232 zfcp_erp_wait(adapter);
233 ret = fc_block_scsi_eh(scpnt);
234 if (ret)
235 return ret;
236
237 if (!(atomic_read(&adapter->status) &
238 ZFCP_STATUS_COMMON_RUNNING)) {
239 zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags);
240 return SUCCESS;
241 }
242 }
243 if (!fsf_req)
244 return FAILED;
245
246 wait_for_completion(&fsf_req->completion);
247
248 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
249 zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags);
250 retval = FAILED;
251 } else
252 zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags);
253
254 zfcp_fsf_req_free(fsf_req);
255 return retval;
256 }
257
258 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
259 {
260 return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET);
261 }
262
263 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
264 {
265 return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET);
266 }
267
268 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
269 {
270 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
271 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
272 int ret;
273
274 zfcp_erp_adapter_reopen(adapter, 0, "schrh_1");
275 zfcp_erp_wait(adapter);
276 ret = fc_block_scsi_eh(scpnt);
277 if (ret)
278 return ret;
279
280 return SUCCESS;
281 }
282
283 struct scsi_transport_template *zfcp_scsi_transport_template;
284
285 static struct scsi_host_template zfcp_scsi_host_template = {
286 .module = THIS_MODULE,
287 .name = "zfcp",
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,
297 .proc_name = "zfcp",
298 .can_queue = 4096,
299 .this_id = -1,
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,
307 .cmd_per_lun = 1,
308 .use_clustering = 1,
309 .shost_attrs = zfcp_sysfs_shost_attrs,
310 .sdev_attrs = zfcp_sysfs_sdev_attrs,
311 .track_queue_depth = 1,
312 };
313
314 /**
315 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
316 * @adapter: The zfcp adapter to register with the SCSI midlayer
317 */
318 int zfcp_scsi_adapter_register(struct zfcp_adapter *adapter)
319 {
320 struct ccw_dev_id dev_id;
321
322 if (adapter->scsi_host)
323 return 0;
324
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");
333 return -EIO;
334 }
335
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;
343
344 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
345
346 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
347 scsi_host_put(adapter->scsi_host);
348 return -EIO;
349 }
350
351 return 0;
352 }
353
354 /**
355 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
356 * @adapter: The zfcp adapter to unregister.
357 */
358 void zfcp_scsi_adapter_unregister(struct zfcp_adapter *adapter)
359 {
360 struct Scsi_Host *shost;
361 struct zfcp_port *port;
362
363 shost = adapter->scsi_host;
364 if (!shost)
365 return;
366
367 read_lock_irq(&adapter->port_list_lock);
368 list_for_each_entry(port, &adapter->port_list, list)
369 port->rport = NULL;
370 read_unlock_irq(&adapter->port_list_lock);
371
372 fc_remove_host(shost);
373 scsi_remove_host(shost);
374 scsi_host_put(shost);
375 adapter->scsi_host = NULL;
376 }
377
378 static struct fc_host_statistics*
379 zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
380 {
381 struct fc_host_statistics *fc_stats;
382
383 if (!adapter->fc_stats) {
384 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
385 if (!fc_stats)
386 return NULL;
387 adapter->fc_stats = fc_stats; /* freed in adapter_release */
388 }
389 memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
390 return adapter->fc_stats;
391 }
392
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)
396 {
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;
424 }
425
426 static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
427 struct fsf_qtcb_bottom_port *data)
428 {
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;
449 }
450
451 static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host)
452 {
453 struct zfcp_adapter *adapter;
454 struct fc_host_statistics *fc_stats;
455 struct fsf_qtcb_bottom_port *data;
456 int ret;
457
458 adapter = (struct zfcp_adapter *)host->hostdata[0];
459 fc_stats = zfcp_init_fc_host_stats(adapter);
460 if (!fc_stats)
461 return NULL;
462
463 data = kzalloc(sizeof(*data), GFP_KERNEL);
464 if (!data)
465 return NULL;
466
467 ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
468 if (ret) {
469 kfree(data);
470 return NULL;
471 }
472
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);
478 else
479 zfcp_set_fc_host_stats(fc_stats, data);
480
481 kfree(data);
482 return fc_stats;
483 }
484
485 static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
486 {
487 struct zfcp_adapter *adapter;
488 struct fsf_qtcb_bottom_port *data;
489 int ret;
490
491 adapter = (struct zfcp_adapter *)shost->hostdata[0];
492 data = kzalloc(sizeof(*data), GFP_KERNEL);
493 if (!data)
494 return;
495
496 ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
497 if (ret)
498 kfree(data);
499 else {
500 adapter->stats_reset = jiffies/HZ;
501 kfree(adapter->stats_reset_data);
502 adapter->stats_reset_data = data; /* finally freed in
503 adapter_release */
504 }
505 }
506
507 static void zfcp_get_host_port_state(struct Scsi_Host *shost)
508 {
509 struct zfcp_adapter *adapter =
510 (struct zfcp_adapter *)shost->hostdata[0];
511 int status = atomic_read(&adapter->status);
512
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;
520 else
521 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
522 }
523
524 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
525 {
526 rport->dev_loss_tmo = timeout;
527 }
528
529 /**
530 * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
531 * @rport: The FC rport where to teminate I/O
532 *
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
537 * non-NPIV mode.
538 */
539 static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
540 {
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];
545
546 port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
547
548 if (port) {
549 zfcp_erp_port_forced_reopen(port, 0, "sctrpi1");
550 put_device(&port->dev);
551 }
552 }
553
554 static void zfcp_scsi_rport_register(struct zfcp_port *port)
555 {
556 struct fc_rport_identifiers ids;
557 struct fc_rport *rport;
558
559 if (port->rport)
560 return;
561
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;
566
567 rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
568 if (!rport) {
569 dev_err(&port->adapter->ccw_device->dev,
570 "Registering port 0x%016Lx failed\n",
571 (unsigned long long)port->wwpn);
572 return;
573 }
574
575 rport->maxframe_size = port->maxframe_size;
576 rport->supported_classes = port->supported_classes;
577 port->rport = rport;
578 port->starget_id = rport->scsi_target_id;
579
580 zfcp_unit_queue_scsi_scan(port);
581 }
582
583 static void zfcp_scsi_rport_block(struct zfcp_port *port)
584 {
585 struct fc_rport *rport = port->rport;
586
587 if (rport) {
588 fc_remote_port_delete(rport);
589 port->rport = NULL;
590 }
591 }
592
593 void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
594 {
595 get_device(&port->dev);
596 port->rport_task = RPORT_ADD;
597
598 if (!queue_work(port->adapter->work_queue, &port->rport_work))
599 put_device(&port->dev);
600 }
601
602 void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
603 {
604 get_device(&port->dev);
605 port->rport_task = RPORT_DEL;
606
607 if (port->rport && queue_work(port->adapter->work_queue,
608 &port->rport_work))
609 return;
610
611 put_device(&port->dev);
612 }
613
614 void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
615 {
616 unsigned long flags;
617 struct zfcp_port *port;
618
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);
623 }
624
625 void zfcp_scsi_rport_work(struct work_struct *work)
626 {
627 struct zfcp_port *port = container_of(work, struct zfcp_port,
628 rport_work);
629
630 while (port->rport_task) {
631 if (port->rport_task == RPORT_ADD) {
632 port->rport_task = RPORT_NONE;
633 zfcp_scsi_rport_register(port);
634 } else {
635 port->rport_task = RPORT_NONE;
636 zfcp_scsi_rport_block(port);
637 }
638 }
639
640 put_device(&port->dev);
641 }
642
643 /**
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
646 */
647 void zfcp_scsi_set_prot(struct zfcp_adapter *adapter)
648 {
649 unsigned int mask = 0;
650 unsigned int data_div;
651 struct Scsi_Host *shost = adapter->scsi_host;
652
653 data_div = atomic_read(&adapter->status) &
654 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED;
655
656 if (enable_dif &&
657 adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1)
658 mask |= SHOST_DIF_TYPE1_PROTECTION;
659
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;
667 }
668
669 scsi_host_set_prot(shost, mask);
670 }
671
672 /**
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
676 *
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.
679 */
680 void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq)
681 {
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);
687 }
688
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),
720 };