[SCSI] zfcp: Change spin_lock_bh to spin_lock_irq to fix lockdep warning
[linux-2.6.git] / drivers / s390 / scsi / zfcp_scsi.c
1 /*
2  * zfcp device driver
3  *
4  * Interface to Linux SCSI midlayer.
5  *
6  * Copyright IBM Corporation 2002, 2010
7  */
8
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
12 #include <linux/types.h>
13 #include <linux/slab.h>
14 #include <scsi/fc/fc_fcp.h>
15 #include <scsi/scsi_eh.h>
16 #include <asm/atomic.h>
17 #include "zfcp_ext.h"
18 #include "zfcp_dbf.h"
19 #include "zfcp_fc.h"
20 #include "zfcp_reqlist.h"
21
22 static unsigned int default_depth = 32;
23 module_param_named(queue_depth, default_depth, uint, 0600);
24 MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices");
25
26 static bool enable_dif;
27
28 #ifdef CONFIG_ZFCP_DIF
29 module_param_named(dif, enable_dif, bool, 0600);
30 MODULE_PARM_DESC(dif, "Enable DIF/DIX data integrity support");
31 #endif
32
33 static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth,
34                                         int reason)
35 {
36         switch (reason) {
37         case SCSI_QDEPTH_DEFAULT:
38                 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
39                 break;
40         case SCSI_QDEPTH_QFULL:
41                 scsi_track_queue_full(sdev, depth);
42                 break;
43         case SCSI_QDEPTH_RAMP_UP:
44                 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
45                 break;
46         default:
47                 return -EOPNOTSUPP;
48         }
49         return sdev->queue_depth;
50 }
51
52 static void zfcp_scsi_slave_destroy(struct scsi_device *sdev)
53 {
54         struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
55
56         zfcp_erp_lun_shutdown_wait(sdev, "scssd_1");
57         put_device(&zfcp_sdev->port->dev);
58 }
59
60 static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
61 {
62         if (sdp->tagged_supported)
63                 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, default_depth);
64         else
65                 scsi_adjust_queue_depth(sdp, 0, 1);
66         return 0;
67 }
68
69 static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
70 {
71         struct zfcp_adapter *adapter =
72                 (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
73
74         set_host_byte(scpnt, result);
75         zfcp_dbf_scsi_fail_send(adapter->dbf, scpnt);
76         scpnt->scsi_done(scpnt);
77 }
78
79 static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
80                                   void (*done) (struct scsi_cmnd *))
81 {
82         struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
83         struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
84         struct fc_rport *rport = starget_to_rport(scsi_target(scpnt->device));
85         int    status, scsi_result, ret;
86
87         /* reset the status for this request */
88         scpnt->result = 0;
89         scpnt->host_scribble = NULL;
90         scpnt->scsi_done = done;
91
92         scsi_result = fc_remote_port_chkready(rport);
93         if (unlikely(scsi_result)) {
94                 scpnt->result = scsi_result;
95                 zfcp_dbf_scsi_fail_send(adapter->dbf, scpnt);
96                 scpnt->scsi_done(scpnt);
97                 return 0;
98         }
99
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);
107                 return 0;
108         }
109
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
116                  */
117                 zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY);
118                 return 0;
119         }
120
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;
126
127         return ret;
128 }
129
130 static int zfcp_scsi_slave_alloc(struct scsi_device *sdev)
131 {
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
139         port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
140         if (!port)
141                 return -ENXIO;
142
143         unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev));
144         if (unit)
145                 put_device(&unit->dev);
146
147         if (!unit && !(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) {
148                 put_device(&port->dev);
149                 return -ENXIO;
150         }
151
152         zfcp_sdev->port = port;
153         zfcp_sdev->latencies.write.channel.min = 0xFFFFFFFF;
154         zfcp_sdev->latencies.write.fabric.min = 0xFFFFFFFF;
155         zfcp_sdev->latencies.read.channel.min = 0xFFFFFFFF;
156         zfcp_sdev->latencies.read.fabric.min = 0xFFFFFFFF;
157         zfcp_sdev->latencies.cmd.channel.min = 0xFFFFFFFF;
158         zfcp_sdev->latencies.cmd.fabric.min = 0xFFFFFFFF;
159         spin_lock_init(&zfcp_sdev->latencies.lock);
160
161         zfcp_erp_modify_lun_status(sdev, "scsla_0", NULL,
162                                    ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
163         zfcp_erp_lun_reopen(sdev, 0, "scsla_1", NULL);
164         zfcp_erp_wait(port->adapter);
165
166         return 0;
167 }
168
169 static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
170 {
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;
175         unsigned long flags;
176         unsigned long old_reqid = (unsigned long) scpnt->host_scribble;
177         int retval = SUCCESS, ret;
178         int retry = 3;
179         char *dbf_tag;
180
181         /* avoid race condition between late normal completion and abort */
182         write_lock_irqsave(&adapter->abort_lock, flags);
183
184         old_req = zfcp_reqlist_find(adapter->req_list, old_reqid);
185         if (!old_req) {
186                 write_unlock_irqrestore(&adapter->abort_lock, flags);
187                 zfcp_dbf_scsi_abort("lte1", adapter->dbf, scpnt, NULL,
188                                     old_reqid);
189                 return FAILED; /* completion could be in progress */
190         }
191         old_req->data = NULL;
192
193         /* don't access old fsf_req after releasing the abort_lock */
194         write_unlock_irqrestore(&adapter->abort_lock, flags);
195
196         while (retry--) {
197                 abrt_req = zfcp_fsf_abort_fcp_cmnd(scpnt);
198                 if (abrt_req)
199                         break;
200
201                 zfcp_erp_wait(adapter);
202                 ret = fc_block_scsi_eh(scpnt);
203                 if (ret)
204                         return ret;
205                 if (!(atomic_read(&adapter->status) &
206                       ZFCP_STATUS_COMMON_RUNNING)) {
207                         zfcp_dbf_scsi_abort("nres", adapter->dbf, scpnt, NULL,
208                                             old_reqid);
209                         return SUCCESS;
210                 }
211         }
212         if (!abrt_req)
213                 return FAILED;
214
215         wait_for_completion(&abrt_req->completion);
216
217         if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED)
218                 dbf_tag = "okay";
219         else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED)
220                 dbf_tag = "lte2";
221         else {
222                 dbf_tag = "fail";
223                 retval = FAILED;
224         }
225         zfcp_dbf_scsi_abort(dbf_tag, adapter->dbf, scpnt, abrt_req, old_reqid);
226         zfcp_fsf_req_free(abrt_req);
227         return retval;
228 }
229
230 static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
231 {
232         struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
233         struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
234         struct zfcp_fsf_req *fsf_req = NULL;
235         int retval = SUCCESS, ret;
236         int retry = 3;
237
238         while (retry--) {
239                 fsf_req = zfcp_fsf_fcp_task_mgmt(scpnt, tm_flags);
240                 if (fsf_req)
241                         break;
242
243                 zfcp_erp_wait(adapter);
244                 ret = fc_block_scsi_eh(scpnt);
245                 if (ret)
246                         return ret;
247
248                 if (!(atomic_read(&adapter->status) &
249                       ZFCP_STATUS_COMMON_RUNNING)) {
250                         zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags);
251                         return SUCCESS;
252                 }
253         }
254         if (!fsf_req)
255                 return FAILED;
256
257         wait_for_completion(&fsf_req->completion);
258
259         if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
260                 zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags);
261                 retval = FAILED;
262         } else
263                 zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags);
264
265         zfcp_fsf_req_free(fsf_req);
266         return retval;
267 }
268
269 static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
270 {
271         return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET);
272 }
273
274 static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
275 {
276         return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET);
277 }
278
279 static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
280 {
281         struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
282         struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
283         int ret;
284
285         zfcp_erp_adapter_reopen(adapter, 0, "schrh_1", scpnt);
286         zfcp_erp_wait(adapter);
287         ret = fc_block_scsi_eh(scpnt);
288         if (ret)
289                 return ret;
290
291         return SUCCESS;
292 }
293
294 int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
295 {
296         struct ccw_dev_id dev_id;
297
298         if (adapter->scsi_host)
299                 return 0;
300
301         ccw_device_get_id(adapter->ccw_device, &dev_id);
302         /* register adapter as SCSI host with mid layer of SCSI stack */
303         adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
304                                              sizeof (struct zfcp_adapter *));
305         if (!adapter->scsi_host) {
306                 dev_err(&adapter->ccw_device->dev,
307                         "Registering the FCP device with the "
308                         "SCSI stack failed\n");
309                 return -EIO;
310         }
311
312         /* tell the SCSI stack some characteristics of this adapter */
313         adapter->scsi_host->max_id = 511;
314         adapter->scsi_host->max_lun = 0xFFFFFFFF;
315         adapter->scsi_host->max_channel = 0;
316         adapter->scsi_host->unique_id = dev_id.devno;
317         adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
318         adapter->scsi_host->transportt = zfcp_data.scsi_transport_template;
319
320         adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
321
322         if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
323                 scsi_host_put(adapter->scsi_host);
324                 return -EIO;
325         }
326
327         return 0;
328 }
329
330 void zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
331 {
332         struct Scsi_Host *shost;
333         struct zfcp_port *port;
334
335         shost = adapter->scsi_host;
336         if (!shost)
337                 return;
338
339         read_lock_irq(&adapter->port_list_lock);
340         list_for_each_entry(port, &adapter->port_list, list)
341                 port->rport = NULL;
342         read_unlock_irq(&adapter->port_list_lock);
343
344         fc_remove_host(shost);
345         scsi_remove_host(shost);
346         scsi_host_put(shost);
347         adapter->scsi_host = NULL;
348
349         return;
350 }
351
352 static struct fc_host_statistics*
353 zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
354 {
355         struct fc_host_statistics *fc_stats;
356
357         if (!adapter->fc_stats) {
358                 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
359                 if (!fc_stats)
360                         return NULL;
361                 adapter->fc_stats = fc_stats; /* freed in adapter_release */
362         }
363         memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
364         return adapter->fc_stats;
365 }
366
367 static void zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
368                                       struct fsf_qtcb_bottom_port *data,
369                                       struct fsf_qtcb_bottom_port *old)
370 {
371         fc_stats->seconds_since_last_reset =
372                 data->seconds_since_last_reset - old->seconds_since_last_reset;
373         fc_stats->tx_frames = data->tx_frames - old->tx_frames;
374         fc_stats->tx_words = data->tx_words - old->tx_words;
375         fc_stats->rx_frames = data->rx_frames - old->rx_frames;
376         fc_stats->rx_words = data->rx_words - old->rx_words;
377         fc_stats->lip_count = data->lip - old->lip;
378         fc_stats->nos_count = data->nos - old->nos;
379         fc_stats->error_frames = data->error_frames - old->error_frames;
380         fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
381         fc_stats->link_failure_count = data->link_failure - old->link_failure;
382         fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
383         fc_stats->loss_of_signal_count =
384                 data->loss_of_signal - old->loss_of_signal;
385         fc_stats->prim_seq_protocol_err_count =
386                 data->psp_error_counts - old->psp_error_counts;
387         fc_stats->invalid_tx_word_count =
388                 data->invalid_tx_words - old->invalid_tx_words;
389         fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
390         fc_stats->fcp_input_requests =
391                 data->input_requests - old->input_requests;
392         fc_stats->fcp_output_requests =
393                 data->output_requests - old->output_requests;
394         fc_stats->fcp_control_requests =
395                 data->control_requests - old->control_requests;
396         fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
397         fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
398 }
399
400 static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
401                                    struct fsf_qtcb_bottom_port *data)
402 {
403         fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
404         fc_stats->tx_frames = data->tx_frames;
405         fc_stats->tx_words = data->tx_words;
406         fc_stats->rx_frames = data->rx_frames;
407         fc_stats->rx_words = data->rx_words;
408         fc_stats->lip_count = data->lip;
409         fc_stats->nos_count = data->nos;
410         fc_stats->error_frames = data->error_frames;
411         fc_stats->dumped_frames = data->dumped_frames;
412         fc_stats->link_failure_count = data->link_failure;
413         fc_stats->loss_of_sync_count = data->loss_of_sync;
414         fc_stats->loss_of_signal_count = data->loss_of_signal;
415         fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
416         fc_stats->invalid_tx_word_count = data->invalid_tx_words;
417         fc_stats->invalid_crc_count = data->invalid_crcs;
418         fc_stats->fcp_input_requests = data->input_requests;
419         fc_stats->fcp_output_requests = data->output_requests;
420         fc_stats->fcp_control_requests = data->control_requests;
421         fc_stats->fcp_input_megabytes = data->input_mb;
422         fc_stats->fcp_output_megabytes = data->output_mb;
423 }
424
425 static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host)
426 {
427         struct zfcp_adapter *adapter;
428         struct fc_host_statistics *fc_stats;
429         struct fsf_qtcb_bottom_port *data;
430         int ret;
431
432         adapter = (struct zfcp_adapter *)host->hostdata[0];
433         fc_stats = zfcp_init_fc_host_stats(adapter);
434         if (!fc_stats)
435                 return NULL;
436
437         data = kzalloc(sizeof(*data), GFP_KERNEL);
438         if (!data)
439                 return NULL;
440
441         ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
442         if (ret) {
443                 kfree(data);
444                 return NULL;
445         }
446
447         if (adapter->stats_reset &&
448             ((jiffies/HZ - adapter->stats_reset) <
449              data->seconds_since_last_reset))
450                 zfcp_adjust_fc_host_stats(fc_stats, data,
451                                           adapter->stats_reset_data);
452         else
453                 zfcp_set_fc_host_stats(fc_stats, data);
454
455         kfree(data);
456         return fc_stats;
457 }
458
459 static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
460 {
461         struct zfcp_adapter *adapter;
462         struct fsf_qtcb_bottom_port *data;
463         int ret;
464
465         adapter = (struct zfcp_adapter *)shost->hostdata[0];
466         data = kzalloc(sizeof(*data), GFP_KERNEL);
467         if (!data)
468                 return;
469
470         ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
471         if (ret)
472                 kfree(data);
473         else {
474                 adapter->stats_reset = jiffies/HZ;
475                 kfree(adapter->stats_reset_data);
476                 adapter->stats_reset_data = data; /* finally freed in
477                                                      adapter_release */
478         }
479 }
480
481 static void zfcp_get_host_port_state(struct Scsi_Host *shost)
482 {
483         struct zfcp_adapter *adapter =
484                 (struct zfcp_adapter *)shost->hostdata[0];
485         int status = atomic_read(&adapter->status);
486
487         if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
488             !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED))
489                 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
490         else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
491                 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
492         else if (status & ZFCP_STATUS_COMMON_ERP_FAILED)
493                 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
494         else
495                 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
496 }
497
498 static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
499 {
500         rport->dev_loss_tmo = timeout;
501 }
502
503 /**
504  * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
505  * @rport: The FC rport where to teminate I/O
506  *
507  * Abort all pending SCSI commands for a port by closing the
508  * port. Using a reopen avoids a conflict with a shutdown
509  * overwriting a reopen. The "forced" ensures that a disappeared port
510  * is not opened again as valid due to the cached plogi data in
511  * non-NPIV mode.
512  */
513 static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
514 {
515         struct zfcp_port *port;
516         struct Scsi_Host *shost = rport_to_shost(rport);
517         struct zfcp_adapter *adapter =
518                 (struct zfcp_adapter *)shost->hostdata[0];
519
520         port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
521
522         if (port) {
523                 zfcp_erp_port_forced_reopen(port, 0, "sctrpi1", NULL);
524                 put_device(&port->dev);
525         }
526 }
527
528 static void zfcp_scsi_rport_register(struct zfcp_port *port)
529 {
530         struct fc_rport_identifiers ids;
531         struct fc_rport *rport;
532
533         if (port->rport)
534                 return;
535
536         ids.node_name = port->wwnn;
537         ids.port_name = port->wwpn;
538         ids.port_id = port->d_id;
539         ids.roles = FC_RPORT_ROLE_FCP_TARGET;
540
541         rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
542         if (!rport) {
543                 dev_err(&port->adapter->ccw_device->dev,
544                         "Registering port 0x%016Lx failed\n",
545                         (unsigned long long)port->wwpn);
546                 return;
547         }
548
549         rport->maxframe_size = port->maxframe_size;
550         rport->supported_classes = port->supported_classes;
551         port->rport = rport;
552         port->starget_id = rport->scsi_target_id;
553
554         zfcp_unit_queue_scsi_scan(port);
555 }
556
557 static void zfcp_scsi_rport_block(struct zfcp_port *port)
558 {
559         struct fc_rport *rport = port->rport;
560
561         if (rport) {
562                 fc_remote_port_delete(rport);
563                 port->rport = NULL;
564         }
565 }
566
567 void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
568 {
569         get_device(&port->dev);
570         port->rport_task = RPORT_ADD;
571
572         if (!queue_work(port->adapter->work_queue, &port->rport_work))
573                 put_device(&port->dev);
574 }
575
576 void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
577 {
578         get_device(&port->dev);
579         port->rport_task = RPORT_DEL;
580
581         if (port->rport && queue_work(port->adapter->work_queue,
582                                       &port->rport_work))
583                 return;
584
585         put_device(&port->dev);
586 }
587
588 void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
589 {
590         unsigned long flags;
591         struct zfcp_port *port;
592
593         read_lock_irqsave(&adapter->port_list_lock, flags);
594         list_for_each_entry(port, &adapter->port_list, list)
595                 zfcp_scsi_schedule_rport_block(port);
596         read_unlock_irqrestore(&adapter->port_list_lock, flags);
597 }
598
599 void zfcp_scsi_rport_work(struct work_struct *work)
600 {
601         struct zfcp_port *port = container_of(work, struct zfcp_port,
602                                               rport_work);
603
604         while (port->rport_task) {
605                 if (port->rport_task == RPORT_ADD) {
606                         port->rport_task = RPORT_NONE;
607                         zfcp_scsi_rport_register(port);
608                 } else {
609                         port->rport_task = RPORT_NONE;
610                         zfcp_scsi_rport_block(port);
611                 }
612         }
613
614         put_device(&port->dev);
615 }
616
617 /**
618  * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
619  * @adapter: The adapter where to configure DIF/DIX for the SCSI host
620  */
621 void zfcp_scsi_set_prot(struct zfcp_adapter *adapter)
622 {
623         unsigned int mask = 0;
624         unsigned int data_div;
625         struct Scsi_Host *shost = adapter->scsi_host;
626
627         data_div = atomic_read(&adapter->status) &
628                    ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED;
629
630         if (enable_dif &&
631             adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1)
632                 mask |= SHOST_DIF_TYPE1_PROTECTION;
633
634         if (enable_dif && data_div &&
635             adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) {
636                 mask |= SHOST_DIX_TYPE1_PROTECTION;
637                 scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP);
638                 shost->sg_tablesize = ZFCP_QDIO_MAX_SBALES_PER_REQ / 2;
639                 shost->max_sectors = ZFCP_QDIO_MAX_SBALES_PER_REQ * 8 / 2;
640         }
641
642         scsi_host_set_prot(shost, mask);
643 }
644
645 /**
646  * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
647  * @scmd: The SCSI command to report the error for
648  * @ascq: The ASCQ to put in the sense buffer
649  *
650  * See the error handling in sd_done for the sense codes used here.
651  * Set DID_SOFT_ERROR to retry the request, if possible.
652  */
653 void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq)
654 {
655         scsi_build_sense_buffer(1, scmd->sense_buffer,
656                                 ILLEGAL_REQUEST, 0x10, ascq);
657         set_driver_byte(scmd, DRIVER_SENSE);
658         scmd->result |= SAM_STAT_CHECK_CONDITION;
659         set_host_byte(scmd, DID_SOFT_ERROR);
660 }
661
662 struct fc_function_template zfcp_transport_functions = {
663         .show_starget_port_id = 1,
664         .show_starget_port_name = 1,
665         .show_starget_node_name = 1,
666         .show_rport_supported_classes = 1,
667         .show_rport_maxframe_size = 1,
668         .show_rport_dev_loss_tmo = 1,
669         .show_host_node_name = 1,
670         .show_host_port_name = 1,
671         .show_host_permanent_port_name = 1,
672         .show_host_supported_classes = 1,
673         .show_host_supported_fc4s = 1,
674         .show_host_supported_speeds = 1,
675         .show_host_maxframe_size = 1,
676         .show_host_serial_number = 1,
677         .get_fc_host_stats = zfcp_get_fc_host_stats,
678         .reset_fc_host_stats = zfcp_reset_fc_host_stats,
679         .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo,
680         .get_host_port_state = zfcp_get_host_port_state,
681         .terminate_rport_io = zfcp_scsi_terminate_rport_io,
682         .show_host_port_state = 1,
683         .show_host_active_fc4s = 1,
684         .bsg_request = zfcp_fc_exec_bsg_job,
685         .bsg_timeout = zfcp_fc_timeout_bsg_job,
686         /* no functions registered for following dynamic attributes but
687            directly set by LLDD */
688         .show_host_port_type = 1,
689         .show_host_speed = 1,
690         .show_host_port_id = 1,
691         .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
692 };
693
694 struct zfcp_data zfcp_data = {
695         .scsi_host_template = {
696                 .name                    = "zfcp",
697                 .module                  = THIS_MODULE,
698                 .proc_name               = "zfcp",
699                 .change_queue_depth      = zfcp_scsi_change_queue_depth,
700                 .slave_alloc             = zfcp_scsi_slave_alloc,
701                 .slave_configure         = zfcp_scsi_slave_configure,
702                 .slave_destroy           = zfcp_scsi_slave_destroy,
703                 .queuecommand            = zfcp_scsi_queuecommand,
704                 .eh_abort_handler        = zfcp_scsi_eh_abort_handler,
705                 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
706                 .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
707                 .eh_host_reset_handler   = zfcp_scsi_eh_host_reset_handler,
708                 .can_queue               = 4096,
709                 .this_id                 = -1,
710                 .sg_tablesize            = ZFCP_QDIO_MAX_SBALES_PER_REQ,
711                 .cmd_per_lun             = 1,
712                 .use_clustering          = 1,
713                 .sdev_attrs              = zfcp_sysfs_sdev_attrs,
714                 .max_sectors             = (ZFCP_QDIO_MAX_SBALES_PER_REQ * 8),
715                 .dma_boundary            = ZFCP_QDIO_SBALE_LEN - 1,
716                 .shost_attrs             = zfcp_sysfs_shost_attrs,
717         },
718 };