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_fsf_req_is_scsi_cmnd(struct zfcp_fsf_req
*fsf_req
)
128 return ((fsf_req
->fsf_command
== FSF_QTCB_FCP_CMND
) &&
129 !(fsf_req
->status
& ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
));
133 zfcp_cmd_dbf_event_fsf(const char *text
, struct zfcp_fsf_req
*fsf_req
,
134 void *add_data
, int add_length
)
136 struct zfcp_adapter
*adapter
= fsf_req
->adapter
;
137 struct scsi_cmnd
*scsi_cmnd
;
142 spin_lock_irqsave(&adapter
->dbf_lock
, flags
);
143 if (zfcp_fsf_req_is_scsi_cmnd(fsf_req
)) {
144 scsi_cmnd
= fsf_req
->data
.send_fcp_command_task
.scsi_cmnd
;
145 debug_text_event(adapter
->cmd_dbf
, level
, "fsferror");
146 debug_text_event(adapter
->cmd_dbf
, level
, text
);
147 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
,
148 sizeof (unsigned long));
149 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
->seq_no
,
151 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
,
152 sizeof (unsigned long));
153 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
->cmnd
,
154 min(ZFCP_CMD_DBF_LENGTH
, (int)scsi_cmnd
->cmd_len
));
155 for (i
= 0; i
< add_length
; i
+= ZFCP_CMD_DBF_LENGTH
)
156 debug_event(adapter
->cmd_dbf
,
158 (char *) add_data
+ i
,
159 min(ZFCP_CMD_DBF_LENGTH
, add_length
- i
));
161 spin_unlock_irqrestore(&adapter
->dbf_lock
, flags
);
164 /* XXX additionally log unit if available */
165 /* ---> introduce new parameter for unit, see 2.4 code */
167 zfcp_cmd_dbf_event_scsi(const char *text
, struct scsi_cmnd
*scsi_cmnd
)
169 struct zfcp_adapter
*adapter
;
170 union zfcp_req_data
*req_data
;
171 struct zfcp_fsf_req
*fsf_req
;
172 int level
= ((host_byte(scsi_cmnd
->result
) != 0) ? 1 : 5);
175 adapter
= (struct zfcp_adapter
*) scsi_cmnd
->device
->host
->hostdata
[0];
176 req_data
= (union zfcp_req_data
*) scsi_cmnd
->host_scribble
;
177 fsf_req
= (req_data
? req_data
->send_fcp_command_task
.fsf_req
: NULL
);
178 spin_lock_irqsave(&adapter
->dbf_lock
, flags
);
179 debug_text_event(adapter
->cmd_dbf
, level
, "hostbyte");
180 debug_text_event(adapter
->cmd_dbf
, level
, text
);
181 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
->result
, sizeof (u32
));
182 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
,
183 sizeof (unsigned long));
184 debug_event(adapter
->cmd_dbf
, level
, &scsi_cmnd
->cmnd
,
185 min(ZFCP_CMD_DBF_LENGTH
, (int)scsi_cmnd
->cmd_len
));
186 if (likely(fsf_req
)) {
187 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
,
188 sizeof (unsigned long));
189 debug_event(adapter
->cmd_dbf
, level
, &fsf_req
->seq_no
,
192 debug_text_event(adapter
->cmd_dbf
, level
, "");
193 debug_text_event(adapter
->cmd_dbf
, level
, "");
195 spin_unlock_irqrestore(&adapter
->dbf_lock
, flags
);
199 zfcp_in_els_dbf_event(struct zfcp_adapter
*adapter
, const char *text
,
200 struct fsf_status_read_buffer
*status_buffer
, int length
)
205 debug_text_event(adapter
->in_els_dbf
, level
, text
);
206 debug_event(adapter
->in_els_dbf
, level
, &status_buffer
->d_id
, 8);
207 for (i
= 0; i
< length
; i
+= ZFCP_IN_ELS_DBF_LENGTH
)
208 debug_event(adapter
->in_els_dbf
,
210 (char *) status_buffer
->payload
+ i
,
211 min(ZFCP_IN_ELS_DBF_LENGTH
, length
- i
));
215 * zfcp_device_setup - setup function
216 * @str: pointer to parameter string
218 * Parse "device=..." parameter string.
221 zfcp_device_setup(char *devstr
)
229 len
= strlen(devstr
) + 1;
230 str
= (char *) kmalloc(len
, GFP_KERNEL
);
233 memcpy(str
, devstr
, len
);
235 tmp
= strchr(str
, ',');
239 strncpy(zfcp_data
.init_busid
, str
, BUS_ID_SIZE
);
240 zfcp_data
.init_busid
[BUS_ID_SIZE
-1] = '\0';
242 zfcp_data
.init_wwpn
= simple_strtoull(tmp
, &tmp
, 0);
248 zfcp_data
.init_fcp_lun
= simple_strtoull(tmp
, &tmp
, 0);
255 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str
);
261 zfcp_init_device_configure(void)
263 struct zfcp_adapter
*adapter
;
264 struct zfcp_port
*port
;
265 struct zfcp_unit
*unit
;
267 down(&zfcp_data
.config_sema
);
268 read_lock_irq(&zfcp_data
.config_lock
);
269 adapter
= zfcp_get_adapter_by_busid(zfcp_data
.init_busid
);
271 zfcp_adapter_get(adapter
);
272 read_unlock_irq(&zfcp_data
.config_lock
);
276 port
= zfcp_port_enqueue(adapter
, zfcp_data
.init_wwpn
, 0, 0);
279 unit
= zfcp_unit_enqueue(port
, zfcp_data
.init_fcp_lun
);
282 up(&zfcp_data
.config_sema
);
283 ccw_device_set_online(adapter
->ccw_device
);
284 zfcp_erp_wait(adapter
);
285 down(&zfcp_data
.config_sema
);
290 zfcp_adapter_put(adapter
);
292 up(&zfcp_data
.config_sema
);
297 zfcp_module_init(void)
302 atomic_set(&zfcp_data
.loglevel
, loglevel
);
304 /* initialize adapter list */
305 INIT_LIST_HEAD(&zfcp_data
.adapter_list_head
);
307 /* initialize adapters to be removed list head */
308 INIT_LIST_HEAD(&zfcp_data
.adapter_remove_lh
);
310 zfcp_transport_template
= fc_attach_transport(&zfcp_transport_functions
);
311 if (!zfcp_transport_template
)
314 retval
= misc_register(&zfcp_cfdc_misc
);
316 ZFCP_LOG_INFO("registration of misc device "
317 "zfcp_cfdc failed\n");
321 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
322 ZFCP_CFDC_DEV_MAJOR
, zfcp_cfdc_misc
.minor
);
324 /* Initialise proc semaphores */
325 sema_init(&zfcp_data
.config_sema
, 1);
327 /* initialise configuration rw lock */
328 rwlock_init(&zfcp_data
.config_lock
);
330 /* save address of data structure managing the driver module */
331 zfcp_data
.scsi_host_template
.module
= THIS_MODULE
;
333 /* setup dynamic I/O */
334 retval
= zfcp_ccw_register();
336 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
337 goto out_ccw_register
;
340 if (zfcp_device_setup(device
))
341 zfcp_init_device_configure();
346 misc_deregister(&zfcp_cfdc_misc
);
352 * function: zfcp_cfdc_dev_ioctl
354 * purpose: Handle control file upload/download transaction via IOCTL
357 * returns: 0 - Operation completed successfuly
358 * -ENOTTY - Unknown IOCTL command
359 * -EINVAL - Invalid sense data record
360 * -ENXIO - The FCP adapter is not available
361 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
362 * -ENOMEM - Insufficient memory
363 * -EFAULT - User space memory I/O operation fault
364 * -EPERM - Cannot create or queue FSF request or create SBALs
365 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
368 zfcp_cfdc_dev_ioctl(struct file
*file
, unsigned int command
,
369 unsigned long buffer
)
371 struct zfcp_cfdc_sense_data
*sense_data
, __user
*sense_data_user
;
372 struct zfcp_adapter
*adapter
= NULL
;
373 struct zfcp_fsf_req
*fsf_req
= NULL
;
374 struct zfcp_sg_list
*sg_list
= NULL
;
375 u32 fsf_command
, option
;
379 sense_data
= kmalloc(sizeof(struct zfcp_cfdc_sense_data
), GFP_KERNEL
);
380 if (sense_data
== NULL
) {
385 sg_list
= kmalloc(sizeof(struct zfcp_sg_list
), GFP_KERNEL
);
386 if (sg_list
== NULL
) {
390 memset(sg_list
, 0, sizeof(*sg_list
));
392 if (command
!= ZFCP_CFDC_IOC
) {
393 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command
);
398 if ((sense_data_user
= (void __user
*) buffer
) == NULL
) {
399 ZFCP_LOG_INFO("sense data record is required\n");
404 retval
= copy_from_user(sense_data
, sense_data_user
,
405 sizeof(struct zfcp_cfdc_sense_data
));
411 if (sense_data
->signature
!= ZFCP_CFDC_SIGNATURE
) {
412 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
413 ZFCP_CFDC_SIGNATURE
);
418 switch (sense_data
->command
) {
420 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL
:
421 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
422 option
= FSF_CFDC_OPTION_NORMAL_MODE
;
425 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE
:
426 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
427 option
= FSF_CFDC_OPTION_FORCE
;
430 case ZFCP_CFDC_CMND_FULL_ACCESS
:
431 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
432 option
= FSF_CFDC_OPTION_FULL_ACCESS
;
435 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS
:
436 fsf_command
= FSF_QTCB_DOWNLOAD_CONTROL_FILE
;
437 option
= FSF_CFDC_OPTION_RESTRICTED_ACCESS
;
440 case ZFCP_CFDC_CMND_UPLOAD
:
441 fsf_command
= FSF_QTCB_UPLOAD_CONTROL_FILE
;
446 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
447 sense_data
->command
);
452 bus_id
= kmalloc(BUS_ID_SIZE
, GFP_KERNEL
);
453 if (bus_id
== NULL
) {
457 snprintf(bus_id
, BUS_ID_SIZE
, "%d.%d.%04x",
458 (sense_data
->devno
>> 24),
459 (sense_data
->devno
>> 16) & 0xFF,
460 (sense_data
->devno
& 0xFFFF));
462 read_lock_irq(&zfcp_data
.config_lock
);
463 adapter
= zfcp_get_adapter_by_busid(bus_id
);
465 zfcp_adapter_get(adapter
);
466 read_unlock_irq(&zfcp_data
.config_lock
);
470 if (adapter
== NULL
) {
471 ZFCP_LOG_INFO("invalid adapter\n");
476 if (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
) {
477 retval
= zfcp_sg_list_alloc(sg_list
,
478 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
485 if ((sense_data
->command
& ZFCP_CFDC_DOWNLOAD
) &&
486 (sense_data
->command
& ZFCP_CFDC_WITH_CONTROL_FILE
)) {
487 retval
= zfcp_sg_list_copy_from_user(
488 sg_list
, &sense_data_user
->control_file
,
489 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
496 retval
= zfcp_fsf_control_file(adapter
, &fsf_req
, fsf_command
,
501 if ((fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_GOOD
) &&
502 (fsf_req
->qtcb
->prefix
.prot_status
!= FSF_PROT_FSF_STATUS_PRESENTED
)) {
507 sense_data
->fsf_status
= fsf_req
->qtcb
->header
.fsf_status
;
508 memcpy(&sense_data
->fsf_status_qual
,
509 &fsf_req
->qtcb
->header
.fsf_status_qual
,
510 sizeof(union fsf_status_qual
));
511 memcpy(&sense_data
->payloads
, &fsf_req
->qtcb
->bottom
.support
.els
, 256);
513 retval
= copy_to_user(sense_data_user
, sense_data
,
514 sizeof(struct zfcp_cfdc_sense_data
));
520 if (sense_data
->command
& ZFCP_CFDC_UPLOAD
) {
521 retval
= zfcp_sg_list_copy_to_user(
522 &sense_data_user
->control_file
, sg_list
,
523 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE
);
532 zfcp_fsf_req_free(fsf_req
);
534 if ((adapter
!= NULL
) && (retval
!= -ENXIO
))
535 zfcp_adapter_put(adapter
);
537 if (sg_list
!= NULL
) {
538 zfcp_sg_list_free(sg_list
);
542 if (sense_data
!= NULL
)
550 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
551 * @sg_list: structure describing a scatter gather list
552 * @size: size of scatter-gather list
553 * Return: 0 on success, else -ENOMEM
555 * In sg_list->sg a pointer to the created scatter-gather list is returned,
556 * or NULL if we run out of memory. sg_list->count specifies the number of
557 * elements of the scatter-gather list. The maximum size of a single element
558 * in the scatter-gather list is PAGE_SIZE.
561 zfcp_sg_list_alloc(struct zfcp_sg_list
*sg_list
, size_t size
)
563 struct scatterlist
*sg
;
568 BUG_ON(sg_list
== NULL
);
570 sg_list
->count
= size
>> PAGE_SHIFT
;
571 if (size
& ~PAGE_MASK
)
573 sg_list
->sg
= kmalloc(sg_list
->count
* sizeof(struct scatterlist
),
575 if (sg_list
->sg
== NULL
) {
580 memset(sg_list
->sg
, 0, sg_list
->count
* sizeof(struct scatterlist
));
582 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++) {
583 sg
->length
= min(size
, PAGE_SIZE
);
585 address
= (void *) get_zeroed_page(GFP_KERNEL
);
586 if (address
== NULL
) {
588 zfcp_sg_list_free(sg_list
);
592 zfcp_address_to_sg(address
, sg
);
602 * zfcp_sg_list_free - free memory of a scatter-gather list
603 * @sg_list: structure describing a scatter-gather list
605 * Memory for each element in the scatter-gather list is freed.
606 * Finally sg_list->sg is freed itself and sg_list->count is reset.
609 zfcp_sg_list_free(struct zfcp_sg_list
*sg_list
)
611 struct scatterlist
*sg
;
614 BUG_ON(sg_list
== NULL
);
616 for (i
= 0, sg
= sg_list
->sg
; i
< sg_list
->count
; i
++, sg
++)
617 free_page((unsigned long) zfcp_sg_to_address(sg
));
624 * zfcp_sg_size - determine size of a scatter-gather list
625 * @sg: array of (struct scatterlist)
626 * @sg_count: elements in array
627 * Return: size of entire scatter-gather list
630 zfcp_sg_size(struct scatterlist
*sg
, unsigned int sg_count
)
633 struct scatterlist
*p
;
637 for (i
= 0, p
= sg
; i
< sg_count
; i
++, p
++) {
647 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
648 * @sg_list: structure describing a scatter-gather list
649 * @user_buffer: pointer to buffer in user space
650 * @size: number of bytes to be copied
651 * Return: 0 on success, -EFAULT if copy_from_user fails.
654 zfcp_sg_list_copy_from_user(struct zfcp_sg_list
*sg_list
,
655 void __user
*user_buffer
,
658 struct scatterlist
*sg
;
663 BUG_ON(sg_list
== NULL
);
665 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
668 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
669 length
= min((unsigned int)size
, sg
->length
);
670 zfcp_buffer
= zfcp_sg_to_address(sg
);
671 if (copy_from_user(zfcp_buffer
, user_buffer
, length
)) {
675 user_buffer
+= length
;
685 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
686 * @user_buffer: pointer to buffer in user space
687 * @sg_list: structure describing a scatter-gather list
688 * @size: number of bytes to be copied
689 * Return: 0 on success, -EFAULT if copy_to_user fails
692 zfcp_sg_list_copy_to_user(void __user
*user_buffer
,
693 struct zfcp_sg_list
*sg_list
,
696 struct scatterlist
*sg
;
701 BUG_ON(sg_list
== NULL
);
703 if (zfcp_sg_size(sg_list
->sg
, sg_list
->count
) < size
)
706 for (sg
= sg_list
->sg
; size
> 0; sg
++) {
707 length
= min((unsigned int) size
, sg
->length
);
708 zfcp_buffer
= zfcp_sg_to_address(sg
);
709 if (copy_to_user(user_buffer
, zfcp_buffer
, length
)) {
713 user_buffer
+= length
;
724 /****************************************************************/
725 /****** Functions for configuration/set-up of structures ********/
726 /****************************************************************/
728 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
731 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
732 * @port: pointer to port to search for unit
733 * @fcp_lun: FCP LUN to search for
734 * Traverse list of all units of a port and return pointer to a unit
735 * with the given FCP LUN.
738 zfcp_get_unit_by_lun(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
740 struct zfcp_unit
*unit
;
743 list_for_each_entry(unit
, &port
->unit_list_head
, list
) {
744 if ((unit
->fcp_lun
== fcp_lun
) &&
745 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
))
751 return found
? unit
: NULL
;
755 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
756 * @adapter: pointer to adapter to search for port
757 * @wwpn: wwpn to search for
758 * Traverse list of all ports of an adapter and return pointer to a port
759 * with the given wwpn.
762 zfcp_get_port_by_wwpn(struct zfcp_adapter
*adapter
, wwn_t wwpn
)
764 struct zfcp_port
*port
;
767 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
768 if ((port
->wwpn
== wwpn
) &&
769 !(atomic_read(&port
->status
) &
770 (ZFCP_STATUS_PORT_NO_WWPN
| ZFCP_STATUS_COMMON_REMOVE
))) {
775 return found
? port
: NULL
;
779 * zfcp_get_port_by_did - find port in port list of adapter by d_id
780 * @adapter: pointer to adapter to search for port
781 * @d_id: d_id to search for
782 * Traverse list of all ports of an adapter and return pointer to a port
783 * with the given d_id.
786 zfcp_get_port_by_did(struct zfcp_adapter
*adapter
, u32 d_id
)
788 struct zfcp_port
*port
;
791 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
792 if ((port
->d_id
== d_id
) &&
793 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
))
799 return found
? port
: NULL
;
803 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
804 * @bus_id: bus_id to search for
805 * Traverse list of all adapters and return pointer to an adapter
806 * with the given bus_id.
808 struct zfcp_adapter
*
809 zfcp_get_adapter_by_busid(char *bus_id
)
811 struct zfcp_adapter
*adapter
;
814 list_for_each_entry(adapter
, &zfcp_data
.adapter_list_head
, list
) {
815 if ((strncmp(bus_id
, zfcp_get_busid_by_adapter(adapter
),
816 BUS_ID_SIZE
) == 0) &&
817 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
,
823 return found
? adapter
: NULL
;
827 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
828 * @port: pointer to port where unit is added
829 * @fcp_lun: FCP LUN of unit to be enqueued
830 * Return: pointer to enqueued unit on success, NULL on error
831 * Locks: config_sema must be held to serialize changes to the unit list
833 * Sets up some unit internal structures and creates sysfs entry.
836 zfcp_unit_enqueue(struct zfcp_port
*port
, fcp_lun_t fcp_lun
)
838 struct zfcp_unit
*unit
, *tmp_unit
;
843 * check that there is no unit with this FCP_LUN already in list
845 * Note: Unlike for the adapter and the port, this is an error
847 read_lock_irq(&zfcp_data
.config_lock
);
848 unit
= zfcp_get_unit_by_lun(port
, fcp_lun
);
849 read_unlock_irq(&zfcp_data
.config_lock
);
853 unit
= kmalloc(sizeof (struct zfcp_unit
), GFP_KERNEL
);
856 memset(unit
, 0, sizeof (struct zfcp_unit
));
858 /* initialise reference count stuff */
859 atomic_set(&unit
->refcount
, 0);
860 init_waitqueue_head(&unit
->remove_wq
);
863 unit
->fcp_lun
= fcp_lun
;
865 /* setup for sysfs registration */
866 snprintf(unit
->sysfs_device
.bus_id
, BUS_ID_SIZE
, "0x%016llx", fcp_lun
);
867 unit
->sysfs_device
.parent
= &port
->sysfs_device
;
868 unit
->sysfs_device
.release
= zfcp_sysfs_unit_release
;
869 dev_set_drvdata(&unit
->sysfs_device
, unit
);
871 /* mark unit unusable as long as sysfs registration is not complete */
872 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
874 if (device_register(&unit
->sysfs_device
)) {
879 if (zfcp_sysfs_unit_create_files(&unit
->sysfs_device
)) {
880 device_unregister(&unit
->sysfs_device
);
888 write_lock_irq(&zfcp_data
.config_lock
);
889 list_for_each_entry(tmp_unit
, &port
->unit_list_head
, list
) {
890 if (tmp_unit
->scsi_lun
!= scsi_lun
) {
896 unit
->scsi_lun
= scsi_lun
;
898 list_add_tail(&unit
->list
, &tmp_unit
->list
);
900 list_add_tail(&unit
->list
, &port
->unit_list_head
);
901 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &unit
->status
);
902 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &unit
->status
);
903 write_unlock_irq(&zfcp_data
.config_lock
);
912 zfcp_unit_dequeue(struct zfcp_unit
*unit
)
914 zfcp_unit_wait(unit
);
915 write_lock_irq(&zfcp_data
.config_lock
);
916 list_del(&unit
->list
);
917 write_unlock_irq(&zfcp_data
.config_lock
);
919 zfcp_port_put(unit
->port
);
920 zfcp_sysfs_unit_remove_files(&unit
->sysfs_device
);
921 device_unregister(&unit
->sysfs_device
);
925 zfcp_mempool_alloc(unsigned int __nocast gfp_mask
, void *size
)
927 return kmalloc((size_t) size
, gfp_mask
);
931 zfcp_mempool_free(void *element
, void *size
)
937 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
939 * It also genrates fcp-nameserver request/response buffer and unsolicited
940 * status read fsf_req buffers.
942 * locks: must only be called with zfcp_data.config_sema taken
945 zfcp_allocate_low_mem_buffers(struct zfcp_adapter
*adapter
)
947 adapter
->pool
.fsf_req_erp
=
948 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR
,
949 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
950 sizeof(struct zfcp_fsf_req_pool_element
));
952 if (NULL
== adapter
->pool
.fsf_req_erp
)
955 adapter
->pool
.fsf_req_scsi
=
956 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR
,
957 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
958 sizeof(struct zfcp_fsf_req_pool_element
));
960 if (NULL
== adapter
->pool
.fsf_req_scsi
)
963 adapter
->pool
.fsf_req_abort
=
964 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR
,
965 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
966 sizeof(struct zfcp_fsf_req_pool_element
));
968 if (NULL
== adapter
->pool
.fsf_req_abort
)
971 adapter
->pool
.fsf_req_status_read
=
972 mempool_create(ZFCP_POOL_STATUS_READ_NR
,
973 zfcp_mempool_alloc
, zfcp_mempool_free
,
974 (void *) sizeof(struct zfcp_fsf_req
));
976 if (NULL
== adapter
->pool
.fsf_req_status_read
)
979 adapter
->pool
.data_status_read
=
980 mempool_create(ZFCP_POOL_STATUS_READ_NR
,
981 zfcp_mempool_alloc
, zfcp_mempool_free
,
982 (void *) sizeof(struct fsf_status_read_buffer
));
984 if (NULL
== adapter
->pool
.data_status_read
)
987 adapter
->pool
.data_gid_pn
=
988 mempool_create(ZFCP_POOL_DATA_GID_PN_NR
,
989 zfcp_mempool_alloc
, zfcp_mempool_free
, (void *)
990 sizeof(struct zfcp_gid_pn_data
));
992 if (NULL
== adapter
->pool
.data_gid_pn
)
999 * zfcp_free_low_mem_buffers - free memory pools of an adapter
1000 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
1001 * locking: zfcp_data.config_sema must be held
1004 zfcp_free_low_mem_buffers(struct zfcp_adapter
*adapter
)
1006 if (adapter
->pool
.fsf_req_erp
)
1007 mempool_destroy(adapter
->pool
.fsf_req_erp
);
1008 if (adapter
->pool
.fsf_req_scsi
)
1009 mempool_destroy(adapter
->pool
.fsf_req_scsi
);
1010 if (adapter
->pool
.fsf_req_abort
)
1011 mempool_destroy(adapter
->pool
.fsf_req_abort
);
1012 if (adapter
->pool
.fsf_req_status_read
)
1013 mempool_destroy(adapter
->pool
.fsf_req_status_read
);
1014 if (adapter
->pool
.data_status_read
)
1015 mempool_destroy(adapter
->pool
.data_status_read
);
1016 if (adapter
->pool
.data_gid_pn
)
1017 mempool_destroy(adapter
->pool
.data_gid_pn
);
1021 * zfcp_adapter_debug_register - registers debug feature for an adapter
1022 * @adapter: pointer to adapter for which debug features should be registered
1023 * return: -ENOMEM on error, 0 otherwise
1026 zfcp_adapter_debug_register(struct zfcp_adapter
*adapter
)
1030 /* debug feature area which records SCSI command failures (hostbyte) */
1031 spin_lock_init(&adapter
->dbf_lock
);
1033 sprintf(dbf_name
, ZFCP_CMD_DBF_NAME
"%s",
1034 zfcp_get_busid_by_adapter(adapter
));
1035 adapter
->cmd_dbf
= debug_register(dbf_name
, ZFCP_CMD_DBF_INDEX
,
1037 ZFCP_CMD_DBF_LENGTH
);
1038 debug_register_view(adapter
->cmd_dbf
, &debug_hex_ascii_view
);
1039 debug_set_level(adapter
->cmd_dbf
, ZFCP_CMD_DBF_LEVEL
);
1041 /* debug feature area which records SCSI command aborts */
1042 sprintf(dbf_name
, ZFCP_ABORT_DBF_NAME
"%s",
1043 zfcp_get_busid_by_adapter(adapter
));
1044 adapter
->abort_dbf
= debug_register(dbf_name
, ZFCP_ABORT_DBF_INDEX
,
1045 ZFCP_ABORT_DBF_AREAS
,
1046 ZFCP_ABORT_DBF_LENGTH
);
1047 debug_register_view(adapter
->abort_dbf
, &debug_hex_ascii_view
);
1048 debug_set_level(adapter
->abort_dbf
, ZFCP_ABORT_DBF_LEVEL
);
1050 /* debug feature area which records incoming ELS commands */
1051 sprintf(dbf_name
, ZFCP_IN_ELS_DBF_NAME
"%s",
1052 zfcp_get_busid_by_adapter(adapter
));
1053 adapter
->in_els_dbf
= debug_register(dbf_name
, ZFCP_IN_ELS_DBF_INDEX
,
1054 ZFCP_IN_ELS_DBF_AREAS
,
1055 ZFCP_IN_ELS_DBF_LENGTH
);
1056 debug_register_view(adapter
->in_els_dbf
, &debug_hex_ascii_view
);
1057 debug_set_level(adapter
->in_els_dbf
, ZFCP_IN_ELS_DBF_LEVEL
);
1059 /* debug feature area which records erp events */
1060 sprintf(dbf_name
, ZFCP_ERP_DBF_NAME
"%s",
1061 zfcp_get_busid_by_adapter(adapter
));
1062 adapter
->erp_dbf
= debug_register(dbf_name
, ZFCP_ERP_DBF_INDEX
,
1064 ZFCP_ERP_DBF_LENGTH
);
1065 debug_register_view(adapter
->erp_dbf
, &debug_hex_ascii_view
);
1066 debug_set_level(adapter
->erp_dbf
, ZFCP_ERP_DBF_LEVEL
);
1068 if (!(adapter
->cmd_dbf
&& adapter
->abort_dbf
&&
1069 adapter
->in_els_dbf
&& adapter
->erp_dbf
)) {
1070 zfcp_adapter_debug_unregister(adapter
);
1079 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1080 * @adapter: pointer to adapter for which debug features should be unregistered
1083 zfcp_adapter_debug_unregister(struct zfcp_adapter
*adapter
)
1085 debug_unregister(adapter
->abort_dbf
);
1086 debug_unregister(adapter
->cmd_dbf
);
1087 debug_unregister(adapter
->erp_dbf
);
1088 debug_unregister(adapter
->in_els_dbf
);
1089 adapter
->abort_dbf
= NULL
;
1090 adapter
->cmd_dbf
= NULL
;
1091 adapter
->erp_dbf
= NULL
;
1092 adapter
->in_els_dbf
= NULL
;
1096 zfcp_dummy_release(struct device
*dev
)
1102 * Enqueues an adapter at the end of the adapter list in the driver data.
1103 * All adapter internal structures are set up.
1104 * Proc-fs entries are also created.
1106 * returns: 0 if a new adapter was successfully enqueued
1107 * ZFCP_KNOWN if an adapter with this devno was already present
1108 * -ENOMEM if alloc failed
1109 * locks: config_sema must be held to serialise changes to the adapter list
1111 struct zfcp_adapter
*
1112 zfcp_adapter_enqueue(struct ccw_device
*ccw_device
)
1115 struct zfcp_adapter
*adapter
;
1118 * Note: It is safe to release the list_lock, as any list changes
1119 * are protected by the config_sema, which must be held to get here
1122 /* try to allocate new adapter data structure (zeroed) */
1123 adapter
= kmalloc(sizeof (struct zfcp_adapter
), GFP_KERNEL
);
1125 ZFCP_LOG_INFO("error: allocation of base adapter "
1126 "structure failed\n");
1129 memset(adapter
, 0, sizeof (struct zfcp_adapter
));
1131 ccw_device
->handler
= NULL
;
1133 /* save ccw_device pointer */
1134 adapter
->ccw_device
= ccw_device
;
1136 retval
= zfcp_qdio_allocate_queues(adapter
);
1138 goto queues_alloc_failed
;
1140 retval
= zfcp_qdio_allocate(adapter
);
1142 goto qdio_allocate_failed
;
1144 retval
= zfcp_allocate_low_mem_buffers(adapter
);
1146 ZFCP_LOG_INFO("error: pool allocation failed\n");
1147 goto failed_low_mem_buffers
;
1150 /* initialise reference count stuff */
1151 atomic_set(&adapter
->refcount
, 0);
1152 init_waitqueue_head(&adapter
->remove_wq
);
1154 /* initialise list of ports */
1155 INIT_LIST_HEAD(&adapter
->port_list_head
);
1157 /* initialise list of ports to be removed */
1158 INIT_LIST_HEAD(&adapter
->port_remove_lh
);
1160 /* initialize list of fsf requests */
1161 spin_lock_init(&adapter
->fsf_req_list_lock
);
1162 INIT_LIST_HEAD(&adapter
->fsf_req_list_head
);
1164 /* initialize abort lock */
1165 rwlock_init(&adapter
->abort_lock
);
1167 /* initialise some erp stuff */
1168 init_waitqueue_head(&adapter
->erp_thread_wqh
);
1169 init_waitqueue_head(&adapter
->erp_done_wqh
);
1171 /* initialize lock of associated request queue */
1172 rwlock_init(&adapter
->request_queue
.queue_lock
);
1174 /* intitialise SCSI ER timer */
1175 init_timer(&adapter
->scsi_er_timer
);
1177 /* set FC service class used per default */
1178 adapter
->fc_service_class
= ZFCP_FC_SERVICE_CLASS_DEFAULT
;
1180 sprintf(adapter
->name
, "%s", zfcp_get_busid_by_adapter(adapter
));
1181 ASCEBC(adapter
->name
, strlen(adapter
->name
));
1183 /* mark adapter unusable as long as sysfs registration is not complete */
1184 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1186 adapter
->ccw_device
= ccw_device
;
1187 dev_set_drvdata(&ccw_device
->dev
, adapter
);
1189 if (zfcp_sysfs_adapter_create_files(&ccw_device
->dev
))
1192 adapter
->generic_services
.parent
= &adapter
->ccw_device
->dev
;
1193 adapter
->generic_services
.release
= zfcp_dummy_release
;
1194 snprintf(adapter
->generic_services
.bus_id
, BUS_ID_SIZE
,
1195 "generic_services");
1197 if (device_register(&adapter
->generic_services
))
1198 goto generic_services_failed
;
1200 /* put allocated adapter at list tail */
1201 write_lock_irq(&zfcp_data
.config_lock
);
1202 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
);
1203 list_add_tail(&adapter
->list
, &zfcp_data
.adapter_list_head
);
1204 write_unlock_irq(&zfcp_data
.config_lock
);
1206 zfcp_data
.adapters
++;
1210 generic_services_failed
:
1211 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1213 dev_set_drvdata(&ccw_device
->dev
, NULL
);
1214 failed_low_mem_buffers
:
1215 zfcp_free_low_mem_buffers(adapter
);
1216 if (qdio_free(ccw_device
) != 0)
1217 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1218 zfcp_get_busid_by_adapter(adapter
));
1219 qdio_allocate_failed
:
1220 zfcp_qdio_free_queues(adapter
);
1221 queues_alloc_failed
:
1229 * returns: 0 - struct zfcp_adapter data structure successfully removed
1230 * !0 - struct zfcp_adapter data structure could not be removed
1232 * locks: adapter list write lock is assumed to be held by caller
1233 * adapter->fsf_req_list_lock is taken and released within this
1234 * function and must not be held on entry
1237 zfcp_adapter_dequeue(struct zfcp_adapter
*adapter
)
1240 unsigned long flags
;
1242 device_unregister(&adapter
->generic_services
);
1243 zfcp_sysfs_adapter_remove_files(&adapter
->ccw_device
->dev
);
1244 dev_set_drvdata(&adapter
->ccw_device
->dev
, NULL
);
1245 /* sanity check: no pending FSF requests */
1246 spin_lock_irqsave(&adapter
->fsf_req_list_lock
, flags
);
1247 retval
= !list_empty(&adapter
->fsf_req_list_head
);
1248 spin_unlock_irqrestore(&adapter
->fsf_req_list_lock
, flags
);
1250 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1251 "%i requests outstanding\n",
1252 zfcp_get_busid_by_adapter(adapter
), adapter
,
1253 atomic_read(&adapter
->fsf_reqs_active
));
1258 /* remove specified adapter data structure from list */
1259 write_lock_irq(&zfcp_data
.config_lock
);
1260 list_del(&adapter
->list
);
1261 write_unlock_irq(&zfcp_data
.config_lock
);
1263 /* decrease number of adapters in list */
1264 zfcp_data
.adapters
--;
1266 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1267 "%i adapters still in list\n",
1268 zfcp_get_busid_by_adapter(adapter
),
1269 adapter
, zfcp_data
.adapters
);
1271 retval
= qdio_free(adapter
->ccw_device
);
1273 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1274 zfcp_get_busid_by_adapter(adapter
));
1276 zfcp_free_low_mem_buffers(adapter
);
1277 /* free memory of adapter data structure and queues */
1278 zfcp_qdio_free_queues(adapter
);
1279 ZFCP_LOG_TRACE("freeing adapter structure\n");
1286 * zfcp_port_enqueue - enqueue port to port list of adapter
1287 * @adapter: adapter where remote port is added
1288 * @wwpn: WWPN of the remote port to be enqueued
1289 * @status: initial status for the port
1290 * @d_id: destination id of the remote port to be enqueued
1291 * Return: pointer to enqueued port on success, NULL on error
1292 * Locks: config_sema must be held to serialize changes to the port list
1294 * All port internal structures are set up and the sysfs entry is generated.
1295 * d_id is used to enqueue ports with a well known address like the Directory
1296 * Service for nameserver lookup.
1299 zfcp_port_enqueue(struct zfcp_adapter
*adapter
, wwn_t wwpn
, u32 status
,
1302 struct zfcp_port
*port
;
1305 check_wwpn
= !(status
& ZFCP_STATUS_PORT_NO_WWPN
);
1307 * check that there is no port with this WWPN already in list
1310 read_lock_irq(&zfcp_data
.config_lock
);
1311 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
1312 read_unlock_irq(&zfcp_data
.config_lock
);
1317 port
= kmalloc(sizeof (struct zfcp_port
), GFP_KERNEL
);
1320 memset(port
, 0, sizeof (struct zfcp_port
));
1322 /* initialise reference count stuff */
1323 atomic_set(&port
->refcount
, 0);
1324 init_waitqueue_head(&port
->remove_wq
);
1326 INIT_LIST_HEAD(&port
->unit_list_head
);
1327 INIT_LIST_HEAD(&port
->unit_remove_lh
);
1329 port
->adapter
= adapter
;
1334 atomic_set_mask(status
, &port
->status
);
1336 /* setup for sysfs registration */
1337 if (status
& ZFCP_STATUS_PORT_WKA
) {
1339 case ZFCP_DID_DIRECTORY_SERVICE
:
1340 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1343 case ZFCP_DID_MANAGEMENT_SERVICE
:
1344 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1347 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE
:
1348 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1349 "key_distribution");
1351 case ZFCP_DID_ALIAS_SERVICE
:
1352 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1355 case ZFCP_DID_TIME_SERVICE
:
1356 snprintf(port
->sysfs_device
.bus_id
, BUS_ID_SIZE
,
1364 port
->sysfs_device
.parent
= &adapter
->generic_services
;
1366 snprintf(port
->sysfs_device
.bus_id
,
1367 BUS_ID_SIZE
, "0x%016llx", wwpn
);
1368 port
->sysfs_device
.parent
= &adapter
->ccw_device
->dev
;
1370 port
->sysfs_device
.release
= zfcp_sysfs_port_release
;
1371 dev_set_drvdata(&port
->sysfs_device
, port
);
1373 /* mark port unusable as long as sysfs registration is not complete */
1374 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1376 if (device_register(&port
->sysfs_device
)) {
1381 if (zfcp_sysfs_port_create_files(&port
->sysfs_device
, status
)) {
1382 device_unregister(&port
->sysfs_device
);
1386 zfcp_port_get(port
);
1388 write_lock_irq(&zfcp_data
.config_lock
);
1389 list_add_tail(&port
->list
, &adapter
->port_list_head
);
1390 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
1391 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
, &port
->status
);
1392 if (d_id
== ZFCP_DID_DIRECTORY_SERVICE
)
1393 if (!adapter
->nameserver_port
)
1394 adapter
->nameserver_port
= port
;
1396 write_unlock_irq(&zfcp_data
.config_lock
);
1398 zfcp_adapter_get(adapter
);
1404 zfcp_port_dequeue(struct zfcp_port
*port
)
1406 zfcp_port_wait(port
);
1407 write_lock_irq(&zfcp_data
.config_lock
);
1408 list_del(&port
->list
);
1409 port
->adapter
->ports
--;
1410 write_unlock_irq(&zfcp_data
.config_lock
);
1412 fc_remote_port_delete(port
->rport
);
1414 zfcp_adapter_put(port
->adapter
);
1415 zfcp_sysfs_port_remove_files(&port
->sysfs_device
,
1416 atomic_read(&port
->status
));
1417 device_unregister(&port
->sysfs_device
);
1420 /* Enqueues a nameserver port */
1422 zfcp_nameserver_enqueue(struct zfcp_adapter
*adapter
)
1424 struct zfcp_port
*port
;
1426 port
= zfcp_port_enqueue(adapter
, 0, ZFCP_STATUS_PORT_WKA
,
1427 ZFCP_DID_DIRECTORY_SERVICE
);
1429 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1430 "adapter %s failed\n",
1431 zfcp_get_busid_by_adapter(adapter
));
1434 zfcp_port_put(port
);
1439 #undef ZFCP_LOG_AREA
1441 /****************************************************************/
1442 /******* Fibre Channel Standard related Functions **************/
1443 /****************************************************************/
1445 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1448 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter
*adapter
,
1449 struct fsf_status_read_buffer
*status_buffer
)
1451 struct fcp_rscn_head
*fcp_rscn_head
;
1452 struct fcp_rscn_element
*fcp_rscn_element
;
1453 struct zfcp_port
*port
;
1457 unsigned long flags
;
1459 fcp_rscn_head
= (struct fcp_rscn_head
*) status_buffer
->payload
;
1460 fcp_rscn_element
= (struct fcp_rscn_element
*) status_buffer
->payload
;
1463 no_entries
= (fcp_rscn_head
->payload_len
/ 4);
1465 zfcp_in_els_dbf_event(adapter
, "##rscn", status_buffer
,
1466 fcp_rscn_head
->payload_len
);
1468 debug_text_event(adapter
->erp_dbf
, 1, "unsol_els_rscn:");
1469 for (i
= 1; i
< no_entries
; i
++) {
1470 /* skip head and start with 1st element */
1472 switch (fcp_rscn_element
->addr_format
) {
1473 case ZFCP_PORT_ADDRESS
:
1474 range_mask
= ZFCP_PORTS_RANGE_PORT
;
1476 case ZFCP_AREA_ADDRESS
:
1477 range_mask
= ZFCP_PORTS_RANGE_AREA
;
1479 case ZFCP_DOMAIN_ADDRESS
:
1480 range_mask
= ZFCP_PORTS_RANGE_DOMAIN
;
1482 case ZFCP_FABRIC_ADDRESS
:
1483 range_mask
= ZFCP_PORTS_RANGE_FABRIC
;
1486 ZFCP_LOG_INFO("incoming RSCN with unknown "
1487 "address format\n");
1490 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1491 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1492 if (atomic_test_mask
1493 (ZFCP_STATUS_PORT_WKA
, &port
->status
))
1495 /* Do we know this port? If not skip it. */
1496 if (!atomic_test_mask
1497 (ZFCP_STATUS_PORT_DID_DID
, &port
->status
)) {
1498 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1499 "port 0x%016Lx\n", port
->wwpn
);
1500 debug_text_event(adapter
->erp_dbf
, 1,
1501 "unsol_els_rscnu:");
1502 zfcp_erp_port_reopen(port
,
1503 ZFCP_STATUS_COMMON_ERP_FAILED
);
1508 * FIXME: race: d_id might being invalidated
1509 * (...DID_DID reset)
1511 if ((port
->d_id
& range_mask
)
1512 == (fcp_rscn_element
->nport_did
& range_mask
)) {
1513 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1514 fcp_rscn_element
->nport_did
);
1516 * Unfortunately, an RSCN does not specify the
1517 * type of change a target underwent. We assume
1518 * that it makes sense to reopen the link.
1519 * FIXME: Shall we try to find out more about
1520 * the target and link state before closing it?
1521 * How to accomplish this? (nameserver?)
1522 * Where would such code be put in?
1523 * (inside or outside erp)
1525 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1526 "port 0x%016Lx\n", port
->wwpn
);
1527 debug_text_event(adapter
->erp_dbf
, 1,
1528 "unsol_els_rscnk:");
1529 zfcp_test_link(port
);
1532 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1537 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter
*adapter
,
1538 struct fsf_status_read_buffer
*status_buffer
)
1540 logi
*els_logi
= (logi
*) status_buffer
->payload
;
1541 struct zfcp_port
*port
;
1542 unsigned long flags
;
1544 zfcp_in_els_dbf_event(adapter
, "##plogi", status_buffer
, 28);
1546 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1547 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1548 if (port
->wwpn
== (*(wwn_t
*) & els_logi
->nport_wwn
))
1551 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1553 if (!port
|| (port
->wwpn
!= (*(wwn_t
*) & els_logi
->nport_wwn
))) {
1554 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1555 "with d_id 0x%08x on adapter %s\n",
1556 status_buffer
->d_id
,
1557 zfcp_get_busid_by_adapter(adapter
));
1559 debug_text_event(adapter
->erp_dbf
, 1, "unsol_els_plogi:");
1560 debug_event(adapter
->erp_dbf
, 1, &els_logi
->nport_wwn
, 8);
1561 zfcp_erp_port_forced_reopen(port
, 0);
1566 zfcp_fsf_incoming_els_logo(struct zfcp_adapter
*adapter
,
1567 struct fsf_status_read_buffer
*status_buffer
)
1569 struct fcp_logo
*els_logo
= (struct fcp_logo
*) status_buffer
->payload
;
1570 struct zfcp_port
*port
;
1571 unsigned long flags
;
1573 zfcp_in_els_dbf_event(adapter
, "##logo", status_buffer
, 16);
1575 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1576 list_for_each_entry(port
, &adapter
->port_list_head
, list
) {
1577 if (port
->wwpn
== els_logo
->nport_wwpn
)
1580 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1582 if (!port
|| (port
->wwpn
!= els_logo
->nport_wwpn
)) {
1583 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1584 "with d_id 0x%08x on adapter %s\n",
1585 status_buffer
->d_id
,
1586 zfcp_get_busid_by_adapter(adapter
));
1588 debug_text_event(adapter
->erp_dbf
, 1, "unsol_els_logo:");
1589 debug_event(adapter
->erp_dbf
, 1, &els_logo
->nport_wwpn
, 8);
1590 zfcp_erp_port_forced_reopen(port
, 0);
1595 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter
*adapter
,
1596 struct fsf_status_read_buffer
*status_buffer
)
1598 zfcp_in_els_dbf_event(adapter
, "##undef", status_buffer
, 24);
1599 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1600 "for adapter %s\n", *(u32
*) (status_buffer
->payload
),
1601 zfcp_get_busid_by_adapter(adapter
));
1606 zfcp_fsf_incoming_els(struct zfcp_fsf_req
*fsf_req
)
1608 struct fsf_status_read_buffer
*status_buffer
;
1610 struct zfcp_adapter
*adapter
;
1612 status_buffer
= fsf_req
->data
.status_read
.buffer
;
1613 els_type
= *(u32
*) (status_buffer
->payload
);
1614 adapter
= fsf_req
->adapter
;
1616 if (els_type
== LS_PLOGI
)
1617 zfcp_fsf_incoming_els_plogi(adapter
, status_buffer
);
1618 else if (els_type
== LS_LOGO
)
1619 zfcp_fsf_incoming_els_logo(adapter
, status_buffer
);
1620 else if ((els_type
& 0xffff0000) == LS_RSCN
)
1621 /* we are only concerned with the command, not the length */
1622 zfcp_fsf_incoming_els_rscn(adapter
, status_buffer
);
1624 zfcp_fsf_incoming_els_unknown(adapter
, status_buffer
);
1629 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1630 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1631 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1634 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data
**gid_pn
, mempool_t
*pool
)
1636 struct zfcp_gid_pn_data
*data
;
1639 data
= mempool_alloc(pool
, GFP_ATOMIC
);
1640 if (likely(data
!= NULL
)) {
1641 data
->ct
.pool
= pool
;
1644 data
= kmalloc(sizeof(struct zfcp_gid_pn_data
), GFP_ATOMIC
);
1650 memset(data
, 0, sizeof(*data
));
1651 data
->ct
.req
= &data
->req
;
1652 data
->ct
.resp
= &data
->resp
;
1653 data
->ct
.req_count
= data
->ct
.resp_count
= 1;
1654 zfcp_address_to_sg(&data
->ct_iu_req
, &data
->req
);
1655 zfcp_address_to_sg(&data
->ct_iu_resp
, &data
->resp
);
1656 data
->req
.length
= sizeof(struct ct_iu_gid_pn_req
);
1657 data
->resp
.length
= sizeof(struct ct_iu_gid_pn_resp
);
1664 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1665 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1668 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data
*gid_pn
)
1670 if ((gid_pn
->ct
.pool
!= 0))
1671 mempool_free(gid_pn
, gid_pn
->ct
.pool
);
1679 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1680 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1683 zfcp_ns_gid_pn_request(struct zfcp_erp_action
*erp_action
)
1686 struct ct_iu_gid_pn_req
*ct_iu_req
;
1687 struct zfcp_gid_pn_data
*gid_pn
;
1688 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1690 ret
= zfcp_gid_pn_buffers_alloc(&gid_pn
, adapter
->pool
.data_gid_pn
);
1692 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1693 "request failed for adapter %s\n",
1694 zfcp_get_busid_by_adapter(adapter
));
1698 /* setup nameserver request */
1699 ct_iu_req
= zfcp_sg_to_address(gid_pn
->ct
.req
);
1700 ct_iu_req
->header
.revision
= ZFCP_CT_REVISION
;
1701 ct_iu_req
->header
.gs_type
= ZFCP_CT_DIRECTORY_SERVICE
;
1702 ct_iu_req
->header
.gs_subtype
= ZFCP_CT_NAME_SERVER
;
1703 ct_iu_req
->header
.options
= ZFCP_CT_SYNCHRONOUS
;
1704 ct_iu_req
->header
.cmd_rsp_code
= ZFCP_CT_GID_PN
;
1705 ct_iu_req
->header
.max_res_size
= ZFCP_CT_MAX_SIZE
;
1706 ct_iu_req
->wwpn
= erp_action
->port
->wwpn
;
1708 /* setup parameters for send generic command */
1709 gid_pn
->ct
.port
= adapter
->nameserver_port
;
1710 gid_pn
->ct
.handler
= zfcp_ns_gid_pn_handler
;
1711 gid_pn
->ct
.handler_data
= (unsigned long) gid_pn
;
1712 gid_pn
->ct
.timeout
= ZFCP_NS_GID_PN_TIMEOUT
;
1713 gid_pn
->ct
.timer
= &erp_action
->timer
;
1714 gid_pn
->port
= erp_action
->port
;
1716 ret
= zfcp_fsf_send_ct(&gid_pn
->ct
, adapter
->pool
.fsf_req_erp
,
1719 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1720 "failed for adapter %s\n",
1721 zfcp_get_busid_by_adapter(adapter
));
1723 zfcp_gid_pn_buffers_free(gid_pn
);
1731 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1732 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1734 static void zfcp_ns_gid_pn_handler(unsigned long data
)
1736 struct zfcp_port
*port
;
1737 struct zfcp_send_ct
*ct
;
1738 struct ct_iu_gid_pn_req
*ct_iu_req
;
1739 struct ct_iu_gid_pn_resp
*ct_iu_resp
;
1740 struct zfcp_gid_pn_data
*gid_pn
;
1743 gid_pn
= (struct zfcp_gid_pn_data
*) data
;
1744 port
= gid_pn
->port
;
1746 ct_iu_req
= zfcp_sg_to_address(ct
->req
);
1747 ct_iu_resp
= zfcp_sg_to_address(ct
->resp
);
1749 if (ct
->status
!= 0)
1752 if (zfcp_check_ct_response(&ct_iu_resp
->header
)) {
1753 /* FIXME: do we need some specific erp entry points */
1754 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN
, &port
->status
);
1758 if (ct_iu_req
->wwpn
!= port
->wwpn
) {
1759 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1760 "lookup does not match expected wwpn 0x%016Lx "
1761 "for adapter %s\n", ct_iu_req
->wwpn
, port
->wwpn
,
1762 zfcp_get_busid_by_port(port
));
1766 /* looks like a valid d_id */
1767 port
->d_id
= ct_iu_resp
->d_id
& ZFCP_DID_MASK
;
1768 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID
, &port
->status
);
1769 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1770 zfcp_get_busid_by_port(port
), port
->wwpn
, port
->d_id
);
1774 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1775 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_req
,
1776 sizeof(struct ct_iu_gid_pn_req
));
1777 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG
, (char *) ct_iu_resp
,
1778 sizeof(struct ct_iu_gid_pn_resp
));
1781 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1782 "0x%016Lx for adapter %s\n",
1783 port
->wwpn
, zfcp_get_busid_by_port(port
));
1785 zfcp_gid_pn_buffers_free(gid_pn
);
1789 /* reject CT_IU reason codes acc. to FC-GS-4 */
1790 static const struct zfcp_rc_entry zfcp_ct_rc
[] = {
1791 {0x01, "invalid command code"},
1792 {0x02, "invalid version level"},
1793 {0x03, "logical error"},
1794 {0x04, "invalid CT_IU size"},
1795 {0x05, "logical busy"},
1796 {0x07, "protocol error"},
1797 {0x09, "unable to perform command request"},
1798 {0x0b, "command not supported"},
1799 {0x0d, "server not available"},
1800 {0x0e, "session could not be established"},
1801 {0xff, "vendor specific error"},
1805 /* LS_RJT reason codes acc. to FC-FS */
1806 static const struct zfcp_rc_entry zfcp_ls_rjt_rc
[] = {
1807 {0x01, "invalid LS_Command code"},
1808 {0x03, "logical error"},
1809 {0x05, "logical busy"},
1810 {0x07, "protocol error"},
1811 {0x09, "unable to perform command request"},
1812 {0x0b, "command not supported"},
1813 {0x0e, "command already in progress"},
1814 {0xff, "vendor specific error"},
1818 /* reject reason codes according to FC-PH/FC-FS */
1819 static const struct zfcp_rc_entry zfcp_p_rjt_rc
[] = {
1820 {0x01, "invalid D_ID"},
1821 {0x02, "invalid S_ID"},
1822 {0x03, "Nx_Port not available, temporary"},
1823 {0x04, "Nx_Port not available, permament"},
1824 {0x05, "class not supported"},
1825 {0x06, "delimiter usage error"},
1826 {0x07, "TYPE not supported"},
1827 {0x08, "invalid Link_Control"},
1828 {0x09, "invalid R_CTL field"},
1829 {0x0a, "invalid F_CTL field"},
1830 {0x0b, "invalid OX_ID"},
1831 {0x0c, "invalid RX_ID"},
1832 {0x0d, "invalid SEQ_ID"},
1833 {0x0e, "invalid DF_CTL"},
1834 {0x0f, "invalid SEQ_CNT"},
1835 {0x10, "invalid parameter field"},
1836 {0x11, "exchange error"},
1837 {0x12, "protocol error"},
1838 {0x13, "incorrect length"},
1839 {0x14, "unsupported ACK"},
1840 {0x15, "class of service not supported by entity at FFFFFE"},
1841 {0x16, "login required"},
1842 {0x17, "excessive sequences attempted"},
1843 {0x18, "unable to establish exchange"},
1844 {0x1a, "fabric path not available"},
1845 {0x1b, "invalid VC_ID (class 4)"},
1846 {0x1c, "invalid CS_CTL field"},
1847 {0x1d, "insufficient resources for VC (class 4)"},
1848 {0x1f, "invalid class of service"},
1849 {0x20, "preemption request rejected"},
1850 {0x21, "preemption not enabled"},
1851 {0x22, "multicast error"},
1852 {0x23, "multicast error terminate"},
1853 {0x24, "process login required"},
1854 {0xff, "vendor specific reject"},
1859 * zfcp_rc_description - return description for given reaon code
1860 * @code: reason code
1861 * @rc_table: table of reason codes and descriptions
1863 static inline const char *
1864 zfcp_rc_description(u8 code
, const struct zfcp_rc_entry
*rc_table
)
1866 const char *descr
= "unknown reason code";
1869 if (code
== rc_table
->code
) {
1870 descr
= rc_table
->description
;
1874 } while (rc_table
->code
&& rc_table
->description
);
1880 * zfcp_check_ct_response - evaluate reason code for CT_IU
1881 * @rjt: response payload to an CT_IU request
1882 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1885 zfcp_check_ct_response(struct ct_hdr
*rjt
)
1887 if (rjt
->cmd_rsp_code
== ZFCP_CT_ACCEPT
)
1890 if (rjt
->cmd_rsp_code
!= ZFCP_CT_REJECT
) {
1891 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1892 "response code (0x%04hx)\n",
1897 ZFCP_LOG_INFO("Generic Service command rejected\n");
1898 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1899 zfcp_rc_description(rjt
->reason_code
, zfcp_ct_rc
),
1900 (u32
) rjt
->reason_code
, (u32
) rjt
->reason_code_expl
,
1901 (u32
) rjt
->vendor_unique
);
1907 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1908 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1909 * @rc_table: table of reason codes and descriptions
1912 zfcp_print_els_rjt(struct zfcp_ls_rjt_par
*rjt_par
,
1913 const struct zfcp_rc_entry
*rc_table
)
1915 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1916 zfcp_rc_description(rjt_par
->reason_code
, rc_table
),
1917 (u32
) rjt_par
->action
, (u32
) rjt_par
->reason_code
,
1918 (u32
) rjt_par
->reason_expl
, (u32
) rjt_par
->vendor_unique
);
1922 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1923 * @sq: status qualifier word
1924 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1925 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1928 zfcp_handle_els_rjt(u32 sq
, struct zfcp_ls_rjt_par
*rjt_par
)
1932 if (sq
== FSF_IOSTAT_NPORT_RJT
) {
1933 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1934 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1936 if (rjt_par
->reason_code
== 0x01)
1938 } else if (sq
== FSF_IOSTAT_FABRIC_RJT
) {
1939 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1940 zfcp_print_els_rjt(rjt_par
, zfcp_p_rjt_rc
);
1942 if (rjt_par
->reason_code
== 0x01)
1944 } else if (sq
== FSF_IOSTAT_LS_RJT
) {
1945 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1946 zfcp_print_els_rjt(rjt_par
, zfcp_ls_rjt_rc
);
1949 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq
);
1954 #undef ZFCP_LOG_AREA