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 inline int zfcp_sg_list_alloc(struct zfcp_sg_list
*, size_t);
51 static inline void zfcp_sg_list_free(struct zfcp_sg_list
*);
52 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*,
53 void __user
*, size_t);
54 static inline int zfcp_sg_list_copy_to_user(void __user
*,
55 struct zfcp_sg_list
*, size_t);
57 static long zfcp_cfdc_dev_ioctl(struct file
*, unsigned int, unsigned long);
59 #define ZFCP_CFDC_IOC_MAGIC 0xDD
60 #define ZFCP_CFDC_IOC \
61 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
64 static struct file_operations zfcp_cfdc_fops
= {
65 .unlocked_ioctl
= zfcp_cfdc_dev_ioctl
,
67 .compat_ioctl
= zfcp_cfdc_dev_ioctl
71 static struct miscdevice zfcp_cfdc_misc
= {
72 .minor
= ZFCP_CFDC_DEV_MINOR
,
73 .name
= ZFCP_CFDC_DEV_NAME
,
74 .fops
= &zfcp_cfdc_fops
77 /*********************** KERNEL/MODULE PARAMETERS ***************************/
79 /* declare driver module init/cleanup functions */
80 module_init(zfcp_module_init
);
82 MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
84 ("FCP (SCSI over Fibre Channel) HBA driver for IBM System z9 and zSeries");
85 MODULE_LICENSE("GPL");
87 module_param(device
, charp
, 0400);
88 MODULE_PARM_DESC(device
, "specify initial device");
90 module_param(loglevel
, uint
, 0400);
91 MODULE_PARM_DESC(loglevel
,
92 "log levels, 8 nibbles: "
93 "FC ERP QDIO CIO Config FSF SCSI Other, "
94 "levels: 0=none 1=normal 2=devel 3=trace");
96 /****************************************************************/
97 /************** Functions without logging ***********************/
98 /****************************************************************/
101 _zfcp_hex_dump(char *addr
, int count
)
104 for (i
= 0; i
< count
; i
++) {
105 printk("%02x", addr
[i
]);
111 if (((i
-1) % 32) != 31)
115 /****************************************************************/
116 /************** Uncategorised Functions *************************/
117 /****************************************************************/
119 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
122 * zfcp_device_setup - setup function
123 * @str: pointer to parameter string
125 * Parse "device=..." parameter string.
128 zfcp_device_setup(char *devstr
)
136 len
= strlen(devstr
) + 1;
137 str
= (char *) kmalloc(len
, GFP_KERNEL
);
140 memcpy(str
, devstr
, len
);
142 tmp
= strchr(str
, ',');
146 strncpy(zfcp_data
.init_busid
, str
, BUS_ID_SIZE
);
147 zfcp_data
.init_busid
[BUS_ID_SIZE
-1] = '\0';
149 zfcp_data
.init_wwpn
= simple_strtoull(tmp
, &tmp
, 0);
155 zfcp_data
.init_fcp_lun
= simple_strtoull(tmp
, &tmp
, 0);
162 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str
);
168 zfcp_init_device_configure(void)
170 struct zfcp_adapter
*adapter
;
171 struct zfcp_port
*port
;
172 struct zfcp_unit
*unit
;
174 down(&zfcp_data
.config_sema
);
175 read_lock_irq(&zfcp_data
.config_lock
);
176 adapter
= zfcp_get_adapter_by_busid(zfcp_data
.init_busid
);
178 zfcp_adapter_get(adapter
);
179 read_unlock_irq(&zfcp_data
.config_lock
);
183 port
= zfcp_port_enqueue(adapter
, zfcp_data
.init_wwpn
, 0, 0);
186 unit
= zfcp_unit_enqueue(port
, zfcp_data
.init_fcp_lun
);
189 up(&zfcp_data
.config_sema
);
190 ccw_device_set_online(adapter
->ccw_device
);
191 zfcp_erp_wait(adapter
);
192 down(&zfcp_data
.config_sema
);
197 zfcp_adapter_put(adapter
);
199 up(&zfcp_data
.config_sema
);
204 zfcp_module_init(void)
209 atomic_set(&zfcp_data
.loglevel
, loglevel
);
211 /* initialize adapter list */
212 INIT_LIST_HEAD(&zfcp_data
.adapter_list_head
);
214 /* initialize adapters to be removed list head */
215 INIT_LIST_HEAD(&zfcp_data
.adapter_remove_lh
);
217 zfcp_transport_template
= fc_attach_transport(&zfcp_transport_functions
);
218 if (!zfcp_transport_template
)
221 retval
= misc_register(&zfcp_cfdc_misc
);
223 ZFCP_LOG_INFO("registration of misc device "
224 "zfcp_cfdc failed\n");
228 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
229 ZFCP_CFDC_DEV_MAJOR
, zfcp_cfdc_misc
.minor
);
231 /* Initialise proc semaphores */
232 sema_init(&zfcp_data
.config_sema
, 1);
234 /* initialise configuration rw lock */
235 rwlock_init(&zfcp_data
.config_lock
);
237 /* save address of data structure managing the driver module */
238 zfcp_data
.scsi_host_template
.module
= THIS_MODULE
;
240 /* setup dynamic I/O */
241 retval
= zfcp_ccw_register();
243 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
244 goto out_ccw_register
;
247 if (zfcp_device_setup(device
))
248 zfcp_init_device_configure();
253 misc_deregister(&zfcp_cfdc_misc
);
259 * function: zfcp_cfdc_dev_ioctl
261 * purpose: Handle control file upload/download transaction via IOCTL
264 * returns: 0 - Operation completed successfuly
265 * -ENOTTY - Unknown IOCTL command
266 * -EINVAL - Invalid sense data record
267 * -ENXIO - The FCP adapter is not available
268 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
269 * -ENOMEM - Insufficient memory
270 * -EFAULT - User space memory I/O operation fault
271 * -EPERM - Cannot create or queue FSF request or create SBALs
272 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
275 zfcp_cfdc_dev_ioctl(struct file
*file
, unsigned int command
,
276 unsigned long buffer
)
278 struct zfcp_cfdc_sense_data
*sense_data
, __user
*sense_data_user
;
279 struct zfcp_adapter
*adapter
= NULL
;
280 struct zfcp_fsf_req
*fsf_req
= NULL
;
281 struct zfcp_sg_list
*sg_list
= NULL
;
282 u32 fsf_command
, option
;
286 sense_data
= kmalloc(sizeof(struct zfcp_cfdc_sense_data
), GFP_KERNEL
);
287 if (sense_data
== NULL
) {
292 sg_list
= kzalloc(sizeof(struct zfcp_sg_list
), GFP_KERNEL
);
293 if (sg_list
== NULL
) {
298 if (command
!= ZFCP_CFDC_IOC
) {
299 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command
);
304 if ((sense_data_user
= (void __user
*) buffer
) == NULL
) {
305 ZFCP_LOG_INFO("sense data record is required\n");
310 retval
= copy_from_user(sense_data
, sense_data_user
,
311 sizeof(struct zfcp_cfdc_sense_data
));
317 if (sense_data
->signature
!= ZFCP_CFDC_SIGNATURE
) {
318 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
319 ZFCP_CFDC_SIGNATURE
);
324 switch (sense_data
->command
) {
326 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL
:
327 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
328 option
= FSF_CFDC_OPTION_NORMAL_MODE
;
331 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE
:
332 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
333 option
= FSF_CFDC_OPTION_FORCE
;
336 case ZFCP_CFDC_CMND_FULL_ACCESS
:
337 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
338 option
= FSF_CFDC_OPTION_FULL_ACCESS
;
341 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS
:
342 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
343 option
= FSF_CFDC_OPTION_RESTRICTED_ACCESS
;
346 case ZFCP_CFDC_CMND_UPLOAD
:
347 fsf_command
= FSF_QTCB_UPLOAD_CONTROL_FILE
;
352 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
353 sense_data
->command
);
358 bus_id
= kmalloc(BUS_ID_SIZE
, GFP_KERNEL
);
359 if (bus_id
== NULL
) {
363 snprintf(bus_id
, BUS_ID_SIZE
, "%d.%d.%04x",
364 (sense_data
->devno
>> 24),
365 (sense_data
->devno
>> 16) & 0xFF,
366 (sense_data
->devno
& 0xFFFF));
368 read_lock_irq(&zfcp_data
.config_lock
);
369 adapter
= zfcp_get_adapter_by_busid(bus_id
);
371 zfcp_adapter_get(adapter
);
372 read_unlock_irq(&zfcp_data
.config_lock
);
376 if (adapter
== NULL
) {
377 ZFCP_LOG_INFO("invalid adapter\n");
382 if (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
) {
383 retval
= zfcp_sg_list_alloc(sg_list
,
384 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
391 if ((sense_data
->command
& ZFCP_CFDC_DOWNLOAD
) &&
392 (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
)) {
393 retval
= zfcp_sg_list_copy_from_user(
394 sg_list
, &sense_data_user
->control_file
,
395 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
402 retval
= zfcp_fsf_control_file(adapter
, &fsf_req
, fsf_command
,
407 if ((fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_GOOD
) &&
408 (fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_FSF_STATUS_PRESENTED
)) {
413 sense_data
->fsf_status
= fsf_req
->qtcb
->header
.fsf_status
;
414 memcpy(&sense_data
->fsf_status_qual
,
415 &fsf_req
->qtcb
->header
.fsf_status_qual
,
416 sizeof(union fsf_status_qual
));
417 memcpy(&sense_data
->payloads
, &fsf_req
->qtcb
->bottom
.support
.els
, 256);
419 retval
= copy_to_user(sense_data_user
, sense_data
,
420 sizeof(struct zfcp_cfdc_sense_data
));
426 if (sense_data
->command
& ZFCP_CFDC_UPLOAD
) {
427 retval
= zfcp_sg_list_copy_to_user(
428 &sense_data_user
->control_file
, sg_list
,
429 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
438 zfcp_fsf_req_free(fsf_req
);
440 if ((adapter
!= NULL
) && (retval
!= -ENXIO
))
441 zfcp_adapter_put(adapter
);
443 if (sg_list
!= NULL
) {
444 zfcp_sg_list_free(sg_list
);
455 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
456 * @sg_list: structure describing a scatter gather list
457 * @size: size of scatter-gather list
458 * Return: 0 on success, else -ENOMEM
460 * In sg_list->sg a pointer to the created scatter-gather list is returned,
461 * or NULL if we run out of memory. sg_list->count specifies the number of
462 * elements of the scatter-gather list. The maximum size of a single element
463 * in the scatter-gather list is PAGE_SIZE.
466 zfcp_sg_list_alloc(struct zfcp_sg_list
*sg_list
, size_t size
)
468 struct scatterlist
*sg
;
473 BUG_ON(sg_list
== NULL
);
475 sg_list
->count
= size
>> PAGE_SHIFT
;
476 if (size
& ~PAGE_MASK
)
478 sg_list
->sg
= kcalloc(sg_list
->count
, sizeof(struct scatterlist
),
480 if (sg_list
->sg
== NULL
) {
486 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++) {
487 sg
->length
= min(size
, PAGE_SIZE
);
489 address
= (void *) get_zeroed_page(GFP_KERNEL
);
490 if (address
== NULL
) {
492 zfcp_sg_list_free(sg_list
);
496 zfcp_address_to_sg(address
, sg
);
506 * zfcp_sg_list_free - free memory of a scatter-gather list
507 * @sg_list: structure describing a scatter-gather list
509 * Memory for each element in the scatter-gather list is freed.
510 * Finally sg_list->sg is freed itself and sg_list->count is reset.
513 zfcp_sg_list_free(struct zfcp_sg_list
*sg_list
)
515 struct scatterlist
*sg
;
518 BUG_ON(sg_list
== NULL
);
520 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++)
521 free_page((unsigned long) zfcp_sg_to_address(sg
));
528 * zfcp_sg_size - determine size of a scatter-gather list
529 * @sg: array of (struct scatterlist)
530 * @sg_count: elements in array
531 * Return: size of entire scatter-gather list
534 zfcp_sg_size(struct scatterlist
*sg
, unsigned int sg_count
)
537 struct scatterlist
*p
;
541 for (i
= 0, p
= sg
; i
< sg_count
; i
++, p
++) {
551 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
552 * @sg_list: structure describing a scatter-gather list
553 * @user_buffer: pointer to buffer in user space
554 * @size: number of bytes to be copied
555 * Return: 0 on success, -EFAULT if copy_from_user fails.
558 zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*sg_list
,
559 void __user
*user_buffer
,
562 struct scatterlist
*sg
;
567 BUG_ON(sg_list
== NULL
);
569 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
572 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
573 length
= min((unsigned int)size
, sg
->length
);
574 zfcp_buffer
= zfcp_sg_to_address(sg
);
575 if (copy_from_user(zfcp_buffer
, user_buffer
, length
)) {
579 user_buffer
+= length
;
589 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
590 * @user_buffer: pointer to buffer in user space
591 * @sg_list: structure describing a scatter-gather list
592 * @size: number of bytes to be copied
593 * Return: 0 on success, -EFAULT if copy_to_user fails
596 zfcp_sg_list_copy_to_user(void __user
*user_buffer
,
597 struct zfcp_sg_list
*sg_list
,
600 struct scatterlist
*sg
;
605 BUG_ON(sg_list
== NULL
);
607 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
610 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
611 length
= min((unsigned int) size
, sg
->length
);
612 zfcp_buffer
= zfcp_sg_to_address(sg
);
613 if (copy_to_user(user_buffer
, zfcp_buffer
, length
)) {
617 user_buffer
+= length
;
628 /****************************************************************/
629 /****** Functions for configuration/set-up of structures ********/
630 /****************************************************************/
632 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
635 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
636 * @port: pointer to port to search for unit
637 * @fcp_lun: FCP LUN to search for
638 * Traverse list of all units of a port and return pointer to a unit
639 * with the given FCP LUN.
642 zfcp_get_unit_by_lun(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
644 struct zfcp_unit
*unit
;
647 list_for_each_entry(unit
, &port
->unit_list_head
, list
) {
648 if ((unit
->fcp_lun
== fcp_lun
) &&
649 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
))
655 return found
? unit
: NULL
;
659 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
660 * @adapter: pointer to adapter to search for port
661 * @wwpn: wwpn to search for
662 * Traverse list of all ports of an adapter and return pointer to a port
663 * with the given wwpn.
666 zfcp_get_port_by_wwpn(struct zfcp_adapter
*adapter
, wwn_t wwpn
)
668 struct zfcp_port
*port
;
671 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
672 if ((port
->wwpn
== wwpn
) &&
673 !(atomic_read(&port
->status
) &
674 (ZFCP_STATUS_PORT_NO_WWPN
| ZFCP_STATUS_COMMON_REMOVE
))) {
679 return found
? port
: NULL
;
683 * zfcp_get_port_by_did - find port in port list of adapter by d_id
684 * @adapter: pointer to adapter to search for port
685 * @d_id: d_id to search for
686 * Traverse list of all ports of an adapter and return pointer to a port
687 * with the given d_id.
690 zfcp_get_port_by_did(struct zfcp_adapter
*adapter
, u32 d_id
)
692 struct zfcp_port
*port
;
695 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
696 if ((port
->d_id
== d_id
) &&
697 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
))
703 return found
? port
: NULL
;
707 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
708 * @bus_id: bus_id to search for
709 * Traverse list of all adapters and return pointer to an adapter
710 * with the given bus_id.
712 struct zfcp_adapter
*
713 zfcp_get_adapter_by_busid(char *bus_id
)
715 struct zfcp_adapter
*adapter
;
718 list_for_each_entry(adapter
, &zfcp_data
.adapter_list_head
, list
) {
719 if ((strncmp(bus_id
, zfcp_get_busid_by_adapter(adapter
),
720 BUS_ID_SIZE
) == 0) &&
721 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
,
727 return found
? adapter
: NULL
;
731 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
732 * @port: pointer to port where unit is added
733 * @fcp_lun: FCP LUN of unit to be enqueued
734 * Return: pointer to enqueued unit on success, NULL on error
735 * Locks: config_sema must be held to serialize changes to the unit list
737 * Sets up some unit internal structures and creates sysfs entry.
740 zfcp_unit_enqueue(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
742 struct zfcp_unit
*unit
, *tmp_unit
;
747 * check that there is no unit with this FCP_LUN already in list
749 * Note: Unlike for the adapter and the port, this is an error
751 read_lock_irq(&zfcp_data
.config_lock
);
752 unit
= zfcp_get_unit_by_lun(port
, fcp_lun
);
753 read_unlock_irq(&zfcp_data
.config_lock
);
757 unit
= kzalloc(sizeof (struct zfcp_unit
), GFP_KERNEL
);
761 /* initialise reference count stuff */
762 atomic_set(&unit
->refcount
, 0);
763 init_waitqueue_head(&unit
->remove_wq
);
766 unit
->fcp_lun
= fcp_lun
;
768 /* setup for sysfs registration */
769 snprintf(unit
->sysfs_device
.bus_id
, BUS_ID_SIZE
, "0x%016llx", fcp_lun
);
770 unit
->sysfs_device
.parent
= &port
->sysfs_device
;
771 unit
->sysfs_device
.release
= zfcp_sysfs_unit_release
;
772 dev_set_drvdata(&unit
->sysfs_device
, unit
);
774 /* mark unit unusable as long as sysfs registration is not complete */
775 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
777 if (device_register(&unit
->sysfs_device
)) {
782 if (zfcp_sysfs_unit_create_files(&unit
->sysfs_device
)) {
783 device_unregister(&unit
->sysfs_device
);
791 write_lock_irq(&zfcp_data
.config_lock
);
792 list_for_each_entry(tmp_unit
, &port
->unit_list_head
, list
) {
793 if (tmp_unit
->scsi_lun
!= scsi_lun
) {
799 unit
->scsi_lun
= scsi_lun
;
801 list_add_tail(&unit
->list
, &tmp_unit
->list
);
803 list_add_tail(&unit
->list
, &port
->unit_list_head
);
804 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
805 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &unit
->status
);
806 write_unlock_irq(&zfcp_data
.config_lock
);
815 zfcp_unit_dequeue(struct zfcp_unit
*unit
)
817 zfcp_unit_wait(unit
);
818 write_lock_irq(&zfcp_data
.config_lock
);
819 list_del(&unit
->list
);
820 write_unlock_irq(&zfcp_data
.config_lock
);
822 zfcp_port_put(unit
->port
);
823 zfcp_sysfs_unit_remove_files(&unit
->sysfs_device
);
824 device_unregister(&unit
->sysfs_device
);
828 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
830 * It also genrates fcp-nameserver request/response buffer and unsolicited
831 * status read fsf_req buffers.
833 * locks: must only be called with zfcp_data.config_sema taken
836 zfcp_allocate_low_mem_buffers(struct zfcp_adapter
*adapter
)
838 adapter
->pool
.fsf_req_erp
=
839 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ERP_NR
,
840 sizeof(struct zfcp_fsf_req_pool_element
));
841 if (!adapter
->pool
.fsf_req_erp
)
844 adapter
->pool
.fsf_req_scsi
=
845 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_SCSI_NR
,
846 sizeof(struct zfcp_fsf_req_pool_element
));
847 if (!adapter
->pool
.fsf_req_scsi
)
850 adapter
->pool
.fsf_req_abort
=
851 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ABORT_NR
,
852 sizeof(struct zfcp_fsf_req_pool_element
));
853 if (!adapter
->pool
.fsf_req_abort
)
856 adapter
->pool
.fsf_req_status_read
=
857 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR
,
858 sizeof(struct zfcp_fsf_req
));
859 if (!adapter
->pool
.fsf_req_status_read
)
862 adapter
->pool
.data_status_read
=
863 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR
,
864 sizeof(struct fsf_status_read_buffer
));
865 if (!adapter
->pool
.data_status_read
)
868 adapter
->pool
.data_gid_pn
=
869 mempool_create_kmalloc_pool(ZFCP_POOL_DATA_GID_PN_NR
,
870 sizeof(struct zfcp_gid_pn_data
));
871 if (!adapter
->pool
.data_gid_pn
)
878 * zfcp_free_low_mem_buffers - free memory pools of an adapter
879 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
880 * locking: zfcp_data.config_sema must be held
883 zfcp_free_low_mem_buffers(struct zfcp_adapter
*adapter
)
885 if (adapter
->pool
.fsf_req_erp
)
886 mempool_destroy(adapter
->pool
.fsf_req_erp
);
887 if (adapter
->pool
.fsf_req_scsi
)
888 mempool_destroy(adapter
->pool
.fsf_req_scsi
);
889 if (adapter
->pool
.fsf_req_abort
)
890 mempool_destroy(adapter
->pool
.fsf_req_abort
);
891 if (adapter
->pool
.fsf_req_status_read
)
892 mempool_destroy(adapter
->pool
.fsf_req_status_read
);
893 if (adapter
->pool
.data_status_read
)
894 mempool_destroy(adapter
->pool
.data_status_read
);
895 if (adapter
->pool
.data_gid_pn
)
896 mempool_destroy(adapter
->pool
.data_gid_pn
);
900 zfcp_dummy_release(struct device
*dev
)
906 * Enqueues an adapter at the end of the adapter list in the driver data.
907 * All adapter internal structures are set up.
908 * Proc-fs entries are also created.
910 * returns: 0 if a new adapter was successfully enqueued
911 * ZFCP_KNOWN if an adapter with this devno was already present
912 * -ENOMEM if alloc failed
913 * locks: config_sema must be held to serialise changes to the adapter list
915 struct zfcp_adapter
*
916 zfcp_adapter_enqueue(struct ccw_device
*ccw_device
)
919 struct zfcp_adapter
*adapter
;
922 * Note: It is safe to release the list_lock, as any list changes
923 * are protected by the config_sema, which must be held to get here
926 /* try to allocate new adapter data structure (zeroed) */
927 adapter
= kzalloc(sizeof (struct zfcp_adapter
), GFP_KERNEL
);
929 ZFCP_LOG_INFO("error: allocation of base adapter "
930 "structure failed\n");
934 ccw_device
->handler
= NULL
;
936 /* save ccw_device pointer */
937 adapter
->ccw_device
= ccw_device
;
939 retval
= zfcp_qdio_allocate_queues(adapter
);
941 goto queues_alloc_failed
;
943 retval
= zfcp_qdio_allocate(adapter
);
945 goto qdio_allocate_failed
;
947 retval
= zfcp_allocate_low_mem_buffers(adapter
);
949 ZFCP_LOG_INFO("error: pool allocation failed\n");
950 goto failed_low_mem_buffers
;
953 /* initialise reference count stuff */
954 atomic_set(&adapter
->refcount
, 0);
955 init_waitqueue_head(&adapter
->remove_wq
);
957 /* initialise list of ports */
958 INIT_LIST_HEAD(&adapter
->port_list_head
);
960 /* initialise list of ports to be removed */
961 INIT_LIST_HEAD(&adapter
->port_remove_lh
);
963 /* initialize list of fsf requests */
964 spin_lock_init(&adapter
->fsf_req_list_lock
);
965 INIT_LIST_HEAD(&adapter
->fsf_req_list_head
);
967 /* initialize debug locks */
969 spin_lock_init(&adapter
->erp_dbf_lock
);
970 spin_lock_init(&adapter
->hba_dbf_lock
);
971 spin_lock_init(&adapter
->san_dbf_lock
);
972 spin_lock_init(&adapter
->scsi_dbf_lock
);
974 /* initialize error recovery stuff */
976 rwlock_init(&adapter
->erp_lock
);
977 sema_init(&adapter
->erp_ready_sem
, 0);
978 INIT_LIST_HEAD(&adapter
->erp_ready_head
);
979 INIT_LIST_HEAD(&adapter
->erp_running_head
);
981 /* initialize abort lock */
982 rwlock_init(&adapter
->abort_lock
);
984 /* initialise some erp stuff */
985 init_waitqueue_head(&adapter
->erp_thread_wqh
);
986 init_waitqueue_head(&adapter
->erp_done_wqh
);
988 /* initialize lock of associated request queue */
989 rwlock_init(&adapter
->request_queue
.queue_lock
);
991 /* intitialise SCSI ER timer */
992 init_timer(&adapter
->scsi_er_timer
);
994 /* set FC service class used per default */
995 adapter
->fc_service_class
= ZFCP_FC_SERVICE_CLASS_DEFAULT
;
997 sprintf(adapter
->name
, "%s", zfcp_get_busid_by_adapter(adapter
));
998 ASCEBC(adapter
->name
, strlen(adapter
->name
));
1000 /* mark adapter unusable as long as sysfs registration is not complete */
1001 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1003 adapter
->ccw_device
= ccw_device
;
1004 dev_set_drvdata(&ccw_device
->dev
, adapter
);
1006 if (zfcp_sysfs_adapter_create_files(&ccw_device
->dev
))
1009 adapter
->generic_services
.parent
= &adapter
->ccw_device
->dev
;
1010 adapter
->generic_services
.release
= zfcp_dummy_release
;
1011 snprintf(adapter
->generic_services
.bus_id
, BUS_ID_SIZE
,
1012 "generic_services");
1014 if (device_register(&adapter
->generic_services
))
1015 goto generic_services_failed
;
1017 /* put allocated adapter at list tail */
1018 write_lock_irq(&zfcp_data
.config_lock
);
1019 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1020 list_add_tail(&adapter
->list
, &zfcp_data
.adapter_list_head
);
1021 write_unlock_irq(&zfcp_data
.config_lock
);
1023 zfcp_data
.adapters
++;
1027 generic_services_failed
:
1028 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1030 dev_set_drvdata(&ccw_device
->dev
, NULL
);
1031 failed_low_mem_buffers
:
1032 zfcp_free_low_mem_buffers(adapter
);
1033 if (qdio_free(ccw_device
) != 0)
1034 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1035 zfcp_get_busid_by_adapter(adapter
));
1036 qdio_allocate_failed
:
1037 zfcp_qdio_free_queues(adapter
);
1038 queues_alloc_failed
:
1046 * returns: 0 - struct zfcp_adapter data structure successfully removed
1047 * !0 - struct zfcp_adapter data structure could not be removed
1049 * locks: adapter list write lock is assumed to be held by caller
1050 * adapter->fsf_req_list_lock is taken and released within this
1051 * function and must not be held on entry
1054 zfcp_adapter_dequeue(struct zfcp_adapter
*adapter
)
1057 unsigned long flags
;
1059 device_unregister(&adapter
->generic_services
);
1060 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1061 dev_set_drvdata(&adapter
->ccw_device
->dev
, NULL
);
1062 /* sanity check: no pending FSF requests */
1063 spin_lock_irqsave(&adapter
->fsf_req_list_lock
, flags
);
1064 retval
= !list_empty(&adapter
->fsf_req_list_head
);
1065 spin_unlock_irqrestore(&adapter
->fsf_req_list_lock
, flags
);
1067 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1068 "%i requests outstanding\n",
1069 zfcp_get_busid_by_adapter(adapter
), adapter
,
1070 atomic_read(&adapter
->fsf_reqs_active
));
1075 /* remove specified adapter data structure from list */
1076 write_lock_irq(&zfcp_data
.config_lock
);
1077 list_del(&adapter
->list
);
1078 write_unlock_irq(&zfcp_data
.config_lock
);
1080 /* decrease number of adapters in list */
1081 zfcp_data
.adapters
--;
1083 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1084 "%i adapters still in list\n",
1085 zfcp_get_busid_by_adapter(adapter
),
1086 adapter
, zfcp_data
.adapters
);
1088 retval
= qdio_free(adapter
->ccw_device
);
1090 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1091 zfcp_get_busid_by_adapter(adapter
));
1093 zfcp_free_low_mem_buffers(adapter
);
1094 /* free memory of adapter data structure and queues */
1095 zfcp_qdio_free_queues(adapter
);
1096 kfree(adapter
->fc_stats
);
1097 kfree(adapter
->stats_reset_data
);
1098 ZFCP_LOG_TRACE("freeing adapter structure\n");
1105 * zfcp_port_enqueue - enqueue port to port list of adapter
1106 * @adapter: adapter where remote port is added
1107 * @wwpn: WWPN of the remote port to be enqueued
1108 * @status: initial status for the port
1109 * @d_id: destination id of the remote port to be enqueued
1110 * Return: pointer to enqueued port on success, NULL on error
1111 * Locks: config_sema must be held to serialize changes to the port list
1113 * All port internal structures are set up and the sysfs entry is generated.
1114 * d_id is used to enqueue ports with a well known address like the Directory
1115 * Service for nameserver lookup.
1118 zfcp_port_enqueue(struct zfcp_adapter
*adapter
, wwn_t wwpn
, u32 status
,
1121 struct zfcp_port
*port
;
1124 check_wwpn
= !(status
& ZFCP_STATUS_PORT_NO_WWPN
);
1126 * check that there is no port with this WWPN already in list
1129 read_lock_irq(&zfcp_data
.config_lock
);
1130 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
1131 read_unlock_irq(&zfcp_data
.config_lock
);
1136 port
= kzalloc(sizeof (struct zfcp_port
), GFP_KERNEL
);
1140 /* initialise reference count stuff */
1141 atomic_set(&port
->refcount
, 0);
1142 init_waitqueue_head(&port
->remove_wq
);
1144 INIT_LIST_HEAD(&port
->unit_list_head
);
1145 INIT_LIST_HEAD(&port
->unit_remove_lh
);
1147 port
->adapter
= adapter
;
1152 atomic_set_mask(status
, &port
->status
);
1154 /* setup for sysfs registration */
1155 if (status
& ZFCP_STATUS_PORT_WKA
) {
1157 case ZFCP_DID_DIRECTORY_SERVICE
:
1158 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1161 case ZFCP_DID_MANAGEMENT_SERVICE
:
1162 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1165 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE
:
1166 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1167 "key_distribution");
1169 case ZFCP_DID_ALIAS_SERVICE
:
1170 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1173 case ZFCP_DID_TIME_SERVICE
:
1174 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1182 port
->sysfs_device
.parent
= &adapter
->generic_services
;
1184 snprintf(port
->sysfs_device
.bus_id
,
1185 BUS_ID_SIZE
, "0x%016llx", wwpn
);
1186 port
->sysfs_device
.parent
= &adapter
->ccw_device
->dev
;
1188 port
->sysfs_device
.release
= zfcp_sysfs_port_release
;
1189 dev_set_drvdata(&port
->sysfs_device
, port
);
1191 /* mark port unusable as long as sysfs registration is not complete */
1192 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1194 if (device_register(&port
->sysfs_device
)) {
1199 if (zfcp_sysfs_port_create_files(&port
->sysfs_device
, status
)) {
1200 device_unregister(&port
->sysfs_device
);
1204 zfcp_port_get(port
);
1206 write_lock_irq(&zfcp_data
.config_lock
);
1207 list_add_tail(&port
->list
, &adapter
->port_list_head
);
1208 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1209 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &port
->status
);
1210 if (d_id
== ZFCP_DID_DIRECTORY_SERVICE
)
1211 if (!adapter
->nameserver_port
)
1212 adapter
->nameserver_port
= port
;
1214 write_unlock_irq(&zfcp_data
.config_lock
);
1216 zfcp_adapter_get(adapter
);
1222 zfcp_port_dequeue(struct zfcp_port
*port
)
1224 zfcp_port_wait(port
);
1225 write_lock_irq(&zfcp_data
.config_lock
);
1226 list_del(&port
->list
);
1227 port
->adapter
->ports
--;
1228 write_unlock_irq(&zfcp_data
.config_lock
);
1230 fc_remote_port_delete(port
->rport
);
1232 zfcp_adapter_put(port
->adapter
);
1233 zfcp_sysfs_port_remove_files(&port
->sysfs_device
,
1234 atomic_read(&port
->status
));
1235 device_unregister(&port
->sysfs_device
);
1238 /* Enqueues a nameserver port */
1240 zfcp_nameserver_enqueue(struct zfcp_adapter
*adapter
)
1242 struct zfcp_port
*port
;
1244 port
= zfcp_port_enqueue(adapter
, 0, ZFCP_STATUS_PORT_WKA
,
1245 ZFCP_DID_DIRECTORY_SERVICE
);
1247 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1248 "adapter %s failed\n",
1249 zfcp_get_busid_by_adapter(adapter
));
1252 zfcp_port_put(port
);
1257 #undef ZFCP_LOG_AREA
1259 /****************************************************************/
1260 /******* Fibre Channel Standard related Functions **************/
1261 /****************************************************************/
1263 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1266 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter
*adapter
,
1267 struct fsf_status_read_buffer
*status_buffer
)
1269 struct fcp_rscn_head
*fcp_rscn_head
;
1270 struct fcp_rscn_element
*fcp_rscn_element
;
1271 struct zfcp_port
*port
;
1275 unsigned long flags
;
1277 fcp_rscn_head
= (struct fcp_rscn_head
*) status_buffer
->payload
;
1278 fcp_rscn_element
= (struct fcp_rscn_element
*) status_buffer
->payload
;
1281 no_entries
= (fcp_rscn_head
->payload_len
/ 4);
1283 for (i
= 1; i
< no_entries
; i
++) {
1284 /* skip head and start with 1st element */
1286 switch (fcp_rscn_element
->addr_format
) {
1287 case ZFCP_PORT_ADDRESS
:
1288 range_mask
= ZFCP_PORTS_RANGE_PORT
;
1290 case ZFCP_AREA_ADDRESS
:
1291 range_mask
= ZFCP_PORTS_RANGE_AREA
;
1293 case ZFCP_DOMAIN_ADDRESS
:
1294 range_mask
= ZFCP_PORTS_RANGE_DOMAIN
;
1296 case ZFCP_FABRIC_ADDRESS
:
1297 range_mask
= ZFCP_PORTS_RANGE_FABRIC
;
1300 ZFCP_LOG_INFO("incoming RSCN with unknown "
1301 "address format\n");
1304 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1305 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1306 if (atomic_test_mask
1307 (ZFCP_STATUS_PORT_WKA
, &port
->status
))
1309 /* Do we know this port? If not skip it. */
1310 if (!atomic_test_mask
1311 (ZFCP_STATUS_PORT_DID_DID
, &port
->status
)) {
1312 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1313 "port 0x%016Lx\n", port
->wwpn
);
1314 zfcp_erp_port_reopen(port
,
1315 ZFCP_STATUS_COMMON_ERP_FAILED
);
1320 * FIXME: race: d_id might being invalidated
1321 * (...DID_DID reset)
1323 if ((port
->d_id
& range_mask
)
1324 == (fcp_rscn_element
->nport_did
& range_mask
)) {
1325 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1326 fcp_rscn_element
->nport_did
);
1328 * Unfortunately, an RSCN does not specify the
1329 * type of change a target underwent. We assume
1330 * that it makes sense to reopen the link.
1331 * FIXME: Shall we try to find out more about
1332 * the target and link state before closing it?
1333 * How to accomplish this? (nameserver?)
1334 * Where would such code be put in?
1335 * (inside or outside erp)
1337 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1338 "port 0x%016Lx\n", port
->wwpn
);
1339 zfcp_test_link(port
);
1342 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1347 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter
*adapter
,
1348 struct fsf_status_read_buffer
*status_buffer
)
1350 logi
*els_logi
= (logi
*) status_buffer
->payload
;
1351 struct zfcp_port
*port
;
1352 unsigned long flags
;
1354 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1355 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1356 if (port
->wwpn
== (*(wwn_t
*) & els_logi
->nport_wwn
))
1359 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1361 if (!port
|| (port
->wwpn
!= (*(wwn_t
*) & els_logi
->nport_wwn
))) {
1362 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1363 "with d_id 0x%08x on adapter %s\n",
1364 status_buffer
->d_id
,
1365 zfcp_get_busid_by_adapter(adapter
));
1367 zfcp_erp_port_forced_reopen(port
, 0);
1372 zfcp_fsf_incoming_els_logo(struct zfcp_adapter
*adapter
,
1373 struct fsf_status_read_buffer
*status_buffer
)
1375 struct fcp_logo
*els_logo
= (struct fcp_logo
*) status_buffer
->payload
;
1376 struct zfcp_port
*port
;
1377 unsigned long flags
;
1379 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1380 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1381 if (port
->wwpn
== els_logo
->nport_wwpn
)
1384 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1386 if (!port
|| (port
->wwpn
!= els_logo
->nport_wwpn
)) {
1387 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1388 "with d_id 0x%08x on adapter %s\n",
1389 status_buffer
->d_id
,
1390 zfcp_get_busid_by_adapter(adapter
));
1392 zfcp_erp_port_forced_reopen(port
, 0);
1397 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter
*adapter
,
1398 struct fsf_status_read_buffer
*status_buffer
)
1400 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1401 "for adapter %s\n", *(u32
*) (status_buffer
->payload
),
1402 zfcp_get_busid_by_adapter(adapter
));
1407 zfcp_fsf_incoming_els(struct zfcp_fsf_req
*fsf_req
)
1409 struct fsf_status_read_buffer
*status_buffer
;
1411 struct zfcp_adapter
*adapter
;
1413 status_buffer
= (struct fsf_status_read_buffer
*) fsf_req
->data
;
1414 els_type
= *(u32
*) (status_buffer
->payload
);
1415 adapter
= fsf_req
->adapter
;
1417 zfcp_san_dbf_event_incoming_els(fsf_req
);
1418 if (els_type
== LS_PLOGI
)
1419 zfcp_fsf_incoming_els_plogi(adapter
, status_buffer
);
1420 else if (els_type
== LS_LOGO
)
1421 zfcp_fsf_incoming_els_logo(adapter
, status_buffer
);
1422 else if ((els_type
& 0xffff0000) == LS_RSCN
)
1423 /* we are only concerned with the command, not the length */
1424 zfcp_fsf_incoming_els_rscn(adapter
, status_buffer
);
1426 zfcp_fsf_incoming_els_unknown(adapter
, status_buffer
);
1431 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1432 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1433 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1436 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data
**gid_pn
, mempool_t
*pool
)
1438 struct zfcp_gid_pn_data
*data
;
1441 data
= mempool_alloc(pool
, GFP_ATOMIC
);
1442 if (likely(data
!= NULL
)) {
1443 data
->ct
.pool
= pool
;
1446 data
= kmalloc(sizeof(struct zfcp_gid_pn_data
), GFP_ATOMIC
);
1452 memset(data
, 0, sizeof(*data
));
1453 data
->ct
.req
= &data
->req
;
1454 data
->ct
.resp
= &data
->resp
;
1455 data
->ct
.req_count
= data
->ct
.resp_count
= 1;
1456 zfcp_address_to_sg(&data
->ct_iu_req
, &data
->req
);
1457 zfcp_address_to_sg(&data
->ct_iu_resp
, &data
->resp
);
1458 data
->req
.length
= sizeof(struct ct_iu_gid_pn_req
);
1459 data
->resp
.length
= sizeof(struct ct_iu_gid_pn_resp
);
1466 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1467 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1470 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data
*gid_pn
)
1472 if ((gid_pn
->ct
.pool
!= 0))
1473 mempool_free(gid_pn
, gid_pn
->ct
.pool
);
1481 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1482 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1485 zfcp_ns_gid_pn_request(struct zfcp_erp_action
*erp_action
)
1488 struct ct_iu_gid_pn_req
*ct_iu_req
;
1489 struct zfcp_gid_pn_data
*gid_pn
;
1490 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1492 ret
= zfcp_gid_pn_buffers_alloc(&gid_pn
, adapter
->pool
.data_gid_pn
);
1494 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1495 "request failed for adapter %s\n",
1496 zfcp_get_busid_by_adapter(adapter
));
1500 /* setup nameserver request */
1501 ct_iu_req
= zfcp_sg_to_address(gid_pn
->ct
.req
);
1502 ct_iu_req
->header
.revision
= ZFCP_CT_REVISION
;
1503 ct_iu_req
->header
.gs_type
= ZFCP_CT_DIRECTORY_SERVICE
;
1504 ct_iu_req
->header
.gs_subtype
= ZFCP_CT_NAME_SERVER
;
1505 ct_iu_req
->header
.options
= ZFCP_CT_SYNCHRONOUS
;
1506 ct_iu_req
->header
.cmd_rsp_code
= ZFCP_CT_GID_PN
;
1507 ct_iu_req
->header
.max_res_size
= ZFCP_CT_MAX_SIZE
;
1508 ct_iu_req
->wwpn
= erp_action
->port
->wwpn
;
1510 /* setup parameters for send generic command */
1511 gid_pn
->ct
.port
= adapter
->nameserver_port
;
1512 gid_pn
->ct
.handler
= zfcp_ns_gid_pn_handler
;
1513 gid_pn
->ct
.handler_data
= (unsigned long) gid_pn
;
1514 gid_pn
->ct
.timeout
= ZFCP_NS_GID_PN_TIMEOUT
;
1515 gid_pn
->ct
.timer
= &erp_action
->timer
;
1516 gid_pn
->port
= erp_action
->port
;
1518 ret
= zfcp_fsf_send_ct(&gid_pn
->ct
, adapter
->pool
.fsf_req_erp
,
1521 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1522 "failed for adapter %s\n",
1523 zfcp_get_busid_by_adapter(adapter
));
1525 zfcp_gid_pn_buffers_free(gid_pn
);
1533 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1534 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1536 static void zfcp_ns_gid_pn_handler(unsigned long data
)
1538 struct zfcp_port
*port
;
1539 struct zfcp_send_ct
*ct
;
1540 struct ct_iu_gid_pn_req
*ct_iu_req
;
1541 struct ct_iu_gid_pn_resp
*ct_iu_resp
;
1542 struct zfcp_gid_pn_data
*gid_pn
;
1545 gid_pn
= (struct zfcp_gid_pn_data
*) data
;
1546 port
= gid_pn
->port
;
1548 ct_iu_req
= zfcp_sg_to_address(ct
->req
);
1549 ct_iu_resp
= zfcp_sg_to_address(ct
->resp
);
1551 if (ct
->status
!= 0)
1554 if (zfcp_check_ct_response(&ct_iu_resp
->header
)) {
1555 /* FIXME: do we need some specific erp entry points */
1556 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN
, &port
->status
);
1560 if (ct_iu_req
->wwpn
!= port
->wwpn
) {
1561 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1562 "lookup does not match expected wwpn 0x%016Lx "
1563 "for adapter %s\n", ct_iu_req
->wwpn
, port
->wwpn
,
1564 zfcp_get_busid_by_port(port
));
1568 /* looks like a valid d_id */
1569 port
->d_id
= ct_iu_resp
->d_id
& ZFCP_DID_MASK
;
1570 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID
, &port
->status
);
1571 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1572 zfcp_get_busid_by_port(port
), port
->wwpn
, port
->d_id
);
1576 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1577 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_req
,
1578 sizeof(struct ct_iu_gid_pn_req
));
1579 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_resp
,
1580 sizeof(struct ct_iu_gid_pn_resp
));
1583 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1584 "0x%016Lx for adapter %s\n",
1585 port
->wwpn
, zfcp_get_busid_by_port(port
));
1587 zfcp_gid_pn_buffers_free(gid_pn
);
1591 /* reject CT_IU reason codes acc. to FC-GS-4 */
1592 static const struct zfcp_rc_entry zfcp_ct_rc
[] = {
1593 {0x01, "invalid command code"},
1594 {0x02, "invalid version level"},
1595 {0x03, "logical error"},
1596 {0x04, "invalid CT_IU size"},
1597 {0x05, "logical busy"},
1598 {0x07, "protocol error"},
1599 {0x09, "unable to perform command request"},
1600 {0x0b, "command not supported"},
1601 {0x0d, "server not available"},
1602 {0x0e, "session could not be established"},
1603 {0xff, "vendor specific error"},
1607 /* LS_RJT reason codes acc. to FC-FS */
1608 static const struct zfcp_rc_entry zfcp_ls_rjt_rc
[] = {
1609 {0x01, "invalid LS_Command code"},
1610 {0x03, "logical error"},
1611 {0x05, "logical busy"},
1612 {0x07, "protocol error"},
1613 {0x09, "unable to perform command request"},
1614 {0x0b, "command not supported"},
1615 {0x0e, "command already in progress"},
1616 {0xff, "vendor specific error"},
1620 /* reject reason codes according to FC-PH/FC-FS */
1621 static const struct zfcp_rc_entry zfcp_p_rjt_rc
[] = {
1622 {0x01, "invalid D_ID"},
1623 {0x02, "invalid S_ID"},
1624 {0x03, "Nx_Port not available, temporary"},
1625 {0x04, "Nx_Port not available, permament"},
1626 {0x05, "class not supported"},
1627 {0x06, "delimiter usage error"},
1628 {0x07, "TYPE not supported"},
1629 {0x08, "invalid Link_Control"},
1630 {0x09, "invalid R_CTL field"},
1631 {0x0a, "invalid F_CTL field"},
1632 {0x0b, "invalid OX_ID"},
1633 {0x0c, "invalid RX_ID"},
1634 {0x0d, "invalid SEQ_ID"},
1635 {0x0e, "invalid DF_CTL"},
1636 {0x0f, "invalid SEQ_CNT"},
1637 {0x10, "invalid parameter field"},
1638 {0x11, "exchange error"},
1639 {0x12, "protocol error"},
1640 {0x13, "incorrect length"},
1641 {0x14, "unsupported ACK"},
1642 {0x15, "class of service not supported by entity at FFFFFE"},
1643 {0x16, "login required"},
1644 {0x17, "excessive sequences attempted"},
1645 {0x18, "unable to establish exchange"},
1646 {0x1a, "fabric path not available"},
1647 {0x1b, "invalid VC_ID (class 4)"},
1648 {0x1c, "invalid CS_CTL field"},
1649 {0x1d, "insufficient resources for VC (class 4)"},
1650 {0x1f, "invalid class of service"},
1651 {0x20, "preemption request rejected"},
1652 {0x21, "preemption not enabled"},
1653 {0x22, "multicast error"},
1654 {0x23, "multicast error terminate"},
1655 {0x24, "process login required"},
1656 {0xff, "vendor specific reject"},
1661 * zfcp_rc_description - return description for given reaon code
1662 * @code: reason code
1663 * @rc_table: table of reason codes and descriptions
1665 static inline const char *
1666 zfcp_rc_description(u8 code
, const struct zfcp_rc_entry
*rc_table
)
1668 const char *descr
= "unknown reason code";
1671 if (code
== rc_table
->code
) {
1672 descr
= rc_table
->description
;
1676 } while (rc_table
->code
&& rc_table
->description
);
1682 * zfcp_check_ct_response - evaluate reason code for CT_IU
1683 * @rjt: response payload to an CT_IU request
1684 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1687 zfcp_check_ct_response(struct ct_hdr
*rjt
)
1689 if (rjt
->cmd_rsp_code
== ZFCP_CT_ACCEPT
)
1692 if (rjt
->cmd_rsp_code
!= ZFCP_CT_REJECT
) {
1693 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1694 "response code (0x%04hx)\n",
1699 ZFCP_LOG_INFO("Generic Service command rejected\n");
1700 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1701 zfcp_rc_description(rjt
->reason_code
, zfcp_ct_rc
),
1702 (u32
) rjt
->reason_code
, (u32
) rjt
->reason_code_expl
,
1703 (u32
) rjt
->vendor_unique
);
1709 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1710 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1711 * @rc_table: table of reason codes and descriptions
1714 zfcp_print_els_rjt(struct zfcp_ls_rjt_par
*rjt_par
,
1715 const struct zfcp_rc_entry
*rc_table
)
1717 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1718 zfcp_rc_description(rjt_par
->reason_code
, rc_table
),
1719 (u32
) rjt_par
->action
, (u32
) rjt_par
->reason_code
,
1720 (u32
) rjt_par
->reason_expl
, (u32
) rjt_par
->vendor_unique
);
1724 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1725 * @sq: status qualifier word
1726 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1727 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1730 zfcp_handle_els_rjt(u32 sq
, struct zfcp_ls_rjt_par
*rjt_par
)
1734 if (sq
== FSF_IOSTAT_NPORT_RJT
) {
1735 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1736 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1738 if (rjt_par
->reason_code
== 0x01)
1740 } else if (sq
== FSF_IOSTAT_FABRIC_RJT
) {
1741 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1742 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1744 if (rjt_par
->reason_code
== 0x01)
1746 } else if (sq
== FSF_IOSTAT_LS_RJT
) {
1747 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1748 zfcp_print_els_rjt(rjt_par
, zfcp_ls_rjt_rc
);
1751 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq
);
1756 #undef ZFCP_LOG_AREA