aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-12-09 22:42:25 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-09 22:42:25 -0500
commit382f51fe2f2276344d8a21447656778cdf6583b6 (patch)
treec2836a2cca4126c9c026ce5aa2fdf9f1c8ccded6 /drivers/s390
parent701791cc3c8fc6dd83f6ec8af7e2541b4a316606 (diff)
parent54987386ee3790f3900de4df2ed4deb0e18dfc9f (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6: (222 commits) [SCSI] zfcp: Remove flag ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP [SCSI] zfcp: Activate fc4s attributes for zfcp in FC transport class [SCSI] zfcp: Block scsi_eh thread for rport state BLOCKED [SCSI] zfcp: Update FSF error reporting [SCSI] zfcp: Improve ELS ADISC handling [SCSI] zfcp: Simplify handling of ct and els requests [SCSI] zfcp: Remove ZFCP_DID_MASK [SCSI] zfcp: Move WKA port to zfcp FC code [SCSI] zfcp: Use common code definitions for FC CT structs [SCSI] zfcp: Use common code definitions for FC ELS structs [SCSI] zfcp: Update FCP protocol related code [SCSI] zfcp: Dont fail SCSI commands when transitioning to blocked fc_rport [SCSI] zfcp: Assign scheduled work to driver queue [SCSI] zfcp: Remove STATUS_COMMON_REMOVE flag as it is not required anymore [SCSI] zfcp: Implement module unloading [SCSI] zfcp: Merge trace code for fsf requests in one function [SCSI] zfcp: Access ports and units with container_of in sysfs code [SCSI] zfcp: Remove suspend callback [SCSI] zfcp: Remove global config_mutex [SCSI] zfcp: Replace local reference counting with common kref ...
Diffstat (limited to 'drivers/s390')
-rw-r--r--drivers/s390/scsi/zfcp_aux.c388
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c179
-rw-r--r--drivers/s390/scsi/zfcp_cfdc.c26
-rw-r--r--drivers/s390/scsi/zfcp_dbf.c134
-rw-r--r--drivers/s390/scsi/zfcp_dbf.h10
-rw-r--r--drivers/s390/scsi/zfcp_def.h323
-rw-r--r--drivers/s390/scsi/zfcp_erp.c138
-rw-r--r--drivers/s390/scsi/zfcp_ext.h38
-rw-r--r--drivers/s390/scsi/zfcp_fc.c677
-rw-r--r--drivers/s390/scsi/zfcp_fc.h260
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c367
-rw-r--r--drivers/s390/scsi/zfcp_fsf.h53
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c156
-rw-r--r--drivers/s390/scsi/zfcp_sysfs.c250
14 files changed, 1388 insertions, 1611 deletions
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 2889e5f2dfd3..9d0c941b7d33 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -31,6 +31,7 @@
31#include <linux/miscdevice.h> 31#include <linux/miscdevice.h>
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include "zfcp_ext.h" 33#include "zfcp_ext.h"
34#include "zfcp_fc.h"
34 35
35#define ZFCP_BUS_ID_SIZE 20 36#define ZFCP_BUS_ID_SIZE 20
36 37
@@ -80,48 +81,40 @@ int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
80 81
81static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun) 82static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun)
82{ 83{
83 struct ccw_device *ccwdev; 84 struct ccw_device *cdev;
84 struct zfcp_adapter *adapter; 85 struct zfcp_adapter *adapter;
85 struct zfcp_port *port; 86 struct zfcp_port *port;
86 struct zfcp_unit *unit; 87 struct zfcp_unit *unit;
87 88
88 ccwdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid); 89 cdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
89 if (!ccwdev) 90 if (!cdev)
90 return; 91 return;
91 92
92 if (ccw_device_set_online(ccwdev)) 93 if (ccw_device_set_online(cdev))
93 goto out_ccwdev; 94 goto out_ccw_device;
94 95
95 mutex_lock(&zfcp_data.config_mutex); 96 adapter = zfcp_ccw_adapter_by_cdev(cdev);
96 adapter = dev_get_drvdata(&ccwdev->dev);
97 if (!adapter) 97 if (!adapter)
98 goto out_unlock; 98 goto out_ccw_device;
99 zfcp_adapter_get(adapter);
100 99
101 port = zfcp_get_port_by_wwpn(adapter, wwpn); 100 port = zfcp_get_port_by_wwpn(adapter, wwpn);
102 if (!port) 101 if (!port)
103 goto out_port; 102 goto out_port;
104 103
105 zfcp_port_get(port);
106 unit = zfcp_unit_enqueue(port, lun); 104 unit = zfcp_unit_enqueue(port, lun);
107 if (IS_ERR(unit)) 105 if (IS_ERR(unit))
108 goto out_unit; 106 goto out_unit;
109 mutex_unlock(&zfcp_data.config_mutex);
110 107
111 zfcp_erp_unit_reopen(unit, 0, "auidc_1", NULL); 108 zfcp_erp_unit_reopen(unit, 0, "auidc_1", NULL);
112 zfcp_erp_wait(adapter); 109 zfcp_erp_wait(adapter);
113 flush_work(&unit->scsi_work); 110 flush_work(&unit->scsi_work);
114 111
115 mutex_lock(&zfcp_data.config_mutex);
116 zfcp_unit_put(unit);
117out_unit: 112out_unit:
118 zfcp_port_put(port); 113 put_device(&port->sysfs_device);
119out_port: 114out_port:
120 zfcp_adapter_put(adapter); 115 zfcp_ccw_adapter_put(adapter);
121out_unlock: 116out_ccw_device:
122 mutex_unlock(&zfcp_data.config_mutex); 117 put_device(&cdev->dev);
123out_ccwdev:
124 put_device(&ccwdev->dev);
125 return; 118 return;
126} 119}
127 120
@@ -167,7 +160,7 @@ static int __init zfcp_module_init(void)
167 int retval = -ENOMEM; 160 int retval = -ENOMEM;
168 161
169 zfcp_data.gpn_ft_cache = zfcp_cache_hw_align("zfcp_gpn", 162 zfcp_data.gpn_ft_cache = zfcp_cache_hw_align("zfcp_gpn",
170 sizeof(struct ct_iu_gpn_ft_req)); 163 sizeof(struct zfcp_fc_gpn_ft_req));
171 if (!zfcp_data.gpn_ft_cache) 164 if (!zfcp_data.gpn_ft_cache)
172 goto out; 165 goto out;
173 166
@@ -182,12 +175,14 @@ static int __init zfcp_module_init(void)
182 goto out_sr_cache; 175 goto out_sr_cache;
183 176
184 zfcp_data.gid_pn_cache = zfcp_cache_hw_align("zfcp_gid", 177 zfcp_data.gid_pn_cache = zfcp_cache_hw_align("zfcp_gid",
185 sizeof(struct zfcp_gid_pn_data)); 178 sizeof(struct zfcp_fc_gid_pn));
186 if (!zfcp_data.gid_pn_cache) 179 if (!zfcp_data.gid_pn_cache)
187 goto out_gid_cache; 180 goto out_gid_cache;
188 181
189 mutex_init(&zfcp_data.config_mutex); 182 zfcp_data.adisc_cache = zfcp_cache_hw_align("zfcp_adisc",
190 rwlock_init(&zfcp_data.config_lock); 183 sizeof(struct zfcp_fc_els_adisc));
184 if (!zfcp_data.adisc_cache)
185 goto out_adisc_cache;
191 186
192 zfcp_data.scsi_transport_template = 187 zfcp_data.scsi_transport_template =
193 fc_attach_transport(&zfcp_transport_functions); 188 fc_attach_transport(&zfcp_transport_functions);
@@ -200,7 +195,7 @@ static int __init zfcp_module_init(void)
200 goto out_misc; 195 goto out_misc;
201 } 196 }
202 197
203 retval = zfcp_ccw_register(); 198 retval = ccw_driver_register(&zfcp_ccw_driver);
204 if (retval) { 199 if (retval) {
205 pr_err("The zfcp device driver could not register with " 200 pr_err("The zfcp device driver could not register with "
206 "the common I/O layer\n"); 201 "the common I/O layer\n");
@@ -216,6 +211,8 @@ out_ccw_register:
216out_misc: 211out_misc:
217 fc_release_transport(zfcp_data.scsi_transport_template); 212 fc_release_transport(zfcp_data.scsi_transport_template);
218out_transport: 213out_transport:
214 kmem_cache_destroy(zfcp_data.adisc_cache);
215out_adisc_cache:
219 kmem_cache_destroy(zfcp_data.gid_pn_cache); 216 kmem_cache_destroy(zfcp_data.gid_pn_cache);
220out_gid_cache: 217out_gid_cache:
221 kmem_cache_destroy(zfcp_data.sr_buffer_cache); 218 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
@@ -229,6 +226,20 @@ out:
229 226
230module_init(zfcp_module_init); 227module_init(zfcp_module_init);
231 228
229static void __exit zfcp_module_exit(void)
230{
231 ccw_driver_unregister(&zfcp_ccw_driver);
232 misc_deregister(&zfcp_cfdc_misc);
233 fc_release_transport(zfcp_data.scsi_transport_template);
234 kmem_cache_destroy(zfcp_data.adisc_cache);
235 kmem_cache_destroy(zfcp_data.gid_pn_cache);
236 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
237 kmem_cache_destroy(zfcp_data.qtcb_cache);
238 kmem_cache_destroy(zfcp_data.gpn_ft_cache);
239}
240
241module_exit(zfcp_module_exit);
242
232/** 243/**
233 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN 244 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
234 * @port: pointer to port to search for unit 245 * @port: pointer to port to search for unit
@@ -238,12 +249,18 @@ module_init(zfcp_module_init);
238 */ 249 */
239struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *port, u64 fcp_lun) 250struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *port, u64 fcp_lun)
240{ 251{
252 unsigned long flags;
241 struct zfcp_unit *unit; 253 struct zfcp_unit *unit;
242 254
243 list_for_each_entry(unit, &port->unit_list_head, list) 255 read_lock_irqsave(&port->unit_list_lock, flags);
244 if ((unit->fcp_lun == fcp_lun) && 256 list_for_each_entry(unit, &port->unit_list, list)
245 !(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_REMOVE)) 257 if (unit->fcp_lun == fcp_lun) {
246 return unit; 258 if (!get_device(&unit->sysfs_device))
259 unit = NULL;
260 read_unlock_irqrestore(&port->unit_list_lock, flags);
261 return unit;
262 }
263 read_unlock_irqrestore(&port->unit_list_lock, flags);
247 return NULL; 264 return NULL;
248} 265}
249 266
@@ -257,18 +274,35 @@ struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *port, u64 fcp_lun)
257struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, 274struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
258 u64 wwpn) 275 u64 wwpn)
259{ 276{
277 unsigned long flags;
260 struct zfcp_port *port; 278 struct zfcp_port *port;
261 279
262 list_for_each_entry(port, &adapter->port_list_head, list) 280 read_lock_irqsave(&adapter->port_list_lock, flags);
263 if ((port->wwpn == wwpn) && 281 list_for_each_entry(port, &adapter->port_list, list)
264 !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE)) 282 if (port->wwpn == wwpn) {
283 if (!get_device(&port->sysfs_device))
284 port = NULL;
285 read_unlock_irqrestore(&adapter->port_list_lock, flags);
265 return port; 286 return port;
287 }
288 read_unlock_irqrestore(&adapter->port_list_lock, flags);
266 return NULL; 289 return NULL;
267} 290}
268 291
269static void zfcp_sysfs_unit_release(struct device *dev) 292/**
293 * zfcp_unit_release - dequeue unit
294 * @dev: pointer to device
295 *
296 * waits until all work is done on unit and removes it then from the unit->list
297 * of the associated port.
298 */
299static void zfcp_unit_release(struct device *dev)
270{ 300{
271 kfree(container_of(dev, struct zfcp_unit, sysfs_device)); 301 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit,
302 sysfs_device);
303
304 put_device(&unit->port->sysfs_device);
305 kfree(unit);
272} 306}
273 307
274/** 308/**
@@ -276,43 +310,40 @@ static void zfcp_sysfs_unit_release(struct device *dev)
276 * @port: pointer to port where unit is added 310 * @port: pointer to port where unit is added
277 * @fcp_lun: FCP LUN of unit to be enqueued 311 * @fcp_lun: FCP LUN of unit to be enqueued
278 * Returns: pointer to enqueued unit on success, ERR_PTR on error 312 * Returns: pointer to enqueued unit on success, ERR_PTR on error
279 * Locks: config_mutex must be held to serialize changes to the unit list
280 * 313 *
281 * Sets up some unit internal structures and creates sysfs entry. 314 * Sets up some unit internal structures and creates sysfs entry.
282 */ 315 */
283struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun) 316struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun)
284{ 317{
285 struct zfcp_unit *unit; 318 struct zfcp_unit *unit;
319 int retval = -ENOMEM;
286 320
287 read_lock_irq(&zfcp_data.config_lock); 321 get_device(&port->sysfs_device);
288 if (zfcp_get_unit_by_lun(port, fcp_lun)) { 322
289 read_unlock_irq(&zfcp_data.config_lock); 323 unit = zfcp_get_unit_by_lun(port, fcp_lun);
290 return ERR_PTR(-EINVAL); 324 if (unit) {
325 put_device(&unit->sysfs_device);
326 retval = -EEXIST;
327 goto err_out;
291 } 328 }
292 read_unlock_irq(&zfcp_data.config_lock);
293 329
294 unit = kzalloc(sizeof(struct zfcp_unit), GFP_KERNEL); 330 unit = kzalloc(sizeof(struct zfcp_unit), GFP_KERNEL);
295 if (!unit) 331 if (!unit)
296 return ERR_PTR(-ENOMEM); 332 goto err_out;
297
298 atomic_set(&unit->refcount, 0);
299 init_waitqueue_head(&unit->remove_wq);
300 INIT_WORK(&unit->scsi_work, zfcp_scsi_scan);
301 333
302 unit->port = port; 334 unit->port = port;
303 unit->fcp_lun = fcp_lun; 335 unit->fcp_lun = fcp_lun;
336 unit->sysfs_device.parent = &port->sysfs_device;
337 unit->sysfs_device.release = zfcp_unit_release;
304 338
305 if (dev_set_name(&unit->sysfs_device, "0x%016llx", 339 if (dev_set_name(&unit->sysfs_device, "0x%016llx",
306 (unsigned long long) fcp_lun)) { 340 (unsigned long long) fcp_lun)) {
307 kfree(unit); 341 kfree(unit);
308 return ERR_PTR(-ENOMEM); 342 goto err_out;
309 } 343 }
310 unit->sysfs_device.parent = &port->sysfs_device; 344 retval = -EINVAL;
311 unit->sysfs_device.release = zfcp_sysfs_unit_release;
312 dev_set_drvdata(&unit->sysfs_device, unit);
313 345
314 /* mark unit unusable as long as sysfs registration is not complete */ 346 INIT_WORK(&unit->scsi_work, zfcp_scsi_scan);
315 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
316 347
317 spin_lock_init(&unit->latencies.lock); 348 spin_lock_init(&unit->latencies.lock);
318 unit->latencies.write.channel.min = 0xFFFFFFFF; 349 unit->latencies.write.channel.min = 0xFFFFFFFF;
@@ -324,50 +355,30 @@ struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun)
324 355
325 if (device_register(&unit->sysfs_device)) { 356 if (device_register(&unit->sysfs_device)) {
326 put_device(&unit->sysfs_device); 357 put_device(&unit->sysfs_device);
327 return ERR_PTR(-EINVAL); 358 goto err_out;
328 } 359 }
329 360
330 if (sysfs_create_group(&unit->sysfs_device.kobj, 361 if (sysfs_create_group(&unit->sysfs_device.kobj,
331 &zfcp_sysfs_unit_attrs)) { 362 &zfcp_sysfs_unit_attrs))
332 device_unregister(&unit->sysfs_device); 363 goto err_out_put;
333 return ERR_PTR(-EINVAL);
334 }
335 364
336 zfcp_unit_get(unit); 365 write_lock_irq(&port->unit_list_lock);
366 list_add_tail(&unit->list, &port->unit_list);
367 write_unlock_irq(&port->unit_list_lock);
337 368
338 write_lock_irq(&zfcp_data.config_lock);
339 list_add_tail(&unit->list, &port->unit_list_head);
340 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
341 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status); 369 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
342 370
343 write_unlock_irq(&zfcp_data.config_lock);
344
345 zfcp_port_get(port);
346
347 return unit; 371 return unit;
348}
349 372
350/** 373err_out_put:
351 * zfcp_unit_dequeue - dequeue unit
352 * @unit: pointer to zfcp_unit
353 *
354 * waits until all work is done on unit and removes it then from the unit->list
355 * of the associated port.
356 */
357void zfcp_unit_dequeue(struct zfcp_unit *unit)
358{
359 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
360 write_lock_irq(&zfcp_data.config_lock);
361 list_del(&unit->list);
362 write_unlock_irq(&zfcp_data.config_lock);
363 zfcp_port_put(unit->port);
364 sysfs_remove_group(&unit->sysfs_device.kobj, &zfcp_sysfs_unit_attrs);
365 device_unregister(&unit->sysfs_device); 374 device_unregister(&unit->sysfs_device);
375err_out:
376 put_device(&port->sysfs_device);
377 return ERR_PTR(retval);
366} 378}
367 379
368static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter) 380static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
369{ 381{
370 /* must only be called with zfcp_data.config_mutex taken */
371 adapter->pool.erp_req = 382 adapter->pool.erp_req =
372 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); 383 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
373 if (!adapter->pool.erp_req) 384 if (!adapter->pool.erp_req)
@@ -405,9 +416,9 @@ static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
405 if (!adapter->pool.status_read_data) 416 if (!adapter->pool.status_read_data)
406 return -ENOMEM; 417 return -ENOMEM;
407 418
408 adapter->pool.gid_pn_data = 419 adapter->pool.gid_pn =
409 mempool_create_slab_pool(1, zfcp_data.gid_pn_cache); 420 mempool_create_slab_pool(1, zfcp_data.gid_pn_cache);
410 if (!adapter->pool.gid_pn_data) 421 if (!adapter->pool.gid_pn)
411 return -ENOMEM; 422 return -ENOMEM;
412 423
413 return 0; 424 return 0;
@@ -415,7 +426,6 @@ static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
415 426
416static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter) 427static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
417{ 428{
418 /* zfcp_data.config_mutex must be held */
419 if (adapter->pool.erp_req) 429 if (adapter->pool.erp_req)
420 mempool_destroy(adapter->pool.erp_req); 430 mempool_destroy(adapter->pool.erp_req);
421 if (adapter->pool.scsi_req) 431 if (adapter->pool.scsi_req)
@@ -428,8 +438,8 @@ static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
428 mempool_destroy(adapter->pool.status_read_req); 438 mempool_destroy(adapter->pool.status_read_req);
429 if (adapter->pool.status_read_data) 439 if (adapter->pool.status_read_data)
430 mempool_destroy(adapter->pool.status_read_data); 440 mempool_destroy(adapter->pool.status_read_data);
431 if (adapter->pool.gid_pn_data) 441 if (adapter->pool.gid_pn)
432 mempool_destroy(adapter->pool.gid_pn_data); 442 mempool_destroy(adapter->pool.gid_pn);
433} 443}
434 444
435/** 445/**
@@ -497,53 +507,56 @@ static void zfcp_destroy_adapter_work_queue(struct zfcp_adapter *adapter)
497 * zfcp_adapter_enqueue - enqueue a new adapter to the list 507 * zfcp_adapter_enqueue - enqueue a new adapter to the list
498 * @ccw_device: pointer to the struct cc_device 508 * @ccw_device: pointer to the struct cc_device
499 * 509 *
500 * Returns: 0 if a new adapter was successfully enqueued 510 * Returns: struct zfcp_adapter*
501 * -ENOMEM if alloc failed
502 * Enqueues an adapter at the end of the adapter list in the driver data. 511 * Enqueues an adapter at the end of the adapter list in the driver data.
503 * All adapter internal structures are set up. 512 * All adapter internal structures are set up.
504 * Proc-fs entries are also created. 513 * Proc-fs entries are also created.
505 * locks: config_mutex must be held to serialize changes to the adapter list
506 */ 514 */
507int zfcp_adapter_enqueue(struct ccw_device *ccw_device) 515struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
508{ 516{
509 struct zfcp_adapter *adapter; 517 struct zfcp_adapter *adapter;
510 518
511 /* 519 if (!get_device(&ccw_device->dev))
512 * Note: It is safe to release the list_lock, as any list changes 520 return ERR_PTR(-ENODEV);
513 * are protected by the config_mutex, which must be held to get here
514 */
515 521
516 adapter = kzalloc(sizeof(struct zfcp_adapter), GFP_KERNEL); 522 adapter = kzalloc(sizeof(struct zfcp_adapter), GFP_KERNEL);
517 if (!adapter) 523 if (!adapter) {
518 return -ENOMEM; 524 put_device(&ccw_device->dev);
525 return ERR_PTR(-ENOMEM);
526 }
527
528 kref_init(&adapter->ref);
519 529
520 ccw_device->handler = NULL; 530 ccw_device->handler = NULL;
521 adapter->ccw_device = ccw_device; 531 adapter->ccw_device = ccw_device;
522 atomic_set(&adapter->refcount, 0); 532
533 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
534 INIT_WORK(&adapter->scan_work, zfcp_fc_scan_ports);
523 535
524 if (zfcp_qdio_setup(adapter)) 536 if (zfcp_qdio_setup(adapter))
525 goto qdio_failed; 537 goto failed;
526 538
527 if (zfcp_allocate_low_mem_buffers(adapter)) 539 if (zfcp_allocate_low_mem_buffers(adapter))
528 goto low_mem_buffers_failed; 540 goto failed;
529 541
530 if (zfcp_reqlist_alloc(adapter)) 542 if (zfcp_reqlist_alloc(adapter))
531 goto low_mem_buffers_failed; 543 goto failed;
532 544
533 if (zfcp_dbf_adapter_register(adapter)) 545 if (zfcp_dbf_adapter_register(adapter))
534 goto debug_register_failed; 546 goto failed;
535 547
536 if (zfcp_setup_adapter_work_queue(adapter)) 548 if (zfcp_setup_adapter_work_queue(adapter))
537 goto work_queue_failed; 549 goto failed;
538 550
539 if (zfcp_fc_gs_setup(adapter)) 551 if (zfcp_fc_gs_setup(adapter))
540 goto generic_services_failed; 552 goto failed;
553
554 rwlock_init(&adapter->port_list_lock);
555 INIT_LIST_HEAD(&adapter->port_list);
541 556
542 init_waitqueue_head(&adapter->remove_wq);
543 init_waitqueue_head(&adapter->erp_ready_wq); 557 init_waitqueue_head(&adapter->erp_ready_wq);
544 init_waitqueue_head(&adapter->erp_done_wqh); 558 init_waitqueue_head(&adapter->erp_done_wqh);
545 559
546 INIT_LIST_HEAD(&adapter->port_list_head);
547 INIT_LIST_HEAD(&adapter->erp_ready_head); 560 INIT_LIST_HEAD(&adapter->erp_ready_head);
548 INIT_LIST_HEAD(&adapter->erp_running_head); 561 INIT_LIST_HEAD(&adapter->erp_running_head);
549 562
@@ -553,83 +566,85 @@ int zfcp_adapter_enqueue(struct ccw_device *ccw_device)
553 rwlock_init(&adapter->abort_lock); 566 rwlock_init(&adapter->abort_lock);
554 567
555 if (zfcp_erp_thread_setup(adapter)) 568 if (zfcp_erp_thread_setup(adapter))
556 goto erp_thread_failed; 569 goto failed;
557
558 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
559 INIT_WORK(&adapter->scan_work, _zfcp_fc_scan_ports_later);
560 570
561 adapter->service_level.seq_print = zfcp_print_sl; 571 adapter->service_level.seq_print = zfcp_print_sl;
562 572
563 /* mark adapter unusable as long as sysfs registration is not complete */
564 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
565
566 dev_set_drvdata(&ccw_device->dev, adapter); 573 dev_set_drvdata(&ccw_device->dev, adapter);
567 574
568 if (sysfs_create_group(&ccw_device->dev.kobj, 575 if (sysfs_create_group(&ccw_device->dev.kobj,
569 &zfcp_sysfs_adapter_attrs)) 576 &zfcp_sysfs_adapter_attrs))
570 goto sysfs_failed; 577 goto failed;
571
572 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
573 578
574 if (!zfcp_adapter_scsi_register(adapter)) 579 if (!zfcp_adapter_scsi_register(adapter))
575 return 0; 580 return adapter;
576 581
577sysfs_failed: 582failed:
578 zfcp_erp_thread_kill(adapter); 583 zfcp_adapter_unregister(adapter);
579erp_thread_failed: 584 return ERR_PTR(-ENOMEM);
580 zfcp_fc_gs_destroy(adapter); 585}
581generic_services_failed: 586
587void zfcp_adapter_unregister(struct zfcp_adapter *adapter)
588{
589 struct ccw_device *cdev = adapter->ccw_device;
590
591 cancel_work_sync(&adapter->scan_work);
592 cancel_work_sync(&adapter->stat_work);
582 zfcp_destroy_adapter_work_queue(adapter); 593 zfcp_destroy_adapter_work_queue(adapter);
583work_queue_failed: 594
595 zfcp_fc_wka_ports_force_offline(adapter->gs);
596 zfcp_adapter_scsi_unregister(adapter);
597 sysfs_remove_group(&cdev->dev.kobj, &zfcp_sysfs_adapter_attrs);
598
599 zfcp_erp_thread_kill(adapter);
584 zfcp_dbf_adapter_unregister(adapter->dbf); 600 zfcp_dbf_adapter_unregister(adapter->dbf);
585debug_register_failed:
586 dev_set_drvdata(&ccw_device->dev, NULL);
587 kfree(adapter->req_list);
588low_mem_buffers_failed:
589 zfcp_free_low_mem_buffers(adapter);
590qdio_failed:
591 zfcp_qdio_destroy(adapter->qdio); 601 zfcp_qdio_destroy(adapter->qdio);
592 kfree(adapter); 602
593 return -ENOMEM; 603 zfcp_ccw_adapter_put(adapter); /* final put to release */
594} 604}
595 605
596/** 606/**
597 * zfcp_adapter_dequeue - remove the adapter from the resource list 607 * zfcp_adapter_release - remove the adapter from the resource list
598 * @adapter: pointer to struct zfcp_adapter which should be removed 608 * @ref: pointer to struct kref
599 * locks: adapter list write lock is assumed to be held by caller 609 * locks: adapter list write lock is assumed to be held by caller
600 */ 610 */
601void zfcp_adapter_dequeue(struct zfcp_adapter *adapter) 611void zfcp_adapter_release(struct kref *ref)
602{ 612{
603 int retval = 0; 613 struct zfcp_adapter *adapter = container_of(ref, struct zfcp_adapter,
604 unsigned long flags; 614 ref);
615 struct ccw_device *cdev = adapter->ccw_device;
605 616
606 cancel_work_sync(&adapter->stat_work);
607 zfcp_fc_wka_ports_force_offline(adapter->gs);
608 sysfs_remove_group(&adapter->ccw_device->dev.kobj,
609 &zfcp_sysfs_adapter_attrs);
610 dev_set_drvdata(&adapter->ccw_device->dev, NULL); 617 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
611 /* sanity check: no pending FSF requests */
612 spin_lock_irqsave(&adapter->req_list_lock, flags);
613 retval = zfcp_reqlist_isempty(adapter);
614 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
615 if (!retval)
616 return;
617
618 zfcp_fc_gs_destroy(adapter); 618 zfcp_fc_gs_destroy(adapter);
619 zfcp_erp_thread_kill(adapter);
620 zfcp_destroy_adapter_work_queue(adapter);
621 zfcp_dbf_adapter_unregister(adapter->dbf);
622 zfcp_free_low_mem_buffers(adapter); 619 zfcp_free_low_mem_buffers(adapter);
623 zfcp_qdio_destroy(adapter->qdio);
624 kfree(adapter->req_list); 620 kfree(adapter->req_list);
625 kfree(adapter->fc_stats); 621 kfree(adapter->fc_stats);
626 kfree(adapter->stats_reset_data); 622 kfree(adapter->stats_reset_data);
627 kfree(adapter); 623 kfree(adapter);
624 put_device(&cdev->dev);
628} 625}
629 626
630static void zfcp_sysfs_port_release(struct device *dev) 627/**
628 * zfcp_device_unregister - remove port, unit from system
629 * @dev: reference to device which is to be removed
630 * @grp: related reference to attribute group
631 *
632 * Helper function to unregister port, unit from system
633 */
634void zfcp_device_unregister(struct device *dev,
635 const struct attribute_group *grp)
631{ 636{
632 kfree(container_of(dev, struct zfcp_port, sysfs_device)); 637 sysfs_remove_group(&dev->kobj, grp);
638 device_unregister(dev);
639}
640
641static void zfcp_port_release(struct device *dev)
642{
643 struct zfcp_port *port = container_of(dev, struct zfcp_port,
644 sysfs_device);
645
646 zfcp_ccw_adapter_put(port->adapter);
647 kfree(port);
633} 648}
634 649
635/** 650/**
@@ -639,7 +654,6 @@ static void zfcp_sysfs_port_release(struct device *dev)
639 * @status: initial status for the port 654 * @status: initial status for the port
640 * @d_id: destination id of the remote port to be enqueued 655 * @d_id: destination id of the remote port to be enqueued
641 * Returns: pointer to enqueued port on success, ERR_PTR on error 656 * Returns: pointer to enqueued port on success, ERR_PTR on error
642 * Locks: config_mutex must be held to serialize changes to the port list
643 * 657 *
644 * All port internal structures are set up and the sysfs entry is generated. 658 * All port internal structures are set up and the sysfs entry is generated.
645 * d_id is used to enqueue ports with a well known address like the Directory 659 * d_id is used to enqueue ports with a well known address like the Directory
@@ -649,20 +663,24 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
649 u32 status, u32 d_id) 663 u32 status, u32 d_id)
650{ 664{
651 struct zfcp_port *port; 665 struct zfcp_port *port;
666 int retval = -ENOMEM;
652 667
653 read_lock_irq(&zfcp_data.config_lock); 668 kref_get(&adapter->ref);
654 if (zfcp_get_port_by_wwpn(adapter, wwpn)) { 669
655 read_unlock_irq(&zfcp_data.config_lock); 670 port = zfcp_get_port_by_wwpn(adapter, wwpn);
656 return ERR_PTR(-EINVAL); 671 if (port) {
672 put_device(&port->sysfs_device);
673 retval = -EEXIST;
674 goto err_out;
657 } 675 }
658 read_unlock_irq(&zfcp_data.config_lock);
659 676
660 port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL); 677 port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL);
661 if (!port) 678 if (!port)
662 return ERR_PTR(-ENOMEM); 679 goto err_out;
680
681 rwlock_init(&port->unit_list_lock);
682 INIT_LIST_HEAD(&port->unit_list);
663 683
664 init_waitqueue_head(&port->remove_wq);
665 INIT_LIST_HEAD(&port->unit_list_head);
666 INIT_WORK(&port->gid_pn_work, zfcp_fc_port_did_lookup); 684 INIT_WORK(&port->gid_pn_work, zfcp_fc_port_did_lookup);
667 INIT_WORK(&port->test_link_work, zfcp_fc_link_test_work); 685 INIT_WORK(&port->test_link_work, zfcp_fc_link_test_work);
668 INIT_WORK(&port->rport_work, zfcp_scsi_rport_work); 686 INIT_WORK(&port->rport_work, zfcp_scsi_rport_work);
@@ -671,58 +689,38 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
671 port->d_id = d_id; 689 port->d_id = d_id;
672 port->wwpn = wwpn; 690 port->wwpn = wwpn;
673 port->rport_task = RPORT_NONE; 691 port->rport_task = RPORT_NONE;
674 692 port->sysfs_device.parent = &adapter->ccw_device->dev;
675 /* mark port unusable as long as sysfs registration is not complete */ 693 port->sysfs_device.release = zfcp_port_release;
676 atomic_set_mask(status | ZFCP_STATUS_COMMON_REMOVE, &port->status);
677 atomic_set(&port->refcount, 0);
678 694
679 if (dev_set_name(&port->sysfs_device, "0x%016llx", 695 if (dev_set_name(&port->sysfs_device, "0x%016llx",
680 (unsigned long long)wwpn)) { 696 (unsigned long long)wwpn)) {
681 kfree(port); 697 kfree(port);
682 return ERR_PTR(-ENOMEM); 698 goto err_out;
683 } 699 }
684 port->sysfs_device.parent = &adapter->ccw_device->dev; 700 retval = -EINVAL;
685 port->sysfs_device.release = zfcp_sysfs_port_release;
686 dev_set_drvdata(&port->sysfs_device, port);
687 701
688 if (device_register(&port->sysfs_device)) { 702 if (device_register(&port->sysfs_device)) {
689 put_device(&port->sysfs_device); 703 put_device(&port->sysfs_device);
690 return ERR_PTR(-EINVAL); 704 goto err_out;
691 } 705 }
692 706
693 if (sysfs_create_group(&port->sysfs_device.kobj, 707 if (sysfs_create_group(&port->sysfs_device.kobj,
694 &zfcp_sysfs_port_attrs)) { 708 &zfcp_sysfs_port_attrs))
695 device_unregister(&port->sysfs_device); 709 goto err_out_put;
696 return ERR_PTR(-EINVAL);
697 }
698 710
699 zfcp_port_get(port); 711 write_lock_irq(&adapter->port_list_lock);
712 list_add_tail(&port->list, &adapter->port_list);
713 write_unlock_irq(&adapter->port_list_lock);
700 714
701 write_lock_irq(&zfcp_data.config_lock); 715 atomic_set_mask(status | ZFCP_STATUS_COMMON_RUNNING, &port->status);
702 list_add_tail(&port->list, &adapter->port_list_head);
703 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
704 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
705 716
706 write_unlock_irq(&zfcp_data.config_lock);
707
708 zfcp_adapter_get(adapter);
709 return port; 717 return port;
710}
711 718
712/** 719err_out_put:
713 * zfcp_port_dequeue - dequeues a port from the port list of the adapter
714 * @port: pointer to struct zfcp_port which should be removed
715 */
716void zfcp_port_dequeue(struct zfcp_port *port)
717{
718 write_lock_irq(&zfcp_data.config_lock);
719 list_del(&port->list);
720 write_unlock_irq(&zfcp_data.config_lock);
721 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
722 cancel_work_sync(&port->rport_work); /* usually not necessary */
723 zfcp_adapter_put(port->adapter);
724 sysfs_remove_group(&port->sysfs_device.kobj, &zfcp_sysfs_port_attrs);
725 device_unregister(&port->sysfs_device); 720 device_unregister(&port->sysfs_device);
721err_out:
722 zfcp_ccw_adapter_put(adapter);
723 return ERR_PTR(retval);
726} 724}
727 725
728/** 726/**
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index e08339428ecf..c22cb72a5ae8 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -13,28 +13,34 @@
13 13
14#define ZFCP_MODEL_PRIV 0x4 14#define ZFCP_MODEL_PRIV 0x4
15 15
16static int zfcp_ccw_suspend(struct ccw_device *cdev) 16static DEFINE_SPINLOCK(zfcp_ccw_adapter_ref_lock);
17 17
18struct zfcp_adapter *zfcp_ccw_adapter_by_cdev(struct ccw_device *cdev)
18{ 19{
19 struct zfcp_adapter *adapter = dev_get_drvdata(&cdev->dev); 20 struct zfcp_adapter *adapter;
20 21 unsigned long flags;
21 if (!adapter)
22 return 0;
23
24 mutex_lock(&zfcp_data.config_mutex);
25 22
26 zfcp_erp_adapter_shutdown(adapter, 0, "ccsusp1", NULL); 23 spin_lock_irqsave(&zfcp_ccw_adapter_ref_lock, flags);
27 zfcp_erp_wait(adapter); 24 adapter = dev_get_drvdata(&cdev->dev);
25 if (adapter)
26 kref_get(&adapter->ref);
27 spin_unlock_irqrestore(&zfcp_ccw_adapter_ref_lock, flags);
28 return adapter;
29}
28 30
29 mutex_unlock(&zfcp_data.config_mutex); 31void zfcp_ccw_adapter_put(struct zfcp_adapter *adapter)
32{
33 unsigned long flags;
30 34
31 return 0; 35 spin_lock_irqsave(&zfcp_ccw_adapter_ref_lock, flags);
36 kref_put(&adapter->ref, zfcp_adapter_release);
37 spin_unlock_irqrestore(&zfcp_ccw_adapter_ref_lock, flags);
32} 38}
33 39
34static int zfcp_ccw_activate(struct ccw_device *cdev) 40static int zfcp_ccw_activate(struct ccw_device *cdev)
35 41
36{ 42{
37 struct zfcp_adapter *adapter = dev_get_drvdata(&cdev->dev); 43 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
38 44
39 if (!adapter) 45 if (!adapter)
40 return 0; 46 return 0;
@@ -46,6 +52,8 @@ static int zfcp_ccw_activate(struct ccw_device *cdev)
46 zfcp_erp_wait(adapter); 52 zfcp_erp_wait(adapter);
47 flush_work(&adapter->scan_work); 53 flush_work(&adapter->scan_work);
48 54
55 zfcp_ccw_adapter_put(adapter);
56
49 return 0; 57 return 0;
50} 58}
51 59
@@ -67,28 +75,28 @@ int zfcp_ccw_priv_sch(struct zfcp_adapter *adapter)
67 75
68/** 76/**
69 * zfcp_ccw_probe - probe function of zfcp driver 77 * zfcp_ccw_probe - probe function of zfcp driver
70 * @ccw_device: pointer to belonging ccw device 78 * @cdev: pointer to belonging ccw device
71 * 79 *
72 * This function gets called by the common i/o layer for each FCP 80 * This function gets called by the common i/o layer for each FCP
73 * device found on the current system. This is only a stub to make cio 81 * device found on the current system. This is only a stub to make cio
74 * work: To only allocate adapter resources for devices actually used, 82 * work: To only allocate adapter resources for devices actually used,
75 * the allocation is deferred to the first call to ccw_set_online. 83 * the allocation is deferred to the first call to ccw_set_online.
76 */ 84 */
77static int zfcp_ccw_probe(struct ccw_device *ccw_device) 85static int zfcp_ccw_probe(struct ccw_device *cdev)
78{ 86{
79 return 0; 87 return 0;
80} 88}
81 89
82/** 90/**
83 * zfcp_ccw_remove - remove function of zfcp driver 91 * zfcp_ccw_remove - remove function of zfcp driver
84 * @ccw_device: pointer to belonging ccw device 92 * @cdev: pointer to belonging ccw device
85 * 93 *
86 * This function gets called by the common i/o layer and removes an adapter 94 * This function gets called by the common i/o layer and removes an adapter
87 * from the system. Task of this function is to get rid of all units and 95 * from the system. Task of this function is to get rid of all units and
88 * ports that belong to this adapter. And in addition all resources of this 96 * ports that belong to this adapter. And in addition all resources of this
89 * adapter will be freed too. 97 * adapter will be freed too.
90 */ 98 */
91static void zfcp_ccw_remove(struct ccw_device *ccw_device) 99static void zfcp_ccw_remove(struct ccw_device *cdev)
92{ 100{
93 struct zfcp_adapter *adapter; 101 struct zfcp_adapter *adapter;
94 struct zfcp_port *port, *p; 102 struct zfcp_port *port, *p;
@@ -96,49 +104,37 @@ static void zfcp_ccw_remove(struct ccw_device *ccw_device)
96 LIST_HEAD(unit_remove_lh); 104 LIST_HEAD(unit_remove_lh);
97 LIST_HEAD(port_remove_lh); 105 LIST_HEAD(port_remove_lh);
98 106
99 ccw_device_set_offline(ccw_device); 107 ccw_device_set_offline(cdev);
100 108
101 mutex_lock(&zfcp_data.config_mutex); 109 adapter = zfcp_ccw_adapter_by_cdev(cdev);
102 adapter = dev_get_drvdata(&ccw_device->dev);
103 if (!adapter) 110 if (!adapter)
104 goto out; 111 return;
105 mutex_unlock(&zfcp_data.config_mutex);
106 112
107 cancel_work_sync(&adapter->scan_work); 113 write_lock_irq(&adapter->port_list_lock);
108 114 list_for_each_entry_safe(port, p, &adapter->port_list, list) {
109 mutex_lock(&zfcp_data.config_mutex); 115 write_lock(&port->unit_list_lock);
110 116 list_for_each_entry_safe(unit, u, &port->unit_list, list)
111 /* this also removes the scsi devices, so call it first */
112 zfcp_adapter_scsi_unregister(adapter);
113
114 write_lock_irq(&zfcp_data.config_lock);
115 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
116 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
117 list_move(&unit->list, &unit_remove_lh); 117 list_move(&unit->list, &unit_remove_lh);
118 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, 118 write_unlock(&port->unit_list_lock);
119 &unit->status);
120 }
121 list_move(&port->list, &port_remove_lh); 119 list_move(&port->list, &port_remove_lh);
122 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
123 } 120 }
124 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); 121 write_unlock_irq(&adapter->port_list_lock);
125 write_unlock_irq(&zfcp_data.config_lock); 122 zfcp_ccw_adapter_put(adapter); /* put from zfcp_ccw_adapter_by_cdev */
126 123
127 list_for_each_entry_safe(port, p, &port_remove_lh, list) { 124 list_for_each_entry_safe(unit, u, &unit_remove_lh, list)
128 list_for_each_entry_safe(unit, u, &unit_remove_lh, list) 125 zfcp_device_unregister(&unit->sysfs_device,
129 zfcp_unit_dequeue(unit); 126 &zfcp_sysfs_unit_attrs);
130 zfcp_port_dequeue(port);
131 }
132 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
133 zfcp_adapter_dequeue(adapter);
134 127
135out: 128 list_for_each_entry_safe(port, p, &port_remove_lh, list)
136 mutex_unlock(&zfcp_data.config_mutex); 129 zfcp_device_unregister(&port->sysfs_device,
130 &zfcp_sysfs_port_attrs);
131
132 zfcp_adapter_unregister(adapter);
137} 133}
138 134
139/** 135/**
140 * zfcp_ccw_set_online - set_online function of zfcp driver 136 * zfcp_ccw_set_online - set_online function of zfcp driver
141 * @ccw_device: pointer to belonging ccw device 137 * @cdev: pointer to belonging ccw device
142 * 138 *
143 * This function gets called by the common i/o layer and sets an 139 * This function gets called by the common i/o layer and sets an
144 * adapter into state online. The first call will allocate all 140 * adapter into state online. The first call will allocate all
@@ -149,23 +145,20 @@ out:
149 * the SCSI stack, that the QDIO queues will be set up and that the 145 * the SCSI stack, that the QDIO queues will be set up and that the
150 * adapter will be opened. 146 * adapter will be opened.
151 */ 147 */
152static int zfcp_ccw_set_online(struct ccw_device *ccw_device) 148static int zfcp_ccw_set_online(struct ccw_device *cdev)
153{ 149{
154 struct zfcp_adapter *adapter; 150 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
155 int ret = 0;
156
157 mutex_lock(&zfcp_data.config_mutex);
158 adapter = dev_get_drvdata(&ccw_device->dev);
159 151
160 if (!adapter) { 152 if (!adapter) {
161 ret = zfcp_adapter_enqueue(ccw_device); 153 adapter = zfcp_adapter_enqueue(cdev);
162 if (ret) { 154
163 dev_err(&ccw_device->dev, 155 if (IS_ERR(adapter)) {
156 dev_err(&cdev->dev,
164 "Setting up data structures for the " 157 "Setting up data structures for the "
165 "FCP adapter failed\n"); 158 "FCP adapter failed\n");
166 goto out; 159 return PTR_ERR(adapter);
167 } 160 }
168 adapter = dev_get_drvdata(&ccw_device->dev); 161 kref_get(&adapter->ref);
169 } 162 }
170 163
171 /* initialize request counter */ 164 /* initialize request counter */
@@ -177,58 +170,61 @@ static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
177 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 170 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
178 "ccsonl2", NULL); 171 "ccsonl2", NULL);
179 zfcp_erp_wait(adapter); 172 zfcp_erp_wait(adapter);
180out: 173
181 mutex_unlock(&zfcp_data.config_mutex); 174 flush_work(&adapter->scan_work);
182 if (!ret) 175
183 flush_work(&adapter->scan_work); 176 zfcp_ccw_adapter_put(adapter);
184 return ret; 177 return 0;
185} 178}
186 179
187/** 180/**
188 * zfcp_ccw_set_offline - set_offline function of zfcp driver 181 * zfcp_ccw_set_offline - set_offline function of zfcp driver
189 * @ccw_device: pointer to belonging ccw device 182 * @cdev: pointer to belonging ccw device
190 * 183 *
191 * This function gets called by the common i/o layer and sets an adapter 184 * This function gets called by the common i/o layer and sets an adapter
192 * into state offline. 185 * into state offline.
193 */ 186 */
194static int zfcp_ccw_set_offline(struct ccw_device *ccw_device) 187static int zfcp_ccw_set_offline(struct ccw_device *cdev)
195{ 188{
196 struct zfcp_adapter *adapter; 189 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
190
191 if (!adapter)
192 return 0;
197 193
198 mutex_lock(&zfcp_data.config_mutex);
199 adapter = dev_get_drvdata(&ccw_device->dev);
200 zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL); 194 zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL);
201 zfcp_erp_wait(adapter); 195 zfcp_erp_wait(adapter);
202 mutex_unlock(&zfcp_data.config_mutex); 196
197 zfcp_ccw_adapter_put(adapter);
203 return 0; 198 return 0;
204} 199}
205 200
206/** 201/**
207 * zfcp_ccw_notify - ccw notify function 202 * zfcp_ccw_notify - ccw notify function
208 * @ccw_device: pointer to belonging ccw device 203 * @cdev: pointer to belonging ccw device
209 * @event: indicates if adapter was detached or attached 204 * @event: indicates if adapter was detached or attached
210 * 205 *
211 * This function gets called by the common i/o layer if an adapter has gone 206 * This function gets called by the common i/o layer if an adapter has gone
212 * or reappeared. 207 * or reappeared.
213 */ 208 */
214static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event) 209static int zfcp_ccw_notify(struct ccw_device *cdev, int event)
215{ 210{
216 struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev); 211 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
212
213 if (!adapter)
214 return 1;
217 215
218 switch (event) { 216 switch (event) {
219 case CIO_GONE: 217 case CIO_GONE:
220 dev_warn(&adapter->ccw_device->dev, 218 dev_warn(&cdev->dev, "The FCP device has been detached\n");
221 "The FCP device has been detached\n");
222 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL); 219 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL);
223 break; 220 break;
224 case CIO_NO_PATH: 221 case CIO_NO_PATH:
225 dev_warn(&adapter->ccw_device->dev, 222 dev_warn(&cdev->dev,
226 "The CHPID for the FCP device is offline\n"); 223 "The CHPID for the FCP device is offline\n");
227 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL); 224 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL);
228 break; 225 break;
229 case CIO_OPER: 226 case CIO_OPER:
230 dev_info(&adapter->ccw_device->dev, 227 dev_info(&cdev->dev, "The FCP device is operational again\n");
231 "The FCP device is operational again\n");
232 zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL, 228 zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL,
233 ZFCP_STATUS_COMMON_RUNNING, 229 ZFCP_STATUS_COMMON_RUNNING,
234 ZFCP_SET); 230 ZFCP_SET);
@@ -236,11 +232,13 @@ static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
236 "ccnoti4", NULL); 232 "ccnoti4", NULL);
237 break; 233 break;
238 case CIO_BOXED: 234 case CIO_BOXED:
239 dev_warn(&adapter->ccw_device->dev, "The FCP device " 235 dev_warn(&cdev->dev, "The FCP device did not respond within "
240 "did not respond within the specified time\n"); 236 "the specified time\n");
241 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL); 237 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL);
242 break; 238 break;
243 } 239 }
240
241 zfcp_ccw_adapter_put(adapter);
244 return 1; 242 return 1;
245} 243}
246 244
@@ -250,18 +248,16 @@ static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
250 */ 248 */
251static void zfcp_ccw_shutdown(struct ccw_device *cdev) 249static void zfcp_ccw_shutdown(struct ccw_device *cdev)
252{ 250{
253 struct zfcp_adapter *adapter; 251 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
254 252
255 mutex_lock(&zfcp_data.config_mutex);
256 adapter = dev_get_drvdata(&cdev->dev);
257 if (!adapter) 253 if (!adapter)
258 goto out; 254 return;
259 255
260 zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL); 256 zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL);
261 zfcp_erp_wait(adapter); 257 zfcp_erp_wait(adapter);
262 zfcp_erp_thread_kill(adapter); 258 zfcp_erp_thread_kill(adapter);
263out: 259
264 mutex_unlock(&zfcp_data.config_mutex); 260 zfcp_ccw_adapter_put(adapter);
265} 261}
266 262
267struct ccw_driver zfcp_ccw_driver = { 263struct ccw_driver zfcp_ccw_driver = {
@@ -274,18 +270,7 @@ struct ccw_driver zfcp_ccw_driver = {
274 .set_offline = zfcp_ccw_set_offline, 270 .set_offline = zfcp_ccw_set_offline,
275 .notify = zfcp_ccw_notify, 271 .notify = zfcp_ccw_notify,
276 .shutdown = zfcp_ccw_shutdown, 272 .shutdown = zfcp_ccw_shutdown,
277 .freeze = zfcp_ccw_suspend, 273 .freeze = zfcp_ccw_set_offline,
278 .thaw = zfcp_ccw_activate, 274 .thaw = zfcp_ccw_activate,
279 .restore = zfcp_ccw_activate, 275 .restore = zfcp_ccw_activate,
280}; 276};
281
282/**
283 * zfcp_ccw_register - ccw register function
284 *
285 * Registers the driver at the common i/o layer. This function will be called
286 * at module load time/system start.
287 */
288int __init zfcp_ccw_register(void)
289{
290 return ccw_driver_register(&zfcp_ccw_driver);
291}
diff --git a/drivers/s390/scsi/zfcp_cfdc.c b/drivers/s390/scsi/zfcp_cfdc.c
index ef681dfed0cc..f932400e980a 100644
--- a/drivers/s390/scsi/zfcp_cfdc.c
+++ b/drivers/s390/scsi/zfcp_cfdc.c
@@ -86,22 +86,17 @@ static int zfcp_cfdc_copy_to_user(void __user *user_buffer,
86static struct zfcp_adapter *zfcp_cfdc_get_adapter(u32 devno) 86static struct zfcp_adapter *zfcp_cfdc_get_adapter(u32 devno)
87{ 87{
88 char busid[9]; 88 char busid[9];
89 struct ccw_device *ccwdev; 89 struct ccw_device *cdev;
90 struct zfcp_adapter *adapter = NULL; 90 struct zfcp_adapter *adapter;
91 91
92 snprintf(busid, sizeof(busid), "0.0.%04x", devno); 92 snprintf(busid, sizeof(busid), "0.0.%04x", devno);
93 ccwdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid); 93 cdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
94 if (!ccwdev) 94 if (!cdev)
95 goto out; 95 return NULL;
96 96
97 adapter = dev_get_drvdata(&ccwdev->dev); 97 adapter = zfcp_ccw_adapter_by_cdev(cdev);
98 if (!adapter) 98
99 goto out_put; 99 put_device(&cdev->dev);
100
101 zfcp_adapter_get(adapter);
102out_put:
103 put_device(&ccwdev->dev);
104out:
105 return adapter; 100 return adapter;
106} 101}
107 102
@@ -212,7 +207,6 @@ static long zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
212 retval = -ENXIO; 207 retval = -ENXIO;
213 goto free_buffer; 208 goto free_buffer;
214 } 209 }
215 zfcp_adapter_get(adapter);
216 210
217 retval = zfcp_cfdc_sg_setup(data->command, fsf_cfdc->sg, 211 retval = zfcp_cfdc_sg_setup(data->command, fsf_cfdc->sg,
218 data_user->control_file); 212 data_user->control_file);
@@ -245,7 +239,7 @@ static long zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
245 free_sg: 239 free_sg:
246 zfcp_sg_free_table(fsf_cfdc->sg, ZFCP_CFDC_PAGES); 240 zfcp_sg_free_table(fsf_cfdc->sg, ZFCP_CFDC_PAGES);
247 adapter_put: 241 adapter_put:
248 zfcp_adapter_put(adapter); 242 zfcp_ccw_adapter_put(adapter);
249 free_buffer: 243 free_buffer:
250 kfree(data); 244 kfree(data);
251 no_mem_sense: 245 no_mem_sense:
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index 215b70749e95..84450955ae11 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -13,6 +13,7 @@
13#include <asm/debug.h> 13#include <asm/debug.h>
14#include "zfcp_dbf.h" 14#include "zfcp_dbf.h"
15#include "zfcp_ext.h" 15#include "zfcp_ext.h"
16#include "zfcp_fc.h"
16 17
17static u32 dbfsize = 4; 18static u32 dbfsize = 4;
18 19
@@ -177,8 +178,7 @@ void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
177 178
178 case FSF_QTCB_SEND_ELS: 179 case FSF_QTCB_SEND_ELS:
179 send_els = (struct zfcp_send_els *)fsf_req->data; 180 send_els = (struct zfcp_send_els *)fsf_req->data;
180 response->u.els.d_id = qtcb->bottom.support.d_id; 181 response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id);
181 response->u.els.ls_code = send_els->ls_code >> 24;
182 break; 182 break;
183 183
184 case FSF_QTCB_ABORT_FCP_CMND: 184 case FSF_QTCB_ABORT_FCP_CMND:
@@ -348,7 +348,6 @@ static void zfcp_dbf_hba_view_response(char **p,
348 348
349 case FSF_QTCB_SEND_ELS: 349 case FSF_QTCB_SEND_ELS:
350 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id); 350 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
351 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
352 break; 351 break;
353 352
354 case FSF_QTCB_ABORT_FCP_CMND: 353 case FSF_QTCB_ABORT_FCP_CMND:
@@ -677,14 +676,14 @@ void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action)
677/** 676/**
678 * zfcp_dbf_san_ct_request - trace event for issued CT request 677 * zfcp_dbf_san_ct_request - trace event for issued CT request
679 * @fsf_req: request containing issued CT data 678 * @fsf_req: request containing issued CT data
679 * @d_id: destination id where ct request is sent to
680 */ 680 */
681void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req) 681void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req, u32 d_id)
682{ 682{
683 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data; 683 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
684 struct zfcp_wka_port *wka_port = ct->wka_port; 684 struct zfcp_adapter *adapter = fsf_req->adapter;
685 struct zfcp_adapter *adapter = wka_port->adapter;
686 struct zfcp_dbf *dbf = adapter->dbf; 685 struct zfcp_dbf *dbf = adapter->dbf;
687 struct ct_hdr *hdr = sg_virt(ct->req); 686 struct fc_ct_hdr *hdr = sg_virt(ct->req);
688 struct zfcp_dbf_san_record *r = &dbf->san_buf; 687 struct zfcp_dbf_san_record *r = &dbf->san_buf;
689 struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req; 688 struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req;
690 int level = 3; 689 int level = 3;
@@ -695,19 +694,18 @@ void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req)
695 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE); 694 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
696 r->fsf_reqid = fsf_req->req_id; 695 r->fsf_reqid = fsf_req->req_id;
697 r->fsf_seqno = fsf_req->seq_no; 696 r->fsf_seqno = fsf_req->seq_no;
698 r->s_id = fc_host_port_id(adapter->scsi_host); 697 oct->d_id = d_id;
699 r->d_id = wka_port->d_id; 698 oct->cmd_req_code = hdr->ct_cmd;
700 oct->cmd_req_code = hdr->cmd_rsp_code; 699 oct->revision = hdr->ct_rev;
701 oct->revision = hdr->revision; 700 oct->gs_type = hdr->ct_fs_type;
702 oct->gs_type = hdr->gs_type; 701 oct->gs_subtype = hdr->ct_fs_subtype;
703 oct->gs_subtype = hdr->gs_subtype; 702 oct->options = hdr->ct_options;
704 oct->options = hdr->options; 703 oct->max_res_size = hdr->ct_mr_size;
705 oct->max_res_size = hdr->max_res_size; 704 oct->len = min((int)ct->req->length - (int)sizeof(struct fc_ct_hdr),
706 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
707 ZFCP_DBF_SAN_MAX_PAYLOAD); 705 ZFCP_DBF_SAN_MAX_PAYLOAD);
708 debug_event(dbf->san, level, r, sizeof(*r)); 706 debug_event(dbf->san, level, r, sizeof(*r));
709 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level, 707 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
710 (void *)hdr + sizeof(struct ct_hdr), oct->len); 708 (void *)hdr + sizeof(struct fc_ct_hdr), oct->len);
711 spin_unlock_irqrestore(&dbf->san_lock, flags); 709 spin_unlock_irqrestore(&dbf->san_lock, flags);
712} 710}
713 711
@@ -717,10 +715,9 @@ void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req)
717 */ 715 */
718void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req) 716void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
719{ 717{
720 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data; 718 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
721 struct zfcp_wka_port *wka_port = ct->wka_port; 719 struct zfcp_adapter *adapter = fsf_req->adapter;
722 struct zfcp_adapter *adapter = wka_port->adapter; 720 struct fc_ct_hdr *hdr = sg_virt(ct->resp);
723 struct ct_hdr *hdr = sg_virt(ct->resp);
724 struct zfcp_dbf *dbf = adapter->dbf; 721 struct zfcp_dbf *dbf = adapter->dbf;
725 struct zfcp_dbf_san_record *r = &dbf->san_buf; 722 struct zfcp_dbf_san_record *r = &dbf->san_buf;
726 struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp; 723 struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp;
@@ -732,25 +729,23 @@ void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
732 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE); 729 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
733 r->fsf_reqid = fsf_req->req_id; 730 r->fsf_reqid = fsf_req->req_id;
734 r->fsf_seqno = fsf_req->seq_no; 731 r->fsf_seqno = fsf_req->seq_no;
735 r->s_id = wka_port->d_id; 732 rct->cmd_rsp_code = hdr->ct_cmd;
736 r->d_id = fc_host_port_id(adapter->scsi_host); 733 rct->revision = hdr->ct_rev;
737 rct->cmd_rsp_code = hdr->cmd_rsp_code; 734 rct->reason_code = hdr->ct_reason;
738 rct->revision = hdr->revision; 735 rct->expl = hdr->ct_explan;
739 rct->reason_code = hdr->reason_code; 736 rct->vendor_unique = hdr->ct_vendor;
740 rct->expl = hdr->reason_code_expl; 737 rct->max_res_size = hdr->ct_mr_size;
741 rct->vendor_unique = hdr->vendor_unique; 738 rct->len = min((int)ct->resp->length - (int)sizeof(struct fc_ct_hdr),
742 rct->max_res_size = hdr->max_res_size;
743 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
744 ZFCP_DBF_SAN_MAX_PAYLOAD); 739 ZFCP_DBF_SAN_MAX_PAYLOAD);
745 debug_event(dbf->san, level, r, sizeof(*r)); 740 debug_event(dbf->san, level, r, sizeof(*r));
746 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level, 741 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
747 (void *)hdr + sizeof(struct ct_hdr), rct->len); 742 (void *)hdr + sizeof(struct fc_ct_hdr), rct->len);
748 spin_unlock_irqrestore(&dbf->san_lock, flags); 743 spin_unlock_irqrestore(&dbf->san_lock, flags);
749} 744}
750 745
751static void zfcp_dbf_san_els(const char *tag, int level, 746static void zfcp_dbf_san_els(const char *tag, int level,
752 struct zfcp_fsf_req *fsf_req, u32 s_id, u32 d_id, 747 struct zfcp_fsf_req *fsf_req, u32 d_id,
753 u8 ls_code, void *buffer, int buflen) 748 void *buffer, int buflen)
754{ 749{
755 struct zfcp_adapter *adapter = fsf_req->adapter; 750 struct zfcp_adapter *adapter = fsf_req->adapter;
756 struct zfcp_dbf *dbf = adapter->dbf; 751 struct zfcp_dbf *dbf = adapter->dbf;
@@ -762,9 +757,7 @@ static void zfcp_dbf_san_els(const char *tag, int level,
762 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); 757 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
763 rec->fsf_reqid = fsf_req->req_id; 758 rec->fsf_reqid = fsf_req->req_id;
764 rec->fsf_seqno = fsf_req->seq_no; 759 rec->fsf_seqno = fsf_req->seq_no;
765 rec->s_id = s_id; 760 rec->u.els.d_id = d_id;
766 rec->d_id = d_id;
767 rec->u.els.ls_code = ls_code;
768 debug_event(dbf->san, level, rec, sizeof(*rec)); 761 debug_event(dbf->san, level, rec, sizeof(*rec));
769 zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level, 762 zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level,
770 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD)); 763 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
@@ -777,12 +770,11 @@ static void zfcp_dbf_san_els(const char *tag, int level,
777 */ 770 */
778void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req) 771void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
779{ 772{
780 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data; 773 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
774 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
781 775
782 zfcp_dbf_san_els("oels", 2, fsf_req, 776 zfcp_dbf_san_els("oels", 2, fsf_req, d_id,
783 fc_host_port_id(els->adapter->scsi_host), 777 sg_virt(els->req), els->req->length);
784 els->d_id, *(u8 *) sg_virt(els->req),
785 sg_virt(els->req), els->req->length);
786} 778}
787 779
788/** 780/**
@@ -791,12 +783,11 @@ void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
791 */ 783 */
792void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req) 784void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
793{ 785{
794 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data; 786 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
787 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
795 788
796 zfcp_dbf_san_els("rels", 2, fsf_req, els->d_id, 789 zfcp_dbf_san_els("rels", 2, fsf_req, d_id,
797 fc_host_port_id(els->adapter->scsi_host), 790 sg_virt(els->resp), els->resp->length);
798 *(u8 *)sg_virt(els->req), sg_virt(els->resp),
799 els->resp->length);
800} 791}
801 792
802/** 793/**
@@ -805,16 +796,13 @@ void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
805 */ 796 */
806void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req) 797void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req)
807{ 798{
808 struct zfcp_adapter *adapter = fsf_req->adapter;
809 struct fsf_status_read_buffer *buf = 799 struct fsf_status_read_buffer *buf =
810 (struct fsf_status_read_buffer *)fsf_req->data; 800 (struct fsf_status_read_buffer *)fsf_req->data;
811 int length = (int)buf->length - 801 int length = (int)buf->length -
812 (int)((void *)&buf->payload - (void *)buf); 802 (int)((void *)&buf->payload - (void *)buf);
813 803
814 zfcp_dbf_san_els("iels", 1, fsf_req, buf->d_id, 804 zfcp_dbf_san_els("iels", 1, fsf_req, ntoh24(buf->d_id),
815 fc_host_port_id(adapter->scsi_host), 805 (void *)buf->payload.data, length);
816 buf->payload.data[0], (void *)buf->payload.data,
817 length);
818} 806}
819 807
820static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view, 808static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
@@ -829,11 +817,10 @@ static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
829 zfcp_dbf_tag(&p, "tag", r->tag); 817 zfcp_dbf_tag(&p, "tag", r->tag);
830 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid); 818 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
831 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno); 819 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
832 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
833 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
834 820
835 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) { 821 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
836 struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req; 822 struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req;
823 zfcp_dbf_out(&p, "d_id", "0x%06x", ct->d_id);
837 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code); 824 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
838 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision); 825 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
839 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type); 826 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
@@ -852,7 +839,7 @@ static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
852 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 || 839 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
853 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) { 840 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
854 struct zfcp_dbf_san_record_els *els = &r->u.els; 841 struct zfcp_dbf_san_record_els *els = &r->u.els;
855 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code); 842 zfcp_dbf_out(&p, "d_id", "0x%06x", els->d_id);
856 } 843 }
857 return p - out_buf; 844 return p - out_buf;
858} 845}
@@ -870,8 +857,9 @@ void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
870 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf; 857 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
871 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec; 858 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
872 unsigned long flags; 859 unsigned long flags;
873 struct fcp_rsp_iu *fcp_rsp; 860 struct fcp_resp_with_ext *fcp_rsp;
874 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL; 861 struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
862 char *fcp_sns_info = NULL;
875 int offset = 0, buflen = 0; 863 int offset = 0, buflen = 0;
876 864
877 spin_lock_irqsave(&dbf->scsi_lock, flags); 865 spin_lock_irqsave(&dbf->scsi_lock, flags);
@@ -895,20 +883,22 @@ void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
895 rec->scsi_allowed = scsi_cmnd->allowed; 883 rec->scsi_allowed = scsi_cmnd->allowed;
896 } 884 }
897 if (fsf_req != NULL) { 885 if (fsf_req != NULL) {
898 fcp_rsp = (struct fcp_rsp_iu *) 886 fcp_rsp = (struct fcp_resp_with_ext *)
899 &(fsf_req->qtcb->bottom.io.fcp_rsp); 887 &(fsf_req->qtcb->bottom.io.fcp_rsp);
900 fcp_rsp_info = (unsigned char *) &fcp_rsp[1]; 888 fcp_rsp_info = (struct fcp_resp_rsp_info *)
901 fcp_sns_info = 889 &fcp_rsp[1];
902 zfcp_get_fcp_sns_info_ptr(fcp_rsp); 890 fcp_sns_info = (char *) &fcp_rsp[1];
903 891 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
904 rec->rsp_validity = fcp_rsp->validity.value; 892 fcp_sns_info += fcp_rsp->ext.fr_sns_len;
905 rec->rsp_scsi_status = fcp_rsp->scsi_status; 893
906 rec->rsp_resid = fcp_rsp->fcp_resid; 894 rec->rsp_validity = fcp_rsp->resp.fr_flags;
907 if (fcp_rsp->validity.bits.fcp_rsp_len_valid) 895 rec->rsp_scsi_status = fcp_rsp->resp.fr_status;
908 rec->rsp_code = *(fcp_rsp_info + 3); 896 rec->rsp_resid = fcp_rsp->ext.fr_resid;
909 if (fcp_rsp->validity.bits.fcp_sns_len_valid) { 897 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
910 buflen = min((int)fcp_rsp->fcp_sns_len, 898 rec->rsp_code = fcp_rsp_info->rsp_code;
911 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO); 899 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
900 buflen = min(fcp_rsp->ext.fr_sns_len,
901 (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
912 rec->sns_info_len = buflen; 902 rec->sns_info_len = buflen;
913 memcpy(rec->sns_info, fcp_sns_info, 903 memcpy(rec->sns_info, fcp_sns_info,
914 min(buflen, 904 min(buflen,
@@ -1067,6 +1057,8 @@ err_out:
1067 */ 1057 */
1068void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf) 1058void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
1069{ 1059{
1060 if (!dbf)
1061 return;
1070 debug_unregister(dbf->scsi); 1062 debug_unregister(dbf->scsi);
1071 debug_unregister(dbf->san); 1063 debug_unregister(dbf->san);
1072 debug_unregister(dbf->hba); 1064 debug_unregister(dbf->hba);
diff --git a/drivers/s390/scsi/zfcp_dbf.h b/drivers/s390/scsi/zfcp_dbf.h
index 6b1461e8f847..8b7fd9a1033e 100644
--- a/drivers/s390/scsi/zfcp_dbf.h
+++ b/drivers/s390/scsi/zfcp_dbf.h
@@ -22,6 +22,7 @@
22#ifndef ZFCP_DBF_H 22#ifndef ZFCP_DBF_H
23#define ZFCP_DBF_H 23#define ZFCP_DBF_H
24 24
25#include <scsi/fc/fc_fcp.h>
25#include "zfcp_ext.h" 26#include "zfcp_ext.h"
26#include "zfcp_fsf.h" 27#include "zfcp_fsf.h"
27#include "zfcp_def.h" 28#include "zfcp_def.h"
@@ -122,7 +123,6 @@ struct zfcp_dbf_hba_record_response {
122 } unit; 123 } unit;
123 struct { 124 struct {
124 u32 d_id; 125 u32 d_id;
125 u8 ls_code;
126 } els; 126 } els;
127 } u; 127 } u;
128} __attribute__ ((packed)); 128} __attribute__ ((packed));
@@ -166,6 +166,7 @@ struct zfcp_dbf_san_record_ct_request {
166 u8 options; 166 u8 options;
167 u16 max_res_size; 167 u16 max_res_size;
168 u32 len; 168 u32 len;
169 u32 d_id;
169} __attribute__ ((packed)); 170} __attribute__ ((packed));
170 171
171struct zfcp_dbf_san_record_ct_response { 172struct zfcp_dbf_san_record_ct_response {
@@ -179,16 +180,13 @@ struct zfcp_dbf_san_record_ct_response {
179} __attribute__ ((packed)); 180} __attribute__ ((packed));
180 181
181struct zfcp_dbf_san_record_els { 182struct zfcp_dbf_san_record_els {
182 u8 ls_code; 183 u32 d_id;
183 u32 len;
184} __attribute__ ((packed)); 184} __attribute__ ((packed));
185 185
186struct zfcp_dbf_san_record { 186struct zfcp_dbf_san_record {
187 u8 tag[ZFCP_DBF_TAG_SIZE]; 187 u8 tag[ZFCP_DBF_TAG_SIZE];
188 u64 fsf_reqid; 188 u64 fsf_reqid;
189 u32 fsf_seqno; 189 u32 fsf_seqno;
190 u32 s_id;
191 u32 d_id;
192 union { 190 union {
193 struct zfcp_dbf_san_record_ct_request ct_req; 191 struct zfcp_dbf_san_record_ct_request ct_req;
194 struct zfcp_dbf_san_record_ct_response ct_resp; 192 struct zfcp_dbf_san_record_ct_response ct_resp;
@@ -343,7 +341,7 @@ static inline
343void zfcp_dbf_scsi_devreset(const char *tag, u8 flag, struct zfcp_unit *unit, 341void zfcp_dbf_scsi_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
344 struct scsi_cmnd *scsi_cmnd) 342 struct scsi_cmnd *scsi_cmnd)
345{ 343{
346 zfcp_dbf_scsi(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1, 344 zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
347 unit->port->adapter->dbf, scsi_cmnd, NULL, 0); 345 unit->port->adapter->dbf, scsi_cmnd, NULL, 0);
348} 346}
349 347
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index 7da2fad8f515..e1b5b88e2ddb 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -71,131 +71,6 @@
71/* timeout value for "default timer" for fsf requests */ 71/* timeout value for "default timer" for fsf requests */
72#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ) 72#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
73 73
74/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
75
76/* task attribute values in FCP-2 FCP_CMND IU */
77#define SIMPLE_Q 0
78#define HEAD_OF_Q 1
79#define ORDERED_Q 2
80#define ACA_Q 4
81#define UNTAGGED 5
82
83/* task management flags in FCP-2 FCP_CMND IU */
84#define FCP_CLEAR_ACA 0x40
85#define FCP_TARGET_RESET 0x20
86#define FCP_LOGICAL_UNIT_RESET 0x10
87#define FCP_CLEAR_TASK_SET 0x04
88#define FCP_ABORT_TASK_SET 0x02
89
90#define FCP_CDB_LENGTH 16
91
92#define ZFCP_DID_MASK 0x00FFFFFF
93
94/* FCP(-2) FCP_CMND IU */
95struct fcp_cmnd_iu {
96 u64 fcp_lun; /* FCP logical unit number */
97 u8 crn; /* command reference number */
98 u8 reserved0:5; /* reserved */
99 u8 task_attribute:3; /* task attribute */
100 u8 task_management_flags; /* task management flags */
101 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
102 u8 rddata:1; /* read data */
103 u8 wddata:1; /* write data */
104 u8 fcp_cdb[FCP_CDB_LENGTH];
105} __attribute__((packed));
106
107/* FCP(-2) FCP_RSP IU */
108struct fcp_rsp_iu {
109 u8 reserved0[10];
110 union {
111 struct {
112 u8 reserved1:3;
113 u8 fcp_conf_req:1;
114 u8 fcp_resid_under:1;
115 u8 fcp_resid_over:1;
116 u8 fcp_sns_len_valid:1;
117 u8 fcp_rsp_len_valid:1;
118 } bits;
119 u8 value;
120 } validity;
121 u8 scsi_status;
122 u32 fcp_resid;
123 u32 fcp_sns_len;
124 u32 fcp_rsp_len;
125} __attribute__((packed));
126
127
128#define RSP_CODE_GOOD 0
129#define RSP_CODE_LENGTH_MISMATCH 1
130#define RSP_CODE_FIELD_INVALID 2
131#define RSP_CODE_RO_MISMATCH 3
132#define RSP_CODE_TASKMAN_UNSUPP 4
133#define RSP_CODE_TASKMAN_FAILED 5
134
135/* see fc-fs */
136#define LS_RSCN 0x61
137#define LS_LOGO 0x05
138#define LS_PLOGI 0x03
139
140struct fcp_rscn_head {
141 u8 command;
142 u8 page_length; /* always 0x04 */
143 u16 payload_len;
144} __attribute__((packed));
145
146struct fcp_rscn_element {
147 u8 reserved:2;
148 u8 event_qual:4;
149 u8 addr_format:2;
150 u32 nport_did:24;
151} __attribute__((packed));
152
153/* see fc-ph */
154struct fcp_logo {
155 u32 command;
156 u32 nport_did;
157 u64 nport_wwpn;
158} __attribute__((packed));
159
160/*
161 * FC-FS stuff
162 */
163#define R_A_TOV 10 /* seconds */
164
165#define ZFCP_LS_RLS 0x0f
166#define ZFCP_LS_ADISC 0x52
167#define ZFCP_LS_RPS 0x56
168#define ZFCP_LS_RSCN 0x61
169#define ZFCP_LS_RNID 0x78
170
171struct zfcp_ls_adisc {
172 u8 code;
173 u8 field[3];
174 u32 hard_nport_id;
175 u64 wwpn;
176 u64 wwnn;
177 u32 nport_id;
178} __attribute__ ((packed));
179
180/*
181 * FC-GS-2 stuff
182 */
183#define ZFCP_CT_REVISION 0x01
184#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
185#define ZFCP_CT_NAME_SERVER 0x02
186#define ZFCP_CT_SYNCHRONOUS 0x00
187#define ZFCP_CT_SCSI_FCP 0x08
188#define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
189#define ZFCP_CT_GID_PN 0x0121
190#define ZFCP_CT_GPN_FT 0x0172
191#define ZFCP_CT_ACCEPT 0x8002
192#define ZFCP_CT_REJECT 0x8001
193
194/*
195 * FC-GS-4 stuff
196 */
197#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
198
199/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/ 74/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
200 75
201/* 76/*
@@ -205,7 +80,6 @@ struct zfcp_ls_adisc {
205#define ZFCP_COMMON_FLAGS 0xfff00000 80#define ZFCP_COMMON_FLAGS 0xfff00000
206 81
207/* common status bits */ 82/* common status bits */
208#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
209#define ZFCP_STATUS_COMMON_RUNNING 0x40000000 83#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
210#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000 84#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
211#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000 85#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
@@ -222,21 +96,10 @@ struct zfcp_ls_adisc {
222#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100 96#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
223#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200 97#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
224 98
225/* FC-PH/FC-GS well-known address identifiers for generic services */
226#define ZFCP_DID_WKA 0xFFFFF0
227
228/* remote port status */ 99/* remote port status */
229#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001 100#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
230#define ZFCP_STATUS_PORT_LINK_TEST 0x00000002 101#define ZFCP_STATUS_PORT_LINK_TEST 0x00000002
231 102
232/* well known address (WKA) port status*/
233enum zfcp_wka_status {
234 ZFCP_WKA_PORT_OFFLINE,
235 ZFCP_WKA_PORT_CLOSING,
236 ZFCP_WKA_PORT_OPENING,
237 ZFCP_WKA_PORT_ONLINE,
238};
239
240/* logical unit status */ 103/* logical unit status */
241#define ZFCP_STATUS_UNIT_SHARED 0x00000004 104#define ZFCP_STATUS_UNIT_SHARED 0x00000004
242#define ZFCP_STATUS_UNIT_READONLY 0x00000008 105#define ZFCP_STATUS_UNIT_READONLY 0x00000008
@@ -247,10 +110,7 @@ enum zfcp_wka_status {
247#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010 110#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
248#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040 111#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
249#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080 112#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
250#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
251#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200 113#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
252#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
253#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
254#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000 114#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
255 115
256/************************* STRUCTURE DEFINITIONS *****************************/ 116/************************* STRUCTURE DEFINITIONS *****************************/
@@ -265,125 +125,10 @@ struct zfcp_adapter_mempool {
265 mempool_t *scsi_abort; 125 mempool_t *scsi_abort;
266 mempool_t *status_read_req; 126 mempool_t *status_read_req;
267 mempool_t *status_read_data; 127 mempool_t *status_read_data;
268 mempool_t *gid_pn_data; 128 mempool_t *gid_pn;
269 mempool_t *qtcb_pool; 129 mempool_t *qtcb_pool;
270}; 130};
271 131
272/*
273 * header for CT_IU
274 */
275struct ct_hdr {
276 u8 revision; // 0x01
277 u8 in_id[3]; // 0x00
278 u8 gs_type; // 0xFC Directory Service
279 u8 gs_subtype; // 0x02 Name Server
280 u8 options; // 0x00 single bidirectional exchange
281 u8 reserved0;
282 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
283 u16 max_res_size; // <= (4096 - 16) / 4
284 u8 reserved1;
285 u8 reason_code;
286 u8 reason_code_expl;
287 u8 vendor_unique;
288} __attribute__ ((packed));
289
290/* nameserver request CT_IU -- for requests where
291 * a port name is required */
292struct ct_iu_gid_pn_req {
293 struct ct_hdr header;
294 u64 wwpn;
295} __attribute__ ((packed));
296
297/* FS_ACC IU and data unit for GID_PN nameserver request */
298struct ct_iu_gid_pn_resp {
299 struct ct_hdr header;
300 u32 d_id;
301} __attribute__ ((packed));
302
303struct ct_iu_gpn_ft_req {
304 struct ct_hdr header;
305 u8 flags;
306 u8 domain_id_scope;
307 u8 area_id_scope;
308 u8 fc4_type;
309} __attribute__ ((packed));
310
311
312/**
313 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
314 * @wka_port: port where the request is sent to
315 * @req: scatter-gather list for request
316 * @resp: scatter-gather list for response
317 * @handler: handler function (called for response to the request)
318 * @handler_data: data passed to handler function
319 * @completion: completion for synchronization purposes
320 * @status: used to pass error status to calling function
321 */
322struct zfcp_send_ct {
323 struct zfcp_wka_port *wka_port;
324 struct scatterlist *req;
325 struct scatterlist *resp;
326 void (*handler)(unsigned long);
327 unsigned long handler_data;
328 struct completion *completion;
329 int status;
330};
331
332/* used for name server requests in error recovery */
333struct zfcp_gid_pn_data {
334 struct zfcp_send_ct ct;
335 struct scatterlist req;
336 struct scatterlist resp;
337 struct ct_iu_gid_pn_req ct_iu_req;
338 struct ct_iu_gid_pn_resp ct_iu_resp;
339 struct zfcp_port *port;
340};
341
342/**
343 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
344 * @adapter: adapter where request is sent from
345 * @port: port where ELS is destinated (port reference count has to be increased)
346 * @d_id: destiniation id of port where request is sent to
347 * @req: scatter-gather list for request
348 * @resp: scatter-gather list for response
349 * @handler: handler function (called for response to the request)
350 * @handler_data: data passed to handler function
351 * @completion: completion for synchronization purposes
352 * @ls_code: hex code of ELS command
353 * @status: used to pass error status to calling function
354 */
355struct zfcp_send_els {
356 struct zfcp_adapter *adapter;
357 struct zfcp_port *port;
358 u32 d_id;
359 struct scatterlist *req;
360 struct scatterlist *resp;
361 void (*handler)(unsigned long);
362 unsigned long handler_data;
363 struct completion *completion;
364 int ls_code;
365 int status;
366};
367
368struct zfcp_wka_port {
369 struct zfcp_adapter *adapter;
370 wait_queue_head_t completion_wq;
371 enum zfcp_wka_status status;
372 atomic_t refcount;
373 u32 d_id;
374 u32 handle;
375 struct mutex mutex;
376 struct delayed_work work;
377};
378
379struct zfcp_wka_ports {
380 struct zfcp_wka_port ms; /* management service */
381 struct zfcp_wka_port ts; /* time service */
382 struct zfcp_wka_port ds; /* directory service */
383 struct zfcp_wka_port as; /* alias service */
384 struct zfcp_wka_port ks; /* key distribution service */
385};
386
387struct zfcp_qdio_queue { 132struct zfcp_qdio_queue {
388 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; 133 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
389 u8 first; /* index of next free bfr in queue */ 134 u8 first; /* index of next free bfr in queue */
@@ -446,9 +191,7 @@ struct zfcp_qdio {
446}; 191};
447 192
448struct zfcp_adapter { 193struct zfcp_adapter {
449 atomic_t refcount; /* reference count */ 194 struct kref ref;
450 wait_queue_head_t remove_wq; /* can be used to wait for
451 refcount drop to zero */
452 u64 peer_wwnn; /* P2P peer WWNN */ 195 u64 peer_wwnn; /* P2P peer WWNN */
453 u64 peer_wwpn; /* P2P peer WWPN */ 196 u64 peer_wwpn; /* P2P peer WWPN */
454 u32 peer_d_id; /* P2P peer D_ID */ 197 u32 peer_d_id; /* P2P peer D_ID */
@@ -461,7 +204,8 @@ struct zfcp_adapter {
461 u32 hardware_version; /* of FCP channel */ 204 u32 hardware_version; /* of FCP channel */
462 u16 timer_ticks; /* time int for a tick */ 205 u16 timer_ticks; /* time int for a tick */
463 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */ 206 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
464 struct list_head port_list_head; /* remote port list */ 207 struct list_head port_list; /* remote port list */
208 rwlock_t port_list_lock; /* port list lock */
465 unsigned long req_no; /* unique FSF req number */ 209 unsigned long req_no; /* unique FSF req number */
466 struct list_head *req_list; /* list of pending reqs */ 210 struct list_head *req_list; /* list of pending reqs */
467 spinlock_t req_list_lock; /* request list lock */ 211 spinlock_t req_list_lock; /* request list lock */
@@ -485,7 +229,7 @@ struct zfcp_adapter {
485 u32 erp_low_mem_count; /* nr of erp actions waiting 229 u32 erp_low_mem_count; /* nr of erp actions waiting
486 for memory */ 230 for memory */
487 struct task_struct *erp_thread; 231 struct task_struct *erp_thread;
488 struct zfcp_wka_ports *gs; /* generic services */ 232 struct zfcp_fc_wka_ports *gs; /* generic services */
489 struct zfcp_dbf *dbf; /* debug traces */ 233 struct zfcp_dbf *dbf; /* debug traces */
490 struct zfcp_adapter_mempool pool; /* Adapter memory pools */ 234 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
491 struct fc_host_statistics *fc_stats; 235 struct fc_host_statistics *fc_stats;
@@ -500,11 +244,9 @@ struct zfcp_port {
500 struct device sysfs_device; /* sysfs device */ 244 struct device sysfs_device; /* sysfs device */
501 struct fc_rport *rport; /* rport of fc transport class */ 245 struct fc_rport *rport; /* rport of fc transport class */
502 struct list_head list; /* list of remote ports */ 246 struct list_head list; /* list of remote ports */
503 atomic_t refcount; /* reference count */
504 wait_queue_head_t remove_wq; /* can be used to wait for
505 refcount drop to zero */
506 struct zfcp_adapter *adapter; /* adapter used to access port */ 247 struct zfcp_adapter *adapter; /* adapter used to access port */
507 struct list_head unit_list_head; /* head of logical unit list */ 248 struct list_head unit_list; /* head of logical unit list */
249 rwlock_t unit_list_lock; /* unit list lock */
508 atomic_t status; /* status of this remote port */ 250 atomic_t status; /* status of this remote port */
509 u64 wwnn; /* WWNN if known */ 251 u64 wwnn; /* WWNN if known */
510 u64 wwpn; /* WWPN */ 252 u64 wwpn; /* WWPN */
@@ -523,9 +265,6 @@ struct zfcp_port {
523struct zfcp_unit { 265struct zfcp_unit {
524 struct device sysfs_device; /* sysfs device */ 266 struct device sysfs_device; /* sysfs device */
525 struct list_head list; /* list of logical units */ 267 struct list_head list; /* list of logical units */
526 atomic_t refcount; /* reference count */
527 wait_queue_head_t remove_wq; /* can be used to wait for
528 refcount drop to zero */
529 struct zfcp_port *port; /* remote port of unit */ 268 struct zfcp_port *port; /* remote port of unit */
530 atomic_t status; /* status of this logical unit */ 269 atomic_t status; /* status of this logical unit */
531 u64 fcp_lun; /* own FCP_LUN */ 270 u64 fcp_lun; /* own FCP_LUN */
@@ -601,14 +340,11 @@ struct zfcp_fsf_req {
601struct zfcp_data { 340struct zfcp_data {
602 struct scsi_host_template scsi_host_template; 341 struct scsi_host_template scsi_host_template;
603 struct scsi_transport_template *scsi_transport_template; 342 struct scsi_transport_template *scsi_transport_template;
604 rwlock_t config_lock; /* serialises changes
605 to adapter/port/unit
606 lists */
607 struct mutex config_mutex;
608 struct kmem_cache *gpn_ft_cache; 343 struct kmem_cache *gpn_ft_cache;
609 struct kmem_cache *qtcb_cache; 344 struct kmem_cache *qtcb_cache;
610 struct kmem_cache *sr_buffer_cache; 345 struct kmem_cache *sr_buffer_cache;
611 struct kmem_cache *gid_pn_cache; 346 struct kmem_cache *gid_pn_cache;
347 struct kmem_cache *adisc_cache;
612}; 348};
613 349
614/********************** ZFCP SPECIFIC DEFINES ********************************/ 350/********************** ZFCP SPECIFIC DEFINES ********************************/
@@ -657,47 +393,4 @@ zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
657 return NULL; 393 return NULL;
658} 394}
659 395
660/*
661 * functions needed for reference/usage counting
662 */
663
664static inline void
665zfcp_unit_get(struct zfcp_unit *unit)
666{
667 atomic_inc(&unit->refcount);
668}
669
670static inline void
671zfcp_unit_put(struct zfcp_unit *unit)
672{
673 if (atomic_dec_return(&unit->refcount) == 0)
674 wake_up(&unit->remove_wq);
675}
676
677static inline void
678zfcp_port_get(struct zfcp_port *port)
679{
680 atomic_inc(&port->refcount);
681}
682
683static inline void
684zfcp_port_put(struct zfcp_port *port)
685{
686 if (atomic_dec_return(&port->refcount) == 0)
687 wake_up(&port->remove_wq);
688}
689
690static inline void
691zfcp_adapter_get(struct zfcp_adapter *adapter)
692{
693 atomic_inc(&adapter->refcount);
694}
695
696static inline void
697zfcp_adapter_put(struct zfcp_adapter *adapter)
698{
699 if (atomic_dec_return(&adapter->refcount) == 0)
700 wake_up(&adapter->remove_wq);
701}
702
703#endif /* ZFCP_DEF_H */ 396#endif /* ZFCP_DEF_H */
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index f73e2180f333..b51a11a82e63 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -99,9 +99,12 @@ static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
99 99
100 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE) 100 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
101 zfcp_erp_action_dismiss(&port->erp_action); 101 zfcp_erp_action_dismiss(&port->erp_action);
102 else 102 else {
103 list_for_each_entry(unit, &port->unit_list_head, list) 103 read_lock(&port->unit_list_lock);
104 zfcp_erp_action_dismiss_unit(unit); 104 list_for_each_entry(unit, &port->unit_list, list)
105 zfcp_erp_action_dismiss_unit(unit);
106 read_unlock(&port->unit_list_lock);
107 }
105} 108}
106 109
107static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter) 110static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
@@ -110,9 +113,12 @@ static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
110 113
111 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE) 114 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
112 zfcp_erp_action_dismiss(&adapter->erp_action); 115 zfcp_erp_action_dismiss(&adapter->erp_action);
113 else 116 else {
114 list_for_each_entry(port, &adapter->port_list_head, list) 117 read_lock(&adapter->port_list_lock);
118 list_for_each_entry(port, &adapter->port_list, list)
115 zfcp_erp_action_dismiss_port(port); 119 zfcp_erp_action_dismiss_port(port);
120 read_unlock(&adapter->port_list_lock);
121 }
116} 122}
117 123
118static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter, 124static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
@@ -168,7 +174,8 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
168 174
169 switch (need) { 175 switch (need) {
170 case ZFCP_ERP_ACTION_REOPEN_UNIT: 176 case ZFCP_ERP_ACTION_REOPEN_UNIT:
171 zfcp_unit_get(unit); 177 if (!get_device(&unit->sysfs_device))
178 return NULL;
172 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status); 179 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
173 erp_action = &unit->erp_action; 180 erp_action = &unit->erp_action;
174 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING)) 181 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
@@ -177,7 +184,8 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
177 184
178 case ZFCP_ERP_ACTION_REOPEN_PORT: 185 case ZFCP_ERP_ACTION_REOPEN_PORT:
179 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: 186 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
180 zfcp_port_get(port); 187 if (!get_device(&port->sysfs_device))
188 return NULL;
181 zfcp_erp_action_dismiss_port(port); 189 zfcp_erp_action_dismiss_port(port);
182 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status); 190 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
183 erp_action = &port->erp_action; 191 erp_action = &port->erp_action;
@@ -186,7 +194,7 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
186 break; 194 break;
187 195
188 case ZFCP_ERP_ACTION_REOPEN_ADAPTER: 196 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
189 zfcp_adapter_get(adapter); 197 kref_get(&adapter->ref);
190 zfcp_erp_action_dismiss_adapter(adapter); 198 zfcp_erp_action_dismiss_adapter(adapter);
191 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status); 199 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
192 erp_action = &adapter->erp_action; 200 erp_action = &adapter->erp_action;
@@ -264,11 +272,16 @@ void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
264{ 272{
265 unsigned long flags; 273 unsigned long flags;
266 274
267 read_lock_irqsave(&zfcp_data.config_lock, flags); 275 zfcp_erp_adapter_block(adapter, clear);
268 write_lock(&adapter->erp_lock); 276 zfcp_scsi_schedule_rports_block(adapter);
269 _zfcp_erp_adapter_reopen(adapter, clear, id, ref); 277
270 write_unlock(&adapter->erp_lock); 278 write_lock_irqsave(&adapter->erp_lock, flags);
271 read_unlock_irqrestore(&zfcp_data.config_lock, flags); 279 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
280 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
281 else
282 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, adapter,
283 NULL, NULL, id, ref);
284 write_unlock_irqrestore(&adapter->erp_lock, flags);
272} 285}
273 286
274/** 287/**
@@ -345,11 +358,9 @@ void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
345 unsigned long flags; 358 unsigned long flags;
346 struct zfcp_adapter *adapter = port->adapter; 359 struct zfcp_adapter *adapter = port->adapter;
347 360
348 read_lock_irqsave(&zfcp_data.config_lock, flags); 361 write_lock_irqsave(&adapter->erp_lock, flags);
349 write_lock(&adapter->erp_lock);
350 _zfcp_erp_port_forced_reopen(port, clear, id, ref); 362 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
351 write_unlock(&adapter->erp_lock); 363 write_unlock_irqrestore(&adapter->erp_lock, flags);
352 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
353} 364}
354 365
355static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, 366static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
@@ -377,15 +388,13 @@ static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
377 */ 388 */
378int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref) 389int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
379{ 390{
380 unsigned long flags;
381 int retval; 391 int retval;
392 unsigned long flags;
382 struct zfcp_adapter *adapter = port->adapter; 393 struct zfcp_adapter *adapter = port->adapter;
383 394
384 read_lock_irqsave(&zfcp_data.config_lock, flags); 395 write_lock_irqsave(&adapter->erp_lock, flags);
385 write_lock(&adapter->erp_lock);
386 retval = _zfcp_erp_port_reopen(port, clear, id, ref); 396 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
387 write_unlock(&adapter->erp_lock); 397 write_unlock_irqrestore(&adapter->erp_lock, flags);
388 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
389 398
390 return retval; 399 return retval;
391} 400}
@@ -424,11 +433,9 @@ void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
424 struct zfcp_port *port = unit->port; 433 struct zfcp_port *port = unit->port;
425 struct zfcp_adapter *adapter = port->adapter; 434 struct zfcp_adapter *adapter = port->adapter;
426 435
427 read_lock_irqsave(&zfcp_data.config_lock, flags); 436 write_lock_irqsave(&adapter->erp_lock, flags);
428 write_lock(&adapter->erp_lock);
429 _zfcp_erp_unit_reopen(unit, clear, id, ref); 437 _zfcp_erp_unit_reopen(unit, clear, id, ref);
430 write_unlock(&adapter->erp_lock); 438 write_unlock_irqrestore(&adapter->erp_lock, flags);
431 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
432} 439}
433 440
434static int status_change_set(unsigned long mask, atomic_t *status) 441static int status_change_set(unsigned long mask, atomic_t *status)
@@ -540,8 +547,10 @@ static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
540{ 547{
541 struct zfcp_port *port; 548 struct zfcp_port *port;
542 549
543 list_for_each_entry(port, &adapter->port_list_head, list) 550 read_lock(&adapter->port_list_lock);
551 list_for_each_entry(port, &adapter->port_list, list)
544 _zfcp_erp_port_reopen(port, clear, id, ref); 552 _zfcp_erp_port_reopen(port, clear, id, ref);
553 read_unlock(&adapter->port_list_lock);
545} 554}
546 555
547static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, 556static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
@@ -549,8 +558,10 @@ static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
549{ 558{
550 struct zfcp_unit *unit; 559 struct zfcp_unit *unit;
551 560
552 list_for_each_entry(unit, &port->unit_list_head, list) 561 read_lock(&port->unit_list_lock);
562 list_for_each_entry(unit, &port->unit_list, list)
553 _zfcp_erp_unit_reopen(unit, clear, id, ref); 563 _zfcp_erp_unit_reopen(unit, clear, id, ref);
564 read_unlock(&port->unit_list_lock);
554} 565}
555 566
556static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act) 567static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
@@ -590,16 +601,14 @@ static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
590{ 601{
591 unsigned long flags; 602 unsigned long flags;
592 603
593 read_lock_irqsave(&zfcp_data.config_lock, flags); 604 read_lock_irqsave(&adapter->erp_lock, flags);
594 read_lock(&adapter->erp_lock);
595 if (list_empty(&adapter->erp_ready_head) && 605 if (list_empty(&adapter->erp_ready_head) &&
596 list_empty(&adapter->erp_running_head)) { 606 list_empty(&adapter->erp_running_head)) {
597 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, 607 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
598 &adapter->status); 608 &adapter->status);
599 wake_up(&adapter->erp_done_wqh); 609 wake_up(&adapter->erp_done_wqh);
600 } 610 }
601 read_unlock(&adapter->erp_lock); 611 read_unlock_irqrestore(&adapter->erp_lock, flags);
602 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
603} 612}
604 613
605static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act) 614static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
@@ -1170,28 +1179,28 @@ static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
1170 switch (act->action) { 1179 switch (act->action) {
1171 case ZFCP_ERP_ACTION_REOPEN_UNIT: 1180 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1172 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) { 1181 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
1173 zfcp_unit_get(unit); 1182 get_device(&unit->sysfs_device);
1174 if (scsi_queue_work(unit->port->adapter->scsi_host, 1183 if (scsi_queue_work(unit->port->adapter->scsi_host,
1175 &unit->scsi_work) <= 0) 1184 &unit->scsi_work) <= 0)
1176 zfcp_unit_put(unit); 1185 put_device(&unit->sysfs_device);
1177 } 1186 }
1178 zfcp_unit_put(unit); 1187 put_device(&unit->sysfs_device);
1179 break; 1188 break;
1180 1189
1181 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: 1190 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1182 case ZFCP_ERP_ACTION_REOPEN_PORT: 1191 case ZFCP_ERP_ACTION_REOPEN_PORT:
1183 if (result == ZFCP_ERP_SUCCEEDED) 1192 if (result == ZFCP_ERP_SUCCEEDED)
1184 zfcp_scsi_schedule_rport_register(port); 1193 zfcp_scsi_schedule_rport_register(port);
1185 zfcp_port_put(port); 1194 put_device(&port->sysfs_device);
1186 break; 1195 break;
1187 1196
1188 case ZFCP_ERP_ACTION_REOPEN_ADAPTER: 1197 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1189 if (result == ZFCP_ERP_SUCCEEDED) { 1198 if (result == ZFCP_ERP_SUCCEEDED) {
1190 register_service_level(&adapter->service_level); 1199 register_service_level(&adapter->service_level);
1191 schedule_work(&adapter->scan_work); 1200 queue_work(adapter->work_queue, &adapter->scan_work);
1192 } else 1201 } else
1193 unregister_service_level(&adapter->service_level); 1202 unregister_service_level(&adapter->service_level);
1194 zfcp_adapter_put(adapter); 1203 kref_put(&adapter->ref, zfcp_adapter_release);
1195 break; 1204 break;
1196 } 1205 }
1197} 1206}
@@ -1214,12 +1223,12 @@ static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1214static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action) 1223static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1215{ 1224{
1216 int retval; 1225 int retval;
1217 struct zfcp_adapter *adapter = erp_action->adapter;
1218 unsigned long flags; 1226 unsigned long flags;
1227 struct zfcp_adapter *adapter = erp_action->adapter;
1219 1228
1220 read_lock_irqsave(&zfcp_data.config_lock, flags); 1229 kref_get(&adapter->ref);
1221 write_lock(&adapter->erp_lock);
1222 1230
1231 write_lock_irqsave(&adapter->erp_lock, flags);
1223 zfcp_erp_strategy_check_fsfreq(erp_action); 1232 zfcp_erp_strategy_check_fsfreq(erp_action);
1224 1233
1225 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) { 1234 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
@@ -1231,11 +1240,9 @@ static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1231 zfcp_erp_action_to_running(erp_action); 1240 zfcp_erp_action_to_running(erp_action);
1232 1241
1233 /* no lock to allow for blocking operations */ 1242 /* no lock to allow for blocking operations */
1234 write_unlock(&adapter->erp_lock); 1243 write_unlock_irqrestore(&adapter->erp_lock, flags);
1235 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1236 retval = zfcp_erp_strategy_do_action(erp_action); 1244 retval = zfcp_erp_strategy_do_action(erp_action);
1237 read_lock_irqsave(&zfcp_data.config_lock, flags); 1245 write_lock_irqsave(&adapter->erp_lock, flags);
1238 write_lock(&adapter->erp_lock);
1239 1246
1240 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) 1247 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1241 retval = ZFCP_ERP_CONTINUES; 1248 retval = ZFCP_ERP_CONTINUES;
@@ -1273,12 +1280,12 @@ static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1273 zfcp_erp_strategy_followup_failed(erp_action); 1280 zfcp_erp_strategy_followup_failed(erp_action);
1274 1281
1275 unlock: 1282 unlock:
1276 write_unlock(&adapter->erp_lock); 1283 write_unlock_irqrestore(&adapter->erp_lock, flags);
1277 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1278 1284
1279 if (retval != ZFCP_ERP_CONTINUES) 1285 if (retval != ZFCP_ERP_CONTINUES)
1280 zfcp_erp_action_cleanup(erp_action, retval); 1286 zfcp_erp_action_cleanup(erp_action, retval);
1281 1287
1288 kref_put(&adapter->ref, zfcp_adapter_release);
1282 return retval; 1289 return retval;
1283} 1290}
1284 1291
@@ -1415,6 +1422,7 @@ void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
1415 void *ref, u32 mask, int set_or_clear) 1422 void *ref, u32 mask, int set_or_clear)
1416{ 1423{
1417 struct zfcp_port *port; 1424 struct zfcp_port *port;
1425 unsigned long flags;
1418 u32 common_mask = mask & ZFCP_COMMON_FLAGS; 1426 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1419 1427
1420 if (set_or_clear == ZFCP_SET) { 1428 if (set_or_clear == ZFCP_SET) {
@@ -1429,10 +1437,13 @@ void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
1429 atomic_set(&adapter->erp_counter, 0); 1437 atomic_set(&adapter->erp_counter, 0);
1430 } 1438 }
1431 1439
1432 if (common_mask) 1440 if (common_mask) {
1433 list_for_each_entry(port, &adapter->port_list_head, list) 1441 read_lock_irqsave(&adapter->port_list_lock, flags);
1442 list_for_each_entry(port, &adapter->port_list, list)
1434 zfcp_erp_modify_port_status(port, id, ref, common_mask, 1443 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1435 set_or_clear); 1444 set_or_clear);
1445 read_unlock_irqrestore(&adapter->port_list_lock, flags);
1446 }
1436} 1447}
1437 1448
1438/** 1449/**
@@ -1449,6 +1460,7 @@ void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
1449 u32 mask, int set_or_clear) 1460 u32 mask, int set_or_clear)
1450{ 1461{
1451 struct zfcp_unit *unit; 1462 struct zfcp_unit *unit;
1463 unsigned long flags;
1452 u32 common_mask = mask & ZFCP_COMMON_FLAGS; 1464 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1453 1465
1454 if (set_or_clear == ZFCP_SET) { 1466 if (set_or_clear == ZFCP_SET) {
@@ -1463,10 +1475,13 @@ void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
1463 atomic_set(&port->erp_counter, 0); 1475 atomic_set(&port->erp_counter, 0);
1464 } 1476 }
1465 1477
1466 if (common_mask) 1478 if (common_mask) {
1467 list_for_each_entry(unit, &port->unit_list_head, list) 1479 read_lock_irqsave(&port->unit_list_lock, flags);
1480 list_for_each_entry(unit, &port->unit_list, list)
1468 zfcp_erp_modify_unit_status(unit, id, ref, common_mask, 1481 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1469 set_or_clear); 1482 set_or_clear);
1483 read_unlock_irqrestore(&port->unit_list_lock, flags);
1484 }
1470} 1485}
1471 1486
1472/** 1487/**
@@ -1502,12 +1517,8 @@ void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
1502 */ 1517 */
1503void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref) 1518void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
1504{ 1519{
1505 unsigned long flags;
1506
1507 read_lock_irqsave(&zfcp_data.config_lock, flags);
1508 zfcp_erp_modify_port_status(port, id, ref, 1520 zfcp_erp_modify_port_status(port, id, ref,
1509 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET); 1521 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1510 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1511 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); 1522 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1512} 1523}
1513 1524
@@ -1535,13 +1546,9 @@ void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
1535 */ 1546 */
1536void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref) 1547void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
1537{ 1548{
1538 unsigned long flags;
1539
1540 read_lock_irqsave(&zfcp_data.config_lock, flags);
1541 zfcp_erp_modify_port_status(port, id, ref, 1549 zfcp_erp_modify_port_status(port, id, ref,
1542 ZFCP_STATUS_COMMON_ERP_FAILED | 1550 ZFCP_STATUS_COMMON_ERP_FAILED |
1543 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET); 1551 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1544 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1545} 1552}
1546 1553
1547/** 1554/**
@@ -1574,12 +1581,15 @@ static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
1574 void *ref) 1581 void *ref)
1575{ 1582{
1576 struct zfcp_unit *unit; 1583 struct zfcp_unit *unit;
1584 unsigned long flags;
1577 int status = atomic_read(&port->status); 1585 int status = atomic_read(&port->status);
1578 1586
1579 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED | 1587 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1580 ZFCP_STATUS_COMMON_ACCESS_BOXED))) { 1588 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
1581 list_for_each_entry(unit, &port->unit_list_head, list) 1589 read_lock_irqsave(&port->unit_list_lock, flags);
1590 list_for_each_entry(unit, &port->unit_list, list)
1582 zfcp_erp_unit_access_changed(unit, id, ref); 1591 zfcp_erp_unit_access_changed(unit, id, ref);
1592 read_unlock_irqrestore(&port->unit_list_lock, flags);
1583 return; 1593 return;
1584 } 1594 }
1585 1595
@@ -1595,14 +1605,14 @@ static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
1595void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id, 1605void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
1596 void *ref) 1606 void *ref)
1597{ 1607{
1598 struct zfcp_port *port;
1599 unsigned long flags; 1608 unsigned long flags;
1609 struct zfcp_port *port;
1600 1610
1601 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) 1611 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1602 return; 1612 return;
1603 1613
1604 read_lock_irqsave(&zfcp_data.config_lock, flags); 1614 read_lock_irqsave(&adapter->port_list_lock, flags);
1605 list_for_each_entry(port, &adapter->port_list_head, list) 1615 list_for_each_entry(port, &adapter->port_list, list)
1606 zfcp_erp_port_access_changed(port, id, ref); 1616 zfcp_erp_port_access_changed(port, id, ref);
1607 read_unlock_irqrestore(&zfcp_data.config_lock, flags); 1617 read_unlock_irqrestore(&adapter->port_list_lock, flags);
1608} 1618}
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index b3f28deb4505..03dec832b465 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -9,26 +9,31 @@
9#ifndef ZFCP_EXT_H 9#ifndef ZFCP_EXT_H
10#define ZFCP_EXT_H 10#define ZFCP_EXT_H
11 11
12#include <linux/types.h>
13#include <scsi/fc/fc_els.h>
12#include "zfcp_def.h" 14#include "zfcp_def.h"
15#include "zfcp_fc.h"
13 16
14/* zfcp_aux.c */ 17/* zfcp_aux.c */
15extern struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *, u64); 18extern struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *, u64);
16extern struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *, u64); 19extern struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *, u64);
17extern int zfcp_adapter_enqueue(struct ccw_device *); 20extern struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *);
18extern void zfcp_adapter_dequeue(struct zfcp_adapter *);
19extern struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *, u64, u32, 21extern struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *, u64, u32,
20 u32); 22 u32);
21extern void zfcp_port_dequeue(struct zfcp_port *);
22extern struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *, u64); 23extern struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *, u64);
23extern void zfcp_unit_dequeue(struct zfcp_unit *);
24extern int zfcp_reqlist_isempty(struct zfcp_adapter *); 24extern int zfcp_reqlist_isempty(struct zfcp_adapter *);
25extern void zfcp_sg_free_table(struct scatterlist *, int); 25extern void zfcp_sg_free_table(struct scatterlist *, int);
26extern int zfcp_sg_setup_table(struct scatterlist *, int); 26extern int zfcp_sg_setup_table(struct scatterlist *, int);
27extern void zfcp_device_unregister(struct device *,
28 const struct attribute_group *);
29extern void zfcp_adapter_release(struct kref *);
30extern void zfcp_adapter_unregister(struct zfcp_adapter *);
27 31
28/* zfcp_ccw.c */ 32/* zfcp_ccw.c */
29extern int zfcp_ccw_register(void);
30extern int zfcp_ccw_priv_sch(struct zfcp_adapter *); 33extern int zfcp_ccw_priv_sch(struct zfcp_adapter *);
31extern struct ccw_driver zfcp_ccw_driver; 34extern struct ccw_driver zfcp_ccw_driver;
35extern struct zfcp_adapter *zfcp_ccw_adapter_by_cdev(struct ccw_device *);
36extern void zfcp_ccw_adapter_put(struct zfcp_adapter *);
32 37
33/* zfcp_cfdc.c */ 38/* zfcp_cfdc.c */
34extern struct miscdevice zfcp_cfdc_misc; 39extern struct miscdevice zfcp_cfdc_misc;
@@ -51,7 +56,7 @@ extern void _zfcp_dbf_hba_fsf_unsol(const char *, int level, struct zfcp_dbf *,
51 struct fsf_status_read_buffer *); 56 struct fsf_status_read_buffer *);
52extern void zfcp_dbf_hba_qdio(struct zfcp_dbf *, unsigned int, int, int); 57extern void zfcp_dbf_hba_qdio(struct zfcp_dbf *, unsigned int, int, int);
53extern void zfcp_dbf_hba_berr(struct zfcp_dbf *, struct zfcp_fsf_req *); 58extern void zfcp_dbf_hba_berr(struct zfcp_dbf *, struct zfcp_fsf_req *);
54extern void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *); 59extern void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *, u32);
55extern void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *); 60extern void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *);
56extern void zfcp_dbf_san_els_request(struct zfcp_fsf_req *); 61extern void zfcp_dbf_san_els_request(struct zfcp_fsf_req *);
57extern void zfcp_dbf_san_els_response(struct zfcp_fsf_req *); 62extern void zfcp_dbf_san_els_response(struct zfcp_fsf_req *);
@@ -92,24 +97,22 @@ extern void zfcp_erp_adapter_access_changed(struct zfcp_adapter *, char *,
92extern void zfcp_erp_timeout_handler(unsigned long); 97extern void zfcp_erp_timeout_handler(unsigned long);
93 98
94/* zfcp_fc.c */ 99/* zfcp_fc.c */
95extern int zfcp_fc_scan_ports(struct zfcp_adapter *); 100extern void zfcp_fc_scan_ports(struct work_struct *);
96extern void _zfcp_fc_scan_ports_later(struct work_struct *);
97extern void zfcp_fc_incoming_els(struct zfcp_fsf_req *); 101extern void zfcp_fc_incoming_els(struct zfcp_fsf_req *);
98extern void zfcp_fc_port_did_lookup(struct work_struct *); 102extern void zfcp_fc_port_did_lookup(struct work_struct *);
99extern void zfcp_fc_trigger_did_lookup(struct zfcp_port *); 103extern void zfcp_fc_trigger_did_lookup(struct zfcp_port *);
100extern void zfcp_fc_plogi_evaluate(struct zfcp_port *, struct fsf_plogi *); 104extern void zfcp_fc_plogi_evaluate(struct zfcp_port *, struct fc_els_flogi *);
101extern void zfcp_fc_test_link(struct zfcp_port *); 105extern void zfcp_fc_test_link(struct zfcp_port *);
102extern void zfcp_fc_link_test_work(struct work_struct *); 106extern void zfcp_fc_link_test_work(struct work_struct *);
103extern void zfcp_fc_wka_ports_force_offline(struct zfcp_wka_ports *); 107extern void zfcp_fc_wka_ports_force_offline(struct zfcp_fc_wka_ports *);
104extern int zfcp_fc_gs_setup(struct zfcp_adapter *); 108extern int zfcp_fc_gs_setup(struct zfcp_adapter *);
105extern void zfcp_fc_gs_destroy(struct zfcp_adapter *); 109extern void zfcp_fc_gs_destroy(struct zfcp_adapter *);
106extern int zfcp_fc_execute_els_fc_job(struct fc_bsg_job *); 110extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *);
107extern int zfcp_fc_execute_ct_fc_job(struct fc_bsg_job *);
108 111
109/* zfcp_fsf.c */ 112/* zfcp_fsf.c */
110extern int zfcp_fsf_open_port(struct zfcp_erp_action *); 113extern int zfcp_fsf_open_port(struct zfcp_erp_action *);
111extern int zfcp_fsf_open_wka_port(struct zfcp_wka_port *); 114extern int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *);
112extern int zfcp_fsf_close_wka_port(struct zfcp_wka_port *); 115extern int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *);
113extern int zfcp_fsf_close_port(struct zfcp_erp_action *); 116extern int zfcp_fsf_close_port(struct zfcp_erp_action *);
114extern int zfcp_fsf_close_physical_port(struct zfcp_erp_action *); 117extern int zfcp_fsf_close_physical_port(struct zfcp_erp_action *);
115extern int zfcp_fsf_open_unit(struct zfcp_erp_action *); 118extern int zfcp_fsf_open_unit(struct zfcp_erp_action *);
@@ -125,8 +128,10 @@ extern struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *,
125extern void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *); 128extern void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *);
126extern int zfcp_fsf_status_read(struct zfcp_qdio *); 129extern int zfcp_fsf_status_read(struct zfcp_qdio *);
127extern int zfcp_status_read_refill(struct zfcp_adapter *adapter); 130extern int zfcp_status_read_refill(struct zfcp_adapter *adapter);
128extern int zfcp_fsf_send_ct(struct zfcp_send_ct *, mempool_t *); 131extern int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *, struct zfcp_fsf_ct_els *,
129extern int zfcp_fsf_send_els(struct zfcp_send_els *); 132 mempool_t *);
133extern int zfcp_fsf_send_els(struct zfcp_adapter *, u32,
134 struct zfcp_fsf_ct_els *);
130extern int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *, 135extern int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *,
131 struct scsi_cmnd *); 136 struct scsi_cmnd *);
132extern void zfcp_fsf_req_free(struct zfcp_fsf_req *); 137extern void zfcp_fsf_req_free(struct zfcp_fsf_req *);
@@ -153,7 +158,6 @@ extern void zfcp_qdio_close(struct zfcp_qdio *);
153extern struct zfcp_data zfcp_data; 158extern struct zfcp_data zfcp_data;
154extern int zfcp_adapter_scsi_register(struct zfcp_adapter *); 159extern int zfcp_adapter_scsi_register(struct zfcp_adapter *);
155extern void zfcp_adapter_scsi_unregister(struct zfcp_adapter *); 160extern void zfcp_adapter_scsi_unregister(struct zfcp_adapter *);
156extern char *zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *);
157extern struct fc_function_template zfcp_transport_functions; 161extern struct fc_function_template zfcp_transport_functions;
158extern void zfcp_scsi_rport_work(struct work_struct *); 162extern void zfcp_scsi_rport_work(struct work_struct *);
159extern void zfcp_scsi_schedule_rport_register(struct zfcp_port *); 163extern void zfcp_scsi_schedule_rport_register(struct zfcp_port *);
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index df23bcead23d..ac5e3b7a3576 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -9,73 +9,38 @@
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_els.h>
14#include <scsi/libfc.h>
12#include "zfcp_ext.h" 15#include "zfcp_ext.h"
16#include "zfcp_fc.h"
13 17
14enum rscn_address_format { 18static u32 zfcp_fc_rscn_range_mask[] = {
15 RSCN_PORT_ADDRESS = 0x0, 19 [ELS_ADDR_FMT_PORT] = 0xFFFFFF,
16 RSCN_AREA_ADDRESS = 0x1, 20 [ELS_ADDR_FMT_AREA] = 0xFFFF00,
17 RSCN_DOMAIN_ADDRESS = 0x2, 21 [ELS_ADDR_FMT_DOM] = 0xFF0000,
18 RSCN_FABRIC_ADDRESS = 0x3, 22 [ELS_ADDR_FMT_FAB] = 0x000000,
19}; 23};
20 24
21static u32 rscn_range_mask[] = { 25static int zfcp_fc_wka_port_get(struct zfcp_fc_wka_port *wka_port)
22 [RSCN_PORT_ADDRESS] = 0xFFFFFF,
23 [RSCN_AREA_ADDRESS] = 0xFFFF00,
24 [RSCN_DOMAIN_ADDRESS] = 0xFF0000,
25 [RSCN_FABRIC_ADDRESS] = 0x000000,
26};
27
28struct gpn_ft_resp_acc {
29 u8 control;
30 u8 port_id[3];
31 u8 reserved[4];
32 u64 wwpn;
33} __attribute__ ((packed));
34
35#define ZFCP_CT_SIZE_ONE_PAGE (PAGE_SIZE - sizeof(struct ct_hdr))
36#define ZFCP_GPN_FT_ENTRIES (ZFCP_CT_SIZE_ONE_PAGE \
37 / sizeof(struct gpn_ft_resp_acc))
38#define ZFCP_GPN_FT_BUFFERS 4
39#define ZFCP_GPN_FT_MAX_SIZE (ZFCP_GPN_FT_BUFFERS * PAGE_SIZE \
40 - sizeof(struct ct_hdr))
41#define ZFCP_GPN_FT_MAX_ENTRIES ZFCP_GPN_FT_BUFFERS * (ZFCP_GPN_FT_ENTRIES + 1)
42
43struct ct_iu_gpn_ft_resp {
44 struct ct_hdr header;
45 struct gpn_ft_resp_acc accept[ZFCP_GPN_FT_ENTRIES];
46} __attribute__ ((packed));
47
48struct zfcp_gpn_ft {
49 struct zfcp_send_ct ct;
50 struct scatterlist sg_req;
51 struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS];
52};
53
54struct zfcp_fc_ns_handler_data {
55 struct completion done;
56 void (*handler)(unsigned long);
57 unsigned long handler_data;
58};
59
60static int zfcp_fc_wka_port_get(struct zfcp_wka_port *wka_port)
61{ 26{
62 if (mutex_lock_interruptible(&wka_port->mutex)) 27 if (mutex_lock_interruptible(&wka_port->mutex))
63 return -ERESTARTSYS; 28 return -ERESTARTSYS;
64 29
65 if (wka_port->status == ZFCP_WKA_PORT_OFFLINE || 30 if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE ||
66 wka_port->status == ZFCP_WKA_PORT_CLOSING) { 31 wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) {
67 wka_port->status = ZFCP_WKA_PORT_OPENING; 32 wka_port->status = ZFCP_FC_WKA_PORT_OPENING;
68 if (zfcp_fsf_open_wka_port(wka_port)) 33 if (zfcp_fsf_open_wka_port(wka_port))
69 wka_port->status = ZFCP_WKA_PORT_OFFLINE; 34 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
70 } 35 }
71 36
72 mutex_unlock(&wka_port->mutex); 37 mutex_unlock(&wka_port->mutex);
73 38
74 wait_event(wka_port->completion_wq, 39 wait_event(wka_port->completion_wq,
75 wka_port->status == ZFCP_WKA_PORT_ONLINE || 40 wka_port->status == ZFCP_FC_WKA_PORT_ONLINE ||
76 wka_port->status == ZFCP_WKA_PORT_OFFLINE); 41 wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE);
77 42
78 if (wka_port->status == ZFCP_WKA_PORT_ONLINE) { 43 if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) {
79 atomic_inc(&wka_port->refcount); 44 atomic_inc(&wka_port->refcount);
80 return 0; 45 return 0;
81 } 46 }
@@ -85,24 +50,24 @@ static int zfcp_fc_wka_port_get(struct zfcp_wka_port *wka_port)
85static void zfcp_fc_wka_port_offline(struct work_struct *work) 50static void zfcp_fc_wka_port_offline(struct work_struct *work)
86{ 51{
87 struct delayed_work *dw = to_delayed_work(work); 52 struct delayed_work *dw = to_delayed_work(work);
88 struct zfcp_wka_port *wka_port = 53 struct zfcp_fc_wka_port *wka_port =
89 container_of(dw, struct zfcp_wka_port, work); 54 container_of(dw, struct zfcp_fc_wka_port, work);
90 55
91 mutex_lock(&wka_port->mutex); 56 mutex_lock(&wka_port->mutex);
92 if ((atomic_read(&wka_port->refcount) != 0) || 57 if ((atomic_read(&wka_port->refcount) != 0) ||
93 (wka_port->status != ZFCP_WKA_PORT_ONLINE)) 58 (wka_port->status != ZFCP_FC_WKA_PORT_ONLINE))
94 goto out; 59 goto out;
95 60
96 wka_port->status = ZFCP_WKA_PORT_CLOSING; 61 wka_port->status = ZFCP_FC_WKA_PORT_CLOSING;
97 if (zfcp_fsf_close_wka_port(wka_port)) { 62 if (zfcp_fsf_close_wka_port(wka_port)) {
98 wka_port->status = ZFCP_WKA_PORT_OFFLINE; 63 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
99 wake_up(&wka_port->completion_wq); 64 wake_up(&wka_port->completion_wq);
100 } 65 }
101out: 66out:
102 mutex_unlock(&wka_port->mutex); 67 mutex_unlock(&wka_port->mutex);
103} 68}
104 69
105static void zfcp_fc_wka_port_put(struct zfcp_wka_port *wka_port) 70static void zfcp_fc_wka_port_put(struct zfcp_fc_wka_port *wka_port)
106{ 71{
107 if (atomic_dec_return(&wka_port->refcount) != 0) 72 if (atomic_dec_return(&wka_port->refcount) != 0)
108 return; 73 return;
@@ -110,7 +75,7 @@ static void zfcp_fc_wka_port_put(struct zfcp_wka_port *wka_port)
110 schedule_delayed_work(&wka_port->work, HZ / 100); 75 schedule_delayed_work(&wka_port->work, HZ / 100);
111} 76}
112 77
113static void zfcp_fc_wka_port_init(struct zfcp_wka_port *wka_port, u32 d_id, 78static void zfcp_fc_wka_port_init(struct zfcp_fc_wka_port *wka_port, u32 d_id,
114 struct zfcp_adapter *adapter) 79 struct zfcp_adapter *adapter)
115{ 80{
116 init_waitqueue_head(&wka_port->completion_wq); 81 init_waitqueue_head(&wka_port->completion_wq);
@@ -118,107 +83,107 @@ static void zfcp_fc_wka_port_init(struct zfcp_wka_port *wka_port, u32 d_id,
118 wka_port->adapter = adapter; 83 wka_port->adapter = adapter;
119 wka_port->d_id = d_id; 84 wka_port->d_id = d_id;
120 85
121 wka_port->status = ZFCP_WKA_PORT_OFFLINE; 86 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
122 atomic_set(&wka_port->refcount, 0); 87 atomic_set(&wka_port->refcount, 0);
123 mutex_init(&wka_port->mutex); 88 mutex_init(&wka_port->mutex);
124 INIT_DELAYED_WORK(&wka_port->work, zfcp_fc_wka_port_offline); 89 INIT_DELAYED_WORK(&wka_port->work, zfcp_fc_wka_port_offline);
125} 90}
126 91
127static void zfcp_fc_wka_port_force_offline(struct zfcp_wka_port *wka) 92static void zfcp_fc_wka_port_force_offline(struct zfcp_fc_wka_port *wka)
128{ 93{
129 cancel_delayed_work_sync(&wka->work); 94 cancel_delayed_work_sync(&wka->work);
130 mutex_lock(&wka->mutex); 95 mutex_lock(&wka->mutex);
131 wka->status = ZFCP_WKA_PORT_OFFLINE; 96 wka->status = ZFCP_FC_WKA_PORT_OFFLINE;
132 mutex_unlock(&wka->mutex); 97 mutex_unlock(&wka->mutex);
133} 98}
134 99
135void zfcp_fc_wka_ports_force_offline(struct zfcp_wka_ports *gs) 100void zfcp_fc_wka_ports_force_offline(struct zfcp_fc_wka_ports *gs)
136{ 101{
102 if (!gs)
103 return;
137 zfcp_fc_wka_port_force_offline(&gs->ms); 104 zfcp_fc_wka_port_force_offline(&gs->ms);
138 zfcp_fc_wka_port_force_offline(&gs->ts); 105 zfcp_fc_wka_port_force_offline(&gs->ts);
139 zfcp_fc_wka_port_force_offline(&gs->ds); 106 zfcp_fc_wka_port_force_offline(&gs->ds);
140 zfcp_fc_wka_port_force_offline(&gs->as); 107 zfcp_fc_wka_port_force_offline(&gs->as);
141 zfcp_fc_wka_port_force_offline(&gs->ks);
142} 108}
143 109
144static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, 110static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range,
145 struct fcp_rscn_element *elem) 111 struct fc_els_rscn_page *page)
146{ 112{
147 unsigned long flags; 113 unsigned long flags;
114 struct zfcp_adapter *adapter = fsf_req->adapter;
148 struct zfcp_port *port; 115 struct zfcp_port *port;
149 116
150 read_lock_irqsave(&zfcp_data.config_lock, flags); 117 read_lock_irqsave(&adapter->port_list_lock, flags);
151 list_for_each_entry(port, &fsf_req->adapter->port_list_head, list) { 118 list_for_each_entry(port, &adapter->port_list, list) {
152 if ((port->d_id & range) == (elem->nport_did & range)) 119 if ((port->d_id & range) == (ntoh24(page->rscn_fid) & range))
153 zfcp_fc_test_link(port); 120 zfcp_fc_test_link(port);
154 if (!port->d_id) 121 if (!port->d_id)
155 zfcp_erp_port_reopen(port, 122 zfcp_erp_port_reopen(port,
156 ZFCP_STATUS_COMMON_ERP_FAILED, 123 ZFCP_STATUS_COMMON_ERP_FAILED,
157 "fcrscn1", NULL); 124 "fcrscn1", NULL);
158 } 125 }
159 126 read_unlock_irqrestore(&adapter->port_list_lock, flags);
160 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
161} 127}
162 128
163static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) 129static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req)
164{ 130{
165 struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; 131 struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data;
166 struct fcp_rscn_head *fcp_rscn_head; 132 struct fc_els_rscn *head;
167 struct fcp_rscn_element *fcp_rscn_element; 133 struct fc_els_rscn_page *page;
168 u16 i; 134 u16 i;
169 u16 no_entries; 135 u16 no_entries;
170 u32 range_mask; 136 unsigned int afmt;
171 137
172 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload.data; 138 head = (struct fc_els_rscn *) status_buffer->payload.data;
173 fcp_rscn_element = (struct fcp_rscn_element *) fcp_rscn_head; 139 page = (struct fc_els_rscn_page *) head;
174 140
175 /* see FC-FS */ 141 /* see FC-FS */
176 no_entries = fcp_rscn_head->payload_len / 142 no_entries = head->rscn_plen / sizeof(struct fc_els_rscn_page);
177 sizeof(struct fcp_rscn_element);
178 143
179 for (i = 1; i < no_entries; i++) { 144 for (i = 1; i < no_entries; i++) {
180 /* skip head and start with 1st element */ 145 /* skip head and start with 1st element */
181 fcp_rscn_element++; 146 page++;
182 range_mask = rscn_range_mask[fcp_rscn_element->addr_format]; 147 afmt = page->rscn_page_flags & ELS_RSCN_ADDR_FMT_MASK;
183 _zfcp_fc_incoming_rscn(fsf_req, range_mask, fcp_rscn_element); 148 _zfcp_fc_incoming_rscn(fsf_req, zfcp_fc_rscn_range_mask[afmt],
149 page);
184 } 150 }
185 schedule_work(&fsf_req->adapter->scan_work); 151 queue_work(fsf_req->adapter->work_queue, &fsf_req->adapter->scan_work);
186} 152}
187 153
188static void zfcp_fc_incoming_wwpn(struct zfcp_fsf_req *req, u64 wwpn) 154static void zfcp_fc_incoming_wwpn(struct zfcp_fsf_req *req, u64 wwpn)
189{ 155{
156 unsigned long flags;
190 struct zfcp_adapter *adapter = req->adapter; 157 struct zfcp_adapter *adapter = req->adapter;
191 struct zfcp_port *port; 158 struct zfcp_port *port;
192 unsigned long flags;
193 159
194 read_lock_irqsave(&zfcp_data.config_lock, flags); 160 read_lock_irqsave(&adapter->port_list_lock, flags);
195 list_for_each_entry(port, &adapter->port_list_head, list) 161 list_for_each_entry(port, &adapter->port_list, list)
196 if (port->wwpn == wwpn) 162 if (port->wwpn == wwpn) {
163 zfcp_erp_port_forced_reopen(port, 0, "fciwwp1", req);
197 break; 164 break;
198 read_unlock_irqrestore(&zfcp_data.config_lock, flags); 165 }
199 166 read_unlock_irqrestore(&adapter->port_list_lock, flags);
200 if (port && (port->wwpn == wwpn))
201 zfcp_erp_port_forced_reopen(port, 0, "fciwwp1", req);
202} 167}
203 168
204static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) 169static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req)
205{ 170{
206 struct fsf_status_read_buffer *status_buffer = 171 struct fsf_status_read_buffer *status_buffer;
207 (struct fsf_status_read_buffer *)req->data; 172 struct fc_els_flogi *plogi;
208 struct fsf_plogi *els_plogi =
209 (struct fsf_plogi *) status_buffer->payload.data;
210 173
211 zfcp_fc_incoming_wwpn(req, els_plogi->serv_param.wwpn); 174 status_buffer = (struct fsf_status_read_buffer *) req->data;
175 plogi = (struct fc_els_flogi *) status_buffer->payload.data;
176 zfcp_fc_incoming_wwpn(req, plogi->fl_wwpn);
212} 177}
213 178
214static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) 179static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req)
215{ 180{
216 struct fsf_status_read_buffer *status_buffer = 181 struct fsf_status_read_buffer *status_buffer =
217 (struct fsf_status_read_buffer *)req->data; 182 (struct fsf_status_read_buffer *)req->data;
218 struct fcp_logo *els_logo = 183 struct fc_els_logo *logo =
219 (struct fcp_logo *) status_buffer->payload.data; 184 (struct fc_els_logo *) status_buffer->payload.data;
220 185
221 zfcp_fc_incoming_wwpn(req, els_logo->nport_wwpn); 186 zfcp_fc_incoming_wwpn(req, logo->fl_n_port_wwn);
222} 187}
223 188
224/** 189/**
@@ -232,79 +197,72 @@ void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req)
232 unsigned int els_type = status_buffer->payload.data[0]; 197 unsigned int els_type = status_buffer->payload.data[0];
233 198
234 zfcp_dbf_san_incoming_els(fsf_req); 199 zfcp_dbf_san_incoming_els(fsf_req);
235 if (els_type == LS_PLOGI) 200 if (els_type == ELS_PLOGI)
236 zfcp_fc_incoming_plogi(fsf_req); 201 zfcp_fc_incoming_plogi(fsf_req);
237 else if (els_type == LS_LOGO) 202 else if (els_type == ELS_LOGO)
238 zfcp_fc_incoming_logo(fsf_req); 203 zfcp_fc_incoming_logo(fsf_req);
239 else if (els_type == LS_RSCN) 204 else if (els_type == ELS_RSCN)
240 zfcp_fc_incoming_rscn(fsf_req); 205 zfcp_fc_incoming_rscn(fsf_req);
241} 206}
242 207
243static void zfcp_fc_ns_handler(unsigned long data) 208static void zfcp_fc_ns_gid_pn_eval(void *data)
244{ 209{
245 struct zfcp_fc_ns_handler_data *compl_rec = 210 struct zfcp_fc_gid_pn *gid_pn = data;
246 (struct zfcp_fc_ns_handler_data *) data; 211 struct zfcp_fsf_ct_els *ct = &gid_pn->ct;
247 212 struct zfcp_fc_gid_pn_req *gid_pn_req = sg_virt(ct->req);
248 if (compl_rec->handler) 213 struct zfcp_fc_gid_pn_resp *gid_pn_resp = sg_virt(ct->resp);
249 compl_rec->handler(compl_rec->handler_data);
250
251 complete(&compl_rec->done);
252}
253
254static void zfcp_fc_ns_gid_pn_eval(unsigned long data)
255{
256 struct zfcp_gid_pn_data *gid_pn = (struct zfcp_gid_pn_data *) data;
257 struct zfcp_send_ct *ct = &gid_pn->ct;
258 struct ct_iu_gid_pn_req *ct_iu_req = sg_virt(ct->req);
259 struct ct_iu_gid_pn_resp *ct_iu_resp = sg_virt(ct->resp);
260 struct zfcp_port *port = gid_pn->port; 214 struct zfcp_port *port = gid_pn->port;
261 215
262 if (ct->status) 216 if (ct->status)
263 return; 217 return;
264 if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) 218 if (gid_pn_resp->ct_hdr.ct_cmd != FC_FS_ACC)
265 return; 219 return;
266 220
267 /* paranoia */ 221 /* paranoia */
268 if (ct_iu_req->wwpn != port->wwpn) 222 if (gid_pn_req->gid_pn.fn_wwpn != port->wwpn)
269 return; 223 return;
270 /* looks like a valid d_id */ 224 /* looks like a valid d_id */
271 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK; 225 port->d_id = ntoh24(gid_pn_resp->gid_pn.fp_fid);
226}
227
228static void zfcp_fc_complete(void *data)
229{
230 complete(data);
272} 231}
273 232
274static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port, 233static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port,
275 struct zfcp_gid_pn_data *gid_pn) 234 struct zfcp_fc_gid_pn *gid_pn)
276{ 235{
277 struct zfcp_adapter *adapter = port->adapter; 236 struct zfcp_adapter *adapter = port->adapter;
278 struct zfcp_fc_ns_handler_data compl_rec; 237 DECLARE_COMPLETION_ONSTACK(completion);
279 int ret; 238 int ret;
280 239
281 /* setup parameters for send generic command */ 240 /* setup parameters for send generic command */
282 gid_pn->port = port; 241 gid_pn->port = port;
283 gid_pn->ct.wka_port = &adapter->gs->ds; 242 gid_pn->ct.handler = zfcp_fc_complete;
284 gid_pn->ct.handler = zfcp_fc_ns_handler; 243 gid_pn->ct.handler_data = &completion;
285 gid_pn->ct.handler_data = (unsigned long) &compl_rec; 244 gid_pn->ct.req = &gid_pn->sg_req;
286 gid_pn->ct.req = &gid_pn->req; 245 gid_pn->ct.resp = &gid_pn->sg_resp;
287 gid_pn->ct.resp = &gid_pn->resp; 246 sg_init_one(&gid_pn->sg_req, &gid_pn->gid_pn_req,
288 sg_init_one(&gid_pn->req, &gid_pn->ct_iu_req, 247 sizeof(struct zfcp_fc_gid_pn_req));
289 sizeof(struct ct_iu_gid_pn_req)); 248 sg_init_one(&gid_pn->sg_resp, &gid_pn->gid_pn_resp,
290 sg_init_one(&gid_pn->resp, &gid_pn->ct_iu_resp, 249 sizeof(struct zfcp_fc_gid_pn_resp));
291 sizeof(struct ct_iu_gid_pn_resp));
292 250
293 /* setup nameserver request */ 251 /* setup nameserver request */
294 gid_pn->ct_iu_req.header.revision = ZFCP_CT_REVISION; 252 gid_pn->gid_pn_req.ct_hdr.ct_rev = FC_CT_REV;
295 gid_pn->ct_iu_req.header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; 253 gid_pn->gid_pn_req.ct_hdr.ct_fs_type = FC_FST_DIR;
296 gid_pn->ct_iu_req.header.gs_subtype = ZFCP_CT_NAME_SERVER; 254 gid_pn->gid_pn_req.ct_hdr.ct_fs_subtype = FC_NS_SUBTYPE;
297 gid_pn->ct_iu_req.header.options = ZFCP_CT_SYNCHRONOUS; 255 gid_pn->gid_pn_req.ct_hdr.ct_options = 0;
298 gid_pn->ct_iu_req.header.cmd_rsp_code = ZFCP_CT_GID_PN; 256 gid_pn->gid_pn_req.ct_hdr.ct_cmd = FC_NS_GID_PN;
299 gid_pn->ct_iu_req.header.max_res_size = ZFCP_CT_SIZE_ONE_PAGE / 4; 257 gid_pn->gid_pn_req.ct_hdr.ct_mr_size = ZFCP_FC_CT_SIZE_PAGE / 4;
300 gid_pn->ct_iu_req.wwpn = port->wwpn; 258 gid_pn->gid_pn_req.gid_pn.fn_wwpn = port->wwpn;
301 259
302 init_completion(&compl_rec.done); 260 ret = zfcp_fsf_send_ct(&adapter->gs->ds, &gid_pn->ct,
303 compl_rec.handler = zfcp_fc_ns_gid_pn_eval; 261 adapter->pool.gid_pn_req);
304 compl_rec.handler_data = (unsigned long) gid_pn; 262 if (!ret) {
305 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.gid_pn_req); 263 wait_for_completion(&completion);
306 if (!ret) 264 zfcp_fc_ns_gid_pn_eval(gid_pn);
307 wait_for_completion(&compl_rec.done); 265 }
308 return ret; 266 return ret;
309} 267}
310 268
@@ -316,10 +274,10 @@ static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port,
316static int zfcp_fc_ns_gid_pn(struct zfcp_port *port) 274static int zfcp_fc_ns_gid_pn(struct zfcp_port *port)
317{ 275{
318 int ret; 276 int ret;
319 struct zfcp_gid_pn_data *gid_pn; 277 struct zfcp_fc_gid_pn *gid_pn;
320 struct zfcp_adapter *adapter = port->adapter; 278 struct zfcp_adapter *adapter = port->adapter;
321 279
322 gid_pn = mempool_alloc(adapter->pool.gid_pn_data, GFP_ATOMIC); 280 gid_pn = mempool_alloc(adapter->pool.gid_pn, GFP_ATOMIC);
323 if (!gid_pn) 281 if (!gid_pn)
324 return -ENOMEM; 282 return -ENOMEM;
325 283
@@ -333,7 +291,7 @@ static int zfcp_fc_ns_gid_pn(struct zfcp_port *port)
333 291
334 zfcp_fc_wka_port_put(&adapter->gs->ds); 292 zfcp_fc_wka_port_put(&adapter->gs->ds);
335out: 293out:
336 mempool_free(gid_pn, adapter->pool.gid_pn_data); 294 mempool_free(gid_pn, adapter->pool.gid_pn);
337 return ret; 295 return ret;
338} 296}
339 297
@@ -357,7 +315,7 @@ void zfcp_fc_port_did_lookup(struct work_struct *work)
357 315
358 zfcp_erp_port_reopen(port, 0, "fcgpn_3", NULL); 316 zfcp_erp_port_reopen(port, 0, "fcgpn_3", NULL);
359out: 317out:
360 zfcp_port_put(port); 318 put_device(&port->sysfs_device);
361} 319}
362 320
363/** 321/**
@@ -366,9 +324,9 @@ out:
366 */ 324 */
367void zfcp_fc_trigger_did_lookup(struct zfcp_port *port) 325void zfcp_fc_trigger_did_lookup(struct zfcp_port *port)
368{ 326{
369 zfcp_port_get(port); 327 get_device(&port->sysfs_device);
370 if (!queue_work(port->adapter->work_queue, &port->gid_pn_work)) 328 if (!queue_work(port->adapter->work_queue, &port->gid_pn_work))
371 zfcp_port_put(port); 329 put_device(&port->sysfs_device);
372} 330}
373 331
374/** 332/**
@@ -378,33 +336,36 @@ void zfcp_fc_trigger_did_lookup(struct zfcp_port *port)
378 * 336 *
379 * Evaluate PLOGI playload and copy important fields into zfcp_port structure 337 * Evaluate PLOGI playload and copy important fields into zfcp_port structure
380 */ 338 */
381void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi) 339void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fc_els_flogi *plogi)
382{ 340{
383 port->maxframe_size = plogi->serv_param.common_serv_param[7] | 341 if (plogi->fl_wwpn != port->wwpn) {
384 ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8); 342 port->d_id = 0;
385 if (plogi->serv_param.class1_serv_param[0] & 0x80) 343 dev_warn(&port->adapter->ccw_device->dev,
344 "A port opened with WWPN 0x%016Lx returned data that "
345 "identifies it as WWPN 0x%016Lx\n",
346 (unsigned long long) port->wwpn,
347 (unsigned long long) plogi->fl_wwpn);
348 return;
349 }
350
351 port->wwnn = plogi->fl_wwnn;
352 port->maxframe_size = plogi->fl_csp.sp_bb_data;
353
354 if (plogi->fl_cssp[0].cp_class & FC_CPC_VALID)
386 port->supported_classes |= FC_COS_CLASS1; 355 port->supported_classes |= FC_COS_CLASS1;
387 if (plogi->serv_param.class2_serv_param[0] & 0x80) 356 if (plogi->fl_cssp[1].cp_class & FC_CPC_VALID)
388 port->supported_classes |= FC_COS_CLASS2; 357 port->supported_classes |= FC_COS_CLASS2;
389 if (plogi->serv_param.class3_serv_param[0] & 0x80) 358 if (plogi->fl_cssp[2].cp_class & FC_CPC_VALID)
390 port->supported_classes |= FC_COS_CLASS3; 359 port->supported_classes |= FC_COS_CLASS3;
391 if (plogi->serv_param.class4_serv_param[0] & 0x80) 360 if (plogi->fl_cssp[3].cp_class & FC_CPC_VALID)
392 port->supported_classes |= FC_COS_CLASS4; 361 port->supported_classes |= FC_COS_CLASS4;
393} 362}
394 363
395struct zfcp_els_adisc { 364static void zfcp_fc_adisc_handler(void *data)
396 struct zfcp_send_els els;
397 struct scatterlist req;
398 struct scatterlist resp;
399 struct zfcp_ls_adisc ls_adisc;
400 struct zfcp_ls_adisc ls_adisc_acc;
401};
402
403static void zfcp_fc_adisc_handler(unsigned long data)
404{ 365{
405 struct zfcp_els_adisc *adisc = (struct zfcp_els_adisc *) data; 366 struct zfcp_fc_els_adisc *adisc = data;
406 struct zfcp_port *port = adisc->els.port; 367 struct zfcp_port *port = adisc->els.port;
407 struct zfcp_ls_adisc *ls_adisc = &adisc->ls_adisc_acc; 368 struct fc_els_adisc *adisc_resp = &adisc->adisc_resp;
408 369
409 if (adisc->els.status) { 370 if (adisc->els.status) {
410 /* request rejected or timed out */ 371 /* request rejected or timed out */
@@ -414,9 +375,9 @@ static void zfcp_fc_adisc_handler(unsigned long data)
414 } 375 }
415 376
416 if (!port->wwnn) 377 if (!port->wwnn)
417 port->wwnn = ls_adisc->wwnn; 378 port->wwnn = adisc_resp->adisc_wwnn;
418 379
419 if ((port->wwpn != ls_adisc->wwpn) || 380 if ((port->wwpn != adisc_resp->adisc_wwpn) ||
420 !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) { 381 !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) {
421 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, 382 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
422 "fcadh_2", NULL); 383 "fcadh_2", NULL);
@@ -427,40 +388,44 @@ static void zfcp_fc_adisc_handler(unsigned long data)
427 zfcp_scsi_schedule_rport_register(port); 388 zfcp_scsi_schedule_rport_register(port);
428 out: 389 out:
429 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); 390 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status);
430 zfcp_port_put(port); 391 put_device(&port->sysfs_device);
431 kfree(adisc); 392 kmem_cache_free(zfcp_data.adisc_cache, adisc);
432} 393}
433 394
434static int zfcp_fc_adisc(struct zfcp_port *port) 395static int zfcp_fc_adisc(struct zfcp_port *port)
435{ 396{
436 struct zfcp_els_adisc *adisc; 397 struct zfcp_fc_els_adisc *adisc;
437 struct zfcp_adapter *adapter = port->adapter; 398 struct zfcp_adapter *adapter = port->adapter;
399 int ret;
438 400
439 adisc = kzalloc(sizeof(struct zfcp_els_adisc), GFP_ATOMIC); 401 adisc = kmem_cache_alloc(zfcp_data.adisc_cache, GFP_ATOMIC);
440 if (!adisc) 402 if (!adisc)
441 return -ENOMEM; 403 return -ENOMEM;
442 404
405 adisc->els.port = port;
443 adisc->els.req = &adisc->req; 406 adisc->els.req = &adisc->req;
444 adisc->els.resp = &adisc->resp; 407 adisc->els.resp = &adisc->resp;
445 sg_init_one(adisc->els.req, &adisc->ls_adisc, 408 sg_init_one(adisc->els.req, &adisc->adisc_req,
446 sizeof(struct zfcp_ls_adisc)); 409 sizeof(struct fc_els_adisc));
447 sg_init_one(adisc->els.resp, &adisc->ls_adisc_acc, 410 sg_init_one(adisc->els.resp, &adisc->adisc_resp,
448 sizeof(struct zfcp_ls_adisc)); 411 sizeof(struct fc_els_adisc));
449 412
450 adisc->els.adapter = adapter;
451 adisc->els.port = port;
452 adisc->els.d_id = port->d_id;
453 adisc->els.handler = zfcp_fc_adisc_handler; 413 adisc->els.handler = zfcp_fc_adisc_handler;
454 adisc->els.handler_data = (unsigned long) adisc; 414 adisc->els.handler_data = adisc;
455 adisc->els.ls_code = adisc->ls_adisc.code = ZFCP_LS_ADISC;
456 415
457 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports 416 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
458 without FC-AL-2 capability, so we don't set it */ 417 without FC-AL-2 capability, so we don't set it */
459 adisc->ls_adisc.wwpn = fc_host_port_name(adapter->scsi_host); 418 adisc->adisc_req.adisc_wwpn = fc_host_port_name(adapter->scsi_host);
460 adisc->ls_adisc.wwnn = fc_host_node_name(adapter->scsi_host); 419 adisc->adisc_req.adisc_wwnn = fc_host_node_name(adapter->scsi_host);
461 adisc->ls_adisc.nport_id = fc_host_port_id(adapter->scsi_host); 420 adisc->adisc_req.adisc_cmd = ELS_ADISC;
421 hton24(adisc->adisc_req.adisc_port_id,
422 fc_host_port_id(adapter->scsi_host));
423
424 ret = zfcp_fsf_send_els(adapter, port->d_id, &adisc->els);
425 if (ret)
426 kmem_cache_free(zfcp_data.adisc_cache, adisc);
462 427
463 return zfcp_fsf_send_els(&adisc->els); 428 return ret;
464} 429}
465 430
466void zfcp_fc_link_test_work(struct work_struct *work) 431void zfcp_fc_link_test_work(struct work_struct *work)
@@ -469,7 +434,7 @@ void zfcp_fc_link_test_work(struct work_struct *work)
469 container_of(work, struct zfcp_port, test_link_work); 434 container_of(work, struct zfcp_port, test_link_work);
470 int retval; 435 int retval;
471 436
472 zfcp_port_get(port); 437 get_device(&port->sysfs_device);
473 port->rport_task = RPORT_DEL; 438 port->rport_task = RPORT_DEL;
474 zfcp_scsi_rport_work(&port->rport_work); 439 zfcp_scsi_rport_work(&port->rport_work);
475 440
@@ -488,7 +453,7 @@ void zfcp_fc_link_test_work(struct work_struct *work)
488 zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL); 453 zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL);
489 454
490out: 455out:
491 zfcp_port_put(port); 456 put_device(&port->sysfs_device);
492} 457}
493 458
494/** 459/**
@@ -501,12 +466,12 @@ out:
501 */ 466 */
502void zfcp_fc_test_link(struct zfcp_port *port) 467void zfcp_fc_test_link(struct zfcp_port *port)
503{ 468{
504 zfcp_port_get(port); 469 get_device(&port->sysfs_device);
505 if (!queue_work(port->adapter->work_queue, &port->test_link_work)) 470 if (!queue_work(port->adapter->work_queue, &port->test_link_work))
506 zfcp_port_put(port); 471 put_device(&port->sysfs_device);
507} 472}
508 473
509static void zfcp_free_sg_env(struct zfcp_gpn_ft *gpn_ft, int buf_num) 474static void zfcp_free_sg_env(struct zfcp_fc_gpn_ft *gpn_ft, int buf_num)
510{ 475{
511 struct scatterlist *sg = &gpn_ft->sg_req; 476 struct scatterlist *sg = &gpn_ft->sg_req;
512 477
@@ -516,10 +481,10 @@ static void zfcp_free_sg_env(struct zfcp_gpn_ft *gpn_ft, int buf_num)
516 kfree(gpn_ft); 481 kfree(gpn_ft);
517} 482}
518 483
519static struct zfcp_gpn_ft *zfcp_alloc_sg_env(int buf_num) 484static struct zfcp_fc_gpn_ft *zfcp_alloc_sg_env(int buf_num)
520{ 485{
521 struct zfcp_gpn_ft *gpn_ft; 486 struct zfcp_fc_gpn_ft *gpn_ft;
522 struct ct_iu_gpn_ft_req *req; 487 struct zfcp_fc_gpn_ft_req *req;
523 488
524 gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL); 489 gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL);
525 if (!gpn_ft) 490 if (!gpn_ft)
@@ -542,159 +507,152 @@ out:
542} 507}
543 508
544 509
545static int zfcp_fc_send_gpn_ft(struct zfcp_gpn_ft *gpn_ft, 510static int zfcp_fc_send_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft,
546 struct zfcp_adapter *adapter, int max_bytes) 511 struct zfcp_adapter *adapter, int max_bytes)
547{ 512{
548 struct zfcp_send_ct *ct = &gpn_ft->ct; 513 struct zfcp_fsf_ct_els *ct = &gpn_ft->ct;
549 struct ct_iu_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req); 514 struct zfcp_fc_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req);
550 struct zfcp_fc_ns_handler_data compl_rec; 515 DECLARE_COMPLETION_ONSTACK(completion);
551 int ret; 516 int ret;
552 517
553 /* prepare CT IU for GPN_FT */ 518 /* prepare CT IU for GPN_FT */
554 req->header.revision = ZFCP_CT_REVISION; 519 req->ct_hdr.ct_rev = FC_CT_REV;
555 req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; 520 req->ct_hdr.ct_fs_type = FC_FST_DIR;
556 req->header.gs_subtype = ZFCP_CT_NAME_SERVER; 521 req->ct_hdr.ct_fs_subtype = FC_NS_SUBTYPE;
557 req->header.options = ZFCP_CT_SYNCHRONOUS; 522 req->ct_hdr.ct_options = 0;
558 req->header.cmd_rsp_code = ZFCP_CT_GPN_FT; 523 req->ct_hdr.ct_cmd = FC_NS_GPN_FT;
559 req->header.max_res_size = max_bytes / 4; 524 req->ct_hdr.ct_mr_size = max_bytes / 4;
560 req->flags = 0; 525 req->gpn_ft.fn_domain_id_scope = 0;
561 req->domain_id_scope = 0; 526 req->gpn_ft.fn_area_id_scope = 0;
562 req->area_id_scope = 0; 527 req->gpn_ft.fn_fc4_type = FC_TYPE_FCP;
563 req->fc4_type = ZFCP_CT_SCSI_FCP;
564 528
565 /* prepare zfcp_send_ct */ 529 /* prepare zfcp_send_ct */
566 ct->wka_port = &adapter->gs->ds; 530 ct->handler = zfcp_fc_complete;
567 ct->handler = zfcp_fc_ns_handler; 531 ct->handler_data = &completion;
568 ct->handler_data = (unsigned long)&compl_rec;
569 ct->req = &gpn_ft->sg_req; 532 ct->req = &gpn_ft->sg_req;
570 ct->resp = gpn_ft->sg_resp; 533 ct->resp = gpn_ft->sg_resp;
571 534
572 init_completion(&compl_rec.done); 535 ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct, NULL);
573 compl_rec.handler = NULL;
574 ret = zfcp_fsf_send_ct(ct, NULL);
575 if (!ret) 536 if (!ret)
576 wait_for_completion(&compl_rec.done); 537 wait_for_completion(&completion);
577 return ret; 538 return ret;
578} 539}
579 540
580static void zfcp_fc_validate_port(struct zfcp_port *port) 541static void zfcp_fc_validate_port(struct zfcp_port *port, struct list_head *lh)
581{ 542{
582 struct zfcp_adapter *adapter = port->adapter;
583
584 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)) 543 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC))
585 return; 544 return;
586 545
587 atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status); 546 atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status);
588 547
589 if ((port->supported_classes != 0) || 548 if ((port->supported_classes != 0) ||
590 !list_empty(&port->unit_list_head)) { 549 !list_empty(&port->unit_list))
591 zfcp_port_put(port);
592 return; 550 return;
593 } 551
594 zfcp_erp_port_shutdown(port, 0, "fcpval1", NULL); 552 list_move_tail(&port->list, lh);
595 zfcp_erp_wait(adapter);
596 zfcp_port_put(port);
597 zfcp_port_dequeue(port);
598} 553}
599 554
600static int zfcp_fc_eval_gpn_ft(struct zfcp_gpn_ft *gpn_ft, int max_entries) 555static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft,
556 struct zfcp_adapter *adapter, int max_entries)
601{ 557{
602 struct zfcp_send_ct *ct = &gpn_ft->ct; 558 struct zfcp_fsf_ct_els *ct = &gpn_ft->ct;
603 struct scatterlist *sg = gpn_ft->sg_resp; 559 struct scatterlist *sg = gpn_ft->sg_resp;
604 struct ct_hdr *hdr = sg_virt(sg); 560 struct fc_ct_hdr *hdr = sg_virt(sg);
605 struct gpn_ft_resp_acc *acc = sg_virt(sg); 561 struct fc_gpn_ft_resp *acc = sg_virt(sg);
606 struct zfcp_adapter *adapter = ct->wka_port->adapter;
607 struct zfcp_port *port, *tmp; 562 struct zfcp_port *port, *tmp;
563 unsigned long flags;
564 LIST_HEAD(remove_lh);
608 u32 d_id; 565 u32 d_id;
609 int ret = 0, x, last = 0; 566 int ret = 0, x, last = 0;
610 567
611 if (ct->status) 568 if (ct->status)
612 return -EIO; 569 return -EIO;
613 570
614 if (hdr->cmd_rsp_code != ZFCP_CT_ACCEPT) { 571 if (hdr->ct_cmd != FC_FS_ACC) {
615 if (hdr->reason_code == ZFCP_CT_UNABLE_TO_PERFORM_CMD) 572 if (hdr->ct_reason == FC_BA_RJT_UNABLE)
616 return -EAGAIN; /* might be a temporary condition */ 573 return -EAGAIN; /* might be a temporary condition */
617 return -EIO; 574 return -EIO;
618 } 575 }
619 576
620 if (hdr->max_res_size) { 577 if (hdr->ct_mr_size) {
621 dev_warn(&adapter->ccw_device->dev, 578 dev_warn(&adapter->ccw_device->dev,
622 "The name server reported %d words residual data\n", 579 "The name server reported %d words residual data\n",
623 hdr->max_res_size); 580 hdr->ct_mr_size);
624 return -E2BIG; 581 return -E2BIG;
625 } 582 }
626 583
627 mutex_lock(&zfcp_data.config_mutex);
628
629 /* first entry is the header */ 584 /* first entry is the header */
630 for (x = 1; x < max_entries && !last; x++) { 585 for (x = 1; x < max_entries && !last; x++) {
631 if (x % (ZFCP_GPN_FT_ENTRIES + 1)) 586 if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
632 acc++; 587 acc++;
633 else 588 else
634 acc = sg_virt(++sg); 589 acc = sg_virt(++sg);
635 590
636 last = acc->control & 0x80; 591 last = acc->fp_flags & FC_NS_FID_LAST;
637 d_id = acc->port_id[0] << 16 | acc->port_id[1] << 8 | 592 d_id = ntoh24(acc->fp_fid);
638 acc->port_id[2];
639 593
640 /* don't attach ports with a well known address */ 594 /* don't attach ports with a well known address */
641 if ((d_id & ZFCP_DID_WKA) == ZFCP_DID_WKA) 595 if (d_id >= FC_FID_WELL_KNOWN_BASE)
642 continue; 596 continue;
643 /* skip the adapter's port and known remote ports */ 597 /* skip the adapter's port and known remote ports */
644 if (acc->wwpn == fc_host_port_name(adapter->scsi_host)) 598 if (acc->fp_wwpn == fc_host_port_name(adapter->scsi_host))
645 continue;
646 port = zfcp_get_port_by_wwpn(adapter, acc->wwpn);
647 if (port)
648 continue; 599 continue;
649 600
650 port = zfcp_port_enqueue(adapter, acc->wwpn, 601 port = zfcp_port_enqueue(adapter, acc->fp_wwpn,
651 ZFCP_STATUS_COMMON_NOESC, d_id); 602 ZFCP_STATUS_COMMON_NOESC, d_id);
652 if (IS_ERR(port)) 603 if (!IS_ERR(port))
653 ret = PTR_ERR(port);
654 else
655 zfcp_erp_port_reopen(port, 0, "fcegpf1", NULL); 604 zfcp_erp_port_reopen(port, 0, "fcegpf1", NULL);
605 else if (PTR_ERR(port) != -EEXIST)
606 ret = PTR_ERR(port);
656 } 607 }
657 608
658 zfcp_erp_wait(adapter); 609 zfcp_erp_wait(adapter);
659 list_for_each_entry_safe(port, tmp, &adapter->port_list_head, list) 610 write_lock_irqsave(&adapter->port_list_lock, flags);
660 zfcp_fc_validate_port(port); 611 list_for_each_entry_safe(port, tmp, &adapter->port_list, list)
661 mutex_unlock(&zfcp_data.config_mutex); 612 zfcp_fc_validate_port(port, &remove_lh);
613 write_unlock_irqrestore(&adapter->port_list_lock, flags);
614
615 list_for_each_entry_safe(port, tmp, &remove_lh, list) {
616 zfcp_erp_port_shutdown(port, 0, "fcegpf2", NULL);
617 zfcp_device_unregister(&port->sysfs_device,
618 &zfcp_sysfs_port_attrs);
619 }
620
662 return ret; 621 return ret;
663} 622}
664 623
665/** 624/**
666 * zfcp_fc_scan_ports - scan remote ports and attach new ports 625 * zfcp_fc_scan_ports - scan remote ports and attach new ports
667 * @adapter: pointer to struct zfcp_adapter 626 * @work: reference to scheduled work
668 */ 627 */
669int zfcp_fc_scan_ports(struct zfcp_adapter *adapter) 628void zfcp_fc_scan_ports(struct work_struct *work)
670{ 629{
630 struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter,
631 scan_work);
671 int ret, i; 632 int ret, i;
672 struct zfcp_gpn_ft *gpn_ft; 633 struct zfcp_fc_gpn_ft *gpn_ft;
673 int chain, max_entries, buf_num, max_bytes; 634 int chain, max_entries, buf_num, max_bytes;
674 635
675 chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; 636 chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS;
676 buf_num = chain ? ZFCP_GPN_FT_BUFFERS : 1; 637 buf_num = chain ? ZFCP_FC_GPN_FT_NUM_BUFS : 1;
677 max_entries = chain ? ZFCP_GPN_FT_MAX_ENTRIES : ZFCP_GPN_FT_ENTRIES; 638 max_entries = chain ? ZFCP_FC_GPN_FT_MAX_ENT : ZFCP_FC_GPN_FT_ENT_PAGE;
678 max_bytes = chain ? ZFCP_GPN_FT_MAX_SIZE : ZFCP_CT_SIZE_ONE_PAGE; 639 max_bytes = chain ? ZFCP_FC_GPN_FT_MAX_SIZE : ZFCP_FC_CT_SIZE_PAGE;
679 640
680 if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && 641 if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT &&
681 fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) 642 fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV)
682 return 0; 643 return;
683 644
684 ret = zfcp_fc_wka_port_get(&adapter->gs->ds); 645 if (zfcp_fc_wka_port_get(&adapter->gs->ds))
685 if (ret) 646 return;
686 return ret;
687 647
688 gpn_ft = zfcp_alloc_sg_env(buf_num); 648 gpn_ft = zfcp_alloc_sg_env(buf_num);
689 if (!gpn_ft) { 649 if (!gpn_ft)
690 ret = -ENOMEM;
691 goto out; 650 goto out;
692 }
693 651
694 for (i = 0; i < 3; i++) { 652 for (i = 0; i < 3; i++) {
695 ret = zfcp_fc_send_gpn_ft(gpn_ft, adapter, max_bytes); 653 ret = zfcp_fc_send_gpn_ft(gpn_ft, adapter, max_bytes);
696 if (!ret) { 654 if (!ret) {
697 ret = zfcp_fc_eval_gpn_ft(gpn_ft, max_entries); 655 ret = zfcp_fc_eval_gpn_ft(gpn_ft, adapter, max_entries);
698 if (ret == -EAGAIN) 656 if (ret == -EAGAIN)
699 ssleep(1); 657 ssleep(1);
700 else 658 else
@@ -704,174 +662,116 @@ int zfcp_fc_scan_ports(struct zfcp_adapter *adapter)
704 zfcp_free_sg_env(gpn_ft, buf_num); 662 zfcp_free_sg_env(gpn_ft, buf_num);
705out: 663out:
706 zfcp_fc_wka_port_put(&adapter->gs->ds); 664 zfcp_fc_wka_port_put(&adapter->gs->ds);
707 return ret;
708}
709
710
711void _zfcp_fc_scan_ports_later(struct work_struct *work)
712{
713 zfcp_fc_scan_ports(container_of(work, struct zfcp_adapter, scan_work));
714} 665}
715 666
716struct zfcp_els_fc_job { 667static void zfcp_fc_ct_els_job_handler(void *data)
717 struct zfcp_send_els els;
718 struct fc_bsg_job *job;
719};
720
721static void zfcp_fc_generic_els_handler(unsigned long data)
722{ 668{
723 struct zfcp_els_fc_job *els_fc_job = (struct zfcp_els_fc_job *) data; 669 struct fc_bsg_job *job = data;
724 struct fc_bsg_job *job = els_fc_job->job; 670 struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data;
725 struct fc_bsg_reply *reply = job->reply; 671 int status = zfcp_ct_els->status;
726 672 int reply_status;
727 if (els_fc_job->els.status) {
728 /* request rejected or timed out */
729 reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_REJECT;
730 goto out;
731 }
732
733 reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
734 reply->reply_payload_rcv_len = job->reply_payload.payload_len;
735 673
736out: 674 reply_status = status ? FC_CTELS_STATUS_REJECT : FC_CTELS_STATUS_OK;
737 job->state_flags = FC_RQST_STATE_DONE; 675 job->reply->reply_data.ctels_reply.status = reply_status;
676 job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
738 job->job_done(job); 677 job->job_done(job);
739 kfree(els_fc_job);
740} 678}
741 679
742int zfcp_fc_execute_els_fc_job(struct fc_bsg_job *job) 680static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
681 struct zfcp_adapter *adapter)
743{ 682{
744 struct zfcp_els_fc_job *els_fc_job; 683 struct zfcp_fsf_ct_els *els = job->dd_data;
745 struct fc_rport *rport = job->rport; 684 struct fc_rport *rport = job->rport;
746 struct Scsi_Host *shost;
747 struct zfcp_adapter *adapter;
748 struct zfcp_port *port; 685 struct zfcp_port *port;
749 u8 *port_did; 686 u32 d_id;
750
751 shost = rport ? rport_to_shost(rport) : job->shost;
752 adapter = (struct zfcp_adapter *)shost->hostdata[0];
753
754 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
755 return -EINVAL;
756
757 els_fc_job = kzalloc(sizeof(struct zfcp_els_fc_job), GFP_KERNEL);
758 if (!els_fc_job)
759 return -ENOMEM;
760 687
761 els_fc_job->els.adapter = adapter;
762 if (rport) { 688 if (rport) {
763 read_lock_irq(&zfcp_data.config_lock);
764 port = zfcp_get_port_by_wwpn(adapter, rport->port_name); 689 port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
765 if (port) 690 if (!port)
766 els_fc_job->els.d_id = port->d_id;
767 read_unlock_irq(&zfcp_data.config_lock);
768 if (!port) {
769 kfree(els_fc_job);
770 return -EINVAL; 691 return -EINVAL;
771 }
772 } else {
773 port_did = job->request->rqst_data.h_els.port_id;
774 els_fc_job->els.d_id = (port_did[0] << 16) +
775 (port_did[1] << 8) + port_did[2];
776 }
777
778 els_fc_job->els.req = job->request_payload.sg_list;
779 els_fc_job->els.resp = job->reply_payload.sg_list;
780 els_fc_job->els.handler = zfcp_fc_generic_els_handler;
781 els_fc_job->els.handler_data = (unsigned long) els_fc_job;
782 els_fc_job->job = job;
783
784 return zfcp_fsf_send_els(&els_fc_job->els);
785}
786
787struct zfcp_ct_fc_job {
788 struct zfcp_send_ct ct;
789 struct fc_bsg_job *job;
790};
791
792static void zfcp_fc_generic_ct_handler(unsigned long data)
793{
794 struct zfcp_ct_fc_job *ct_fc_job = (struct zfcp_ct_fc_job *) data;
795 struct fc_bsg_job *job = ct_fc_job->job;
796
797 job->reply->reply_data.ctels_reply.status = ct_fc_job->ct.status ?
798 FC_CTELS_STATUS_REJECT : FC_CTELS_STATUS_OK;
799 job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
800 job->state_flags = FC_RQST_STATE_DONE;
801 job->job_done(job);
802 692
803 zfcp_fc_wka_port_put(ct_fc_job->ct.wka_port); 693 d_id = port->d_id;
694 put_device(&port->sysfs_device);
695 } else
696 d_id = ntoh24(job->request->rqst_data.h_els.port_id);
804 697
805 kfree(ct_fc_job); 698 return zfcp_fsf_send_els(adapter, d_id, els);
806} 699}
807 700
808int zfcp_fc_execute_ct_fc_job(struct fc_bsg_job *job) 701static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
702 struct zfcp_adapter *adapter)
809{ 703{
810 int ret; 704 int ret;
811 u8 gs_type; 705 u8 gs_type;
812 struct fc_rport *rport = job->rport; 706 struct zfcp_fsf_ct_els *ct = job->dd_data;
813 struct Scsi_Host *shost; 707 struct zfcp_fc_wka_port *wka_port;
814 struct zfcp_adapter *adapter;
815 struct zfcp_ct_fc_job *ct_fc_job;
816 u32 preamble_word1; 708 u32 preamble_word1;
817 709
818 shost = rport ? rport_to_shost(rport) : job->shost;
819
820 adapter = (struct zfcp_adapter *)shost->hostdata[0];
821 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
822 return -EINVAL;
823
824 ct_fc_job = kzalloc(sizeof(struct zfcp_ct_fc_job), GFP_KERNEL);
825 if (!ct_fc_job)
826 return -ENOMEM;
827
828 preamble_word1 = job->request->rqst_data.r_ct.preamble_word1; 710 preamble_word1 = job->request->rqst_data.r_ct.preamble_word1;
829 gs_type = (preamble_word1 & 0xff000000) >> 24; 711 gs_type = (preamble_word1 & 0xff000000) >> 24;
830 712
831 switch (gs_type) { 713 switch (gs_type) {
832 case FC_FST_ALIAS: 714 case FC_FST_ALIAS:
833 ct_fc_job->ct.wka_port = &adapter->gs->as; 715 wka_port = &adapter->gs->as;
834 break; 716 break;
835 case FC_FST_MGMT: 717 case FC_FST_MGMT:
836 ct_fc_job->ct.wka_port = &adapter->gs->ms; 718 wka_port = &adapter->gs->ms;
837 break; 719 break;
838 case FC_FST_TIME: 720 case FC_FST_TIME:
839 ct_fc_job->ct.wka_port = &adapter->gs->ts; 721 wka_port = &adapter->gs->ts;
840 break; 722 break;
841 case FC_FST_DIR: 723 case FC_FST_DIR:
842 ct_fc_job->ct.wka_port = &adapter->gs->ds; 724 wka_port = &adapter->gs->ds;
843 break; 725 break;
844 default: 726 default:
845 kfree(ct_fc_job);
846 return -EINVAL; /* no such service */ 727 return -EINVAL; /* no such service */
847 } 728 }
848 729
849 ret = zfcp_fc_wka_port_get(ct_fc_job->ct.wka_port); 730 ret = zfcp_fc_wka_port_get(wka_port);
850 if (ret) { 731 if (ret)
851 kfree(ct_fc_job);
852 return ret; 732 return ret;
853 }
854 733
855 ct_fc_job->ct.req = job->request_payload.sg_list; 734 ret = zfcp_fsf_send_ct(wka_port, ct, NULL);
856 ct_fc_job->ct.resp = job->reply_payload.sg_list; 735 if (ret)
857 ct_fc_job->ct.handler = zfcp_fc_generic_ct_handler; 736 zfcp_fc_wka_port_put(wka_port);
858 ct_fc_job->ct.handler_data = (unsigned long) ct_fc_job;
859 ct_fc_job->ct.completion = NULL;
860 ct_fc_job->job = job;
861 737
862 ret = zfcp_fsf_send_ct(&ct_fc_job->ct, NULL);
863 if (ret) {
864 kfree(ct_fc_job);
865 zfcp_fc_wka_port_put(ct_fc_job->ct.wka_port);
866 }
867 return ret; 738 return ret;
868} 739}
869 740
741int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
742{
743 struct Scsi_Host *shost;
744 struct zfcp_adapter *adapter;
745 struct zfcp_fsf_ct_els *ct_els = job->dd_data;
746
747 shost = job->rport ? rport_to_shost(job->rport) : job->shost;
748 adapter = (struct zfcp_adapter *)shost->hostdata[0];
749
750 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
751 return -EINVAL;
752
753 ct_els->req = job->request_payload.sg_list;
754 ct_els->resp = job->reply_payload.sg_list;
755 ct_els->handler = zfcp_fc_ct_els_job_handler;
756 ct_els->handler_data = job;
757
758 switch (job->request->msgcode) {
759 case FC_BSG_RPT_ELS:
760 case FC_BSG_HST_ELS_NOLOGIN:
761 return zfcp_fc_exec_els_job(job, adapter);
762 case FC_BSG_RPT_CT:
763 case FC_BSG_HST_CT:
764 return zfcp_fc_exec_ct_job(job, adapter);
765 default:
766 return -EINVAL;
767 }
768}
769
870int zfcp_fc_gs_setup(struct zfcp_adapter *adapter) 770int zfcp_fc_gs_setup(struct zfcp_adapter *adapter)
871{ 771{
872 struct zfcp_wka_ports *wka_ports; 772 struct zfcp_fc_wka_ports *wka_ports;
873 773
874 wka_ports = kzalloc(sizeof(struct zfcp_wka_ports), GFP_KERNEL); 774 wka_ports = kzalloc(sizeof(struct zfcp_fc_wka_ports), GFP_KERNEL);
875 if (!wka_ports) 775 if (!wka_ports)
876 return -ENOMEM; 776 return -ENOMEM;
877 777
@@ -880,7 +780,6 @@ int zfcp_fc_gs_setup(struct zfcp_adapter *adapter)
880 zfcp_fc_wka_port_init(&wka_ports->ts, FC_FID_TIME_SERV, adapter); 780 zfcp_fc_wka_port_init(&wka_ports->ts, FC_FID_TIME_SERV, adapter);
881 zfcp_fc_wka_port_init(&wka_ports->ds, FC_FID_DIR_SERV, adapter); 781 zfcp_fc_wka_port_init(&wka_ports->ds, FC_FID_DIR_SERV, adapter);
882 zfcp_fc_wka_port_init(&wka_ports->as, FC_FID_ALIASES, adapter); 782 zfcp_fc_wka_port_init(&wka_ports->as, FC_FID_ALIASES, adapter);
883 zfcp_fc_wka_port_init(&wka_ports->ks, FC_FID_SEC_KEY, adapter);
884 783
885 return 0; 784 return 0;
886} 785}
diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
new file mode 100644
index 000000000000..cb2a3669a384
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_fc.h
@@ -0,0 +1,260 @@
1/*
2 * zfcp device driver
3 *
4 * Fibre Channel related definitions and inline functions for the zfcp
5 * device driver
6 *
7 * Copyright IBM Corporation 2009
8 */
9
10#ifndef ZFCP_FC_H
11#define ZFCP_FC_H
12
13#include <scsi/fc/fc_els.h>
14#include <scsi/fc/fc_fcp.h>
15#include <scsi/fc/fc_ns.h>
16#include <scsi/scsi_cmnd.h>
17#include <scsi/scsi_tcq.h>
18#include "zfcp_fsf.h"
19
20#define ZFCP_FC_CT_SIZE_PAGE (PAGE_SIZE - sizeof(struct fc_ct_hdr))
21#define ZFCP_FC_GPN_FT_ENT_PAGE (ZFCP_FC_CT_SIZE_PAGE \
22 / sizeof(struct fc_gpn_ft_resp))
23#define ZFCP_FC_GPN_FT_NUM_BUFS 4 /* memory pages */
24
25#define ZFCP_FC_GPN_FT_MAX_SIZE (ZFCP_FC_GPN_FT_NUM_BUFS * PAGE_SIZE \
26 - sizeof(struct fc_ct_hdr))
27#define ZFCP_FC_GPN_FT_MAX_ENT (ZFCP_FC_GPN_FT_NUM_BUFS * \
28 (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
29
30/**
31 * struct zfcp_fc_gid_pn_req - container for ct header plus gid_pn request
32 * @ct_hdr: FC GS common transport header
33 * @gid_pn: GID_PN request
34 */
35struct zfcp_fc_gid_pn_req {
36 struct fc_ct_hdr ct_hdr;
37 struct fc_ns_gid_pn gid_pn;
38} __packed;
39
40/**
41 * struct zfcp_fc_gid_pn_resp - container for ct header plus gid_pn response
42 * @ct_hdr: FC GS common transport header
43 * @gid_pn: GID_PN response
44 */
45struct zfcp_fc_gid_pn_resp {
46 struct fc_ct_hdr ct_hdr;
47 struct fc_gid_pn_resp gid_pn;
48} __packed;
49
50/**
51 * struct zfcp_fc_gid_pn - everything required in zfcp for gid_pn request
52 * @ct: data passed to zfcp_fsf for issuing fsf request
53 * @sg_req: scatterlist entry for request data
54 * @sg_resp: scatterlist entry for response data
55 * @gid_pn_req: GID_PN request data
56 * @gid_pn_resp: GID_PN response data
57 */
58struct zfcp_fc_gid_pn {
59 struct zfcp_fsf_ct_els ct;
60 struct scatterlist sg_req;
61 struct scatterlist sg_resp;
62 struct zfcp_fc_gid_pn_req gid_pn_req;
63 struct zfcp_fc_gid_pn_resp gid_pn_resp;
64 struct zfcp_port *port;
65};
66
67/**
68 * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request
69 * @ct_hdr: FC GS common transport header
70 * @gpn_ft: GPN_FT request
71 */
72struct zfcp_fc_gpn_ft_req {
73 struct fc_ct_hdr ct_hdr;
74 struct fc_ns_gid_ft gpn_ft;
75} __packed;
76
77/**
78 * struct zfcp_fc_gpn_ft_resp - container for ct header plus gpn_ft response
79 * @ct_hdr: FC GS common transport header
80 * @gpn_ft: Array of gpn_ft response data to fill one memory page
81 */
82struct zfcp_fc_gpn_ft_resp {
83 struct fc_ct_hdr ct_hdr;
84 struct fc_gpn_ft_resp gpn_ft[ZFCP_FC_GPN_FT_ENT_PAGE];
85} __packed;
86
87/**
88 * struct zfcp_fc_gpn_ft - zfcp data for gpn_ft request
89 * @ct: data passed to zfcp_fsf for issuing fsf request
90 * @sg_req: scatter list entry for gpn_ft request
91 * @sg_resp: scatter list entries for gpn_ft responses (per memory page)
92 */
93struct zfcp_fc_gpn_ft {
94 struct zfcp_fsf_ct_els ct;
95 struct scatterlist sg_req;
96 struct scatterlist sg_resp[ZFCP_FC_GPN_FT_NUM_BUFS];
97};
98
99/**
100 * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC
101 * @els: data required for issuing els fsf command
102 * @req: scatterlist entry for ELS ADISC request
103 * @resp: scatterlist entry for ELS ADISC response
104 * @adisc_req: ELS ADISC request data
105 * @adisc_resp: ELS ADISC response data
106 */
107struct zfcp_fc_els_adisc {
108 struct zfcp_fsf_ct_els els;
109 struct scatterlist req;
110 struct scatterlist resp;
111 struct fc_els_adisc adisc_req;
112 struct fc_els_adisc adisc_resp;
113};
114
115/**
116 * enum zfcp_fc_wka_status - FC WKA port status in zfcp
117 * @ZFCP_FC_WKA_PORT_OFFLINE: Port is closed and not in use
118 * @ZFCP_FC_WKA_PORT_CLOSING: The FSF "close port" request is pending
119 * @ZFCP_FC_WKA_PORT_OPENING: The FSF "open port" request is pending
120 * @ZFCP_FC_WKA_PORT_ONLINE: The port is open and the port handle is valid
121 */
122enum zfcp_fc_wka_status {
123 ZFCP_FC_WKA_PORT_OFFLINE,
124 ZFCP_FC_WKA_PORT_CLOSING,
125 ZFCP_FC_WKA_PORT_OPENING,
126 ZFCP_FC_WKA_PORT_ONLINE,
127};
128
129/**
130 * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
131 * @adapter: Pointer to adapter structure this WKA port belongs to
132 * @completion_wq: Wait for completion of open/close command
133 * @status: Current status of WKA port
134 * @refcount: Reference count to keep port open as long as it is in use
135 * @d_id: FC destination id or well-known-address
136 * @handle: FSF handle for the open WKA port
137 * @mutex: Mutex used during opening/closing state changes
138 * @work: For delaying the closing of the WKA port
139 */
140struct zfcp_fc_wka_port {
141 struct zfcp_adapter *adapter;
142 wait_queue_head_t completion_wq;
143 enum zfcp_fc_wka_status status;
144 atomic_t refcount;
145 u32 d_id;
146 u32 handle;
147 struct mutex mutex;
148 struct delayed_work work;
149};
150
151/**
152 * struct zfcp_fc_wka_ports - Data structures for FC generic services
153 * @ms: FC Management service
154 * @ts: FC time service
155 * @ds: FC directory service
156 * @as: FC alias service
157 */
158struct zfcp_fc_wka_ports {
159 struct zfcp_fc_wka_port ms;
160 struct zfcp_fc_wka_port ts;
161 struct zfcp_fc_wka_port ds;
162 struct zfcp_fc_wka_port as;
163};
164
165/**
166 * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
167 * @fcp: fcp_cmnd to setup
168 * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
169 */
170static inline
171void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
172{
173 char tag[2];
174
175 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
176
177 if (scsi_populate_tag_msg(scsi, tag)) {
178 switch (tag[0]) {
179 case MSG_ORDERED_TAG:
180 fcp->fc_pri_ta |= FCP_PTA_ORDERED;
181 break;
182 case MSG_SIMPLE_TAG:
183 fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
184 break;
185 };
186 } else
187 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
188
189 if (scsi->sc_data_direction == DMA_FROM_DEVICE)
190 fcp->fc_flags |= FCP_CFL_RDDATA;
191 if (scsi->sc_data_direction == DMA_TO_DEVICE)
192 fcp->fc_flags |= FCP_CFL_WRDATA;
193
194 memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
195
196 fcp->fc_dl = scsi_bufflen(scsi);
197}
198
199/**
200 * zfcp_fc_fcp_tm - setup FCP command as task management command
201 * @fcp: fcp_cmnd to setup
202 * @dev: scsi_device where to send the task management command
203 * @tm: task management flags to setup tm command
204 */
205static inline
206void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
207{
208 int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
209 fcp->fc_tm_flags |= tm_flags;
210}
211
212/**
213 * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
214 * @fcp_rsp: FCP RSP IU to evaluate
215 * @scsi: SCSI command where to update status and sense buffer
216 */
217static inline
218void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
219 struct scsi_cmnd *scsi)
220{
221 struct fcp_resp_rsp_info *rsp_info;
222 char *sense;
223 u32 sense_len, resid;
224 u8 rsp_flags;
225
226 set_msg_byte(scsi, COMMAND_COMPLETE);
227 scsi->result |= fcp_rsp->resp.fr_status;
228
229 rsp_flags = fcp_rsp->resp.fr_flags;
230
231 if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
232 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
233 if (rsp_info->rsp_code == FCP_TMF_CMPL)
234 set_host_byte(scsi, DID_OK);
235 else {
236 set_host_byte(scsi, DID_ERROR);
237 return;
238 }
239 }
240
241 if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
242 sense = (char *) &fcp_rsp[1];
243 if (rsp_flags & FCP_RSP_LEN_VAL)
244 sense += fcp_rsp->ext.fr_sns_len;
245 sense_len = min(fcp_rsp->ext.fr_sns_len,
246 (u32) SCSI_SENSE_BUFFERSIZE);
247 memcpy(scsi->sense_buffer, sense, sense_len);
248 }
249
250 if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
251 resid = fcp_rsp->ext.fr_resid;
252 scsi_set_resid(scsi, resid);
253 if (scsi_bufflen(scsi) - resid < scsi->underflow &&
254 !(rsp_flags & FCP_SNS_LEN_VAL) &&
255 fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
256 set_host_byte(scsi, DID_ERROR);
257 }
258}
259
260#endif
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 4e41baa0c141..482dcd97aa5d 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -10,7 +10,9 @@
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include <linux/blktrace_api.h> 12#include <linux/blktrace_api.h>
13#include <scsi/fc/fc_els.h>
13#include "zfcp_ext.h" 14#include "zfcp_ext.h"
15#include "zfcp_fc.h"
14#include "zfcp_dbf.h" 16#include "zfcp_dbf.h"
15 17
16static void zfcp_fsf_request_timeout_handler(unsigned long data) 18static void zfcp_fsf_request_timeout_handler(unsigned long data)
@@ -122,36 +124,32 @@ void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
122 124
123static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req) 125static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
124{ 126{
127 unsigned long flags;
125 struct fsf_status_read_buffer *sr_buf = req->data; 128 struct fsf_status_read_buffer *sr_buf = req->data;
126 struct zfcp_adapter *adapter = req->adapter; 129 struct zfcp_adapter *adapter = req->adapter;
127 struct zfcp_port *port; 130 struct zfcp_port *port;
128 int d_id = sr_buf->d_id & ZFCP_DID_MASK; 131 int d_id = ntoh24(sr_buf->d_id);
129 unsigned long flags;
130 132
131 read_lock_irqsave(&zfcp_data.config_lock, flags); 133 read_lock_irqsave(&adapter->port_list_lock, flags);
132 list_for_each_entry(port, &adapter->port_list_head, list) 134 list_for_each_entry(port, &adapter->port_list, list)
133 if (port->d_id == d_id) { 135 if (port->d_id == d_id) {
134 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
135 zfcp_erp_port_reopen(port, 0, "fssrpc1", req); 136 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
136 return; 137 break;
137 } 138 }
138 read_unlock_irqrestore(&zfcp_data.config_lock, flags); 139 read_unlock_irqrestore(&adapter->port_list_lock, flags);
139} 140}
140 141
141static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id, 142static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
142 struct fsf_link_down_info *link_down) 143 struct fsf_link_down_info *link_down)
143{ 144{
144 struct zfcp_adapter *adapter = req->adapter; 145 struct zfcp_adapter *adapter = req->adapter;
145 unsigned long flags;
146 146
147 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) 147 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
148 return; 148 return;
149 149
150 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); 150 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
151 151
152 read_lock_irqsave(&zfcp_data.config_lock, flags);
153 zfcp_scsi_schedule_rports_block(adapter); 152 zfcp_scsi_schedule_rports_block(adapter);
154 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
155 153
156 if (!link_down) 154 if (!link_down)
157 goto out; 155 goto out;
@@ -291,7 +289,7 @@ static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
291 zfcp_erp_adapter_access_changed(adapter, "fssrh_3", 289 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
292 req); 290 req);
293 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS) 291 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
294 schedule_work(&adapter->scan_work); 292 queue_work(adapter->work_queue, &adapter->scan_work);
295 break; 293 break;
296 case FSF_STATUS_READ_CFDC_UPDATED: 294 case FSF_STATUS_READ_CFDC_UPDATED:
297 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req); 295 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
@@ -317,7 +315,6 @@ static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
317 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 315 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
318 return; 316 return;
319 case FSF_SQ_COMMAND_ABORTED: 317 case FSF_SQ_COMMAND_ABORTED:
320 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
321 break; 318 break;
322 case FSF_SQ_NO_RECOM: 319 case FSF_SQ_NO_RECOM:
323 dev_err(&req->adapter->ccw_device->dev, 320 dev_err(&req->adapter->ccw_device->dev,
@@ -358,8 +355,7 @@ static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
358 zfcp_dbf_hba_fsf_response(req); 355 zfcp_dbf_hba_fsf_response(req);
359 356
360 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { 357 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
361 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 358 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
362 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
363 return; 359 return;
364 } 360 }
365 361
@@ -377,7 +373,7 @@ static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
377 case FSF_PROT_ERROR_STATE: 373 case FSF_PROT_ERROR_STATE:
378 case FSF_PROT_SEQ_NUMB_ERROR: 374 case FSF_PROT_SEQ_NUMB_ERROR:
379 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req); 375 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
380 req->status |= ZFCP_STATUS_FSFREQ_RETRY; 376 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
381 break; 377 break;
382 case FSF_PROT_UNSUPP_QTCB_TYPE: 378 case FSF_PROT_UNSUPP_QTCB_TYPE:
383 dev_err(&adapter->ccw_device->dev, 379 dev_err(&adapter->ccw_device->dev,
@@ -480,20 +476,27 @@ void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
480 476
481static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req) 477static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
482{ 478{
483 struct fsf_qtcb_bottom_config *bottom; 479 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
484 struct zfcp_adapter *adapter = req->adapter; 480 struct zfcp_adapter *adapter = req->adapter;
485 struct Scsi_Host *shost = adapter->scsi_host; 481 struct Scsi_Host *shost = adapter->scsi_host;
482 struct fc_els_flogi *nsp, *plogi;
486 483
487 bottom = &req->qtcb->bottom.config; 484 /* adjust pointers for missing command code */
485 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
486 - sizeof(u32));
487 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
488 - sizeof(u32));
488 489
489 if (req->data) 490 if (req->data)
490 memcpy(req->data, bottom, sizeof(*bottom)); 491 memcpy(req->data, bottom, sizeof(*bottom));
491 492
492 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn; 493 fc_host_port_name(shost) = nsp->fl_wwpn;
493 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn; 494 fc_host_node_name(shost) = nsp->fl_wwnn;
494 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK; 495 fc_host_port_id(shost) = ntoh24(bottom->s_id);
495 fc_host_speed(shost) = bottom->fc_link_speed; 496 fc_host_speed(shost) = bottom->fc_link_speed;
496 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; 497 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
498 fc_host_supported_fc4s(shost)[2] = 1; /* FCP */
499 fc_host_active_fc4s(shost)[2] = 1; /* FCP */
497 500
498 adapter->hydra_version = bottom->adapter_type; 501 adapter->hydra_version = bottom->adapter_type;
499 adapter->timer_ticks = bottom->timer_interval; 502 adapter->timer_ticks = bottom->timer_interval;
@@ -503,9 +506,9 @@ static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
503 506
504 switch (bottom->fc_topology) { 507 switch (bottom->fc_topology) {
505 case FSF_TOPO_P2P: 508 case FSF_TOPO_P2P:
506 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK; 509 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
507 adapter->peer_wwpn = bottom->plogi_payload.wwpn; 510 adapter->peer_wwpn = plogi->fl_wwpn;
508 adapter->peer_wwnn = bottom->plogi_payload.wwnn; 511 adapter->peer_wwnn = plogi->fl_wwnn;
509 fc_host_port_type(shost) = FC_PORTTYPE_PTP; 512 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
510 break; 513 break;
511 case FSF_TOPO_FABRIC: 514 case FSF_TOPO_FABRIC:
@@ -881,13 +884,11 @@ static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
881 break; 884 break;
882 case FSF_PORT_BOXED: 885 case FSF_PORT_BOXED:
883 zfcp_erp_port_boxed(unit->port, "fsafch3", req); 886 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
884 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 887 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
885 ZFCP_STATUS_FSFREQ_RETRY;
886 break; 888 break;
887 case FSF_LUN_BOXED: 889 case FSF_LUN_BOXED:
888 zfcp_erp_unit_boxed(unit, "fsafch4", req); 890 zfcp_erp_unit_boxed(unit, "fsafch4", req);
889 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 891 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
890 ZFCP_STATUS_FSFREQ_RETRY;
891 break; 892 break;
892 case FSF_ADAPTER_STATUS_AVAILABLE: 893 case FSF_ADAPTER_STATUS_AVAILABLE:
893 switch (fsq->word[0]) { 894 switch (fsq->word[0]) {
@@ -958,10 +959,10 @@ out:
958static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) 959static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
959{ 960{
960 struct zfcp_adapter *adapter = req->adapter; 961 struct zfcp_adapter *adapter = req->adapter;
961 struct zfcp_send_ct *send_ct = req->data; 962 struct zfcp_fsf_ct_els *ct = req->data;
962 struct fsf_qtcb_header *header = &req->qtcb->header; 963 struct fsf_qtcb_header *header = &req->qtcb->header;
963 964
964 send_ct->status = -EINVAL; 965 ct->status = -EINVAL;
965 966
966 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) 967 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
967 goto skip_fsfstatus; 968 goto skip_fsfstatus;
@@ -969,7 +970,7 @@ static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
969 switch (header->fsf_status) { 970 switch (header->fsf_status) {
970 case FSF_GOOD: 971 case FSF_GOOD:
971 zfcp_dbf_san_ct_response(req); 972 zfcp_dbf_san_ct_response(req);
972 send_ct->status = 0; 973 ct->status = 0;
973 break; 974 break;
974 case FSF_SERVICE_CLASS_NOT_SUPPORTED: 975 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
975 zfcp_fsf_class_not_supp(req); 976 zfcp_fsf_class_not_supp(req);
@@ -985,8 +986,7 @@ static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
985 case FSF_ACCESS_DENIED: 986 case FSF_ACCESS_DENIED:
986 break; 987 break;
987 case FSF_PORT_BOXED: 988 case FSF_PORT_BOXED:
988 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 989 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
989 ZFCP_STATUS_FSFREQ_RETRY;
990 break; 990 break;
991 case FSF_PORT_HANDLE_NOT_VALID: 991 case FSF_PORT_HANDLE_NOT_VALID:
992 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req); 992 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
@@ -1001,8 +1001,8 @@ static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
1001 } 1001 }
1002 1002
1003skip_fsfstatus: 1003skip_fsfstatus:
1004 if (send_ct->handler) 1004 if (ct->handler)
1005 send_ct->handler(send_ct->handler_data); 1005 ct->handler(ct->handler_data);
1006} 1006}
1007 1007
1008static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale, 1008static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
@@ -1071,15 +1071,17 @@ static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1071 int max_sbals) 1071 int max_sbals)
1072{ 1072{
1073 int ret; 1073 int ret;
1074 unsigned int fcp_chan_timeout;
1074 1075
1075 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals); 1076 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1076 if (ret) 1077 if (ret)
1077 return ret; 1078 return ret;
1078 1079
1079 /* common settings for ct/gs and els requests */ 1080 /* common settings for ct/gs and els requests */
1081 fcp_chan_timeout = 2 * FC_DEF_R_A_TOV / 1000;
1080 req->qtcb->bottom.support.service_class = FSF_CLASS_3; 1082 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1081 req->qtcb->bottom.support.timeout = 2 * R_A_TOV; 1083 req->qtcb->bottom.support.timeout = fcp_chan_timeout;
1082 zfcp_fsf_start_timer(req, (2 * R_A_TOV + 10) * HZ); 1084 zfcp_fsf_start_timer(req, (fcp_chan_timeout + 10) * HZ);
1083 1085
1084 return 0; 1086 return 0;
1085} 1087}
@@ -1089,9 +1091,9 @@ static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1089 * @ct: pointer to struct zfcp_send_ct with data for request 1091 * @ct: pointer to struct zfcp_send_ct with data for request
1090 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req 1092 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1091 */ 1093 */
1092int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool) 1094int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1095 struct zfcp_fsf_ct_els *ct, mempool_t *pool)
1093{ 1096{
1094 struct zfcp_wka_port *wka_port = ct->wka_port;
1095 struct zfcp_qdio *qdio = wka_port->adapter->qdio; 1097 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1096 struct zfcp_fsf_req *req; 1098 struct zfcp_fsf_req *req;
1097 int ret = -EIO; 1099 int ret = -EIO;
@@ -1117,7 +1119,7 @@ int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool)
1117 req->qtcb->header.port_handle = wka_port->handle; 1119 req->qtcb->header.port_handle = wka_port->handle;
1118 req->data = ct; 1120 req->data = ct;
1119 1121
1120 zfcp_dbf_san_ct_request(req); 1122 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1121 1123
1122 ret = zfcp_fsf_req_send(req); 1124 ret = zfcp_fsf_req_send(req);
1123 if (ret) 1125 if (ret)
@@ -1134,7 +1136,7 @@ out:
1134 1136
1135static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req) 1137static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1136{ 1138{
1137 struct zfcp_send_els *send_els = req->data; 1139 struct zfcp_fsf_ct_els *send_els = req->data;
1138 struct zfcp_port *port = send_els->port; 1140 struct zfcp_port *port = send_els->port;
1139 struct fsf_qtcb_header *header = &req->qtcb->header; 1141 struct fsf_qtcb_header *header = &req->qtcb->header;
1140 1142
@@ -1154,9 +1156,6 @@ static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1154 case FSF_ADAPTER_STATUS_AVAILABLE: 1156 case FSF_ADAPTER_STATUS_AVAILABLE:
1155 switch (header->fsf_status_qual.word[0]){ 1157 switch (header->fsf_status_qual.word[0]){
1156 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: 1158 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1157 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1158 zfcp_fc_test_link(port);
1159 /*fall through */
1160 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: 1159 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1161 case FSF_SQ_RETRY_IF_POSSIBLE: 1160 case FSF_SQ_RETRY_IF_POSSIBLE:
1162 req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1161 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
@@ -1188,10 +1187,11 @@ skip_fsfstatus:
1188 * zfcp_fsf_send_els - initiate an ELS command (FC-FS) 1187 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1189 * @els: pointer to struct zfcp_send_els with data for the command 1188 * @els: pointer to struct zfcp_send_els with data for the command
1190 */ 1189 */
1191int zfcp_fsf_send_els(struct zfcp_send_els *els) 1190int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1191 struct zfcp_fsf_ct_els *els)
1192{ 1192{
1193 struct zfcp_fsf_req *req; 1193 struct zfcp_fsf_req *req;
1194 struct zfcp_qdio *qdio = els->adapter->qdio; 1194 struct zfcp_qdio *qdio = adapter->qdio;
1195 int ret = -EIO; 1195 int ret = -EIO;
1196 1196
1197 spin_lock_bh(&qdio->req_q_lock); 1197 spin_lock_bh(&qdio->req_q_lock);
@@ -1211,7 +1211,7 @@ int zfcp_fsf_send_els(struct zfcp_send_els *els)
1211 if (ret) 1211 if (ret)
1212 goto failed_send; 1212 goto failed_send;
1213 1213
1214 req->qtcb->bottom.support.d_id = els->d_id; 1214 hton24(req->qtcb->bottom.support.d_id, d_id);
1215 req->handler = zfcp_fsf_send_els_handler; 1215 req->handler = zfcp_fsf_send_els_handler;
1216 req->data = els; 1216 req->data = els;
1217 1217
@@ -1422,7 +1422,7 @@ static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1422{ 1422{
1423 struct zfcp_port *port = req->data; 1423 struct zfcp_port *port = req->data;
1424 struct fsf_qtcb_header *header = &req->qtcb->header; 1424 struct fsf_qtcb_header *header = &req->qtcb->header;
1425 struct fsf_plogi *plogi; 1425 struct fc_els_flogi *plogi;
1426 1426
1427 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) 1427 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1428 goto out; 1428 goto out;
@@ -1472,23 +1472,10 @@ static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1472 * another GID_PN straight after a port has been opened. 1472 * another GID_PN straight after a port has been opened.
1473 * Alternately, an ADISC/PDISC ELS should suffice, as well. 1473 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1474 */ 1474 */
1475 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els; 1475 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1476 if (req->qtcb->bottom.support.els1_length >= 1476 if (req->qtcb->bottom.support.els1_length >=
1477 FSF_PLOGI_MIN_LEN) { 1477 FSF_PLOGI_MIN_LEN)
1478 if (plogi->serv_param.wwpn != port->wwpn) {
1479 port->d_id = 0;
1480 dev_warn(&port->adapter->ccw_device->dev,
1481 "A port opened with WWPN 0x%016Lx "
1482 "returned data that identifies it as "
1483 "WWPN 0x%016Lx\n",
1484 (unsigned long long) port->wwpn,
1485 (unsigned long long)
1486 plogi->serv_param.wwpn);
1487 } else {
1488 port->wwnn = plogi->serv_param.wwnn;
1489 zfcp_fc_plogi_evaluate(port, plogi); 1478 zfcp_fc_plogi_evaluate(port, plogi);
1490 }
1491 }
1492 break; 1479 break;
1493 case FSF_UNKNOWN_OP_SUBTYPE: 1480 case FSF_UNKNOWN_OP_SUBTYPE:
1494 req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1481 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
@@ -1496,7 +1483,7 @@ static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1496 } 1483 }
1497 1484
1498out: 1485out:
1499 zfcp_port_put(port); 1486 put_device(&port->sysfs_device);
1500} 1487}
1501 1488
1502/** 1489/**
@@ -1530,18 +1517,18 @@ int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1530 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1517 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1531 1518
1532 req->handler = zfcp_fsf_open_port_handler; 1519 req->handler = zfcp_fsf_open_port_handler;
1533 req->qtcb->bottom.support.d_id = port->d_id; 1520 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1534 req->data = port; 1521 req->data = port;
1535 req->erp_action = erp_action; 1522 req->erp_action = erp_action;
1536 erp_action->fsf_req = req; 1523 erp_action->fsf_req = req;
1537 zfcp_port_get(port); 1524 get_device(&port->sysfs_device);
1538 1525
1539 zfcp_fsf_start_erp_timer(req); 1526 zfcp_fsf_start_erp_timer(req);
1540 retval = zfcp_fsf_req_send(req); 1527 retval = zfcp_fsf_req_send(req);
1541 if (retval) { 1528 if (retval) {
1542 zfcp_fsf_req_free(req); 1529 zfcp_fsf_req_free(req);
1543 erp_action->fsf_req = NULL; 1530 erp_action->fsf_req = NULL;
1544 zfcp_port_put(port); 1531 put_device(&port->sysfs_device);
1545 } 1532 }
1546out: 1533out:
1547 spin_unlock_bh(&qdio->req_q_lock); 1534 spin_unlock_bh(&qdio->req_q_lock);
@@ -1618,11 +1605,11 @@ out:
1618 1605
1619static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req) 1606static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1620{ 1607{
1621 struct zfcp_wka_port *wka_port = req->data; 1608 struct zfcp_fc_wka_port *wka_port = req->data;
1622 struct fsf_qtcb_header *header = &req->qtcb->header; 1609 struct fsf_qtcb_header *header = &req->qtcb->header;
1623 1610
1624 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) { 1611 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1625 wka_port->status = ZFCP_WKA_PORT_OFFLINE; 1612 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1626 goto out; 1613 goto out;
1627 } 1614 }
1628 1615
@@ -1635,13 +1622,13 @@ static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1635 req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1622 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1636 /* fall through */ 1623 /* fall through */
1637 case FSF_ACCESS_DENIED: 1624 case FSF_ACCESS_DENIED:
1638 wka_port->status = ZFCP_WKA_PORT_OFFLINE; 1625 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1639 break; 1626 break;
1640 case FSF_GOOD: 1627 case FSF_GOOD:
1641 wka_port->handle = header->port_handle; 1628 wka_port->handle = header->port_handle;
1642 /* fall through */ 1629 /* fall through */
1643 case FSF_PORT_ALREADY_OPEN: 1630 case FSF_PORT_ALREADY_OPEN:
1644 wka_port->status = ZFCP_WKA_PORT_ONLINE; 1631 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1645 } 1632 }
1646out: 1633out:
1647 wake_up(&wka_port->completion_wq); 1634 wake_up(&wka_port->completion_wq);
@@ -1649,10 +1636,10 @@ out:
1649 1636
1650/** 1637/**
1651 * zfcp_fsf_open_wka_port - create and send open wka-port request 1638 * zfcp_fsf_open_wka_port - create and send open wka-port request
1652 * @wka_port: pointer to struct zfcp_wka_port 1639 * @wka_port: pointer to struct zfcp_fc_wka_port
1653 * Returns: 0 on success, error otherwise 1640 * Returns: 0 on success, error otherwise
1654 */ 1641 */
1655int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port) 1642int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1656{ 1643{
1657 struct qdio_buffer_element *sbale; 1644 struct qdio_buffer_element *sbale;
1658 struct zfcp_qdio *qdio = wka_port->adapter->qdio; 1645 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
@@ -1677,7 +1664,7 @@ int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1677 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1664 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1678 1665
1679 req->handler = zfcp_fsf_open_wka_port_handler; 1666 req->handler = zfcp_fsf_open_wka_port_handler;
1680 req->qtcb->bottom.support.d_id = wka_port->d_id; 1667 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1681 req->data = wka_port; 1668 req->data = wka_port;
1682 1669
1683 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); 1670 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
@@ -1691,23 +1678,23 @@ out:
1691 1678
1692static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req) 1679static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1693{ 1680{
1694 struct zfcp_wka_port *wka_port = req->data; 1681 struct zfcp_fc_wka_port *wka_port = req->data;
1695 1682
1696 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) { 1683 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1697 req->status |= ZFCP_STATUS_FSFREQ_ERROR; 1684 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1698 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req); 1685 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1699 } 1686 }
1700 1687
1701 wka_port->status = ZFCP_WKA_PORT_OFFLINE; 1688 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1702 wake_up(&wka_port->completion_wq); 1689 wake_up(&wka_port->completion_wq);
1703} 1690}
1704 1691
1705/** 1692/**
1706 * zfcp_fsf_close_wka_port - create and send close wka port request 1693 * zfcp_fsf_close_wka_port - create and send close wka port request
1707 * @erp_action: pointer to struct zfcp_erp_action 1694 * @wka_port: WKA port to open
1708 * Returns: 0 on success, error otherwise 1695 * Returns: 0 on success, error otherwise
1709 */ 1696 */
1710int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port) 1697int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1711{ 1698{
1712 struct qdio_buffer_element *sbale; 1699 struct qdio_buffer_element *sbale;
1713 struct zfcp_qdio *qdio = wka_port->adapter->qdio; 1700 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
@@ -1765,13 +1752,13 @@ static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1765 /* can't use generic zfcp_erp_modify_port_status because 1752 /* can't use generic zfcp_erp_modify_port_status because
1766 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ 1753 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1767 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); 1754 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1768 list_for_each_entry(unit, &port->unit_list_head, list) 1755 read_lock(&port->unit_list_lock);
1756 list_for_each_entry(unit, &port->unit_list, list)
1769 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, 1757 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1770 &unit->status); 1758 &unit->status);
1759 read_unlock(&port->unit_list_lock);
1771 zfcp_erp_port_boxed(port, "fscpph2", req); 1760 zfcp_erp_port_boxed(port, "fscpph2", req);
1772 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 1761 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1773 ZFCP_STATUS_FSFREQ_RETRY;
1774
1775 break; 1762 break;
1776 case FSF_ADAPTER_STATUS_AVAILABLE: 1763 case FSF_ADAPTER_STATUS_AVAILABLE:
1777 switch (header->fsf_status_qual.word[0]) { 1764 switch (header->fsf_status_qual.word[0]) {
@@ -1787,9 +1774,11 @@ static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1787 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port 1774 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1788 */ 1775 */
1789 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); 1776 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1790 list_for_each_entry(unit, &port->unit_list_head, list) 1777 read_lock(&port->unit_list_lock);
1778 list_for_each_entry(unit, &port->unit_list, list)
1791 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, 1779 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1792 &unit->status); 1780 &unit->status);
1781 read_unlock(&port->unit_list_lock);
1793 break; 1782 break;
1794 } 1783 }
1795} 1784}
@@ -1873,8 +1862,7 @@ static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1873 break; 1862 break;
1874 case FSF_PORT_BOXED: 1863 case FSF_PORT_BOXED:
1875 zfcp_erp_port_boxed(unit->port, "fsouh_2", req); 1864 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1876 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 1865 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1877 ZFCP_STATUS_FSFREQ_RETRY;
1878 break; 1866 break;
1879 case FSF_LUN_SHARING_VIOLATION: 1867 case FSF_LUN_SHARING_VIOLATION:
1880 if (header->fsf_status_qual.word[0]) 1868 if (header->fsf_status_qual.word[0])
@@ -2036,8 +2024,7 @@ static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
2036 break; 2024 break;
2037 case FSF_PORT_BOXED: 2025 case FSF_PORT_BOXED:
2038 zfcp_erp_port_boxed(unit->port, "fscuh_3", req); 2026 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2039 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 2027 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2040 ZFCP_STATUS_FSFREQ_RETRY;
2041 break; 2028 break;
2042 case FSF_ADAPTER_STATUS_AVAILABLE: 2029 case FSF_ADAPTER_STATUS_AVAILABLE:
2043 switch (req->qtcb->header.fsf_status_qual.word[0]) { 2030 switch (req->qtcb->header.fsf_status_qual.word[0]) {
@@ -2109,72 +2096,57 @@ static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2109 lat_rec->max = max(lat_rec->max, lat); 2096 lat_rec->max = max(lat_rec->max, lat);
2110} 2097}
2111 2098
2112static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req) 2099static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2113{ 2100{
2114 struct fsf_qual_latency_info *lat_inf; 2101 struct fsf_qual_latency_info *lat_in;
2115 struct latency_cont *lat; 2102 struct latency_cont *lat = NULL;
2116 struct zfcp_unit *unit = req->unit; 2103 struct zfcp_unit *unit = req->unit;
2104 struct zfcp_blk_drv_data blktrc;
2105 int ticks = req->adapter->timer_ticks;
2117 2106
2118 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info; 2107 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2119
2120 switch (req->qtcb->bottom.io.data_direction) {
2121 case FSF_DATADIR_READ:
2122 lat = &unit->latencies.read;
2123 break;
2124 case FSF_DATADIR_WRITE:
2125 lat = &unit->latencies.write;
2126 break;
2127 case FSF_DATADIR_CMND:
2128 lat = &unit->latencies.cmd;
2129 break;
2130 default:
2131 return;
2132 }
2133 2108
2134 spin_lock(&unit->latencies.lock); 2109 blktrc.flags = 0;
2135 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat); 2110 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2136 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat); 2111 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2137 lat->counter++; 2112 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2138 spin_unlock(&unit->latencies.lock); 2113 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2139} 2114 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2140 2115
2141#ifdef CONFIG_BLK_DEV_IO_TRACE 2116 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2142static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req) 2117 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2143{ 2118 blktrc.channel_lat = lat_in->channel_lat * ticks;
2144 struct fsf_qual_latency_info *lat_inf; 2119 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2145 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data; 2120
2146 struct request *req = scsi_cmnd->request; 2121 switch (req->qtcb->bottom.io.data_direction) {
2147 struct zfcp_blk_drv_data trace; 2122 case FSF_DATADIR_READ:
2148 int ticks = fsf_req->adapter->timer_ticks; 2123 lat = &unit->latencies.read;
2124 break;
2125 case FSF_DATADIR_WRITE:
2126 lat = &unit->latencies.write;
2127 break;
2128 case FSF_DATADIR_CMND:
2129 lat = &unit->latencies.cmd;
2130 break;
2131 }
2149 2132
2150 trace.flags = 0; 2133 if (lat) {
2151 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC; 2134 spin_lock(&unit->latencies.lock);
2152 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) { 2135 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2153 trace.flags |= ZFCP_BLK_LAT_VALID; 2136 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2154 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info; 2137 lat->counter++;
2155 trace.channel_lat = lat_inf->channel_lat * ticks; 2138 spin_unlock(&unit->latencies.lock);
2156 trace.fabric_lat = lat_inf->fabric_lat * ticks; 2139 }
2157 } 2140 }
2158 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2159 trace.flags |= ZFCP_BLK_REQ_ERROR;
2160 trace.inb_usage = fsf_req->queue_req.qdio_inb_usage;
2161 trace.outb_usage = fsf_req->queue_req.qdio_outb_usage;
2162 2141
2163 blk_add_driver_data(req->q, req, &trace, sizeof(trace)); 2142 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2164} 2143 sizeof(blktrc));
2165#else
2166static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2167{
2168} 2144}
2169#endif
2170 2145
2171static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req) 2146static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2172{ 2147{
2173 struct scsi_cmnd *scpnt; 2148 struct scsi_cmnd *scpnt;
2174 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) 2149 struct fcp_resp_with_ext *fcp_rsp;
2175 &(req->qtcb->bottom.io.fcp_rsp);
2176 u32 sns_len;
2177 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2178 unsigned long flags; 2150 unsigned long flags;
2179 2151
2180 read_lock_irqsave(&req->adapter->abort_lock, flags); 2152 read_lock_irqsave(&req->adapter->abort_lock, flags);
@@ -2185,50 +2157,16 @@ static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2185 return; 2157 return;
2186 } 2158 }
2187 2159
2188 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
2189 set_host_byte(scpnt, DID_SOFT_ERROR);
2190 goto skip_fsfstatus;
2191 }
2192
2193 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { 2160 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2194 set_host_byte(scpnt, DID_ERROR); 2161 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2195 goto skip_fsfstatus; 2162 goto skip_fsfstatus;
2196 } 2163 }
2197 2164
2198 set_msg_byte(scpnt, COMMAND_COMPLETE); 2165 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2199 2166 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2200 scpnt->result |= fcp_rsp_iu->scsi_status;
2201 2167
2202 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) 2168 zfcp_fsf_req_trace(req, scpnt);
2203 zfcp_fsf_req_latency(req);
2204
2205 zfcp_fsf_trace_latency(req);
2206
2207 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
2208 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
2209 set_host_byte(scpnt, DID_OK);
2210 else {
2211 set_host_byte(scpnt, DID_ERROR);
2212 goto skip_fsfstatus;
2213 }
2214 }
2215
2216 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
2217 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2218 fcp_rsp_iu->fcp_rsp_len;
2219 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
2220 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
2221
2222 memcpy(scpnt->sense_buffer,
2223 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
2224 }
2225 2169
2226 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
2227 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2228 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2229 scpnt->underflow)
2230 set_host_byte(scpnt, DID_ERROR);
2231 }
2232skip_fsfstatus: 2170skip_fsfstatus:
2233 if (scpnt->result != 0) 2171 if (scpnt->result != 0)
2234 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req); 2172 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
@@ -2250,11 +2188,13 @@ skip_fsfstatus:
2250 2188
2251static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req) 2189static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2252{ 2190{
2253 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) 2191 struct fcp_resp_with_ext *fcp_rsp;
2254 &(req->qtcb->bottom.io.fcp_rsp); 2192 struct fcp_resp_rsp_info *rsp_info;
2255 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; 2193
2194 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2195 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2256 2196
2257 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) || 2197 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2258 (req->status & ZFCP_STATUS_FSFREQ_ERROR)) 2198 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2259 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; 2199 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2260} 2200}
@@ -2314,13 +2254,11 @@ static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2314 break; 2254 break;
2315 case FSF_PORT_BOXED: 2255 case FSF_PORT_BOXED:
2316 zfcp_erp_port_boxed(unit->port, "fssfch5", req); 2256 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2317 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 2257 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2318 ZFCP_STATUS_FSFREQ_RETRY;
2319 break; 2258 break;
2320 case FSF_LUN_BOXED: 2259 case FSF_LUN_BOXED:
2321 zfcp_erp_unit_boxed(unit, "fssfch6", req); 2260 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2322 req->status |= ZFCP_STATUS_FSFREQ_ERROR | 2261 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2323 ZFCP_STATUS_FSFREQ_RETRY;
2324 break; 2262 break;
2325 case FSF_ADAPTER_STATUS_AVAILABLE: 2263 case FSF_ADAPTER_STATUS_AVAILABLE:
2326 if (header->fsf_status_qual.word[0] == 2264 if (header->fsf_status_qual.word[0] ==
@@ -2335,24 +2273,10 @@ skip_fsfstatus:
2335 else { 2273 else {
2336 zfcp_fsf_send_fcp_command_task_handler(req); 2274 zfcp_fsf_send_fcp_command_task_handler(req);
2337 req->unit = NULL; 2275 req->unit = NULL;
2338 zfcp_unit_put(unit); 2276 put_device(&unit->sysfs_device);
2339 } 2277 }
2340} 2278}
2341 2279
2342static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2343{
2344 u32 *fcp_dl_ptr;
2345
2346 /*
2347 * fcp_dl_addr = start address of fcp_cmnd structure +
2348 * size of fixed part + size of dynamically sized add_dcp_cdb field
2349 * SEE FCP-2 documentation
2350 */
2351 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2352 (fcp_cmd->add_fcp_cdb_length << 2));
2353 *fcp_dl_ptr = fcp_dl;
2354}
2355
2356/** 2280/**
2357 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) 2281 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2358 * @unit: unit where command is sent to 2282 * @unit: unit where command is sent to
@@ -2362,7 +2286,7 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2362 struct scsi_cmnd *scsi_cmnd) 2286 struct scsi_cmnd *scsi_cmnd)
2363{ 2287{
2364 struct zfcp_fsf_req *req; 2288 struct zfcp_fsf_req *req;
2365 struct fcp_cmnd_iu *fcp_cmnd_iu; 2289 struct fcp_cmnd *fcp_cmnd;
2366 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ; 2290 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2367 int real_bytes, retval = -EIO; 2291 int real_bytes, retval = -EIO;
2368 struct zfcp_adapter *adapter = unit->port->adapter; 2292 struct zfcp_adapter *adapter = unit->port->adapter;
@@ -2387,23 +2311,21 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2387 } 2311 }
2388 2312
2389 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 2313 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2390 zfcp_unit_get(unit); 2314 get_device(&unit->sysfs_device);
2391 req->unit = unit; 2315 req->unit = unit;
2392 req->data = scsi_cmnd; 2316 req->data = scsi_cmnd;
2393 req->handler = zfcp_fsf_send_fcp_command_handler; 2317 req->handler = zfcp_fsf_send_fcp_command_handler;
2394 req->qtcb->header.lun_handle = unit->handle; 2318 req->qtcb->header.lun_handle = unit->handle;
2395 req->qtcb->header.port_handle = unit->port->handle; 2319 req->qtcb->header.port_handle = unit->port->handle;
2396 req->qtcb->bottom.io.service_class = FSF_CLASS_3; 2320 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2321 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2397 2322
2398 scsi_cmnd->host_scribble = (unsigned char *) req->req_id; 2323 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2399 2324
2400 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2401 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2402 /* 2325 /*
2403 * set depending on data direction: 2326 * set depending on data direction:
2404 * data direction bits in SBALE (SB Type) 2327 * data direction bits in SBALE (SB Type)
2405 * data direction bits in QTCB 2328 * data direction bits in QTCB
2406 * data direction bits in FCP_CMND IU
2407 */ 2329 */
2408 switch (scsi_cmnd->sc_data_direction) { 2330 switch (scsi_cmnd->sc_data_direction) {
2409 case DMA_NONE: 2331 case DMA_NONE:
@@ -2411,32 +2333,17 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2411 break; 2333 break;
2412 case DMA_FROM_DEVICE: 2334 case DMA_FROM_DEVICE:
2413 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; 2335 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2414 fcp_cmnd_iu->rddata = 1;
2415 break; 2336 break;
2416 case DMA_TO_DEVICE: 2337 case DMA_TO_DEVICE:
2417 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; 2338 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2418 sbtype = SBAL_FLAGS0_TYPE_WRITE; 2339 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2419 fcp_cmnd_iu->wddata = 1;
2420 break; 2340 break;
2421 case DMA_BIDIRECTIONAL: 2341 case DMA_BIDIRECTIONAL:
2422 goto failed_scsi_cmnd; 2342 goto failed_scsi_cmnd;
2423 } 2343 }
2424 2344
2425 if (likely((scsi_cmnd->device->simple_tags) || 2345 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2426 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) && 2346 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2427 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2428 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2429 else
2430 fcp_cmnd_iu->task_attribute = UNTAGGED;
2431
2432 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2433 fcp_cmnd_iu->add_fcp_cdb_length =
2434 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2435
2436 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2437
2438 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2439 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
2440 2347
2441 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype, 2348 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
2442 scsi_sglist(scsi_cmnd), 2349 scsi_sglist(scsi_cmnd),
@@ -2454,8 +2361,6 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2454 goto failed_scsi_cmnd; 2361 goto failed_scsi_cmnd;
2455 } 2362 }
2456 2363
2457 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2458
2459 retval = zfcp_fsf_req_send(req); 2364 retval = zfcp_fsf_req_send(req);
2460 if (unlikely(retval)) 2365 if (unlikely(retval))
2461 goto failed_scsi_cmnd; 2366 goto failed_scsi_cmnd;
@@ -2463,7 +2368,7 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2463 goto out; 2368 goto out;
2464 2369
2465failed_scsi_cmnd: 2370failed_scsi_cmnd:
2466 zfcp_unit_put(unit); 2371 put_device(&unit->sysfs_device);
2467 zfcp_fsf_req_free(req); 2372 zfcp_fsf_req_free(req);
2468 scsi_cmnd->host_scribble = NULL; 2373 scsi_cmnd->host_scribble = NULL;
2469out: 2374out:
@@ -2481,7 +2386,7 @@ struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2481{ 2386{
2482 struct qdio_buffer_element *sbale; 2387 struct qdio_buffer_element *sbale;
2483 struct zfcp_fsf_req *req = NULL; 2388 struct zfcp_fsf_req *req = NULL;
2484 struct fcp_cmnd_iu *fcp_cmnd_iu; 2389 struct fcp_cmnd *fcp_cmnd;
2485 struct zfcp_qdio *qdio = unit->port->adapter->qdio; 2390 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2486 2391
2487 if (unlikely(!(atomic_read(&unit->status) & 2392 if (unlikely(!(atomic_read(&unit->status) &
@@ -2507,16 +2412,14 @@ struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2507 req->qtcb->header.port_handle = unit->port->handle; 2412 req->qtcb->header.port_handle = unit->port->handle;
2508 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; 2413 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2509 req->qtcb->bottom.io.service_class = FSF_CLASS_3; 2414 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2510 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + 2415 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2511 sizeof(u32);
2512 2416
2513 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 2417 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2514 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; 2418 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2515 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 2419 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2516 2420
2517 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd; 2421 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2518 fcp_cmnd_iu->fcp_lun = unit->fcp_lun; 2422 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2519 fcp_cmnd_iu->task_management_flags = tm_flags;
2520 2423
2521 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); 2424 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2522 if (!zfcp_fsf_req_send(req)) 2425 if (!zfcp_fsf_req_send(req))
diff --git a/drivers/s390/scsi/zfcp_fsf.h b/drivers/s390/scsi/zfcp_fsf.h
index dcc7c1dbcf58..b3de682b64cf 100644
--- a/drivers/s390/scsi/zfcp_fsf.h
+++ b/drivers/s390/scsi/zfcp_fsf.h
@@ -11,6 +11,7 @@
11 11
12#include <linux/pfn.h> 12#include <linux/pfn.h>
13#include <linux/scatterlist.h> 13#include <linux/scatterlist.h>
14#include <scsi/libfc.h>
14 15
15#define FSF_QTCB_CURRENT_VERSION 0x00000001 16#define FSF_QTCB_CURRENT_VERSION 0x00000001
16 17
@@ -228,7 +229,8 @@ struct fsf_status_read_buffer {
228 u32 length; 229 u32 length;
229 u32 res1; 230 u32 res1;
230 struct fsf_queue_designator queue_designator; 231 struct fsf_queue_designator queue_designator;
231 u32 d_id; 232 u8 res2;
233 u8 d_id[3];
232 u32 class; 234 u32 class;
233 u64 fcp_lun; 235 u64 fcp_lun;
234 u8 res3[24]; 236 u8 res3[24];
@@ -309,22 +311,7 @@ struct fsf_qtcb_header {
309 u8 res4[16]; 311 u8 res4[16];
310} __attribute__ ((packed)); 312} __attribute__ ((packed));
311 313
312struct fsf_nport_serv_param {
313 u8 common_serv_param[16];
314 u64 wwpn;
315 u64 wwnn;
316 u8 class1_serv_param[16];
317 u8 class2_serv_param[16];
318 u8 class3_serv_param[16];
319 u8 class4_serv_param[16];
320 u8 vendor_version_level[16];
321} __attribute__ ((packed));
322
323#define FSF_PLOGI_MIN_LEN 112 314#define FSF_PLOGI_MIN_LEN 112
324struct fsf_plogi {
325 u32 code;
326 struct fsf_nport_serv_param serv_param;
327} __attribute__ ((packed));
328 315
329#define FSF_FCP_CMND_SIZE 288 316#define FSF_FCP_CMND_SIZE 288
330#define FSF_FCP_RSP_SIZE 128 317#define FSF_FCP_RSP_SIZE 128
@@ -342,8 +329,8 @@ struct fsf_qtcb_bottom_io {
342 329
343struct fsf_qtcb_bottom_support { 330struct fsf_qtcb_bottom_support {
344 u32 operation_subtype; 331 u32 operation_subtype;
345 u8 res1[12]; 332 u8 res1[13];
346 u32 d_id; 333 u8 d_id[3];
347 u32 option; 334 u32 option;
348 u64 fcp_lun; 335 u64 fcp_lun;
349 u64 res2; 336 u64 res2;
@@ -372,18 +359,18 @@ struct fsf_qtcb_bottom_config {
372 u32 fc_topology; 359 u32 fc_topology;
373 u32 fc_link_speed; 360 u32 fc_link_speed;
374 u32 adapter_type; 361 u32 adapter_type;
375 u32 peer_d_id; 362 u8 res0;
363 u8 peer_d_id[3];
376 u8 res1[2]; 364 u8 res1[2];
377 u16 timer_interval; 365 u16 timer_interval;
378 u8 res2[8]; 366 u8 res2[9];
379 u32 s_id; 367 u8 s_id[3];
380 struct fsf_nport_serv_param nport_serv_param; 368 u8 nport_serv_param[128];
381 u8 reserved_nport_serv_param[16];
382 u8 res3[8]; 369 u8 res3[8];
383 u32 adapter_ports; 370 u32 adapter_ports;
384 u32 hardware_version; 371 u32 hardware_version;
385 u8 serial_number[32]; 372 u8 serial_number[32];
386 struct fsf_nport_serv_param plogi_payload; 373 u8 plogi_payload[112];
387 struct fsf_statistics_info stat_info; 374 struct fsf_statistics_info stat_info;
388 u8 res4[112]; 375 u8 res4[112];
389} __attribute__ ((packed)); 376} __attribute__ ((packed));
@@ -450,4 +437,22 @@ struct zfcp_blk_drv_data {
450 u64 fabric_lat; 437 u64 fabric_lat;
451} __attribute__ ((packed)); 438} __attribute__ ((packed));
452 439
440/**
441 * struct zfcp_fsf_ct_els - zfcp data for ct or els request
442 * @req: scatter-gather list for request
443 * @resp: scatter-gather list for response
444 * @handler: handler function (called for response to the request)
445 * @handler_data: data passed to handler function
446 * @port: Optional pointer to port for zfcp internal ELS (only test link ADISC)
447 * @status: used to pass error status to calling function
448 */
449struct zfcp_fsf_ct_els {
450 struct scatterlist *req;
451 struct scatterlist *resp;
452 void (*handler)(void *);
453 void *handler_data;
454 struct zfcp_port *port;
455 int status;
456};
457
453#endif /* FSF_H */ 458#endif /* FSF_H */
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 = {
diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c
index d31000886ca8..f539e006683c 100644
--- a/drivers/s390/scsi/zfcp_sysfs.c
+++ b/drivers/s390/scsi/zfcp_sysfs.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * sysfs attributes. 4 * sysfs attributes.
5 * 5 *
6 * Copyright IBM Corporation 2008 6 * Copyright IBM Corporation 2008, 2009
7 */ 7 */
8 8
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
@@ -19,30 +19,44 @@ static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
19 struct device_attribute *at,\ 19 struct device_attribute *at,\
20 char *buf) \ 20 char *buf) \
21{ \ 21{ \
22 struct _feat_def *_feat = dev_get_drvdata(dev); \ 22 struct _feat_def *_feat = container_of(dev, struct _feat_def, \
23 sysfs_device); \
23 \ 24 \
24 return sprintf(buf, _format, _value); \ 25 return sprintf(buf, _format, _value); \
25} \ 26} \
26static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \ 27static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
27 zfcp_sysfs_##_feat##_##_name##_show, NULL); 28 zfcp_sysfs_##_feat##_##_name##_show, NULL);
28 29
29ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, status, "0x%08x\n", 30#define ZFCP_DEFINE_A_ATTR(_name, _format, _value) \
30 atomic_read(&adapter->status)); 31static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
31ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, peer_wwnn, "0x%016llx\n", 32 struct device_attribute *at,\
32 (unsigned long long) adapter->peer_wwnn); 33 char *buf) \
33ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, peer_wwpn, "0x%016llx\n", 34{ \
34 (unsigned long long) adapter->peer_wwpn); 35 struct ccw_device *cdev = to_ccwdev(dev); \
35ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, peer_d_id, "0x%06x\n", 36 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); \
36 adapter->peer_d_id); 37 int i; \
37ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, card_version, "0x%04x\n", 38 \
38 adapter->hydra_version); 39 if (!adapter) \
39ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, lic_version, "0x%08x\n", 40 return -ENODEV; \
40 adapter->fsf_lic_version); 41 \
41ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, hardware_version, "0x%08x\n", 42 i = sprintf(buf, _format, _value); \
42 adapter->hardware_version); 43 zfcp_ccw_adapter_put(adapter); \
43ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, in_recovery, "%d\n", 44 return i; \
44 (atomic_read(&adapter->status) & 45} \
45 ZFCP_STATUS_COMMON_ERP_INUSE) != 0); 46static ZFCP_DEV_ATTR(adapter, _name, S_IRUGO, \
47 zfcp_sysfs_adapter_##_name##_show, NULL);
48
49ZFCP_DEFINE_A_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
50ZFCP_DEFINE_A_ATTR(peer_wwnn, "0x%016llx\n",
51 (unsigned long long) adapter->peer_wwnn);
52ZFCP_DEFINE_A_ATTR(peer_wwpn, "0x%016llx\n",
53 (unsigned long long) adapter->peer_wwpn);
54ZFCP_DEFINE_A_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
55ZFCP_DEFINE_A_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
56ZFCP_DEFINE_A_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
57ZFCP_DEFINE_A_ATTR(hardware_version, "0x%08x\n", adapter->hardware_version);
58ZFCP_DEFINE_A_ATTR(in_recovery, "%d\n", (atomic_read(&adapter->status) &
59 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
46 60
47ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n", 61ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n",
48 atomic_read(&port->status)); 62 atomic_read(&port->status));
@@ -73,7 +87,8 @@ static ssize_t zfcp_sysfs_##_feat##_failed_show(struct device *dev, \
73 struct device_attribute *attr, \ 87 struct device_attribute *attr, \
74 char *buf) \ 88 char *buf) \
75{ \ 89{ \
76 struct _feat_def *_feat = dev_get_drvdata(dev); \ 90 struct _feat_def *_feat = container_of(dev, struct _feat_def, \
91 sysfs_device); \
77 \ 92 \
78 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_ERP_FAILED) \ 93 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_ERP_FAILED) \
79 return sprintf(buf, "1\n"); \ 94 return sprintf(buf, "1\n"); \
@@ -84,15 +99,13 @@ static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
84 struct device_attribute *attr,\ 99 struct device_attribute *attr,\
85 const char *buf, size_t count)\ 100 const char *buf, size_t count)\
86{ \ 101{ \
87 struct _feat_def *_feat = dev_get_drvdata(dev); \ 102 struct _feat_def *_feat = container_of(dev, struct _feat_def, \
103 sysfs_device); \
88 unsigned long val; \ 104 unsigned long val; \
89 int retval = 0; \ 105 int retval = 0; \
90 \ 106 \
91 mutex_lock(&zfcp_data.config_mutex); \ 107 if (!(_feat && get_device(&_feat->sysfs_device))) \
92 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_REMOVE) { \ 108 return -EBUSY; \
93 retval = -EBUSY; \
94 goto out; \
95 } \
96 \ 109 \
97 if (strict_strtoul(buf, 0, &val) || val != 0) { \ 110 if (strict_strtoul(buf, 0, &val) || val != 0) { \
98 retval = -EINVAL; \ 111 retval = -EINVAL; \
@@ -105,29 +118,82 @@ static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
105 _reopen_id, NULL); \ 118 _reopen_id, NULL); \
106 zfcp_erp_wait(_adapter); \ 119 zfcp_erp_wait(_adapter); \
107out: \ 120out: \
108 mutex_unlock(&zfcp_data.config_mutex); \ 121 put_device(&_feat->sysfs_device); \
109 return retval ? retval : (ssize_t) count; \ 122 return retval ? retval : (ssize_t) count; \
110} \ 123} \
111static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \ 124static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \
112 zfcp_sysfs_##_feat##_failed_show, \ 125 zfcp_sysfs_##_feat##_failed_show, \
113 zfcp_sysfs_##_feat##_failed_store); 126 zfcp_sysfs_##_feat##_failed_store);
114 127
115ZFCP_SYSFS_FAILED(zfcp_adapter, adapter, adapter, "syafai1", "syafai2");
116ZFCP_SYSFS_FAILED(zfcp_port, port, port->adapter, "sypfai1", "sypfai2"); 128ZFCP_SYSFS_FAILED(zfcp_port, port, port->adapter, "sypfai1", "sypfai2");
117ZFCP_SYSFS_FAILED(zfcp_unit, unit, unit->port->adapter, "syufai1", "syufai2"); 129ZFCP_SYSFS_FAILED(zfcp_unit, unit, unit->port->adapter, "syufai1", "syufai2");
118 130
131static ssize_t zfcp_sysfs_adapter_failed_show(struct device *dev,
132 struct device_attribute *attr,
133 char *buf)
134{
135 struct ccw_device *cdev = to_ccwdev(dev);
136 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
137 int i;
138
139 if (!adapter)
140 return -ENODEV;
141
142 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
143 i = sprintf(buf, "1\n");
144 else
145 i = sprintf(buf, "0\n");
146
147 zfcp_ccw_adapter_put(adapter);
148 return i;
149}
150
151static ssize_t zfcp_sysfs_adapter_failed_store(struct device *dev,
152 struct device_attribute *attr,
153 const char *buf, size_t count)
154{
155 struct ccw_device *cdev = to_ccwdev(dev);
156 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
157 unsigned long val;
158 int retval = 0;
159
160 if (!adapter)
161 return -ENODEV;
162
163 if (strict_strtoul(buf, 0, &val) || val != 0) {
164 retval = -EINVAL;
165 goto out;
166 }
167
168 zfcp_erp_modify_adapter_status(adapter, "syafai1", NULL,
169 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
170 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
171 "syafai2", NULL);
172 zfcp_erp_wait(adapter);
173out:
174 zfcp_ccw_adapter_put(adapter);
175 return retval ? retval : (ssize_t) count;
176}
177static ZFCP_DEV_ATTR(adapter, failed, S_IWUSR | S_IRUGO,
178 zfcp_sysfs_adapter_failed_show,
179 zfcp_sysfs_adapter_failed_store);
180
119static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev, 181static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
120 struct device_attribute *attr, 182 struct device_attribute *attr,
121 const char *buf, size_t count) 183 const char *buf, size_t count)
122{ 184{
123 struct zfcp_adapter *adapter = dev_get_drvdata(dev); 185 struct ccw_device *cdev = to_ccwdev(dev);
124 int ret; 186 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
125 187
126 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_REMOVE) 188 if (!adapter)
127 return -EBUSY; 189 return -ENODEV;
128 190
129 ret = zfcp_fc_scan_ports(adapter); 191 /* sync the user-space- with the kernel-invocation of scan_work */
130 return ret ? ret : (ssize_t) count; 192 queue_work(adapter->work_queue, &adapter->scan_work);
193 flush_work(&adapter->scan_work);
194 zfcp_ccw_adapter_put(adapter);
195
196 return (ssize_t) count;
131} 197}
132static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL, 198static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL,
133 zfcp_sysfs_port_rescan_store); 199 zfcp_sysfs_port_rescan_store);
@@ -136,44 +202,34 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
136 struct device_attribute *attr, 202 struct device_attribute *attr,
137 const char *buf, size_t count) 203 const char *buf, size_t count)
138{ 204{
139 struct zfcp_adapter *adapter = dev_get_drvdata(dev); 205 struct ccw_device *cdev = to_ccwdev(dev);
206 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
140 struct zfcp_port *port; 207 struct zfcp_port *port;
141 u64 wwpn; 208 u64 wwpn;
142 int retval = 0; 209 int retval = -EINVAL;
143 LIST_HEAD(port_remove_lh);
144 210
145 mutex_lock(&zfcp_data.config_mutex); 211 if (!adapter)
146 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_REMOVE) { 212 return -ENODEV;
147 retval = -EBUSY;
148 goto out;
149 }
150 213
151 if (strict_strtoull(buf, 0, (unsigned long long *) &wwpn)) { 214 if (strict_strtoull(buf, 0, (unsigned long long *) &wwpn))
152 retval = -EINVAL;
153 goto out; 215 goto out;
154 }
155 216
156 write_lock_irq(&zfcp_data.config_lock);
157 port = zfcp_get_port_by_wwpn(adapter, wwpn); 217 port = zfcp_get_port_by_wwpn(adapter, wwpn);
158 if (port && (atomic_read(&port->refcount) == 0)) { 218 if (!port)
159 zfcp_port_get(port);
160 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
161 list_move(&port->list, &port_remove_lh);
162 } else
163 port = NULL;
164 write_unlock_irq(&zfcp_data.config_lock);
165
166 if (!port) {
167 retval = -ENXIO;
168 goto out; 219 goto out;
169 } 220 else
221 retval = 0;
222
223 write_lock_irq(&adapter->port_list_lock);
224 list_del(&port->list);
225 write_unlock_irq(&adapter->port_list_lock);
226
227 put_device(&port->sysfs_device);
170 228
171 zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL); 229 zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL);
172 zfcp_erp_wait(adapter); 230 zfcp_device_unregister(&port->sysfs_device, &zfcp_sysfs_port_attrs);
173 zfcp_port_put(port);
174 zfcp_port_dequeue(port);
175 out: 231 out:
176 mutex_unlock(&zfcp_data.config_mutex); 232 zfcp_ccw_adapter_put(adapter);
177 return retval ? retval : (ssize_t) count; 233 return retval ? retval : (ssize_t) count;
178} 234}
179static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL, 235static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL,
@@ -202,16 +258,14 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
202 struct device_attribute *attr, 258 struct device_attribute *attr,
203 const char *buf, size_t count) 259 const char *buf, size_t count)
204{ 260{
205 struct zfcp_port *port = dev_get_drvdata(dev); 261 struct zfcp_port *port = container_of(dev, struct zfcp_port,
262 sysfs_device);
206 struct zfcp_unit *unit; 263 struct zfcp_unit *unit;
207 u64 fcp_lun; 264 u64 fcp_lun;
208 int retval = -EINVAL; 265 int retval = -EINVAL;
209 266
210 mutex_lock(&zfcp_data.config_mutex); 267 if (!(port && get_device(&port->sysfs_device)))
211 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE) { 268 return -EBUSY;
212 retval = -EBUSY;
213 goto out;
214 }
215 269
216 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) 270 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
217 goto out; 271 goto out;
@@ -219,15 +273,14 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
219 unit = zfcp_unit_enqueue(port, fcp_lun); 273 unit = zfcp_unit_enqueue(port, fcp_lun);
220 if (IS_ERR(unit)) 274 if (IS_ERR(unit))
221 goto out; 275 goto out;
222 276 else
223 retval = 0; 277 retval = 0;
224 278
225 zfcp_erp_unit_reopen(unit, 0, "syuas_1", NULL); 279 zfcp_erp_unit_reopen(unit, 0, "syuas_1", NULL);
226 zfcp_erp_wait(unit->port->adapter); 280 zfcp_erp_wait(unit->port->adapter);
227 flush_work(&unit->scsi_work); 281 flush_work(&unit->scsi_work);
228 zfcp_unit_put(unit);
229out: 282out:
230 mutex_unlock(&zfcp_data.config_mutex); 283 put_device(&port->sysfs_device);
231 return retval ? retval : (ssize_t) count; 284 return retval ? retval : (ssize_t) count;
232} 285}
233static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store); 286static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
@@ -236,54 +289,37 @@ static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
236 struct device_attribute *attr, 289 struct device_attribute *attr,
237 const char *buf, size_t count) 290 const char *buf, size_t count)
238{ 291{
239 struct zfcp_port *port = dev_get_drvdata(dev); 292 struct zfcp_port *port = container_of(dev, struct zfcp_port,
293 sysfs_device);
240 struct zfcp_unit *unit; 294 struct zfcp_unit *unit;
241 u64 fcp_lun; 295 u64 fcp_lun;
242 int retval = 0; 296 int retval = -EINVAL;
243 LIST_HEAD(unit_remove_lh);
244 297
245 mutex_lock(&zfcp_data.config_mutex); 298 if (!(port && get_device(&port->sysfs_device)))
246 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE) { 299 return -EBUSY;
247 retval = -EBUSY;
248 goto out;
249 }
250 300
251 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) { 301 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
252 retval = -EINVAL;
253 goto out; 302 goto out;
254 }
255 303
256 write_lock_irq(&zfcp_data.config_lock);
257 unit = zfcp_get_unit_by_lun(port, fcp_lun); 304 unit = zfcp_get_unit_by_lun(port, fcp_lun);
258 if (unit) { 305 if (!unit)
259 write_unlock_irq(&zfcp_data.config_lock); 306 goto out;
260 /* wait for possible timeout during SCSI probe */ 307 else
261 flush_work(&unit->scsi_work); 308 retval = 0;
262 write_lock_irq(&zfcp_data.config_lock);
263
264 if (atomic_read(&unit->refcount) == 0) {
265 zfcp_unit_get(unit);
266 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
267 &unit->status);
268 list_move(&unit->list, &unit_remove_lh);
269 } else {
270 unit = NULL;
271 }
272 }
273 309
274 write_unlock_irq(&zfcp_data.config_lock); 310 /* wait for possible timeout during SCSI probe */
311 flush_work(&unit->scsi_work);
275 312
276 if (!unit) { 313 write_lock_irq(&port->unit_list_lock);
277 retval = -ENXIO; 314 list_del(&unit->list);
278 goto out; 315 write_unlock_irq(&port->unit_list_lock);
279 } 316
317 put_device(&unit->sysfs_device);
280 318
281 zfcp_erp_unit_shutdown(unit, 0, "syurs_1", NULL); 319 zfcp_erp_unit_shutdown(unit, 0, "syurs_1", NULL);
282 zfcp_erp_wait(unit->port->adapter); 320 zfcp_device_unregister(&unit->sysfs_device, &zfcp_sysfs_unit_attrs);
283 zfcp_unit_put(unit);
284 zfcp_unit_dequeue(unit);
285out: 321out:
286 mutex_unlock(&zfcp_data.config_mutex); 322 put_device(&port->sysfs_device);
287 return retval ? retval : (ssize_t) count; 323 return retval ? retval : (ssize_t) count;
288} 324}
289static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store); 325static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);