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 #ifdef ZFCP_PRINT_FLAGS
102 module_param(flags_dump
, uint
, 0);
105 /****************************************************************/
106 /************** Functions without logging ***********************/
107 /****************************************************************/
110 _zfcp_hex_dump(char *addr
, int count
)
113 for (i
= 0; i
< count
; i
++) {
114 printk("%02x", addr
[i
]);
120 if (((i
-1) % 32) != 31)
124 /****************************************************************/
125 /************** Uncategorised Functions *************************/
126 /****************************************************************/
128 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
131 zfcp_fsf_req_is_scsi_cmnd(struct zfcp_fsf_req
*fsf_req
)
133 return ((fsf_req
->fsf_command
== FSF_QTCB_FCP_CMND
) &&
134 !(fsf_req
->status
& ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
));
138 zfcp_cmd_dbf_event_fsf(const char *text
, struct zfcp_fsf_req
*fsf_req
,
139 void *add_data
, int add_length
)
141 struct zfcp_adapter
*adapter
= fsf_req
->adapter
;
142 struct scsi_cmnd
*scsi_cmnd
;
147 spin_lock_irqsave(&adapter
->dbf_lock
, flags
);
148 if (zfcp_fsf_req_is_scsi_cmnd(fsf_req
)) {
149 scsi_cmnd
= fsf_req
->data
.send_fcp_command_task
.scsi_cmnd
;
150 debug_text_event(adapter
->cmd_dbf
, level
, "fsferror");
151 debug_text_event(adapter
->cmd_dbf
, level
, text
);
152 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
,
153 sizeof (unsigned long));
154 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
->seq_no
,
156 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
,
157 sizeof (unsigned long));
158 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
->cmnd
,
159 min(ZFCP_CMD_DBF_LENGTH
, (int)scsi_cmnd
->cmd_len
));
160 for (i
= 0; i
< add_length
; i
+= ZFCP_CMD_DBF_LENGTH
)
161 debug_event(adapter
->cmd_dbf
,
163 (char *) add_data
+ i
,
164 min(ZFCP_CMD_DBF_LENGTH
, add_length
- i
));
166 spin_unlock_irqrestore(&adapter
->dbf_lock
, flags
);
169 /* XXX additionally log unit if available */
170 /* ---> introduce new parameter for unit, see 2.4 code */
172 zfcp_cmd_dbf_event_scsi(const char *text
, struct scsi_cmnd
*scsi_cmnd
)
174 struct zfcp_adapter
*adapter
;
175 union zfcp_req_data
*req_data
;
176 struct zfcp_fsf_req
*fsf_req
;
177 int level
= ((host_byte(scsi_cmnd
->result
) != 0) ? 1 : 5);
180 adapter
= (struct zfcp_adapter
*) scsi_cmnd
->device
->host
->hostdata
[0];
181 req_data
= (union zfcp_req_data
*) scsi_cmnd
->host_scribble
;
182 fsf_req
= (req_data
? req_data
->send_fcp_command_task
.fsf_req
: NULL
);
183 spin_lock_irqsave(&adapter
->dbf_lock
, flags
);
184 debug_text_event(adapter
->cmd_dbf
, level
, "hostbyte");
185 debug_text_event(adapter
->cmd_dbf
, level
, text
);
186 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
->result
, sizeof (u32
));
187 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
,
188 sizeof (unsigned long));
189 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
->cmnd
,
190 min(ZFCP_CMD_DBF_LENGTH
, (int)scsi_cmnd
->cmd_len
));
191 if (likely(fsf_req
)) {
192 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
,
193 sizeof (unsigned long));
194 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
->seq_no
,
197 debug_text_event(adapter
->cmd_dbf
, level
, "");
198 debug_text_event(adapter
->cmd_dbf
, level
, "");
200 spin_unlock_irqrestore(&adapter
->dbf_lock
, flags
);
204 zfcp_in_els_dbf_event(struct zfcp_adapter
*adapter
, const char *text
,
205 struct fsf_status_read_buffer
*status_buffer
, int length
)
210 debug_text_event(adapter
->in_els_dbf
, level
, text
);
211 debug_event(adapter
->in_els_dbf
, level
, &status_buffer
->d_id
, 8);
212 for (i
= 0; i
< length
; i
+= ZFCP_IN_ELS_DBF_LENGTH
)
213 debug_event(adapter
->in_els_dbf
,
215 (char *) status_buffer
->payload
+ i
,
216 min(ZFCP_IN_ELS_DBF_LENGTH
, length
- i
));
220 * zfcp_device_setup - setup function
221 * @str: pointer to parameter string
223 * Parse "device=..." parameter string.
226 zfcp_device_setup(char *str
)
233 tmp
= strchr(str
, ',');
237 strncpy(zfcp_data
.init_busid
, str
, BUS_ID_SIZE
);
238 zfcp_data
.init_busid
[BUS_ID_SIZE
-1] = '\0';
240 zfcp_data
.init_wwpn
= simple_strtoull(tmp
, &tmp
, 0);
246 zfcp_data
.init_fcp_lun
= simple_strtoull(tmp
, &tmp
, 0);
252 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str
);
257 zfcp_init_device_configure(void)
259 struct zfcp_adapter
*adapter
;
260 struct zfcp_port
*port
;
261 struct zfcp_unit
*unit
;
263 down(&zfcp_data
.config_sema
);
264 read_lock_irq(&zfcp_data
.config_lock
);
265 adapter
= zfcp_get_adapter_by_busid(zfcp_data
.init_busid
);
267 zfcp_adapter_get(adapter
);
268 read_unlock_irq(&zfcp_data
.config_lock
);
272 port
= zfcp_port_enqueue(adapter
, zfcp_data
.init_wwpn
, 0, 0);
275 unit
= zfcp_unit_enqueue(port
, zfcp_data
.init_fcp_lun
);
278 up(&zfcp_data
.config_sema
);
279 ccw_device_set_online(adapter
->ccw_device
);
280 zfcp_erp_wait(adapter
);
281 down(&zfcp_data
.config_sema
);
286 zfcp_adapter_put(adapter
);
288 up(&zfcp_data
.config_sema
);
293 zfcp_module_init(void)
298 atomic_set(&zfcp_data
.loglevel
, loglevel
);
300 /* initialize adapter list */
301 INIT_LIST_HEAD(&zfcp_data
.adapter_list_head
);
303 /* initialize adapters to be removed list head */
304 INIT_LIST_HEAD(&zfcp_data
.adapter_remove_lh
);
306 zfcp_transport_template
= fc_attach_transport(&zfcp_transport_functions
);
307 if (!zfcp_transport_template
)
310 retval
= misc_register(&zfcp_cfdc_misc
);
312 ZFCP_LOG_INFO("registration of misc device "
313 "zfcp_cfdc failed\n");
317 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
318 ZFCP_CFDC_DEV_MAJOR
, zfcp_cfdc_misc
.minor
);
320 /* Initialise proc semaphores */
321 sema_init(&zfcp_data
.config_sema
, 1);
323 /* initialise configuration rw lock */
324 rwlock_init(&zfcp_data
.config_lock
);
326 /* save address of data structure managing the driver module */
327 zfcp_data
.scsi_host_template
.module
= THIS_MODULE
;
329 /* setup dynamic I/O */
330 retval
= zfcp_ccw_register();
332 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
333 goto out_ccw_register
;
336 if (zfcp_device_setup(device
))
337 zfcp_init_device_configure();
342 misc_deregister(&zfcp_cfdc_misc
);
348 * function: zfcp_cfdc_dev_ioctl
350 * purpose: Handle control file upload/download transaction via IOCTL
353 * returns: 0 - Operation completed successfuly
354 * -ENOTTY - Unknown IOCTL command
355 * -EINVAL - Invalid sense data record
356 * -ENXIO - The FCP adapter is not available
357 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
358 * -ENOMEM - Insufficient memory
359 * -EFAULT - User space memory I/O operation fault
360 * -EPERM - Cannot create or queue FSF request or create SBALs
361 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
364 zfcp_cfdc_dev_ioctl(struct file
*file
, unsigned int command
,
365 unsigned long buffer
)
367 struct zfcp_cfdc_sense_data
*sense_data
, __user
*sense_data_user
;
368 struct zfcp_adapter
*adapter
= NULL
;
369 struct zfcp_fsf_req
*fsf_req
= NULL
;
370 struct zfcp_sg_list
*sg_list
= NULL
;
371 u32 fsf_command
, option
;
375 sense_data
= kmalloc(sizeof(struct zfcp_cfdc_sense_data
), GFP_KERNEL
);
376 if (sense_data
== NULL
) {
381 sg_list
= kmalloc(sizeof(struct zfcp_sg_list
), GFP_KERNEL
);
382 if (sg_list
== NULL
) {
386 memset(sg_list
, 0, sizeof(*sg_list
));
388 if (command
!= ZFCP_CFDC_IOC
) {
389 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command
);
394 if ((sense_data_user
= (void __user
*) buffer
) == NULL
) {
395 ZFCP_LOG_INFO("sense data record is required\n");
400 retval
= copy_from_user(sense_data
, sense_data_user
,
401 sizeof(struct zfcp_cfdc_sense_data
));
407 if (sense_data
->signature
!= ZFCP_CFDC_SIGNATURE
) {
408 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
409 ZFCP_CFDC_SIGNATURE
);
414 switch (sense_data
->command
) {
416 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL
:
417 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
418 option
= FSF_CFDC_OPTION_NORMAL_MODE
;
421 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE
:
422 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
423 option
= FSF_CFDC_OPTION_FORCE
;
426 case ZFCP_CFDC_CMND_FULL_ACCESS
:
427 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
428 option
= FSF_CFDC_OPTION_FULL_ACCESS
;
431 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS
:
432 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
433 option
= FSF_CFDC_OPTION_RESTRICTED_ACCESS
;
436 case ZFCP_CFDC_CMND_UPLOAD
:
437 fsf_command
= FSF_QTCB_UPLOAD_CONTROL_FILE
;
442 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
443 sense_data
->command
);
448 bus_id
= kmalloc(BUS_ID_SIZE
, GFP_KERNEL
);
449 if (bus_id
== NULL
) {
453 snprintf(bus_id
, BUS_ID_SIZE
, "%d.%d.%04x",
454 (sense_data
->devno
>> 24),
455 (sense_data
->devno
>> 16) & 0xFF,
456 (sense_data
->devno
& 0xFFFF));
458 read_lock_irq(&zfcp_data
.config_lock
);
459 adapter
= zfcp_get_adapter_by_busid(bus_id
);
461 zfcp_adapter_get(adapter
);
462 read_unlock_irq(&zfcp_data
.config_lock
);
466 if (adapter
== NULL
) {
467 ZFCP_LOG_INFO("invalid adapter\n");
472 if (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
) {
473 retval
= zfcp_sg_list_alloc(sg_list
,
474 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
481 if ((sense_data
->command
& ZFCP_CFDC_DOWNLOAD
) &&
482 (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
)) {
483 retval
= zfcp_sg_list_copy_from_user(
484 sg_list
, &sense_data_user
->control_file
,
485 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
492 retval
= zfcp_fsf_control_file(adapter
, &fsf_req
, fsf_command
,
497 if ((fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_GOOD
) &&
498 (fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_FSF_STATUS_PRESENTED
)) {
503 sense_data
->fsf_status
= fsf_req
->qtcb
->header
.fsf_status
;
504 memcpy(&sense_data
->fsf_status_qual
,
505 &fsf_req
->qtcb
->header
.fsf_status_qual
,
506 sizeof(union fsf_status_qual
));
507 memcpy(&sense_data
->payloads
, &fsf_req
->qtcb
->bottom
.support
.els
, 256);
509 retval
= copy_to_user(sense_data_user
, sense_data
,
510 sizeof(struct zfcp_cfdc_sense_data
));
516 if (sense_data
->command
& ZFCP_CFDC_UPLOAD
) {
517 retval
= zfcp_sg_list_copy_to_user(
518 &sense_data_user
->control_file
, sg_list
,
519 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
528 zfcp_fsf_req_cleanup(fsf_req
);
530 if ((adapter
!= NULL
) && (retval
!= -ENXIO
))
531 zfcp_adapter_put(adapter
);
533 if (sg_list
!= NULL
) {
534 zfcp_sg_list_free(sg_list
);
538 if (sense_data
!= NULL
)
546 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
547 * @sg_list: structure describing a scatter gather list
548 * @size: size of scatter-gather list
549 * Return: 0 on success, else -ENOMEM
551 * In sg_list->sg a pointer to the created scatter-gather list is returned,
552 * or NULL if we run out of memory. sg_list->count specifies the number of
553 * elements of the scatter-gather list. The maximum size of a single element
554 * in the scatter-gather list is PAGE_SIZE.
557 zfcp_sg_list_alloc(struct zfcp_sg_list
*sg_list
, size_t size
)
559 struct scatterlist
*sg
;
564 BUG_ON(sg_list
== NULL
);
566 sg_list
->count
= size
>> PAGE_SHIFT
;
567 if (size
& ~PAGE_MASK
)
569 sg_list
->sg
= kmalloc(sg_list
->count
* sizeof(struct scatterlist
),
571 if (sg_list
->sg
== NULL
) {
576 memset(sg_list
->sg
, 0, sg_list
->count
* sizeof(struct scatterlist
));
578 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++) {
579 sg
->length
= min(size
, PAGE_SIZE
);
581 address
= (void *) get_zeroed_page(GFP_KERNEL
);
582 if (address
== NULL
) {
584 zfcp_sg_list_free(sg_list
);
588 zfcp_address_to_sg(address
, sg
);
598 * zfcp_sg_list_free - free memory of a scatter-gather list
599 * @sg_list: structure describing a scatter-gather list
601 * Memory for each element in the scatter-gather list is freed.
602 * Finally sg_list->sg is freed itself and sg_list->count is reset.
605 zfcp_sg_list_free(struct zfcp_sg_list
*sg_list
)
607 struct scatterlist
*sg
;
610 BUG_ON(sg_list
== NULL
);
612 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++)
613 free_page((unsigned long) zfcp_sg_to_address(sg
));
620 * zfcp_sg_size - determine size of a scatter-gather list
621 * @sg: array of (struct scatterlist)
622 * @sg_count: elements in array
623 * Return: size of entire scatter-gather list
626 zfcp_sg_size(struct scatterlist
*sg
, unsigned int sg_count
)
629 struct scatterlist
*p
;
633 for (i
= 0, p
= sg
; i
< sg_count
; i
++, p
++) {
643 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
644 * @sg_list: structure describing a scatter-gather list
645 * @user_buffer: pointer to buffer in user space
646 * @size: number of bytes to be copied
647 * Return: 0 on success, -EFAULT if copy_from_user fails.
650 zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*sg_list
,
651 void __user
*user_buffer
,
654 struct scatterlist
*sg
;
659 BUG_ON(sg_list
== NULL
);
661 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
664 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
665 length
= min((unsigned int)size
, sg
->length
);
666 zfcp_buffer
= zfcp_sg_to_address(sg
);
667 if (copy_from_user(zfcp_buffer
, user_buffer
, length
)) {
671 user_buffer
+= length
;
681 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
682 * @user_buffer: pointer to buffer in user space
683 * @sg_list: structure describing a scatter-gather list
684 * @size: number of bytes to be copied
685 * Return: 0 on success, -EFAULT if copy_to_user fails
688 zfcp_sg_list_copy_to_user(void __user
*user_buffer
,
689 struct zfcp_sg_list
*sg_list
,
692 struct scatterlist
*sg
;
697 BUG_ON(sg_list
== NULL
);
699 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
702 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
703 length
= min((unsigned int) size
, sg
->length
);
704 zfcp_buffer
= zfcp_sg_to_address(sg
);
705 if (copy_to_user(user_buffer
, zfcp_buffer
, length
)) {
709 user_buffer
+= length
;
720 /****************************************************************/
721 /****** Functions for configuration/set-up of structures ********/
722 /****************************************************************/
724 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
727 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
728 * @port: pointer to port to search for unit
729 * @fcp_lun: FCP LUN to search for
730 * Traverse list of all units of a port and return pointer to a unit
731 * with the given FCP LUN.
734 zfcp_get_unit_by_lun(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
736 struct zfcp_unit
*unit
;
739 list_for_each_entry(unit
, &port
->unit_list_head
, list
) {
740 if ((unit
->fcp_lun
== fcp_lun
) &&
741 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
))
747 return found
? unit
: NULL
;
751 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
752 * @adapter: pointer to adapter to search for port
753 * @wwpn: wwpn to search for
754 * Traverse list of all ports of an adapter and return pointer to a port
755 * with the given wwpn.
758 zfcp_get_port_by_wwpn(struct zfcp_adapter
*adapter
, wwn_t wwpn
)
760 struct zfcp_port
*port
;
763 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
764 if ((port
->wwpn
== wwpn
) &&
765 !(atomic_read(&port
->status
) &
766 (ZFCP_STATUS_PORT_NO_WWPN
| ZFCP_STATUS_COMMON_REMOVE
))) {
771 return found
? port
: NULL
;
775 * zfcp_get_port_by_did - find port in port list of adapter by d_id
776 * @adapter: pointer to adapter to search for port
777 * @d_id: d_id to search for
778 * Traverse list of all ports of an adapter and return pointer to a port
779 * with the given d_id.
782 zfcp_get_port_by_did(struct zfcp_adapter
*adapter
, u32 d_id
)
784 struct zfcp_port
*port
;
787 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
788 if ((port
->d_id
== d_id
) &&
789 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
))
795 return found
? port
: NULL
;
799 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
800 * @bus_id: bus_id to search for
801 * Traverse list of all adapters and return pointer to an adapter
802 * with the given bus_id.
804 struct zfcp_adapter
*
805 zfcp_get_adapter_by_busid(char *bus_id
)
807 struct zfcp_adapter
*adapter
;
810 list_for_each_entry(adapter
, &zfcp_data
.adapter_list_head
, list
) {
811 if ((strncmp(bus_id
, zfcp_get_busid_by_adapter(adapter
),
812 BUS_ID_SIZE
) == 0) &&
813 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
,
819 return found
? adapter
: NULL
;
823 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
824 * @port: pointer to port where unit is added
825 * @fcp_lun: FCP LUN of unit to be enqueued
826 * Return: pointer to enqueued unit on success, NULL on error
827 * Locks: config_sema must be held to serialize changes to the unit list
829 * Sets up some unit internal structures and creates sysfs entry.
832 zfcp_unit_enqueue(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
834 struct zfcp_unit
*unit
, *tmp_unit
;
839 * check that there is no unit with this FCP_LUN already in list
841 * Note: Unlike for the adapter and the port, this is an error
843 read_lock_irq(&zfcp_data
.config_lock
);
844 unit
= zfcp_get_unit_by_lun(port
, fcp_lun
);
845 read_unlock_irq(&zfcp_data
.config_lock
);
849 unit
= kmalloc(sizeof (struct zfcp_unit
), GFP_KERNEL
);
852 memset(unit
, 0, sizeof (struct zfcp_unit
));
854 /* initialise reference count stuff */
855 atomic_set(&unit
->refcount
, 0);
856 init_waitqueue_head(&unit
->remove_wq
);
859 unit
->fcp_lun
= fcp_lun
;
861 /* setup for sysfs registration */
862 snprintf(unit
->sysfs_device
.bus_id
, BUS_ID_SIZE
, "0x%016llx", fcp_lun
);
863 unit
->sysfs_device
.parent
= &port
->sysfs_device
;
864 unit
->sysfs_device
.release
= zfcp_sysfs_unit_release
;
865 dev_set_drvdata(&unit
->sysfs_device
, unit
);
867 /* mark unit unusable as long as sysfs registration is not complete */
868 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
870 if (device_register(&unit
->sysfs_device
)) {
875 if (zfcp_sysfs_unit_create_files(&unit
->sysfs_device
)) {
876 device_unregister(&unit
->sysfs_device
);
884 write_lock_irq(&zfcp_data
.config_lock
);
885 list_for_each_entry(tmp_unit
, &port
->unit_list_head
, list
) {
886 if (tmp_unit
->scsi_lun
!= scsi_lun
) {
892 unit
->scsi_lun
= scsi_lun
;
894 list_add_tail(&unit
->list
, &tmp_unit
->list
);
896 list_add_tail(&unit
->list
, &port
->unit_list_head
);
897 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
898 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &unit
->status
);
899 write_unlock_irq(&zfcp_data
.config_lock
);
908 zfcp_unit_dequeue(struct zfcp_unit
*unit
)
910 zfcp_unit_wait(unit
);
911 write_lock_irq(&zfcp_data
.config_lock
);
912 list_del(&unit
->list
);
913 write_unlock_irq(&zfcp_data
.config_lock
);
915 zfcp_port_put(unit
->port
);
916 zfcp_sysfs_unit_remove_files(&unit
->sysfs_device
);
917 device_unregister(&unit
->sysfs_device
);
921 zfcp_mempool_alloc(unsigned int __nocast gfp_mask
, void *size
)
923 return kmalloc((size_t) size
, gfp_mask
);
927 zfcp_mempool_free(void *element
, void *size
)
933 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
935 * It also genrates fcp-nameserver request/response buffer and unsolicited
936 * status read fsf_req buffers.
938 * locks: must only be called with zfcp_data.config_sema taken
941 zfcp_allocate_low_mem_buffers(struct zfcp_adapter
*adapter
)
943 adapter
->pool
.fsf_req_erp
=
944 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR
,
945 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
946 sizeof(struct zfcp_fsf_req_pool_element
));
948 if (NULL
== adapter
->pool
.fsf_req_erp
)
951 adapter
->pool
.fsf_req_scsi
=
952 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR
,
953 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
954 sizeof(struct zfcp_fsf_req_pool_element
));
956 if (NULL
== adapter
->pool
.fsf_req_scsi
)
959 adapter
->pool
.fsf_req_abort
=
960 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR
,
961 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
962 sizeof(struct zfcp_fsf_req_pool_element
));
964 if (NULL
== adapter
->pool
.fsf_req_abort
)
967 adapter
->pool
.fsf_req_status_read
=
968 mempool_create(ZFCP_POOL_STATUS_READ_NR
,
969 zfcp_mempool_alloc
, zfcp_mempool_free
,
970 (void *) sizeof(struct zfcp_fsf_req
));
972 if (NULL
== adapter
->pool
.fsf_req_status_read
)
975 adapter
->pool
.data_status_read
=
976 mempool_create(ZFCP_POOL_STATUS_READ_NR
,
977 zfcp_mempool_alloc
, zfcp_mempool_free
,
978 (void *) sizeof(struct fsf_status_read_buffer
));
980 if (NULL
== adapter
->pool
.data_status_read
)
983 adapter
->pool
.data_gid_pn
=
984 mempool_create(ZFCP_POOL_DATA_GID_PN_NR
,
985 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
986 sizeof(struct zfcp_gid_pn_data
));
988 if (NULL
== adapter
->pool
.data_gid_pn
)
995 * zfcp_free_low_mem_buffers - free memory pools of an adapter
996 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
997 * locking: zfcp_data.config_sema must be held
1000 zfcp_free_low_mem_buffers(struct zfcp_adapter
*adapter
)
1002 if (adapter
->pool
.fsf_req_erp
)
1003 mempool_destroy(adapter
->pool
.fsf_req_erp
);
1004 if (adapter
->pool
.fsf_req_scsi
)
1005 mempool_destroy(adapter
->pool
.fsf_req_scsi
);
1006 if (adapter
->pool
.fsf_req_abort
)
1007 mempool_destroy(adapter
->pool
.fsf_req_abort
);
1008 if (adapter
->pool
.fsf_req_status_read
)
1009 mempool_destroy(adapter
->pool
.fsf_req_status_read
);
1010 if (adapter
->pool
.data_status_read
)
1011 mempool_destroy(adapter
->pool
.data_status_read
);
1012 if (adapter
->pool
.data_gid_pn
)
1013 mempool_destroy(adapter
->pool
.data_gid_pn
);
1017 * zfcp_adapter_debug_register - registers debug feature for an adapter
1018 * @adapter: pointer to adapter for which debug features should be registered
1019 * return: -ENOMEM on error, 0 otherwise
1022 zfcp_adapter_debug_register(struct zfcp_adapter
*adapter
)
1026 /* debug feature area which records SCSI command failures (hostbyte) */
1027 spin_lock_init(&adapter
->dbf_lock
);
1029 sprintf(dbf_name
, ZFCP_CMD_DBF_NAME
"%s",
1030 zfcp_get_busid_by_adapter(adapter
));
1031 adapter
->cmd_dbf
= debug_register(dbf_name
, ZFCP_CMD_DBF_INDEX
,
1033 ZFCP_CMD_DBF_LENGTH
);
1034 debug_register_view(adapter
->cmd_dbf
, &debug_hex_ascii_view
);
1035 debug_set_level(adapter
->cmd_dbf
, ZFCP_CMD_DBF_LEVEL
);
1037 /* debug feature area which records SCSI command aborts */
1038 sprintf(dbf_name
, ZFCP_ABORT_DBF_NAME
"%s",
1039 zfcp_get_busid_by_adapter(adapter
));
1040 adapter
->abort_dbf
= debug_register(dbf_name
, ZFCP_ABORT_DBF_INDEX
,
1041 ZFCP_ABORT_DBF_AREAS
,
1042 ZFCP_ABORT_DBF_LENGTH
);
1043 debug_register_view(adapter
->abort_dbf
, &debug_hex_ascii_view
);
1044 debug_set_level(adapter
->abort_dbf
, ZFCP_ABORT_DBF_LEVEL
);
1046 /* debug feature area which records incoming ELS commands */
1047 sprintf(dbf_name
, ZFCP_IN_ELS_DBF_NAME
"%s",
1048 zfcp_get_busid_by_adapter(adapter
));
1049 adapter
->in_els_dbf
= debug_register(dbf_name
, ZFCP_IN_ELS_DBF_INDEX
,
1050 ZFCP_IN_ELS_DBF_AREAS
,
1051 ZFCP_IN_ELS_DBF_LENGTH
);
1052 debug_register_view(adapter
->in_els_dbf
, &debug_hex_ascii_view
);
1053 debug_set_level(adapter
->in_els_dbf
, ZFCP_IN_ELS_DBF_LEVEL
);
1055 /* debug feature area which records erp events */
1056 sprintf(dbf_name
, ZFCP_ERP_DBF_NAME
"%s",
1057 zfcp_get_busid_by_adapter(adapter
));
1058 adapter
->erp_dbf
= debug_register(dbf_name
, ZFCP_ERP_DBF_INDEX
,
1060 ZFCP_ERP_DBF_LENGTH
);
1061 debug_register_view(adapter
->erp_dbf
, &debug_hex_ascii_view
);
1062 debug_set_level(adapter
->erp_dbf
, ZFCP_ERP_DBF_LEVEL
);
1064 if (!(adapter
->cmd_dbf
&& adapter
->abort_dbf
&&
1065 adapter
->in_els_dbf
&& adapter
->erp_dbf
)) {
1066 zfcp_adapter_debug_unregister(adapter
);
1075 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1076 * @adapter: pointer to adapter for which debug features should be unregistered
1079 zfcp_adapter_debug_unregister(struct zfcp_adapter
*adapter
)
1081 debug_unregister(adapter
->abort_dbf
);
1082 debug_unregister(adapter
->cmd_dbf
);
1083 debug_unregister(adapter
->erp_dbf
);
1084 debug_unregister(adapter
->in_els_dbf
);
1085 adapter
->abort_dbf
= NULL
;
1086 adapter
->cmd_dbf
= NULL
;
1087 adapter
->erp_dbf
= NULL
;
1088 adapter
->in_els_dbf
= NULL
;
1092 zfcp_dummy_release(struct device
*dev
)
1098 * Enqueues an adapter at the end of the adapter list in the driver data.
1099 * All adapter internal structures are set up.
1100 * Proc-fs entries are also created.
1102 * returns: 0 if a new adapter was successfully enqueued
1103 * ZFCP_KNOWN if an adapter with this devno was already present
1104 * -ENOMEM if alloc failed
1105 * locks: config_sema must be held to serialise changes to the adapter list
1107 struct zfcp_adapter
*
1108 zfcp_adapter_enqueue(struct ccw_device
*ccw_device
)
1111 struct zfcp_adapter
*adapter
;
1114 * Note: It is safe to release the list_lock, as any list changes
1115 * are protected by the config_sema, which must be held to get here
1118 /* try to allocate new adapter data structure (zeroed) */
1119 adapter
= kmalloc(sizeof (struct zfcp_adapter
), GFP_KERNEL
);
1121 ZFCP_LOG_INFO("error: allocation of base adapter "
1122 "structure failed\n");
1125 memset(adapter
, 0, sizeof (struct zfcp_adapter
));
1127 ccw_device
->handler
= NULL
;
1129 /* save ccw_device pointer */
1130 adapter
->ccw_device
= ccw_device
;
1132 retval
= zfcp_qdio_allocate_queues(adapter
);
1134 goto queues_alloc_failed
;
1136 retval
= zfcp_qdio_allocate(adapter
);
1138 goto qdio_allocate_failed
;
1140 retval
= zfcp_allocate_low_mem_buffers(adapter
);
1142 ZFCP_LOG_INFO("error: pool allocation failed\n");
1143 goto failed_low_mem_buffers
;
1146 /* initialise reference count stuff */
1147 atomic_set(&adapter
->refcount
, 0);
1148 init_waitqueue_head(&adapter
->remove_wq
);
1150 /* initialise list of ports */
1151 INIT_LIST_HEAD(&adapter
->port_list_head
);
1153 /* initialise list of ports to be removed */
1154 INIT_LIST_HEAD(&adapter
->port_remove_lh
);
1156 /* initialize list of fsf requests */
1157 rwlock_init(&adapter
->fsf_req_list_lock
);
1158 INIT_LIST_HEAD(&adapter
->fsf_req_list_head
);
1160 /* initialize abort lock */
1161 rwlock_init(&adapter
->abort_lock
);
1163 /* initialise some erp stuff */
1164 init_waitqueue_head(&adapter
->erp_thread_wqh
);
1165 init_waitqueue_head(&adapter
->erp_done_wqh
);
1167 /* initialize lock of associated request queue */
1168 rwlock_init(&adapter
->request_queue
.queue_lock
);
1170 /* intitialise SCSI ER timer */
1171 init_timer(&adapter
->scsi_er_timer
);
1173 /* set FC service class used per default */
1174 adapter
->fc_service_class
= ZFCP_FC_SERVICE_CLASS_DEFAULT
;
1176 sprintf(adapter
->name
, "%s", zfcp_get_busid_by_adapter(adapter
));
1177 ASCEBC(adapter
->name
, strlen(adapter
->name
));
1179 /* mark adapter unusable as long as sysfs registration is not complete */
1180 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1182 adapter
->ccw_device
= ccw_device
;
1183 dev_set_drvdata(&ccw_device
->dev
, adapter
);
1185 if (zfcp_sysfs_adapter_create_files(&ccw_device
->dev
))
1188 adapter
->generic_services
.parent
= &adapter
->ccw_device
->dev
;
1189 adapter
->generic_services
.release
= zfcp_dummy_release
;
1190 snprintf(adapter
->generic_services
.bus_id
, BUS_ID_SIZE
,
1191 "generic_services");
1193 if (device_register(&adapter
->generic_services
))
1194 goto generic_services_failed
;
1196 /* put allocated adapter at list tail */
1197 write_lock_irq(&zfcp_data
.config_lock
);
1198 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1199 list_add_tail(&adapter
->list
, &zfcp_data
.adapter_list_head
);
1200 write_unlock_irq(&zfcp_data
.config_lock
);
1202 zfcp_data
.adapters
++;
1206 generic_services_failed
:
1207 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1209 dev_set_drvdata(&ccw_device
->dev
, NULL
);
1210 failed_low_mem_buffers
:
1211 zfcp_free_low_mem_buffers(adapter
);
1212 if (qdio_free(ccw_device
) != 0)
1213 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1214 zfcp_get_busid_by_adapter(adapter
));
1215 qdio_allocate_failed
:
1216 zfcp_qdio_free_queues(adapter
);
1217 queues_alloc_failed
:
1225 * returns: 0 - struct zfcp_adapter data structure successfully removed
1226 * !0 - struct zfcp_adapter data structure could not be removed
1228 * locks: adapter list write lock is assumed to be held by caller
1229 * adapter->fsf_req_list_lock is taken and released within this
1230 * function and must not be held on entry
1233 zfcp_adapter_dequeue(struct zfcp_adapter
*adapter
)
1236 unsigned long flags
;
1238 device_unregister(&adapter
->generic_services
);
1239 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1240 dev_set_drvdata(&adapter
->ccw_device
->dev
, NULL
);
1241 /* sanity check: no pending FSF requests */
1242 read_lock_irqsave(&adapter
->fsf_req_list_lock
, flags
);
1243 retval
= !list_empty(&adapter
->fsf_req_list_head
);
1244 read_unlock_irqrestore(&adapter
->fsf_req_list_lock
, flags
);
1246 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1247 "%i requests outstanding\n",
1248 zfcp_get_busid_by_adapter(adapter
), adapter
,
1249 atomic_read(&adapter
->fsf_reqs_active
));
1254 /* remove specified adapter data structure from list */
1255 write_lock_irq(&zfcp_data
.config_lock
);
1256 list_del(&adapter
->list
);
1257 write_unlock_irq(&zfcp_data
.config_lock
);
1259 /* decrease number of adapters in list */
1260 zfcp_data
.adapters
--;
1262 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1263 "%i adapters still in list\n",
1264 zfcp_get_busid_by_adapter(adapter
),
1265 adapter
, zfcp_data
.adapters
);
1267 retval
= qdio_free(adapter
->ccw_device
);
1269 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1270 zfcp_get_busid_by_adapter(adapter
));
1272 zfcp_free_low_mem_buffers(adapter
);
1273 /* free memory of adapter data structure and queues */
1274 zfcp_qdio_free_queues(adapter
);
1275 ZFCP_LOG_TRACE("freeing adapter structure\n");
1282 * zfcp_port_enqueue - enqueue port to port list of adapter
1283 * @adapter: adapter where remote port is added
1284 * @wwpn: WWPN of the remote port to be enqueued
1285 * @status: initial status for the port
1286 * @d_id: destination id of the remote port to be enqueued
1287 * Return: pointer to enqueued port on success, NULL on error
1288 * Locks: config_sema must be held to serialize changes to the port list
1290 * All port internal structures are set up and the sysfs entry is generated.
1291 * d_id is used to enqueue ports with a well known address like the Directory
1292 * Service for nameserver lookup.
1295 zfcp_port_enqueue(struct zfcp_adapter
*adapter
, wwn_t wwpn
, u32 status
,
1298 struct zfcp_port
*port
, *tmp_port
;
1303 check_wwpn
= !(status
& ZFCP_STATUS_PORT_NO_WWPN
);
1306 * check that there is no port with this WWPN already in list
1309 read_lock_irq(&zfcp_data
.config_lock
);
1310 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
1311 read_unlock_irq(&zfcp_data
.config_lock
);
1316 port
= kmalloc(sizeof (struct zfcp_port
), GFP_KERNEL
);
1319 memset(port
, 0, sizeof (struct zfcp_port
));
1321 /* initialise reference count stuff */
1322 atomic_set(&port
->refcount
, 0);
1323 init_waitqueue_head(&port
->remove_wq
);
1325 INIT_LIST_HEAD(&port
->unit_list_head
);
1326 INIT_LIST_HEAD(&port
->unit_remove_lh
);
1328 port
->adapter
= adapter
;
1333 atomic_set_mask(status
, &port
->status
);
1335 /* setup for sysfs registration */
1336 if (status
& ZFCP_STATUS_PORT_WKA
) {
1338 case ZFCP_DID_DIRECTORY_SERVICE
:
1339 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1342 case ZFCP_DID_MANAGEMENT_SERVICE
:
1343 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1346 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE
:
1347 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1348 "key_distribution");
1350 case ZFCP_DID_ALIAS_SERVICE
:
1351 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1354 case ZFCP_DID_TIME_SERVICE
:
1355 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1363 port
->sysfs_device
.parent
= &adapter
->generic_services
;
1365 snprintf(port
->sysfs_device
.bus_id
,
1366 BUS_ID_SIZE
, "0x%016llx", wwpn
);
1367 port
->sysfs_device
.parent
= &adapter
->ccw_device
->dev
;
1369 port
->sysfs_device
.release
= zfcp_sysfs_port_release
;
1370 dev_set_drvdata(&port
->sysfs_device
, port
);
1372 /* mark port unusable as long as sysfs registration is not complete */
1373 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1375 if (device_register(&port
->sysfs_device
)) {
1380 if (zfcp_sysfs_port_create_files(&port
->sysfs_device
, status
)) {
1381 device_unregister(&port
->sysfs_device
);
1385 zfcp_port_get(port
);
1389 write_lock_irq(&zfcp_data
.config_lock
);
1390 list_for_each_entry(tmp_port
, &adapter
->port_list_head
, list
) {
1391 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_SCSI_ID
,
1394 if (tmp_port
->scsi_id
!= scsi_id
) {
1400 port
->scsi_id
= scsi_id
;
1402 list_add_tail(&port
->list
, &tmp_port
->list
);
1404 list_add_tail(&port
->list
, &adapter
->port_list_head
);
1405 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1406 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &port
->status
);
1407 if (d_id
== ZFCP_DID_DIRECTORY_SERVICE
)
1408 if (!adapter
->nameserver_port
)
1409 adapter
->nameserver_port
= port
;
1411 write_unlock_irq(&zfcp_data
.config_lock
);
1413 zfcp_adapter_get(adapter
);
1419 zfcp_port_dequeue(struct zfcp_port
*port
)
1421 zfcp_port_wait(port
);
1422 write_lock_irq(&zfcp_data
.config_lock
);
1423 list_del(&port
->list
);
1424 port
->adapter
->ports
--;
1425 write_unlock_irq(&zfcp_data
.config_lock
);
1426 zfcp_adapter_put(port
->adapter
);
1427 zfcp_sysfs_port_remove_files(&port
->sysfs_device
,
1428 atomic_read(&port
->status
));
1429 device_unregister(&port
->sysfs_device
);
1432 /* Enqueues a nameserver port */
1434 zfcp_nameserver_enqueue(struct zfcp_adapter
*adapter
)
1436 struct zfcp_port
*port
;
1438 port
= zfcp_port_enqueue(adapter
, 0, ZFCP_STATUS_PORT_WKA
,
1439 ZFCP_DID_DIRECTORY_SERVICE
);
1441 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1442 "adapter %s failed\n",
1443 zfcp_get_busid_by_adapter(adapter
));
1446 zfcp_port_put(port
);
1451 #undef ZFCP_LOG_AREA
1453 /****************************************************************/
1454 /******* Fibre Channel Standard related Functions **************/
1455 /****************************************************************/
1457 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1460 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter
*adapter
,
1461 struct fsf_status_read_buffer
*status_buffer
)
1463 struct fcp_rscn_head
*fcp_rscn_head
;
1464 struct fcp_rscn_element
*fcp_rscn_element
;
1465 struct zfcp_port
*port
;
1469 unsigned long flags
;
1471 fcp_rscn_head
= (struct fcp_rscn_head
*) status_buffer
->payload
;
1472 fcp_rscn_element
= (struct fcp_rscn_element
*) status_buffer
->payload
;
1475 no_entries
= (fcp_rscn_head
->payload_len
/ 4);
1477 zfcp_in_els_dbf_event(adapter
, "##rscn", status_buffer
,
1478 fcp_rscn_head
->payload_len
);
1480 debug_text_event(adapter
->erp_dbf
, 1, "unsol_els_rscn:");
1481 for (i
= 1; i
< no_entries
; i
++) {
1482 /* skip head and start with 1st element */
1484 switch (fcp_rscn_element
->addr_format
) {
1485 case ZFCP_PORT_ADDRESS
:
1486 ZFCP_LOG_FLAGS(1, "ZFCP_PORT_ADDRESS\n");
1487 range_mask
= ZFCP_PORTS_RANGE_PORT
;
1489 case ZFCP_AREA_ADDRESS
:
1490 ZFCP_LOG_FLAGS(1, "ZFCP_AREA_ADDRESS\n");
1491 range_mask
= ZFCP_PORTS_RANGE_AREA
;
1493 case ZFCP_DOMAIN_ADDRESS
:
1494 ZFCP_LOG_FLAGS(1, "ZFCP_DOMAIN_ADDRESS\n");
1495 range_mask
= ZFCP_PORTS_RANGE_DOMAIN
;
1497 case ZFCP_FABRIC_ADDRESS
:
1498 ZFCP_LOG_FLAGS(1, "ZFCP_FABRIC_ADDRESS\n");
1499 range_mask
= ZFCP_PORTS_RANGE_FABRIC
;
1502 ZFCP_LOG_INFO("incoming RSCN with unknown "
1503 "address format\n");
1506 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1507 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1508 if (atomic_test_mask
1509 (ZFCP_STATUS_PORT_WKA
, &port
->status
))
1511 /* Do we know this port? If not skip it. */
1512 if (!atomic_test_mask
1513 (ZFCP_STATUS_PORT_DID_DID
, &port
->status
)) {
1514 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1515 "port 0x%016Lx\n", port
->wwpn
);
1516 debug_text_event(adapter
->erp_dbf
, 1,
1517 "unsol_els_rscnu:");
1518 zfcp_erp_port_reopen(port
,
1519 ZFCP_STATUS_COMMON_ERP_FAILED
);
1524 * FIXME: race: d_id might being invalidated
1525 * (...DID_DID reset)
1527 if ((port
->d_id
& range_mask
)
1528 == (fcp_rscn_element
->nport_did
& range_mask
)) {
1529 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1530 fcp_rscn_element
->nport_did
);
1532 * Unfortunately, an RSCN does not specify the
1533 * type of change a target underwent. We assume
1534 * that it makes sense to reopen the link.
1535 * FIXME: Shall we try to find out more about
1536 * the target and link state before closing it?
1537 * How to accomplish this? (nameserver?)
1538 * Where would such code be put in?
1539 * (inside or outside erp)
1541 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1542 "port 0x%016Lx\n", port
->wwpn
);
1543 debug_text_event(adapter
->erp_dbf
, 1,
1544 "unsol_els_rscnk:");
1545 zfcp_test_link(port
);
1548 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1553 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter
*adapter
,
1554 struct fsf_status_read_buffer
*status_buffer
)
1556 logi
*els_logi
= (logi
*) status_buffer
->payload
;
1557 struct zfcp_port
*port
;
1558 unsigned long flags
;
1560 zfcp_in_els_dbf_event(adapter
, "##plogi", status_buffer
, 28);
1562 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1563 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1564 if (port
->wwpn
== (*(wwn_t
*) & els_logi
->nport_wwn
))
1567 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1569 if (!port
|| (port
->wwpn
!= (*(wwn_t
*) & els_logi
->nport_wwn
))) {
1570 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1571 "with d_id 0x%08x on adapter %s\n",
1572 status_buffer
->d_id
,
1573 zfcp_get_busid_by_adapter(adapter
));
1575 debug_text_event(adapter
->erp_dbf
, 1, "unsol_els_plogi:");
1576 debug_event(adapter
->erp_dbf
, 1, &els_logi
->nport_wwn
, 8);
1577 zfcp_erp_port_forced_reopen(port
, 0);
1582 zfcp_fsf_incoming_els_logo(struct zfcp_adapter
*adapter
,
1583 struct fsf_status_read_buffer
*status_buffer
)
1585 struct fcp_logo
*els_logo
= (struct fcp_logo
*) status_buffer
->payload
;
1586 struct zfcp_port
*port
;
1587 unsigned long flags
;
1589 zfcp_in_els_dbf_event(adapter
, "##logo", status_buffer
, 16);
1591 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1592 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1593 if (port
->wwpn
== els_logo
->nport_wwpn
)
1596 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1598 if (!port
|| (port
->wwpn
!= els_logo
->nport_wwpn
)) {
1599 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1600 "with d_id 0x%08x on adapter %s\n",
1601 status_buffer
->d_id
,
1602 zfcp_get_busid_by_adapter(adapter
));
1604 debug_text_event(adapter
->erp_dbf
, 1, "unsol_els_logo:");
1605 debug_event(adapter
->erp_dbf
, 1, &els_logo
->nport_wwpn
, 8);
1606 zfcp_erp_port_forced_reopen(port
, 0);
1611 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter
*adapter
,
1612 struct fsf_status_read_buffer
*status_buffer
)
1614 zfcp_in_els_dbf_event(adapter
, "##undef", status_buffer
, 24);
1615 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1616 "for adapter %s\n", *(u32
*) (status_buffer
->payload
),
1617 zfcp_get_busid_by_adapter(adapter
));
1622 zfcp_fsf_incoming_els(struct zfcp_fsf_req
*fsf_req
)
1624 struct fsf_status_read_buffer
*status_buffer
;
1626 struct zfcp_adapter
*adapter
;
1628 status_buffer
= fsf_req
->data
.status_read
.buffer
;
1629 els_type
= *(u32
*) (status_buffer
->payload
);
1630 adapter
= fsf_req
->adapter
;
1632 if (els_type
== LS_PLOGI
)
1633 zfcp_fsf_incoming_els_plogi(adapter
, status_buffer
);
1634 else if (els_type
== LS_LOGO
)
1635 zfcp_fsf_incoming_els_logo(adapter
, status_buffer
);
1636 else if ((els_type
& 0xffff0000) == LS_RSCN
)
1637 /* we are only concerned with the command, not the length */
1638 zfcp_fsf_incoming_els_rscn(adapter
, status_buffer
);
1640 zfcp_fsf_incoming_els_unknown(adapter
, status_buffer
);
1645 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1646 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1647 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1650 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data
**gid_pn
, mempool_t
*pool
)
1652 struct zfcp_gid_pn_data
*data
;
1655 data
= mempool_alloc(pool
, GFP_ATOMIC
);
1656 if (likely(data
!= NULL
)) {
1657 data
->ct
.pool
= pool
;
1660 data
= kmalloc(sizeof(struct zfcp_gid_pn_data
), GFP_ATOMIC
);
1666 memset(data
, 0, sizeof(*data
));
1667 data
->ct
.req
= &data
->req
;
1668 data
->ct
.resp
= &data
->resp
;
1669 data
->ct
.req_count
= data
->ct
.resp_count
= 1;
1670 zfcp_address_to_sg(&data
->ct_iu_req
, &data
->req
);
1671 zfcp_address_to_sg(&data
->ct_iu_resp
, &data
->resp
);
1672 data
->req
.length
= sizeof(struct ct_iu_gid_pn_req
);
1673 data
->resp
.length
= sizeof(struct ct_iu_gid_pn_resp
);
1680 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1681 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1684 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data
*gid_pn
)
1686 if ((gid_pn
->ct
.pool
!= 0))
1687 mempool_free(gid_pn
, gid_pn
->ct
.pool
);
1695 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1696 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1699 zfcp_ns_gid_pn_request(struct zfcp_erp_action
*erp_action
)
1702 struct ct_iu_gid_pn_req
*ct_iu_req
;
1703 struct zfcp_gid_pn_data
*gid_pn
;
1704 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1706 ret
= zfcp_gid_pn_buffers_alloc(&gid_pn
, adapter
->pool
.data_gid_pn
);
1708 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1709 "request failed for adapter %s\n",
1710 zfcp_get_busid_by_adapter(adapter
));
1714 /* setup nameserver request */
1715 ct_iu_req
= zfcp_sg_to_address(gid_pn
->ct
.req
);
1716 ct_iu_req
->header
.revision
= ZFCP_CT_REVISION
;
1717 ct_iu_req
->header
.gs_type
= ZFCP_CT_DIRECTORY_SERVICE
;
1718 ct_iu_req
->header
.gs_subtype
= ZFCP_CT_NAME_SERVER
;
1719 ct_iu_req
->header
.options
= ZFCP_CT_SYNCHRONOUS
;
1720 ct_iu_req
->header
.cmd_rsp_code
= ZFCP_CT_GID_PN
;
1721 ct_iu_req
->header
.max_res_size
= ZFCP_CT_MAX_SIZE
;
1722 ct_iu_req
->wwpn
= erp_action
->port
->wwpn
;
1724 /* setup parameters for send generic command */
1725 gid_pn
->ct
.port
= adapter
->nameserver_port
;
1726 gid_pn
->ct
.handler
= zfcp_ns_gid_pn_handler
;
1727 gid_pn
->ct
.handler_data
= (unsigned long) gid_pn
;
1728 gid_pn
->ct
.timeout
= ZFCP_NS_GID_PN_TIMEOUT
;
1729 gid_pn
->ct
.timer
= &erp_action
->timer
;
1730 gid_pn
->port
= erp_action
->port
;
1732 ret
= zfcp_fsf_send_ct(&gid_pn
->ct
, adapter
->pool
.fsf_req_erp
,
1735 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1736 "failed for adapter %s\n",
1737 zfcp_get_busid_by_adapter(adapter
));
1739 zfcp_gid_pn_buffers_free(gid_pn
);
1747 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1748 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1750 static void zfcp_ns_gid_pn_handler(unsigned long data
)
1752 struct zfcp_port
*port
;
1753 struct zfcp_send_ct
*ct
;
1754 struct ct_iu_gid_pn_req
*ct_iu_req
;
1755 struct ct_iu_gid_pn_resp
*ct_iu_resp
;
1756 struct zfcp_gid_pn_data
*gid_pn
;
1759 gid_pn
= (struct zfcp_gid_pn_data
*) data
;
1760 port
= gid_pn
->port
;
1762 ct_iu_req
= zfcp_sg_to_address(ct
->req
);
1763 ct_iu_resp
= zfcp_sg_to_address(ct
->resp
);
1765 if ((ct
->status
!= 0) || zfcp_check_ct_response(&ct_iu_resp
->header
)) {
1766 /* FIXME: do we need some specific erp entry points */
1767 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN
, &port
->status
);
1771 if (ct_iu_req
->wwpn
!= port
->wwpn
) {
1772 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1773 "lookup does not match expected wwpn 0x%016Lx "
1774 "for adapter %s\n", ct_iu_req
->wwpn
, port
->wwpn
,
1775 zfcp_get_busid_by_port(port
));
1779 /* looks like a valid d_id */
1780 port
->d_id
= ct_iu_resp
->d_id
& ZFCP_DID_MASK
;
1781 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID
, &port
->status
);
1782 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1783 zfcp_get_busid_by_port(port
), port
->wwpn
, port
->d_id
);
1787 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1788 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_req
,
1789 sizeof(struct ct_iu_gid_pn_req
));
1790 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_resp
,
1791 sizeof(struct ct_iu_gid_pn_resp
));
1794 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1795 "0x%016Lx for adapter %s\n",
1796 port
->wwpn
, zfcp_get_busid_by_port(port
));
1798 zfcp_gid_pn_buffers_free(gid_pn
);
1802 /* reject CT_IU reason codes acc. to FC-GS-4 */
1803 static const struct zfcp_rc_entry zfcp_ct_rc
[] = {
1804 {0x01, "invalid command code"},
1805 {0x02, "invalid version level"},
1806 {0x03, "logical error"},
1807 {0x04, "invalid CT_IU size"},
1808 {0x05, "logical busy"},
1809 {0x07, "protocol error"},
1810 {0x09, "unable to perform command request"},
1811 {0x0b, "command not supported"},
1812 {0x0d, "server not available"},
1813 {0x0e, "session could not be established"},
1814 {0xff, "vendor specific error"},
1818 /* LS_RJT reason codes acc. to FC-FS */
1819 static const struct zfcp_rc_entry zfcp_ls_rjt_rc
[] = {
1820 {0x01, "invalid LS_Command code"},
1821 {0x03, "logical error"},
1822 {0x05, "logical busy"},
1823 {0x07, "protocol error"},
1824 {0x09, "unable to perform command request"},
1825 {0x0b, "command not supported"},
1826 {0x0e, "command already in progress"},
1827 {0xff, "vendor specific error"},
1831 /* reject reason codes according to FC-PH/FC-FS */
1832 static const struct zfcp_rc_entry zfcp_p_rjt_rc
[] = {
1833 {0x01, "invalid D_ID"},
1834 {0x02, "invalid S_ID"},
1835 {0x03, "Nx_Port not available, temporary"},
1836 {0x04, "Nx_Port not available, permament"},
1837 {0x05, "class not supported"},
1838 {0x06, "delimiter usage error"},
1839 {0x07, "TYPE not supported"},
1840 {0x08, "invalid Link_Control"},
1841 {0x09, "invalid R_CTL field"},
1842 {0x0a, "invalid F_CTL field"},
1843 {0x0b, "invalid OX_ID"},
1844 {0x0c, "invalid RX_ID"},
1845 {0x0d, "invalid SEQ_ID"},
1846 {0x0e, "invalid DF_CTL"},
1847 {0x0f, "invalid SEQ_CNT"},
1848 {0x10, "invalid parameter field"},
1849 {0x11, "exchange error"},
1850 {0x12, "protocol error"},
1851 {0x13, "incorrect length"},
1852 {0x14, "unsupported ACK"},
1853 {0x15, "class of service not supported by entity at FFFFFE"},
1854 {0x16, "login required"},
1855 {0x17, "excessive sequences attempted"},
1856 {0x18, "unable to establish exchange"},
1857 {0x1a, "fabric path not available"},
1858 {0x1b, "invalid VC_ID (class 4)"},
1859 {0x1c, "invalid CS_CTL field"},
1860 {0x1d, "insufficient resources for VC (class 4)"},
1861 {0x1f, "invalid class of service"},
1862 {0x20, "preemption request rejected"},
1863 {0x21, "preemption not enabled"},
1864 {0x22, "multicast error"},
1865 {0x23, "multicast error terminate"},
1866 {0x24, "process login required"},
1867 {0xff, "vendor specific reject"},
1872 * zfcp_rc_description - return description for given reaon code
1873 * @code: reason code
1874 * @rc_table: table of reason codes and descriptions
1876 static inline const char *
1877 zfcp_rc_description(u8 code
, const struct zfcp_rc_entry
*rc_table
)
1879 const char *descr
= "unknown reason code";
1882 if (code
== rc_table
->code
) {
1883 descr
= rc_table
->description
;
1887 } while (rc_table
->code
&& rc_table
->description
);
1893 * zfcp_check_ct_response - evaluate reason code for CT_IU
1894 * @rjt: response payload to an CT_IU request
1895 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1898 zfcp_check_ct_response(struct ct_hdr
*rjt
)
1900 if (rjt
->cmd_rsp_code
== ZFCP_CT_ACCEPT
)
1903 if (rjt
->cmd_rsp_code
!= ZFCP_CT_REJECT
) {
1904 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1905 "response code (0x%04hx)\n",
1910 ZFCP_LOG_INFO("Generic Service command rejected\n");
1911 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1912 zfcp_rc_description(rjt
->reason_code
, zfcp_ct_rc
),
1913 (u32
) rjt
->reason_code
, (u32
) rjt
->reason_code_expl
,
1914 (u32
) rjt
->vendor_unique
);
1920 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1921 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1922 * @rc_table: table of reason codes and descriptions
1925 zfcp_print_els_rjt(struct zfcp_ls_rjt_par
*rjt_par
,
1926 const struct zfcp_rc_entry
*rc_table
)
1928 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1929 zfcp_rc_description(rjt_par
->reason_code
, rc_table
),
1930 (u32
) rjt_par
->action
, (u32
) rjt_par
->reason_code
,
1931 (u32
) rjt_par
->reason_expl
, (u32
) rjt_par
->vendor_unique
);
1935 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1936 * @sq: status qualifier word
1937 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1938 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1941 zfcp_handle_els_rjt(u32 sq
, struct zfcp_ls_rjt_par
*rjt_par
)
1945 if (sq
== FSF_IOSTAT_NPORT_RJT
) {
1946 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1947 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1949 if (rjt_par
->reason_code
== 0x01)
1951 } else if (sq
== FSF_IOSTAT_FABRIC_RJT
) {
1952 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1953 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1955 if (rjt_par
->reason_code
== 0x01)
1957 } else if (sq
== FSF_IOSTAT_LS_RJT
) {
1958 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1959 zfcp_print_els_rjt(rjt_par
, zfcp_ls_rjt_rc
);
1962 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq
);
1967 #undef ZFCP_LOG_AREA