| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* zfcp device driver |
| 4 |
* |
| 5 |
* Module interface and handling of zfcp data structures. |
| 6 |
* |
| 7 |
* Copyright IBM Corp. 2002, 2020 |
| 8 |
*/ |
| 9 |
|
| 10 |
/* |
| 11 |
* Driver authors: |
| 12 |
* Martin Peschke (originator of the driver) |
| 13 |
* Raimund Schroeder |
| 14 |
* Aron Zeh |
| 15 |
* Wolfgang Taphorn |
| 16 |
* Stefan Bader |
| 17 |
* Heiko Carstens (kernel 2.6 port of the driver) |
| 18 |
* Andreas Herrmann |
| 19 |
* Maxim Shchetynin |
| 20 |
* Volker Sameske |
| 21 |
* Ralph Wuerthner |
| 22 |
* Michael Loehr |
| 23 |
* Swen Schillig |
| 24 |
* Christof Schmitt |
| 25 |
* Martin Petermann |
| 26 |
* Sven Schuetz |
| 27 |
* Steffen Maier |
| 28 |
* Benjamin Block |
| 29 |
*/ |
| 30 |
|
| 31 |
#define pr_fmt(fmt) "zfcp: " fmt |
| 32 |
|
| 33 |
#include <linux/seq_file.h> |
| 34 |
#include <linux/slab.h> |
| 35 |
#include <linux/module.h> |
| 36 |
#include "zfcp_ext.h" |
| 37 |
#include "zfcp_fc.h" |
| 38 |
#include "zfcp_reqlist.h" |
| 39 |
#include "zfcp_diag.h" |
| 40 |
|
| 41 |
#define ZFCP_BUS_ID_SIZE 20 |
| 42 |
|
| 43 |
MODULE_AUTHOR("IBM Corporation"); |
| 44 |
MODULE_DESCRIPTION("FCP HBA driver"); |
| 45 |
MODULE_LICENSE("GPL"); |
| 46 |
|
| 47 |
static char *init_device; |
| 48 |
module_param_named(device, init_device, charp, 0400); |
| 49 |
MODULE_PARM_DESC(device, "specify initial device"); |
| 50 |
|
| 51 |
static struct kmem_cache * __init zfcp_cache_hw_align(const char *name, |
| 52 |
unsigned long size) |
| 53 |
{ |
| 54 |
return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL); |
| 55 |
} |
| 56 |
|
| 57 |
static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun) |
| 58 |
{ |
| 59 |
struct ccw_device *cdev; |
| 60 |
struct zfcp_adapter *adapter; |
| 61 |
struct zfcp_port *port; |
| 62 |
|
| 63 |
cdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid); |
| 64 |
if (!cdev) |
| 65 |
return; |
| 66 |
|
| 67 |
if (ccw_device_set_online(cdev)) |
| 68 |
goto out_ccw_device; |
| 69 |
|
| 70 |
adapter = zfcp_ccw_adapter_by_cdev(cdev); |
| 71 |
if (!adapter) |
| 72 |
goto out_ccw_device; |
| 73 |
|
| 74 |
port = zfcp_get_port_by_wwpn(adapter, wwpn); |
| 75 |
if (!port) |
| 76 |
goto out_port; |
| 77 |
flush_work(&port->rport_work); |
| 78 |
|
| 79 |
zfcp_unit_add(port, lun); |
| 80 |
put_device(&port->dev); |
| 81 |
|
| 82 |
out_port: |
| 83 |
zfcp_ccw_adapter_put(adapter); |
| 84 |
out_ccw_device: |
| 85 |
put_device(&cdev->dev); |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
static void __init zfcp_init_device_setup(char *devstr) |
| 90 |
{ |
| 91 |
char *token; |
| 92 |
char *str, *str_saved; |
| 93 |
char busid[ZFCP_BUS_ID_SIZE]; |
| 94 |
u64 wwpn, lun; |
| 95 |
|
| 96 |
/* duplicate devstr and keep the original for sysfs presentation*/ |
| 97 |
str_saved = kstrdup(devstr, GFP_KERNEL); |
| 98 |
str = str_saved; |
| 99 |
if (!str) |
| 100 |
return; |
| 101 |
|
| 102 |
token = strsep(&str, ","); |
| 103 |
if (!token || strlen(token) >= ZFCP_BUS_ID_SIZE) |
| 104 |
goto err_out; |
| 105 |
strscpy(busid, token, ZFCP_BUS_ID_SIZE); |
| 106 |
|
| 107 |
token = strsep(&str, ","); |
| 108 |
if (!token || kstrtoull(token, 0, (unsigned long long *) &wwpn)) |
| 109 |
goto err_out; |
| 110 |
|
| 111 |
token = strsep(&str, ","); |
| 112 |
if (!token || kstrtoull(token, 0, (unsigned long long *) &lun)) |
| 113 |
goto err_out; |
| 114 |
|
| 115 |
kfree(str_saved); |
| 116 |
zfcp_init_device_configure(busid, wwpn, lun); |
| 117 |
return; |
| 118 |
|
| 119 |
err_out: |
| 120 |
kfree(str_saved); |
| 121 |
pr_err("%s is not a valid SCSI device\n", devstr); |
| 122 |
} |
| 123 |
|
| 124 |
static int __init zfcp_module_init(void) |
| 125 |
{ |
| 126 |
int retval = -ENOMEM; |
| 127 |
|
| 128 |
if (zfcp_experimental_dix) |
| 129 |
pr_warn("DIX is enabled. It is experimental and might cause problems\n"); |
| 130 |
|
| 131 |
zfcp_fsf_qtcb_cache = zfcp_cache_hw_align("zfcp_fsf_qtcb", |
| 132 |
sizeof(struct fsf_qtcb)); |
| 133 |
if (!zfcp_fsf_qtcb_cache) |
| 134 |
goto out_qtcb_cache; |
| 135 |
|
| 136 |
zfcp_fc_req_cache = zfcp_cache_hw_align("zfcp_fc_req", |
| 137 |
sizeof(struct zfcp_fc_req)); |
| 138 |
if (!zfcp_fc_req_cache) |
| 139 |
goto out_fc_cache; |
| 140 |
|
| 141 |
zfcp_scsi_transport_template = |
| 142 |
fc_attach_transport(&zfcp_transport_functions); |
| 143 |
if (!zfcp_scsi_transport_template) |
| 144 |
goto out_transport; |
| 145 |
scsi_transport_reserve_device(zfcp_scsi_transport_template, |
| 146 |
sizeof(struct zfcp_scsi_dev)); |
| 147 |
|
| 148 |
retval = ccw_driver_register(&zfcp_ccw_driver); |
| 149 |
if (retval) { |
| 150 |
pr_err("The zfcp device driver could not register with " |
| 151 |
"the common I/O layer\n"); |
| 152 |
goto out_ccw_register; |
| 153 |
} |
| 154 |
|
| 155 |
if (init_device) |
| 156 |
zfcp_init_device_setup(init_device); |
| 157 |
return 0; |
| 158 |
|
| 159 |
out_ccw_register: |
| 160 |
fc_release_transport(zfcp_scsi_transport_template); |
| 161 |
out_transport: |
| 162 |
kmem_cache_destroy(zfcp_fc_req_cache); |
| 163 |
out_fc_cache: |
| 164 |
kmem_cache_destroy(zfcp_fsf_qtcb_cache); |
| 165 |
out_qtcb_cache: |
| 166 |
return retval; |
| 167 |
} |
| 168 |
|
| 169 |
module_init(zfcp_module_init); |
| 170 |
|
| 171 |
static void __exit zfcp_module_exit(void) |
| 172 |
{ |
| 173 |
ccw_driver_unregister(&zfcp_ccw_driver); |
| 174 |
fc_release_transport(zfcp_scsi_transport_template); |
| 175 |
kmem_cache_destroy(zfcp_fc_req_cache); |
| 176 |
kmem_cache_destroy(zfcp_fsf_qtcb_cache); |
| 177 |
} |
| 178 |
|
| 179 |
module_exit(zfcp_module_exit); |
| 180 |
|
| 181 |
/** |
| 182 |
* zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn |
| 183 |
* @adapter: pointer to adapter to search for port |
| 184 |
* @wwpn: wwpn to search for |
| 185 |
* |
| 186 |
* Returns: pointer to zfcp_port or NULL |
| 187 |
*/ |
| 188 |
struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, |
| 189 |
u64 wwpn) |
| 190 |
{ |
| 191 |
unsigned long flags; |
| 192 |
struct zfcp_port *port; |
| 193 |
|
| 194 |
read_lock_irqsave(&adapter->port_list_lock, flags); |
| 195 |
list_for_each_entry(port, &adapter->port_list, list) |
| 196 |
if (port->wwpn == wwpn) { |
| 197 |
if (!get_device(&port->dev)) |
| 198 |
port = NULL; |
| 199 |
read_unlock_irqrestore(&adapter->port_list_lock, flags); |
| 200 |
return port; |
| 201 |
} |
| 202 |
read_unlock_irqrestore(&adapter->port_list_lock, flags); |
| 203 |
return NULL; |
| 204 |
} |
| 205 |
|
| 206 |
static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter) |
| 207 |
{ |
| 208 |
adapter->pool.erp_req = |
| 209 |
mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 210 |
if (!adapter->pool.erp_req) |
| 211 |
return -ENOMEM; |
| 212 |
|
| 213 |
adapter->pool.gid_pn_req = |
| 214 |
mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 215 |
if (!adapter->pool.gid_pn_req) |
| 216 |
return -ENOMEM; |
| 217 |
|
| 218 |
adapter->pool.scsi_req = |
| 219 |
mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 220 |
if (!adapter->pool.scsi_req) |
| 221 |
return -ENOMEM; |
| 222 |
|
| 223 |
adapter->pool.scsi_abort = |
| 224 |
mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 225 |
if (!adapter->pool.scsi_abort) |
| 226 |
return -ENOMEM; |
| 227 |
|
| 228 |
adapter->pool.status_read_req = |
| 229 |
mempool_create_kmalloc_pool(FSF_STATUS_READS_RECOM, |
| 230 |
sizeof(struct zfcp_fsf_req)); |
| 231 |
if (!adapter->pool.status_read_req) |
| 232 |
return -ENOMEM; |
| 233 |
|
| 234 |
adapter->pool.qtcb_pool = |
| 235 |
mempool_create_slab_pool(4, zfcp_fsf_qtcb_cache); |
| 236 |
if (!adapter->pool.qtcb_pool) |
| 237 |
return -ENOMEM; |
| 238 |
|
| 239 |
BUILD_BUG_ON(sizeof(struct fsf_status_read_buffer) > PAGE_SIZE); |
| 240 |
adapter->pool.sr_data = |
| 241 |
mempool_create_page_pool(FSF_STATUS_READS_RECOM, 0); |
| 242 |
if (!adapter->pool.sr_data) |
| 243 |
return -ENOMEM; |
| 244 |
|
| 245 |
adapter->pool.gid_pn = |
| 246 |
mempool_create_slab_pool(1, zfcp_fc_req_cache); |
| 247 |
if (!adapter->pool.gid_pn) |
| 248 |
return -ENOMEM; |
| 249 |
|
| 250 |
return 0; |
| 251 |
} |
| 252 |
|
| 253 |
static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter) |
| 254 |
{ |
| 255 |
mempool_destroy(adapter->pool.erp_req); |
| 256 |
mempool_destroy(adapter->pool.scsi_req); |
| 257 |
mempool_destroy(adapter->pool.scsi_abort); |
| 258 |
mempool_destroy(adapter->pool.qtcb_pool); |
| 259 |
mempool_destroy(adapter->pool.status_read_req); |
| 260 |
mempool_destroy(adapter->pool.sr_data); |
| 261 |
mempool_destroy(adapter->pool.gid_pn); |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* zfcp_status_read_refill - refill the long running status_read_requests |
| 266 |
* @adapter: ptr to struct zfcp_adapter for which the buffers should be refilled |
| 267 |
* |
| 268 |
* Return: |
| 269 |
* * 0 on success meaning at least one status read is pending |
| 270 |
* * 1 if posting failed and not a single status read buffer is pending, |
| 271 |
* also triggers adapter reopen recovery |
| 272 |
*/ |
| 273 |
int zfcp_status_read_refill(struct zfcp_adapter *adapter) |
| 274 |
{ |
| 275 |
while (atomic_add_unless(&adapter->stat_miss, -1, 0)) |
| 276 |
if (zfcp_fsf_status_read(adapter->qdio)) { |
| 277 |
atomic_inc(&adapter->stat_miss); /* undo add -1 */ |
| 278 |
if (atomic_read(&adapter->stat_miss) >= |
| 279 |
adapter->stat_read_buf_num) { |
| 280 |
zfcp_erp_adapter_reopen(adapter, 0, "axsref1"); |
| 281 |
return 1; |
| 282 |
} |
| 283 |
break; |
| 284 |
} |
| 285 |
return 0; |
| 286 |
} |
| 287 |
|
| 288 |
static void _zfcp_status_read_scheduler(struct work_struct *work) |
| 289 |
{ |
| 290 |
zfcp_status_read_refill(container_of(work, struct zfcp_adapter, |
| 291 |
stat_work)); |
| 292 |
} |
| 293 |
|
| 294 |
static void zfcp_version_change_lost_work(struct work_struct *work) |
| 295 |
{ |
| 296 |
struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter, |
| 297 |
version_change_lost_work); |
| 298 |
|
| 299 |
zfcp_fsf_exchange_config_data_sync(adapter->qdio, NULL); |
| 300 |
} |
| 301 |
|
| 302 |
static void zfcp_print_sl(struct seq_file *m, struct service_level *sl) |
| 303 |
{ |
| 304 |
struct zfcp_adapter *adapter = |
| 305 |
container_of(sl, struct zfcp_adapter, service_level); |
| 306 |
|
| 307 |
seq_printf(m, "zfcp: %s microcode level %x\n", |
| 308 |
dev_name(&adapter->ccw_device->dev), |
| 309 |
adapter->fsf_lic_version); |
| 310 |
} |
| 311 |
|
| 312 |
static int zfcp_setup_adapter_work_queue(struct zfcp_adapter *adapter) |
| 313 |
{ |
| 314 |
adapter->work_queue = |
| 315 |
alloc_ordered_workqueue("zfcp_q_%s", WQ_MEM_RECLAIM, |
| 316 |
dev_name(&adapter->ccw_device->dev)); |
| 317 |
if (!adapter->work_queue) |
| 318 |
return -ENOMEM; |
| 319 |
|
| 320 |
return 0; |
| 321 |
} |
| 322 |
|
| 323 |
static void zfcp_destroy_adapter_work_queue(struct zfcp_adapter *adapter) |
| 324 |
{ |
| 325 |
if (adapter->work_queue) |
| 326 |
destroy_workqueue(adapter->work_queue); |
| 327 |
adapter->work_queue = NULL; |
| 328 |
|
| 329 |
} |
| 330 |
|
| 331 |
/** |
| 332 |
* zfcp_adapter_enqueue - enqueue a new adapter to the list |
| 333 |
* @ccw_device: pointer to the struct cc_device |
| 334 |
* |
| 335 |
* Returns: struct zfcp_adapter* |
| 336 |
* Enqueues an adapter at the end of the adapter list in the driver data. |
| 337 |
* All adapter internal structures are set up. |
| 338 |
* Proc-fs entries are also created. |
| 339 |
*/ |
| 340 |
struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device) |
| 341 |
{ |
| 342 |
struct zfcp_adapter *adapter; |
| 343 |
|
| 344 |
if (!get_device(&ccw_device->dev)) |
| 345 |
return ERR_PTR(-ENODEV); |
| 346 |
|
| 347 |
adapter = kzalloc_obj(struct zfcp_adapter); |
| 348 |
if (!adapter) { |
| 349 |
put_device(&ccw_device->dev); |
| 350 |
return ERR_PTR(-ENOMEM); |
| 351 |
} |
| 352 |
|
| 353 |
kref_init(&adapter->ref); |
| 354 |
|
| 355 |
ccw_device->handler = NULL; |
| 356 |
adapter->ccw_device = ccw_device; |
| 357 |
|
| 358 |
INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler); |
| 359 |
INIT_DELAYED_WORK(&adapter->scan_work, zfcp_fc_scan_ports); |
| 360 |
INIT_WORK(&adapter->ns_up_work, zfcp_fc_sym_name_update); |
| 361 |
INIT_WORK(&adapter->version_change_lost_work, |
| 362 |
zfcp_version_change_lost_work); |
| 363 |
|
| 364 |
adapter->next_port_scan = jiffies; |
| 365 |
|
| 366 |
adapter->erp_action.adapter = adapter; |
| 367 |
|
| 368 |
if (zfcp_diag_adapter_setup(adapter)) |
| 369 |
goto failed; |
| 370 |
|
| 371 |
if (zfcp_qdio_setup(adapter)) |
| 372 |
goto failed; |
| 373 |
|
| 374 |
if (zfcp_allocate_low_mem_buffers(adapter)) |
| 375 |
goto failed; |
| 376 |
|
| 377 |
adapter->req_list = zfcp_reqlist_alloc(); |
| 378 |
if (!adapter->req_list) |
| 379 |
goto failed; |
| 380 |
|
| 381 |
if (zfcp_dbf_adapter_register(adapter)) |
| 382 |
goto failed; |
| 383 |
|
| 384 |
if (zfcp_setup_adapter_work_queue(adapter)) |
| 385 |
goto failed; |
| 386 |
|
| 387 |
if (zfcp_fc_gs_setup(adapter)) |
| 388 |
goto failed; |
| 389 |
|
| 390 |
rwlock_init(&adapter->port_list_lock); |
| 391 |
INIT_LIST_HEAD(&adapter->port_list); |
| 392 |
|
| 393 |
INIT_LIST_HEAD(&adapter->events.list); |
| 394 |
INIT_WORK(&adapter->events.work, zfcp_fc_post_event); |
| 395 |
spin_lock_init(&adapter->events.list_lock); |
| 396 |
|
| 397 |
init_waitqueue_head(&adapter->erp_ready_wq); |
| 398 |
init_waitqueue_head(&adapter->erp_done_wqh); |
| 399 |
|
| 400 |
INIT_LIST_HEAD(&adapter->erp_ready_head); |
| 401 |
INIT_LIST_HEAD(&adapter->erp_running_head); |
| 402 |
|
| 403 |
rwlock_init(&adapter->erp_lock); |
| 404 |
rwlock_init(&adapter->abort_lock); |
| 405 |
|
| 406 |
if (zfcp_erp_thread_setup(adapter)) |
| 407 |
goto failed; |
| 408 |
|
| 409 |
adapter->service_level.seq_print = zfcp_print_sl; |
| 410 |
|
| 411 |
dev_set_drvdata(&ccw_device->dev, adapter); |
| 412 |
|
| 413 |
if (device_add_groups(&ccw_device->dev, zfcp_sysfs_adapter_attr_groups)) |
| 414 |
goto err_sysfs; |
| 415 |
|
| 416 |
/* report size limit per scatter-gather segment */ |
| 417 |
adapter->ccw_device->dev.dma_parms = &adapter->dma_parms; |
| 418 |
|
| 419 |
adapter->stat_read_buf_num = FSF_STATUS_READS_RECOM; |
| 420 |
|
| 421 |
return adapter; |
| 422 |
|
| 423 |
err_sysfs: |
| 424 |
failed: |
| 425 |
/* TODO: make this more fine-granular */ |
| 426 |
cancel_delayed_work_sync(&adapter->scan_work); |
| 427 |
cancel_work_sync(&adapter->stat_work); |
| 428 |
cancel_work_sync(&adapter->ns_up_work); |
| 429 |
cancel_work_sync(&adapter->version_change_lost_work); |
| 430 |
zfcp_destroy_adapter_work_queue(adapter); |
| 431 |
|
| 432 |
zfcp_fc_wka_ports_force_offline(adapter->gs); |
| 433 |
zfcp_scsi_adapter_unregister(adapter); |
| 434 |
|
| 435 |
zfcp_erp_thread_kill(adapter); |
| 436 |
zfcp_dbf_adapter_unregister(adapter); |
| 437 |
zfcp_qdio_destroy(adapter->qdio); |
| 438 |
|
| 439 |
zfcp_ccw_adapter_put(adapter); /* final put to release */ |
| 440 |
return ERR_PTR(-ENOMEM); |
| 441 |
} |
| 442 |
|
| 443 |
void zfcp_adapter_unregister(struct zfcp_adapter *adapter) |
| 444 |
{ |
| 445 |
struct ccw_device *cdev = adapter->ccw_device; |
| 446 |
|
| 447 |
cancel_delayed_work_sync(&adapter->scan_work); |
| 448 |
cancel_work_sync(&adapter->stat_work); |
| 449 |
cancel_work_sync(&adapter->ns_up_work); |
| 450 |
cancel_work_sync(&adapter->version_change_lost_work); |
| 451 |
zfcp_destroy_adapter_work_queue(adapter); |
| 452 |
|
| 453 |
zfcp_fc_wka_ports_force_offline(adapter->gs); |
| 454 |
zfcp_scsi_adapter_unregister(adapter); |
| 455 |
device_remove_groups(&cdev->dev, zfcp_sysfs_adapter_attr_groups); |
| 456 |
|
| 457 |
zfcp_erp_thread_kill(adapter); |
| 458 |
zfcp_dbf_adapter_unregister(adapter); |
| 459 |
zfcp_qdio_destroy(adapter->qdio); |
| 460 |
|
| 461 |
zfcp_ccw_adapter_put(adapter); /* final put to release */ |
| 462 |
} |
| 463 |
|
| 464 |
/** |
| 465 |
* zfcp_adapter_release - remove the adapter from the resource list |
| 466 |
* @ref: pointer to struct kref |
| 467 |
* locks: adapter list write lock is assumed to be held by caller |
| 468 |
*/ |
| 469 |
void zfcp_adapter_release(struct kref *ref) |
| 470 |
{ |
| 471 |
struct zfcp_adapter *adapter = container_of(ref, struct zfcp_adapter, |
| 472 |
ref); |
| 473 |
struct ccw_device *cdev = adapter->ccw_device; |
| 474 |
|
| 475 |
dev_set_drvdata(&adapter->ccw_device->dev, NULL); |
| 476 |
zfcp_fc_gs_destroy(adapter); |
| 477 |
zfcp_free_low_mem_buffers(adapter); |
| 478 |
zfcp_diag_adapter_free(adapter); |
| 479 |
kfree(adapter->req_list); |
| 480 |
kfree(adapter->fc_stats); |
| 481 |
kfree(adapter->stats_reset_data); |
| 482 |
kfree(adapter); |
| 483 |
put_device(&cdev->dev); |
| 484 |
} |
| 485 |
|
| 486 |
static void zfcp_port_release(struct device *dev) |
| 487 |
{ |
| 488 |
struct zfcp_port *port = container_of(dev, struct zfcp_port, dev); |
| 489 |
|
| 490 |
zfcp_ccw_adapter_put(port->adapter); |
| 491 |
kfree(port); |
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* zfcp_port_enqueue - enqueue port to port list of adapter |
| 496 |
* @adapter: adapter where remote port is added |
| 497 |
* @wwpn: WWPN of the remote port to be enqueued |
| 498 |
* @status: initial status for the port |
| 499 |
* @d_id: destination id of the remote port to be enqueued |
| 500 |
* Returns: pointer to enqueued port on success, ERR_PTR on error |
| 501 |
* |
| 502 |
* All port internal structures are set up and the sysfs entry is generated. |
| 503 |
* d_id is used to enqueue ports with a well known address like the Directory |
| 504 |
* Service for nameserver lookup. |
| 505 |
*/ |
| 506 |
struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn, |
| 507 |
u32 status, u32 d_id) |
| 508 |
{ |
| 509 |
struct zfcp_port *port; |
| 510 |
int retval = -ENOMEM; |
| 511 |
|
| 512 |
kref_get(&adapter->ref); |
| 513 |
|
| 514 |
port = zfcp_get_port_by_wwpn(adapter, wwpn); |
| 515 |
if (port) { |
| 516 |
put_device(&port->dev); |
| 517 |
retval = -EEXIST; |
| 518 |
goto err_put; |
| 519 |
} |
| 520 |
|
| 521 |
port = kzalloc_obj(struct zfcp_port); |
| 522 |
if (!port) |
| 523 |
goto err_put; |
| 524 |
|
| 525 |
rwlock_init(&port->unit_list_lock); |
| 526 |
INIT_LIST_HEAD(&port->unit_list); |
| 527 |
atomic_set(&port->units, 0); |
| 528 |
|
| 529 |
INIT_WORK(&port->gid_pn_work, zfcp_fc_port_did_lookup); |
| 530 |
INIT_WORK(&port->test_link_work, zfcp_fc_link_test_work); |
| 531 |
INIT_WORK(&port->rport_work, zfcp_scsi_rport_work); |
| 532 |
|
| 533 |
port->adapter = adapter; |
| 534 |
port->d_id = d_id; |
| 535 |
port->wwpn = wwpn; |
| 536 |
port->rport_task = RPORT_NONE; |
| 537 |
port->dev.parent = &adapter->ccw_device->dev; |
| 538 |
port->dev.groups = zfcp_port_attr_groups; |
| 539 |
port->dev.release = zfcp_port_release; |
| 540 |
|
| 541 |
port->erp_action.adapter = adapter; |
| 542 |
port->erp_action.port = port; |
| 543 |
|
| 544 |
if (dev_set_name(&port->dev, "0x%016llx", (unsigned long long)wwpn)) { |
| 545 |
kfree(port); |
| 546 |
goto err_put; |
| 547 |
} |
| 548 |
retval = -EINVAL; |
| 549 |
|
| 550 |
if (device_register(&port->dev)) { |
| 551 |
put_device(&port->dev); |
| 552 |
goto err_out; |
| 553 |
} |
| 554 |
|
| 555 |
write_lock_irq(&adapter->port_list_lock); |
| 556 |
list_add_tail(&port->list, &adapter->port_list); |
| 557 |
write_unlock_irq(&adapter->port_list_lock); |
| 558 |
|
| 559 |
atomic_or(status | ZFCP_STATUS_COMMON_RUNNING, &port->status); |
| 560 |
|
| 561 |
return port; |
| 562 |
|
| 563 |
err_put: |
| 564 |
zfcp_ccw_adapter_put(adapter); |
| 565 |
err_out: |
| 566 |
return ERR_PTR(retval); |
| 567 |
} |