2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Martin Peschke (originator of the driver)
29 * Heiko Carstens (kernel 2.6 port of the driver)
38 /* accumulated log level (module parameter) */
39 static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS;
41 /*********************** FUNCTION PROTOTYPES *********************************/
43 /* written against the module interface */
44 static int __init zfcp_module_init(void);
47 static void zfcp_ns_gid_pn_handler(unsigned long);
50 static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
51 static inline void zfcp_sg_list_free(struct zfcp_sg_list *);
52 static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *,
53 void __user *, size_t);
54 static inline int zfcp_sg_list_copy_to_user(void __user *,
55 struct zfcp_sg_list *, size_t);
57 static long zfcp_cfdc_dev_ioctl(struct file *, 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)
64 static struct file_operations zfcp_cfdc_fops = {
65 .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
67 .compat_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("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
84 ("FCP (SCSI over Fibre Channel) HBA driver for IBM System z9 and zSeries");
85 MODULE_LICENSE("GPL");
87 module_param(device, charp, 0400);
88 MODULE_PARM_DESC(device, "specify initial device");
90 module_param(loglevel, uint, 0400);
91 MODULE_PARM_DESC(loglevel,
92 "log levels, 8 nibbles: "
93 "FC ERP QDIO CIO Config FSF SCSI Other, "
94 "levels: 0=none 1=normal 2=devel 3=trace");
96 /****************************************************************/
97 /************** Functions without logging ***********************/
98 /****************************************************************/
101 _zfcp_hex_dump(char *addr, int count)
104 for (i = 0; i < count; i++) {
105 printk("%02x", addr[i]);
111 if (((i-1) % 32) != 31)
116 /****************************************************************/
117 /****** Functions to handle the request ID hash table ********/
118 /****************************************************************/
120 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
122 static int zfcp_reqlist_init(struct zfcp_adapter *adapter)
126 adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head),
129 if (!adapter->req_list)
132 for (i=0; i<REQUEST_LIST_SIZE; i++)
133 INIT_LIST_HEAD(&adapter->req_list[i]);
138 static void zfcp_reqlist_free(struct zfcp_adapter *adapter)
140 struct zfcp_fsf_req *request, *tmp;
143 for (i=0; i<REQUEST_LIST_SIZE; i++) {
144 if (list_empty(&adapter->req_list[i]))
147 list_for_each_entry_safe(request, tmp,
148 &adapter->req_list[i], list)
149 list_del(&request->list);
152 kfree(adapter->req_list);
155 void zfcp_reqlist_add(struct zfcp_adapter *adapter,
156 struct zfcp_fsf_req *fsf_req)
160 i = fsf_req->req_id % REQUEST_LIST_SIZE;
161 list_add_tail(&fsf_req->list, &adapter->req_list[i]);
164 void zfcp_reqlist_remove(struct zfcp_adapter *adapter, unsigned long req_id)
166 struct zfcp_fsf_req *request, *tmp;
167 unsigned int i, counter;
170 i = req_id % REQUEST_LIST_SIZE;
171 BUG_ON(list_empty(&adapter->req_list[i]));
174 list_for_each_entry_safe(request, tmp, &adapter->req_list[i], list) {
175 if (request->req_id == req_id) {
176 dbg_tmp[0] = (u64) atomic_read(&adapter->reqs_active);
177 dbg_tmp[1] = (u64) counter;
178 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
179 list_del(&request->list);
186 struct zfcp_fsf_req *zfcp_reqlist_ismember(struct zfcp_adapter *adapter,
187 unsigned long req_id)
189 struct zfcp_fsf_req *request, *tmp;
192 i = req_id % REQUEST_LIST_SIZE;
194 list_for_each_entry_safe(request, tmp, &adapter->req_list[i], list)
195 if (request->req_id == req_id)
201 int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
205 for (i=0; i<REQUEST_LIST_SIZE; i++)
206 if (!list_empty(&adapter->req_list[i]))
214 /****************************************************************/
215 /************** Uncategorised Functions *************************/
216 /****************************************************************/
218 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
221 * zfcp_device_setup - setup function
222 * @str: pointer to parameter string
224 * Parse "device=..." parameter string.
227 zfcp_device_setup(char *devstr)
235 len = strlen(devstr) + 1;
236 str = (char *) kmalloc(len, GFP_KERNEL);
239 memcpy(str, devstr, len);
241 tmp = strchr(str, ',');
245 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
246 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
248 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
254 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
261 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
267 zfcp_init_device_configure(void)
269 struct zfcp_adapter *adapter;
270 struct zfcp_port *port;
271 struct zfcp_unit *unit;
273 down(&zfcp_data.config_sema);
274 read_lock_irq(&zfcp_data.config_lock);
275 adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
277 zfcp_adapter_get(adapter);
278 read_unlock_irq(&zfcp_data.config_lock);
282 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
285 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
288 up(&zfcp_data.config_sema);
289 ccw_device_set_online(adapter->ccw_device);
290 zfcp_erp_wait(adapter);
291 down(&zfcp_data.config_sema);
296 zfcp_adapter_put(adapter);
298 up(&zfcp_data.config_sema);
303 zfcp_module_init(void)
308 atomic_set(&zfcp_data.loglevel, loglevel);
310 /* initialize adapter list */
311 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
313 /* initialize adapters to be removed list head */
314 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
316 zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
317 if (!zfcp_transport_template)
320 retval = misc_register(&zfcp_cfdc_misc);
322 ZFCP_LOG_INFO("registration of misc device "
323 "zfcp_cfdc failed\n");
327 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
328 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
330 /* Initialise proc semaphores */
331 sema_init(&zfcp_data.config_sema, 1);
333 /* initialise configuration rw lock */
334 rwlock_init(&zfcp_data.config_lock);
336 /* save address of data structure managing the driver module */
337 zfcp_data.scsi_host_template.module = THIS_MODULE;
339 /* setup dynamic I/O */
340 retval = zfcp_ccw_register();
342 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
343 goto out_ccw_register;
346 if (zfcp_device_setup(device))
347 zfcp_init_device_configure();
352 misc_deregister(&zfcp_cfdc_misc);
358 * function: zfcp_cfdc_dev_ioctl
360 * purpose: Handle control file upload/download transaction via IOCTL
363 * returns: 0 - Operation completed successfuly
364 * -ENOTTY - Unknown IOCTL command
365 * -EINVAL - Invalid sense data record
366 * -ENXIO - The FCP adapter is not available
367 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
368 * -ENOMEM - Insufficient memory
369 * -EFAULT - User space memory I/O operation fault
370 * -EPERM - Cannot create or queue FSF request or create SBALs
371 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
374 zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
375 unsigned long buffer)
377 struct zfcp_cfdc_sense_data *sense_data, __user *sense_data_user;
378 struct zfcp_adapter *adapter = NULL;
379 struct zfcp_fsf_req *fsf_req = NULL;
380 struct zfcp_sg_list *sg_list = NULL;
381 u32 fsf_command, option;
385 sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL);
386 if (sense_data == NULL) {
391 sg_list = kzalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
392 if (sg_list == NULL) {
397 if (command != ZFCP_CFDC_IOC) {
398 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
403 if ((sense_data_user = (void __user *) buffer) == NULL) {
404 ZFCP_LOG_INFO("sense data record is required\n");
409 retval = copy_from_user(sense_data, sense_data_user,
410 sizeof(struct zfcp_cfdc_sense_data));
416 if (sense_data->signature != ZFCP_CFDC_SIGNATURE) {
417 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
418 ZFCP_CFDC_SIGNATURE);
423 switch (sense_data->command) {
425 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
426 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
427 option = FSF_CFDC_OPTION_NORMAL_MODE;
430 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
431 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
432 option = FSF_CFDC_OPTION_FORCE;
435 case ZFCP_CFDC_CMND_FULL_ACCESS:
436 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
437 option = FSF_CFDC_OPTION_FULL_ACCESS;
440 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
441 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
442 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
445 case ZFCP_CFDC_CMND_UPLOAD:
446 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
451 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
452 sense_data->command);
457 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
458 if (bus_id == NULL) {
462 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
463 (sense_data->devno >> 24),
464 (sense_data->devno >> 16) & 0xFF,
465 (sense_data->devno & 0xFFFF));
467 read_lock_irq(&zfcp_data.config_lock);
468 adapter = zfcp_get_adapter_by_busid(bus_id);
470 zfcp_adapter_get(adapter);
471 read_unlock_irq(&zfcp_data.config_lock);
475 if (adapter == NULL) {
476 ZFCP_LOG_INFO("invalid adapter\n");
481 if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) {
482 retval = zfcp_sg_list_alloc(sg_list,
483 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
490 if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) &&
491 (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
492 retval = zfcp_sg_list_copy_from_user(
493 sg_list, &sense_data_user->control_file,
494 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
501 retval = zfcp_fsf_control_file(adapter, &fsf_req, fsf_command,
506 if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
507 (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
512 sense_data->fsf_status = fsf_req->qtcb->header.fsf_status;
513 memcpy(&sense_data->fsf_status_qual,
514 &fsf_req->qtcb->header.fsf_status_qual,
515 sizeof(union fsf_status_qual));
516 memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256);
518 retval = copy_to_user(sense_data_user, sense_data,
519 sizeof(struct zfcp_cfdc_sense_data));
525 if (sense_data->command & ZFCP_CFDC_UPLOAD) {
526 retval = zfcp_sg_list_copy_to_user(
527 &sense_data_user->control_file, sg_list,
528 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
537 zfcp_fsf_req_free(fsf_req);
539 if ((adapter != NULL) && (retval != -ENXIO))
540 zfcp_adapter_put(adapter);
542 if (sg_list != NULL) {
543 zfcp_sg_list_free(sg_list);
554 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
555 * @sg_list: structure describing a scatter gather list
556 * @size: size of scatter-gather list
557 * Return: 0 on success, else -ENOMEM
559 * In sg_list->sg a pointer to the created scatter-gather list is returned,
560 * or NULL if we run out of memory. sg_list->count specifies the number of
561 * elements of the scatter-gather list. The maximum size of a single element
562 * in the scatter-gather list is PAGE_SIZE.
565 zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
567 struct scatterlist *sg;
572 BUG_ON(sg_list == NULL);
574 sg_list->count = size >> PAGE_SHIFT;
575 if (size & ~PAGE_MASK)
577 sg_list->sg = kcalloc(sg_list->count, sizeof(struct scatterlist),
579 if (sg_list->sg == NULL) {
585 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
586 sg->length = min(size, PAGE_SIZE);
588 address = (void *) get_zeroed_page(GFP_KERNEL);
589 if (address == NULL) {
591 zfcp_sg_list_free(sg_list);
595 zfcp_address_to_sg(address, sg);
605 * zfcp_sg_list_free - free memory of a scatter-gather list
606 * @sg_list: structure describing a scatter-gather list
608 * Memory for each element in the scatter-gather list is freed.
609 * Finally sg_list->sg is freed itself and sg_list->count is reset.
612 zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
614 struct scatterlist *sg;
617 BUG_ON(sg_list == NULL);
619 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
620 free_page((unsigned long) zfcp_sg_to_address(sg));
627 * zfcp_sg_size - determine size of a scatter-gather list
628 * @sg: array of (struct scatterlist)
629 * @sg_count: elements in array
630 * Return: size of entire scatter-gather list
633 zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
636 struct scatterlist *p;
640 for (i = 0, p = sg; i < sg_count; i++, p++) {
650 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
651 * @sg_list: structure describing a scatter-gather list
652 * @user_buffer: pointer to buffer in user space
653 * @size: number of bytes to be copied
654 * Return: 0 on success, -EFAULT if copy_from_user fails.
657 zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list,
658 void __user *user_buffer,
661 struct scatterlist *sg;
666 BUG_ON(sg_list == NULL);
668 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
671 for (sg = sg_list->sg; size > 0; sg++) {
672 length = min((unsigned int)size, sg->length);
673 zfcp_buffer = zfcp_sg_to_address(sg);
674 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
678 user_buffer += length;
688 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
689 * @user_buffer: pointer to buffer in user space
690 * @sg_list: structure describing a scatter-gather list
691 * @size: number of bytes to be copied
692 * Return: 0 on success, -EFAULT if copy_to_user fails
695 zfcp_sg_list_copy_to_user(void __user *user_buffer,
696 struct zfcp_sg_list *sg_list,
699 struct scatterlist *sg;
704 BUG_ON(sg_list == NULL);
706 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
709 for (sg = sg_list->sg; size > 0; sg++) {
710 length = min((unsigned int) size, sg->length);
711 zfcp_buffer = zfcp_sg_to_address(sg);
712 if (copy_to_user(user_buffer, zfcp_buffer, length)) {
716 user_buffer += length;
727 /****************************************************************/
728 /****** Functions for configuration/set-up of structures ********/
729 /****************************************************************/
731 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
734 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
735 * @port: pointer to port to search for unit
736 * @fcp_lun: FCP LUN to search for
737 * Traverse list of all units of a port and return pointer to a unit
738 * with the given FCP LUN.
741 zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
743 struct zfcp_unit *unit;
746 list_for_each_entry(unit, &port->unit_list_head, list) {
747 if ((unit->fcp_lun == fcp_lun) &&
748 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
754 return found ? unit : NULL;
758 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
759 * @adapter: pointer to adapter to search for port
760 * @wwpn: wwpn to search for
761 * Traverse list of all ports of an adapter and return pointer to a port
762 * with the given wwpn.
765 zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
767 struct zfcp_port *port;
770 list_for_each_entry(port, &adapter->port_list_head, list) {
771 if ((port->wwpn == wwpn) &&
772 !(atomic_read(&port->status) &
773 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
778 return found ? port : NULL;
782 * zfcp_get_port_by_did - find port in port list of adapter by d_id
783 * @adapter: pointer to adapter to search for port
784 * @d_id: d_id to search for
785 * Traverse list of all ports of an adapter and return pointer to a port
786 * with the given d_id.
789 zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
791 struct zfcp_port *port;
794 list_for_each_entry(port, &adapter->port_list_head, list) {
795 if ((port->d_id == d_id) &&
796 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
802 return found ? port : NULL;
806 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
807 * @bus_id: bus_id to search for
808 * Traverse list of all adapters and return pointer to an adapter
809 * with the given bus_id.
811 struct zfcp_adapter *
812 zfcp_get_adapter_by_busid(char *bus_id)
814 struct zfcp_adapter *adapter;
817 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
818 if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
819 BUS_ID_SIZE) == 0) &&
820 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
826 return found ? adapter : NULL;
830 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
831 * @port: pointer to port where unit is added
832 * @fcp_lun: FCP LUN of unit to be enqueued
833 * Return: pointer to enqueued unit on success, NULL on error
834 * Locks: config_sema must be held to serialize changes to the unit list
836 * Sets up some unit internal structures and creates sysfs entry.
839 zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
841 struct zfcp_unit *unit, *tmp_unit;
842 unsigned int scsi_lun;
846 * check that there is no unit with this FCP_LUN already in list
848 * Note: Unlike for the adapter and the port, this is an error
850 read_lock_irq(&zfcp_data.config_lock);
851 unit = zfcp_get_unit_by_lun(port, fcp_lun);
852 read_unlock_irq(&zfcp_data.config_lock);
856 unit = kzalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
860 /* initialise reference count stuff */
861 atomic_set(&unit->refcount, 0);
862 init_waitqueue_head(&unit->remove_wq);
865 unit->fcp_lun = fcp_lun;
867 /* setup for sysfs registration */
868 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
869 unit->sysfs_device.parent = &port->sysfs_device;
870 unit->sysfs_device.release = zfcp_sysfs_unit_release;
871 dev_set_drvdata(&unit->sysfs_device, unit);
873 /* mark unit unusable as long as sysfs registration is not complete */
874 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
876 if (device_register(&unit->sysfs_device)) {
881 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
882 device_unregister(&unit->sysfs_device);
890 write_lock_irq(&zfcp_data.config_lock);
891 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
892 if (tmp_unit->scsi_lun != scsi_lun) {
898 unit->scsi_lun = scsi_lun;
900 list_add_tail(&unit->list, &tmp_unit->list);
902 list_add_tail(&unit->list, &port->unit_list_head);
903 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
904 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
905 write_unlock_irq(&zfcp_data.config_lock);
914 zfcp_unit_dequeue(struct zfcp_unit *unit)
916 zfcp_unit_wait(unit);
917 write_lock_irq(&zfcp_data.config_lock);
918 list_del(&unit->list);
919 write_unlock_irq(&zfcp_data.config_lock);
921 zfcp_port_put(unit->port);
922 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
923 device_unregister(&unit->sysfs_device);
927 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
929 * It also genrates fcp-nameserver request/response buffer and unsolicited
930 * status read fsf_req buffers.
932 * locks: must only be called with zfcp_data.config_sema taken
935 zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
937 adapter->pool.fsf_req_erp =
938 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ERP_NR,
939 sizeof(struct zfcp_fsf_req_pool_element));
940 if (!adapter->pool.fsf_req_erp)
943 adapter->pool.fsf_req_scsi =
944 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_SCSI_NR,
945 sizeof(struct zfcp_fsf_req_pool_element));
946 if (!adapter->pool.fsf_req_scsi)
949 adapter->pool.fsf_req_abort =
950 mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ABORT_NR,
951 sizeof(struct zfcp_fsf_req_pool_element));
952 if (!adapter->pool.fsf_req_abort)
955 adapter->pool.fsf_req_status_read =
956 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
957 sizeof(struct zfcp_fsf_req));
958 if (!adapter->pool.fsf_req_status_read)
961 adapter->pool.data_status_read =
962 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
963 sizeof(struct fsf_status_read_buffer));
964 if (!adapter->pool.data_status_read)
967 adapter->pool.data_gid_pn =
968 mempool_create_kmalloc_pool(ZFCP_POOL_DATA_GID_PN_NR,
969 sizeof(struct zfcp_gid_pn_data));
970 if (!adapter->pool.data_gid_pn)
977 * zfcp_free_low_mem_buffers - free memory pools of an adapter
978 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
979 * locking: zfcp_data.config_sema must be held
982 zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
984 if (adapter->pool.fsf_req_erp)
985 mempool_destroy(adapter->pool.fsf_req_erp);
986 if (adapter->pool.fsf_req_scsi)
987 mempool_destroy(adapter->pool.fsf_req_scsi);
988 if (adapter->pool.fsf_req_abort)
989 mempool_destroy(adapter->pool.fsf_req_abort);
990 if (adapter->pool.fsf_req_status_read)
991 mempool_destroy(adapter->pool.fsf_req_status_read);
992 if (adapter->pool.data_status_read)
993 mempool_destroy(adapter->pool.data_status_read);
994 if (adapter->pool.data_gid_pn)
995 mempool_destroy(adapter->pool.data_gid_pn);
999 zfcp_dummy_release(struct device *dev)
1005 * Enqueues an adapter at the end of the adapter list in the driver data.
1006 * All adapter internal structures are set up.
1007 * Proc-fs entries are also created.
1009 * returns: 0 if a new adapter was successfully enqueued
1010 * ZFCP_KNOWN if an adapter with this devno was already present
1011 * -ENOMEM if alloc failed
1012 * locks: config_sema must be held to serialise changes to the adapter list
1014 struct zfcp_adapter *
1015 zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1018 struct zfcp_adapter *adapter;
1021 * Note: It is safe to release the list_lock, as any list changes
1022 * are protected by the config_sema, which must be held to get here
1025 /* try to allocate new adapter data structure (zeroed) */
1026 adapter = kzalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
1028 ZFCP_LOG_INFO("error: allocation of base adapter "
1029 "structure failed\n");
1033 ccw_device->handler = NULL;
1035 /* save ccw_device pointer */
1036 adapter->ccw_device = ccw_device;
1038 retval = zfcp_qdio_allocate_queues(adapter);
1040 goto queues_alloc_failed;
1042 retval = zfcp_qdio_allocate(adapter);
1044 goto qdio_allocate_failed;
1046 retval = zfcp_allocate_low_mem_buffers(adapter);
1048 ZFCP_LOG_INFO("error: pool allocation failed\n");
1049 goto failed_low_mem_buffers;
1052 /* initialise reference count stuff */
1053 atomic_set(&adapter->refcount, 0);
1054 init_waitqueue_head(&adapter->remove_wq);
1056 /* initialise list of ports */
1057 INIT_LIST_HEAD(&adapter->port_list_head);
1059 /* initialise list of ports to be removed */
1060 INIT_LIST_HEAD(&adapter->port_remove_lh);
1062 /* initialize list of fsf requests */
1063 spin_lock_init(&adapter->req_list_lock);
1064 retval = zfcp_reqlist_init(adapter);
1066 ZFCP_LOG_INFO("request list initialization failed\n");
1067 goto failed_low_mem_buffers;
1070 /* initialize debug locks */
1072 spin_lock_init(&adapter->erp_dbf_lock);
1073 spin_lock_init(&adapter->hba_dbf_lock);
1074 spin_lock_init(&adapter->san_dbf_lock);
1075 spin_lock_init(&adapter->scsi_dbf_lock);
1077 /* initialize error recovery stuff */
1079 rwlock_init(&adapter->erp_lock);
1080 sema_init(&adapter->erp_ready_sem, 0);
1081 INIT_LIST_HEAD(&adapter->erp_ready_head);
1082 INIT_LIST_HEAD(&adapter->erp_running_head);
1084 /* initialize abort lock */
1085 rwlock_init(&adapter->abort_lock);
1087 /* initialise some erp stuff */
1088 init_waitqueue_head(&adapter->erp_thread_wqh);
1089 init_waitqueue_head(&adapter->erp_done_wqh);
1091 /* initialize lock of associated request queue */
1092 rwlock_init(&adapter->request_queue.queue_lock);
1094 /* intitialise SCSI ER timer */
1095 init_timer(&adapter->scsi_er_timer);
1097 /* mark adapter unusable as long as sysfs registration is not complete */
1098 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1100 adapter->ccw_device = ccw_device;
1101 dev_set_drvdata(&ccw_device->dev, adapter);
1103 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1106 adapter->generic_services.parent = &adapter->ccw_device->dev;
1107 adapter->generic_services.release = zfcp_dummy_release;
1108 snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
1109 "generic_services");
1111 if (device_register(&adapter->generic_services))
1112 goto generic_services_failed;
1114 /* put allocated adapter at list tail */
1115 write_lock_irq(&zfcp_data.config_lock);
1116 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1117 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1118 write_unlock_irq(&zfcp_data.config_lock);
1120 zfcp_data.adapters++;
1124 generic_services_failed:
1125 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
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
1149 zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1152 unsigned long flags;
1154 device_unregister(&adapter->generic_services);
1155 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1156 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1157 /* sanity check: no pending FSF requests */
1158 spin_lock_irqsave(&adapter->req_list_lock, flags);
1159 retval = zfcp_reqlist_isempty(adapter);
1160 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
1162 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1163 "%i requests outstanding\n",
1164 zfcp_get_busid_by_adapter(adapter), adapter,
1165 atomic_read(&adapter->reqs_active));
1170 /* remove specified adapter data structure from list */
1171 write_lock_irq(&zfcp_data.config_lock);
1172 list_del(&adapter->list);
1173 write_unlock_irq(&zfcp_data.config_lock);
1175 /* decrease number of adapters in list */
1176 zfcp_data.adapters--;
1178 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1179 "%i adapters still in list\n",
1180 zfcp_get_busid_by_adapter(adapter),
1181 adapter, zfcp_data.adapters);
1183 retval = qdio_free(adapter->ccw_device);
1185 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1186 zfcp_get_busid_by_adapter(adapter));
1188 zfcp_free_low_mem_buffers(adapter);
1189 /* free memory of adapter data structure and queues */
1190 zfcp_qdio_free_queues(adapter);
1191 zfcp_reqlist_free(adapter);
1192 kfree(adapter->fc_stats);
1193 kfree(adapter->stats_reset_data);
1194 ZFCP_LOG_TRACE("freeing adapter structure\n");
1201 * zfcp_port_enqueue - enqueue port to port list of adapter
1202 * @adapter: adapter where remote port is added
1203 * @wwpn: WWPN of the remote port to be enqueued
1204 * @status: initial status for the port
1205 * @d_id: destination id of the remote port to be enqueued
1206 * Return: pointer to enqueued port on success, NULL on error
1207 * Locks: config_sema must be held to serialize changes to the port list
1209 * All port internal structures are set up and the sysfs entry is generated.
1210 * d_id is used to enqueue ports with a well known address like the Directory
1211 * Service for nameserver lookup.
1214 zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
1217 struct zfcp_port *port;
1220 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1222 * check that there is no port with this WWPN already in list
1225 read_lock_irq(&zfcp_data.config_lock);
1226 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1227 read_unlock_irq(&zfcp_data.config_lock);
1232 port = kzalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1236 /* initialise reference count stuff */
1237 atomic_set(&port->refcount, 0);
1238 init_waitqueue_head(&port->remove_wq);
1240 INIT_LIST_HEAD(&port->unit_list_head);
1241 INIT_LIST_HEAD(&port->unit_remove_lh);
1243 port->adapter = adapter;
1248 atomic_set_mask(status, &port->status);
1250 /* setup for sysfs registration */
1251 if (status & ZFCP_STATUS_PORT_WKA) {
1253 case ZFCP_DID_DIRECTORY_SERVICE:
1254 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1257 case ZFCP_DID_MANAGEMENT_SERVICE:
1258 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1261 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
1262 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1263 "key_distribution");
1265 case ZFCP_DID_ALIAS_SERVICE:
1266 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1269 case ZFCP_DID_TIME_SERVICE:
1270 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1278 port->sysfs_device.parent = &adapter->generic_services;
1280 snprintf(port->sysfs_device.bus_id,
1281 BUS_ID_SIZE, "0x%016llx", wwpn);
1282 port->sysfs_device.parent = &adapter->ccw_device->dev;
1284 port->sysfs_device.release = zfcp_sysfs_port_release;
1285 dev_set_drvdata(&port->sysfs_device, port);
1287 /* mark port unusable as long as sysfs registration is not complete */
1288 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1290 if (device_register(&port->sysfs_device)) {
1295 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1296 device_unregister(&port->sysfs_device);
1300 zfcp_port_get(port);
1302 write_lock_irq(&zfcp_data.config_lock);
1303 list_add_tail(&port->list, &adapter->port_list_head);
1304 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1305 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1306 if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
1307 if (!adapter->nameserver_port)
1308 adapter->nameserver_port = port;
1310 write_unlock_irq(&zfcp_data.config_lock);
1312 zfcp_adapter_get(adapter);
1318 zfcp_port_dequeue(struct zfcp_port *port)
1320 zfcp_port_wait(port);
1321 write_lock_irq(&zfcp_data.config_lock);
1322 list_del(&port->list);
1323 port->adapter->ports--;
1324 write_unlock_irq(&zfcp_data.config_lock);
1326 fc_remote_port_delete(port->rport);
1328 zfcp_adapter_put(port->adapter);
1329 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1330 atomic_read(&port->status));
1331 device_unregister(&port->sysfs_device);
1334 /* Enqueues a nameserver port */
1336 zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1338 struct zfcp_port *port;
1340 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
1341 ZFCP_DID_DIRECTORY_SERVICE);
1343 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1344 "adapter %s failed\n",
1345 zfcp_get_busid_by_adapter(adapter));
1348 zfcp_port_put(port);
1353 #undef ZFCP_LOG_AREA
1355 /****************************************************************/
1356 /******* Fibre Channel Standard related Functions **************/
1357 /****************************************************************/
1359 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1362 zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1363 struct fsf_status_read_buffer *status_buffer)
1365 struct fcp_rscn_head *fcp_rscn_head;
1366 struct fcp_rscn_element *fcp_rscn_element;
1367 struct zfcp_port *port;
1371 unsigned long flags;
1373 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1374 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1377 no_entries = (fcp_rscn_head->payload_len / 4);
1379 for (i = 1; i < no_entries; i++) {
1380 /* skip head and start with 1st element */
1382 switch (fcp_rscn_element->addr_format) {
1383 case ZFCP_PORT_ADDRESS:
1384 range_mask = ZFCP_PORTS_RANGE_PORT;
1386 case ZFCP_AREA_ADDRESS:
1387 range_mask = ZFCP_PORTS_RANGE_AREA;
1389 case ZFCP_DOMAIN_ADDRESS:
1390 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1392 case ZFCP_FABRIC_ADDRESS:
1393 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1396 ZFCP_LOG_INFO("incoming RSCN with unknown "
1397 "address format\n");
1400 read_lock_irqsave(&zfcp_data.config_lock, flags);
1401 list_for_each_entry(port, &adapter->port_list_head, list) {
1402 if (atomic_test_mask
1403 (ZFCP_STATUS_PORT_WKA, &port->status))
1405 /* Do we know this port? If not skip it. */
1406 if (!atomic_test_mask
1407 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1408 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1409 "port 0x%016Lx\n", port->wwpn);
1410 zfcp_erp_port_reopen(port,
1411 ZFCP_STATUS_COMMON_ERP_FAILED);
1416 * FIXME: race: d_id might being invalidated
1417 * (...DID_DID reset)
1419 if ((port->d_id & range_mask)
1420 == (fcp_rscn_element->nport_did & range_mask)) {
1421 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1422 fcp_rscn_element->nport_did);
1424 * Unfortunately, an RSCN does not specify the
1425 * type of change a target underwent. We assume
1426 * that it makes sense to reopen the link.
1427 * FIXME: Shall we try to find out more about
1428 * the target and link state before closing it?
1429 * How to accomplish this? (nameserver?)
1430 * Where would such code be put in?
1431 * (inside or outside erp)
1433 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1434 "port 0x%016Lx\n", port->wwpn);
1435 zfcp_test_link(port);
1438 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1443 zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1444 struct fsf_status_read_buffer *status_buffer)
1446 struct fsf_plogi *els_plogi;
1447 struct zfcp_port *port;
1448 unsigned long flags;
1450 els_plogi = (struct fsf_plogi *) status_buffer->payload;
1451 read_lock_irqsave(&zfcp_data.config_lock, flags);
1452 list_for_each_entry(port, &adapter->port_list_head, list) {
1453 if (port->wwpn == (*(wwn_t *) &els_plogi->serv_param.wwpn))
1456 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1458 if (!port || (port->wwpn != (*(wwn_t *) &els_plogi->serv_param.wwpn))) {
1459 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1460 "with d_id 0x%08x on adapter %s\n",
1461 status_buffer->d_id,
1462 zfcp_get_busid_by_adapter(adapter));
1464 zfcp_erp_port_forced_reopen(port, 0);
1469 zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1470 struct fsf_status_read_buffer *status_buffer)
1472 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1473 struct zfcp_port *port;
1474 unsigned long flags;
1476 read_lock_irqsave(&zfcp_data.config_lock, flags);
1477 list_for_each_entry(port, &adapter->port_list_head, list) {
1478 if (port->wwpn == els_logo->nport_wwpn)
1481 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1483 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1484 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1485 "with d_id 0x%08x on adapter %s\n",
1486 status_buffer->d_id,
1487 zfcp_get_busid_by_adapter(adapter));
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_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1498 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1499 zfcp_get_busid_by_adapter(adapter));
1504 zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1506 struct fsf_status_read_buffer *status_buffer;
1508 struct zfcp_adapter *adapter;
1510 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
1511 els_type = *(u32 *) (status_buffer->payload);
1512 adapter = fsf_req->adapter;
1514 zfcp_san_dbf_event_incoming_els(fsf_req);
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);
1528 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1529 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1530 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1533 zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1535 struct zfcp_gid_pn_data *data;
1538 data = mempool_alloc(pool, GFP_ATOMIC);
1539 if (likely(data != NULL)) {
1540 data->ct.pool = pool;
1543 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1549 memset(data, 0, sizeof(*data));
1550 data->ct.req = &data->req;
1551 data->ct.resp = &data->resp;
1552 data->ct.req_count = data->ct.resp_count = 1;
1553 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1554 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1555 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1556 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1563 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1564 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1567 zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1569 if ((gid_pn->ct.pool != 0))
1570 mempool_free(gid_pn, gid_pn->ct.pool);
1578 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1579 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1582 zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1585 struct ct_iu_gid_pn_req *ct_iu_req;
1586 struct zfcp_gid_pn_data *gid_pn;
1587 struct zfcp_adapter *adapter = erp_action->adapter;
1589 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1591 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1592 "request failed for adapter %s\n",
1593 zfcp_get_busid_by_adapter(adapter));
1597 /* setup nameserver request */
1598 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1599 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1600 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1601 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1602 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1603 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1604 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1605 ct_iu_req->wwpn = erp_action->port->wwpn;
1607 /* setup parameters for send generic command */
1608 gid_pn->ct.port = adapter->nameserver_port;
1609 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1610 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1611 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1612 gid_pn->ct.timer = &erp_action->timer;
1613 gid_pn->port = erp_action->port;
1615 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1618 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1619 "failed for adapter %s\n",
1620 zfcp_get_busid_by_adapter(adapter));
1622 zfcp_gid_pn_buffers_free(gid_pn);
1630 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1631 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1633 static void zfcp_ns_gid_pn_handler(unsigned long data)
1635 struct zfcp_port *port;
1636 struct zfcp_send_ct *ct;
1637 struct ct_iu_gid_pn_req *ct_iu_req;
1638 struct ct_iu_gid_pn_resp *ct_iu_resp;
1639 struct zfcp_gid_pn_data *gid_pn;
1642 gid_pn = (struct zfcp_gid_pn_data *) data;
1643 port = gid_pn->port;
1645 ct_iu_req = zfcp_sg_to_address(ct->req);
1646 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1648 if (ct->status != 0)
1651 if (zfcp_check_ct_response(&ct_iu_resp->header)) {
1652 /* FIXME: do we need some specific erp entry points */
1653 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1657 if (ct_iu_req->wwpn != port->wwpn) {
1658 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1659 "lookup does not match expected wwpn 0x%016Lx "
1660 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1661 zfcp_get_busid_by_port(port));
1665 /* looks like a valid d_id */
1666 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1667 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1668 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1669 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1673 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1674 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1675 sizeof(struct ct_iu_gid_pn_req));
1676 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1677 sizeof(struct ct_iu_gid_pn_resp));
1680 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1681 "0x%016Lx for adapter %s\n",
1682 port->wwpn, zfcp_get_busid_by_port(port));
1684 zfcp_gid_pn_buffers_free(gid_pn);
1688 /* reject CT_IU reason codes acc. to FC-GS-4 */
1689 static const struct zfcp_rc_entry zfcp_ct_rc[] = {
1690 {0x01, "invalid command code"},
1691 {0x02, "invalid version level"},
1692 {0x03, "logical error"},
1693 {0x04, "invalid CT_IU size"},
1694 {0x05, "logical busy"},
1695 {0x07, "protocol error"},
1696 {0x09, "unable to perform command request"},
1697 {0x0b, "command not supported"},
1698 {0x0d, "server not available"},
1699 {0x0e, "session could not be established"},
1700 {0xff, "vendor specific error"},
1704 /* LS_RJT reason codes acc. to FC-FS */
1705 static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = {
1706 {0x01, "invalid LS_Command code"},
1707 {0x03, "logical error"},
1708 {0x05, "logical busy"},
1709 {0x07, "protocol error"},
1710 {0x09, "unable to perform command request"},
1711 {0x0b, "command not supported"},
1712 {0x0e, "command already in progress"},
1713 {0xff, "vendor specific error"},
1717 /* reject reason codes according to FC-PH/FC-FS */
1718 static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = {
1719 {0x01, "invalid D_ID"},
1720 {0x02, "invalid S_ID"},
1721 {0x03, "Nx_Port not available, temporary"},
1722 {0x04, "Nx_Port not available, permament"},
1723 {0x05, "class not supported"},
1724 {0x06, "delimiter usage error"},
1725 {0x07, "TYPE not supported"},
1726 {0x08, "invalid Link_Control"},
1727 {0x09, "invalid R_CTL field"},
1728 {0x0a, "invalid F_CTL field"},
1729 {0x0b, "invalid OX_ID"},
1730 {0x0c, "invalid RX_ID"},
1731 {0x0d, "invalid SEQ_ID"},
1732 {0x0e, "invalid DF_CTL"},
1733 {0x0f, "invalid SEQ_CNT"},
1734 {0x10, "invalid parameter field"},
1735 {0x11, "exchange error"},
1736 {0x12, "protocol error"},
1737 {0x13, "incorrect length"},
1738 {0x14, "unsupported ACK"},
1739 {0x15, "class of service not supported by entity at FFFFFE"},
1740 {0x16, "login required"},
1741 {0x17, "excessive sequences attempted"},
1742 {0x18, "unable to establish exchange"},
1743 {0x1a, "fabric path not available"},
1744 {0x1b, "invalid VC_ID (class 4)"},
1745 {0x1c, "invalid CS_CTL field"},
1746 {0x1d, "insufficient resources for VC (class 4)"},
1747 {0x1f, "invalid class of service"},
1748 {0x20, "preemption request rejected"},
1749 {0x21, "preemption not enabled"},
1750 {0x22, "multicast error"},
1751 {0x23, "multicast error terminate"},
1752 {0x24, "process login required"},
1753 {0xff, "vendor specific reject"},
1758 * zfcp_rc_description - return description for given reaon code
1759 * @code: reason code
1760 * @rc_table: table of reason codes and descriptions
1762 static inline const char *
1763 zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table)
1765 const char *descr = "unknown reason code";
1768 if (code == rc_table->code) {
1769 descr = rc_table->description;
1773 } while (rc_table->code && rc_table->description);
1779 * zfcp_check_ct_response - evaluate reason code for CT_IU
1780 * @rjt: response payload to an CT_IU request
1781 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1784 zfcp_check_ct_response(struct ct_hdr *rjt)
1786 if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT)
1789 if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) {
1790 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1791 "response code (0x%04hx)\n",
1796 ZFCP_LOG_INFO("Generic Service command rejected\n");
1797 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1798 zfcp_rc_description(rjt->reason_code, zfcp_ct_rc),
1799 (u32) rjt->reason_code, (u32) rjt->reason_code_expl,
1800 (u32) rjt->vendor_unique);
1806 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1807 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1808 * @rc_table: table of reason codes and descriptions
1811 zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par,
1812 const struct zfcp_rc_entry *rc_table)
1814 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1815 zfcp_rc_description(rjt_par->reason_code, rc_table),
1816 (u32) rjt_par->action, (u32) rjt_par->reason_code,
1817 (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique);
1821 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1822 * @sq: status qualifier word
1823 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1824 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1827 zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par)
1831 if (sq == FSF_IOSTAT_NPORT_RJT) {
1832 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1833 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1835 if (rjt_par->reason_code == 0x01)
1837 } else if (sq == FSF_IOSTAT_FABRIC_RJT) {
1838 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1839 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1841 if (rjt_par->reason_code == 0x01)
1843 } else if (sq == FSF_IOSTAT_LS_RJT) {
1844 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1845 zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc);
1848 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq);
1854 * zfcp_plogi_evaluate - evaluate PLOGI playload and copy important fields
1855 * into zfcp_port structure
1856 * @port: zfcp_port structure
1857 * @plogi: plogi payload
1860 zfcp_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi)
1862 port->maxframe_size = plogi->serv_param.common_serv_param[7] |
1863 ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8);
1864 if (plogi->serv_param.class1_serv_param[0] & 0x80)
1865 port->supported_classes |= FC_COS_CLASS1;
1866 if (plogi->serv_param.class2_serv_param[0] & 0x80)
1867 port->supported_classes |= FC_COS_CLASS2;
1868 if (plogi->serv_param.class3_serv_param[0] & 0x80)
1869 port->supported_classes |= FC_COS_CLASS3;
1870 if (plogi->serv_param.class4_serv_param[0] & 0x80)
1871 port->supported_classes |= FC_COS_CLASS4;
1874 #undef ZFCP_LOG_AREA