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.107 $"
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);
50 #ifdef ZFCP_STAT_REQSIZES
51 static int zfcp_statistics_init_all(void);
52 static int zfcp_statistics_clear_all(void);
53 static int zfcp_statistics_clear(struct list_head *);
54 static int zfcp_statistics_new(struct list_head *, u32);
57 static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
58 static inline int zfcp_sg_list_free(struct zfcp_sg_list *);
59 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *, void *,
61 static inline int zfcp_sg_list_copy_to_user(void *, struct zfcp_sg_list *,
64 static int zfcp_cfdc_dev_ioctl(struct inode *, struct file *,
65 unsigned int, unsigned long);
67 #define ZFCP_CFDC_IOC_MAGIC 0xDD
68 #define ZFCP_CFDC_IOC \
69 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
71 #ifdef CONFIG_S390_SUPPORT
72 static struct ioctl_trans zfcp_ioctl_trans = {ZFCP_CFDC_IOC, (void*) sys_ioctl};
75 static struct file_operations zfcp_cfdc_fops = {
76 .ioctl = zfcp_cfdc_dev_ioctl
79 static struct miscdevice zfcp_cfdc_misc = {
80 .minor = ZFCP_CFDC_DEV_MINOR,
81 .name = ZFCP_CFDC_DEV_NAME,
82 .fops = &zfcp_cfdc_fops
85 /*********************** KERNEL/MODULE PARAMETERS ***************************/
87 /* declare driver module init/cleanup functions */
88 module_init(zfcp_module_init);
90 MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, "
91 "Martin Peschke <mpeschke@de.ibm.com>, "
92 "Raimund Schroeder <raimund.schroeder@de.ibm.com>, "
93 "Wolfgang Taphorn <taphorn@de.ibm.com>, "
94 "Aron Zeh <arzeh@de.ibm.com>, "
95 "IBM Deutschland Entwicklung GmbH");
97 ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries");
98 MODULE_LICENSE("GPL");
100 module_param(device, charp, 0);
101 MODULE_PARM_DESC(device, "specify initial device");
103 module_param(loglevel, uint, 0);
104 MODULE_PARM_DESC(loglevel,
105 "log levels, 8 nibbles: "
106 "(unassigned) ERP QDIO DIO Config FSF SCSI Other, "
107 "levels: 0=none 1=normal 2=devel 3=trace");
109 #ifdef ZFCP_PRINT_FLAGS
111 module_param(flags_dump, uint, 0);
114 /****************************************************************/
115 /************** Functions without logging ***********************/
116 /****************************************************************/
119 _zfcp_hex_dump(char *addr, int count)
122 for (i = 0; i < count; i++) {
123 printk("%02x", addr[i]);
129 if (((i-1) % 32) != 31)
133 /****************************************************************/
134 /************** Uncategorised Functions *************************/
135 /****************************************************************/
137 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
139 #ifdef ZFCP_STAT_REQSIZES
142 zfcp_statistics_clear(struct list_head *head)
146 struct zfcp_statistics *stat, *tmp;
148 write_lock_irqsave(&zfcp_data.stat_lock, flags);
149 list_for_each_entry_safe(stat, tmp, head, list) {
150 list_del(&stat->list);
153 write_unlock_irqrestore(&zfcp_data.stat_lock, flags);
158 /* Add new statistics entry */
160 zfcp_statistics_new(struct list_head *head, u32 num)
163 struct zfcp_statistics *stat;
165 stat = kmalloc(sizeof (struct zfcp_statistics), GFP_ATOMIC);
167 memset(stat, 0, sizeof (struct zfcp_statistics));
169 stat->occurrence = 1;
170 list_add_tail(&stat->list, head);
172 zfcp_data.stat_errors++;
178 zfcp_statistics_inc(struct list_head *head, u32 num)
182 struct zfcp_statistics *stat;
184 write_lock_irqsave(&zfcp_data.stat_lock, flags);
185 list_for_each_entry(stat, head, list) {
186 if (stat->num == num) {
191 /* occurrence must be initialized to 1 */
192 zfcp_statistics_new(head, num);
194 write_unlock_irqrestore(&zfcp_data.stat_lock, flags);
199 zfcp_statistics_init_all(void)
203 rwlock_init(&zfcp_data.stat_lock);
204 INIT_LIST_HEAD(&zfcp_data.read_req_head);
205 INIT_LIST_HEAD(&zfcp_data.write_req_head);
206 INIT_LIST_HEAD(&zfcp_data.read_sg_head);
207 INIT_LIST_HEAD(&zfcp_data.write_sg_head);
208 INIT_LIST_HEAD(&zfcp_data.read_sguse_head);
209 INIT_LIST_HEAD(&zfcp_data.write_sguse_head);
214 zfcp_statistics_clear_all(void)
218 zfcp_statistics_clear(&zfcp_data.read_req_head);
219 zfcp_statistics_clear(&zfcp_data.write_req_head);
220 zfcp_statistics_clear(&zfcp_data.read_sg_head);
221 zfcp_statistics_clear(&zfcp_data.write_sg_head);
222 zfcp_statistics_clear(&zfcp_data.read_sguse_head);
223 zfcp_statistics_clear(&zfcp_data.write_sguse_head);
227 #endif /* ZFCP_STAT_REQSIZES */
230 zfcp_fsf_req_is_scsi_cmnd(struct zfcp_fsf_req *fsf_req)
232 return ((fsf_req->fsf_command == FSF_QTCB_FCP_CMND) &&
233 !(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT));
237 zfcp_cmd_dbf_event_fsf(const char *text, struct zfcp_fsf_req *fsf_req,
238 void *add_data, int add_length)
240 struct zfcp_adapter *adapter = fsf_req->adapter;
241 struct scsi_cmnd *scsi_cmnd;
246 write_lock_irqsave(&adapter->cmd_dbf_lock, flags);
247 if (zfcp_fsf_req_is_scsi_cmnd(fsf_req)) {
248 scsi_cmnd = fsf_req->data.send_fcp_command_task.scsi_cmnd;
249 debug_text_event(adapter->cmd_dbf, level, "fsferror");
250 debug_text_event(adapter->cmd_dbf, level, text);
251 debug_event(adapter->cmd_dbf, level, &fsf_req,
252 sizeof (unsigned long));
253 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
255 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
256 sizeof (unsigned long));
257 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
258 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
259 for (i = 0; i < add_length; i += ZFCP_CMD_DBF_LENGTH)
260 debug_event(adapter->cmd_dbf,
262 (char *) add_data + i,
263 min(ZFCP_CMD_DBF_LENGTH, add_length - i));
265 write_unlock_irqrestore(&adapter->cmd_dbf_lock, flags);
268 /* XXX additionally log unit if available */
269 /* ---> introduce new parameter for unit, see 2.4 code */
271 zfcp_cmd_dbf_event_scsi(const char *text, struct scsi_cmnd *scsi_cmnd)
273 struct zfcp_adapter *adapter;
274 union zfcp_req_data *req_data;
275 struct zfcp_fsf_req *fsf_req;
276 int level = ((host_byte(scsi_cmnd->result) != 0) ? 1 : 5);
279 adapter = (struct zfcp_adapter *) scsi_cmnd->device->host->hostdata[0];
280 req_data = (union zfcp_req_data *) scsi_cmnd->host_scribble;
281 fsf_req = (req_data ? req_data->send_fcp_command_task.fsf_req : NULL);
282 write_lock_irqsave(&adapter->cmd_dbf_lock, flags);
283 debug_text_event(adapter->cmd_dbf, level, "hostbyte");
284 debug_text_event(adapter->cmd_dbf, level, text);
285 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->result, sizeof (u32));
286 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
287 sizeof (unsigned long));
288 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
289 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
290 if (likely(fsf_req)) {
291 debug_event(adapter->cmd_dbf, level, &fsf_req,
292 sizeof (unsigned long));
293 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
296 debug_text_event(adapter->cmd_dbf, level, "");
297 debug_text_event(adapter->cmd_dbf, level, "");
299 write_unlock_irqrestore(&adapter->cmd_dbf_lock, flags);
303 zfcp_in_els_dbf_event(struct zfcp_adapter *adapter, const char *text,
304 struct fsf_status_read_buffer *status_buffer, int length)
309 debug_text_event(adapter->in_els_dbf, level, text);
310 debug_event(adapter->in_els_dbf, level, &status_buffer->d_id, 8);
311 for (i = 0; i < length; i += ZFCP_IN_ELS_DBF_LENGTH)
312 debug_event(adapter->in_els_dbf,
314 (char *) status_buffer->payload + i,
315 min(ZFCP_IN_ELS_DBF_LENGTH, length - i));
319 * zfcp_device_setup - setup function
320 * @str: pointer to parameter string
322 * Parse "device=..." parameter string.
325 zfcp_device_setup(char *str)
332 tmp = strchr(str, ',');
336 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
337 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
339 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
345 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
351 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
356 zfcp_init_device_configure(void)
359 struct zfcp_adapter *adapter;
360 struct zfcp_port *port;
361 struct zfcp_unit *unit;
363 down(&zfcp_data.config_sema);
364 read_lock_irq(&zfcp_data.config_lock);
365 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list)
366 if (strcmp(zfcp_data.init_busid,
367 zfcp_get_busid_by_adapter(adapter)) == 0) {
368 zfcp_adapter_get(adapter);
372 read_unlock_irq(&zfcp_data.config_lock);
375 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0);
378 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
381 up(&zfcp_data.config_sema);
382 ccw_device_set_online(adapter->ccw_device);
383 wait_event(unit->scsi_add_wq, atomic_read(&unit->scsi_add_work) == 0);
384 down(&zfcp_data.config_sema);
389 zfcp_adapter_put(adapter);
391 up(&zfcp_data.config_sema);
396 zfcp_module_init(void)
401 atomic_set(&zfcp_data.loglevel, loglevel);
403 /* initialize adapter list */
404 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
406 /* initialize adapters to be removed list head */
407 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
409 #ifdef ZFCP_STAT_REQSIZES
410 zfcp_statistics_init_all();
413 #ifdef CONFIG_S390_SUPPORT
414 retval = register_ioctl32_conversion(zfcp_ioctl_trans.cmd,
415 zfcp_ioctl_trans.handler);
417 ZFCP_LOG_INFO("registration of ioctl32 conversion failed\n");
421 retval = misc_register(&zfcp_cfdc_misc);
423 ZFCP_LOG_INFO("registration of misc device "
424 "zfcp_cfdc failed\n");
425 goto out_misc_register;
427 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
428 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
431 /* Initialise proc semaphores */
432 sema_init(&zfcp_data.config_sema, 1);
434 /* initialise configuration rw lock */
435 rwlock_init(&zfcp_data.config_lock);
437 zfcp_data.reboot_notifier.notifier_call = zfcp_reboot_handler;
438 register_reboot_notifier(&zfcp_data.reboot_notifier);
440 /* save address of data structure managing the driver module */
441 zfcp_data.scsi_host_template.module = THIS_MODULE;
443 /* setup dynamic I/O */
444 retval = zfcp_ccw_register();
446 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
447 goto out_ccw_register;
450 if (zfcp_device_setup(device))
451 zfcp_init_device_configure();
456 unregister_reboot_notifier(&zfcp_data.reboot_notifier);
457 misc_deregister(&zfcp_cfdc_misc);
459 #ifdef CONFIG_S390_SUPPORT
460 unregister_ioctl32_conversion(zfcp_ioctl_trans.cmd);
463 #ifdef ZFCP_STAT_REQSIZES
464 zfcp_statistics_clear_all();
472 * This function is called automatically by the kernel whenever a reboot or a
473 * shut-down is initiated and zfcp is still loaded
475 * locks: zfcp_data.config_sema is taken prior to shutting down the module
476 * and removing all structures
477 * returns: NOTIFY_DONE in all cases
480 zfcp_reboot_handler(struct notifier_block *notifier, unsigned long code,
483 zfcp_ccw_unregister();
489 * function: zfcp_cfdc_dev_ioctl
491 * purpose: Handle control file upload/download transaction via IOCTL
494 * returns: 0 - Operation completed successfuly
495 * -ENOTTY - Unknown IOCTL command
496 * -EINVAL - Invalid sense data record
497 * -ENXIO - The FCP adapter is not available
498 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
499 * -ENOMEM - Insufficient memory
500 * -EFAULT - User space memory I/O operation fault
501 * -EPERM - Cannot create or queue FSF request or create SBALs
504 zfcp_cfdc_dev_ioctl(struct inode *inode, struct file *file,
505 unsigned int command, unsigned long buffer)
507 struct zfcp_cfdc_sense_data sense_data, *sense_data_user;
508 struct zfcp_adapter *adapter = NULL;
509 struct zfcp_fsf_req *fsf_req = NULL;
510 struct zfcp_sg_list *sg_list = NULL;
511 u32 fsf_command, option;
515 sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
516 if (sg_list == NULL) {
522 if (command != ZFCP_CFDC_IOC) {
523 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
528 if ((sense_data_user = (struct zfcp_cfdc_sense_data*)buffer) == NULL) {
529 ZFCP_LOG_INFO("sense data record is required\n");
534 retval = copy_from_user(&sense_data, sense_data_user,
535 sizeof(struct zfcp_cfdc_sense_data));
541 if (sense_data.signature != ZFCP_CFDC_SIGNATURE) {
542 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
543 ZFCP_CFDC_SIGNATURE);
548 switch (sense_data.command) {
550 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
551 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
552 option = FSF_CFDC_OPTION_NORMAL_MODE;
555 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
556 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
557 option = FSF_CFDC_OPTION_FORCE;
560 case ZFCP_CFDC_CMND_FULL_ACCESS:
561 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
562 option = FSF_CFDC_OPTION_FULL_ACCESS;
565 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
566 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
567 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
570 case ZFCP_CFDC_CMND_UPLOAD:
571 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
576 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
582 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
583 if (bus_id == NULL) {
587 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
588 (sense_data.devno >> 24),
589 (sense_data.devno >> 16) & 0xFF,
590 (sense_data.devno & 0xFFFF));
593 read_lock_irq(&zfcp_data.config_lock);
594 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
595 if (strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
597 zfcp_adapter_get(adapter);
602 read_unlock_irq(&zfcp_data.config_lock);
607 ZFCP_LOG_INFO("invalid adapter\n");
611 if (sense_data.command & ZFCP_CFDC_WITH_CONTROL_FILE) {
612 retval = zfcp_sg_list_alloc(sg_list,
613 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
620 if ((sense_data.command & ZFCP_CFDC_DOWNLOAD) &&
621 (sense_data.command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
622 retval = zfcp_sg_list_copy_from_user(
623 sg_list, &sense_data_user->control_file,
624 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
631 retval = zfcp_fsf_control_file(
632 adapter, &fsf_req, fsf_command, option, sg_list);
633 if (retval == -EOPNOTSUPP) {
634 ZFCP_LOG_INFO("adapter does not support cfdc\n");
636 } else if (retval != 0) {
637 ZFCP_LOG_INFO("initiation of cfdc up/download failed\n");
642 wait_event(fsf_req->completion_wq,
643 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
645 sense_data.fsf_status = fsf_req->qtcb->header.fsf_status;
646 memcpy(&sense_data.fsf_status_qual,
647 &fsf_req->qtcb->header.fsf_status_qual,
648 sizeof(union fsf_status_qual));
649 memcpy(&sense_data.payloads, &fsf_req->qtcb->bottom.support.els, 256);
651 retval = copy_to_user(sense_data_user, &sense_data,
652 sizeof(struct zfcp_cfdc_sense_data));
658 if (sense_data.command & ZFCP_CFDC_UPLOAD) {
659 retval = zfcp_sg_list_copy_to_user(
660 &sense_data_user->control_file, sg_list,
661 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
670 zfcp_fsf_req_cleanup(fsf_req);
672 if ((adapter != NULL) && (retval != -ENXIO))
673 zfcp_adapter_put(adapter);
675 if (sg_list != NULL) {
676 zfcp_sg_list_free(sg_list);
685 * function: zfcp_sg_list_alloc
687 * purpose: Create a scatter-gather list of the specified size
689 * returns: 0 - Scatter gather list is created
690 * -ENOMEM - Insufficient memory (*list_ptr is then set to NULL)
693 zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
695 struct scatterlist *sg;
699 sg_list->count = size >> PAGE_SHIFT;
700 if (size & ~PAGE_MASK)
702 sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
704 if (sg_list->sg == NULL) {
709 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
710 sg->length = min(size, PAGE_SIZE);
712 sg->page = alloc_pages(GFP_KERNEL, 0);
713 if (sg->page == NULL) {
715 zfcp_sg_list_free(sg_list);
728 * function: zfcp_sg_list_free
730 * purpose: Destroy a scatter-gather list and release memory
735 zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
737 struct scatterlist *sg;
741 BUG_ON((sg_list->sg == NULL) || (sg_list == NULL));
743 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
744 __free_pages(sg->page, 0);
751 * function: zfcp_sg_list_copy_from_user
753 * purpose: Copy data from user space memory to the scatter-gather list
755 * returns: 0 - The data has been copied from user
756 * -EFAULT - Memory I/O operation fault
759 zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list, void *user_buffer,
762 struct scatterlist *sg;
767 for (sg = sg_list->sg; size > 0; sg++) {
768 length = min((unsigned int)size, sg->length);
769 zfcp_buffer = (void*)
770 ((page_to_pfn(sg->page) << PAGE_SHIFT) + sg->offset);
771 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
775 user_buffer += length;
785 * function: zfcp_sg_list_copy_to_user
787 * purpose: Copy data from the scatter-gather list to user space memory
789 * returns: 0 - The data has been copied to user
790 * -EFAULT - Memory I/O operation fault
793 zfcp_sg_list_copy_to_user(void *user_buffer, struct zfcp_sg_list *sg_list,
796 struct scatterlist *sg;
801 for (sg = sg_list->sg; size > 0; sg++) {
802 length = min((unsigned int)size, sg->length);
803 zfcp_buffer = (void*)
804 ((page_to_pfn(sg->page) << PAGE_SHIFT) + sg->offset);
805 if (copy_to_user(user_buffer, zfcp_buffer, length)) {
809 user_buffer += length;
820 /****************************************************************/
821 /****** Functions for configuration/set-up of structures ********/
822 /****************************************************************/
824 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
827 * zfcp_get_unit_by_lun - find unit in unit list of port by fcp lun
828 * @port: pointer to port to search for unit
829 * @fcp_lun: lun to search for
830 * Traverses list of all units of a port and returns pointer to a unit
831 * if lun of a unit matches.
835 zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
837 struct zfcp_unit *unit;
840 list_for_each_entry(unit, &port->unit_list_head, list) {
841 if ((unit->fcp_lun == fcp_lun) &&
842 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
848 return found ? unit : NULL;
852 * zfcp_get_port_by_wwpn - find unit in unit list of port by fcp lun
853 * @adapter: pointer to adapter to search for port
854 * @wwpn: wwpn to search for
855 * Traverses list of all ports of an adapter and returns a pointer to a port
856 * if wwpn of a port matches.
860 zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
862 struct zfcp_port *port;
865 list_for_each_entry(port, &adapter->port_list_head, list) {
866 if ((port->wwpn == wwpn) &&
867 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
873 return found ? port : NULL;
877 * Enqueues a logical unit at the end of the unit list associated with the
878 * specified port. Also sets up some unit internal structures.
880 * returns: pointer to unit with a usecount of 1 if a new unit was
881 * successfully enqueued
883 * locks: config_sema must be held to serialise changes to the unit list
886 zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
888 struct zfcp_unit *unit, *tmp_unit;
893 * check that there is no unit with this FCP_LUN already in list
895 * Note: Unlike for the adapter and the port, this is an error
897 read_lock_irq(&zfcp_data.config_lock);
898 unit = zfcp_get_unit_by_lun(port, fcp_lun);
899 read_unlock_irq(&zfcp_data.config_lock);
903 unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
906 memset(unit, 0, sizeof (struct zfcp_unit));
908 init_waitqueue_head(&unit->scsi_add_wq);
909 /* initialise reference count stuff */
910 atomic_set(&unit->refcount, 0);
911 init_waitqueue_head(&unit->remove_wq);
914 unit->fcp_lun = fcp_lun;
916 /* setup for sysfs registration */
917 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
918 unit->sysfs_device.parent = &port->sysfs_device;
919 unit->sysfs_device.release = zfcp_sysfs_unit_release;
920 dev_set_drvdata(&unit->sysfs_device, unit);
922 /* mark unit unusable as long as sysfs registration is not complete */
923 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
925 if (device_register(&unit->sysfs_device)) {
930 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
931 device_unregister(&unit->sysfs_device);
939 write_lock_irq(&zfcp_data.config_lock);
940 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
941 if (tmp_unit->scsi_lun != scsi_lun) {
947 unit->scsi_lun = scsi_lun;
949 list_add_tail(&unit->list, &tmp_unit->list);
951 list_add_tail(&unit->list, &port->unit_list_head);
952 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
953 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
954 write_unlock_irq(&zfcp_data.config_lock);
963 zfcp_unit_dequeue(struct zfcp_unit *unit)
965 zfcp_unit_wait(unit);
966 write_lock_irq(&zfcp_data.config_lock);
967 list_del(&unit->list);
968 write_unlock_irq(&zfcp_data.config_lock);
970 zfcp_port_put(unit->port);
971 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
972 device_unregister(&unit->sysfs_device);
976 zfcp_mempool_alloc(int gfp_mask, void *size)
978 return kmalloc((size_t) size, gfp_mask);
982 zfcp_mempool_free(void *element, void *size)
988 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
990 * It also genrates fcp-nameserver request/response buffer and unsolicited
991 * status read fsf_req buffers.
993 * locks: must only be called with zfcp_data.config_sema taken
996 zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
998 adapter->pool.fsf_req_erp =
999 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR,
1000 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
1001 sizeof(struct zfcp_fsf_req_pool_element));
1003 if (NULL == adapter->pool.fsf_req_erp)
1006 adapter->pool.fsf_req_scsi =
1007 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR,
1008 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
1009 sizeof(struct zfcp_fsf_req_pool_element));
1011 if (NULL == adapter->pool.fsf_req_scsi)
1014 adapter->pool.fsf_req_abort =
1015 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR,
1016 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
1017 sizeof(struct zfcp_fsf_req_pool_element));
1019 if (NULL == adapter->pool.fsf_req_abort)
1022 adapter->pool.fsf_req_status_read =
1023 mempool_create(ZFCP_POOL_STATUS_READ_NR,
1024 zfcp_mempool_alloc, zfcp_mempool_free,
1025 (void *) sizeof(struct zfcp_fsf_req));
1027 if (NULL == adapter->pool.fsf_req_status_read)
1030 adapter->pool.data_status_read =
1031 mempool_create(ZFCP_POOL_STATUS_READ_NR,
1032 zfcp_mempool_alloc, zfcp_mempool_free,
1033 (void *) sizeof(struct fsf_status_read_buffer));
1035 if (NULL == adapter->pool.data_status_read)
1038 adapter->pool.data_gid_pn =
1039 mempool_create(ZFCP_POOL_DATA_GID_PN_NR,
1040 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
1041 sizeof(struct zfcp_gid_pn_data));
1043 if (NULL == adapter->pool.data_gid_pn)
1050 * zfcp_free_low_mem_buffers - free memory pools of an adapter
1051 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
1052 * locking: zfcp_data.config_sema must be held
1055 zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
1057 if (adapter->pool.fsf_req_erp)
1058 mempool_destroy(adapter->pool.fsf_req_erp);
1059 if (adapter->pool.fsf_req_scsi)
1060 mempool_destroy(adapter->pool.fsf_req_scsi);
1061 if (adapter->pool.fsf_req_abort)
1062 mempool_destroy(adapter->pool.fsf_req_abort);
1063 if (adapter->pool.fsf_req_status_read)
1064 mempool_destroy(adapter->pool.fsf_req_status_read);
1065 if (adapter->pool.data_status_read)
1066 mempool_destroy(adapter->pool.data_status_read);
1067 if (adapter->pool.data_gid_pn)
1068 mempool_destroy(adapter->pool.data_gid_pn);
1072 * zfcp_adapter_debug_register - registers debug feature for an adapter
1073 * @adapter: pointer to adapter for which debug features should be registered
1074 * return: -ENOMEM on error, 0 otherwise
1077 zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1081 /* debug feature area which records SCSI command failures (hostbyte) */
1082 rwlock_init(&adapter->cmd_dbf_lock);
1083 sprintf(dbf_name, ZFCP_CMD_DBF_NAME "%s",
1084 zfcp_get_busid_by_adapter(adapter));
1085 adapter->cmd_dbf = debug_register(dbf_name,
1088 ZFCP_CMD_DBF_LENGTH);
1089 debug_register_view(adapter->cmd_dbf, &debug_hex_ascii_view);
1090 debug_set_level(adapter->cmd_dbf, ZFCP_CMD_DBF_LEVEL);
1092 /* debug feature area which records SCSI command aborts */
1093 sprintf(dbf_name, ZFCP_ABORT_DBF_NAME "%s",
1094 zfcp_get_busid_by_adapter(adapter));
1095 adapter->abort_dbf = debug_register(dbf_name,
1096 ZFCP_ABORT_DBF_INDEX,
1097 ZFCP_ABORT_DBF_AREAS,
1098 ZFCP_ABORT_DBF_LENGTH);
1099 debug_register_view(adapter->abort_dbf, &debug_hex_ascii_view);
1100 debug_set_level(adapter->abort_dbf, ZFCP_ABORT_DBF_LEVEL);
1102 /* debug feature area which records SCSI command aborts */
1103 sprintf(dbf_name, ZFCP_IN_ELS_DBF_NAME "%s",
1104 zfcp_get_busid_by_adapter(adapter));
1105 adapter->in_els_dbf = debug_register(dbf_name,
1106 ZFCP_IN_ELS_DBF_INDEX,
1107 ZFCP_IN_ELS_DBF_AREAS,
1108 ZFCP_IN_ELS_DBF_LENGTH);
1109 debug_register_view(adapter->in_els_dbf, &debug_hex_ascii_view);
1110 debug_set_level(adapter->in_els_dbf, ZFCP_IN_ELS_DBF_LEVEL);
1113 /* debug feature area which records erp events */
1114 sprintf(dbf_name, ZFCP_ERP_DBF_NAME "%s",
1115 zfcp_get_busid_by_adapter(adapter));
1116 adapter->erp_dbf = debug_register(dbf_name,
1119 ZFCP_ERP_DBF_LENGTH);
1120 debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view);
1121 debug_set_level(adapter->erp_dbf, ZFCP_ERP_DBF_LEVEL);
1123 if (adapter->cmd_dbf && adapter->abort_dbf &&
1124 adapter->in_els_dbf && adapter->erp_dbf)
1127 zfcp_adapter_debug_unregister(adapter);
1132 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1133 * @adapter: pointer to adapter for which debug features should be unregistered
1136 zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1138 debug_unregister(adapter->erp_dbf);
1139 debug_unregister(adapter->cmd_dbf);
1140 debug_unregister(adapter->abort_dbf);
1141 debug_unregister(adapter->in_els_dbf);
1145 * Enqueues an adapter at the end of the adapter list in the driver data.
1146 * All adapter internal structures are set up.
1147 * Proc-fs entries are also created.
1149 * returns: 0 if a new adapter was successfully enqueued
1150 * ZFCP_KNOWN if an adapter with this devno was already present
1151 * -ENOMEM if alloc failed
1152 * locks: config_sema must be held to serialise changes to the adapter list
1154 struct zfcp_adapter *
1155 zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1158 struct zfcp_adapter *adapter;
1161 * Note: It is safe to release the list_lock, as any list changes
1162 * are protected by the config_sema, which must be held to get here
1165 /* try to allocate new adapter data structure (zeroed) */
1166 adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
1168 ZFCP_LOG_INFO("error: allocation of base adapter "
1169 "structure failed\n");
1172 memset(adapter, 0, sizeof (struct zfcp_adapter));
1174 ccw_device->handler = NULL;
1176 /* save ccw_device pointer */
1177 adapter->ccw_device = ccw_device;
1179 retval = zfcp_qdio_allocate_queues(adapter);
1181 goto queues_alloc_failed;
1183 retval = zfcp_qdio_allocate(adapter);
1185 goto qdio_allocate_failed;
1187 retval = zfcp_allocate_low_mem_buffers(adapter);
1189 ZFCP_LOG_INFO("error: pool allocation failed\n");
1190 goto failed_low_mem_buffers;
1193 /* initialise reference count stuff */
1194 atomic_set(&adapter->refcount, 0);
1195 init_waitqueue_head(&adapter->remove_wq);
1197 /* initialise list of ports */
1198 INIT_LIST_HEAD(&adapter->port_list_head);
1200 /* initialise list of ports to be removed */
1201 INIT_LIST_HEAD(&adapter->port_remove_lh);
1203 /* initialize list of fsf requests */
1204 rwlock_init(&adapter->fsf_req_list_lock);
1205 INIT_LIST_HEAD(&adapter->fsf_req_list_head);
1207 /* initialize abort lock */
1208 rwlock_init(&adapter->abort_lock);
1210 /* initialise some erp stuff */
1211 init_waitqueue_head(&adapter->erp_thread_wqh);
1212 init_waitqueue_head(&adapter->erp_done_wqh);
1214 /* initialize lock of associated request queue */
1215 rwlock_init(&adapter->request_queue.queue_lock);
1217 /* intitialise SCSI ER timer */
1218 init_timer(&adapter->scsi_er_timer);
1220 /* set FC service class used per default */
1221 adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1223 sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
1224 ASCEBC(adapter->name, strlen(adapter->name));
1226 /* mark adapter unusable as long as sysfs registration is not complete */
1227 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1229 adapter->ccw_device = ccw_device;
1230 dev_set_drvdata(&ccw_device->dev, adapter);
1232 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1235 /* put allocated adapter at list tail */
1236 write_lock_irq(&zfcp_data.config_lock);
1237 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1238 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1239 write_unlock_irq(&zfcp_data.config_lock);
1241 zfcp_data.adapters++;
1246 dev_set_drvdata(&ccw_device->dev, NULL);
1247 failed_low_mem_buffers:
1248 zfcp_free_low_mem_buffers(adapter);
1249 if (qdio_free(ccw_device) != 0)
1250 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1251 zfcp_get_busid_by_adapter(adapter));
1252 qdio_allocate_failed:
1253 zfcp_qdio_free_queues(adapter);
1254 queues_alloc_failed:
1262 * returns: 0 - struct zfcp_adapter data structure successfully removed
1263 * !0 - struct zfcp_adapter data structure could not be removed
1265 * locks: adapter list write lock is assumed to be held by caller
1266 * adapter->fsf_req_list_lock is taken and released within this
1267 * function and must not be held on entry
1270 zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1273 unsigned long flags;
1275 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1276 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1277 /* sanity check: no pending FSF requests */
1278 read_lock_irqsave(&adapter->fsf_req_list_lock, flags);
1279 retval = !list_empty(&adapter->fsf_req_list_head);
1280 read_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
1282 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1283 "%i requests outstanding\n",
1284 zfcp_get_busid_by_adapter(adapter), adapter,
1285 atomic_read(&adapter->fsf_reqs_active));
1290 /* remove specified adapter data structure from list */
1291 write_lock_irq(&zfcp_data.config_lock);
1292 list_del(&adapter->list);
1293 write_unlock_irq(&zfcp_data.config_lock);
1295 /* decrease number of adapters in list */
1296 zfcp_data.adapters--;
1298 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1299 "%i adapters still in list\n",
1300 zfcp_get_busid_by_adapter(adapter),
1301 adapter, zfcp_data.adapters);
1303 retval = qdio_free(adapter->ccw_device);
1305 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1306 zfcp_get_busid_by_adapter(adapter));
1308 zfcp_free_low_mem_buffers(adapter);
1309 /* free memory of adapter data structure and queues */
1310 zfcp_qdio_free_queues(adapter);
1311 ZFCP_LOG_TRACE("freeing adapter structure\n");
1318 * Enqueues a remote port to the port list. All port internal structures
1319 * are set up and the sysfs entry is also generated.
1321 * returns: pointer to port or NULL
1322 * locks: config_sema must be held to serialise changes to the port list
1325 zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status)
1327 struct zfcp_port *port, *tmp_port;
1332 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1335 * check that there is no port with this WWPN already in list
1338 read_lock_irq(&zfcp_data.config_lock);
1339 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1340 read_unlock_irq(&zfcp_data.config_lock);
1345 port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1348 memset(port, 0, sizeof (struct zfcp_port));
1350 /* initialise reference count stuff */
1351 atomic_set(&port->refcount, 0);
1352 init_waitqueue_head(&port->remove_wq);
1354 INIT_LIST_HEAD(&port->unit_list_head);
1355 INIT_LIST_HEAD(&port->unit_remove_lh);
1357 port->adapter = adapter;
1362 atomic_set_mask(status, &port->status);
1364 /* setup for sysfs registration */
1365 if (status & ZFCP_STATUS_PORT_NAMESERVER)
1366 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, "nameserver");
1368 snprintf(port->sysfs_device.bus_id,
1369 BUS_ID_SIZE, "0x%016llx", wwpn);
1370 port->sysfs_device.parent = &adapter->ccw_device->dev;
1371 port->sysfs_device.release = zfcp_sysfs_port_release;
1372 dev_set_drvdata(&port->sysfs_device, port);
1374 /* mark port unusable as long as sysfs registration is not complete */
1375 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1377 if (device_register(&port->sysfs_device)) {
1382 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1383 device_unregister(&port->sysfs_device);
1387 zfcp_port_get(port);
1391 write_lock_irq(&zfcp_data.config_lock);
1392 list_for_each_entry(tmp_port, &adapter->port_list_head, list) {
1393 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_SCSI_ID,
1396 if (tmp_port->scsi_id != scsi_id) {
1402 port->scsi_id = scsi_id;
1404 list_add_tail(&port->list, &tmp_port->list);
1406 list_add_tail(&port->list, &adapter->port_list_head);
1407 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1408 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1409 write_unlock_irq(&zfcp_data.config_lock);
1412 zfcp_adapter_get(adapter);
1418 zfcp_port_dequeue(struct zfcp_port *port)
1420 zfcp_port_wait(port);
1421 write_lock_irq(&zfcp_data.config_lock);
1422 list_del(&port->list);
1423 write_unlock_irq(&zfcp_data.config_lock);
1424 port->adapter->ports--;
1425 zfcp_adapter_put(port->adapter);
1426 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1427 atomic_read(&port->status));
1428 device_unregister(&port->sysfs_device);
1431 /* Enqueues a nameserver port */
1433 zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1435 struct zfcp_port *port;
1437 /* generate port structure */
1438 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_NAMESERVER);
1440 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1441 "adapter %s failed\n",
1442 zfcp_get_busid_by_adapter(adapter));
1445 /* set special D_ID */
1446 port->d_id = ZFCP_DID_NAMESERVER;
1447 adapter->nameserver_port = port;
1448 zfcp_port_put(port);
1453 #undef ZFCP_LOG_AREA
1455 /****************************************************************/
1456 /******* Fibre Channel Standard related Functions **************/
1457 /****************************************************************/
1459 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1462 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1463 struct fsf_status_read_buffer *status_buffer)
1465 struct fcp_rscn_head *fcp_rscn_head;
1466 struct fcp_rscn_element *fcp_rscn_element;
1467 struct zfcp_port *port;
1471 unsigned long flags;
1473 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1474 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1477 no_entries = (fcp_rscn_head->payload_len / 4);
1479 zfcp_in_els_dbf_event(adapter, "##rscn", status_buffer,
1480 fcp_rscn_head->payload_len);
1482 debug_text_event(adapter->erp_dbf, 1, "unsol_els_rscn:");
1483 for (i = 1; i < no_entries; i++) {
1484 /* skip head and start with 1st element */
1486 switch (fcp_rscn_element->addr_format) {
1487 case ZFCP_PORT_ADDRESS:
1488 ZFCP_LOG_FLAGS(1, "ZFCP_PORT_ADDRESS\n");
1489 range_mask = ZFCP_PORTS_RANGE_PORT;
1491 case ZFCP_AREA_ADDRESS:
1492 ZFCP_LOG_FLAGS(1, "ZFCP_AREA_ADDRESS\n");
1493 range_mask = ZFCP_PORTS_RANGE_AREA;
1495 case ZFCP_DOMAIN_ADDRESS:
1496 ZFCP_LOG_FLAGS(1, "ZFCP_DOMAIN_ADDRESS\n");
1497 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1499 case ZFCP_FABRIC_ADDRESS:
1500 ZFCP_LOG_FLAGS(1, "ZFCP_FABRIC_ADDRESS\n");
1501 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1504 ZFCP_LOG_INFO("incoming RSCN with unknown "
1505 "address format\n");
1508 read_lock_irqsave(&zfcp_data.config_lock, flags);
1509 list_for_each_entry(port, &adapter->port_list_head, list) {
1510 if (atomic_test_mask
1511 (ZFCP_STATUS_PORT_NAMESERVER, &port->status))
1513 /* Do we know this port? If not skip it. */
1514 if (!atomic_test_mask
1515 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1516 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1517 "port 0x%016Lx\n", port->wwpn);
1518 debug_text_event(adapter->erp_dbf, 1,
1519 "unsol_els_rscnu:");
1520 zfcp_erp_port_reopen(port,
1521 ZFCP_STATUS_COMMON_ERP_FAILED);
1526 * FIXME: race: d_id might being invalidated
1527 * (...DID_DID reset)
1529 if ((port->d_id & range_mask)
1530 == (fcp_rscn_element->nport_did & range_mask)) {
1531 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1532 fcp_rscn_element->nport_did);
1534 * Unfortunately, an RSCN does not specify the
1535 * type of change a target underwent. We assume
1536 * that it makes sense to reopen the link.
1537 * FIXME: Shall we try to find out more about
1538 * the target and link state before closing it?
1539 * How to accomplish this? (nameserver?)
1540 * Where would such code be put in?
1541 * (inside or outside erp)
1543 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1544 "port 0x%016Lx\n", port->wwpn);
1545 debug_text_event(adapter->erp_dbf, 1,
1546 "unsol_els_rscnk:");
1547 zfcp_test_link(port);
1550 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1555 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1556 struct fsf_status_read_buffer *status_buffer)
1558 logi *els_logi = (logi *) status_buffer->payload;
1559 struct zfcp_port *port;
1560 unsigned long flags;
1562 zfcp_in_els_dbf_event(adapter, "##plogi", status_buffer, 28);
1564 read_lock_irqsave(&zfcp_data.config_lock, flags);
1565 list_for_each_entry(port, &adapter->port_list_head, list) {
1566 if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
1569 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1571 if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
1572 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1573 "with d_id 0x%08x on adapter %s\n",
1574 status_buffer->d_id,
1575 zfcp_get_busid_by_adapter(adapter));
1577 debug_text_event(adapter->erp_dbf, 1, "unsol_els_plogi:");
1578 debug_event(adapter->erp_dbf, 1, &els_logi->nport_wwn, 8);
1579 zfcp_erp_port_forced_reopen(port, 0);
1584 zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1585 struct fsf_status_read_buffer *status_buffer)
1587 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1588 struct zfcp_port *port;
1589 unsigned long flags;
1591 zfcp_in_els_dbf_event(adapter, "##logo", status_buffer, 16);
1593 read_lock_irqsave(&zfcp_data.config_lock, flags);
1594 list_for_each_entry(port, &adapter->port_list_head, list) {
1595 if (port->wwpn == els_logo->nport_wwpn)
1598 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1600 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1601 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1602 "with d_id 0x%08x on adapter %s\n",
1603 status_buffer->d_id,
1604 zfcp_get_busid_by_adapter(adapter));
1606 debug_text_event(adapter->erp_dbf, 1, "unsol_els_logo:");
1607 debug_event(adapter->erp_dbf, 1, &els_logo->nport_wwpn, 8);
1608 zfcp_erp_port_forced_reopen(port, 0);
1613 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
1614 struct fsf_status_read_buffer *status_buffer)
1616 zfcp_in_els_dbf_event(adapter, "##undef", status_buffer, 24);
1617 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1618 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1619 zfcp_get_busid_by_adapter(adapter));
1624 zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1626 struct fsf_status_read_buffer *status_buffer;
1628 struct zfcp_adapter *adapter;
1630 status_buffer = fsf_req->data.status_read.buffer;
1631 els_type = *(u32 *) (status_buffer->payload);
1632 adapter = fsf_req->adapter;
1634 if (els_type == LS_PLOGI)
1635 zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
1636 else if (els_type == LS_LOGO)
1637 zfcp_fsf_incoming_els_logo(adapter, status_buffer);
1638 else if ((els_type & 0xffff0000) == LS_RSCN)
1639 /* we are only concerned with the command, not the length */
1640 zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
1642 zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
1648 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1649 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1650 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1653 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1655 struct zfcp_gid_pn_data *data;
1658 data = mempool_alloc(pool, GFP_ATOMIC);
1659 if (likely(data != NULL)) {
1660 data->ct.pool = pool;
1663 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1669 memset(data, 0, sizeof(*data));
1670 data->ct.req = &data->req;
1671 data->ct.resp = &data->resp;
1672 data->ct.req_count = data->ct.resp_count = 1;
1673 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1674 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1675 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1676 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1683 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1684 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1687 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1689 if ((gid_pn->ct.pool != 0))
1690 mempool_free(gid_pn, gid_pn->ct.pool);
1698 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1699 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1702 zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1705 struct ct_iu_gid_pn_req *ct_iu_req;
1706 struct zfcp_gid_pn_data *gid_pn;
1707 struct zfcp_adapter *adapter = erp_action->adapter;
1709 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1711 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1712 "request failed for adapter %s\n",
1713 zfcp_get_busid_by_adapter(adapter));
1717 /* setup nameserver request */
1718 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1719 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1720 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1721 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1722 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1723 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1724 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1725 ct_iu_req->wwpn = erp_action->port->wwpn;
1727 /* setup parameters for send generic command */
1728 gid_pn->ct.port = adapter->nameserver_port;
1729 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1730 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1731 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1732 gid_pn->ct.timer = &erp_action->timer;
1733 gid_pn->port = erp_action->port;
1735 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1738 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1739 "failed for adapter %s\n",
1740 zfcp_get_busid_by_adapter(adapter));
1742 zfcp_gid_pn_buffers_free(gid_pn);
1750 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1751 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1753 static void zfcp_ns_gid_pn_handler(unsigned long data)
1755 struct zfcp_port *port;
1756 struct zfcp_send_ct *ct;
1757 struct ct_iu_gid_pn_req *ct_iu_req;
1758 struct ct_iu_gid_pn_resp *ct_iu_resp;
1759 struct zfcp_gid_pn_data *gid_pn;
1762 gid_pn = (struct zfcp_gid_pn_data *) data;
1763 port = gid_pn->port;
1765 ct_iu_req = zfcp_sg_to_address(ct->req);
1766 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1768 if (ct_iu_resp->header.revision != ZFCP_CT_REVISION)
1770 if (ct_iu_resp->header.gs_type != ZFCP_CT_DIRECTORY_SERVICE)
1772 if (ct_iu_resp->header.gs_subtype != ZFCP_CT_NAME_SERVER)
1774 if (ct_iu_resp->header.options != ZFCP_CT_SYNCHRONOUS)
1776 if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) {
1777 /* FIXME: do we need some specific erp entry points */
1778 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1782 if (ct_iu_req->wwpn != port->wwpn) {
1783 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1784 "lookup does not match expected wwpn 0x%016Lx "
1785 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1786 zfcp_get_busid_by_port(port));
1790 /* looks like a valid d_id */
1791 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1792 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1793 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1794 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1798 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1799 "0x%016Lx for adapter %s\n",
1800 port->wwpn, zfcp_get_busid_by_port(port));
1801 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1802 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1803 sizeof(struct ct_iu_gid_pn_req));
1804 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1805 sizeof(struct ct_iu_gid_pn_resp));
1808 zfcp_gid_pn_buffers_free(gid_pn);
1812 #undef ZFCP_LOG_AREA