blob: dc85973479284cc9d290a757e7c42b12c8e37130 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * IUCV base infrastructure.
4 *
5 * Copyright IBM Corp. 2001, 2009
6 *
7 * Author(s):
8 * Original source:
9 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
10 * Xenia Tkatschow (xenia@us.ibm.com)
11 * 2Gb awareness and general cleanup:
12 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
13 * Rewritten for af_iucv:
14 * Martin Schwidefsky <schwidefsky@de.ibm.com>
15 * PM functions:
16 * Ursula Braun (ursula.braun@de.ibm.com)
17 *
18 * Documentation used:
19 * The original source
20 * CP Programming Service, IBM document # SC24-5760
21 */
22
23#define KMSG_COMPONENT "iucv"
24#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
25
26#include <linux/kernel_stat.h>
27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/spinlock.h>
30#include <linux/kernel.h>
31#include <linux/slab.h>
32#include <linux/init.h>
33#include <linux/interrupt.h>
34#include <linux/list.h>
35#include <linux/errno.h>
36#include <linux/err.h>
37#include <linux/device.h>
38#include <linux/cpu.h>
39#include <linux/reboot.h>
40#include <net/iucv/iucv.h>
41#include <linux/atomic.h>
42#include <asm/ebcdic.h>
43#include <asm/io.h>
44#include <asm/irq.h>
45#include <asm/smp.h>
46
47/*
48 * FLAGS:
49 * All flags are defined in the field IPFLAGS1 of each function
50 * and can be found in CP Programming Services.
51 * IPSRCCLS - Indicates you have specified a source class.
52 * IPTRGCLS - Indicates you have specified a target class.
53 * IPFGPID - Indicates you have specified a pathid.
54 * IPFGMID - Indicates you have specified a message ID.
55 * IPNORPY - Indicates a one-way message. No reply expected.
56 * IPALL - Indicates that all paths are affected.
57 */
58#define IUCV_IPSRCCLS 0x01
59#define IUCV_IPTRGCLS 0x01
60#define IUCV_IPFGPID 0x02
61#define IUCV_IPFGMID 0x04
62#define IUCV_IPNORPY 0x10
63#define IUCV_IPALL 0x80
64
65static int iucv_bus_match(struct device *dev, struct device_driver *drv)
66{
67 return 0;
68}
69
70enum iucv_pm_states {
71 IUCV_PM_INITIAL = 0,
72 IUCV_PM_FREEZING = 1,
73 IUCV_PM_THAWING = 2,
74 IUCV_PM_RESTORING = 3,
75};
76static enum iucv_pm_states iucv_pm_state;
77
78static int iucv_pm_prepare(struct device *);
79static void iucv_pm_complete(struct device *);
80static int iucv_pm_freeze(struct device *);
81static int iucv_pm_thaw(struct device *);
82static int iucv_pm_restore(struct device *);
83
84static const struct dev_pm_ops iucv_pm_ops = {
85 .prepare = iucv_pm_prepare,
86 .complete = iucv_pm_complete,
87 .freeze = iucv_pm_freeze,
88 .thaw = iucv_pm_thaw,
89 .restore = iucv_pm_restore,
90};
91
92struct bus_type iucv_bus = {
93 .name = "iucv",
94 .match = iucv_bus_match,
95 .pm = &iucv_pm_ops,
96};
97EXPORT_SYMBOL(iucv_bus);
98
99struct device *iucv_root;
100EXPORT_SYMBOL(iucv_root);
101
102static int iucv_available;
103
104/* General IUCV interrupt structure */
105struct iucv_irq_data {
106 u16 ippathid;
107 u8 ipflags1;
108 u8 iptype;
109 u32 res2[9];
110};
111
112struct iucv_irq_list {
113 struct list_head list;
114 struct iucv_irq_data data;
115};
116
117static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
118static cpumask_t iucv_buffer_cpumask = { CPU_BITS_NONE };
119static cpumask_t iucv_irq_cpumask = { CPU_BITS_NONE };
120
121/*
122 * Queue of interrupt buffers lock for delivery via the tasklet
123 * (fast but can't call smp_call_function).
124 */
125static LIST_HEAD(iucv_task_queue);
126
127/*
128 * The tasklet for fast delivery of iucv interrupts.
129 */
130static void iucv_tasklet_fn(unsigned long);
131static DECLARE_TASKLET_OLD(iucv_tasklet, iucv_tasklet_fn);
132
133/*
134 * Queue of interrupt buffers for delivery via a work queue
135 * (slower but can call smp_call_function).
136 */
137static LIST_HEAD(iucv_work_queue);
138
139/*
140 * The work element to deliver path pending interrupts.
141 */
142static void iucv_work_fn(struct work_struct *work);
143static DECLARE_WORK(iucv_work, iucv_work_fn);
144
145/*
146 * Spinlock protecting task and work queue.
147 */
148static DEFINE_SPINLOCK(iucv_queue_lock);
149
150enum iucv_command_codes {
151 IUCV_QUERY = 0,
152 IUCV_RETRIEVE_BUFFER = 2,
153 IUCV_SEND = 4,
154 IUCV_RECEIVE = 5,
155 IUCV_REPLY = 6,
156 IUCV_REJECT = 8,
157 IUCV_PURGE = 9,
158 IUCV_ACCEPT = 10,
159 IUCV_CONNECT = 11,
160 IUCV_DECLARE_BUFFER = 12,
161 IUCV_QUIESCE = 13,
162 IUCV_RESUME = 14,
163 IUCV_SEVER = 15,
164 IUCV_SETMASK = 16,
165 IUCV_SETCONTROLMASK = 17,
166};
167
168/*
169 * Error messages that are used with the iucv_sever function. They get
170 * converted to EBCDIC.
171 */
172static char iucv_error_no_listener[16] = "NO LISTENER";
173static char iucv_error_no_memory[16] = "NO MEMORY";
174static char iucv_error_pathid[16] = "INVALID PATHID";
175
176/*
177 * iucv_handler_list: List of registered handlers.
178 */
179static LIST_HEAD(iucv_handler_list);
180
181/*
182 * iucv_path_table: array of pointers to iucv_path structures.
183 */
184static struct iucv_path **iucv_path_table;
185static unsigned long iucv_max_pathid;
186
187/*
188 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
189 */
190static DEFINE_SPINLOCK(iucv_table_lock);
191
192/*
193 * iucv_active_cpu: contains the number of the cpu executing the tasklet
194 * or the work handler. Needed for iucv_path_sever called from tasklet.
195 */
196static int iucv_active_cpu = -1;
197
198/*
199 * Mutex and wait queue for iucv_register/iucv_unregister.
200 */
201static DEFINE_MUTEX(iucv_register_mutex);
202
203/*
204 * Counter for number of non-smp capable handlers.
205 */
206static int iucv_nonsmp_handler;
207
208/*
209 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
210 * iucv_path_quiesce and iucv_path_sever.
211 */
212struct iucv_cmd_control {
213 u16 ippathid;
214 u8 ipflags1;
215 u8 iprcode;
216 u16 ipmsglim;
217 u16 res1;
218 u8 ipvmid[8];
219 u8 ipuser[16];
220 u8 iptarget[8];
221} __attribute__ ((packed,aligned(8)));
222
223/*
224 * Data in parameter list iucv structure. Used by iucv_message_send,
225 * iucv_message_send2way and iucv_message_reply.
226 */
227struct iucv_cmd_dpl {
228 u16 ippathid;
229 u8 ipflags1;
230 u8 iprcode;
231 u32 ipmsgid;
232 u32 iptrgcls;
233 u8 iprmmsg[8];
234 u32 ipsrccls;
235 u32 ipmsgtag;
236 u32 ipbfadr2;
237 u32 ipbfln2f;
238 u32 res;
239} __attribute__ ((packed,aligned(8)));
240
241/*
242 * Data in buffer iucv structure. Used by iucv_message_receive,
243 * iucv_message_reject, iucv_message_send, iucv_message_send2way
244 * and iucv_declare_cpu.
245 */
246struct iucv_cmd_db {
247 u16 ippathid;
248 u8 ipflags1;
249 u8 iprcode;
250 u32 ipmsgid;
251 u32 iptrgcls;
252 u32 ipbfadr1;
253 u32 ipbfln1f;
254 u32 ipsrccls;
255 u32 ipmsgtag;
256 u32 ipbfadr2;
257 u32 ipbfln2f;
258 u32 res;
259} __attribute__ ((packed,aligned(8)));
260
261/*
262 * Purge message iucv structure. Used by iucv_message_purge.
263 */
264struct iucv_cmd_purge {
265 u16 ippathid;
266 u8 ipflags1;
267 u8 iprcode;
268 u32 ipmsgid;
269 u8 ipaudit[3];
270 u8 res1[5];
271 u32 res2;
272 u32 ipsrccls;
273 u32 ipmsgtag;
274 u32 res3[3];
275} __attribute__ ((packed,aligned(8)));
276
277/*
278 * Set mask iucv structure. Used by iucv_enable_cpu.
279 */
280struct iucv_cmd_set_mask {
281 u8 ipmask;
282 u8 res1[2];
283 u8 iprcode;
284 u32 res2[9];
285} __attribute__ ((packed,aligned(8)));
286
287union iucv_param {
288 struct iucv_cmd_control ctrl;
289 struct iucv_cmd_dpl dpl;
290 struct iucv_cmd_db db;
291 struct iucv_cmd_purge purge;
292 struct iucv_cmd_set_mask set_mask;
293};
294
295/*
296 * Anchor for per-cpu IUCV command parameter block.
297 */
298static union iucv_param *iucv_param[NR_CPUS];
299static union iucv_param *iucv_param_irq[NR_CPUS];
300
301/**
302 * iucv_call_b2f0
303 * @code: identifier of IUCV call to CP.
304 * @parm: pointer to a struct iucv_parm block
305 *
306 * Calls CP to execute IUCV commands.
307 *
308 * Returns the result of the CP IUCV call.
309 */
310static inline int __iucv_call_b2f0(int command, union iucv_param *parm)
311{
312 register unsigned long reg0 asm ("0");
313 register unsigned long reg1 asm ("1");
314 int ccode;
315
316 reg0 = command;
317 reg1 = (unsigned long)parm;
318 asm volatile(
319 " .long 0xb2f01000\n"
320 " ipm %0\n"
321 " srl %0,28\n"
322 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
323 : "m" (*parm) : "cc");
324 return ccode;
325}
326
327static inline int iucv_call_b2f0(int command, union iucv_param *parm)
328{
329 int ccode;
330
331 ccode = __iucv_call_b2f0(command, parm);
332 return ccode == 1 ? parm->ctrl.iprcode : ccode;
333}
334
335/**
336 * iucv_query_maxconn
337 *
338 * Determines the maximum number of connections that may be established.
339 *
340 * Returns the maximum number of connections or -EPERM is IUCV is not
341 * available.
342 */
343static int __iucv_query_maxconn(void *param, unsigned long *max_pathid)
344{
345 register unsigned long reg0 asm ("0");
346 register unsigned long reg1 asm ("1");
347 int ccode;
348
349 reg0 = IUCV_QUERY;
350 reg1 = (unsigned long) param;
351 asm volatile (
352 " .long 0xb2f01000\n"
353 " ipm %0\n"
354 " srl %0,28\n"
355 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
356 *max_pathid = reg1;
357 return ccode;
358}
359
360static int iucv_query_maxconn(void)
361{
362 unsigned long max_pathid;
363 void *param;
364 int ccode;
365
366 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL | GFP_DMA);
367 if (!param)
368 return -ENOMEM;
369 ccode = __iucv_query_maxconn(param, &max_pathid);
370 if (ccode == 0)
371 iucv_max_pathid = max_pathid;
372 kfree(param);
373 return ccode ? -EPERM : 0;
374}
375
376/**
377 * iucv_allow_cpu
378 * @data: unused
379 *
380 * Allow iucv interrupts on this cpu.
381 */
382static void iucv_allow_cpu(void *data)
383{
384 int cpu = smp_processor_id();
385 union iucv_param *parm;
386
387 /*
388 * Enable all iucv interrupts.
389 * ipmask contains bits for the different interrupts
390 * 0x80 - Flag to allow nonpriority message pending interrupts
391 * 0x40 - Flag to allow priority message pending interrupts
392 * 0x20 - Flag to allow nonpriority message completion interrupts
393 * 0x10 - Flag to allow priority message completion interrupts
394 * 0x08 - Flag to allow IUCV control interrupts
395 */
396 parm = iucv_param_irq[cpu];
397 memset(parm, 0, sizeof(union iucv_param));
398 parm->set_mask.ipmask = 0xf8;
399 iucv_call_b2f0(IUCV_SETMASK, parm);
400
401 /*
402 * Enable all iucv control interrupts.
403 * ipmask contains bits for the different interrupts
404 * 0x80 - Flag to allow pending connections interrupts
405 * 0x40 - Flag to allow connection complete interrupts
406 * 0x20 - Flag to allow connection severed interrupts
407 * 0x10 - Flag to allow connection quiesced interrupts
408 * 0x08 - Flag to allow connection resumed interrupts
409 */
410 memset(parm, 0, sizeof(union iucv_param));
411 parm->set_mask.ipmask = 0xf8;
412 iucv_call_b2f0(IUCV_SETCONTROLMASK, parm);
413 /* Set indication that iucv interrupts are allowed for this cpu. */
414 cpumask_set_cpu(cpu, &iucv_irq_cpumask);
415}
416
417/**
418 * iucv_block_cpu
419 * @data: unused
420 *
421 * Block iucv interrupts on this cpu.
422 */
423static void iucv_block_cpu(void *data)
424{
425 int cpu = smp_processor_id();
426 union iucv_param *parm;
427
428 /* Disable all iucv interrupts. */
429 parm = iucv_param_irq[cpu];
430 memset(parm, 0, sizeof(union iucv_param));
431 iucv_call_b2f0(IUCV_SETMASK, parm);
432
433 /* Clear indication that iucv interrupts are allowed for this cpu. */
434 cpumask_clear_cpu(cpu, &iucv_irq_cpumask);
435}
436
437/**
438 * iucv_block_cpu_almost
439 * @data: unused
440 *
441 * Allow connection-severed interrupts only on this cpu.
442 */
443static void iucv_block_cpu_almost(void *data)
444{
445 int cpu = smp_processor_id();
446 union iucv_param *parm;
447
448 /* Allow iucv control interrupts only */
449 parm = iucv_param_irq[cpu];
450 memset(parm, 0, sizeof(union iucv_param));
451 parm->set_mask.ipmask = 0x08;
452 iucv_call_b2f0(IUCV_SETMASK, parm);
453 /* Allow iucv-severed interrupt only */
454 memset(parm, 0, sizeof(union iucv_param));
455 parm->set_mask.ipmask = 0x20;
456 iucv_call_b2f0(IUCV_SETCONTROLMASK, parm);
457
458 /* Clear indication that iucv interrupts are allowed for this cpu. */
459 cpumask_clear_cpu(cpu, &iucv_irq_cpumask);
460}
461
462/**
463 * iucv_declare_cpu
464 * @data: unused
465 *
466 * Declare a interrupt buffer on this cpu.
467 */
468static void iucv_declare_cpu(void *data)
469{
470 int cpu = smp_processor_id();
471 union iucv_param *parm;
472 int rc;
473
474 if (cpumask_test_cpu(cpu, &iucv_buffer_cpumask))
475 return;
476
477 /* Declare interrupt buffer. */
478 parm = iucv_param_irq[cpu];
479 memset(parm, 0, sizeof(union iucv_param));
480 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
481 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
482 if (rc) {
483 char *err = "Unknown";
484 switch (rc) {
485 case 0x03:
486 err = "Directory error";
487 break;
488 case 0x0a:
489 err = "Invalid length";
490 break;
491 case 0x13:
492 err = "Buffer already exists";
493 break;
494 case 0x3e:
495 err = "Buffer overlap";
496 break;
497 case 0x5c:
498 err = "Paging or storage error";
499 break;
500 }
501 pr_warn("Defining an interrupt buffer on CPU %i failed with 0x%02x (%s)\n",
502 cpu, rc, err);
503 return;
504 }
505
506 /* Set indication that an iucv buffer exists for this cpu. */
507 cpumask_set_cpu(cpu, &iucv_buffer_cpumask);
508
509 if (iucv_nonsmp_handler == 0 || cpumask_empty(&iucv_irq_cpumask))
510 /* Enable iucv interrupts on this cpu. */
511 iucv_allow_cpu(NULL);
512 else
513 /* Disable iucv interrupts on this cpu. */
514 iucv_block_cpu(NULL);
515}
516
517/**
518 * iucv_retrieve_cpu
519 * @data: unused
520 *
521 * Retrieve interrupt buffer on this cpu.
522 */
523static void iucv_retrieve_cpu(void *data)
524{
525 int cpu = smp_processor_id();
526 union iucv_param *parm;
527
528 if (!cpumask_test_cpu(cpu, &iucv_buffer_cpumask))
529 return;
530
531 /* Block iucv interrupts. */
532 iucv_block_cpu(NULL);
533
534 /* Retrieve interrupt buffer. */
535 parm = iucv_param_irq[cpu];
536 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
537
538 /* Clear indication that an iucv buffer exists for this cpu. */
539 cpumask_clear_cpu(cpu, &iucv_buffer_cpumask);
540}
541
542/**
543 * iucv_setmask_smp
544 *
545 * Allow iucv interrupts on all cpus.
546 */
547static void iucv_setmask_mp(void)
548{
549 int cpu;
550
551 get_online_cpus();
552 for_each_online_cpu(cpu)
553 /* Enable all cpus with a declared buffer. */
554 if (cpumask_test_cpu(cpu, &iucv_buffer_cpumask) &&
555 !cpumask_test_cpu(cpu, &iucv_irq_cpumask))
556 smp_call_function_single(cpu, iucv_allow_cpu,
557 NULL, 1);
558 put_online_cpus();
559}
560
561/**
562 * iucv_setmask_up
563 *
564 * Allow iucv interrupts on a single cpu.
565 */
566static void iucv_setmask_up(void)
567{
568 static cpumask_t cpumask;
569 int cpu;
570
571 /* Disable all cpu but the first in cpu_irq_cpumask. */
572 cpumask_copy(&cpumask, &iucv_irq_cpumask);
573 cpumask_clear_cpu(cpumask_first(&iucv_irq_cpumask), &cpumask);
574 for_each_cpu(cpu, &cpumask)
575 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
576}
577
578/**
579 * iucv_enable
580 *
581 * This function makes iucv ready for use. It allocates the pathid
582 * table, declares an iucv interrupt buffer and enables the iucv
583 * interrupts. Called when the first user has registered an iucv
584 * handler.
585 */
586static int iucv_enable(void)
587{
588 size_t alloc_size;
589 int cpu, rc;
590
591 get_online_cpus();
592 rc = -ENOMEM;
593 alloc_size = iucv_max_pathid * sizeof(*iucv_path_table);
594 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
595 if (!iucv_path_table)
596 goto out;
597 /* Declare per cpu buffers. */
598 rc = -EIO;
599 for_each_online_cpu(cpu)
600 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
601 if (cpumask_empty(&iucv_buffer_cpumask))
602 /* No cpu could declare an iucv buffer. */
603 goto out;
604 put_online_cpus();
605 return 0;
606out:
607 kfree(iucv_path_table);
608 iucv_path_table = NULL;
609 put_online_cpus();
610 return rc;
611}
612
613/**
614 * iucv_disable
615 *
616 * This function shuts down iucv. It disables iucv interrupts, retrieves
617 * the iucv interrupt buffer and frees the pathid table. Called after the
618 * last user unregister its iucv handler.
619 */
620static void iucv_disable(void)
621{
622 get_online_cpus();
623 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
624 kfree(iucv_path_table);
625 iucv_path_table = NULL;
626 put_online_cpus();
627}
628
629static int iucv_cpu_dead(unsigned int cpu)
630{
631 kfree(iucv_param_irq[cpu]);
632 iucv_param_irq[cpu] = NULL;
633 kfree(iucv_param[cpu]);
634 iucv_param[cpu] = NULL;
635 kfree(iucv_irq_data[cpu]);
636 iucv_irq_data[cpu] = NULL;
637 return 0;
638}
639
640static int iucv_cpu_prepare(unsigned int cpu)
641{
642 /* Note: GFP_DMA used to get memory below 2G */
643 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
644 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
645 if (!iucv_irq_data[cpu])
646 goto out_free;
647
648 /* Allocate parameter blocks. */
649 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
650 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
651 if (!iucv_param[cpu])
652 goto out_free;
653
654 iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
655 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
656 if (!iucv_param_irq[cpu])
657 goto out_free;
658
659 return 0;
660
661out_free:
662 iucv_cpu_dead(cpu);
663 return -ENOMEM;
664}
665
666static int iucv_cpu_online(unsigned int cpu)
667{
668 if (!iucv_path_table)
669 return 0;
670 iucv_declare_cpu(NULL);
671 return 0;
672}
673
674static int iucv_cpu_down_prep(unsigned int cpu)
675{
676 cpumask_var_t cpumask;
677 int ret = 0;
678
679 if (!iucv_path_table)
680 return 0;
681
682 if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
683 return -ENOMEM;
684
685 cpumask_copy(cpumask, &iucv_buffer_cpumask);
686 cpumask_clear_cpu(cpu, cpumask);
687 if (cpumask_empty(cpumask)) {
688 /* Can't offline last IUCV enabled cpu. */
689 ret = -EINVAL;
690 goto __free_cpumask;
691 }
692
693 iucv_retrieve_cpu(NULL);
694 if (!cpumask_empty(&iucv_irq_cpumask))
695 goto __free_cpumask;
696
697 smp_call_function_single(cpumask_first(&iucv_buffer_cpumask),
698 iucv_allow_cpu, NULL, 1);
699
700__free_cpumask:
701 free_cpumask_var(cpumask);
702 return ret;
703}
704
705/**
706 * iucv_sever_pathid
707 * @pathid: path identification number.
708 * @userdata: 16-bytes of user data.
709 *
710 * Sever an iucv path to free up the pathid. Used internally.
711 */
712static int iucv_sever_pathid(u16 pathid, u8 *userdata)
713{
714 union iucv_param *parm;
715
716 parm = iucv_param_irq[smp_processor_id()];
717 memset(parm, 0, sizeof(union iucv_param));
718 if (userdata)
719 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
720 parm->ctrl.ippathid = pathid;
721 return iucv_call_b2f0(IUCV_SEVER, parm);
722}
723
724/**
725 * __iucv_cleanup_queue
726 * @dummy: unused dummy argument
727 *
728 * Nop function called via smp_call_function to force work items from
729 * pending external iucv interrupts to the work queue.
730 */
731static void __iucv_cleanup_queue(void *dummy)
732{
733}
734
735/**
736 * iucv_cleanup_queue
737 *
738 * Function called after a path has been severed to find all remaining
739 * work items for the now stale pathid. The caller needs to hold the
740 * iucv_table_lock.
741 */
742static void iucv_cleanup_queue(void)
743{
744 struct iucv_irq_list *p, *n;
745
746 /*
747 * When a path is severed, the pathid can be reused immediately
748 * on a iucv connect or a connection pending interrupt. Remove
749 * all entries from the task queue that refer to a stale pathid
750 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
751 * or deliver the connection pending interrupt. To get all the
752 * pending interrupts force them to the work queue by calling
753 * an empty function on all cpus.
754 */
755 smp_call_function(__iucv_cleanup_queue, NULL, 1);
756 spin_lock_irq(&iucv_queue_lock);
757 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
758 /* Remove stale work items from the task queue. */
759 if (iucv_path_table[p->data.ippathid] == NULL) {
760 list_del(&p->list);
761 kfree(p);
762 }
763 }
764 spin_unlock_irq(&iucv_queue_lock);
765}
766
767/**
768 * iucv_register:
769 * @handler: address of iucv handler structure
770 * @smp: != 0 indicates that the handler can deal with out of order messages
771 *
772 * Registers a driver with IUCV.
773 *
774 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
775 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
776 */
777int iucv_register(struct iucv_handler *handler, int smp)
778{
779 int rc;
780
781 if (!iucv_available)
782 return -ENOSYS;
783 mutex_lock(&iucv_register_mutex);
784 if (!smp)
785 iucv_nonsmp_handler++;
786 if (list_empty(&iucv_handler_list)) {
787 rc = iucv_enable();
788 if (rc)
789 goto out_mutex;
790 } else if (!smp && iucv_nonsmp_handler == 1)
791 iucv_setmask_up();
792 INIT_LIST_HEAD(&handler->paths);
793
794 spin_lock_bh(&iucv_table_lock);
795 list_add_tail(&handler->list, &iucv_handler_list);
796 spin_unlock_bh(&iucv_table_lock);
797 rc = 0;
798out_mutex:
799 mutex_unlock(&iucv_register_mutex);
800 return rc;
801}
802EXPORT_SYMBOL(iucv_register);
803
804/**
805 * iucv_unregister
806 * @handler: address of iucv handler structure
807 * @smp: != 0 indicates that the handler can deal with out of order messages
808 *
809 * Unregister driver from IUCV.
810 */
811void iucv_unregister(struct iucv_handler *handler, int smp)
812{
813 struct iucv_path *p, *n;
814
815 mutex_lock(&iucv_register_mutex);
816 spin_lock_bh(&iucv_table_lock);
817 /* Remove handler from the iucv_handler_list. */
818 list_del_init(&handler->list);
819 /* Sever all pathids still referring to the handler. */
820 list_for_each_entry_safe(p, n, &handler->paths, list) {
821 iucv_sever_pathid(p->pathid, NULL);
822 iucv_path_table[p->pathid] = NULL;
823 list_del(&p->list);
824 iucv_path_free(p);
825 }
826 spin_unlock_bh(&iucv_table_lock);
827 if (!smp)
828 iucv_nonsmp_handler--;
829 if (list_empty(&iucv_handler_list))
830 iucv_disable();
831 else if (!smp && iucv_nonsmp_handler == 0)
832 iucv_setmask_mp();
833 mutex_unlock(&iucv_register_mutex);
834}
835EXPORT_SYMBOL(iucv_unregister);
836
837static int iucv_reboot_event(struct notifier_block *this,
838 unsigned long event, void *ptr)
839{
840 int i;
841
842 if (cpumask_empty(&iucv_irq_cpumask))
843 return NOTIFY_DONE;
844
845 get_online_cpus();
846 on_each_cpu_mask(&iucv_irq_cpumask, iucv_block_cpu, NULL, 1);
847 preempt_disable();
848 for (i = 0; i < iucv_max_pathid; i++) {
849 if (iucv_path_table[i])
850 iucv_sever_pathid(i, NULL);
851 }
852 preempt_enable();
853 put_online_cpus();
854 iucv_disable();
855 return NOTIFY_DONE;
856}
857
858static struct notifier_block iucv_reboot_notifier = {
859 .notifier_call = iucv_reboot_event,
860};
861
862/**
863 * iucv_path_accept
864 * @path: address of iucv path structure
865 * @handler: address of iucv handler structure
866 * @userdata: 16 bytes of data reflected to the communication partner
867 * @private: private data passed to interrupt handlers for this path
868 *
869 * This function is issued after the user received a connection pending
870 * external interrupt and now wishes to complete the IUCV communication path.
871 *
872 * Returns the result of the CP IUCV call.
873 */
874int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
875 u8 *userdata, void *private)
876{
877 union iucv_param *parm;
878 int rc;
879
880 local_bh_disable();
881 if (cpumask_empty(&iucv_buffer_cpumask)) {
882 rc = -EIO;
883 goto out;
884 }
885 /* Prepare parameter block. */
886 parm = iucv_param[smp_processor_id()];
887 memset(parm, 0, sizeof(union iucv_param));
888 parm->ctrl.ippathid = path->pathid;
889 parm->ctrl.ipmsglim = path->msglim;
890 if (userdata)
891 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
892 parm->ctrl.ipflags1 = path->flags;
893
894 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
895 if (!rc) {
896 path->private = private;
897 path->msglim = parm->ctrl.ipmsglim;
898 path->flags = parm->ctrl.ipflags1;
899 }
900out:
901 local_bh_enable();
902 return rc;
903}
904EXPORT_SYMBOL(iucv_path_accept);
905
906/**
907 * iucv_path_connect
908 * @path: address of iucv path structure
909 * @handler: address of iucv handler structure
910 * @userid: 8-byte user identification
911 * @system: 8-byte target system identification
912 * @userdata: 16 bytes of data reflected to the communication partner
913 * @private: private data passed to interrupt handlers for this path
914 *
915 * This function establishes an IUCV path. Although the connect may complete
916 * successfully, you are not able to use the path until you receive an IUCV
917 * Connection Complete external interrupt.
918 *
919 * Returns the result of the CP IUCV call.
920 */
921int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
922 u8 *userid, u8 *system, u8 *userdata,
923 void *private)
924{
925 union iucv_param *parm;
926 int rc;
927
928 spin_lock_bh(&iucv_table_lock);
929 iucv_cleanup_queue();
930 if (cpumask_empty(&iucv_buffer_cpumask)) {
931 rc = -EIO;
932 goto out;
933 }
934 parm = iucv_param[smp_processor_id()];
935 memset(parm, 0, sizeof(union iucv_param));
936 parm->ctrl.ipmsglim = path->msglim;
937 parm->ctrl.ipflags1 = path->flags;
938 if (userid) {
939 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
940 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
941 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
942 }
943 if (system) {
944 memcpy(parm->ctrl.iptarget, system,
945 sizeof(parm->ctrl.iptarget));
946 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
947 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
948 }
949 if (userdata)
950 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
951
952 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
953 if (!rc) {
954 if (parm->ctrl.ippathid < iucv_max_pathid) {
955 path->pathid = parm->ctrl.ippathid;
956 path->msglim = parm->ctrl.ipmsglim;
957 path->flags = parm->ctrl.ipflags1;
958 path->handler = handler;
959 path->private = private;
960 list_add_tail(&path->list, &handler->paths);
961 iucv_path_table[path->pathid] = path;
962 } else {
963 iucv_sever_pathid(parm->ctrl.ippathid,
964 iucv_error_pathid);
965 rc = -EIO;
966 }
967 }
968out:
969 spin_unlock_bh(&iucv_table_lock);
970 return rc;
971}
972EXPORT_SYMBOL(iucv_path_connect);
973
974/**
975 * iucv_path_quiesce:
976 * @path: address of iucv path structure
977 * @userdata: 16 bytes of data reflected to the communication partner
978 *
979 * This function temporarily suspends incoming messages on an IUCV path.
980 * You can later reactivate the path by invoking the iucv_resume function.
981 *
982 * Returns the result from the CP IUCV call.
983 */
984int iucv_path_quiesce(struct iucv_path *path, u8 *userdata)
985{
986 union iucv_param *parm;
987 int rc;
988
989 local_bh_disable();
990 if (cpumask_empty(&iucv_buffer_cpumask)) {
991 rc = -EIO;
992 goto out;
993 }
994 parm = iucv_param[smp_processor_id()];
995 memset(parm, 0, sizeof(union iucv_param));
996 if (userdata)
997 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
998 parm->ctrl.ippathid = path->pathid;
999 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
1000out:
1001 local_bh_enable();
1002 return rc;
1003}
1004EXPORT_SYMBOL(iucv_path_quiesce);
1005
1006/**
1007 * iucv_path_resume:
1008 * @path: address of iucv path structure
1009 * @userdata: 16 bytes of data reflected to the communication partner
1010 *
1011 * This function resumes incoming messages on an IUCV path that has
1012 * been stopped with iucv_path_quiesce.
1013 *
1014 * Returns the result from the CP IUCV call.
1015 */
1016int iucv_path_resume(struct iucv_path *path, u8 *userdata)
1017{
1018 union iucv_param *parm;
1019 int rc;
1020
1021 local_bh_disable();
1022 if (cpumask_empty(&iucv_buffer_cpumask)) {
1023 rc = -EIO;
1024 goto out;
1025 }
1026 parm = iucv_param[smp_processor_id()];
1027 memset(parm, 0, sizeof(union iucv_param));
1028 if (userdata)
1029 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
1030 parm->ctrl.ippathid = path->pathid;
1031 rc = iucv_call_b2f0(IUCV_RESUME, parm);
1032out:
1033 local_bh_enable();
1034 return rc;
1035}
1036
1037/**
1038 * iucv_path_sever
1039 * @path: address of iucv path structure
1040 * @userdata: 16 bytes of data reflected to the communication partner
1041 *
1042 * This function terminates an IUCV path.
1043 *
1044 * Returns the result from the CP IUCV call.
1045 */
1046int iucv_path_sever(struct iucv_path *path, u8 *userdata)
1047{
1048 int rc;
1049
1050 preempt_disable();
1051 if (cpumask_empty(&iucv_buffer_cpumask)) {
1052 rc = -EIO;
1053 goto out;
1054 }
1055 if (iucv_active_cpu != smp_processor_id())
1056 spin_lock_bh(&iucv_table_lock);
1057 rc = iucv_sever_pathid(path->pathid, userdata);
1058 iucv_path_table[path->pathid] = NULL;
1059 list_del_init(&path->list);
1060 if (iucv_active_cpu != smp_processor_id())
1061 spin_unlock_bh(&iucv_table_lock);
1062out:
1063 preempt_enable();
1064 return rc;
1065}
1066EXPORT_SYMBOL(iucv_path_sever);
1067
1068/**
1069 * iucv_message_purge
1070 * @path: address of iucv path structure
1071 * @msg: address of iucv msg structure
1072 * @srccls: source class of message
1073 *
1074 * Cancels a message you have sent.
1075 *
1076 * Returns the result from the CP IUCV call.
1077 */
1078int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
1079 u32 srccls)
1080{
1081 union iucv_param *parm;
1082 int rc;
1083
1084 local_bh_disable();
1085 if (cpumask_empty(&iucv_buffer_cpumask)) {
1086 rc = -EIO;
1087 goto out;
1088 }
1089 parm = iucv_param[smp_processor_id()];
1090 memset(parm, 0, sizeof(union iucv_param));
1091 parm->purge.ippathid = path->pathid;
1092 parm->purge.ipmsgid = msg->id;
1093 parm->purge.ipsrccls = srccls;
1094 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
1095 rc = iucv_call_b2f0(IUCV_PURGE, parm);
1096 if (!rc) {
1097 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
1098 msg->tag = parm->purge.ipmsgtag;
1099 }
1100out:
1101 local_bh_enable();
1102 return rc;
1103}
1104EXPORT_SYMBOL(iucv_message_purge);
1105
1106/**
1107 * iucv_message_receive_iprmdata
1108 * @path: address of iucv path structure
1109 * @msg: address of iucv msg structure
1110 * @flags: how the message is received (IUCV_IPBUFLST)
1111 * @buffer: address of data buffer or address of struct iucv_array
1112 * @size: length of data buffer
1113 * @residual:
1114 *
1115 * Internal function used by iucv_message_receive and __iucv_message_receive
1116 * to receive RMDATA data stored in struct iucv_message.
1117 */
1118static int iucv_message_receive_iprmdata(struct iucv_path *path,
1119 struct iucv_message *msg,
1120 u8 flags, void *buffer,
1121 size_t size, size_t *residual)
1122{
1123 struct iucv_array *array;
1124 u8 *rmmsg;
1125 size_t copy;
1126
1127 /*
1128 * Message is 8 bytes long and has been stored to the
1129 * message descriptor itself.
1130 */
1131 if (residual)
1132 *residual = abs(size - 8);
1133 rmmsg = msg->rmmsg;
1134 if (flags & IUCV_IPBUFLST) {
1135 /* Copy to struct iucv_array. */
1136 size = (size < 8) ? size : 8;
1137 for (array = buffer; size > 0; array++) {
1138 copy = min_t(size_t, size, array->length);
1139 memcpy(phys_to_virt(array->address), rmmsg, copy);
1140 rmmsg += copy;
1141 size -= copy;
1142 }
1143 } else {
1144 /* Copy to direct buffer. */
1145 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1146 }
1147 return 0;
1148}
1149
1150/**
1151 * __iucv_message_receive
1152 * @path: address of iucv path structure
1153 * @msg: address of iucv msg structure
1154 * @flags: how the message is received (IUCV_IPBUFLST)
1155 * @buffer: address of data buffer or address of struct iucv_array
1156 * @size: length of data buffer
1157 * @residual:
1158 *
1159 * This function receives messages that are being sent to you over
1160 * established paths. This function will deal with RMDATA messages
1161 * embedded in struct iucv_message as well.
1162 *
1163 * Locking: no locking
1164 *
1165 * Returns the result from the CP IUCV call.
1166 */
1167int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1168 u8 flags, void *buffer, size_t size, size_t *residual)
1169{
1170 union iucv_param *parm;
1171 int rc;
1172
1173 if (msg->flags & IUCV_IPRMDATA)
1174 return iucv_message_receive_iprmdata(path, msg, flags,
1175 buffer, size, residual);
1176 if (cpumask_empty(&iucv_buffer_cpumask)) {
1177 rc = -EIO;
1178 goto out;
1179 }
1180 parm = iucv_param[smp_processor_id()];
1181 memset(parm, 0, sizeof(union iucv_param));
1182 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1183 parm->db.ipbfln1f = (u32) size;
1184 parm->db.ipmsgid = msg->id;
1185 parm->db.ippathid = path->pathid;
1186 parm->db.iptrgcls = msg->class;
1187 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1188 IUCV_IPFGMID | IUCV_IPTRGCLS);
1189 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1190 if (!rc || rc == 5) {
1191 msg->flags = parm->db.ipflags1;
1192 if (residual)
1193 *residual = parm->db.ipbfln1f;
1194 }
1195out:
1196 return rc;
1197}
1198EXPORT_SYMBOL(__iucv_message_receive);
1199
1200/**
1201 * iucv_message_receive
1202 * @path: address of iucv path structure
1203 * @msg: address of iucv msg structure
1204 * @flags: how the message is received (IUCV_IPBUFLST)
1205 * @buffer: address of data buffer or address of struct iucv_array
1206 * @size: length of data buffer
1207 * @residual:
1208 *
1209 * This function receives messages that are being sent to you over
1210 * established paths. This function will deal with RMDATA messages
1211 * embedded in struct iucv_message as well.
1212 *
1213 * Locking: local_bh_enable/local_bh_disable
1214 *
1215 * Returns the result from the CP IUCV call.
1216 */
1217int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1218 u8 flags, void *buffer, size_t size, size_t *residual)
1219{
1220 int rc;
1221
1222 if (msg->flags & IUCV_IPRMDATA)
1223 return iucv_message_receive_iprmdata(path, msg, flags,
1224 buffer, size, residual);
1225 local_bh_disable();
1226 rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
1227 local_bh_enable();
1228 return rc;
1229}
1230EXPORT_SYMBOL(iucv_message_receive);
1231
1232/**
1233 * iucv_message_reject
1234 * @path: address of iucv path structure
1235 * @msg: address of iucv msg structure
1236 *
1237 * The reject function refuses a specified message. Between the time you
1238 * are notified of a message and the time that you complete the message,
1239 * the message may be rejected.
1240 *
1241 * Returns the result from the CP IUCV call.
1242 */
1243int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1244{
1245 union iucv_param *parm;
1246 int rc;
1247
1248 local_bh_disable();
1249 if (cpumask_empty(&iucv_buffer_cpumask)) {
1250 rc = -EIO;
1251 goto out;
1252 }
1253 parm = iucv_param[smp_processor_id()];
1254 memset(parm, 0, sizeof(union iucv_param));
1255 parm->db.ippathid = path->pathid;
1256 parm->db.ipmsgid = msg->id;
1257 parm->db.iptrgcls = msg->class;
1258 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1259 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1260out:
1261 local_bh_enable();
1262 return rc;
1263}
1264EXPORT_SYMBOL(iucv_message_reject);
1265
1266/**
1267 * iucv_message_reply
1268 * @path: address of iucv path structure
1269 * @msg: address of iucv msg structure
1270 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1271 * @reply: address of reply data buffer or address of struct iucv_array
1272 * @size: length of reply data buffer
1273 *
1274 * This function responds to the two-way messages that you receive. You
1275 * must identify completely the message to which you wish to reply. ie,
1276 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1277 * the parameter list.
1278 *
1279 * Returns the result from the CP IUCV call.
1280 */
1281int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1282 u8 flags, void *reply, size_t size)
1283{
1284 union iucv_param *parm;
1285 int rc;
1286
1287 local_bh_disable();
1288 if (cpumask_empty(&iucv_buffer_cpumask)) {
1289 rc = -EIO;
1290 goto out;
1291 }
1292 parm = iucv_param[smp_processor_id()];
1293 memset(parm, 0, sizeof(union iucv_param));
1294 if (flags & IUCV_IPRMDATA) {
1295 parm->dpl.ippathid = path->pathid;
1296 parm->dpl.ipflags1 = flags;
1297 parm->dpl.ipmsgid = msg->id;
1298 parm->dpl.iptrgcls = msg->class;
1299 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1300 } else {
1301 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1302 parm->db.ipbfln1f = (u32) size;
1303 parm->db.ippathid = path->pathid;
1304 parm->db.ipflags1 = flags;
1305 parm->db.ipmsgid = msg->id;
1306 parm->db.iptrgcls = msg->class;
1307 }
1308 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1309out:
1310 local_bh_enable();
1311 return rc;
1312}
1313EXPORT_SYMBOL(iucv_message_reply);
1314
1315/**
1316 * __iucv_message_send
1317 * @path: address of iucv path structure
1318 * @msg: address of iucv msg structure
1319 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1320 * @srccls: source class of message
1321 * @buffer: address of send buffer or address of struct iucv_array
1322 * @size: length of send buffer
1323 *
1324 * This function transmits data to another application. Data to be
1325 * transmitted is in a buffer and this is a one-way message and the
1326 * receiver will not reply to the message.
1327 *
1328 * Locking: no locking
1329 *
1330 * Returns the result from the CP IUCV call.
1331 */
1332int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1333 u8 flags, u32 srccls, void *buffer, size_t size)
1334{
1335 union iucv_param *parm;
1336 int rc;
1337
1338 if (cpumask_empty(&iucv_buffer_cpumask)) {
1339 rc = -EIO;
1340 goto out;
1341 }
1342 parm = iucv_param[smp_processor_id()];
1343 memset(parm, 0, sizeof(union iucv_param));
1344 if (flags & IUCV_IPRMDATA) {
1345 /* Message of 8 bytes can be placed into the parameter list. */
1346 parm->dpl.ippathid = path->pathid;
1347 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1348 parm->dpl.iptrgcls = msg->class;
1349 parm->dpl.ipsrccls = srccls;
1350 parm->dpl.ipmsgtag = msg->tag;
1351 memcpy(parm->dpl.iprmmsg, buffer, 8);
1352 } else {
1353 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1354 parm->db.ipbfln1f = (u32) size;
1355 parm->db.ippathid = path->pathid;
1356 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1357 parm->db.iptrgcls = msg->class;
1358 parm->db.ipsrccls = srccls;
1359 parm->db.ipmsgtag = msg->tag;
1360 }
1361 rc = iucv_call_b2f0(IUCV_SEND, parm);
1362 if (!rc)
1363 msg->id = parm->db.ipmsgid;
1364out:
1365 return rc;
1366}
1367EXPORT_SYMBOL(__iucv_message_send);
1368
1369/**
1370 * iucv_message_send
1371 * @path: address of iucv path structure
1372 * @msg: address of iucv msg structure
1373 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1374 * @srccls: source class of message
1375 * @buffer: address of send buffer or address of struct iucv_array
1376 * @size: length of send buffer
1377 *
1378 * This function transmits data to another application. Data to be
1379 * transmitted is in a buffer and this is a one-way message and the
1380 * receiver will not reply to the message.
1381 *
1382 * Locking: local_bh_enable/local_bh_disable
1383 *
1384 * Returns the result from the CP IUCV call.
1385 */
1386int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1387 u8 flags, u32 srccls, void *buffer, size_t size)
1388{
1389 int rc;
1390
1391 local_bh_disable();
1392 rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
1393 local_bh_enable();
1394 return rc;
1395}
1396EXPORT_SYMBOL(iucv_message_send);
1397
1398/**
1399 * iucv_message_send2way
1400 * @path: address of iucv path structure
1401 * @msg: address of iucv msg structure
1402 * @flags: how the message is sent and the reply is received
1403 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1404 * @srccls: source class of message
1405 * @buffer: address of send buffer or address of struct iucv_array
1406 * @size: length of send buffer
1407 * @ansbuf: address of answer buffer or address of struct iucv_array
1408 * @asize: size of reply buffer
1409 *
1410 * This function transmits data to another application. Data to be
1411 * transmitted is in a buffer. The receiver of the send is expected to
1412 * reply to the message and a buffer is provided into which IUCV moves
1413 * the reply to this message.
1414 *
1415 * Returns the result from the CP IUCV call.
1416 */
1417int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1418 u8 flags, u32 srccls, void *buffer, size_t size,
1419 void *answer, size_t asize, size_t *residual)
1420{
1421 union iucv_param *parm;
1422 int rc;
1423
1424 local_bh_disable();
1425 if (cpumask_empty(&iucv_buffer_cpumask)) {
1426 rc = -EIO;
1427 goto out;
1428 }
1429 parm = iucv_param[smp_processor_id()];
1430 memset(parm, 0, sizeof(union iucv_param));
1431 if (flags & IUCV_IPRMDATA) {
1432 parm->dpl.ippathid = path->pathid;
1433 parm->dpl.ipflags1 = path->flags; /* priority message */
1434 parm->dpl.iptrgcls = msg->class;
1435 parm->dpl.ipsrccls = srccls;
1436 parm->dpl.ipmsgtag = msg->tag;
1437 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1438 parm->dpl.ipbfln2f = (u32) asize;
1439 memcpy(parm->dpl.iprmmsg, buffer, 8);
1440 } else {
1441 parm->db.ippathid = path->pathid;
1442 parm->db.ipflags1 = path->flags; /* priority message */
1443 parm->db.iptrgcls = msg->class;
1444 parm->db.ipsrccls = srccls;
1445 parm->db.ipmsgtag = msg->tag;
1446 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1447 parm->db.ipbfln1f = (u32) size;
1448 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1449 parm->db.ipbfln2f = (u32) asize;
1450 }
1451 rc = iucv_call_b2f0(IUCV_SEND, parm);
1452 if (!rc)
1453 msg->id = parm->db.ipmsgid;
1454out:
1455 local_bh_enable();
1456 return rc;
1457}
1458EXPORT_SYMBOL(iucv_message_send2way);
1459
1460/**
1461 * iucv_path_pending
1462 * @data: Pointer to external interrupt buffer
1463 *
1464 * Process connection pending work item. Called from tasklet while holding
1465 * iucv_table_lock.
1466 */
1467struct iucv_path_pending {
1468 u16 ippathid;
1469 u8 ipflags1;
1470 u8 iptype;
1471 u16 ipmsglim;
1472 u16 res1;
1473 u8 ipvmid[8];
1474 u8 ipuser[16];
1475 u32 res3;
1476 u8 ippollfg;
1477 u8 res4[3];
1478} __packed;
1479
1480static void iucv_path_pending(struct iucv_irq_data *data)
1481{
1482 struct iucv_path_pending *ipp = (void *) data;
1483 struct iucv_handler *handler;
1484 struct iucv_path *path;
1485 char *error;
1486
1487 BUG_ON(iucv_path_table[ipp->ippathid]);
1488 /* New pathid, handler found. Create a new path struct. */
1489 error = iucv_error_no_memory;
1490 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1491 if (!path)
1492 goto out_sever;
1493 path->pathid = ipp->ippathid;
1494 iucv_path_table[path->pathid] = path;
1495 EBCASC(ipp->ipvmid, 8);
1496
1497 /* Call registered handler until one is found that wants the path. */
1498 list_for_each_entry(handler, &iucv_handler_list, list) {
1499 if (!handler->path_pending)
1500 continue;
1501 /*
1502 * Add path to handler to allow a call to iucv_path_sever
1503 * inside the path_pending function. If the handler returns
1504 * an error remove the path from the handler again.
1505 */
1506 list_add(&path->list, &handler->paths);
1507 path->handler = handler;
1508 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1509 return;
1510 list_del(&path->list);
1511 path->handler = NULL;
1512 }
1513 /* No handler wanted the path. */
1514 iucv_path_table[path->pathid] = NULL;
1515 iucv_path_free(path);
1516 error = iucv_error_no_listener;
1517out_sever:
1518 iucv_sever_pathid(ipp->ippathid, error);
1519}
1520
1521/**
1522 * iucv_path_complete
1523 * @data: Pointer to external interrupt buffer
1524 *
1525 * Process connection complete work item. Called from tasklet while holding
1526 * iucv_table_lock.
1527 */
1528struct iucv_path_complete {
1529 u16 ippathid;
1530 u8 ipflags1;
1531 u8 iptype;
1532 u16 ipmsglim;
1533 u16 res1;
1534 u8 res2[8];
1535 u8 ipuser[16];
1536 u32 res3;
1537 u8 ippollfg;
1538 u8 res4[3];
1539} __packed;
1540
1541static void iucv_path_complete(struct iucv_irq_data *data)
1542{
1543 struct iucv_path_complete *ipc = (void *) data;
1544 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1545
1546 if (path)
1547 path->flags = ipc->ipflags1;
1548 if (path && path->handler && path->handler->path_complete)
1549 path->handler->path_complete(path, ipc->ipuser);
1550}
1551
1552/**
1553 * iucv_path_severed
1554 * @data: Pointer to external interrupt buffer
1555 *
1556 * Process connection severed work item. Called from tasklet while holding
1557 * iucv_table_lock.
1558 */
1559struct iucv_path_severed {
1560 u16 ippathid;
1561 u8 res1;
1562 u8 iptype;
1563 u32 res2;
1564 u8 res3[8];
1565 u8 ipuser[16];
1566 u32 res4;
1567 u8 ippollfg;
1568 u8 res5[3];
1569} __packed;
1570
1571static void iucv_path_severed(struct iucv_irq_data *data)
1572{
1573 struct iucv_path_severed *ips = (void *) data;
1574 struct iucv_path *path = iucv_path_table[ips->ippathid];
1575
1576 if (!path || !path->handler) /* Already severed */
1577 return;
1578 if (path->handler->path_severed)
1579 path->handler->path_severed(path, ips->ipuser);
1580 else {
1581 iucv_sever_pathid(path->pathid, NULL);
1582 iucv_path_table[path->pathid] = NULL;
1583 list_del(&path->list);
1584 iucv_path_free(path);
1585 }
1586}
1587
1588/**
1589 * iucv_path_quiesced
1590 * @data: Pointer to external interrupt buffer
1591 *
1592 * Process connection quiesced work item. Called from tasklet while holding
1593 * iucv_table_lock.
1594 */
1595struct iucv_path_quiesced {
1596 u16 ippathid;
1597 u8 res1;
1598 u8 iptype;
1599 u32 res2;
1600 u8 res3[8];
1601 u8 ipuser[16];
1602 u32 res4;
1603 u8 ippollfg;
1604 u8 res5[3];
1605} __packed;
1606
1607static void iucv_path_quiesced(struct iucv_irq_data *data)
1608{
1609 struct iucv_path_quiesced *ipq = (void *) data;
1610 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1611
1612 if (path && path->handler && path->handler->path_quiesced)
1613 path->handler->path_quiesced(path, ipq->ipuser);
1614}
1615
1616/**
1617 * iucv_path_resumed
1618 * @data: Pointer to external interrupt buffer
1619 *
1620 * Process connection resumed work item. Called from tasklet while holding
1621 * iucv_table_lock.
1622 */
1623struct iucv_path_resumed {
1624 u16 ippathid;
1625 u8 res1;
1626 u8 iptype;
1627 u32 res2;
1628 u8 res3[8];
1629 u8 ipuser[16];
1630 u32 res4;
1631 u8 ippollfg;
1632 u8 res5[3];
1633} __packed;
1634
1635static void iucv_path_resumed(struct iucv_irq_data *data)
1636{
1637 struct iucv_path_resumed *ipr = (void *) data;
1638 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1639
1640 if (path && path->handler && path->handler->path_resumed)
1641 path->handler->path_resumed(path, ipr->ipuser);
1642}
1643
1644/**
1645 * iucv_message_complete
1646 * @data: Pointer to external interrupt buffer
1647 *
1648 * Process message complete work item. Called from tasklet while holding
1649 * iucv_table_lock.
1650 */
1651struct iucv_message_complete {
1652 u16 ippathid;
1653 u8 ipflags1;
1654 u8 iptype;
1655 u32 ipmsgid;
1656 u32 ipaudit;
1657 u8 iprmmsg[8];
1658 u32 ipsrccls;
1659 u32 ipmsgtag;
1660 u32 res;
1661 u32 ipbfln2f;
1662 u8 ippollfg;
1663 u8 res2[3];
1664} __packed;
1665
1666static void iucv_message_complete(struct iucv_irq_data *data)
1667{
1668 struct iucv_message_complete *imc = (void *) data;
1669 struct iucv_path *path = iucv_path_table[imc->ippathid];
1670 struct iucv_message msg;
1671
1672 if (path && path->handler && path->handler->message_complete) {
1673 msg.flags = imc->ipflags1;
1674 msg.id = imc->ipmsgid;
1675 msg.audit = imc->ipaudit;
1676 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1677 msg.class = imc->ipsrccls;
1678 msg.tag = imc->ipmsgtag;
1679 msg.length = imc->ipbfln2f;
1680 path->handler->message_complete(path, &msg);
1681 }
1682}
1683
1684/**
1685 * iucv_message_pending
1686 * @data: Pointer to external interrupt buffer
1687 *
1688 * Process message pending work item. Called from tasklet while holding
1689 * iucv_table_lock.
1690 */
1691struct iucv_message_pending {
1692 u16 ippathid;
1693 u8 ipflags1;
1694 u8 iptype;
1695 u32 ipmsgid;
1696 u32 iptrgcls;
1697 union {
1698 u32 iprmmsg1_u32;
1699 u8 iprmmsg1[4];
1700 } ln1msg1;
1701 union {
1702 u32 ipbfln1f;
1703 u8 iprmmsg2[4];
1704 } ln1msg2;
1705 u32 res1[3];
1706 u32 ipbfln2f;
1707 u8 ippollfg;
1708 u8 res2[3];
1709} __packed;
1710
1711static void iucv_message_pending(struct iucv_irq_data *data)
1712{
1713 struct iucv_message_pending *imp = (void *) data;
1714 struct iucv_path *path = iucv_path_table[imp->ippathid];
1715 struct iucv_message msg;
1716
1717 if (path && path->handler && path->handler->message_pending) {
1718 msg.flags = imp->ipflags1;
1719 msg.id = imp->ipmsgid;
1720 msg.class = imp->iptrgcls;
1721 if (imp->ipflags1 & IUCV_IPRMDATA) {
1722 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1723 msg.length = 8;
1724 } else
1725 msg.length = imp->ln1msg2.ipbfln1f;
1726 msg.reply_size = imp->ipbfln2f;
1727 path->handler->message_pending(path, &msg);
1728 }
1729}
1730
1731/**
1732 * iucv_tasklet_fn:
1733 *
1734 * This tasklet loops over the queue of irq buffers created by
1735 * iucv_external_interrupt, calls the appropriate action handler
1736 * and then frees the buffer.
1737 */
1738static void iucv_tasklet_fn(unsigned long ignored)
1739{
1740 typedef void iucv_irq_fn(struct iucv_irq_data *);
1741 static iucv_irq_fn *irq_fn[] = {
1742 [0x02] = iucv_path_complete,
1743 [0x03] = iucv_path_severed,
1744 [0x04] = iucv_path_quiesced,
1745 [0x05] = iucv_path_resumed,
1746 [0x06] = iucv_message_complete,
1747 [0x07] = iucv_message_complete,
1748 [0x08] = iucv_message_pending,
1749 [0x09] = iucv_message_pending,
1750 };
1751 LIST_HEAD(task_queue);
1752 struct iucv_irq_list *p, *n;
1753
1754 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1755 if (!spin_trylock(&iucv_table_lock)) {
1756 tasklet_schedule(&iucv_tasklet);
1757 return;
1758 }
1759 iucv_active_cpu = smp_processor_id();
1760
1761 spin_lock_irq(&iucv_queue_lock);
1762 list_splice_init(&iucv_task_queue, &task_queue);
1763 spin_unlock_irq(&iucv_queue_lock);
1764
1765 list_for_each_entry_safe(p, n, &task_queue, list) {
1766 list_del_init(&p->list);
1767 irq_fn[p->data.iptype](&p->data);
1768 kfree(p);
1769 }
1770
1771 iucv_active_cpu = -1;
1772 spin_unlock(&iucv_table_lock);
1773}
1774
1775/**
1776 * iucv_work_fn:
1777 *
1778 * This work function loops over the queue of path pending irq blocks
1779 * created by iucv_external_interrupt, calls the appropriate action
1780 * handler and then frees the buffer.
1781 */
1782static void iucv_work_fn(struct work_struct *work)
1783{
1784 LIST_HEAD(work_queue);
1785 struct iucv_irq_list *p, *n;
1786
1787 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1788 spin_lock_bh(&iucv_table_lock);
1789 iucv_active_cpu = smp_processor_id();
1790
1791 spin_lock_irq(&iucv_queue_lock);
1792 list_splice_init(&iucv_work_queue, &work_queue);
1793 spin_unlock_irq(&iucv_queue_lock);
1794
1795 iucv_cleanup_queue();
1796 list_for_each_entry_safe(p, n, &work_queue, list) {
1797 list_del_init(&p->list);
1798 iucv_path_pending(&p->data);
1799 kfree(p);
1800 }
1801
1802 iucv_active_cpu = -1;
1803 spin_unlock_bh(&iucv_table_lock);
1804}
1805
1806/**
1807 * iucv_external_interrupt
1808 * @code: irq code
1809 *
1810 * Handles external interrupts coming in from CP.
1811 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1812 */
1813static void iucv_external_interrupt(struct ext_code ext_code,
1814 unsigned int param32, unsigned long param64)
1815{
1816 struct iucv_irq_data *p;
1817 struct iucv_irq_list *work;
1818
1819 inc_irq_stat(IRQEXT_IUC);
1820 p = iucv_irq_data[smp_processor_id()];
1821 if (p->ippathid >= iucv_max_pathid) {
1822 WARN_ON(p->ippathid >= iucv_max_pathid);
1823 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1824 return;
1825 }
1826 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
1827 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1828 if (!work) {
1829 pr_warn("iucv_external_interrupt: out of memory\n");
1830 return;
1831 }
1832 memcpy(&work->data, p, sizeof(work->data));
1833 spin_lock(&iucv_queue_lock);
1834 if (p->iptype == 0x01) {
1835 /* Path pending interrupt. */
1836 list_add_tail(&work->list, &iucv_work_queue);
1837 schedule_work(&iucv_work);
1838 } else {
1839 /* The other interrupts. */
1840 list_add_tail(&work->list, &iucv_task_queue);
1841 tasklet_schedule(&iucv_tasklet);
1842 }
1843 spin_unlock(&iucv_queue_lock);
1844}
1845
1846static int iucv_pm_prepare(struct device *dev)
1847{
1848 int rc = 0;
1849
1850#ifdef CONFIG_PM_DEBUG
1851 printk(KERN_INFO "iucv_pm_prepare\n");
1852#endif
1853 if (dev->driver && dev->driver->pm && dev->driver->pm->prepare)
1854 rc = dev->driver->pm->prepare(dev);
1855 return rc;
1856}
1857
1858static void iucv_pm_complete(struct device *dev)
1859{
1860#ifdef CONFIG_PM_DEBUG
1861 printk(KERN_INFO "iucv_pm_complete\n");
1862#endif
1863 if (dev->driver && dev->driver->pm && dev->driver->pm->complete)
1864 dev->driver->pm->complete(dev);
1865}
1866
1867/**
1868 * iucv_path_table_empty() - determine if iucv path table is empty
1869 *
1870 * Returns 0 if there are still iucv pathes defined
1871 * 1 if there are no iucv pathes defined
1872 */
1873static int iucv_path_table_empty(void)
1874{
1875 int i;
1876
1877 for (i = 0; i < iucv_max_pathid; i++) {
1878 if (iucv_path_table[i])
1879 return 0;
1880 }
1881 return 1;
1882}
1883
1884/**
1885 * iucv_pm_freeze() - Freeze PM callback
1886 * @dev: iucv-based device
1887 *
1888 * disable iucv interrupts
1889 * invoke callback function of the iucv-based driver
1890 * shut down iucv, if no iucv-pathes are established anymore
1891 */
1892static int iucv_pm_freeze(struct device *dev)
1893{
1894 int cpu;
1895 struct iucv_irq_list *p, *n;
1896 int rc = 0;
1897
1898#ifdef CONFIG_PM_DEBUG
1899 printk(KERN_WARNING "iucv_pm_freeze\n");
1900#endif
1901 if (iucv_pm_state != IUCV_PM_FREEZING) {
1902 for_each_cpu(cpu, &iucv_irq_cpumask)
1903 smp_call_function_single(cpu, iucv_block_cpu_almost,
1904 NULL, 1);
1905 cancel_work_sync(&iucv_work);
1906 list_for_each_entry_safe(p, n, &iucv_work_queue, list) {
1907 list_del_init(&p->list);
1908 iucv_sever_pathid(p->data.ippathid,
1909 iucv_error_no_listener);
1910 kfree(p);
1911 }
1912 }
1913 iucv_pm_state = IUCV_PM_FREEZING;
1914 if (dev->driver && dev->driver->pm && dev->driver->pm->freeze)
1915 rc = dev->driver->pm->freeze(dev);
1916 if (iucv_path_table_empty())
1917 iucv_disable();
1918 return rc;
1919}
1920
1921/**
1922 * iucv_pm_thaw() - Thaw PM callback
1923 * @dev: iucv-based device
1924 *
1925 * make iucv ready for use again: allocate path table, declare interrupt buffers
1926 * and enable iucv interrupts
1927 * invoke callback function of the iucv-based driver
1928 */
1929static int iucv_pm_thaw(struct device *dev)
1930{
1931 int rc = 0;
1932
1933#ifdef CONFIG_PM_DEBUG
1934 printk(KERN_WARNING "iucv_pm_thaw\n");
1935#endif
1936 iucv_pm_state = IUCV_PM_THAWING;
1937 if (!iucv_path_table) {
1938 rc = iucv_enable();
1939 if (rc)
1940 goto out;
1941 }
1942 if (cpumask_empty(&iucv_irq_cpumask)) {
1943 if (iucv_nonsmp_handler)
1944 /* enable interrupts on one cpu */
1945 iucv_allow_cpu(NULL);
1946 else
1947 /* enable interrupts on all cpus */
1948 iucv_setmask_mp();
1949 }
1950 if (dev->driver && dev->driver->pm && dev->driver->pm->thaw)
1951 rc = dev->driver->pm->thaw(dev);
1952out:
1953 return rc;
1954}
1955
1956/**
1957 * iucv_pm_restore() - Restore PM callback
1958 * @dev: iucv-based device
1959 *
1960 * make iucv ready for use again: allocate path table, declare interrupt buffers
1961 * and enable iucv interrupts
1962 * invoke callback function of the iucv-based driver
1963 */
1964static int iucv_pm_restore(struct device *dev)
1965{
1966 int rc = 0;
1967
1968#ifdef CONFIG_PM_DEBUG
1969 printk(KERN_WARNING "iucv_pm_restore %p\n", iucv_path_table);
1970#endif
1971 if ((iucv_pm_state != IUCV_PM_RESTORING) && iucv_path_table)
1972 pr_warn("Suspending Linux did not completely close all IUCV connections\n");
1973 iucv_pm_state = IUCV_PM_RESTORING;
1974 if (cpumask_empty(&iucv_irq_cpumask)) {
1975 rc = iucv_query_maxconn();
1976 rc = iucv_enable();
1977 if (rc)
1978 goto out;
1979 }
1980 if (dev->driver && dev->driver->pm && dev->driver->pm->restore)
1981 rc = dev->driver->pm->restore(dev);
1982out:
1983 return rc;
1984}
1985
1986struct iucv_interface iucv_if = {
1987 .message_receive = iucv_message_receive,
1988 .__message_receive = __iucv_message_receive,
1989 .message_reply = iucv_message_reply,
1990 .message_reject = iucv_message_reject,
1991 .message_send = iucv_message_send,
1992 .__message_send = __iucv_message_send,
1993 .message_send2way = iucv_message_send2way,
1994 .message_purge = iucv_message_purge,
1995 .path_accept = iucv_path_accept,
1996 .path_connect = iucv_path_connect,
1997 .path_quiesce = iucv_path_quiesce,
1998 .path_resume = iucv_path_resume,
1999 .path_sever = iucv_path_sever,
2000 .iucv_register = iucv_register,
2001 .iucv_unregister = iucv_unregister,
2002 .bus = NULL,
2003 .root = NULL,
2004};
2005EXPORT_SYMBOL(iucv_if);
2006
2007static enum cpuhp_state iucv_online;
2008/**
2009 * iucv_init
2010 *
2011 * Allocates and initializes various data structures.
2012 */
2013static int __init iucv_init(void)
2014{
2015 int rc;
2016
2017 if (!MACHINE_IS_VM) {
2018 rc = -EPROTONOSUPPORT;
2019 goto out;
2020 }
2021 ctl_set_bit(0, 1);
2022 rc = iucv_query_maxconn();
2023 if (rc)
2024 goto out_ctl;
2025 rc = register_external_irq(EXT_IRQ_IUCV, iucv_external_interrupt);
2026 if (rc)
2027 goto out_ctl;
2028 iucv_root = root_device_register("iucv");
2029 if (IS_ERR(iucv_root)) {
2030 rc = PTR_ERR(iucv_root);
2031 goto out_int;
2032 }
2033
2034 rc = cpuhp_setup_state(CPUHP_NET_IUCV_PREPARE, "net/iucv:prepare",
2035 iucv_cpu_prepare, iucv_cpu_dead);
2036 if (rc)
2037 goto out_dev;
2038 rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "net/iucv:online",
2039 iucv_cpu_online, iucv_cpu_down_prep);
2040 if (rc < 0)
2041 goto out_prep;
2042 iucv_online = rc;
2043
2044 rc = register_reboot_notifier(&iucv_reboot_notifier);
2045 if (rc)
2046 goto out_remove_hp;
2047 ASCEBC(iucv_error_no_listener, 16);
2048 ASCEBC(iucv_error_no_memory, 16);
2049 ASCEBC(iucv_error_pathid, 16);
2050 iucv_available = 1;
2051 rc = bus_register(&iucv_bus);
2052 if (rc)
2053 goto out_reboot;
2054 iucv_if.root = iucv_root;
2055 iucv_if.bus = &iucv_bus;
2056 return 0;
2057
2058out_reboot:
2059 unregister_reboot_notifier(&iucv_reboot_notifier);
2060out_remove_hp:
2061 cpuhp_remove_state(iucv_online);
2062out_prep:
2063 cpuhp_remove_state(CPUHP_NET_IUCV_PREPARE);
2064out_dev:
2065 root_device_unregister(iucv_root);
2066out_int:
2067 unregister_external_irq(EXT_IRQ_IUCV, iucv_external_interrupt);
2068out_ctl:
2069 ctl_clear_bit(0, 1);
2070out:
2071 return rc;
2072}
2073
2074/**
2075 * iucv_exit
2076 *
2077 * Frees everything allocated from iucv_init.
2078 */
2079static void __exit iucv_exit(void)
2080{
2081 struct iucv_irq_list *p, *n;
2082
2083 spin_lock_irq(&iucv_queue_lock);
2084 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
2085 kfree(p);
2086 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
2087 kfree(p);
2088 spin_unlock_irq(&iucv_queue_lock);
2089 unregister_reboot_notifier(&iucv_reboot_notifier);
2090
2091 cpuhp_remove_state_nocalls(iucv_online);
2092 cpuhp_remove_state(CPUHP_NET_IUCV_PREPARE);
2093 root_device_unregister(iucv_root);
2094 bus_unregister(&iucv_bus);
2095 unregister_external_irq(EXT_IRQ_IUCV, iucv_external_interrupt);
2096}
2097
2098subsys_initcall(iucv_init);
2099module_exit(iucv_exit);
2100
2101MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
2102MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
2103MODULE_LICENSE("GPL");