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)
38 /* accumulated log level (module parameter) */
39 static u32 loglevel
= ZFCP_LOG_LEVEL_DEFAULTS
;
41 /*********************** FUNCTION PROTOTYPES *********************************/
43 /* written against the module interface */
44 static int __init
zfcp_module_init(void);
47 static void zfcp_ns_gid_pn_handler(unsigned long);
50 static int zfcp_sg_list_alloc(struct zfcp_sg_list
*, size_t);
51 static void zfcp_sg_list_free(struct zfcp_sg_list
*);
52 static int zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*,
53 void __user
*, size_t);
54 static int zfcp_sg_list_copy_to_user(void __user
*,
55 struct zfcp_sg_list
*, size_t);
56 static long zfcp_cfdc_dev_ioctl(struct file
*, unsigned int, unsigned long);
58 #define ZFCP_CFDC_IOC_MAGIC 0xDD
59 #define ZFCP_CFDC_IOC \
60 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
63 static const struct file_operations zfcp_cfdc_fops
= {
64 .unlocked_ioctl
= zfcp_cfdc_dev_ioctl
,
66 .compat_ioctl
= zfcp_cfdc_dev_ioctl
70 static struct miscdevice zfcp_cfdc_misc
= {
71 .minor
= ZFCP_CFDC_DEV_MINOR
,
72 .name
= ZFCP_CFDC_DEV_NAME
,
73 .fops
= &zfcp_cfdc_fops
76 /*********************** KERNEL/MODULE PARAMETERS ***************************/
78 /* declare driver module init/cleanup functions */
79 module_init(zfcp_module_init
);
81 MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
83 ("FCP (SCSI over Fibre Channel) HBA driver for IBM System z9 and zSeries");
84 MODULE_LICENSE("GPL");
86 module_param(device
, charp
, 0400);
87 MODULE_PARM_DESC(device
, "specify initial device");
89 module_param(loglevel
, uint
, 0400);
90 MODULE_PARM_DESC(loglevel
,
91 "log levels, 8 nibbles: "
92 "FC ERP QDIO CIO Config FSF SCSI Other, "
93 "levels: 0=none 1=normal 2=devel 3=trace");
95 /****************************************************************/
96 /************** Functions without logging ***********************/
97 /****************************************************************/
100 _zfcp_hex_dump(char *addr
, int count
)
103 for (i
= 0; i
< count
; i
++) {
104 printk("%02x", addr
[i
]);
110 if (((i
-1) % 32) != 31)
115 /****************************************************************/
116 /****** Functions to handle the request ID hash table ********/
117 /****************************************************************/
119 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
121 static int zfcp_reqlist_alloc(struct zfcp_adapter
*adapter
)
125 adapter
->req_list
= kcalloc(REQUEST_LIST_SIZE
, sizeof(struct list_head
),
127 if (!adapter
->req_list
)
130 for (idx
= 0; idx
< REQUEST_LIST_SIZE
; idx
++)
131 INIT_LIST_HEAD(&adapter
->req_list
[idx
]);
135 static void zfcp_reqlist_free(struct zfcp_adapter
*adapter
)
137 kfree(adapter
->req_list
);
140 int zfcp_reqlist_isempty(struct zfcp_adapter
*adapter
)
144 for (idx
= 0; idx
< REQUEST_LIST_SIZE
; idx
++)
145 if (!list_empty(&adapter
->req_list
[idx
]))
152 /****************************************************************/
153 /************** Uncategorised Functions *************************/
154 /****************************************************************/
156 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
159 * zfcp_device_setup - setup function
160 * @str: pointer to parameter string
162 * Parse "device=..." parameter string.
165 zfcp_device_setup(char *devstr
)
173 len
= strlen(devstr
) + 1;
174 str
= kmalloc(len
, GFP_KERNEL
);
177 memcpy(str
, devstr
, len
);
179 tmp
= strchr(str
, ',');
183 strncpy(zfcp_data
.init_busid
, str
, BUS_ID_SIZE
);
184 zfcp_data
.init_busid
[BUS_ID_SIZE
-1] = '\0';
186 zfcp_data
.init_wwpn
= simple_strtoull(tmp
, &tmp
, 0);
192 zfcp_data
.init_fcp_lun
= simple_strtoull(tmp
, &tmp
, 0);
199 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str
);
205 zfcp_init_device_configure(void)
207 struct zfcp_adapter
*adapter
;
208 struct zfcp_port
*port
;
209 struct zfcp_unit
*unit
;
211 down(&zfcp_data
.config_sema
);
212 read_lock_irq(&zfcp_data
.config_lock
);
213 adapter
= zfcp_get_adapter_by_busid(zfcp_data
.init_busid
);
215 zfcp_adapter_get(adapter
);
216 read_unlock_irq(&zfcp_data
.config_lock
);
220 port
= zfcp_port_enqueue(adapter
, zfcp_data
.init_wwpn
, 0, 0);
223 unit
= zfcp_unit_enqueue(port
, zfcp_data
.init_fcp_lun
);
226 up(&zfcp_data
.config_sema
);
227 ccw_device_set_online(adapter
->ccw_device
);
228 zfcp_erp_wait(adapter
);
229 down(&zfcp_data
.config_sema
);
234 zfcp_adapter_put(adapter
);
236 up(&zfcp_data
.config_sema
);
240 static int calc_alignment(int size
)
247 while ((size
- align
) > 0)
254 zfcp_module_init(void)
256 int retval
= -ENOMEM
;
259 size
= sizeof(struct zfcp_fsf_req_qtcb
);
260 align
= calc_alignment(size
);
261 zfcp_data
.fsf_req_qtcb_cache
=
262 kmem_cache_create("zfcp_fsf", size
, align
, 0, NULL
);
263 if (!zfcp_data
.fsf_req_qtcb_cache
)
266 size
= sizeof(struct fsf_status_read_buffer
);
267 align
= calc_alignment(size
);
268 zfcp_data
.sr_buffer_cache
=
269 kmem_cache_create("zfcp_sr", size
, align
, 0, NULL
);
270 if (!zfcp_data
.sr_buffer_cache
)
273 size
= sizeof(struct zfcp_gid_pn_data
);
274 align
= calc_alignment(size
);
275 zfcp_data
.gid_pn_cache
=
276 kmem_cache_create("zfcp_gid", size
, align
, 0, NULL
);
277 if (!zfcp_data
.gid_pn_cache
)
280 atomic_set(&zfcp_data
.loglevel
, loglevel
);
282 /* initialize adapter list */
283 INIT_LIST_HEAD(&zfcp_data
.adapter_list_head
);
285 /* initialize adapters to be removed list head */
286 INIT_LIST_HEAD(&zfcp_data
.adapter_remove_lh
);
288 zfcp_data
.scsi_transport_template
=
289 fc_attach_transport(&zfcp_transport_functions
);
290 if (!zfcp_data
.scsi_transport_template
)
293 retval
= misc_register(&zfcp_cfdc_misc
);
295 ZFCP_LOG_INFO("registration of misc device "
296 "zfcp_cfdc failed\n");
300 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
301 ZFCP_CFDC_DEV_MAJOR
, zfcp_cfdc_misc
.minor
);
303 /* Initialise proc semaphores */
304 sema_init(&zfcp_data
.config_sema
, 1);
306 /* initialise configuration rw lock */
307 rwlock_init(&zfcp_data
.config_lock
);
309 /* setup dynamic I/O */
310 retval
= zfcp_ccw_register();
312 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
313 goto out_ccw_register
;
316 if (zfcp_device_setup(device
))
317 zfcp_init_device_configure();
322 misc_deregister(&zfcp_cfdc_misc
);
324 fc_release_transport(zfcp_data
.scsi_transport_template
);
326 kmem_cache_destroy(zfcp_data
.gid_pn_cache
);
328 kmem_cache_destroy(zfcp_data
.sr_buffer_cache
);
330 kmem_cache_destroy(zfcp_data
.fsf_req_qtcb_cache
);
336 * function: zfcp_cfdc_dev_ioctl
338 * purpose: Handle control file upload/download transaction via IOCTL
341 * returns: 0 - Operation completed successfuly
342 * -ENOTTY - Unknown IOCTL command
343 * -EINVAL - Invalid sense data record
344 * -ENXIO - The FCP adapter is not available
345 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
346 * -ENOMEM - Insufficient memory
347 * -EFAULT - User space memory I/O operation fault
348 * -EPERM - Cannot create or queue FSF request or create SBALs
349 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
352 zfcp_cfdc_dev_ioctl(struct file
*file
, unsigned int command
,
353 unsigned long buffer
)
355 struct zfcp_cfdc_sense_data
*sense_data
, __user
*sense_data_user
;
356 struct zfcp_adapter
*adapter
= NULL
;
357 struct zfcp_fsf_req
*fsf_req
= NULL
;
358 struct zfcp_sg_list
*sg_list
= NULL
;
359 u32 fsf_command
, option
;
363 sense_data
= kmalloc(sizeof(struct zfcp_cfdc_sense_data
), GFP_KERNEL
);
364 if (sense_data
== NULL
) {
369 sg_list
= kzalloc(sizeof(struct zfcp_sg_list
), GFP_KERNEL
);
370 if (sg_list
== NULL
) {
375 if (command
!= ZFCP_CFDC_IOC
) {
376 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command
);
381 if ((sense_data_user
= (void __user
*) buffer
) == NULL
) {
382 ZFCP_LOG_INFO("sense data record is required\n");
387 retval
= copy_from_user(sense_data
, sense_data_user
,
388 sizeof(struct zfcp_cfdc_sense_data
));
394 if (sense_data
->signature
!= ZFCP_CFDC_SIGNATURE
) {
395 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
396 ZFCP_CFDC_SIGNATURE
);
401 switch (sense_data
->command
) {
403 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL
:
404 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
405 option
= FSF_CFDC_OPTION_NORMAL_MODE
;
408 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE
:
409 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
410 option
= FSF_CFDC_OPTION_FORCE
;
413 case ZFCP_CFDC_CMND_FULL_ACCESS
:
414 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
415 option
= FSF_CFDC_OPTION_FULL_ACCESS
;
418 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS
:
419 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
420 option
= FSF_CFDC_OPTION_RESTRICTED_ACCESS
;
423 case ZFCP_CFDC_CMND_UPLOAD
:
424 fsf_command
= FSF_QTCB_UPLOAD_CONTROL_FILE
;
429 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
430 sense_data
->command
);
435 bus_id
= kmalloc(BUS_ID_SIZE
, GFP_KERNEL
);
436 if (bus_id
== NULL
) {
440 snprintf(bus_id
, BUS_ID_SIZE
, "%d.%d.%04x",
441 (sense_data
->devno
>> 24),
442 (sense_data
->devno
>> 16) & 0xFF,
443 (sense_data
->devno
& 0xFFFF));
445 read_lock_irq(&zfcp_data
.config_lock
);
446 adapter
= zfcp_get_adapter_by_busid(bus_id
);
448 zfcp_adapter_get(adapter
);
449 read_unlock_irq(&zfcp_data
.config_lock
);
453 if (adapter
== NULL
) {
454 ZFCP_LOG_INFO("invalid adapter\n");
459 if (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
) {
460 retval
= zfcp_sg_list_alloc(sg_list
,
461 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
468 if ((sense_data
->command
& ZFCP_CFDC_DOWNLOAD
) &&
469 (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
)) {
470 retval
= zfcp_sg_list_copy_from_user(
471 sg_list
, &sense_data_user
->control_file
,
472 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
479 retval
= zfcp_fsf_control_file(adapter
, &fsf_req
, fsf_command
,
484 if ((fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_GOOD
) &&
485 (fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_FSF_STATUS_PRESENTED
)) {
490 sense_data
->fsf_status
= fsf_req
->qtcb
->header
.fsf_status
;
491 memcpy(&sense_data
->fsf_status_qual
,
492 &fsf_req
->qtcb
->header
.fsf_status_qual
,
493 sizeof(union fsf_status_qual
));
494 memcpy(&sense_data
->payloads
, &fsf_req
->qtcb
->bottom
.support
.els
, 256);
496 retval
= copy_to_user(sense_data_user
, sense_data
,
497 sizeof(struct zfcp_cfdc_sense_data
));
503 if (sense_data
->command
& ZFCP_CFDC_UPLOAD
) {
504 retval
= zfcp_sg_list_copy_to_user(
505 &sense_data_user
->control_file
, sg_list
,
506 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
515 zfcp_fsf_req_free(fsf_req
);
517 if ((adapter
!= NULL
) && (retval
!= -ENXIO
))
518 zfcp_adapter_put(adapter
);
520 if (sg_list
!= NULL
) {
521 zfcp_sg_list_free(sg_list
);
532 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
533 * @sg_list: structure describing a scatter gather list
534 * @size: size of scatter-gather list
535 * Return: 0 on success, else -ENOMEM
537 * In sg_list->sg a pointer to the created scatter-gather list is returned,
538 * or NULL if we run out of memory. sg_list->count specifies the number of
539 * elements of the scatter-gather list. The maximum size of a single element
540 * in the scatter-gather list is PAGE_SIZE.
543 zfcp_sg_list_alloc(struct zfcp_sg_list
*sg_list
, size_t size
)
545 struct scatterlist
*sg
;
550 BUG_ON(sg_list
== NULL
);
552 sg_list
->count
= size
>> PAGE_SHIFT
;
553 if (size
& ~PAGE_MASK
)
555 sg_list
->sg
= kcalloc(sg_list
->count
, sizeof(struct scatterlist
),
557 if (sg_list
->sg
== NULL
) {
562 sg_init_table(sg_list
->sg
, sg_list
->count
);
564 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++) {
565 sg
->length
= min(size
, PAGE_SIZE
);
567 address
= (void *) get_zeroed_page(GFP_KERNEL
);
568 if (address
== NULL
) {
570 zfcp_sg_list_free(sg_list
);
574 zfcp_address_to_sg(address
, sg
);
584 * zfcp_sg_list_free - free memory of a scatter-gather list
585 * @sg_list: structure describing a scatter-gather list
587 * Memory for each element in the scatter-gather list is freed.
588 * Finally sg_list->sg is freed itself and sg_list->count is reset.
591 zfcp_sg_list_free(struct zfcp_sg_list
*sg_list
)
593 struct scatterlist
*sg
;
596 BUG_ON(sg_list
== NULL
);
598 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++)
599 free_page((unsigned long) zfcp_sg_to_address(sg
));
606 * zfcp_sg_size - determine size of a scatter-gather list
607 * @sg: array of (struct scatterlist)
608 * @sg_count: elements in array
609 * Return: size of entire scatter-gather list
611 static size_t zfcp_sg_size(struct scatterlist
*sg
, unsigned int sg_count
)
614 struct scatterlist
*p
;
618 for (i
= 0, p
= sg
; i
< sg_count
; i
++, p
++) {
628 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
629 * @sg_list: structure describing a scatter-gather list
630 * @user_buffer: pointer to buffer in user space
631 * @size: number of bytes to be copied
632 * Return: 0 on success, -EFAULT if copy_from_user fails.
635 zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*sg_list
,
636 void __user
*user_buffer
,
639 struct scatterlist
*sg
;
644 BUG_ON(sg_list
== NULL
);
646 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
649 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
650 length
= min((unsigned int)size
, sg
->length
);
651 zfcp_buffer
= zfcp_sg_to_address(sg
);
652 if (copy_from_user(zfcp_buffer
, user_buffer
, length
)) {
656 user_buffer
+= length
;
666 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
667 * @user_buffer: pointer to buffer in user space
668 * @sg_list: structure describing a scatter-gather list
669 * @size: number of bytes to be copied
670 * Return: 0 on success, -EFAULT if copy_to_user fails
673 zfcp_sg_list_copy_to_user(void __user
*user_buffer
,
674 struct zfcp_sg_list
*sg_list
,
677 struct scatterlist
*sg
;
682 BUG_ON(sg_list
== NULL
);
684 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
687 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
688 length
= min((unsigned int) size
, sg
->length
);
689 zfcp_buffer
= zfcp_sg_to_address(sg
);
690 if (copy_to_user(user_buffer
, zfcp_buffer
, length
)) {
694 user_buffer
+= length
;
705 /****************************************************************/
706 /****** Functions for configuration/set-up of structures ********/
707 /****************************************************************/
709 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
712 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
713 * @port: pointer to port to search for unit
714 * @fcp_lun: FCP LUN to search for
715 * Traverse list of all units of a port and return pointer to a unit
716 * with the given FCP LUN.
719 zfcp_get_unit_by_lun(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
721 struct zfcp_unit
*unit
;
724 list_for_each_entry(unit
, &port
->unit_list_head
, list
) {
725 if ((unit
->fcp_lun
== fcp_lun
) &&
726 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
))
732 return found
? unit
: NULL
;
736 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
737 * @adapter: pointer to adapter to search for port
738 * @wwpn: wwpn to search for
739 * Traverse list of all ports of an adapter and return pointer to a port
740 * with the given wwpn.
743 zfcp_get_port_by_wwpn(struct zfcp_adapter
*adapter
, wwn_t wwpn
)
745 struct zfcp_port
*port
;
748 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
749 if ((port
->wwpn
== wwpn
) &&
750 !(atomic_read(&port
->status
) &
751 (ZFCP_STATUS_PORT_NO_WWPN
| ZFCP_STATUS_COMMON_REMOVE
))) {
756 return found
? port
: NULL
;
760 * zfcp_get_port_by_did - find port in port list of adapter by d_id
761 * @adapter: pointer to adapter to search for port
762 * @d_id: d_id to search for
763 * Traverse list of all ports of an adapter and return pointer to a port
764 * with the given d_id.
767 zfcp_get_port_by_did(struct zfcp_adapter
*adapter
, u32 d_id
)
769 struct zfcp_port
*port
;
772 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
773 if ((port
->d_id
== d_id
) &&
774 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
))
780 return found
? port
: NULL
;
784 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
785 * @bus_id: bus_id to search for
786 * Traverse list of all adapters and return pointer to an adapter
787 * with the given bus_id.
789 struct zfcp_adapter
*
790 zfcp_get_adapter_by_busid(char *bus_id
)
792 struct zfcp_adapter
*adapter
;
795 list_for_each_entry(adapter
, &zfcp_data
.adapter_list_head
, list
) {
796 if ((strncmp(bus_id
, zfcp_get_busid_by_adapter(adapter
),
797 BUS_ID_SIZE
) == 0) &&
798 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
,
804 return found
? adapter
: NULL
;
808 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
809 * @port: pointer to port where unit is added
810 * @fcp_lun: FCP LUN of unit to be enqueued
811 * Return: pointer to enqueued unit on success, NULL on error
812 * Locks: config_sema must be held to serialize changes to the unit list
814 * Sets up some unit internal structures and creates sysfs entry.
817 zfcp_unit_enqueue(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
819 struct zfcp_unit
*unit
;
822 * check that there is no unit with this FCP_LUN already in list
824 * Note: Unlike for the adapter and the port, this is an error
826 read_lock_irq(&zfcp_data
.config_lock
);
827 unit
= zfcp_get_unit_by_lun(port
, fcp_lun
);
828 read_unlock_irq(&zfcp_data
.config_lock
);
832 unit
= kzalloc(sizeof (struct zfcp_unit
), GFP_KERNEL
);
836 /* initialise reference count stuff */
837 atomic_set(&unit
->refcount
, 0);
838 init_waitqueue_head(&unit
->remove_wq
);
841 unit
->fcp_lun
= fcp_lun
;
843 /* setup for sysfs registration */
844 snprintf(unit
->sysfs_device
.bus_id
, BUS_ID_SIZE
, "0x%016llx", fcp_lun
);
845 unit
->sysfs_device
.parent
= &port
->sysfs_device
;
846 unit
->sysfs_device
.release
= zfcp_sysfs_unit_release
;
847 dev_set_drvdata(&unit
->sysfs_device
, unit
);
849 init_waitqueue_head(&unit
->scsi_scan_wq
);
851 /* mark unit unusable as long as sysfs registration is not complete */
852 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
854 if (device_register(&unit
->sysfs_device
)) {
859 if (zfcp_sysfs_unit_create_files(&unit
->sysfs_device
)) {
860 device_unregister(&unit
->sysfs_device
);
865 unit
->scsi_lun
= scsilun_to_int((struct scsi_lun
*)&unit
->fcp_lun
);
867 write_lock_irq(&zfcp_data
.config_lock
);
868 list_add_tail(&unit
->list
, &port
->unit_list_head
);
869 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
870 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &unit
->status
);
871 write_unlock_irq(&zfcp_data
.config_lock
);
880 zfcp_unit_dequeue(struct zfcp_unit
*unit
)
882 zfcp_unit_wait(unit
);
883 write_lock_irq(&zfcp_data
.config_lock
);
884 list_del(&unit
->list
);
885 write_unlock_irq(&zfcp_data
.config_lock
);
887 zfcp_port_put(unit
->port
);
888 zfcp_sysfs_unit_remove_files(&unit
->sysfs_device
);
889 device_unregister(&unit
->sysfs_device
);
893 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
895 * It also genrates fcp-nameserver request/response buffer and unsolicited
896 * status read fsf_req buffers.
898 * locks: must only be called with zfcp_data.config_sema taken
901 zfcp_allocate_low_mem_buffers(struct zfcp_adapter
*adapter
)
903 adapter
->pool
.fsf_req_erp
=
904 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ERP_NR
,
905 zfcp_data
.fsf_req_qtcb_cache
);
906 if (!adapter
->pool
.fsf_req_erp
)
909 adapter
->pool
.fsf_req_scsi
=
910 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_SCSI_NR
,
911 zfcp_data
.fsf_req_qtcb_cache
);
912 if (!adapter
->pool
.fsf_req_scsi
)
915 adapter
->pool
.fsf_req_abort
=
916 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ABORT_NR
,
917 zfcp_data
.fsf_req_qtcb_cache
);
918 if (!adapter
->pool
.fsf_req_abort
)
921 adapter
->pool
.fsf_req_status_read
=
922 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR
,
923 sizeof(struct zfcp_fsf_req
));
924 if (!adapter
->pool
.fsf_req_status_read
)
927 adapter
->pool
.data_status_read
=
928 mempool_create_slab_pool(ZFCP_POOL_STATUS_READ_NR
,
929 zfcp_data
.sr_buffer_cache
);
930 if (!adapter
->pool
.data_status_read
)
933 adapter
->pool
.data_gid_pn
=
934 mempool_create_slab_pool(ZFCP_POOL_DATA_GID_PN_NR
,
935 zfcp_data
.gid_pn_cache
);
936 if (!adapter
->pool
.data_gid_pn
)
943 * zfcp_free_low_mem_buffers - free memory pools of an adapter
944 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
945 * locking: zfcp_data.config_sema must be held
948 zfcp_free_low_mem_buffers(struct zfcp_adapter
*adapter
)
950 if (adapter
->pool
.fsf_req_erp
)
951 mempool_destroy(adapter
->pool
.fsf_req_erp
);
952 if (adapter
->pool
.fsf_req_scsi
)
953 mempool_destroy(adapter
->pool
.fsf_req_scsi
);
954 if (adapter
->pool
.fsf_req_abort
)
955 mempool_destroy(adapter
->pool
.fsf_req_abort
);
956 if (adapter
->pool
.fsf_req_status_read
)
957 mempool_destroy(adapter
->pool
.fsf_req_status_read
);
958 if (adapter
->pool
.data_status_read
)
959 mempool_destroy(adapter
->pool
.data_status_read
);
960 if (adapter
->pool
.data_gid_pn
)
961 mempool_destroy(adapter
->pool
.data_gid_pn
);
964 static void zfcp_dummy_release(struct device
*dev
)
970 * Enqueues an adapter at the end of the adapter list in the driver data.
971 * All adapter internal structures are set up.
972 * Proc-fs entries are also created.
974 * returns: 0 if a new adapter was successfully enqueued
975 * ZFCP_KNOWN if an adapter with this devno was already present
976 * -ENOMEM if alloc failed
977 * locks: config_sema must be held to serialise changes to the adapter list
979 struct zfcp_adapter
*
980 zfcp_adapter_enqueue(struct ccw_device
*ccw_device
)
983 struct zfcp_adapter
*adapter
;
986 * Note: It is safe to release the list_lock, as any list changes
987 * are protected by the config_sema, which must be held to get here
990 /* try to allocate new adapter data structure (zeroed) */
991 adapter
= kzalloc(sizeof (struct zfcp_adapter
), GFP_KERNEL
);
993 ZFCP_LOG_INFO("error: allocation of base adapter "
994 "structure failed\n");
998 ccw_device
->handler
= NULL
;
1000 /* save ccw_device pointer */
1001 adapter
->ccw_device
= ccw_device
;
1003 retval
= zfcp_qdio_allocate_queues(adapter
);
1005 goto queues_alloc_failed
;
1007 retval
= zfcp_qdio_allocate(adapter
);
1009 goto qdio_allocate_failed
;
1011 retval
= zfcp_allocate_low_mem_buffers(adapter
);
1013 ZFCP_LOG_INFO("error: pool allocation failed\n");
1014 goto failed_low_mem_buffers
;
1017 /* initialise reference count stuff */
1018 atomic_set(&adapter
->refcount
, 0);
1019 init_waitqueue_head(&adapter
->remove_wq
);
1021 /* initialise list of ports */
1022 INIT_LIST_HEAD(&adapter
->port_list_head
);
1024 /* initialise list of ports to be removed */
1025 INIT_LIST_HEAD(&adapter
->port_remove_lh
);
1027 /* initialize list of fsf requests */
1028 spin_lock_init(&adapter
->req_list_lock
);
1029 retval
= zfcp_reqlist_alloc(adapter
);
1031 ZFCP_LOG_INFO("request list initialization failed\n");
1032 goto failed_low_mem_buffers
;
1035 /* initialize debug locks */
1037 spin_lock_init(&adapter
->erp_dbf_lock
);
1038 spin_lock_init(&adapter
->hba_dbf_lock
);
1039 spin_lock_init(&adapter
->san_dbf_lock
);
1040 spin_lock_init(&adapter
->scsi_dbf_lock
);
1042 retval
= zfcp_adapter_debug_register(adapter
);
1044 goto debug_register_failed
;
1046 /* initialize error recovery stuff */
1048 rwlock_init(&adapter
->erp_lock
);
1049 sema_init(&adapter
->erp_ready_sem
, 0);
1050 INIT_LIST_HEAD(&adapter
->erp_ready_head
);
1051 INIT_LIST_HEAD(&adapter
->erp_running_head
);
1053 /* initialize abort lock */
1054 rwlock_init(&adapter
->abort_lock
);
1056 /* initialise some erp stuff */
1057 init_waitqueue_head(&adapter
->erp_thread_wqh
);
1058 init_waitqueue_head(&adapter
->erp_done_wqh
);
1060 /* initialize lock of associated request queue */
1061 rwlock_init(&adapter
->request_queue
.queue_lock
);
1063 /* mark adapter unusable as long as sysfs registration is not complete */
1064 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1066 dev_set_drvdata(&ccw_device
->dev
, adapter
);
1068 if (zfcp_sysfs_adapter_create_files(&ccw_device
->dev
))
1071 adapter
->generic_services
.parent
= &adapter
->ccw_device
->dev
;
1072 adapter
->generic_services
.release
= zfcp_dummy_release
;
1073 snprintf(adapter
->generic_services
.bus_id
, BUS_ID_SIZE
,
1074 "generic_services");
1076 if (device_register(&adapter
->generic_services
))
1077 goto generic_services_failed
;
1079 /* put allocated adapter at list tail */
1080 write_lock_irq(&zfcp_data
.config_lock
);
1081 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1082 list_add_tail(&adapter
->list
, &zfcp_data
.adapter_list_head
);
1083 write_unlock_irq(&zfcp_data
.config_lock
);
1085 zfcp_data
.adapters
++;
1089 generic_services_failed
:
1090 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1092 zfcp_adapter_debug_unregister(adapter
);
1093 debug_register_failed
:
1094 dev_set_drvdata(&ccw_device
->dev
, NULL
);
1095 zfcp_reqlist_free(adapter
);
1096 failed_low_mem_buffers
:
1097 zfcp_free_low_mem_buffers(adapter
);
1098 if (qdio_free(ccw_device
) != 0)
1099 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1100 zfcp_get_busid_by_adapter(adapter
));
1101 qdio_allocate_failed
:
1102 zfcp_qdio_free_queues(adapter
);
1103 queues_alloc_failed
:
1111 * returns: 0 - struct zfcp_adapter data structure successfully removed
1112 * !0 - struct zfcp_adapter data structure could not be removed
1114 * locks: adapter list write lock is assumed to be held by caller
1117 zfcp_adapter_dequeue(struct zfcp_adapter
*adapter
)
1120 unsigned long flags
;
1122 zfcp_adapter_scsi_unregister(adapter
);
1123 device_unregister(&adapter
->generic_services
);
1124 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1125 dev_set_drvdata(&adapter
->ccw_device
->dev
, NULL
);
1126 /* sanity check: no pending FSF requests */
1127 spin_lock_irqsave(&adapter
->req_list_lock
, flags
);
1128 retval
= zfcp_reqlist_isempty(adapter
);
1129 spin_unlock_irqrestore(&adapter
->req_list_lock
, flags
);
1131 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1132 "%i requests outstanding\n",
1133 zfcp_get_busid_by_adapter(adapter
), adapter
,
1134 atomic_read(&adapter
->reqs_active
));
1139 zfcp_adapter_debug_unregister(adapter
);
1141 /* remove specified adapter data structure from list */
1142 write_lock_irq(&zfcp_data
.config_lock
);
1143 list_del(&adapter
->list
);
1144 write_unlock_irq(&zfcp_data
.config_lock
);
1146 /* decrease number of adapters in list */
1147 zfcp_data
.adapters
--;
1149 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1150 "%i adapters still in list\n",
1151 zfcp_get_busid_by_adapter(adapter
),
1152 adapter
, zfcp_data
.adapters
);
1154 retval
= qdio_free(adapter
->ccw_device
);
1156 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1157 zfcp_get_busid_by_adapter(adapter
));
1159 zfcp_free_low_mem_buffers(adapter
);
1160 /* free memory of adapter data structure and queues */
1161 zfcp_qdio_free_queues(adapter
);
1162 zfcp_reqlist_free(adapter
);
1163 kfree(adapter
->fc_stats
);
1164 kfree(adapter
->stats_reset_data
);
1165 ZFCP_LOG_TRACE("freeing adapter structure\n");
1172 * zfcp_port_enqueue - enqueue port to port list of adapter
1173 * @adapter: adapter where remote port is added
1174 * @wwpn: WWPN of the remote port to be enqueued
1175 * @status: initial status for the port
1176 * @d_id: destination id of the remote port to be enqueued
1177 * Return: pointer to enqueued port on success, NULL on error
1178 * Locks: config_sema must be held to serialize changes to the port list
1180 * All port internal structures are set up and the sysfs entry is generated.
1181 * d_id is used to enqueue ports with a well known address like the Directory
1182 * Service for nameserver lookup.
1185 zfcp_port_enqueue(struct zfcp_adapter
*adapter
, wwn_t wwpn
, u32 status
,
1188 struct zfcp_port
*port
;
1191 check_wwpn
= !(status
& ZFCP_STATUS_PORT_NO_WWPN
);
1193 * check that there is no port with this WWPN already in list
1196 read_lock_irq(&zfcp_data
.config_lock
);
1197 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
1198 read_unlock_irq(&zfcp_data
.config_lock
);
1203 port
= kzalloc(sizeof (struct zfcp_port
), GFP_KERNEL
);
1207 /* initialise reference count stuff */
1208 atomic_set(&port
->refcount
, 0);
1209 init_waitqueue_head(&port
->remove_wq
);
1211 INIT_LIST_HEAD(&port
->unit_list_head
);
1212 INIT_LIST_HEAD(&port
->unit_remove_lh
);
1214 port
->adapter
= adapter
;
1219 atomic_set_mask(status
, &port
->status
);
1221 /* setup for sysfs registration */
1222 if (status
& ZFCP_STATUS_PORT_WKA
) {
1224 case ZFCP_DID_DIRECTORY_SERVICE
:
1225 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1228 case ZFCP_DID_MANAGEMENT_SERVICE
:
1229 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1232 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE
:
1233 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1234 "key_distribution");
1236 case ZFCP_DID_ALIAS_SERVICE
:
1237 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1240 case ZFCP_DID_TIME_SERVICE
:
1241 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1249 port
->sysfs_device
.parent
= &adapter
->generic_services
;
1251 snprintf(port
->sysfs_device
.bus_id
,
1252 BUS_ID_SIZE
, "0x%016llx", wwpn
);
1253 port
->sysfs_device
.parent
= &adapter
->ccw_device
->dev
;
1255 port
->sysfs_device
.release
= zfcp_sysfs_port_release
;
1256 dev_set_drvdata(&port
->sysfs_device
, port
);
1258 /* mark port unusable as long as sysfs registration is not complete */
1259 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1261 if (device_register(&port
->sysfs_device
)) {
1266 if (zfcp_sysfs_port_create_files(&port
->sysfs_device
, status
)) {
1267 device_unregister(&port
->sysfs_device
);
1271 zfcp_port_get(port
);
1273 write_lock_irq(&zfcp_data
.config_lock
);
1274 list_add_tail(&port
->list
, &adapter
->port_list_head
);
1275 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1276 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &port
->status
);
1277 if (d_id
== ZFCP_DID_DIRECTORY_SERVICE
)
1278 if (!adapter
->nameserver_port
)
1279 adapter
->nameserver_port
= port
;
1281 write_unlock_irq(&zfcp_data
.config_lock
);
1283 zfcp_adapter_get(adapter
);
1289 zfcp_port_dequeue(struct zfcp_port
*port
)
1291 zfcp_port_wait(port
);
1292 write_lock_irq(&zfcp_data
.config_lock
);
1293 list_del(&port
->list
);
1294 port
->adapter
->ports
--;
1295 write_unlock_irq(&zfcp_data
.config_lock
);
1297 fc_remote_port_delete(port
->rport
);
1299 zfcp_adapter_put(port
->adapter
);
1300 zfcp_sysfs_port_remove_files(&port
->sysfs_device
,
1301 atomic_read(&port
->status
));
1302 device_unregister(&port
->sysfs_device
);
1305 /* Enqueues a nameserver port */
1307 zfcp_nameserver_enqueue(struct zfcp_adapter
*adapter
)
1309 struct zfcp_port
*port
;
1311 port
= zfcp_port_enqueue(adapter
, 0, ZFCP_STATUS_PORT_WKA
,
1312 ZFCP_DID_DIRECTORY_SERVICE
);
1314 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1315 "adapter %s failed\n",
1316 zfcp_get_busid_by_adapter(adapter
));
1319 zfcp_port_put(port
);
1324 #undef ZFCP_LOG_AREA
1326 /****************************************************************/
1327 /******* Fibre Channel Standard related Functions **************/
1328 /****************************************************************/
1330 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1333 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter
*adapter
,
1334 struct fsf_status_read_buffer
*status_buffer
)
1336 struct fcp_rscn_head
*fcp_rscn_head
;
1337 struct fcp_rscn_element
*fcp_rscn_element
;
1338 struct zfcp_port
*port
;
1342 unsigned long flags
;
1344 fcp_rscn_head
= (struct fcp_rscn_head
*) status_buffer
->payload
;
1345 fcp_rscn_element
= (struct fcp_rscn_element
*) status_buffer
->payload
;
1348 no_entries
= (fcp_rscn_head
->payload_len
/ 4);
1350 for (i
= 1; i
< no_entries
; i
++) {
1351 /* skip head and start with 1st element */
1353 switch (fcp_rscn_element
->addr_format
) {
1354 case ZFCP_PORT_ADDRESS
:
1355 range_mask
= ZFCP_PORTS_RANGE_PORT
;
1357 case ZFCP_AREA_ADDRESS
:
1358 range_mask
= ZFCP_PORTS_RANGE_AREA
;
1360 case ZFCP_DOMAIN_ADDRESS
:
1361 range_mask
= ZFCP_PORTS_RANGE_DOMAIN
;
1363 case ZFCP_FABRIC_ADDRESS
:
1364 range_mask
= ZFCP_PORTS_RANGE_FABRIC
;
1367 ZFCP_LOG_INFO("incoming RSCN with unknown "
1368 "address format\n");
1371 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1372 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1373 if (atomic_test_mask
1374 (ZFCP_STATUS_PORT_WKA
, &port
->status
))
1376 /* Do we know this port? If not skip it. */
1377 if (!atomic_test_mask
1378 (ZFCP_STATUS_PORT_DID_DID
, &port
->status
)) {
1379 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1380 "port 0x%016Lx\n", port
->wwpn
);
1381 zfcp_erp_port_reopen(port
,
1382 ZFCP_STATUS_COMMON_ERP_FAILED
);
1387 * FIXME: race: d_id might being invalidated
1388 * (...DID_DID reset)
1390 if ((port
->d_id
& range_mask
)
1391 == (fcp_rscn_element
->nport_did
& range_mask
)) {
1392 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1393 fcp_rscn_element
->nport_did
);
1395 * Unfortunately, an RSCN does not specify the
1396 * type of change a target underwent. We assume
1397 * that it makes sense to reopen the link.
1398 * FIXME: Shall we try to find out more about
1399 * the target and link state before closing it?
1400 * How to accomplish this? (nameserver?)
1401 * Where would such code be put in?
1402 * (inside or outside erp)
1404 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1405 "port 0x%016Lx\n", port
->wwpn
);
1406 zfcp_test_link(port
);
1409 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1414 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter
*adapter
,
1415 struct fsf_status_read_buffer
*status_buffer
)
1417 struct fsf_plogi
*els_plogi
;
1418 struct zfcp_port
*port
;
1419 unsigned long flags
;
1421 els_plogi
= (struct fsf_plogi
*) status_buffer
->payload
;
1422 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1423 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1424 if (port
->wwpn
== (*(wwn_t
*) &els_plogi
->serv_param
.wwpn
))
1427 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1429 if (!port
|| (port
->wwpn
!= (*(wwn_t
*) &els_plogi
->serv_param
.wwpn
))) {
1430 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1431 "with d_id 0x%06x on adapter %s\n",
1432 status_buffer
->d_id
,
1433 zfcp_get_busid_by_adapter(adapter
));
1435 zfcp_erp_port_forced_reopen(port
, 0);
1440 zfcp_fsf_incoming_els_logo(struct zfcp_adapter
*adapter
,
1441 struct fsf_status_read_buffer
*status_buffer
)
1443 struct fcp_logo
*els_logo
= (struct fcp_logo
*) status_buffer
->payload
;
1444 struct zfcp_port
*port
;
1445 unsigned long flags
;
1447 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1448 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1449 if (port
->wwpn
== els_logo
->nport_wwpn
)
1452 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1454 if (!port
|| (port
->wwpn
!= els_logo
->nport_wwpn
)) {
1455 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1456 "with d_id 0x%06x on adapter %s\n",
1457 status_buffer
->d_id
,
1458 zfcp_get_busid_by_adapter(adapter
));
1460 zfcp_erp_port_forced_reopen(port
, 0);
1465 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter
*adapter
,
1466 struct fsf_status_read_buffer
*status_buffer
)
1468 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1469 "for adapter %s\n", *(u32
*) (status_buffer
->payload
),
1470 zfcp_get_busid_by_adapter(adapter
));
1475 zfcp_fsf_incoming_els(struct zfcp_fsf_req
*fsf_req
)
1477 struct fsf_status_read_buffer
*status_buffer
;
1479 struct zfcp_adapter
*adapter
;
1481 status_buffer
= (struct fsf_status_read_buffer
*) fsf_req
->data
;
1482 els_type
= *(u32
*) (status_buffer
->payload
);
1483 adapter
= fsf_req
->adapter
;
1485 zfcp_san_dbf_event_incoming_els(fsf_req
);
1486 if (els_type
== LS_PLOGI
)
1487 zfcp_fsf_incoming_els_plogi(adapter
, status_buffer
);
1488 else if (els_type
== LS_LOGO
)
1489 zfcp_fsf_incoming_els_logo(adapter
, status_buffer
);
1490 else if ((els_type
& 0xffff0000) == LS_RSCN
)
1491 /* we are only concerned with the command, not the length */
1492 zfcp_fsf_incoming_els_rscn(adapter
, status_buffer
);
1494 zfcp_fsf_incoming_els_unknown(adapter
, status_buffer
);
1499 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1500 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1501 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1504 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data
**gid_pn
, mempool_t
*pool
)
1506 struct zfcp_gid_pn_data
*data
;
1509 data
= mempool_alloc(pool
, GFP_ATOMIC
);
1510 if (likely(data
!= NULL
)) {
1511 data
->ct
.pool
= pool
;
1514 data
= kmem_cache_alloc(zfcp_data
.gid_pn_cache
, GFP_ATOMIC
);
1520 memset(data
, 0, sizeof(*data
));
1521 data
->ct
.req
= &data
->req
;
1522 data
->ct
.resp
= &data
->resp
;
1523 data
->ct
.req_count
= data
->ct
.resp_count
= 1;
1524 zfcp_address_to_sg(&data
->ct_iu_req
, &data
->req
);
1525 zfcp_address_to_sg(&data
->ct_iu_resp
, &data
->resp
);
1526 data
->req
.length
= sizeof(struct ct_iu_gid_pn_req
);
1527 data
->resp
.length
= sizeof(struct ct_iu_gid_pn_resp
);
1534 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1535 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1537 static void zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data
*gid_pn
)
1539 if (gid_pn
->ct
.pool
)
1540 mempool_free(gid_pn
, gid_pn
->ct
.pool
);
1542 kmem_cache_free(zfcp_data
.gid_pn_cache
, gid_pn
);
1546 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1547 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1550 zfcp_ns_gid_pn_request(struct zfcp_erp_action
*erp_action
)
1553 struct ct_iu_gid_pn_req
*ct_iu_req
;
1554 struct zfcp_gid_pn_data
*gid_pn
;
1555 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1557 ret
= zfcp_gid_pn_buffers_alloc(&gid_pn
, adapter
->pool
.data_gid_pn
);
1559 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1560 "request failed for adapter %s\n",
1561 zfcp_get_busid_by_adapter(adapter
));
1565 /* setup nameserver request */
1566 ct_iu_req
= zfcp_sg_to_address(gid_pn
->ct
.req
);
1567 ct_iu_req
->header
.revision
= ZFCP_CT_REVISION
;
1568 ct_iu_req
->header
.gs_type
= ZFCP_CT_DIRECTORY_SERVICE
;
1569 ct_iu_req
->header
.gs_subtype
= ZFCP_CT_NAME_SERVER
;
1570 ct_iu_req
->header
.options
= ZFCP_CT_SYNCHRONOUS
;
1571 ct_iu_req
->header
.cmd_rsp_code
= ZFCP_CT_GID_PN
;
1572 ct_iu_req
->header
.max_res_size
= ZFCP_CT_MAX_SIZE
;
1573 ct_iu_req
->wwpn
= erp_action
->port
->wwpn
;
1575 /* setup parameters for send generic command */
1576 gid_pn
->ct
.port
= adapter
->nameserver_port
;
1577 gid_pn
->ct
.handler
= zfcp_ns_gid_pn_handler
;
1578 gid_pn
->ct
.handler_data
= (unsigned long) gid_pn
;
1579 gid_pn
->ct
.timeout
= ZFCP_NS_GID_PN_TIMEOUT
;
1580 gid_pn
->port
= erp_action
->port
;
1582 ret
= zfcp_fsf_send_ct(&gid_pn
->ct
, adapter
->pool
.fsf_req_erp
,
1585 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1586 "failed for adapter %s\n",
1587 zfcp_get_busid_by_adapter(adapter
));
1589 zfcp_gid_pn_buffers_free(gid_pn
);
1597 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1598 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1600 static void zfcp_ns_gid_pn_handler(unsigned long data
)
1602 struct zfcp_port
*port
;
1603 struct zfcp_send_ct
*ct
;
1604 struct ct_iu_gid_pn_req
*ct_iu_req
;
1605 struct ct_iu_gid_pn_resp
*ct_iu_resp
;
1606 struct zfcp_gid_pn_data
*gid_pn
;
1609 gid_pn
= (struct zfcp_gid_pn_data
*) data
;
1610 port
= gid_pn
->port
;
1612 ct_iu_req
= zfcp_sg_to_address(ct
->req
);
1613 ct_iu_resp
= zfcp_sg_to_address(ct
->resp
);
1615 if (ct
->status
!= 0)
1618 if (zfcp_check_ct_response(&ct_iu_resp
->header
)) {
1619 /* FIXME: do we need some specific erp entry points */
1620 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN
, &port
->status
);
1624 if (ct_iu_req
->wwpn
!= port
->wwpn
) {
1625 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1626 "lookup does not match expected wwpn 0x%016Lx "
1627 "for adapter %s\n", ct_iu_req
->wwpn
, port
->wwpn
,
1628 zfcp_get_busid_by_port(port
));
1632 /* looks like a valid d_id */
1633 port
->d_id
= ct_iu_resp
->d_id
& ZFCP_DID_MASK
;
1634 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID
, &port
->status
);
1635 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%06x\n",
1636 zfcp_get_busid_by_port(port
), port
->wwpn
, port
->d_id
);
1640 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1641 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_req
,
1642 sizeof(struct ct_iu_gid_pn_req
));
1643 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_resp
,
1644 sizeof(struct ct_iu_gid_pn_resp
));
1647 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1648 "0x%016Lx for adapter %s\n",
1649 port
->wwpn
, zfcp_get_busid_by_port(port
));
1651 zfcp_gid_pn_buffers_free(gid_pn
);
1655 /* reject CT_IU reason codes acc. to FC-GS-4 */
1656 static const struct zfcp_rc_entry zfcp_ct_rc
[] = {
1657 {0x01, "invalid command code"},
1658 {0x02, "invalid version level"},
1659 {0x03, "logical error"},
1660 {0x04, "invalid CT_IU size"},
1661 {0x05, "logical busy"},
1662 {0x07, "protocol error"},
1663 {0x09, "unable to perform command request"},
1664 {0x0b, "command not supported"},
1665 {0x0d, "server not available"},
1666 {0x0e, "session could not be established"},
1667 {0xff, "vendor specific error"},
1671 /* LS_RJT reason codes acc. to FC-FS */
1672 static const struct zfcp_rc_entry zfcp_ls_rjt_rc
[] = {
1673 {0x01, "invalid LS_Command code"},
1674 {0x03, "logical error"},
1675 {0x05, "logical busy"},
1676 {0x07, "protocol error"},
1677 {0x09, "unable to perform command request"},
1678 {0x0b, "command not supported"},
1679 {0x0e, "command already in progress"},
1680 {0xff, "vendor specific error"},
1684 /* reject reason codes according to FC-PH/FC-FS */
1685 static const struct zfcp_rc_entry zfcp_p_rjt_rc
[] = {
1686 {0x01, "invalid D_ID"},
1687 {0x02, "invalid S_ID"},
1688 {0x03, "Nx_Port not available, temporary"},
1689 {0x04, "Nx_Port not available, permament"},
1690 {0x05, "class not supported"},
1691 {0x06, "delimiter usage error"},
1692 {0x07, "TYPE not supported"},
1693 {0x08, "invalid Link_Control"},
1694 {0x09, "invalid R_CTL field"},
1695 {0x0a, "invalid F_CTL field"},
1696 {0x0b, "invalid OX_ID"},
1697 {0x0c, "invalid RX_ID"},
1698 {0x0d, "invalid SEQ_ID"},
1699 {0x0e, "invalid DF_CTL"},
1700 {0x0f, "invalid SEQ_CNT"},
1701 {0x10, "invalid parameter field"},
1702 {0x11, "exchange error"},
1703 {0x12, "protocol error"},
1704 {0x13, "incorrect length"},
1705 {0x14, "unsupported ACK"},
1706 {0x15, "class of service not supported by entity at FFFFFE"},
1707 {0x16, "login required"},
1708 {0x17, "excessive sequences attempted"},
1709 {0x18, "unable to establish exchange"},
1710 {0x1a, "fabric path not available"},
1711 {0x1b, "invalid VC_ID (class 4)"},
1712 {0x1c, "invalid CS_CTL field"},
1713 {0x1d, "insufficient resources for VC (class 4)"},
1714 {0x1f, "invalid class of service"},
1715 {0x20, "preemption request rejected"},
1716 {0x21, "preemption not enabled"},
1717 {0x22, "multicast error"},
1718 {0x23, "multicast error terminate"},
1719 {0x24, "process login required"},
1720 {0xff, "vendor specific reject"},
1725 * zfcp_rc_description - return description for given reaon code
1726 * @code: reason code
1727 * @rc_table: table of reason codes and descriptions
1730 zfcp_rc_description(u8 code
, const struct zfcp_rc_entry
*rc_table
)
1732 const char *descr
= "unknown reason code";
1735 if (code
== rc_table
->code
) {
1736 descr
= rc_table
->description
;
1740 } while (rc_table
->code
&& rc_table
->description
);
1746 * zfcp_check_ct_response - evaluate reason code for CT_IU
1747 * @rjt: response payload to an CT_IU request
1748 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1751 zfcp_check_ct_response(struct ct_hdr
*rjt
)
1753 if (rjt
->cmd_rsp_code
== ZFCP_CT_ACCEPT
)
1756 if (rjt
->cmd_rsp_code
!= ZFCP_CT_REJECT
) {
1757 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1758 "response code (0x%04hx)\n",
1763 ZFCP_LOG_INFO("Generic Service command rejected\n");
1764 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1765 zfcp_rc_description(rjt
->reason_code
, zfcp_ct_rc
),
1766 (u32
) rjt
->reason_code
, (u32
) rjt
->reason_code_expl
,
1767 (u32
) rjt
->vendor_unique
);
1773 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1774 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1775 * @rc_table: table of reason codes and descriptions
1778 zfcp_print_els_rjt(struct zfcp_ls_rjt_par
*rjt_par
,
1779 const struct zfcp_rc_entry
*rc_table
)
1781 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1782 zfcp_rc_description(rjt_par
->reason_code
, rc_table
),
1783 (u32
) rjt_par
->action
, (u32
) rjt_par
->reason_code
,
1784 (u32
) rjt_par
->reason_expl
, (u32
) rjt_par
->vendor_unique
);
1788 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1789 * @sq: status qualifier word
1790 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1791 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1794 zfcp_handle_els_rjt(u32 sq
, struct zfcp_ls_rjt_par
*rjt_par
)
1798 if (sq
== FSF_IOSTAT_NPORT_RJT
) {
1799 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1800 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1802 if (rjt_par
->reason_code
== 0x01)
1804 } else if (sq
== FSF_IOSTAT_FABRIC_RJT
) {
1805 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1806 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1808 if (rjt_par
->reason_code
== 0x01)
1810 } else if (sq
== FSF_IOSTAT_LS_RJT
) {
1811 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1812 zfcp_print_els_rjt(rjt_par
, zfcp_ls_rjt_rc
);
1815 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq
);
1821 * zfcp_plogi_evaluate - evaluate PLOGI playload and copy important fields
1822 * into zfcp_port structure
1823 * @port: zfcp_port structure
1824 * @plogi: plogi payload
1827 zfcp_plogi_evaluate(struct zfcp_port
*port
, struct fsf_plogi
*plogi
)
1829 port
->maxframe_size
= plogi
->serv_param
.common_serv_param
[7] |
1830 ((plogi
->serv_param
.common_serv_param
[6] & 0x0F) << 8);
1831 if (plogi
->serv_param
.class1_serv_param
[0] & 0x80)
1832 port
->supported_classes
|= FC_COS_CLASS1
;
1833 if (plogi
->serv_param
.class2_serv_param
[0] & 0x80)
1834 port
->supported_classes
|= FC_COS_CLASS2
;
1835 if (plogi
->serv_param
.class3_serv_param
[0] & 0x80)
1836 port
->supported_classes
|= FC_COS_CLASS3
;
1837 if (plogi
->serv_param
.class4_serv_param
[0] & 0x80)
1838 port
->supported_classes
|= FC_COS_CLASS4
;
1841 #undef ZFCP_LOG_AREA