Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[deliverable/linux.git] / drivers / s390 / scsi / zfcp_aux.c
CommitLineData
1da177e4 1/*
4a9d2d8b
AH
2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
1da177e4 4 *
4a9d2d8b 5 * (C) Copyright IBM Corp. 2002, 2006
1da177e4
LT
6 *
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)
10 * any later version.
11 *
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.
16 *
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.
20 */
21
4a9d2d8b
AH
22/*
23 * Driver authors:
24 * Martin Peschke (originator of the driver)
25 * Raimund Schroeder
26 * Aron Zeh
27 * Wolfgang Taphorn
28 * Stefan Bader
29 * Heiko Carstens (kernel 2.6 port of the driver)
30 * Andreas Herrmann
31 * Maxim Shchetynin
32 * Volker Sameske
33 * Ralph Wuerthner
34 */
35
1da177e4
LT
36#include "zfcp_ext.h"
37
38/* accumulated log level (module parameter) */
39static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS;
40static char *device;
41/*********************** FUNCTION PROTOTYPES *********************************/
42
43/* written against the module interface */
44static int __init zfcp_module_init(void);
45
46/* FCP related */
47static void zfcp_ns_gid_pn_handler(unsigned long);
48
49/* miscellaneous */
4d284cac
HC
50static int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
51static void zfcp_sg_list_free(struct zfcp_sg_list *);
52static int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *,
53 void __user *, size_t);
54static int zfcp_sg_list_copy_to_user(void __user *,
55 struct zfcp_sg_list *, size_t);
bd6ae2f6 56static long zfcp_cfdc_dev_ioctl(struct file *, unsigned int, unsigned long);
1da177e4
LT
57
58#define ZFCP_CFDC_IOC_MAGIC 0xDD
59#define ZFCP_CFDC_IOC \
60 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
61
1da177e4 62
d54b1fdb 63static const struct file_operations zfcp_cfdc_fops = {
e183b06b 64 .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
65#ifdef CONFIG_COMPAT
66 .compat_ioctl = zfcp_cfdc_dev_ioctl
67#endif
1da177e4
LT
68};
69
70static struct miscdevice zfcp_cfdc_misc = {
71 .minor = ZFCP_CFDC_DEV_MINOR,
72 .name = ZFCP_CFDC_DEV_NAME,
73 .fops = &zfcp_cfdc_fops
74};
75
76/*********************** KERNEL/MODULE PARAMETERS ***************************/
77
78/* declare driver module init/cleanup functions */
79module_init(zfcp_module_init);
80
4a9d2d8b 81MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
1da177e4 82MODULE_DESCRIPTION
4a9d2d8b 83 ("FCP (SCSI over Fibre Channel) HBA driver for IBM System z9 and zSeries");
1da177e4
LT
84MODULE_LICENSE("GPL");
85
6f71d9bc 86module_param(device, charp, 0400);
1da177e4
LT
87MODULE_PARM_DESC(device, "specify initial device");
88
6f71d9bc 89module_param(loglevel, uint, 0400);
1da177e4
LT
90MODULE_PARM_DESC(loglevel,
91 "log levels, 8 nibbles: "
92 "FC ERP QDIO CIO Config FSF SCSI Other, "
93 "levels: 0=none 1=normal 2=devel 3=trace");
94
1da177e4
LT
95/****************************************************************/
96/************** Functions without logging ***********************/
97/****************************************************************/
98
99void
100_zfcp_hex_dump(char *addr, int count)
101{
102 int i;
103 for (i = 0; i < count; i++) {
104 printk("%02x", addr[i]);
105 if ((i % 4) == 3)
106 printk(" ");
107 if ((i % 32) == 31)
108 printk("\n");
109 }
110 if (((i-1) % 32) != 31)
111 printk("\n");
112}
113
fea9d6c7
VS
114
115/****************************************************************/
116/****** Functions to handle the request ID hash table ********/
117/****************************************************************/
118
119#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
120
ca2d02c2 121static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter)
fea9d6c7 122{
ca2d02c2 123 int idx;
fea9d6c7
VS
124
125 adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head),
126 GFP_KERNEL);
fea9d6c7
VS
127 if (!adapter->req_list)
128 return -ENOMEM;
129
ca2d02c2
HC
130 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
131 INIT_LIST_HEAD(&adapter->req_list[idx]);
fea9d6c7
VS
132 return 0;
133}
134
135static void zfcp_reqlist_free(struct zfcp_adapter *adapter)
136{
fea9d6c7
VS
137 kfree(adapter->req_list);
138}
139
fea9d6c7
VS
140int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
141{
ca2d02c2 142 unsigned int idx;
fea9d6c7 143
ca2d02c2
HC
144 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
145 if (!list_empty(&adapter->req_list[idx]))
fea9d6c7 146 return 0;
fea9d6c7
VS
147 return 1;
148}
149
150#undef ZFCP_LOG_AREA
151
1da177e4
LT
152/****************************************************************/
153/************** Uncategorised Functions *************************/
154/****************************************************************/
155
156#define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
157
1da177e4
LT
158/**
159 * zfcp_device_setup - setup function
160 * @str: pointer to parameter string
161 *
162 * Parse "device=..." parameter string.
163 */
164static int __init
cd8a383e 165zfcp_device_setup(char *devstr)
1da177e4 166{
cd8a383e
AH
167 char *tmp, *str;
168 size_t len;
1da177e4 169
cd8a383e 170 if (!devstr)
1da177e4
LT
171 return 0;
172
cd8a383e 173 len = strlen(devstr) + 1;
5cbded58 174 str = kmalloc(len, GFP_KERNEL);
cd8a383e
AH
175 if (!str)
176 goto err_out;
177 memcpy(str, devstr, len);
178
1da177e4
LT
179 tmp = strchr(str, ',');
180 if (!tmp)
181 goto err_out;
182 *tmp++ = '\0';
183 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
184 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
185
186 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
187 if (*tmp++ != ',')
188 goto err_out;
189 if (*tmp == '\0')
190 goto err_out;
191
192 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
193 if (*tmp != '\0')
194 goto err_out;
cd8a383e 195 kfree(str);
1da177e4
LT
196 return 1;
197
198 err_out:
199 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
cd8a383e 200 kfree(str);
1da177e4
LT
201 return 0;
202}
203
204static void __init
205zfcp_init_device_configure(void)
206{
207 struct zfcp_adapter *adapter;
208 struct zfcp_port *port;
209 struct zfcp_unit *unit;
210
211 down(&zfcp_data.config_sema);
212 read_lock_irq(&zfcp_data.config_lock);
213 adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
214 if (adapter)
215 zfcp_adapter_get(adapter);
216 read_unlock_irq(&zfcp_data.config_lock);
217
218 if (adapter == NULL)
219 goto out_adapter;
220 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
221 if (!port)
222 goto out_port;
223 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
224 if (!unit)
225 goto out_unit;
226 up(&zfcp_data.config_sema);
227 ccw_device_set_online(adapter->ccw_device);
228 zfcp_erp_wait(adapter);
229 down(&zfcp_data.config_sema);
230 zfcp_unit_put(unit);
231 out_unit:
232 zfcp_port_put(port);
233 out_port:
234 zfcp_adapter_put(adapter);
235 out_adapter:
236 up(&zfcp_data.config_sema);
237 return;
238}
239
dd52e0ea
HC
240static int calc_alignment(int size)
241{
242 int align = 1;
243
244 if (!size)
245 return 0;
246
247 while ((size - align) > 0)
248 align <<= 1;
249
250 return align;
251}
252
1da177e4
LT
253static int __init
254zfcp_module_init(void)
255{
dd52e0ea
HC
256 int retval = -ENOMEM;
257 int size, align;
258
259 size = sizeof(struct zfcp_fsf_req_qtcb);
260 align = calc_alignment(size);
261 zfcp_data.fsf_req_qtcb_cache =
262 kmem_cache_create("zfcp_fsf", size, align, 0, NULL, NULL);
263 if (!zfcp_data.fsf_req_qtcb_cache)
264 goto out;
1da177e4 265
dd52e0ea
HC
266 size = sizeof(struct fsf_status_read_buffer);
267 align = calc_alignment(size);
268 zfcp_data.sr_buffer_cache =
269 kmem_cache_create("zfcp_sr", size, align, 0, NULL, NULL);
270 if (!zfcp_data.sr_buffer_cache)
271 goto out_sr_cache;
272
273 size = sizeof(struct zfcp_gid_pn_data);
274 align = calc_alignment(size);
275 zfcp_data.gid_pn_cache =
276 kmem_cache_create("zfcp_gid", size, align, 0, NULL, NULL);
277 if (!zfcp_data.gid_pn_cache)
278 goto out_gid_cache;
1da177e4
LT
279
280 atomic_set(&zfcp_data.loglevel, loglevel);
281
282 /* initialize adapter list */
283 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
284
285 /* initialize adapters to be removed list head */
286 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
287
dd52e0ea
HC
288 zfcp_data.scsi_transport_template =
289 fc_attach_transport(&zfcp_transport_functions);
290 if (!zfcp_data.scsi_transport_template)
291 goto out_transport;
1da177e4 292
1da177e4
LT
293 retval = misc_register(&zfcp_cfdc_misc);
294 if (retval != 0) {
295 ZFCP_LOG_INFO("registration of misc device "
296 "zfcp_cfdc failed\n");
dd52e0ea 297 goto out_misc;
1da177e4
LT
298 }
299
e183b06b 300 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
301 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
302
1da177e4
LT
303 /* Initialise proc semaphores */
304 sema_init(&zfcp_data.config_sema, 1);
305
306 /* initialise configuration rw lock */
307 rwlock_init(&zfcp_data.config_lock);
308
1da177e4
LT
309 /* setup dynamic I/O */
310 retval = zfcp_ccw_register();
311 if (retval) {
312 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
313 goto out_ccw_register;
314 }
315
316 if (zfcp_device_setup(device))
317 zfcp_init_device_configure();
318
319 goto out;
320
321 out_ccw_register:
322 misc_deregister(&zfcp_cfdc_misc);
dd52e0ea
HC
323 out_misc:
324 fc_release_transport(zfcp_data.scsi_transport_template);
325 out_transport:
326 kmem_cache_destroy(zfcp_data.gid_pn_cache);
327 out_gid_cache:
328 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
329 out_sr_cache:
330 kmem_cache_destroy(zfcp_data.fsf_req_qtcb_cache);
1da177e4
LT
331 out:
332 return retval;
333}
334
335/*
336 * function: zfcp_cfdc_dev_ioctl
337 *
338 * purpose: Handle control file upload/download transaction via IOCTL
339 * interface
340 *
341 * returns: 0 - Operation completed successfuly
342 * -ENOTTY - Unknown IOCTL command
343 * -EINVAL - Invalid sense data record
344 * -ENXIO - The FCP adapter is not available
345 * -EOPNOTSUPP - The FCP adapter does not have CFDC support
346 * -ENOMEM - Insufficient memory
347 * -EFAULT - User space memory I/O operation fault
348 * -EPERM - Cannot create or queue FSF request or create SBALs
349 * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
350 */
e183b06b 351static long
352zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
353 unsigned long buffer)
1da177e4
LT
354{
355 struct zfcp_cfdc_sense_data *sense_data, __user *sense_data_user;
356 struct zfcp_adapter *adapter = NULL;
357 struct zfcp_fsf_req *fsf_req = NULL;
358 struct zfcp_sg_list *sg_list = NULL;
359 u32 fsf_command, option;
360 char *bus_id = NULL;
361 int retval = 0;
362
363 sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL);
364 if (sense_data == NULL) {
365 retval = -ENOMEM;
366 goto out;
367 }
368
ec4081c6 369 sg_list = kzalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
1da177e4
LT
370 if (sg_list == NULL) {
371 retval = -ENOMEM;
372 goto out;
373 }
1da177e4
LT
374
375 if (command != ZFCP_CFDC_IOC) {
376 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
377 retval = -ENOTTY;
378 goto out;
379 }
380
381 if ((sense_data_user = (void __user *) buffer) == NULL) {
382 ZFCP_LOG_INFO("sense data record is required\n");
383 retval = -EINVAL;
384 goto out;
385 }
386
387 retval = copy_from_user(sense_data, sense_data_user,
388 sizeof(struct zfcp_cfdc_sense_data));
389 if (retval) {
390 retval = -EFAULT;
391 goto out;
392 }
393
394 if (sense_data->signature != ZFCP_CFDC_SIGNATURE) {
395 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
396 ZFCP_CFDC_SIGNATURE);
397 retval = -EINVAL;
398 goto out;
399 }
400
401 switch (sense_data->command) {
402
403 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
404 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
405 option = FSF_CFDC_OPTION_NORMAL_MODE;
406 break;
407
408 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
409 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
410 option = FSF_CFDC_OPTION_FORCE;
411 break;
412
413 case ZFCP_CFDC_CMND_FULL_ACCESS:
414 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
415 option = FSF_CFDC_OPTION_FULL_ACCESS;
416 break;
417
418 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
419 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
420 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
421 break;
422
423 case ZFCP_CFDC_CMND_UPLOAD:
424 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
425 option = 0;
426 break;
427
428 default:
429 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
430 sense_data->command);
431 retval = -EINVAL;
432 goto out;
433 }
434
435 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
436 if (bus_id == NULL) {
437 retval = -ENOMEM;
438 goto out;
439 }
440 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
441 (sense_data->devno >> 24),
442 (sense_data->devno >> 16) & 0xFF,
443 (sense_data->devno & 0xFFFF));
444
445 read_lock_irq(&zfcp_data.config_lock);
446 adapter = zfcp_get_adapter_by_busid(bus_id);
447 if (adapter)
448 zfcp_adapter_get(adapter);
449 read_unlock_irq(&zfcp_data.config_lock);
450
451 kfree(bus_id);
452
453 if (adapter == NULL) {
454 ZFCP_LOG_INFO("invalid adapter\n");
455 retval = -ENXIO;
456 goto out;
457 }
458
459 if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) {
460 retval = zfcp_sg_list_alloc(sg_list,
461 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
462 if (retval) {
463 retval = -ENOMEM;
464 goto out;
465 }
466 }
467
468 if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) &&
469 (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
470 retval = zfcp_sg_list_copy_from_user(
471 sg_list, &sense_data_user->control_file,
472 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
473 if (retval) {
474 retval = -EFAULT;
475 goto out;
476 }
477 }
478
479 retval = zfcp_fsf_control_file(adapter, &fsf_req, fsf_command,
480 option, sg_list);
481 if (retval)
482 goto out;
483
484 if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
485 (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
486 retval = -ENXIO;
487 goto out;
488 }
489
490 sense_data->fsf_status = fsf_req->qtcb->header.fsf_status;
491 memcpy(&sense_data->fsf_status_qual,
492 &fsf_req->qtcb->header.fsf_status_qual,
493 sizeof(union fsf_status_qual));
494 memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256);
495
496 retval = copy_to_user(sense_data_user, sense_data,
497 sizeof(struct zfcp_cfdc_sense_data));
498 if (retval) {
499 retval = -EFAULT;
500 goto out;
501 }
502
503 if (sense_data->command & ZFCP_CFDC_UPLOAD) {
504 retval = zfcp_sg_list_copy_to_user(
505 &sense_data_user->control_file, sg_list,
506 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
507 if (retval) {
508 retval = -EFAULT;
509 goto out;
510 }
511 }
512
513 out:
514 if (fsf_req != NULL)
1db2c9c0 515 zfcp_fsf_req_free(fsf_req);
1da177e4
LT
516
517 if ((adapter != NULL) && (retval != -ENXIO))
518 zfcp_adapter_put(adapter);
519
520 if (sg_list != NULL) {
521 zfcp_sg_list_free(sg_list);
522 kfree(sg_list);
523 }
524
17fd682e 525 kfree(sense_data);
1da177e4
LT
526
527 return retval;
528}
529
530
531/**
532 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
533 * @sg_list: structure describing a scatter gather list
534 * @size: size of scatter-gather list
535 * Return: 0 on success, else -ENOMEM
536 *
537 * In sg_list->sg a pointer to the created scatter-gather list is returned,
538 * or NULL if we run out of memory. sg_list->count specifies the number of
539 * elements of the scatter-gather list. The maximum size of a single element
540 * in the scatter-gather list is PAGE_SIZE.
541 */
4d284cac 542static int
1da177e4
LT
543zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
544{
545 struct scatterlist *sg;
546 unsigned int i;
547 int retval = 0;
548 void *address;
549
550 BUG_ON(sg_list == NULL);
551
552 sg_list->count = size >> PAGE_SHIFT;
553 if (size & ~PAGE_MASK)
554 sg_list->count++;
ec4081c6 555 sg_list->sg = kcalloc(sg_list->count, sizeof(struct scatterlist),
1da177e4
LT
556 GFP_KERNEL);
557 if (sg_list->sg == NULL) {
558 sg_list->count = 0;
559 retval = -ENOMEM;
560 goto out;
561 }
1da177e4
LT
562
563 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
564 sg->length = min(size, PAGE_SIZE);
565 sg->offset = 0;
566 address = (void *) get_zeroed_page(GFP_KERNEL);
567 if (address == NULL) {
568 sg_list->count = i;
569 zfcp_sg_list_free(sg_list);
570 retval = -ENOMEM;
571 goto out;
572 }
573 zfcp_address_to_sg(address, sg);
574 size -= sg->length;
575 }
576
577 out:
578 return retval;
579}
580
581
582/**
583 * zfcp_sg_list_free - free memory of a scatter-gather list
584 * @sg_list: structure describing a scatter-gather list
585 *
586 * Memory for each element in the scatter-gather list is freed.
587 * Finally sg_list->sg is freed itself and sg_list->count is reset.
588 */
4d284cac 589static void
1da177e4
LT
590zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
591{
592 struct scatterlist *sg;
593 unsigned int i;
594
595 BUG_ON(sg_list == NULL);
596
597 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
598 free_page((unsigned long) zfcp_sg_to_address(sg));
599
600 sg_list->count = 0;
601 kfree(sg_list->sg);
602}
603
604/**
605 * zfcp_sg_size - determine size of a scatter-gather list
606 * @sg: array of (struct scatterlist)
607 * @sg_count: elements in array
608 * Return: size of entire scatter-gather list
609 */
610size_t
611zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
612{
613 unsigned int i;
614 struct scatterlist *p;
615 size_t size;
616
617 size = 0;
618 for (i = 0, p = sg; i < sg_count; i++, p++) {
619 BUG_ON(p == NULL);
620 size += p->length;
621 }
622
623 return size;
624}
625
626
627/**
628 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
629 * @sg_list: structure describing a scatter-gather list
630 * @user_buffer: pointer to buffer in user space
631 * @size: number of bytes to be copied
632 * Return: 0 on success, -EFAULT if copy_from_user fails.
633 */
4d284cac 634static int
1da177e4
LT
635zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list,
636 void __user *user_buffer,
637 size_t size)
638{
639 struct scatterlist *sg;
640 unsigned int length;
641 void *zfcp_buffer;
642 int retval = 0;
643
644 BUG_ON(sg_list == NULL);
645
646 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
647 return -EFAULT;
648
649 for (sg = sg_list->sg; size > 0; sg++) {
650 length = min((unsigned int)size, sg->length);
651 zfcp_buffer = zfcp_sg_to_address(sg);
652 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
653 retval = -EFAULT;
654 goto out;
655 }
656 user_buffer += length;
657 size -= length;
658 }
659
660 out:
661 return retval;
662}
663
664
665/**
666 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
667 * @user_buffer: pointer to buffer in user space
668 * @sg_list: structure describing a scatter-gather list
669 * @size: number of bytes to be copied
670 * Return: 0 on success, -EFAULT if copy_to_user fails
671 */
4d284cac 672static int
1da177e4
LT
673zfcp_sg_list_copy_to_user(void __user *user_buffer,
674 struct zfcp_sg_list *sg_list,
675 size_t size)
676{
677 struct scatterlist *sg;
678 unsigned int length;
679 void *zfcp_buffer;
680 int retval = 0;
681
682 BUG_ON(sg_list == NULL);
683
684 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
685 return -EFAULT;
686
687 for (sg = sg_list->sg; size > 0; sg++) {
688 length = min((unsigned int) size, sg->length);
689 zfcp_buffer = zfcp_sg_to_address(sg);
690 if (copy_to_user(user_buffer, zfcp_buffer, length)) {
691 retval = -EFAULT;
692 goto out;
693 }
694 user_buffer += length;
695 size -= length;
696 }
697
698 out:
699 return retval;
700}
701
702
703#undef ZFCP_LOG_AREA
704
705/****************************************************************/
706/****** Functions for configuration/set-up of structures ********/
707/****************************************************************/
708
709#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
710
711/**
712 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
713 * @port: pointer to port to search for unit
714 * @fcp_lun: FCP LUN to search for
715 * Traverse list of all units of a port and return pointer to a unit
716 * with the given FCP LUN.
717 */
718struct zfcp_unit *
719zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
720{
721 struct zfcp_unit *unit;
722 int found = 0;
723
724 list_for_each_entry(unit, &port->unit_list_head, list) {
725 if ((unit->fcp_lun == fcp_lun) &&
726 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
727 {
728 found = 1;
729 break;
730 }
731 }
732 return found ? unit : NULL;
733}
734
735/**
736 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
737 * @adapter: pointer to adapter to search for port
738 * @wwpn: wwpn to search for
739 * Traverse list of all ports of an adapter and return pointer to a port
740 * with the given wwpn.
741 */
742struct zfcp_port *
743zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
744{
745 struct zfcp_port *port;
746 int found = 0;
747
748 list_for_each_entry(port, &adapter->port_list_head, list) {
749 if ((port->wwpn == wwpn) &&
750 !(atomic_read(&port->status) &
751 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
752 found = 1;
753 break;
754 }
755 }
756 return found ? port : NULL;
757}
758
759/**
760 * zfcp_get_port_by_did - find port in port list of adapter by d_id
761 * @adapter: pointer to adapter to search for port
762 * @d_id: d_id to search for
763 * Traverse list of all ports of an adapter and return pointer to a port
764 * with the given d_id.
765 */
766struct zfcp_port *
767zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
768{
769 struct zfcp_port *port;
770 int found = 0;
771
772 list_for_each_entry(port, &adapter->port_list_head, list) {
773 if ((port->d_id == d_id) &&
774 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
775 {
776 found = 1;
777 break;
778 }
779 }
780 return found ? port : NULL;
781}
782
783/**
784 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
785 * @bus_id: bus_id to search for
786 * Traverse list of all adapters and return pointer to an adapter
787 * with the given bus_id.
788 */
789struct zfcp_adapter *
790zfcp_get_adapter_by_busid(char *bus_id)
791{
792 struct zfcp_adapter *adapter;
793 int found = 0;
794
795 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
796 if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
797 BUS_ID_SIZE) == 0) &&
798 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
799 &adapter->status)){
800 found = 1;
801 break;
802 }
803 }
804 return found ? adapter : NULL;
805}
806
807/**
808 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
809 * @port: pointer to port where unit is added
810 * @fcp_lun: FCP LUN of unit to be enqueued
811 * Return: pointer to enqueued unit on success, NULL on error
812 * Locks: config_sema must be held to serialize changes to the unit list
813 *
814 * Sets up some unit internal structures and creates sysfs entry.
815 */
816struct zfcp_unit *
817zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
818{
819 struct zfcp_unit *unit, *tmp_unit;
06506d00 820 unsigned int scsi_lun;
1da177e4
LT
821 int found;
822
823 /*
824 * check that there is no unit with this FCP_LUN already in list
825 * and enqueue it.
826 * Note: Unlike for the adapter and the port, this is an error
827 */
828 read_lock_irq(&zfcp_data.config_lock);
829 unit = zfcp_get_unit_by_lun(port, fcp_lun);
830 read_unlock_irq(&zfcp_data.config_lock);
831 if (unit)
832 return NULL;
833
ec4081c6 834 unit = kzalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
1da177e4
LT
835 if (!unit)
836 return NULL;
1da177e4
LT
837
838 /* initialise reference count stuff */
839 atomic_set(&unit->refcount, 0);
840 init_waitqueue_head(&unit->remove_wq);
841
842 unit->port = port;
843 unit->fcp_lun = fcp_lun;
844
845 /* setup for sysfs registration */
846 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
847 unit->sysfs_device.parent = &port->sysfs_device;
848 unit->sysfs_device.release = zfcp_sysfs_unit_release;
849 dev_set_drvdata(&unit->sysfs_device, unit);
850
5f852be9
CS
851 init_waitqueue_head(&unit->scsi_scan_wq);
852
1da177e4
LT
853 /* mark unit unusable as long as sysfs registration is not complete */
854 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
855
856 if (device_register(&unit->sysfs_device)) {
857 kfree(unit);
858 return NULL;
859 }
860
861 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
862 device_unregister(&unit->sysfs_device);
863 return NULL;
864 }
865
866 zfcp_unit_get(unit);
867
868 scsi_lun = 0;
869 found = 0;
870 write_lock_irq(&zfcp_data.config_lock);
871 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
872 if (tmp_unit->scsi_lun != scsi_lun) {
873 found = 1;
874 break;
875 }
876 scsi_lun++;
877 }
878 unit->scsi_lun = scsi_lun;
879 if (found)
880 list_add_tail(&unit->list, &tmp_unit->list);
881 else
882 list_add_tail(&unit->list, &port->unit_list_head);
883 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
884 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
885 write_unlock_irq(&zfcp_data.config_lock);
886
887 port->units++;
888 zfcp_port_get(port);
889
890 return unit;
891}
892
893void
894zfcp_unit_dequeue(struct zfcp_unit *unit)
895{
896 zfcp_unit_wait(unit);
897 write_lock_irq(&zfcp_data.config_lock);
898 list_del(&unit->list);
899 write_unlock_irq(&zfcp_data.config_lock);
900 unit->port->units--;
901 zfcp_port_put(unit->port);
902 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
903 device_unregister(&unit->sysfs_device);
904}
905
1da177e4
LT
906/*
907 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
908 * commands.
909 * It also genrates fcp-nameserver request/response buffer and unsolicited
910 * status read fsf_req buffers.
911 *
912 * locks: must only be called with zfcp_data.config_sema taken
913 */
914static int
915zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
916{
917 adapter->pool.fsf_req_erp =
dd52e0ea
HC
918 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ERP_NR,
919 zfcp_data.fsf_req_qtcb_cache);
0eaae62a 920 if (!adapter->pool.fsf_req_erp)
1da177e4
LT
921 return -ENOMEM;
922
923 adapter->pool.fsf_req_scsi =
dd52e0ea
HC
924 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_SCSI_NR,
925 zfcp_data.fsf_req_qtcb_cache);
0eaae62a 926 if (!adapter->pool.fsf_req_scsi)
1da177e4
LT
927 return -ENOMEM;
928
929 adapter->pool.fsf_req_abort =
dd52e0ea
HC
930 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ABORT_NR,
931 zfcp_data.fsf_req_qtcb_cache);
0eaae62a 932 if (!adapter->pool.fsf_req_abort)
1da177e4
LT
933 return -ENOMEM;
934
935 adapter->pool.fsf_req_status_read =
0eaae62a
MD
936 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
937 sizeof(struct zfcp_fsf_req));
938 if (!adapter->pool.fsf_req_status_read)
1da177e4
LT
939 return -ENOMEM;
940
941 adapter->pool.data_status_read =
dd52e0ea
HC
942 mempool_create_slab_pool(ZFCP_POOL_STATUS_READ_NR,
943 zfcp_data.sr_buffer_cache);
0eaae62a 944 if (!adapter->pool.data_status_read)
1da177e4
LT
945 return -ENOMEM;
946
947 adapter->pool.data_gid_pn =
dd52e0ea
HC
948 mempool_create_slab_pool(ZFCP_POOL_DATA_GID_PN_NR,
949 zfcp_data.gid_pn_cache);
0eaae62a 950 if (!adapter->pool.data_gid_pn)
1da177e4
LT
951 return -ENOMEM;
952
953 return 0;
954}
955
956/**
957 * zfcp_free_low_mem_buffers - free memory pools of an adapter
958 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
959 * locking: zfcp_data.config_sema must be held
960 */
961static void
962zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
963{
964 if (adapter->pool.fsf_req_erp)
965 mempool_destroy(adapter->pool.fsf_req_erp);
966 if (adapter->pool.fsf_req_scsi)
967 mempool_destroy(adapter->pool.fsf_req_scsi);
968 if (adapter->pool.fsf_req_abort)
969 mempool_destroy(adapter->pool.fsf_req_abort);
970 if (adapter->pool.fsf_req_status_read)
971 mempool_destroy(adapter->pool.fsf_req_status_read);
972 if (adapter->pool.data_status_read)
973 mempool_destroy(adapter->pool.data_status_read);
974 if (adapter->pool.data_gid_pn)
975 mempool_destroy(adapter->pool.data_gid_pn);
976}
977
1da177e4
LT
978void
979zfcp_dummy_release(struct device *dev)
980{
981 return;
982}
983
984/*
985 * Enqueues an adapter at the end of the adapter list in the driver data.
986 * All adapter internal structures are set up.
987 * Proc-fs entries are also created.
988 *
989 * returns: 0 if a new adapter was successfully enqueued
990 * ZFCP_KNOWN if an adapter with this devno was already present
991 * -ENOMEM if alloc failed
992 * locks: config_sema must be held to serialise changes to the adapter list
993 */
994struct zfcp_adapter *
995zfcp_adapter_enqueue(struct ccw_device *ccw_device)
996{
997 int retval = 0;
998 struct zfcp_adapter *adapter;
999
1000 /*
1001 * Note: It is safe to release the list_lock, as any list changes
1002 * are protected by the config_sema, which must be held to get here
1003 */
1004
1005 /* try to allocate new adapter data structure (zeroed) */
ec4081c6 1006 adapter = kzalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
1da177e4
LT
1007 if (!adapter) {
1008 ZFCP_LOG_INFO("error: allocation of base adapter "
1009 "structure failed\n");
1010 goto out;
1011 }
1da177e4
LT
1012
1013 ccw_device->handler = NULL;
1014
1015 /* save ccw_device pointer */
1016 adapter->ccw_device = ccw_device;
1017
1018 retval = zfcp_qdio_allocate_queues(adapter);
1019 if (retval)
1020 goto queues_alloc_failed;
1021
1022 retval = zfcp_qdio_allocate(adapter);
1023 if (retval)
1024 goto qdio_allocate_failed;
1025
1026 retval = zfcp_allocate_low_mem_buffers(adapter);
1027 if (retval) {
1028 ZFCP_LOG_INFO("error: pool allocation failed\n");
1029 goto failed_low_mem_buffers;
1030 }
1031
1032 /* initialise reference count stuff */
1033 atomic_set(&adapter->refcount, 0);
1034 init_waitqueue_head(&adapter->remove_wq);
1035
1036 /* initialise list of ports */
1037 INIT_LIST_HEAD(&adapter->port_list_head);
1038
1039 /* initialise list of ports to be removed */
1040 INIT_LIST_HEAD(&adapter->port_remove_lh);
1041
1042 /* initialize list of fsf requests */
fea9d6c7 1043 spin_lock_init(&adapter->req_list_lock);
ca2d02c2 1044 retval = zfcp_reqlist_alloc(adapter);
fea9d6c7
VS
1045 if (retval) {
1046 ZFCP_LOG_INFO("request list initialization failed\n");
1047 goto failed_low_mem_buffers;
1048 }
1da177e4 1049
c48a29d0
HC
1050 /* initialize debug locks */
1051
1052 spin_lock_init(&adapter->erp_dbf_lock);
1053 spin_lock_init(&adapter->hba_dbf_lock);
1054 spin_lock_init(&adapter->san_dbf_lock);
1055 spin_lock_init(&adapter->scsi_dbf_lock);
1056
1057 /* initialize error recovery stuff */
1058
1059 rwlock_init(&adapter->erp_lock);
1060 sema_init(&adapter->erp_ready_sem, 0);
1061 INIT_LIST_HEAD(&adapter->erp_ready_head);
1062 INIT_LIST_HEAD(&adapter->erp_running_head);
1063
1da177e4
LT
1064 /* initialize abort lock */
1065 rwlock_init(&adapter->abort_lock);
1066
1067 /* initialise some erp stuff */
1068 init_waitqueue_head(&adapter->erp_thread_wqh);
1069 init_waitqueue_head(&adapter->erp_done_wqh);
1070
1071 /* initialize lock of associated request queue */
1072 rwlock_init(&adapter->request_queue.queue_lock);
1073
1da177e4
LT
1074 /* mark adapter unusable as long as sysfs registration is not complete */
1075 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1076
1077 adapter->ccw_device = ccw_device;
1078 dev_set_drvdata(&ccw_device->dev, adapter);
1079
1080 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1081 goto sysfs_failed;
1082
1083 adapter->generic_services.parent = &adapter->ccw_device->dev;
1084 adapter->generic_services.release = zfcp_dummy_release;
1085 snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
1086 "generic_services");
1087
1088 if (device_register(&adapter->generic_services))
1089 goto generic_services_failed;
1090
1091 /* put allocated adapter at list tail */
1092 write_lock_irq(&zfcp_data.config_lock);
1093 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1094 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1095 write_unlock_irq(&zfcp_data.config_lock);
1096
1097 zfcp_data.adapters++;
1098
1099 goto out;
1100
1101 generic_services_failed:
1102 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1103 sysfs_failed:
1104 dev_set_drvdata(&ccw_device->dev, NULL);
ca2d02c2 1105 zfcp_reqlist_free(adapter);
1da177e4
LT
1106 failed_low_mem_buffers:
1107 zfcp_free_low_mem_buffers(adapter);
1108 if (qdio_free(ccw_device) != 0)
1109 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1110 zfcp_get_busid_by_adapter(adapter));
1111 qdio_allocate_failed:
1112 zfcp_qdio_free_queues(adapter);
1113 queues_alloc_failed:
1114 kfree(adapter);
1115 adapter = NULL;
1116 out:
1117 return adapter;
1118}
1119
1120/*
1121 * returns: 0 - struct zfcp_adapter data structure successfully removed
1122 * !0 - struct zfcp_adapter data structure could not be removed
1123 * (e.g. still used)
1124 * locks: adapter list write lock is assumed to be held by caller
1da177e4
LT
1125 */
1126void
1127zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1128{
1129 int retval = 0;
1130 unsigned long flags;
1131
1132 device_unregister(&adapter->generic_services);
1133 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1134 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1135 /* sanity check: no pending FSF requests */
fea9d6c7
VS
1136 spin_lock_irqsave(&adapter->req_list_lock, flags);
1137 retval = zfcp_reqlist_isempty(adapter);
1138 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
1139 if (!retval) {
1da177e4
LT
1140 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1141 "%i requests outstanding\n",
1142 zfcp_get_busid_by_adapter(adapter), adapter,
fea9d6c7 1143 atomic_read(&adapter->reqs_active));
1da177e4
LT
1144 retval = -EBUSY;
1145 goto out;
1146 }
1147
1148 /* remove specified adapter data structure from list */
1149 write_lock_irq(&zfcp_data.config_lock);
1150 list_del(&adapter->list);
1151 write_unlock_irq(&zfcp_data.config_lock);
1152
1153 /* decrease number of adapters in list */
1154 zfcp_data.adapters--;
1155
1156 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1157 "%i adapters still in list\n",
1158 zfcp_get_busid_by_adapter(adapter),
1159 adapter, zfcp_data.adapters);
1160
1161 retval = qdio_free(adapter->ccw_device);
1162 if (retval)
1163 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1164 zfcp_get_busid_by_adapter(adapter));
1165
1166 zfcp_free_low_mem_buffers(adapter);
1167 /* free memory of adapter data structure and queues */
1168 zfcp_qdio_free_queues(adapter);
fea9d6c7 1169 zfcp_reqlist_free(adapter);
f6cd94b1
AH
1170 kfree(adapter->fc_stats);
1171 kfree(adapter->stats_reset_data);
1da177e4
LT
1172 ZFCP_LOG_TRACE("freeing adapter structure\n");
1173 kfree(adapter);
1174 out:
1175 return;
1176}
1177
1178/**
1179 * zfcp_port_enqueue - enqueue port to port list of adapter
1180 * @adapter: adapter where remote port is added
1181 * @wwpn: WWPN of the remote port to be enqueued
1182 * @status: initial status for the port
1183 * @d_id: destination id of the remote port to be enqueued
1184 * Return: pointer to enqueued port on success, NULL on error
1185 * Locks: config_sema must be held to serialize changes to the port list
1186 *
1187 * All port internal structures are set up and the sysfs entry is generated.
1188 * d_id is used to enqueue ports with a well known address like the Directory
1189 * Service for nameserver lookup.
1190 */
1191struct zfcp_port *
1192zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
1193 u32 d_id)
1194{
3859f6a2 1195 struct zfcp_port *port;
1da177e4 1196 int check_wwpn;
1da177e4
LT
1197
1198 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1da177e4
LT
1199 /*
1200 * check that there is no port with this WWPN already in list
1201 */
1202 if (check_wwpn) {
1203 read_lock_irq(&zfcp_data.config_lock);
1204 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1205 read_unlock_irq(&zfcp_data.config_lock);
1206 if (port)
1207 return NULL;
1208 }
1209
ec4081c6 1210 port = kzalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1da177e4
LT
1211 if (!port)
1212 return NULL;
1da177e4
LT
1213
1214 /* initialise reference count stuff */
1215 atomic_set(&port->refcount, 0);
1216 init_waitqueue_head(&port->remove_wq);
1217
1218 INIT_LIST_HEAD(&port->unit_list_head);
1219 INIT_LIST_HEAD(&port->unit_remove_lh);
1220
1221 port->adapter = adapter;
1222
1223 if (check_wwpn)
1224 port->wwpn = wwpn;
1225
1226 atomic_set_mask(status, &port->status);
1227
1228 /* setup for sysfs registration */
1229 if (status & ZFCP_STATUS_PORT_WKA) {
1230 switch (d_id) {
1231 case ZFCP_DID_DIRECTORY_SERVICE:
1232 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1233 "directory");
1234 break;
1235 case ZFCP_DID_MANAGEMENT_SERVICE:
1236 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1237 "management");
1238 break;
1239 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
1240 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1241 "key_distribution");
1242 break;
1243 case ZFCP_DID_ALIAS_SERVICE:
1244 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1245 "alias");
1246 break;
1247 case ZFCP_DID_TIME_SERVICE:
1248 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1249 "time");
1250 break;
1251 default:
1252 kfree(port);
1253 return NULL;
1254 }
1255 port->d_id = d_id;
1256 port->sysfs_device.parent = &adapter->generic_services;
1257 } else {
1258 snprintf(port->sysfs_device.bus_id,
1259 BUS_ID_SIZE, "0x%016llx", wwpn);
3859f6a2 1260 port->sysfs_device.parent = &adapter->ccw_device->dev;
1da177e4
LT
1261 }
1262 port->sysfs_device.release = zfcp_sysfs_port_release;
1263 dev_set_drvdata(&port->sysfs_device, port);
1264
1265 /* mark port unusable as long as sysfs registration is not complete */
1266 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1267
1268 if (device_register(&port->sysfs_device)) {
1269 kfree(port);
1270 return NULL;
1271 }
1272
1273 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1274 device_unregister(&port->sysfs_device);
1275 return NULL;
1276 }
1277
1278 zfcp_port_get(port);
1279
1da177e4 1280 write_lock_irq(&zfcp_data.config_lock);
3859f6a2 1281 list_add_tail(&port->list, &adapter->port_list_head);
1da177e4
LT
1282 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1283 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1284 if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
1285 if (!adapter->nameserver_port)
1286 adapter->nameserver_port = port;
1287 adapter->ports++;
1288 write_unlock_irq(&zfcp_data.config_lock);
1289
1290 zfcp_adapter_get(adapter);
1291
1292 return port;
1293}
1294
1295void
1296zfcp_port_dequeue(struct zfcp_port *port)
1297{
1298 zfcp_port_wait(port);
1299 write_lock_irq(&zfcp_data.config_lock);
1300 list_del(&port->list);
1301 port->adapter->ports--;
1302 write_unlock_irq(&zfcp_data.config_lock);
3859f6a2 1303 if (port->rport)
20b1730a
HC
1304 fc_remote_port_delete(port->rport);
1305 port->rport = NULL;
1da177e4
LT
1306 zfcp_adapter_put(port->adapter);
1307 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1308 atomic_read(&port->status));
1309 device_unregister(&port->sysfs_device);
1310}
1311
1312/* Enqueues a nameserver port */
1313int
1314zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1315{
1316 struct zfcp_port *port;
1317
1318 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
1319 ZFCP_DID_DIRECTORY_SERVICE);
1320 if (!port) {
1321 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1322 "adapter %s failed\n",
1323 zfcp_get_busid_by_adapter(adapter));
1324 return -ENXIO;
1325 }
1326 zfcp_port_put(port);
1327
1328 return 0;
1329}
1330
1331#undef ZFCP_LOG_AREA
1332
1333/****************************************************************/
1334/******* Fibre Channel Standard related Functions **************/
1335/****************************************************************/
1336
1337#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1338
1339void
1340zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1341 struct fsf_status_read_buffer *status_buffer)
1342{
1343 struct fcp_rscn_head *fcp_rscn_head;
1344 struct fcp_rscn_element *fcp_rscn_element;
1345 struct zfcp_port *port;
1346 u16 i;
1347 u16 no_entries;
1348 u32 range_mask;
1349 unsigned long flags;
1350
1351 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1352 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1353
1354 /* see FC-FS */
1355 no_entries = (fcp_rscn_head->payload_len / 4);
1356
1da177e4
LT
1357 for (i = 1; i < no_entries; i++) {
1358 /* skip head and start with 1st element */
1359 fcp_rscn_element++;
1360 switch (fcp_rscn_element->addr_format) {
1361 case ZFCP_PORT_ADDRESS:
1da177e4
LT
1362 range_mask = ZFCP_PORTS_RANGE_PORT;
1363 break;
1364 case ZFCP_AREA_ADDRESS:
1da177e4
LT
1365 range_mask = ZFCP_PORTS_RANGE_AREA;
1366 break;
1367 case ZFCP_DOMAIN_ADDRESS:
1da177e4
LT
1368 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1369 break;
1370 case ZFCP_FABRIC_ADDRESS:
1da177e4
LT
1371 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1372 break;
1373 default:
1374 ZFCP_LOG_INFO("incoming RSCN with unknown "
1375 "address format\n");
1376 continue;
1377 }
1378 read_lock_irqsave(&zfcp_data.config_lock, flags);
1379 list_for_each_entry(port, &adapter->port_list_head, list) {
1380 if (atomic_test_mask
1381 (ZFCP_STATUS_PORT_WKA, &port->status))
1382 continue;
1383 /* Do we know this port? If not skip it. */
1384 if (!atomic_test_mask
1385 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1386 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1387 "port 0x%016Lx\n", port->wwpn);
1da177e4
LT
1388 zfcp_erp_port_reopen(port,
1389 ZFCP_STATUS_COMMON_ERP_FAILED);
1390 continue;
1391 }
1392
1393 /*
1394 * FIXME: race: d_id might being invalidated
1395 * (...DID_DID reset)
1396 */
1397 if ((port->d_id & range_mask)
1398 == (fcp_rscn_element->nport_did & range_mask)) {
1399 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1400 fcp_rscn_element->nport_did);
1401 /*
1402 * Unfortunately, an RSCN does not specify the
1403 * type of change a target underwent. We assume
1404 * that it makes sense to reopen the link.
1405 * FIXME: Shall we try to find out more about
1406 * the target and link state before closing it?
1407 * How to accomplish this? (nameserver?)
1408 * Where would such code be put in?
1409 * (inside or outside erp)
1410 */
1411 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1412 "port 0x%016Lx\n", port->wwpn);
1da177e4
LT
1413 zfcp_test_link(port);
1414 }
1415 }
1416 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1417 }
1418}
1419
1420static void
1421zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1422 struct fsf_status_read_buffer *status_buffer)
1423{
06506d00 1424 struct fsf_plogi *els_plogi;
1da177e4
LT
1425 struct zfcp_port *port;
1426 unsigned long flags;
1427
06506d00 1428 els_plogi = (struct fsf_plogi *) status_buffer->payload;
1da177e4
LT
1429 read_lock_irqsave(&zfcp_data.config_lock, flags);
1430 list_for_each_entry(port, &adapter->port_list_head, list) {
06506d00 1431 if (port->wwpn == (*(wwn_t *) &els_plogi->serv_param.wwpn))
1da177e4
LT
1432 break;
1433 }
1434 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1435
06506d00 1436 if (!port || (port->wwpn != (*(wwn_t *) &els_plogi->serv_param.wwpn))) {
1da177e4 1437 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1d589edf 1438 "with d_id 0x%06x on adapter %s\n",
1da177e4
LT
1439 status_buffer->d_id,
1440 zfcp_get_busid_by_adapter(adapter));
1441 } else {
1da177e4
LT
1442 zfcp_erp_port_forced_reopen(port, 0);
1443 }
1444}
1445
1446static void
1447zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1448 struct fsf_status_read_buffer *status_buffer)
1449{
1450 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1451 struct zfcp_port *port;
1452 unsigned long flags;
1453
1da177e4
LT
1454 read_lock_irqsave(&zfcp_data.config_lock, flags);
1455 list_for_each_entry(port, &adapter->port_list_head, list) {
1456 if (port->wwpn == els_logo->nport_wwpn)
1457 break;
1458 }
1459 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1460
1461 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1462 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1d589edf 1463 "with d_id 0x%06x on adapter %s\n",
1da177e4
LT
1464 status_buffer->d_id,
1465 zfcp_get_busid_by_adapter(adapter));
1466 } else {
1da177e4
LT
1467 zfcp_erp_port_forced_reopen(port, 0);
1468 }
1469}
1470
1471static void
1472zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
1473 struct fsf_status_read_buffer *status_buffer)
1474{
1da177e4
LT
1475 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1476 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1477 zfcp_get_busid_by_adapter(adapter));
1478
1479}
1480
1481void
1482zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1483{
1484 struct fsf_status_read_buffer *status_buffer;
1485 u32 els_type;
1486 struct zfcp_adapter *adapter;
1487
059c97d0 1488 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
1da177e4
LT
1489 els_type = *(u32 *) (status_buffer->payload);
1490 adapter = fsf_req->adapter;
1491
8a36e453 1492 zfcp_san_dbf_event_incoming_els(fsf_req);
1da177e4
LT
1493 if (els_type == LS_PLOGI)
1494 zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
1495 else if (els_type == LS_LOGO)
1496 zfcp_fsf_incoming_els_logo(adapter, status_buffer);
1497 else if ((els_type & 0xffff0000) == LS_RSCN)
1498 /* we are only concerned with the command, not the length */
1499 zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
1500 else
1501 zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
1502}
1503
1504
1505/**
1506 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1507 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1508 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1509 */
1510static int
1511zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1512{
1513 struct zfcp_gid_pn_data *data;
1514
1515 if (pool != NULL) {
1516 data = mempool_alloc(pool, GFP_ATOMIC);
1517 if (likely(data != NULL)) {
1518 data->ct.pool = pool;
1519 }
1520 } else {
1521 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1522 }
1523
1524 if (NULL == data)
1525 return -ENOMEM;
1526
1527 memset(data, 0, sizeof(*data));
1528 data->ct.req = &data->req;
1529 data->ct.resp = &data->resp;
1530 data->ct.req_count = data->ct.resp_count = 1;
1531 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1532 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1533 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1534 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1535
1536 *gid_pn = data;
1537 return 0;
1538}
1539
1540/**
1541 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1542 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1543 */
1544static void
1545zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1546{
1547 if ((gid_pn->ct.pool != 0))
1548 mempool_free(gid_pn, gid_pn->ct.pool);
1549 else
1550 kfree(gid_pn);
1551
1552 return;
1553}
1554
1555/**
1556 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1557 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1558 */
1559int
1560zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1561{
1562 int ret;
1563 struct ct_iu_gid_pn_req *ct_iu_req;
1564 struct zfcp_gid_pn_data *gid_pn;
1565 struct zfcp_adapter *adapter = erp_action->adapter;
1566
1567 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1568 if (ret < 0) {
1569 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1570 "request failed for adapter %s\n",
1571 zfcp_get_busid_by_adapter(adapter));
1572 goto out;
1573 }
1574
1575 /* setup nameserver request */
1576 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1577 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1578 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1579 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1580 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1581 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1582 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1583 ct_iu_req->wwpn = erp_action->port->wwpn;
1584
1585 /* setup parameters for send generic command */
1586 gid_pn->ct.port = adapter->nameserver_port;
1587 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1588 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1589 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1da177e4
LT
1590 gid_pn->port = erp_action->port;
1591
1592 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1593 erp_action);
1594 if (ret) {
1595 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1596 "failed for adapter %s\n",
1597 zfcp_get_busid_by_adapter(adapter));
1598
1599 zfcp_gid_pn_buffers_free(gid_pn);
1600 }
1601
1602 out:
1603 return ret;
1604}
1605
1606/**
1607 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1608 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1609 */
1610static void zfcp_ns_gid_pn_handler(unsigned long data)
1611{
1612 struct zfcp_port *port;
1613 struct zfcp_send_ct *ct;
1614 struct ct_iu_gid_pn_req *ct_iu_req;
1615 struct ct_iu_gid_pn_resp *ct_iu_resp;
1616 struct zfcp_gid_pn_data *gid_pn;
1617
1618
1619 gid_pn = (struct zfcp_gid_pn_data *) data;
1620 port = gid_pn->port;
1621 ct = &gid_pn->ct;
1622 ct_iu_req = zfcp_sg_to_address(ct->req);
1623 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1624
66c8684a
AH
1625 if (ct->status != 0)
1626 goto failed;
1627
1628 if (zfcp_check_ct_response(&ct_iu_resp->header)) {
1da177e4
LT
1629 /* FIXME: do we need some specific erp entry points */
1630 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1631 goto failed;
1632 }
1633 /* paranoia */
1634 if (ct_iu_req->wwpn != port->wwpn) {
1635 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1636 "lookup does not match expected wwpn 0x%016Lx "
1637 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1638 zfcp_get_busid_by_port(port));
1639 goto mismatch;
1640 }
1641
1642 /* looks like a valid d_id */
1643 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1644 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1d589edf 1645 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%06x\n",
1da177e4
LT
1646 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1647 goto out;
1648
1649 mismatch:
1650 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1651 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1652 sizeof(struct ct_iu_gid_pn_req));
1653 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1654 sizeof(struct ct_iu_gid_pn_resp));
1655
1656 failed:
1657 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1658 "0x%016Lx for adapter %s\n",
1659 port->wwpn, zfcp_get_busid_by_port(port));
1660 out:
1661 zfcp_gid_pn_buffers_free(gid_pn);
1662 return;
1663}
1664
1665/* reject CT_IU reason codes acc. to FC-GS-4 */
1666static const struct zfcp_rc_entry zfcp_ct_rc[] = {
1667 {0x01, "invalid command code"},
1668 {0x02, "invalid version level"},
1669 {0x03, "logical error"},
1670 {0x04, "invalid CT_IU size"},
1671 {0x05, "logical busy"},
1672 {0x07, "protocol error"},
1673 {0x09, "unable to perform command request"},
1674 {0x0b, "command not supported"},
1675 {0x0d, "server not available"},
1676 {0x0e, "session could not be established"},
1677 {0xff, "vendor specific error"},
1678 {0, NULL},
1679};
1680
1681/* LS_RJT reason codes acc. to FC-FS */
1682static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = {
1683 {0x01, "invalid LS_Command code"},
1684 {0x03, "logical error"},
1685 {0x05, "logical busy"},
1686 {0x07, "protocol error"},
1687 {0x09, "unable to perform command request"},
1688 {0x0b, "command not supported"},
1689 {0x0e, "command already in progress"},
1690 {0xff, "vendor specific error"},
1691 {0, NULL},
1692};
1693
1694/* reject reason codes according to FC-PH/FC-FS */
1695static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = {
1696 {0x01, "invalid D_ID"},
1697 {0x02, "invalid S_ID"},
1698 {0x03, "Nx_Port not available, temporary"},
1699 {0x04, "Nx_Port not available, permament"},
1700 {0x05, "class not supported"},
1701 {0x06, "delimiter usage error"},
1702 {0x07, "TYPE not supported"},
1703 {0x08, "invalid Link_Control"},
1704 {0x09, "invalid R_CTL field"},
1705 {0x0a, "invalid F_CTL field"},
1706 {0x0b, "invalid OX_ID"},
1707 {0x0c, "invalid RX_ID"},
1708 {0x0d, "invalid SEQ_ID"},
1709 {0x0e, "invalid DF_CTL"},
1710 {0x0f, "invalid SEQ_CNT"},
1711 {0x10, "invalid parameter field"},
1712 {0x11, "exchange error"},
1713 {0x12, "protocol error"},
1714 {0x13, "incorrect length"},
1715 {0x14, "unsupported ACK"},
1716 {0x15, "class of service not supported by entity at FFFFFE"},
1717 {0x16, "login required"},
1718 {0x17, "excessive sequences attempted"},
1719 {0x18, "unable to establish exchange"},
1720 {0x1a, "fabric path not available"},
1721 {0x1b, "invalid VC_ID (class 4)"},
1722 {0x1c, "invalid CS_CTL field"},
1723 {0x1d, "insufficient resources for VC (class 4)"},
1724 {0x1f, "invalid class of service"},
1725 {0x20, "preemption request rejected"},
1726 {0x21, "preemption not enabled"},
1727 {0x22, "multicast error"},
1728 {0x23, "multicast error terminate"},
1729 {0x24, "process login required"},
1730 {0xff, "vendor specific reject"},
1731 {0, NULL},
1732};
1733
1734/**
1735 * zfcp_rc_description - return description for given reaon code
1736 * @code: reason code
1737 * @rc_table: table of reason codes and descriptions
1738 */
4d284cac 1739static const char *
1da177e4
LT
1740zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table)
1741{
1742 const char *descr = "unknown reason code";
1743
1744 do {
1745 if (code == rc_table->code) {
1746 descr = rc_table->description;
1747 break;
1748 }
1749 rc_table++;
1750 } while (rc_table->code && rc_table->description);
1751
1752 return descr;
1753}
1754
1755/**
1756 * zfcp_check_ct_response - evaluate reason code for CT_IU
1757 * @rjt: response payload to an CT_IU request
1758 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1759 */
1760int
1761zfcp_check_ct_response(struct ct_hdr *rjt)
1762{
1763 if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT)
1764 return 0;
1765
1766 if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) {
1767 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1768 "response code (0x%04hx)\n",
1769 rjt->cmd_rsp_code);
1770 return 1;
1771 }
1772
1773 ZFCP_LOG_INFO("Generic Service command rejected\n");
1774 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1775 zfcp_rc_description(rjt->reason_code, zfcp_ct_rc),
1776 (u32) rjt->reason_code, (u32) rjt->reason_code_expl,
1777 (u32) rjt->vendor_unique);
1778
1779 return 1;
1780}
1781
1782/**
1783 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1784 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1785 * @rc_table: table of reason codes and descriptions
1786 */
4d284cac 1787static void
1da177e4
LT
1788zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par,
1789 const struct zfcp_rc_entry *rc_table)
1790{
1791 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1792 zfcp_rc_description(rjt_par->reason_code, rc_table),
1793 (u32) rjt_par->action, (u32) rjt_par->reason_code,
1794 (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique);
1795}
1796
1797/**
1798 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1799 * @sq: status qualifier word
1800 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1801 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1802 */
1803int
1804zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par)
1805{
1806 int ret = -EIO;
1807
1808 if (sq == FSF_IOSTAT_NPORT_RJT) {
1809 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1810 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1811 /* invalid d_id */
1812 if (rjt_par->reason_code == 0x01)
1813 ret = -EREMCHG;
1814 } else if (sq == FSF_IOSTAT_FABRIC_RJT) {
1815 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1816 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1817 /* invalid d_id */
1818 if (rjt_par->reason_code == 0x01)
1819 ret = -EREMCHG;
1820 } else if (sq == FSF_IOSTAT_LS_RJT) {
1821 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1822 zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc);
1823 ret = -EREMOTEIO;
1824 } else
1825 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq);
1826
1827 return ret;
1828}
1829
75bfc283
RW
1830/**
1831 * zfcp_plogi_evaluate - evaluate PLOGI playload and copy important fields
1832 * into zfcp_port structure
1833 * @port: zfcp_port structure
1834 * @plogi: plogi payload
1835 */
1836void
1837zfcp_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi)
1838{
1839 port->maxframe_size = plogi->serv_param.common_serv_param[7] |
1840 ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8);
1841 if (plogi->serv_param.class1_serv_param[0] & 0x80)
1842 port->supported_classes |= FC_COS_CLASS1;
1843 if (plogi->serv_param.class2_serv_param[0] & 0x80)
1844 port->supported_classes |= FC_COS_CLASS2;
1845 if (plogi->serv_param.class3_serv_param[0] & 0x80)
1846 port->supported_classes |= FC_COS_CLASS3;
1847 if (plogi->serv_param.class4_serv_param[0] & 0x80)
1848 port->supported_classes |= FC_COS_CLASS4;
1849}
1850
1da177e4 1851#undef ZFCP_LOG_AREA
This page took 0.296765 seconds and 5 git commands to generate.