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.114 $"
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);
44 int zfcp_reboot_handler(struct notifier_block *, unsigned long, void *);
47 static void zfcp_ns_gid_pn_handler(unsigned long);
51 static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
52 static inline int zfcp_sg_list_free(struct zfcp_sg_list *);
53 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *, void *,
55 static inline int zfcp_sg_list_copy_to_user(void *, struct zfcp_sg_list *,
58 static int zfcp_cfdc_dev_ioctl(struct inode *, struct file *,
59 unsigned int, unsigned long);
61 #define ZFCP_CFDC_IOC_MAGIC 0xDD
62 #define ZFCP_CFDC_IOC \
63 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
65 #ifdef CONFIG_S390_SUPPORT
66 static struct ioctl_trans zfcp_ioctl_trans = {ZFCP_CFDC_IOC, (void*) sys_ioctl};
69 static struct file_operations zfcp_cfdc_fops = {
70 .ioctl = zfcp_cfdc_dev_ioctl
73 static struct miscdevice zfcp_cfdc_misc = {
74 .minor = ZFCP_CFDC_DEV_MINOR,
75 .name = ZFCP_CFDC_DEV_NAME,
76 .fops = &zfcp_cfdc_fops
79 /*********************** KERNEL/MODULE PARAMETERS ***************************/
81 /* declare driver module init/cleanup functions */
82 module_init(zfcp_module_init);
84 MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, "
85 "Martin Peschke <mpeschke@de.ibm.com>, "
86 "Raimund Schroeder <raimund.schroeder@de.ibm.com>, "
87 "Wolfgang Taphorn <taphorn@de.ibm.com>, "
88 "Aron Zeh <arzeh@de.ibm.com>, "
89 "IBM Deutschland Entwicklung GmbH");
91 ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries");
92 MODULE_LICENSE("GPL");
94 module_param(device, charp, 0);
95 MODULE_PARM_DESC(device, "specify initial device");
97 module_param(loglevel, uint, 0);
98 MODULE_PARM_DESC(loglevel,
99 "log levels, 8 nibbles: "
100 "(unassigned) ERP QDIO DIO Config FSF SCSI Other, "
101 "levels: 0=none 1=normal 2=devel 3=trace");
103 #ifdef ZFCP_PRINT_FLAGS
105 module_param(flags_dump, uint, 0);
108 /****************************************************************/
109 /************** Functions without logging ***********************/
110 /****************************************************************/
113 _zfcp_hex_dump(char *addr, int count)
116 for (i = 0; i < count; i++) {
117 printk("%02x", addr[i]);
123 if (((i-1) % 32) != 31)
127 /****************************************************************/
128 /************** Uncategorised Functions *************************/
129 /****************************************************************/
131 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
134 zfcp_fsf_req_is_scsi_cmnd(struct zfcp_fsf_req *fsf_req)
136 return ((fsf_req->fsf_command == FSF_QTCB_FCP_CMND) &&
137 !(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT));
141 zfcp_cmd_dbf_event_fsf(const char *text, struct zfcp_fsf_req *fsf_req,
142 void *add_data, int add_length)
144 struct zfcp_adapter *adapter = fsf_req->adapter;
145 struct scsi_cmnd *scsi_cmnd;
150 write_lock_irqsave(&adapter->cmd_dbf_lock, flags);
151 if (zfcp_fsf_req_is_scsi_cmnd(fsf_req)) {
152 scsi_cmnd = fsf_req->data.send_fcp_command_task.scsi_cmnd;
153 debug_text_event(adapter->cmd_dbf, level, "fsferror");
154 debug_text_event(adapter->cmd_dbf, level, text);
155 debug_event(adapter->cmd_dbf, level, &fsf_req,
156 sizeof (unsigned long));
157 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
159 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
160 sizeof (unsigned long));
161 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
162 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
163 for (i = 0; i < add_length; i += ZFCP_CMD_DBF_LENGTH)
164 debug_event(adapter->cmd_dbf,
166 (char *) add_data + i,
167 min(ZFCP_CMD_DBF_LENGTH, add_length - i));
169 write_unlock_irqrestore(&adapter->cmd_dbf_lock, flags);
172 /* XXX additionally log unit if available */
173 /* ---> introduce new parameter for unit, see 2.4 code */
175 zfcp_cmd_dbf_event_scsi(const char *text, struct scsi_cmnd *scsi_cmnd)
177 struct zfcp_adapter *adapter;
178 union zfcp_req_data *req_data;
179 struct zfcp_fsf_req *fsf_req;
180 int level = ((host_byte(scsi_cmnd->result) != 0) ? 1 : 5);
183 adapter = (struct zfcp_adapter *) scsi_cmnd->device->host->hostdata[0];
184 req_data = (union zfcp_req_data *) scsi_cmnd->host_scribble;
185 fsf_req = (req_data ? req_data->send_fcp_command_task.fsf_req : NULL);
186 write_lock_irqsave(&adapter->cmd_dbf_lock, flags);
187 debug_text_event(adapter->cmd_dbf, level, "hostbyte");
188 debug_text_event(adapter->cmd_dbf, level, text);
189 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->result, sizeof (u32));
190 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
191 sizeof (unsigned long));
192 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
193 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
194 if (likely(fsf_req)) {
195 debug_event(adapter->cmd_dbf, level, &fsf_req,
196 sizeof (unsigned long));
197 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
200 debug_text_event(adapter->cmd_dbf, level, "");
201 debug_text_event(adapter->cmd_dbf, level, "");
203 write_unlock_irqrestore(&adapter->cmd_dbf_lock, flags);
207 zfcp_in_els_dbf_event(struct zfcp_adapter *adapter, const char *text,
208 struct fsf_status_read_buffer *status_buffer, int length)
213 debug_text_event(adapter->in_els_dbf, level, text);
214 debug_event(adapter->in_els_dbf, level, &status_buffer->d_id, 8);
215 for (i = 0; i < length; i += ZFCP_IN_ELS_DBF_LENGTH)
216 debug_event(adapter->in_els_dbf,
218 (char *) status_buffer->payload + i,
219 min(ZFCP_IN_ELS_DBF_LENGTH, length - i));
223 * zfcp_device_setup - setup function
224 * @str: pointer to parameter string
226 * Parse "device=..." parameter string.
229 zfcp_device_setup(char *str)
236 tmp = strchr(str, ',');
240 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
241 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
243 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
249 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
255 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
260 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 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list)
270 if (strcmp(zfcp_data.init_busid,
271 zfcp_get_busid_by_adapter(adapter)) == 0) {
272 zfcp_adapter_get(adapter);
276 read_unlock_irq(&zfcp_data.config_lock);
279 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0);
282 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
285 up(&zfcp_data.config_sema);
286 ccw_device_set_online(adapter->ccw_device);
287 wait_event(unit->scsi_add_wq, atomic_read(&unit->scsi_add_work) == 0);
288 down(&zfcp_data.config_sema);
293 zfcp_adapter_put(adapter);
295 up(&zfcp_data.config_sema);
300 zfcp_module_init(void)
305 atomic_set(&zfcp_data.loglevel, loglevel);
307 /* initialize adapter list */
308 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
310 /* initialize adapters to be removed list head */
311 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
313 zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
314 if (!zfcp_transport_template)
317 #ifdef CONFIG_S390_SUPPORT
318 retval = register_ioctl32_conversion(zfcp_ioctl_trans.cmd,
319 zfcp_ioctl_trans.handler);
321 ZFCP_LOG_INFO("registration of ioctl32 conversion failed\n");
325 retval = misc_register(&zfcp_cfdc_misc);
327 ZFCP_LOG_INFO("registration of misc device "
328 "zfcp_cfdc failed\n");
329 goto out_misc_register;
331 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
332 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
335 /* Initialise proc semaphores */
336 sema_init(&zfcp_data.config_sema, 1);
338 /* initialise configuration rw lock */
339 rwlock_init(&zfcp_data.config_lock);
341 zfcp_data.reboot_notifier.notifier_call = zfcp_reboot_handler;
342 register_reboot_notifier(&zfcp_data.reboot_notifier);
344 /* save address of data structure managing the driver module */
345 zfcp_data.scsi_host_template.module = THIS_MODULE;
347 /* setup dynamic I/O */
348 retval = zfcp_ccw_register();
350 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
351 goto out_ccw_register;
354 if (zfcp_device_setup(device))
355 zfcp_init_device_configure();
360 unregister_reboot_notifier(&zfcp_data.reboot_notifier);
361 misc_deregister(&zfcp_cfdc_misc);
363 #ifdef CONFIG_S390_SUPPORT
364 unregister_ioctl32_conversion(zfcp_ioctl_trans.cmd);
373 * This function is called automatically by the kernel whenever a reboot or a
374 * shut-down is initiated and zfcp is still loaded
376 * locks: zfcp_data.config_sema is taken prior to shutting down the module
377 * and removing all structures
378 * returns: NOTIFY_DONE in all cases
381 zfcp_reboot_handler(struct notifier_block *notifier, unsigned long code,
384 zfcp_ccw_unregister();
390 * function: zfcp_cfdc_dev_ioctl
392 * purpose: Handle control file upload/download transaction via IOCTL
395 * returns: 0 - Operation completed successfuly
396 * -ENOTTY - Unknown IOCTL command
397 * -EINVAL - Invalid sense data record
398 * -ENXIO - The FCP adapter is not available
399 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
400 * -ENOMEM - Insufficient memory
401 * -EFAULT - User space memory I/O operation fault
402 * -EPERM - Cannot create or queue FSF request or create SBALs
405 zfcp_cfdc_dev_ioctl(struct inode *inode, struct file *file,
406 unsigned int command, unsigned long buffer)
408 struct zfcp_cfdc_sense_data sense_data, *sense_data_user;
409 struct zfcp_adapter *adapter = NULL;
410 struct zfcp_fsf_req *fsf_req = NULL;
411 struct zfcp_sg_list *sg_list = NULL;
412 u32 fsf_command, option;
416 sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
417 if (sg_list == NULL) {
421 memset(sg_list, 0, sizeof(*sg_list));
423 if (command != ZFCP_CFDC_IOC) {
424 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
429 if ((sense_data_user = (struct zfcp_cfdc_sense_data*)buffer) == NULL) {
430 ZFCP_LOG_INFO("sense data record is required\n");
435 retval = copy_from_user(&sense_data, sense_data_user,
436 sizeof(struct zfcp_cfdc_sense_data));
442 if (sense_data.signature != ZFCP_CFDC_SIGNATURE) {
443 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
444 ZFCP_CFDC_SIGNATURE);
449 switch (sense_data.command) {
451 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
452 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
453 option = FSF_CFDC_OPTION_NORMAL_MODE;
456 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
457 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
458 option = FSF_CFDC_OPTION_FORCE;
461 case ZFCP_CFDC_CMND_FULL_ACCESS:
462 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
463 option = FSF_CFDC_OPTION_FULL_ACCESS;
466 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
467 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
468 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
471 case ZFCP_CFDC_CMND_UPLOAD:
472 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
477 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
483 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
484 if (bus_id == NULL) {
488 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
489 (sense_data.devno >> 24),
490 (sense_data.devno >> 16) & 0xFF,
491 (sense_data.devno & 0xFFFF));
494 read_lock_irq(&zfcp_data.config_lock);
495 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
496 if (strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
498 zfcp_adapter_get(adapter);
503 read_unlock_irq(&zfcp_data.config_lock);
508 ZFCP_LOG_INFO("invalid adapter\n");
512 if (sense_data.command & ZFCP_CFDC_WITH_CONTROL_FILE) {
513 retval = zfcp_sg_list_alloc(sg_list,
514 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
521 if ((sense_data.command & ZFCP_CFDC_DOWNLOAD) &&
522 (sense_data.command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
523 retval = zfcp_sg_list_copy_from_user(
524 sg_list, &sense_data_user->control_file,
525 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
532 retval = zfcp_fsf_control_file(
533 adapter, &fsf_req, fsf_command, option, sg_list);
534 if (retval == -EOPNOTSUPP) {
535 ZFCP_LOG_INFO("adapter does not support cfdc\n");
537 } else if (retval != 0) {
538 ZFCP_LOG_INFO("initiation of cfdc up/download failed\n");
543 wait_event(fsf_req->completion_wq,
544 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
546 sense_data.fsf_status = fsf_req->qtcb->header.fsf_status;
547 memcpy(&sense_data.fsf_status_qual,
548 &fsf_req->qtcb->header.fsf_status_qual,
549 sizeof(union fsf_status_qual));
550 memcpy(&sense_data.payloads, &fsf_req->qtcb->bottom.support.els, 256);
552 retval = copy_to_user(sense_data_user, &sense_data,
553 sizeof(struct zfcp_cfdc_sense_data));
559 if (sense_data.command & ZFCP_CFDC_UPLOAD) {
560 retval = zfcp_sg_list_copy_to_user(
561 &sense_data_user->control_file, sg_list,
562 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
571 zfcp_fsf_req_cleanup(fsf_req);
573 if ((adapter != NULL) && (retval != -ENXIO))
574 zfcp_adapter_put(adapter);
576 if (sg_list != NULL) {
577 zfcp_sg_list_free(sg_list);
586 * function: zfcp_sg_list_alloc
588 * purpose: Create a scatter-gather list of the specified size
590 * returns: 0 - Scatter gather list is created
591 * -ENOMEM - Insufficient memory (*list_ptr is then set to NULL)
594 zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
596 struct scatterlist *sg;
600 sg_list->count = size >> PAGE_SHIFT;
601 if (size & ~PAGE_MASK)
603 sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
605 if (sg_list->sg == NULL) {
611 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
612 sg->length = min(size, PAGE_SIZE);
614 sg->page = alloc_pages(GFP_KERNEL, 0);
615 if (sg->page == NULL) {
617 zfcp_sg_list_free(sg_list);
630 * function: zfcp_sg_list_free
632 * purpose: Destroy a scatter-gather list and release memory
637 zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
639 struct scatterlist *sg;
643 BUG_ON(sg_list == NULL);
645 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
646 __free_pages(sg->page, 0);
655 * function: zfcp_sg_list_copy_from_user
657 * purpose: Copy data from user space memory to the scatter-gather list
659 * returns: 0 - The data has been copied from user
660 * -EFAULT - Memory I/O operation fault
663 zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list, void *user_buffer,
666 struct scatterlist *sg;
671 for (sg = sg_list->sg; size > 0; sg++) {
672 length = min((unsigned int)size, sg->length);
673 zfcp_buffer = (void*)
674 ((page_to_pfn(sg->page) << PAGE_SHIFT) + sg->offset);
675 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
679 user_buffer += length;
689 * function: zfcp_sg_list_copy_to_user
691 * purpose: Copy data from the scatter-gather list to user space memory
693 * returns: 0 - The data has been copied to user
694 * -EFAULT - Memory I/O operation fault
697 zfcp_sg_list_copy_to_user(void *user_buffer, struct zfcp_sg_list *sg_list,
700 struct scatterlist *sg;
705 for (sg = sg_list->sg; size > 0; sg++) {
706 length = min((unsigned int)size, sg->length);
707 zfcp_buffer = (void*)
708 ((page_to_pfn(sg->page) << PAGE_SHIFT) + sg->offset);
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: lun to search for
734 * Traverses list of all units of a port and returns pointer to a unit
735 * if lun of a unit matches.
739 zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
741 struct zfcp_unit *unit;
744 list_for_each_entry(unit, &port->unit_list_head, list) {
745 if ((unit->fcp_lun == fcp_lun) &&
746 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
752 return found ? unit : NULL;
756 * zfcp_get_port_by_wwpn - find unit in unit list of port by fcp lun
757 * @adapter: pointer to adapter to search for port
758 * @wwpn: wwpn to search for
759 * Traverses list of all ports of an adapter and returns a pointer to a port
760 * if wwpn of a port matches.
764 zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
766 struct zfcp_port *port;
769 list_for_each_entry(port, &adapter->port_list_head, list) {
770 if ((port->wwpn == wwpn) &&
771 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
777 return found ? port : NULL;
781 * Enqueues a logical unit at the end of the unit list associated with the
782 * specified port. Also sets up some unit internal structures.
784 * returns: pointer to unit with a usecount of 1 if a new unit was
785 * successfully enqueued
787 * locks: config_sema must be held to serialise changes to the unit list
790 zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
792 struct zfcp_unit *unit, *tmp_unit;
797 * check that there is no unit with this FCP_LUN already in list
799 * Note: Unlike for the adapter and the port, this is an error
801 read_lock_irq(&zfcp_data.config_lock);
802 unit = zfcp_get_unit_by_lun(port, fcp_lun);
803 read_unlock_irq(&zfcp_data.config_lock);
807 unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
810 memset(unit, 0, sizeof (struct zfcp_unit));
812 init_waitqueue_head(&unit->scsi_add_wq);
813 /* initialise reference count stuff */
814 atomic_set(&unit->refcount, 0);
815 init_waitqueue_head(&unit->remove_wq);
818 unit->fcp_lun = fcp_lun;
820 /* setup for sysfs registration */
821 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
822 unit->sysfs_device.parent = &port->sysfs_device;
823 unit->sysfs_device.release = zfcp_sysfs_unit_release;
824 dev_set_drvdata(&unit->sysfs_device, unit);
826 /* mark unit unusable as long as sysfs registration is not complete */
827 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
829 if (device_register(&unit->sysfs_device)) {
834 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
835 device_unregister(&unit->sysfs_device);
843 write_lock_irq(&zfcp_data.config_lock);
844 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
845 if (tmp_unit->scsi_lun != scsi_lun) {
851 unit->scsi_lun = scsi_lun;
853 list_add_tail(&unit->list, &tmp_unit->list);
855 list_add_tail(&unit->list, &port->unit_list_head);
856 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
857 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
858 write_unlock_irq(&zfcp_data.config_lock);
867 zfcp_unit_dequeue(struct zfcp_unit *unit)
869 zfcp_unit_wait(unit);
870 write_lock_irq(&zfcp_data.config_lock);
871 list_del(&unit->list);
872 write_unlock_irq(&zfcp_data.config_lock);
874 zfcp_port_put(unit->port);
875 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
876 device_unregister(&unit->sysfs_device);
880 zfcp_mempool_alloc(int gfp_mask, void *size)
882 return kmalloc((size_t) size, gfp_mask);
886 zfcp_mempool_free(void *element, void *size)
892 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
894 * It also genrates fcp-nameserver request/response buffer and unsolicited
895 * status read fsf_req buffers.
897 * locks: must only be called with zfcp_data.config_sema taken
900 zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
902 adapter->pool.fsf_req_erp =
903 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR,
904 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
905 sizeof(struct zfcp_fsf_req_pool_element));
907 if (NULL == adapter->pool.fsf_req_erp)
910 adapter->pool.fsf_req_scsi =
911 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR,
912 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
913 sizeof(struct zfcp_fsf_req_pool_element));
915 if (NULL == adapter->pool.fsf_req_scsi)
918 adapter->pool.fsf_req_abort =
919 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR,
920 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
921 sizeof(struct zfcp_fsf_req_pool_element));
923 if (NULL == adapter->pool.fsf_req_abort)
926 adapter->pool.fsf_req_status_read =
927 mempool_create(ZFCP_POOL_STATUS_READ_NR,
928 zfcp_mempool_alloc, zfcp_mempool_free,
929 (void *) sizeof(struct zfcp_fsf_req));
931 if (NULL == adapter->pool.fsf_req_status_read)
934 adapter->pool.data_status_read =
935 mempool_create(ZFCP_POOL_STATUS_READ_NR,
936 zfcp_mempool_alloc, zfcp_mempool_free,
937 (void *) sizeof(struct fsf_status_read_buffer));
939 if (NULL == adapter->pool.data_status_read)
942 adapter->pool.data_gid_pn =
943 mempool_create(ZFCP_POOL_DATA_GID_PN_NR,
944 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
945 sizeof(struct zfcp_gid_pn_data));
947 if (NULL == adapter->pool.data_gid_pn)
954 * zfcp_free_low_mem_buffers - free memory pools of an adapter
955 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
956 * locking: zfcp_data.config_sema must be held
959 zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
961 if (adapter->pool.fsf_req_erp)
962 mempool_destroy(adapter->pool.fsf_req_erp);
963 if (adapter->pool.fsf_req_scsi)
964 mempool_destroy(adapter->pool.fsf_req_scsi);
965 if (adapter->pool.fsf_req_abort)
966 mempool_destroy(adapter->pool.fsf_req_abort);
967 if (adapter->pool.fsf_req_status_read)
968 mempool_destroy(adapter->pool.fsf_req_status_read);
969 if (adapter->pool.data_status_read)
970 mempool_destroy(adapter->pool.data_status_read);
971 if (adapter->pool.data_gid_pn)
972 mempool_destroy(adapter->pool.data_gid_pn);
976 * zfcp_adapter_debug_register - registers debug feature for an adapter
977 * @adapter: pointer to adapter for which debug features should be registered
978 * return: -ENOMEM on error, 0 otherwise
981 zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
985 /* debug feature area which records SCSI command failures (hostbyte) */
986 rwlock_init(&adapter->cmd_dbf_lock);
987 sprintf(dbf_name, ZFCP_CMD_DBF_NAME "%s",
988 zfcp_get_busid_by_adapter(adapter));
989 adapter->cmd_dbf = debug_register(dbf_name,
992 ZFCP_CMD_DBF_LENGTH);
993 debug_register_view(adapter->cmd_dbf, &debug_hex_ascii_view);
994 debug_set_level(adapter->cmd_dbf, ZFCP_CMD_DBF_LEVEL);
996 /* debug feature area which records SCSI command aborts */
997 sprintf(dbf_name, ZFCP_ABORT_DBF_NAME "%s",
998 zfcp_get_busid_by_adapter(adapter));
999 adapter->abort_dbf = debug_register(dbf_name,
1000 ZFCP_ABORT_DBF_INDEX,
1001 ZFCP_ABORT_DBF_AREAS,
1002 ZFCP_ABORT_DBF_LENGTH);
1003 debug_register_view(adapter->abort_dbf, &debug_hex_ascii_view);
1004 debug_set_level(adapter->abort_dbf, ZFCP_ABORT_DBF_LEVEL);
1006 /* debug feature area which records SCSI command aborts */
1007 sprintf(dbf_name, ZFCP_IN_ELS_DBF_NAME "%s",
1008 zfcp_get_busid_by_adapter(adapter));
1009 adapter->in_els_dbf = debug_register(dbf_name,
1010 ZFCP_IN_ELS_DBF_INDEX,
1011 ZFCP_IN_ELS_DBF_AREAS,
1012 ZFCP_IN_ELS_DBF_LENGTH);
1013 debug_register_view(adapter->in_els_dbf, &debug_hex_ascii_view);
1014 debug_set_level(adapter->in_els_dbf, ZFCP_IN_ELS_DBF_LEVEL);
1017 /* debug feature area which records erp events */
1018 sprintf(dbf_name, ZFCP_ERP_DBF_NAME "%s",
1019 zfcp_get_busid_by_adapter(adapter));
1020 adapter->erp_dbf = debug_register(dbf_name,
1023 ZFCP_ERP_DBF_LENGTH);
1024 debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view);
1025 debug_set_level(adapter->erp_dbf, ZFCP_ERP_DBF_LEVEL);
1027 if (adapter->cmd_dbf && adapter->abort_dbf &&
1028 adapter->in_els_dbf && adapter->erp_dbf)
1031 zfcp_adapter_debug_unregister(adapter);
1036 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1037 * @adapter: pointer to adapter for which debug features should be unregistered
1040 zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1042 debug_unregister(adapter->erp_dbf);
1043 debug_unregister(adapter->cmd_dbf);
1044 debug_unregister(adapter->abort_dbf);
1045 debug_unregister(adapter->in_els_dbf);
1049 * Enqueues an adapter at the end of the adapter list in the driver data.
1050 * All adapter internal structures are set up.
1051 * Proc-fs entries are also created.
1053 * returns: 0 if a new adapter was successfully enqueued
1054 * ZFCP_KNOWN if an adapter with this devno was already present
1055 * -ENOMEM if alloc failed
1056 * locks: config_sema must be held to serialise changes to the adapter list
1058 struct zfcp_adapter *
1059 zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1062 struct zfcp_adapter *adapter;
1065 * Note: It is safe to release the list_lock, as any list changes
1066 * are protected by the config_sema, which must be held to get here
1069 /* try to allocate new adapter data structure (zeroed) */
1070 adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
1072 ZFCP_LOG_INFO("error: allocation of base adapter "
1073 "structure failed\n");
1076 memset(adapter, 0, sizeof (struct zfcp_adapter));
1078 ccw_device->handler = NULL;
1080 /* save ccw_device pointer */
1081 adapter->ccw_device = ccw_device;
1083 retval = zfcp_qdio_allocate_queues(adapter);
1085 goto queues_alloc_failed;
1087 retval = zfcp_qdio_allocate(adapter);
1089 goto qdio_allocate_failed;
1091 retval = zfcp_allocate_low_mem_buffers(adapter);
1093 ZFCP_LOG_INFO("error: pool allocation failed\n");
1094 goto failed_low_mem_buffers;
1097 /* initialise reference count stuff */
1098 atomic_set(&adapter->refcount, 0);
1099 init_waitqueue_head(&adapter->remove_wq);
1101 /* initialise list of ports */
1102 INIT_LIST_HEAD(&adapter->port_list_head);
1104 /* initialise list of ports to be removed */
1105 INIT_LIST_HEAD(&adapter->port_remove_lh);
1107 /* initialize list of fsf requests */
1108 rwlock_init(&adapter->fsf_req_list_lock);
1109 INIT_LIST_HEAD(&adapter->fsf_req_list_head);
1111 /* initialize abort lock */
1112 rwlock_init(&adapter->abort_lock);
1114 /* initialise some erp stuff */
1115 init_waitqueue_head(&adapter->erp_thread_wqh);
1116 init_waitqueue_head(&adapter->erp_done_wqh);
1118 /* initialize lock of associated request queue */
1119 rwlock_init(&adapter->request_queue.queue_lock);
1121 /* intitialise SCSI ER timer */
1122 init_timer(&adapter->scsi_er_timer);
1124 /* set FC service class used per default */
1125 adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1127 sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
1128 ASCEBC(adapter->name, strlen(adapter->name));
1130 /* mark adapter unusable as long as sysfs registration is not complete */
1131 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1133 adapter->ccw_device = ccw_device;
1134 dev_set_drvdata(&ccw_device->dev, adapter);
1136 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1139 /* put allocated adapter at list tail */
1140 write_lock_irq(&zfcp_data.config_lock);
1141 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1142 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1143 write_unlock_irq(&zfcp_data.config_lock);
1145 zfcp_data.adapters++;
1150 dev_set_drvdata(&ccw_device->dev, NULL);
1151 failed_low_mem_buffers:
1152 zfcp_free_low_mem_buffers(adapter);
1153 if (qdio_free(ccw_device) != 0)
1154 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1155 zfcp_get_busid_by_adapter(adapter));
1156 qdio_allocate_failed:
1157 zfcp_qdio_free_queues(adapter);
1158 queues_alloc_failed:
1166 * returns: 0 - struct zfcp_adapter data structure successfully removed
1167 * !0 - struct zfcp_adapter data structure could not be removed
1169 * locks: adapter list write lock is assumed to be held by caller
1170 * adapter->fsf_req_list_lock is taken and released within this
1171 * function and must not be held on entry
1174 zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1177 unsigned long flags;
1179 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1180 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1181 /* sanity check: no pending FSF requests */
1182 read_lock_irqsave(&adapter->fsf_req_list_lock, flags);
1183 retval = !list_empty(&adapter->fsf_req_list_head);
1184 read_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
1186 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1187 "%i requests outstanding\n",
1188 zfcp_get_busid_by_adapter(adapter), adapter,
1189 atomic_read(&adapter->fsf_reqs_active));
1194 /* remove specified adapter data structure from list */
1195 write_lock_irq(&zfcp_data.config_lock);
1196 list_del(&adapter->list);
1197 write_unlock_irq(&zfcp_data.config_lock);
1199 /* decrease number of adapters in list */
1200 zfcp_data.adapters--;
1202 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1203 "%i adapters still in list\n",
1204 zfcp_get_busid_by_adapter(adapter),
1205 adapter, zfcp_data.adapters);
1207 retval = qdio_free(adapter->ccw_device);
1209 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1210 zfcp_get_busid_by_adapter(adapter));
1212 zfcp_free_low_mem_buffers(adapter);
1213 /* free memory of adapter data structure and queues */
1214 zfcp_qdio_free_queues(adapter);
1215 ZFCP_LOG_TRACE("freeing adapter structure\n");
1222 * Enqueues a remote port to the port list. All port internal structures
1223 * are set up and the sysfs entry is also generated.
1225 * returns: pointer to port or NULL
1226 * locks: config_sema must be held to serialise changes to the port list
1229 zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status)
1231 struct zfcp_port *port, *tmp_port;
1236 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1239 * check that there is no port with this WWPN already in list
1242 read_lock_irq(&zfcp_data.config_lock);
1243 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1244 read_unlock_irq(&zfcp_data.config_lock);
1249 port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1252 memset(port, 0, sizeof (struct zfcp_port));
1254 /* initialise reference count stuff */
1255 atomic_set(&port->refcount, 0);
1256 init_waitqueue_head(&port->remove_wq);
1258 INIT_LIST_HEAD(&port->unit_list_head);
1259 INIT_LIST_HEAD(&port->unit_remove_lh);
1261 port->adapter = adapter;
1266 atomic_set_mask(status, &port->status);
1268 /* setup for sysfs registration */
1269 if (status & ZFCP_STATUS_PORT_NAMESERVER)
1270 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, "nameserver");
1272 snprintf(port->sysfs_device.bus_id,
1273 BUS_ID_SIZE, "0x%016llx", wwpn);
1274 port->sysfs_device.parent = &adapter->ccw_device->dev;
1275 port->sysfs_device.release = zfcp_sysfs_port_release;
1276 dev_set_drvdata(&port->sysfs_device, port);
1278 /* mark port unusable as long as sysfs registration is not complete */
1279 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1281 if (device_register(&port->sysfs_device)) {
1286 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1287 device_unregister(&port->sysfs_device);
1291 zfcp_port_get(port);
1295 write_lock_irq(&zfcp_data.config_lock);
1296 list_for_each_entry(tmp_port, &adapter->port_list_head, list) {
1297 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_SCSI_ID,
1300 if (tmp_port->scsi_id != scsi_id) {
1306 port->scsi_id = scsi_id;
1308 list_add_tail(&port->list, &tmp_port->list);
1310 list_add_tail(&port->list, &adapter->port_list_head);
1311 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1312 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1313 write_unlock_irq(&zfcp_data.config_lock);
1316 zfcp_adapter_get(adapter);
1322 zfcp_port_dequeue(struct zfcp_port *port)
1324 zfcp_port_wait(port);
1325 write_lock_irq(&zfcp_data.config_lock);
1326 list_del(&port->list);
1327 write_unlock_irq(&zfcp_data.config_lock);
1328 port->adapter->ports--;
1329 zfcp_adapter_put(port->adapter);
1330 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1331 atomic_read(&port->status));
1332 device_unregister(&port->sysfs_device);
1335 /* Enqueues a nameserver port */
1337 zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1339 struct zfcp_port *port;
1341 /* generate port structure */
1342 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_NAMESERVER);
1344 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1345 "adapter %s failed\n",
1346 zfcp_get_busid_by_adapter(adapter));
1349 /* set special D_ID */
1350 port->d_id = ZFCP_DID_NAMESERVER;
1351 adapter->nameserver_port = port;
1352 zfcp_port_put(port);
1357 #undef ZFCP_LOG_AREA
1359 /****************************************************************/
1360 /******* Fibre Channel Standard related Functions **************/
1361 /****************************************************************/
1363 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1366 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1367 struct fsf_status_read_buffer *status_buffer)
1369 struct fcp_rscn_head *fcp_rscn_head;
1370 struct fcp_rscn_element *fcp_rscn_element;
1371 struct zfcp_port *port;
1375 unsigned long flags;
1377 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1378 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1381 no_entries = (fcp_rscn_head->payload_len / 4);
1383 zfcp_in_els_dbf_event(adapter, "##rscn", status_buffer,
1384 fcp_rscn_head->payload_len);
1386 debug_text_event(adapter->erp_dbf, 1, "unsol_els_rscn:");
1387 for (i = 1; i < no_entries; i++) {
1388 /* skip head and start with 1st element */
1390 switch (fcp_rscn_element->addr_format) {
1391 case ZFCP_PORT_ADDRESS:
1392 ZFCP_LOG_FLAGS(1, "ZFCP_PORT_ADDRESS\n");
1393 range_mask = ZFCP_PORTS_RANGE_PORT;
1395 case ZFCP_AREA_ADDRESS:
1396 ZFCP_LOG_FLAGS(1, "ZFCP_AREA_ADDRESS\n");
1397 range_mask = ZFCP_PORTS_RANGE_AREA;
1399 case ZFCP_DOMAIN_ADDRESS:
1400 ZFCP_LOG_FLAGS(1, "ZFCP_DOMAIN_ADDRESS\n");
1401 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1403 case ZFCP_FABRIC_ADDRESS:
1404 ZFCP_LOG_FLAGS(1, "ZFCP_FABRIC_ADDRESS\n");
1405 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1408 ZFCP_LOG_INFO("incoming RSCN with unknown "
1409 "address format\n");
1412 read_lock_irqsave(&zfcp_data.config_lock, flags);
1413 list_for_each_entry(port, &adapter->port_list_head, list) {
1414 if (atomic_test_mask
1415 (ZFCP_STATUS_PORT_NAMESERVER, &port->status))
1417 /* Do we know this port? If not skip it. */
1418 if (!atomic_test_mask
1419 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1420 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1421 "port 0x%016Lx\n", port->wwpn);
1422 debug_text_event(adapter->erp_dbf, 1,
1423 "unsol_els_rscnu:");
1424 zfcp_erp_port_reopen(port,
1425 ZFCP_STATUS_COMMON_ERP_FAILED);
1430 * FIXME: race: d_id might being invalidated
1431 * (...DID_DID reset)
1433 if ((port->d_id & range_mask)
1434 == (fcp_rscn_element->nport_did & range_mask)) {
1435 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1436 fcp_rscn_element->nport_did);
1438 * Unfortunately, an RSCN does not specify the
1439 * type of change a target underwent. We assume
1440 * that it makes sense to reopen the link.
1441 * FIXME: Shall we try to find out more about
1442 * the target and link state before closing it?
1443 * How to accomplish this? (nameserver?)
1444 * Where would such code be put in?
1445 * (inside or outside erp)
1447 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1448 "port 0x%016Lx\n", port->wwpn);
1449 debug_text_event(adapter->erp_dbf, 1,
1450 "unsol_els_rscnk:");
1451 zfcp_test_link(port);
1454 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1459 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1460 struct fsf_status_read_buffer *status_buffer)
1462 logi *els_logi = (logi *) status_buffer->payload;
1463 struct zfcp_port *port;
1464 unsigned long flags;
1466 zfcp_in_els_dbf_event(adapter, "##plogi", status_buffer, 28);
1468 read_lock_irqsave(&zfcp_data.config_lock, flags);
1469 list_for_each_entry(port, &adapter->port_list_head, list) {
1470 if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
1473 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1475 if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
1476 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1477 "with d_id 0x%08x on adapter %s\n",
1478 status_buffer->d_id,
1479 zfcp_get_busid_by_adapter(adapter));
1481 debug_text_event(adapter->erp_dbf, 1, "unsol_els_plogi:");
1482 debug_event(adapter->erp_dbf, 1, &els_logi->nport_wwn, 8);
1483 zfcp_erp_port_forced_reopen(port, 0);
1488 zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1489 struct fsf_status_read_buffer *status_buffer)
1491 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1492 struct zfcp_port *port;
1493 unsigned long flags;
1495 zfcp_in_els_dbf_event(adapter, "##logo", status_buffer, 16);
1497 read_lock_irqsave(&zfcp_data.config_lock, flags);
1498 list_for_each_entry(port, &adapter->port_list_head, list) {
1499 if (port->wwpn == els_logo->nport_wwpn)
1502 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1504 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1505 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1506 "with d_id 0x%08x on adapter %s\n",
1507 status_buffer->d_id,
1508 zfcp_get_busid_by_adapter(adapter));
1510 debug_text_event(adapter->erp_dbf, 1, "unsol_els_logo:");
1511 debug_event(adapter->erp_dbf, 1, &els_logo->nport_wwpn, 8);
1512 zfcp_erp_port_forced_reopen(port, 0);
1517 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
1518 struct fsf_status_read_buffer *status_buffer)
1520 zfcp_in_els_dbf_event(adapter, "##undef", status_buffer, 24);
1521 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1522 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1523 zfcp_get_busid_by_adapter(adapter));
1528 zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1530 struct fsf_status_read_buffer *status_buffer;
1532 struct zfcp_adapter *adapter;
1534 status_buffer = fsf_req->data.status_read.buffer;
1535 els_type = *(u32 *) (status_buffer->payload);
1536 adapter = fsf_req->adapter;
1538 if (els_type == LS_PLOGI)
1539 zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
1540 else if (els_type == LS_LOGO)
1541 zfcp_fsf_incoming_els_logo(adapter, status_buffer);
1542 else if ((els_type & 0xffff0000) == LS_RSCN)
1543 /* we are only concerned with the command, not the length */
1544 zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
1546 zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
1552 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1553 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1554 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1557 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1559 struct zfcp_gid_pn_data *data;
1562 data = mempool_alloc(pool, GFP_ATOMIC);
1563 if (likely(data != NULL)) {
1564 data->ct.pool = pool;
1567 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1573 memset(data, 0, sizeof(*data));
1574 data->ct.req = &data->req;
1575 data->ct.resp = &data->resp;
1576 data->ct.req_count = data->ct.resp_count = 1;
1577 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1578 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1579 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1580 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1587 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1588 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1591 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1593 if ((gid_pn->ct.pool != 0))
1594 mempool_free(gid_pn, gid_pn->ct.pool);
1602 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1603 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1606 zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1609 struct ct_iu_gid_pn_req *ct_iu_req;
1610 struct zfcp_gid_pn_data *gid_pn;
1611 struct zfcp_adapter *adapter = erp_action->adapter;
1613 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1615 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1616 "request failed for adapter %s\n",
1617 zfcp_get_busid_by_adapter(adapter));
1621 /* setup nameserver request */
1622 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1623 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1624 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1625 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1626 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1627 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1628 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1629 ct_iu_req->wwpn = erp_action->port->wwpn;
1631 /* setup parameters for send generic command */
1632 gid_pn->ct.port = adapter->nameserver_port;
1633 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1634 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1635 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1636 gid_pn->ct.timer = &erp_action->timer;
1637 gid_pn->port = erp_action->port;
1639 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1642 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1643 "failed for adapter %s\n",
1644 zfcp_get_busid_by_adapter(adapter));
1646 zfcp_gid_pn_buffers_free(gid_pn);
1654 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1655 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1657 static void zfcp_ns_gid_pn_handler(unsigned long data)
1659 struct zfcp_port *port;
1660 struct zfcp_send_ct *ct;
1661 struct ct_iu_gid_pn_req *ct_iu_req;
1662 struct ct_iu_gid_pn_resp *ct_iu_resp;
1663 struct zfcp_gid_pn_data *gid_pn;
1666 gid_pn = (struct zfcp_gid_pn_data *) data;
1667 port = gid_pn->port;
1669 ct_iu_req = zfcp_sg_to_address(ct->req);
1670 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1672 if (ct_iu_resp->header.revision != ZFCP_CT_REVISION)
1674 if (ct_iu_resp->header.gs_type != ZFCP_CT_DIRECTORY_SERVICE)
1676 if (ct_iu_resp->header.gs_subtype != ZFCP_CT_NAME_SERVER)
1678 if (ct_iu_resp->header.options != ZFCP_CT_SYNCHRONOUS)
1680 if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) {
1681 /* FIXME: do we need some specific erp entry points */
1682 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1686 if (ct_iu_req->wwpn != port->wwpn) {
1687 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1688 "lookup does not match expected wwpn 0x%016Lx "
1689 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1690 zfcp_get_busid_by_port(port));
1694 /* looks like a valid d_id */
1695 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1696 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1697 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1698 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1702 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1703 "0x%016Lx for adapter %s\n",
1704 port->wwpn, zfcp_get_busid_by_port(port));
1705 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1706 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1707 sizeof(struct ct_iu_gid_pn_req));
1708 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1709 sizeof(struct ct_iu_gid_pn_resp));
1712 zfcp_gid_pn_buffers_free(gid_pn);
1716 #undef ZFCP_LOG_AREA