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.115 $"
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 int zfcp_sg_list_free(struct zfcp_sg_list *);
51 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *, void *,
53 static inline int zfcp_sg_list_copy_to_user(void *, struct zfcp_sg_list *,
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 "(unassigned) ERP QDIO DIO 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)
261 struct zfcp_adapter *adapter;
262 struct zfcp_port *port;
263 struct zfcp_unit *unit;
265 down(&zfcp_data.config_sema);
266 read_lock_irq(&zfcp_data.config_lock);
267 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list)
268 if (strcmp(zfcp_data.init_busid,
269 zfcp_get_busid_by_adapter(adapter)) == 0) {
270 zfcp_adapter_get(adapter);
274 read_unlock_irq(&zfcp_data.config_lock);
277 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0);
280 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
283 up(&zfcp_data.config_sema);
284 ccw_device_set_online(adapter->ccw_device);
285 wait_event(unit->scsi_add_wq, atomic_read(&unit->scsi_add_work) == 0);
286 down(&zfcp_data.config_sema);
291 zfcp_adapter_put(adapter);
293 up(&zfcp_data.config_sema);
298 zfcp_module_init(void)
303 atomic_set(&zfcp_data.loglevel, loglevel);
305 /* initialize adapter list */
306 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
308 /* initialize adapters to be removed list head */
309 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
311 zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
312 if (!zfcp_transport_template)
315 #ifdef CONFIG_S390_SUPPORT
316 retval = register_ioctl32_conversion(zfcp_ioctl_trans.cmd,
317 zfcp_ioctl_trans.handler);
319 ZFCP_LOG_INFO("registration of ioctl32 conversion failed\n");
323 retval = misc_register(&zfcp_cfdc_misc);
325 ZFCP_LOG_INFO("registration of misc device "
326 "zfcp_cfdc failed\n");
327 goto out_misc_register;
329 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
330 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
333 /* Initialise proc semaphores */
334 sema_init(&zfcp_data.config_sema, 1);
336 /* initialise configuration rw lock */
337 rwlock_init(&zfcp_data.config_lock);
339 /* save address of data structure managing the driver module */
340 zfcp_data.scsi_host_template.module = THIS_MODULE;
342 /* setup dynamic I/O */
343 retval = zfcp_ccw_register();
345 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
346 goto out_ccw_register;
349 if (zfcp_device_setup(device))
350 zfcp_init_device_configure();
355 misc_deregister(&zfcp_cfdc_misc);
357 #ifdef CONFIG_S390_SUPPORT
358 unregister_ioctl32_conversion(zfcp_ioctl_trans.cmd);
367 * function: zfcp_cfdc_dev_ioctl
369 * purpose: Handle control file upload/download transaction via IOCTL
372 * returns: 0 - Operation completed successfuly
373 * -ENOTTY - Unknown IOCTL command
374 * -EINVAL - Invalid sense data record
375 * -ENXIO - The FCP adapter is not available
376 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
377 * -ENOMEM - Insufficient memory
378 * -EFAULT - User space memory I/O operation fault
379 * -EPERM - Cannot create or queue FSF request or create SBALs
382 zfcp_cfdc_dev_ioctl(struct inode *inode, struct file *file,
383 unsigned int command, unsigned long buffer)
385 struct zfcp_cfdc_sense_data sense_data, *sense_data_user;
386 struct zfcp_adapter *adapter = NULL;
387 struct zfcp_fsf_req *fsf_req = NULL;
388 struct zfcp_sg_list *sg_list = NULL;
389 u32 fsf_command, option;
393 sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
394 if (sg_list == NULL) {
398 memset(sg_list, 0, sizeof(*sg_list));
400 if (command != ZFCP_CFDC_IOC) {
401 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
406 if ((sense_data_user = (struct zfcp_cfdc_sense_data*)buffer) == NULL) {
407 ZFCP_LOG_INFO("sense data record is required\n");
412 retval = copy_from_user(&sense_data, sense_data_user,
413 sizeof(struct zfcp_cfdc_sense_data));
419 if (sense_data.signature != ZFCP_CFDC_SIGNATURE) {
420 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
421 ZFCP_CFDC_SIGNATURE);
426 switch (sense_data.command) {
428 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
429 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
430 option = FSF_CFDC_OPTION_NORMAL_MODE;
433 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
434 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
435 option = FSF_CFDC_OPTION_FORCE;
438 case ZFCP_CFDC_CMND_FULL_ACCESS:
439 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
440 option = FSF_CFDC_OPTION_FULL_ACCESS;
443 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
444 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
445 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
448 case ZFCP_CFDC_CMND_UPLOAD:
449 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
454 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
460 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
461 if (bus_id == NULL) {
465 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
466 (sense_data.devno >> 24),
467 (sense_data.devno >> 16) & 0xFF,
468 (sense_data.devno & 0xFFFF));
471 read_lock_irq(&zfcp_data.config_lock);
472 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
473 if (strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
475 zfcp_adapter_get(adapter);
480 read_unlock_irq(&zfcp_data.config_lock);
485 ZFCP_LOG_INFO("invalid adapter\n");
489 if (sense_data.command & ZFCP_CFDC_WITH_CONTROL_FILE) {
490 retval = zfcp_sg_list_alloc(sg_list,
491 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
498 if ((sense_data.command & ZFCP_CFDC_DOWNLOAD) &&
499 (sense_data.command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
500 retval = zfcp_sg_list_copy_from_user(
501 sg_list, &sense_data_user->control_file,
502 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
509 retval = zfcp_fsf_control_file(
510 adapter, &fsf_req, fsf_command, option, sg_list);
511 if (retval == -EOPNOTSUPP) {
512 ZFCP_LOG_INFO("adapter does not support cfdc\n");
514 } else if (retval != 0) {
515 ZFCP_LOG_INFO("initiation of cfdc up/download failed\n");
520 wait_event(fsf_req->completion_wq,
521 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
523 sense_data.fsf_status = fsf_req->qtcb->header.fsf_status;
524 memcpy(&sense_data.fsf_status_qual,
525 &fsf_req->qtcb->header.fsf_status_qual,
526 sizeof(union fsf_status_qual));
527 memcpy(&sense_data.payloads, &fsf_req->qtcb->bottom.support.els, 256);
529 retval = copy_to_user(sense_data_user, &sense_data,
530 sizeof(struct zfcp_cfdc_sense_data));
536 if (sense_data.command & ZFCP_CFDC_UPLOAD) {
537 retval = zfcp_sg_list_copy_to_user(
538 &sense_data_user->control_file, sg_list,
539 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
548 zfcp_fsf_req_cleanup(fsf_req);
550 if ((adapter != NULL) && (retval != -ENXIO))
551 zfcp_adapter_put(adapter);
553 if (sg_list != NULL) {
554 zfcp_sg_list_free(sg_list);
563 * function: zfcp_sg_list_alloc
565 * purpose: Create a scatter-gather list of the specified size
567 * returns: 0 - Scatter gather list is created
568 * -ENOMEM - Insufficient memory (*list_ptr is then set to NULL)
571 zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
573 struct scatterlist *sg;
577 sg_list->count = size >> PAGE_SHIFT;
578 if (size & ~PAGE_MASK)
580 sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
582 if (sg_list->sg == NULL) {
588 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
589 sg->length = min(size, PAGE_SIZE);
591 sg->page = alloc_pages(GFP_KERNEL, 0);
592 if (sg->page == NULL) {
594 zfcp_sg_list_free(sg_list);
607 * function: zfcp_sg_list_free
609 * purpose: Destroy a scatter-gather list and release memory
614 zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
616 struct scatterlist *sg;
620 BUG_ON(sg_list == NULL);
622 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
623 __free_pages(sg->page, 0);
632 * function: zfcp_sg_list_copy_from_user
634 * purpose: Copy data from user space memory to the scatter-gather list
636 * returns: 0 - The data has been copied from user
637 * -EFAULT - Memory I/O operation fault
640 zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list, void *user_buffer,
643 struct scatterlist *sg;
648 for (sg = sg_list->sg; size > 0; sg++) {
649 length = min((unsigned int)size, sg->length);
650 zfcp_buffer = (void*)
651 ((page_to_pfn(sg->page) << PAGE_SHIFT) + sg->offset);
652 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
656 user_buffer += length;
666 * function: zfcp_sg_list_copy_to_user
668 * purpose: Copy data from the scatter-gather list to user space memory
670 * returns: 0 - The data has been copied to user
671 * -EFAULT - Memory I/O operation fault
674 zfcp_sg_list_copy_to_user(void *user_buffer, struct zfcp_sg_list *sg_list,
677 struct scatterlist *sg;
682 for (sg = sg_list->sg; size > 0; sg++) {
683 length = min((unsigned int)size, sg->length);
684 zfcp_buffer = (void*)
685 ((page_to_pfn(sg->page) << PAGE_SHIFT) + sg->offset);
686 if (copy_to_user(user_buffer, zfcp_buffer, length)) {
690 user_buffer += length;
701 /****************************************************************/
702 /****** Functions for configuration/set-up of structures ********/
703 /****************************************************************/
705 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
708 * zfcp_get_unit_by_lun - find unit in unit list of port by fcp lun
709 * @port: pointer to port to search for unit
710 * @fcp_lun: lun to search for
711 * Traverses list of all units of a port and returns pointer to a unit
712 * if lun of a unit matches.
716 zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
718 struct zfcp_unit *unit;
721 list_for_each_entry(unit, &port->unit_list_head, list) {
722 if ((unit->fcp_lun == fcp_lun) &&
723 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
729 return found ? unit : NULL;
733 * zfcp_get_port_by_wwpn - find unit in unit list of port by fcp lun
734 * @adapter: pointer to adapter to search for port
735 * @wwpn: wwpn to search for
736 * Traverses list of all ports of an adapter and returns a pointer to a port
737 * if wwpn of a port matches.
741 zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
743 struct zfcp_port *port;
746 list_for_each_entry(port, &adapter->port_list_head, list) {
747 if ((port->wwpn == wwpn) &&
748 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
754 return found ? port : NULL;
758 * Enqueues a logical unit at the end of the unit list associated with the
759 * specified port. Also sets up some unit internal structures.
761 * returns: pointer to unit with a usecount of 1 if a new unit was
762 * successfully enqueued
764 * locks: config_sema must be held to serialise changes to the unit list
767 zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
769 struct zfcp_unit *unit, *tmp_unit;
774 * check that there is no unit with this FCP_LUN already in list
776 * Note: Unlike for the adapter and the port, this is an error
778 read_lock_irq(&zfcp_data.config_lock);
779 unit = zfcp_get_unit_by_lun(port, fcp_lun);
780 read_unlock_irq(&zfcp_data.config_lock);
784 unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
787 memset(unit, 0, sizeof (struct zfcp_unit));
789 init_waitqueue_head(&unit->scsi_add_wq);
790 /* initialise reference count stuff */
791 atomic_set(&unit->refcount, 0);
792 init_waitqueue_head(&unit->remove_wq);
795 unit->fcp_lun = fcp_lun;
797 /* setup for sysfs registration */
798 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
799 unit->sysfs_device.parent = &port->sysfs_device;
800 unit->sysfs_device.release = zfcp_sysfs_unit_release;
801 dev_set_drvdata(&unit->sysfs_device, unit);
803 /* mark unit unusable as long as sysfs registration is not complete */
804 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
806 if (device_register(&unit->sysfs_device)) {
811 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
812 device_unregister(&unit->sysfs_device);
820 write_lock_irq(&zfcp_data.config_lock);
821 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
822 if (tmp_unit->scsi_lun != scsi_lun) {
828 unit->scsi_lun = scsi_lun;
830 list_add_tail(&unit->list, &tmp_unit->list);
832 list_add_tail(&unit->list, &port->unit_list_head);
833 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
834 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
835 write_unlock_irq(&zfcp_data.config_lock);
844 zfcp_unit_dequeue(struct zfcp_unit *unit)
846 zfcp_unit_wait(unit);
847 write_lock_irq(&zfcp_data.config_lock);
848 list_del(&unit->list);
849 write_unlock_irq(&zfcp_data.config_lock);
851 zfcp_port_put(unit->port);
852 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
853 device_unregister(&unit->sysfs_device);
857 zfcp_mempool_alloc(int gfp_mask, void *size)
859 return kmalloc((size_t) size, gfp_mask);
863 zfcp_mempool_free(void *element, void *size)
869 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
871 * It also genrates fcp-nameserver request/response buffer and unsolicited
872 * status read fsf_req buffers.
874 * locks: must only be called with zfcp_data.config_sema taken
877 zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
879 adapter->pool.fsf_req_erp =
880 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR,
881 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
882 sizeof(struct zfcp_fsf_req_pool_element));
884 if (NULL == adapter->pool.fsf_req_erp)
887 adapter->pool.fsf_req_scsi =
888 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR,
889 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
890 sizeof(struct zfcp_fsf_req_pool_element));
892 if (NULL == adapter->pool.fsf_req_scsi)
895 adapter->pool.fsf_req_abort =
896 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR,
897 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
898 sizeof(struct zfcp_fsf_req_pool_element));
900 if (NULL == adapter->pool.fsf_req_abort)
903 adapter->pool.fsf_req_status_read =
904 mempool_create(ZFCP_POOL_STATUS_READ_NR,
905 zfcp_mempool_alloc, zfcp_mempool_free,
906 (void *) sizeof(struct zfcp_fsf_req));
908 if (NULL == adapter->pool.fsf_req_status_read)
911 adapter->pool.data_status_read =
912 mempool_create(ZFCP_POOL_STATUS_READ_NR,
913 zfcp_mempool_alloc, zfcp_mempool_free,
914 (void *) sizeof(struct fsf_status_read_buffer));
916 if (NULL == adapter->pool.data_status_read)
919 adapter->pool.data_gid_pn =
920 mempool_create(ZFCP_POOL_DATA_GID_PN_NR,
921 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
922 sizeof(struct zfcp_gid_pn_data));
924 if (NULL == adapter->pool.data_gid_pn)
931 * zfcp_free_low_mem_buffers - free memory pools of an adapter
932 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
933 * locking: zfcp_data.config_sema must be held
936 zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
938 if (adapter->pool.fsf_req_erp)
939 mempool_destroy(adapter->pool.fsf_req_erp);
940 if (adapter->pool.fsf_req_scsi)
941 mempool_destroy(adapter->pool.fsf_req_scsi);
942 if (adapter->pool.fsf_req_abort)
943 mempool_destroy(adapter->pool.fsf_req_abort);
944 if (adapter->pool.fsf_req_status_read)
945 mempool_destroy(adapter->pool.fsf_req_status_read);
946 if (adapter->pool.data_status_read)
947 mempool_destroy(adapter->pool.data_status_read);
948 if (adapter->pool.data_gid_pn)
949 mempool_destroy(adapter->pool.data_gid_pn);
953 * zfcp_adapter_debug_register - registers debug feature for an adapter
954 * @adapter: pointer to adapter for which debug features should be registered
955 * return: -ENOMEM on error, 0 otherwise
958 zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
962 /* debug feature area which records SCSI command failures (hostbyte) */
963 rwlock_init(&adapter->cmd_dbf_lock);
964 sprintf(dbf_name, ZFCP_CMD_DBF_NAME "%s",
965 zfcp_get_busid_by_adapter(adapter));
966 adapter->cmd_dbf = debug_register(dbf_name,
969 ZFCP_CMD_DBF_LENGTH);
970 debug_register_view(adapter->cmd_dbf, &debug_hex_ascii_view);
971 debug_set_level(adapter->cmd_dbf, ZFCP_CMD_DBF_LEVEL);
973 /* debug feature area which records SCSI command aborts */
974 sprintf(dbf_name, ZFCP_ABORT_DBF_NAME "%s",
975 zfcp_get_busid_by_adapter(adapter));
976 adapter->abort_dbf = debug_register(dbf_name,
977 ZFCP_ABORT_DBF_INDEX,
978 ZFCP_ABORT_DBF_AREAS,
979 ZFCP_ABORT_DBF_LENGTH);
980 debug_register_view(adapter->abort_dbf, &debug_hex_ascii_view);
981 debug_set_level(adapter->abort_dbf, ZFCP_ABORT_DBF_LEVEL);
983 /* debug feature area which records SCSI command aborts */
984 sprintf(dbf_name, ZFCP_IN_ELS_DBF_NAME "%s",
985 zfcp_get_busid_by_adapter(adapter));
986 adapter->in_els_dbf = debug_register(dbf_name,
987 ZFCP_IN_ELS_DBF_INDEX,
988 ZFCP_IN_ELS_DBF_AREAS,
989 ZFCP_IN_ELS_DBF_LENGTH);
990 debug_register_view(adapter->in_els_dbf, &debug_hex_ascii_view);
991 debug_set_level(adapter->in_els_dbf, ZFCP_IN_ELS_DBF_LEVEL);
994 /* debug feature area which records erp events */
995 sprintf(dbf_name, ZFCP_ERP_DBF_NAME "%s",
996 zfcp_get_busid_by_adapter(adapter));
997 adapter->erp_dbf = debug_register(dbf_name,
1000 ZFCP_ERP_DBF_LENGTH);
1001 debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view);
1002 debug_set_level(adapter->erp_dbf, ZFCP_ERP_DBF_LEVEL);
1004 if (adapter->cmd_dbf && adapter->abort_dbf &&
1005 adapter->in_els_dbf && adapter->erp_dbf)
1008 zfcp_adapter_debug_unregister(adapter);
1013 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1014 * @adapter: pointer to adapter for which debug features should be unregistered
1017 zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1019 debug_unregister(adapter->erp_dbf);
1020 debug_unregister(adapter->cmd_dbf);
1021 debug_unregister(adapter->abort_dbf);
1022 debug_unregister(adapter->in_els_dbf);
1026 * Enqueues an adapter at the end of the adapter list in the driver data.
1027 * All adapter internal structures are set up.
1028 * Proc-fs entries are also created.
1030 * returns: 0 if a new adapter was successfully enqueued
1031 * ZFCP_KNOWN if an adapter with this devno was already present
1032 * -ENOMEM if alloc failed
1033 * locks: config_sema must be held to serialise changes to the adapter list
1035 struct zfcp_adapter *
1036 zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1039 struct zfcp_adapter *adapter;
1042 * Note: It is safe to release the list_lock, as any list changes
1043 * are protected by the config_sema, which must be held to get here
1046 /* try to allocate new adapter data structure (zeroed) */
1047 adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
1049 ZFCP_LOG_INFO("error: allocation of base adapter "
1050 "structure failed\n");
1053 memset(adapter, 0, sizeof (struct zfcp_adapter));
1055 ccw_device->handler = NULL;
1057 /* save ccw_device pointer */
1058 adapter->ccw_device = ccw_device;
1060 retval = zfcp_qdio_allocate_queues(adapter);
1062 goto queues_alloc_failed;
1064 retval = zfcp_qdio_allocate(adapter);
1066 goto qdio_allocate_failed;
1068 retval = zfcp_allocate_low_mem_buffers(adapter);
1070 ZFCP_LOG_INFO("error: pool allocation failed\n");
1071 goto failed_low_mem_buffers;
1074 /* initialise reference count stuff */
1075 atomic_set(&adapter->refcount, 0);
1076 init_waitqueue_head(&adapter->remove_wq);
1078 /* initialise list of ports */
1079 INIT_LIST_HEAD(&adapter->port_list_head);
1081 /* initialise list of ports to be removed */
1082 INIT_LIST_HEAD(&adapter->port_remove_lh);
1084 /* initialize list of fsf requests */
1085 rwlock_init(&adapter->fsf_req_list_lock);
1086 INIT_LIST_HEAD(&adapter->fsf_req_list_head);
1088 /* initialize abort lock */
1089 rwlock_init(&adapter->abort_lock);
1091 /* initialise some erp stuff */
1092 init_waitqueue_head(&adapter->erp_thread_wqh);
1093 init_waitqueue_head(&adapter->erp_done_wqh);
1095 /* initialize lock of associated request queue */
1096 rwlock_init(&adapter->request_queue.queue_lock);
1098 /* intitialise SCSI ER timer */
1099 init_timer(&adapter->scsi_er_timer);
1101 /* set FC service class used per default */
1102 adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1104 sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
1105 ASCEBC(adapter->name, strlen(adapter->name));
1107 /* mark adapter unusable as long as sysfs registration is not complete */
1108 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1110 adapter->ccw_device = ccw_device;
1111 dev_set_drvdata(&ccw_device->dev, adapter);
1113 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1116 /* put allocated adapter at list tail */
1117 write_lock_irq(&zfcp_data.config_lock);
1118 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1119 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1120 write_unlock_irq(&zfcp_data.config_lock);
1122 zfcp_data.adapters++;
1127 dev_set_drvdata(&ccw_device->dev, NULL);
1128 failed_low_mem_buffers:
1129 zfcp_free_low_mem_buffers(adapter);
1130 if (qdio_free(ccw_device) != 0)
1131 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1132 zfcp_get_busid_by_adapter(adapter));
1133 qdio_allocate_failed:
1134 zfcp_qdio_free_queues(adapter);
1135 queues_alloc_failed:
1143 * returns: 0 - struct zfcp_adapter data structure successfully removed
1144 * !0 - struct zfcp_adapter data structure could not be removed
1146 * locks: adapter list write lock is assumed to be held by caller
1147 * adapter->fsf_req_list_lock is taken and released within this
1148 * function and must not be held on entry
1151 zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1154 unsigned long flags;
1156 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1157 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1158 /* sanity check: no pending FSF requests */
1159 read_lock_irqsave(&adapter->fsf_req_list_lock, flags);
1160 retval = !list_empty(&adapter->fsf_req_list_head);
1161 read_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
1163 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1164 "%i requests outstanding\n",
1165 zfcp_get_busid_by_adapter(adapter), adapter,
1166 atomic_read(&adapter->fsf_reqs_active));
1171 /* remove specified adapter data structure from list */
1172 write_lock_irq(&zfcp_data.config_lock);
1173 list_del(&adapter->list);
1174 write_unlock_irq(&zfcp_data.config_lock);
1176 /* decrease number of adapters in list */
1177 zfcp_data.adapters--;
1179 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1180 "%i adapters still in list\n",
1181 zfcp_get_busid_by_adapter(adapter),
1182 adapter, zfcp_data.adapters);
1184 retval = qdio_free(adapter->ccw_device);
1186 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1187 zfcp_get_busid_by_adapter(adapter));
1189 zfcp_free_low_mem_buffers(adapter);
1190 /* free memory of adapter data structure and queues */
1191 zfcp_qdio_free_queues(adapter);
1192 ZFCP_LOG_TRACE("freeing adapter structure\n");
1199 * Enqueues a remote port to the port list. All port internal structures
1200 * are set up and the sysfs entry is also generated.
1202 * returns: pointer to port or NULL
1203 * locks: config_sema must be held to serialise changes to the port list
1206 zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status)
1208 struct zfcp_port *port, *tmp_port;
1213 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1216 * check that there is no port with this WWPN already in list
1219 read_lock_irq(&zfcp_data.config_lock);
1220 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1221 read_unlock_irq(&zfcp_data.config_lock);
1226 port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1229 memset(port, 0, sizeof (struct zfcp_port));
1231 /* initialise reference count stuff */
1232 atomic_set(&port->refcount, 0);
1233 init_waitqueue_head(&port->remove_wq);
1235 INIT_LIST_HEAD(&port->unit_list_head);
1236 INIT_LIST_HEAD(&port->unit_remove_lh);
1238 port->adapter = adapter;
1243 atomic_set_mask(status, &port->status);
1245 /* setup for sysfs registration */
1246 if (status & ZFCP_STATUS_PORT_NAMESERVER)
1247 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, "nameserver");
1249 snprintf(port->sysfs_device.bus_id,
1250 BUS_ID_SIZE, "0x%016llx", wwpn);
1251 port->sysfs_device.parent = &adapter->ccw_device->dev;
1252 port->sysfs_device.release = zfcp_sysfs_port_release;
1253 dev_set_drvdata(&port->sysfs_device, port);
1255 /* mark port unusable as long as sysfs registration is not complete */
1256 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1258 if (device_register(&port->sysfs_device)) {
1263 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1264 device_unregister(&port->sysfs_device);
1268 zfcp_port_get(port);
1272 write_lock_irq(&zfcp_data.config_lock);
1273 list_for_each_entry(tmp_port, &adapter->port_list_head, list) {
1274 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_SCSI_ID,
1277 if (tmp_port->scsi_id != scsi_id) {
1283 port->scsi_id = scsi_id;
1285 list_add_tail(&port->list, &tmp_port->list);
1287 list_add_tail(&port->list, &adapter->port_list_head);
1288 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1289 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1290 write_unlock_irq(&zfcp_data.config_lock);
1293 zfcp_adapter_get(adapter);
1299 zfcp_port_dequeue(struct zfcp_port *port)
1301 zfcp_port_wait(port);
1302 write_lock_irq(&zfcp_data.config_lock);
1303 list_del(&port->list);
1304 write_unlock_irq(&zfcp_data.config_lock);
1305 port->adapter->ports--;
1306 zfcp_adapter_put(port->adapter);
1307 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1308 atomic_read(&port->status));
1309 device_unregister(&port->sysfs_device);
1312 /* Enqueues a nameserver port */
1314 zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1316 struct zfcp_port *port;
1318 /* generate port structure */
1319 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_NAMESERVER);
1321 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1322 "adapter %s failed\n",
1323 zfcp_get_busid_by_adapter(adapter));
1326 /* set special D_ID */
1327 port->d_id = ZFCP_DID_NAMESERVER;
1328 adapter->nameserver_port = port;
1329 zfcp_port_put(port);
1334 #undef ZFCP_LOG_AREA
1336 /****************************************************************/
1337 /******* Fibre Channel Standard related Functions **************/
1338 /****************************************************************/
1340 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1343 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1344 struct fsf_status_read_buffer *status_buffer)
1346 struct fcp_rscn_head *fcp_rscn_head;
1347 struct fcp_rscn_element *fcp_rscn_element;
1348 struct zfcp_port *port;
1352 unsigned long flags;
1354 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1355 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1358 no_entries = (fcp_rscn_head->payload_len / 4);
1360 zfcp_in_els_dbf_event(adapter, "##rscn", status_buffer,
1361 fcp_rscn_head->payload_len);
1363 debug_text_event(adapter->erp_dbf, 1, "unsol_els_rscn:");
1364 for (i = 1; i < no_entries; i++) {
1365 /* skip head and start with 1st element */
1367 switch (fcp_rscn_element->addr_format) {
1368 case ZFCP_PORT_ADDRESS:
1369 ZFCP_LOG_FLAGS(1, "ZFCP_PORT_ADDRESS\n");
1370 range_mask = ZFCP_PORTS_RANGE_PORT;
1372 case ZFCP_AREA_ADDRESS:
1373 ZFCP_LOG_FLAGS(1, "ZFCP_AREA_ADDRESS\n");
1374 range_mask = ZFCP_PORTS_RANGE_AREA;
1376 case ZFCP_DOMAIN_ADDRESS:
1377 ZFCP_LOG_FLAGS(1, "ZFCP_DOMAIN_ADDRESS\n");
1378 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1380 case ZFCP_FABRIC_ADDRESS:
1381 ZFCP_LOG_FLAGS(1, "ZFCP_FABRIC_ADDRESS\n");
1382 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1385 ZFCP_LOG_INFO("incoming RSCN with unknown "
1386 "address format\n");
1389 read_lock_irqsave(&zfcp_data.config_lock, flags);
1390 list_for_each_entry(port, &adapter->port_list_head, list) {
1391 if (atomic_test_mask
1392 (ZFCP_STATUS_PORT_NAMESERVER, &port->status))
1394 /* Do we know this port? If not skip it. */
1395 if (!atomic_test_mask
1396 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1397 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1398 "port 0x%016Lx\n", port->wwpn);
1399 debug_text_event(adapter->erp_dbf, 1,
1400 "unsol_els_rscnu:");
1401 zfcp_erp_port_reopen(port,
1402 ZFCP_STATUS_COMMON_ERP_FAILED);
1407 * FIXME: race: d_id might being invalidated
1408 * (...DID_DID reset)
1410 if ((port->d_id & range_mask)
1411 == (fcp_rscn_element->nport_did & range_mask)) {
1412 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1413 fcp_rscn_element->nport_did);
1415 * Unfortunately, an RSCN does not specify the
1416 * type of change a target underwent. We assume
1417 * that it makes sense to reopen the link.
1418 * FIXME: Shall we try to find out more about
1419 * the target and link state before closing it?
1420 * How to accomplish this? (nameserver?)
1421 * Where would such code be put in?
1422 * (inside or outside erp)
1424 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1425 "port 0x%016Lx\n", port->wwpn);
1426 debug_text_event(adapter->erp_dbf, 1,
1427 "unsol_els_rscnk:");
1428 zfcp_test_link(port);
1431 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1436 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1437 struct fsf_status_read_buffer *status_buffer)
1439 logi *els_logi = (logi *) status_buffer->payload;
1440 struct zfcp_port *port;
1441 unsigned long flags;
1443 zfcp_in_els_dbf_event(adapter, "##plogi", status_buffer, 28);
1445 read_lock_irqsave(&zfcp_data.config_lock, flags);
1446 list_for_each_entry(port, &adapter->port_list_head, list) {
1447 if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
1450 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1452 if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
1453 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1454 "with d_id 0x%08x on adapter %s\n",
1455 status_buffer->d_id,
1456 zfcp_get_busid_by_adapter(adapter));
1458 debug_text_event(adapter->erp_dbf, 1, "unsol_els_plogi:");
1459 debug_event(adapter->erp_dbf, 1, &els_logi->nport_wwn, 8);
1460 zfcp_erp_port_forced_reopen(port, 0);
1465 zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1466 struct fsf_status_read_buffer *status_buffer)
1468 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1469 struct zfcp_port *port;
1470 unsigned long flags;
1472 zfcp_in_els_dbf_event(adapter, "##logo", status_buffer, 16);
1474 read_lock_irqsave(&zfcp_data.config_lock, flags);
1475 list_for_each_entry(port, &adapter->port_list_head, list) {
1476 if (port->wwpn == els_logo->nport_wwpn)
1479 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1481 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1482 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1483 "with d_id 0x%08x on adapter %s\n",
1484 status_buffer->d_id,
1485 zfcp_get_busid_by_adapter(adapter));
1487 debug_text_event(adapter->erp_dbf, 1, "unsol_els_logo:");
1488 debug_event(adapter->erp_dbf, 1, &els_logo->nport_wwpn, 8);
1489 zfcp_erp_port_forced_reopen(port, 0);
1494 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
1495 struct fsf_status_read_buffer *status_buffer)
1497 zfcp_in_els_dbf_event(adapter, "##undef", status_buffer, 24);
1498 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1499 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1500 zfcp_get_busid_by_adapter(adapter));
1505 zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1507 struct fsf_status_read_buffer *status_buffer;
1509 struct zfcp_adapter *adapter;
1511 status_buffer = fsf_req->data.status_read.buffer;
1512 els_type = *(u32 *) (status_buffer->payload);
1513 adapter = fsf_req->adapter;
1515 if (els_type == LS_PLOGI)
1516 zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
1517 else if (els_type == LS_LOGO)
1518 zfcp_fsf_incoming_els_logo(adapter, status_buffer);
1519 else if ((els_type & 0xffff0000) == LS_RSCN)
1520 /* we are only concerned with the command, not the length */
1521 zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
1523 zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
1529 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1530 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1531 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1534 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1536 struct zfcp_gid_pn_data *data;
1539 data = mempool_alloc(pool, GFP_ATOMIC);
1540 if (likely(data != NULL)) {
1541 data->ct.pool = pool;
1544 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1550 memset(data, 0, sizeof(*data));
1551 data->ct.req = &data->req;
1552 data->ct.resp = &data->resp;
1553 data->ct.req_count = data->ct.resp_count = 1;
1554 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1555 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1556 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1557 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1564 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1565 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1568 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1570 if ((gid_pn->ct.pool != 0))
1571 mempool_free(gid_pn, gid_pn->ct.pool);
1579 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1580 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1583 zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1586 struct ct_iu_gid_pn_req *ct_iu_req;
1587 struct zfcp_gid_pn_data *gid_pn;
1588 struct zfcp_adapter *adapter = erp_action->adapter;
1590 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1592 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1593 "request failed for adapter %s\n",
1594 zfcp_get_busid_by_adapter(adapter));
1598 /* setup nameserver request */
1599 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1600 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1601 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1602 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1603 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1604 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1605 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1606 ct_iu_req->wwpn = erp_action->port->wwpn;
1608 /* setup parameters for send generic command */
1609 gid_pn->ct.port = adapter->nameserver_port;
1610 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1611 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1612 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1613 gid_pn->ct.timer = &erp_action->timer;
1614 gid_pn->port = erp_action->port;
1616 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1619 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1620 "failed for adapter %s\n",
1621 zfcp_get_busid_by_adapter(adapter));
1623 zfcp_gid_pn_buffers_free(gid_pn);
1631 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1632 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1634 static void zfcp_ns_gid_pn_handler(unsigned long data)
1636 struct zfcp_port *port;
1637 struct zfcp_send_ct *ct;
1638 struct ct_iu_gid_pn_req *ct_iu_req;
1639 struct ct_iu_gid_pn_resp *ct_iu_resp;
1640 struct zfcp_gid_pn_data *gid_pn;
1643 gid_pn = (struct zfcp_gid_pn_data *) data;
1644 port = gid_pn->port;
1646 ct_iu_req = zfcp_sg_to_address(ct->req);
1647 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1649 if (ct_iu_resp->header.revision != ZFCP_CT_REVISION)
1651 if (ct_iu_resp->header.gs_type != ZFCP_CT_DIRECTORY_SERVICE)
1653 if (ct_iu_resp->header.gs_subtype != ZFCP_CT_NAME_SERVER)
1655 if (ct_iu_resp->header.options != ZFCP_CT_SYNCHRONOUS)
1657 if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) {
1658 /* FIXME: do we need some specific erp entry points */
1659 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1663 if (ct_iu_req->wwpn != port->wwpn) {
1664 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1665 "lookup does not match expected wwpn 0x%016Lx "
1666 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1667 zfcp_get_busid_by_port(port));
1671 /* looks like a valid d_id */
1672 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1673 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1674 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1675 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1679 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1680 "0x%016Lx for adapter %s\n",
1681 port->wwpn, zfcp_get_busid_by_port(port));
1682 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1683 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1684 sizeof(struct ct_iu_gid_pn_req));
1685 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1686 sizeof(struct ct_iu_gid_pn_resp));
1689 zfcp_gid_pn_buffers_free(gid_pn);
1693 #undef ZFCP_LOG_AREA