aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/scsi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/s390/scsi')
-rw-r--r--drivers/s390/scsi/Makefile9
-rw-r--r--drivers/s390/scsi/zfcp_aux.c1977
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c312
-rw-r--r--drivers/s390/scsi/zfcp_def.h1121
-rw-r--r--drivers/s390/scsi/zfcp_erp.c3585
-rw-r--r--drivers/s390/scsi/zfcp_ext.h186
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c5087
-rw-r--r--drivers/s390/scsi/zfcp_fsf.h472
-rw-r--r--drivers/s390/scsi/zfcp_qdio.c868
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c949
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_adapter.c298
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_driver.c135
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_port.c311
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_unit.c179
14 files changed, 15489 insertions, 0 deletions
diff --git a/drivers/s390/scsi/Makefile b/drivers/s390/scsi/Makefile
new file mode 100644
index 000000000000..fc145307a7d4
--- /dev/null
+++ b/drivers/s390/scsi/Makefile
@@ -0,0 +1,9 @@
1#
2# Makefile for the S/390 specific device drivers
3#
4
5zfcp-objs := zfcp_aux.o zfcp_ccw.o zfcp_scsi.o zfcp_erp.o zfcp_qdio.o \
6 zfcp_fsf.o zfcp_sysfs_adapter.o zfcp_sysfs_port.o \
7 zfcp_sysfs_unit.o zfcp_sysfs_driver.o
8
9obj-$(CONFIG_ZFCP) += zfcp.o
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
new file mode 100644
index 000000000000..6a43322ccb0a
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -0,0 +1,1977 @@
1/*
2 *
3 * linux/drivers/s390/scsi/zfcp_aux.c
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
32#define ZFCP_AUX_REVISION "$Revision: 1.145 $"
33
34#include "zfcp_ext.h"
35
36/* accumulated log level (module parameter) */
37static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS;
38static char *device;
39/*********************** FUNCTION PROTOTYPES *********************************/
40
41/* written against the module interface */
42static int __init zfcp_module_init(void);
43
44/* FCP related */
45static void zfcp_ns_gid_pn_handler(unsigned long);
46
47/* miscellaneous */
48static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
49static inline void zfcp_sg_list_free(struct zfcp_sg_list *);
50static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *,
51 void __user *, size_t);
52static inline int zfcp_sg_list_copy_to_user(void __user *,
53 struct zfcp_sg_list *, size_t);
54
55static int zfcp_cfdc_dev_ioctl(struct inode *, struct file *,
56 unsigned int, unsigned long);
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
62#ifdef CONFIG_COMPAT
63static struct ioctl_trans zfcp_ioctl_trans = {ZFCP_CFDC_IOC, (void*) sys_ioctl};
64#endif
65
66static struct file_operations zfcp_cfdc_fops = {
67 .ioctl = zfcp_cfdc_dev_ioctl
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
81MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, "
82 "Andreas Herrman <aherrman@de.ibm.com>, "
83 "Martin Peschke <mpeschke@de.ibm.com>, "
84 "Raimund Schroeder <raimund.schroeder@de.ibm.com>, "
85 "Wolfgang Taphorn <taphorn@de.ibm.com>, "
86 "Aron Zeh <arzeh@de.ibm.com>, "
87 "IBM Deutschland Entwicklung GmbH");
88MODULE_DESCRIPTION
89 ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries");
90MODULE_LICENSE("GPL");
91
92module_param(device, charp, 0);
93MODULE_PARM_DESC(device, "specify initial device");
94
95module_param(loglevel, uint, 0);
96MODULE_PARM_DESC(loglevel,
97 "log levels, 8 nibbles: "
98 "FC ERP QDIO CIO Config FSF SCSI Other, "
99 "levels: 0=none 1=normal 2=devel 3=trace");
100
101#ifdef ZFCP_PRINT_FLAGS
102u32 flags_dump = 0;
103module_param(flags_dump, uint, 0);
104#endif
105
106/****************************************************************/
107/************** Functions without logging ***********************/
108/****************************************************************/
109
110void
111_zfcp_hex_dump(char *addr, int count)
112{
113 int i;
114 for (i = 0; i < count; i++) {
115 printk("%02x", addr[i]);
116 if ((i % 4) == 3)
117 printk(" ");
118 if ((i % 32) == 31)
119 printk("\n");
120 }
121 if (((i-1) % 32) != 31)
122 printk("\n");
123}
124
125/****************************************************************/
126/************** Uncategorised Functions *************************/
127/****************************************************************/
128
129#define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
130
131static inline int
132zfcp_fsf_req_is_scsi_cmnd(struct zfcp_fsf_req *fsf_req)
133{
134 return ((fsf_req->fsf_command == FSF_QTCB_FCP_CMND) &&
135 !(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT));
136}
137
138void
139zfcp_cmd_dbf_event_fsf(const char *text, struct zfcp_fsf_req *fsf_req,
140 void *add_data, int add_length)
141{
142 struct zfcp_adapter *adapter = fsf_req->adapter;
143 struct scsi_cmnd *scsi_cmnd;
144 int level = 3;
145 int i;
146 unsigned long flags;
147
148 spin_lock_irqsave(&adapter->dbf_lock, flags);
149 if (zfcp_fsf_req_is_scsi_cmnd(fsf_req)) {
150 scsi_cmnd = fsf_req->data.send_fcp_command_task.scsi_cmnd;
151 debug_text_event(adapter->cmd_dbf, level, "fsferror");
152 debug_text_event(adapter->cmd_dbf, level, text);
153 debug_event(adapter->cmd_dbf, level, &fsf_req,
154 sizeof (unsigned long));
155 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
156 sizeof (u32));
157 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
158 sizeof (unsigned long));
159 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
160 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
161 for (i = 0; i < add_length; i += ZFCP_CMD_DBF_LENGTH)
162 debug_event(adapter->cmd_dbf,
163 level,
164 (char *) add_data + i,
165 min(ZFCP_CMD_DBF_LENGTH, add_length - i));
166 }
167 spin_unlock_irqrestore(&adapter->dbf_lock, flags);
168}
169
170/* XXX additionally log unit if available */
171/* ---> introduce new parameter for unit, see 2.4 code */
172void
173zfcp_cmd_dbf_event_scsi(const char *text, struct scsi_cmnd *scsi_cmnd)
174{
175 struct zfcp_adapter *adapter;
176 union zfcp_req_data *req_data;
177 struct zfcp_fsf_req *fsf_req;
178 int level = ((host_byte(scsi_cmnd->result) != 0) ? 1 : 5);
179 unsigned long flags;
180
181 adapter = (struct zfcp_adapter *) scsi_cmnd->device->host->hostdata[0];
182 req_data = (union zfcp_req_data *) scsi_cmnd->host_scribble;
183 fsf_req = (req_data ? req_data->send_fcp_command_task.fsf_req : NULL);
184 spin_lock_irqsave(&adapter->dbf_lock, flags);
185 debug_text_event(adapter->cmd_dbf, level, "hostbyte");
186 debug_text_event(adapter->cmd_dbf, level, text);
187 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->result, sizeof (u32));
188 debug_event(adapter->cmd_dbf, level, &scsi_cmnd,
189 sizeof (unsigned long));
190 debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd,
191 min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len));
192 if (likely(fsf_req)) {
193 debug_event(adapter->cmd_dbf, level, &fsf_req,
194 sizeof (unsigned long));
195 debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no,
196 sizeof (u32));
197 } else {
198 debug_text_event(adapter->cmd_dbf, level, "");
199 debug_text_event(adapter->cmd_dbf, level, "");
200 }
201 spin_unlock_irqrestore(&adapter->dbf_lock, flags);
202}
203
204void
205zfcp_in_els_dbf_event(struct zfcp_adapter *adapter, const char *text,
206 struct fsf_status_read_buffer *status_buffer, int length)
207{
208 int level = 1;
209 int i;
210
211 debug_text_event(adapter->in_els_dbf, level, text);
212 debug_event(adapter->in_els_dbf, level, &status_buffer->d_id, 8);
213 for (i = 0; i < length; i += ZFCP_IN_ELS_DBF_LENGTH)
214 debug_event(adapter->in_els_dbf,
215 level,
216 (char *) status_buffer->payload + i,
217 min(ZFCP_IN_ELS_DBF_LENGTH, length - i));
218}
219
220/**
221 * zfcp_device_setup - setup function
222 * @str: pointer to parameter string
223 *
224 * Parse "device=..." parameter string.
225 */
226static int __init
227zfcp_device_setup(char *str)
228{
229 char *tmp;
230
231 if (!str)
232 return 0;
233
234 tmp = strchr(str, ',');
235 if (!tmp)
236 goto err_out;
237 *tmp++ = '\0';
238 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
239 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
240
241 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
242 if (*tmp++ != ',')
243 goto err_out;
244 if (*tmp == '\0')
245 goto err_out;
246
247 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
248 if (*tmp != '\0')
249 goto err_out;
250 return 1;
251
252 err_out:
253 ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
254 return 0;
255}
256
257static void __init
258zfcp_init_device_configure(void)
259{
260 struct zfcp_adapter *adapter;
261 struct zfcp_port *port;
262 struct zfcp_unit *unit;
263
264 down(&zfcp_data.config_sema);
265 read_lock_irq(&zfcp_data.config_lock);
266 adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
267 if (adapter)
268 zfcp_adapter_get(adapter);
269 read_unlock_irq(&zfcp_data.config_lock);
270
271 if (adapter == NULL)
272 goto out_adapter;
273 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
274 if (!port)
275 goto out_port;
276 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
277 if (!unit)
278 goto out_unit;
279 up(&zfcp_data.config_sema);
280 ccw_device_set_online(adapter->ccw_device);
281 zfcp_erp_wait(adapter);
282 down(&zfcp_data.config_sema);
283 zfcp_unit_put(unit);
284 out_unit:
285 zfcp_port_put(port);
286 out_port:
287 zfcp_adapter_put(adapter);
288 out_adapter:
289 up(&zfcp_data.config_sema);
290 return;
291}
292
293static int __init
294zfcp_module_init(void)
295{
296
297 int retval = 0;
298
299 atomic_set(&zfcp_data.loglevel, loglevel);
300
301 /* initialize adapter list */
302 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
303
304 /* initialize adapters to be removed list head */
305 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
306
307 zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
308 if (!zfcp_transport_template)
309 return -ENODEV;
310
311 retval = register_ioctl32_conversion(zfcp_ioctl_trans.cmd,
312 zfcp_ioctl_trans.handler);
313 if (retval != 0) {
314 ZFCP_LOG_INFO("registration of ioctl32 conversion failed\n");
315 goto out;
316 }
317
318 retval = misc_register(&zfcp_cfdc_misc);
319 if (retval != 0) {
320 ZFCP_LOG_INFO("registration of misc device "
321 "zfcp_cfdc failed\n");
322 goto out_misc_register;
323 } else {
324 ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
325 ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
326 }
327
328 /* Initialise proc semaphores */
329 sema_init(&zfcp_data.config_sema, 1);
330
331 /* initialise configuration rw lock */
332 rwlock_init(&zfcp_data.config_lock);
333
334 /* save address of data structure managing the driver module */
335 zfcp_data.scsi_host_template.module = THIS_MODULE;
336
337 /* setup dynamic I/O */
338 retval = zfcp_ccw_register();
339 if (retval) {
340 ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
341 goto out_ccw_register;
342 }
343
344 if (zfcp_device_setup(device))
345 zfcp_init_device_configure();
346
347 goto out;
348
349 out_ccw_register:
350 misc_deregister(&zfcp_cfdc_misc);
351 out_misc_register:
352 unregister_ioctl32_conversion(zfcp_ioctl_trans.cmd);
353 out:
354 return retval;
355}
356
357/*
358 * function: zfcp_cfdc_dev_ioctl
359 *
360 * purpose: Handle control file upload/download transaction via IOCTL
361 * interface
362 *
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)
372 */
373static int
374zfcp_cfdc_dev_ioctl(struct inode *inode, struct file *file,
375 unsigned int command, unsigned long buffer)
376{
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;
382 char *bus_id = NULL;
383 int retval = 0;
384
385 sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL);
386 if (sense_data == NULL) {
387 retval = -ENOMEM;
388 goto out;
389 }
390
391 sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
392 if (sg_list == NULL) {
393 retval = -ENOMEM;
394 goto out;
395 }
396 memset(sg_list, 0, sizeof(*sg_list));
397
398 if (command != ZFCP_CFDC_IOC) {
399 ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
400 retval = -ENOTTY;
401 goto out;
402 }
403
404 if ((sense_data_user = (void __user *) buffer) == NULL) {
405 ZFCP_LOG_INFO("sense data record is required\n");
406 retval = -EINVAL;
407 goto out;
408 }
409
410 retval = copy_from_user(sense_data, sense_data_user,
411 sizeof(struct zfcp_cfdc_sense_data));
412 if (retval) {
413 retval = -EFAULT;
414 goto out;
415 }
416
417 if (sense_data->signature != ZFCP_CFDC_SIGNATURE) {
418 ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
419 ZFCP_CFDC_SIGNATURE);
420 retval = -EINVAL;
421 goto out;
422 }
423
424 switch (sense_data->command) {
425
426 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
427 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
428 option = FSF_CFDC_OPTION_NORMAL_MODE;
429 break;
430
431 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
432 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
433 option = FSF_CFDC_OPTION_FORCE;
434 break;
435
436 case ZFCP_CFDC_CMND_FULL_ACCESS:
437 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
438 option = FSF_CFDC_OPTION_FULL_ACCESS;
439 break;
440
441 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
442 fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
443 option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
444 break;
445
446 case ZFCP_CFDC_CMND_UPLOAD:
447 fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
448 option = 0;
449 break;
450
451 default:
452 ZFCP_LOG_INFO("invalid command code 0x%08x\n",
453 sense_data->command);
454 retval = -EINVAL;
455 goto out;
456 }
457
458 bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
459 if (bus_id == NULL) {
460 retval = -ENOMEM;
461 goto out;
462 }
463 snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
464 (sense_data->devno >> 24),
465 (sense_data->devno >> 16) & 0xFF,
466 (sense_data->devno & 0xFFFF));
467
468 read_lock_irq(&zfcp_data.config_lock);
469 adapter = zfcp_get_adapter_by_busid(bus_id);
470 if (adapter)
471 zfcp_adapter_get(adapter);
472 read_unlock_irq(&zfcp_data.config_lock);
473
474 kfree(bus_id);
475
476 if (adapter == NULL) {
477 ZFCP_LOG_INFO("invalid adapter\n");
478 retval = -ENXIO;
479 goto out;
480 }
481
482 if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) {
483 retval = zfcp_sg_list_alloc(sg_list,
484 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
485 if (retval) {
486 retval = -ENOMEM;
487 goto out;
488 }
489 }
490
491 if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) &&
492 (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
493 retval = zfcp_sg_list_copy_from_user(
494 sg_list, &sense_data_user->control_file,
495 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
496 if (retval) {
497 retval = -EFAULT;
498 goto out;
499 }
500 }
501
502 retval = zfcp_fsf_control_file(adapter, &fsf_req, fsf_command,
503 option, sg_list);
504 if (retval)
505 goto out;
506
507 if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
508 (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
509 retval = -ENXIO;
510 goto out;
511 }
512
513 sense_data->fsf_status = fsf_req->qtcb->header.fsf_status;
514 memcpy(&sense_data->fsf_status_qual,
515 &fsf_req->qtcb->header.fsf_status_qual,
516 sizeof(union fsf_status_qual));
517 memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256);
518
519 retval = copy_to_user(sense_data_user, sense_data,
520 sizeof(struct zfcp_cfdc_sense_data));
521 if (retval) {
522 retval = -EFAULT;
523 goto out;
524 }
525
526 if (sense_data->command & ZFCP_CFDC_UPLOAD) {
527 retval = zfcp_sg_list_copy_to_user(
528 &sense_data_user->control_file, sg_list,
529 ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
530 if (retval) {
531 retval = -EFAULT;
532 goto out;
533 }
534 }
535
536 out:
537 if (fsf_req != NULL)
538 zfcp_fsf_req_cleanup(fsf_req);
539
540 if ((adapter != NULL) && (retval != -ENXIO))
541 zfcp_adapter_put(adapter);
542
543 if (sg_list != NULL) {
544 zfcp_sg_list_free(sg_list);
545 kfree(sg_list);
546 }
547
548 if (sense_data != NULL)
549 kfree(sense_data);
550
551 return retval;
552}
553
554
555/**
556 * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
557 * @sg_list: structure describing a scatter gather list
558 * @size: size of scatter-gather list
559 * Return: 0 on success, else -ENOMEM
560 *
561 * In sg_list->sg a pointer to the created scatter-gather list is returned,
562 * or NULL if we run out of memory. sg_list->count specifies the number of
563 * elements of the scatter-gather list. The maximum size of a single element
564 * in the scatter-gather list is PAGE_SIZE.
565 */
566static inline int
567zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
568{
569 struct scatterlist *sg;
570 unsigned int i;
571 int retval = 0;
572 void *address;
573
574 BUG_ON(sg_list == NULL);
575
576 sg_list->count = size >> PAGE_SHIFT;
577 if (size & ~PAGE_MASK)
578 sg_list->count++;
579 sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
580 GFP_KERNEL);
581 if (sg_list->sg == NULL) {
582 sg_list->count = 0;
583 retval = -ENOMEM;
584 goto out;
585 }
586 memset(sg_list->sg, 0, sg_list->count * sizeof(struct scatterlist));
587
588 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
589 sg->length = min(size, PAGE_SIZE);
590 sg->offset = 0;
591 address = (void *) get_zeroed_page(GFP_KERNEL);
592 if (address == NULL) {
593 sg_list->count = i;
594 zfcp_sg_list_free(sg_list);
595 retval = -ENOMEM;
596 goto out;
597 }
598 zfcp_address_to_sg(address, sg);
599 size -= sg->length;
600 }
601
602 out:
603 return retval;
604}
605
606
607/**
608 * zfcp_sg_list_free - free memory of a scatter-gather list
609 * @sg_list: structure describing a scatter-gather list
610 *
611 * Memory for each element in the scatter-gather list is freed.
612 * Finally sg_list->sg is freed itself and sg_list->count is reset.
613 */
614static inline void
615zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
616{
617 struct scatterlist *sg;
618 unsigned int i;
619
620 BUG_ON(sg_list == NULL);
621
622 for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
623 free_page((unsigned long) zfcp_sg_to_address(sg));
624
625 sg_list->count = 0;
626 kfree(sg_list->sg);
627}
628
629/**
630 * zfcp_sg_size - determine size of a scatter-gather list
631 * @sg: array of (struct scatterlist)
632 * @sg_count: elements in array
633 * Return: size of entire scatter-gather list
634 */
635size_t
636zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
637{
638 unsigned int i;
639 struct scatterlist *p;
640 size_t size;
641
642 size = 0;
643 for (i = 0, p = sg; i < sg_count; i++, p++) {
644 BUG_ON(p == NULL);
645 size += p->length;
646 }
647
648 return size;
649}
650
651
652/**
653 * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
654 * @sg_list: structure describing a scatter-gather list
655 * @user_buffer: pointer to buffer in user space
656 * @size: number of bytes to be copied
657 * Return: 0 on success, -EFAULT if copy_from_user fails.
658 */
659static inline int
660zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list,
661 void __user *user_buffer,
662 size_t size)
663{
664 struct scatterlist *sg;
665 unsigned int length;
666 void *zfcp_buffer;
667 int retval = 0;
668
669 BUG_ON(sg_list == NULL);
670
671 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
672 return -EFAULT;
673
674 for (sg = sg_list->sg; size > 0; sg++) {
675 length = min((unsigned int)size, sg->length);
676 zfcp_buffer = zfcp_sg_to_address(sg);
677 if (copy_from_user(zfcp_buffer, user_buffer, length)) {
678 retval = -EFAULT;
679 goto out;
680 }
681 user_buffer += length;
682 size -= length;
683 }
684
685 out:
686 return retval;
687}
688
689
690/**
691 * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
692 * @user_buffer: pointer to buffer in user space
693 * @sg_list: structure describing a scatter-gather list
694 * @size: number of bytes to be copied
695 * Return: 0 on success, -EFAULT if copy_to_user fails
696 */
697static inline int
698zfcp_sg_list_copy_to_user(void __user *user_buffer,
699 struct zfcp_sg_list *sg_list,
700 size_t size)
701{
702 struct scatterlist *sg;
703 unsigned int length;
704 void *zfcp_buffer;
705 int retval = 0;
706
707 BUG_ON(sg_list == NULL);
708
709 if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
710 return -EFAULT;
711
712 for (sg = sg_list->sg; size > 0; sg++) {
713 length = min((unsigned int) size, sg->length);
714 zfcp_buffer = zfcp_sg_to_address(sg);
715 if (copy_to_user(user_buffer, zfcp_buffer, length)) {
716 retval = -EFAULT;
717 goto out;
718 }
719 user_buffer += length;
720 size -= length;
721 }
722
723 out:
724 return retval;
725}
726
727
728#undef ZFCP_LOG_AREA
729
730/****************************************************************/
731/****** Functions for configuration/set-up of structures ********/
732/****************************************************************/
733
734#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
735
736/**
737 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
738 * @port: pointer to port to search for unit
739 * @fcp_lun: FCP LUN to search for
740 * Traverse list of all units of a port and return pointer to a unit
741 * with the given FCP LUN.
742 */
743struct zfcp_unit *
744zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
745{
746 struct zfcp_unit *unit;
747 int found = 0;
748
749 list_for_each_entry(unit, &port->unit_list_head, list) {
750 if ((unit->fcp_lun == fcp_lun) &&
751 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
752 {
753 found = 1;
754 break;
755 }
756 }
757 return found ? unit : NULL;
758}
759
760/**
761 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
762 * @adapter: pointer to adapter to search for port
763 * @wwpn: wwpn to search for
764 * Traverse list of all ports of an adapter and return pointer to a port
765 * with the given wwpn.
766 */
767struct zfcp_port *
768zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
769{
770 struct zfcp_port *port;
771 int found = 0;
772
773 list_for_each_entry(port, &adapter->port_list_head, list) {
774 if ((port->wwpn == wwpn) &&
775 !(atomic_read(&port->status) &
776 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
777 found = 1;
778 break;
779 }
780 }
781 return found ? port : NULL;
782}
783
784/**
785 * zfcp_get_port_by_did - find port in port list of adapter by d_id
786 * @adapter: pointer to adapter to search for port
787 * @d_id: d_id to search for
788 * Traverse list of all ports of an adapter and return pointer to a port
789 * with the given d_id.
790 */
791struct zfcp_port *
792zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
793{
794 struct zfcp_port *port;
795 int found = 0;
796
797 list_for_each_entry(port, &adapter->port_list_head, list) {
798 if ((port->d_id == d_id) &&
799 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
800 {
801 found = 1;
802 break;
803 }
804 }
805 return found ? port : NULL;
806}
807
808/**
809 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
810 * @bus_id: bus_id to search for
811 * Traverse list of all adapters and return pointer to an adapter
812 * with the given bus_id.
813 */
814struct zfcp_adapter *
815zfcp_get_adapter_by_busid(char *bus_id)
816{
817 struct zfcp_adapter *adapter;
818 int found = 0;
819
820 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
821 if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
822 BUS_ID_SIZE) == 0) &&
823 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
824 &adapter->status)){
825 found = 1;
826 break;
827 }
828 }
829 return found ? adapter : NULL;
830}
831
832/**
833 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
834 * @port: pointer to port where unit is added
835 * @fcp_lun: FCP LUN of unit to be enqueued
836 * Return: pointer to enqueued unit on success, NULL on error
837 * Locks: config_sema must be held to serialize changes to the unit list
838 *
839 * Sets up some unit internal structures and creates sysfs entry.
840 */
841struct zfcp_unit *
842zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
843{
844 struct zfcp_unit *unit, *tmp_unit;
845 scsi_lun_t scsi_lun;
846 int found;
847
848 /*
849 * check that there is no unit with this FCP_LUN already in list
850 * and enqueue it.
851 * Note: Unlike for the adapter and the port, this is an error
852 */
853 read_lock_irq(&zfcp_data.config_lock);
854 unit = zfcp_get_unit_by_lun(port, fcp_lun);
855 read_unlock_irq(&zfcp_data.config_lock);
856 if (unit)
857 return NULL;
858
859 unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
860 if (!unit)
861 return NULL;
862 memset(unit, 0, sizeof (struct zfcp_unit));
863
864 /* initialise reference count stuff */
865 atomic_set(&unit->refcount, 0);
866 init_waitqueue_head(&unit->remove_wq);
867
868 unit->port = port;
869 unit->fcp_lun = fcp_lun;
870
871 /* setup for sysfs registration */
872 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
873 unit->sysfs_device.parent = &port->sysfs_device;
874 unit->sysfs_device.release = zfcp_sysfs_unit_release;
875 dev_set_drvdata(&unit->sysfs_device, unit);
876
877 /* mark unit unusable as long as sysfs registration is not complete */
878 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
879
880 if (device_register(&unit->sysfs_device)) {
881 kfree(unit);
882 return NULL;
883 }
884
885 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
886 device_unregister(&unit->sysfs_device);
887 return NULL;
888 }
889
890 zfcp_unit_get(unit);
891
892 scsi_lun = 0;
893 found = 0;
894 write_lock_irq(&zfcp_data.config_lock);
895 list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
896 if (tmp_unit->scsi_lun != scsi_lun) {
897 found = 1;
898 break;
899 }
900 scsi_lun++;
901 }
902 unit->scsi_lun = scsi_lun;
903 if (found)
904 list_add_tail(&unit->list, &tmp_unit->list);
905 else
906 list_add_tail(&unit->list, &port->unit_list_head);
907 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
908 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
909 write_unlock_irq(&zfcp_data.config_lock);
910
911 port->units++;
912 zfcp_port_get(port);
913
914 return unit;
915}
916
917void
918zfcp_unit_dequeue(struct zfcp_unit *unit)
919{
920 zfcp_unit_wait(unit);
921 write_lock_irq(&zfcp_data.config_lock);
922 list_del(&unit->list);
923 write_unlock_irq(&zfcp_data.config_lock);
924 unit->port->units--;
925 zfcp_port_put(unit->port);
926 zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
927 device_unregister(&unit->sysfs_device);
928}
929
930static void *
931zfcp_mempool_alloc(unsigned int __nocast gfp_mask, void *size)
932{
933 return kmalloc((size_t) size, gfp_mask);
934}
935
936static void
937zfcp_mempool_free(void *element, void *size)
938{
939 kfree(element);
940}
941
942/*
943 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
944 * commands.
945 * It also genrates fcp-nameserver request/response buffer and unsolicited
946 * status read fsf_req buffers.
947 *
948 * locks: must only be called with zfcp_data.config_sema taken
949 */
950static int
951zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
952{
953 adapter->pool.fsf_req_erp =
954 mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR,
955 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
956 sizeof(struct zfcp_fsf_req_pool_element));
957
958 if (NULL == adapter->pool.fsf_req_erp)
959 return -ENOMEM;
960
961 adapter->pool.fsf_req_scsi =
962 mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR,
963 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
964 sizeof(struct zfcp_fsf_req_pool_element));
965
966 if (NULL == adapter->pool.fsf_req_scsi)
967 return -ENOMEM;
968
969 adapter->pool.fsf_req_abort =
970 mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR,
971 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
972 sizeof(struct zfcp_fsf_req_pool_element));
973
974 if (NULL == adapter->pool.fsf_req_abort)
975 return -ENOMEM;
976
977 adapter->pool.fsf_req_status_read =
978 mempool_create(ZFCP_POOL_STATUS_READ_NR,
979 zfcp_mempool_alloc, zfcp_mempool_free,
980 (void *) sizeof(struct zfcp_fsf_req));
981
982 if (NULL == adapter->pool.fsf_req_status_read)
983 return -ENOMEM;
984
985 adapter->pool.data_status_read =
986 mempool_create(ZFCP_POOL_STATUS_READ_NR,
987 zfcp_mempool_alloc, zfcp_mempool_free,
988 (void *) sizeof(struct fsf_status_read_buffer));
989
990 if (NULL == adapter->pool.data_status_read)
991 return -ENOMEM;
992
993 adapter->pool.data_gid_pn =
994 mempool_create(ZFCP_POOL_DATA_GID_PN_NR,
995 zfcp_mempool_alloc, zfcp_mempool_free, (void *)
996 sizeof(struct zfcp_gid_pn_data));
997
998 if (NULL == adapter->pool.data_gid_pn)
999 return -ENOMEM;
1000
1001 return 0;
1002}
1003
1004/**
1005 * zfcp_free_low_mem_buffers - free memory pools of an adapter
1006 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
1007 * locking: zfcp_data.config_sema must be held
1008 */
1009static void
1010zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
1011{
1012 if (adapter->pool.fsf_req_erp)
1013 mempool_destroy(adapter->pool.fsf_req_erp);
1014 if (adapter->pool.fsf_req_scsi)
1015 mempool_destroy(adapter->pool.fsf_req_scsi);
1016 if (adapter->pool.fsf_req_abort)
1017 mempool_destroy(adapter->pool.fsf_req_abort);
1018 if (adapter->pool.fsf_req_status_read)
1019 mempool_destroy(adapter->pool.fsf_req_status_read);
1020 if (adapter->pool.data_status_read)
1021 mempool_destroy(adapter->pool.data_status_read);
1022 if (adapter->pool.data_gid_pn)
1023 mempool_destroy(adapter->pool.data_gid_pn);
1024}
1025
1026/**
1027 * zfcp_adapter_debug_register - registers debug feature for an adapter
1028 * @adapter: pointer to adapter for which debug features should be registered
1029 * return: -ENOMEM on error, 0 otherwise
1030 */
1031int
1032zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1033{
1034 char dbf_name[20];
1035
1036 /* debug feature area which records SCSI command failures (hostbyte) */
1037 spin_lock_init(&adapter->dbf_lock);
1038
1039 sprintf(dbf_name, ZFCP_CMD_DBF_NAME "%s",
1040 zfcp_get_busid_by_adapter(adapter));
1041 adapter->cmd_dbf = debug_register(dbf_name, ZFCP_CMD_DBF_INDEX,
1042 ZFCP_CMD_DBF_AREAS,
1043 ZFCP_CMD_DBF_LENGTH);
1044 debug_register_view(adapter->cmd_dbf, &debug_hex_ascii_view);
1045 debug_set_level(adapter->cmd_dbf, ZFCP_CMD_DBF_LEVEL);
1046
1047 /* debug feature area which records SCSI command aborts */
1048 sprintf(dbf_name, ZFCP_ABORT_DBF_NAME "%s",
1049 zfcp_get_busid_by_adapter(adapter));
1050 adapter->abort_dbf = debug_register(dbf_name, ZFCP_ABORT_DBF_INDEX,
1051 ZFCP_ABORT_DBF_AREAS,
1052 ZFCP_ABORT_DBF_LENGTH);
1053 debug_register_view(adapter->abort_dbf, &debug_hex_ascii_view);
1054 debug_set_level(adapter->abort_dbf, ZFCP_ABORT_DBF_LEVEL);
1055
1056 /* debug feature area which records incoming ELS commands */
1057 sprintf(dbf_name, ZFCP_IN_ELS_DBF_NAME "%s",
1058 zfcp_get_busid_by_adapter(adapter));
1059 adapter->in_els_dbf = debug_register(dbf_name, ZFCP_IN_ELS_DBF_INDEX,
1060 ZFCP_IN_ELS_DBF_AREAS,
1061 ZFCP_IN_ELS_DBF_LENGTH);
1062 debug_register_view(adapter->in_els_dbf, &debug_hex_ascii_view);
1063 debug_set_level(adapter->in_els_dbf, ZFCP_IN_ELS_DBF_LEVEL);
1064
1065 /* debug feature area which records erp events */
1066 sprintf(dbf_name, ZFCP_ERP_DBF_NAME "%s",
1067 zfcp_get_busid_by_adapter(adapter));
1068 adapter->erp_dbf = debug_register(dbf_name, ZFCP_ERP_DBF_INDEX,
1069 ZFCP_ERP_DBF_AREAS,
1070 ZFCP_ERP_DBF_LENGTH);
1071 debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view);
1072 debug_set_level(adapter->erp_dbf, ZFCP_ERP_DBF_LEVEL);
1073
1074 if (!(adapter->cmd_dbf && adapter->abort_dbf &&
1075 adapter->in_els_dbf && adapter->erp_dbf)) {
1076 zfcp_adapter_debug_unregister(adapter);
1077 return -ENOMEM;
1078 }
1079
1080 return 0;
1081
1082}
1083
1084/**
1085 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1086 * @adapter: pointer to adapter for which debug features should be unregistered
1087 */
1088void
1089zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1090{
1091 debug_unregister(adapter->abort_dbf);
1092 debug_unregister(adapter->cmd_dbf);
1093 debug_unregister(adapter->erp_dbf);
1094 debug_unregister(adapter->in_els_dbf);
1095 adapter->abort_dbf = NULL;
1096 adapter->cmd_dbf = NULL;
1097 adapter->erp_dbf = NULL;
1098 adapter->in_els_dbf = NULL;
1099}
1100
1101void
1102zfcp_dummy_release(struct device *dev)
1103{
1104 return;
1105}
1106
1107/*
1108 * Enqueues an adapter at the end of the adapter list in the driver data.
1109 * All adapter internal structures are set up.
1110 * Proc-fs entries are also created.
1111 *
1112 * returns: 0 if a new adapter was successfully enqueued
1113 * ZFCP_KNOWN if an adapter with this devno was already present
1114 * -ENOMEM if alloc failed
1115 * locks: config_sema must be held to serialise changes to the adapter list
1116 */
1117struct zfcp_adapter *
1118zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1119{
1120 int retval = 0;
1121 struct zfcp_adapter *adapter;
1122
1123 /*
1124 * Note: It is safe to release the list_lock, as any list changes
1125 * are protected by the config_sema, which must be held to get here
1126 */
1127
1128 /* try to allocate new adapter data structure (zeroed) */
1129 adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
1130 if (!adapter) {
1131 ZFCP_LOG_INFO("error: allocation of base adapter "
1132 "structure failed\n");
1133 goto out;
1134 }
1135 memset(adapter, 0, sizeof (struct zfcp_adapter));
1136
1137 ccw_device->handler = NULL;
1138
1139 /* save ccw_device pointer */
1140 adapter->ccw_device = ccw_device;
1141
1142 retval = zfcp_qdio_allocate_queues(adapter);
1143 if (retval)
1144 goto queues_alloc_failed;
1145
1146 retval = zfcp_qdio_allocate(adapter);
1147 if (retval)
1148 goto qdio_allocate_failed;
1149
1150 retval = zfcp_allocate_low_mem_buffers(adapter);
1151 if (retval) {
1152 ZFCP_LOG_INFO("error: pool allocation failed\n");
1153 goto failed_low_mem_buffers;
1154 }
1155
1156 /* initialise reference count stuff */
1157 atomic_set(&adapter->refcount, 0);
1158 init_waitqueue_head(&adapter->remove_wq);
1159
1160 /* initialise list of ports */
1161 INIT_LIST_HEAD(&adapter->port_list_head);
1162
1163 /* initialise list of ports to be removed */
1164 INIT_LIST_HEAD(&adapter->port_remove_lh);
1165
1166 /* initialize list of fsf requests */
1167 rwlock_init(&adapter->fsf_req_list_lock);
1168 INIT_LIST_HEAD(&adapter->fsf_req_list_head);
1169
1170 /* initialize abort lock */
1171 rwlock_init(&adapter->abort_lock);
1172
1173 /* initialise some erp stuff */
1174 init_waitqueue_head(&adapter->erp_thread_wqh);
1175 init_waitqueue_head(&adapter->erp_done_wqh);
1176
1177 /* initialize lock of associated request queue */
1178 rwlock_init(&adapter->request_queue.queue_lock);
1179
1180 /* intitialise SCSI ER timer */
1181 init_timer(&adapter->scsi_er_timer);
1182
1183 /* set FC service class used per default */
1184 adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1185
1186 sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
1187 ASCEBC(adapter->name, strlen(adapter->name));
1188
1189 /* mark adapter unusable as long as sysfs registration is not complete */
1190 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1191
1192 adapter->ccw_device = ccw_device;
1193 dev_set_drvdata(&ccw_device->dev, adapter);
1194
1195 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
1196 goto sysfs_failed;
1197
1198 adapter->generic_services.parent = &adapter->ccw_device->dev;
1199 adapter->generic_services.release = zfcp_dummy_release;
1200 snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
1201 "generic_services");
1202
1203 if (device_register(&adapter->generic_services))
1204 goto generic_services_failed;
1205
1206 /* put allocated adapter at list tail */
1207 write_lock_irq(&zfcp_data.config_lock);
1208 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
1209 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
1210 write_unlock_irq(&zfcp_data.config_lock);
1211
1212 zfcp_data.adapters++;
1213
1214 goto out;
1215
1216 generic_services_failed:
1217 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1218 sysfs_failed:
1219 dev_set_drvdata(&ccw_device->dev, NULL);
1220 failed_low_mem_buffers:
1221 zfcp_free_low_mem_buffers(adapter);
1222 if (qdio_free(ccw_device) != 0)
1223 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1224 zfcp_get_busid_by_adapter(adapter));
1225 qdio_allocate_failed:
1226 zfcp_qdio_free_queues(adapter);
1227 queues_alloc_failed:
1228 kfree(adapter);
1229 adapter = NULL;
1230 out:
1231 return adapter;
1232}
1233
1234/*
1235 * returns: 0 - struct zfcp_adapter data structure successfully removed
1236 * !0 - struct zfcp_adapter data structure could not be removed
1237 * (e.g. still used)
1238 * locks: adapter list write lock is assumed to be held by caller
1239 * adapter->fsf_req_list_lock is taken and released within this
1240 * function and must not be held on entry
1241 */
1242void
1243zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1244{
1245 int retval = 0;
1246 unsigned long flags;
1247
1248 device_unregister(&adapter->generic_services);
1249 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1250 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1251 /* sanity check: no pending FSF requests */
1252 read_lock_irqsave(&adapter->fsf_req_list_lock, flags);
1253 retval = !list_empty(&adapter->fsf_req_list_head);
1254 read_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
1255 if (retval) {
1256 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1257 "%i requests outstanding\n",
1258 zfcp_get_busid_by_adapter(adapter), adapter,
1259 atomic_read(&adapter->fsf_reqs_active));
1260 retval = -EBUSY;
1261 goto out;
1262 }
1263
1264 /* remove specified adapter data structure from list */
1265 write_lock_irq(&zfcp_data.config_lock);
1266 list_del(&adapter->list);
1267 write_unlock_irq(&zfcp_data.config_lock);
1268
1269 /* decrease number of adapters in list */
1270 zfcp_data.adapters--;
1271
1272 ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
1273 "%i adapters still in list\n",
1274 zfcp_get_busid_by_adapter(adapter),
1275 adapter, zfcp_data.adapters);
1276
1277 retval = qdio_free(adapter->ccw_device);
1278 if (retval)
1279 ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
1280 zfcp_get_busid_by_adapter(adapter));
1281
1282 zfcp_free_low_mem_buffers(adapter);
1283 /* free memory of adapter data structure and queues */
1284 zfcp_qdio_free_queues(adapter);
1285 ZFCP_LOG_TRACE("freeing adapter structure\n");
1286 kfree(adapter);
1287 out:
1288 return;
1289}
1290
1291/**
1292 * zfcp_port_enqueue - enqueue port to port list of adapter
1293 * @adapter: adapter where remote port is added
1294 * @wwpn: WWPN of the remote port to be enqueued
1295 * @status: initial status for the port
1296 * @d_id: destination id of the remote port to be enqueued
1297 * Return: pointer to enqueued port on success, NULL on error
1298 * Locks: config_sema must be held to serialize changes to the port list
1299 *
1300 * All port internal structures are set up and the sysfs entry is generated.
1301 * d_id is used to enqueue ports with a well known address like the Directory
1302 * Service for nameserver lookup.
1303 */
1304struct zfcp_port *
1305zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
1306 u32 d_id)
1307{
1308 struct zfcp_port *port, *tmp_port;
1309 int check_wwpn;
1310 scsi_id_t scsi_id;
1311 int found;
1312
1313 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
1314
1315 /*
1316 * check that there is no port with this WWPN already in list
1317 */
1318 if (check_wwpn) {
1319 read_lock_irq(&zfcp_data.config_lock);
1320 port = zfcp_get_port_by_wwpn(adapter, wwpn);
1321 read_unlock_irq(&zfcp_data.config_lock);
1322 if (port)
1323 return NULL;
1324 }
1325
1326 port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
1327 if (!port)
1328 return NULL;
1329 memset(port, 0, sizeof (struct zfcp_port));
1330
1331 /* initialise reference count stuff */
1332 atomic_set(&port->refcount, 0);
1333 init_waitqueue_head(&port->remove_wq);
1334
1335 INIT_LIST_HEAD(&port->unit_list_head);
1336 INIT_LIST_HEAD(&port->unit_remove_lh);
1337
1338 port->adapter = adapter;
1339
1340 if (check_wwpn)
1341 port->wwpn = wwpn;
1342
1343 atomic_set_mask(status, &port->status);
1344
1345 /* setup for sysfs registration */
1346 if (status & ZFCP_STATUS_PORT_WKA) {
1347 switch (d_id) {
1348 case ZFCP_DID_DIRECTORY_SERVICE:
1349 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1350 "directory");
1351 break;
1352 case ZFCP_DID_MANAGEMENT_SERVICE:
1353 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1354 "management");
1355 break;
1356 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
1357 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1358 "key_distribution");
1359 break;
1360 case ZFCP_DID_ALIAS_SERVICE:
1361 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1362 "alias");
1363 break;
1364 case ZFCP_DID_TIME_SERVICE:
1365 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
1366 "time");
1367 break;
1368 default:
1369 kfree(port);
1370 return NULL;
1371 }
1372 port->d_id = d_id;
1373 port->sysfs_device.parent = &adapter->generic_services;
1374 } else {
1375 snprintf(port->sysfs_device.bus_id,
1376 BUS_ID_SIZE, "0x%016llx", wwpn);
1377 port->sysfs_device.parent = &adapter->ccw_device->dev;
1378 }
1379 port->sysfs_device.release = zfcp_sysfs_port_release;
1380 dev_set_drvdata(&port->sysfs_device, port);
1381
1382 /* mark port unusable as long as sysfs registration is not complete */
1383 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1384
1385 if (device_register(&port->sysfs_device)) {
1386 kfree(port);
1387 return NULL;
1388 }
1389
1390 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
1391 device_unregister(&port->sysfs_device);
1392 return NULL;
1393 }
1394
1395 zfcp_port_get(port);
1396
1397 scsi_id = 1;
1398 found = 0;
1399 write_lock_irq(&zfcp_data.config_lock);
1400 list_for_each_entry(tmp_port, &adapter->port_list_head, list) {
1401 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_SCSI_ID,
1402 &tmp_port->status))
1403 continue;
1404 if (tmp_port->scsi_id != scsi_id) {
1405 found = 1;
1406 break;
1407 }
1408 scsi_id++;
1409 }
1410 port->scsi_id = scsi_id;
1411 if (found)
1412 list_add_tail(&port->list, &tmp_port->list);
1413 else
1414 list_add_tail(&port->list, &adapter->port_list_head);
1415 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
1416 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
1417 if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
1418 if (!adapter->nameserver_port)
1419 adapter->nameserver_port = port;
1420 adapter->ports++;
1421 write_unlock_irq(&zfcp_data.config_lock);
1422
1423 zfcp_adapter_get(adapter);
1424
1425 return port;
1426}
1427
1428void
1429zfcp_port_dequeue(struct zfcp_port *port)
1430{
1431 zfcp_port_wait(port);
1432 write_lock_irq(&zfcp_data.config_lock);
1433 list_del(&port->list);
1434 port->adapter->ports--;
1435 write_unlock_irq(&zfcp_data.config_lock);
1436 zfcp_adapter_put(port->adapter);
1437 zfcp_sysfs_port_remove_files(&port->sysfs_device,
1438 atomic_read(&port->status));
1439 device_unregister(&port->sysfs_device);
1440}
1441
1442/* Enqueues a nameserver port */
1443int
1444zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1445{
1446 struct zfcp_port *port;
1447
1448 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
1449 ZFCP_DID_DIRECTORY_SERVICE);
1450 if (!port) {
1451 ZFCP_LOG_INFO("error: enqueue of nameserver port for "
1452 "adapter %s failed\n",
1453 zfcp_get_busid_by_adapter(adapter));
1454 return -ENXIO;
1455 }
1456 zfcp_port_put(port);
1457
1458 return 0;
1459}
1460
1461#undef ZFCP_LOG_AREA
1462
1463/****************************************************************/
1464/******* Fibre Channel Standard related Functions **************/
1465/****************************************************************/
1466
1467#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1468
1469void
1470zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1471 struct fsf_status_read_buffer *status_buffer)
1472{
1473 struct fcp_rscn_head *fcp_rscn_head;
1474 struct fcp_rscn_element *fcp_rscn_element;
1475 struct zfcp_port *port;
1476 u16 i;
1477 u16 no_entries;
1478 u32 range_mask;
1479 unsigned long flags;
1480
1481 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
1482 fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
1483
1484 /* see FC-FS */
1485 no_entries = (fcp_rscn_head->payload_len / 4);
1486
1487 zfcp_in_els_dbf_event(adapter, "##rscn", status_buffer,
1488 fcp_rscn_head->payload_len);
1489
1490 debug_text_event(adapter->erp_dbf, 1, "unsol_els_rscn:");
1491 for (i = 1; i < no_entries; i++) {
1492 /* skip head and start with 1st element */
1493 fcp_rscn_element++;
1494 switch (fcp_rscn_element->addr_format) {
1495 case ZFCP_PORT_ADDRESS:
1496 ZFCP_LOG_FLAGS(1, "ZFCP_PORT_ADDRESS\n");
1497 range_mask = ZFCP_PORTS_RANGE_PORT;
1498 break;
1499 case ZFCP_AREA_ADDRESS:
1500 ZFCP_LOG_FLAGS(1, "ZFCP_AREA_ADDRESS\n");
1501 range_mask = ZFCP_PORTS_RANGE_AREA;
1502 break;
1503 case ZFCP_DOMAIN_ADDRESS:
1504 ZFCP_LOG_FLAGS(1, "ZFCP_DOMAIN_ADDRESS\n");
1505 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
1506 break;
1507 case ZFCP_FABRIC_ADDRESS:
1508 ZFCP_LOG_FLAGS(1, "ZFCP_FABRIC_ADDRESS\n");
1509 range_mask = ZFCP_PORTS_RANGE_FABRIC;
1510 break;
1511 default:
1512 ZFCP_LOG_INFO("incoming RSCN with unknown "
1513 "address format\n");
1514 continue;
1515 }
1516 read_lock_irqsave(&zfcp_data.config_lock, flags);
1517 list_for_each_entry(port, &adapter->port_list_head, list) {
1518 if (atomic_test_mask
1519 (ZFCP_STATUS_PORT_WKA, &port->status))
1520 continue;
1521 /* Do we know this port? If not skip it. */
1522 if (!atomic_test_mask
1523 (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1524 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1525 "port 0x%016Lx\n", port->wwpn);
1526 debug_text_event(adapter->erp_dbf, 1,
1527 "unsol_els_rscnu:");
1528 zfcp_erp_port_reopen(port,
1529 ZFCP_STATUS_COMMON_ERP_FAILED);
1530 continue;
1531 }
1532
1533 /*
1534 * FIXME: race: d_id might being invalidated
1535 * (...DID_DID reset)
1536 */
1537 if ((port->d_id & range_mask)
1538 == (fcp_rscn_element->nport_did & range_mask)) {
1539 ZFCP_LOG_TRACE("reopen did 0x%08x\n",
1540 fcp_rscn_element->nport_did);
1541 /*
1542 * Unfortunately, an RSCN does not specify the
1543 * type of change a target underwent. We assume
1544 * that it makes sense to reopen the link.
1545 * FIXME: Shall we try to find out more about
1546 * the target and link state before closing it?
1547 * How to accomplish this? (nameserver?)
1548 * Where would such code be put in?
1549 * (inside or outside erp)
1550 */
1551 ZFCP_LOG_INFO("incoming RSCN, trying to open "
1552 "port 0x%016Lx\n", port->wwpn);
1553 debug_text_event(adapter->erp_dbf, 1,
1554 "unsol_els_rscnk:");
1555 zfcp_test_link(port);
1556 }
1557 }
1558 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1559 }
1560}
1561
1562static void
1563zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1564 struct fsf_status_read_buffer *status_buffer)
1565{
1566 logi *els_logi = (logi *) status_buffer->payload;
1567 struct zfcp_port *port;
1568 unsigned long flags;
1569
1570 zfcp_in_els_dbf_event(adapter, "##plogi", status_buffer, 28);
1571
1572 read_lock_irqsave(&zfcp_data.config_lock, flags);
1573 list_for_each_entry(port, &adapter->port_list_head, list) {
1574 if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
1575 break;
1576 }
1577 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1578
1579 if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
1580 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1581 "with d_id 0x%08x on adapter %s\n",
1582 status_buffer->d_id,
1583 zfcp_get_busid_by_adapter(adapter));
1584 } else {
1585 debug_text_event(adapter->erp_dbf, 1, "unsol_els_plogi:");
1586 debug_event(adapter->erp_dbf, 1, &els_logi->nport_wwn, 8);
1587 zfcp_erp_port_forced_reopen(port, 0);
1588 }
1589}
1590
1591static void
1592zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1593 struct fsf_status_read_buffer *status_buffer)
1594{
1595 struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
1596 struct zfcp_port *port;
1597 unsigned long flags;
1598
1599 zfcp_in_els_dbf_event(adapter, "##logo", status_buffer, 16);
1600
1601 read_lock_irqsave(&zfcp_data.config_lock, flags);
1602 list_for_each_entry(port, &adapter->port_list_head, list) {
1603 if (port->wwpn == els_logo->nport_wwpn)
1604 break;
1605 }
1606 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1607
1608 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1609 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1610 "with d_id 0x%08x on adapter %s\n",
1611 status_buffer->d_id,
1612 zfcp_get_busid_by_adapter(adapter));
1613 } else {
1614 debug_text_event(adapter->erp_dbf, 1, "unsol_els_logo:");
1615 debug_event(adapter->erp_dbf, 1, &els_logo->nport_wwpn, 8);
1616 zfcp_erp_port_forced_reopen(port, 0);
1617 }
1618}
1619
1620static void
1621zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
1622 struct fsf_status_read_buffer *status_buffer)
1623{
1624 zfcp_in_els_dbf_event(adapter, "##undef", status_buffer, 24);
1625 ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
1626 "for adapter %s\n", *(u32 *) (status_buffer->payload),
1627 zfcp_get_busid_by_adapter(adapter));
1628
1629}
1630
1631void
1632zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
1633{
1634 struct fsf_status_read_buffer *status_buffer;
1635 u32 els_type;
1636 struct zfcp_adapter *adapter;
1637
1638 status_buffer = fsf_req->data.status_read.buffer;
1639 els_type = *(u32 *) (status_buffer->payload);
1640 adapter = fsf_req->adapter;
1641
1642 if (els_type == LS_PLOGI)
1643 zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
1644 else if (els_type == LS_LOGO)
1645 zfcp_fsf_incoming_els_logo(adapter, status_buffer);
1646 else if ((els_type & 0xffff0000) == LS_RSCN)
1647 /* we are only concerned with the command, not the length */
1648 zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
1649 else
1650 zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
1651}
1652
1653
1654/**
1655 * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
1656 * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
1657 * @pool: pointer to mempool_t if non-null memory pool is used for allocation
1658 */
1659static int
1660zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
1661{
1662 struct zfcp_gid_pn_data *data;
1663
1664 if (pool != NULL) {
1665 data = mempool_alloc(pool, GFP_ATOMIC);
1666 if (likely(data != NULL)) {
1667 data->ct.pool = pool;
1668 }
1669 } else {
1670 data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
1671 }
1672
1673 if (NULL == data)
1674 return -ENOMEM;
1675
1676 memset(data, 0, sizeof(*data));
1677 data->ct.req = &data->req;
1678 data->ct.resp = &data->resp;
1679 data->ct.req_count = data->ct.resp_count = 1;
1680 zfcp_address_to_sg(&data->ct_iu_req, &data->req);
1681 zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
1682 data->req.length = sizeof(struct ct_iu_gid_pn_req);
1683 data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
1684
1685 *gid_pn = data;
1686 return 0;
1687}
1688
1689/**
1690 * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
1691 * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
1692 */
1693static void
1694zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
1695{
1696 if ((gid_pn->ct.pool != 0))
1697 mempool_free(gid_pn, gid_pn->ct.pool);
1698 else
1699 kfree(gid_pn);
1700
1701 return;
1702}
1703
1704/**
1705 * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
1706 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
1707 */
1708int
1709zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
1710{
1711 int ret;
1712 struct ct_iu_gid_pn_req *ct_iu_req;
1713 struct zfcp_gid_pn_data *gid_pn;
1714 struct zfcp_adapter *adapter = erp_action->adapter;
1715
1716 ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
1717 if (ret < 0) {
1718 ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
1719 "request failed for adapter %s\n",
1720 zfcp_get_busid_by_adapter(adapter));
1721 goto out;
1722 }
1723
1724 /* setup nameserver request */
1725 ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
1726 ct_iu_req->header.revision = ZFCP_CT_REVISION;
1727 ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
1728 ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
1729 ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
1730 ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
1731 ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
1732 ct_iu_req->wwpn = erp_action->port->wwpn;
1733
1734 /* setup parameters for send generic command */
1735 gid_pn->ct.port = adapter->nameserver_port;
1736 gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
1737 gid_pn->ct.handler_data = (unsigned long) gid_pn;
1738 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
1739 gid_pn->ct.timer = &erp_action->timer;
1740 gid_pn->port = erp_action->port;
1741
1742 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
1743 erp_action);
1744 if (ret) {
1745 ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
1746 "failed for adapter %s\n",
1747 zfcp_get_busid_by_adapter(adapter));
1748
1749 zfcp_gid_pn_buffers_free(gid_pn);
1750 }
1751
1752 out:
1753 return ret;
1754}
1755
1756/**
1757 * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
1758 * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
1759 */
1760static void zfcp_ns_gid_pn_handler(unsigned long data)
1761{
1762 struct zfcp_port *port;
1763 struct zfcp_send_ct *ct;
1764 struct ct_iu_gid_pn_req *ct_iu_req;
1765 struct ct_iu_gid_pn_resp *ct_iu_resp;
1766 struct zfcp_gid_pn_data *gid_pn;
1767
1768
1769 gid_pn = (struct zfcp_gid_pn_data *) data;
1770 port = gid_pn->port;
1771 ct = &gid_pn->ct;
1772 ct_iu_req = zfcp_sg_to_address(ct->req);
1773 ct_iu_resp = zfcp_sg_to_address(ct->resp);
1774
1775 if ((ct->status != 0) || zfcp_check_ct_response(&ct_iu_resp->header)) {
1776 /* FIXME: do we need some specific erp entry points */
1777 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
1778 goto failed;
1779 }
1780 /* paranoia */
1781 if (ct_iu_req->wwpn != port->wwpn) {
1782 ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
1783 "lookup does not match expected wwpn 0x%016Lx "
1784 "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
1785 zfcp_get_busid_by_port(port));
1786 goto mismatch;
1787 }
1788
1789 /* looks like a valid d_id */
1790 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1791 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1792 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
1793 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1794 goto out;
1795
1796 mismatch:
1797 ZFCP_LOG_DEBUG("CT IUs do not match:\n");
1798 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
1799 sizeof(struct ct_iu_gid_pn_req));
1800 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
1801 sizeof(struct ct_iu_gid_pn_resp));
1802
1803 failed:
1804 ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
1805 "0x%016Lx for adapter %s\n",
1806 port->wwpn, zfcp_get_busid_by_port(port));
1807 out:
1808 zfcp_gid_pn_buffers_free(gid_pn);
1809 return;
1810}
1811
1812/* reject CT_IU reason codes acc. to FC-GS-4 */
1813static const struct zfcp_rc_entry zfcp_ct_rc[] = {
1814 {0x01, "invalid command code"},
1815 {0x02, "invalid version level"},
1816 {0x03, "logical error"},
1817 {0x04, "invalid CT_IU size"},
1818 {0x05, "logical busy"},
1819 {0x07, "protocol error"},
1820 {0x09, "unable to perform command request"},
1821 {0x0b, "command not supported"},
1822 {0x0d, "server not available"},
1823 {0x0e, "session could not be established"},
1824 {0xff, "vendor specific error"},
1825 {0, NULL},
1826};
1827
1828/* LS_RJT reason codes acc. to FC-FS */
1829static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = {
1830 {0x01, "invalid LS_Command code"},
1831 {0x03, "logical error"},
1832 {0x05, "logical busy"},
1833 {0x07, "protocol error"},
1834 {0x09, "unable to perform command request"},
1835 {0x0b, "command not supported"},
1836 {0x0e, "command already in progress"},
1837 {0xff, "vendor specific error"},
1838 {0, NULL},
1839};
1840
1841/* reject reason codes according to FC-PH/FC-FS */
1842static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = {
1843 {0x01, "invalid D_ID"},
1844 {0x02, "invalid S_ID"},
1845 {0x03, "Nx_Port not available, temporary"},
1846 {0x04, "Nx_Port not available, permament"},
1847 {0x05, "class not supported"},
1848 {0x06, "delimiter usage error"},
1849 {0x07, "TYPE not supported"},
1850 {0x08, "invalid Link_Control"},
1851 {0x09, "invalid R_CTL field"},
1852 {0x0a, "invalid F_CTL field"},
1853 {0x0b, "invalid OX_ID"},
1854 {0x0c, "invalid RX_ID"},
1855 {0x0d, "invalid SEQ_ID"},
1856 {0x0e, "invalid DF_CTL"},
1857 {0x0f, "invalid SEQ_CNT"},
1858 {0x10, "invalid parameter field"},
1859 {0x11, "exchange error"},
1860 {0x12, "protocol error"},
1861 {0x13, "incorrect length"},
1862 {0x14, "unsupported ACK"},
1863 {0x15, "class of service not supported by entity at FFFFFE"},
1864 {0x16, "login required"},
1865 {0x17, "excessive sequences attempted"},
1866 {0x18, "unable to establish exchange"},
1867 {0x1a, "fabric path not available"},
1868 {0x1b, "invalid VC_ID (class 4)"},
1869 {0x1c, "invalid CS_CTL field"},
1870 {0x1d, "insufficient resources for VC (class 4)"},
1871 {0x1f, "invalid class of service"},
1872 {0x20, "preemption request rejected"},
1873 {0x21, "preemption not enabled"},
1874 {0x22, "multicast error"},
1875 {0x23, "multicast error terminate"},
1876 {0x24, "process login required"},
1877 {0xff, "vendor specific reject"},
1878 {0, NULL},
1879};
1880
1881/**
1882 * zfcp_rc_description - return description for given reaon code
1883 * @code: reason code
1884 * @rc_table: table of reason codes and descriptions
1885 */
1886static inline const char *
1887zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table)
1888{
1889 const char *descr = "unknown reason code";
1890
1891 do {
1892 if (code == rc_table->code) {
1893 descr = rc_table->description;
1894 break;
1895 }
1896 rc_table++;
1897 } while (rc_table->code && rc_table->description);
1898
1899 return descr;
1900}
1901
1902/**
1903 * zfcp_check_ct_response - evaluate reason code for CT_IU
1904 * @rjt: response payload to an CT_IU request
1905 * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
1906 */
1907int
1908zfcp_check_ct_response(struct ct_hdr *rjt)
1909{
1910 if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT)
1911 return 0;
1912
1913 if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) {
1914 ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
1915 "response code (0x%04hx)\n",
1916 rjt->cmd_rsp_code);
1917 return 1;
1918 }
1919
1920 ZFCP_LOG_INFO("Generic Service command rejected\n");
1921 ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
1922 zfcp_rc_description(rjt->reason_code, zfcp_ct_rc),
1923 (u32) rjt->reason_code, (u32) rjt->reason_code_expl,
1924 (u32) rjt->vendor_unique);
1925
1926 return 1;
1927}
1928
1929/**
1930 * zfcp_print_els_rjt - print reject parameter and description for ELS reject
1931 * @rjt_par: reject parameter acc. to FC-PH/FC-FS
1932 * @rc_table: table of reason codes and descriptions
1933 */
1934static inline void
1935zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par,
1936 const struct zfcp_rc_entry *rc_table)
1937{
1938 ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
1939 zfcp_rc_description(rjt_par->reason_code, rc_table),
1940 (u32) rjt_par->action, (u32) rjt_par->reason_code,
1941 (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique);
1942}
1943
1944/**
1945 * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
1946 * @sq: status qualifier word
1947 * @rjt_par: reject parameter as described in FC-PH and FC-FS
1948 * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
1949 */
1950int
1951zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par)
1952{
1953 int ret = -EIO;
1954
1955 if (sq == FSF_IOSTAT_NPORT_RJT) {
1956 ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
1957 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1958 /* invalid d_id */
1959 if (rjt_par->reason_code == 0x01)
1960 ret = -EREMCHG;
1961 } else if (sq == FSF_IOSTAT_FABRIC_RJT) {
1962 ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
1963 zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
1964 /* invalid d_id */
1965 if (rjt_par->reason_code == 0x01)
1966 ret = -EREMCHG;
1967 } else if (sq == FSF_IOSTAT_LS_RJT) {
1968 ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
1969 zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc);
1970 ret = -EREMOTEIO;
1971 } else
1972 ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq);
1973
1974 return ret;
1975}
1976
1977#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
new file mode 100644
index 000000000000..0fc46381fc22
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -0,0 +1,312 @@
1/*
2 * linux/drivers/s390/scsi/zfcp_ccw.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * CCW driver related routines
7 *
8 * (C) Copyright IBM Corp. 2003, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#define ZFCP_CCW_C_REVISION "$Revision: 1.58 $"
31
32#include "zfcp_ext.h"
33
34#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
35
36static int zfcp_ccw_probe(struct ccw_device *);
37static void zfcp_ccw_remove(struct ccw_device *);
38static int zfcp_ccw_set_online(struct ccw_device *);
39static int zfcp_ccw_set_offline(struct ccw_device *);
40static int zfcp_ccw_notify(struct ccw_device *, int);
41static void zfcp_ccw_shutdown(struct device *);
42
43static struct ccw_device_id zfcp_ccw_device_id[] = {
44 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
45 ZFCP_CONTROL_UNIT_MODEL,
46 ZFCP_DEVICE_TYPE,
47 ZFCP_DEVICE_MODEL)},
48 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
49 ZFCP_CONTROL_UNIT_MODEL,
50 ZFCP_DEVICE_TYPE,
51 ZFCP_DEVICE_MODEL_PRIV)},
52 {},
53};
54
55static struct ccw_driver zfcp_ccw_driver = {
56 .owner = THIS_MODULE,
57 .name = ZFCP_NAME,
58 .ids = zfcp_ccw_device_id,
59 .probe = zfcp_ccw_probe,
60 .remove = zfcp_ccw_remove,
61 .set_online = zfcp_ccw_set_online,
62 .set_offline = zfcp_ccw_set_offline,
63 .notify = zfcp_ccw_notify,
64 .driver = {
65 .shutdown = zfcp_ccw_shutdown,
66 },
67};
68
69MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
70
71/**
72 * zfcp_ccw_probe - probe function of zfcp driver
73 * @ccw_device: pointer to belonging ccw device
74 *
75 * This function gets called by the common i/o layer and sets up the initial
76 * data structures for each fcp adapter, which was detected by the system.
77 * Also the sysfs files for this adapter will be created by this function.
78 * In addition the nameserver port will be added to the ports of the adapter
79 * and its sysfs representation will be created too.
80 */
81static int
82zfcp_ccw_probe(struct ccw_device *ccw_device)
83{
84 struct zfcp_adapter *adapter;
85 int retval = 0;
86
87 down(&zfcp_data.config_sema);
88 adapter = zfcp_adapter_enqueue(ccw_device);
89 if (!adapter)
90 retval = -EINVAL;
91 else
92 ZFCP_LOG_DEBUG("Probed adapter %s\n",
93 zfcp_get_busid_by_adapter(adapter));
94 up(&zfcp_data.config_sema);
95 return retval;
96}
97
98/**
99 * zfcp_ccw_remove - remove function of zfcp driver
100 * @ccw_device: pointer to belonging ccw device
101 *
102 * This function gets called by the common i/o layer and removes an adapter
103 * from the system. Task of this function is to get rid of all units and
104 * ports that belong to this adapter. And in addition all resources of this
105 * adapter will be freed too.
106 */
107static void
108zfcp_ccw_remove(struct ccw_device *ccw_device)
109{
110 struct zfcp_adapter *adapter;
111 struct zfcp_port *port, *p;
112 struct zfcp_unit *unit, *u;
113
114 ccw_device_set_offline(ccw_device);
115 down(&zfcp_data.config_sema);
116 adapter = dev_get_drvdata(&ccw_device->dev);
117
118 ZFCP_LOG_DEBUG("Removing adapter %s\n",
119 zfcp_get_busid_by_adapter(adapter));
120 write_lock_irq(&zfcp_data.config_lock);
121 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
122 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
123 list_move(&unit->list, &port->unit_remove_lh);
124 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
125 &unit->status);
126 }
127 list_move(&port->list, &adapter->port_remove_lh);
128 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
129 }
130 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
131 write_unlock_irq(&zfcp_data.config_lock);
132
133 list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
134 list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
135 zfcp_unit_dequeue(unit);
136 }
137 zfcp_port_dequeue(port);
138 }
139 zfcp_adapter_wait(adapter);
140 zfcp_adapter_dequeue(adapter);
141
142 up(&zfcp_data.config_sema);
143}
144
145/**
146 * zfcp_ccw_set_online - set_online function of zfcp driver
147 * @ccw_device: pointer to belonging ccw device
148 *
149 * This function gets called by the common i/o layer and sets an adapter
150 * into state online. Setting an fcp device online means that it will be
151 * registered with the SCSI stack, that the QDIO queues will be set up
152 * and that the adapter will be opened (asynchronously).
153 */
154static int
155zfcp_ccw_set_online(struct ccw_device *ccw_device)
156{
157 struct zfcp_adapter *adapter;
158 int retval;
159
160 down(&zfcp_data.config_sema);
161 adapter = dev_get_drvdata(&ccw_device->dev);
162
163 retval = zfcp_adapter_debug_register(adapter);
164 if (retval)
165 goto out;
166 retval = zfcp_erp_thread_setup(adapter);
167 if (retval) {
168 ZFCP_LOG_INFO("error: start of error recovery thread for "
169 "adapter %s failed\n",
170 zfcp_get_busid_by_adapter(adapter));
171 goto out_erp_thread;
172 }
173
174 retval = zfcp_adapter_scsi_register(adapter);
175 if (retval)
176 goto out_scsi_register;
177 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
178 ZFCP_SET);
179 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
180 zfcp_erp_wait(adapter);
181 goto out;
182
183 out_scsi_register:
184 zfcp_erp_thread_kill(adapter);
185 out_erp_thread:
186 zfcp_adapter_debug_unregister(adapter);
187 out:
188 up(&zfcp_data.config_sema);
189 return retval;
190}
191
192/**
193 * zfcp_ccw_set_offline - set_offline function of zfcp driver
194 * @ccw_device: pointer to belonging ccw device
195 *
196 * This function gets called by the common i/o layer and sets an adapter
197 * into state offline. Setting an fcp device offline means that it will be
198 * unregistered from the SCSI stack and that the adapter will be shut down
199 * asynchronously.
200 */
201static int
202zfcp_ccw_set_offline(struct ccw_device *ccw_device)
203{
204 struct zfcp_adapter *adapter;
205
206 down(&zfcp_data.config_sema);
207 adapter = dev_get_drvdata(&ccw_device->dev);
208 zfcp_erp_adapter_shutdown(adapter, 0);
209 zfcp_erp_wait(adapter);
210 zfcp_adapter_scsi_unregister(adapter);
211 zfcp_erp_thread_kill(adapter);
212 zfcp_adapter_debug_unregister(adapter);
213 up(&zfcp_data.config_sema);
214 return 0;
215}
216
217/**
218 * zfcp_ccw_notify
219 * @ccw_device: pointer to belonging ccw device
220 * @event: indicates if adapter was detached or attached
221 *
222 * This function gets called by the common i/o layer if an adapter has gone
223 * or reappeared.
224 */
225static int
226zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
227{
228 struct zfcp_adapter *adapter;
229
230 down(&zfcp_data.config_sema);
231 adapter = dev_get_drvdata(&ccw_device->dev);
232 switch (event) {
233 case CIO_GONE:
234 ZFCP_LOG_NORMAL("adapter %s: device gone\n",
235 zfcp_get_busid_by_adapter(adapter));
236 debug_text_event(adapter->erp_dbf,1,"dev_gone");
237 zfcp_erp_adapter_shutdown(adapter, 0);
238 break;
239 case CIO_NO_PATH:
240 ZFCP_LOG_NORMAL("adapter %s: no path\n",
241 zfcp_get_busid_by_adapter(adapter));
242 debug_text_event(adapter->erp_dbf,1,"no_path");
243 zfcp_erp_adapter_shutdown(adapter, 0);
244 break;
245 case CIO_OPER:
246 ZFCP_LOG_NORMAL("adapter %s: operational again\n",
247 zfcp_get_busid_by_adapter(adapter));
248 debug_text_event(adapter->erp_dbf,1,"dev_oper");
249 zfcp_erp_modify_adapter_status(adapter,
250 ZFCP_STATUS_COMMON_RUNNING,
251 ZFCP_SET);
252 zfcp_erp_adapter_reopen(adapter,
253 ZFCP_STATUS_COMMON_ERP_FAILED);
254 break;
255 }
256 zfcp_erp_wait(adapter);
257 up(&zfcp_data.config_sema);
258 return 1;
259}
260
261/**
262 * zfcp_ccw_register - ccw register function
263 *
264 * Registers the driver at the common i/o layer. This function will be called
265 * at module load time/system start.
266 */
267int __init
268zfcp_ccw_register(void)
269{
270 int retval;
271
272 retval = ccw_driver_register(&zfcp_ccw_driver);
273 if (retval)
274 goto out;
275 retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
276 if (retval)
277 ccw_driver_unregister(&zfcp_ccw_driver);
278 out:
279 return retval;
280}
281
282/**
283 * zfcp_ccw_unregister - ccw unregister function
284 *
285 * Unregisters the driver from common i/o layer. Function will be called at
286 * module unload/system shutdown.
287 */
288void __exit
289zfcp_ccw_unregister(void)
290{
291 zfcp_sysfs_driver_remove_files(&zfcp_ccw_driver.driver);
292 ccw_driver_unregister(&zfcp_ccw_driver);
293}
294
295/**
296 * zfcp_ccw_shutdown - gets called on reboot/shutdown
297 *
298 * Makes sure that QDIO queues are down when the system gets stopped.
299 */
300static void
301zfcp_ccw_shutdown(struct device *dev)
302{
303 struct zfcp_adapter *adapter;
304
305 down(&zfcp_data.config_sema);
306 adapter = dev_get_drvdata(dev);
307 zfcp_erp_adapter_shutdown(adapter, 0);
308 zfcp_erp_wait(adapter);
309 up(&zfcp_data.config_sema);
310}
311
312#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
new file mode 100644
index 000000000000..53fcccbb424c
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -0,0 +1,1121 @@
1/*
2 *
3 * linux/drivers/s390/scsi/zfcp_def.h
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 * Volker Sameske <sameske@de.ibm.com>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33
34#ifndef ZFCP_DEF_H
35#define ZFCP_DEF_H
36
37#define ZFCP_DEF_REVISION "$Revision: 1.111 $"
38
39/*************************** INCLUDES *****************************************/
40
41#include <linux/init.h>
42#include <linux/moduleparam.h>
43#include <linux/miscdevice.h>
44#include <linux/major.h>
45#include <linux/blkdev.h>
46#include <linux/delay.h>
47#include <linux/timer.h>
48#include <scsi/scsi.h>
49#include <scsi/scsi_tcq.h>
50#include <scsi/scsi_cmnd.h>
51#include <scsi/scsi_device.h>
52#include <scsi/scsi_host.h>
53#include <scsi/scsi_transport.h>
54#include <scsi/scsi_transport_fc.h>
55#include "../../fc4/fc.h"
56#include "zfcp_fsf.h"
57#include <asm/ccwdev.h>
58#include <asm/qdio.h>
59#include <asm/debug.h>
60#include <asm/ebcdic.h>
61#include <linux/mempool.h>
62#include <linux/syscalls.h>
63#include <linux/ioctl.h>
64#include <linux/ioctl32.h>
65
66/************************ DEBUG FLAGS *****************************************/
67
68#define ZFCP_PRINT_FLAGS
69
70/********************* GENERAL DEFINES *********************************/
71
72/* zfcp version number, it consists of major, minor, and patch-level number */
73#define ZFCP_VERSION "4.2.0"
74
75/**
76 * zfcp_sg_to_address - determine kernel address from struct scatterlist
77 * @list: struct scatterlist
78 * Return: kernel address
79 */
80static inline void *
81zfcp_sg_to_address(struct scatterlist *list)
82{
83 return (void *) (page_address(list->page) + list->offset);
84}
85
86/**
87 * zfcp_address_to_sg - set up struct scatterlist from kernel address
88 * @address: kernel address
89 * @list: struct scatterlist
90 */
91static inline void
92zfcp_address_to_sg(void *address, struct scatterlist *list)
93{
94 list->page = virt_to_page(address);
95 list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
96}
97
98/********************* SCSI SPECIFIC DEFINES *********************************/
99
100/* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
101typedef u32 scsi_id_t;
102typedef u32 scsi_lun_t;
103
104#define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
105#define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
106
107/********************* CIO/QDIO SPECIFIC DEFINES *****************************/
108
109/* Adapter Identification Parameters */
110#define ZFCP_CONTROL_UNIT_TYPE 0x1731
111#define ZFCP_CONTROL_UNIT_MODEL 0x03
112#define ZFCP_DEVICE_TYPE 0x1732
113#define ZFCP_DEVICE_MODEL 0x03
114#define ZFCP_DEVICE_MODEL_PRIV 0x04
115
116/* allow as many chained SBALs as are supported by hardware */
117#define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
118#define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
119#define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
120
121/* DMQ bug workaround: don't use last SBALE */
122#define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
123
124/* index of last SBALE (with respect to DMQ bug workaround) */
125#define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
126
127/* max. number of (data buffer) SBALEs in largest SBAL chain */
128#define ZFCP_MAX_SBALES_PER_REQ \
129 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
130 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
131
132/* FIXME(tune): free space should be one max. SBAL chain plus what? */
133#define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
134 - (ZFCP_MAX_SBALS_PER_REQ + 4))
135
136#define ZFCP_SBAL_TIMEOUT (5*HZ)
137
138#define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
139
140/* queue polling (values in microseconds) */
141#define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
142#define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
143#define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
144#define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
145
146#define QDIO_SCSI_QFMT 1 /* 1 for FSF */
147
148/********************* FSF SPECIFIC DEFINES *********************************/
149
150#define ZFCP_ULP_INFO_VERSION 26
151#define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
152/* ATTENTION: value must not be used by hardware */
153#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
154#define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
155#define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
156#define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 6
157#define ZFCP_EXCHANGE_CONFIG_DATA_SLEEP 50
158
159/* timeout value for "default timer" for fsf requests */
160#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ);
161
162/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
163
164typedef unsigned long long wwn_t;
165typedef unsigned int fc_id_t;
166typedef unsigned long long fcp_lun_t;
167/* data length field may be at variable position in FCP-2 FCP_CMND IU */
168typedef unsigned int fcp_dl_t;
169
170#define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
171
172/* timeout for name-server lookup (in seconds) */
173#define ZFCP_NS_GID_PN_TIMEOUT 10
174
175/* largest SCSI command we can process */
176/* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
177#define ZFCP_MAX_SCSI_CMND_LENGTH 255
178/* maximum number of commands in LUN queue (tagged queueing) */
179#define ZFCP_CMND_PER_LUN 32
180
181/* task attribute values in FCP-2 FCP_CMND IU */
182#define SIMPLE_Q 0
183#define HEAD_OF_Q 1
184#define ORDERED_Q 2
185#define ACA_Q 4
186#define UNTAGGED 5
187
188/* task management flags in FCP-2 FCP_CMND IU */
189#define FCP_CLEAR_ACA 0x40
190#define FCP_TARGET_RESET 0x20
191#define FCP_LOGICAL_UNIT_RESET 0x10
192#define FCP_CLEAR_TASK_SET 0x04
193#define FCP_ABORT_TASK_SET 0x02
194
195#define FCP_CDB_LENGTH 16
196
197#define ZFCP_DID_MASK 0x00FFFFFF
198
199/* FCP(-2) FCP_CMND IU */
200struct fcp_cmnd_iu {
201 fcp_lun_t fcp_lun; /* FCP logical unit number */
202 u8 crn; /* command reference number */
203 u8 reserved0:5; /* reserved */
204 u8 task_attribute:3; /* task attribute */
205 u8 task_management_flags; /* task management flags */
206 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
207 u8 rddata:1; /* read data */
208 u8 wddata:1; /* write data */
209 u8 fcp_cdb[FCP_CDB_LENGTH];
210} __attribute__((packed));
211
212/* FCP(-2) FCP_RSP IU */
213struct fcp_rsp_iu {
214 u8 reserved0[10];
215 union {
216 struct {
217 u8 reserved1:3;
218 u8 fcp_conf_req:1;
219 u8 fcp_resid_under:1;
220 u8 fcp_resid_over:1;
221 u8 fcp_sns_len_valid:1;
222 u8 fcp_rsp_len_valid:1;
223 } bits;
224 u8 value;
225 } validity;
226 u8 scsi_status;
227 u32 fcp_resid;
228 u32 fcp_sns_len;
229 u32 fcp_rsp_len;
230} __attribute__((packed));
231
232
233#define RSP_CODE_GOOD 0
234#define RSP_CODE_LENGTH_MISMATCH 1
235#define RSP_CODE_FIELD_INVALID 2
236#define RSP_CODE_RO_MISMATCH 3
237#define RSP_CODE_TASKMAN_UNSUPP 4
238#define RSP_CODE_TASKMAN_FAILED 5
239
240/* see fc-fs */
241#define LS_FAN 0x60000000
242#define LS_RSCN 0x61040000
243
244struct fcp_rscn_head {
245 u8 command;
246 u8 page_length; /* always 0x04 */
247 u16 payload_len;
248} __attribute__((packed));
249
250struct fcp_rscn_element {
251 u8 reserved:2;
252 u8 event_qual:4;
253 u8 addr_format:2;
254 u32 nport_did:24;
255} __attribute__((packed));
256
257#define ZFCP_PORT_ADDRESS 0x0
258#define ZFCP_AREA_ADDRESS 0x1
259#define ZFCP_DOMAIN_ADDRESS 0x2
260#define ZFCP_FABRIC_ADDRESS 0x3
261
262#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
263#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
264#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
265#define ZFCP_PORTS_RANGE_FABRIC 0x000000
266
267#define ZFCP_NO_PORTS_PER_AREA 0x100
268#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
269#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
270
271struct fcp_fan {
272 u32 command;
273 u32 fport_did;
274 wwn_t fport_wwpn;
275 wwn_t fport_wwname;
276} __attribute__((packed));
277
278/* see fc-ph */
279struct fcp_logo {
280 u32 command;
281 u32 nport_did;
282 wwn_t nport_wwpn;
283} __attribute__((packed));
284
285/*
286 * FC-FS stuff
287 */
288#define R_A_TOV 10 /* seconds */
289#define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
290
291#define ZFCP_LS_RLS 0x0f
292#define ZFCP_LS_ADISC 0x52
293#define ZFCP_LS_RPS 0x56
294#define ZFCP_LS_RSCN 0x61
295#define ZFCP_LS_RNID 0x78
296
297struct zfcp_ls_rjt_par {
298 u8 action;
299 u8 reason_code;
300 u8 reason_expl;
301 u8 vendor_unique;
302} __attribute__ ((packed));
303
304struct zfcp_ls_adisc {
305 u8 code;
306 u8 field[3];
307 u32 hard_nport_id;
308 u64 wwpn;
309 u64 wwnn;
310 u32 nport_id;
311} __attribute__ ((packed));
312
313struct zfcp_ls_adisc_acc {
314 u8 code;
315 u8 field[3];
316 u32 hard_nport_id;
317 u64 wwpn;
318 u64 wwnn;
319 u32 nport_id;
320} __attribute__ ((packed));
321
322struct zfcp_rc_entry {
323 u8 code;
324 const char *description;
325};
326
327/*
328 * FC-GS-2 stuff
329 */
330#define ZFCP_CT_REVISION 0x01
331#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
332#define ZFCP_CT_NAME_SERVER 0x02
333#define ZFCP_CT_SYNCHRONOUS 0x00
334#define ZFCP_CT_GID_PN 0x0121
335#define ZFCP_CT_MAX_SIZE 0x1020
336#define ZFCP_CT_ACCEPT 0x8002
337#define ZFCP_CT_REJECT 0x8001
338
339/*
340 * FC-GS-4 stuff
341 */
342#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
343
344
345/***************** S390 DEBUG FEATURE SPECIFIC DEFINES ***********************/
346
347/* debug feature entries per adapter */
348#define ZFCP_ERP_DBF_INDEX 1
349#define ZFCP_ERP_DBF_AREAS 2
350#define ZFCP_ERP_DBF_LENGTH 16
351#define ZFCP_ERP_DBF_LEVEL 3
352#define ZFCP_ERP_DBF_NAME "zfcperp"
353
354#define ZFCP_CMD_DBF_INDEX 2
355#define ZFCP_CMD_DBF_AREAS 1
356#define ZFCP_CMD_DBF_LENGTH 8
357#define ZFCP_CMD_DBF_LEVEL 3
358#define ZFCP_CMD_DBF_NAME "zfcpcmd"
359
360#define ZFCP_ABORT_DBF_INDEX 2
361#define ZFCP_ABORT_DBF_AREAS 1
362#define ZFCP_ABORT_DBF_LENGTH 8
363#define ZFCP_ABORT_DBF_LEVEL 6
364#define ZFCP_ABORT_DBF_NAME "zfcpabt"
365
366#define ZFCP_IN_ELS_DBF_INDEX 2
367#define ZFCP_IN_ELS_DBF_AREAS 1
368#define ZFCP_IN_ELS_DBF_LENGTH 8
369#define ZFCP_IN_ELS_DBF_LEVEL 6
370#define ZFCP_IN_ELS_DBF_NAME "zfcpels"
371
372/******************** LOGGING MACROS AND DEFINES *****************************/
373
374/*
375 * Logging may be applied on certain kinds of driver operations
376 * independently. Additionally, different log-levels are supported for
377 * each of these areas.
378 */
379
380#define ZFCP_NAME "zfcp"
381
382/* read-only LUN sharing switch initial value */
383#define ZFCP_RO_LUN_SHARING_DEFAULTS 0
384
385/* independent log areas */
386#define ZFCP_LOG_AREA_OTHER 0
387#define ZFCP_LOG_AREA_SCSI 1
388#define ZFCP_LOG_AREA_FSF 2
389#define ZFCP_LOG_AREA_CONFIG 3
390#define ZFCP_LOG_AREA_CIO 4
391#define ZFCP_LOG_AREA_QDIO 5
392#define ZFCP_LOG_AREA_ERP 6
393#define ZFCP_LOG_AREA_FC 7
394
395/* log level values*/
396#define ZFCP_LOG_LEVEL_NORMAL 0
397#define ZFCP_LOG_LEVEL_INFO 1
398#define ZFCP_LOG_LEVEL_DEBUG 2
399#define ZFCP_LOG_LEVEL_TRACE 3
400
401/*
402 * this allows removal of logging code by the preprocessor
403 * (the most detailed log level still to be compiled in is specified,
404 * higher log levels are removed)
405 */
406#define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
407
408/* get "loglevel" nibble assignment */
409#define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
410 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
411
412/* set "loglevel" nibble */
413#define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
414 (value << (zfcp_lognibble << 2))
415
416/* all log-level defaults are combined to generate initial log-level */
417#define ZFCP_LOG_LEVEL_DEFAULTS \
418 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
419 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
420 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
421 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
422 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
423 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
424 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
425 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
426
427/* check whether we have the right level for logging */
428#define ZFCP_LOG_CHECK(level) \
429 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
430
431/* logging routine for zfcp */
432#define _ZFCP_LOG(fmt, args...) \
433 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
434 __LINE__ , ##args)
435
436#define ZFCP_LOG(level, fmt, args...) \
437do { \
438 if (ZFCP_LOG_CHECK(level)) \
439 _ZFCP_LOG(fmt, ##args); \
440} while (0)
441
442#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
443# define ZFCP_LOG_NORMAL(fmt, args...)
444#else
445# define ZFCP_LOG_NORMAL(fmt, args...) \
446do { \
447 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
448 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
449} while (0)
450#endif
451
452#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
453# define ZFCP_LOG_INFO(fmt, args...)
454#else
455# define ZFCP_LOG_INFO(fmt, args...) \
456do { \
457 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
458 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
459} while (0)
460#endif
461
462#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
463# define ZFCP_LOG_DEBUG(fmt, args...)
464#else
465# define ZFCP_LOG_DEBUG(fmt, args...) \
466 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
467#endif
468
469#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
470# define ZFCP_LOG_TRACE(fmt, args...)
471#else
472# define ZFCP_LOG_TRACE(fmt, args...) \
473 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
474#endif
475
476#ifndef ZFCP_PRINT_FLAGS
477# define ZFCP_LOG_FLAGS(level, fmt, args...)
478#else
479extern u32 flags_dump;
480# define ZFCP_LOG_FLAGS(level, fmt, args...) \
481do { \
482 if (level <= flags_dump) \
483 _ZFCP_LOG(fmt, ##args); \
484} while (0)
485#endif
486
487/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
488
489/*
490 * Note, the leftmost status byte is common among adapter, port
491 * and unit
492 */
493#define ZFCP_COMMON_FLAGS 0xfff00000
494#define ZFCP_SPECIFIC_FLAGS 0x000fffff
495
496/* common status bits */
497#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
498#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
499#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
500#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
501#define ZFCP_STATUS_COMMON_OPENING 0x08000000
502#define ZFCP_STATUS_COMMON_OPEN 0x04000000
503#define ZFCP_STATUS_COMMON_CLOSING 0x02000000
504#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
505#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
506
507/* adapter status */
508#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
509#define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
510#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
511#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
512#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
513#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
514#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
515#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
516
517#define ZFCP_STATUS_ADAPTER_SCSI_UP \
518 (ZFCP_STATUS_COMMON_UNBLOCKED | \
519 ZFCP_STATUS_ADAPTER_REGISTERED)
520
521
522/* FC-PH/FC-GS well-known address identifiers for generic services */
523#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
524#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
525#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
526#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
527#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
528
529/* remote port status */
530#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
531#define ZFCP_STATUS_PORT_DID_DID 0x00000002
532#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
533#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
534#define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
535#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
536#define ZFCP_STATUS_PORT_ACCESS_DENIED 0x00000040
537
538/* for ports with well known addresses */
539#define ZFCP_STATUS_PORT_WKA \
540 (ZFCP_STATUS_PORT_NO_WWPN | \
541 ZFCP_STATUS_PORT_NO_SCSI_ID)
542
543/* logical unit status */
544#define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
545#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
546#define ZFCP_STATUS_UNIT_SHARED 0x00000004
547#define ZFCP_STATUS_UNIT_READONLY 0x00000008
548
549/* FSF request status (this does not have a common part) */
550#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
551#define ZFCP_STATUS_FSFREQ_POOL 0x00000001
552#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
553#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
554#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
555#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
556#define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
557#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
558#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
559#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
560#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
561#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
562#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
563#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
564
565/*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
566
567#define ZFCP_MAX_ERPS 3
568
569#define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
570#define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
571
572#define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
573#define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
574#define ZFCP_STATUS_ERP_DISMISSING 0x00100000
575#define ZFCP_STATUS_ERP_DISMISSED 0x00200000
576#define ZFCP_STATUS_ERP_LOWMEM 0x00400000
577
578#define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
579#define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
580#define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
581#define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
582#define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
583#define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
584#define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
585#define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
586#define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
587
588/* Ordered by escalation level (necessary for proper erp-code operation) */
589#define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
590#define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
591#define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
592#define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
593
594#define ZFCP_ERP_ACTION_RUNNING 0x1
595#define ZFCP_ERP_ACTION_READY 0x2
596
597#define ZFCP_ERP_SUCCEEDED 0x0
598#define ZFCP_ERP_FAILED 0x1
599#define ZFCP_ERP_CONTINUES 0x2
600#define ZFCP_ERP_EXIT 0x3
601#define ZFCP_ERP_DISMISSED 0x4
602#define ZFCP_ERP_NOMEM 0x5
603
604
605/******************** CFDC SPECIFIC STUFF *****************************/
606
607/* Firewall data channel sense data record */
608struct zfcp_cfdc_sense_data {
609 u32 signature; /* Request signature */
610 u32 devno; /* FCP adapter device number */
611 u32 command; /* Command code */
612 u32 fsf_status; /* FSF request status and status qualifier */
613 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
614 u8 payloads[256]; /* Access conflicts list */
615 u8 control_file[0]; /* Access control table */
616};
617
618#define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
619
620#define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
621#define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
622#define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
623#define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
624#define ZFCP_CFDC_CMND_UPLOAD 0x00010002
625
626#define ZFCP_CFDC_DOWNLOAD 0x00000001
627#define ZFCP_CFDC_UPLOAD 0x00000002
628#define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
629
630#define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
631#define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
632#define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
633
634#define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
635
636/************************* STRUCTURE DEFINITIONS *****************************/
637
638struct zfcp_fsf_req;
639
640/* holds various memory pools of an adapter */
641struct zfcp_adapter_mempool {
642 mempool_t *fsf_req_erp;
643 mempool_t *fsf_req_scsi;
644 mempool_t *fsf_req_abort;
645 mempool_t *fsf_req_status_read;
646 mempool_t *data_status_read;
647 mempool_t *data_gid_pn;
648};
649
650struct zfcp_exchange_config_data{
651};
652
653struct zfcp_open_port {
654 struct zfcp_port *port;
655};
656
657struct zfcp_close_port {
658 struct zfcp_port *port;
659};
660
661struct zfcp_open_unit {
662 struct zfcp_unit *unit;
663};
664
665struct zfcp_close_unit {
666 struct zfcp_unit *unit;
667};
668
669struct zfcp_close_physical_port {
670 struct zfcp_port *port;
671};
672
673struct zfcp_send_fcp_command_task {
674 struct zfcp_fsf_req *fsf_req;
675 struct zfcp_unit *unit;
676 struct scsi_cmnd *scsi_cmnd;
677 unsigned long start_jiffies;
678};
679
680struct zfcp_send_fcp_command_task_management {
681 struct zfcp_unit *unit;
682};
683
684struct zfcp_abort_fcp_command {
685 struct zfcp_fsf_req *fsf_req;
686 struct zfcp_unit *unit;
687};
688
689/*
690 * header for CT_IU
691 */
692struct ct_hdr {
693 u8 revision; // 0x01
694 u8 in_id[3]; // 0x00
695 u8 gs_type; // 0xFC Directory Service
696 u8 gs_subtype; // 0x02 Name Server
697 u8 options; // 0x00 single bidirectional exchange
698 u8 reserved0;
699 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
700 u16 max_res_size; // <= (4096 - 16) / 4
701 u8 reserved1;
702 u8 reason_code;
703 u8 reason_code_expl;
704 u8 vendor_unique;
705} __attribute__ ((packed));
706
707/* nameserver request CT_IU -- for requests where
708 * a port name is required */
709struct ct_iu_gid_pn_req {
710 struct ct_hdr header;
711 wwn_t wwpn;
712} __attribute__ ((packed));
713
714/* FS_ACC IU and data unit for GID_PN nameserver request */
715struct ct_iu_gid_pn_resp {
716 struct ct_hdr header;
717 fc_id_t d_id;
718} __attribute__ ((packed));
719
720typedef void (*zfcp_send_ct_handler_t)(unsigned long);
721
722/**
723 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
724 * @port: port where the request is sent to
725 * @req: scatter-gather list for request
726 * @resp: scatter-gather list for response
727 * @req_count: number of elements in request scatter-gather list
728 * @resp_count: number of elements in response scatter-gather list
729 * @handler: handler function (called for response to the request)
730 * @handler_data: data passed to handler function
731 * @pool: pointer to memory pool for ct request structure
732 * @timeout: FSF timeout for this request
733 * @timer: timer (e.g. for request initiated by erp)
734 * @completion: completion for synchronization purposes
735 * @status: used to pass error status to calling function
736 */
737struct zfcp_send_ct {
738 struct zfcp_port *port;
739 struct scatterlist *req;
740 struct scatterlist *resp;
741 unsigned int req_count;
742 unsigned int resp_count;
743 zfcp_send_ct_handler_t handler;
744 unsigned long handler_data;
745 mempool_t *pool;
746 int timeout;
747 struct timer_list *timer;
748 struct completion *completion;
749 int status;
750};
751
752/* used for name server requests in error recovery */
753struct zfcp_gid_pn_data {
754 struct zfcp_send_ct ct;
755 struct scatterlist req;
756 struct scatterlist resp;
757 struct ct_iu_gid_pn_req ct_iu_req;
758 struct ct_iu_gid_pn_resp ct_iu_resp;
759 struct zfcp_port *port;
760};
761
762typedef void (*zfcp_send_els_handler_t)(unsigned long);
763
764/**
765 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
766 * @adapter: adapter where request is sent from
767 * @d_id: destiniation id of port where request is sent to
768 * @req: scatter-gather list for request
769 * @resp: scatter-gather list for response
770 * @req_count: number of elements in request scatter-gather list
771 * @resp_count: number of elements in response scatter-gather list
772 * @handler: handler function (called for response to the request)
773 * @handler_data: data passed to handler function
774 * @timer: timer (e.g. for request initiated by erp)
775 * @completion: completion for synchronization purposes
776 * @ls_code: hex code of ELS command
777 * @status: used to pass error status to calling function
778 */
779struct zfcp_send_els {
780 struct zfcp_adapter *adapter;
781 fc_id_t d_id;
782 struct scatterlist *req;
783 struct scatterlist *resp;
784 unsigned int req_count;
785 unsigned int resp_count;
786 zfcp_send_els_handler_t handler;
787 unsigned long handler_data;
788 struct timer_list *timer;
789 struct completion *completion;
790 int ls_code;
791 int status;
792};
793
794struct zfcp_status_read {
795 struct fsf_status_read_buffer *buffer;
796};
797
798struct zfcp_fsf_done {
799 struct completion *complete;
800 int status;
801};
802
803/* request specific data */
804union zfcp_req_data {
805 struct zfcp_exchange_config_data exchange_config_data;
806 struct zfcp_open_port open_port;
807 struct zfcp_close_port close_port;
808 struct zfcp_open_unit open_unit;
809 struct zfcp_close_unit close_unit;
810 struct zfcp_close_physical_port close_physical_port;
811 struct zfcp_send_fcp_command_task send_fcp_command_task;
812 struct zfcp_send_fcp_command_task_management
813 send_fcp_command_task_management;
814 struct zfcp_abort_fcp_command abort_fcp_command;
815 struct zfcp_send_ct *send_ct;
816 struct zfcp_send_els *send_els;
817 struct zfcp_status_read status_read;
818 struct fsf_qtcb_bottom_port *port_data;
819};
820
821struct zfcp_qdio_queue {
822 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
823 u8 free_index; /* index of next free bfr
824 in queue (free_count>0) */
825 atomic_t free_count; /* number of free buffers
826 in queue */
827 rwlock_t queue_lock; /* lock for operations on queue */
828 int distance_from_int; /* SBALs used since PCI indication
829 was last set */
830};
831
832struct zfcp_erp_action {
833 struct list_head list;
834 int action; /* requested action code */
835 struct zfcp_adapter *adapter; /* device which should be recovered */
836 struct zfcp_port *port;
837 struct zfcp_unit *unit;
838 volatile u32 status; /* recovery status */
839 u32 step; /* active step of this erp action */
840 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
841 for this action */
842 struct timer_list timer;
843};
844
845
846struct zfcp_adapter {
847 struct list_head list; /* list of adapters */
848 atomic_t refcount; /* reference count */
849 wait_queue_head_t remove_wq; /* can be used to wait for
850 refcount drop to zero */
851 wwn_t wwnn; /* WWNN */
852 wwn_t wwpn; /* WWPN */
853 fc_id_t s_id; /* N_Port ID */
854 struct ccw_device *ccw_device; /* S/390 ccw device */
855 u8 fc_service_class;
856 u32 fc_topology; /* FC topology */
857 u32 fc_link_speed; /* FC interface speed */
858 u32 hydra_version; /* Hydra version */
859 u32 fsf_lic_version;
860 u32 supported_features;/* of FCP channel */
861 u32 hardware_version; /* of FCP channel */
862 u8 serial_number[32]; /* of hardware */
863 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
864 unsigned short scsi_host_no; /* Assigned host number */
865 unsigned char name[9];
866 struct list_head port_list_head; /* remote port list */
867 struct list_head port_remove_lh; /* head of ports to be
868 removed */
869 u32 ports; /* number of remote ports */
870 struct timer_list scsi_er_timer; /* SCSI err recovery watch */
871 struct list_head fsf_req_list_head; /* head of FSF req list */
872 rwlock_t fsf_req_list_lock; /* lock for ops on list of
873 FSF requests */
874 atomic_t fsf_reqs_active; /* # active FSF reqs */
875 struct zfcp_qdio_queue request_queue; /* request queue */
876 u32 fsf_req_seq_no; /* FSF cmnd seq number */
877 wait_queue_head_t request_wq; /* can be used to wait for
878 more avaliable SBALs */
879 struct zfcp_qdio_queue response_queue; /* response queue */
880 rwlock_t abort_lock; /* Protects against SCSI
881 stack abort/command
882 completion races */
883 u16 status_read_failed; /* # failed status reads */
884 atomic_t status; /* status of this adapter */
885 struct list_head erp_ready_head; /* error recovery for this
886 adapter/devices */
887 struct list_head erp_running_head;
888 rwlock_t erp_lock;
889 struct semaphore erp_ready_sem;
890 wait_queue_head_t erp_thread_wqh;
891 wait_queue_head_t erp_done_wqh;
892 struct zfcp_erp_action erp_action; /* pending error recovery */
893 atomic_t erp_counter;
894 u32 erp_total_count; /* total nr of enqueued erp
895 actions */
896 u32 erp_low_mem_count; /* nr of erp actions waiting
897 for memory */
898 struct zfcp_port *nameserver_port; /* adapter's nameserver */
899 debug_info_t *erp_dbf; /* S/390 debug features */
900 debug_info_t *abort_dbf;
901 debug_info_t *in_els_dbf;
902 debug_info_t *cmd_dbf;
903 spinlock_t dbf_lock;
904 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
905 struct qdio_initialize qdio_init_data; /* for qdio_establish */
906 struct device generic_services; /* directory for WKA ports */
907};
908
909/*
910 * the struct device sysfs_device must be at the beginning of this structure.
911 * pointer to struct device is used to free port structure in release function
912 * of the device. don't change!
913 */
914struct zfcp_port {
915 struct device sysfs_device; /* sysfs device */
916 struct list_head list; /* list of remote ports */
917 atomic_t refcount; /* reference count */
918 wait_queue_head_t remove_wq; /* can be used to wait for
919 refcount drop to zero */
920 struct zfcp_adapter *adapter; /* adapter used to access port */
921 struct list_head unit_list_head; /* head of logical unit list */
922 struct list_head unit_remove_lh; /* head of luns to be removed
923 list */
924 u32 units; /* # of logical units in list */
925 atomic_t status; /* status of this remote port */
926 scsi_id_t scsi_id; /* own SCSI ID */
927 wwn_t wwnn; /* WWNN if known */
928 wwn_t wwpn; /* WWPN */
929 fc_id_t d_id; /* D_ID */
930 u32 handle; /* handle assigned by FSF */
931 struct zfcp_erp_action erp_action; /* pending error recovery */
932 atomic_t erp_counter;
933};
934
935/* the struct device sysfs_device must be at the beginning of this structure.
936 * pointer to struct device is used to free unit structure in release function
937 * of the device. don't change!
938 */
939struct zfcp_unit {
940 struct device sysfs_device; /* sysfs device */
941 struct list_head list; /* list of logical units */
942 atomic_t refcount; /* reference count */
943 wait_queue_head_t remove_wq; /* can be used to wait for
944 refcount drop to zero */
945 struct zfcp_port *port; /* remote port of unit */
946 atomic_t status; /* status of this logical unit */
947 scsi_lun_t scsi_lun; /* own SCSI LUN */
948 fcp_lun_t fcp_lun; /* own FCP_LUN */
949 u32 handle; /* handle assigned by FSF */
950 struct scsi_device *device; /* scsi device struct pointer */
951 struct zfcp_erp_action erp_action; /* pending error recovery */
952 atomic_t erp_counter;
953};
954
955/* FSF request */
956struct zfcp_fsf_req {
957 struct list_head list; /* list of FSF requests */
958 struct zfcp_adapter *adapter; /* adapter request belongs to */
959 u8 sbal_number; /* nr of SBALs free for use */
960 u8 sbal_first; /* first SBAL for this request */
961 u8 sbal_last; /* last possible SBAL for
962 this reuest */
963 u8 sbal_curr; /* current SBAL during creation
964 of request */
965 u8 sbale_curr; /* current SBALE during creation
966 of request */
967 wait_queue_head_t completion_wq; /* can be used by a routine
968 to wait for completion */
969 volatile u32 status; /* status of this request */
970 u32 fsf_command; /* FSF Command copy */
971 struct fsf_qtcb *qtcb; /* address of associated QTCB */
972 u32 seq_no; /* Sequence number of request */
973 union zfcp_req_data data; /* Info fields of request */
974 struct zfcp_erp_action *erp_action; /* used if this request is
975 issued on behalf of erp */
976 mempool_t *pool; /* used if request was alloacted
977 from emergency pool */
978};
979
980typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
981
982/* driver data */
983struct zfcp_data {
984 struct scsi_host_template scsi_host_template;
985 atomic_t status; /* Module status flags */
986 struct list_head adapter_list_head; /* head of adapter list */
987 struct list_head adapter_remove_lh; /* head of adapters to be
988 removed */
989 rwlock_t status_read_lock; /* for status read thread */
990 struct list_head status_read_receive_head;
991 struct list_head status_read_send_head;
992 struct semaphore status_read_sema;
993 wait_queue_head_t status_read_thread_wqh;
994 u32 adapters; /* # of adapters in list */
995 rwlock_t config_lock; /* serialises changes
996 to adapter/port/unit
997 lists */
998 struct semaphore config_sema; /* serialises configuration
999 changes */
1000 atomic_t loglevel; /* current loglevel */
1001 char init_busid[BUS_ID_SIZE];
1002 wwn_t init_wwpn;
1003 fcp_lun_t init_fcp_lun;
1004 char *driver_version;
1005};
1006
1007/**
1008 * struct zfcp_sg_list - struct describing a scatter-gather list
1009 * @sg: pointer to array of (struct scatterlist)
1010 * @count: number of elements in scatter-gather list
1011 */
1012struct zfcp_sg_list {
1013 struct scatterlist *sg;
1014 unsigned int count;
1015};
1016
1017/* number of elements for various memory pools */
1018#define ZFCP_POOL_FSF_REQ_ERP_NR 1
1019#define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1020#define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1021#define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1022#define ZFCP_POOL_DATA_GID_PN_NR 1
1023
1024/* struct used by memory pools for fsf_requests */
1025struct zfcp_fsf_req_pool_element {
1026 struct zfcp_fsf_req fsf_req;
1027 struct fsf_qtcb qtcb;
1028};
1029
1030/********************** ZFCP SPECIFIC DEFINES ********************************/
1031
1032#define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
1033
1034#define ZFCP_KNOWN 0x00000001
1035#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1036#define ZFCP_WAIT_FOR_SBAL 0x00000004
1037#define ZFCP_REQ_NO_QTCB 0x00000008
1038
1039#define ZFCP_SET 0x00000100
1040#define ZFCP_CLEAR 0x00000200
1041
1042#define ZFCP_INTERRUPTIBLE 1
1043#define ZFCP_UNINTERRUPTIBLE 0
1044
1045#ifndef atomic_test_mask
1046#define atomic_test_mask(mask, target) \
1047 ((atomic_read(target) & mask) == mask)
1048#endif
1049
1050extern void _zfcp_hex_dump(char *, int);
1051#define ZFCP_HEX_DUMP(level, addr, count) \
1052 if (ZFCP_LOG_CHECK(level)) { \
1053 _zfcp_hex_dump(addr, count); \
1054 }
1055
1056#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1057#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1058#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1059
1060/*
1061 * functions needed for reference/usage counting
1062 */
1063
1064static inline void
1065zfcp_unit_get(struct zfcp_unit *unit)
1066{
1067 atomic_inc(&unit->refcount);
1068}
1069
1070static inline void
1071zfcp_unit_put(struct zfcp_unit *unit)
1072{
1073 if (atomic_dec_return(&unit->refcount) == 0)
1074 wake_up(&unit->remove_wq);
1075}
1076
1077static inline void
1078zfcp_unit_wait(struct zfcp_unit *unit)
1079{
1080 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1081}
1082
1083static inline void
1084zfcp_port_get(struct zfcp_port *port)
1085{
1086 atomic_inc(&port->refcount);
1087}
1088
1089static inline void
1090zfcp_port_put(struct zfcp_port *port)
1091{
1092 if (atomic_dec_return(&port->refcount) == 0)
1093 wake_up(&port->remove_wq);
1094}
1095
1096static inline void
1097zfcp_port_wait(struct zfcp_port *port)
1098{
1099 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1100}
1101
1102static inline void
1103zfcp_adapter_get(struct zfcp_adapter *adapter)
1104{
1105 atomic_inc(&adapter->refcount);
1106}
1107
1108static inline void
1109zfcp_adapter_put(struct zfcp_adapter *adapter)
1110{
1111 if (atomic_dec_return(&adapter->refcount) == 0)
1112 wake_up(&adapter->remove_wq);
1113}
1114
1115static inline void
1116zfcp_adapter_wait(struct zfcp_adapter *adapter)
1117{
1118 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1119}
1120
1121#endif /* ZFCP_DEF_H */
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
new file mode 100644
index 000000000000..cfc0d8c588df
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -0,0 +1,3585 @@
1/*
2 *
3 * linux/drivers/s390/scsi/zfcp_erp.c
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
32#define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
33
34#define ZFCP_ERP_REVISION "$Revision: 1.86 $"
35
36#include "zfcp_ext.h"
37
38static int zfcp_erp_adisc(struct zfcp_adapter *, fc_id_t);
39static void zfcp_erp_adisc_handler(unsigned long);
40
41static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
42static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
43static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
44static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
45
46static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
47static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
48
49static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
50static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
51static void zfcp_erp_port_block(struct zfcp_port *, int);
52static void zfcp_erp_port_unblock(struct zfcp_port *);
53static void zfcp_erp_unit_block(struct zfcp_unit *, int);
54static void zfcp_erp_unit_unblock(struct zfcp_unit *);
55
56static int zfcp_erp_thread(void *);
57
58static int zfcp_erp_strategy(struct zfcp_erp_action *);
59
60static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
61static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
62static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
63static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
64static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
65static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
66static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
67 struct zfcp_port *,
68 struct zfcp_unit *, int);
69static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
70static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
71 struct zfcp_port *,
72 struct zfcp_unit *, int);
73static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
74static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
75
76static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
77static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
78static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
79static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
80static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
81static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
82static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
83static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
84static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
85static int zfcp_erp_adapter_strategy_open_fsf_statusread(
86 struct zfcp_erp_action *);
87
88static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
89static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
90
91static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
92static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
93static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
94static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
95static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
96static int zfcp_erp_port_strategy_open_nameserver_wakeup(
97 struct zfcp_erp_action *);
98static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
99static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
100static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
101
102static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
103static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
104static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
105static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
106
107static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
108static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
109static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
110static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
111
112static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
113 struct zfcp_port *, struct zfcp_unit *);
114static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
115static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
116 struct zfcp_port *, struct zfcp_unit *,
117 int);
118
119static void zfcp_erp_action_ready(struct zfcp_erp_action *);
120static int zfcp_erp_action_exists(struct zfcp_erp_action *);
121
122static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
123static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
124
125static void zfcp_erp_memwait_handler(unsigned long);
126static void zfcp_erp_timeout_handler(unsigned long);
127static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
128
129/**
130 * zfcp_fsf_request_timeout_handler - called if a request timed out
131 * @data: pointer to adapter for handler function
132 *
133 * This function needs to be called if requests (ELS, Generic Service,
134 * or SCSI commands) exceed a certain time limit. The assumption is
135 * that after the time limit the adapter get stuck. So we trigger a reopen of
136 * the adapter. This should not be used for error recovery, SCSI abort
137 * commands and SCSI requests from SCSI mid-layer.
138 */
139void
140zfcp_fsf_request_timeout_handler(unsigned long data)
141{
142 struct zfcp_adapter *adapter;
143
144 adapter = (struct zfcp_adapter *) data;
145
146 zfcp_erp_adapter_reopen(adapter, 0);
147}
148
149/*
150 * function: zfcp_fsf_scsi_er_timeout_handler
151 *
152 * purpose: This function needs to be called whenever a SCSI error recovery
153 * action (abort/reset) does not return.
154 * Re-opening the adapter means that the command can be returned
155 * by zfcp (it is guarranteed that it does not return via the
156 * adapter anymore). The buffer can then be used again.
157 *
158 * returns: sod all
159 */
160void
161zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
162{
163 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
164
165 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
166 "Restarting all operations on the adapter %s\n",
167 zfcp_get_busid_by_adapter(adapter));
168 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
169 zfcp_erp_adapter_reopen(adapter, 0);
170
171 return;
172}
173
174/*
175 * function:
176 *
177 * purpose: called if an adapter failed,
178 * initiates adapter recovery which is done
179 * asynchronously
180 *
181 * returns: 0 - initiated action succesfully
182 * <0 - failed to initiate action
183 */
184int
185zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
186{
187 int retval;
188
189 debug_text_event(adapter->erp_dbf, 5, "a_ro");
190 ZFCP_LOG_DEBUG("reopen adapter %s\n",
191 zfcp_get_busid_by_adapter(adapter));
192
193 zfcp_erp_adapter_block(adapter, clear_mask);
194
195 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
196 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
197 zfcp_get_busid_by_adapter(adapter));
198 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
199 /* ensure propagation of failed status to new devices */
200 zfcp_erp_adapter_failed(adapter);
201 retval = -EIO;
202 goto out;
203 }
204 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
205 adapter, NULL, NULL);
206
207 out:
208 return retval;
209}
210
211/*
212 * function:
213 *
214 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
215 * used to ensure the correct locking
216 *
217 * returns: 0 - initiated action succesfully
218 * <0 - failed to initiate action
219 */
220int
221zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
222{
223 int retval;
224 unsigned long flags;
225
226 read_lock_irqsave(&zfcp_data.config_lock, flags);
227 write_lock(&adapter->erp_lock);
228 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
229 write_unlock(&adapter->erp_lock);
230 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
231
232 return retval;
233}
234
235/*
236 * function:
237 *
238 * purpose:
239 *
240 * returns:
241 */
242int
243zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
244{
245 int retval;
246
247 retval = zfcp_erp_adapter_reopen(adapter,
248 ZFCP_STATUS_COMMON_RUNNING |
249 ZFCP_STATUS_COMMON_ERP_FAILED |
250 clear_mask);
251
252 return retval;
253}
254
255/*
256 * function:
257 *
258 * purpose:
259 *
260 * returns:
261 */
262int
263zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
264{
265 int retval;
266
267 retval = zfcp_erp_port_reopen(port,
268 ZFCP_STATUS_COMMON_RUNNING |
269 ZFCP_STATUS_COMMON_ERP_FAILED |
270 clear_mask);
271
272 return retval;
273}
274
275/*
276 * function:
277 *
278 * purpose:
279 *
280 * returns:
281 */
282int
283zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
284{
285 int retval;
286
287 retval = zfcp_erp_unit_reopen(unit,
288 ZFCP_STATUS_COMMON_RUNNING |
289 ZFCP_STATUS_COMMON_ERP_FAILED |
290 clear_mask);
291
292 return retval;
293}
294
295
296/**
297 * zfcp_erp_adisc - send ADISC ELS command
298 * @adapter: adapter structure
299 * @d_id: d_id of port where ADISC is sent to
300 */
301int
302zfcp_erp_adisc(struct zfcp_adapter *adapter, fc_id_t d_id)
303{
304 struct zfcp_send_els *send_els;
305 struct zfcp_ls_adisc *adisc;
306 void *address = NULL;
307 int retval = 0;
308 struct timer_list *timer;
309
310 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
311 if (send_els == NULL)
312 goto nomem;
313 memset(send_els, 0, sizeof(*send_els));
314
315 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
316 if (send_els->req == NULL)
317 goto nomem;
318 memset(send_els->req, 0, sizeof(*send_els->req));
319
320 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
321 if (send_els->resp == NULL)
322 goto nomem;
323 memset(send_els->resp, 0, sizeof(*send_els->resp));
324
325 address = (void *) get_zeroed_page(GFP_ATOMIC);
326 if (address == NULL)
327 goto nomem;
328
329 zfcp_address_to_sg(address, send_els->req);
330 address += PAGE_SIZE >> 1;
331 zfcp_address_to_sg(address, send_els->resp);
332 send_els->req_count = send_els->resp_count = 1;
333
334 send_els->adapter = adapter;
335 send_els->d_id = d_id;
336 send_els->handler = zfcp_erp_adisc_handler;
337 send_els->handler_data = (unsigned long) send_els;
338
339 adisc = zfcp_sg_to_address(send_els->req);
340 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
341
342 send_els->req->length = sizeof(struct zfcp_ls_adisc);
343 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
344
345 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
346 without FC-AL-2 capability, so we don't set it */
347 adisc->wwpn = adapter->wwpn;
348 adisc->wwnn = adapter->wwnn;
349 adisc->nport_id = adapter->s_id;
350 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
351 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
352 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
353 adapter->s_id, d_id, (wwn_t) adisc->wwpn,
354 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
355 adisc->nport_id);
356
357 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
358 if (!timer)
359 goto nomem;
360
361 init_timer(timer);
362 timer->function = zfcp_fsf_request_timeout_handler;
363 timer->data = (unsigned long) adapter;
364 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
365 send_els->timer = timer;
366
367 retval = zfcp_fsf_send_els(send_els);
368 if (retval != 0) {
369 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
370 "0x%08x on adapter %s\n", d_id,
371 zfcp_get_busid_by_adapter(adapter));
372 del_timer(send_els->timer);
373 goto freemem;
374 }
375
376 goto out;
377
378 nomem:
379 retval = -ENOMEM;
380 freemem:
381 if (address != NULL)
382 __free_pages(send_els->req->page, 0);
383 if (send_els != NULL) {
384 kfree(send_els->timer);
385 kfree(send_els->req);
386 kfree(send_els->resp);
387 kfree(send_els);
388 }
389 out:
390 return retval;
391}
392
393
394/**
395 * zfcp_erp_adisc_handler - handler for ADISC ELS command
396 * @data: pointer to struct zfcp_send_els
397 *
398 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
399 */
400void
401zfcp_erp_adisc_handler(unsigned long data)
402{
403 struct zfcp_send_els *send_els;
404 struct zfcp_port *port;
405 struct zfcp_adapter *adapter;
406 fc_id_t d_id;
407 struct zfcp_ls_adisc_acc *adisc;
408
409 send_els = (struct zfcp_send_els *) data;
410
411 del_timer(send_els->timer);
412
413 adapter = send_els->adapter;
414 d_id = send_els->d_id;
415
416 read_lock(&zfcp_data.config_lock);
417 port = zfcp_get_port_by_did(send_els->adapter, send_els->d_id);
418 read_unlock(&zfcp_data.config_lock);
419
420 BUG_ON(port == NULL);
421
422 /* request rejected or timed out */
423 if (send_els->status != 0) {
424 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
425 "force physical port reopen "
426 "(adapter %s, port d_id=0x%08x)\n",
427 zfcp_get_busid_by_adapter(adapter), d_id);
428 debug_text_event(adapter->erp_dbf, 3, "forcreop");
429 if (zfcp_erp_port_forced_reopen(port, 0))
430 ZFCP_LOG_NORMAL("failed reopen of port "
431 "(adapter %s, wwpn=0x%016Lx)\n",
432 zfcp_get_busid_by_port(port),
433 port->wwpn);
434 goto out;
435 }
436
437 adisc = zfcp_sg_to_address(send_els->resp);
438
439 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
440 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
441 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
442 d_id, adapter->s_id, (wwn_t) adisc->wwpn,
443 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
444 adisc->nport_id);
445
446 /* set wwnn for port */
447 if (port->wwnn == 0)
448 port->wwnn = adisc->wwnn;
449
450 if (port->wwpn != adisc->wwpn) {
451 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
452 "port (adapter %s, wwpn=0x%016Lx, "
453 "adisc_resp_wwpn=0x%016Lx)\n",
454 zfcp_get_busid_by_port(port),
455 port->wwpn, (wwn_t) adisc->wwpn);
456 if (zfcp_erp_port_reopen(port, 0))
457 ZFCP_LOG_NORMAL("failed reopen of port "
458 "(adapter %s, wwpn=0x%016Lx)\n",
459 zfcp_get_busid_by_port(port),
460 port->wwpn);
461 }
462
463 out:
464 zfcp_port_put(port);
465 __free_pages(send_els->req->page, 0);
466 kfree(send_els->timer);
467 kfree(send_els->req);
468 kfree(send_els->resp);
469 kfree(send_els);
470}
471
472
473/**
474 * zfcp_test_link - lightweight link test procedure
475 * @port: port to be tested
476 *
477 * Test status of a link to a remote port using the ELS command ADISC.
478 */
479int
480zfcp_test_link(struct zfcp_port *port)
481{
482 int retval;
483
484 zfcp_port_get(port);
485 retval = zfcp_erp_adisc(port->adapter, port->d_id);
486 if (retval != 0) {
487 zfcp_port_put(port);
488 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
489 "on adapter %s\n ", port->wwpn,
490 zfcp_get_busid_by_port(port));
491 retval = zfcp_erp_port_forced_reopen(port, 0);
492 if (retval != 0) {
493 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
494 "on adapter %s failed\n", port->wwpn,
495 zfcp_get_busid_by_port(port));
496 retval = -EPERM;
497 }
498 }
499
500 return retval;
501}
502
503
504/*
505 * function:
506 *
507 * purpose: called if a port failed to be opened normally
508 * initiates Forced Reopen recovery which is done
509 * asynchronously
510 *
511 * returns: 0 - initiated action succesfully
512 * <0 - failed to initiate action
513 */
514static int
515zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
516{
517 int retval;
518 struct zfcp_adapter *adapter = port->adapter;
519
520 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
521 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
522
523 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
524 port->wwpn, zfcp_get_busid_by_port(port));
525
526 zfcp_erp_port_block(port, clear_mask);
527
528 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
529 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
530 "on adapter %s\n", port->wwpn,
531 zfcp_get_busid_by_port(port));
532 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
533 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
534 retval = -EIO;
535 goto out;
536 }
537
538 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
539 port->adapter, port, NULL);
540
541 out:
542 return retval;
543}
544
545/*
546 * function:
547 *
548 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
549 * used to ensure the correct locking
550 *
551 * returns: 0 - initiated action succesfully
552 * <0 - failed to initiate action
553 */
554int
555zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
556{
557 int retval;
558 unsigned long flags;
559 struct zfcp_adapter *adapter;
560
561 adapter = port->adapter;
562 read_lock_irqsave(&zfcp_data.config_lock, flags);
563 write_lock(&adapter->erp_lock);
564 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
565 write_unlock(&adapter->erp_lock);
566 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
567
568 return retval;
569}
570
571/*
572 * function:
573 *
574 * purpose: called if a port is to be opened
575 * initiates Reopen recovery which is done
576 * asynchronously
577 *
578 * returns: 0 - initiated action succesfully
579 * <0 - failed to initiate action
580 */
581static int
582zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
583{
584 int retval;
585 struct zfcp_adapter *adapter = port->adapter;
586
587 debug_text_event(adapter->erp_dbf, 5, "p_ro");
588 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
589
590 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
591 port->wwpn, zfcp_get_busid_by_port(port));
592
593 zfcp_erp_port_block(port, clear_mask);
594
595 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
596 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
597 "on adapter %s\n", port->wwpn,
598 zfcp_get_busid_by_port(port));
599 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
600 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
601 /* ensure propagation of failed status to new devices */
602 zfcp_erp_port_failed(port);
603 retval = -EIO;
604 goto out;
605 }
606
607 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
608 port->adapter, port, NULL);
609
610 out:
611 return retval;
612}
613
614/**
615 * zfcp_erp_port_reopen - initiate reopen of a remote port
616 * @port: port to be reopened
617 * @clear_mask: specifies flags in port status to be cleared
618 * Return: 0 on success, < 0 on error
619 *
620 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
621 * correct locking. An error recovery task is initiated to do the reopen.
622 * To wait for the completion of the reopen zfcp_erp_wait should be used.
623 */
624int
625zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
626{
627 int retval;
628 unsigned long flags;
629 struct zfcp_adapter *adapter = port->adapter;
630
631 read_lock_irqsave(&zfcp_data.config_lock, flags);
632 write_lock(&adapter->erp_lock);
633 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
634 write_unlock(&adapter->erp_lock);
635 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
636
637 return retval;
638}
639
640/*
641 * function:
642 *
643 * purpose: called if a unit is to be opened
644 * initiates Reopen recovery which is done
645 * asynchronously
646 *
647 * returns: 0 - initiated action succesfully
648 * <0 - failed to initiate action
649 */
650static int
651zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
652{
653 int retval;
654 struct zfcp_adapter *adapter = unit->port->adapter;
655
656 debug_text_event(adapter->erp_dbf, 5, "u_ro");
657 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
658 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
659 "on adapter %s\n", unit->fcp_lun,
660 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
661
662 zfcp_erp_unit_block(unit, clear_mask);
663
664 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
665 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
666 "on port 0x%016Lx on adapter %s\n",
667 unit->fcp_lun, unit->port->wwpn,
668 zfcp_get_busid_by_unit(unit));
669 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
670 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
671 sizeof (fcp_lun_t));
672 retval = -EIO;
673 goto out;
674 }
675
676 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
677 unit->port->adapter, unit->port, unit);
678 out:
679 return retval;
680}
681
682/**
683 * zfcp_erp_unit_reopen - initiate reopen of a unit
684 * @unit: unit to be reopened
685 * @clear_mask: specifies flags in unit status to be cleared
686 * Return: 0 on success, < 0 on error
687 *
688 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
689 * locking. An error recovery task is initiated to do the reopen.
690 * To wait for the completion of the reopen zfcp_erp_wait should be used.
691 */
692int
693zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
694{
695 int retval;
696 unsigned long flags;
697 struct zfcp_adapter *adapter;
698 struct zfcp_port *port;
699
700 port = unit->port;
701 adapter = port->adapter;
702
703 read_lock_irqsave(&zfcp_data.config_lock, flags);
704 write_lock(&adapter->erp_lock);
705 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
706 write_unlock(&adapter->erp_lock);
707 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
708
709 return retval;
710}
711
712/*
713 * function:
714 *
715 * purpose: disable I/O,
716 * return any open requests and clean them up,
717 * aim: no pending and incoming I/O
718 *
719 * returns:
720 */
721static void
722zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
723{
724 debug_text_event(adapter->erp_dbf, 6, "a_bl");
725 zfcp_erp_modify_adapter_status(adapter,
726 ZFCP_STATUS_COMMON_UNBLOCKED |
727 clear_mask, ZFCP_CLEAR);
728}
729
730/*
731 * function:
732 *
733 * purpose: enable I/O
734 *
735 * returns:
736 */
737static void
738zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
739{
740 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
741 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
742}
743
744/*
745 * function:
746 *
747 * purpose: disable I/O,
748 * return any open requests and clean them up,
749 * aim: no pending and incoming I/O
750 *
751 * returns:
752 */
753static void
754zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
755{
756 struct zfcp_adapter *adapter = port->adapter;
757
758 debug_text_event(adapter->erp_dbf, 6, "p_bl");
759 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
760 zfcp_erp_modify_port_status(port,
761 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
762 ZFCP_CLEAR);
763}
764
765/*
766 * function:
767 *
768 * purpose: enable I/O
769 *
770 * returns:
771 */
772static void
773zfcp_erp_port_unblock(struct zfcp_port *port)
774{
775 struct zfcp_adapter *adapter = port->adapter;
776
777 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
778 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
779 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
780}
781
782/*
783 * function:
784 *
785 * purpose: disable I/O,
786 * return any open requests and clean them up,
787 * aim: no pending and incoming I/O
788 *
789 * returns:
790 */
791static void
792zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
793{
794 struct zfcp_adapter *adapter = unit->port->adapter;
795
796 debug_text_event(adapter->erp_dbf, 6, "u_bl");
797 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
798 zfcp_erp_modify_unit_status(unit,
799 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
800 ZFCP_CLEAR);
801}
802
803/*
804 * function:
805 *
806 * purpose: enable I/O
807 *
808 * returns:
809 */
810static void
811zfcp_erp_unit_unblock(struct zfcp_unit *unit)
812{
813 struct zfcp_adapter *adapter = unit->port->adapter;
814
815 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
816 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
817 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
818}
819
820/*
821 * function:
822 *
823 * purpose:
824 *
825 * returns:
826 */
827static void
828zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
829{
830 struct zfcp_adapter *adapter = erp_action->adapter;
831
832 debug_text_event(adapter->erp_dbf, 4, "a_ar");
833 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
834
835 zfcp_erp_action_to_ready(erp_action);
836 up(&adapter->erp_ready_sem);
837}
838
839/*
840 * function:
841 *
842 * purpose:
843 *
844 * returns: <0 erp_action not found in any list
845 * ZFCP_ERP_ACTION_READY erp_action is in ready list
846 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
847 *
848 * locks: erp_lock must be held
849 */
850static int
851zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
852{
853 int retval = -EINVAL;
854 struct list_head *entry;
855 struct zfcp_erp_action *entry_erp_action;
856 struct zfcp_adapter *adapter = erp_action->adapter;
857
858 /* search in running list */
859 list_for_each(entry, &adapter->erp_running_head) {
860 entry_erp_action =
861 list_entry(entry, struct zfcp_erp_action, list);
862 if (entry_erp_action == erp_action) {
863 retval = ZFCP_ERP_ACTION_RUNNING;
864 goto out;
865 }
866 }
867 /* search in ready list */
868 list_for_each(entry, &adapter->erp_ready_head) {
869 entry_erp_action =
870 list_entry(entry, struct zfcp_erp_action, list);
871 if (entry_erp_action == erp_action) {
872 retval = ZFCP_ERP_ACTION_READY;
873 goto out;
874 }
875 }
876
877 out:
878 return retval;
879}
880
881/*
882 * purpose: checks current status of action (timed out, dismissed, ...)
883 * and does appropriate preparations (dismiss fsf request, ...)
884 *
885 * locks: called under erp_lock (disabled interrupts)
886 *
887 * returns: 0
888 */
889static int
890zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
891{
892 int retval = 0;
893 struct zfcp_fsf_req *fsf_req;
894 struct zfcp_adapter *adapter = erp_action->adapter;
895
896 if (erp_action->fsf_req) {
897 /* take lock to ensure that request is not being deleted meanwhile */
898 write_lock(&adapter->fsf_req_list_lock);
899 /* check whether fsf req does still exist */
900 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
901 if (fsf_req == erp_action->fsf_req)
902 break;
903 if (fsf_req == erp_action->fsf_req) {
904 /* fsf_req still exists */
905 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
906 debug_event(adapter->erp_dbf, 3, &fsf_req,
907 sizeof (unsigned long));
908 /* dismiss fsf_req of timed out or dismissed erp_action */
909 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
910 ZFCP_STATUS_ERP_TIMEDOUT)) {
911 debug_text_event(adapter->erp_dbf, 3,
912 "a_ca_disreq");
913 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
914 }
915 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
916 ZFCP_LOG_NORMAL("error: erp step timed out "
917 "(action=%d, fsf_req=%p)\n ",
918 erp_action->action,
919 erp_action->fsf_req);
920 }
921 /*
922 * If fsf_req is neither dismissed nor completed
923 * then keep it running asynchronously and don't mess
924 * with the association of erp_action and fsf_req.
925 */
926 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
927 ZFCP_STATUS_FSFREQ_DISMISSED)) {
928 /* forget about association between fsf_req
929 and erp_action */
930 fsf_req->erp_action = NULL;
931 erp_action->fsf_req = NULL;
932 }
933 } else {
934 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
935 /*
936 * even if this fsf_req has gone, forget about
937 * association between erp_action and fsf_req
938 */
939 erp_action->fsf_req = NULL;
940 }
941 write_unlock(&adapter->fsf_req_list_lock);
942 } else
943 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
944
945 return retval;
946}
947
948/*
949 * purpose: generic handler for asynchronous events related to erp_action events
950 * (normal completion, time-out, dismissing, retry after
951 * low memory condition)
952 *
953 * note: deletion of timer is not required (e.g. in case of a time-out),
954 * but a second try does no harm,
955 * we leave it in here to allow for greater simplification
956 *
957 * returns: 0 - there was an action to handle
958 * !0 - otherwise
959 */
960static int
961zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
962 unsigned long set_mask)
963{
964 int retval;
965 struct zfcp_adapter *adapter = erp_action->adapter;
966
967 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
968 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
969 debug_event(adapter->erp_dbf, 2, &erp_action->action,
970 sizeof (int));
971 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
972 del_timer(&erp_action->timer);
973 erp_action->status |= set_mask;
974 zfcp_erp_action_ready(erp_action);
975 retval = 0;
976 } else {
977 /* action is ready or gone - nothing to do */
978 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
979 debug_event(adapter->erp_dbf, 3, &erp_action->action,
980 sizeof (int));
981 retval = 1;
982 }
983
984 return retval;
985}
986
987/*
988 * purpose: generic handler for asynchronous events related to erp_action
989 * events (normal completion, time-out, dismissing, retry after
990 * low memory condition)
991 *
992 * note: deletion of timer is not required (e.g. in case of a time-out),
993 * but a second try does no harm,
994 * we leave it in here to allow for greater simplification
995 *
996 * returns: 0 - there was an action to handle
997 * !0 - otherwise
998 */
999int
1000zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
1001 unsigned long set_mask)
1002{
1003 struct zfcp_adapter *adapter = erp_action->adapter;
1004 unsigned long flags;
1005 int retval;
1006
1007 write_lock_irqsave(&adapter->erp_lock, flags);
1008 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1009 write_unlock_irqrestore(&adapter->erp_lock, flags);
1010
1011 return retval;
1012}
1013
1014/*
1015 * purpose: is called for erp_action which was slept waiting for
1016 * memory becoming avaliable,
1017 * will trigger that this action will be continued
1018 */
1019static void
1020zfcp_erp_memwait_handler(unsigned long data)
1021{
1022 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1023 struct zfcp_adapter *adapter = erp_action->adapter;
1024
1025 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1026 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1027
1028 zfcp_erp_async_handler(erp_action, 0);
1029}
1030
1031/*
1032 * purpose: is called if an asynchronous erp step timed out,
1033 * action gets an appropriate flag and will be processed
1034 * accordingly
1035 */
1036static void
1037zfcp_erp_timeout_handler(unsigned long data)
1038{
1039 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1040 struct zfcp_adapter *adapter = erp_action->adapter;
1041
1042 debug_text_event(adapter->erp_dbf, 2, "a_th");
1043 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1044
1045 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1046}
1047
1048/*
1049 * purpose: is called for an erp_action which needs to be ended
1050 * though not being done,
1051 * this is usually required if an higher is generated,
1052 * action gets an appropriate flag and will be processed
1053 * accordingly
1054 *
1055 * locks: erp_lock held (thus we need to call another handler variant)
1056 */
1057static int
1058zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1059{
1060 struct zfcp_adapter *adapter = erp_action->adapter;
1061
1062 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1063 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1064
1065 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1066
1067 return 0;
1068}
1069
1070int
1071zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1072{
1073 int retval = 0;
1074
1075 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1076
1077 rwlock_init(&adapter->erp_lock);
1078 INIT_LIST_HEAD(&adapter->erp_ready_head);
1079 INIT_LIST_HEAD(&adapter->erp_running_head);
1080 sema_init(&adapter->erp_ready_sem, 0);
1081
1082 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1083 if (retval < 0) {
1084 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1085 "adapter %s\n",
1086 zfcp_get_busid_by_adapter(adapter));
1087 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1088 } else {
1089 wait_event(adapter->erp_thread_wqh,
1090 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1091 &adapter->status));
1092 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1093 }
1094
1095 return (retval < 0);
1096}
1097
1098/*
1099 * function:
1100 *
1101 * purpose:
1102 *
1103 * returns:
1104 *
1105 * context: process (i.e. proc-fs or rmmod/insmod)
1106 *
1107 * note: The caller of this routine ensures that the specified
1108 * adapter has been shut down and that this operation
1109 * has been completed. Thus, there are no pending erp_actions
1110 * which would need to be handled here.
1111 */
1112int
1113zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1114{
1115 int retval = 0;
1116
1117 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1118 up(&adapter->erp_ready_sem);
1119
1120 wait_event(adapter->erp_thread_wqh,
1121 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1122 &adapter->status));
1123
1124 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1125 &adapter->status);
1126
1127 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1128
1129 return retval;
1130}
1131
1132/*
1133 * purpose: is run as a kernel thread,
1134 * goes through list of error recovery actions of associated adapter
1135 * and delegates single action to execution
1136 *
1137 * returns: 0
1138 */
1139static int
1140zfcp_erp_thread(void *data)
1141{
1142 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1143 struct list_head *next;
1144 struct zfcp_erp_action *erp_action;
1145 unsigned long flags;
1146
1147 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1148 /* Block all signals */
1149 siginitsetinv(&current->blocked, 0);
1150 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1151 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1152 wake_up(&adapter->erp_thread_wqh);
1153
1154 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1155 &adapter->status)) {
1156
1157 write_lock_irqsave(&adapter->erp_lock, flags);
1158 next = adapter->erp_ready_head.prev;
1159 write_unlock_irqrestore(&adapter->erp_lock, flags);
1160
1161 if (next != &adapter->erp_ready_head) {
1162 erp_action =
1163 list_entry(next, struct zfcp_erp_action, list);
1164 /*
1165 * process action (incl. [re]moving it
1166 * from 'ready' queue)
1167 */
1168 zfcp_erp_strategy(erp_action);
1169 }
1170
1171 /*
1172 * sleep as long as there is nothing to do, i.e.
1173 * no action in 'ready' queue to be processed and
1174 * thread is not to be killed
1175 */
1176 down_interruptible(&adapter->erp_ready_sem);
1177 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1178 }
1179
1180 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1181 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1182 wake_up(&adapter->erp_thread_wqh);
1183
1184 return 0;
1185}
1186
1187/*
1188 * function:
1189 *
1190 * purpose: drives single error recovery action and schedules higher and
1191 * subordinate actions, if necessary
1192 *
1193 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1194 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1195 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1196 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1197 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1198 */
1199static int
1200zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1201{
1202 int retval = 0;
1203 struct zfcp_adapter *adapter = erp_action->adapter;
1204 struct zfcp_port *port = erp_action->port;
1205 struct zfcp_unit *unit = erp_action->unit;
1206 int action = erp_action->action;
1207 u32 status = erp_action->status;
1208 unsigned long flags;
1209
1210 /* serialise dismissing, timing out, moving, enqueueing */
1211 read_lock_irqsave(&zfcp_data.config_lock, flags);
1212 write_lock(&adapter->erp_lock);
1213
1214 /* dequeue dismissed action and leave, if required */
1215 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1216 if (retval == ZFCP_ERP_DISMISSED) {
1217 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1218 goto unlock;
1219 }
1220
1221 /*
1222 * move action to 'running' queue before processing it
1223 * (to avoid a race condition regarding moving the
1224 * action to the 'running' queue and back)
1225 */
1226 zfcp_erp_action_to_running(erp_action);
1227
1228 /*
1229 * try to process action as far as possible,
1230 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1231 * afterwards the lock is required again for the following reasons:
1232 * - dequeueing of finished action and enqueueing of
1233 * follow-up actions must be atomic so that any other
1234 * reopen-routine does not believe there is nothing to do
1235 * and that it is safe to enqueue something else,
1236 * - we want to force any control thread which is dismissing
1237 * actions to finish this before we decide about
1238 * necessary steps to be taken here further
1239 */
1240 write_unlock(&adapter->erp_lock);
1241 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1242 retval = zfcp_erp_strategy_do_action(erp_action);
1243 read_lock_irqsave(&zfcp_data.config_lock, flags);
1244 write_lock(&adapter->erp_lock);
1245
1246 /*
1247 * check for dismissed status again to avoid follow-up actions,
1248 * failing of targets and so on for dismissed actions
1249 */
1250 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1251
1252 switch (retval) {
1253 case ZFCP_ERP_DISMISSED:
1254 /* leave since this action has ridden to its ancestors */
1255 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1256 goto unlock;
1257 case ZFCP_ERP_NOMEM:
1258 /* no memory to continue immediately, let it sleep */
1259 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1260 ++adapter->erp_low_mem_count;
1261 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1262 }
1263 /* This condition is true if there is no memory available
1264 for any erp_action on this adapter. This implies that there
1265 are no elements in the memory pool(s) left for erp_actions.
1266 This might happen if an erp_action that used a memory pool
1267 element was timed out.
1268 */
1269 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1270 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1271 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1272 "restarting I/O on adapter %s "
1273 "to free mempool\n",
1274 zfcp_get_busid_by_adapter(adapter));
1275 zfcp_erp_adapter_reopen_internal(adapter, 0);
1276 } else {
1277 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1278 retval = zfcp_erp_strategy_memwait(erp_action);
1279 }
1280 goto unlock;
1281 case ZFCP_ERP_CONTINUES:
1282 /* leave since this action runs asynchronously */
1283 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1284 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1285 --adapter->erp_low_mem_count;
1286 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1287 }
1288 goto unlock;
1289 }
1290 /* ok, finished action (whatever its result is) */
1291
1292 /* check for unrecoverable targets */
1293 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1294
1295 /* action must be dequeued (here to allow for further ones) */
1296 zfcp_erp_action_dequeue(erp_action);
1297
1298 /*
1299 * put this target through the erp mill again if someone has
1300 * requested to change the status of a target being online
1301 * to offline or the other way around
1302 * (old retval is preserved if nothing has to be done here)
1303 */
1304 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1305 port, unit, retval);
1306
1307 /*
1308 * leave if target is in permanent error state or if
1309 * action is repeated in order to process state change
1310 */
1311 if (retval == ZFCP_ERP_EXIT) {
1312 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1313 goto unlock;
1314 }
1315
1316 /* trigger follow up actions */
1317 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1318
1319 unlock:
1320 write_unlock(&adapter->erp_lock);
1321 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1322
1323 if (retval != ZFCP_ERP_CONTINUES)
1324 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1325
1326 /*
1327 * a few tasks remain when the erp queues are empty
1328 * (don't do that if the last action evaluated was dismissed
1329 * since this clearly indicates that there is more to come) :
1330 * - close the name server port if it is open yet
1331 * (enqueues another [probably] final action)
1332 * - otherwise, wake up whoever wants to be woken when we are
1333 * done with erp
1334 */
1335 if (retval != ZFCP_ERP_DISMISSED)
1336 zfcp_erp_strategy_check_queues(adapter);
1337
1338 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1339
1340 return retval;
1341}
1342
1343/*
1344 * function:
1345 *
1346 * purpose:
1347 *
1348 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1349 * retval - otherwise
1350 */
1351static int
1352zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1353{
1354 struct zfcp_adapter *adapter = erp_action->adapter;
1355
1356 zfcp_erp_strategy_check_fsfreq(erp_action);
1357
1358 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1359 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1360 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1361 zfcp_erp_action_dequeue(erp_action);
1362 retval = ZFCP_ERP_DISMISSED;
1363 } else
1364 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1365
1366 return retval;
1367}
1368
1369/*
1370 * function:
1371 *
1372 * purpose:
1373 *
1374 * returns:
1375 */
1376static int
1377zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1378{
1379 int retval = ZFCP_ERP_FAILED;
1380 struct zfcp_adapter *adapter = erp_action->adapter;
1381
1382 /*
1383 * try to execute/continue action as far as possible,
1384 * note: no lock in subsequent strategy routines
1385 * (this allows these routine to call schedule, e.g.
1386 * kmalloc with such flags or qdio_initialize & friends)
1387 * Note: in case of timeout, the seperate strategies will fail
1388 * anyhow. No need for a special action. Even worse, a nameserver
1389 * failure would not wake up waiting ports without the call.
1390 */
1391 switch (erp_action->action) {
1392
1393 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1394 retval = zfcp_erp_adapter_strategy(erp_action);
1395 break;
1396
1397 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1398 retval = zfcp_erp_port_forced_strategy(erp_action);
1399 break;
1400
1401 case ZFCP_ERP_ACTION_REOPEN_PORT:
1402 retval = zfcp_erp_port_strategy(erp_action);
1403 break;
1404
1405 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1406 retval = zfcp_erp_unit_strategy(erp_action);
1407 break;
1408
1409 default:
1410 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1411 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1412 sizeof (int));
1413 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1414 "adapter %s (action=%d)\n",
1415 zfcp_get_busid_by_adapter(erp_action->adapter),
1416 erp_action->action);
1417 }
1418
1419 return retval;
1420}
1421
1422/*
1423 * function:
1424 *
1425 * purpose: triggers retry of this action after a certain amount of time
1426 * by means of timer provided by erp_action
1427 *
1428 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1429 */
1430static int
1431zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1432{
1433 int retval = ZFCP_ERP_CONTINUES;
1434 struct zfcp_adapter *adapter = erp_action->adapter;
1435
1436 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1437 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1438 init_timer(&erp_action->timer);
1439 erp_action->timer.function = zfcp_erp_memwait_handler;
1440 erp_action->timer.data = (unsigned long) erp_action;
1441 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1442 add_timer(&erp_action->timer);
1443
1444 return retval;
1445}
1446
1447/*
1448 * function: zfcp_erp_adapter_failed
1449 *
1450 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1451 *
1452 */
1453void
1454zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1455{
1456 zfcp_erp_modify_adapter_status(adapter,
1457 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1458 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1459 zfcp_get_busid_by_adapter(adapter));
1460 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1461}
1462
1463/*
1464 * function: zfcp_erp_port_failed
1465 *
1466 * purpose: sets the port and all underlying devices to ERP_FAILED
1467 *
1468 */
1469void
1470zfcp_erp_port_failed(struct zfcp_port *port)
1471{
1472 zfcp_erp_modify_port_status(port,
1473 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1474
1475 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1476 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1477 "port d_id=0x%08x)\n",
1478 zfcp_get_busid_by_port(port), port->d_id);
1479 else
1480 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1481 zfcp_get_busid_by_port(port), port->wwpn);
1482
1483 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1484 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1485}
1486
1487/*
1488 * function: zfcp_erp_unit_failed
1489 *
1490 * purpose: sets the unit to ERP_FAILED
1491 *
1492 */
1493void
1494zfcp_erp_unit_failed(struct zfcp_unit *unit)
1495{
1496 zfcp_erp_modify_unit_status(unit,
1497 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1498
1499 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1500 " on adapter %s\n", unit->fcp_lun,
1501 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1502 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1503 debug_event(unit->port->adapter->erp_dbf, 2,
1504 &unit->fcp_lun, sizeof (fcp_lun_t));
1505}
1506
1507/*
1508 * function: zfcp_erp_strategy_check_target
1509 *
1510 * purpose: increments the erp action count on the device currently in
1511 * recovery if the action failed or resets the count in case of
1512 * success. If a maximum count is exceeded the device is marked
1513 * as ERP_FAILED.
1514 * The 'blocked' state of a target which has been recovered
1515 * successfully is reset.
1516 *
1517 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1518 * ZFCP_ERP_SUCCEEDED - action finished successfully
1519 * ZFCP_ERP_EXIT - action failed and will not continue
1520 */
1521static int
1522zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1523{
1524 struct zfcp_adapter *adapter = erp_action->adapter;
1525 struct zfcp_port *port = erp_action->port;
1526 struct zfcp_unit *unit = erp_action->unit;
1527
1528 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1529 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1530 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1531
1532 switch (erp_action->action) {
1533
1534 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1535 result = zfcp_erp_strategy_check_unit(unit, result);
1536 break;
1537
1538 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1539 case ZFCP_ERP_ACTION_REOPEN_PORT:
1540 result = zfcp_erp_strategy_check_port(port, result);
1541 break;
1542
1543 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1544 result = zfcp_erp_strategy_check_adapter(adapter, result);
1545 break;
1546 }
1547
1548 return result;
1549}
1550
1551/*
1552 * function:
1553 *
1554 * purpose:
1555 *
1556 * returns:
1557 */
1558static int
1559zfcp_erp_strategy_statechange(int action,
1560 u32 status,
1561 struct zfcp_adapter *adapter,
1562 struct zfcp_port *port,
1563 struct zfcp_unit *unit, int retval)
1564{
1565 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1566 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1567
1568 switch (action) {
1569
1570 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1571 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1572 status)) {
1573 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1574 retval = ZFCP_ERP_EXIT;
1575 }
1576 break;
1577
1578 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1579 case ZFCP_ERP_ACTION_REOPEN_PORT:
1580 if (zfcp_erp_strategy_statechange_detected(&port->status,
1581 status)) {
1582 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1583 retval = ZFCP_ERP_EXIT;
1584 }
1585 break;
1586
1587 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1588 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1589 status)) {
1590 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1591 retval = ZFCP_ERP_EXIT;
1592 }
1593 break;
1594 }
1595
1596 return retval;
1597}
1598
1599/*
1600 * function:
1601 *
1602 * purpose:
1603 *
1604 * returns:
1605 */
1606static inline int
1607zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1608{
1609 return
1610 /* take it online */
1611 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1612 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1613 /* take it offline */
1614 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1615 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1616}
1617
1618/*
1619 * function:
1620 *
1621 * purpose:
1622 *
1623 * returns:
1624 */
1625static int
1626zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1627{
1628 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1629 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1630 sizeof (fcp_lun_t));
1631
1632 switch (result) {
1633 case ZFCP_ERP_SUCCEEDED :
1634 atomic_set(&unit->erp_counter, 0);
1635 zfcp_erp_unit_unblock(unit);
1636 break;
1637 case ZFCP_ERP_FAILED :
1638 atomic_inc(&unit->erp_counter);
1639 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1640 zfcp_erp_unit_failed(unit);
1641 break;
1642 case ZFCP_ERP_EXIT :
1643 /* nothing */
1644 break;
1645 }
1646
1647 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1648 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1649 result = ZFCP_ERP_EXIT;
1650 }
1651
1652 return result;
1653}
1654
1655/*
1656 * function:
1657 *
1658 * purpose:
1659 *
1660 * returns:
1661 */
1662static int
1663zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1664{
1665 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1666 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1667
1668 switch (result) {
1669 case ZFCP_ERP_SUCCEEDED :
1670 atomic_set(&port->erp_counter, 0);
1671 zfcp_erp_port_unblock(port);
1672 break;
1673 case ZFCP_ERP_FAILED :
1674 atomic_inc(&port->erp_counter);
1675 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1676 zfcp_erp_port_failed(port);
1677 break;
1678 case ZFCP_ERP_EXIT :
1679 /* nothing */
1680 break;
1681 }
1682
1683 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1684 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1685 result = ZFCP_ERP_EXIT;
1686 }
1687
1688 return result;
1689}
1690
1691/*
1692 * function:
1693 *
1694 * purpose:
1695 *
1696 * returns:
1697 */
1698static int
1699zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1700{
1701 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1702
1703 switch (result) {
1704 case ZFCP_ERP_SUCCEEDED :
1705 atomic_set(&adapter->erp_counter, 0);
1706 zfcp_erp_adapter_unblock(adapter);
1707 break;
1708 case ZFCP_ERP_FAILED :
1709 atomic_inc(&adapter->erp_counter);
1710 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1711 zfcp_erp_adapter_failed(adapter);
1712 break;
1713 case ZFCP_ERP_EXIT :
1714 /* nothing */
1715 break;
1716 }
1717
1718 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1719 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1720 result = ZFCP_ERP_EXIT;
1721 }
1722
1723 return result;
1724}
1725
1726/*
1727 * function:
1728 *
1729 * purpose: remaining things in good cases,
1730 * escalation in bad cases
1731 *
1732 * returns:
1733 */
1734static int
1735zfcp_erp_strategy_followup_actions(int action,
1736 struct zfcp_adapter *adapter,
1737 struct zfcp_port *port,
1738 struct zfcp_unit *unit, int status)
1739{
1740 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1741 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1742
1743 /* initiate follow-up actions depending on success of finished action */
1744 switch (action) {
1745
1746 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1747 if (status == ZFCP_ERP_SUCCEEDED)
1748 zfcp_erp_port_reopen_all_internal(adapter, 0);
1749 else
1750 zfcp_erp_adapter_reopen_internal(adapter, 0);
1751 break;
1752
1753 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1754 if (status == ZFCP_ERP_SUCCEEDED)
1755 zfcp_erp_port_reopen_internal(port, 0);
1756 else
1757 zfcp_erp_adapter_reopen_internal(adapter, 0);
1758 break;
1759
1760 case ZFCP_ERP_ACTION_REOPEN_PORT:
1761 if (status == ZFCP_ERP_SUCCEEDED)
1762 zfcp_erp_unit_reopen_all_internal(port, 0);
1763 else
1764 zfcp_erp_port_forced_reopen_internal(port, 0);
1765 break;
1766
1767 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1768 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1769 else
1770 zfcp_erp_port_reopen_internal(unit->port, 0);
1771 break;
1772 }
1773
1774 return 0;
1775}
1776
1777/*
1778 * function:
1779 *
1780 * purpose:
1781 *
1782 * returns:
1783 */
1784static int
1785zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1786{
1787 unsigned long flags;
1788
1789 read_lock_irqsave(&zfcp_data.config_lock, flags);
1790 read_lock(&adapter->erp_lock);
1791 if (list_empty(&adapter->erp_ready_head) &&
1792 list_empty(&adapter->erp_running_head)) {
1793 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1794 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1795 &adapter->status);
1796 wake_up(&adapter->erp_done_wqh);
1797 } else
1798 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1799 read_unlock(&adapter->erp_lock);
1800 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1801
1802 return 0;
1803}
1804
1805/**
1806 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1807 * @adapter: adapter for which to wait for completion of its error recovery
1808 * Return: 0
1809 */
1810int
1811zfcp_erp_wait(struct zfcp_adapter *adapter)
1812{
1813 int retval = 0;
1814
1815 wait_event(adapter->erp_done_wqh,
1816 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1817 &adapter->status));
1818
1819 return retval;
1820}
1821
1822/*
1823 * function: zfcp_erp_modify_adapter_status
1824 *
1825 * purpose:
1826 *
1827 */
1828void
1829zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1830 u32 mask, int set_or_clear)
1831{
1832 struct zfcp_port *port;
1833 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1834
1835 if (set_or_clear == ZFCP_SET) {
1836 atomic_set_mask(mask, &adapter->status);
1837 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1838 } else {
1839 atomic_clear_mask(mask, &adapter->status);
1840 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1841 atomic_set(&adapter->erp_counter, 0);
1842 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1843 }
1844 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1845
1846 /* Deal with all underlying devices, only pass common_mask */
1847 if (common_mask)
1848 list_for_each_entry(port, &adapter->port_list_head, list)
1849 zfcp_erp_modify_port_status(port, common_mask,
1850 set_or_clear);
1851}
1852
1853/*
1854 * function: zfcp_erp_modify_port_status
1855 *
1856 * purpose: sets the port and all underlying devices to ERP_FAILED
1857 *
1858 */
1859void
1860zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1861{
1862 struct zfcp_unit *unit;
1863 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1864
1865 if (set_or_clear == ZFCP_SET) {
1866 atomic_set_mask(mask, &port->status);
1867 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1868 } else {
1869 atomic_clear_mask(mask, &port->status);
1870 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1871 atomic_set(&port->erp_counter, 0);
1872 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1873 }
1874 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1875 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1876
1877 /* Modify status of all underlying devices, only pass common mask */
1878 if (common_mask)
1879 list_for_each_entry(unit, &port->unit_list_head, list)
1880 zfcp_erp_modify_unit_status(unit, common_mask,
1881 set_or_clear);
1882}
1883
1884/*
1885 * function: zfcp_erp_modify_unit_status
1886 *
1887 * purpose: sets the unit to ERP_FAILED
1888 *
1889 */
1890void
1891zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1892{
1893 if (set_or_clear == ZFCP_SET) {
1894 atomic_set_mask(mask, &unit->status);
1895 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1896 } else {
1897 atomic_clear_mask(mask, &unit->status);
1898 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1899 atomic_set(&unit->erp_counter, 0);
1900 }
1901 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1902 }
1903 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1904 sizeof (fcp_lun_t));
1905 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1906}
1907
1908/*
1909 * function:
1910 *
1911 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1912 * used to ensure the correct locking
1913 *
1914 * returns: 0 - initiated action succesfully
1915 * <0 - failed to initiate action
1916 */
1917int
1918zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1919{
1920 int retval;
1921 unsigned long flags;
1922
1923 read_lock_irqsave(&zfcp_data.config_lock, flags);
1924 write_lock(&adapter->erp_lock);
1925 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1926 write_unlock(&adapter->erp_lock);
1927 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1928
1929 return retval;
1930}
1931
1932/*
1933 * function:
1934 *
1935 * purpose:
1936 *
1937 * returns: FIXME
1938 */
1939static int
1940zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1941{
1942 int retval = 0;
1943 struct zfcp_port *port;
1944
1945 list_for_each_entry(port, &adapter->port_list_head, list)
1946 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1947 zfcp_erp_port_reopen_internal(port, clear_mask);
1948
1949 return retval;
1950}
1951
1952/*
1953 * function:
1954 *
1955 * purpose:
1956 *
1957 * returns: FIXME
1958 */
1959static int
1960zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1961{
1962 int retval = 0;
1963 struct zfcp_unit *unit;
1964
1965 list_for_each_entry(unit, &port->unit_list_head, list)
1966 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1967
1968 return retval;
1969}
1970
1971/*
1972 * function:
1973 *
1974 * purpose: this routine executes the 'Reopen Adapter' action
1975 * (the entire action is processed synchronously, since
1976 * there are no actions which might be run concurrently
1977 * per definition)
1978 *
1979 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1980 * ZFCP_ERP_FAILED - action finished unsuccessfully
1981 */
1982static int
1983zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1984{
1985 int retval;
1986 struct zfcp_adapter *adapter = erp_action->adapter;
1987
1988 retval = zfcp_erp_adapter_strategy_close(erp_action);
1989 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1990 retval = ZFCP_ERP_EXIT;
1991 else
1992 retval = zfcp_erp_adapter_strategy_open(erp_action);
1993
1994 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1995 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1996 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1997
1998 if (retval == ZFCP_ERP_FAILED) {
1999 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
2000 "to recover itself\n",
2001 zfcp_get_busid_by_adapter(adapter));
2002 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
2003 }
2004
2005 return retval;
2006}
2007
2008/*
2009 * function:
2010 *
2011 * purpose:
2012 *
2013 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2014 * ZFCP_ERP_FAILED - action finished unsuccessfully
2015 */
2016static int
2017zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2018{
2019 int retval;
2020
2021 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2022 &erp_action->adapter->status);
2023 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2024 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2025 &erp_action->adapter->status);
2026
2027 return retval;
2028}
2029
2030/*
2031 * function:
2032 *
2033 * purpose:
2034 *
2035 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2036 * ZFCP_ERP_FAILED - action finished unsuccessfully
2037 */
2038static int
2039zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2040{
2041 int retval;
2042
2043 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2044 &erp_action->adapter->status);
2045 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2046 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2047 &erp_action->adapter->status);
2048
2049 return retval;
2050}
2051
2052/*
2053 * function: zfcp_register_adapter
2054 *
2055 * purpose: allocate the irq associated with this devno and register
2056 * the FSF adapter with the SCSI stack
2057 *
2058 * returns:
2059 */
2060static int
2061zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2062{
2063 int retval = ZFCP_ERP_SUCCEEDED;
2064
2065 if (close)
2066 goto close_only;
2067
2068 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2069 if (retval != ZFCP_ERP_SUCCEEDED)
2070 goto failed_qdio;
2071
2072 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2073 if (retval != ZFCP_ERP_SUCCEEDED)
2074 goto failed_openfcp;
2075
2076 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2077 goto out;
2078
2079 close_only:
2080 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2081 &erp_action->adapter->status);
2082
2083 failed_openfcp:
2084 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2085 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2086 failed_qdio:
2087 out:
2088 return retval;
2089}
2090
2091/*
2092 * function: zfcp_qdio_init
2093 *
2094 * purpose: setup QDIO operation for specified adapter
2095 *
2096 * returns: 0 - successful setup
2097 * !0 - failed setup
2098 */
2099int
2100zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2101{
2102 int retval;
2103 int i;
2104 volatile struct qdio_buffer_element *sbale;
2105 struct zfcp_adapter *adapter = erp_action->adapter;
2106
2107 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2108 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2109 "adapter %s\n",
2110 zfcp_get_busid_by_adapter(adapter));
2111 goto failed_sanity;
2112 }
2113
2114 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2115 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2116 "on adapter %s\n",
2117 zfcp_get_busid_by_adapter(adapter));
2118 goto failed_qdio_establish;
2119 }
2120 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2121
2122 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2123 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2124 "on adapter %s\n",
2125 zfcp_get_busid_by_adapter(adapter));
2126 goto failed_qdio_activate;
2127 }
2128 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2129
2130 /*
2131 * put buffers into response queue,
2132 */
2133 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2134 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2135 sbale->length = 0;
2136 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2137 sbale->addr = 0;
2138 }
2139
2140 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2141 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2142 zfcp_get_busid_by_adapter(adapter),
2143 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2144
2145 retval = do_QDIO(adapter->ccw_device,
2146 QDIO_FLAG_SYNC_INPUT,
2147 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2148
2149 if (retval) {
2150 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2151 retval);
2152 goto failed_do_qdio;
2153 } else {
2154 adapter->response_queue.free_index = 0;
2155 atomic_set(&adapter->response_queue.free_count, 0);
2156 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2157 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2158 }
2159 /* set index of first avalable SBALS / number of available SBALS */
2160 adapter->request_queue.free_index = 0;
2161 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2162 adapter->request_queue.distance_from_int = 0;
2163
2164 /* initialize waitqueue used to wait for free SBALs in requests queue */
2165 init_waitqueue_head(&adapter->request_wq);
2166
2167 /* ok, we did it - skip all cleanups for different failures */
2168 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2169 retval = ZFCP_ERP_SUCCEEDED;
2170 goto out;
2171
2172 failed_do_qdio:
2173 /* NOP */
2174
2175 failed_qdio_activate:
2176 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2177 while (qdio_shutdown(adapter->ccw_device,
2178 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2179 msleep(1000);
2180 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2181
2182 failed_qdio_establish:
2183 failed_sanity:
2184 retval = ZFCP_ERP_FAILED;
2185
2186 out:
2187 return retval;
2188}
2189
2190/*
2191 * function: zfcp_qdio_cleanup
2192 *
2193 * purpose: cleans up QDIO operation for the specified adapter
2194 *
2195 * returns: 0 - successful cleanup
2196 * !0 - failed cleanup
2197 */
2198int
2199zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2200{
2201 int retval = ZFCP_ERP_SUCCEEDED;
2202 int first_used;
2203 int used_count;
2204 struct zfcp_adapter *adapter = erp_action->adapter;
2205
2206 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2207 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2208 "queues on adapter %s\n",
2209 zfcp_get_busid_by_adapter(adapter));
2210 retval = ZFCP_ERP_FAILED;
2211 goto out;
2212 }
2213
2214 /*
2215 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2216 * do_QDIO won't be called while qdio_shutdown is in progress.
2217 */
2218
2219 write_lock_irq(&adapter->request_queue.queue_lock);
2220 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2221 write_unlock_irq(&adapter->request_queue.queue_lock);
2222
2223 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2224 while (qdio_shutdown(adapter->ccw_device,
2225 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2226 msleep(1000);
2227 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2228
2229 /*
2230 * First we had to stop QDIO operation.
2231 * Now it is safe to take the following actions.
2232 */
2233
2234 /* Cleanup only necessary when there are unacknowledged buffers */
2235 if (atomic_read(&adapter->request_queue.free_count)
2236 < QDIO_MAX_BUFFERS_PER_Q) {
2237 first_used = (adapter->request_queue.free_index +
2238 atomic_read(&adapter->request_queue.free_count))
2239 % QDIO_MAX_BUFFERS_PER_Q;
2240 used_count = QDIO_MAX_BUFFERS_PER_Q -
2241 atomic_read(&adapter->request_queue.free_count);
2242 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2243 first_used, used_count);
2244 }
2245 adapter->response_queue.free_index = 0;
2246 atomic_set(&adapter->response_queue.free_count, 0);
2247 adapter->request_queue.free_index = 0;
2248 atomic_set(&adapter->request_queue.free_count, 0);
2249 adapter->request_queue.distance_from_int = 0;
2250 out:
2251 return retval;
2252}
2253
2254/*
2255 * function: zfcp_fsf_init
2256 *
2257 * purpose: initializes FSF operation for the specified adapter
2258 *
2259 * returns: 0 - succesful initialization of FSF operation
2260 * !0 - failed to initialize FSF operation
2261 */
2262static int
2263zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2264{
2265 int retval;
2266
2267 /* do 'exchange configuration data' */
2268 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2269 if (retval == ZFCP_ERP_FAILED)
2270 return retval;
2271
2272 /* start the desired number of Status Reads */
2273 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2274 return retval;
2275}
2276
2277/*
2278 * function:
2279 *
2280 * purpose:
2281 *
2282 * returns:
2283 */
2284static int
2285zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2286{
2287 int retval = ZFCP_ERP_SUCCEEDED;
2288 int retries;
2289 struct zfcp_adapter *adapter = erp_action->adapter;
2290
2291 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2292 retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES;
2293
2294 do {
2295 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2296 &adapter->status);
2297 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2298 zfcp_erp_action_to_running(erp_action);
2299 zfcp_erp_timeout_init(erp_action);
2300 if (zfcp_fsf_exchange_config_data(erp_action)) {
2301 retval = ZFCP_ERP_FAILED;
2302 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2303 ZFCP_LOG_INFO("error: initiation of exchange of "
2304 "configuration data failed for "
2305 "adapter %s\n",
2306 zfcp_get_busid_by_adapter(adapter));
2307 break;
2308 }
2309 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2310 ZFCP_LOG_DEBUG("Xchange underway\n");
2311
2312 /*
2313 * Why this works:
2314 * Both the normal completion handler as well as the timeout
2315 * handler will do an 'up' when the 'exchange config data'
2316 * request completes or times out. Thus, the signal to go on
2317 * won't be lost utilizing this semaphore.
2318 * Furthermore, this 'adapter_reopen' action is
2319 * guaranteed to be the only action being there (highest action
2320 * which prevents other actions from being created).
2321 * Resulting from that, the wake signal recognized here
2322 * _must_ be the one belonging to the 'exchange config
2323 * data' request.
2324 */
2325 down(&adapter->erp_ready_sem);
2326 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2327 ZFCP_LOG_INFO("error: exchange of configuration data "
2328 "for adapter %s timed out\n",
2329 zfcp_get_busid_by_adapter(adapter));
2330 break;
2331 }
2332 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2333 &adapter->status)) {
2334 ZFCP_LOG_DEBUG("host connection still initialising... "
2335 "waiting and retrying...\n");
2336 /* sleep a little bit before retry */
2337 msleep(jiffies_to_msecs(ZFCP_EXCHANGE_CONFIG_DATA_SLEEP));
2338 }
2339 } while ((retries--) &&
2340 atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2341 &adapter->status));
2342
2343 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2344 &adapter->status)) {
2345 ZFCP_LOG_INFO("error: exchange of configuration data for "
2346 "adapter %s failed\n",
2347 zfcp_get_busid_by_adapter(adapter));
2348 retval = ZFCP_ERP_FAILED;
2349 }
2350
2351 return retval;
2352}
2353
2354/*
2355 * function:
2356 *
2357 * purpose:
2358 *
2359 * returns:
2360 */
2361static int
2362zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2363 *erp_action)
2364{
2365 int retval = ZFCP_ERP_SUCCEEDED;
2366 int temp_ret;
2367 struct zfcp_adapter *adapter = erp_action->adapter;
2368 int i;
2369
2370 adapter->status_read_failed = 0;
2371 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2372 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2373 if (temp_ret < 0) {
2374 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2375 "notification failed on adapter %s\n",
2376 zfcp_get_busid_by_adapter(adapter));
2377 retval = ZFCP_ERP_FAILED;
2378 i--;
2379 break;
2380 }
2381 }
2382
2383 return retval;
2384}
2385
2386/*
2387 * function: zfcp_fsf_cleanup
2388 *
2389 * purpose: cleanup FSF operation for specified adapter
2390 *
2391 * returns: 0 - FSF operation successfully cleaned up
2392 * !0 - failed to cleanup FSF operation for this adapter
2393 */
2394static int
2395zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2396{
2397 int retval = ZFCP_ERP_SUCCEEDED;
2398 struct zfcp_adapter *adapter = erp_action->adapter;
2399
2400 /*
2401 * wake waiting initiators of requests,
2402 * return SCSI commands (with error status),
2403 * clean up all requests (synchronously)
2404 */
2405 zfcp_fsf_req_dismiss_all(adapter);
2406 /* reset FSF request sequence number */
2407 adapter->fsf_req_seq_no = 0;
2408 /* all ports and units are closed */
2409 zfcp_erp_modify_adapter_status(adapter,
2410 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2411
2412 return retval;
2413}
2414
2415/*
2416 * function:
2417 *
2418 * purpose: this routine executes the 'Reopen Physical Port' action
2419 *
2420 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2421 * ZFCP_ERP_SUCCEEDED - action finished successfully
2422 * ZFCP_ERP_FAILED - action finished unsuccessfully
2423 */
2424static int
2425zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2426{
2427 int retval = ZFCP_ERP_FAILED;
2428 struct zfcp_port *port = erp_action->port;
2429 struct zfcp_adapter *adapter = erp_action->adapter;
2430
2431 switch (erp_action->step) {
2432
2433 /*
2434 * FIXME:
2435 * the ULP spec. begs for waiting for oustanding commands
2436 */
2437 case ZFCP_ERP_STEP_UNINITIALIZED:
2438 zfcp_erp_port_strategy_clearstati(port);
2439 /*
2440 * it would be sufficient to test only the normal open flag
2441 * since the phys. open flag cannot be set if the normal
2442 * open flag is unset - however, this is for readabilty ...
2443 */
2444 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2445 ZFCP_STATUS_COMMON_OPEN),
2446 &port->status)) {
2447 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2448 "close physical\n", port->wwpn);
2449 retval =
2450 zfcp_erp_port_forced_strategy_close(erp_action);
2451 } else
2452 retval = ZFCP_ERP_FAILED;
2453 break;
2454
2455 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2456 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2457 &port->status)) {
2458 ZFCP_LOG_DEBUG("close physical failed for port "
2459 "0x%016Lx\n", port->wwpn);
2460 retval = ZFCP_ERP_FAILED;
2461 } else
2462 retval = ZFCP_ERP_SUCCEEDED;
2463 break;
2464 }
2465
2466 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2467 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2468 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2469 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2470
2471 return retval;
2472}
2473
2474/*
2475 * function:
2476 *
2477 * purpose: this routine executes the 'Reopen Port' action
2478 *
2479 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2480 * ZFCP_ERP_SUCCEEDED - action finished successfully
2481 * ZFCP_ERP_FAILED - action finished unsuccessfully
2482 */
2483static int
2484zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2485{
2486 int retval = ZFCP_ERP_FAILED;
2487 struct zfcp_port *port = erp_action->port;
2488 struct zfcp_adapter *adapter = erp_action->adapter;
2489
2490 switch (erp_action->step) {
2491
2492 /*
2493 * FIXME:
2494 * the ULP spec. begs for waiting for oustanding commands
2495 */
2496 case ZFCP_ERP_STEP_UNINITIALIZED:
2497 zfcp_erp_port_strategy_clearstati(port);
2498 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2499 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2500 "close\n", port->wwpn);
2501 retval = zfcp_erp_port_strategy_close(erp_action);
2502 goto out;
2503 } /* else it's already closed, open it */
2504 break;
2505
2506 case ZFCP_ERP_STEP_PORT_CLOSING:
2507 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2508 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2509 port->wwpn);
2510 retval = ZFCP_ERP_FAILED;
2511 goto out;
2512 } /* else it's closed now, open it */
2513 break;
2514 }
2515 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2516 retval = ZFCP_ERP_EXIT;
2517 else
2518 retval = zfcp_erp_port_strategy_open(erp_action);
2519
2520 out:
2521 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2522 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2523 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2524 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2525
2526 return retval;
2527}
2528
2529/*
2530 * function:
2531 *
2532 * purpose:
2533 *
2534 * returns:
2535 */
2536static int
2537zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2538{
2539 int retval;
2540
2541 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2542 &erp_action->port->status))
2543 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2544 else
2545 retval = zfcp_erp_port_strategy_open_common(erp_action);
2546
2547 return retval;
2548}
2549
2550/*
2551 * function:
2552 *
2553 * purpose:
2554 *
2555 * returns:
2556 *
2557 * FIXME(design): currently only prepared for fabric (nameserver!)
2558 */
2559static int
2560zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2561{
2562 int retval = 0;
2563 struct zfcp_adapter *adapter = erp_action->adapter;
2564 struct zfcp_port *port = erp_action->port;
2565
2566 switch (erp_action->step) {
2567
2568 case ZFCP_ERP_STEP_UNINITIALIZED:
2569 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2570 case ZFCP_ERP_STEP_PORT_CLOSING:
2571 if (!(adapter->nameserver_port)) {
2572 retval = zfcp_nameserver_enqueue(adapter);
2573 if (retval != 0) {
2574 ZFCP_LOG_NORMAL("error: nameserver port "
2575 "unavailable for adapter %s\n",
2576 zfcp_get_busid_by_adapter(adapter));
2577 retval = ZFCP_ERP_FAILED;
2578 break;
2579 }
2580 }
2581 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2582 &adapter->nameserver_port->status)) {
2583 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2584 "nameserver port\n");
2585 /* nameserver port may live again */
2586 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2587 &adapter->nameserver_port->status);
2588 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2589 >= 0) {
2590 erp_action->step =
2591 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2592 retval = ZFCP_ERP_CONTINUES;
2593 } else
2594 retval = ZFCP_ERP_FAILED;
2595 break;
2596 }
2597 /* else nameserver port is already open, fall through */
2598 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2599 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2600 &adapter->nameserver_port->status)) {
2601 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2602 retval = ZFCP_ERP_FAILED;
2603 } else {
2604 ZFCP_LOG_DEBUG("nameserver port is open -> "
2605 "nameserver look-up for port 0x%016Lx\n",
2606 port->wwpn);
2607 retval = zfcp_erp_port_strategy_open_common_lookup
2608 (erp_action);
2609 }
2610 break;
2611
2612 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2613 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2614 if (atomic_test_mask
2615 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2616 ZFCP_LOG_DEBUG("nameserver look-up failed "
2617 "for port 0x%016Lx "
2618 "(misconfigured WWPN?)\n",
2619 port->wwpn);
2620 zfcp_erp_port_failed(port);
2621 retval = ZFCP_ERP_EXIT;
2622 } else {
2623 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2624 "port 0x%016Lx\n", port->wwpn);
2625 retval = ZFCP_ERP_FAILED;
2626 }
2627 } else {
2628 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2629 "trying open\n", port->wwpn, port->d_id);
2630 retval = zfcp_erp_port_strategy_open_port(erp_action);
2631 }
2632 break;
2633
2634 case ZFCP_ERP_STEP_PORT_OPENING:
2635 /* D_ID might have changed during open */
2636 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2637 ZFCP_STATUS_PORT_DID_DID),
2638 &port->status)) {
2639 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2640 retval = ZFCP_ERP_SUCCEEDED;
2641 } else {
2642 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2643 port->wwpn);
2644 retval = ZFCP_ERP_FAILED;
2645 }
2646 break;
2647
2648 default:
2649 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2650 erp_action->step);
2651 retval = ZFCP_ERP_FAILED;
2652 }
2653
2654 return retval;
2655}
2656
2657/*
2658 * function:
2659 *
2660 * purpose:
2661 *
2662 * returns:
2663 */
2664static int
2665zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2666{
2667 int retval;
2668 struct zfcp_port *port = erp_action->port;
2669
2670 switch (erp_action->step) {
2671
2672 case ZFCP_ERP_STEP_UNINITIALIZED:
2673 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2674 case ZFCP_ERP_STEP_PORT_CLOSING:
2675 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2676 port->wwpn, port->d_id);
2677 retval = zfcp_erp_port_strategy_open_port(erp_action);
2678 break;
2679
2680 case ZFCP_ERP_STEP_PORT_OPENING:
2681 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2682 ZFCP_LOG_DEBUG("WKA port is open\n");
2683 retval = ZFCP_ERP_SUCCEEDED;
2684 } else {
2685 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2686 retval = ZFCP_ERP_FAILED;
2687 }
2688 /* this is needed anyway (dont care for retval of wakeup) */
2689 ZFCP_LOG_DEBUG("continue other open port operations\n");
2690 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2691 break;
2692
2693 default:
2694 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2695 erp_action->step);
2696 retval = ZFCP_ERP_FAILED;
2697 }
2698
2699 return retval;
2700}
2701
2702/*
2703 * function:
2704 *
2705 * purpose: makes the erp thread continue with reopen (physical) port
2706 * actions which have been paused until the name server port
2707 * is opened (or failed)
2708 *
2709 * returns: 0 (a kind of void retval, its not used)
2710 */
2711static int
2712zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2713 *ns_erp_action)
2714{
2715 int retval = 0;
2716 unsigned long flags;
2717 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2718 struct zfcp_erp_action *erp_action, *tmp;
2719
2720 read_lock_irqsave(&adapter->erp_lock, flags);
2721 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2722 list) {
2723 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2724 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2725 sizeof (wwn_t));
2726 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2727 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2728 debug_event(adapter->erp_dbf, 3,
2729 &erp_action->port->wwpn, sizeof (wwn_t));
2730 if (atomic_test_mask(
2731 ZFCP_STATUS_COMMON_ERP_FAILED,
2732 &adapter->nameserver_port->status))
2733 zfcp_erp_port_failed(erp_action->port);
2734 zfcp_erp_action_ready(erp_action);
2735 }
2736 }
2737 read_unlock_irqrestore(&adapter->erp_lock, flags);
2738
2739 return retval;
2740}
2741
2742/*
2743 * function:
2744 *
2745 * purpose:
2746 *
2747 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2748 * ZFCP_ERP_FAILED - action finished unsuccessfully
2749 */
2750static int
2751zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2752{
2753 int retval;
2754 struct zfcp_adapter *adapter = erp_action->adapter;
2755 struct zfcp_port *port = erp_action->port;
2756
2757 zfcp_erp_timeout_init(erp_action);
2758 retval = zfcp_fsf_close_physical_port(erp_action);
2759 if (retval == -ENOMEM) {
2760 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2761 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2762 retval = ZFCP_ERP_NOMEM;
2763 goto out;
2764 }
2765 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2766 if (retval != 0) {
2767 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2768 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2769 /* could not send 'open', fail */
2770 retval = ZFCP_ERP_FAILED;
2771 goto out;
2772 }
2773 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2774 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2775 retval = ZFCP_ERP_CONTINUES;
2776 out:
2777 return retval;
2778}
2779
2780/*
2781 * function:
2782 *
2783 * purpose:
2784 *
2785 * returns:
2786 */
2787static int
2788zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2789{
2790 int retval = 0;
2791 struct zfcp_adapter *adapter = port->adapter;
2792
2793 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2794 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2795
2796 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2797 ZFCP_STATUS_COMMON_CLOSING |
2798 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2799 ZFCP_STATUS_PORT_DID_DID |
2800 ZFCP_STATUS_PORT_PHYS_CLOSING |
2801 ZFCP_STATUS_PORT_INVALID_WWPN,
2802 &port->status);
2803 return retval;
2804}
2805
2806/*
2807 * function:
2808 *
2809 * purpose:
2810 *
2811 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2812 * ZFCP_ERP_FAILED - action finished unsuccessfully
2813 */
2814static int
2815zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2816{
2817 int retval;
2818 struct zfcp_adapter *adapter = erp_action->adapter;
2819 struct zfcp_port *port = erp_action->port;
2820
2821 zfcp_erp_timeout_init(erp_action);
2822 retval = zfcp_fsf_close_port(erp_action);
2823 if (retval == -ENOMEM) {
2824 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2825 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2826 retval = ZFCP_ERP_NOMEM;
2827 goto out;
2828 }
2829 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2830 if (retval != 0) {
2831 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2832 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2833 /* could not send 'close', fail */
2834 retval = ZFCP_ERP_FAILED;
2835 goto out;
2836 }
2837 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2838 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2839 retval = ZFCP_ERP_CONTINUES;
2840 out:
2841 return retval;
2842}
2843
2844/*
2845 * function:
2846 *
2847 * purpose:
2848 *
2849 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2850 * ZFCP_ERP_FAILED - action finished unsuccessfully
2851 */
2852static int
2853zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2854{
2855 int retval;
2856 struct zfcp_adapter *adapter = erp_action->adapter;
2857 struct zfcp_port *port = erp_action->port;
2858
2859 zfcp_erp_timeout_init(erp_action);
2860 retval = zfcp_fsf_open_port(erp_action);
2861 if (retval == -ENOMEM) {
2862 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2863 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2864 retval = ZFCP_ERP_NOMEM;
2865 goto out;
2866 }
2867 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2868 if (retval != 0) {
2869 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2870 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2871 /* could not send 'open', fail */
2872 retval = ZFCP_ERP_FAILED;
2873 goto out;
2874 }
2875 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2876 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2877 retval = ZFCP_ERP_CONTINUES;
2878 out:
2879 return retval;
2880}
2881
2882/*
2883 * function:
2884 *
2885 * purpose:
2886 *
2887 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2888 * ZFCP_ERP_FAILED - action finished unsuccessfully
2889 */
2890static int
2891zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2892{
2893 int retval;
2894 struct zfcp_adapter *adapter = erp_action->adapter;
2895 struct zfcp_port *port = erp_action->port;
2896
2897 zfcp_erp_timeout_init(erp_action);
2898 retval = zfcp_ns_gid_pn_request(erp_action);
2899 if (retval == -ENOMEM) {
2900 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2901 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2902 retval = ZFCP_ERP_NOMEM;
2903 goto out;
2904 }
2905 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2906 if (retval != 0) {
2907 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2908 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2909 /* could not send nameserver request, fail */
2910 retval = ZFCP_ERP_FAILED;
2911 goto out;
2912 }
2913 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2914 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2915 retval = ZFCP_ERP_CONTINUES;
2916 out:
2917 return retval;
2918}
2919
2920/*
2921 * function:
2922 *
2923 * purpose: this routine executes the 'Reopen Unit' action
2924 * currently no retries
2925 *
2926 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2927 * ZFCP_ERP_SUCCEEDED - action finished successfully
2928 * ZFCP_ERP_FAILED - action finished unsuccessfully
2929 */
2930static int
2931zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2932{
2933 int retval = ZFCP_ERP_FAILED;
2934 struct zfcp_unit *unit = erp_action->unit;
2935 struct zfcp_adapter *adapter = erp_action->adapter;
2936
2937 switch (erp_action->step) {
2938
2939 /*
2940 * FIXME:
2941 * the ULP spec. begs for waiting for oustanding commands
2942 */
2943 case ZFCP_ERP_STEP_UNINITIALIZED:
2944 zfcp_erp_unit_strategy_clearstati(unit);
2945 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2946 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2947 "trying close\n", unit->fcp_lun);
2948 retval = zfcp_erp_unit_strategy_close(erp_action);
2949 break;
2950 }
2951 /* else it's already closed, fall through */
2952 case ZFCP_ERP_STEP_UNIT_CLOSING:
2953 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2954 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2955 unit->fcp_lun);
2956 retval = ZFCP_ERP_FAILED;
2957 } else {
2958 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2959 retval = ZFCP_ERP_EXIT;
2960 else {
2961 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2962 "trying open\n", unit->fcp_lun);
2963 retval =
2964 zfcp_erp_unit_strategy_open(erp_action);
2965 }
2966 }
2967 break;
2968
2969 case ZFCP_ERP_STEP_UNIT_OPENING:
2970 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2971 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2972 unit->fcp_lun);
2973 retval = ZFCP_ERP_SUCCEEDED;
2974 } else {
2975 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2976 unit->fcp_lun);
2977 retval = ZFCP_ERP_FAILED;
2978 }
2979 break;
2980 }
2981
2982 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2983 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2984 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2985 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2986 return retval;
2987}
2988
2989/*
2990 * function:
2991 *
2992 * purpose:
2993 *
2994 * returns:
2995 */
2996static int
2997zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2998{
2999 int retval = 0;
3000 struct zfcp_adapter *adapter = unit->port->adapter;
3001
3002 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3003 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3004
3005 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3006 ZFCP_STATUS_COMMON_CLOSING |
3007 ZFCP_STATUS_COMMON_ACCESS_DENIED |
3008 ZFCP_STATUS_UNIT_SHARED |
3009 ZFCP_STATUS_UNIT_READONLY,
3010 &unit->status);
3011
3012 return retval;
3013}
3014
3015/*
3016 * function:
3017 *
3018 * purpose:
3019 *
3020 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3021 * ZFCP_ERP_FAILED - action finished unsuccessfully
3022 */
3023static int
3024zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3025{
3026 int retval;
3027 struct zfcp_adapter *adapter = erp_action->adapter;
3028 struct zfcp_unit *unit = erp_action->unit;
3029
3030 zfcp_erp_timeout_init(erp_action);
3031 retval = zfcp_fsf_close_unit(erp_action);
3032 if (retval == -ENOMEM) {
3033 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3034 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3035 sizeof (fcp_lun_t));
3036 retval = ZFCP_ERP_NOMEM;
3037 goto out;
3038 }
3039 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3040 if (retval != 0) {
3041 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3042 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3043 sizeof (fcp_lun_t));
3044 /* could not send 'close', fail */
3045 retval = ZFCP_ERP_FAILED;
3046 goto out;
3047 }
3048 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3049 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3050 retval = ZFCP_ERP_CONTINUES;
3051
3052 out:
3053 return retval;
3054}
3055
3056/*
3057 * function:
3058 *
3059 * purpose:
3060 *
3061 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3062 * ZFCP_ERP_FAILED - action finished unsuccessfully
3063 */
3064static int
3065zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3066{
3067 int retval;
3068 struct zfcp_adapter *adapter = erp_action->adapter;
3069 struct zfcp_unit *unit = erp_action->unit;
3070
3071 zfcp_erp_timeout_init(erp_action);
3072 retval = zfcp_fsf_open_unit(erp_action);
3073 if (retval == -ENOMEM) {
3074 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3075 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3076 sizeof (fcp_lun_t));
3077 retval = ZFCP_ERP_NOMEM;
3078 goto out;
3079 }
3080 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3081 if (retval != 0) {
3082 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3083 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3084 sizeof (fcp_lun_t));
3085 /* could not send 'open', fail */
3086 retval = ZFCP_ERP_FAILED;
3087 goto out;
3088 }
3089 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3090 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3091 retval = ZFCP_ERP_CONTINUES;
3092 out:
3093 return retval;
3094}
3095
3096/*
3097 * function:
3098 *
3099 * purpose:
3100 *
3101 * returns:
3102 */
3103static inline void
3104zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3105{
3106 init_timer(&erp_action->timer);
3107 erp_action->timer.function = zfcp_erp_timeout_handler;
3108 erp_action->timer.data = (unsigned long) erp_action;
3109 /* jiffies will be added in zfcp_fsf_req_send */
3110 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3111}
3112
3113/*
3114 * function:
3115 *
3116 * purpose: enqueue the specified error recovery action, if needed
3117 *
3118 * returns:
3119 */
3120static int
3121zfcp_erp_action_enqueue(int action,
3122 struct zfcp_adapter *adapter,
3123 struct zfcp_port *port, struct zfcp_unit *unit)
3124{
3125 int retval = 1;
3126 struct zfcp_erp_action *erp_action = NULL;
3127 int stronger_action = 0;
3128 u32 status = 0;
3129
3130 /*
3131 * We need some rules here which check whether we really need
3132 * this action or whether we should just drop it.
3133 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3134 * 'Reopen Unit' request for an associated unit since we can't
3135 * satisfy this request now. A 'Reopen Port' action will trigger
3136 * 'Reopen Unit' actions when it completes.
3137 * Thus, there are only actions in the queue which can immediately be
3138 * executed. This makes the processing of the action queue more
3139 * efficient.
3140 */
3141
3142 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3143 &adapter->status))
3144 return -EIO;
3145
3146 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3147 /* check whether we really need this */
3148 switch (action) {
3149 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3150 if (atomic_test_mask
3151 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3152 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3153 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3154 sizeof (wwn_t));
3155 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3156 sizeof (fcp_lun_t));
3157 goto out;
3158 }
3159 if (!atomic_test_mask
3160 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3161 atomic_test_mask
3162 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3163 goto out;
3164 }
3165 if (!atomic_test_mask
3166 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3167 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3168 unit = NULL;
3169 }
3170 /* fall through !!! */
3171
3172 case ZFCP_ERP_ACTION_REOPEN_PORT:
3173 if (atomic_test_mask
3174 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3175 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3176 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3177 sizeof (wwn_t));
3178 goto out;
3179 }
3180 /* fall through !!! */
3181
3182 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3183 if (atomic_test_mask
3184 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3185 && port->erp_action.action ==
3186 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3187 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3188 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3189 sizeof (wwn_t));
3190 goto out;
3191 }
3192 if (!atomic_test_mask
3193 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3194 atomic_test_mask
3195 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3196 goto out;
3197 }
3198 if (!atomic_test_mask
3199 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3200 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3201 port = NULL;
3202 }
3203 /* fall through !!! */
3204
3205 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3206 if (atomic_test_mask
3207 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3208 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3209 goto out;
3210 }
3211 break;
3212
3213 default:
3214 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3215 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3216 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3217 "on adapter %s (action=%d)\n",
3218 zfcp_get_busid_by_adapter(adapter), action);
3219 goto out;
3220 }
3221
3222 /* check whether we need something stronger first */
3223 if (stronger_action) {
3224 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3225 debug_event(adapter->erp_dbf, 4, &stronger_action,
3226 sizeof (int));
3227 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3228 "erp action %d on adapter %s\n",
3229 stronger_action, action,
3230 zfcp_get_busid_by_adapter(adapter));
3231 action = stronger_action;
3232 }
3233
3234 /* mark adapter to have some error recovery pending */
3235 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3236
3237 /* setup error recovery action */
3238 switch (action) {
3239
3240 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3241 zfcp_unit_get(unit);
3242 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3243 erp_action = &unit->erp_action;
3244 if (!atomic_test_mask
3245 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3246 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3247 break;
3248
3249 case ZFCP_ERP_ACTION_REOPEN_PORT:
3250 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3251 zfcp_port_get(port);
3252 zfcp_erp_action_dismiss_port(port);
3253 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3254 erp_action = &port->erp_action;
3255 if (!atomic_test_mask
3256 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3257 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3258 break;
3259
3260 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3261 zfcp_adapter_get(adapter);
3262 zfcp_erp_action_dismiss_adapter(adapter);
3263 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3264 erp_action = &adapter->erp_action;
3265 if (!atomic_test_mask
3266 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3267 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3268 break;
3269 }
3270
3271 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3272
3273 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3274 erp_action->adapter = adapter;
3275 erp_action->port = port;
3276 erp_action->unit = unit;
3277 erp_action->action = action;
3278 erp_action->status = status;
3279
3280 ++adapter->erp_total_count;
3281
3282 /* finally put it into 'ready' queue and kick erp thread */
3283 list_add(&erp_action->list, &adapter->erp_ready_head);
3284 up(&adapter->erp_ready_sem);
3285 retval = 0;
3286 out:
3287 return retval;
3288}
3289
3290/*
3291 * function:
3292 *
3293 * purpose:
3294 *
3295 * returns:
3296 */
3297static int
3298zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3299{
3300 int retval = 0;
3301 struct zfcp_adapter *adapter = erp_action->adapter;
3302
3303 --adapter->erp_total_count;
3304 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3305 --adapter->erp_low_mem_count;
3306 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3307 }
3308
3309 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3310 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3311 list_del(&erp_action->list);
3312 switch (erp_action->action) {
3313 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3314 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3315 &erp_action->unit->status);
3316 break;
3317 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3318 case ZFCP_ERP_ACTION_REOPEN_PORT:
3319 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3320 &erp_action->port->status);
3321 break;
3322 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3323 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3324 &erp_action->adapter->status);
3325 break;
3326 default:
3327 /* bug */
3328 break;
3329 }
3330 return retval;
3331}
3332
3333/**
3334 * zfcp_erp_action_cleanup
3335 *
3336 * Register unit with scsi stack if appropiate and fix reference counts.
3337 * Note: Temporary units are not registered with scsi stack.
3338 */
3339static void
3340zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3341 struct zfcp_port *port, struct zfcp_unit *unit,
3342 int result)
3343{
3344 switch (action) {
3345 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3346 if ((result == ZFCP_ERP_SUCCEEDED)
3347 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3348 &unit->status))
3349 && (!unit->device))
3350 scsi_add_device(unit->port->adapter->scsi_host, 0,
3351 unit->port->scsi_id, unit->scsi_lun);
3352 zfcp_unit_put(unit);
3353 break;
3354 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3355 case ZFCP_ERP_ACTION_REOPEN_PORT:
3356 zfcp_port_put(port);
3357 break;
3358 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3359 zfcp_adapter_put(adapter);
3360 break;
3361 default:
3362 break;
3363 }
3364}
3365
3366
3367/*
3368 * function:
3369 *
3370 * purpose:
3371 *
3372 * returns: FIXME
3373 */
3374static int
3375zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3376{
3377 int retval = 0;
3378 struct zfcp_port *port;
3379
3380 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3381 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3382 zfcp_erp_action_dismiss(&adapter->erp_action);
3383 else
3384 list_for_each_entry(port, &adapter->port_list_head, list)
3385 zfcp_erp_action_dismiss_port(port);
3386
3387 return retval;
3388}
3389
3390/*
3391 * function:
3392 *
3393 * purpose:
3394 *
3395 * returns: FIXME
3396 */
3397static int
3398zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3399{
3400 int retval = 0;
3401 struct zfcp_unit *unit;
3402 struct zfcp_adapter *adapter = port->adapter;
3403
3404 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3405 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3406 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3407 zfcp_erp_action_dismiss(&port->erp_action);
3408 else
3409 list_for_each_entry(unit, &port->unit_list_head, list)
3410 zfcp_erp_action_dismiss_unit(unit);
3411
3412 return retval;
3413}
3414
3415/*
3416 * function:
3417 *
3418 * purpose:
3419 *
3420 * returns: FIXME
3421 */
3422static int
3423zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3424{
3425 int retval = 0;
3426 struct zfcp_adapter *adapter = unit->port->adapter;
3427
3428 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3429 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3430 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3431 zfcp_erp_action_dismiss(&unit->erp_action);
3432
3433 return retval;
3434}
3435
3436/*
3437 * function:
3438 *
3439 * purpose: moves erp_action to 'erp running list'
3440 *
3441 * returns:
3442 */
3443static inline void
3444zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3445{
3446 struct zfcp_adapter *adapter = erp_action->adapter;
3447
3448 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3449 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3450 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3451}
3452
3453/*
3454 * function:
3455 *
3456 * purpose: moves erp_action to 'erp ready list'
3457 *
3458 * returns:
3459 */
3460static inline void
3461zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3462{
3463 struct zfcp_adapter *adapter = erp_action->adapter;
3464
3465 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3466 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3467 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3468}
3469
3470/*
3471 * function: zfcp_erp_port_access_denied
3472 *
3473 * purpose:
3474 */
3475void
3476zfcp_erp_port_access_denied(struct zfcp_port *port)
3477{
3478 struct zfcp_adapter *adapter = port->adapter;
3479 unsigned long flags;
3480
3481 debug_text_event(adapter->erp_dbf, 3, "p_access_block");
3482 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3483 read_lock_irqsave(&zfcp_data.config_lock, flags);
3484 zfcp_erp_modify_port_status(port, ZFCP_STATUS_COMMON_ERP_FAILED |
3485 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3486 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3487}
3488
3489/*
3490 * function: zfcp_erp_unit_access_denied
3491 *
3492 * purpose:
3493 */
3494void
3495zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3496{
3497 struct zfcp_adapter *adapter = unit->port->adapter;
3498
3499 debug_text_event(adapter->erp_dbf, 3, "u_access_block");
3500 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3501 zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_ERP_FAILED |
3502 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3503}
3504
3505/*
3506 * function: zfcp_erp_adapter_access_changed
3507 *
3508 * purpose:
3509 */
3510void
3511zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3512{
3513 struct zfcp_port *port;
3514 unsigned long flags;
3515
3516 debug_text_event(adapter->erp_dbf, 3, "a_access_unblock");
3517 debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
3518
3519 zfcp_erp_port_access_changed(adapter->nameserver_port);
3520 read_lock_irqsave(&zfcp_data.config_lock, flags);
3521 list_for_each_entry(port, &adapter->port_list_head, list)
3522 if (port != adapter->nameserver_port)
3523 zfcp_erp_port_access_changed(port);
3524 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3525}
3526
3527/*
3528 * function: zfcp_erp_port_access_changed
3529 *
3530 * purpose:
3531 */
3532void
3533zfcp_erp_port_access_changed(struct zfcp_port *port)
3534{
3535 struct zfcp_adapter *adapter = port->adapter;
3536 struct zfcp_unit *unit;
3537
3538 debug_text_event(adapter->erp_dbf, 3, "p_access_unblock");
3539 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3540
3541 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3542 &port->status)) {
3543 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3544 list_for_each_entry(unit, &port->unit_list_head, list)
3545 zfcp_erp_unit_access_changed(unit);
3546 return;
3547 }
3548
3549 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3550 "(due to ACT update)\n",
3551 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3552 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3553 ZFCP_LOG_NORMAL("failed reopen of port"
3554 "(adapter %s, wwpn=0x%016Lx)\n",
3555 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3556}
3557
3558/*
3559 * function: zfcp_erp_unit_access_changed
3560 *
3561 * purpose:
3562 */
3563void
3564zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3565{
3566 struct zfcp_adapter *adapter = unit->port->adapter;
3567
3568 debug_text_event(adapter->erp_dbf, 3, "u_access_unblock");
3569 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3570
3571 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status))
3572 return;
3573
3574 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3575 " on adapter %s (due to ACT update)\n",
3576 unit->fcp_lun, unit->port->wwpn,
3577 zfcp_get_busid_by_adapter(adapter));
3578 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3579 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3580 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3581 zfcp_get_busid_by_adapter(adapter),
3582 unit->port->wwpn, unit->fcp_lun);
3583}
3584
3585#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
new file mode 100644
index 000000000000..d5fd43352071
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -0,0 +1,186 @@
1/*
2 *
3 * linux/drivers/s390/scsi/zfcp_ext.h
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
32#ifndef ZFCP_EXT_H
33#define ZFCP_EXT_H
34
35#define ZFCP_EXT_REVISION "$Revision: 1.62 $"
36
37#include "zfcp_def.h"
38
39extern struct zfcp_data zfcp_data;
40
41/******************************** SYSFS *************************************/
42extern int zfcp_sysfs_driver_create_files(struct device_driver *);
43extern void zfcp_sysfs_driver_remove_files(struct device_driver *);
44extern int zfcp_sysfs_adapter_create_files(struct device *);
45extern void zfcp_sysfs_adapter_remove_files(struct device *);
46extern int zfcp_sysfs_port_create_files(struct device *, u32);
47extern void zfcp_sysfs_port_remove_files(struct device *, u32);
48extern int zfcp_sysfs_unit_create_files(struct device *);
49extern void zfcp_sysfs_unit_remove_files(struct device *);
50extern void zfcp_sysfs_port_release(struct device *);
51extern void zfcp_sysfs_unit_release(struct device *);
52
53/**************************** CONFIGURATION *********************************/
54extern struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *, fcp_lun_t);
55extern struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *, wwn_t);
56extern struct zfcp_port *zfcp_get_port_by_did(struct zfcp_adapter *, u32);
57struct zfcp_adapter *zfcp_get_adapter_by_busid(char *);
58extern struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *);
59extern int zfcp_adapter_debug_register(struct zfcp_adapter *);
60extern void zfcp_adapter_dequeue(struct zfcp_adapter *);
61extern void zfcp_adapter_debug_unregister(struct zfcp_adapter *);
62extern struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *, wwn_t,
63 u32, u32);
64extern void zfcp_port_dequeue(struct zfcp_port *);
65extern struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *, fcp_lun_t);
66extern void zfcp_unit_dequeue(struct zfcp_unit *);
67
68/******************************* S/390 IO ************************************/
69extern int zfcp_ccw_register(void);
70extern void zfcp_ccw_unregister(void);
71
72extern void zfcp_qdio_zero_sbals(struct qdio_buffer **, int, int);
73extern int zfcp_qdio_allocate(struct zfcp_adapter *);
74extern int zfcp_qdio_allocate_queues(struct zfcp_adapter *);
75extern void zfcp_qdio_free_queues(struct zfcp_adapter *);
76extern int zfcp_qdio_determine_pci(struct zfcp_qdio_queue *,
77 struct zfcp_fsf_req *);
78extern int zfcp_qdio_reqid_check(struct zfcp_adapter *, void *);
79
80extern volatile struct qdio_buffer_element *zfcp_qdio_sbale_req
81 (struct zfcp_fsf_req *, int, int);
82extern volatile struct qdio_buffer_element *zfcp_qdio_sbale_curr
83 (struct zfcp_fsf_req *);
84extern int zfcp_qdio_sbals_from_sg
85 (struct zfcp_fsf_req *, unsigned long, struct scatterlist *, int, int);
86extern int zfcp_qdio_sbals_from_scsicmnd
87 (struct zfcp_fsf_req *, unsigned long, struct scsi_cmnd *);
88
89
90/******************************** FSF ****************************************/
91extern int zfcp_fsf_open_port(struct zfcp_erp_action *);
92extern int zfcp_fsf_close_port(struct zfcp_erp_action *);
93extern int zfcp_fsf_close_physical_port(struct zfcp_erp_action *);
94
95extern int zfcp_fsf_open_unit(struct zfcp_erp_action *);
96extern int zfcp_fsf_close_unit(struct zfcp_erp_action *);
97
98extern int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *);
99extern int zfcp_fsf_exchange_port_data(struct zfcp_adapter *,
100 struct fsf_qtcb_bottom_port *);
101extern int zfcp_fsf_control_file(struct zfcp_adapter *, struct zfcp_fsf_req **,
102 u32, u32, struct zfcp_sg_list *);
103extern void zfcp_fsf_request_timeout_handler(unsigned long);
104extern void zfcp_fsf_scsi_er_timeout_handler(unsigned long);
105extern int zfcp_fsf_req_dismiss_all(struct zfcp_adapter *);
106extern int zfcp_fsf_status_read(struct zfcp_adapter *, int);
107extern int zfcp_fsf_req_create(struct zfcp_adapter *, u32, int, mempool_t *,
108 unsigned long *, struct zfcp_fsf_req **);
109extern int zfcp_fsf_send_ct(struct zfcp_send_ct *, mempool_t *,
110 struct zfcp_erp_action *);
111extern int zfcp_fsf_send_els(struct zfcp_send_els *);
112extern int zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *, int, u32 *);
113extern int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *,
114 struct zfcp_unit *,
115 struct scsi_cmnd *,
116 struct timer_list*, int);
117extern int zfcp_fsf_req_complete(struct zfcp_fsf_req *);
118extern void zfcp_fsf_incoming_els(struct zfcp_fsf_req *);
119extern void zfcp_fsf_req_cleanup(struct zfcp_fsf_req *);
120extern struct zfcp_fsf_req *zfcp_fsf_send_fcp_command_task_management(
121 struct zfcp_adapter *, struct zfcp_unit *, u8, int);
122extern struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(
123 unsigned long, struct zfcp_adapter *, struct zfcp_unit *, int);
124
125/******************************* FC/FCP **************************************/
126extern int zfcp_nameserver_enqueue(struct zfcp_adapter *);
127extern int zfcp_ns_gid_pn_request(struct zfcp_erp_action *);
128extern int zfcp_check_ct_response(struct ct_hdr *);
129extern int zfcp_handle_els_rjt(u32, struct zfcp_ls_rjt_par *);
130
131/******************************* SCSI ****************************************/
132extern int zfcp_adapter_scsi_register(struct zfcp_adapter *);
133extern void zfcp_adapter_scsi_unregister(struct zfcp_adapter *);
134extern void zfcp_set_fcp_dl(struct fcp_cmnd_iu *, fcp_dl_t);
135extern char *zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *);
136extern void set_host_byte(u32 *, char);
137extern void set_driver_byte(u32 *, char);
138extern char *zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *);
139extern void zfcp_fsf_start_scsi_er_timer(struct zfcp_adapter *);
140extern fcp_dl_t zfcp_get_fcp_dl(struct fcp_cmnd_iu *);
141
142extern int zfcp_scsi_command_async(struct zfcp_adapter *,struct zfcp_unit *,
143 struct scsi_cmnd *, struct timer_list *);
144extern int zfcp_scsi_command_sync(struct zfcp_unit *, struct scsi_cmnd *,
145 struct timer_list *);
146extern struct scsi_transport_template *zfcp_transport_template;
147extern struct fc_function_template zfcp_transport_functions;
148
149/******************************** ERP ****************************************/
150extern void zfcp_erp_modify_adapter_status(struct zfcp_adapter *, u32, int);
151extern int zfcp_erp_adapter_reopen(struct zfcp_adapter *, int);
152extern int zfcp_erp_adapter_shutdown(struct zfcp_adapter *, int);
153extern void zfcp_erp_adapter_failed(struct zfcp_adapter *);
154
155extern void zfcp_erp_modify_port_status(struct zfcp_port *, u32, int);
156extern int zfcp_erp_port_reopen(struct zfcp_port *, int);
157extern int zfcp_erp_port_shutdown(struct zfcp_port *, int);
158extern int zfcp_erp_port_forced_reopen(struct zfcp_port *, int);
159extern void zfcp_erp_port_failed(struct zfcp_port *);
160extern int zfcp_erp_port_reopen_all(struct zfcp_adapter *, int);
161
162extern void zfcp_erp_modify_unit_status(struct zfcp_unit *, u32, int);
163extern int zfcp_erp_unit_reopen(struct zfcp_unit *, int);
164extern int zfcp_erp_unit_shutdown(struct zfcp_unit *, int);
165extern void zfcp_erp_unit_failed(struct zfcp_unit *);
166
167extern int zfcp_erp_thread_setup(struct zfcp_adapter *);
168extern int zfcp_erp_thread_kill(struct zfcp_adapter *);
169extern int zfcp_erp_wait(struct zfcp_adapter *);
170extern int zfcp_erp_async_handler(struct zfcp_erp_action *, unsigned long);
171
172extern int zfcp_test_link(struct zfcp_port *);
173
174extern void zfcp_erp_port_access_denied(struct zfcp_port *);
175extern void zfcp_erp_unit_access_denied(struct zfcp_unit *);
176extern void zfcp_erp_adapter_access_changed(struct zfcp_adapter *);
177extern void zfcp_erp_port_access_changed(struct zfcp_port *);
178extern void zfcp_erp_unit_access_changed(struct zfcp_unit *);
179
180/******************************** AUX ****************************************/
181extern void zfcp_cmd_dbf_event_fsf(const char *, struct zfcp_fsf_req *,
182 void *, int);
183extern void zfcp_cmd_dbf_event_scsi(const char *, struct scsi_cmnd *);
184extern void zfcp_in_els_dbf_event(struct zfcp_adapter *, const char *,
185 struct fsf_status_read_buffer *, int);
186#endif /* ZFCP_EXT_H */
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
new file mode 100644
index 000000000000..578b9fbe5206
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -0,0 +1,5087 @@
1/*
2 *
3 * linux/drivers/s390/scsi/zfcp_fsf.c
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 * Volker Sameske <sameske@de.ibm.com>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#define ZFCP_FSF_C_REVISION "$Revision: 1.92 $"
34
35#include "zfcp_ext.h"
36
37static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
38static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
39static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
40static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
41static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
42static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
43static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
44static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
45static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
46static int zfcp_fsf_send_fcp_command_task_management_handler(
47 struct zfcp_fsf_req *);
48static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
49static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
50static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
51static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
52static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
53static inline int zfcp_fsf_req_sbal_check(
54 unsigned long *, struct zfcp_qdio_queue *, int);
55static inline int zfcp_use_one_sbal(
56 struct scatterlist *, int, struct scatterlist *, int);
57static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
58static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
59static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
60static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
61static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
62static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
63static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
64static void zfcp_fsf_req_free(struct zfcp_fsf_req *);
65
66/* association between FSF command and FSF QTCB type */
67static u32 fsf_qtcb_type[] = {
68 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
69 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
76 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
77 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
78 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
79 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
80 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
81};
82
83static const char zfcp_act_subtable_type[5][8] = {
84 "unknown", "OS", "WWPN", "DID", "LUN"
85};
86
87/****************************************************************/
88/*************** FSF related Functions *************************/
89/****************************************************************/
90
91#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
92
93/*
94 * function: zfcp_fsf_req_alloc
95 *
96 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
97 * unsolicited requests) via helper functions
98 * Does some initial fsf request set-up.
99 *
100 * returns: pointer to allocated fsf_req if successfull
101 * NULL otherwise
102 *
103 * locks: none
104 *
105 */
106static struct zfcp_fsf_req *
107zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
108{
109 size_t size;
110 void *ptr;
111 struct zfcp_fsf_req *fsf_req = NULL;
112
113 if (req_flags & ZFCP_REQ_NO_QTCB)
114 size = sizeof(struct zfcp_fsf_req);
115 else
116 size = sizeof(struct zfcp_fsf_req_pool_element);
117
118 if (likely(pool != NULL))
119 ptr = mempool_alloc(pool, GFP_ATOMIC);
120 else
121 ptr = kmalloc(size, GFP_ATOMIC);
122
123 if (unlikely(NULL == ptr))
124 goto out;
125
126 memset(ptr, 0, size);
127
128 if (req_flags & ZFCP_REQ_NO_QTCB) {
129 fsf_req = (struct zfcp_fsf_req *) ptr;
130 } else {
131 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
132 fsf_req->qtcb =
133 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
134 }
135
136 fsf_req->pool = pool;
137
138 out:
139 return fsf_req;
140}
141
142/*
143 * function: zfcp_fsf_req_free
144 *
145 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
146 * returns it into the pool via helper functions.
147 *
148 * returns: sod all
149 *
150 * locks: none
151 */
152static void
153zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
154{
155 if (likely(fsf_req->pool != NULL))
156 mempool_free(fsf_req, fsf_req->pool);
157 else
158 kfree(fsf_req);
159}
160
161/*
162 * function:
163 *
164 * purpose:
165 *
166 * returns:
167 *
168 * note: qdio queues shall be down (no ongoing inbound processing)
169 */
170int
171zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
172{
173 int retval = 0;
174 struct zfcp_fsf_req *fsf_req, *tmp;
175
176 list_for_each_entry_safe(fsf_req, tmp, &adapter->fsf_req_list_head,
177 list)
178 zfcp_fsf_req_dismiss(fsf_req);
179 /* wait_event_timeout? */
180 while (!list_empty(&adapter->fsf_req_list_head)) {
181 ZFCP_LOG_DEBUG("fsf req list of adapter %s not yet empty\n",
182 zfcp_get_busid_by_adapter(adapter));
183 /* wait for woken intiators to clean up their requests */
184 msleep(jiffies_to_msecs(ZFCP_FSFREQ_CLEANUP_TIMEOUT));
185 }
186
187 /* consistency check */
188 if (atomic_read(&adapter->fsf_reqs_active)) {
189 ZFCP_LOG_NORMAL("bug: There are still %d FSF requests pending "
190 "on adapter %s after cleanup.\n",
191 atomic_read(&adapter->fsf_reqs_active),
192 zfcp_get_busid_by_adapter(adapter));
193 atomic_set(&adapter->fsf_reqs_active, 0);
194 }
195
196 return retval;
197}
198
199/*
200 * function:
201 *
202 * purpose:
203 *
204 * returns:
205 */
206static void
207zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
208{
209 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
210 zfcp_fsf_req_complete(fsf_req);
211}
212
213/*
214 * function: zfcp_fsf_req_complete
215 *
216 * purpose: Updates active counts and timers for openfcp-reqs
217 * May cleanup request after req_eval returns
218 *
219 * returns: 0 - success
220 * !0 - failure
221 *
222 * context:
223 */
224int
225zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
226{
227 int retval = 0;
228 int cleanup;
229 struct zfcp_adapter *adapter = fsf_req->adapter;
230
231 /* do some statistics */
232 atomic_dec(&adapter->fsf_reqs_active);
233
234 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
235 ZFCP_LOG_DEBUG("Status read response received\n");
236 /*
237 * Note: all cleanup handling is done in the callchain of
238 * the function call-chain below.
239 */
240 zfcp_fsf_status_read_handler(fsf_req);
241 goto out;
242 } else
243 zfcp_fsf_protstatus_eval(fsf_req);
244
245 /*
246 * fsf_req may be deleted due to waking up functions, so
247 * cleanup is saved here and used later
248 */
249 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
250 cleanup = 1;
251 else
252 cleanup = 0;
253
254 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
255
256 /* cleanup request if requested by initiator */
257 if (likely(cleanup)) {
258 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
259 /*
260 * lock must not be held here since it will be
261 * grabed by the called routine, too
262 */
263 zfcp_fsf_req_cleanup(fsf_req);
264 } else {
265 /* notify initiator waiting for the requests completion */
266 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
267 /*
268 * FIXME: Race! We must not access fsf_req here as it might have been
269 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
270 * flag. It's an improbable case. But, we have the same paranoia for
271 * the cleanup flag already.
272 * Might better be handled using complete()?
273 * (setting the flag and doing wakeup ought to be atomic
274 * with regard to checking the flag as long as waitqueue is
275 * part of the to be released structure)
276 */
277 wake_up(&fsf_req->completion_wq);
278 }
279
280 out:
281 return retval;
282}
283
284/*
285 * function: zfcp_fsf_protstatus_eval
286 *
287 * purpose: evaluates the QTCB of the finished FSF request
288 * and initiates appropriate actions
289 * (usually calling FSF command specific handlers)
290 *
291 * returns:
292 *
293 * context:
294 *
295 * locks:
296 */
297static int
298zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
299{
300 int retval = 0;
301 struct zfcp_adapter *adapter = fsf_req->adapter;
302
303 ZFCP_LOG_DEBUG("QTCB is at %p\n", fsf_req->qtcb);
304
305 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
306 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
307 (unsigned long) fsf_req);
308 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
309 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
310 zfcp_cmd_dbf_event_fsf("dismiss", fsf_req, NULL, 0);
311 goto skip_protstatus;
312 }
313
314 /* log additional information provided by FSF (if any) */
315 if (unlikely(fsf_req->qtcb->header.log_length)) {
316 /* do not trust them ;-) */
317 if (fsf_req->qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
318 ZFCP_LOG_NORMAL
319 ("bug: ULP (FSF logging) log data starts "
320 "beyond end of packet header. Ignored. "
321 "(start=%i, size=%li)\n",
322 fsf_req->qtcb->header.log_start,
323 sizeof(struct fsf_qtcb));
324 goto forget_log;
325 }
326 if ((size_t) (fsf_req->qtcb->header.log_start +
327 fsf_req->qtcb->header.log_length)
328 > sizeof(struct fsf_qtcb)) {
329 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
330 "beyond end of packet header. Ignored. "
331 "(start=%i, length=%i, size=%li)\n",
332 fsf_req->qtcb->header.log_start,
333 fsf_req->qtcb->header.log_length,
334 sizeof(struct fsf_qtcb));
335 goto forget_log;
336 }
337 ZFCP_LOG_TRACE("ULP log data: \n");
338 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
339 (char *) fsf_req->qtcb +
340 fsf_req->qtcb->header.log_start,
341 fsf_req->qtcb->header.log_length);
342 }
343 forget_log:
344
345 /* evaluate FSF Protocol Status */
346 switch (fsf_req->qtcb->prefix.prot_status) {
347
348 case FSF_PROT_GOOD:
349 ZFCP_LOG_TRACE("FSF_PROT_GOOD\n");
350 break;
351
352 case FSF_PROT_FSF_STATUS_PRESENTED:
353 ZFCP_LOG_TRACE("FSF_PROT_FSF_STATUS_PRESENTED\n");
354 break;
355
356 case FSF_PROT_QTCB_VERSION_ERROR:
357 ZFCP_LOG_FLAGS(0, "FSF_PROT_QTCB_VERSION_ERROR\n");
358 ZFCP_LOG_NORMAL("error: The adapter %s contains "
359 "microcode of version 0x%x, the device driver "
360 "only supports 0x%x. Aborting.\n",
361 zfcp_get_busid_by_adapter(adapter),
362 fsf_req->qtcb->prefix.prot_status_qual.
363 version_error.fsf_version, ZFCP_QTCB_VERSION);
364 /* stop operation for this adapter */
365 debug_text_exception(adapter->erp_dbf, 0, "prot_ver_err");
366 zfcp_erp_adapter_shutdown(adapter, 0);
367 zfcp_cmd_dbf_event_fsf("qverserr", fsf_req,
368 &fsf_req->qtcb->prefix.prot_status_qual,
369 sizeof (union fsf_prot_status_qual));
370 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
371 break;
372
373 case FSF_PROT_SEQ_NUMB_ERROR:
374 ZFCP_LOG_FLAGS(0, "FSF_PROT_SEQ_NUMB_ERROR\n");
375 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
376 "driver (0x%x) and adapter %s (0x%x). "
377 "Restarting all operations on this adapter.\n",
378 fsf_req->qtcb->prefix.req_seq_no,
379 zfcp_get_busid_by_adapter(adapter),
380 fsf_req->qtcb->prefix.prot_status_qual.
381 sequence_error.exp_req_seq_no);
382 debug_text_exception(adapter->erp_dbf, 0, "prot_seq_err");
383 /* restart operation on this adapter */
384 zfcp_erp_adapter_reopen(adapter, 0);
385 zfcp_cmd_dbf_event_fsf("seqnoerr", fsf_req,
386 &fsf_req->qtcb->prefix.prot_status_qual,
387 sizeof (union fsf_prot_status_qual));
388 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
389 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
390 break;
391
392 case FSF_PROT_UNSUPP_QTCB_TYPE:
393 ZFCP_LOG_FLAGS(0, "FSF_PROT_UNSUP_QTCB_TYPE\n");
394 ZFCP_LOG_NORMAL("error: Packet header type used by the "
395 "device driver is incompatible with "
396 "that used on adapter %s. "
397 "Stopping all operations on this adapter.\n",
398 zfcp_get_busid_by_adapter(adapter));
399 debug_text_exception(adapter->erp_dbf, 0, "prot_unsup_qtcb");
400 zfcp_erp_adapter_shutdown(adapter, 0);
401 zfcp_cmd_dbf_event_fsf("unsqtcbt", fsf_req,
402 &fsf_req->qtcb->prefix.prot_status_qual,
403 sizeof (union fsf_prot_status_qual));
404 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
405 break;
406
407 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
408 ZFCP_LOG_FLAGS(1, "FSF_PROT_HOST_CONNECTION_INITIALIZING\n");
409 zfcp_cmd_dbf_event_fsf("hconinit", fsf_req,
410 &fsf_req->qtcb->prefix.prot_status_qual,
411 sizeof (union fsf_prot_status_qual));
412 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
413 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
414 &(adapter->status));
415 debug_text_event(adapter->erp_dbf, 3, "prot_con_init");
416 break;
417
418 case FSF_PROT_DUPLICATE_REQUEST_ID:
419 ZFCP_LOG_FLAGS(0, "FSF_PROT_DUPLICATE_REQUEST_IDS\n");
420 if (fsf_req->qtcb) {
421 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
422 "to the adapter %s is ambiguous. "
423 "Stopping all operations on this "
424 "adapter.\n",
425 *(unsigned long long *)
426 (&fsf_req->qtcb->bottom.support.
427 req_handle),
428 zfcp_get_busid_by_adapter(adapter));
429 } else {
430 ZFCP_LOG_NORMAL("bug: The request identifier %p "
431 "to the adapter %s is ambiguous. "
432 "Stopping all operations on this "
433 "adapter. "
434 "(bug: got this for an unsolicited "
435 "status read request)\n",
436 fsf_req,
437 zfcp_get_busid_by_adapter(adapter));
438 }
439 debug_text_exception(adapter->erp_dbf, 0, "prot_dup_id");
440 zfcp_erp_adapter_shutdown(adapter, 0);
441 zfcp_cmd_dbf_event_fsf("dupreqid", fsf_req,
442 &fsf_req->qtcb->prefix.prot_status_qual,
443 sizeof (union fsf_prot_status_qual));
444 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
445 break;
446
447 case FSF_PROT_LINK_DOWN:
448 ZFCP_LOG_FLAGS(1, "FSF_PROT_LINK_DOWN\n");
449 /*
450 * 'test and set' is not atomic here -
451 * it's ok as long as calls to our response queue handler
452 * (and thus execution of this code here) are serialized
453 * by the qdio module
454 */
455 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
456 &adapter->status)) {
457 switch (fsf_req->qtcb->prefix.prot_status_qual.
458 locallink_error.code) {
459 case FSF_PSQ_LINK_NOLIGHT:
460 ZFCP_LOG_INFO("The local link to adapter %s "
461 "is down (no light detected).\n",
462 zfcp_get_busid_by_adapter(
463 adapter));
464 break;
465 case FSF_PSQ_LINK_WRAPPLUG:
466 ZFCP_LOG_INFO("The local link to adapter %s "
467 "is down (wrap plug detected).\n",
468 zfcp_get_busid_by_adapter(
469 adapter));
470 break;
471 case FSF_PSQ_LINK_NOFCP:
472 ZFCP_LOG_INFO("The local link to adapter %s "
473 "is down (adjacent node on "
474 "link does not support FCP).\n",
475 zfcp_get_busid_by_adapter(
476 adapter));
477 break;
478 default:
479 ZFCP_LOG_INFO("The local link to adapter %s "
480 "is down "
481 "(warning: unknown reason "
482 "code).\n",
483 zfcp_get_busid_by_adapter(
484 adapter));
485 break;
486
487 }
488 /*
489 * Due to the 'erp failed' flag the adapter won't
490 * be recovered but will be just set to 'blocked'
491 * state. All subordinary devices will have state
492 * 'blocked' and 'erp failed', too.
493 * Thus the adapter is still able to provide
494 * 'link up' status without being flooded with
495 * requests.
496 * (note: even 'close port' is not permitted)
497 */
498 ZFCP_LOG_INFO("Stopping all operations for adapter "
499 "%s.\n",
500 zfcp_get_busid_by_adapter(adapter));
501 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
502 ZFCP_STATUS_COMMON_ERP_FAILED,
503 &adapter->status);
504 zfcp_erp_adapter_reopen(adapter, 0);
505 debug_text_event(adapter->erp_dbf, 1, "prot_link_down");
506 }
507 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
508 break;
509
510 case FSF_PROT_REEST_QUEUE:
511 ZFCP_LOG_FLAGS(1, "FSF_PROT_REEST_QUEUE\n");
512 debug_text_event(adapter->erp_dbf, 1, "prot_reest_queue");
513 ZFCP_LOG_INFO("The local link to adapter with "
514 "%s was re-plugged. "
515 "Re-starting operations on this adapter.\n",
516 zfcp_get_busid_by_adapter(adapter));
517 /* All ports should be marked as ready to run again */
518 zfcp_erp_modify_adapter_status(adapter,
519 ZFCP_STATUS_COMMON_RUNNING,
520 ZFCP_SET);
521 zfcp_erp_adapter_reopen(adapter,
522 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
523 | ZFCP_STATUS_COMMON_ERP_FAILED);
524 zfcp_cmd_dbf_event_fsf("reestque", fsf_req,
525 &fsf_req->qtcb->prefix.prot_status_qual,
526 sizeof (union fsf_prot_status_qual));
527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
528 break;
529
530 case FSF_PROT_ERROR_STATE:
531 ZFCP_LOG_FLAGS(0, "FSF_PROT_ERROR_STATE\n");
532 ZFCP_LOG_NORMAL("error: The adapter %s "
533 "has entered the error state. "
534 "Restarting all operations on this "
535 "adapter.\n",
536 zfcp_get_busid_by_adapter(adapter));
537 debug_text_event(adapter->erp_dbf, 0, "prot_err_sta");
538 /* restart operation on this adapter */
539 zfcp_erp_adapter_reopen(adapter, 0);
540 zfcp_cmd_dbf_event_fsf("proterrs", fsf_req,
541 &fsf_req->qtcb->prefix.prot_status_qual,
542 sizeof (union fsf_prot_status_qual));
543 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
545 break;
546
547 default:
548 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
549 "provided by the adapter %s "
550 "is not compatible with the device driver. "
551 "Stopping all operations on this adapter. "
552 "(debug info 0x%x).\n",
553 zfcp_get_busid_by_adapter(adapter),
554 fsf_req->qtcb->prefix.prot_status);
555 debug_text_event(adapter->erp_dbf, 0, "prot_inval:");
556 debug_exception(adapter->erp_dbf, 0,
557 &fsf_req->qtcb->prefix.prot_status,
558 sizeof (u32));
559 zfcp_erp_adapter_shutdown(adapter, 0);
560 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
561 }
562
563 skip_protstatus:
564 /*
565 * always call specific handlers to give them a chance to do
566 * something meaningful even in error cases
567 */
568 zfcp_fsf_fsfstatus_eval(fsf_req);
569 return retval;
570}
571
572/*
573 * function: zfcp_fsf_fsfstatus_eval
574 *
575 * purpose: evaluates FSF status of completed FSF request
576 * and acts accordingly
577 *
578 * returns:
579 */
580static int
581zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
582{
583 int retval = 0;
584
585 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
586 goto skip_fsfstatus;
587 }
588
589 /* evaluate FSF Status */
590 switch (fsf_req->qtcb->header.fsf_status) {
591 case FSF_UNKNOWN_COMMAND:
592 ZFCP_LOG_FLAGS(0, "FSF_UNKNOWN_COMMAND\n");
593 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
594 "not known by the adapter %s "
595 "Stopping all operations on this adapter. "
596 "(debug info 0x%x).\n",
597 zfcp_get_busid_by_adapter(fsf_req->adapter),
598 fsf_req->qtcb->header.fsf_command);
599 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
600 "fsf_s_unknown");
601 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
602 zfcp_cmd_dbf_event_fsf("unknownc", fsf_req,
603 &fsf_req->qtcb->header.fsf_status_qual,
604 sizeof (union fsf_status_qual));
605 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
606 break;
607
608 case FSF_FCP_RSP_AVAILABLE:
609 ZFCP_LOG_FLAGS(2, "FSF_FCP_RSP_AVAILABLE\n");
610 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
611 "SCSI stack.\n");
612 debug_text_event(fsf_req->adapter->erp_dbf, 3, "fsf_s_rsp");
613 break;
614
615 case FSF_ADAPTER_STATUS_AVAILABLE:
616 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
617 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_astatus");
618 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
619 break;
620
621 default:
622 break;
623 }
624
625 skip_fsfstatus:
626 /*
627 * always call specific handlers to give them a chance to do
628 * something meaningful even in error cases
629 */
630 zfcp_fsf_req_dispatch(fsf_req);
631
632 return retval;
633}
634
635/*
636 * function: zfcp_fsf_fsfstatus_qual_eval
637 *
638 * purpose: evaluates FSF status-qualifier of completed FSF request
639 * and acts accordingly
640 *
641 * returns:
642 */
643static int
644zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
645{
646 int retval = 0;
647
648 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
649 case FSF_SQ_FCP_RSP_AVAILABLE:
650 ZFCP_LOG_FLAGS(2, "FSF_SQ_FCP_RSP_AVAILABLE\n");
651 debug_text_event(fsf_req->adapter->erp_dbf, 4, "fsf_sq_rsp");
652 break;
653 case FSF_SQ_RETRY_IF_POSSIBLE:
654 ZFCP_LOG_FLAGS(2, "FSF_SQ_RETRY_IF_POSSIBLE\n");
655 /* The SCSI-stack may now issue retries or escalate */
656 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_retry");
657 zfcp_cmd_dbf_event_fsf("sqretry", fsf_req,
658 &fsf_req->qtcb->header.fsf_status_qual,
659 sizeof (union fsf_status_qual));
660 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
661 break;
662 case FSF_SQ_COMMAND_ABORTED:
663 ZFCP_LOG_FLAGS(2, "FSF_SQ_COMMAND_ABORTED\n");
664 /* Carry the aborted state on to upper layer */
665 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_abort");
666 zfcp_cmd_dbf_event_fsf("sqabort", fsf_req,
667 &fsf_req->qtcb->header.fsf_status_qual,
668 sizeof (union fsf_status_qual));
669 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
670 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
671 break;
672 case FSF_SQ_NO_RECOM:
673 ZFCP_LOG_FLAGS(0, "FSF_SQ_NO_RECOM\n");
674 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
675 "fsf_sq_no_rec");
676 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
677 "problem on the adapter %s "
678 "Stopping all operations on this adapter. ",
679 zfcp_get_busid_by_adapter(fsf_req->adapter));
680 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
681 zfcp_cmd_dbf_event_fsf("sqnrecom", fsf_req,
682 &fsf_req->qtcb->header.fsf_status_qual,
683 sizeof (union fsf_status_qual));
684 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
685 break;
686 case FSF_SQ_ULP_PROGRAMMING_ERROR:
687 ZFCP_LOG_FLAGS(0, "FSF_SQ_ULP_PROGRAMMING_ERROR\n");
688 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
689 "(adapter %s)\n",
690 zfcp_get_busid_by_adapter(fsf_req->adapter));
691 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
692 "fsf_sq_ulp_err");
693 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
694 break;
695 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
696 case FSF_SQ_NO_RETRY_POSSIBLE:
697 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
698 /* dealt with in the respective functions */
699 break;
700 default:
701 ZFCP_LOG_NORMAL("bug: Additional status info could "
702 "not be interpreted properly.\n");
703 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
704 (char *) &fsf_req->qtcb->header.fsf_status_qual,
705 sizeof (union fsf_status_qual));
706 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval:");
707 debug_exception(fsf_req->adapter->erp_dbf, 0,
708 &fsf_req->qtcb->header.fsf_status_qual.word[0],
709 sizeof (u32));
710 zfcp_cmd_dbf_event_fsf("squndef", fsf_req,
711 &fsf_req->qtcb->header.fsf_status_qual,
712 sizeof (union fsf_status_qual));
713 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
714 break;
715 }
716
717 return retval;
718}
719
720/*
721 * function: zfcp_fsf_req_dispatch
722 *
723 * purpose: calls the appropriate command specific handler
724 *
725 * returns:
726 */
727static int
728zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
729{
730 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
731 struct zfcp_adapter *adapter = fsf_req->adapter;
732 int retval = 0;
733
734 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
735 ZFCP_LOG_TRACE("fsf_req=%p, QTCB=%p\n", fsf_req, fsf_req->qtcb);
736 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
737 (char *) fsf_req->qtcb, sizeof(struct fsf_qtcb));
738 }
739
740 switch (fsf_req->fsf_command) {
741
742 case FSF_QTCB_FCP_CMND:
743 ZFCP_LOG_FLAGS(3, "FSF_QTCB_FCP_CMND\n");
744 zfcp_fsf_send_fcp_command_handler(fsf_req);
745 break;
746
747 case FSF_QTCB_ABORT_FCP_CMND:
748 ZFCP_LOG_FLAGS(2, "FSF_QTCB_ABORT_FCP_CMND\n");
749 zfcp_fsf_abort_fcp_command_handler(fsf_req);
750 break;
751
752 case FSF_QTCB_SEND_GENERIC:
753 ZFCP_LOG_FLAGS(2, "FSF_QTCB_SEND_GENERIC\n");
754 zfcp_fsf_send_ct_handler(fsf_req);
755 break;
756
757 case FSF_QTCB_OPEN_PORT_WITH_DID:
758 ZFCP_LOG_FLAGS(2, "FSF_QTCB_OPEN_PORT_WITH_DID\n");
759 zfcp_fsf_open_port_handler(fsf_req);
760 break;
761
762 case FSF_QTCB_OPEN_LUN:
763 ZFCP_LOG_FLAGS(2, "FSF_QTCB_OPEN_LUN\n");
764 zfcp_fsf_open_unit_handler(fsf_req);
765 break;
766
767 case FSF_QTCB_CLOSE_LUN:
768 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_LUN\n");
769 zfcp_fsf_close_unit_handler(fsf_req);
770 break;
771
772 case FSF_QTCB_CLOSE_PORT:
773 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_PORT\n");
774 zfcp_fsf_close_port_handler(fsf_req);
775 break;
776
777 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
778 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_PHYSICAL_PORT\n");
779 zfcp_fsf_close_physical_port_handler(fsf_req);
780 break;
781
782 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
783 ZFCP_LOG_FLAGS(2, "FSF_QTCB_EXCHANGE_CONFIG_DATA\n");
784 zfcp_fsf_exchange_config_data_handler(fsf_req);
785 break;
786
787 case FSF_QTCB_EXCHANGE_PORT_DATA:
788 ZFCP_LOG_FLAGS(2, "FSF_QTCB_EXCHANGE_PORT_DATA\n");
789 zfcp_fsf_exchange_port_data_handler(fsf_req);
790 break;
791
792 case FSF_QTCB_SEND_ELS:
793 ZFCP_LOG_FLAGS(2, "FSF_QTCB_SEND_ELS\n");
794 zfcp_fsf_send_els_handler(fsf_req);
795 break;
796
797 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
798 ZFCP_LOG_FLAGS(2, "FSF_QTCB_DOWNLOAD_CONTROL_FILE\n");
799 zfcp_fsf_control_file_handler(fsf_req);
800 break;
801
802 case FSF_QTCB_UPLOAD_CONTROL_FILE:
803 ZFCP_LOG_FLAGS(2, "FSF_QTCB_UPLOAD_CONTROL_FILE\n");
804 zfcp_fsf_control_file_handler(fsf_req);
805 break;
806
807 default:
808 ZFCP_LOG_FLAGS(2, "FSF_QTCB_UNKNOWN\n");
809 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
810 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
811 "not supported by the adapter %s\n",
812 zfcp_get_busid_by_adapter(fsf_req->adapter));
813 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
814 ZFCP_LOG_NORMAL
815 ("bug: Command issued by the device driver differs "
816 "from the command returned by the adapter %s "
817 "(debug info 0x%x, 0x%x).\n",
818 zfcp_get_busid_by_adapter(fsf_req->adapter),
819 fsf_req->fsf_command,
820 fsf_req->qtcb->header.fsf_command);
821 }
822
823 if (!erp_action)
824 return retval;
825
826 debug_text_event(adapter->erp_dbf, 3, "a_frh");
827 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
828 zfcp_erp_async_handler(erp_action, 0);
829
830 return retval;
831}
832
833/*
834 * function: zfcp_fsf_status_read
835 *
836 * purpose: initiates a Status Read command at the specified adapter
837 *
838 * returns:
839 */
840int
841zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
842{
843 struct zfcp_fsf_req *fsf_req;
844 struct fsf_status_read_buffer *status_buffer;
845 unsigned long lock_flags;
846 volatile struct qdio_buffer_element *sbale;
847 int retval = 0;
848
849 /* setup new FSF request */
850 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
851 req_flags | ZFCP_REQ_NO_QTCB,
852 adapter->pool.fsf_req_status_read,
853 &lock_flags, &fsf_req);
854 if (retval < 0) {
855 ZFCP_LOG_INFO("error: Could not create unsolicited status "
856 "buffer for adapter %s.\n",
857 zfcp_get_busid_by_adapter(adapter));
858 goto failed_req_create;
859 }
860
861 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
862 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
863 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
864 fsf_req->sbale_curr = 2;
865
866 status_buffer =
867 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
868 if (!status_buffer) {
869 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
870 goto failed_buf;
871 }
872 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
873 fsf_req->data.status_read.buffer = status_buffer;
874
875 /* insert pointer to respective buffer */
876 sbale = zfcp_qdio_sbale_curr(fsf_req);
877 sbale->addr = (void *) status_buffer;
878 sbale->length = sizeof(struct fsf_status_read_buffer);
879
880 /* start QDIO request for this FSF request */
881 retval = zfcp_fsf_req_send(fsf_req, NULL);
882 if (retval) {
883 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
884 "environment.\n");
885 goto failed_req_send;
886 }
887
888 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
889 zfcp_get_busid_by_adapter(adapter));
890 goto out;
891
892 failed_req_send:
893 mempool_free(status_buffer, adapter->pool.data_status_read);
894
895 failed_buf:
896 zfcp_fsf_req_free(fsf_req);
897 failed_req_create:
898 out:
899 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
900 return retval;
901}
902
903static int
904zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
905{
906 struct fsf_status_read_buffer *status_buffer;
907 struct zfcp_adapter *adapter;
908 struct zfcp_port *port;
909 unsigned long flags;
910
911 status_buffer = fsf_req->data.status_read.buffer;
912 adapter = fsf_req->adapter;
913
914 read_lock_irqsave(&zfcp_data.config_lock, flags);
915 list_for_each_entry(port, &adapter->port_list_head, list)
916 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
917 break;
918 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
919
920 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
921 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
922 "nonexisting port with d_id 0x%08x on "
923 "adapter %s. Ignored.\n",
924 status_buffer->d_id & ZFCP_DID_MASK,
925 zfcp_get_busid_by_adapter(adapter));
926 goto out;
927 }
928
929 switch (status_buffer->status_subtype) {
930
931 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
932 ZFCP_LOG_FLAGS(2, "FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT\n");
933 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
934 zfcp_erp_port_reopen(port, 0);
935 break;
936
937 case FSF_STATUS_READ_SUB_ERROR_PORT:
938 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_SUB_ERROR_PORT\n");
939 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
940 zfcp_erp_port_shutdown(port, 0);
941 break;
942
943 default:
944 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
945 debug_exception(adapter->erp_dbf, 0,
946 &status_buffer->status_subtype, sizeof (u32));
947 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
948 "for a reopen indication on port with "
949 "d_id 0x%08x on the adapter %s. "
950 "Ignored. (debug info 0x%x)\n",
951 status_buffer->d_id,
952 zfcp_get_busid_by_adapter(adapter),
953 status_buffer->status_subtype);
954 }
955 out:
956 return 0;
957}
958
959/*
960 * function: zfcp_fsf_status_read_handler
961 *
962 * purpose: is called for finished Open Port command
963 *
964 * returns:
965 */
966static int
967zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
968{
969 int retval = 0;
970 struct zfcp_adapter *adapter = fsf_req->adapter;
971 struct fsf_status_read_buffer *status_buffer =
972 fsf_req->data.status_read.buffer;
973
974 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
975 mempool_free(status_buffer, adapter->pool.data_status_read);
976 zfcp_fsf_req_cleanup(fsf_req);
977 goto out;
978 }
979
980 switch (status_buffer->status_type) {
981
982 case FSF_STATUS_READ_PORT_CLOSED:
983 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_PORT_CLOSED\n");
984 debug_text_event(adapter->erp_dbf, 3, "unsol_pclosed:");
985 debug_event(adapter->erp_dbf, 3,
986 &status_buffer->d_id, sizeof (u32));
987 zfcp_fsf_status_read_port_closed(fsf_req);
988 break;
989
990 case FSF_STATUS_READ_INCOMING_ELS:
991 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_INCOMING_ELS\n");
992 debug_text_event(adapter->erp_dbf, 3, "unsol_els:");
993 zfcp_fsf_incoming_els(fsf_req);
994 break;
995
996 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
997 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_SENSE_DATA_AVAIL\n");
998 debug_text_event(adapter->erp_dbf, 3, "unsol_sense:");
999 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
1000 zfcp_get_busid_by_adapter(adapter));
1001 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, (char *) status_buffer,
1002 sizeof(struct fsf_status_read_buffer));
1003 break;
1004
1005 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
1006 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_BIT_ERROR_THRESHOLD\n");
1007 debug_text_event(adapter->erp_dbf, 3, "unsol_bit_err:");
1008 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
1009 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
1010 (char *) status_buffer,
1011 sizeof (struct fsf_status_read_buffer));
1012 break;
1013
1014 case FSF_STATUS_READ_LINK_DOWN:
1015 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_LINK_DOWN\n");
1016 debug_text_event(adapter->erp_dbf, 0, "unsol_link_down:");
1017 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
1018 zfcp_get_busid_by_adapter(adapter));
1019 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
1020 &adapter->status);
1021 zfcp_erp_adapter_failed(adapter);
1022 break;
1023
1024 case FSF_STATUS_READ_LINK_UP:
1025 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_LINK_UP\n");
1026 debug_text_event(adapter->erp_dbf, 2, "unsol_link_up:");
1027 ZFCP_LOG_INFO("Local link to adapter %s was replugged. "
1028 "Restarting operations on this adapter\n",
1029 zfcp_get_busid_by_adapter(adapter));
1030 /* All ports should be marked as ready to run again */
1031 zfcp_erp_modify_adapter_status(adapter,
1032 ZFCP_STATUS_COMMON_RUNNING,
1033 ZFCP_SET);
1034 zfcp_erp_adapter_reopen(adapter,
1035 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
1036 | ZFCP_STATUS_COMMON_ERP_FAILED);
1037 break;
1038
1039 case FSF_STATUS_READ_CFDC_UPDATED:
1040 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_CFDC_UPDATED\n");
1041 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_update:");
1042 ZFCP_LOG_INFO("CFDC has been updated on the adapter %s\n",
1043 zfcp_get_busid_by_adapter(adapter));
1044 zfcp_erp_adapter_access_changed(adapter);
1045 break;
1046
1047 case FSF_STATUS_READ_CFDC_HARDENED:
1048 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_CFDC_HARDENED\n");
1049 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_harden:");
1050 switch (status_buffer->status_subtype) {
1051 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1052 ZFCP_LOG_INFO("CFDC of adapter %s saved on SE\n",
1053 zfcp_get_busid_by_adapter(adapter));
1054 break;
1055 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1056 ZFCP_LOG_INFO("CFDC of adapter %s has been copied "
1057 "to the secondary SE\n",
1058 zfcp_get_busid_by_adapter(adapter));
1059 break;
1060 default:
1061 ZFCP_LOG_INFO("CFDC of adapter %s has been hardened\n",
1062 zfcp_get_busid_by_adapter(adapter));
1063 }
1064 break;
1065
1066 default:
1067 debug_text_event(adapter->erp_dbf, 0, "unsol_unknown:");
1068 debug_exception(adapter->erp_dbf, 0,
1069 &status_buffer->status_type, sizeof (u32));
1070 ZFCP_LOG_NORMAL("bug: An unsolicited status packet of unknown "
1071 "type was received (debug info 0x%x)\n",
1072 status_buffer->status_type);
1073 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1074 status_buffer);
1075 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1076 (char *) status_buffer,
1077 sizeof (struct fsf_status_read_buffer));
1078 break;
1079 }
1080 mempool_free(status_buffer, adapter->pool.data_status_read);
1081 zfcp_fsf_req_cleanup(fsf_req);
1082 /*
1083 * recycle buffer and start new request repeat until outbound
1084 * queue is empty or adapter shutdown is requested
1085 */
1086 /*
1087 * FIXME(qdio):
1088 * we may wait in the req_create for 5s during shutdown, so
1089 * qdio_cleanup will have to wait at least that long before returning
1090 * with failure to allow us a proper cleanup under all circumstances
1091 */
1092 /*
1093 * FIXME:
1094 * allocation failure possible? (Is this code needed?)
1095 */
1096 retval = zfcp_fsf_status_read(adapter, 0);
1097 if (retval < 0) {
1098 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1099 "request for the adapter %s.\n",
1100 zfcp_get_busid_by_adapter(adapter));
1101 /* temporary fix to avoid status read buffer shortage */
1102 adapter->status_read_failed++;
1103 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1104 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1105 ZFCP_LOG_INFO("restart adapter %s due to status read "
1106 "buffer shortage\n",
1107 zfcp_get_busid_by_adapter(adapter));
1108 zfcp_erp_adapter_reopen(adapter, 0);
1109 }
1110 }
1111 out:
1112 return retval;
1113}
1114
1115/*
1116 * function: zfcp_fsf_abort_fcp_command
1117 *
1118 * purpose: tells FSF to abort a running SCSI command
1119 *
1120 * returns: address of initiated FSF request
1121 * NULL - request could not be initiated
1122 *
1123 * FIXME(design): should be watched by a timeout !!!
1124 * FIXME(design) shouldn't this be modified to return an int
1125 * also...don't know how though
1126 */
1127struct zfcp_fsf_req *
1128zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1129 struct zfcp_adapter *adapter,
1130 struct zfcp_unit *unit, int req_flags)
1131{
1132 volatile struct qdio_buffer_element *sbale;
1133 unsigned long lock_flags;
1134 struct zfcp_fsf_req *fsf_req = NULL;
1135 int retval = 0;
1136
1137 /* setup new FSF request */
1138 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1139 req_flags, adapter->pool.fsf_req_abort,
1140 &lock_flags, &fsf_req);
1141 if (retval < 0) {
1142 ZFCP_LOG_INFO("error: Failed to create an abort command "
1143 "request for lun 0x%016Lx on port 0x%016Lx "
1144 "on adapter %s.\n",
1145 unit->fcp_lun,
1146 unit->port->wwpn,
1147 zfcp_get_busid_by_adapter(adapter));
1148 goto out;
1149 }
1150
1151 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1152 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1153 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1154
1155 fsf_req->data.abort_fcp_command.unit = unit;
1156
1157 /* set handles of unit and its parent port in QTCB */
1158 fsf_req->qtcb->header.lun_handle = unit->handle;
1159 fsf_req->qtcb->header.port_handle = unit->port->handle;
1160
1161 /* set handle of request which should be aborted */
1162 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1163
1164 /* start QDIO request for this FSF request */
1165
1166 zfcp_fsf_start_scsi_er_timer(adapter);
1167 retval = zfcp_fsf_req_send(fsf_req, NULL);
1168 if (retval) {
1169 del_timer(&adapter->scsi_er_timer);
1170 ZFCP_LOG_INFO("error: Failed to send abort command request "
1171 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1172 zfcp_get_busid_by_adapter(adapter),
1173 unit->port->wwpn, unit->fcp_lun);
1174 zfcp_fsf_req_free(fsf_req);
1175 fsf_req = NULL;
1176 goto out;
1177 }
1178
1179 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1180 "(adapter%s, port d_id=0x%08x, "
1181 "unit x%016Lx, old_req_id=0x%lx)\n",
1182 zfcp_get_busid_by_adapter(adapter),
1183 unit->port->d_id,
1184 unit->fcp_lun, old_req_id);
1185 out:
1186 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1187 return fsf_req;
1188}
1189
1190/*
1191 * function: zfcp_fsf_abort_fcp_command_handler
1192 *
1193 * purpose: is called for finished Abort FCP Command request
1194 *
1195 * returns:
1196 */
1197static int
1198zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1199{
1200 int retval = -EINVAL;
1201 struct zfcp_unit *unit = new_fsf_req->data.abort_fcp_command.unit;
1202 unsigned char status_qual =
1203 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1204
1205 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1206
1207 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1208 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1209 goto skip_fsfstatus;
1210 }
1211
1212 /* evaluate FSF status in QTCB */
1213 switch (new_fsf_req->qtcb->header.fsf_status) {
1214
1215 case FSF_PORT_HANDLE_NOT_VALID:
1216 if (status_qual >> 4 != status_qual % 0xf) {
1217 ZFCP_LOG_FLAGS(2, "FSF_PORT_HANDLE_NOT_VALID\n");
1218 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1219 "fsf_s_phand_nv0");
1220 /*
1221 * In this case a command that was sent prior to a port
1222 * reopen was aborted (handles are different). This is
1223 * fine.
1224 */
1225 } else {
1226 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
1227 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1228 "port 0x%016Lx on adapter %s invalid. "
1229 "This may happen occasionally.\n",
1230 unit->port->handle,
1231 unit->port->wwpn,
1232 zfcp_get_busid_by_unit(unit));
1233 ZFCP_LOG_INFO("status qualifier:\n");
1234 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1235 (char *) &new_fsf_req->qtcb->header.
1236 fsf_status_qual,
1237 sizeof (union fsf_status_qual));
1238 /* Let's hope this sorts out the mess */
1239 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1240 "fsf_s_phand_nv1");
1241 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1242 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1243 }
1244 break;
1245
1246 case FSF_LUN_HANDLE_NOT_VALID:
1247 if (status_qual >> 4 != status_qual % 0xf) {
1248 /* 2 */
1249 ZFCP_LOG_FLAGS(0, "FSF_LUN_HANDLE_NOT_VALID\n");
1250 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1251 "fsf_s_lhand_nv0");
1252 /*
1253 * In this case a command that was sent prior to a unit
1254 * reopen was aborted (handles are different).
1255 * This is fine.
1256 */
1257 } else {
1258 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
1259 ZFCP_LOG_INFO
1260 ("Warning: Temporary LUN identifier 0x%x of LUN "
1261 "0x%016Lx on port 0x%016Lx on adapter %s is "
1262 "invalid. This may happen in rare cases. "
1263 "Trying to re-establish link.\n",
1264 unit->handle,
1265 unit->fcp_lun,
1266 unit->port->wwpn,
1267 zfcp_get_busid_by_unit(unit));
1268 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1269 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1270 (char *) &new_fsf_req->qtcb->header.
1271 fsf_status_qual,
1272 sizeof (union fsf_status_qual));
1273 /* Let's hope this sorts out the mess */
1274 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1275 "fsf_s_lhand_nv1");
1276 zfcp_erp_port_reopen(unit->port, 0);
1277 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1278 }
1279 break;
1280
1281 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1282 ZFCP_LOG_FLAGS(2, "FSF_FCP_COMMAND_DOES_NOT_EXIST\n");
1283 retval = 0;
1284 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1285 "fsf_s_no_exist");
1286 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1287 break;
1288
1289 case FSF_PORT_BOXED:
1290 /* 2 */
1291 ZFCP_LOG_FLAGS(0, "FSF_PORT_BOXED\n");
1292 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1293 "be reopened\n", unit->port->wwpn,
1294 zfcp_get_busid_by_unit(unit));
1295 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1296 "fsf_s_pboxed");
1297 zfcp_erp_port_reopen(unit->port, 0);
1298 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1299 | ZFCP_STATUS_FSFREQ_RETRY;
1300 break;
1301
1302 case FSF_LUN_BOXED:
1303 ZFCP_LOG_FLAGS(0, "FSF_LUN_BOXED\n");
1304 ZFCP_LOG_INFO(
1305 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1306 "to be reopened\n",
1307 unit->fcp_lun, unit->port->wwpn,
1308 zfcp_get_busid_by_unit(unit));
1309 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1310 zfcp_erp_unit_reopen(unit, 0);
1311 zfcp_cmd_dbf_event_fsf("unitbox", new_fsf_req,
1312 &new_fsf_req->qtcb->header.fsf_status_qual,
1313 sizeof(union fsf_status_qual));
1314 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1315 | ZFCP_STATUS_FSFREQ_RETRY;
1316 break;
1317
1318 case FSF_ADAPTER_STATUS_AVAILABLE:
1319 /* 2 */
1320 ZFCP_LOG_FLAGS(0, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1321 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1322 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1323 ZFCP_LOG_FLAGS(2,
1324 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1325 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1326 "fsf_sq_ltest");
1327 /* reopening link to port */
1328 zfcp_erp_port_reopen(unit->port, 0);
1329 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1330 break;
1331 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1332 ZFCP_LOG_FLAGS(2,
1333 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1334 /* SCSI stack will escalate */
1335 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1336 "fsf_sq_ulp");
1337 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1338 break;
1339 default:
1340 ZFCP_LOG_NORMAL
1341 ("bug: Wrong status qualifier 0x%x arrived.\n",
1342 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1343 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1344 "fsf_sq_inval:");
1345 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1346 &new_fsf_req->qtcb->header.
1347 fsf_status_qual.word[0], sizeof (u32));
1348 break;
1349 }
1350 break;
1351
1352 case FSF_GOOD:
1353 /* 3 */
1354 ZFCP_LOG_FLAGS(0, "FSF_GOOD\n");
1355 retval = 0;
1356 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1357 break;
1358
1359 default:
1360 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1361 "(debug info 0x%x)\n",
1362 new_fsf_req->qtcb->header.fsf_status);
1363 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1364 "fsf_s_inval:");
1365 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1366 &new_fsf_req->qtcb->header.fsf_status,
1367 sizeof (u32));
1368 break;
1369 }
1370 skip_fsfstatus:
1371 return retval;
1372}
1373
1374/**
1375 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1376 * one SBALE
1377 * Two scatter-gather lists are passed, one for the reqeust and one for the
1378 * response.
1379 */
1380static inline int
1381zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1382 struct scatterlist *resp, int resp_count)
1383{
1384 return ((req_count == 1) &&
1385 (resp_count == 1) &&
1386 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1387 PAGE_MASK) ==
1388 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1389 req[0].length - 1) & PAGE_MASK)) &&
1390 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1391 PAGE_MASK) ==
1392 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1393 resp[0].length - 1) & PAGE_MASK)));
1394}
1395
1396/**
1397 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1398 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1399 * the request
1400 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1401 * a struct zfcp_fsf_req
1402 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1403 * is sent within error recovery
1404 */
1405int
1406zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1407 struct zfcp_erp_action *erp_action)
1408{
1409 volatile struct qdio_buffer_element *sbale;
1410 struct zfcp_port *port;
1411 struct zfcp_adapter *adapter;
1412 struct zfcp_fsf_req *fsf_req;
1413 unsigned long lock_flags;
1414 int bytes;
1415 int ret = 0;
1416
1417 port = ct->port;
1418 adapter = port->adapter;
1419
1420 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1421 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1422 pool, &lock_flags, &fsf_req);
1423 if (ret < 0) {
1424 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1425 "adapter: %s\n",
1426 zfcp_get_busid_by_adapter(adapter));
1427 goto failed_req;
1428 }
1429
1430 if (erp_action != NULL) {
1431 erp_action->fsf_req = fsf_req;
1432 fsf_req->erp_action = erp_action;
1433 }
1434
1435 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1436 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1437 ct->resp, ct->resp_count)){
1438 /* both request buffer and response buffer
1439 fit into one sbale each */
1440 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1441 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1442 sbale[2].length = ct->req[0].length;
1443 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1444 sbale[3].length = ct->resp[0].length;
1445 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1446 } else if (adapter->supported_features &
1447 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1448 /* try to use chained SBALs */
1449 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1450 SBAL_FLAGS0_TYPE_WRITE_READ,
1451 ct->req, ct->req_count,
1452 ZFCP_MAX_SBALS_PER_CT_REQ);
1453 if (bytes <= 0) {
1454 ZFCP_LOG_INFO("error: creation of CT request failed "
1455 "on adapter %s\n",
1456 zfcp_get_busid_by_adapter(adapter));
1457 if (bytes == 0)
1458 ret = -ENOMEM;
1459 else
1460 ret = bytes;
1461
1462 goto failed_send;
1463 }
1464 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1465 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1466 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1467 SBAL_FLAGS0_TYPE_WRITE_READ,
1468 ct->resp, ct->resp_count,
1469 ZFCP_MAX_SBALS_PER_CT_REQ);
1470 if (bytes <= 0) {
1471 ZFCP_LOG_INFO("error: creation of CT request failed "
1472 "on adapter %s\n",
1473 zfcp_get_busid_by_adapter(adapter));
1474 if (bytes == 0)
1475 ret = -ENOMEM;
1476 else
1477 ret = bytes;
1478
1479 goto failed_send;
1480 }
1481 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1482 } else {
1483 /* reject send generic request */
1484 ZFCP_LOG_INFO(
1485 "error: microcode does not support chained SBALs,"
1486 "CT request too big (adapter %s)\n",
1487 zfcp_get_busid_by_adapter(adapter));
1488 ret = -EOPNOTSUPP;
1489 goto failed_send;
1490 }
1491
1492 /* settings in QTCB */
1493 fsf_req->qtcb->header.port_handle = port->handle;
1494 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1495 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1496 fsf_req->data.send_ct = ct;
1497
1498 /* start QDIO request for this FSF request */
1499 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1500 if (ret) {
1501 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1502 "(adapter %s, port 0x%016Lx)\n",
1503 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1504 goto failed_send;
1505 }
1506
1507 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1508 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1509 goto out;
1510
1511 failed_send:
1512 zfcp_fsf_req_free(fsf_req);
1513 if (erp_action != NULL) {
1514 erp_action->fsf_req = NULL;
1515 }
1516 failed_req:
1517 out:
1518 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1519 lock_flags);
1520 return ret;
1521}
1522
1523/**
1524 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1525 * @fsf_req: pointer to struct zfcp_fsf_req
1526 *
1527 * Data specific for the Generic Service request is passed by
1528 * fsf_req->data.send_ct
1529 * Usually a specific handler for the request is called via
1530 * fsf_req->data.send_ct->handler at end of this function.
1531 */
1532static int
1533zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1534{
1535 struct zfcp_port *port;
1536 struct zfcp_adapter *adapter;
1537 struct zfcp_send_ct *send_ct;
1538 struct fsf_qtcb_header *header;
1539 struct fsf_qtcb_bottom_support *bottom;
1540 int retval = -EINVAL;
1541 u16 subtable, rule, counter;
1542
1543 adapter = fsf_req->adapter;
1544 send_ct = fsf_req->data.send_ct;
1545 port = send_ct->port;
1546 header = &fsf_req->qtcb->header;
1547 bottom = &fsf_req->qtcb->bottom.support;
1548
1549 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1550 goto skip_fsfstatus;
1551
1552 /* evaluate FSF status in QTCB */
1553 switch (header->fsf_status) {
1554
1555 case FSF_GOOD:
1556 ZFCP_LOG_FLAGS(2,"FSF_GOOD\n");
1557 retval = 0;
1558 break;
1559
1560 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1561 ZFCP_LOG_FLAGS(2, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
1562 if (adapter->fc_service_class <= 3) {
1563 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1564 "class %d.\n",
1565 zfcp_get_busid_by_port(port),
1566 adapter->fc_service_class);
1567 } else {
1568 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1569 "adapter %s is invalid. "
1570 "(debug info %d)\n",
1571 zfcp_get_busid_by_port(port),
1572 adapter->fc_service_class);
1573 }
1574 /* stop operation for this adapter */
1575 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1576 zfcp_erp_adapter_shutdown(adapter, 0);
1577 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1578 break;
1579
1580 case FSF_ADAPTER_STATUS_AVAILABLE:
1581 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1582 switch (header->fsf_status_qual.word[0]){
1583 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1584 ZFCP_LOG_FLAGS(2,"FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1585 /* reopening link to port */
1586 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1587 zfcp_test_link(port);
1588 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1589 break;
1590 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1591 ZFCP_LOG_FLAGS(2,"FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1592 /* ERP strategy will escalate */
1593 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1594 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1595 break;
1596 default:
1597 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1598 "arrived.\n",
1599 header->fsf_status_qual.word[0]);
1600 break;
1601 }
1602 break;
1603
1604 case FSF_ACCESS_DENIED:
1605 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
1606 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1607 "command (adapter %s, port d_id=0x%08x)\n",
1608 zfcp_get_busid_by_port(port), port->d_id);
1609 for (counter = 0; counter < 2; counter++) {
1610 subtable = header->fsf_status_qual.halfword[counter * 2];
1611 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1612 switch (subtable) {
1613 case FSF_SQ_CFDC_SUBTABLE_OS:
1614 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1615 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1616 case FSF_SQ_CFDC_SUBTABLE_LUN:
1617 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1618 zfcp_act_subtable_type[subtable], rule);
1619 break;
1620 }
1621 }
1622 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1623 zfcp_erp_port_access_denied(port);
1624 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1625 break;
1626
1627 case FSF_GENERIC_COMMAND_REJECTED:
1628 ZFCP_LOG_FLAGS(2, "FSF_GENERIC_COMMAND_REJECTED\n");
1629 ZFCP_LOG_INFO("generic service command rejected "
1630 "(adapter %s, port d_id=0x%08x)\n",
1631 zfcp_get_busid_by_port(port), port->d_id);
1632 ZFCP_LOG_INFO("status qualifier:\n");
1633 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1634 (char *) &header->fsf_status_qual,
1635 sizeof (union fsf_status_qual));
1636 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1637 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1638 break;
1639
1640 case FSF_PORT_HANDLE_NOT_VALID:
1641 ZFCP_LOG_FLAGS(2, "FSF_PORT_HANDLE_NOT_VALID\n");
1642 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1643 "0x%016Lx on adapter %s invalid. This may "
1644 "happen occasionally.\n", port->handle,
1645 port->wwpn, zfcp_get_busid_by_port(port));
1646 ZFCP_LOG_INFO("status qualifier:\n");
1647 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1648 (char *) &header->fsf_status_qual,
1649 sizeof (union fsf_status_qual));
1650 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1651 zfcp_erp_adapter_reopen(adapter, 0);
1652 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1653 break;
1654
1655 case FSF_PORT_BOXED:
1656 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
1657 ZFCP_LOG_INFO("port needs to be reopened "
1658 "(adapter %s, port d_id=0x%08x)\n",
1659 zfcp_get_busid_by_port(port), port->d_id);
1660 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1661 zfcp_erp_port_reopen(port, 0);
1662 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1663 | ZFCP_STATUS_FSFREQ_RETRY;
1664 break;
1665
1666 /* following states should never occure, all cases avoided
1667 in zfcp_fsf_send_ct - but who knows ... */
1668 case FSF_PAYLOAD_SIZE_MISMATCH:
1669 ZFCP_LOG_FLAGS(2, "FSF_PAYLOAD_SIZE_MISMATCH\n");
1670 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1671 "req_buf_length=%d, resp_buf_length=%d)\n",
1672 zfcp_get_busid_by_adapter(adapter),
1673 bottom->req_buf_length, bottom->resp_buf_length);
1674 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1675 break;
1676 case FSF_REQUEST_SIZE_TOO_LARGE:
1677 ZFCP_LOG_FLAGS(2, "FSF_REQUEST_SIZE_TOO_LARGE\n");
1678 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1679 "req_buf_length=%d)\n",
1680 zfcp_get_busid_by_adapter(adapter),
1681 bottom->req_buf_length);
1682 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1683 break;
1684 case FSF_RESPONSE_SIZE_TOO_LARGE:
1685 ZFCP_LOG_FLAGS(2, "FSF_RESPONSE_SIZE_TOO_LARGE\n");
1686 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1687 "resp_buf_length=%d)\n",
1688 zfcp_get_busid_by_adapter(adapter),
1689 bottom->resp_buf_length);
1690 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1691 break;
1692 case FSF_SBAL_MISMATCH:
1693 ZFCP_LOG_FLAGS(2, "FSF_SBAL_MISMATCH\n");
1694 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1695 "resp_buf_length=%d)\n",
1696 zfcp_get_busid_by_adapter(adapter),
1697 bottom->req_buf_length, bottom->resp_buf_length);
1698 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1699 break;
1700
1701 default:
1702 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1703 "(debug info 0x%x)\n", header->fsf_status);
1704 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1705 debug_exception(adapter->erp_dbf, 0,
1706 &header->fsf_status_qual.word[0], sizeof (u32));
1707 break;
1708 }
1709
1710skip_fsfstatus:
1711 send_ct->status = retval;
1712
1713 if (send_ct->handler != NULL)
1714 send_ct->handler(send_ct->handler_data);
1715
1716 return retval;
1717}
1718
1719/**
1720 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1721 * @els: pointer to struct zfcp_send_els which contains all needed data for
1722 * the command.
1723 */
1724int
1725zfcp_fsf_send_els(struct zfcp_send_els *els)
1726{
1727 volatile struct qdio_buffer_element *sbale;
1728 struct zfcp_fsf_req *fsf_req;
1729 fc_id_t d_id;
1730 struct zfcp_adapter *adapter;
1731 unsigned long lock_flags;
1732 int bytes;
1733 int ret = 0;
1734
1735 d_id = els->d_id;
1736 adapter = els->adapter;
1737
1738 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1739 ZFCP_REQ_AUTO_CLEANUP,
1740 NULL, &lock_flags, &fsf_req);
1741 if (ret < 0) {
1742 ZFCP_LOG_INFO("error: creation of ELS request failed "
1743 "(adapter %s, port d_id: 0x%08x)\n",
1744 zfcp_get_busid_by_adapter(adapter), d_id);
1745 goto failed_req;
1746 }
1747
1748 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1749 if (zfcp_use_one_sbal(els->req, els->req_count,
1750 els->resp, els->resp_count)){
1751 /* both request buffer and response buffer
1752 fit into one sbale each */
1753 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1754 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1755 sbale[2].length = els->req[0].length;
1756 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1757 sbale[3].length = els->resp[0].length;
1758 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1759 } else if (adapter->supported_features &
1760 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1761 /* try to use chained SBALs */
1762 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1763 SBAL_FLAGS0_TYPE_WRITE_READ,
1764 els->req, els->req_count,
1765 ZFCP_MAX_SBALS_PER_ELS_REQ);
1766 if (bytes <= 0) {
1767 ZFCP_LOG_INFO("error: creation of ELS request failed "
1768 "(adapter %s, port d_id: 0x%08x)\n",
1769 zfcp_get_busid_by_adapter(adapter), d_id);
1770 if (bytes == 0) {
1771 ret = -ENOMEM;
1772 } else {
1773 ret = bytes;
1774 }
1775 goto failed_send;
1776 }
1777 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1778 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1779 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1780 SBAL_FLAGS0_TYPE_WRITE_READ,
1781 els->resp, els->resp_count,
1782 ZFCP_MAX_SBALS_PER_ELS_REQ);
1783 if (bytes <= 0) {
1784 ZFCP_LOG_INFO("error: creation of ELS request failed "
1785 "(adapter %s, port d_id: 0x%08x)\n",
1786 zfcp_get_busid_by_adapter(adapter), d_id);
1787 if (bytes == 0) {
1788 ret = -ENOMEM;
1789 } else {
1790 ret = bytes;
1791 }
1792 goto failed_send;
1793 }
1794 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1795 } else {
1796 /* reject request */
1797 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1798 ", ELS request too big (adapter %s, "
1799 "port d_id: 0x%08x)\n",
1800 zfcp_get_busid_by_adapter(adapter), d_id);
1801 ret = -EOPNOTSUPP;
1802 goto failed_send;
1803 }
1804
1805 /* settings in QTCB */
1806 fsf_req->qtcb->bottom.support.d_id = d_id;
1807 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1808 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1809 fsf_req->data.send_els = els;
1810
1811 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1812
1813 /* start QDIO request for this FSF request */
1814 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1815 if (ret) {
1816 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1817 "(adapter %s, port d_id: 0x%08x)\n",
1818 zfcp_get_busid_by_adapter(adapter), d_id);
1819 goto failed_send;
1820 }
1821
1822 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1823 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1824 goto out;
1825
1826 failed_send:
1827 zfcp_fsf_req_free(fsf_req);
1828
1829 failed_req:
1830 out:
1831 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1832 lock_flags);
1833
1834 return ret;
1835}
1836
1837/**
1838 * zfcp_fsf_send_els_handler - handler for ELS commands
1839 * @fsf_req: pointer to struct zfcp_fsf_req
1840 *
1841 * Data specific for the ELS command is passed by
1842 * fsf_req->data.send_els
1843 * Usually a specific handler for the command is called via
1844 * fsf_req->data.send_els->handler at end of this function.
1845 */
1846static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1847{
1848 struct zfcp_adapter *adapter;
1849 fc_id_t d_id;
1850 struct zfcp_port *port;
1851 struct fsf_qtcb_header *header;
1852 struct fsf_qtcb_bottom_support *bottom;
1853 struct zfcp_send_els *send_els;
1854 int retval = -EINVAL;
1855 u16 subtable, rule, counter;
1856
1857 send_els = fsf_req->data.send_els;
1858 adapter = send_els->adapter;
1859 d_id = send_els->d_id;
1860 header = &fsf_req->qtcb->header;
1861 bottom = &fsf_req->qtcb->bottom.support;
1862
1863 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1864 goto skip_fsfstatus;
1865
1866 switch (header->fsf_status) {
1867
1868 case FSF_GOOD:
1869 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
1870 retval = 0;
1871 break;
1872
1873 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1874 ZFCP_LOG_FLAGS(2, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
1875 if (adapter->fc_service_class <= 3) {
1876 ZFCP_LOG_INFO("error: adapter %s does "
1877 "not support fibrechannel class %d.\n",
1878 zfcp_get_busid_by_adapter(adapter),
1879 adapter->fc_service_class);
1880 } else {
1881 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1882 "adapter %s is invalid. "
1883 "(debug info %d)\n",
1884 zfcp_get_busid_by_adapter(adapter),
1885 adapter->fc_service_class);
1886 }
1887 /* stop operation for this adapter */
1888 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1889 zfcp_erp_adapter_shutdown(adapter, 0);
1890 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1891 break;
1892
1893 case FSF_ADAPTER_STATUS_AVAILABLE:
1894 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1895 switch (header->fsf_status_qual.word[0]){
1896 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1897 ZFCP_LOG_FLAGS(2,"FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1898 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1899 if (send_els->ls_code != ZFCP_LS_ADISC) {
1900 read_lock(&zfcp_data.config_lock);
1901 port = zfcp_get_port_by_did(adapter, d_id);
1902 if (port)
1903 zfcp_test_link(port);
1904 read_unlock(&zfcp_data.config_lock);
1905 }
1906 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1907 break;
1908 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1909 ZFCP_LOG_FLAGS(2,"FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1910 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1911 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1912 retval =
1913 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1914 (struct zfcp_ls_rjt_par *)
1915 &header->fsf_status_qual.word[2]);
1916 break;
1917 case FSF_SQ_RETRY_IF_POSSIBLE:
1918 ZFCP_LOG_FLAGS(2, "FSF_SQ_RETRY_IF_POSSIBLE\n");
1919 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1920 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1921 break;
1922 default:
1923 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1924 header->fsf_status_qual.word[0]);
1925 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1926 (char*)header->fsf_status_qual.word, 16);
1927 }
1928 break;
1929
1930 case FSF_ELS_COMMAND_REJECTED:
1931 ZFCP_LOG_FLAGS(2, "FSF_ELS_COMMAND_REJECTED\n");
1932 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1933 "prohibited sending "
1934 "(adapter: %s, port d_id: 0x%08x)\n",
1935 zfcp_get_busid_by_adapter(adapter), d_id);
1936
1937 break;
1938
1939 case FSF_PAYLOAD_SIZE_MISMATCH:
1940 ZFCP_LOG_FLAGS(2, "FSF_PAYLOAD_SIZE_MISMATCH\n");
1941 ZFCP_LOG_INFO(
1942 "ELS request size and ELS response size must be either "
1943 "both 0, or both greater than 0 "
1944 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1945 zfcp_get_busid_by_adapter(adapter),
1946 bottom->req_buf_length,
1947 bottom->resp_buf_length);
1948 break;
1949
1950 case FSF_REQUEST_SIZE_TOO_LARGE:
1951 ZFCP_LOG_FLAGS(2, "FSF_REQUEST_SIZE_TOO_LARGE\n");
1952 ZFCP_LOG_INFO(
1953 "Length of the ELS request buffer, "
1954 "specified in QTCB bottom, "
1955 "exceeds the size of the buffers "
1956 "that have been allocated for ELS request data "
1957 "(adapter: %s, req_buf_length=%d)\n",
1958 zfcp_get_busid_by_adapter(adapter),
1959 bottom->req_buf_length);
1960 break;
1961
1962 case FSF_RESPONSE_SIZE_TOO_LARGE:
1963 ZFCP_LOG_FLAGS(2, "FSF_RESPONSE_SIZE_TOO_LARGE\n");
1964 ZFCP_LOG_INFO(
1965 "Length of the ELS response buffer, "
1966 "specified in QTCB bottom, "
1967 "exceeds the size of the buffers "
1968 "that have been allocated for ELS response data "
1969 "(adapter: %s, resp_buf_length=%d)\n",
1970 zfcp_get_busid_by_adapter(adapter),
1971 bottom->resp_buf_length);
1972 break;
1973
1974 case FSF_SBAL_MISMATCH:
1975 /* should never occure, avoided in zfcp_fsf_send_els */
1976 ZFCP_LOG_FLAGS(2, "FSF_SBAL_MISMATCH\n");
1977 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1978 "resp_buf_length=%d)\n",
1979 zfcp_get_busid_by_adapter(adapter),
1980 bottom->req_buf_length, bottom->resp_buf_length);
1981 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1982 break;
1983
1984 case FSF_ACCESS_DENIED:
1985 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
1986 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1987 "(adapter %s, port d_id=0x%08x)\n",
1988 zfcp_get_busid_by_adapter(adapter), d_id);
1989 for (counter = 0; counter < 2; counter++) {
1990 subtable = header->fsf_status_qual.halfword[counter * 2];
1991 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1992 switch (subtable) {
1993 case FSF_SQ_CFDC_SUBTABLE_OS:
1994 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1995 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1996 case FSF_SQ_CFDC_SUBTABLE_LUN:
1997 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1998 zfcp_act_subtable_type[subtable], rule);
1999 break;
2000 }
2001 }
2002 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
2003 read_lock(&zfcp_data.config_lock);
2004 port = zfcp_get_port_by_did(adapter, d_id);
2005 if (port != NULL)
2006 zfcp_erp_port_access_denied(port);
2007 read_unlock(&zfcp_data.config_lock);
2008 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2009 break;
2010
2011 default:
2012 ZFCP_LOG_NORMAL(
2013 "bug: An unknown FSF Status was presented "
2014 "(adapter: %s, fsf_status=0x%08x)\n",
2015 zfcp_get_busid_by_adapter(adapter),
2016 header->fsf_status);
2017 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
2018 debug_exception(adapter->erp_dbf, 0,
2019 &header->fsf_status_qual.word[0], sizeof(u32));
2020 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2021 break;
2022 }
2023
2024skip_fsfstatus:
2025 send_els->status = retval;
2026
2027 if (send_els->handler != 0)
2028 send_els->handler(send_els->handler_data);
2029
2030 return retval;
2031}
2032
2033/*
2034 * function:
2035 *
2036 * purpose:
2037 *
2038 * returns: address of initiated FSF request
2039 * NULL - request could not be initiated
2040 */
2041int
2042zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
2043{
2044 volatile struct qdio_buffer_element *sbale;
2045 unsigned long lock_flags;
2046 int retval = 0;
2047
2048 /* setup new FSF request */
2049 retval = zfcp_fsf_req_create(erp_action->adapter,
2050 FSF_QTCB_EXCHANGE_CONFIG_DATA,
2051 ZFCP_REQ_AUTO_CLEANUP,
2052 erp_action->adapter->pool.fsf_req_erp,
2053 &lock_flags, &(erp_action->fsf_req));
2054 if (retval < 0) {
2055 ZFCP_LOG_INFO("error: Could not create exchange configuration "
2056 "data request for adapter %s.\n",
2057 zfcp_get_busid_by_adapter(erp_action->adapter));
2058 goto out;
2059 }
2060
2061 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2062 erp_action->fsf_req->sbal_curr, 0);
2063 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2064 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2065
2066 erp_action->fsf_req->erp_action = erp_action;
2067 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
2068 (FSF_FEATURE_CFDC | FSF_FEATURE_LUN_SHARING);
2069
2070 /* start QDIO request for this FSF request */
2071 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2072 if (retval) {
2073 ZFCP_LOG_INFO
2074 ("error: Could not send exchange configuration data "
2075 "command on the adapter %s\n",
2076 zfcp_get_busid_by_adapter(erp_action->adapter));
2077 zfcp_fsf_req_free(erp_action->fsf_req);
2078 erp_action->fsf_req = NULL;
2079 goto out;
2080 }
2081
2082 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
2083 "(adapter %s)\n",
2084 zfcp_get_busid_by_adapter(erp_action->adapter));
2085
2086 out:
2087 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2088 lock_flags);
2089 return retval;
2090}
2091
2092/**
2093 * zfcp_fsf_exchange_config_evaluate
2094 * @fsf_req: fsf_req which belongs to xchg config data request
2095 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2096 *
2097 * returns: -EIO on error, 0 otherwise
2098 */
2099static int
2100zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2101{
2102 struct fsf_qtcb_bottom_config *bottom;
2103 struct zfcp_adapter *adapter = fsf_req->adapter;
2104
2105 bottom = &fsf_req->qtcb->bottom.config;
2106 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2107 bottom->low_qtcb_version, bottom->high_qtcb_version);
2108 adapter->fsf_lic_version = bottom->lic_version;
2109 adapter->supported_features = bottom->supported_features;
2110
2111 if (xchg_ok) {
2112 adapter->wwnn = bottom->nport_serv_param.wwnn;
2113 adapter->wwpn = bottom->nport_serv_param.wwpn;
2114 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2115 adapter->fc_topology = bottom->fc_topology;
2116 adapter->fc_link_speed = bottom->fc_link_speed;
2117 adapter->hydra_version = bottom->adapter_type;
2118 } else {
2119 adapter->wwnn = 0;
2120 adapter->wwpn = 0;
2121 adapter->s_id = 0;
2122 adapter->fc_topology = 0;
2123 adapter->fc_link_speed = 0;
2124 adapter->hydra_version = 0;
2125 }
2126
2127 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2128 adapter->hardware_version = bottom->hardware_version;
2129 memcpy(adapter->serial_number, bottom->serial_number, 17);
2130 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2131 }
2132
2133 ZFCP_LOG_INFO("The adapter %s reported the following characteristics:\n"
2134 "WWNN 0x%016Lx, "
2135 "WWPN 0x%016Lx, "
2136 "S_ID 0x%08x,\n"
2137 "adapter version 0x%x, "
2138 "LIC version 0x%x, "
2139 "FC link speed %d Gb/s\n",
2140 zfcp_get_busid_by_adapter(adapter),
2141 adapter->wwnn,
2142 adapter->wwpn,
2143 (unsigned int) adapter->s_id,
2144 adapter->hydra_version,
2145 adapter->fsf_lic_version,
2146 adapter->fc_link_speed);
2147 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2148 ZFCP_LOG_NORMAL("error: the adapter %s "
2149 "only supports newer control block "
2150 "versions in comparison to this device "
2151 "driver (try updated device driver)\n",
2152 zfcp_get_busid_by_adapter(adapter));
2153 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2154 zfcp_erp_adapter_shutdown(adapter, 0);
2155 return -EIO;
2156 }
2157 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2158 ZFCP_LOG_NORMAL("error: the adapter %s "
2159 "only supports older control block "
2160 "versions than this device driver uses"
2161 "(consider a microcode upgrade)\n",
2162 zfcp_get_busid_by_adapter(adapter));
2163 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2164 zfcp_erp_adapter_shutdown(adapter, 0);
2165 return -EIO;
2166 }
2167 return 0;
2168}
2169
2170/*
2171 * function: zfcp_fsf_exchange_config_data_handler
2172 *
2173 * purpose: is called for finished Exchange Configuration Data command
2174 *
2175 * returns:
2176 */
2177static int
2178zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2179{
2180 struct fsf_qtcb_bottom_config *bottom;
2181 struct zfcp_adapter *adapter = fsf_req->adapter;
2182
2183 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2184 return -EIO;
2185
2186 switch (fsf_req->qtcb->header.fsf_status) {
2187
2188 case FSF_GOOD:
2189 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
2190
2191 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2192 return -EIO;
2193
2194 switch (adapter->fc_topology) {
2195 case FSF_TOPO_P2P:
2196 ZFCP_LOG_FLAGS(1, "FSF_TOPO_P2P\n");
2197 ZFCP_LOG_NORMAL("error: Point-to-point fibrechannel "
2198 "configuration detected at adapter %s "
2199 "unsupported, shutting down adapter\n",
2200 zfcp_get_busid_by_adapter(adapter));
2201 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2202 "top-p-to-p");
2203 zfcp_erp_adapter_shutdown(adapter, 0);
2204 return -EIO;
2205 case FSF_TOPO_AL:
2206 ZFCP_LOG_FLAGS(1, "FSF_TOPO_AL\n");
2207 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2208 "topology detected at adapter %s "
2209 "unsupported, shutting down adapter\n",
2210 zfcp_get_busid_by_adapter(adapter));
2211 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2212 "top-al");
2213 zfcp_erp_adapter_shutdown(adapter, 0);
2214 return -EIO;
2215 case FSF_TOPO_FABRIC:
2216 ZFCP_LOG_FLAGS(1, "FSF_TOPO_FABRIC\n");
2217 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2218 "network detected at adapter %s.\n",
2219 zfcp_get_busid_by_adapter(adapter));
2220 break;
2221 default:
2222 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2223 "reported by the exchange "
2224 "configuration command for "
2225 "the adapter %s is not "
2226 "of a type known to the zfcp "
2227 "driver, shutting down adapter\n",
2228 zfcp_get_busid_by_adapter(adapter));
2229 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2230 "unknown-topo");
2231 zfcp_erp_adapter_shutdown(adapter, 0);
2232 return -EIO;
2233 }
2234 bottom = &fsf_req->qtcb->bottom.config;
2235 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2236 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2237 "allowed by the adapter %s "
2238 "is lower than the minimum "
2239 "required by the driver (%ld bytes).\n",
2240 bottom->max_qtcb_size,
2241 zfcp_get_busid_by_adapter(adapter),
2242 sizeof(struct fsf_qtcb));
2243 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2244 "qtcb-size");
2245 debug_event(fsf_req->adapter->erp_dbf, 0,
2246 &bottom->max_qtcb_size, sizeof (u32));
2247 zfcp_erp_adapter_shutdown(adapter, 0);
2248 return -EIO;
2249 }
2250 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2251 &adapter->status);
2252 break;
2253 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2254 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2255
2256 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2257 return -EIO;
2258
2259 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2260 zfcp_get_busid_by_adapter(adapter));
2261 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2262 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2263 &adapter->status);
2264 zfcp_erp_adapter_failed(adapter);
2265 break;
2266 default:
2267 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2268 debug_event(fsf_req->adapter->erp_dbf, 0,
2269 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2270 zfcp_erp_adapter_shutdown(adapter, 0);
2271 return -EIO;
2272 }
2273 return 0;
2274}
2275
2276/**
2277 * zfcp_fsf_exchange_port_data - request information about local port
2278 * @adapter: for which port data is requested
2279 * @data: response to exchange port data request
2280 */
2281int
2282zfcp_fsf_exchange_port_data(struct zfcp_adapter *adapter,
2283 struct fsf_qtcb_bottom_port *data)
2284{
2285 volatile struct qdio_buffer_element *sbale;
2286 int retval = 0;
2287 unsigned long lock_flags;
2288 struct zfcp_fsf_req *fsf_req;
2289 struct timer_list *timer;
2290
2291 if(!(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT)){
2292 ZFCP_LOG_INFO("error: exchange port data "
2293 "command not supported by adapter %s\n",
2294 zfcp_get_busid_by_adapter(adapter));
2295 return -EOPNOTSUPP;
2296 }
2297
2298 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2299 if (!timer)
2300 return -ENOMEM;
2301
2302 /* setup new FSF request */
2303 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2304 0, 0, &lock_flags, &fsf_req);
2305 if (retval < 0) {
2306 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2307 "exchange port data request for"
2308 "the adapter %s.\n",
2309 zfcp_get_busid_by_adapter(adapter));
2310 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2311 lock_flags);
2312 goto out;
2313 }
2314
2315 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2316 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2317 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2318
2319 fsf_req->data.port_data = data;
2320
2321 init_timer(timer);
2322 timer->function = zfcp_fsf_request_timeout_handler;
2323 timer->data = (unsigned long) adapter;
2324 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2325
2326 retval = zfcp_fsf_req_send(fsf_req, timer);
2327 if (retval) {
2328 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2329 "command on the adapter %s\n",
2330 zfcp_get_busid_by_adapter(adapter));
2331 zfcp_fsf_req_free(fsf_req);
2332 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2333 lock_flags);
2334 goto out;
2335 }
2336
2337 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2338 zfcp_get_busid_by_adapter(adapter));
2339
2340 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2341 lock_flags);
2342
2343 wait_event(fsf_req->completion_wq,
2344 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2345 del_timer_sync(timer);
2346 zfcp_fsf_req_cleanup(fsf_req);
2347 out:
2348 kfree(timer);
2349 return retval;
2350}
2351
2352
2353/**
2354 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2355 * @fsf_req: pointer to struct zfcp_fsf_req
2356 */
2357static void
2358zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2359{
2360 struct fsf_qtcb_bottom_port *bottom;
2361 struct fsf_qtcb_bottom_port *data = fsf_req->data.port_data;
2362
2363 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2364 return;
2365
2366 switch (fsf_req->qtcb->header.fsf_status) {
2367 case FSF_GOOD:
2368 ZFCP_LOG_FLAGS(2,"FSF_GOOD\n");
2369 bottom = &fsf_req->qtcb->bottom.port;
2370 memcpy(data, bottom, sizeof(*data));
2371 break;
2372
2373 default:
2374 debug_text_event(fsf_req->adapter->erp_dbf, 0, "xchg-port-ng");
2375 debug_event(fsf_req->adapter->erp_dbf, 0,
2376 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2377 }
2378}
2379
2380
2381/*
2382 * function: zfcp_fsf_open_port
2383 *
2384 * purpose:
2385 *
2386 * returns: address of initiated FSF request
2387 * NULL - request could not be initiated
2388 */
2389int
2390zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2391{
2392 volatile struct qdio_buffer_element *sbale;
2393 unsigned long lock_flags;
2394 int retval = 0;
2395
2396 /* setup new FSF request */
2397 retval = zfcp_fsf_req_create(erp_action->adapter,
2398 FSF_QTCB_OPEN_PORT_WITH_DID,
2399 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2400 erp_action->adapter->pool.fsf_req_erp,
2401 &lock_flags, &(erp_action->fsf_req));
2402 if (retval < 0) {
2403 ZFCP_LOG_INFO("error: Could not create open port request "
2404 "for port 0x%016Lx on adapter %s.\n",
2405 erp_action->port->wwpn,
2406 zfcp_get_busid_by_adapter(erp_action->adapter));
2407 goto out;
2408 }
2409
2410 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2411 erp_action->fsf_req->sbal_curr, 0);
2412 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2413 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2414
2415 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2416 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2417 erp_action->fsf_req->data.open_port.port = erp_action->port;
2418 erp_action->fsf_req->erp_action = erp_action;
2419
2420 /* start QDIO request for this FSF request */
2421 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2422 if (retval) {
2423 ZFCP_LOG_INFO("error: Could not send open port request for "
2424 "port 0x%016Lx on adapter %s.\n",
2425 erp_action->port->wwpn,
2426 zfcp_get_busid_by_adapter(erp_action->adapter));
2427 zfcp_fsf_req_free(erp_action->fsf_req);
2428 erp_action->fsf_req = NULL;
2429 goto out;
2430 }
2431
2432 ZFCP_LOG_DEBUG("open port request initiated "
2433 "(adapter %s, port 0x%016Lx)\n",
2434 zfcp_get_busid_by_adapter(erp_action->adapter),
2435 erp_action->port->wwpn);
2436 out:
2437 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2438 lock_flags);
2439 return retval;
2440}
2441
2442/*
2443 * function: zfcp_fsf_open_port_handler
2444 *
2445 * purpose: is called for finished Open Port command
2446 *
2447 * returns:
2448 */
2449static int
2450zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2451{
2452 int retval = -EINVAL;
2453 struct zfcp_port *port;
2454 struct fsf_plogi *plogi;
2455 struct fsf_qtcb_header *header;
2456 u16 subtable, rule, counter;
2457
2458 port = fsf_req->data.open_port.port;
2459 header = &fsf_req->qtcb->header;
2460
2461 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2462 /* don't change port status in our bookkeeping */
2463 goto skip_fsfstatus;
2464 }
2465
2466 /* evaluate FSF status in QTCB */
2467 switch (header->fsf_status) {
2468
2469 case FSF_PORT_ALREADY_OPEN:
2470 ZFCP_LOG_FLAGS(0, "FSF_PORT_ALREADY_OPEN\n");
2471 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2472 "is already open.\n",
2473 port->wwpn, zfcp_get_busid_by_port(port));
2474 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2475 "fsf_s_popen");
2476 /*
2477 * This is a bug, however operation should continue normally
2478 * if it is simply ignored
2479 */
2480 break;
2481
2482 case FSF_ACCESS_DENIED:
2483 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2484 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2485 "on adapter %s\n",
2486 port->wwpn, zfcp_get_busid_by_port(port));
2487 for (counter = 0; counter < 2; counter++) {
2488 subtable = header->fsf_status_qual.halfword[counter * 2];
2489 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2490 switch (subtable) {
2491 case FSF_SQ_CFDC_SUBTABLE_OS:
2492 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2493 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2494 case FSF_SQ_CFDC_SUBTABLE_LUN:
2495 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2496 zfcp_act_subtable_type[subtable], rule);
2497 break;
2498 }
2499 }
2500 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2501 zfcp_erp_port_access_denied(port);
2502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2503 break;
2504
2505 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2506 ZFCP_LOG_FLAGS(1, "FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED\n");
2507 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2508 "The remote port 0x%016Lx on adapter %s "
2509 "could not be opened. Disabling it.\n",
2510 port->wwpn, zfcp_get_busid_by_port(port));
2511 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2512 "fsf_s_max_ports");
2513 zfcp_erp_port_failed(port);
2514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2515 break;
2516
2517 case FSF_ADAPTER_STATUS_AVAILABLE:
2518 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2519 switch (header->fsf_status_qual.word[0]) {
2520 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2521 ZFCP_LOG_FLAGS(2,
2522 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
2523 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2524 "fsf_sq_ltest");
2525 /* ERP strategy will escalate */
2526 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2527 break;
2528 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2529 /* ERP strategy will escalate */
2530 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2531 "fsf_sq_ulp");
2532 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2533 break;
2534 case FSF_SQ_NO_RETRY_POSSIBLE:
2535 ZFCP_LOG_FLAGS(0, "FSF_SQ_NO_RETRY_POSSIBLE\n");
2536 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2537 "adapter %s could not be opened. "
2538 "Disabling it.\n",
2539 port->wwpn,
2540 zfcp_get_busid_by_port(port));
2541 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2542 "fsf_sq_no_retry");
2543 zfcp_erp_port_failed(port);
2544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2545 break;
2546 default:
2547 ZFCP_LOG_NORMAL
2548 ("bug: Wrong status qualifier 0x%x arrived.\n",
2549 header->fsf_status_qual.word[0]);
2550 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2551 "fsf_sq_inval:");
2552 debug_exception(
2553 fsf_req->adapter->erp_dbf, 0,
2554 &header->fsf_status_qual.word[0],
2555 sizeof (u32));
2556 break;
2557 }
2558 break;
2559
2560 case FSF_GOOD:
2561 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2562 /* save port handle assigned by FSF */
2563 port->handle = header->port_handle;
2564 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2565 "was opened, it's port handle is 0x%x\n",
2566 port->wwpn, zfcp_get_busid_by_port(port),
2567 port->handle);
2568 /* mark port as open */
2569 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2570 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2571 retval = 0;
2572 /* check whether D_ID has changed during open */
2573 /*
2574 * FIXME: This check is not airtight, as the FCP channel does
2575 * not monitor closures of target port connections caused on
2576 * the remote side. Thus, they might miss out on invalidating
2577 * locally cached WWPNs (and other N_Port parameters) of gone
2578 * target ports. So, our heroic attempt to make things safe
2579 * could be undermined by 'open port' response data tagged with
2580 * obsolete WWPNs. Another reason to monitor potential
2581 * connection closures ourself at least (by interpreting
2582 * incoming ELS' and unsolicited status). It just crosses my
2583 * mind that one should be able to cross-check by means of
2584 * another GID_PN straight after a port has been opened.
2585 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2586 */
2587 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2588 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2589 {
2590 if (fsf_req->qtcb->bottom.support.els1_length <
2591 ((((unsigned long) &plogi->serv_param.wwpn) -
2592 ((unsigned long) plogi)) + sizeof (u64))) {
2593 ZFCP_LOG_INFO(
2594 "warning: insufficient length of "
2595 "PLOGI payload (%i)\n",
2596 fsf_req->qtcb->bottom.support.els1_length);
2597 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2598 "fsf_s_short_plogi:");
2599 /* skip sanity check and assume wwpn is ok */
2600 } else {
2601 if (plogi->serv_param.wwpn != port->wwpn) {
2602 ZFCP_LOG_INFO("warning: d_id of port "
2603 "0x%016Lx changed during "
2604 "open\n", port->wwpn);
2605 debug_text_event(
2606 fsf_req->adapter->erp_dbf, 0,
2607 "fsf_s_did_change:");
2608 atomic_clear_mask(
2609 ZFCP_STATUS_PORT_DID_DID,
2610 &port->status);
2611 } else
2612 port->wwnn = plogi->serv_param.wwnn;
2613 }
2614 }
2615 break;
2616
2617 case FSF_UNKNOWN_OP_SUBTYPE:
2618 /* should never occure, subtype not set in zfcp_fsf_open_port */
2619 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_OP_SUBTYPE\n");
2620 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2621 "op_subtype=0x%x)\n",
2622 zfcp_get_busid_by_port(port),
2623 fsf_req->qtcb->bottom.support.operation_subtype);
2624 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2625 break;
2626
2627 default:
2628 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2629 "(debug info 0x%x)\n",
2630 header->fsf_status);
2631 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2632 debug_exception(fsf_req->adapter->erp_dbf, 0,
2633 &header->fsf_status, sizeof (u32));
2634 break;
2635 }
2636
2637 skip_fsfstatus:
2638 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2639 return retval;
2640}
2641
2642/*
2643 * function: zfcp_fsf_close_port
2644 *
2645 * purpose: submit FSF command "close port"
2646 *
2647 * returns: address of initiated FSF request
2648 * NULL - request could not be initiated
2649 */
2650int
2651zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2652{
2653 volatile struct qdio_buffer_element *sbale;
2654 unsigned long lock_flags;
2655 int retval = 0;
2656
2657 /* setup new FSF request */
2658 retval = zfcp_fsf_req_create(erp_action->adapter,
2659 FSF_QTCB_CLOSE_PORT,
2660 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2661 erp_action->adapter->pool.fsf_req_erp,
2662 &lock_flags, &(erp_action->fsf_req));
2663 if (retval < 0) {
2664 ZFCP_LOG_INFO("error: Could not create a close port request "
2665 "for port 0x%016Lx on adapter %s.\n",
2666 erp_action->port->wwpn,
2667 zfcp_get_busid_by_adapter(erp_action->adapter));
2668 goto out;
2669 }
2670
2671 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2672 erp_action->fsf_req->sbal_curr, 0);
2673 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2674 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2675
2676 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2677 erp_action->fsf_req->data.close_port.port = erp_action->port;
2678 erp_action->fsf_req->erp_action = erp_action;
2679 erp_action->fsf_req->qtcb->header.port_handle =
2680 erp_action->port->handle;
2681
2682 /* start QDIO request for this FSF request */
2683 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2684 if (retval) {
2685 ZFCP_LOG_INFO("error: Could not send a close port request for "
2686 "port 0x%016Lx on adapter %s.\n",
2687 erp_action->port->wwpn,
2688 zfcp_get_busid_by_adapter(erp_action->adapter));
2689 zfcp_fsf_req_free(erp_action->fsf_req);
2690 erp_action->fsf_req = NULL;
2691 goto out;
2692 }
2693
2694 ZFCP_LOG_TRACE("close port request initiated "
2695 "(adapter %s, port 0x%016Lx)\n",
2696 zfcp_get_busid_by_adapter(erp_action->adapter),
2697 erp_action->port->wwpn);
2698 out:
2699 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2700 lock_flags);
2701 return retval;
2702}
2703
2704/*
2705 * function: zfcp_fsf_close_port_handler
2706 *
2707 * purpose: is called for finished Close Port FSF command
2708 *
2709 * returns:
2710 */
2711static int
2712zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2713{
2714 int retval = -EINVAL;
2715 struct zfcp_port *port;
2716
2717 port = fsf_req->data.close_port.port;
2718
2719 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2720 /* don't change port status in our bookkeeping */
2721 goto skip_fsfstatus;
2722 }
2723
2724 /* evaluate FSF status in QTCB */
2725 switch (fsf_req->qtcb->header.fsf_status) {
2726
2727 case FSF_PORT_HANDLE_NOT_VALID:
2728 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2729 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2730 "0x%016Lx on adapter %s invalid. This may happen "
2731 "occasionally.\n", port->handle,
2732 port->wwpn, zfcp_get_busid_by_port(port));
2733 ZFCP_LOG_DEBUG("status qualifier:\n");
2734 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2735 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2736 sizeof (union fsf_status_qual));
2737 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2738 "fsf_s_phand_nv");
2739 zfcp_erp_adapter_reopen(port->adapter, 0);
2740 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2741 break;
2742
2743 case FSF_ADAPTER_STATUS_AVAILABLE:
2744 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2745 /* Note: FSF has actually closed the port in this case.
2746 * The status code is just daft. Fingers crossed for a change
2747 */
2748 retval = 0;
2749 break;
2750
2751 case FSF_GOOD:
2752 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2753 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2754 "port handle 0x%x\n", port->wwpn,
2755 zfcp_get_busid_by_port(port), port->handle);
2756 zfcp_erp_modify_port_status(port,
2757 ZFCP_STATUS_COMMON_OPEN,
2758 ZFCP_CLEAR);
2759 retval = 0;
2760 break;
2761
2762 default:
2763 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2764 "(debug info 0x%x)\n",
2765 fsf_req->qtcb->header.fsf_status);
2766 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2767 debug_exception(fsf_req->adapter->erp_dbf, 0,
2768 &fsf_req->qtcb->header.fsf_status,
2769 sizeof (u32));
2770 break;
2771 }
2772
2773 skip_fsfstatus:
2774 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2775 return retval;
2776}
2777
2778/*
2779 * function: zfcp_fsf_close_physical_port
2780 *
2781 * purpose: submit FSF command "close physical port"
2782 *
2783 * returns: address of initiated FSF request
2784 * NULL - request could not be initiated
2785 */
2786int
2787zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2788{
2789 int retval = 0;
2790 unsigned long lock_flags;
2791 volatile struct qdio_buffer_element *sbale;
2792
2793 /* setup new FSF request */
2794 retval = zfcp_fsf_req_create(erp_action->adapter,
2795 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2796 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2797 erp_action->adapter->pool.fsf_req_erp,
2798 &lock_flags, &erp_action->fsf_req);
2799 if (retval < 0) {
2800 ZFCP_LOG_INFO("error: Could not create close physical port "
2801 "request (adapter %s, port 0x%016Lx)\n",
2802 zfcp_get_busid_by_adapter(erp_action->adapter),
2803 erp_action->port->wwpn);
2804
2805 goto out;
2806 }
2807
2808 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2809 erp_action->fsf_req->sbal_curr, 0);
2810 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2811 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2812
2813 /* mark port as being closed */
2814 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2815 &erp_action->port->status);
2816 /* save a pointer to this port */
2817 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2818 /* port to be closeed */
2819 erp_action->fsf_req->qtcb->header.port_handle =
2820 erp_action->port->handle;
2821 erp_action->fsf_req->erp_action = erp_action;
2822
2823 /* start QDIO request for this FSF request */
2824 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2825 if (retval) {
2826 ZFCP_LOG_INFO("error: Could not send close physical port "
2827 "request (adapter %s, port 0x%016Lx)\n",
2828 zfcp_get_busid_by_adapter(erp_action->adapter),
2829 erp_action->port->wwpn);
2830 zfcp_fsf_req_free(erp_action->fsf_req);
2831 erp_action->fsf_req = NULL;
2832 goto out;
2833 }
2834
2835 ZFCP_LOG_TRACE("close physical port request initiated "
2836 "(adapter %s, port 0x%016Lx)\n",
2837 zfcp_get_busid_by_adapter(erp_action->adapter),
2838 erp_action->port->wwpn);
2839 out:
2840 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2841 lock_flags);
2842 return retval;
2843}
2844
2845/*
2846 * function: zfcp_fsf_close_physical_port_handler
2847 *
2848 * purpose: is called for finished Close Physical Port FSF command
2849 *
2850 * returns:
2851 */
2852static int
2853zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2854{
2855 int retval = -EINVAL;
2856 struct zfcp_port *port;
2857 struct zfcp_unit *unit;
2858 struct fsf_qtcb_header *header;
2859 u16 subtable, rule, counter;
2860
2861 port = fsf_req->data.close_physical_port.port;
2862 header = &fsf_req->qtcb->header;
2863
2864 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2865 /* don't change port status in our bookkeeping */
2866 goto skip_fsfstatus;
2867 }
2868
2869 /* evaluate FSF status in QTCB */
2870 switch (header->fsf_status) {
2871
2872 case FSF_PORT_HANDLE_NOT_VALID:
2873 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2874 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2875 "(adapter %s, port 0x%016Lx). "
2876 "This may happen occasionally.\n",
2877 port->handle,
2878 zfcp_get_busid_by_port(port),
2879 port->wwpn);
2880 ZFCP_LOG_DEBUG("status qualifier:\n");
2881 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2882 (char *) &header->fsf_status_qual,
2883 sizeof (union fsf_status_qual));
2884 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2885 "fsf_s_phand_nv");
2886 zfcp_erp_adapter_reopen(port->adapter, 0);
2887 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2888 break;
2889
2890 case FSF_ACCESS_DENIED:
2891 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2892 ZFCP_LOG_NORMAL("Access denied, cannot close "
2893 "physical port 0x%016Lx on adapter %s\n",
2894 port->wwpn, zfcp_get_busid_by_port(port));
2895 for (counter = 0; counter < 2; counter++) {
2896 subtable = header->fsf_status_qual.halfword[counter * 2];
2897 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2898 switch (subtable) {
2899 case FSF_SQ_CFDC_SUBTABLE_OS:
2900 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2901 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2902 case FSF_SQ_CFDC_SUBTABLE_LUN:
2903 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2904 zfcp_act_subtable_type[subtable], rule);
2905 break;
2906 }
2907 }
2908 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2909 zfcp_erp_port_access_denied(port);
2910 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2911 break;
2912
2913 case FSF_PORT_BOXED:
2914 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
2915 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2916 "%s needs to be reopened but it was attempted "
2917 "to close it physically.\n",
2918 port->wwpn,
2919 zfcp_get_busid_by_port(port));
2920 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2921 zfcp_erp_port_reopen(port, 0);
2922 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2923 ZFCP_STATUS_FSFREQ_RETRY;
2924 break;
2925
2926 case FSF_ADAPTER_STATUS_AVAILABLE:
2927 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2928 switch (header->fsf_status_qual.word[0]) {
2929 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2930 ZFCP_LOG_FLAGS(2,
2931 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
2932 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2933 "fsf_sq_ltest");
2934 /* This will now be escalated by ERP */
2935 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2936 break;
2937 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2938 ZFCP_LOG_FLAGS(2,
2939 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
2940 /* ERP strategy will escalate */
2941 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2942 "fsf_sq_ulp");
2943 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2944 break;
2945 default:
2946 ZFCP_LOG_NORMAL
2947 ("bug: Wrong status qualifier 0x%x arrived.\n",
2948 header->fsf_status_qual.word[0]);
2949 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2950 "fsf_sq_inval:");
2951 debug_exception(
2952 fsf_req->adapter->erp_dbf, 0,
2953 &header->fsf_status_qual.word[0], sizeof (u32));
2954 break;
2955 }
2956 break;
2957
2958 case FSF_GOOD:
2959 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2960 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2961 "physically closed, port handle 0x%x\n",
2962 port->wwpn,
2963 zfcp_get_busid_by_port(port), port->handle);
2964 /* can't use generic zfcp_erp_modify_port_status because
2965 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2966 */
2967 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2968 list_for_each_entry(unit, &port->unit_list_head, list)
2969 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2970 retval = 0;
2971 break;
2972
2973 default:
2974 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2975 "(debug info 0x%x)\n",
2976 header->fsf_status);
2977 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2978 debug_exception(fsf_req->adapter->erp_dbf, 0,
2979 &header->fsf_status, sizeof (u32));
2980 break;
2981 }
2982
2983 skip_fsfstatus:
2984 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2985 return retval;
2986}
2987
2988/*
2989 * function: zfcp_fsf_open_unit
2990 *
2991 * purpose:
2992 *
2993 * returns:
2994 *
2995 * assumptions: This routine does not check whether the associated
2996 * remote port has already been opened. This should be
2997 * done by calling routines. Otherwise some status
2998 * may be presented by FSF
2999 */
3000int
3001zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3002{
3003 volatile struct qdio_buffer_element *sbale;
3004 unsigned long lock_flags;
3005 int retval = 0;
3006
3007 /* setup new FSF request */
3008 retval = zfcp_fsf_req_create(erp_action->adapter,
3009 FSF_QTCB_OPEN_LUN,
3010 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3011 erp_action->adapter->pool.fsf_req_erp,
3012 &lock_flags, &(erp_action->fsf_req));
3013 if (retval < 0) {
3014 ZFCP_LOG_INFO("error: Could not create open unit request for "
3015 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3016 erp_action->unit->fcp_lun,
3017 erp_action->unit->port->wwpn,
3018 zfcp_get_busid_by_adapter(erp_action->adapter));
3019 goto out;
3020 }
3021
3022 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3023 erp_action->fsf_req->sbal_curr, 0);
3024 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3025 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3026
3027 erp_action->fsf_req->qtcb->header.port_handle =
3028 erp_action->port->handle;
3029 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
3030 erp_action->unit->fcp_lun;
3031 erp_action->fsf_req->qtcb->bottom.support.option =
3032 FSF_OPEN_LUN_SUPPRESS_BOXING;
3033 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
3034 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
3035 erp_action->fsf_req->erp_action = erp_action;
3036
3037 /* start QDIO request for this FSF request */
3038 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3039 if (retval) {
3040 ZFCP_LOG_INFO("error: Could not send an open unit request "
3041 "on the adapter %s, port 0x%016Lx for "
3042 "unit 0x%016Lx\n",
3043 zfcp_get_busid_by_adapter(erp_action->adapter),
3044 erp_action->port->wwpn,
3045 erp_action->unit->fcp_lun);
3046 zfcp_fsf_req_free(erp_action->fsf_req);
3047 erp_action->fsf_req = NULL;
3048 goto out;
3049 }
3050
3051 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3052 "port 0x%016Lx, unit 0x%016Lx)\n",
3053 zfcp_get_busid_by_adapter(erp_action->adapter),
3054 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3055 out:
3056 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3057 lock_flags);
3058 return retval;
3059}
3060
3061/*
3062 * function: zfcp_fsf_open_unit_handler
3063 *
3064 * purpose: is called for finished Open LUN command
3065 *
3066 * returns:
3067 */
3068static int
3069zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3070{
3071 int retval = -EINVAL;
3072 struct zfcp_adapter *adapter;
3073 struct zfcp_unit *unit;
3074 struct fsf_qtcb_header *header;
3075 struct fsf_qtcb_bottom_support *bottom;
3076 struct fsf_queue_designator *queue_designator;
3077 u16 subtable, rule, counter;
3078 u32 allowed, exclusive, readwrite;
3079
3080 unit = fsf_req->data.open_unit.unit;
3081
3082 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3083 /* don't change unit status in our bookkeeping */
3084 goto skip_fsfstatus;
3085 }
3086
3087 adapter = fsf_req->adapter;
3088 header = &fsf_req->qtcb->header;
3089 bottom = &fsf_req->qtcb->bottom.support;
3090 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3091
3092 allowed = bottom->lun_access_info & FSF_UNIT_ACCESS_OPEN_LUN_ALLOWED;
3093 exclusive = bottom->lun_access_info & FSF_UNIT_ACCESS_EXCLUSIVE;
3094 readwrite = bottom->lun_access_info & FSF_UNIT_ACCESS_OUTBOUND_TRANSFER;
3095
3096 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3097 ZFCP_STATUS_UNIT_SHARED |
3098 ZFCP_STATUS_UNIT_READONLY,
3099 &unit->status);
3100
3101 /* evaluate FSF status in QTCB */
3102 switch (header->fsf_status) {
3103
3104 case FSF_PORT_HANDLE_NOT_VALID:
3105 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
3106 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3107 "for port 0x%016Lx on adapter %s invalid "
3108 "This may happen occasionally\n",
3109 unit->port->handle,
3110 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3111 ZFCP_LOG_DEBUG("status qualifier:\n");
3112 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3113 (char *) &header->fsf_status_qual,
3114 sizeof (union fsf_status_qual));
3115 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3116 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3117 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3118 break;
3119
3120 case FSF_LUN_ALREADY_OPEN:
3121 ZFCP_LOG_FLAGS(0, "FSF_LUN_ALREADY_OPEN\n");
3122 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3123 "remote port 0x%016Lx on adapter %s twice.\n",
3124 unit->fcp_lun,
3125 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3126 debug_text_exception(adapter->erp_dbf, 0,
3127 "fsf_s_uopen");
3128 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3129 break;
3130
3131 case FSF_ACCESS_DENIED:
3132 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
3133 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3134 "remote port 0x%016Lx on adapter %s\n",
3135 unit->fcp_lun, unit->port->wwpn,
3136 zfcp_get_busid_by_unit(unit));
3137 for (counter = 0; counter < 2; counter++) {
3138 subtable = header->fsf_status_qual.halfword[counter * 2];
3139 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3140 switch (subtable) {
3141 case FSF_SQ_CFDC_SUBTABLE_OS:
3142 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3143 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3144 case FSF_SQ_CFDC_SUBTABLE_LUN:
3145 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3146 zfcp_act_subtable_type[subtable], rule);
3147 break;
3148 }
3149 }
3150 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3151 zfcp_erp_unit_access_denied(unit);
3152 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3153 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3154 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3155 break;
3156
3157 case FSF_PORT_BOXED:
3158 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
3159 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3160 "needs to be reopened\n",
3161 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3162 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3163 zfcp_erp_port_reopen(unit->port, 0);
3164 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3165 ZFCP_STATUS_FSFREQ_RETRY;
3166 break;
3167
3168 case FSF_LUN_SHARING_VIOLATION:
3169 ZFCP_LOG_FLAGS(2, "FSF_LUN_SHARING_VIOLATION\n");
3170 if (header->fsf_status_qual.word[0] != 0) {
3171 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3172 "with WWPN 0x%Lx "
3173 "connected to the adapter %s "
3174 "is already in use in LPAR%d, CSS%d\n",
3175 unit->fcp_lun,
3176 unit->port->wwpn,
3177 zfcp_get_busid_by_unit(unit),
3178 queue_designator->hla,
3179 queue_designator->cssid);
3180 } else {
3181 subtable = header->fsf_status_qual.halfword[4];
3182 rule = header->fsf_status_qual.halfword[5];
3183 switch (subtable) {
3184 case FSF_SQ_CFDC_SUBTABLE_OS:
3185 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3186 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3187 case FSF_SQ_CFDC_SUBTABLE_LUN:
3188 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3189 "remote port with WWPN 0x%Lx "
3190 "connected to the adapter %s "
3191 "is denied (%s rule %d)\n",
3192 unit->fcp_lun,
3193 unit->port->wwpn,
3194 zfcp_get_busid_by_unit(unit),
3195 zfcp_act_subtable_type[subtable],
3196 rule);
3197 break;
3198 }
3199 }
3200 ZFCP_LOG_DEBUG("status qualifier:\n");
3201 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3202 (char *) &header->fsf_status_qual,
3203 sizeof (union fsf_status_qual));
3204 debug_text_event(adapter->erp_dbf, 2,
3205 "fsf_s_l_sh_vio");
3206 zfcp_erp_unit_access_denied(unit);
3207 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3208 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3209 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3210 break;
3211
3212 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3213 ZFCP_LOG_FLAGS(1, "FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED\n");
3214 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3215 "There is no handle (temporary port identifier) "
3216 "available for unit 0x%016Lx on port 0x%016Lx "
3217 "on adapter %s\n",
3218 unit->fcp_lun,
3219 unit->port->wwpn,
3220 zfcp_get_busid_by_unit(unit));
3221 debug_text_event(adapter->erp_dbf, 1,
3222 "fsf_s_max_units");
3223 zfcp_erp_unit_failed(unit);
3224 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3225 break;
3226
3227 case FSF_ADAPTER_STATUS_AVAILABLE:
3228 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3229 switch (header->fsf_status_qual.word[0]) {
3230 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3231 ZFCP_LOG_FLAGS(2,
3232 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3233 /* Re-establish link to port */
3234 debug_text_event(adapter->erp_dbf, 1,
3235 "fsf_sq_ltest");
3236 zfcp_erp_port_reopen(unit->port, 0);
3237 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3238 break;
3239 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3240 ZFCP_LOG_FLAGS(2,
3241 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3242 /* ERP strategy will escalate */
3243 debug_text_event(adapter->erp_dbf, 1,
3244 "fsf_sq_ulp");
3245 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3246 break;
3247 default:
3248 ZFCP_LOG_NORMAL
3249 ("bug: Wrong status qualifier 0x%x arrived.\n",
3250 header->fsf_status_qual.word[0]);
3251 debug_text_event(adapter->erp_dbf, 0,
3252 "fsf_sq_inval:");
3253 debug_exception(adapter->erp_dbf, 0,
3254 &header->fsf_status_qual.word[0],
3255 sizeof (u32));
3256 }
3257 break;
3258
3259 case FSF_INVALID_COMMAND_OPTION:
3260 ZFCP_LOG_FLAGS(2, "FSF_INVALID_COMMAND_OPTION\n");
3261 ZFCP_LOG_NORMAL(
3262 "Invalid option 0x%x has been specified "
3263 "in QTCB bottom sent to the adapter %s\n",
3264 bottom->option,
3265 zfcp_get_busid_by_adapter(adapter));
3266 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3267 retval = -EINVAL;
3268 break;
3269
3270 case FSF_GOOD:
3271 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3272 /* save LUN handle assigned by FSF */
3273 unit->handle = header->lun_handle;
3274 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3275 "adapter %s opened, port handle 0x%x\n",
3276 unit->fcp_lun,
3277 unit->port->wwpn,
3278 zfcp_get_busid_by_unit(unit),
3279 unit->handle);
3280 /* mark unit as open */
3281 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3282
3283 if (adapter->supported_features & FSF_FEATURE_LUN_SHARING){
3284 if (!exclusive)
3285 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3286 &unit->status);
3287
3288 if (!readwrite) {
3289 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3290 &unit->status);
3291 ZFCP_LOG_NORMAL("read-only access for unit "
3292 "(adapter %s, wwpn=0x%016Lx, "
3293 "fcp_lun=0x%016Lx)\n",
3294 zfcp_get_busid_by_unit(unit),
3295 unit->port->wwpn,
3296 unit->fcp_lun);
3297 }
3298
3299 if (exclusive && !readwrite) {
3300 ZFCP_LOG_NORMAL("exclusive access of read-only "
3301 "unit not supported\n");
3302 zfcp_erp_unit_failed(unit);
3303 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3304 zfcp_erp_unit_shutdown(unit, 0);
3305 } else if (!exclusive && readwrite) {
3306 ZFCP_LOG_NORMAL("shared access of read-write "
3307 "unit not supported\n");
3308 zfcp_erp_unit_failed(unit);
3309 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3310 zfcp_erp_unit_shutdown(unit, 0);
3311 }
3312 }
3313
3314 retval = 0;
3315 break;
3316
3317 default:
3318 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3319 "(debug info 0x%x)\n",
3320 header->fsf_status);
3321 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3322 debug_exception(adapter->erp_dbf, 0,
3323 &header->fsf_status, sizeof (u32));
3324 break;
3325 }
3326
3327 skip_fsfstatus:
3328 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3329 return retval;
3330}
3331
3332/*
3333 * function: zfcp_fsf_close_unit
3334 *
3335 * purpose:
3336 *
3337 * returns: address of fsf_req - request successfully initiated
3338 * NULL -
3339 *
3340 * assumptions: This routine does not check whether the associated
3341 * remote port/lun has already been opened. This should be
3342 * done by calling routines. Otherwise some status
3343 * may be presented by FSF
3344 */
3345int
3346zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3347{
3348 volatile struct qdio_buffer_element *sbale;
3349 unsigned long lock_flags;
3350 int retval = 0;
3351
3352 /* setup new FSF request */
3353 retval = zfcp_fsf_req_create(erp_action->adapter,
3354 FSF_QTCB_CLOSE_LUN,
3355 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3356 erp_action->adapter->pool.fsf_req_erp,
3357 &lock_flags, &(erp_action->fsf_req));
3358 if (retval < 0) {
3359 ZFCP_LOG_INFO("error: Could not create close unit request for "
3360 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3361 erp_action->unit->fcp_lun,
3362 erp_action->port->wwpn,
3363 zfcp_get_busid_by_adapter(erp_action->adapter));
3364 goto out;
3365 }
3366
3367 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3368 erp_action->fsf_req->sbal_curr, 0);
3369 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3370 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3371
3372 erp_action->fsf_req->qtcb->header.port_handle =
3373 erp_action->port->handle;
3374 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3375 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3376 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3377 erp_action->fsf_req->erp_action = erp_action;
3378
3379 /* start QDIO request for this FSF request */
3380 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3381 if (retval) {
3382 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3383 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3384 erp_action->unit->fcp_lun,
3385 erp_action->port->wwpn,
3386 zfcp_get_busid_by_adapter(erp_action->adapter));
3387 zfcp_fsf_req_free(erp_action->fsf_req);
3388 erp_action->fsf_req = NULL;
3389 goto out;
3390 }
3391
3392 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3393 "port 0x%016Lx, unit 0x%016Lx)\n",
3394 zfcp_get_busid_by_adapter(erp_action->adapter),
3395 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3396 out:
3397 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3398 lock_flags);
3399 return retval;
3400}
3401
3402/*
3403 * function: zfcp_fsf_close_unit_handler
3404 *
3405 * purpose: is called for finished Close LUN FSF command
3406 *
3407 * returns:
3408 */
3409static int
3410zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3411{
3412 int retval = -EINVAL;
3413 struct zfcp_unit *unit;
3414
3415 unit = fsf_req->data.close_unit.unit; /* restore unit */
3416
3417 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3418 /* don't change unit status in our bookkeeping */
3419 goto skip_fsfstatus;
3420 }
3421
3422 /* evaluate FSF status in QTCB */
3423 switch (fsf_req->qtcb->header.fsf_status) {
3424
3425 case FSF_PORT_HANDLE_NOT_VALID:
3426 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
3427 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3428 "0x%016Lx on adapter %s invalid. This may "
3429 "happen in rare circumstances\n",
3430 unit->port->handle,
3431 unit->port->wwpn,
3432 zfcp_get_busid_by_unit(unit));
3433 ZFCP_LOG_DEBUG("status qualifier:\n");
3434 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3435 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3436 sizeof (union fsf_status_qual));
3437 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3438 "fsf_s_phand_nv");
3439 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3440 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3441 &fsf_req->qtcb->header.fsf_status_qual,
3442 sizeof (union fsf_status_qual));
3443 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3444 break;
3445
3446 case FSF_LUN_HANDLE_NOT_VALID:
3447 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
3448 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3449 "0x%016Lx on port 0x%016Lx on adapter %s is "
3450 "invalid. This may happen occasionally.\n",
3451 unit->handle,
3452 unit->fcp_lun,
3453 unit->port->wwpn,
3454 zfcp_get_busid_by_unit(unit));
3455 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3456 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3457 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3458 sizeof (union fsf_status_qual));
3459 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3460 "fsf_s_lhand_nv");
3461 zfcp_erp_port_reopen(unit->port, 0);
3462 zfcp_cmd_dbf_event_fsf("lunhinv", fsf_req,
3463 &fsf_req->qtcb->header.fsf_status_qual,
3464 sizeof (union fsf_status_qual));
3465 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3466 break;
3467
3468 case FSF_PORT_BOXED:
3469 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
3470 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3471 "needs to be reopened\n",
3472 unit->port->wwpn,
3473 zfcp_get_busid_by_unit(unit));
3474 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3475 zfcp_erp_port_reopen(unit->port, 0);
3476 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3477 ZFCP_STATUS_FSFREQ_RETRY;
3478 break;
3479
3480 case FSF_ADAPTER_STATUS_AVAILABLE:
3481 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3482 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3483 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3484 ZFCP_LOG_FLAGS(2,
3485 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3486 /* re-establish link to port */
3487 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3488 "fsf_sq_ltest");
3489 zfcp_erp_port_reopen(unit->port, 0);
3490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3491 break;
3492 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3493 ZFCP_LOG_FLAGS(2,
3494 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3495 /* ERP strategy will escalate */
3496 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3497 "fsf_sq_ulp");
3498 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3499 break;
3500 default:
3501 ZFCP_LOG_NORMAL
3502 ("bug: Wrong status qualifier 0x%x arrived.\n",
3503 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3504 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3505 "fsf_sq_inval:");
3506 debug_exception(
3507 fsf_req->adapter->erp_dbf, 0,
3508 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3509 sizeof (u32));
3510 break;
3511 }
3512 break;
3513
3514 case FSF_GOOD:
3515 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3516 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3517 "closed, port handle 0x%x\n",
3518 unit->fcp_lun,
3519 unit->port->wwpn,
3520 zfcp_get_busid_by_unit(unit),
3521 unit->handle);
3522 /* mark unit as closed */
3523 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3524 retval = 0;
3525 break;
3526
3527 default:
3528 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3529 "(debug info 0x%x)\n",
3530 fsf_req->qtcb->header.fsf_status);
3531 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3532 debug_exception(fsf_req->adapter->erp_dbf, 0,
3533 &fsf_req->qtcb->header.fsf_status,
3534 sizeof (u32));
3535 break;
3536 }
3537
3538 skip_fsfstatus:
3539 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3540 return retval;
3541}
3542
3543/**
3544 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3545 * @adapter: adapter where scsi command is issued
3546 * @unit: unit where command is sent to
3547 * @scsi_cmnd: scsi command to be sent
3548 * @timer: timer to be started when request is initiated
3549 * @req_flags: flags for fsf_request
3550 */
3551int
3552zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3553 struct zfcp_unit *unit,
3554 struct scsi_cmnd * scsi_cmnd,
3555 struct timer_list *timer, int req_flags)
3556{
3557 struct zfcp_fsf_req *fsf_req = NULL;
3558 struct fcp_cmnd_iu *fcp_cmnd_iu;
3559 unsigned int sbtype;
3560 unsigned long lock_flags;
3561 int real_bytes = 0;
3562 int retval = 0;
3563 int mask;
3564
3565 /* setup new FSF request */
3566 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3567 adapter->pool.fsf_req_scsi,
3568 &lock_flags, &fsf_req);
3569 if (unlikely(retval < 0)) {
3570 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3571 "for unit 0x%016Lx on port 0x%016Lx on "
3572 "adapter %s\n",
3573 unit->fcp_lun,
3574 unit->port->wwpn,
3575 zfcp_get_busid_by_adapter(adapter));
3576 goto failed_req_create;
3577 }
3578
3579 /*
3580 * associate FSF request with SCSI request
3581 * (need this for look up on abort)
3582 */
3583 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3584 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3585
3586 /*
3587 * associate SCSI command with FSF request
3588 * (need this for look up on normal command completion)
3589 */
3590 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3591 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3592 fsf_req->data.send_fcp_command_task.unit = unit;
3593 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3594
3595 /* set handles of unit and its parent port in QTCB */
3596 fsf_req->qtcb->header.lun_handle = unit->handle;
3597 fsf_req->qtcb->header.port_handle = unit->port->handle;
3598
3599 /* FSF does not define the structure of the FCP_CMND IU */
3600 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3601 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3602
3603 /*
3604 * set depending on data direction:
3605 * data direction bits in SBALE (SB Type)
3606 * data direction bits in QTCB
3607 * data direction bits in FCP_CMND IU
3608 */
3609 switch (scsi_cmnd->sc_data_direction) {
3610 case DMA_NONE:
3611 ZFCP_LOG_FLAGS(3, "DMA_NONE\n");
3612 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3613 /*
3614 * FIXME(qdio):
3615 * what is the correct type for commands
3616 * without 'real' data buffers?
3617 */
3618 sbtype = SBAL_FLAGS0_TYPE_READ;
3619 break;
3620 case DMA_FROM_DEVICE:
3621 ZFCP_LOG_FLAGS(3, "DMA_FROM_DEVICE\n");
3622 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3623 sbtype = SBAL_FLAGS0_TYPE_READ;
3624 fcp_cmnd_iu->rddata = 1;
3625 break;
3626 case DMA_TO_DEVICE:
3627 ZFCP_LOG_FLAGS(3, "DMA_TO_DEVICE\n");
3628 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3629 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3630 fcp_cmnd_iu->wddata = 1;
3631 break;
3632 case DMA_BIDIRECTIONAL:
3633 ZFCP_LOG_FLAGS(0, "DMA_BIDIRECTIONAL not supported\n");
3634 default:
3635 /*
3636 * dummy, catch this condition earlier
3637 * in zfcp_scsi_queuecommand
3638 */
3639 goto failed_scsi_cmnd;
3640 }
3641
3642 /* set FC service class in QTCB (3 per default) */
3643 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3644
3645 /* set FCP_LUN in FCP_CMND IU in QTCB */
3646 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3647
3648 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3649
3650 /* set task attributes in FCP_CMND IU in QTCB */
3651 if (likely((scsi_cmnd->device->simple_tags) ||
3652 (atomic_test_mask(mask, &unit->status))))
3653 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3654 else
3655 fcp_cmnd_iu->task_attribute = UNTAGGED;
3656
3657 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3658 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3659 fcp_cmnd_iu->add_fcp_cdb_length
3660 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3661 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3662 "additional FCP_CDB length is 0x%x "
3663 "(shifted right 2 bits)\n",
3664 scsi_cmnd->cmd_len,
3665 fcp_cmnd_iu->add_fcp_cdb_length);
3666 }
3667 /*
3668 * copy SCSI CDB (including additional length, if any) to
3669 * FCP_CDB in FCP_CMND IU in QTCB
3670 */
3671 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3672
3673 /* FCP CMND IU length in QTCB */
3674 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3675 sizeof (struct fcp_cmnd_iu) +
3676 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3677
3678 /* generate SBALEs from data buffer */
3679 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3680 if (unlikely(real_bytes < 0)) {
3681 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3682 ZFCP_LOG_DEBUG(
3683 "Data did not fit into available buffer(s), "
3684 "waiting for more...\n");
3685 retval = -EIO;
3686 } else {
3687 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3688 "required. Shutting down unit "
3689 "(adapter %s, port 0x%016Lx, "
3690 "unit 0x%016Lx)\n",
3691 zfcp_get_busid_by_unit(unit),
3692 unit->port->wwpn,
3693 unit->fcp_lun);
3694 zfcp_erp_unit_shutdown(unit, 0);
3695 retval = -EINVAL;
3696 }
3697 goto no_fit;
3698 }
3699
3700 /* set length of FCP data length in FCP_CMND IU in QTCB */
3701 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3702
3703 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3704 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3705 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3706
3707 /*
3708 * start QDIO request for this FSF request
3709 * covered by an SBALE)
3710 */
3711 retval = zfcp_fsf_req_send(fsf_req, timer);
3712 if (unlikely(retval < 0)) {
3713 ZFCP_LOG_INFO("error: Could not send FCP command request "
3714 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3715 zfcp_get_busid_by_adapter(adapter),
3716 unit->port->wwpn,
3717 unit->fcp_lun);
3718 goto send_failed;
3719 }
3720
3721 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3722 "port 0x%016Lx, unit 0x%016Lx)\n",
3723 zfcp_get_busid_by_adapter(adapter),
3724 unit->port->wwpn,
3725 unit->fcp_lun);
3726 goto success;
3727
3728 send_failed:
3729 no_fit:
3730 failed_scsi_cmnd:
3731 zfcp_fsf_req_free(fsf_req);
3732 fsf_req = NULL;
3733 scsi_cmnd->host_scribble = NULL;
3734 success:
3735 failed_req_create:
3736 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3737 return retval;
3738}
3739
3740/*
3741 * function: zfcp_fsf_send_fcp_command_task_management
3742 *
3743 * purpose:
3744 *
3745 * returns:
3746 *
3747 * FIXME(design): should be watched by a timeout!!!
3748 * FIXME(design) shouldn't this be modified to return an int
3749 * also...don't know how though
3750 *
3751 */
3752struct zfcp_fsf_req *
3753zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3754 struct zfcp_unit *unit,
3755 u8 tm_flags, int req_flags)
3756{
3757 struct zfcp_fsf_req *fsf_req = NULL;
3758 int retval = 0;
3759 struct fcp_cmnd_iu *fcp_cmnd_iu;
3760 unsigned long lock_flags;
3761 volatile struct qdio_buffer_element *sbale;
3762
3763 /* setup new FSF request */
3764 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3765 adapter->pool.fsf_req_scsi,
3766 &lock_flags, &fsf_req);
3767 if (retval < 0) {
3768 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3769 "management) request for adapter %s, port "
3770 " 0x%016Lx, unit 0x%016Lx.\n",
3771 zfcp_get_busid_by_adapter(adapter),
3772 unit->port->wwpn, unit->fcp_lun);
3773 goto out;
3774 }
3775
3776 /*
3777 * Used to decide on proper handler in the return path,
3778 * could be either zfcp_fsf_send_fcp_command_task_handler or
3779 * zfcp_fsf_send_fcp_command_task_management_handler */
3780
3781 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3782
3783 /*
3784 * hold a pointer to the unit being target of this
3785 * task management request
3786 */
3787 fsf_req->data.send_fcp_command_task_management.unit = unit;
3788
3789 /* set FSF related fields in QTCB */
3790 fsf_req->qtcb->header.lun_handle = unit->handle;
3791 fsf_req->qtcb->header.port_handle = unit->port->handle;
3792 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3793 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3794 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3795 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3796
3797 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3798 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3799 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3800
3801 /* set FCP related fields in FCP_CMND IU in QTCB */
3802 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3803 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3804 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3805 fcp_cmnd_iu->task_management_flags = tm_flags;
3806
3807 /* start QDIO request for this FSF request */
3808 zfcp_fsf_start_scsi_er_timer(adapter);
3809 retval = zfcp_fsf_req_send(fsf_req, NULL);
3810 if (retval) {
3811 del_timer(&adapter->scsi_er_timer);
3812 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3813 "management) on adapter %s, port 0x%016Lx for "
3814 "unit LUN 0x%016Lx\n",
3815 zfcp_get_busid_by_adapter(adapter),
3816 unit->port->wwpn,
3817 unit->fcp_lun);
3818 zfcp_fsf_req_free(fsf_req);
3819 fsf_req = NULL;
3820 goto out;
3821 }
3822
3823 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3824 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3825 "tm_flags=0x%x)\n",
3826 zfcp_get_busid_by_adapter(adapter),
3827 unit->port->wwpn,
3828 unit->fcp_lun,
3829 tm_flags);
3830 out:
3831 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3832 return fsf_req;
3833}
3834
3835/*
3836 * function: zfcp_fsf_send_fcp_command_handler
3837 *
3838 * purpose: is called for finished Send FCP Command
3839 *
3840 * returns:
3841 */
3842static int
3843zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3844{
3845 int retval = -EINVAL;
3846 struct zfcp_unit *unit;
3847 struct fsf_qtcb_header *header;
3848 u16 subtable, rule, counter;
3849
3850 header = &fsf_req->qtcb->header;
3851
3852 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3853 unit = fsf_req->data.send_fcp_command_task_management.unit;
3854 else
3855 unit = fsf_req->data.send_fcp_command_task.unit;
3856
3857 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3858 /* go directly to calls of special handlers */
3859 goto skip_fsfstatus;
3860 }
3861
3862 /* evaluate FSF status in QTCB */
3863 switch (header->fsf_status) {
3864
3865 case FSF_PORT_HANDLE_NOT_VALID:
3866 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
3867 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3868 "0x%016Lx on adapter %s invalid\n",
3869 unit->port->handle,
3870 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3871 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3872 (char *) &header->fsf_status_qual,
3873 sizeof (union fsf_status_qual));
3874 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3875 "fsf_s_phand_nv");
3876 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3877 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3878 break;
3879
3880 case FSF_LUN_HANDLE_NOT_VALID:
3881 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
3882 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3883 "0x%016Lx on port 0x%016Lx on adapter %s is "
3884 "invalid. This may happen occasionally.\n",
3885 unit->handle,
3886 unit->fcp_lun,
3887 unit->port->wwpn,
3888 zfcp_get_busid_by_unit(unit));
3889 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3890 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3891 (char *) &header->fsf_status_qual,
3892 sizeof (union fsf_status_qual));
3893 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3894 "fsf_s_uhand_nv");
3895 zfcp_erp_port_reopen(unit->port, 0);
3896 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3897 break;
3898
3899 case FSF_HANDLE_MISMATCH:
3900 ZFCP_LOG_FLAGS(0, "FSF_HANDLE_MISMATCH\n");
3901 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3902 "unexpectedly. (adapter %s, port 0x%016Lx, "
3903 "unit 0x%016Lx)\n",
3904 unit->port->handle,
3905 zfcp_get_busid_by_unit(unit),
3906 unit->port->wwpn,
3907 unit->fcp_lun);
3908 ZFCP_LOG_NORMAL("status qualifier:\n");
3909 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3910 (char *) &header->fsf_status_qual,
3911 sizeof (union fsf_status_qual));
3912 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3913 "fsf_s_hand_mis");
3914 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3915 zfcp_cmd_dbf_event_fsf("handmism",
3916 fsf_req,
3917 &header->fsf_status_qual,
3918 sizeof (union fsf_status_qual));
3919 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3920 break;
3921
3922 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3923 ZFCP_LOG_FLAGS(0, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
3924 if (fsf_req->adapter->fc_service_class <= 3) {
3925 ZFCP_LOG_NORMAL("error: The adapter %s does "
3926 "not support fibrechannel class %d.\n",
3927 zfcp_get_busid_by_unit(unit),
3928 fsf_req->adapter->fc_service_class);
3929 } else {
3930 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3931 "adapter %s is invalid. "
3932 "(debug info %d)\n",
3933 zfcp_get_busid_by_unit(unit),
3934 fsf_req->adapter->fc_service_class);
3935 }
3936 /* stop operation for this adapter */
3937 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3938 "fsf_s_class_nsup");
3939 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3940 zfcp_cmd_dbf_event_fsf("unsclass",
3941 fsf_req,
3942 &header->fsf_status_qual,
3943 sizeof (union fsf_status_qual));
3944 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3945 break;
3946
3947 case FSF_FCPLUN_NOT_VALID:
3948 ZFCP_LOG_FLAGS(0, "FSF_FCPLUN_NOT_VALID\n");
3949 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3950 "adapter %s does not have correct unit "
3951 "handle 0x%x\n",
3952 unit->fcp_lun,
3953 unit->port->wwpn,
3954 zfcp_get_busid_by_unit(unit),
3955 unit->handle);
3956 ZFCP_LOG_DEBUG("status qualifier:\n");
3957 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3958 (char *) &header->fsf_status_qual,
3959 sizeof (union fsf_status_qual));
3960 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3961 "fsf_s_fcp_lun_nv");
3962 zfcp_erp_port_reopen(unit->port, 0);
3963 zfcp_cmd_dbf_event_fsf("fluninv",
3964 fsf_req,
3965 &header->fsf_status_qual,
3966 sizeof (union fsf_status_qual));
3967 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3968 break;
3969
3970 case FSF_ACCESS_DENIED:
3971 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
3972 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3973 "unit 0x%016Lx on port 0x%016Lx on "
3974 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3975 zfcp_get_busid_by_unit(unit));
3976 for (counter = 0; counter < 2; counter++) {
3977 subtable = header->fsf_status_qual.halfword[counter * 2];
3978 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3979 switch (subtable) {
3980 case FSF_SQ_CFDC_SUBTABLE_OS:
3981 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3982 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3983 case FSF_SQ_CFDC_SUBTABLE_LUN:
3984 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3985 zfcp_act_subtable_type[subtable], rule);
3986 break;
3987 }
3988 }
3989 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3990 zfcp_erp_unit_access_denied(unit);
3991 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3992 break;
3993
3994 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3995 ZFCP_LOG_FLAGS(0, "FSF_DIRECTION_INDICATOR_NOT_VALID\n");
3996 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3997 "0x%016Lx on port 0x%016Lx on adapter %s "
3998 "(debug info %d)\n",
3999 unit->fcp_lun,
4000 unit->port->wwpn,
4001 zfcp_get_busid_by_unit(unit),
4002 fsf_req->qtcb->bottom.io.data_direction);
4003 /* stop operation for this adapter */
4004 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4005 "fsf_s_dir_ind_nv");
4006 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
4007 zfcp_cmd_dbf_event_fsf("dirinv",
4008 fsf_req,
4009 &header->fsf_status_qual,
4010 sizeof (union fsf_status_qual));
4011 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4012 break;
4013
4014 case FSF_CMND_LENGTH_NOT_VALID:
4015 ZFCP_LOG_FLAGS(0, "FSF_CMND_LENGTH_NOT_VALID\n");
4016 ZFCP_LOG_NORMAL
4017 ("bug: An invalid control-data-block length field "
4018 "was found in a command for unit 0x%016Lx on port "
4019 "0x%016Lx on adapter %s " "(debug info %d)\n",
4020 unit->fcp_lun, unit->port->wwpn,
4021 zfcp_get_busid_by_unit(unit),
4022 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
4023 /* stop operation for this adapter */
4024 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4025 "fsf_s_cmd_len_nv");
4026 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
4027 zfcp_cmd_dbf_event_fsf("cleninv",
4028 fsf_req,
4029 &header->fsf_status_qual,
4030 sizeof (union fsf_status_qual));
4031 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4032 break;
4033
4034 case FSF_PORT_BOXED:
4035 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
4036 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
4037 "needs to be reopened\n",
4038 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
4039 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
4040 zfcp_erp_port_reopen(unit->port, 0);
4041 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
4042 &header->fsf_status_qual,
4043 sizeof (union fsf_status_qual));
4044 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
4045 ZFCP_STATUS_FSFREQ_RETRY;
4046 break;
4047
4048 case FSF_LUN_BOXED:
4049 ZFCP_LOG_FLAGS(0, "FSF_LUN_BOXED\n");
4050 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
4051 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
4052 zfcp_get_busid_by_unit(unit),
4053 unit->port->wwpn, unit->fcp_lun);
4054 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
4055 zfcp_erp_unit_reopen(unit, 0);
4056 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
4057 &header->fsf_status_qual,
4058 sizeof(union fsf_status_qual));
4059 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
4060 | ZFCP_STATUS_FSFREQ_RETRY;
4061 break;
4062
4063 case FSF_ADAPTER_STATUS_AVAILABLE:
4064 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
4065 switch (header->fsf_status_qual.word[0]) {
4066 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
4067 ZFCP_LOG_FLAGS(2,
4068 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
4069 /* re-establish link to port */
4070 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4071 "fsf_sq_ltest");
4072 zfcp_erp_port_reopen(unit->port, 0);
4073 zfcp_cmd_dbf_event_fsf(
4074 "sqltest",
4075 fsf_req,
4076 &header->fsf_status_qual,
4077 sizeof (union fsf_status_qual));
4078 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4079 break;
4080 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
4081 ZFCP_LOG_FLAGS(3,
4082 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
4083 /* FIXME(hw) need proper specs for proper action */
4084 /* let scsi stack deal with retries and escalation */
4085 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4086 "fsf_sq_ulp");
4087 zfcp_cmd_dbf_event_fsf(
4088 "sqdeperp",
4089 fsf_req,
4090 &header->fsf_status_qual,
4091 sizeof (union fsf_status_qual));
4092 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4093 break;
4094 default:
4095 /* FIXME: shall we consider this a successful transfer? */
4096 ZFCP_LOG_NORMAL
4097 ("bug: Wrong status qualifier 0x%x arrived.\n",
4098 header->fsf_status_qual.word[0]);
4099 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4100 "fsf_sq_inval:");
4101 debug_exception(fsf_req->adapter->erp_dbf, 0,
4102 &header->fsf_status_qual.word[0],
4103 sizeof(u32));
4104 break;
4105 }
4106 break;
4107
4108 case FSF_GOOD:
4109 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
4110 break;
4111
4112 case FSF_FCP_RSP_AVAILABLE:
4113 ZFCP_LOG_FLAGS(2, "FSF_FCP_RSP_AVAILABLE\n");
4114 break;
4115
4116 default:
4117 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
4118 debug_exception(fsf_req->adapter->erp_dbf, 0,
4119 &header->fsf_status, sizeof(u32));
4120 break;
4121 }
4122
4123 skip_fsfstatus:
4124 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4125 retval =
4126 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4127 } else {
4128 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
4129 }
4130 return retval;
4131}
4132
4133/*
4134 * function: zfcp_fsf_send_fcp_command_task_handler
4135 *
4136 * purpose: evaluates FCP_RSP IU
4137 *
4138 * returns:
4139 */
4140static int
4141zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4142{
4143 int retval = 0;
4144 struct scsi_cmnd *scpnt;
4145 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4146 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4147 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4148 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4149 u32 sns_len;
4150 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4151 unsigned long flags;
4152 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
4153
4154 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4155 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
4156 if (unlikely(!scpnt)) {
4157 ZFCP_LOG_DEBUG
4158 ("Command with fsf_req %p is not associated to "
4159 "a scsi command anymore. Aborted?\n", fsf_req);
4160 goto out;
4161 }
4162 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4163 /* FIXME: (design) mid-layer should handle DID_ABORT like
4164 * DID_SOFT_ERROR by retrying the request for devices
4165 * that allow retries.
4166 */
4167 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4168 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4169 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4170 goto skip_fsfstatus;
4171 }
4172
4173 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4174 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4175 set_host_byte(&scpnt->result, DID_ERROR);
4176 goto skip_fsfstatus;
4177 }
4178
4179 /* set message byte of result in SCSI command */
4180 scpnt->result |= COMMAND_COMPLETE << 8;
4181
4182 /*
4183 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4184 * of result in SCSI command
4185 */
4186 scpnt->result |= fcp_rsp_iu->scsi_status;
4187 if (unlikely(fcp_rsp_iu->scsi_status)) {
4188 /* DEBUG */
4189 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4190 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4191 scpnt->cmnd, scpnt->cmd_len);
4192 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4193 fcp_rsp_iu->scsi_status);
4194 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4195 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4196 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4197 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4198 fcp_rsp_iu->fcp_sns_len);
4199 }
4200
4201 /* check FCP_RSP_INFO */
4202 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4203 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4204 switch (fcp_rsp_info[3]) {
4205 case RSP_CODE_GOOD:
4206 ZFCP_LOG_FLAGS(3, "RSP_CODE_GOOD\n");
4207 /* ok, continue */
4208 ZFCP_LOG_TRACE("no failure or Task Management "
4209 "Function complete\n");
4210 set_host_byte(&scpnt->result, DID_OK);
4211 break;
4212 case RSP_CODE_LENGTH_MISMATCH:
4213 ZFCP_LOG_FLAGS(0, "RSP_CODE_LENGTH_MISMATCH\n");
4214 /* hardware bug */
4215 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4216 "that the fibrechannel protocol data "
4217 "length differs from the burst length. "
4218 "The problem occured on unit 0x%016Lx "
4219 "on port 0x%016Lx on adapter %s",
4220 unit->fcp_lun,
4221 unit->port->wwpn,
4222 zfcp_get_busid_by_unit(unit));
4223 /* dump SCSI CDB as prepared by zfcp */
4224 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4225 (char *) &fsf_req->qtcb->
4226 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4227 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4228 set_host_byte(&scpnt->result, DID_ERROR);
4229 goto skip_fsfstatus;
4230 case RSP_CODE_FIELD_INVALID:
4231 ZFCP_LOG_FLAGS(0, "RSP_CODE_FIELD_INVALID\n");
4232 /* driver or hardware bug */
4233 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4234 "that the fibrechannel protocol data "
4235 "fields were incorrectly set up. "
4236 "The problem occured on the unit "
4237 "0x%016Lx on port 0x%016Lx on "
4238 "adapter %s",
4239 unit->fcp_lun,
4240 unit->port->wwpn,
4241 zfcp_get_busid_by_unit(unit));
4242 /* dump SCSI CDB as prepared by zfcp */
4243 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4244 (char *) &fsf_req->qtcb->
4245 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4246 set_host_byte(&scpnt->result, DID_ERROR);
4247 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4248 goto skip_fsfstatus;
4249 case RSP_CODE_RO_MISMATCH:
4250 ZFCP_LOG_FLAGS(0, "RSP_CODE_RO_MISMATCH\n");
4251 /* hardware bug */
4252 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4253 "that conflicting values for the "
4254 "fibrechannel payload offset from the "
4255 "header were found. "
4256 "The problem occured on unit 0x%016Lx "
4257 "on port 0x%016Lx on adapter %s.\n",
4258 unit->fcp_lun,
4259 unit->port->wwpn,
4260 zfcp_get_busid_by_unit(unit));
4261 /* dump SCSI CDB as prepared by zfcp */
4262 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4263 (char *) &fsf_req->qtcb->
4264 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4265 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4266 set_host_byte(&scpnt->result, DID_ERROR);
4267 goto skip_fsfstatus;
4268 default:
4269 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4270 "code was detected for a command. "
4271 "The problem occured on the unit "
4272 "0x%016Lx on port 0x%016Lx on "
4273 "adapter %s (debug info 0x%x)\n",
4274 unit->fcp_lun,
4275 unit->port->wwpn,
4276 zfcp_get_busid_by_unit(unit),
4277 fcp_rsp_info[3]);
4278 /* dump SCSI CDB as prepared by zfcp */
4279 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4280 (char *) &fsf_req->qtcb->
4281 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4282 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4283 set_host_byte(&scpnt->result, DID_ERROR);
4284 }
4285 }
4286
4287 /* check for sense data */
4288 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4289 sns_len = FSF_FCP_RSP_SIZE -
4290 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4291 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4292 sns_len);
4293 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4294 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4295 SCSI_SENSE_BUFFERSIZE);
4296 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4297 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4298 scpnt->result);
4299 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4300 (void *) &scpnt->cmnd, scpnt->cmd_len);
4301
4302 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4303 fcp_rsp_iu->fcp_sns_len);
4304 memcpy(&scpnt->sense_buffer,
4305 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4306 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4307 (void *) &scpnt->sense_buffer, sns_len);
4308 }
4309
4310 /* check for overrun */
4311 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4312 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4313 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4314 "The response data length is "
4315 "%d, the original length was %d.\n",
4316 unit->fcp_lun,
4317 unit->port->wwpn,
4318 zfcp_get_busid_by_unit(unit),
4319 fcp_rsp_iu->fcp_resid,
4320 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4321 }
4322
4323 /* check for underrun */
4324 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4325 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4326 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4327 "The response data length is "
4328 "%d, the original length was %d.\n",
4329 unit->fcp_lun,
4330 unit->port->wwpn,
4331 zfcp_get_busid_by_unit(unit),
4332 fcp_rsp_iu->fcp_resid,
4333 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4334
4335 scpnt->resid = fcp_rsp_iu->fcp_resid;
4336 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4337 scpnt->result |= DID_ERROR << 16;
4338 }
4339
4340 skip_fsfstatus:
4341 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4342
4343 zfcp_cmd_dbf_event_scsi("response", scpnt);
4344
4345 /* cleanup pointer (need this especially for abort) */
4346 scpnt->host_scribble = NULL;
4347
4348 /*
4349 * NOTE:
4350 * according to the outcome of a discussion on linux-scsi we
4351 * don't need to grab the io_request_lock here since we use
4352 * the new eh
4353 */
4354 /* always call back */
4355
4356 (scpnt->scsi_done) (scpnt);
4357
4358 /*
4359 * We must hold this lock until scsi_done has been called.
4360 * Otherwise we may call scsi_done after abort regarding this
4361 * command has completed.
4362 * Note: scsi_done must not block!
4363 */
4364 out:
4365 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4366 return retval;
4367}
4368
4369/*
4370 * function: zfcp_fsf_send_fcp_command_task_management_handler
4371 *
4372 * purpose: evaluates FCP_RSP IU
4373 *
4374 * returns:
4375 */
4376static int
4377zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4378{
4379 int retval = 0;
4380 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4381 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4382 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4383 struct zfcp_unit *unit =
4384 fsf_req->data.send_fcp_command_task_management.unit;
4385
4386 del_timer(&fsf_req->adapter->scsi_er_timer);
4387 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4388 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4389 goto skip_fsfstatus;
4390 }
4391
4392 /* check FCP_RSP_INFO */
4393 switch (fcp_rsp_info[3]) {
4394 case RSP_CODE_GOOD:
4395 ZFCP_LOG_FLAGS(3, "RSP_CODE_GOOD\n");
4396 /* ok, continue */
4397 ZFCP_LOG_DEBUG("no failure or Task Management "
4398 "Function complete\n");
4399 break;
4400 case RSP_CODE_TASKMAN_UNSUPP:
4401 ZFCP_LOG_FLAGS(0, "RSP_CODE_TASKMAN_UNSUPP\n");
4402 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4403 "is not supported on the target device "
4404 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4405 unit->fcp_lun,
4406 unit->port->wwpn,
4407 zfcp_get_busid_by_unit(unit));
4408 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4409 break;
4410 case RSP_CODE_TASKMAN_FAILED:
4411 ZFCP_LOG_FLAGS(0, "RSP_CODE_TASKMAN_FAILED\n");
4412 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4413 "failed to complete successfully. "
4414 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4415 unit->fcp_lun,
4416 unit->port->wwpn,
4417 zfcp_get_busid_by_unit(unit));
4418 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4419 break;
4420 default:
4421 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4422 "code was detected for a command. "
4423 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4424 "(debug info 0x%x)\n",
4425 unit->fcp_lun,
4426 unit->port->wwpn,
4427 zfcp_get_busid_by_unit(unit),
4428 fcp_rsp_info[3]);
4429 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4430 }
4431
4432 skip_fsfstatus:
4433 return retval;
4434}
4435
4436
4437/*
4438 * function: zfcp_fsf_control_file
4439 *
4440 * purpose: Initiator of the control file upload/download FSF requests
4441 *
4442 * returns: 0 - FSF request is successfuly created and queued
4443 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4444 * -EINVAL - Invalid direction specified
4445 * -ENOMEM - Insufficient memory
4446 * -EPERM - Cannot create FSF request or place it in QDIO queue
4447 */
4448int
4449zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4450 struct zfcp_fsf_req **fsf_req_ptr,
4451 u32 fsf_command,
4452 u32 option,
4453 struct zfcp_sg_list *sg_list)
4454{
4455 struct zfcp_fsf_req *fsf_req;
4456 struct fsf_qtcb_bottom_support *bottom;
4457 volatile struct qdio_buffer_element *sbale;
4458 struct timer_list *timer;
4459 unsigned long lock_flags;
4460 int req_flags = 0;
4461 int direction;
4462 int retval = 0;
4463
4464 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4465 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4466 zfcp_get_busid_by_adapter(adapter));
4467 retval = -EOPNOTSUPP;
4468 goto out;
4469 }
4470
4471 switch (fsf_command) {
4472
4473 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4474 direction = SBAL_FLAGS0_TYPE_WRITE;
4475 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4476 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4477 req_flags = ZFCP_WAIT_FOR_SBAL;
4478 break;
4479
4480 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4481 direction = SBAL_FLAGS0_TYPE_READ;
4482 break;
4483
4484 default:
4485 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4486 retval = -EINVAL;
4487 goto out;
4488 }
4489
4490 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4491 if (!timer) {
4492 retval = -ENOMEM;
4493 goto out;
4494 }
4495
4496 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4497 NULL, &lock_flags, &fsf_req);
4498 if (retval < 0) {
4499 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4500 "adapter %s\n",
4501 zfcp_get_busid_by_adapter(adapter));
4502 retval = -EPERM;
4503 goto unlock_queue_lock;
4504 }
4505
4506 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4507 sbale[0].flags |= direction;
4508
4509 bottom = &fsf_req->qtcb->bottom.support;
4510 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4511 bottom->option = option;
4512
4513 if (sg_list->count > 0) {
4514 int bytes;
4515
4516 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4517 sg_list->sg, sg_list->count,
4518 ZFCP_MAX_SBALS_PER_REQ);
4519 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4520 ZFCP_LOG_INFO(
4521 "error: Could not create sufficient number of "
4522 "SBALS for an FSF request to the adapter %s\n",
4523 zfcp_get_busid_by_adapter(adapter));
4524 retval = -ENOMEM;
4525 goto free_fsf_req;
4526 }
4527 } else
4528 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4529
4530 init_timer(timer);
4531 timer->function = zfcp_fsf_request_timeout_handler;
4532 timer->data = (unsigned long) adapter;
4533 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4534
4535 retval = zfcp_fsf_req_send(fsf_req, timer);
4536 if (retval < 0) {
4537 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4538 "(adapter %s)\n",
4539 zfcp_get_busid_by_adapter(adapter));
4540 retval = -EPERM;
4541 goto free_fsf_req;
4542 }
4543 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4544
4545 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4546 "adapter %s\n",
4547 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4548 "download" : "upload",
4549 zfcp_get_busid_by_adapter(adapter));
4550
4551 wait_event(fsf_req->completion_wq,
4552 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4553
4554 *fsf_req_ptr = fsf_req;
4555 del_timer_sync(timer);
4556 goto free_timer;
4557
4558 free_fsf_req:
4559 zfcp_fsf_req_free(fsf_req);
4560 unlock_queue_lock:
4561 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4562 free_timer:
4563 kfree(timer);
4564 out:
4565 return retval;
4566}
4567
4568
4569/*
4570 * function: zfcp_fsf_control_file_handler
4571 *
4572 * purpose: Handler of the control file upload/download FSF requests
4573 *
4574 * returns: 0 - FSF request successfuly processed
4575 * -EAGAIN - Operation has to be repeated because of a temporary problem
4576 * -EACCES - There is no permission to execute an operation
4577 * -EPERM - The control file is not in a right format
4578 * -EIO - There is a problem with the FCP adapter
4579 * -EINVAL - Invalid operation
4580 * -EFAULT - User space memory I/O operation fault
4581 */
4582static int
4583zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4584{
4585 struct zfcp_adapter *adapter = fsf_req->adapter;
4586 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4587 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4588 int retval = 0;
4589
4590 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4591 retval = -EINVAL;
4592 goto skip_fsfstatus;
4593 }
4594
4595 switch (header->fsf_status) {
4596
4597 case FSF_GOOD:
4598 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
4599 ZFCP_LOG_NORMAL(
4600 "The FSF request has been successfully completed "
4601 "on the adapter %s\n",
4602 zfcp_get_busid_by_adapter(adapter));
4603 break;
4604
4605 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4606 ZFCP_LOG_FLAGS(2, "FSF_OPERATION_PARTIALLY_SUCCESSFUL\n");
4607 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4608 switch (header->fsf_status_qual.word[0]) {
4609
4610 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4611 ZFCP_LOG_NORMAL(
4612 "CFDC of the adapter %s could not "
4613 "be saved on the SE\n",
4614 zfcp_get_busid_by_adapter(adapter));
4615 break;
4616
4617 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4618 ZFCP_LOG_NORMAL(
4619 "CFDC of the adapter %s could not "
4620 "be copied to the secondary SE\n",
4621 zfcp_get_busid_by_adapter(adapter));
4622 break;
4623
4624 default:
4625 ZFCP_LOG_NORMAL(
4626 "CFDC could not be hardened "
4627 "on the adapter %s\n",
4628 zfcp_get_busid_by_adapter(adapter));
4629 }
4630 }
4631 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4632 retval = -EAGAIN;
4633 break;
4634
4635 case FSF_AUTHORIZATION_FAILURE:
4636 ZFCP_LOG_FLAGS(2, "FSF_AUTHORIZATION_FAILURE\n");
4637 ZFCP_LOG_NORMAL(
4638 "Adapter %s does not accept privileged commands\n",
4639 zfcp_get_busid_by_adapter(adapter));
4640 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4641 retval = -EACCES;
4642 break;
4643
4644 case FSF_CFDC_ERROR_DETECTED:
4645 ZFCP_LOG_FLAGS(2, "FSF_CFDC_ERROR_DETECTED\n");
4646 ZFCP_LOG_NORMAL(
4647 "Error at position %d in the CFDC, "
4648 "CFDC is discarded by the adapter %s\n",
4649 header->fsf_status_qual.word[0],
4650 zfcp_get_busid_by_adapter(adapter));
4651 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4652 retval = -EPERM;
4653 break;
4654
4655 case FSF_CONTROL_FILE_UPDATE_ERROR:
4656 ZFCP_LOG_FLAGS(2, "FSF_CONTROL_FILE_UPDATE_ERROR\n");
4657 ZFCP_LOG_NORMAL(
4658 "Adapter %s cannot harden the control file, "
4659 "file is discarded\n",
4660 zfcp_get_busid_by_adapter(adapter));
4661 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4662 retval = -EIO;
4663 break;
4664
4665 case FSF_CONTROL_FILE_TOO_LARGE:
4666 ZFCP_LOG_FLAGS(2, "FSF_CONTROL_FILE_TOO_LARGE\n");
4667 ZFCP_LOG_NORMAL(
4668 "Control file is too large, file is discarded "
4669 "by the adapter %s\n",
4670 zfcp_get_busid_by_adapter(adapter));
4671 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4672 retval = -EIO;
4673 break;
4674
4675 case FSF_ACCESS_CONFLICT_DETECTED:
4676 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_CONFLICT_DETECTED\n");
4677 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4678 ZFCP_LOG_NORMAL(
4679 "CFDC has been discarded by the adapter %s, "
4680 "because activation would impact "
4681 "%d active connection(s)\n",
4682 zfcp_get_busid_by_adapter(adapter),
4683 header->fsf_status_qual.word[0]);
4684 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4685 retval = -EIO;
4686 break;
4687
4688 case FSF_CONFLICTS_OVERRULED:
4689 ZFCP_LOG_FLAGS(2, "FSF_CONFLICTS_OVERRULED\n");
4690 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4691 ZFCP_LOG_NORMAL(
4692 "CFDC has been activated on the adapter %s, "
4693 "but activation has impacted "
4694 "%d active connection(s)\n",
4695 zfcp_get_busid_by_adapter(adapter),
4696 header->fsf_status_qual.word[0]);
4697 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4698 retval = -EIO;
4699 break;
4700
4701 case FSF_UNKNOWN_OP_SUBTYPE:
4702 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_OP_SUBTYPE\n");
4703 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4704 "op_subtype=0x%x)\n",
4705 zfcp_get_busid_by_adapter(adapter),
4706 bottom->operation_subtype);
4707 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4708 retval = -EINVAL;
4709 break;
4710
4711 case FSF_INVALID_COMMAND_OPTION:
4712 ZFCP_LOG_FLAGS(2, "FSF_INVALID_COMMAND_OPTION\n");
4713 ZFCP_LOG_NORMAL(
4714 "Invalid option 0x%x has been specified "
4715 "in QTCB bottom sent to the adapter %s\n",
4716 bottom->option,
4717 zfcp_get_busid_by_adapter(adapter));
4718 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4719 retval = -EINVAL;
4720 break;
4721
4722 default:
4723 ZFCP_LOG_NORMAL(
4724 "bug: An unknown/unexpected FSF status 0x%08x "
4725 "was presented on the adapter %s\n",
4726 header->fsf_status,
4727 zfcp_get_busid_by_adapter(adapter));
4728 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4729 debug_exception(fsf_req->adapter->erp_dbf, 0,
4730 &header->fsf_status_qual.word[0], sizeof(u32));
4731 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4732 retval = -EINVAL;
4733 break;
4734 }
4735
4736skip_fsfstatus:
4737 return retval;
4738}
4739
4740
4741/*
4742 * function: zfcp_fsf_req_wait_and_cleanup
4743 *
4744 * purpose:
4745 *
4746 * FIXME(design): signal seems to be <0 !!!
4747 * returns: 0 - request completed (*status is valid), cleanup succ.
4748 * <0 - request completed (*status is valid), cleanup failed
4749 * >0 - signal which interrupted waiting (*status invalid),
4750 * request not completed, no cleanup
4751 *
4752 * *status is a copy of status of completed fsf_req
4753 */
4754int
4755zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4756 int interruptible, u32 * status)
4757{
4758 int retval = 0;
4759 int signal = 0;
4760
4761 if (interruptible) {
4762 __wait_event_interruptible(fsf_req->completion_wq,
4763 fsf_req->status &
4764 ZFCP_STATUS_FSFREQ_COMPLETED,
4765 signal);
4766 if (signal) {
4767 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4768 "completion of the request at %p\n",
4769 signal, fsf_req);
4770 retval = signal;
4771 goto out;
4772 }
4773 } else {
4774 __wait_event(fsf_req->completion_wq,
4775 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4776 }
4777
4778 *status = fsf_req->status;
4779
4780 /* cleanup request */
4781 zfcp_fsf_req_cleanup(fsf_req);
4782 out:
4783 return retval;
4784}
4785
4786static inline int
4787zfcp_fsf_req_sbal_check(unsigned long *flags,
4788 struct zfcp_qdio_queue *queue, int needed)
4789{
4790 write_lock_irqsave(&queue->queue_lock, *flags);
4791 if (likely(atomic_read(&queue->free_count) >= needed))
4792 return 1;
4793 write_unlock_irqrestore(&queue->queue_lock, *flags);
4794 return 0;
4795}
4796
4797/*
4798 * set qtcb pointer in fsf_req and initialize QTCB
4799 */
4800static inline void
4801zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4802{
4803 if (likely(fsf_req->qtcb != NULL)) {
4804 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4805 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4806 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4807 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4808 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4809 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4810 }
4811}
4812
4813/**
4814 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4815 * @adapter: adapter for which request queue is examined
4816 * @req_flags: flags indicating whether to wait for needed SBAL or not
4817 * @lock_flags: lock_flags if queue_lock is taken
4818 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4819 * Locks: lock adapter->request_queue->queue_lock on success
4820 */
4821static int
4822zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4823 unsigned long *lock_flags)
4824{
4825 long ret;
4826 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4827
4828 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4829 ret = wait_event_interruptible_timeout(adapter->request_wq,
4830 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4831 ZFCP_SBAL_TIMEOUT);
4832 if (ret < 0)
4833 return ret;
4834 if (!ret)
4835 return -EIO;
4836 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4837 return -EIO;
4838
4839 return 0;
4840}
4841
4842/*
4843 * function: zfcp_fsf_req_create
4844 *
4845 * purpose: create an FSF request at the specified adapter and
4846 * setup common fields
4847 *
4848 * returns: -ENOMEM if there was insufficient memory for a request
4849 * -EIO if no qdio buffers could be allocate to the request
4850 * -EINVAL/-EPERM on bug conditions in req_dequeue
4851 * 0 in success
4852 *
4853 * note: The created request is returned by reference.
4854 *
4855 * locks: lock of concerned request queue must not be held,
4856 * but is held on completion (write, irqsave)
4857 */
4858int
4859zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4860 mempool_t *pool, unsigned long *lock_flags,
4861 struct zfcp_fsf_req **fsf_req_p)
4862{
4863 volatile struct qdio_buffer_element *sbale;
4864 struct zfcp_fsf_req *fsf_req = NULL;
4865 int ret = 0;
4866 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4867
4868 /* allocate new FSF request */
4869 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4870 if (unlikely(NULL == fsf_req)) {
4871 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4872 "the outbound (send) queue.\n");
4873 ret = -ENOMEM;
4874 goto failed_fsf_req;
4875 }
4876
4877 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4878
4879 /* initialize waitqueue which may be used to wait on
4880 this request completion */
4881 init_waitqueue_head(&fsf_req->completion_wq);
4882
4883 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4884 if(ret < 0) {
4885 goto failed_sbals;
4886 }
4887
4888 /*
4889 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4890 * if it is not set (see also *_open_qdio and *_close_qdio).
4891 */
4892
4893 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4894 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4895 ret = -EIO;
4896 goto failed_sbals;
4897 }
4898
4899 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4900 fsf_req->fsf_command = fsf_cmd;
4901 fsf_req->sbal_number = 1;
4902 fsf_req->sbal_first = req_queue->free_index;
4903 fsf_req->sbal_curr = req_queue->free_index;
4904 fsf_req->sbale_curr = 1;
4905
4906 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4907 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4908 }
4909
4910 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4911
4912 /* setup common SBALE fields */
4913 sbale[0].addr = fsf_req;
4914 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4915 if (likely(fsf_req->qtcb != NULL)) {
4916 sbale[1].addr = (void *) fsf_req->qtcb;
4917 sbale[1].length = sizeof(struct fsf_qtcb);
4918 }
4919
4920 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4921 fsf_req->sbal_number, fsf_req->sbal_first);
4922
4923 goto success;
4924
4925 failed_sbals:
4926/* dequeue new FSF request previously enqueued */
4927 zfcp_fsf_req_free(fsf_req);
4928 fsf_req = NULL;
4929
4930 failed_fsf_req:
4931 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4932 success:
4933 *fsf_req_p = fsf_req;
4934 return ret;
4935}
4936
4937/*
4938 * function: zfcp_fsf_req_send
4939 *
4940 * purpose: start transfer of FSF request via QDIO
4941 *
4942 * returns: 0 - request transfer succesfully started
4943 * !0 - start of request transfer failed
4944 */
4945static int
4946zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4947{
4948 struct zfcp_adapter *adapter;
4949 struct zfcp_qdio_queue *req_queue;
4950 volatile struct qdio_buffer_element *sbale;
4951 int new_distance_from_int;
4952 unsigned long flags;
4953 int inc_seq_no = 1;
4954 int retval = 0;
4955
4956 adapter = fsf_req->adapter;
4957 req_queue = &adapter->request_queue,
4958
4959
4960 /* FIXME(debug): remove it later */
4961 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4962 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4963 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4964 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4965 sbale[1].length);
4966
4967 /* set sequence counter in QTCB */
4968 if (likely(fsf_req->qtcb)) {
4969 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4970 fsf_req->seq_no = adapter->fsf_req_seq_no;
4971 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4972 "FSF sequence counter value of %i\n",
4973 fsf_req,
4974 zfcp_get_busid_by_adapter(adapter),
4975 fsf_req->qtcb->prefix.req_seq_no);
4976 } else
4977 inc_seq_no = 0;
4978
4979 /* put allocated FSF request at list tail */
4980 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4981 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4982 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4983
4984 /* figure out expiration time of timeout and start timeout */
4985 if (unlikely(timer)) {
4986 timer->expires += jiffies;
4987 add_timer(timer);
4988 }
4989
4990 ZFCP_LOG_TRACE("request queue of adapter %s: "
4991 "next free SBAL is %i, %i free SBALs\n",
4992 zfcp_get_busid_by_adapter(adapter),
4993 req_queue->free_index,
4994 atomic_read(&req_queue->free_count));
4995
4996 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4997 "index_in_queue=%i, count=%i, buffers=%p\n",
4998 zfcp_get_busid_by_adapter(adapter),
4999 QDIO_FLAG_SYNC_OUTPUT,
5000 0, fsf_req->sbal_first, fsf_req->sbal_number,
5001 &req_queue->buffer[fsf_req->sbal_first]);
5002
5003 /*
5004 * adjust the number of free SBALs in request queue as well as
5005 * position of first one
5006 */
5007 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
5008 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
5009 req_queue->free_index += fsf_req->sbal_number; /* increase */
5010 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
5011 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
5012
5013 retval = do_QDIO(adapter->ccw_device,
5014 QDIO_FLAG_SYNC_OUTPUT,
5015 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
5016
5017 if (unlikely(retval)) {
5018 /* Queues are down..... */
5019 retval = -EIO;
5020 /*
5021 * FIXME(potential race):
5022 * timer might be expired (absolutely unlikely)
5023 */
5024 if (timer)
5025 del_timer(timer);
5026 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
5027 list_del(&fsf_req->list);
5028 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
5029 /*
5030 * adjust the number of free SBALs in request queue as well as
5031 * position of first one
5032 */
5033 zfcp_qdio_zero_sbals(req_queue->buffer,
5034 fsf_req->sbal_first, fsf_req->sbal_number);
5035 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
5036 req_queue->free_index -= fsf_req->sbal_number; /* increase */
5037 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
5038 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
5039 ZFCP_LOG_DEBUG
5040 ("error: do_QDIO failed. Buffers could not be enqueued "
5041 "to request queue.\n");
5042 } else {
5043 req_queue->distance_from_int = new_distance_from_int;
5044 /*
5045 * increase FSF sequence counter -
5046 * this must only be done for request successfully enqueued to
5047 * QDIO this rejected requests may be cleaned up by calling
5048 * routines resulting in missing sequence counter values
5049 * otherwise,
5050 */
5051 /* Don't increase for unsolicited status */
5052 if (likely(inc_seq_no)) {
5053 adapter->fsf_req_seq_no++;
5054 ZFCP_LOG_TRACE
5055 ("FSF sequence counter value of adapter %s "
5056 "increased to %i\n",
5057 zfcp_get_busid_by_adapter(adapter),
5058 adapter->fsf_req_seq_no);
5059 }
5060 /* count FSF requests pending */
5061 atomic_inc(&adapter->fsf_reqs_active);
5062 }
5063 return retval;
5064}
5065
5066/*
5067 * function: zfcp_fsf_req_cleanup
5068 *
5069 * purpose: cleans up an FSF request and removes it from the specified list
5070 *
5071 * returns:
5072 *
5073 * assumption: no pending SB in SBALEs other than QTCB
5074 */
5075void
5076zfcp_fsf_req_cleanup(struct zfcp_fsf_req *fsf_req)
5077{
5078 struct zfcp_adapter *adapter = fsf_req->adapter;
5079 unsigned long flags;
5080
5081 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
5082 list_del(&fsf_req->list);
5083 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
5084 zfcp_fsf_req_free(fsf_req);
5085}
5086
5087#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_fsf.h b/drivers/s390/scsi/zfcp_fsf.h
new file mode 100644
index 000000000000..5889956bbf08
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_fsf.h
@@ -0,0 +1,472 @@
1/*
2 *
3 * linux/drivers/s390/scsi/zfcp_fsf.h
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 * Volker Sameske <sameske@de.ibm.com>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#ifndef FSF_H
34#define FSF_H
35
36#define FSF_QTCB_VERSION1 0x00000001
37#define FSF_QTCB_CURRENT_VERSION FSF_QTCB_VERSION1
38
39/* FSF commands */
40#define FSF_QTCB_FCP_CMND 0x00000001
41#define FSF_QTCB_ABORT_FCP_CMND 0x00000002
42#define FSF_QTCB_OPEN_PORT_WITH_DID 0x00000005
43#define FSF_QTCB_OPEN_LUN 0x00000006
44#define FSF_QTCB_CLOSE_LUN 0x00000007
45#define FSF_QTCB_CLOSE_PORT 0x00000008
46#define FSF_QTCB_CLOSE_PHYSICAL_PORT 0x00000009
47#define FSF_QTCB_SEND_ELS 0x0000000B
48#define FSF_QTCB_SEND_GENERIC 0x0000000C
49#define FSF_QTCB_EXCHANGE_CONFIG_DATA 0x0000000D
50#define FSF_QTCB_EXCHANGE_PORT_DATA 0x0000000E
51#define FSF_QTCB_DOWNLOAD_CONTROL_FILE 0x00000012
52#define FSF_QTCB_UPLOAD_CONTROL_FILE 0x00000013
53
54/* FSF QTCB types */
55#define FSF_IO_COMMAND 0x00000001
56#define FSF_SUPPORT_COMMAND 0x00000002
57#define FSF_CONFIG_COMMAND 0x00000003
58#define FSF_PORT_COMMAND 0x00000004
59
60/* FSF control file upload/download operations' subtype and options */
61#define FSF_CFDC_OPERATION_SUBTYPE 0x00020001
62#define FSF_CFDC_OPTION_NORMAL_MODE 0x00000000
63#define FSF_CFDC_OPTION_FORCE 0x00000001
64#define FSF_CFDC_OPTION_FULL_ACCESS 0x00000002
65#define FSF_CFDC_OPTION_RESTRICTED_ACCESS 0x00000004
66
67/* FSF protocol stati */
68#define FSF_PROT_GOOD 0x00000001
69#define FSF_PROT_QTCB_VERSION_ERROR 0x00000010
70#define FSF_PROT_SEQ_NUMB_ERROR 0x00000020
71#define FSF_PROT_UNSUPP_QTCB_TYPE 0x00000040
72#define FSF_PROT_HOST_CONNECTION_INITIALIZING 0x00000080
73#define FSF_PROT_FSF_STATUS_PRESENTED 0x00000100
74#define FSF_PROT_DUPLICATE_REQUEST_ID 0x00000200
75#define FSF_PROT_LINK_DOWN 0x00000400
76#define FSF_PROT_REEST_QUEUE 0x00000800
77#define FSF_PROT_ERROR_STATE 0x01000000
78
79/* FSF stati */
80#define FSF_GOOD 0x00000000
81#define FSF_PORT_ALREADY_OPEN 0x00000001
82#define FSF_LUN_ALREADY_OPEN 0x00000002
83#define FSF_PORT_HANDLE_NOT_VALID 0x00000003
84#define FSF_LUN_HANDLE_NOT_VALID 0x00000004
85#define FSF_HANDLE_MISMATCH 0x00000005
86#define FSF_SERVICE_CLASS_NOT_SUPPORTED 0x00000006
87#define FSF_FCPLUN_NOT_VALID 0x00000009
88#define FSF_ACCESS_DENIED 0x00000010
89#define FSF_LUN_SHARING_VIOLATION 0x00000012
90#define FSF_FCP_COMMAND_DOES_NOT_EXIST 0x00000022
91#define FSF_DIRECTION_INDICATOR_NOT_VALID 0x00000030
92#define FSF_CMND_LENGTH_NOT_VALID 0x00000033
93#define FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED 0x00000040
94#define FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED 0x00000041
95#define FSF_ELS_COMMAND_REJECTED 0x00000050
96#define FSF_GENERIC_COMMAND_REJECTED 0x00000051
97#define FSF_OPERATION_PARTIALLY_SUCCESSFUL 0x00000052
98#define FSF_AUTHORIZATION_FAILURE 0x00000053
99#define FSF_CFDC_ERROR_DETECTED 0x00000054
100#define FSF_CONTROL_FILE_UPDATE_ERROR 0x00000055
101#define FSF_CONTROL_FILE_TOO_LARGE 0x00000056
102#define FSF_ACCESS_CONFLICT_DETECTED 0x00000057
103#define FSF_CONFLICTS_OVERRULED 0x00000058
104#define FSF_PORT_BOXED 0x00000059
105#define FSF_LUN_BOXED 0x0000005A
106#define FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE 0x0000005B
107#define FSF_PAYLOAD_SIZE_MISMATCH 0x00000060
108#define FSF_REQUEST_SIZE_TOO_LARGE 0x00000061
109#define FSF_RESPONSE_SIZE_TOO_LARGE 0x00000062
110#define FSF_SBAL_MISMATCH 0x00000063
111#define FSF_OPEN_PORT_WITHOUT_PRLI 0x00000064
112#define FSF_ADAPTER_STATUS_AVAILABLE 0x000000AD
113#define FSF_FCP_RSP_AVAILABLE 0x000000AF
114#define FSF_UNKNOWN_COMMAND 0x000000E2
115#define FSF_UNKNOWN_OP_SUBTYPE 0x000000E3
116#define FSF_INVALID_COMMAND_OPTION 0x000000E5
117/* #define FSF_ERROR 0x000000FF */
118
119#define FSF_STATUS_QUALIFIER_SIZE 16
120
121/* FSF status qualifier, recommendations */
122#define FSF_SQ_NO_RECOM 0x00
123#define FSF_SQ_FCP_RSP_AVAILABLE 0x01
124#define FSF_SQ_RETRY_IF_POSSIBLE 0x02
125#define FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED 0x03
126#define FSF_SQ_INVOKE_LINK_TEST_PROCEDURE 0x04
127#define FSF_SQ_ULP_PROGRAMMING_ERROR 0x05
128#define FSF_SQ_COMMAND_ABORTED 0x06
129#define FSF_SQ_NO_RETRY_POSSIBLE 0x07
130
131/* FSF status qualifier for CFDC commands */
132#define FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE 0x00000001
133#define FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2 0x00000002
134/* CFDC subtable codes */
135#define FSF_SQ_CFDC_SUBTABLE_OS 0x0001
136#define FSF_SQ_CFDC_SUBTABLE_PORT_WWPN 0x0002
137#define FSF_SQ_CFDC_SUBTABLE_PORT_DID 0x0003
138#define FSF_SQ_CFDC_SUBTABLE_LUN 0x0004
139
140/* FSF status qualifier (most significant 4 bytes), local link down */
141#define FSF_PSQ_LINK_NOLIGHT 0x00000004
142#define FSF_PSQ_LINK_WRAPPLUG 0x00000008
143#define FSF_PSQ_LINK_NOFCP 0x00000010
144
145/* payload size in status read buffer */
146#define FSF_STATUS_READ_PAYLOAD_SIZE 4032
147
148/* number of status read buffers that should be sent by ULP */
149#define FSF_STATUS_READS_RECOM 16
150
151/* status types in status read buffer */
152#define FSF_STATUS_READ_PORT_CLOSED 0x00000001
153#define FSF_STATUS_READ_INCOMING_ELS 0x00000002
154#define FSF_STATUS_READ_SENSE_DATA_AVAIL 0x00000003
155#define FSF_STATUS_READ_BIT_ERROR_THRESHOLD 0x00000004
156#define FSF_STATUS_READ_LINK_DOWN 0x00000005 /* FIXME: really? */
157#define FSF_STATUS_READ_LINK_UP 0x00000006
158#define FSF_STATUS_READ_CFDC_UPDATED 0x0000000A
159#define FSF_STATUS_READ_CFDC_HARDENED 0x0000000B
160
161/* status subtypes in status read buffer */
162#define FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT 0x00000001
163#define FSF_STATUS_READ_SUB_ERROR_PORT 0x00000002
164
165/* status subtypes for CFDC */
166#define FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE 0x00000002
167#define FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2 0x0000000F
168
169/* topologie that is detected by the adapter */
170#define FSF_TOPO_ERROR 0x00000000
171#define FSF_TOPO_P2P 0x00000001
172#define FSF_TOPO_FABRIC 0x00000002
173#define FSF_TOPO_AL 0x00000003
174#define FSF_TOPO_FABRIC_VIRT 0x00000004
175
176/* data direction for FCP commands */
177#define FSF_DATADIR_WRITE 0x00000001
178#define FSF_DATADIR_READ 0x00000002
179#define FSF_DATADIR_READ_WRITE 0x00000003
180#define FSF_DATADIR_CMND 0x00000004
181
182/* fc service class */
183#define FSF_CLASS_1 0x00000001
184#define FSF_CLASS_2 0x00000002
185#define FSF_CLASS_3 0x00000003
186
187/* SBAL chaining */
188#define FSF_MAX_SBALS_PER_REQ 36
189#define FSF_MAX_SBALS_PER_ELS_REQ 2
190
191/* logging space behind QTCB */
192#define FSF_QTCB_LOG_SIZE 1024
193
194/* channel features */
195#define FSF_FEATURE_QTCB_SUPPRESSION 0x00000001
196#define FSF_FEATURE_CFDC 0x00000002
197#define FSF_FEATURE_LUN_SHARING 0x00000004
198#define FSF_FEATURE_HBAAPI_MANAGEMENT 0x00000010
199#define FSF_FEATURE_ELS_CT_CHAINED_SBALS 0x00000020
200
201/* option */
202#define FSF_OPEN_LUN_SUPPRESS_BOXING 0x00000001
203#define FSF_OPEN_LUN_REPLICATE_SENSE 0x00000002
204
205/* adapter types */
206#define FSF_ADAPTER_TYPE_FICON 0x00000001
207#define FSF_ADAPTER_TYPE_FICON_EXPRESS 0x00000002
208
209/* port types */
210#define FSF_HBA_PORTTYPE_UNKNOWN 0x00000001
211#define FSF_HBA_PORTTYPE_NOTPRESENT 0x00000003
212#define FSF_HBA_PORTTYPE_NPORT 0x00000005
213#define FSF_HBA_PORTTYPE_PTP 0x00000021
214/* following are not defined and used by FSF Spec
215 but are additionally defined by FC-HBA */
216#define FSF_HBA_PORTTYPE_OTHER 0x00000002
217#define FSF_HBA_PORTTYPE_NOTPRESENT 0x00000003
218#define FSF_HBA_PORTTYPE_NLPORT 0x00000006
219#define FSF_HBA_PORTTYPE_FLPORT 0x00000007
220#define FSF_HBA_PORTTYPE_FPORT 0x00000008
221#define FSF_HBA_PORTTYPE_LPORT 0x00000020
222
223/* port states */
224#define FSF_HBA_PORTSTATE_UNKNOWN 0x00000001
225#define FSF_HBA_PORTSTATE_ONLINE 0x00000002
226#define FSF_HBA_PORTSTATE_OFFLINE 0x00000003
227#define FSF_HBA_PORTSTATE_LINKDOWN 0x00000006
228#define FSF_HBA_PORTSTATE_ERROR 0x00000007
229
230/* IO states of adapter */
231#define FSF_IOSTAT_NPORT_RJT 0x00000004
232#define FSF_IOSTAT_FABRIC_RJT 0x00000005
233#define FSF_IOSTAT_LS_RJT 0x00000009
234
235/* open LUN access flags*/
236#define FSF_UNIT_ACCESS_OPEN_LUN_ALLOWED 0x01000000
237#define FSF_UNIT_ACCESS_EXCLUSIVE 0x02000000
238#define FSF_UNIT_ACCESS_OUTBOUND_TRANSFER 0x10000000
239
240struct fsf_queue_designator;
241struct fsf_status_read_buffer;
242struct fsf_port_closed_payload;
243struct fsf_bit_error_payload;
244union fsf_prot_status_qual;
245struct fsf_qual_version_error;
246struct fsf_qual_sequence_error;
247struct fsf_qtcb_prefix;
248struct fsf_qtcb_header;
249struct fsf_qtcb_bottom_config;
250struct fsf_qtcb_bottom_support;
251struct fsf_qtcb_bottom_io;
252union fsf_qtcb_bottom;
253
254struct fsf_queue_designator {
255 u8 cssid;
256 u8 chpid;
257 u8 hla;
258 u8 ua;
259 u32 res1;
260} __attribute__ ((packed));
261
262struct fsf_port_closed_payload {
263 struct fsf_queue_designator queue_designator;
264 u32 port_handle;
265} __attribute__ ((packed));
266
267struct fsf_bit_error_payload {
268 u32 res1;
269 u32 link_failure_error_count;
270 u32 loss_of_sync_error_count;
271 u32 loss_of_signal_error_count;
272 u32 primitive_sequence_error_count;
273 u32 invalid_transmission_word_error_count;
274 u32 crc_error_count;
275 u32 primitive_sequence_event_timeout_count;
276 u32 elastic_buffer_overrun_error_count;
277 u32 fcal_arbitration_timeout_count;
278 u32 advertised_receive_b2b_credit;
279 u32 current_receive_b2b_credit;
280 u32 advertised_transmit_b2b_credit;
281 u32 current_transmit_b2b_credit;
282} __attribute__ ((packed));
283
284struct fsf_status_read_buffer {
285 u32 status_type;
286 u32 status_subtype;
287 u32 length;
288 u32 res1;
289 struct fsf_queue_designator queue_designator;
290 u32 d_id;
291 u32 class;
292 u64 fcp_lun;
293 u8 res3[24];
294 u8 payload[FSF_STATUS_READ_PAYLOAD_SIZE];
295} __attribute__ ((packed));
296
297struct fsf_qual_version_error {
298 u32 fsf_version;
299 u32 res1[3];
300} __attribute__ ((packed));
301
302struct fsf_qual_sequence_error {
303 u32 exp_req_seq_no;
304 u32 res1[3];
305} __attribute__ ((packed));
306
307struct fsf_qual_locallink_error {
308 u32 code;
309 u32 res1[3];
310} __attribute__ ((packed));
311
312union fsf_prot_status_qual {
313 struct fsf_qual_version_error version_error;
314 struct fsf_qual_sequence_error sequence_error;
315 struct fsf_qual_locallink_error locallink_error;
316} __attribute__ ((packed));
317
318struct fsf_qtcb_prefix {
319 u64 req_id;
320 u32 qtcb_version;
321 u32 ulp_info;
322 u32 qtcb_type;
323 u32 req_seq_no;
324 u32 prot_status;
325 union fsf_prot_status_qual prot_status_qual;
326 u8 res1[20];
327} __attribute__ ((packed));
328
329union fsf_status_qual {
330 u8 byte[FSF_STATUS_QUALIFIER_SIZE];
331 u16 halfword[FSF_STATUS_QUALIFIER_SIZE / sizeof (u16)];
332 u32 word[FSF_STATUS_QUALIFIER_SIZE / sizeof (u32)];
333 struct fsf_queue_designator fsf_queue_designator;
334} __attribute__ ((packed));
335
336struct fsf_qtcb_header {
337 u64 req_handle;
338 u32 fsf_command;
339 u32 res1;
340 u32 port_handle;
341 u32 lun_handle;
342 u32 res2;
343 u32 fsf_status;
344 union fsf_status_qual fsf_status_qual;
345 u8 res3[28];
346 u16 log_start;
347 u16 log_length;
348 u8 res4[16];
349} __attribute__ ((packed));
350
351struct fsf_nport_serv_param {
352 u8 common_serv_param[16];
353 u64 wwpn;
354 u64 wwnn;
355 u8 class1_serv_param[16];
356 u8 class2_serv_param[16];
357 u8 class3_serv_param[16];
358 u8 class4_serv_param[16];
359 u8 vendor_version_level[16];
360 u8 res1[16];
361} __attribute__ ((packed));
362
363struct fsf_plogi {
364 u32 code;
365 struct fsf_nport_serv_param serv_param;
366} __attribute__ ((packed));
367
368#define FSF_FCP_CMND_SIZE 288
369#define FSF_FCP_RSP_SIZE 128
370
371struct fsf_qtcb_bottom_io {
372 u32 data_direction;
373 u32 service_class;
374 u8 res1[8];
375 u32 fcp_cmnd_length;
376 u8 res2[12];
377 u8 fcp_cmnd[FSF_FCP_CMND_SIZE];
378 u8 fcp_rsp[FSF_FCP_RSP_SIZE];
379 u8 res3[64];
380} __attribute__ ((packed));
381
382struct fsf_qtcb_bottom_support {
383 u32 operation_subtype;
384 u8 res1[12];
385 u32 d_id;
386 u32 option;
387 u64 fcp_lun;
388 u64 res2;
389 u64 req_handle;
390 u32 service_class;
391 u8 res3[3];
392 u8 timeout;
393 u32 lun_access_info;
394 u8 res4[180];
395 u32 els1_length;
396 u32 els2_length;
397 u32 req_buf_length;
398 u32 resp_buf_length;
399 u8 els[256];
400} __attribute__ ((packed));
401
402struct fsf_qtcb_bottom_config {
403 u32 lic_version;
404 u32 feature_selection;
405 u32 high_qtcb_version;
406 u32 low_qtcb_version;
407 u32 max_qtcb_size;
408 u32 max_data_transfer_size;
409 u32 supported_features;
410 u8 res1[4];
411 u32 fc_topology;
412 u32 fc_link_speed;
413 u32 adapter_type;
414 u32 peer_d_id;
415 u8 res2[12];
416 u32 s_id;
417 struct fsf_nport_serv_param nport_serv_param;
418 u8 res3[8];
419 u32 adapter_ports;
420 u32 hardware_version;
421 u8 serial_number[32];
422 u8 res4[272];
423} __attribute__ ((packed));
424
425struct fsf_qtcb_bottom_port {
426 u8 res1[8];
427 u32 fc_port_id;
428 u32 port_type;
429 u32 port_state;
430 u32 class_of_service; /* should be 0x00000006 for class 2 and 3 */
431 u8 supported_fc4_types[32]; /* should be 0x00000100 for scsi fcp */
432 u8 active_fc4_types[32];
433 u32 supported_speed; /* 0x0001 for 1 GBit/s or 0x0002 for 2 GBit/s */
434 u32 maximum_frame_size; /* fixed value of 2112 */
435 u64 seconds_since_last_reset;
436 u64 tx_frames;
437 u64 tx_words;
438 u64 rx_frames;
439 u64 rx_words;
440 u64 lip; /* 0 */
441 u64 nos; /* currently 0 */
442 u64 error_frames; /* currently 0 */
443 u64 dumped_frames; /* currently 0 */
444 u64 link_failure;
445 u64 loss_of_sync;
446 u64 loss_of_signal;
447 u64 psp_error_counts;
448 u64 invalid_tx_words;
449 u64 invalid_crcs;
450 u64 input_requests;
451 u64 output_requests;
452 u64 control_requests;
453 u64 input_mb; /* where 1 MByte == 1.000.000 Bytes */
454 u64 output_mb; /* where 1 MByte == 1.000.000 Bytes */
455 u8 res2[256];
456} __attribute__ ((packed));
457
458union fsf_qtcb_bottom {
459 struct fsf_qtcb_bottom_io io;
460 struct fsf_qtcb_bottom_support support;
461 struct fsf_qtcb_bottom_config config;
462 struct fsf_qtcb_bottom_port port;
463};
464
465struct fsf_qtcb {
466 struct fsf_qtcb_prefix prefix;
467 struct fsf_qtcb_header header;
468 union fsf_qtcb_bottom bottom;
469 u8 log[FSF_QTCB_LOG_SIZE];
470} __attribute__ ((packed));
471
472#endif /* FSF_H */
diff --git a/drivers/s390/scsi/zfcp_qdio.c b/drivers/s390/scsi/zfcp_qdio.c
new file mode 100644
index 000000000000..06e862d7bc90
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_qdio.c
@@ -0,0 +1,868 @@
1/*
2 * linux/drivers/s390/scsi/zfcp_qdio.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * QDIO related routines
7 *
8 * (C) Copyright IBM Corp. 2002, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Wolfgang Taphorn
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
32#define ZFCP_QDIO_C_REVISION "$Revision: 1.20 $"
33
34#include "zfcp_ext.h"
35
36static inline void zfcp_qdio_sbal_limit(struct zfcp_fsf_req *, int);
37static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_get
38 (struct zfcp_qdio_queue *, int, int);
39static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_resp
40 (struct zfcp_fsf_req *, int, int);
41static inline volatile struct qdio_buffer_element *zfcp_qdio_sbal_chain
42 (struct zfcp_fsf_req *, unsigned long);
43static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_next
44 (struct zfcp_fsf_req *, unsigned long);
45static inline int zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *, int, int);
46static inline int zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *);
47static inline void zfcp_qdio_sbale_fill
48 (struct zfcp_fsf_req *, unsigned long, void *, int);
49static inline int zfcp_qdio_sbals_from_segment
50 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long);
51static inline int zfcp_qdio_sbals_from_buffer
52 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long, int);
53
54static qdio_handler_t zfcp_qdio_request_handler;
55static qdio_handler_t zfcp_qdio_response_handler;
56static int zfcp_qdio_handler_error_check(struct zfcp_adapter *,
57 unsigned int,
58 unsigned int, unsigned int);
59
60#define ZFCP_LOG_AREA ZFCP_LOG_AREA_QDIO
61
62/*
63 * Allocates BUFFER memory to each of the pointers of the qdio_buffer_t
64 * array in the adapter struct.
65 * Cur_buf is the pointer array and count can be any number of required
66 * buffers, the page-fitting arithmetic is done entirely within this funciton.
67 *
68 * returns: number of buffers allocated
69 * locks: must only be called with zfcp_data.config_sema taken
70 */
71static int
72zfcp_qdio_buffers_enqueue(struct qdio_buffer **cur_buf, int count)
73{
74 int buf_pos;
75 int qdio_buffers_per_page;
76 int page_pos = 0;
77 struct qdio_buffer *first_in_page = NULL;
78
79 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
80 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
81
82 for (buf_pos = 0; buf_pos < count; buf_pos++) {
83 if (page_pos == 0) {
84 cur_buf[buf_pos] = (struct qdio_buffer *)
85 get_zeroed_page(GFP_KERNEL);
86 if (cur_buf[buf_pos] == NULL) {
87 ZFCP_LOG_INFO("error: allocation of "
88 "QDIO buffer failed \n");
89 goto out;
90 }
91 first_in_page = cur_buf[buf_pos];
92 } else {
93 cur_buf[buf_pos] = first_in_page + page_pos;
94
95 }
96 /* was initialised to zero */
97 page_pos++;
98 page_pos %= qdio_buffers_per_page;
99 }
100 out:
101 return buf_pos;
102}
103
104/*
105 * Frees BUFFER memory for each of the pointers of the struct qdio_buffer array
106 * in the adapter struct cur_buf is the pointer array and count can be any
107 * number of buffers in the array that should be freed starting from buffer 0
108 *
109 * locks: must only be called with zfcp_data.config_sema taken
110 */
111static void
112zfcp_qdio_buffers_dequeue(struct qdio_buffer **cur_buf, int count)
113{
114 int buf_pos;
115 int qdio_buffers_per_page;
116
117 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
118 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
119
120 for (buf_pos = 0; buf_pos < count; buf_pos += qdio_buffers_per_page)
121 free_page((unsigned long) cur_buf[buf_pos]);
122 return;
123}
124
125/* locks: must only be called with zfcp_data.config_sema taken */
126int
127zfcp_qdio_allocate_queues(struct zfcp_adapter *adapter)
128{
129 int buffer_count;
130 int retval = 0;
131
132 buffer_count =
133 zfcp_qdio_buffers_enqueue(&(adapter->request_queue.buffer[0]),
134 QDIO_MAX_BUFFERS_PER_Q);
135 if (buffer_count < QDIO_MAX_BUFFERS_PER_Q) {
136 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for request "
137 "queue\n", buffer_count);
138 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
139 buffer_count);
140 retval = -ENOMEM;
141 goto out;
142 }
143
144 buffer_count =
145 zfcp_qdio_buffers_enqueue(&(adapter->response_queue.buffer[0]),
146 QDIO_MAX_BUFFERS_PER_Q);
147 if (buffer_count < QDIO_MAX_BUFFERS_PER_Q) {
148 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for response "
149 "queue", buffer_count);
150 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
151 buffer_count);
152 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
153 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
154 QDIO_MAX_BUFFERS_PER_Q);
155 retval = -ENOMEM;
156 goto out;
157 }
158 out:
159 return retval;
160}
161
162/* locks: must only be called with zfcp_data.config_sema taken */
163void
164zfcp_qdio_free_queues(struct zfcp_adapter *adapter)
165{
166 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
167 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
168 QDIO_MAX_BUFFERS_PER_Q);
169
170 ZFCP_LOG_TRACE("freeing response_queue buffers\n");
171 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
172 QDIO_MAX_BUFFERS_PER_Q);
173}
174
175int
176zfcp_qdio_allocate(struct zfcp_adapter *adapter)
177{
178 struct qdio_initialize *init_data;
179
180 init_data = &adapter->qdio_init_data;
181
182 init_data->cdev = adapter->ccw_device;
183 init_data->q_format = QDIO_SCSI_QFMT;
184 memcpy(init_data->adapter_name, &adapter->name, 8);
185 init_data->qib_param_field_format = 0;
186 init_data->qib_param_field = NULL;
187 init_data->input_slib_elements = NULL;
188 init_data->output_slib_elements = NULL;
189 init_data->min_input_threshold = ZFCP_MIN_INPUT_THRESHOLD;
190 init_data->max_input_threshold = ZFCP_MAX_INPUT_THRESHOLD;
191 init_data->min_output_threshold = ZFCP_MIN_OUTPUT_THRESHOLD;
192 init_data->max_output_threshold = ZFCP_MAX_OUTPUT_THRESHOLD;
193 init_data->no_input_qs = 1;
194 init_data->no_output_qs = 1;
195 init_data->input_handler = zfcp_qdio_response_handler;
196 init_data->output_handler = zfcp_qdio_request_handler;
197 init_data->int_parm = (unsigned long) adapter;
198 init_data->flags = QDIO_INBOUND_0COPY_SBALS |
199 QDIO_OUTBOUND_0COPY_SBALS | QDIO_USE_OUTBOUND_PCIS;
200 init_data->input_sbal_addr_array =
201 (void **) (adapter->response_queue.buffer);
202 init_data->output_sbal_addr_array =
203 (void **) (adapter->request_queue.buffer);
204
205 return qdio_allocate(init_data);
206}
207
208/*
209 * function: zfcp_qdio_handler_error_check
210 *
211 * purpose: called by the response handler to determine error condition
212 *
213 * returns: error flag
214 *
215 */
216static inline int
217zfcp_qdio_handler_error_check(struct zfcp_adapter *adapter,
218 unsigned int status,
219 unsigned int qdio_error, unsigned int siga_error)
220{
221 int retval = 0;
222
223 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_TRACE)) {
224 if (status & QDIO_STATUS_INBOUND_INT) {
225 ZFCP_LOG_TRACE("status is"
226 " QDIO_STATUS_INBOUND_INT \n");
227 }
228 if (status & QDIO_STATUS_OUTBOUND_INT) {
229 ZFCP_LOG_TRACE("status is"
230 " QDIO_STATUS_OUTBOUND_INT \n");
231 }
232 } // if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_TRACE))
233 if (unlikely(status & QDIO_STATUS_LOOK_FOR_ERROR)) {
234 retval = -EIO;
235
236 ZFCP_LOG_FLAGS(1, "QDIO_STATUS_LOOK_FOR_ERROR \n");
237
238 ZFCP_LOG_INFO("QDIO problem occurred (status=0x%x, "
239 "qdio_error=0x%x, siga_error=0x%x)\n",
240 status, qdio_error, siga_error);
241
242 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) {
243 ZFCP_LOG_FLAGS(2,
244 "QDIO_STATUS_ACTIVATE_CHECK_CONDITION\n");
245 }
246 if (status & QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR) {
247 ZFCP_LOG_FLAGS(2,
248 "QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR\n");
249 }
250 if (status & QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR) {
251 ZFCP_LOG_FLAGS(2,
252 "QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR\n");
253 }
254
255 if (siga_error & QDIO_SIGA_ERROR_ACCESS_EXCEPTION) {
256 ZFCP_LOG_FLAGS(2, "QDIO_SIGA_ERROR_ACCESS_EXCEPTION\n");
257 }
258
259 if (siga_error & QDIO_SIGA_ERROR_B_BIT_SET) {
260 ZFCP_LOG_FLAGS(2, "QDIO_SIGA_ERROR_B_BIT_SET\n");
261 }
262
263 switch (qdio_error) {
264 case 0:
265 ZFCP_LOG_FLAGS(3, "QDIO_OK");
266 break;
267 case SLSB_P_INPUT_ERROR:
268 ZFCP_LOG_FLAGS(1, "SLSB_P_INPUT_ERROR\n");
269 break;
270 case SLSB_P_OUTPUT_ERROR:
271 ZFCP_LOG_FLAGS(1, "SLSB_P_OUTPUT_ERROR\n");
272 break;
273 default:
274 ZFCP_LOG_NORMAL("bug: unknown QDIO error 0x%x\n",
275 qdio_error);
276 break;
277 }
278 /* Restarting IO on the failed adapter from scratch */
279 debug_text_event(adapter->erp_dbf, 1, "qdio_err");
280 /*
281 * Since we have been using this adapter, it is save to assume
282 * that it is not failed but recoverable. The card seems to
283 * report link-up events by self-initiated queue shutdown.
284 * That is why we need to clear the the link-down flag
285 * which is set again in case we have missed by a mile.
286 */
287 zfcp_erp_adapter_reopen(
288 adapter,
289 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
290 ZFCP_STATUS_COMMON_ERP_FAILED);
291 }
292 return retval;
293}
294
295/*
296 * function: zfcp_qdio_request_handler
297 *
298 * purpose: is called by QDIO layer for completed SBALs in request queue
299 *
300 * returns: (void)
301 */
302static void
303zfcp_qdio_request_handler(struct ccw_device *ccw_device,
304 unsigned int status,
305 unsigned int qdio_error,
306 unsigned int siga_error,
307 unsigned int queue_number,
308 int first_element,
309 int elements_processed,
310 unsigned long int_parm)
311{
312 struct zfcp_adapter *adapter;
313 struct zfcp_qdio_queue *queue;
314
315 adapter = (struct zfcp_adapter *) int_parm;
316 queue = &adapter->request_queue;
317
318 ZFCP_LOG_DEBUG("adapter %s, first=%d, elements_processed=%d\n",
319 zfcp_get_busid_by_adapter(adapter),
320 first_element, elements_processed);
321
322 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
323 siga_error)))
324 goto out;
325 /*
326 * we stored address of struct zfcp_adapter data structure
327 * associated with irq in int_parm
328 */
329
330 /* cleanup all SBALs being program-owned now */
331 zfcp_qdio_zero_sbals(queue->buffer, first_element, elements_processed);
332
333 /* increase free space in outbound queue */
334 atomic_add(elements_processed, &queue->free_count);
335 ZFCP_LOG_DEBUG("free_count=%d\n", atomic_read(&queue->free_count));
336 wake_up(&adapter->request_wq);
337 ZFCP_LOG_DEBUG("elements_processed=%d, free count=%d\n",
338 elements_processed, atomic_read(&queue->free_count));
339 out:
340 return;
341}
342
343/*
344 * function: zfcp_qdio_response_handler
345 *
346 * purpose: is called by QDIO layer for completed SBALs in response queue
347 *
348 * returns: (void)
349 */
350static void
351zfcp_qdio_response_handler(struct ccw_device *ccw_device,
352 unsigned int status,
353 unsigned int qdio_error,
354 unsigned int siga_error,
355 unsigned int queue_number,
356 int first_element,
357 int elements_processed,
358 unsigned long int_parm)
359{
360 struct zfcp_adapter *adapter;
361 struct zfcp_qdio_queue *queue;
362 int buffer_index;
363 int i;
364 struct qdio_buffer *buffer;
365 int retval = 0;
366 u8 count;
367 u8 start;
368 volatile struct qdio_buffer_element *buffere = NULL;
369 int buffere_index;
370
371 adapter = (struct zfcp_adapter *) int_parm;
372 queue = &adapter->response_queue;
373
374 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
375 siga_error)))
376 goto out;
377
378 /*
379 * we stored address of struct zfcp_adapter data structure
380 * associated with irq in int_parm
381 */
382
383 buffere = &(queue->buffer[first_element]->element[0]);
384 ZFCP_LOG_DEBUG("first BUFFERE flags=0x%x\n", buffere->flags);
385 /*
386 * go through all SBALs from input queue currently
387 * returned by QDIO layer
388 */
389
390 for (i = 0; i < elements_processed; i++) {
391
392 buffer_index = first_element + i;
393 buffer_index %= QDIO_MAX_BUFFERS_PER_Q;
394 buffer = queue->buffer[buffer_index];
395
396 /* go through all SBALEs of SBAL */
397 for (buffere_index = 0;
398 buffere_index < QDIO_MAX_ELEMENTS_PER_BUFFER;
399 buffere_index++) {
400
401 /* look for QDIO request identifiers in SB */
402 buffere = &buffer->element[buffere_index];
403 retval = zfcp_qdio_reqid_check(adapter,
404 (void *) buffere->addr);
405
406 if (retval) {
407 ZFCP_LOG_NORMAL("bug: unexpected inbound "
408 "packet on adapter %s "
409 "(reqid=0x%lx, "
410 "first_element=%d, "
411 "elements_processed=%d)\n",
412 zfcp_get_busid_by_adapter(adapter),
413 (unsigned long) buffere->addr,
414 first_element,
415 elements_processed);
416 ZFCP_LOG_NORMAL("hex dump of inbound buffer "
417 "at address %p "
418 "(buffer_index=%d, "
419 "buffere_index=%d)\n", buffer,
420 buffer_index, buffere_index);
421 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
422 (char *) buffer, SBAL_SIZE);
423 }
424 /*
425 * A single used SBALE per inbound SBALE has been
426 * implemented by QDIO so far. Hope they will
427 * do some optimisation. Will need to change to
428 * unlikely() then.
429 */
430 if (likely(buffere->flags & SBAL_FLAGS_LAST_ENTRY))
431 break;
432 };
433
434 if (unlikely(!(buffere->flags & SBAL_FLAGS_LAST_ENTRY))) {
435 ZFCP_LOG_NORMAL("bug: End of inbound data "
436 "not marked!\n");
437 }
438 }
439
440 /*
441 * put range of SBALs back to response queue
442 * (including SBALs which have already been free before)
443 */
444 count = atomic_read(&queue->free_count) + elements_processed;
445 start = queue->free_index;
446
447 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
448 "queue_no=%i, index_in_queue=%i, count=%i, "
449 "buffers=0x%lx\n",
450 zfcp_get_busid_by_adapter(adapter),
451 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
452 0, start, count, (unsigned long) &queue->buffer[start]);
453
454 retval = do_QDIO(ccw_device,
455 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
456 0, start, count, NULL);
457
458 if (unlikely(retval)) {
459 atomic_set(&queue->free_count, count);
460 ZFCP_LOG_DEBUG("clearing of inbound data regions failed, "
461 "queues may be down "
462 "(count=%d, start=%d, retval=%d)\n",
463 count, start, retval);
464 } else {
465 queue->free_index += count;
466 queue->free_index %= QDIO_MAX_BUFFERS_PER_Q;
467 atomic_set(&queue->free_count, 0);
468 ZFCP_LOG_TRACE("%i buffers enqueued to response "
469 "queue at position %i\n", count, start);
470 }
471 out:
472 return;
473}
474
475/*
476 * function: zfcp_qdio_reqid_check
477 *
478 * purpose: checks for valid reqids or unsolicited status
479 *
480 * returns: 0 - valid request id or unsolicited status
481 * !0 - otherwise
482 */
483int
484zfcp_qdio_reqid_check(struct zfcp_adapter *adapter, void *sbale_addr)
485{
486 struct zfcp_fsf_req *fsf_req;
487 int retval = 0;
488
489 /* invalid (per convention used in this driver) */
490 if (unlikely(!sbale_addr)) {
491 ZFCP_LOG_NORMAL("bug: invalid reqid\n");
492 retval = -EINVAL;
493 goto out;
494 }
495
496 /* valid request id and thus (hopefully :) valid fsf_req address */
497 fsf_req = (struct zfcp_fsf_req *) sbale_addr;
498
499 if (unlikely(adapter != fsf_req->adapter)) {
500 ZFCP_LOG_NORMAL("bug: invalid reqid (fsf_req=%p, "
501 "fsf_req->adapter=%p, adapter=%p)\n",
502 fsf_req, fsf_req->adapter, adapter);
503 retval = -EINVAL;
504 goto out;
505 }
506
507 ZFCP_LOG_TRACE("fsf_req at %p, QTCB at %p\n", fsf_req, fsf_req->qtcb);
508 if (likely(fsf_req->qtcb)) {
509 ZFCP_LOG_TRACE("hex dump of QTCB:\n");
510 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) fsf_req->qtcb,
511 sizeof(struct fsf_qtcb));
512 }
513
514 /* finish the FSF request */
515 zfcp_fsf_req_complete(fsf_req);
516 out:
517 return retval;
518}
519
520/**
521 * zfcp_qdio_sbale_get - return pointer to SBALE of qdio_queue
522 * @queue: queue from which SBALE should be returned
523 * @sbal: specifies number of SBAL in queue
524 * @sbale: specifes number of SBALE in SBAL
525 */
526static inline volatile struct qdio_buffer_element *
527zfcp_qdio_sbale_get(struct zfcp_qdio_queue *queue, int sbal, int sbale)
528{
529 return &queue->buffer[sbal]->element[sbale];
530}
531
532/**
533 * zfcp_qdio_sbale_req - return pointer to SBALE of request_queue for
534 * a struct zfcp_fsf_req
535 */
536inline volatile struct qdio_buffer_element *
537zfcp_qdio_sbale_req(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
538{
539 return zfcp_qdio_sbale_get(&fsf_req->adapter->request_queue,
540 sbal, sbale);
541}
542
543/**
544 * zfcp_qdio_sbale_resp - return pointer to SBALE of response_queue for
545 * a struct zfcp_fsf_req
546 */
547static inline volatile struct qdio_buffer_element *
548zfcp_qdio_sbale_resp(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
549{
550 return zfcp_qdio_sbale_get(&fsf_req->adapter->response_queue,
551 sbal, sbale);
552}
553
554/**
555 * zfcp_qdio_sbale_curr - return current SBALE on request_queue for
556 * a struct zfcp_fsf_req
557 */
558inline volatile struct qdio_buffer_element *
559zfcp_qdio_sbale_curr(struct zfcp_fsf_req *fsf_req)
560{
561 return zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr,
562 fsf_req->sbale_curr);
563}
564
565/**
566 * zfcp_qdio_sbal_limit - determine maximum number of SBALs that can be used
567 * on the request_queue for a struct zfcp_fsf_req
568 * @fsf_req: the number of the last SBAL that can be used is stored herein
569 * @max_sbals: used to pass an upper limit for the number of SBALs
570 *
571 * Note: We can assume at least one free SBAL in the request_queue when called.
572 */
573static inline void
574zfcp_qdio_sbal_limit(struct zfcp_fsf_req *fsf_req, int max_sbals)
575{
576 int count = atomic_read(&fsf_req->adapter->request_queue.free_count);
577 count = min(count, max_sbals);
578 fsf_req->sbal_last = fsf_req->sbal_first;
579 fsf_req->sbal_last += (count - 1);
580 fsf_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q;
581}
582
583/**
584 * zfcp_qdio_sbal_chain - chain SBALs if more than one SBAL is needed for a
585 * request
586 * @fsf_req: zfcp_fsf_req to be processed
587 * @sbtype: SBAL flags which have to be set in first SBALE of new SBAL
588 *
589 * This function changes sbal_curr, sbale_curr, sbal_number of fsf_req.
590 */
591static inline volatile struct qdio_buffer_element *
592zfcp_qdio_sbal_chain(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
593{
594 volatile struct qdio_buffer_element *sbale;
595
596 /* set last entry flag in current SBALE of current SBAL */
597 sbale = zfcp_qdio_sbale_curr(fsf_req);
598 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
599
600 /* don't exceed last allowed SBAL */
601 if (fsf_req->sbal_curr == fsf_req->sbal_last)
602 return NULL;
603
604 /* set chaining flag in first SBALE of current SBAL */
605 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
606 sbale->flags |= SBAL_FLAGS0_MORE_SBALS;
607
608 /* calculate index of next SBAL */
609 fsf_req->sbal_curr++;
610 fsf_req->sbal_curr %= QDIO_MAX_BUFFERS_PER_Q;
611
612 /* keep this requests number of SBALs up-to-date */
613 fsf_req->sbal_number++;
614
615 /* start at first SBALE of new SBAL */
616 fsf_req->sbale_curr = 0;
617
618 /* set storage-block type for new SBAL */
619 sbale = zfcp_qdio_sbale_curr(fsf_req);
620 sbale->flags |= sbtype;
621
622 return sbale;
623}
624
625/**
626 * zfcp_qdio_sbale_next - switch to next SBALE, chain SBALs if needed
627 */
628static inline volatile struct qdio_buffer_element *
629zfcp_qdio_sbale_next(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
630{
631 if (fsf_req->sbale_curr == ZFCP_LAST_SBALE_PER_SBAL)
632 return zfcp_qdio_sbal_chain(fsf_req, sbtype);
633
634 fsf_req->sbale_curr++;
635
636 return zfcp_qdio_sbale_curr(fsf_req);
637}
638
639/**
640 * zfcp_qdio_sbals_zero - initialize SBALs between first and last in queue
641 * with zero from
642 */
643static inline int
644zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *queue, int first, int last)
645{
646 struct qdio_buffer **buf = queue->buffer;
647 int curr = first;
648 int count = 0;
649
650 for(;;) {
651 curr %= QDIO_MAX_BUFFERS_PER_Q;
652 count++;
653 memset(buf[curr], 0, sizeof(struct qdio_buffer));
654 if (curr == last)
655 break;
656 curr++;
657 }
658 return count;
659}
660
661
662/**
663 * zfcp_qdio_sbals_wipe - reset all changes in SBALs for an fsf_req
664 */
665static inline int
666zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *fsf_req)
667{
668 return zfcp_qdio_sbals_zero(&fsf_req->adapter->request_queue,
669 fsf_req->sbal_first, fsf_req->sbal_curr);
670}
671
672
673/**
674 * zfcp_qdio_sbale_fill - set address and lenght in current SBALE
675 * on request_queue
676 */
677static inline void
678zfcp_qdio_sbale_fill(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
679 void *addr, int length)
680{
681 volatile struct qdio_buffer_element *sbale;
682
683 sbale = zfcp_qdio_sbale_curr(fsf_req);
684 sbale->addr = addr;
685 sbale->length = length;
686}
687
688/**
689 * zfcp_qdio_sbals_from_segment - map memory segment to SBALE(s)
690 * @fsf_req: request to be processed
691 * @sbtype: SBALE flags
692 * @start_addr: address of memory segment
693 * @total_length: length of memory segment
694 *
695 * Alignment and length of the segment determine how many SBALEs are needed
696 * for the memory segment.
697 */
698static inline int
699zfcp_qdio_sbals_from_segment(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
700 void *start_addr, unsigned long total_length)
701{
702 unsigned long remaining, length;
703 void *addr;
704
705 /* split segment up heeding page boundaries */
706 for (addr = start_addr, remaining = total_length; remaining > 0;
707 addr += length, remaining -= length) {
708 /* get next free SBALE for new piece */
709 if (NULL == zfcp_qdio_sbale_next(fsf_req, sbtype)) {
710 /* no SBALE left, clean up and leave */
711 zfcp_qdio_sbals_wipe(fsf_req);
712 return -EINVAL;
713 }
714 /* calculate length of new piece */
715 length = min(remaining,
716 (PAGE_SIZE - ((unsigned long) addr &
717 (PAGE_SIZE - 1))));
718 /* fill current SBALE with calculated piece */
719 zfcp_qdio_sbale_fill(fsf_req, sbtype, addr, length);
720 }
721 return total_length;
722}
723
724
725/**
726 * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list
727 * @fsf_req: request to be processed
728 * @sbtype: SBALE flags
729 * @sg: scatter-gather list
730 * @sg_count: number of elements in scatter-gather list
731 * @max_sbals: upper bound for number of SBALs to be used
732 */
733inline int
734zfcp_qdio_sbals_from_sg(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
735 struct scatterlist *sg, int sg_count, int max_sbals)
736{
737 int sg_index;
738 struct scatterlist *sg_segment;
739 int retval;
740 volatile struct qdio_buffer_element *sbale;
741 int bytes = 0;
742
743 /* figure out last allowed SBAL */
744 zfcp_qdio_sbal_limit(fsf_req, max_sbals);
745
746 /* set storage-block type for current SBAL */
747 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
748 sbale->flags |= sbtype;
749
750 /* process all segements of scatter-gather list */
751 for (sg_index = 0, sg_segment = sg, bytes = 0;
752 sg_index < sg_count;
753 sg_index++, sg_segment++) {
754 retval = zfcp_qdio_sbals_from_segment(
755 fsf_req,
756 sbtype,
757 zfcp_sg_to_address(sg_segment),
758 sg_segment->length);
759 if (retval < 0) {
760 bytes = retval;
761 goto out;
762 } else
763 bytes += retval;
764 }
765 /* assume that no other SBALEs are to follow in the same SBAL */
766 sbale = zfcp_qdio_sbale_curr(fsf_req);
767 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
768out:
769 return bytes;
770}
771
772
773/**
774 * zfcp_qdio_sbals_from_buffer - fill SBALs from buffer
775 * @fsf_req: request to be processed
776 * @sbtype: SBALE flags
777 * @buffer: data buffer
778 * @length: length of buffer
779 * @max_sbals: upper bound for number of SBALs to be used
780 */
781static inline int
782zfcp_qdio_sbals_from_buffer(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
783 void *buffer, unsigned long length, int max_sbals)
784{
785 struct scatterlist sg_segment;
786
787 zfcp_address_to_sg(buffer, &sg_segment);
788 sg_segment.length = length;
789
790 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype, &sg_segment, 1,
791 max_sbals);
792}
793
794
795/**
796 * zfcp_qdio_sbals_from_scsicmnd - fill SBALs from scsi command
797 * @fsf_req: request to be processed
798 * @sbtype: SBALE flags
799 * @scsi_cmnd: either scatter-gather list or buffer contained herein is used
800 * to fill SBALs
801 */
802inline int
803zfcp_qdio_sbals_from_scsicmnd(struct zfcp_fsf_req *fsf_req,
804 unsigned long sbtype, struct scsi_cmnd *scsi_cmnd)
805{
806 if (scsi_cmnd->use_sg) {
807 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype,
808 (struct scatterlist *)
809 scsi_cmnd->request_buffer,
810 scsi_cmnd->use_sg,
811 ZFCP_MAX_SBALS_PER_REQ);
812 } else {
813 return zfcp_qdio_sbals_from_buffer(fsf_req, sbtype,
814 scsi_cmnd->request_buffer,
815 scsi_cmnd->request_bufflen,
816 ZFCP_MAX_SBALS_PER_REQ);
817 }
818}
819
820/**
821 * zfcp_qdio_determine_pci - set PCI flag in first SBALE on qdio queue if needed
822 */
823int
824zfcp_qdio_determine_pci(struct zfcp_qdio_queue *req_queue,
825 struct zfcp_fsf_req *fsf_req)
826{
827 int new_distance_from_int;
828 int pci_pos;
829 volatile struct qdio_buffer_element *sbale;
830
831 new_distance_from_int = req_queue->distance_from_int +
832 fsf_req->sbal_number;
833
834 if (unlikely(new_distance_from_int >= ZFCP_QDIO_PCI_INTERVAL)) {
835 new_distance_from_int %= ZFCP_QDIO_PCI_INTERVAL;
836 pci_pos = fsf_req->sbal_first;
837 pci_pos += fsf_req->sbal_number;
838 pci_pos -= new_distance_from_int;
839 pci_pos -= 1;
840 pci_pos %= QDIO_MAX_BUFFERS_PER_Q;
841 sbale = zfcp_qdio_sbale_req(fsf_req, pci_pos, 0);
842 sbale->flags |= SBAL_FLAGS0_PCI;
843 }
844 return new_distance_from_int;
845}
846
847/*
848 * function: zfcp_zero_sbals
849 *
850 * purpose: zeros specified range of SBALs
851 *
852 * returns:
853 */
854void
855zfcp_qdio_zero_sbals(struct qdio_buffer *buf[], int first, int clean_count)
856{
857 int cur_pos;
858 int index;
859
860 for (cur_pos = first; cur_pos < (first + clean_count); cur_pos++) {
861 index = cur_pos % QDIO_MAX_BUFFERS_PER_Q;
862 memset(buf[index], 0, sizeof (struct qdio_buffer));
863 ZFCP_LOG_TRACE("zeroing BUFFER %d at address %p\n",
864 index, buf[index]);
865 }
866}
867
868#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
new file mode 100644
index 000000000000..e21b547fd427
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -0,0 +1,949 @@
1/*
2 *
3 * linux/drivers/s390/scsi/zfcp_scsi.c
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
32#define ZFCP_LOG_AREA ZFCP_LOG_AREA_SCSI
33
34#define ZFCP_SCSI_REVISION "$Revision: 1.74 $"
35
36#include "zfcp_ext.h"
37
38static void zfcp_scsi_slave_destroy(struct scsi_device *sdp);
39static int zfcp_scsi_slave_alloc(struct scsi_device *sdp);
40static int zfcp_scsi_slave_configure(struct scsi_device *sdp);
41static int zfcp_scsi_queuecommand(struct scsi_cmnd *,
42 void (*done) (struct scsi_cmnd *));
43static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *);
44static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *);
45static int zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *);
46static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *);
47static int zfcp_task_management_function(struct zfcp_unit *, u8);
48
49static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int, scsi_id_t,
50 scsi_lun_t);
51static struct zfcp_port *zfcp_port_lookup(struct zfcp_adapter *, int,
52 scsi_id_t);
53
54static struct device_attribute *zfcp_sysfs_sdev_attrs[];
55
56struct scsi_transport_template *zfcp_transport_template;
57
58struct zfcp_data zfcp_data = {
59 .scsi_host_template = {
60 name: ZFCP_NAME,
61 proc_name: "zfcp",
62 proc_info: NULL,
63 detect: NULL,
64 slave_alloc: zfcp_scsi_slave_alloc,
65 slave_configure: zfcp_scsi_slave_configure,
66 slave_destroy: zfcp_scsi_slave_destroy,
67 queuecommand: zfcp_scsi_queuecommand,
68 eh_abort_handler: zfcp_scsi_eh_abort_handler,
69 eh_device_reset_handler: zfcp_scsi_eh_device_reset_handler,
70 eh_bus_reset_handler: zfcp_scsi_eh_bus_reset_handler,
71 eh_host_reset_handler: zfcp_scsi_eh_host_reset_handler,
72 /* FIXME(openfcp): Tune */
73 can_queue: 4096,
74 this_id: 0,
75 /*
76 * FIXME:
77 * one less? can zfcp_create_sbale cope with it?
78 */
79 sg_tablesize: ZFCP_MAX_SBALES_PER_REQ,
80 cmd_per_lun: 1,
81 unchecked_isa_dma: 0,
82 use_clustering: 1,
83 sdev_attrs: zfcp_sysfs_sdev_attrs,
84 },
85 .driver_version = ZFCP_VERSION,
86 /* rest initialised with zeros */
87};
88
89/* Find start of Response Information in FCP response unit*/
90char *
91zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
92{
93 char *fcp_rsp_info_ptr;
94
95 fcp_rsp_info_ptr =
96 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
97
98 return fcp_rsp_info_ptr;
99}
100
101/* Find start of Sense Information in FCP response unit*/
102char *
103zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu)
104{
105 char *fcp_sns_info_ptr;
106
107 fcp_sns_info_ptr =
108 (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu));
109 if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)
110 fcp_sns_info_ptr = (char *) fcp_sns_info_ptr +
111 fcp_rsp_iu->fcp_rsp_len;
112
113 return fcp_sns_info_ptr;
114}
115
116fcp_dl_t *
117zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd)
118{
119 int additional_length = fcp_cmd->add_fcp_cdb_length << 2;
120 fcp_dl_t *fcp_dl_addr;
121
122 fcp_dl_addr = (fcp_dl_t *)
123 ((unsigned char *) fcp_cmd +
124 sizeof (struct fcp_cmnd_iu) + additional_length);
125 /*
126 * fcp_dl_addr = start address of fcp_cmnd structure +
127 * size of fixed part + size of dynamically sized add_dcp_cdb field
128 * SEE FCP-2 documentation
129 */
130 return fcp_dl_addr;
131}
132
133fcp_dl_t
134zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd)
135{
136 return *zfcp_get_fcp_dl_ptr(fcp_cmd);
137}
138
139void
140zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl)
141{
142 *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl;
143}
144
145/*
146 * note: it's a bit-or operation not an assignment
147 * regarding the specified byte
148 */
149static inline void
150set_byte(u32 * result, char status, char pos)
151{
152 *result |= status << (pos * 8);
153}
154
155void
156set_host_byte(u32 * result, char status)
157{
158 set_byte(result, status, 2);
159}
160
161void
162set_driver_byte(u32 * result, char status)
163{
164 set_byte(result, status, 3);
165}
166
167/*
168 * function: zfcp_scsi_slave_alloc
169 *
170 * purpose:
171 *
172 * returns:
173 */
174
175static int
176zfcp_scsi_slave_alloc(struct scsi_device *sdp)
177{
178 struct zfcp_adapter *adapter;
179 struct zfcp_unit *unit;
180 unsigned long flags;
181 int retval = -ENODEV;
182
183 adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
184 if (!adapter)
185 goto out;
186
187 read_lock_irqsave(&zfcp_data.config_lock, flags);
188 unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun);
189 if (unit) {
190 sdp->hostdata = unit;
191 unit->device = sdp;
192 zfcp_unit_get(unit);
193 retval = 0;
194 }
195 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
196 out:
197 return retval;
198}
199
200/*
201 * function: zfcp_scsi_slave_destroy
202 *
203 * purpose:
204 *
205 * returns:
206 */
207
208static void
209zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
210{
211 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
212
213 if (unit) {
214 sdpnt->hostdata = NULL;
215 unit->device = NULL;
216 zfcp_unit_put(unit);
217 } else {
218 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at "
219 "address %p\n", sdpnt);
220 }
221}
222
223/*
224 * called from scsi midlayer to allow finetuning of a device.
225 */
226static int
227zfcp_scsi_slave_configure(struct scsi_device *sdp)
228{
229 if (sdp->tagged_supported)
230 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN);
231 else
232 scsi_adjust_queue_depth(sdp, 0, 1);
233 return 0;
234}
235
236/**
237 * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function
238 * @scpnt: pointer to struct scsi_cmnd where result is set
239 * @result: result to be set in scpnt (e.g. DID_ERROR)
240 */
241static void
242zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
243{
244 set_host_byte(&scpnt->result, result);
245 zfcp_cmd_dbf_event_scsi("failing", scpnt);
246 /* return directly */
247 scpnt->scsi_done(scpnt);
248}
249
250/**
251 * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and
252 * zfcp_scsi_command_sync
253 * @adapter: adapter where scsi command is issued
254 * @unit: unit to which scsi command is sent
255 * @scpnt: scsi command to be sent
256 * @timer: timer to be started if request is successfully initiated
257 *
258 * Note: In scsi_done function must be set in scpnt.
259 */
260int
261zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit,
262 struct scsi_cmnd *scpnt, struct timer_list *timer)
263{
264 int tmp;
265 int retval;
266
267 retval = 0;
268
269 BUG_ON((adapter == NULL) || (adapter != unit->port->adapter));
270 BUG_ON(scpnt->scsi_done == NULL);
271
272 if (unlikely(NULL == unit)) {
273 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
274 goto out;
275 }
276
277 if (unlikely(
278 atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) ||
279 !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) {
280 ZFCP_LOG_DEBUG("stopping SCSI I/O on unit 0x%016Lx on port "
281 "0x%016Lx on adapter %s\n",
282 unit->fcp_lun, unit->port->wwpn,
283 zfcp_get_busid_by_adapter(adapter));
284 zfcp_scsi_command_fail(scpnt, DID_ERROR);
285 goto out;
286 }
287
288 if (unlikely(
289 !atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))) {
290 ZFCP_LOG_DEBUG("adapter %s not ready or unit 0x%016Lx "
291 "on port 0x%016Lx in recovery\n",
292 zfcp_get_busid_by_unit(unit),
293 unit->fcp_lun, unit->port->wwpn);
294 retval = SCSI_MLQUEUE_DEVICE_BUSY;
295 goto out;
296 }
297
298 tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, timer,
299 ZFCP_REQ_AUTO_CLEANUP);
300
301 if (unlikely(tmp < 0)) {
302 ZFCP_LOG_DEBUG("error: initiation of Send FCP Cmnd failed\n");
303 retval = SCSI_MLQUEUE_HOST_BUSY;
304 }
305
306out:
307 return retval;
308}
309
310void
311zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt)
312{
313 struct completion *wait = (struct completion *) scpnt->SCp.ptr;
314 complete(wait);
315}
316
317
318/**
319 * zfcp_scsi_command_sync - send a SCSI command and wait for completion
320 * @unit: unit where command is sent to
321 * @scpnt: scsi command to be sent
322 * @timer: timer to be started if request is successfully initiated
323 * Return: 0
324 *
325 * Errors are indicated in scpnt->result
326 */
327int
328zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt,
329 struct timer_list *timer)
330{
331 int ret;
332 DECLARE_COMPLETION(wait);
333
334 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */
335 scpnt->scsi_done = zfcp_scsi_command_sync_handler;
336 ret = zfcp_scsi_command_async(unit->port->adapter, unit, scpnt, timer);
337 if (ret == 0)
338 wait_for_completion(&wait);
339
340 scpnt->SCp.ptr = NULL;
341
342 return 0;
343}
344
345/*
346 * function: zfcp_scsi_queuecommand
347 *
348 * purpose: enqueues a SCSI command to the specified target device
349 *
350 * returns: 0 - success, SCSI command enqueued
351 * !0 - failure
352 */
353int
354zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
355 void (*done) (struct scsi_cmnd *))
356{
357 struct zfcp_unit *unit;
358 struct zfcp_adapter *adapter;
359
360 /* reset the status for this request */
361 scpnt->result = 0;
362 scpnt->host_scribble = NULL;
363 scpnt->scsi_done = done;
364
365 /*
366 * figure out adapter and target device
367 * (stored there by zfcp_scsi_slave_alloc)
368 */
369 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
370 unit = (struct zfcp_unit *) scpnt->device->hostdata;
371
372 return zfcp_scsi_command_async(adapter, unit, scpnt, NULL);
373}
374
375/*
376 * function: zfcp_unit_lookup
377 *
378 * purpose:
379 *
380 * returns:
381 *
382 * context:
383 */
384static struct zfcp_unit *
385zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id,
386 scsi_lun_t lun)
387{
388 struct zfcp_port *port;
389 struct zfcp_unit *unit, *retval = NULL;
390
391 list_for_each_entry(port, &adapter->port_list_head, list) {
392 if (id != port->scsi_id)
393 continue;
394 list_for_each_entry(unit, &port->unit_list_head, list) {
395 if (lun == unit->scsi_lun) {
396 retval = unit;
397 goto out;
398 }
399 }
400 }
401 out:
402 return retval;
403}
404
405static struct zfcp_port *
406zfcp_port_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id)
407{
408 struct zfcp_port *port;
409
410 list_for_each_entry(port, &adapter->port_list_head, list) {
411 if (id == port->scsi_id)
412 return port;
413 }
414 return (struct zfcp_port *) NULL;
415}
416
417/*
418 * function: zfcp_scsi_eh_abort_handler
419 *
420 * purpose: tries to abort the specified (timed out) SCSI command
421 *
422 * note: We do not need to care for a SCSI command which completes
423 * normally but late during this abort routine runs.
424 * We are allowed to return late commands to the SCSI stack.
425 * It tracks the state of commands and will handle late commands.
426 * (Usually, the normal completion of late commands is ignored with
427 * respect to the running abort operation. Grep for 'done_late'
428 * in the SCSI stacks sources.)
429 *
430 * returns: SUCCESS - command has been aborted and cleaned up in internal
431 * bookkeeping,
432 * SCSI stack won't be called for aborted command
433 * FAILED - otherwise
434 */
435int
436zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
437{
438 int retval = SUCCESS;
439 struct zfcp_fsf_req *new_fsf_req, *old_fsf_req;
440 struct zfcp_adapter *adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
441 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
442 struct zfcp_port *port = unit->port;
443 struct Scsi_Host *scsi_host = scpnt->device->host;
444 union zfcp_req_data *req_data = NULL;
445 unsigned long flags;
446 u32 status = 0;
447
448 /* the components of a abort_dbf record (fixed size record) */
449 u64 dbf_scsi_cmnd = (unsigned long) scpnt;
450 char dbf_opcode[ZFCP_ABORT_DBF_LENGTH];
451 wwn_t dbf_wwn = port->wwpn;
452 fcp_lun_t dbf_fcp_lun = unit->fcp_lun;
453 u64 dbf_retries = scpnt->retries;
454 u64 dbf_allowed = scpnt->allowed;
455 u64 dbf_timeout = 0;
456 u64 dbf_fsf_req = 0;
457 u64 dbf_fsf_status = 0;
458 u64 dbf_fsf_qual[2] = { 0, 0 };
459 char dbf_result[ZFCP_ABORT_DBF_LENGTH] = "##undef";
460
461 memset(dbf_opcode, 0, ZFCP_ABORT_DBF_LENGTH);
462 memcpy(dbf_opcode,
463 scpnt->cmnd,
464 min(scpnt->cmd_len, (unsigned char) ZFCP_ABORT_DBF_LENGTH));
465
466 ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n",
467 scpnt, zfcp_get_busid_by_adapter(adapter));
468
469 spin_unlock_irq(scsi_host->host_lock);
470
471 /*
472 * Race condition between normal (late) completion and abort has
473 * to be avoided.
474 * The entirity of all accesses to scsi_req have to be atomic.
475 * scsi_req is usually part of the fsf_req and thus we block the
476 * release of fsf_req as long as we need to access scsi_req.
477 */
478 write_lock_irqsave(&adapter->abort_lock, flags);
479
480 /*
481 * Check whether command has just completed and can not be aborted.
482 * Even if the command has just been completed late, we can access
483 * scpnt since the SCSI stack does not release it at least until
484 * this routine returns. (scpnt is parameter passed to this routine
485 * and must not disappear during abort even on late completion.)
486 */
487 req_data = (union zfcp_req_data *) scpnt->host_scribble;
488 /* DEBUG */
489 ZFCP_LOG_DEBUG("req_data=%p\n", req_data);
490 if (!req_data) {
491 ZFCP_LOG_DEBUG("late command completion overtook abort\n");
492 /*
493 * That's it.
494 * Do not initiate abort but return SUCCESS.
495 */
496 write_unlock_irqrestore(&adapter->abort_lock, flags);
497 retval = SUCCESS;
498 strncpy(dbf_result, "##late1", ZFCP_ABORT_DBF_LENGTH);
499 goto out;
500 }
501
502 /* Figure out which fsf_req needs to be aborted. */
503 old_fsf_req = req_data->send_fcp_command_task.fsf_req;
504
505 dbf_fsf_req = (unsigned long) old_fsf_req;
506 dbf_timeout =
507 (jiffies - req_data->send_fcp_command_task.start_jiffies) / HZ;
508
509 ZFCP_LOG_DEBUG("old_fsf_req=%p\n", old_fsf_req);
510 if (!old_fsf_req) {
511 write_unlock_irqrestore(&adapter->abort_lock, flags);
512 ZFCP_LOG_NORMAL("bug: no old fsf request found\n");
513 ZFCP_LOG_NORMAL("req_data:\n");
514 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
515 (char *) req_data, sizeof (union zfcp_req_data));
516 ZFCP_LOG_NORMAL("scsi_cmnd:\n");
517 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
518 (char *) scpnt, sizeof (struct scsi_cmnd));
519 retval = FAILED;
520 strncpy(dbf_result, "##bug:r", ZFCP_ABORT_DBF_LENGTH);
521 goto out;
522 }
523 old_fsf_req->data.send_fcp_command_task.scsi_cmnd = NULL;
524 /* mark old request as being aborted */
525 old_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING;
526 /*
527 * We have to collect all information (e.g. unit) needed by
528 * zfcp_fsf_abort_fcp_command before calling that routine
529 * since that routine is not allowed to access
530 * fsf_req which it is going to abort.
531 * This is because of we need to release fsf_req_list_lock
532 * before calling zfcp_fsf_abort_fcp_command.
533 * Since this lock will not be held, fsf_req may complete
534 * late and may be released meanwhile.
535 */
536 ZFCP_LOG_DEBUG("unit 0x%016Lx (%p)\n", unit->fcp_lun, unit);
537
538 /*
539 * We block (call schedule)
540 * That's why we must release the lock and enable the
541 * interrupts before.
542 * On the other hand we do not need the lock anymore since
543 * all critical accesses to scsi_req are done.
544 */
545 write_unlock_irqrestore(&adapter->abort_lock, flags);
546 /* call FSF routine which does the abort */
547 new_fsf_req = zfcp_fsf_abort_fcp_command((unsigned long) old_fsf_req,
548 adapter, unit, 0);
549 ZFCP_LOG_DEBUG("new_fsf_req=%p\n", new_fsf_req);
550 if (!new_fsf_req) {
551 retval = FAILED;
552 ZFCP_LOG_NORMAL("error: initiation of Abort FCP Cmnd "
553 "failed\n");
554 strncpy(dbf_result, "##nores", ZFCP_ABORT_DBF_LENGTH);
555 goto out;
556 }
557
558 /* wait for completion of abort */
559 ZFCP_LOG_DEBUG("waiting for cleanup...\n");
560#if 1
561 /*
562 * FIXME:
563 * copying zfcp_fsf_req_wait_and_cleanup code is not really nice
564 */
565 __wait_event(new_fsf_req->completion_wq,
566 new_fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
567 status = new_fsf_req->status;
568 dbf_fsf_status = new_fsf_req->qtcb->header.fsf_status;
569 /*
570 * Ralphs special debug load provides timestamps in the FSF
571 * status qualifier. This might be specified later if being
572 * useful for debugging aborts.
573 */
574 dbf_fsf_qual[0] =
575 *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[0];
576 dbf_fsf_qual[1] =
577 *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[2];
578 zfcp_fsf_req_cleanup(new_fsf_req);
579#else
580 retval = zfcp_fsf_req_wait_and_cleanup(new_fsf_req,
581 ZFCP_UNINTERRUPTIBLE, &status);
582#endif
583 ZFCP_LOG_DEBUG("Waiting for cleanup complete, status=0x%x\n", status);
584 /* status should be valid since signals were not permitted */
585 if (status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {
586 retval = SUCCESS;
587 strncpy(dbf_result, "##succ", ZFCP_ABORT_DBF_LENGTH);
588 } else if (status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
589 retval = SUCCESS;
590 strncpy(dbf_result, "##late2", ZFCP_ABORT_DBF_LENGTH);
591 } else {
592 retval = FAILED;
593 strncpy(dbf_result, "##fail", ZFCP_ABORT_DBF_LENGTH);
594 }
595
596 out:
597 debug_event(adapter->abort_dbf, 1, &dbf_scsi_cmnd, sizeof (u64));
598 debug_event(adapter->abort_dbf, 1, &dbf_opcode, ZFCP_ABORT_DBF_LENGTH);
599 debug_event(adapter->abort_dbf, 1, &dbf_wwn, sizeof (wwn_t));
600 debug_event(adapter->abort_dbf, 1, &dbf_fcp_lun, sizeof (fcp_lun_t));
601 debug_event(adapter->abort_dbf, 1, &dbf_retries, sizeof (u64));
602 debug_event(adapter->abort_dbf, 1, &dbf_allowed, sizeof (u64));
603 debug_event(adapter->abort_dbf, 1, &dbf_timeout, sizeof (u64));
604 debug_event(adapter->abort_dbf, 1, &dbf_fsf_req, sizeof (u64));
605 debug_event(adapter->abort_dbf, 1, &dbf_fsf_status, sizeof (u64));
606 debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[0], sizeof (u64));
607 debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[1], sizeof (u64));
608 debug_text_event(adapter->abort_dbf, 1, dbf_result);
609
610 spin_lock_irq(scsi_host->host_lock);
611 return retval;
612}
613
614/*
615 * function: zfcp_scsi_eh_device_reset_handler
616 *
617 * purpose:
618 *
619 * returns:
620 */
621int
622zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
623{
624 int retval;
625 struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
626 struct Scsi_Host *scsi_host = scpnt->device->host;
627
628 spin_unlock_irq(scsi_host->host_lock);
629
630 if (!unit) {
631 ZFCP_LOG_NORMAL("bug: Tried reset for nonexistent unit\n");
632 retval = SUCCESS;
633 goto out;
634 }
635 ZFCP_LOG_NORMAL("resetting unit 0x%016Lx\n", unit->fcp_lun);
636
637 /*
638 * If we do not know whether the unit supports 'logical unit reset'
639 * then try 'logical unit reset' and proceed with 'target reset'
640 * if 'logical unit reset' fails.
641 * If the unit is known not to support 'logical unit reset' then
642 * skip 'logical unit reset' and try 'target reset' immediately.
643 */
644 if (!atomic_test_mask(ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
645 &unit->status)) {
646 retval =
647 zfcp_task_management_function(unit, FCP_LOGICAL_UNIT_RESET);
648 if (retval) {
649 ZFCP_LOG_DEBUG("unit reset failed (unit=%p)\n", unit);
650 if (retval == -ENOTSUPP)
651 atomic_set_mask
652 (ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,
653 &unit->status);
654 /* fall through and try 'target reset' next */
655 } else {
656 ZFCP_LOG_DEBUG("unit reset succeeded (unit=%p)\n",
657 unit);
658 /* avoid 'target reset' */
659 retval = SUCCESS;
660 goto out;
661 }
662 }
663 retval = zfcp_task_management_function(unit, FCP_TARGET_RESET);
664 if (retval) {
665 ZFCP_LOG_DEBUG("target reset failed (unit=%p)\n", unit);
666 retval = FAILED;
667 } else {
668 ZFCP_LOG_DEBUG("target reset succeeded (unit=%p)\n", unit);
669 retval = SUCCESS;
670 }
671 out:
672 spin_lock_irq(scsi_host->host_lock);
673 return retval;
674}
675
676static int
677zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags)
678{
679 struct zfcp_adapter *adapter = unit->port->adapter;
680 int retval;
681 int status;
682 struct zfcp_fsf_req *fsf_req;
683
684 /* issue task management function */
685 fsf_req = zfcp_fsf_send_fcp_command_task_management
686 (adapter, unit, tm_flags, 0);
687 if (!fsf_req) {
688 ZFCP_LOG_INFO("error: creation of task management request "
689 "failed for unit 0x%016Lx on port 0x%016Lx on "
690 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
691 zfcp_get_busid_by_adapter(adapter));
692 retval = -ENOMEM;
693 goto out;
694 }
695
696 retval = zfcp_fsf_req_wait_and_cleanup(fsf_req,
697 ZFCP_UNINTERRUPTIBLE, &status);
698 /*
699 * check completion status of task management function
700 * (status should always be valid since no signals permitted)
701 */
702 if (status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED)
703 retval = -EIO;
704 else if (status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP)
705 retval = -ENOTSUPP;
706 else
707 retval = 0;
708 out:
709 return retval;
710}
711
712/*
713 * function: zfcp_scsi_eh_bus_reset_handler
714 *
715 * purpose:
716 *
717 * returns:
718 */
719int
720zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *scpnt)
721{
722 int retval = 0;
723 struct zfcp_unit *unit;
724 struct Scsi_Host *scsi_host = scpnt->device->host;
725
726 spin_unlock_irq(scsi_host->host_lock);
727
728 unit = (struct zfcp_unit *) scpnt->device->hostdata;
729 ZFCP_LOG_NORMAL("bus reset because of problems with "
730 "unit 0x%016Lx\n", unit->fcp_lun);
731 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
732 zfcp_erp_wait(unit->port->adapter);
733 retval = SUCCESS;
734
735 spin_lock_irq(scsi_host->host_lock);
736 return retval;
737}
738
739/*
740 * function: zfcp_scsi_eh_host_reset_handler
741 *
742 * purpose:
743 *
744 * returns:
745 */
746int
747zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
748{
749 int retval = 0;
750 struct zfcp_unit *unit;
751 struct Scsi_Host *scsi_host = scpnt->device->host;
752
753 spin_unlock_irq(scsi_host->host_lock);
754
755 unit = (struct zfcp_unit *) scpnt->device->hostdata;
756 ZFCP_LOG_NORMAL("host reset because of problems with "
757 "unit 0x%016Lx\n", unit->fcp_lun);
758 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
759 zfcp_erp_wait(unit->port->adapter);
760 retval = SUCCESS;
761
762 spin_lock_irq(scsi_host->host_lock);
763 return retval;
764}
765
766/*
767 * function:
768 *
769 * purpose:
770 *
771 * returns:
772 */
773int
774zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
775{
776 int retval = 0;
777 static unsigned int unique_id = 0;
778
779 /* register adapter as SCSI host with mid layer of SCSI stack */
780 adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
781 sizeof (struct zfcp_adapter *));
782 if (!adapter->scsi_host) {
783 ZFCP_LOG_NORMAL("error: registration with SCSI stack failed "
784 "for adapter %s ",
785 zfcp_get_busid_by_adapter(adapter));
786 retval = -EIO;
787 goto out;
788 }
789 ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host);
790
791 /* tell the SCSI stack some characteristics of this adapter */
792 adapter->scsi_host->max_id = 1;
793 adapter->scsi_host->max_lun = 1;
794 adapter->scsi_host->max_channel = 0;
795 adapter->scsi_host->unique_id = unique_id++; /* FIXME */
796 adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH;
797 adapter->scsi_host->transportt = zfcp_transport_template;
798 /*
799 * Reverse mapping of the host number to avoid race condition
800 */
801 adapter->scsi_host_no = adapter->scsi_host->host_no;
802
803 /*
804 * save a pointer to our own adapter data structure within
805 * hostdata field of SCSI host data structure
806 */
807 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
808
809 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
810 scsi_host_put(adapter->scsi_host);
811 retval = -EIO;
812 goto out;
813 }
814 atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
815 out:
816 return retval;
817}
818
819/*
820 * function:
821 *
822 * purpose:
823 *
824 * returns:
825 */
826void
827zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
828{
829 struct Scsi_Host *shost;
830
831 shost = adapter->scsi_host;
832 if (!shost)
833 return;
834 scsi_remove_host(shost);
835 scsi_host_put(shost);
836 adapter->scsi_host = NULL;
837 adapter->scsi_host_no = 0;
838 atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);
839
840 return;
841}
842
843
844void
845zfcp_fsf_start_scsi_er_timer(struct zfcp_adapter *adapter)
846{
847 adapter->scsi_er_timer.function = zfcp_fsf_scsi_er_timeout_handler;
848 adapter->scsi_er_timer.data = (unsigned long) adapter;
849 adapter->scsi_er_timer.expires = jiffies + ZFCP_SCSI_ER_TIMEOUT;
850 add_timer(&adapter->scsi_er_timer);
851}
852
853/*
854 * Support functions for FC transport class
855 */
856static void
857zfcp_get_port_id(struct scsi_target *starget)
858{
859 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
860 struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
861 struct zfcp_port *port;
862 unsigned long flags;
863
864 read_lock_irqsave(&zfcp_data.config_lock, flags);
865 port = zfcp_port_lookup(adapter, starget->channel, starget->id);
866 if (port)
867 fc_starget_port_id(starget) = port->d_id;
868 else
869 fc_starget_port_id(starget) = -1;
870 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
871}
872
873static void
874zfcp_get_port_name(struct scsi_target *starget)
875{
876 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
877 struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
878 struct zfcp_port *port;
879 unsigned long flags;
880
881 read_lock_irqsave(&zfcp_data.config_lock, flags);
882 port = zfcp_port_lookup(adapter, starget->channel, starget->id);
883 if (port)
884 fc_starget_port_name(starget) = port->wwpn;
885 else
886 fc_starget_port_name(starget) = -1;
887 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
888}
889
890static void
891zfcp_get_node_name(struct scsi_target *starget)
892{
893 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
894 struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
895 struct zfcp_port *port;
896 unsigned long flags;
897
898 read_lock_irqsave(&zfcp_data.config_lock, flags);
899 port = zfcp_port_lookup(adapter, starget->channel, starget->id);
900 if (port)
901 fc_starget_node_name(starget) = port->wwnn;
902 else
903 fc_starget_node_name(starget) = -1;
904 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
905}
906
907struct fc_function_template zfcp_transport_functions = {
908 .get_starget_port_id = zfcp_get_port_id,
909 .get_starget_port_name = zfcp_get_port_name,
910 .get_starget_node_name = zfcp_get_node_name,
911 .show_starget_port_id = 1,
912 .show_starget_port_name = 1,
913 .show_starget_node_name = 1,
914};
915
916/**
917 * ZFCP_DEFINE_SCSI_ATTR
918 * @_name: name of show attribute
919 * @_format: format string
920 * @_value: value to print
921 *
922 * Generates attribute for a unit.
923 */
924#define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
925static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
926 char *buf) \
927{ \
928 struct scsi_device *sdev; \
929 struct zfcp_unit *unit; \
930 \
931 sdev = to_scsi_device(dev); \
932 unit = sdev->hostdata; \
933 return sprintf(buf, _format, _value); \
934} \
935 \
936static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
937
938ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit));
939ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
940ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
941
942static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
943 &dev_attr_fcp_lun,
944 &dev_attr_wwpn,
945 &dev_attr_hba_id,
946 NULL
947};
948
949#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_sysfs_adapter.c b/drivers/s390/scsi/zfcp_sysfs_adapter.c
new file mode 100644
index 000000000000..ff28ade1dfc7
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_sysfs_adapter.c
@@ -0,0 +1,298 @@
1/*
2 * linux/drivers/s390/scsi/zfcp_sysfs_adapter.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * sysfs adapter related routines
7 *
8 * (C) Copyright IBM Corp. 2003, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#define ZFCP_SYSFS_ADAPTER_C_REVISION "$Revision: 1.38 $"
31
32#include "zfcp_ext.h"
33
34#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
35
36static const char fc_topologies[5][25] = {
37 "<error>",
38 "point-to-point",
39 "fabric",
40 "arbitrated loop",
41 "fabric (virt. adapter)"
42};
43
44/**
45 * ZFCP_DEFINE_ADAPTER_ATTR
46 * @_name: name of show attribute
47 * @_format: format string
48 * @_value: value to print
49 *
50 * Generates attributes for an adapter.
51 */
52#define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
53static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
54 char *buf) \
55{ \
56 struct zfcp_adapter *adapter; \
57 \
58 adapter = dev_get_drvdata(dev); \
59 return sprintf(buf, _format, _value); \
60} \
61 \
62static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
63
64ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
65ZFCP_DEFINE_ADAPTER_ATTR(wwnn, "0x%016llx\n", adapter->wwnn);
66ZFCP_DEFINE_ADAPTER_ATTR(wwpn, "0x%016llx\n", adapter->wwpn);
67ZFCP_DEFINE_ADAPTER_ATTR(s_id, "0x%06x\n", adapter->s_id);
68ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
69ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
70ZFCP_DEFINE_ADAPTER_ATTR(fc_link_speed, "%d Gb/s\n", adapter->fc_link_speed);
71ZFCP_DEFINE_ADAPTER_ATTR(fc_service_class, "%d\n", adapter->fc_service_class);
72ZFCP_DEFINE_ADAPTER_ATTR(fc_topology, "%s\n",
73 fc_topologies[adapter->fc_topology]);
74ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
75 adapter->hardware_version);
76ZFCP_DEFINE_ADAPTER_ATTR(serial_number, "%17s\n", adapter->serial_number);
77ZFCP_DEFINE_ADAPTER_ATTR(scsi_host_no, "0x%x\n", adapter->scsi_host_no);
78ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
79 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
80
81/**
82 * zfcp_sysfs_port_add_store - add a port to sysfs tree
83 * @dev: pointer to belonging device
84 * @buf: pointer to input buffer
85 * @count: number of bytes in buffer
86 *
87 * Store function of the "port_add" attribute of an adapter.
88 */
89static ssize_t
90zfcp_sysfs_port_add_store(struct device *dev, const char *buf, size_t count)
91{
92 wwn_t wwpn;
93 char *endp;
94 struct zfcp_adapter *adapter;
95 struct zfcp_port *port;
96 int retval = -EINVAL;
97
98 down(&zfcp_data.config_sema);
99
100 adapter = dev_get_drvdata(dev);
101 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
102 retval = -EBUSY;
103 goto out;
104 }
105
106 wwpn = simple_strtoull(buf, &endp, 0);
107 if ((endp + 1) < (buf + count))
108 goto out;
109
110 port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
111 if (!port)
112 goto out;
113
114 retval = 0;
115
116 zfcp_erp_port_reopen(port, 0);
117 zfcp_erp_wait(port->adapter);
118 zfcp_port_put(port);
119 out:
120 up(&zfcp_data.config_sema);
121 return retval ? retval : (ssize_t) count;
122}
123
124static DEVICE_ATTR(port_add, S_IWUSR, NULL, zfcp_sysfs_port_add_store);
125
126/**
127 * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
128 * @dev: pointer to belonging device
129 * @buf: pointer to input buffer
130 * @count: number of bytes in buffer
131 *
132 * Store function of the "port_remove" attribute of an adapter.
133 */
134static ssize_t
135zfcp_sysfs_port_remove_store(struct device *dev, const char *buf, size_t count)
136{
137 struct zfcp_adapter *adapter;
138 struct zfcp_port *port;
139 wwn_t wwpn;
140 char *endp;
141 int retval = 0;
142
143 down(&zfcp_data.config_sema);
144
145 adapter = dev_get_drvdata(dev);
146 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
147 retval = -EBUSY;
148 goto out;
149 }
150
151 wwpn = simple_strtoull(buf, &endp, 0);
152 if ((endp + 1) < (buf + count)) {
153 retval = -EINVAL;
154 goto out;
155 }
156
157 write_lock_irq(&zfcp_data.config_lock);
158 port = zfcp_get_port_by_wwpn(adapter, wwpn);
159 if (port && (atomic_read(&port->refcount) == 0)) {
160 zfcp_port_get(port);
161 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
162 list_move(&port->list, &adapter->port_remove_lh);
163 }
164 else {
165 port = NULL;
166 }
167 write_unlock_irq(&zfcp_data.config_lock);
168
169 if (!port) {
170 retval = -ENXIO;
171 goto out;
172 }
173
174 zfcp_erp_port_shutdown(port, 0);
175 zfcp_erp_wait(adapter);
176 zfcp_port_put(port);
177 zfcp_port_dequeue(port);
178 out:
179 up(&zfcp_data.config_sema);
180 return retval ? retval : (ssize_t) count;
181}
182
183static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
184
185/**
186 * zfcp_sysfs_adapter_failed_store - failed state of adapter
187 * @dev: pointer to belonging device
188 * @buf: pointer to input buffer
189 * @count: number of bytes in buffer
190 *
191 * Store function of the "failed" attribute of an adapter.
192 * If a "0" gets written to "failed", error recovery will be
193 * started for the belonging adapter.
194 */
195static ssize_t
196zfcp_sysfs_adapter_failed_store(struct device *dev,
197 const char *buf, size_t count)
198{
199 struct zfcp_adapter *adapter;
200 unsigned int val;
201 char *endp;
202 int retval = 0;
203
204 down(&zfcp_data.config_sema);
205
206 adapter = dev_get_drvdata(dev);
207 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
208 retval = -EBUSY;
209 goto out;
210 }
211
212 val = simple_strtoul(buf, &endp, 0);
213 if (((endp + 1) < (buf + count)) || (val != 0)) {
214 retval = -EINVAL;
215 goto out;
216 }
217
218 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
219 ZFCP_SET);
220 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
221 zfcp_erp_wait(adapter);
222 out:
223 up(&zfcp_data.config_sema);
224 return retval ? retval : (ssize_t) count;
225}
226
227/**
228 * zfcp_sysfs_adapter_failed_show - failed state of adapter
229 * @dev: pointer to belonging device
230 * @buf: pointer to input buffer
231 *
232 * Show function of "failed" attribute of adapter. Will be
233 * "0" if adapter is working, otherwise "1".
234 */
235static ssize_t
236zfcp_sysfs_adapter_failed_show(struct device *dev, char *buf)
237{
238 struct zfcp_adapter *adapter;
239
240 adapter = dev_get_drvdata(dev);
241 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
242 return sprintf(buf, "1\n");
243 else
244 return sprintf(buf, "0\n");
245}
246
247static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
248 zfcp_sysfs_adapter_failed_store);
249
250static struct attribute *zfcp_adapter_attrs[] = {
251 &dev_attr_failed.attr,
252 &dev_attr_in_recovery.attr,
253 &dev_attr_port_remove.attr,
254 &dev_attr_port_add.attr,
255 &dev_attr_wwnn.attr,
256 &dev_attr_wwpn.attr,
257 &dev_attr_s_id.attr,
258 &dev_attr_card_version.attr,
259 &dev_attr_lic_version.attr,
260 &dev_attr_fc_link_speed.attr,
261 &dev_attr_fc_service_class.attr,
262 &dev_attr_fc_topology.attr,
263 &dev_attr_scsi_host_no.attr,
264 &dev_attr_status.attr,
265 &dev_attr_hardware_version.attr,
266 &dev_attr_serial_number.attr,
267 NULL
268};
269
270static struct attribute_group zfcp_adapter_attr_group = {
271 .attrs = zfcp_adapter_attrs,
272};
273
274/**
275 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
276 * @dev: pointer to belonging device
277 *
278 * Create all attributes of the sysfs representation of an adapter.
279 */
280int
281zfcp_sysfs_adapter_create_files(struct device *dev)
282{
283 return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
284}
285
286/**
287 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
288 * @dev: pointer to belonging device
289 *
290 * Remove all attributes of the sysfs representation of an adapter.
291 */
292void
293zfcp_sysfs_adapter_remove_files(struct device *dev)
294{
295 sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);
296}
297
298#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_sysfs_driver.c b/drivers/s390/scsi/zfcp_sysfs_driver.c
new file mode 100644
index 000000000000..77a5e2dcc0ff
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_sysfs_driver.c
@@ -0,0 +1,135 @@
1/*
2 * linux/drivers/s390/scsi/zfcp_sysfs_driver.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * sysfs driver related routines
7 *
8 * (C) Copyright IBM Corp. 2003, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#define ZFCP_SYSFS_DRIVER_C_REVISION "$Revision: 1.17 $"
31
32#include "zfcp_ext.h"
33
34#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
35
36/**
37 * ZFCP_DEFINE_DRIVER_ATTR - define for all loglevels sysfs attributes
38 * @_name: name of attribute
39 * @_define: name of ZFCP loglevel define
40 *
41 * Generates store function for a sysfs loglevel attribute of zfcp driver.
42 */
43#define ZFCP_DEFINE_DRIVER_ATTR(_name, _define) \
44static ssize_t zfcp_sysfs_loglevel_##_name##_store(struct device_driver *drv, \
45 const char *buf, \
46 size_t count) \
47{ \
48 unsigned int loglevel; \
49 unsigned int new_loglevel; \
50 char *endp; \
51 \
52 new_loglevel = simple_strtoul(buf, &endp, 0); \
53 if ((endp + 1) < (buf + count)) \
54 return -EINVAL; \
55 if (new_loglevel > 3) \
56 return -EINVAL; \
57 down(&zfcp_data.config_sema); \
58 loglevel = atomic_read(&zfcp_data.loglevel); \
59 loglevel &= ~((unsigned int) 0xf << (ZFCP_LOG_AREA_##_define << 2)); \
60 loglevel |= new_loglevel << (ZFCP_LOG_AREA_##_define << 2); \
61 atomic_set(&zfcp_data.loglevel, loglevel); \
62 up(&zfcp_data.config_sema); \
63 return count; \
64} \
65 \
66static ssize_t zfcp_sysfs_loglevel_##_name##_show(struct device_driver *dev, \
67 char *buf) \
68{ \
69 return sprintf(buf,"%d\n", (unsigned int) \
70 ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA_##_define)); \
71} \
72 \
73static DRIVER_ATTR(loglevel_##_name, S_IWUSR | S_IRUGO, \
74 zfcp_sysfs_loglevel_##_name##_show, \
75 zfcp_sysfs_loglevel_##_name##_store);
76
77ZFCP_DEFINE_DRIVER_ATTR(other, OTHER);
78ZFCP_DEFINE_DRIVER_ATTR(scsi, SCSI);
79ZFCP_DEFINE_DRIVER_ATTR(fsf, FSF);
80ZFCP_DEFINE_DRIVER_ATTR(config, CONFIG);
81ZFCP_DEFINE_DRIVER_ATTR(cio, CIO);
82ZFCP_DEFINE_DRIVER_ATTR(qdio, QDIO);
83ZFCP_DEFINE_DRIVER_ATTR(erp, ERP);
84ZFCP_DEFINE_DRIVER_ATTR(fc, FC);
85
86static ssize_t zfcp_sysfs_version_show(struct device_driver *dev,
87 char *buf)
88{
89 return sprintf(buf, "%s\n", zfcp_data.driver_version);
90}
91
92static DRIVER_ATTR(version, S_IRUGO, zfcp_sysfs_version_show, NULL);
93
94static struct attribute *zfcp_driver_attrs[] = {
95 &driver_attr_loglevel_other.attr,
96 &driver_attr_loglevel_scsi.attr,
97 &driver_attr_loglevel_fsf.attr,
98 &driver_attr_loglevel_config.attr,
99 &driver_attr_loglevel_cio.attr,
100 &driver_attr_loglevel_qdio.attr,
101 &driver_attr_loglevel_erp.attr,
102 &driver_attr_loglevel_fc.attr,
103 &driver_attr_version.attr,
104 NULL
105};
106
107static struct attribute_group zfcp_driver_attr_group = {
108 .attrs = zfcp_driver_attrs,
109};
110
111/**
112 * zfcp_sysfs_create_driver_files - create sysfs driver files
113 * @dev: pointer to belonging device
114 *
115 * Create all sysfs attributes of the zfcp device driver
116 */
117int
118zfcp_sysfs_driver_create_files(struct device_driver *drv)
119{
120 return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
121}
122
123/**
124 * zfcp_sysfs_remove_driver_files - remove sysfs driver files
125 * @dev: pointer to belonging device
126 *
127 * Remove all sysfs attributes of the zfcp device driver
128 */
129void
130zfcp_sysfs_driver_remove_files(struct device_driver *drv)
131{
132 sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
133}
134
135#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_sysfs_port.c b/drivers/s390/scsi/zfcp_sysfs_port.c
new file mode 100644
index 000000000000..6aafb2abb4b5
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_sysfs_port.c
@@ -0,0 +1,311 @@
1/*
2 * linux/drivers/s390/scsi/zfcp_sysfs_port.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * sysfs port related routines
7 *
8 * (C) Copyright IBM Corp. 2003, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 * Volker Sameske <sameske@de.ibm.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#define ZFCP_SYSFS_PORT_C_REVISION "$Revision: 1.47 $"
32
33#include "zfcp_ext.h"
34
35#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
36
37/**
38 * zfcp_sysfs_port_release - gets called when a struct device port is released
39 * @dev: pointer to belonging device
40 */
41void
42zfcp_sysfs_port_release(struct device *dev)
43{
44 kfree(dev);
45}
46
47/**
48 * ZFCP_DEFINE_PORT_ATTR
49 * @_name: name of show attribute
50 * @_format: format string
51 * @_value: value to print
52 *
53 * Generates attributes for a port.
54 */
55#define ZFCP_DEFINE_PORT_ATTR(_name, _format, _value) \
56static ssize_t zfcp_sysfs_port_##_name##_show(struct device *dev, \
57 char *buf) \
58{ \
59 struct zfcp_port *port; \
60 \
61 port = dev_get_drvdata(dev); \
62 return sprintf(buf, _format, _value); \
63} \
64 \
65static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_port_##_name##_show, NULL);
66
67ZFCP_DEFINE_PORT_ATTR(status, "0x%08x\n", atomic_read(&port->status));
68ZFCP_DEFINE_PORT_ATTR(wwnn, "0x%016llx\n", port->wwnn);
69ZFCP_DEFINE_PORT_ATTR(d_id, "0x%06x\n", port->d_id);
70ZFCP_DEFINE_PORT_ATTR(scsi_id, "0x%x\n", port->scsi_id);
71ZFCP_DEFINE_PORT_ATTR(in_recovery, "%d\n", atomic_test_mask
72 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status));
73ZFCP_DEFINE_PORT_ATTR(access_denied, "%d\n", atomic_test_mask
74 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status));
75
76/**
77 * zfcp_sysfs_unit_add_store - add a unit to sysfs tree
78 * @dev: pointer to belonging device
79 * @buf: pointer to input buffer
80 * @count: number of bytes in buffer
81 *
82 * Store function of the "unit_add" attribute of a port.
83 */
84static ssize_t
85zfcp_sysfs_unit_add_store(struct device *dev, const char *buf, size_t count)
86{
87 fcp_lun_t fcp_lun;
88 char *endp;
89 struct zfcp_port *port;
90 struct zfcp_unit *unit;
91 int retval = -EINVAL;
92
93 down(&zfcp_data.config_sema);
94
95 port = dev_get_drvdata(dev);
96 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
97 retval = -EBUSY;
98 goto out;
99 }
100
101 fcp_lun = simple_strtoull(buf, &endp, 0);
102 if ((endp + 1) < (buf + count))
103 goto out;
104
105 unit = zfcp_unit_enqueue(port, fcp_lun);
106 if (!unit)
107 goto out;
108
109 retval = 0;
110
111 zfcp_erp_unit_reopen(unit, 0);
112 zfcp_erp_wait(unit->port->adapter);
113 zfcp_unit_put(unit);
114 out:
115 up(&zfcp_data.config_sema);
116 return retval ? retval : (ssize_t) count;
117}
118
119static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
120
121/**
122 * zfcp_sysfs_unit_remove_store - remove a unit from sysfs tree
123 * @dev: pointer to belonging device
124 * @buf: pointer to input buffer
125 * @count: number of bytes in buffer
126 */
127static ssize_t
128zfcp_sysfs_unit_remove_store(struct device *dev, const char *buf, size_t count)
129{
130 struct zfcp_port *port;
131 struct zfcp_unit *unit;
132 fcp_lun_t fcp_lun;
133 char *endp;
134 int retval = 0;
135
136 down(&zfcp_data.config_sema);
137
138 port = dev_get_drvdata(dev);
139 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
140 retval = -EBUSY;
141 goto out;
142 }
143
144 fcp_lun = simple_strtoull(buf, &endp, 0);
145 if ((endp + 1) < (buf + count)) {
146 retval = -EINVAL;
147 goto out;
148 }
149
150 write_lock_irq(&zfcp_data.config_lock);
151 unit = zfcp_get_unit_by_lun(port, fcp_lun);
152 if (unit && (atomic_read(&unit->refcount) == 0)) {
153 zfcp_unit_get(unit);
154 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
155 list_move(&unit->list, &port->unit_remove_lh);
156 }
157 else {
158 unit = NULL;
159 }
160 write_unlock_irq(&zfcp_data.config_lock);
161
162 if (!unit) {
163 retval = -ENXIO;
164 goto out;
165 }
166
167 zfcp_erp_unit_shutdown(unit, 0);
168 zfcp_erp_wait(unit->port->adapter);
169 zfcp_unit_put(unit);
170 zfcp_unit_dequeue(unit);
171 out:
172 up(&zfcp_data.config_sema);
173 return retval ? retval : (ssize_t) count;
174}
175
176static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
177
178/**
179 * zfcp_sysfs_port_failed_store - failed state of port
180 * @dev: pointer to belonging device
181 * @buf: pointer to input buffer
182 * @count: number of bytes in buffer
183 *
184 * Store function of the "failed" attribute of a port.
185 * If a "0" gets written to "failed", error recovery will be
186 * started for the belonging port.
187 */
188static ssize_t
189zfcp_sysfs_port_failed_store(struct device *dev, const char *buf, size_t count)
190{
191 struct zfcp_port *port;
192 unsigned int val;
193 char *endp;
194 int retval = 0;
195
196 down(&zfcp_data.config_sema);
197
198 port = dev_get_drvdata(dev);
199 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
200 retval = -EBUSY;
201 goto out;
202 }
203
204 val = simple_strtoul(buf, &endp, 0);
205 if (((endp + 1) < (buf + count)) || (val != 0)) {
206 retval = -EINVAL;
207 goto out;
208 }
209
210 zfcp_erp_modify_port_status(port, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
211 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
212 zfcp_erp_wait(port->adapter);
213 out:
214 up(&zfcp_data.config_sema);
215 return retval ? retval : (ssize_t) count;
216}
217
218/**
219 * zfcp_sysfs_port_failed_show - failed state of port
220 * @dev: pointer to belonging device
221 * @buf: pointer to input buffer
222 *
223 * Show function of "failed" attribute of port. Will be
224 * "0" if port is working, otherwise "1".
225 */
226static ssize_t
227zfcp_sysfs_port_failed_show(struct device *dev, char *buf)
228{
229 struct zfcp_port *port;
230
231 port = dev_get_drvdata(dev);
232 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status))
233 return sprintf(buf, "1\n");
234 else
235 return sprintf(buf, "0\n");
236}
237
238static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_port_failed_show,
239 zfcp_sysfs_port_failed_store);
240
241/**
242 * zfcp_port_common_attrs
243 * sysfs attributes that are common for all kind of fc ports.
244 */
245static struct attribute *zfcp_port_common_attrs[] = {
246 &dev_attr_failed.attr,
247 &dev_attr_in_recovery.attr,
248 &dev_attr_status.attr,
249 &dev_attr_wwnn.attr,
250 &dev_attr_d_id.attr,
251 &dev_attr_access_denied.attr,
252 NULL
253};
254
255static struct attribute_group zfcp_port_common_attr_group = {
256 .attrs = zfcp_port_common_attrs,
257};
258
259/**
260 * zfcp_port_no_ns_attrs
261 * sysfs attributes not to be used for nameserver ports.
262 */
263static struct attribute *zfcp_port_no_ns_attrs[] = {
264 &dev_attr_unit_add.attr,
265 &dev_attr_unit_remove.attr,
266 &dev_attr_scsi_id.attr,
267 NULL
268};
269
270static struct attribute_group zfcp_port_no_ns_attr_group = {
271 .attrs = zfcp_port_no_ns_attrs,
272};
273
274/**
275 * zfcp_sysfs_port_create_files - create sysfs port files
276 * @dev: pointer to belonging device
277 *
278 * Create all attributes of the sysfs representation of a port.
279 */
280int
281zfcp_sysfs_port_create_files(struct device *dev, u32 flags)
282{
283 int retval;
284
285 retval = sysfs_create_group(&dev->kobj, &zfcp_port_common_attr_group);
286
287 if ((flags & ZFCP_STATUS_PORT_WKA) || retval)
288 return retval;
289
290 retval = sysfs_create_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
291 if (retval)
292 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
293
294 return retval;
295}
296
297/**
298 * zfcp_sysfs_port_remove_files - remove sysfs port files
299 * @dev: pointer to belonging device
300 *
301 * Remove all attributes of the sysfs representation of a port.
302 */
303void
304zfcp_sysfs_port_remove_files(struct device *dev, u32 flags)
305{
306 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
307 if (!(flags & ZFCP_STATUS_PORT_WKA))
308 sysfs_remove_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
309}
310
311#undef ZFCP_LOG_AREA
diff --git a/drivers/s390/scsi/zfcp_sysfs_unit.c b/drivers/s390/scsi/zfcp_sysfs_unit.c
new file mode 100644
index 000000000000..87c0b461831f
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_sysfs_unit.c
@@ -0,0 +1,179 @@
1/*
2 * linux/drivers/s390/scsi/zfcp_sysfs_unit.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * sysfs unit related routines
7 *
8 * (C) Copyright IBM Corp. 2003, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 * Volker Sameske <sameske@de.ibm.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#define ZFCP_SYSFS_UNIT_C_REVISION "$Revision: 1.30 $"
32
33#include "zfcp_ext.h"
34
35#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
36
37/**
38 * zfcp_sysfs_unit_release - gets called when a struct device unit is released
39 * @dev: pointer to belonging device
40 */
41void
42zfcp_sysfs_unit_release(struct device *dev)
43{
44 kfree(dev);
45}
46
47/**
48 * ZFCP_DEFINE_UNIT_ATTR
49 * @_name: name of show attribute
50 * @_format: format string
51 * @_value: value to print
52 *
53 * Generates attribute for a unit.
54 */
55#define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
56static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, \
57 char *buf) \
58{ \
59 struct zfcp_unit *unit; \
60 \
61 unit = dev_get_drvdata(dev); \
62 return sprintf(buf, _format, _value); \
63} \
64 \
65static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
66
67ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
68ZFCP_DEFINE_UNIT_ATTR(scsi_lun, "0x%x\n", unit->scsi_lun);
69ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
70 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
71ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
72 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
73ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
74 (ZFCP_STATUS_UNIT_SHARED, &unit->status));
75ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
76 (ZFCP_STATUS_UNIT_READONLY, &unit->status));
77
78/**
79 * zfcp_sysfs_unit_failed_store - failed state of unit
80 * @dev: pointer to belonging device
81 * @buf: pointer to input buffer
82 * @count: number of bytes in buffer
83 *
84 * Store function of the "failed" attribute of a unit.
85 * If a "0" gets written to "failed", error recovery will be
86 * started for the belonging unit.
87 */
88static ssize_t
89zfcp_sysfs_unit_failed_store(struct device *dev, const char *buf, size_t count)
90{
91 struct zfcp_unit *unit;
92 unsigned int val;
93 char *endp;
94 int retval = 0;
95
96 down(&zfcp_data.config_sema);
97 unit = dev_get_drvdata(dev);
98 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
99 retval = -EBUSY;
100 goto out;
101 }
102
103 val = simple_strtoul(buf, &endp, 0);
104 if (((endp + 1) < (buf + count)) || (val != 0)) {
105 retval = -EINVAL;
106 goto out;
107 }
108
109 zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
110 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
111 zfcp_erp_wait(unit->port->adapter);
112 out:
113 up(&zfcp_data.config_sema);
114 return retval ? retval : (ssize_t) count;
115}
116
117/**
118 * zfcp_sysfs_unit_failed_show - failed state of unit
119 * @dev: pointer to belonging device
120 * @buf: pointer to input buffer
121 *
122 * Show function of "failed" attribute of unit. Will be
123 * "0" if unit is working, otherwise "1".
124 */
125static ssize_t
126zfcp_sysfs_unit_failed_show(struct device *dev, char *buf)
127{
128 struct zfcp_unit *unit;
129
130 unit = dev_get_drvdata(dev);
131 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
132 return sprintf(buf, "1\n");
133 else
134 return sprintf(buf, "0\n");
135}
136
137static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
138 zfcp_sysfs_unit_failed_store);
139
140static struct attribute *zfcp_unit_attrs[] = {
141 &dev_attr_scsi_lun.attr,
142 &dev_attr_failed.attr,
143 &dev_attr_in_recovery.attr,
144 &dev_attr_status.attr,
145 &dev_attr_access_denied.attr,
146 &dev_attr_access_shared.attr,
147 &dev_attr_access_readonly.attr,
148 NULL
149};
150
151static struct attribute_group zfcp_unit_attr_group = {
152 .attrs = zfcp_unit_attrs,
153};
154
155/**
156 * zfcp_sysfs_create_unit_files - create sysfs unit files
157 * @dev: pointer to belonging device
158 *
159 * Create all attributes of the sysfs representation of a unit.
160 */
161int
162zfcp_sysfs_unit_create_files(struct device *dev)
163{
164 return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
165}
166
167/**
168 * zfcp_sysfs_remove_unit_files - remove sysfs unit files
169 * @dev: pointer to belonging device
170 *
171 * Remove all attributes of the sysfs representation of a unit.
172 */
173void
174zfcp_sysfs_unit_remove_files(struct device *dev)
175{
176 sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
177}
178
179#undef ZFCP_LOG_AREA