3 * linux/drivers/s390/scsi/zfcp_aux.c
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #define ZFCP_AUX_REVISION "$Revision: 1.145 $"
36 /* accumulated log level (module parameter) */
37 static u32 loglevel
= ZFCP_LOG_LEVEL_DEFAULTS
;
39 /*********************** FUNCTION PROTOTYPES *********************************/
41 /* written against the module interface */
42 static int __init
zfcp_module_init(void);
45 static void zfcp_ns_gid_pn_handler(unsigned long);
48 static inline int zfcp_sg_list_alloc(struct zfcp_sg_list
*, size_t);
49 static inline void zfcp_sg_list_free(struct zfcp_sg_list
*);
50 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*,
51 void __user
*, size_t);
52 static inline int zfcp_sg_list_copy_to_user(void __user
*,
53 struct zfcp_sg_list
*, size_t);
55 static long zfcp_cfdc_dev_ioctl(struct file
*, unsigned int, unsigned long);
57 #define ZFCP_CFDC_IOC_MAGIC 0xDD
58 #define ZFCP_CFDC_IOC \
59 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
62 static struct file_operations zfcp_cfdc_fops
= {
63 .unlocked_ioctl
= zfcp_cfdc_dev_ioctl
,
65 .compat_ioctl
= zfcp_cfdc_dev_ioctl
69 static struct miscdevice zfcp_cfdc_misc
= {
70 .minor
= ZFCP_CFDC_DEV_MINOR
,
71 .name
= ZFCP_CFDC_DEV_NAME
,
72 .fops
= &zfcp_cfdc_fops
75 /*********************** KERNEL/MODULE PARAMETERS ***************************/
77 /* declare driver module init/cleanup functions */
78 module_init(zfcp_module_init
);
80 MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, "
81 "Andreas Herrman <aherrman@de.ibm.com>, "
82 "Martin Peschke <mpeschke@de.ibm.com>, "
83 "Raimund Schroeder <raimund.schroeder@de.ibm.com>, "
84 "Wolfgang Taphorn <taphorn@de.ibm.com>, "
85 "Aron Zeh <arzeh@de.ibm.com>, "
86 "IBM Deutschland Entwicklung GmbH");
88 ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries");
89 MODULE_LICENSE("GPL");
91 module_param(device
, charp
, 0400);
92 MODULE_PARM_DESC(device
, "specify initial device");
94 module_param(loglevel
, uint
, 0400);
95 MODULE_PARM_DESC(loglevel
,
96 "log levels, 8 nibbles: "
97 "FC ERP QDIO CIO Config FSF SCSI Other, "
98 "levels: 0=none 1=normal 2=devel 3=trace");
100 /****************************************************************/
101 /************** Functions without logging ***********************/
102 /****************************************************************/
105 _zfcp_hex_dump(char *addr
, int count
)
108 for (i
= 0; i
< count
; i
++) {
109 printk("%02x", addr
[i
]);
115 if (((i
-1) % 32) != 31)
119 /****************************************************************/
120 /************** Uncategorised Functions *************************/
121 /****************************************************************/
123 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
126 * zfcp_device_setup - setup function
127 * @str: pointer to parameter string
129 * Parse "device=..." parameter string.
132 zfcp_device_setup(char *devstr
)
140 len
= strlen(devstr
) + 1;
141 str
= (char *) kmalloc(len
, GFP_KERNEL
);
144 memcpy(str
, devstr
, len
);
146 tmp
= strchr(str
, ',');
150 strncpy(zfcp_data
.init_busid
, str
, BUS_ID_SIZE
);
151 zfcp_data
.init_busid
[BUS_ID_SIZE
-1] = '\0';
153 zfcp_data
.init_wwpn
= simple_strtoull(tmp
, &tmp
, 0);
159 zfcp_data
.init_fcp_lun
= simple_strtoull(tmp
, &tmp
, 0);
166 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str
);
172 zfcp_init_device_configure(void)
174 struct zfcp_adapter
*adapter
;
175 struct zfcp_port
*port
;
176 struct zfcp_unit
*unit
;
178 down(&zfcp_data
.config_sema
);
179 read_lock_irq(&zfcp_data
.config_lock
);
180 adapter
= zfcp_get_adapter_by_busid(zfcp_data
.init_busid
);
182 zfcp_adapter_get(adapter
);
183 read_unlock_irq(&zfcp_data
.config_lock
);
187 port
= zfcp_port_enqueue(adapter
, zfcp_data
.init_wwpn
, 0, 0);
190 unit
= zfcp_unit_enqueue(port
, zfcp_data
.init_fcp_lun
);
193 up(&zfcp_data
.config_sema
);
194 ccw_device_set_online(adapter
->ccw_device
);
195 zfcp_erp_wait(adapter
);
196 down(&zfcp_data
.config_sema
);
201 zfcp_adapter_put(adapter
);
203 up(&zfcp_data
.config_sema
);
208 zfcp_module_init(void)
213 atomic_set(&zfcp_data
.loglevel
, loglevel
);
215 /* initialize adapter list */
216 INIT_LIST_HEAD(&zfcp_data
.adapter_list_head
);
218 /* initialize adapters to be removed list head */
219 INIT_LIST_HEAD(&zfcp_data
.adapter_remove_lh
);
221 zfcp_transport_template
= fc_attach_transport(&zfcp_transport_functions
);
222 if (!zfcp_transport_template
)
225 retval
= misc_register(&zfcp_cfdc_misc
);
227 ZFCP_LOG_INFO("registration of misc device "
228 "zfcp_cfdc failed\n");
232 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
233 ZFCP_CFDC_DEV_MAJOR
, zfcp_cfdc_misc
.minor
);
235 /* Initialise proc semaphores */
236 sema_init(&zfcp_data
.config_sema
, 1);
238 /* initialise configuration rw lock */
239 rwlock_init(&zfcp_data
.config_lock
);
241 /* save address of data structure managing the driver module */
242 zfcp_data
.scsi_host_template
.module
= THIS_MODULE
;
244 /* setup dynamic I/O */
245 retval
= zfcp_ccw_register();
247 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
248 goto out_ccw_register
;
251 if (zfcp_device_setup(device
))
252 zfcp_init_device_configure();
257 misc_deregister(&zfcp_cfdc_misc
);
263 * function: zfcp_cfdc_dev_ioctl
265 * purpose: Handle control file upload/download transaction via IOCTL
268 * returns: 0 - Operation completed successfuly
269 * -ENOTTY - Unknown IOCTL command
270 * -EINVAL - Invalid sense data record
271 * -ENXIO - The FCP adapter is not available
272 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
273 * -ENOMEM - Insufficient memory
274 * -EFAULT - User space memory I/O operation fault
275 * -EPERM - Cannot create or queue FSF request or create SBALs
276 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
279 zfcp_cfdc_dev_ioctl(struct file
*file
, unsigned int command
,
280 unsigned long buffer
)
282 struct zfcp_cfdc_sense_data
*sense_data
, __user
*sense_data_user
;
283 struct zfcp_adapter
*adapter
= NULL
;
284 struct zfcp_fsf_req
*fsf_req
= NULL
;
285 struct zfcp_sg_list
*sg_list
= NULL
;
286 u32 fsf_command
, option
;
290 sense_data
= kmalloc(sizeof(struct zfcp_cfdc_sense_data
), GFP_KERNEL
);
291 if (sense_data
== NULL
) {
296 sg_list
= kmalloc(sizeof(struct zfcp_sg_list
), GFP_KERNEL
);
297 if (sg_list
== NULL
) {
301 memset(sg_list
, 0, sizeof(*sg_list
));
303 if (command
!= ZFCP_CFDC_IOC
) {
304 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command
);
309 if ((sense_data_user
= (void __user
*) buffer
) == NULL
) {
310 ZFCP_LOG_INFO("sense data record is required\n");
315 retval
= copy_from_user(sense_data
, sense_data_user
,
316 sizeof(struct zfcp_cfdc_sense_data
));
322 if (sense_data
->signature
!= ZFCP_CFDC_SIGNATURE
) {
323 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
324 ZFCP_CFDC_SIGNATURE
);
329 switch (sense_data
->command
) {
331 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL
:
332 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
333 option
= FSF_CFDC_OPTION_NORMAL_MODE
;
336 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE
:
337 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
338 option
= FSF_CFDC_OPTION_FORCE
;
341 case ZFCP_CFDC_CMND_FULL_ACCESS
:
342 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
343 option
= FSF_CFDC_OPTION_FULL_ACCESS
;
346 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS
:
347 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
348 option
= FSF_CFDC_OPTION_RESTRICTED_ACCESS
;
351 case ZFCP_CFDC_CMND_UPLOAD
:
352 fsf_command
= FSF_QTCB_UPLOAD_CONTROL_FILE
;
357 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
358 sense_data
->command
);
363 bus_id
= kmalloc(BUS_ID_SIZE
, GFP_KERNEL
);
364 if (bus_id
== NULL
) {
368 snprintf(bus_id
, BUS_ID_SIZE
, "%d.%d.%04x",
369 (sense_data
->devno
>> 24),
370 (sense_data
->devno
>> 16) & 0xFF,
371 (sense_data
->devno
& 0xFFFF));
373 read_lock_irq(&zfcp_data
.config_lock
);
374 adapter
= zfcp_get_adapter_by_busid(bus_id
);
376 zfcp_adapter_get(adapter
);
377 read_unlock_irq(&zfcp_data
.config_lock
);
381 if (adapter
== NULL
) {
382 ZFCP_LOG_INFO("invalid adapter\n");
387 if (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
) {
388 retval
= zfcp_sg_list_alloc(sg_list
,
389 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
396 if ((sense_data
->command
& ZFCP_CFDC_DOWNLOAD
) &&
397 (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
)) {
398 retval
= zfcp_sg_list_copy_from_user(
399 sg_list
, &sense_data_user
->control_file
,
400 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
407 retval
= zfcp_fsf_control_file(adapter
, &fsf_req
, fsf_command
,
412 if ((fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_GOOD
) &&
413 (fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_FSF_STATUS_PRESENTED
)) {
418 sense_data
->fsf_status
= fsf_req
->qtcb
->header
.fsf_status
;
419 memcpy(&sense_data
->fsf_status_qual
,
420 &fsf_req
->qtcb
->header
.fsf_status_qual
,
421 sizeof(union fsf_status_qual
));
422 memcpy(&sense_data
->payloads
, &fsf_req
->qtcb
->bottom
.support
.els
, 256);
424 retval
= copy_to_user(sense_data_user
, sense_data
,
425 sizeof(struct zfcp_cfdc_sense_data
));
431 if (sense_data
->command
& ZFCP_CFDC_UPLOAD
) {
432 retval
= zfcp_sg_list_copy_to_user(
433 &sense_data_user
->control_file
, sg_list
,
434 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
443 zfcp_fsf_req_free(fsf_req
);
445 if ((adapter
!= NULL
) && (retval
!= -ENXIO
))
446 zfcp_adapter_put(adapter
);
448 if (sg_list
!= NULL
) {
449 zfcp_sg_list_free(sg_list
);
460 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
461 * @sg_list: structure describing a scatter gather list
462 * @size: size of scatter-gather list
463 * Return: 0 on success, else -ENOMEM
465 * In sg_list->sg a pointer to the created scatter-gather list is returned,
466 * or NULL if we run out of memory. sg_list->count specifies the number of
467 * elements of the scatter-gather list. The maximum size of a single element
468 * in the scatter-gather list is PAGE_SIZE.
471 zfcp_sg_list_alloc(struct zfcp_sg_list
*sg_list
, size_t size
)
473 struct scatterlist
*sg
;
478 BUG_ON(sg_list
== NULL
);
480 sg_list
->count
= size
>> PAGE_SHIFT
;
481 if (size
& ~PAGE_MASK
)
483 sg_list
->sg
= kmalloc(sg_list
->count
* sizeof(struct scatterlist
),
485 if (sg_list
->sg
== NULL
) {
490 memset(sg_list
->sg
, 0, sg_list
->count
* sizeof(struct scatterlist
));
492 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++) {
493 sg
->length
= min(size
, PAGE_SIZE
);
495 address
= (void *) get_zeroed_page(GFP_KERNEL
);
496 if (address
== NULL
) {
498 zfcp_sg_list_free(sg_list
);
502 zfcp_address_to_sg(address
, sg
);
512 * zfcp_sg_list_free - free memory of a scatter-gather list
513 * @sg_list: structure describing a scatter-gather list
515 * Memory for each element in the scatter-gather list is freed.
516 * Finally sg_list->sg is freed itself and sg_list->count is reset.
519 zfcp_sg_list_free(struct zfcp_sg_list
*sg_list
)
521 struct scatterlist
*sg
;
524 BUG_ON(sg_list
== NULL
);
526 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++)
527 free_page((unsigned long) zfcp_sg_to_address(sg
));
534 * zfcp_sg_size - determine size of a scatter-gather list
535 * @sg: array of (struct scatterlist)
536 * @sg_count: elements in array
537 * Return: size of entire scatter-gather list
540 zfcp_sg_size(struct scatterlist
*sg
, unsigned int sg_count
)
543 struct scatterlist
*p
;
547 for (i
= 0, p
= sg
; i
< sg_count
; i
++, p
++) {
557 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
558 * @sg_list: structure describing a scatter-gather list
559 * @user_buffer: pointer to buffer in user space
560 * @size: number of bytes to be copied
561 * Return: 0 on success, -EFAULT if copy_from_user fails.
564 zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*sg_list
,
565 void __user
*user_buffer
,
568 struct scatterlist
*sg
;
573 BUG_ON(sg_list
== NULL
);
575 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
578 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
579 length
= min((unsigned int)size
, sg
->length
);
580 zfcp_buffer
= zfcp_sg_to_address(sg
);
581 if (copy_from_user(zfcp_buffer
, user_buffer
, length
)) {
585 user_buffer
+= length
;
595 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
596 * @user_buffer: pointer to buffer in user space
597 * @sg_list: structure describing a scatter-gather list
598 * @size: number of bytes to be copied
599 * Return: 0 on success, -EFAULT if copy_to_user fails
602 zfcp_sg_list_copy_to_user(void __user
*user_buffer
,
603 struct zfcp_sg_list
*sg_list
,
606 struct scatterlist
*sg
;
611 BUG_ON(sg_list
== NULL
);
613 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
616 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
617 length
= min((unsigned int) size
, sg
->length
);
618 zfcp_buffer
= zfcp_sg_to_address(sg
);
619 if (copy_to_user(user_buffer
, zfcp_buffer
, length
)) {
623 user_buffer
+= length
;
634 /****************************************************************/
635 /****** Functions for configuration/set-up of structures ********/
636 /****************************************************************/
638 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
641 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
642 * @port: pointer to port to search for unit
643 * @fcp_lun: FCP LUN to search for
644 * Traverse list of all units of a port and return pointer to a unit
645 * with the given FCP LUN.
648 zfcp_get_unit_by_lun(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
650 struct zfcp_unit
*unit
;
653 list_for_each_entry(unit
, &port
->unit_list_head
, list
) {
654 if ((unit
->fcp_lun
== fcp_lun
) &&
655 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
))
661 return found
? unit
: NULL
;
665 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
666 * @adapter: pointer to adapter to search for port
667 * @wwpn: wwpn to search for
668 * Traverse list of all ports of an adapter and return pointer to a port
669 * with the given wwpn.
672 zfcp_get_port_by_wwpn(struct zfcp_adapter
*adapter
, wwn_t wwpn
)
674 struct zfcp_port
*port
;
677 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
678 if ((port
->wwpn
== wwpn
) &&
679 !(atomic_read(&port
->status
) &
680 (ZFCP_STATUS_PORT_NO_WWPN
| ZFCP_STATUS_COMMON_REMOVE
))) {
685 return found
? port
: NULL
;
689 * zfcp_get_port_by_did - find port in port list of adapter by d_id
690 * @adapter: pointer to adapter to search for port
691 * @d_id: d_id to search for
692 * Traverse list of all ports of an adapter and return pointer to a port
693 * with the given d_id.
696 zfcp_get_port_by_did(struct zfcp_adapter
*adapter
, u32 d_id
)
698 struct zfcp_port
*port
;
701 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
702 if ((port
->d_id
== d_id
) &&
703 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
))
709 return found
? port
: NULL
;
713 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
714 * @bus_id: bus_id to search for
715 * Traverse list of all adapters and return pointer to an adapter
716 * with the given bus_id.
718 struct zfcp_adapter
*
719 zfcp_get_adapter_by_busid(char *bus_id
)
721 struct zfcp_adapter
*adapter
;
724 list_for_each_entry(adapter
, &zfcp_data
.adapter_list_head
, list
) {
725 if ((strncmp(bus_id
, zfcp_get_busid_by_adapter(adapter
),
726 BUS_ID_SIZE
) == 0) &&
727 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
,
733 return found
? adapter
: NULL
;
737 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
738 * @port: pointer to port where unit is added
739 * @fcp_lun: FCP LUN of unit to be enqueued
740 * Return: pointer to enqueued unit on success, NULL on error
741 * Locks: config_sema must be held to serialize changes to the unit list
743 * Sets up some unit internal structures and creates sysfs entry.
746 zfcp_unit_enqueue(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
748 struct zfcp_unit
*unit
, *tmp_unit
;
753 * check that there is no unit with this FCP_LUN already in list
755 * Note: Unlike for the adapter and the port, this is an error
757 read_lock_irq(&zfcp_data
.config_lock
);
758 unit
= zfcp_get_unit_by_lun(port
, fcp_lun
);
759 read_unlock_irq(&zfcp_data
.config_lock
);
763 unit
= kmalloc(sizeof (struct zfcp_unit
), GFP_KERNEL
);
766 memset(unit
, 0, sizeof (struct zfcp_unit
));
768 /* initialise reference count stuff */
769 atomic_set(&unit
->refcount
, 0);
770 init_waitqueue_head(&unit
->remove_wq
);
773 unit
->fcp_lun
= fcp_lun
;
775 /* setup for sysfs registration */
776 snprintf(unit
->sysfs_device
.bus_id
, BUS_ID_SIZE
, "0x%016llx", fcp_lun
);
777 unit
->sysfs_device
.parent
= &port
->sysfs_device
;
778 unit
->sysfs_device
.release
= zfcp_sysfs_unit_release
;
779 dev_set_drvdata(&unit
->sysfs_device
, unit
);
781 /* mark unit unusable as long as sysfs registration is not complete */
782 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
784 if (device_register(&unit
->sysfs_device
)) {
789 if (zfcp_sysfs_unit_create_files(&unit
->sysfs_device
)) {
790 device_unregister(&unit
->sysfs_device
);
798 write_lock_irq(&zfcp_data
.config_lock
);
799 list_for_each_entry(tmp_unit
, &port
->unit_list_head
, list
) {
800 if (tmp_unit
->scsi_lun
!= scsi_lun
) {
806 unit
->scsi_lun
= scsi_lun
;
808 list_add_tail(&unit
->list
, &tmp_unit
->list
);
810 list_add_tail(&unit
->list
, &port
->unit_list_head
);
811 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
812 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &unit
->status
);
813 write_unlock_irq(&zfcp_data
.config_lock
);
822 zfcp_unit_dequeue(struct zfcp_unit
*unit
)
824 zfcp_unit_wait(unit
);
825 write_lock_irq(&zfcp_data
.config_lock
);
826 list_del(&unit
->list
);
827 write_unlock_irq(&zfcp_data
.config_lock
);
829 zfcp_port_put(unit
->port
);
830 zfcp_sysfs_unit_remove_files(&unit
->sysfs_device
);
831 device_unregister(&unit
->sysfs_device
);
835 zfcp_mempool_alloc(gfp_t gfp_mask
, void *size
)
837 return kmalloc((size_t) size
, gfp_mask
);
841 zfcp_mempool_free(void *element
, void *size
)
847 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
849 * It also genrates fcp-nameserver request/response buffer and unsolicited
850 * status read fsf_req buffers.
852 * locks: must only be called with zfcp_data.config_sema taken
855 zfcp_allocate_low_mem_buffers(struct zfcp_adapter
*adapter
)
857 adapter
->pool
.fsf_req_erp
=
858 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR
,
859 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
860 sizeof(struct zfcp_fsf_req_pool_element
));
862 if (NULL
== adapter
->pool
.fsf_req_erp
)
865 adapter
->pool
.fsf_req_scsi
=
866 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR
,
867 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
868 sizeof(struct zfcp_fsf_req_pool_element
));
870 if (NULL
== adapter
->pool
.fsf_req_scsi
)
873 adapter
->pool
.fsf_req_abort
=
874 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR
,
875 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
876 sizeof(struct zfcp_fsf_req_pool_element
));
878 if (NULL
== adapter
->pool
.fsf_req_abort
)
881 adapter
->pool
.fsf_req_status_read
=
882 mempool_create(ZFCP_POOL_STATUS_READ_NR
,
883 zfcp_mempool_alloc
, zfcp_mempool_free
,
884 (void *) sizeof(struct zfcp_fsf_req
));
886 if (NULL
== adapter
->pool
.fsf_req_status_read
)
889 adapter
->pool
.data_status_read
=
890 mempool_create(ZFCP_POOL_STATUS_READ_NR
,
891 zfcp_mempool_alloc
, zfcp_mempool_free
,
892 (void *) sizeof(struct fsf_status_read_buffer
));
894 if (NULL
== adapter
->pool
.data_status_read
)
897 adapter
->pool
.data_gid_pn
=
898 mempool_create(ZFCP_POOL_DATA_GID_PN_NR
,
899 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
900 sizeof(struct zfcp_gid_pn_data
));
902 if (NULL
== adapter
->pool
.data_gid_pn
)
909 * zfcp_free_low_mem_buffers - free memory pools of an adapter
910 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
911 * locking: zfcp_data.config_sema must be held
914 zfcp_free_low_mem_buffers(struct zfcp_adapter
*adapter
)
916 if (adapter
->pool
.fsf_req_erp
)
917 mempool_destroy(adapter
->pool
.fsf_req_erp
);
918 if (adapter
->pool
.fsf_req_scsi
)
919 mempool_destroy(adapter
->pool
.fsf_req_scsi
);
920 if (adapter
->pool
.fsf_req_abort
)
921 mempool_destroy(adapter
->pool
.fsf_req_abort
);
922 if (adapter
->pool
.fsf_req_status_read
)
923 mempool_destroy(adapter
->pool
.fsf_req_status_read
);
924 if (adapter
->pool
.data_status_read
)
925 mempool_destroy(adapter
->pool
.data_status_read
);
926 if (adapter
->pool
.data_gid_pn
)
927 mempool_destroy(adapter
->pool
.data_gid_pn
);
931 zfcp_dummy_release(struct device
*dev
)
937 * Enqueues an adapter at the end of the adapter list in the driver data.
938 * All adapter internal structures are set up.
939 * Proc-fs entries are also created.
941 * returns: 0 if a new adapter was successfully enqueued
942 * ZFCP_KNOWN if an adapter with this devno was already present
943 * -ENOMEM if alloc failed
944 * locks: config_sema must be held to serialise changes to the adapter list
946 struct zfcp_adapter
*
947 zfcp_adapter_enqueue(struct ccw_device
*ccw_device
)
950 struct zfcp_adapter
*adapter
;
953 * Note: It is safe to release the list_lock, as any list changes
954 * are protected by the config_sema, which must be held to get here
957 /* try to allocate new adapter data structure (zeroed) */
958 adapter
= kmalloc(sizeof (struct zfcp_adapter
), GFP_KERNEL
);
960 ZFCP_LOG_INFO("error: allocation of base adapter "
961 "structure failed\n");
964 memset(adapter
, 0, sizeof (struct zfcp_adapter
));
966 ccw_device
->handler
= NULL
;
968 /* save ccw_device pointer */
969 adapter
->ccw_device
= ccw_device
;
971 retval
= zfcp_qdio_allocate_queues(adapter
);
973 goto queues_alloc_failed
;
975 retval
= zfcp_qdio_allocate(adapter
);
977 goto qdio_allocate_failed
;
979 retval
= zfcp_allocate_low_mem_buffers(adapter
);
981 ZFCP_LOG_INFO("error: pool allocation failed\n");
982 goto failed_low_mem_buffers
;
985 /* initialise reference count stuff */
986 atomic_set(&adapter
->refcount
, 0);
987 init_waitqueue_head(&adapter
->remove_wq
);
989 /* initialise list of ports */
990 INIT_LIST_HEAD(&adapter
->port_list_head
);
992 /* initialise list of ports to be removed */
993 INIT_LIST_HEAD(&adapter
->port_remove_lh
);
995 /* initialize list of fsf requests */
996 spin_lock_init(&adapter
->fsf_req_list_lock
);
997 INIT_LIST_HEAD(&adapter
->fsf_req_list_head
);
999 /* initialize abort lock */
1000 rwlock_init(&adapter
->abort_lock
);
1002 /* initialise some erp stuff */
1003 init_waitqueue_head(&adapter
->erp_thread_wqh
);
1004 init_waitqueue_head(&adapter
->erp_done_wqh
);
1006 /* initialize lock of associated request queue */
1007 rwlock_init(&adapter
->request_queue
.queue_lock
);
1009 /* intitialise SCSI ER timer */
1010 init_timer(&adapter
->scsi_er_timer
);
1012 /* set FC service class used per default */
1013 adapter
->fc_service_class
= ZFCP_FC_SERVICE_CLASS_DEFAULT
;
1015 sprintf(adapter
->name
, "%s", zfcp_get_busid_by_adapter(adapter
));
1016 ASCEBC(adapter
->name
, strlen(adapter
->name
));
1018 /* mark adapter unusable as long as sysfs registration is not complete */
1019 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1021 adapter
->ccw_device
= ccw_device
;
1022 dev_set_drvdata(&ccw_device
->dev
, adapter
);
1024 if (zfcp_sysfs_adapter_create_files(&ccw_device
->dev
))
1027 adapter
->generic_services
.parent
= &adapter
->ccw_device
->dev
;
1028 adapter
->generic_services
.release
= zfcp_dummy_release
;
1029 snprintf(adapter
->generic_services
.bus_id
, BUS_ID_SIZE
,
1030 "generic_services");
1032 if (device_register(&adapter
->generic_services
))
1033 goto generic_services_failed
;
1035 /* put allocated adapter at list tail */
1036 write_lock_irq(&zfcp_data
.config_lock
);
1037 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1038 list_add_tail(&adapter
->list
, &zfcp_data
.adapter_list_head
);
1039 write_unlock_irq(&zfcp_data
.config_lock
);
1041 zfcp_data
.adapters
++;
1045 generic_services_failed
:
1046 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1048 dev_set_drvdata(&ccw_device
->dev
, NULL
);
1049 failed_low_mem_buffers
:
1050 zfcp_free_low_mem_buffers(adapter
);
1051 if (qdio_free(ccw_device
) != 0)
1052 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1053 zfcp_get_busid_by_adapter(adapter
));
1054 qdio_allocate_failed
:
1055 zfcp_qdio_free_queues(adapter
);
1056 queues_alloc_failed
:
1064 * returns: 0 - struct zfcp_adapter data structure successfully removed
1065 * !0 - struct zfcp_adapter data structure could not be removed
1067 * locks: adapter list write lock is assumed to be held by caller
1068 * adapter->fsf_req_list_lock is taken and released within this
1069 * function and must not be held on entry
1072 zfcp_adapter_dequeue(struct zfcp_adapter
*adapter
)
1075 unsigned long flags
;
1077 device_unregister(&adapter
->generic_services
);
1078 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1079 dev_set_drvdata(&adapter
->ccw_device
->dev
, NULL
);
1080 /* sanity check: no pending FSF requests */
1081 spin_lock_irqsave(&adapter
->fsf_req_list_lock
, flags
);
1082 retval
= !list_empty(&adapter
->fsf_req_list_head
);
1083 spin_unlock_irqrestore(&adapter
->fsf_req_list_lock
, flags
);
1085 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1086 "%i requests outstanding\n",
1087 zfcp_get_busid_by_adapter(adapter
), adapter
,
1088 atomic_read(&adapter
->fsf_reqs_active
));
1093 /* remove specified adapter data structure from list */
1094 write_lock_irq(&zfcp_data
.config_lock
);
1095 list_del(&adapter
->list
);
1096 write_unlock_irq(&zfcp_data
.config_lock
);
1098 /* decrease number of adapters in list */
1099 zfcp_data
.adapters
--;
1101 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1102 "%i adapters still in list\n",
1103 zfcp_get_busid_by_adapter(adapter
),
1104 adapter
, zfcp_data
.adapters
);
1106 retval
= qdio_free(adapter
->ccw_device
);
1108 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1109 zfcp_get_busid_by_adapter(adapter
));
1111 zfcp_free_low_mem_buffers(adapter
);
1112 /* free memory of adapter data structure and queues */
1113 zfcp_qdio_free_queues(adapter
);
1114 ZFCP_LOG_TRACE("freeing adapter structure\n");
1121 * zfcp_port_enqueue - enqueue port to port list of adapter
1122 * @adapter: adapter where remote port is added
1123 * @wwpn: WWPN of the remote port to be enqueued
1124 * @status: initial status for the port
1125 * @d_id: destination id of the remote port to be enqueued
1126 * Return: pointer to enqueued port on success, NULL on error
1127 * Locks: config_sema must be held to serialize changes to the port list
1129 * All port internal structures are set up and the sysfs entry is generated.
1130 * d_id is used to enqueue ports with a well known address like the Directory
1131 * Service for nameserver lookup.
1134 zfcp_port_enqueue(struct zfcp_adapter
*adapter
, wwn_t wwpn
, u32 status
,
1137 struct zfcp_port
*port
;
1140 check_wwpn
= !(status
& ZFCP_STATUS_PORT_NO_WWPN
);
1142 * check that there is no port with this WWPN already in list
1145 read_lock_irq(&zfcp_data
.config_lock
);
1146 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
1147 read_unlock_irq(&zfcp_data
.config_lock
);
1152 port
= kmalloc(sizeof (struct zfcp_port
), GFP_KERNEL
);
1155 memset(port
, 0, sizeof (struct zfcp_port
));
1157 /* initialise reference count stuff */
1158 atomic_set(&port
->refcount
, 0);
1159 init_waitqueue_head(&port
->remove_wq
);
1161 INIT_LIST_HEAD(&port
->unit_list_head
);
1162 INIT_LIST_HEAD(&port
->unit_remove_lh
);
1164 port
->adapter
= adapter
;
1169 atomic_set_mask(status
, &port
->status
);
1171 /* setup for sysfs registration */
1172 if (status
& ZFCP_STATUS_PORT_WKA
) {
1174 case ZFCP_DID_DIRECTORY_SERVICE
:
1175 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1178 case ZFCP_DID_MANAGEMENT_SERVICE
:
1179 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1182 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE
:
1183 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1184 "key_distribution");
1186 case ZFCP_DID_ALIAS_SERVICE
:
1187 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1190 case ZFCP_DID_TIME_SERVICE
:
1191 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1199 port
->sysfs_device
.parent
= &adapter
->generic_services
;
1201 snprintf(port
->sysfs_device
.bus_id
,
1202 BUS_ID_SIZE
, "0x%016llx", wwpn
);
1203 port
->sysfs_device
.parent
= &adapter
->ccw_device
->dev
;
1205 port
->sysfs_device
.release
= zfcp_sysfs_port_release
;
1206 dev_set_drvdata(&port
->sysfs_device
, port
);
1208 /* mark port unusable as long as sysfs registration is not complete */
1209 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1211 if (device_register(&port
->sysfs_device
)) {
1216 if (zfcp_sysfs_port_create_files(&port
->sysfs_device
, status
)) {
1217 device_unregister(&port
->sysfs_device
);
1221 zfcp_port_get(port
);
1223 write_lock_irq(&zfcp_data
.config_lock
);
1224 list_add_tail(&port
->list
, &adapter
->port_list_head
);
1225 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1226 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &port
->status
);
1227 if (d_id
== ZFCP_DID_DIRECTORY_SERVICE
)
1228 if (!adapter
->nameserver_port
)
1229 adapter
->nameserver_port
= port
;
1231 write_unlock_irq(&zfcp_data
.config_lock
);
1233 zfcp_adapter_get(adapter
);
1239 zfcp_port_dequeue(struct zfcp_port
*port
)
1241 zfcp_port_wait(port
);
1242 write_lock_irq(&zfcp_data
.config_lock
);
1243 list_del(&port
->list
);
1244 port
->adapter
->ports
--;
1245 write_unlock_irq(&zfcp_data
.config_lock
);
1247 fc_remote_port_delete(port
->rport
);
1249 zfcp_adapter_put(port
->adapter
);
1250 zfcp_sysfs_port_remove_files(&port
->sysfs_device
,
1251 atomic_read(&port
->status
));
1252 device_unregister(&port
->sysfs_device
);
1255 /* Enqueues a nameserver port */
1257 zfcp_nameserver_enqueue(struct zfcp_adapter
*adapter
)
1259 struct zfcp_port
*port
;
1261 port
= zfcp_port_enqueue(adapter
, 0, ZFCP_STATUS_PORT_WKA
,
1262 ZFCP_DID_DIRECTORY_SERVICE
);
1264 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1265 "adapter %s failed\n",
1266 zfcp_get_busid_by_adapter(adapter
));
1269 zfcp_port_put(port
);
1274 #undef ZFCP_LOG_AREA
1276 /****************************************************************/
1277 /******* Fibre Channel Standard related Functions **************/
1278 /****************************************************************/
1280 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1283 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter
*adapter
,
1284 struct fsf_status_read_buffer
*status_buffer
)
1286 struct fcp_rscn_head
*fcp_rscn_head
;
1287 struct fcp_rscn_element
*fcp_rscn_element
;
1288 struct zfcp_port
*port
;
1292 unsigned long flags
;
1294 fcp_rscn_head
= (struct fcp_rscn_head
*) status_buffer
->payload
;
1295 fcp_rscn_element
= (struct fcp_rscn_element
*) status_buffer
->payload
;
1298 no_entries
= (fcp_rscn_head
->payload_len
/ 4);
1300 for (i
= 1; i
< no_entries
; i
++) {
1301 /* skip head and start with 1st element */
1303 switch (fcp_rscn_element
->addr_format
) {
1304 case ZFCP_PORT_ADDRESS
:
1305 range_mask
= ZFCP_PORTS_RANGE_PORT
;
1307 case ZFCP_AREA_ADDRESS
:
1308 range_mask
= ZFCP_PORTS_RANGE_AREA
;
1310 case ZFCP_DOMAIN_ADDRESS
:
1311 range_mask
= ZFCP_PORTS_RANGE_DOMAIN
;
1313 case ZFCP_FABRIC_ADDRESS
:
1314 range_mask
= ZFCP_PORTS_RANGE_FABRIC
;
1317 ZFCP_LOG_INFO("incoming RSCN with unknown "
1318 "address format\n");
1321 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1322 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1323 if (atomic_test_mask
1324 (ZFCP_STATUS_PORT_WKA
, &port
->status
))
1326 /* Do we know this port? If not skip it. */
1327 if (!atomic_test_mask
1328 (ZFCP_STATUS_PORT_DID_DID
, &port
->status
)) {
1329 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1330 "port 0x%016Lx\n", port
->wwpn
);
1331 zfcp_erp_port_reopen(port
,
1332 ZFCP_STATUS_COMMON_ERP_FAILED
);
1337 * FIXME: race: d_id might being invalidated
1338 * (...DID_DID reset)
1340 if ((port
->d_id
& range_mask
)
1341 == (fcp_rscn_element
->nport_did
& range_mask
)) {
1342 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1343 fcp_rscn_element
->nport_did
);
1345 * Unfortunately, an RSCN does not specify the
1346 * type of change a target underwent. We assume
1347 * that it makes sense to reopen the link.
1348 * FIXME: Shall we try to find out more about
1349 * the target and link state before closing it?
1350 * How to accomplish this? (nameserver?)
1351 * Where would such code be put in?
1352 * (inside or outside erp)
1354 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1355 "port 0x%016Lx\n", port
->wwpn
);
1356 zfcp_test_link(port
);
1359 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1364 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter
*adapter
,
1365 struct fsf_status_read_buffer
*status_buffer
)
1367 logi
*els_logi
= (logi
*) status_buffer
->payload
;
1368 struct zfcp_port
*port
;
1369 unsigned long flags
;
1371 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1372 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1373 if (port
->wwpn
== (*(wwn_t
*) & els_logi
->nport_wwn
))
1376 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1378 if (!port
|| (port
->wwpn
!= (*(wwn_t
*) & els_logi
->nport_wwn
))) {
1379 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1380 "with d_id 0x%08x on adapter %s\n",
1381 status_buffer
->d_id
,
1382 zfcp_get_busid_by_adapter(adapter
));
1384 zfcp_erp_port_forced_reopen(port
, 0);
1389 zfcp_fsf_incoming_els_logo(struct zfcp_adapter
*adapter
,
1390 struct fsf_status_read_buffer
*status_buffer
)
1392 struct fcp_logo
*els_logo
= (struct fcp_logo
*) status_buffer
->payload
;
1393 struct zfcp_port
*port
;
1394 unsigned long flags
;
1396 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1397 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1398 if (port
->wwpn
== els_logo
->nport_wwpn
)
1401 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1403 if (!port
|| (port
->wwpn
!= els_logo
->nport_wwpn
)) {
1404 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1405 "with d_id 0x%08x on adapter %s\n",
1406 status_buffer
->d_id
,
1407 zfcp_get_busid_by_adapter(adapter
));
1409 zfcp_erp_port_forced_reopen(port
, 0);
1414 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter
*adapter
,
1415 struct fsf_status_read_buffer
*status_buffer
)
1417 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1418 "for adapter %s\n", *(u32
*) (status_buffer
->payload
),
1419 zfcp_get_busid_by_adapter(adapter
));
1424 zfcp_fsf_incoming_els(struct zfcp_fsf_req
*fsf_req
)
1426 struct fsf_status_read_buffer
*status_buffer
;
1428 struct zfcp_adapter
*adapter
;
1430 status_buffer
= (struct fsf_status_read_buffer
*) fsf_req
->data
;
1431 els_type
= *(u32
*) (status_buffer
->payload
);
1432 adapter
= fsf_req
->adapter
;
1434 zfcp_san_dbf_event_incoming_els(fsf_req
);
1435 if (els_type
== LS_PLOGI
)
1436 zfcp_fsf_incoming_els_plogi(adapter
, status_buffer
);
1437 else if (els_type
== LS_LOGO
)
1438 zfcp_fsf_incoming_els_logo(adapter
, status_buffer
);
1439 else if ((els_type
& 0xffff0000) == LS_RSCN
)
1440 /* we are only concerned with the command, not the length */
1441 zfcp_fsf_incoming_els_rscn(adapter
, status_buffer
);
1443 zfcp_fsf_incoming_els_unknown(adapter
, status_buffer
);
1448 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1449 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1450 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1453 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data
**gid_pn
, mempool_t
*pool
)
1455 struct zfcp_gid_pn_data
*data
;
1458 data
= mempool_alloc(pool
, GFP_ATOMIC
);
1459 if (likely(data
!= NULL
)) {
1460 data
->ct
.pool
= pool
;
1463 data
= kmalloc(sizeof(struct zfcp_gid_pn_data
), GFP_ATOMIC
);
1469 memset(data
, 0, sizeof(*data
));
1470 data
->ct
.req
= &data
->req
;
1471 data
->ct
.resp
= &data
->resp
;
1472 data
->ct
.req_count
= data
->ct
.resp_count
= 1;
1473 zfcp_address_to_sg(&data
->ct_iu_req
, &data
->req
);
1474 zfcp_address_to_sg(&data
->ct_iu_resp
, &data
->resp
);
1475 data
->req
.length
= sizeof(struct ct_iu_gid_pn_req
);
1476 data
->resp
.length
= sizeof(struct ct_iu_gid_pn_resp
);
1483 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1484 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1487 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data
*gid_pn
)
1489 if ((gid_pn
->ct
.pool
!= 0))
1490 mempool_free(gid_pn
, gid_pn
->ct
.pool
);
1498 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1499 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1502 zfcp_ns_gid_pn_request(struct zfcp_erp_action
*erp_action
)
1505 struct ct_iu_gid_pn_req
*ct_iu_req
;
1506 struct zfcp_gid_pn_data
*gid_pn
;
1507 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1509 ret
= zfcp_gid_pn_buffers_alloc(&gid_pn
, adapter
->pool
.data_gid_pn
);
1511 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1512 "request failed for adapter %s\n",
1513 zfcp_get_busid_by_adapter(adapter
));
1517 /* setup nameserver request */
1518 ct_iu_req
= zfcp_sg_to_address(gid_pn
->ct
.req
);
1519 ct_iu_req
->header
.revision
= ZFCP_CT_REVISION
;
1520 ct_iu_req
->header
.gs_type
= ZFCP_CT_DIRECTORY_SERVICE
;
1521 ct_iu_req
->header
.gs_subtype
= ZFCP_CT_NAME_SERVER
;
1522 ct_iu_req
->header
.options
= ZFCP_CT_SYNCHRONOUS
;
1523 ct_iu_req
->header
.cmd_rsp_code
= ZFCP_CT_GID_PN
;
1524 ct_iu_req
->header
.max_res_size
= ZFCP_CT_MAX_SIZE
;
1525 ct_iu_req
->wwpn
= erp_action
->port
->wwpn
;
1527 /* setup parameters for send generic command */
1528 gid_pn
->ct
.port
= adapter
->nameserver_port
;
1529 gid_pn
->ct
.handler
= zfcp_ns_gid_pn_handler
;
1530 gid_pn
->ct
.handler_data
= (unsigned long) gid_pn
;
1531 gid_pn
->ct
.timeout
= ZFCP_NS_GID_PN_TIMEOUT
;
1532 gid_pn
->ct
.timer
= &erp_action
->timer
;
1533 gid_pn
->port
= erp_action
->port
;
1535 ret
= zfcp_fsf_send_ct(&gid_pn
->ct
, adapter
->pool
.fsf_req_erp
,
1538 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1539 "failed for adapter %s\n",
1540 zfcp_get_busid_by_adapter(adapter
));
1542 zfcp_gid_pn_buffers_free(gid_pn
);
1550 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1551 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1553 static void zfcp_ns_gid_pn_handler(unsigned long data
)
1555 struct zfcp_port
*port
;
1556 struct zfcp_send_ct
*ct
;
1557 struct ct_iu_gid_pn_req
*ct_iu_req
;
1558 struct ct_iu_gid_pn_resp
*ct_iu_resp
;
1559 struct zfcp_gid_pn_data
*gid_pn
;
1562 gid_pn
= (struct zfcp_gid_pn_data
*) data
;
1563 port
= gid_pn
->port
;
1565 ct_iu_req
= zfcp_sg_to_address(ct
->req
);
1566 ct_iu_resp
= zfcp_sg_to_address(ct
->resp
);
1568 if (ct
->status
!= 0)
1571 if (zfcp_check_ct_response(&ct_iu_resp
->header
)) {
1572 /* FIXME: do we need some specific erp entry points */
1573 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN
, &port
->status
);
1577 if (ct_iu_req
->wwpn
!= port
->wwpn
) {
1578 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1579 "lookup does not match expected wwpn 0x%016Lx "
1580 "for adapter %s\n", ct_iu_req
->wwpn
, port
->wwpn
,
1581 zfcp_get_busid_by_port(port
));
1585 /* looks like a valid d_id */
1586 port
->d_id
= ct_iu_resp
->d_id
& ZFCP_DID_MASK
;
1587 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID
, &port
->status
);
1588 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1589 zfcp_get_busid_by_port(port
), port
->wwpn
, port
->d_id
);
1593 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1594 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_req
,
1595 sizeof(struct ct_iu_gid_pn_req
));
1596 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_resp
,
1597 sizeof(struct ct_iu_gid_pn_resp
));
1600 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1601 "0x%016Lx for adapter %s\n",
1602 port
->wwpn
, zfcp_get_busid_by_port(port
));
1604 zfcp_gid_pn_buffers_free(gid_pn
);
1608 /* reject CT_IU reason codes acc. to FC-GS-4 */
1609 static const struct zfcp_rc_entry zfcp_ct_rc
[] = {
1610 {0x01, "invalid command code"},
1611 {0x02, "invalid version level"},
1612 {0x03, "logical error"},
1613 {0x04, "invalid CT_IU size"},
1614 {0x05, "logical busy"},
1615 {0x07, "protocol error"},
1616 {0x09, "unable to perform command request"},
1617 {0x0b, "command not supported"},
1618 {0x0d, "server not available"},
1619 {0x0e, "session could not be established"},
1620 {0xff, "vendor specific error"},
1624 /* LS_RJT reason codes acc. to FC-FS */
1625 static const struct zfcp_rc_entry zfcp_ls_rjt_rc
[] = {
1626 {0x01, "invalid LS_Command code"},
1627 {0x03, "logical error"},
1628 {0x05, "logical busy"},
1629 {0x07, "protocol error"},
1630 {0x09, "unable to perform command request"},
1631 {0x0b, "command not supported"},
1632 {0x0e, "command already in progress"},
1633 {0xff, "vendor specific error"},
1637 /* reject reason codes according to FC-PH/FC-FS */
1638 static const struct zfcp_rc_entry zfcp_p_rjt_rc
[] = {
1639 {0x01, "invalid D_ID"},
1640 {0x02, "invalid S_ID"},
1641 {0x03, "Nx_Port not available, temporary"},
1642 {0x04, "Nx_Port not available, permament"},
1643 {0x05, "class not supported"},
1644 {0x06, "delimiter usage error"},
1645 {0x07, "TYPE not supported"},
1646 {0x08, "invalid Link_Control"},
1647 {0x09, "invalid R_CTL field"},
1648 {0x0a, "invalid F_CTL field"},
1649 {0x0b, "invalid OX_ID"},
1650 {0x0c, "invalid RX_ID"},
1651 {0x0d, "invalid SEQ_ID"},
1652 {0x0e, "invalid DF_CTL"},
1653 {0x0f, "invalid SEQ_CNT"},
1654 {0x10, "invalid parameter field"},
1655 {0x11, "exchange error"},
1656 {0x12, "protocol error"},
1657 {0x13, "incorrect length"},
1658 {0x14, "unsupported ACK"},
1659 {0x15, "class of service not supported by entity at FFFFFE"},
1660 {0x16, "login required"},
1661 {0x17, "excessive sequences attempted"},
1662 {0x18, "unable to establish exchange"},
1663 {0x1a, "fabric path not available"},
1664 {0x1b, "invalid VC_ID (class 4)"},
1665 {0x1c, "invalid CS_CTL field"},
1666 {0x1d, "insufficient resources for VC (class 4)"},
1667 {0x1f, "invalid class of service"},
1668 {0x20, "preemption request rejected"},
1669 {0x21, "preemption not enabled"},
1670 {0x22, "multicast error"},
1671 {0x23, "multicast error terminate"},
1672 {0x24, "process login required"},
1673 {0xff, "vendor specific reject"},
1678 * zfcp_rc_description - return description for given reaon code
1679 * @code: reason code
1680 * @rc_table: table of reason codes and descriptions
1682 static inline const char *
1683 zfcp_rc_description(u8 code
, const struct zfcp_rc_entry
*rc_table
)
1685 const char *descr
= "unknown reason code";
1688 if (code
== rc_table
->code
) {
1689 descr
= rc_table
->description
;
1693 } while (rc_table
->code
&& rc_table
->description
);
1699 * zfcp_check_ct_response - evaluate reason code for CT_IU
1700 * @rjt: response payload to an CT_IU request
1701 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1704 zfcp_check_ct_response(struct ct_hdr
*rjt
)
1706 if (rjt
->cmd_rsp_code
== ZFCP_CT_ACCEPT
)
1709 if (rjt
->cmd_rsp_code
!= ZFCP_CT_REJECT
) {
1710 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1711 "response code (0x%04hx)\n",
1716 ZFCP_LOG_INFO("Generic Service command rejected\n");
1717 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1718 zfcp_rc_description(rjt
->reason_code
, zfcp_ct_rc
),
1719 (u32
) rjt
->reason_code
, (u32
) rjt
->reason_code_expl
,
1720 (u32
) rjt
->vendor_unique
);
1726 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1727 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1728 * @rc_table: table of reason codes and descriptions
1731 zfcp_print_els_rjt(struct zfcp_ls_rjt_par
*rjt_par
,
1732 const struct zfcp_rc_entry
*rc_table
)
1734 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1735 zfcp_rc_description(rjt_par
->reason_code
, rc_table
),
1736 (u32
) rjt_par
->action
, (u32
) rjt_par
->reason_code
,
1737 (u32
) rjt_par
->reason_expl
, (u32
) rjt_par
->vendor_unique
);
1741 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1742 * @sq: status qualifier word
1743 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1744 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1747 zfcp_handle_els_rjt(u32 sq
, struct zfcp_ls_rjt_par
*rjt_par
)
1751 if (sq
== FSF_IOSTAT_NPORT_RJT
) {
1752 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1753 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1755 if (rjt_par
->reason_code
== 0x01)
1757 } else if (sq
== FSF_IOSTAT_FABRIC_RJT
) {
1758 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1759 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1761 if (rjt_par
->reason_code
== 0x01)
1763 } else if (sq
== FSF_IOSTAT_LS_RJT
) {
1764 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1765 zfcp_print_els_rjt(rjt_par
, zfcp_ls_rjt_rc
);
1768 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq
);
1773 #undef ZFCP_LOG_AREA