2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Martin Peschke (originator of the driver)
29 * Heiko Carstens (kernel 2.6 port of the driver)
36 #include <linux/miscdevice.h>
39 /* accumulated log level (module parameter) */
40 static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS;
42 /*********************** FUNCTION PROTOTYPES *********************************/
44 /* written against the module interface */
45 static int __init zfcp_module_init(void);
47 /*********************** KERNEL/MODULE PARAMETERS ***************************/
49 /* declare driver module init/cleanup functions */
50 module_init(zfcp_module_init);
52 MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
54 ("FCP (SCSI over Fibre Channel) HBA driver for IBM System z9 and zSeries");
55 MODULE_LICENSE("GPL");
57 module_param(device, charp, 0400);
58 MODULE_PARM_DESC(device, "specify initial device");
60 module_param(loglevel, uint, 0400);
61 MODULE_PARM_DESC(loglevel,
62 "log levels, 8 nibbles: "
63 "FC ERP QDIO CIO Config FSF SCSI Other, "
64 "levels: 0=none 1=normal 2=devel 3=trace");
66 /****************************************************************/
67 /************** Functions without logging ***********************/
68 /****************************************************************/
71 _zfcp_hex_dump(char *addr, int count)
74 for (i = 0; i < count; i++) {
75 printk("%02x", addr[i]);
81 if (((i-1) % 32) != 31)
86 /****************************************************************/
87 /****** Functions to handle the request ID hash table ********/
88 /****************************************************************/
90 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
92 static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter)
96 adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head),
98 if (!adapter->req_list)
101 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
102 INIT_LIST_HEAD(&adapter->req_list[idx]);
106 static void zfcp_reqlist_free(struct zfcp_adapter *adapter)
108 kfree(adapter->req_list);
111 int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
115 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
116 if (!list_empty(&adapter->req_list[idx]))
123 /****************************************************************/
124 /************** Uncategorised Functions *************************/
125 /****************************************************************/
127 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
130 * zfcp_device_setup - setup function
131 * @str: pointer to parameter string
133 * Parse "device=..." parameter string.
136 zfcp_device_setup(char *devstr)
144 len = strlen(devstr) + 1;
145 str = kmalloc(len, GFP_KERNEL);
148 memcpy(str, devstr, len);
150 tmp = strchr(str, ',');
154 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
155 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
157 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
163 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
170 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
176 zfcp_init_device_configure(void)
178 struct zfcp_adapter *adapter;
179 struct zfcp_port *port;
180 struct zfcp_unit *unit;
182 down(&zfcp_data.config_sema);
183 read_lock_irq(&zfcp_data.config_lock);
184 adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
186 zfcp_adapter_get(adapter);
187 read_unlock_irq(&zfcp_data.config_lock);
191 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
194 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
197 up(&zfcp_data.config_sema);
198 ccw_device_set_online(adapter->ccw_device);
199 zfcp_erp_wait(adapter);
200 down(&zfcp_data.config_sema);
205 zfcp_adapter_put(adapter);
207 up(&zfcp_data.config_sema);
211 static int calc_alignment(int size)
218 while ((size - align) > 0)
225 zfcp_module_init(void)
227 int retval = -ENOMEM;
230 size = sizeof(struct zfcp_fsf_req_qtcb);
231 align = calc_alignment(size);
232 zfcp_data.fsf_req_qtcb_cache =
233 kmem_cache_create("zfcp_fsf", size, align, 0, NULL);
234 if (!zfcp_data.fsf_req_qtcb_cache)
237 size = sizeof(struct fsf_status_read_buffer);
238 align = calc_alignment(size);
239 zfcp_data.sr_buffer_cache =
240 kmem_cache_create("zfcp_sr", size, align, 0, NULL);
241 if (!zfcp_data.sr_buffer_cache)
244 size = sizeof(struct zfcp_gid_pn_data);
245 align = calc_alignment(size);
246 zfcp_data.gid_pn_cache =
247 kmem_cache_create("zfcp_gid", size, align, 0, NULL);
248 if (!zfcp_data.gid_pn_cache)
251 atomic_set(&zfcp_data.loglevel, loglevel);
253 /* initialize adapter list */
254 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
256 /* initialize adapters to be removed list head */
257 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
259 zfcp_data.scsi_transport_template =
260 fc_attach_transport(&zfcp_transport_functions);
261 if (!zfcp_data.scsi_transport_template)
264 retval = misc_register(&zfcp_cfdc_misc);
266 ZFCP_LOG_INFO("registration of misc device "
267 "zfcp_cfdc failed\n");
271 /* Initialise proc semaphores */
272 sema_init(&zfcp_data.config_sema, 1);
274 /* initialise configuration rw lock */
275 rwlock_init(&zfcp_data.config_lock);
277 /* setup dynamic I/O */
278 retval = zfcp_ccw_register();
280 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
281 goto out_ccw_register;
284 if (zfcp_device_setup(device))
285 zfcp_init_device_configure();
290 misc_deregister(&zfcp_cfdc_misc);
292 fc_release_transport(zfcp_data.scsi_transport_template);
294 kmem_cache_destroy(zfcp_data.gid_pn_cache);
296 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
298 kmem_cache_destroy(zfcp_data.fsf_req_qtcb_cache);
305 /****************************************************************/
306 /****** Functions for configuration/set-up of structures ********/
307 /****************************************************************/
309 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
312 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
313 * @port: pointer to port to search for unit
314 * @fcp_lun: FCP LUN to search for
315 * Traverse list of all units of a port and return pointer to a unit
316 * with the given FCP LUN.
319 zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
321 struct zfcp_unit *unit;
324 list_for_each_entry(unit, &port->unit_list_head, list) {
325 if ((unit->fcp_lun == fcp_lun) &&
326 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
332 return found ? unit : NULL;
336 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
337 * @adapter: pointer to adapter to search for port
338 * @wwpn: wwpn to search for
339 * Traverse list of all ports of an adapter and return pointer to a port
340 * with the given wwpn.
343 zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
345 struct zfcp_port *port;
348 list_for_each_entry(port, &adapter->port_list_head, list) {
349 if ((port->wwpn == wwpn) &&
350 !(atomic_read(&port->status) &
351 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
356 return found ? port : NULL;
360 * zfcp_get_port_by_did - find port in port list of adapter by d_id
361 * @adapter: pointer to adapter to search for port
362 * @d_id: d_id to search for
363 * Traverse list of all ports of an adapter and return pointer to a port
364 * with the given d_id.
367 zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
369 struct zfcp_port *port;
372 list_for_each_entry(port, &adapter->port_list_head, list) {
373 if ((port->d_id == d_id) &&
374 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
380 return found ? port : NULL;
384 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
385 * @bus_id: bus_id to search for
386 * Traverse list of all adapters and return pointer to an adapter
387 * with the given bus_id.
389 struct zfcp_adapter *
390 zfcp_get_adapter_by_busid(char *bus_id)
392 struct zfcp_adapter *adapter;
395 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
396 if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
397 BUS_ID_SIZE) == 0) &&
398 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
404 return found ? adapter : NULL;
408 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
409 * @port: pointer to port where unit is added
410 * @fcp_lun: FCP LUN of unit to be enqueued
411 * Return: pointer to enqueued unit on success, NULL on error
412 * Locks: config_sema must be held to serialize changes to the unit list
414 * Sets up some unit internal structures and creates sysfs entry.
417 zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
419 struct zfcp_unit *unit;
422 * check that there is no unit with this FCP_LUN already in list
424 * Note: Unlike for the adapter and the port, this is an error
426 read_lock_irq(&zfcp_data.config_lock);
427 unit = zfcp_get_unit_by_lun(port, fcp_lun);
428 read_unlock_irq(&zfcp_data.config_lock);
432 unit = kzalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
436 /* initialise reference count stuff */
437 atomic_set(&unit->refcount, 0);
438 init_waitqueue_head(&unit->remove_wq);
441 unit->fcp_lun = fcp_lun;
443 /* setup for sysfs registration */
444 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
445 unit->sysfs_device.parent = &port->sysfs_device;
446 unit->sysfs_device.release = zfcp_sysfs_unit_release;
447 dev_set_drvdata(&unit->sysfs_device, unit);
449 /* mark unit unusable as long as sysfs registration is not complete */
450 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
452 spin_lock_init(&unit->latencies.lock);
453 unit->latencies.write.channel.min = 0xFFFFFFFF;
454 unit->latencies.write.fabric.min = 0xFFFFFFFF;
455 unit->latencies.read.channel.min = 0xFFFFFFFF;
456 unit->latencies.read.fabric.min = 0xFFFFFFFF;
457 unit->latencies.cmd.channel.min = 0xFFFFFFFF;
458 unit->latencies.cmd.fabric.min = 0xFFFFFFFF;
460 if (device_register(&unit->sysfs_device)) {
465 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
466 device_unregister(&unit->sysfs_device);
471 unit->scsi_lun = scsilun_to_int((struct scsi_lun *)&unit->fcp_lun);
473 write_lock_irq(&zfcp_data.config_lock);
474 list_add_tail(&unit->list, &port->unit_list_head);
475 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
476 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
477 write_unlock_irq(&zfcp_data.config_lock);
486 zfcp_unit_dequeue(struct zfcp_unit *unit)
488 zfcp_unit_wait(unit);
489 write_lock_irq(&zfcp_data.config_lock);
490 list_del(&unit->list);
491 write_unlock_irq(&zfcp_data.config_lock);
493 zfcp_port_put(unit->port);
494 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
495 device_unregister(&unit->sysfs_device);
499 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
501 * It also genrates fcp-nameserver request/response buffer and unsolicited
502 * status read fsf_req buffers.
504 * locks: must only be called with zfcp_data.config_sema taken
507 zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
509 adapter->pool.fsf_req_erp =
510 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ERP_NR,
511 zfcp_data.fsf_req_qtcb_cache);
512 if (!adapter->pool.fsf_req_erp)
515 adapter->pool.fsf_req_scsi =
516 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_SCSI_NR,
517 zfcp_data.fsf_req_qtcb_cache);
518 if (!adapter->pool.fsf_req_scsi)
521 adapter->pool.fsf_req_abort =
522 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ABORT_NR,
523 zfcp_data.fsf_req_qtcb_cache);
524 if (!adapter->pool.fsf_req_abort)
527 adapter->pool.fsf_req_status_read =
528 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
529 sizeof(struct zfcp_fsf_req));
530 if (!adapter->pool.fsf_req_status_read)
533 adapter->pool.data_status_read =
534 mempool_create_slab_pool(ZFCP_POOL_STATUS_READ_NR,
535 zfcp_data.sr_buffer_cache);
536 if (!adapter->pool.data_status_read)
539 adapter->pool.data_gid_pn =
540 mempool_create_slab_pool(ZFCP_POOL_DATA_GID_PN_NR,
541 zfcp_data.gid_pn_cache);
542 if (!adapter->pool.data_gid_pn)
549 * zfcp_free_low_mem_buffers - free memory pools of an adapter
550 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
551 * locking: zfcp_data.config_sema must be held
554 zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
556 if (adapter->pool.fsf_req_erp)
557 mempool_destroy(adapter->pool.fsf_req_erp);
558 if (adapter->pool.fsf_req_scsi)
559 mempool_destroy(adapter->pool.fsf_req_scsi);
560 if (adapter->pool.fsf_req_abort)
561 mempool_destroy(adapter->pool.fsf_req_abort);
562 if (adapter->pool.fsf_req_status_read)
563 mempool_destroy(adapter->pool.fsf_req_status_read);
564 if (adapter->pool.data_status_read)
565 mempool_destroy(adapter->pool.data_status_read);
566 if (adapter->pool.data_gid_pn)
567 mempool_destroy(adapter->pool.data_gid_pn);
570 static void zfcp_dummy_release(struct device *dev)
575 int zfcp_status_read_refill(struct zfcp_adapter *adapter)
577 while (atomic_read(&adapter->stat_miss) > 0)
578 if (zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL))
581 atomic_dec(&adapter->stat_miss);
583 if (ZFCP_STATUS_READS_RECOM <= atomic_read(&adapter->stat_miss)) {
584 zfcp_erp_adapter_reopen(adapter, 0, 103, NULL);
590 static void _zfcp_status_read_scheduler(struct work_struct *work)
592 zfcp_status_read_refill(container_of(work, struct zfcp_adapter,
597 * Enqueues an adapter at the end of the adapter list in the driver data.
598 * All adapter internal structures are set up.
599 * Proc-fs entries are also created.
601 * returns: 0 if a new adapter was successfully enqueued
602 * ZFCP_KNOWN if an adapter with this devno was already present
603 * -ENOMEM if alloc failed
604 * locks: config_sema must be held to serialise changes to the adapter list
606 struct zfcp_adapter *
607 zfcp_adapter_enqueue(struct ccw_device *ccw_device)
609 struct zfcp_adapter *adapter;
612 * Note: It is safe to release the list_lock, as any list changes
613 * are protected by the config_sema, which must be held to get here
616 /* try to allocate new adapter data structure (zeroed) */
617 adapter = kzalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
619 ZFCP_LOG_INFO("error: allocation of base adapter "
620 "structure failed\n");
624 ccw_device->handler = NULL;
626 /* save ccw_device pointer */
627 adapter->ccw_device = ccw_device;
629 if (zfcp_qdio_allocate(adapter))
630 goto qdio_allocate_failed;
632 if (zfcp_allocate_low_mem_buffers(adapter))
633 goto failed_low_mem_buffers;
635 /* initialise reference count stuff */
636 atomic_set(&adapter->refcount, 0);
637 init_waitqueue_head(&adapter->remove_wq);
639 /* initialise list of ports */
640 INIT_LIST_HEAD(&adapter->port_list_head);
642 /* initialise list of ports to be removed */
643 INIT_LIST_HEAD(&adapter->port_remove_lh);
645 /* initialize list of fsf requests */
646 spin_lock_init(&adapter->req_list_lock);
647 if (zfcp_reqlist_alloc(adapter))
648 goto failed_low_mem_buffers;
650 /* initialize debug locks */
652 spin_lock_init(&adapter->hba_dbf_lock);
653 spin_lock_init(&adapter->san_dbf_lock);
654 spin_lock_init(&adapter->scsi_dbf_lock);
655 spin_lock_init(&adapter->rec_dbf_lock);
657 if (zfcp_adapter_debug_register(adapter))
658 goto debug_register_failed;
660 /* initialize error recovery stuff */
662 rwlock_init(&adapter->erp_lock);
663 sema_init(&adapter->erp_ready_sem, 0);
664 INIT_LIST_HEAD(&adapter->erp_ready_head);
665 INIT_LIST_HEAD(&adapter->erp_running_head);
667 /* initialize abort lock */
668 rwlock_init(&adapter->abort_lock);
670 /* initialise some erp stuff */
671 init_waitqueue_head(&adapter->erp_thread_wqh);
672 init_waitqueue_head(&adapter->erp_done_wqh);
674 /* initialize lock of associated request queue */
675 rwlock_init(&adapter->req_q.lock);
676 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
678 /* mark adapter unusable as long as sysfs registration is not complete */
679 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
681 dev_set_drvdata(&ccw_device->dev, adapter);
683 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
686 adapter->generic_services.parent = &adapter->ccw_device->dev;
687 adapter->generic_services.release = zfcp_dummy_release;
688 snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
691 if (device_register(&adapter->generic_services))
692 goto generic_services_failed;
694 /* put allocated adapter at list tail */
695 write_lock_irq(&zfcp_data.config_lock);
696 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
697 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
698 write_unlock_irq(&zfcp_data.config_lock);
700 zfcp_data.adapters++;
704 generic_services_failed:
705 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
707 zfcp_adapter_debug_unregister(adapter);
708 debug_register_failed:
709 dev_set_drvdata(&ccw_device->dev, NULL);
710 zfcp_reqlist_free(adapter);
711 failed_low_mem_buffers:
712 zfcp_free_low_mem_buffers(adapter);
713 qdio_allocate_failed:
714 zfcp_qdio_free(adapter);
722 * returns: 0 - struct zfcp_adapter data structure successfully removed
723 * !0 - struct zfcp_adapter data structure could not be removed
725 * locks: adapter list write lock is assumed to be held by caller
728 zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
733 cancel_work_sync(&adapter->stat_work);
734 zfcp_adapter_scsi_unregister(adapter);
735 device_unregister(&adapter->generic_services);
736 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
737 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
738 /* sanity check: no pending FSF requests */
739 spin_lock_irqsave(&adapter->req_list_lock, flags);
740 retval = zfcp_reqlist_isempty(adapter);
741 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
747 zfcp_adapter_debug_unregister(adapter);
749 /* remove specified adapter data structure from list */
750 write_lock_irq(&zfcp_data.config_lock);
751 list_del(&adapter->list);
752 write_unlock_irq(&zfcp_data.config_lock);
754 /* decrease number of adapters in list */
755 zfcp_data.adapters--;
757 zfcp_qdio_free(adapter);
759 zfcp_free_low_mem_buffers(adapter);
760 zfcp_reqlist_free(adapter);
761 kfree(adapter->fc_stats);
762 kfree(adapter->stats_reset_data);
763 ZFCP_LOG_TRACE("freeing adapter structure\n");
770 * zfcp_port_enqueue - enqueue port to port list of adapter
771 * @adapter: adapter where remote port is added
772 * @wwpn: WWPN of the remote port to be enqueued
773 * @status: initial status for the port
774 * @d_id: destination id of the remote port to be enqueued
775 * Return: pointer to enqueued port on success, NULL on error
776 * Locks: config_sema must be held to serialize changes to the port list
778 * All port internal structures are set up and the sysfs entry is generated.
779 * d_id is used to enqueue ports with a well known address like the Directory
780 * Service for nameserver lookup.
783 zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
786 struct zfcp_port *port;
789 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
791 * check that there is no port with this WWPN already in list
794 read_lock_irq(&zfcp_data.config_lock);
795 port = zfcp_get_port_by_wwpn(adapter, wwpn);
796 read_unlock_irq(&zfcp_data.config_lock);
801 port = kzalloc(sizeof (struct zfcp_port), GFP_KERNEL);
805 /* initialise reference count stuff */
806 atomic_set(&port->refcount, 0);
807 init_waitqueue_head(&port->remove_wq);
809 INIT_LIST_HEAD(&port->unit_list_head);
810 INIT_LIST_HEAD(&port->unit_remove_lh);
812 port->adapter = adapter;
817 atomic_set_mask(status, &port->status);
819 /* setup for sysfs registration */
820 if (status & ZFCP_STATUS_PORT_WKA) {
822 case ZFCP_DID_DIRECTORY_SERVICE:
823 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
826 case ZFCP_DID_MANAGEMENT_SERVICE:
827 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
830 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
831 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
834 case ZFCP_DID_ALIAS_SERVICE:
835 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
838 case ZFCP_DID_TIME_SERVICE:
839 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
847 port->sysfs_device.parent = &adapter->generic_services;
849 snprintf(port->sysfs_device.bus_id,
850 BUS_ID_SIZE, "0x%016llx", wwpn);
851 port->sysfs_device.parent = &adapter->ccw_device->dev;
853 port->sysfs_device.release = zfcp_sysfs_port_release;
854 dev_set_drvdata(&port->sysfs_device, port);
856 /* mark port unusable as long as sysfs registration is not complete */
857 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
859 if (device_register(&port->sysfs_device)) {
864 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
865 device_unregister(&port->sysfs_device);
871 write_lock_irq(&zfcp_data.config_lock);
872 list_add_tail(&port->list, &adapter->port_list_head);
873 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
874 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
875 if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
876 if (!adapter->nameserver_port)
877 adapter->nameserver_port = port;
879 write_unlock_irq(&zfcp_data.config_lock);
881 zfcp_adapter_get(adapter);
887 zfcp_port_dequeue(struct zfcp_port *port)
889 zfcp_port_wait(port);
890 write_lock_irq(&zfcp_data.config_lock);
891 list_del(&port->list);
892 port->adapter->ports--;
893 write_unlock_irq(&zfcp_data.config_lock);
895 fc_remote_port_delete(port->rport);
897 zfcp_adapter_put(port->adapter);
898 zfcp_sysfs_port_remove_files(&port->sysfs_device,
899 atomic_read(&port->status));
900 device_unregister(&port->sysfs_device);
903 /* Enqueues a nameserver port */
905 zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
907 struct zfcp_port *port;
909 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
910 ZFCP_DID_DIRECTORY_SERVICE);
912 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
913 "adapter %s failed\n",
914 zfcp_get_busid_by_adapter(adapter));
922 void zfcp_sg_free_table(struct scatterlist *sg, int count)
926 for (i = 0; i < count; i++, sg++)
928 free_page((unsigned long) sg_virt(sg));
933 int zfcp_sg_setup_table(struct scatterlist *sg, int count)
938 sg_init_table(sg, count);
939 for (i = 0; i < count; i++, sg++) {
940 addr = (void *) get_zeroed_page(GFP_KERNEL);
942 zfcp_sg_free_table(sg, i);
945 sg_set_buf(sg, addr, PAGE_SIZE);