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>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 /* this drivers version (do not edit !!! generated and updated by cvs) */
32 #define ZFCP_AUX_REVISION "$Revision: 1.129 $"
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);
49 static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
50 static inline void zfcp_sg_list_free(struct zfcp_sg_list *);
51 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *,
52 void __user *, size_t);
53 static inline int zfcp_sg_list_copy_to_user(void __user *,
54 struct zfcp_sg_list *, size_t);
56 static int zfcp_cfdc_dev_ioctl(struct inode *, struct file *,
57 unsigned int, unsigned long);
59 #define ZFCP_CFDC_IOC_MAGIC 0xDD
60 #define ZFCP_CFDC_IOC \
61 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
63 #ifdef CONFIG_S390_SUPPORT
64 static struct ioctl_trans zfcp_ioctl_trans = {ZFCP_CFDC_IOC, (void*) sys_ioctl};
67 static struct file_operations zfcp_cfdc_fops = {
68 .ioctl = zfcp_cfdc_dev_ioctl
71 static struct miscdevice zfcp_cfdc_misc = {
72 .minor = ZFCP_CFDC_DEV_MINOR,
73 .name = ZFCP_CFDC_DEV_NAME,
74 .fops = &zfcp_cfdc_fops
77 /*********************** KERNEL/MODULE PARAMETERS ***************************/
79 /* declare driver module init/cleanup functions */
80 module_init(zfcp_module_init);
82 MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, "
83 "Martin Peschke <mpeschke@de.ibm.com>, "
84 "Raimund Schroeder <raimund.schroeder@de.ibm.com>, "
85 "Wolfgang Taphorn <taphorn@de.ibm.com>, "
86 "Aron Zeh <arzeh@de.ibm.com>, "
87 "IBM Deutschland Entwicklung GmbH");
89 ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries");
90 MODULE_LICENSE("GPL");
92 module_param(device, charp, 0);
93 MODULE_PARM_DESC(device, "specify initial device");
95 module_param(loglevel, uint, 0);
96 MODULE_PARM_DESC(loglevel,
97 "log levels, 8 nibbles: "
98 "FC ERP QDIO CIO Config FSF SCSI Other, "
99 "levels: 0=none 1=normal 2=devel 3=trace");
101 #ifdef ZFCP_PRINT_FLAGS
103 module_param(flags_dump, uint, 0);
106 /****************************************************************/
107 /************** Functions without logging ***********************/
108 /****************************************************************/
111 _zfcp_hex_dump(char *addr, int count)
114 for (i = 0; i < count; i++) {
115 printk("%02x", addr[i]);
121 if (((i-1) % 32) != 31)
125 /****************************************************************/
126 /************** Uncategorised Functions *************************/
127 /****************************************************************/
129 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
132 zfcp_fsf_req_is_scsi_cmnd(struct zfcp_fsf_req *fsf_req)
134 return ((fsf_req->fsf_command == FSF_QTCB_FCP_CMND) &&
135 !(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT));
139 zfcp_cmd_dbf_event_fsf(const char *text, struct zfcp_fsf_req *fsf_req,
140 void *add_data, int add_length)
142 struct zfcp_adapter *adapter = fsf_req->adapter;
143 struct scsi_cmnd *scsi_cmnd;
148 write_lock_irqsave(&adapter->cmd_dbf_lock, flags);
149 if (zfcp_fsf_req_is_scsi_cmnd(fsf_req)) {
150 scsi_cmnd = fsf_req->data.send_fcp_command_task.scsi_cmnd;
151 debug_text_event(adapter->cmd_dbf, level, "fsferror");
152 debug_text_event(adapter->cmd_dbf, level, text);
153 debug_event(adapter->cmd_dbf, level, &fsf_req,
154 sizeof (unsigned long));
155 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
157 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
158 sizeof (unsigned long));
159 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
160 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
161 for (i = 0; i < add_length; i += ZFCP_CMD_DBF_LENGTH)
162 debug_event(adapter->cmd_dbf,
164 (char *) add_data + i,
165 min(ZFCP_CMD_DBF_LENGTH, add_length - i));
167 write_unlock_irqrestore(&adapter->cmd_dbf_lock, flags);
170 /* XXX additionally log unit if available */
171 /* ---> introduce new parameter for unit, see 2.4 code */
173 zfcp_cmd_dbf_event_scsi(const char *text, struct scsi_cmnd *scsi_cmnd)
175 struct zfcp_adapter *adapter;
176 union zfcp_req_data *req_data;
177 struct zfcp_fsf_req *fsf_req;
178 int level = ((host_byte(scsi_cmnd->result) != 0) ? 1 : 5);
181 adapter = (struct zfcp_adapter *) scsi_cmnd->device->host->hostdata[0];
182 req_data = (union zfcp_req_data *) scsi_cmnd->host_scribble;
183 fsf_req = (req_data ? req_data->send_fcp_command_task.fsf_req : NULL);
184 write_lock_irqsave(&adapter->cmd_dbf_lock, flags);
185 debug_text_event(adapter->cmd_dbf, level, "hostbyte");
186 debug_text_event(adapter->cmd_dbf, level, text);
187 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->result, sizeof (u32));
188 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
189 sizeof (unsigned long));
190 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
191 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
192 if (likely(fsf_req)) {
193 debug_event(adapter->cmd_dbf, level, &fsf_req,
194 sizeof (unsigned long));
195 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
198 debug_text_event(adapter->cmd_dbf, level, "");
199 debug_text_event(adapter->cmd_dbf, level, "");
201 write_unlock_irqrestore(&adapter->cmd_dbf_lock, flags);
205 zfcp_in_els_dbf_event(struct zfcp_adapter *adapter, const char *text,
206 struct fsf_status_read_buffer *status_buffer, int length)
211 debug_text_event(adapter->in_els_dbf, level, text);
212 debug_event(adapter->in_els_dbf, level, &status_buffer->d_id, 8);
213 for (i = 0; i < length; i += ZFCP_IN_ELS_DBF_LENGTH)
214 debug_event(adapter->in_els_dbf,
216 (char *) status_buffer->payload + i,
217 min(ZFCP_IN_ELS_DBF_LENGTH, length - i));
221 * zfcp_device_setup - setup function
222 * @str: pointer to parameter string
224 * Parse "device=..." parameter string.
227 zfcp_device_setup(char *str)
234 tmp = strchr(str, ',');
238 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
239 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
241 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
247 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
253 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
258 zfcp_init_device_configure(void)
260 struct zfcp_adapter *adapter;
261 struct zfcp_port *port;
262 struct zfcp_unit *unit;
264 down(&zfcp_data.config_sema);
265 read_lock_irq(&zfcp_data.config_lock);
266 adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
268 zfcp_adapter_get(adapter);
269 read_unlock_irq(&zfcp_data.config_lock);
273 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
276 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
279 up(&zfcp_data.config_sema);
280 ccw_device_set_online(adapter->ccw_device);
281 wait_event(unit->scsi_add_wq, atomic_read(&unit->scsi_add_work) == 0);
282 down(&zfcp_data.config_sema);
287 zfcp_adapter_put(adapter);
289 up(&zfcp_data.config_sema);
294 zfcp_module_init(void)
299 atomic_set(&zfcp_data.loglevel, loglevel);
301 /* initialize adapter list */
302 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
304 /* initialize adapters to be removed list head */
305 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
307 zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
308 if (!zfcp_transport_template)
311 #ifdef CONFIG_S390_SUPPORT
312 retval = register_ioctl32_conversion(zfcp_ioctl_trans.cmd,
313 zfcp_ioctl_trans.handler);
315 ZFCP_LOG_INFO("registration of ioctl32 conversion failed\n");
319 retval = misc_register(&zfcp_cfdc_misc);
321 ZFCP_LOG_INFO("registration of misc device "
322 "zfcp_cfdc failed\n");
323 goto out_misc_register;
325 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
326 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
329 /* Initialise proc semaphores */
330 sema_init(&zfcp_data.config_sema, 1);
332 /* initialise configuration rw lock */
333 rwlock_init(&zfcp_data.config_lock);
335 /* save address of data structure managing the driver module */
336 zfcp_data.scsi_host_template.module = THIS_MODULE;
338 /* setup dynamic I/O */
339 retval = zfcp_ccw_register();
341 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
342 goto out_ccw_register;
345 if (zfcp_device_setup(device))
346 zfcp_init_device_configure();
351 misc_deregister(&zfcp_cfdc_misc);
353 #ifdef CONFIG_S390_SUPPORT
354 unregister_ioctl32_conversion(zfcp_ioctl_trans.cmd);
363 * function: zfcp_cfdc_dev_ioctl
365 * purpose: Handle control file upload/download transaction via IOCTL
368 * returns: 0 - Operation completed successfuly
369 * -ENOTTY - Unknown IOCTL command
370 * -EINVAL - Invalid sense data record
371 * -ENXIO - The FCP adapter is not available
372 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
373 * -ENOMEM - Insufficient memory
374 * -EFAULT - User space memory I/O operation fault
375 * -EPERM - Cannot create or queue FSF request or create SBALs
376 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
379 zfcp_cfdc_dev_ioctl(struct inode *inode, struct file *file,
380 unsigned int command, unsigned long buffer)
382 struct zfcp_cfdc_sense_data *sense_data, __user *sense_data_user;
383 struct zfcp_adapter *adapter = NULL;
384 struct zfcp_fsf_req *fsf_req = NULL;
385 struct zfcp_sg_list *sg_list = NULL;
386 u32 fsf_command, option;
390 sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL);
391 if (sense_data == NULL) {
396 sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
397 if (sg_list == NULL) {
401 memset(sg_list, 0, sizeof(*sg_list));
403 if (command != ZFCP_CFDC_IOC) {
404 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
409 if ((sense_data_user = (void __user *) buffer) == NULL) {
410 ZFCP_LOG_INFO("sense data record is required\n");
415 retval = copy_from_user(sense_data, sense_data_user,
416 sizeof(struct zfcp_cfdc_sense_data));
422 if (sense_data->signature != ZFCP_CFDC_SIGNATURE) {
423 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
424 ZFCP_CFDC_SIGNATURE);
429 switch (sense_data->command) {
431 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
432 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
433 option = FSF_CFDC_OPTION_NORMAL_MODE;
436 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
437 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
438 option = FSF_CFDC_OPTION_FORCE;
441 case ZFCP_CFDC_CMND_FULL_ACCESS:
442 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
443 option = FSF_CFDC_OPTION_FULL_ACCESS;
446 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
447 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
448 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
451 case ZFCP_CFDC_CMND_UPLOAD:
452 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
457 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
458 sense_data->command);
463 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
464 if (bus_id == NULL) {
468 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
469 (sense_data->devno >> 24),
470 (sense_data->devno >> 16) & 0xFF,
471 (sense_data->devno & 0xFFFF));
473 read_lock_irq(&zfcp_data.config_lock);
474 adapter = zfcp_get_adapter_by_busid(bus_id);
476 zfcp_adapter_get(adapter);
477 read_unlock_irq(&zfcp_data.config_lock);
481 if (adapter == NULL) {
482 ZFCP_LOG_INFO("invalid adapter\n");
487 if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) {
488 retval = zfcp_sg_list_alloc(sg_list,
489 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
496 if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) &&
497 (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
498 retval = zfcp_sg_list_copy_from_user(
499 sg_list, &sense_data_user->control_file,
500 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
507 retval = zfcp_fsf_control_file(
508 adapter, &fsf_req, fsf_command, option, sg_list);
509 if (retval == -EOPNOTSUPP) {
510 ZFCP_LOG_INFO("adapter does not support cfdc\n");
512 } else if (retval != 0) {
513 ZFCP_LOG_INFO("initiation of cfdc up/download failed\n");
518 wait_event(fsf_req->completion_wq,
519 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
521 if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
522 (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
527 sense_data->fsf_status = fsf_req->qtcb->header.fsf_status;
528 memcpy(&sense_data->fsf_status_qual,
529 &fsf_req->qtcb->header.fsf_status_qual,
530 sizeof(union fsf_status_qual));
531 memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256);
533 retval = copy_to_user(sense_data_user, sense_data,
534 sizeof(struct zfcp_cfdc_sense_data));
540 if (sense_data->command & ZFCP_CFDC_UPLOAD) {
541 retval = zfcp_sg_list_copy_to_user(
542 &sense_data_user->control_file, sg_list,
543 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
552 zfcp_fsf_req_cleanup(fsf_req);
554 if ((adapter != NULL) && (retval != -ENXIO))
555 zfcp_adapter_put(adapter);
557 if (sg_list != NULL) {
558 zfcp_sg_list_free(sg_list);
562 if (sense_data != NULL)
570 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
571 * @sg_list: structure describing a scatter gather list
572 * @size: size of scatter-gather list
573 * Return: 0 on success, else -ENOMEM
575 * In sg_list->sg a pointer to the created scatter-gather list is returned,
576 * or NULL if we run out of memory. sg_list->count specifies the number of
577 * elements of the scatter-gather list. The maximum size of a single element
578 * in the scatter-gather list is PAGE_SIZE.
581 zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
583 struct scatterlist *sg;
588 BUG_ON(sg_list == NULL);
590 sg_list->count = size >> PAGE_SHIFT;
591 if (size & ~PAGE_MASK)
593 sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
595 if (sg_list->sg == NULL) {
601 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
602 sg->length = min(size, PAGE_SIZE);
604 address = (void *) get_zeroed_page(GFP_KERNEL);
605 zfcp_address_to_sg(address, sg);
606 if (sg->page == NULL) {
608 zfcp_sg_list_free(sg_list);
621 * zfcp_sg_list_free - free memory of a scatter-gather list
622 * @sg_list: structure describing a scatter-gather list
624 * Memory for each element in the scatter-gather list is freed.
625 * Finally sg_list->sg is freed itself and sg_list->count is reset.
628 zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
630 struct scatterlist *sg;
633 BUG_ON(sg_list == NULL);
635 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
636 __free_pages(sg->page, 0);
643 * zfcp_sg_size - determine size of a scatter-gather list
644 * @sg: array of (struct scatterlist)
645 * @sg_count: elements in array
646 * Return: size of entire scatter-gather list
649 zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
652 struct scatterlist *p;
656 for (i = 0, p = sg; i < sg_count; i++, p++) {
666 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
667 * @sg_list: structure describing a scatter-gather list
668 * @user_buffer: pointer to buffer in user space
669 * @size: number of bytes to be copied
670 * Return: 0 on success, -EFAULT if copy_from_user fails.
673 zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list,
674 void __user *user_buffer,
677 struct scatterlist *sg;
682 BUG_ON(sg_list == NULL);
684 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
687 for (sg = sg_list->sg; size > 0; sg++) {
688 length = min((unsigned int)size, sg->length);
689 zfcp_buffer = zfcp_sg_to_address(sg);
690 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
694 user_buffer += length;
704 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
705 * @user_buffer: pointer to buffer in user space
706 * @sg_list: structure describing a scatter-gather list
707 * @size: number of bytes to be copied
708 * Return: 0 on success, -EFAULT if copy_to_user fails
711 zfcp_sg_list_copy_to_user(void __user *user_buffer,
712 struct zfcp_sg_list *sg_list,
715 struct scatterlist *sg;
720 BUG_ON(sg_list == NULL);
722 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
725 for (sg = sg_list->sg; size > 0; sg++) {
726 length = min((unsigned int) size, sg->length);
727 zfcp_buffer = zfcp_sg_to_address(sg);
728 if (copy_to_user(user_buffer, zfcp_buffer, length)) {
732 user_buffer += length;
743 /****************************************************************/
744 /****** Functions for configuration/set-up of structures ********/
745 /****************************************************************/
747 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
750 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
751 * @port: pointer to port to search for unit
752 * @fcp_lun: FCP LUN to search for
753 * Traverse list of all units of a port and return pointer to a unit
754 * with the given FCP LUN.
757 zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
759 struct zfcp_unit *unit;
762 list_for_each_entry(unit, &port->unit_list_head, list) {
763 if ((unit->fcp_lun == fcp_lun) &&
764 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
770 return found ? unit : NULL;
774 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
775 * @adapter: pointer to adapter to search for port
776 * @wwpn: wwpn to search for
777 * Traverse list of all ports of an adapter and return pointer to a port
778 * with the given wwpn.
781 zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
783 struct zfcp_port *port;
786 list_for_each_entry(port, &adapter->port_list_head, list) {
787 if ((port->wwpn == wwpn) &&
788 !(atomic_read(&port->status) &
789 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
794 return found ? port : NULL;
798 * zfcp_get_port_by_did - find port in port list of adapter by d_id
799 * @adapter: pointer to adapter to search for port
800 * @d_id: d_id to search for
801 * Traverse list of all ports of an adapter and return pointer to a port
802 * with the given d_id.
805 zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
807 struct zfcp_port *port;
810 list_for_each_entry(port, &adapter->port_list_head, list) {
811 if ((port->d_id == d_id) &&
812 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
818 return found ? port : NULL;
822 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
823 * @bus_id: bus_id to search for
824 * Traverse list of all adapters and return pointer to an adapter
825 * with the given bus_id.
827 struct zfcp_adapter *
828 zfcp_get_adapter_by_busid(char *bus_id)
830 struct zfcp_adapter *adapter;
833 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
834 if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
835 BUS_ID_SIZE) == 0) &&
836 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
842 return found ? adapter : NULL;
846 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
847 * @port: pointer to port where unit is added
848 * @fcp_lun: FCP LUN of unit to be enqueued
849 * Return: pointer to enqueued unit on success, NULL on error
850 * Locks: config_sema must be held to serialize changes to the unit list
852 * Sets up some unit internal structures and creates sysfs entry.
855 zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
857 struct zfcp_unit *unit, *tmp_unit;
862 * check that there is no unit with this FCP_LUN already in list
864 * Note: Unlike for the adapter and the port, this is an error
866 read_lock_irq(&zfcp_data.config_lock);
867 unit = zfcp_get_unit_by_lun(port, fcp_lun);
868 read_unlock_irq(&zfcp_data.config_lock);
872 unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
875 memset(unit, 0, sizeof (struct zfcp_unit));
877 init_waitqueue_head(&unit->scsi_add_wq);
878 /* initialise reference count stuff */
879 atomic_set(&unit->refcount, 0);
880 init_waitqueue_head(&unit->remove_wq);
883 unit->fcp_lun = fcp_lun;
885 /* setup for sysfs registration */
886 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
887 unit->sysfs_device.parent = &port->sysfs_device;
888 unit->sysfs_device.release = zfcp_sysfs_unit_release;
889 dev_set_drvdata(&unit->sysfs_device, unit);
891 /* mark unit unusable as long as sysfs registration is not complete */
892 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
894 if (device_register(&unit->sysfs_device)) {
899 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
900 device_unregister(&unit->sysfs_device);
908 write_lock_irq(&zfcp_data.config_lock);
909 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
910 if (tmp_unit->scsi_lun != scsi_lun) {
916 unit->scsi_lun = scsi_lun;
918 list_add_tail(&unit->list, &tmp_unit->list);
920 list_add_tail(&unit->list, &port->unit_list_head);
921 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
922 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
923 write_unlock_irq(&zfcp_data.config_lock);
932 zfcp_unit_dequeue(struct zfcp_unit *unit)
934 zfcp_unit_wait(unit);
935 write_lock_irq(&zfcp_data.config_lock);
936 list_del(&unit->list);
937 write_unlock_irq(&zfcp_data.config_lock);
939 zfcp_port_put(unit->port);
940 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
941 device_unregister(&unit->sysfs_device);
945 zfcp_mempool_alloc(int gfp_mask, void *size)
947 return kmalloc((size_t) size, gfp_mask);
951 zfcp_mempool_free(void *element, void *size)
957 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
959 * It also genrates fcp-nameserver request/response buffer and unsolicited
960 * status read fsf_req buffers.
962 * locks: must only be called with zfcp_data.config_sema taken
965 zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
967 adapter->pool.fsf_req_erp =
968 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR,
969 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
970 sizeof(struct zfcp_fsf_req_pool_element));
972 if (NULL == adapter->pool.fsf_req_erp)
975 adapter->pool.fsf_req_scsi =
976 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR,
977 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
978 sizeof(struct zfcp_fsf_req_pool_element));
980 if (NULL == adapter->pool.fsf_req_scsi)
983 adapter->pool.fsf_req_abort =
984 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR,
985 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
986 sizeof(struct zfcp_fsf_req_pool_element));
988 if (NULL == adapter->pool.fsf_req_abort)
991 adapter->pool.fsf_req_status_read =
992 mempool_create(ZFCP_POOL_STATUS_READ_NR,
993 zfcp_mempool_alloc, zfcp_mempool_free,
994 (void *) sizeof(struct zfcp_fsf_req));
996 if (NULL == adapter->pool.fsf_req_status_read)
999 adapter->pool.data_status_read =
1000 mempool_create(ZFCP_POOL_STATUS_READ_NR,
1001 zfcp_mempool_alloc, zfcp_mempool_free,
1002 (void *) sizeof(struct fsf_status_read_buffer));
1004 if (NULL == adapter->pool.data_status_read)
1007 adapter->pool.data_gid_pn =
1008 mempool_create(ZFCP_POOL_DATA_GID_PN_NR,
1009 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
1010 sizeof(struct zfcp_gid_pn_data));
1012 if (NULL == adapter->pool.data_gid_pn)
1019 * zfcp_free_low_mem_buffers - free memory pools of an adapter
1020 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
1021 * locking: zfcp_data.config_sema must be held
1024 zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
1026 if (adapter->pool.fsf_req_erp)
1027 mempool_destroy(adapter->pool.fsf_req_erp);
1028 if (adapter->pool.fsf_req_scsi)
1029 mempool_destroy(adapter->pool.fsf_req_scsi);
1030 if (adapter->pool.fsf_req_abort)
1031 mempool_destroy(adapter->pool.fsf_req_abort);
1032 if (adapter->pool.fsf_req_status_read)
1033 mempool_destroy(adapter->pool.fsf_req_status_read);
1034 if (adapter->pool.data_status_read)
1035 mempool_destroy(adapter->pool.data_status_read);
1036 if (adapter->pool.data_gid_pn)
1037 mempool_destroy(adapter->pool.data_gid_pn);
1041 * zfcp_adapter_debug_register - registers debug feature for an adapter
1042 * @adapter: pointer to adapter for which debug features should be registered
1043 * return: -ENOMEM on error, 0 otherwise
1046 zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1050 /* debug feature area which records SCSI command failures (hostbyte) */
1051 rwlock_init(&adapter->cmd_dbf_lock);
1052 sprintf(dbf_name, ZFCP_CMD_DBF_NAME "%s",
1053 zfcp_get_busid_by_adapter(adapter));
1054 adapter->cmd_dbf = debug_register(dbf_name,
1057 ZFCP_CMD_DBF_LENGTH);
1058 debug_register_view(adapter->cmd_dbf, &debug_hex_ascii_view);
1059 debug_set_level(adapter->cmd_dbf, ZFCP_CMD_DBF_LEVEL);
1061 /* debug feature area which records SCSI command aborts */
1062 sprintf(dbf_name, ZFCP_ABORT_DBF_NAME "%s",
1063 zfcp_get_busid_by_adapter(adapter));
1064 adapter->abort_dbf = debug_register(dbf_name,
1065 ZFCP_ABORT_DBF_INDEX,
1066 ZFCP_ABORT_DBF_AREAS,
1067 ZFCP_ABORT_DBF_LENGTH);
1068 debug_register_view(adapter->abort_dbf, &debug_hex_ascii_view);
1069 debug_set_level(adapter->abort_dbf, ZFCP_ABORT_DBF_LEVEL);
1071 /* debug feature area which records SCSI command aborts */
1072 sprintf(dbf_name, ZFCP_IN_ELS_DBF_NAME "%s",
1073 zfcp_get_busid_by_adapter(adapter));
1074 adapter->in_els_dbf = debug_register(dbf_name,
1075 ZFCP_IN_ELS_DBF_INDEX,
1076 ZFCP_IN_ELS_DBF_AREAS,
1077 ZFCP_IN_ELS_DBF_LENGTH);
1078 debug_register_view(adapter->in_els_dbf, &debug_hex_ascii_view);
1079 debug_set_level(adapter->in_els_dbf, ZFCP_IN_ELS_DBF_LEVEL);
1082 /* debug feature area which records erp events */
1083 sprintf(dbf_name, ZFCP_ERP_DBF_NAME "%s",
1084 zfcp_get_busid_by_adapter(adapter));
1085 adapter->erp_dbf = debug_register(dbf_name,
1088 ZFCP_ERP_DBF_LENGTH);
1089 debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view);
1090 debug_set_level(adapter->erp_dbf, ZFCP_ERP_DBF_LEVEL);
1092 if (adapter->cmd_dbf && adapter->abort_dbf &&
1093 adapter->in_els_dbf && adapter->erp_dbf)
1096 zfcp_adapter_debug_unregister(adapter);
1101 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1102 * @adapter: pointer to adapter for which debug features should be unregistered
1105 zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1107 debug_unregister(adapter->erp_dbf);
1108 debug_unregister(adapter->cmd_dbf);
1109 debug_unregister(adapter->abort_dbf);
1110 debug_unregister(adapter->in_els_dbf);
1114 zfcp_dummy_release(struct device *dev)
1120 * Enqueues an adapter at the end of the adapter list in the driver data.
1121 * All adapter internal structures are set up.
1122 * Proc-fs entries are also created.
1124 * returns: 0 if a new adapter was successfully enqueued
1125 * ZFCP_KNOWN if an adapter with this devno was already present
1126 * -ENOMEM if alloc failed
1127 * locks: config_sema must be held to serialise changes to the adapter list
1129 struct zfcp_adapter *
1130 zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1133 struct zfcp_adapter *adapter;
1136 * Note: It is safe to release the list_lock, as any list changes
1137 * are protected by the config_sema, which must be held to get here
1140 /* try to allocate new adapter data structure (zeroed) */
1141 adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
1143 ZFCP_LOG_INFO("error: allocation of base adapter "
1144 "structure failed\n");
1147 memset(adapter, 0, sizeof (struct zfcp_adapter));
1149 ccw_device->handler = NULL;
1151 /* save ccw_device pointer */
1152 adapter->ccw_device = ccw_device;
1154 retval = zfcp_qdio_allocate_queues(adapter);
1156 goto queues_alloc_failed;
1158 retval = zfcp_qdio_allocate(adapter);
1160 goto qdio_allocate_failed;
1162 retval = zfcp_allocate_low_mem_buffers(adapter);
1164 ZFCP_LOG_INFO("error: pool allocation failed\n");
1165 goto failed_low_mem_buffers;
1168 /* initialise reference count stuff */
1169 atomic_set(&adapter->refcount, 0);
1170 init_waitqueue_head(&adapter->remove_wq);
1172 /* initialise list of ports */
1173 INIT_LIST_HEAD(&adapter->port_list_head);
1175 /* initialise list of ports to be removed */
1176 INIT_LIST_HEAD(&adapter->port_remove_lh);
1178 /* initialize list of fsf requests */
1179 rwlock_init(&adapter->fsf_req_list_lock);
1180 INIT_LIST_HEAD(&adapter->fsf_req_list_head);
1182 /* initialize abort lock */
1183 rwlock_init(&adapter->abort_lock);
1185 /* initialise some erp stuff */
1186 init_waitqueue_head(&adapter->erp_thread_wqh);
1187 init_waitqueue_head(&adapter->erp_done_wqh);
1189 /* initialize lock of associated request queue */
1190 rwlock_init(&adapter->request_queue.queue_lock);
1192 /* intitialise SCSI ER timer */
1193 init_timer(&adapter->scsi_er_timer);
1195 /* set FC service class used per default */
1196 adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1198 sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
1199 ASCEBC(adapter->name, strlen(adapter->name));
1201 /* mark adapter unusable as long as sysfs registration is not complete */
1202 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1204 adapter->ccw_device = ccw_device;
1205 dev_set_drvdata(&ccw_device->dev, adapter);
1207 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1210 adapter->generic_services.parent = &adapter->ccw_device->dev;
1211 adapter->generic_services.release = zfcp_dummy_release;
1212 snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
1213 "generic_services");
1215 if (device_register(&adapter->generic_services))
1216 goto generic_services_failed;
1218 /* put allocated adapter at list tail */
1219 write_lock_irq(&zfcp_data.config_lock);
1220 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1221 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1222 write_unlock_irq(&zfcp_data.config_lock);
1224 zfcp_data.adapters++;
1228 generic_services_failed:
1229 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1231 dev_set_drvdata(&ccw_device->dev, NULL);
1232 failed_low_mem_buffers:
1233 zfcp_free_low_mem_buffers(adapter);
1234 if (qdio_free(ccw_device) != 0)
1235 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1236 zfcp_get_busid_by_adapter(adapter));
1237 qdio_allocate_failed:
1238 zfcp_qdio_free_queues(adapter);
1239 queues_alloc_failed:
1247 * returns: 0 - struct zfcp_adapter data structure successfully removed
1248 * !0 - struct zfcp_adapter data structure could not be removed
1250 * locks: adapter list write lock is assumed to be held by caller
1251 * adapter->fsf_req_list_lock is taken and released within this
1252 * function and must not be held on entry
1255 zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1258 unsigned long flags;
1260 device_unregister(&adapter->generic_services);
1261 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1262 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1263 /* sanity check: no pending FSF requests */
1264 read_lock_irqsave(&adapter->fsf_req_list_lock, flags);
1265 retval = !list_empty(&adapter->fsf_req_list_head);
1266 read_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
1268 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1269 "%i requests outstanding\n",
1270 zfcp_get_busid_by_adapter(adapter), adapter,
1271 atomic_read(&adapter->fsf_reqs_active));
1276 /* remove specified adapter data structure from list */
1277 write_lock_irq(&zfcp_data.config_lock);
1278 list_del(&adapter->list);
1279 write_unlock_irq(&zfcp_data.config_lock);
1281 /* decrease number of adapters in list */
1282 zfcp_data.adapters--;
1284 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1285 "%i adapters still in list\n",
1286 zfcp_get_busid_by_adapter(adapter),
1287 adapter, zfcp_data.adapters);
1289 retval = qdio_free(adapter->ccw_device);
1291 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1292 zfcp_get_busid_by_adapter(adapter));
1294 zfcp_free_low_mem_buffers(adapter);
1295 /* free memory of adapter data structure and queues */
1296 zfcp_qdio_free_queues(adapter);
1297 ZFCP_LOG_TRACE("freeing adapter structure\n");
1304 * zfcp_port_enqueue - enqueue port to port list of adapter
1305 * @adapter: adapter where remote port is added
1306 * @wwpn: WWPN of the remote port to be enqueued
1307 * @status: initial status for the port
1308 * @d_id: destination id of the remote port to be enqueued
1309 * Return: pointer to enqueued port on success, NULL on error
1310 * Locks: config_sema must be held to serialize changes to the port list
1312 * All port internal structures are set up and the sysfs entry is generated.
1313 * d_id is used to enqueue ports with a well known address like the Directory
1314 * Service for nameserver lookup.
1317 zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
1320 struct zfcp_port *port, *tmp_port;
1325 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1328 * check that there is no port with this WWPN already in list
1331 read_lock_irq(&zfcp_data.config_lock);
1332 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1333 read_unlock_irq(&zfcp_data.config_lock);
1338 port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1341 memset(port, 0, sizeof (struct zfcp_port));
1343 /* initialise reference count stuff */
1344 atomic_set(&port->refcount, 0);
1345 init_waitqueue_head(&port->remove_wq);
1347 INIT_LIST_HEAD(&port->unit_list_head);
1348 INIT_LIST_HEAD(&port->unit_remove_lh);
1350 port->adapter = adapter;
1355 atomic_set_mask(status, &port->status);
1357 /* setup for sysfs registration */
1358 if (status & ZFCP_STATUS_PORT_WKA) {
1360 case ZFCP_DID_DIRECTORY_SERVICE:
1361 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1364 case ZFCP_DID_MANAGEMENT_SERVICE:
1365 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1368 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
1369 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1370 "key_distribution");
1372 case ZFCP_DID_ALIAS_SERVICE:
1373 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1376 case ZFCP_DID_TIME_SERVICE:
1377 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1385 port->sysfs_device.parent = &adapter->generic_services;
1387 snprintf(port->sysfs_device.bus_id,
1388 BUS_ID_SIZE, "0x%016llx", wwpn);
1389 port->sysfs_device.parent = &adapter->ccw_device->dev;
1391 port->sysfs_device.release = zfcp_sysfs_port_release;
1392 dev_set_drvdata(&port->sysfs_device, port);
1394 /* mark port unusable as long as sysfs registration is not complete */
1395 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1397 if (device_register(&port->sysfs_device)) {
1402 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1403 device_unregister(&port->sysfs_device);
1407 zfcp_port_get(port);
1411 write_lock_irq(&zfcp_data.config_lock);
1412 list_for_each_entry(tmp_port, &adapter->port_list_head, list) {
1413 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_SCSI_ID,
1416 if (tmp_port->scsi_id != scsi_id) {
1422 port->scsi_id = scsi_id;
1424 list_add_tail(&port->list, &tmp_port->list);
1426 list_add_tail(&port->list, &adapter->port_list_head);
1427 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1428 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1429 if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
1430 if (!adapter->nameserver_port)
1431 adapter->nameserver_port = port;
1433 write_unlock_irq(&zfcp_data.config_lock);
1435 zfcp_adapter_get(adapter);
1441 zfcp_port_dequeue(struct zfcp_port *port)
1443 zfcp_port_wait(port);
1444 write_lock_irq(&zfcp_data.config_lock);
1445 list_del(&port->list);
1446 port->adapter->ports--;
1447 write_unlock_irq(&zfcp_data.config_lock);
1448 zfcp_adapter_put(port->adapter);
1449 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1450 atomic_read(&port->status));
1451 device_unregister(&port->sysfs_device);
1454 /* Enqueues a nameserver port */
1456 zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1458 struct zfcp_port *port;
1460 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
1461 ZFCP_DID_DIRECTORY_SERVICE);
1463 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1464 "adapter %s failed\n",
1465 zfcp_get_busid_by_adapter(adapter));
1468 zfcp_port_put(port);
1473 #undef ZFCP_LOG_AREA
1475 /****************************************************************/
1476 /******* Fibre Channel Standard related Functions **************/
1477 /****************************************************************/
1479 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1482 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1483 struct fsf_status_read_buffer *status_buffer)
1485 struct fcp_rscn_head *fcp_rscn_head;
1486 struct fcp_rscn_element *fcp_rscn_element;
1487 struct zfcp_port *port;
1491 unsigned long flags;
1493 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1494 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1497 no_entries = (fcp_rscn_head->payload_len / 4);
1499 zfcp_in_els_dbf_event(adapter, "##rscn", status_buffer,
1500 fcp_rscn_head->payload_len);
1502 debug_text_event(adapter->erp_dbf, 1, "unsol_els_rscn:");
1503 for (i = 1; i < no_entries; i++) {
1504 /* skip head and start with 1st element */
1506 switch (fcp_rscn_element->addr_format) {
1507 case ZFCP_PORT_ADDRESS:
1508 ZFCP_LOG_FLAGS(1, "ZFCP_PORT_ADDRESS\n");
1509 range_mask = ZFCP_PORTS_RANGE_PORT;
1511 case ZFCP_AREA_ADDRESS:
1512 ZFCP_LOG_FLAGS(1, "ZFCP_AREA_ADDRESS\n");
1513 range_mask = ZFCP_PORTS_RANGE_AREA;
1515 case ZFCP_DOMAIN_ADDRESS:
1516 ZFCP_LOG_FLAGS(1, "ZFCP_DOMAIN_ADDRESS\n");
1517 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1519 case ZFCP_FABRIC_ADDRESS:
1520 ZFCP_LOG_FLAGS(1, "ZFCP_FABRIC_ADDRESS\n");
1521 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1524 ZFCP_LOG_INFO("incoming RSCN with unknown "
1525 "address format\n");
1528 read_lock_irqsave(&zfcp_data.config_lock, flags);
1529 list_for_each_entry(port, &adapter->port_list_head, list) {
1530 if (atomic_test_mask
1531 (ZFCP_STATUS_PORT_WKA, &port->status))
1533 /* Do we know this port? If not skip it. */
1534 if (!atomic_test_mask
1535 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1536 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1537 "port 0x%016Lx\n", port->wwpn);
1538 debug_text_event(adapter->erp_dbf, 1,
1539 "unsol_els_rscnu:");
1540 zfcp_erp_port_reopen(port,
1541 ZFCP_STATUS_COMMON_ERP_FAILED);
1546 * FIXME: race: d_id might being invalidated
1547 * (...DID_DID reset)
1549 if ((port->d_id & range_mask)
1550 == (fcp_rscn_element->nport_did & range_mask)) {
1551 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1552 fcp_rscn_element->nport_did);
1554 * Unfortunately, an RSCN does not specify the
1555 * type of change a target underwent. We assume
1556 * that it makes sense to reopen the link.
1557 * FIXME: Shall we try to find out more about
1558 * the target and link state before closing it?
1559 * How to accomplish this? (nameserver?)
1560 * Where would such code be put in?
1561 * (inside or outside erp)
1563 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1564 "port 0x%016Lx\n", port->wwpn);
1565 debug_text_event(adapter->erp_dbf, 1,
1566 "unsol_els_rscnk:");
1567 zfcp_test_link(port);
1570 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1575 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1576 struct fsf_status_read_buffer *status_buffer)
1578 logi *els_logi = (logi *) status_buffer->payload;
1579 struct zfcp_port *port;
1580 unsigned long flags;
1582 zfcp_in_els_dbf_event(adapter, "##plogi", status_buffer, 28);
1584 read_lock_irqsave(&zfcp_data.config_lock, flags);
1585 list_for_each_entry(port, &adapter->port_list_head, list) {
1586 if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
1589 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1591 if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
1592 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1593 "with d_id 0x%08x on adapter %s\n",
1594 status_buffer->d_id,
1595 zfcp_get_busid_by_adapter(adapter));
1597 debug_text_event(adapter->erp_dbf, 1, "unsol_els_plogi:");
1598 debug_event(adapter->erp_dbf, 1, &els_logi->nport_wwn, 8);
1599 zfcp_erp_port_forced_reopen(port, 0);
1604 zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1605 struct fsf_status_read_buffer *status_buffer)
1607 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1608 struct zfcp_port *port;
1609 unsigned long flags;
1611 zfcp_in_els_dbf_event(adapter, "##logo", status_buffer, 16);
1613 read_lock_irqsave(&zfcp_data.config_lock, flags);
1614 list_for_each_entry(port, &adapter->port_list_head, list) {
1615 if (port->wwpn == els_logo->nport_wwpn)
1618 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1620 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1621 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1622 "with d_id 0x%08x on adapter %s\n",
1623 status_buffer->d_id,
1624 zfcp_get_busid_by_adapter(adapter));
1626 debug_text_event(adapter->erp_dbf, 1, "unsol_els_logo:");
1627 debug_event(adapter->erp_dbf, 1, &els_logo->nport_wwpn, 8);
1628 zfcp_erp_port_forced_reopen(port, 0);
1633 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
1634 struct fsf_status_read_buffer *status_buffer)
1636 zfcp_in_els_dbf_event(adapter, "##undef", status_buffer, 24);
1637 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1638 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1639 zfcp_get_busid_by_adapter(adapter));
1644 zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1646 struct fsf_status_read_buffer *status_buffer;
1648 struct zfcp_adapter *adapter;
1650 status_buffer = fsf_req->data.status_read.buffer;
1651 els_type = *(u32 *) (status_buffer->payload);
1652 adapter = fsf_req->adapter;
1654 if (els_type == LS_PLOGI)
1655 zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
1656 else if (els_type == LS_LOGO)
1657 zfcp_fsf_incoming_els_logo(adapter, status_buffer);
1658 else if ((els_type & 0xffff0000) == LS_RSCN)
1659 /* we are only concerned with the command, not the length */
1660 zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
1662 zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
1668 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1669 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1670 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1673 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1675 struct zfcp_gid_pn_data *data;
1678 data = mempool_alloc(pool, GFP_ATOMIC);
1679 if (likely(data != NULL)) {
1680 data->ct.pool = pool;
1683 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1689 memset(data, 0, sizeof(*data));
1690 data->ct.req = &data->req;
1691 data->ct.resp = &data->resp;
1692 data->ct.req_count = data->ct.resp_count = 1;
1693 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1694 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1695 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1696 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1703 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1704 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1707 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1709 if ((gid_pn->ct.pool != 0))
1710 mempool_free(gid_pn, gid_pn->ct.pool);
1718 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1719 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1722 zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1725 struct ct_iu_gid_pn_req *ct_iu_req;
1726 struct zfcp_gid_pn_data *gid_pn;
1727 struct zfcp_adapter *adapter = erp_action->adapter;
1729 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1731 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1732 "request failed for adapter %s\n",
1733 zfcp_get_busid_by_adapter(adapter));
1737 /* setup nameserver request */
1738 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1739 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1740 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1741 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1742 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1743 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1744 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1745 ct_iu_req->wwpn = erp_action->port->wwpn;
1747 /* setup parameters for send generic command */
1748 gid_pn->ct.port = adapter->nameserver_port;
1749 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1750 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1751 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1752 gid_pn->ct.timer = &erp_action->timer;
1753 gid_pn->port = erp_action->port;
1755 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1758 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1759 "failed for adapter %s\n",
1760 zfcp_get_busid_by_adapter(adapter));
1762 zfcp_gid_pn_buffers_free(gid_pn);
1770 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1771 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1773 static void zfcp_ns_gid_pn_handler(unsigned long data)
1775 struct zfcp_port *port;
1776 struct zfcp_send_ct *ct;
1777 struct ct_iu_gid_pn_req *ct_iu_req;
1778 struct ct_iu_gid_pn_resp *ct_iu_resp;
1779 struct zfcp_gid_pn_data *gid_pn;
1782 gid_pn = (struct zfcp_gid_pn_data *) data;
1783 port = gid_pn->port;
1785 ct_iu_req = zfcp_sg_to_address(ct->req);
1786 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1791 if (zfcp_check_ct_response(&ct_iu_resp->header)) {
1792 /* FIXME: do we need some specific erp entry points */
1793 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1797 if (ct_iu_req->wwpn != port->wwpn) {
1798 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1799 "lookup does not match expected wwpn 0x%016Lx "
1800 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1801 zfcp_get_busid_by_port(port));
1805 /* looks like a valid d_id */
1806 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1807 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1808 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1809 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1813 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1814 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1815 sizeof(struct ct_iu_gid_pn_req));
1816 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1817 sizeof(struct ct_iu_gid_pn_resp));
1820 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1821 "0x%016Lx for adapter %s\n",
1822 port->wwpn, zfcp_get_busid_by_port(port));
1824 zfcp_gid_pn_buffers_free(gid_pn);
1828 /* reject CT_IU reason codes acc. to FC-GS-4 */
1829 static const struct zfcp_rc_entry zfcp_ct_rc[] = {
1830 {0x01, "invalid command code"},
1831 {0x02, "invalid version level"},
1832 {0x03, "logical error"},
1833 {0x04, "invalid CT_IU size"},
1834 {0x05, "logical busy"},
1835 {0x07, "protocol error"},
1836 {0x09, "unable to perform command request"},
1837 {0x0b, "command not supported"},
1838 {0x0d, "server not available"},
1839 {0x0e, "session could not be established"},
1840 {0xff, "vendor specific error"},
1844 /* LS_RJT reason codes acc. to FC-FS */
1845 static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = {
1846 {0x01, "invalid LS_Command code"},
1847 {0x03, "logical error"},
1848 {0x05, "logical busy"},
1849 {0x07, "protocol error"},
1850 {0x09, "unable to perform command request"},
1851 {0x0b, "command not supported"},
1852 {0x0e, "command already in progress"},
1853 {0xff, "vendor specific error"},
1857 /* reject reason codes according to FC-PH/FC-FS */
1858 static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = {
1859 {0x01, "invalid D_ID"},
1860 {0x02, "invalid S_ID"},
1861 {0x03, "Nx_Port not available, temporary"},
1862 {0x04, "Nx_Port not available, permament"},
1863 {0x05, "class not supported"},
1864 {0x06, "delimiter usage error"},
1865 {0x07, "TYPE not supported"},
1866 {0x08, "invalid Link_Control"},
1867 {0x09, "invalid R_CTL field"},
1868 {0x0a, "invalid F_CTL field"},
1869 {0x0b, "invalid OX_ID"},
1870 {0x0c, "invalid RX_ID"},
1871 {0x0d, "invalid SEQ_ID"},
1872 {0x0e, "invalid DF_CTL"},
1873 {0x0f, "invalid SEQ_CNT"},
1874 {0x10, "invalid parameter field"},
1875 {0x11, "exchange error"},
1876 {0x12, "protocol error"},
1877 {0x13, "incorrect length"},
1878 {0x14, "unsupported ACK"},
1879 {0x15, "class of service not supported by entity at FFFFFE"},
1880 {0x16, "login required"},
1881 {0x17, "excessive sequences attempted"},
1882 {0x18, "unable to establish exchange"},
1883 {0x1a, "fabric path not available"},
1884 {0x1b, "invalid VC_ID (class 4)"},
1885 {0x1c, "invalid CS_CTL field"},
1886 {0x1d, "insufficient resources for VC (class 4)"},
1887 {0x1f, "invalid class of service"},
1888 {0x20, "preemption request rejected"},
1889 {0x21, "preemption not enabled"},
1890 {0x22, "multicast error"},
1891 {0x23, "multicast error terminate"},
1892 {0x24, "process login required"},
1893 {0xff, "vendor specific reject"},
1898 * zfcp_rc_description - return description for given reaon code
1899 * @code: reason code
1900 * @rc_table: table of reason codes and descriptions
1902 static inline const char *
1903 zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table)
1905 const char *descr = "unknown reason code";
1908 if (code == rc_table->code) {
1909 descr = rc_table->description;
1913 } while (rc_table->code && rc_table->description);
1919 * zfcp_check_ct_response - evaluate reason code for CT_IU
1920 * @rjt: response payload to an CT_IU request
1921 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1924 zfcp_check_ct_response(struct ct_hdr *rjt)
1926 if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT)
1929 if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) {
1930 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1931 "response code (0x%04hx)\n",
1936 ZFCP_LOG_INFO("Generic Service command rejected\n");
1937 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1938 zfcp_rc_description(rjt->reason_code, zfcp_ct_rc),
1939 (u32) rjt->reason_code, (u32) rjt->reason_code_expl,
1940 (u32) rjt->vendor_unique);
1946 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1947 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1948 * @rc_table: table of reason codes and descriptions
1951 zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par,
1952 const struct zfcp_rc_entry *rc_table)
1954 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1955 zfcp_rc_description(rjt_par->reason_code, rc_table),
1956 (u32) rjt_par->action, (u32) rjt_par->reason_code,
1957 (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique);
1961 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1962 * @sq: status qualifier word
1963 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1964 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1967 zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par)
1971 if (sq == FSF_IOSTAT_NPORT_RJT) {
1972 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1973 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1975 if (rjt_par->reason_code == 0x01)
1977 } else if (sq == FSF_IOSTAT_FABRIC_RJT) {
1978 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1979 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1981 if (rjt_par->reason_code == 0x01)
1983 } else if (sq == FSF_IOSTAT_LS_RJT) {
1984 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1985 zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc);
1988 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq);
1993 #undef ZFCP_LOG_AREA