3 * linux/drivers/s390/scsi/zfcp_aux.c
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 /* accumulated log level (module parameter) */
35 static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS;
37 /*********************** FUNCTION PROTOTYPES *********************************/
39 /* written against the module interface */
40 static int __init zfcp_module_init(void);
43 static void zfcp_ns_gid_pn_handler(unsigned long);
46 static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
47 static inline void zfcp_sg_list_free(struct zfcp_sg_list *);
48 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *,
49 void __user *, size_t);
50 static inline int zfcp_sg_list_copy_to_user(void __user *,
51 struct zfcp_sg_list *, size_t);
53 static long zfcp_cfdc_dev_ioctl(struct file *, unsigned int, unsigned long);
55 #define ZFCP_CFDC_IOC_MAGIC 0xDD
56 #define ZFCP_CFDC_IOC \
57 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
60 static struct file_operations zfcp_cfdc_fops = {
61 .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
63 .compat_ioctl = zfcp_cfdc_dev_ioctl
67 static struct miscdevice zfcp_cfdc_misc = {
68 .minor = ZFCP_CFDC_DEV_MINOR,
69 .name = ZFCP_CFDC_DEV_NAME,
70 .fops = &zfcp_cfdc_fops
73 /*********************** KERNEL/MODULE PARAMETERS ***************************/
75 /* declare driver module init/cleanup functions */
76 module_init(zfcp_module_init);
78 MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, "
79 "Andreas Herrman <aherrman@de.ibm.com>, "
80 "Martin Peschke <mpeschke@de.ibm.com>, "
81 "Raimund Schroeder <raimund.schroeder@de.ibm.com>, "
82 "Wolfgang Taphorn <taphorn@de.ibm.com>, "
83 "Aron Zeh <arzeh@de.ibm.com>, "
84 "IBM Deutschland Entwicklung GmbH");
86 ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries");
87 MODULE_LICENSE("GPL");
89 module_param(device, charp, 0400);
90 MODULE_PARM_DESC(device, "specify initial device");
92 module_param(loglevel, uint, 0400);
93 MODULE_PARM_DESC(loglevel,
94 "log levels, 8 nibbles: "
95 "FC ERP QDIO CIO Config FSF SCSI Other, "
96 "levels: 0=none 1=normal 2=devel 3=trace");
98 /****************************************************************/
99 /************** Functions without logging ***********************/
100 /****************************************************************/
103 _zfcp_hex_dump(char *addr, int count)
106 for (i = 0; i < count; i++) {
107 printk("%02x", addr[i]);
113 if (((i-1) % 32) != 31)
117 /****************************************************************/
118 /************** Uncategorised Functions *************************/
119 /****************************************************************/
121 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
124 * zfcp_device_setup - setup function
125 * @str: pointer to parameter string
127 * Parse "device=..." parameter string.
130 zfcp_device_setup(char *devstr)
138 len = strlen(devstr) + 1;
139 str = (char *) kmalloc(len, GFP_KERNEL);
142 memcpy(str, devstr, len);
144 tmp = strchr(str, ',');
148 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
149 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
151 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
157 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
164 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
170 zfcp_init_device_configure(void)
172 struct zfcp_adapter *adapter;
173 struct zfcp_port *port;
174 struct zfcp_unit *unit;
176 down(&zfcp_data.config_sema);
177 read_lock_irq(&zfcp_data.config_lock);
178 adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
180 zfcp_adapter_get(adapter);
181 read_unlock_irq(&zfcp_data.config_lock);
185 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
188 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
191 up(&zfcp_data.config_sema);
192 ccw_device_set_online(adapter->ccw_device);
193 zfcp_erp_wait(adapter);
194 down(&zfcp_data.config_sema);
199 zfcp_adapter_put(adapter);
201 up(&zfcp_data.config_sema);
206 zfcp_module_init(void)
211 atomic_set(&zfcp_data.loglevel, loglevel);
213 /* initialize adapter list */
214 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
216 /* initialize adapters to be removed list head */
217 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
219 zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
220 if (!zfcp_transport_template)
223 retval = misc_register(&zfcp_cfdc_misc);
225 ZFCP_LOG_INFO("registration of misc device "
226 "zfcp_cfdc failed\n");
230 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
231 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
233 /* Initialise proc semaphores */
234 sema_init(&zfcp_data.config_sema, 1);
236 /* initialise configuration rw lock */
237 rwlock_init(&zfcp_data.config_lock);
239 /* save address of data structure managing the driver module */
240 zfcp_data.scsi_host_template.module = THIS_MODULE;
242 /* setup dynamic I/O */
243 retval = zfcp_ccw_register();
245 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
246 goto out_ccw_register;
249 if (zfcp_device_setup(device))
250 zfcp_init_device_configure();
255 misc_deregister(&zfcp_cfdc_misc);
261 * function: zfcp_cfdc_dev_ioctl
263 * purpose: Handle control file upload/download transaction via IOCTL
266 * returns: 0 - Operation completed successfuly
267 * -ENOTTY - Unknown IOCTL command
268 * -EINVAL - Invalid sense data record
269 * -ENXIO - The FCP adapter is not available
270 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
271 * -ENOMEM - Insufficient memory
272 * -EFAULT - User space memory I/O operation fault
273 * -EPERM - Cannot create or queue FSF request or create SBALs
274 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
277 zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
278 unsigned long buffer)
280 struct zfcp_cfdc_sense_data *sense_data, __user *sense_data_user;
281 struct zfcp_adapter *adapter = NULL;
282 struct zfcp_fsf_req *fsf_req = NULL;
283 struct zfcp_sg_list *sg_list = NULL;
284 u32 fsf_command, option;
288 sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL);
289 if (sense_data == NULL) {
294 sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
295 if (sg_list == NULL) {
299 memset(sg_list, 0, sizeof(*sg_list));
301 if (command != ZFCP_CFDC_IOC) {
302 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
307 if ((sense_data_user = (void __user *) buffer) == NULL) {
308 ZFCP_LOG_INFO("sense data record is required\n");
313 retval = copy_from_user(sense_data, sense_data_user,
314 sizeof(struct zfcp_cfdc_sense_data));
320 if (sense_data->signature != ZFCP_CFDC_SIGNATURE) {
321 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
322 ZFCP_CFDC_SIGNATURE);
327 switch (sense_data->command) {
329 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
330 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
331 option = FSF_CFDC_OPTION_NORMAL_MODE;
334 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
335 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
336 option = FSF_CFDC_OPTION_FORCE;
339 case ZFCP_CFDC_CMND_FULL_ACCESS:
340 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
341 option = FSF_CFDC_OPTION_FULL_ACCESS;
344 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
345 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
346 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
349 case ZFCP_CFDC_CMND_UPLOAD:
350 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
355 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
356 sense_data->command);
361 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
362 if (bus_id == NULL) {
366 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
367 (sense_data->devno >> 24),
368 (sense_data->devno >> 16) & 0xFF,
369 (sense_data->devno & 0xFFFF));
371 read_lock_irq(&zfcp_data.config_lock);
372 adapter = zfcp_get_adapter_by_busid(bus_id);
374 zfcp_adapter_get(adapter);
375 read_unlock_irq(&zfcp_data.config_lock);
379 if (adapter == NULL) {
380 ZFCP_LOG_INFO("invalid adapter\n");
385 if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) {
386 retval = zfcp_sg_list_alloc(sg_list,
387 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
394 if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) &&
395 (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
396 retval = zfcp_sg_list_copy_from_user(
397 sg_list, &sense_data_user->control_file,
398 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
405 retval = zfcp_fsf_control_file(adapter, &fsf_req, fsf_command,
410 if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
411 (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
416 sense_data->fsf_status = fsf_req->qtcb->header.fsf_status;
417 memcpy(&sense_data->fsf_status_qual,
418 &fsf_req->qtcb->header.fsf_status_qual,
419 sizeof(union fsf_status_qual));
420 memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256);
422 retval = copy_to_user(sense_data_user, sense_data,
423 sizeof(struct zfcp_cfdc_sense_data));
429 if (sense_data->command & ZFCP_CFDC_UPLOAD) {
430 retval = zfcp_sg_list_copy_to_user(
431 &sense_data_user->control_file, sg_list,
432 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
441 zfcp_fsf_req_free(fsf_req);
443 if ((adapter != NULL) && (retval != -ENXIO))
444 zfcp_adapter_put(adapter);
446 if (sg_list != NULL) {
447 zfcp_sg_list_free(sg_list);
458 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
459 * @sg_list: structure describing a scatter gather list
460 * @size: size of scatter-gather list
461 * Return: 0 on success, else -ENOMEM
463 * In sg_list->sg a pointer to the created scatter-gather list is returned,
464 * or NULL if we run out of memory. sg_list->count specifies the number of
465 * elements of the scatter-gather list. The maximum size of a single element
466 * in the scatter-gather list is PAGE_SIZE.
469 zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
471 struct scatterlist *sg;
476 BUG_ON(sg_list == NULL);
478 sg_list->count = size >> PAGE_SHIFT;
479 if (size & ~PAGE_MASK)
481 sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
483 if (sg_list->sg == NULL) {
488 memset(sg_list->sg, 0, sg_list->count * sizeof(struct scatterlist));
490 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
491 sg->length = min(size, PAGE_SIZE);
493 address = (void *) get_zeroed_page(GFP_KERNEL);
494 if (address == NULL) {
496 zfcp_sg_list_free(sg_list);
500 zfcp_address_to_sg(address, sg);
510 * zfcp_sg_list_free - free memory of a scatter-gather list
511 * @sg_list: structure describing a scatter-gather list
513 * Memory for each element in the scatter-gather list is freed.
514 * Finally sg_list->sg is freed itself and sg_list->count is reset.
517 zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
519 struct scatterlist *sg;
522 BUG_ON(sg_list == NULL);
524 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
525 free_page((unsigned long) zfcp_sg_to_address(sg));
532 * zfcp_sg_size - determine size of a scatter-gather list
533 * @sg: array of (struct scatterlist)
534 * @sg_count: elements in array
535 * Return: size of entire scatter-gather list
538 zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
541 struct scatterlist *p;
545 for (i = 0, p = sg; i < sg_count; i++, p++) {
555 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
556 * @sg_list: structure describing a scatter-gather list
557 * @user_buffer: pointer to buffer in user space
558 * @size: number of bytes to be copied
559 * Return: 0 on success, -EFAULT if copy_from_user fails.
562 zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list,
563 void __user *user_buffer,
566 struct scatterlist *sg;
571 BUG_ON(sg_list == NULL);
573 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
576 for (sg = sg_list->sg; size > 0; sg++) {
577 length = min((unsigned int)size, sg->length);
578 zfcp_buffer = zfcp_sg_to_address(sg);
579 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
583 user_buffer += length;
593 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
594 * @user_buffer: pointer to buffer in user space
595 * @sg_list: structure describing a scatter-gather list
596 * @size: number of bytes to be copied
597 * Return: 0 on success, -EFAULT if copy_to_user fails
600 zfcp_sg_list_copy_to_user(void __user *user_buffer,
601 struct zfcp_sg_list *sg_list,
604 struct scatterlist *sg;
609 BUG_ON(sg_list == NULL);
611 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
614 for (sg = sg_list->sg; size > 0; sg++) {
615 length = min((unsigned int) size, sg->length);
616 zfcp_buffer = zfcp_sg_to_address(sg);
617 if (copy_to_user(user_buffer, zfcp_buffer, length)) {
621 user_buffer += length;
632 /****************************************************************/
633 /****** Functions for configuration/set-up of structures ********/
634 /****************************************************************/
636 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
639 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
640 * @port: pointer to port to search for unit
641 * @fcp_lun: FCP LUN to search for
642 * Traverse list of all units of a port and return pointer to a unit
643 * with the given FCP LUN.
646 zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
648 struct zfcp_unit *unit;
651 list_for_each_entry(unit, &port->unit_list_head, list) {
652 if ((unit->fcp_lun == fcp_lun) &&
653 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
659 return found ? unit : NULL;
663 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
664 * @adapter: pointer to adapter to search for port
665 * @wwpn: wwpn to search for
666 * Traverse list of all ports of an adapter and return pointer to a port
667 * with the given wwpn.
670 zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
672 struct zfcp_port *port;
675 list_for_each_entry(port, &adapter->port_list_head, list) {
676 if ((port->wwpn == wwpn) &&
677 !(atomic_read(&port->status) &
678 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
683 return found ? port : NULL;
687 * zfcp_get_port_by_did - find port in port list of adapter by d_id
688 * @adapter: pointer to adapter to search for port
689 * @d_id: d_id to search for
690 * Traverse list of all ports of an adapter and return pointer to a port
691 * with the given d_id.
694 zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
696 struct zfcp_port *port;
699 list_for_each_entry(port, &adapter->port_list_head, list) {
700 if ((port->d_id == d_id) &&
701 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
707 return found ? port : NULL;
711 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
712 * @bus_id: bus_id to search for
713 * Traverse list of all adapters and return pointer to an adapter
714 * with the given bus_id.
716 struct zfcp_adapter *
717 zfcp_get_adapter_by_busid(char *bus_id)
719 struct zfcp_adapter *adapter;
722 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
723 if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
724 BUS_ID_SIZE) == 0) &&
725 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
731 return found ? adapter : NULL;
735 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
736 * @port: pointer to port where unit is added
737 * @fcp_lun: FCP LUN of unit to be enqueued
738 * Return: pointer to enqueued unit on success, NULL on error
739 * Locks: config_sema must be held to serialize changes to the unit list
741 * Sets up some unit internal structures and creates sysfs entry.
744 zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
746 struct zfcp_unit *unit, *tmp_unit;
751 * check that there is no unit with this FCP_LUN already in list
753 * Note: Unlike for the adapter and the port, this is an error
755 read_lock_irq(&zfcp_data.config_lock);
756 unit = zfcp_get_unit_by_lun(port, fcp_lun);
757 read_unlock_irq(&zfcp_data.config_lock);
761 unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
764 memset(unit, 0, sizeof (struct zfcp_unit));
766 /* initialise reference count stuff */
767 atomic_set(&unit->refcount, 0);
768 init_waitqueue_head(&unit->remove_wq);
771 unit->fcp_lun = fcp_lun;
773 /* setup for sysfs registration */
774 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
775 unit->sysfs_device.parent = &port->sysfs_device;
776 unit->sysfs_device.release = zfcp_sysfs_unit_release;
777 dev_set_drvdata(&unit->sysfs_device, unit);
779 /* mark unit unusable as long as sysfs registration is not complete */
780 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
782 if (device_register(&unit->sysfs_device)) {
787 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
788 device_unregister(&unit->sysfs_device);
796 write_lock_irq(&zfcp_data.config_lock);
797 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
798 if (tmp_unit->scsi_lun != scsi_lun) {
804 unit->scsi_lun = scsi_lun;
806 list_add_tail(&unit->list, &tmp_unit->list);
808 list_add_tail(&unit->list, &port->unit_list_head);
809 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
810 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
811 write_unlock_irq(&zfcp_data.config_lock);
820 zfcp_unit_dequeue(struct zfcp_unit *unit)
822 zfcp_unit_wait(unit);
823 write_lock_irq(&zfcp_data.config_lock);
824 list_del(&unit->list);
825 write_unlock_irq(&zfcp_data.config_lock);
827 zfcp_port_put(unit->port);
828 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
829 device_unregister(&unit->sysfs_device);
833 zfcp_mempool_alloc(gfp_t gfp_mask, void *size)
835 return kmalloc((size_t) size, gfp_mask);
839 zfcp_mempool_free(void *element, void *size)
845 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
847 * It also genrates fcp-nameserver request/response buffer and unsolicited
848 * status read fsf_req buffers.
850 * locks: must only be called with zfcp_data.config_sema taken
853 zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
855 adapter->pool.fsf_req_erp =
856 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR,
857 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
858 sizeof(struct zfcp_fsf_req_pool_element));
860 if (NULL == adapter->pool.fsf_req_erp)
863 adapter->pool.fsf_req_scsi =
864 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR,
865 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
866 sizeof(struct zfcp_fsf_req_pool_element));
868 if (NULL == adapter->pool.fsf_req_scsi)
871 adapter->pool.fsf_req_abort =
872 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR,
873 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
874 sizeof(struct zfcp_fsf_req_pool_element));
876 if (NULL == adapter->pool.fsf_req_abort)
879 adapter->pool.fsf_req_status_read =
880 mempool_create(ZFCP_POOL_STATUS_READ_NR,
881 zfcp_mempool_alloc, zfcp_mempool_free,
882 (void *) sizeof(struct zfcp_fsf_req));
884 if (NULL == adapter->pool.fsf_req_status_read)
887 adapter->pool.data_status_read =
888 mempool_create(ZFCP_POOL_STATUS_READ_NR,
889 zfcp_mempool_alloc, zfcp_mempool_free,
890 (void *) sizeof(struct fsf_status_read_buffer));
892 if (NULL == adapter->pool.data_status_read)
895 adapter->pool.data_gid_pn =
896 mempool_create(ZFCP_POOL_DATA_GID_PN_NR,
897 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
898 sizeof(struct zfcp_gid_pn_data));
900 if (NULL == adapter->pool.data_gid_pn)
907 * zfcp_free_low_mem_buffers - free memory pools of an adapter
908 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
909 * locking: zfcp_data.config_sema must be held
912 zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
914 if (adapter->pool.fsf_req_erp)
915 mempool_destroy(adapter->pool.fsf_req_erp);
916 if (adapter->pool.fsf_req_scsi)
917 mempool_destroy(adapter->pool.fsf_req_scsi);
918 if (adapter->pool.fsf_req_abort)
919 mempool_destroy(adapter->pool.fsf_req_abort);
920 if (adapter->pool.fsf_req_status_read)
921 mempool_destroy(adapter->pool.fsf_req_status_read);
922 if (adapter->pool.data_status_read)
923 mempool_destroy(adapter->pool.data_status_read);
924 if (adapter->pool.data_gid_pn)
925 mempool_destroy(adapter->pool.data_gid_pn);
929 zfcp_dummy_release(struct device *dev)
935 * Enqueues an adapter at the end of the adapter list in the driver data.
936 * All adapter internal structures are set up.
937 * Proc-fs entries are also created.
939 * returns: 0 if a new adapter was successfully enqueued
940 * ZFCP_KNOWN if an adapter with this devno was already present
941 * -ENOMEM if alloc failed
942 * locks: config_sema must be held to serialise changes to the adapter list
944 struct zfcp_adapter *
945 zfcp_adapter_enqueue(struct ccw_device *ccw_device)
948 struct zfcp_adapter *adapter;
951 * Note: It is safe to release the list_lock, as any list changes
952 * are protected by the config_sema, which must be held to get here
955 /* try to allocate new adapter data structure (zeroed) */
956 adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
958 ZFCP_LOG_INFO("error: allocation of base adapter "
959 "structure failed\n");
962 memset(adapter, 0, sizeof (struct zfcp_adapter));
964 ccw_device->handler = NULL;
966 /* save ccw_device pointer */
967 adapter->ccw_device = ccw_device;
969 retval = zfcp_qdio_allocate_queues(adapter);
971 goto queues_alloc_failed;
973 retval = zfcp_qdio_allocate(adapter);
975 goto qdio_allocate_failed;
977 retval = zfcp_allocate_low_mem_buffers(adapter);
979 ZFCP_LOG_INFO("error: pool allocation failed\n");
980 goto failed_low_mem_buffers;
983 /* initialise reference count stuff */
984 atomic_set(&adapter->refcount, 0);
985 init_waitqueue_head(&adapter->remove_wq);
987 /* initialise list of ports */
988 INIT_LIST_HEAD(&adapter->port_list_head);
990 /* initialise list of ports to be removed */
991 INIT_LIST_HEAD(&adapter->port_remove_lh);
993 /* initialize list of fsf requests */
994 spin_lock_init(&adapter->fsf_req_list_lock);
995 INIT_LIST_HEAD(&adapter->fsf_req_list_head);
997 /* initialize debug locks */
999 spin_lock_init(&adapter->erp_dbf_lock);
1000 spin_lock_init(&adapter->hba_dbf_lock);
1001 spin_lock_init(&adapter->san_dbf_lock);
1002 spin_lock_init(&adapter->scsi_dbf_lock);
1004 /* initialize error recovery stuff */
1006 rwlock_init(&adapter->erp_lock);
1007 sema_init(&adapter->erp_ready_sem, 0);
1008 INIT_LIST_HEAD(&adapter->erp_ready_head);
1009 INIT_LIST_HEAD(&adapter->erp_running_head);
1011 /* initialize abort lock */
1012 rwlock_init(&adapter->abort_lock);
1014 /* initialise some erp stuff */
1015 init_waitqueue_head(&adapter->erp_thread_wqh);
1016 init_waitqueue_head(&adapter->erp_done_wqh);
1018 /* initialize lock of associated request queue */
1019 rwlock_init(&adapter->request_queue.queue_lock);
1021 /* intitialise SCSI ER timer */
1022 init_timer(&adapter->scsi_er_timer);
1024 /* set FC service class used per default */
1025 adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1027 sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
1028 ASCEBC(adapter->name, strlen(adapter->name));
1030 /* mark adapter unusable as long as sysfs registration is not complete */
1031 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1033 adapter->ccw_device = ccw_device;
1034 dev_set_drvdata(&ccw_device->dev, adapter);
1036 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1039 adapter->generic_services.parent = &adapter->ccw_device->dev;
1040 adapter->generic_services.release = zfcp_dummy_release;
1041 snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
1042 "generic_services");
1044 if (device_register(&adapter->generic_services))
1045 goto generic_services_failed;
1047 /* put allocated adapter at list tail */
1048 write_lock_irq(&zfcp_data.config_lock);
1049 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1050 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1051 write_unlock_irq(&zfcp_data.config_lock);
1053 zfcp_data.adapters++;
1057 generic_services_failed:
1058 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1060 dev_set_drvdata(&ccw_device->dev, NULL);
1061 failed_low_mem_buffers:
1062 zfcp_free_low_mem_buffers(adapter);
1063 if (qdio_free(ccw_device) != 0)
1064 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1065 zfcp_get_busid_by_adapter(adapter));
1066 qdio_allocate_failed:
1067 zfcp_qdio_free_queues(adapter);
1068 queues_alloc_failed:
1076 * returns: 0 - struct zfcp_adapter data structure successfully removed
1077 * !0 - struct zfcp_adapter data structure could not be removed
1079 * locks: adapter list write lock is assumed to be held by caller
1080 * adapter->fsf_req_list_lock is taken and released within this
1081 * function and must not be held on entry
1084 zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1087 unsigned long flags;
1089 device_unregister(&adapter->generic_services);
1090 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1091 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1092 /* sanity check: no pending FSF requests */
1093 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
1094 retval = !list_empty(&adapter->fsf_req_list_head);
1095 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
1097 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1098 "%i requests outstanding\n",
1099 zfcp_get_busid_by_adapter(adapter), adapter,
1100 atomic_read(&adapter->fsf_reqs_active));
1105 /* remove specified adapter data structure from list */
1106 write_lock_irq(&zfcp_data.config_lock);
1107 list_del(&adapter->list);
1108 write_unlock_irq(&zfcp_data.config_lock);
1110 /* decrease number of adapters in list */
1111 zfcp_data.adapters--;
1113 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1114 "%i adapters still in list\n",
1115 zfcp_get_busid_by_adapter(adapter),
1116 adapter, zfcp_data.adapters);
1118 retval = qdio_free(adapter->ccw_device);
1120 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1121 zfcp_get_busid_by_adapter(adapter));
1123 zfcp_free_low_mem_buffers(adapter);
1124 /* free memory of adapter data structure and queues */
1125 zfcp_qdio_free_queues(adapter);
1126 kfree(adapter->fc_stats);
1127 kfree(adapter->stats_reset_data);
1128 ZFCP_LOG_TRACE("freeing adapter structure\n");
1135 * zfcp_port_enqueue - enqueue port to port list of adapter
1136 * @adapter: adapter where remote port is added
1137 * @wwpn: WWPN of the remote port to be enqueued
1138 * @status: initial status for the port
1139 * @d_id: destination id of the remote port to be enqueued
1140 * Return: pointer to enqueued port on success, NULL on error
1141 * Locks: config_sema must be held to serialize changes to the port list
1143 * All port internal structures are set up and the sysfs entry is generated.
1144 * d_id is used to enqueue ports with a well known address like the Directory
1145 * Service for nameserver lookup.
1148 zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
1151 struct zfcp_port *port;
1154 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1156 * check that there is no port with this WWPN already in list
1159 read_lock_irq(&zfcp_data.config_lock);
1160 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1161 read_unlock_irq(&zfcp_data.config_lock);
1166 port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1169 memset(port, 0, sizeof (struct zfcp_port));
1171 /* initialise reference count stuff */
1172 atomic_set(&port->refcount, 0);
1173 init_waitqueue_head(&port->remove_wq);
1175 INIT_LIST_HEAD(&port->unit_list_head);
1176 INIT_LIST_HEAD(&port->unit_remove_lh);
1178 port->adapter = adapter;
1183 atomic_set_mask(status, &port->status);
1185 /* setup for sysfs registration */
1186 if (status & ZFCP_STATUS_PORT_WKA) {
1188 case ZFCP_DID_DIRECTORY_SERVICE:
1189 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1192 case ZFCP_DID_MANAGEMENT_SERVICE:
1193 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1196 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
1197 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1198 "key_distribution");
1200 case ZFCP_DID_ALIAS_SERVICE:
1201 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1204 case ZFCP_DID_TIME_SERVICE:
1205 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1213 port->sysfs_device.parent = &adapter->generic_services;
1215 snprintf(port->sysfs_device.bus_id,
1216 BUS_ID_SIZE, "0x%016llx", wwpn);
1217 port->sysfs_device.parent = &adapter->ccw_device->dev;
1219 port->sysfs_device.release = zfcp_sysfs_port_release;
1220 dev_set_drvdata(&port->sysfs_device, port);
1222 /* mark port unusable as long as sysfs registration is not complete */
1223 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1225 if (device_register(&port->sysfs_device)) {
1230 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1231 device_unregister(&port->sysfs_device);
1235 zfcp_port_get(port);
1237 write_lock_irq(&zfcp_data.config_lock);
1238 list_add_tail(&port->list, &adapter->port_list_head);
1239 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1240 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1241 if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
1242 if (!adapter->nameserver_port)
1243 adapter->nameserver_port = port;
1245 write_unlock_irq(&zfcp_data.config_lock);
1247 zfcp_adapter_get(adapter);
1253 zfcp_port_dequeue(struct zfcp_port *port)
1255 zfcp_port_wait(port);
1256 write_lock_irq(&zfcp_data.config_lock);
1257 list_del(&port->list);
1258 port->adapter->ports--;
1259 write_unlock_irq(&zfcp_data.config_lock);
1261 fc_remote_port_delete(port->rport);
1263 zfcp_adapter_put(port->adapter);
1264 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1265 atomic_read(&port->status));
1266 device_unregister(&port->sysfs_device);
1269 /* Enqueues a nameserver port */
1271 zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1273 struct zfcp_port *port;
1275 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
1276 ZFCP_DID_DIRECTORY_SERVICE);
1278 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1279 "adapter %s failed\n",
1280 zfcp_get_busid_by_adapter(adapter));
1283 zfcp_port_put(port);
1288 #undef ZFCP_LOG_AREA
1290 /****************************************************************/
1291 /******* Fibre Channel Standard related Functions **************/
1292 /****************************************************************/
1294 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1297 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1298 struct fsf_status_read_buffer *status_buffer)
1300 struct fcp_rscn_head *fcp_rscn_head;
1301 struct fcp_rscn_element *fcp_rscn_element;
1302 struct zfcp_port *port;
1306 unsigned long flags;
1308 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1309 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1312 no_entries = (fcp_rscn_head->payload_len / 4);
1314 for (i = 1; i < no_entries; i++) {
1315 /* skip head and start with 1st element */
1317 switch (fcp_rscn_element->addr_format) {
1318 case ZFCP_PORT_ADDRESS:
1319 range_mask = ZFCP_PORTS_RANGE_PORT;
1321 case ZFCP_AREA_ADDRESS:
1322 range_mask = ZFCP_PORTS_RANGE_AREA;
1324 case ZFCP_DOMAIN_ADDRESS:
1325 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1327 case ZFCP_FABRIC_ADDRESS:
1328 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1331 ZFCP_LOG_INFO("incoming RSCN with unknown "
1332 "address format\n");
1335 read_lock_irqsave(&zfcp_data.config_lock, flags);
1336 list_for_each_entry(port, &adapter->port_list_head, list) {
1337 if (atomic_test_mask
1338 (ZFCP_STATUS_PORT_WKA, &port->status))
1340 /* Do we know this port? If not skip it. */
1341 if (!atomic_test_mask
1342 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1343 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1344 "port 0x%016Lx\n", port->wwpn);
1345 zfcp_erp_port_reopen(port,
1346 ZFCP_STATUS_COMMON_ERP_FAILED);
1351 * FIXME: race: d_id might being invalidated
1352 * (...DID_DID reset)
1354 if ((port->d_id & range_mask)
1355 == (fcp_rscn_element->nport_did & range_mask)) {
1356 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1357 fcp_rscn_element->nport_did);
1359 * Unfortunately, an RSCN does not specify the
1360 * type of change a target underwent. We assume
1361 * that it makes sense to reopen the link.
1362 * FIXME: Shall we try to find out more about
1363 * the target and link state before closing it?
1364 * How to accomplish this? (nameserver?)
1365 * Where would such code be put in?
1366 * (inside or outside erp)
1368 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1369 "port 0x%016Lx\n", port->wwpn);
1370 zfcp_test_link(port);
1373 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1378 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1379 struct fsf_status_read_buffer *status_buffer)
1381 logi *els_logi = (logi *) status_buffer->payload;
1382 struct zfcp_port *port;
1383 unsigned long flags;
1385 read_lock_irqsave(&zfcp_data.config_lock, flags);
1386 list_for_each_entry(port, &adapter->port_list_head, list) {
1387 if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
1390 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1392 if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
1393 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1394 "with d_id 0x%08x on adapter %s\n",
1395 status_buffer->d_id,
1396 zfcp_get_busid_by_adapter(adapter));
1398 zfcp_erp_port_forced_reopen(port, 0);
1403 zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1404 struct fsf_status_read_buffer *status_buffer)
1406 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1407 struct zfcp_port *port;
1408 unsigned long flags;
1410 read_lock_irqsave(&zfcp_data.config_lock, flags);
1411 list_for_each_entry(port, &adapter->port_list_head, list) {
1412 if (port->wwpn == els_logo->nport_wwpn)
1415 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1417 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1418 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1419 "with d_id 0x%08x on adapter %s\n",
1420 status_buffer->d_id,
1421 zfcp_get_busid_by_adapter(adapter));
1423 zfcp_erp_port_forced_reopen(port, 0);
1428 zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
1429 struct fsf_status_read_buffer *status_buffer)
1431 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1432 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1433 zfcp_get_busid_by_adapter(adapter));
1438 zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1440 struct fsf_status_read_buffer *status_buffer;
1442 struct zfcp_adapter *adapter;
1444 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
1445 els_type = *(u32 *) (status_buffer->payload);
1446 adapter = fsf_req->adapter;
1448 zfcp_san_dbf_event_incoming_els(fsf_req);
1449 if (els_type == LS_PLOGI)
1450 zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
1451 else if (els_type == LS_LOGO)
1452 zfcp_fsf_incoming_els_logo(adapter, status_buffer);
1453 else if ((els_type & 0xffff0000) == LS_RSCN)
1454 /* we are only concerned with the command, not the length */
1455 zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
1457 zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
1462 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1463 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1464 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1467 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1469 struct zfcp_gid_pn_data *data;
1472 data = mempool_alloc(pool, GFP_ATOMIC);
1473 if (likely(data != NULL)) {
1474 data->ct.pool = pool;
1477 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1483 memset(data, 0, sizeof(*data));
1484 data->ct.req = &data->req;
1485 data->ct.resp = &data->resp;
1486 data->ct.req_count = data->ct.resp_count = 1;
1487 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1488 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1489 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1490 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1497 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1498 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1501 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1503 if ((gid_pn->ct.pool != 0))
1504 mempool_free(gid_pn, gid_pn->ct.pool);
1512 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1513 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1516 zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1519 struct ct_iu_gid_pn_req *ct_iu_req;
1520 struct zfcp_gid_pn_data *gid_pn;
1521 struct zfcp_adapter *adapter = erp_action->adapter;
1523 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1525 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1526 "request failed for adapter %s\n",
1527 zfcp_get_busid_by_adapter(adapter));
1531 /* setup nameserver request */
1532 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1533 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1534 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1535 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1536 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1537 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1538 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1539 ct_iu_req->wwpn = erp_action->port->wwpn;
1541 /* setup parameters for send generic command */
1542 gid_pn->ct.port = adapter->nameserver_port;
1543 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1544 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1545 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1546 gid_pn->ct.timer = &erp_action->timer;
1547 gid_pn->port = erp_action->port;
1549 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1552 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1553 "failed for adapter %s\n",
1554 zfcp_get_busid_by_adapter(adapter));
1556 zfcp_gid_pn_buffers_free(gid_pn);
1564 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1565 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1567 static void zfcp_ns_gid_pn_handler(unsigned long data)
1569 struct zfcp_port *port;
1570 struct zfcp_send_ct *ct;
1571 struct ct_iu_gid_pn_req *ct_iu_req;
1572 struct ct_iu_gid_pn_resp *ct_iu_resp;
1573 struct zfcp_gid_pn_data *gid_pn;
1576 gid_pn = (struct zfcp_gid_pn_data *) data;
1577 port = gid_pn->port;
1579 ct_iu_req = zfcp_sg_to_address(ct->req);
1580 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1582 if (ct->status != 0)
1585 if (zfcp_check_ct_response(&ct_iu_resp->header)) {
1586 /* FIXME: do we need some specific erp entry points */
1587 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1591 if (ct_iu_req->wwpn != port->wwpn) {
1592 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1593 "lookup does not match expected wwpn 0x%016Lx "
1594 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1595 zfcp_get_busid_by_port(port));
1599 /* looks like a valid d_id */
1600 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1601 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1602 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1603 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1607 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1608 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1609 sizeof(struct ct_iu_gid_pn_req));
1610 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1611 sizeof(struct ct_iu_gid_pn_resp));
1614 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1615 "0x%016Lx for adapter %s\n",
1616 port->wwpn, zfcp_get_busid_by_port(port));
1618 zfcp_gid_pn_buffers_free(gid_pn);
1622 /* reject CT_IU reason codes acc. to FC-GS-4 */
1623 static const struct zfcp_rc_entry zfcp_ct_rc[] = {
1624 {0x01, "invalid command code"},
1625 {0x02, "invalid version level"},
1626 {0x03, "logical error"},
1627 {0x04, "invalid CT_IU size"},
1628 {0x05, "logical busy"},
1629 {0x07, "protocol error"},
1630 {0x09, "unable to perform command request"},
1631 {0x0b, "command not supported"},
1632 {0x0d, "server not available"},
1633 {0x0e, "session could not be established"},
1634 {0xff, "vendor specific error"},
1638 /* LS_RJT reason codes acc. to FC-FS */
1639 static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = {
1640 {0x01, "invalid LS_Command code"},
1641 {0x03, "logical error"},
1642 {0x05, "logical busy"},
1643 {0x07, "protocol error"},
1644 {0x09, "unable to perform command request"},
1645 {0x0b, "command not supported"},
1646 {0x0e, "command already in progress"},
1647 {0xff, "vendor specific error"},
1651 /* reject reason codes according to FC-PH/FC-FS */
1652 static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = {
1653 {0x01, "invalid D_ID"},
1654 {0x02, "invalid S_ID"},
1655 {0x03, "Nx_Port not available, temporary"},
1656 {0x04, "Nx_Port not available, permament"},
1657 {0x05, "class not supported"},
1658 {0x06, "delimiter usage error"},
1659 {0x07, "TYPE not supported"},
1660 {0x08, "invalid Link_Control"},
1661 {0x09, "invalid R_CTL field"},
1662 {0x0a, "invalid F_CTL field"},
1663 {0x0b, "invalid OX_ID"},
1664 {0x0c, "invalid RX_ID"},
1665 {0x0d, "invalid SEQ_ID"},
1666 {0x0e, "invalid DF_CTL"},
1667 {0x0f, "invalid SEQ_CNT"},
1668 {0x10, "invalid parameter field"},
1669 {0x11, "exchange error"},
1670 {0x12, "protocol error"},
1671 {0x13, "incorrect length"},
1672 {0x14, "unsupported ACK"},
1673 {0x15, "class of service not supported by entity at FFFFFE"},
1674 {0x16, "login required"},
1675 {0x17, "excessive sequences attempted"},
1676 {0x18, "unable to establish exchange"},
1677 {0x1a, "fabric path not available"},
1678 {0x1b, "invalid VC_ID (class 4)"},
1679 {0x1c, "invalid CS_CTL field"},
1680 {0x1d, "insufficient resources for VC (class 4)"},
1681 {0x1f, "invalid class of service"},
1682 {0x20, "preemption request rejected"},
1683 {0x21, "preemption not enabled"},
1684 {0x22, "multicast error"},
1685 {0x23, "multicast error terminate"},
1686 {0x24, "process login required"},
1687 {0xff, "vendor specific reject"},
1692 * zfcp_rc_description - return description for given reaon code
1693 * @code: reason code
1694 * @rc_table: table of reason codes and descriptions
1696 static inline const char *
1697 zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table)
1699 const char *descr = "unknown reason code";
1702 if (code == rc_table->code) {
1703 descr = rc_table->description;
1707 } while (rc_table->code && rc_table->description);
1713 * zfcp_check_ct_response - evaluate reason code for CT_IU
1714 * @rjt: response payload to an CT_IU request
1715 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1718 zfcp_check_ct_response(struct ct_hdr *rjt)
1720 if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT)
1723 if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) {
1724 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1725 "response code (0x%04hx)\n",
1730 ZFCP_LOG_INFO("Generic Service command rejected\n");
1731 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1732 zfcp_rc_description(rjt->reason_code, zfcp_ct_rc),
1733 (u32) rjt->reason_code, (u32) rjt->reason_code_expl,
1734 (u32) rjt->vendor_unique);
1740 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1741 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1742 * @rc_table: table of reason codes and descriptions
1745 zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par,
1746 const struct zfcp_rc_entry *rc_table)
1748 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1749 zfcp_rc_description(rjt_par->reason_code, rc_table),
1750 (u32) rjt_par->action, (u32) rjt_par->reason_code,
1751 (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique);
1755 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1756 * @sq: status qualifier word
1757 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1758 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1761 zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par)
1765 if (sq == FSF_IOSTAT_NPORT_RJT) {
1766 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1767 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1769 if (rjt_par->reason_code == 0x01)
1771 } else if (sq == FSF_IOSTAT_FABRIC_RJT) {
1772 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1773 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1775 if (rjt_par->reason_code == 0x01)
1777 } else if (sq == FSF_IOSTAT_LS_RJT) {
1778 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1779 zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc);
1782 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq);
1787 #undef ZFCP_LOG_AREA