aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/scsi/zfcp_scsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/s390/scsi/zfcp_scsi.c')
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c156
1 files changed, 78 insertions, 78 deletions
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 0e1a34627a2e..771cc536a989 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -9,29 +9,33 @@
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include <linux/types.h>
13#include <scsi/fc/fc_fcp.h>
12#include <asm/atomic.h> 14#include <asm/atomic.h>
13#include "zfcp_ext.h" 15#include "zfcp_ext.h"
14#include "zfcp_dbf.h" 16#include "zfcp_dbf.h"
17#include "zfcp_fc.h"
15 18
16static unsigned int default_depth = 32; 19static unsigned int default_depth = 32;
17module_param_named(queue_depth, default_depth, uint, 0600); 20module_param_named(queue_depth, default_depth, uint, 0600);
18MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices"); 21MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices");
19 22
20/* Find start of Sense Information in FCP response unit*/ 23static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth,
21char *zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu) 24 int reason)
22{ 25{
23 char *fcp_sns_info_ptr; 26 switch (reason) {
24 27 case SCSI_QDEPTH_DEFAULT:
25 fcp_sns_info_ptr = (unsigned char *) &fcp_rsp_iu[1]; 28 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
26 if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid) 29 break;
27 fcp_sns_info_ptr += fcp_rsp_iu->fcp_rsp_len; 30 case SCSI_QDEPTH_QFULL:
28 31 scsi_track_queue_full(sdev, depth);
29 return fcp_sns_info_ptr; 32 break;
30} 33 case SCSI_QDEPTH_RAMP_UP:
31 34 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
32static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth) 35 break;
33{ 36 default:
34 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 37 return -EOPNOTSUPP;
38 }
35 return sdev->queue_depth; 39 return sdev->queue_depth;
36} 40}
37 41
@@ -39,7 +43,7 @@ static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
39{ 43{
40 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata; 44 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
41 unit->device = NULL; 45 unit->device = NULL;
42 zfcp_unit_put(unit); 46 put_device(&unit->sysfs_device);
43} 47}
44 48
45static int zfcp_scsi_slave_configure(struct scsi_device *sdp) 49static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
@@ -99,12 +103,26 @@ static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
99 } 103 }
100 104
101 status = atomic_read(&unit->status); 105 status = atomic_read(&unit->status);
102 if (unlikely((status & ZFCP_STATUS_COMMON_ERP_FAILED) || 106 if (unlikely(status & ZFCP_STATUS_COMMON_ERP_FAILED) &&
103 !(status & ZFCP_STATUS_COMMON_RUNNING))) { 107 !(atomic_read(&unit->port->status) &
108 ZFCP_STATUS_COMMON_ERP_FAILED)) {
109 /* only unit access denied, but port is good
110 * not covered by FC transport, have to fail here */
104 zfcp_scsi_command_fail(scpnt, DID_ERROR); 111 zfcp_scsi_command_fail(scpnt, DID_ERROR);
105 return 0; 112 return 0;
106 } 113 }
107 114
115 if (unlikely(!(status & ZFCP_STATUS_COMMON_UNBLOCKED))) {
116 /* This could be either
117 * open unit pending: this is temporary, will result in
118 * open unit or ERP_FAILED, so retry command
119 * call to rport_delete pending: mimic retry from
120 * fc_remote_port_chkready until rport is BLOCKED
121 */
122 zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY);
123 return 0;
124 }
125
108 ret = zfcp_fsf_send_fcp_command_task(unit, scpnt); 126 ret = zfcp_fsf_send_fcp_command_task(unit, scpnt);
109 if (unlikely(ret == -EBUSY)) 127 if (unlikely(ret == -EBUSY))
110 return SCSI_MLQUEUE_DEVICE_BUSY; 128 return SCSI_MLQUEUE_DEVICE_BUSY;
@@ -115,49 +133,44 @@ static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
115} 133}
116 134
117static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *adapter, 135static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *adapter,
118 int channel, unsigned int id, 136 unsigned int id, u64 lun)
119 unsigned int lun)
120{ 137{
138 unsigned long flags;
121 struct zfcp_port *port; 139 struct zfcp_port *port;
122 struct zfcp_unit *unit; 140 struct zfcp_unit *unit = NULL;
123 int scsi_lun;
124 141
125 list_for_each_entry(port, &adapter->port_list_head, list) { 142 read_lock_irqsave(&adapter->port_list_lock, flags);
143 list_for_each_entry(port, &adapter->port_list, list) {
126 if (!port->rport || (id != port->rport->scsi_target_id)) 144 if (!port->rport || (id != port->rport->scsi_target_id))
127 continue; 145 continue;
128 list_for_each_entry(unit, &port->unit_list_head, list) { 146 unit = zfcp_get_unit_by_lun(port, lun);
129 scsi_lun = scsilun_to_int( 147 if (unit)
130 (struct scsi_lun *)&unit->fcp_lun); 148 break;
131 if (lun == scsi_lun)
132 return unit;
133 }
134 } 149 }
150 read_unlock_irqrestore(&adapter->port_list_lock, flags);
135 151
136 return NULL; 152 return unit;
137} 153}
138 154
139static int zfcp_scsi_slave_alloc(struct scsi_device *sdp) 155static int zfcp_scsi_slave_alloc(struct scsi_device *sdp)
140{ 156{
141 struct zfcp_adapter *adapter; 157 struct zfcp_adapter *adapter;
142 struct zfcp_unit *unit; 158 struct zfcp_unit *unit;
143 unsigned long flags; 159 u64 lun;
144 int retval = -ENXIO;
145 160
146 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0]; 161 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
147 if (!adapter) 162 if (!adapter)
148 goto out; 163 goto out;
149 164
150 read_lock_irqsave(&zfcp_data.config_lock, flags); 165 int_to_scsilun(sdp->lun, (struct scsi_lun *)&lun);
151 unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun); 166 unit = zfcp_unit_lookup(adapter, sdp->id, lun);
152 if (unit) { 167 if (unit) {
153 sdp->hostdata = unit; 168 sdp->hostdata = unit;
154 unit->device = sdp; 169 unit->device = sdp;
155 zfcp_unit_get(unit); 170 return 0;
156 retval = 0;
157 } 171 }
158 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
159out: 172out:
160 return retval; 173 return -ENXIO;
161} 174}
162 175
163static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) 176static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
@@ -196,6 +209,7 @@ static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
196 break; 209 break;
197 210
198 zfcp_erp_wait(adapter); 211 zfcp_erp_wait(adapter);
212 fc_block_scsi_eh(scpnt);
199 if (!(atomic_read(&adapter->status) & 213 if (!(atomic_read(&adapter->status) &
200 ZFCP_STATUS_COMMON_RUNNING)) { 214 ZFCP_STATUS_COMMON_RUNNING)) {
201 zfcp_dbf_scsi_abort("nres", adapter->dbf, scpnt, NULL, 215 zfcp_dbf_scsi_abort("nres", adapter->dbf, scpnt, NULL,
@@ -235,6 +249,7 @@ static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
235 break; 249 break;
236 250
237 zfcp_erp_wait(adapter); 251 zfcp_erp_wait(adapter);
252 fc_block_scsi_eh(scpnt);
238 if (!(atomic_read(&adapter->status) & 253 if (!(atomic_read(&adapter->status) &
239 ZFCP_STATUS_COMMON_RUNNING)) { 254 ZFCP_STATUS_COMMON_RUNNING)) {
240 zfcp_dbf_scsi_devreset("nres", tm_flags, unit, scpnt); 255 zfcp_dbf_scsi_devreset("nres", tm_flags, unit, scpnt);
@@ -249,9 +264,6 @@ static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
249 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) { 264 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
250 zfcp_dbf_scsi_devreset("fail", tm_flags, unit, scpnt); 265 zfcp_dbf_scsi_devreset("fail", tm_flags, unit, scpnt);
251 retval = FAILED; 266 retval = FAILED;
252 } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP) {
253 zfcp_dbf_scsi_devreset("nsup", tm_flags, unit, scpnt);
254 retval = FAILED;
255 } else 267 } else
256 zfcp_dbf_scsi_devreset("okay", tm_flags, unit, scpnt); 268 zfcp_dbf_scsi_devreset("okay", tm_flags, unit, scpnt);
257 269
@@ -261,12 +273,12 @@ static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
261 273
262static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt) 274static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
263{ 275{
264 return zfcp_task_mgmt_function(scpnt, FCP_LOGICAL_UNIT_RESET); 276 return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET);
265} 277}
266 278
267static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt) 279static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
268{ 280{
269 return zfcp_task_mgmt_function(scpnt, FCP_TARGET_RESET); 281 return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET);
270} 282}
271 283
272static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) 284static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
@@ -276,6 +288,7 @@ static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
276 288
277 zfcp_erp_adapter_reopen(adapter, 0, "schrh_1", scpnt); 289 zfcp_erp_adapter_reopen(adapter, 0, "schrh_1", scpnt);
278 zfcp_erp_wait(adapter); 290 zfcp_erp_wait(adapter);
291 fc_block_scsi_eh(scpnt);
279 292
280 return SUCCESS; 293 return SUCCESS;
281} 294}
@@ -303,7 +316,7 @@ int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
303 adapter->scsi_host->max_lun = 1; 316 adapter->scsi_host->max_lun = 1;
304 adapter->scsi_host->max_channel = 0; 317 adapter->scsi_host->max_channel = 0;
305 adapter->scsi_host->unique_id = dev_id.devno; 318 adapter->scsi_host->unique_id = dev_id.devno;
306 adapter->scsi_host->max_cmd_len = 255; 319 adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
307 adapter->scsi_host->transportt = zfcp_data.scsi_transport_template; 320 adapter->scsi_host->transportt = zfcp_data.scsi_transport_template;
308 321
309 adapter->scsi_host->hostdata[0] = (unsigned long) adapter; 322 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
@@ -325,12 +338,11 @@ void zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
325 if (!shost) 338 if (!shost)
326 return; 339 return;
327 340
328 read_lock_irq(&zfcp_data.config_lock); 341 read_lock_irq(&adapter->port_list_lock);
329 list_for_each_entry(port, &adapter->port_list_head, list) 342 list_for_each_entry(port, &adapter->port_list, list)
330 if (port->rport) 343 port->rport = NULL;
331 port->rport = NULL; 344 read_unlock_irq(&adapter->port_list_lock);
332 345
333 read_unlock_irq(&zfcp_data.config_lock);
334 fc_remove_host(shost); 346 fc_remove_host(shost);
335 scsi_remove_host(shost); 347 scsi_remove_host(shost);
336 scsi_host_put(shost); 348 scsi_host_put(shost);
@@ -348,7 +360,7 @@ zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
348 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL); 360 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
349 if (!fc_stats) 361 if (!fc_stats)
350 return NULL; 362 return NULL;
351 adapter->fc_stats = fc_stats; /* freed in adater_dequeue */ 363 adapter->fc_stats = fc_stats; /* freed in adapter_release */
352 } 364 }
353 memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats)); 365 memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
354 return adapter->fc_stats; 366 return adapter->fc_stats;
@@ -464,7 +476,7 @@ static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
464 adapter->stats_reset = jiffies/HZ; 476 adapter->stats_reset = jiffies/HZ;
465 kfree(adapter->stats_reset_data); 477 kfree(adapter->stats_reset_data);
466 adapter->stats_reset_data = data; /* finally freed in 478 adapter->stats_reset_data = data; /* finally freed in
467 adapter_dequeue */ 479 adapter_release */
468 } 480 }
469} 481}
470 482
@@ -495,7 +507,7 @@ static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
495 * @rport: The FC rport where to teminate I/O 507 * @rport: The FC rport where to teminate I/O
496 * 508 *
497 * Abort all pending SCSI commands for a port by closing the 509 * Abort all pending SCSI commands for a port by closing the
498 * port. Using a reopen for avoids a conflict with a shutdown 510 * port. Using a reopen avoiding a conflict with a shutdown
499 * overwriting a reopen. 511 * overwriting a reopen.
500 */ 512 */
501static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport) 513static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
@@ -505,15 +517,11 @@ static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
505 struct zfcp_adapter *adapter = 517 struct zfcp_adapter *adapter =
506 (struct zfcp_adapter *)shost->hostdata[0]; 518 (struct zfcp_adapter *)shost->hostdata[0];
507 519
508 write_lock_irq(&zfcp_data.config_lock);
509 port = zfcp_get_port_by_wwpn(adapter, rport->port_name); 520 port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
510 if (port)
511 zfcp_port_get(port);
512 write_unlock_irq(&zfcp_data.config_lock);
513 521
514 if (port) { 522 if (port) {
515 zfcp_erp_port_reopen(port, 0, "sctrpi1", NULL); 523 zfcp_erp_port_reopen(port, 0, "sctrpi1", NULL);
516 zfcp_port_put(port); 524 put_device(&port->sysfs_device);
517 } 525 }
518} 526}
519 527
@@ -555,31 +563,34 @@ static void zfcp_scsi_rport_block(struct zfcp_port *port)
555 563
556void zfcp_scsi_schedule_rport_register(struct zfcp_port *port) 564void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
557{ 565{
558 zfcp_port_get(port); 566 get_device(&port->sysfs_device);
559 port->rport_task = RPORT_ADD; 567 port->rport_task = RPORT_ADD;
560 568
561 if (!queue_work(port->adapter->work_queue, &port->rport_work)) 569 if (!queue_work(port->adapter->work_queue, &port->rport_work))
562 zfcp_port_put(port); 570 put_device(&port->sysfs_device);
563} 571}
564 572
565void zfcp_scsi_schedule_rport_block(struct zfcp_port *port) 573void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
566{ 574{
567 zfcp_port_get(port); 575 get_device(&port->sysfs_device);
568 port->rport_task = RPORT_DEL; 576 port->rport_task = RPORT_DEL;
569 577
570 if (port->rport && queue_work(port->adapter->work_queue, 578 if (port->rport && queue_work(port->adapter->work_queue,
571 &port->rport_work)) 579 &port->rport_work))
572 return; 580 return;
573 581
574 zfcp_port_put(port); 582 put_device(&port->sysfs_device);
575} 583}
576 584
577void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter) 585void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
578{ 586{
587 unsigned long flags;
579 struct zfcp_port *port; 588 struct zfcp_port *port;
580 589
581 list_for_each_entry(port, &adapter->port_list_head, list) 590 read_lock_irqsave(&adapter->port_list_lock, flags);
591 list_for_each_entry(port, &adapter->port_list, list)
582 zfcp_scsi_schedule_rport_block(port); 592 zfcp_scsi_schedule_rport_block(port);
593 read_unlock_irqrestore(&adapter->port_list_lock, flags);
583} 594}
584 595
585void zfcp_scsi_rport_work(struct work_struct *work) 596void zfcp_scsi_rport_work(struct work_struct *work)
@@ -597,7 +608,7 @@ void zfcp_scsi_rport_work(struct work_struct *work)
597 } 608 }
598 } 609 }
599 610
600 zfcp_port_put(port); 611 put_device(&port->sysfs_device);
601} 612}
602 613
603 614
@@ -615,21 +626,7 @@ void zfcp_scsi_scan(struct work_struct *work)
615 scsilun_to_int((struct scsi_lun *) 626 scsilun_to_int((struct scsi_lun *)
616 &unit->fcp_lun), 0); 627 &unit->fcp_lun), 0);
617 628
618 zfcp_unit_put(unit); 629 put_device(&unit->sysfs_device);
619}
620
621static int zfcp_execute_fc_job(struct fc_bsg_job *job)
622{
623 switch (job->request->msgcode) {
624 case FC_BSG_RPT_ELS:
625 case FC_BSG_HST_ELS_NOLOGIN:
626 return zfcp_fc_execute_els_fc_job(job);
627 case FC_BSG_RPT_CT:
628 case FC_BSG_HST_CT:
629 return zfcp_fc_execute_ct_fc_job(job);
630 default:
631 return -EINVAL;
632 }
633} 630}
634 631
635struct fc_function_template zfcp_transport_functions = { 632struct fc_function_template zfcp_transport_functions = {
@@ -643,6 +640,7 @@ struct fc_function_template zfcp_transport_functions = {
643 .show_host_port_name = 1, 640 .show_host_port_name = 1,
644 .show_host_permanent_port_name = 1, 641 .show_host_permanent_port_name = 1,
645 .show_host_supported_classes = 1, 642 .show_host_supported_classes = 1,
643 .show_host_supported_fc4s = 1,
646 .show_host_supported_speeds = 1, 644 .show_host_supported_speeds = 1,
647 .show_host_maxframe_size = 1, 645 .show_host_maxframe_size = 1,
648 .show_host_serial_number = 1, 646 .show_host_serial_number = 1,
@@ -652,13 +650,15 @@ struct fc_function_template zfcp_transport_functions = {
652 .get_host_port_state = zfcp_get_host_port_state, 650 .get_host_port_state = zfcp_get_host_port_state,
653 .terminate_rport_io = zfcp_scsi_terminate_rport_io, 651 .terminate_rport_io = zfcp_scsi_terminate_rport_io,
654 .show_host_port_state = 1, 652 .show_host_port_state = 1,
655 .bsg_request = zfcp_execute_fc_job, 653 .show_host_active_fc4s = 1,
654 .bsg_request = zfcp_fc_exec_bsg_job,
656 /* no functions registered for following dynamic attributes but 655 /* no functions registered for following dynamic attributes but
657 directly set by LLDD */ 656 directly set by LLDD */
658 .show_host_port_type = 1, 657 .show_host_port_type = 1,
659 .show_host_speed = 1, 658 .show_host_speed = 1,
660 .show_host_port_id = 1, 659 .show_host_port_id = 1,
661 .disable_target_scan = 1, 660 .disable_target_scan = 1,
661 .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
662}; 662};
663 663
664struct zfcp_data zfcp_data = { 664struct zfcp_data zfcp_data = {