This source file includes following definitions.
- zfcp_cache_hw_align
- zfcp_init_device_configure
- zfcp_init_device_setup
- zfcp_module_init
- zfcp_module_exit
- zfcp_get_port_by_wwpn
- zfcp_allocate_low_mem_buffers
- zfcp_free_low_mem_buffers
- zfcp_status_read_refill
- _zfcp_status_read_scheduler
- zfcp_print_sl
- zfcp_setup_adapter_work_queue
- zfcp_destroy_adapter_work_queue
- zfcp_adapter_enqueue
- zfcp_adapter_unregister
- zfcp_adapter_release
- zfcp_port_release
- zfcp_port_enqueue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #define KMSG_COMPONENT "zfcp"
31 #define pr_fmt(fmt) KMSG_COMPONENT ": " 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
40 #define ZFCP_BUS_ID_SIZE 20
41
42 MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
43 MODULE_DESCRIPTION("FCP HBA driver");
44 MODULE_LICENSE("GPL");
45
46 static char *init_device;
47 module_param_named(device, init_device, charp, 0400);
48 MODULE_PARM_DESC(device, "specify initial device");
49
50 static struct kmem_cache * __init zfcp_cache_hw_align(const char *name,
51 unsigned long size)
52 {
53 return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL);
54 }
55
56 static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun)
57 {
58 struct ccw_device *cdev;
59 struct zfcp_adapter *adapter;
60 struct zfcp_port *port;
61
62 cdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
63 if (!cdev)
64 return;
65
66 if (ccw_device_set_online(cdev))
67 goto out_ccw_device;
68
69 adapter = zfcp_ccw_adapter_by_cdev(cdev);
70 if (!adapter)
71 goto out_ccw_device;
72
73 port = zfcp_get_port_by_wwpn(adapter, wwpn);
74 if (!port)
75 goto out_port;
76 flush_work(&port->rport_work);
77
78 zfcp_unit_add(port, lun);
79 put_device(&port->dev);
80
81 out_port:
82 zfcp_ccw_adapter_put(adapter);
83 out_ccw_device:
84 put_device(&cdev->dev);
85 return;
86 }
87
88 static void __init zfcp_init_device_setup(char *devstr)
89 {
90 char *token;
91 char *str, *str_saved;
92 char busid[ZFCP_BUS_ID_SIZE];
93 u64 wwpn, lun;
94
95
96 str_saved = kstrdup(devstr, GFP_KERNEL);
97 str = str_saved;
98 if (!str)
99 return;
100
101 token = strsep(&str, ",");
102 if (!token || strlen(token) >= ZFCP_BUS_ID_SIZE)
103 goto err_out;
104 strlcpy(busid, token, ZFCP_BUS_ID_SIZE);
105
106 token = strsep(&str, ",");
107 if (!token || kstrtoull(token, 0, (unsigned long long *) &wwpn))
108 goto err_out;
109
110 token = strsep(&str, ",");
111 if (!token || kstrtoull(token, 0, (unsigned long long *) &lun))
112 goto err_out;
113
114 kfree(str_saved);
115 zfcp_init_device_configure(busid, wwpn, lun);
116 return;
117
118 err_out:
119 kfree(str_saved);
120 pr_err("%s is not a valid SCSI device\n", devstr);
121 }
122
123 static int __init zfcp_module_init(void)
124 {
125 int retval = -ENOMEM;
126
127 if (zfcp_experimental_dix)
128 pr_warn("DIX is enabled. It is experimental and might cause problems\n");
129
130 zfcp_fsf_qtcb_cache = zfcp_cache_hw_align("zfcp_fsf_qtcb",
131 sizeof(struct fsf_qtcb));
132 if (!zfcp_fsf_qtcb_cache)
133 goto out_qtcb_cache;
134
135 zfcp_fc_req_cache = zfcp_cache_hw_align("zfcp_fc_req",
136 sizeof(struct zfcp_fc_req));
137 if (!zfcp_fc_req_cache)
138 goto out_fc_cache;
139
140 zfcp_scsi_transport_template =
141 fc_attach_transport(&zfcp_transport_functions);
142 if (!zfcp_scsi_transport_template)
143 goto out_transport;
144 scsi_transport_reserve_device(zfcp_scsi_transport_template,
145 sizeof(struct zfcp_scsi_dev));
146
147 retval = ccw_driver_register(&zfcp_ccw_driver);
148 if (retval) {
149 pr_err("The zfcp device driver could not register with "
150 "the common I/O layer\n");
151 goto out_ccw_register;
152 }
153
154 if (init_device)
155 zfcp_init_device_setup(init_device);
156 return 0;
157
158 out_ccw_register:
159 fc_release_transport(zfcp_scsi_transport_template);
160 out_transport:
161 kmem_cache_destroy(zfcp_fc_req_cache);
162 out_fc_cache:
163 kmem_cache_destroy(zfcp_fsf_qtcb_cache);
164 out_qtcb_cache:
165 return retval;
166 }
167
168 module_init(zfcp_module_init);
169
170 static void __exit zfcp_module_exit(void)
171 {
172 ccw_driver_unregister(&zfcp_ccw_driver);
173 fc_release_transport(zfcp_scsi_transport_template);
174 kmem_cache_destroy(zfcp_fc_req_cache);
175 kmem_cache_destroy(zfcp_fsf_qtcb_cache);
176 }
177
178 module_exit(zfcp_module_exit);
179
180
181
182
183
184
185
186
187 struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
188 u64 wwpn)
189 {
190 unsigned long flags;
191 struct zfcp_port *port;
192
193 read_lock_irqsave(&adapter->port_list_lock, flags);
194 list_for_each_entry(port, &adapter->port_list, list)
195 if (port->wwpn == wwpn) {
196 if (!get_device(&port->dev))
197 port = NULL;
198 read_unlock_irqrestore(&adapter->port_list_lock, flags);
199 return port;
200 }
201 read_unlock_irqrestore(&adapter->port_list_lock, flags);
202 return NULL;
203 }
204
205 static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
206 {
207 adapter->pool.erp_req =
208 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
209 if (!adapter->pool.erp_req)
210 return -ENOMEM;
211
212 adapter->pool.gid_pn_req =
213 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
214 if (!adapter->pool.gid_pn_req)
215 return -ENOMEM;
216
217 adapter->pool.scsi_req =
218 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
219 if (!adapter->pool.scsi_req)
220 return -ENOMEM;
221
222 adapter->pool.scsi_abort =
223 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
224 if (!adapter->pool.scsi_abort)
225 return -ENOMEM;
226
227 adapter->pool.status_read_req =
228 mempool_create_kmalloc_pool(FSF_STATUS_READS_RECOM,
229 sizeof(struct zfcp_fsf_req));
230 if (!adapter->pool.status_read_req)
231 return -ENOMEM;
232
233 adapter->pool.qtcb_pool =
234 mempool_create_slab_pool(4, zfcp_fsf_qtcb_cache);
235 if (!adapter->pool.qtcb_pool)
236 return -ENOMEM;
237
238 BUILD_BUG_ON(sizeof(struct fsf_status_read_buffer) > PAGE_SIZE);
239 adapter->pool.sr_data =
240 mempool_create_page_pool(FSF_STATUS_READS_RECOM, 0);
241 if (!adapter->pool.sr_data)
242 return -ENOMEM;
243
244 adapter->pool.gid_pn =
245 mempool_create_slab_pool(1, zfcp_fc_req_cache);
246 if (!adapter->pool.gid_pn)
247 return -ENOMEM;
248
249 return 0;
250 }
251
252 static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
253 {
254 mempool_destroy(adapter->pool.erp_req);
255 mempool_destroy(adapter->pool.scsi_req);
256 mempool_destroy(adapter->pool.scsi_abort);
257 mempool_destroy(adapter->pool.qtcb_pool);
258 mempool_destroy(adapter->pool.status_read_req);
259 mempool_destroy(adapter->pool.sr_data);
260 mempool_destroy(adapter->pool.gid_pn);
261 }
262
263
264
265
266
267
268
269
270
271
272 int zfcp_status_read_refill(struct zfcp_adapter *adapter)
273 {
274 while (atomic_add_unless(&adapter->stat_miss, -1, 0))
275 if (zfcp_fsf_status_read(adapter->qdio)) {
276 atomic_inc(&adapter->stat_miss);
277 if (atomic_read(&adapter->stat_miss) >=
278 adapter->stat_read_buf_num) {
279 zfcp_erp_adapter_reopen(adapter, 0, "axsref1");
280 return 1;
281 }
282 break;
283 }
284 return 0;
285 }
286
287 static void _zfcp_status_read_scheduler(struct work_struct *work)
288 {
289 zfcp_status_read_refill(container_of(work, struct zfcp_adapter,
290 stat_work));
291 }
292
293 static void zfcp_print_sl(struct seq_file *m, struct service_level *sl)
294 {
295 struct zfcp_adapter *adapter =
296 container_of(sl, struct zfcp_adapter, service_level);
297
298 seq_printf(m, "zfcp: %s microcode level %x\n",
299 dev_name(&adapter->ccw_device->dev),
300 adapter->fsf_lic_version);
301 }
302
303 static int zfcp_setup_adapter_work_queue(struct zfcp_adapter *adapter)
304 {
305 char name[TASK_COMM_LEN];
306
307 snprintf(name, sizeof(name), "zfcp_q_%s",
308 dev_name(&adapter->ccw_device->dev));
309 adapter->work_queue = alloc_ordered_workqueue(name, WQ_MEM_RECLAIM);
310
311 if (adapter->work_queue)
312 return 0;
313 return -ENOMEM;
314 }
315
316 static void zfcp_destroy_adapter_work_queue(struct zfcp_adapter *adapter)
317 {
318 if (adapter->work_queue)
319 destroy_workqueue(adapter->work_queue);
320 adapter->work_queue = NULL;
321
322 }
323
324
325
326
327
328
329
330
331
332
333 struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
334 {
335 struct zfcp_adapter *adapter;
336
337 if (!get_device(&ccw_device->dev))
338 return ERR_PTR(-ENODEV);
339
340 adapter = kzalloc(sizeof(struct zfcp_adapter), GFP_KERNEL);
341 if (!adapter) {
342 put_device(&ccw_device->dev);
343 return ERR_PTR(-ENOMEM);
344 }
345
346 kref_init(&adapter->ref);
347
348 ccw_device->handler = NULL;
349 adapter->ccw_device = ccw_device;
350
351 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
352 INIT_DELAYED_WORK(&adapter->scan_work, zfcp_fc_scan_ports);
353 INIT_WORK(&adapter->ns_up_work, zfcp_fc_sym_name_update);
354
355 adapter->next_port_scan = jiffies;
356
357 adapter->erp_action.adapter = adapter;
358
359 if (zfcp_qdio_setup(adapter))
360 goto failed;
361
362 if (zfcp_allocate_low_mem_buffers(adapter))
363 goto failed;
364
365 adapter->req_list = zfcp_reqlist_alloc();
366 if (!adapter->req_list)
367 goto failed;
368
369 if (zfcp_dbf_adapter_register(adapter))
370 goto failed;
371
372 if (zfcp_setup_adapter_work_queue(adapter))
373 goto failed;
374
375 if (zfcp_fc_gs_setup(adapter))
376 goto failed;
377
378 rwlock_init(&adapter->port_list_lock);
379 INIT_LIST_HEAD(&adapter->port_list);
380
381 INIT_LIST_HEAD(&adapter->events.list);
382 INIT_WORK(&adapter->events.work, zfcp_fc_post_event);
383 spin_lock_init(&adapter->events.list_lock);
384
385 init_waitqueue_head(&adapter->erp_ready_wq);
386 init_waitqueue_head(&adapter->erp_done_wqh);
387
388 INIT_LIST_HEAD(&adapter->erp_ready_head);
389 INIT_LIST_HEAD(&adapter->erp_running_head);
390
391 rwlock_init(&adapter->erp_lock);
392 rwlock_init(&adapter->abort_lock);
393
394 if (zfcp_erp_thread_setup(adapter))
395 goto failed;
396
397 adapter->service_level.seq_print = zfcp_print_sl;
398
399 dev_set_drvdata(&ccw_device->dev, adapter);
400
401 if (sysfs_create_group(&ccw_device->dev.kobj,
402 &zfcp_sysfs_adapter_attrs))
403 goto failed;
404
405
406 adapter->ccw_device->dev.dma_parms = &adapter->dma_parms;
407
408 adapter->stat_read_buf_num = FSF_STATUS_READS_RECOM;
409
410 if (!zfcp_scsi_adapter_register(adapter))
411 return adapter;
412
413 failed:
414 zfcp_adapter_unregister(adapter);
415 return ERR_PTR(-ENOMEM);
416 }
417
418 void zfcp_adapter_unregister(struct zfcp_adapter *adapter)
419 {
420 struct ccw_device *cdev = adapter->ccw_device;
421
422 cancel_delayed_work_sync(&adapter->scan_work);
423 cancel_work_sync(&adapter->stat_work);
424 cancel_work_sync(&adapter->ns_up_work);
425 zfcp_destroy_adapter_work_queue(adapter);
426
427 zfcp_fc_wka_ports_force_offline(adapter->gs);
428 zfcp_scsi_adapter_unregister(adapter);
429 sysfs_remove_group(&cdev->dev.kobj, &zfcp_sysfs_adapter_attrs);
430
431 zfcp_erp_thread_kill(adapter);
432 zfcp_dbf_adapter_unregister(adapter);
433 zfcp_qdio_destroy(adapter->qdio);
434
435 zfcp_ccw_adapter_put(adapter);
436 }
437
438
439
440
441
442
443 void zfcp_adapter_release(struct kref *ref)
444 {
445 struct zfcp_adapter *adapter = container_of(ref, struct zfcp_adapter,
446 ref);
447 struct ccw_device *cdev = adapter->ccw_device;
448
449 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
450 zfcp_fc_gs_destroy(adapter);
451 zfcp_free_low_mem_buffers(adapter);
452 kfree(adapter->req_list);
453 kfree(adapter->fc_stats);
454 kfree(adapter->stats_reset_data);
455 kfree(adapter);
456 put_device(&cdev->dev);
457 }
458
459 static void zfcp_port_release(struct device *dev)
460 {
461 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
462
463 zfcp_ccw_adapter_put(port->adapter);
464 kfree(port);
465 }
466
467
468
469
470
471
472
473
474
475
476
477
478
479 struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
480 u32 status, u32 d_id)
481 {
482 struct zfcp_port *port;
483 int retval = -ENOMEM;
484
485 kref_get(&adapter->ref);
486
487 port = zfcp_get_port_by_wwpn(adapter, wwpn);
488 if (port) {
489 put_device(&port->dev);
490 retval = -EEXIST;
491 goto err_out;
492 }
493
494 port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL);
495 if (!port)
496 goto err_out;
497
498 rwlock_init(&port->unit_list_lock);
499 INIT_LIST_HEAD(&port->unit_list);
500 atomic_set(&port->units, 0);
501
502 INIT_WORK(&port->gid_pn_work, zfcp_fc_port_did_lookup);
503 INIT_WORK(&port->test_link_work, zfcp_fc_link_test_work);
504 INIT_WORK(&port->rport_work, zfcp_scsi_rport_work);
505
506 port->adapter = adapter;
507 port->d_id = d_id;
508 port->wwpn = wwpn;
509 port->rport_task = RPORT_NONE;
510 port->dev.parent = &adapter->ccw_device->dev;
511 port->dev.groups = zfcp_port_attr_groups;
512 port->dev.release = zfcp_port_release;
513
514 port->erp_action.adapter = adapter;
515 port->erp_action.port = port;
516
517 if (dev_set_name(&port->dev, "0x%016llx", (unsigned long long)wwpn)) {
518 kfree(port);
519 goto err_out;
520 }
521 retval = -EINVAL;
522
523 if (device_register(&port->dev)) {
524 put_device(&port->dev);
525 goto err_out;
526 }
527
528 write_lock_irq(&adapter->port_list_lock);
529 list_add_tail(&port->list, &adapter->port_list);
530 write_unlock_irq(&adapter->port_list_lock);
531
532 atomic_or(status | ZFCP_STATUS_COMMON_RUNNING, &port->status);
533
534 return port;
535
536 err_out:
537 zfcp_ccw_adapter_put(adapter);
538 return ERR_PTR(retval);
539 }