ACPI: make acpi_pci_bind() static
[linux-2.6/linux-acpi-2.6.git] / net / iucv / iucv.c
bloba35240f61ec3bad362fed2da6378920b3f4fcd99
1 /*
2 * IUCV base infrastructure.
4 * Copyright 2001, 2006 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s):
6 * Original source:
7 * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
8 * Xenia Tkatschow (xenia@us.ibm.com)
9 * 2Gb awareness and general cleanup:
10 * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
11 * Rewritten for af_iucv:
12 * Martin Schwidefsky <schwidefsky@de.ibm.com>
14 * Documentation used:
15 * The original source
16 * CP Programming Service, IBM document # SC24-5760
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.
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.
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.
33 #define KMSG_COMPONENT "iucv"
34 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
36 #include <linux/module.h>
37 #include <linux/moduleparam.h>
38 #include <linux/spinlock.h>
39 #include <linux/kernel.h>
40 #include <linux/slab.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/list.h>
44 #include <linux/errno.h>
45 #include <linux/err.h>
46 #include <linux/device.h>
47 #include <linux/cpu.h>
48 #include <net/iucv/iucv.h>
49 #include <asm/atomic.h>
50 #include <asm/ebcdic.h>
51 #include <asm/io.h>
52 #include <asm/s390_ext.h>
53 #include <asm/smp.h>
56 * FLAGS:
57 * All flags are defined in the field IPFLAGS1 of each function
58 * and can be found in CP Programming Services.
59 * IPSRCCLS - Indicates you have specified a source class.
60 * IPTRGCLS - Indicates you have specified a target class.
61 * IPFGPID - Indicates you have specified a pathid.
62 * IPFGMID - Indicates you have specified a message ID.
63 * IPNORPY - Indicates a one-way message. No reply expected.
64 * IPALL - Indicates that all paths are affected.
66 #define IUCV_IPSRCCLS 0x01
67 #define IUCV_IPTRGCLS 0x01
68 #define IUCV_IPFGPID 0x02
69 #define IUCV_IPFGMID 0x04
70 #define IUCV_IPNORPY 0x10
71 #define IUCV_IPALL 0x80
73 static int iucv_bus_match(struct device *dev, struct device_driver *drv)
75 return 0;
78 struct bus_type iucv_bus = {
79 .name = "iucv",
80 .match = iucv_bus_match,
82 EXPORT_SYMBOL(iucv_bus);
84 struct device *iucv_root;
85 EXPORT_SYMBOL(iucv_root);
87 static int iucv_available;
89 /* General IUCV interrupt structure */
90 struct iucv_irq_data {
91 u16 ippathid;
92 u8 ipflags1;
93 u8 iptype;
94 u32 res2[8];
97 struct iucv_irq_list {
98 struct list_head list;
99 struct iucv_irq_data data;
102 static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
103 static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
104 static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
107 * Queue of interrupt buffers lock for delivery via the tasklet
108 * (fast but can't call smp_call_function).
110 static LIST_HEAD(iucv_task_queue);
113 * The tasklet for fast delivery of iucv interrupts.
115 static void iucv_tasklet_fn(unsigned long);
116 static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
119 * Queue of interrupt buffers for delivery via a work queue
120 * (slower but can call smp_call_function).
122 static LIST_HEAD(iucv_work_queue);
125 * The work element to deliver path pending interrupts.
127 static void iucv_work_fn(struct work_struct *work);
128 static DECLARE_WORK(iucv_work, iucv_work_fn);
131 * Spinlock protecting task and work queue.
133 static DEFINE_SPINLOCK(iucv_queue_lock);
135 enum iucv_command_codes {
136 IUCV_QUERY = 0,
137 IUCV_RETRIEVE_BUFFER = 2,
138 IUCV_SEND = 4,
139 IUCV_RECEIVE = 5,
140 IUCV_REPLY = 6,
141 IUCV_REJECT = 8,
142 IUCV_PURGE = 9,
143 IUCV_ACCEPT = 10,
144 IUCV_CONNECT = 11,
145 IUCV_DECLARE_BUFFER = 12,
146 IUCV_QUIESCE = 13,
147 IUCV_RESUME = 14,
148 IUCV_SEVER = 15,
149 IUCV_SETMASK = 16,
153 * Error messages that are used with the iucv_sever function. They get
154 * converted to EBCDIC.
156 static char iucv_error_no_listener[16] = "NO LISTENER";
157 static char iucv_error_no_memory[16] = "NO MEMORY";
158 static char iucv_error_pathid[16] = "INVALID PATHID";
161 * iucv_handler_list: List of registered handlers.
163 static LIST_HEAD(iucv_handler_list);
166 * iucv_path_table: an array of iucv_path structures.
168 static struct iucv_path **iucv_path_table;
169 static unsigned long iucv_max_pathid;
172 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
174 static DEFINE_SPINLOCK(iucv_table_lock);
177 * iucv_active_cpu: contains the number of the cpu executing the tasklet
178 * or the work handler. Needed for iucv_path_sever called from tasklet.
180 static int iucv_active_cpu = -1;
183 * Mutex and wait queue for iucv_register/iucv_unregister.
185 static DEFINE_MUTEX(iucv_register_mutex);
188 * Counter for number of non-smp capable handlers.
190 static int iucv_nonsmp_handler;
193 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
194 * iucv_path_quiesce and iucv_path_sever.
196 struct iucv_cmd_control {
197 u16 ippathid;
198 u8 ipflags1;
199 u8 iprcode;
200 u16 ipmsglim;
201 u16 res1;
202 u8 ipvmid[8];
203 u8 ipuser[16];
204 u8 iptarget[8];
205 } __attribute__ ((packed,aligned(8)));
208 * Data in parameter list iucv structure. Used by iucv_message_send,
209 * iucv_message_send2way and iucv_message_reply.
211 struct iucv_cmd_dpl {
212 u16 ippathid;
213 u8 ipflags1;
214 u8 iprcode;
215 u32 ipmsgid;
216 u32 iptrgcls;
217 u8 iprmmsg[8];
218 u32 ipsrccls;
219 u32 ipmsgtag;
220 u32 ipbfadr2;
221 u32 ipbfln2f;
222 u32 res;
223 } __attribute__ ((packed,aligned(8)));
226 * Data in buffer iucv structure. Used by iucv_message_receive,
227 * iucv_message_reject, iucv_message_send, iucv_message_send2way
228 * and iucv_declare_cpu.
230 struct iucv_cmd_db {
231 u16 ippathid;
232 u8 ipflags1;
233 u8 iprcode;
234 u32 ipmsgid;
235 u32 iptrgcls;
236 u32 ipbfadr1;
237 u32 ipbfln1f;
238 u32 ipsrccls;
239 u32 ipmsgtag;
240 u32 ipbfadr2;
241 u32 ipbfln2f;
242 u32 res;
243 } __attribute__ ((packed,aligned(8)));
246 * Purge message iucv structure. Used by iucv_message_purge.
248 struct iucv_cmd_purge {
249 u16 ippathid;
250 u8 ipflags1;
251 u8 iprcode;
252 u32 ipmsgid;
253 u8 ipaudit[3];
254 u8 res1[5];
255 u32 res2;
256 u32 ipsrccls;
257 u32 ipmsgtag;
258 u32 res3[3];
259 } __attribute__ ((packed,aligned(8)));
262 * Set mask iucv structure. Used by iucv_enable_cpu.
264 struct iucv_cmd_set_mask {
265 u8 ipmask;
266 u8 res1[2];
267 u8 iprcode;
268 u32 res2[9];
269 } __attribute__ ((packed,aligned(8)));
271 union iucv_param {
272 struct iucv_cmd_control ctrl;
273 struct iucv_cmd_dpl dpl;
274 struct iucv_cmd_db db;
275 struct iucv_cmd_purge purge;
276 struct iucv_cmd_set_mask set_mask;
280 * Anchor for per-cpu IUCV command parameter block.
282 static union iucv_param *iucv_param[NR_CPUS];
285 * iucv_call_b2f0
286 * @code: identifier of IUCV call to CP.
287 * @parm: pointer to a struct iucv_parm block
289 * Calls CP to execute IUCV commands.
291 * Returns the result of the CP IUCV call.
293 static inline int iucv_call_b2f0(int command, union iucv_param *parm)
295 register unsigned long reg0 asm ("0");
296 register unsigned long reg1 asm ("1");
297 int ccode;
299 reg0 = command;
300 reg1 = virt_to_phys(parm);
301 asm volatile(
302 " .long 0xb2f01000\n"
303 " ipm %0\n"
304 " srl %0,28\n"
305 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
306 : "m" (*parm) : "cc");
307 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
311 * iucv_query_maxconn
313 * Determines the maximum number of connections that may be established.
315 * Returns the maximum number of connections or -EPERM is IUCV is not
316 * available.
318 static int iucv_query_maxconn(void)
320 register unsigned long reg0 asm ("0");
321 register unsigned long reg1 asm ("1");
322 void *param;
323 int ccode;
325 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
326 if (!param)
327 return -ENOMEM;
328 reg0 = IUCV_QUERY;
329 reg1 = (unsigned long) param;
330 asm volatile (
331 " .long 0xb2f01000\n"
332 " ipm %0\n"
333 " srl %0,28\n"
334 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
335 if (ccode == 0)
336 iucv_max_pathid = reg0;
337 kfree(param);
338 return ccode ? -EPERM : 0;
342 * iucv_allow_cpu
343 * @data: unused
345 * Allow iucv interrupts on this cpu.
347 static void iucv_allow_cpu(void *data)
349 int cpu = smp_processor_id();
350 union iucv_param *parm;
353 * Enable all iucv interrupts.
354 * ipmask contains bits for the different interrupts
355 * 0x80 - Flag to allow nonpriority message pending interrupts
356 * 0x40 - Flag to allow priority message pending interrupts
357 * 0x20 - Flag to allow nonpriority message completion interrupts
358 * 0x10 - Flag to allow priority message completion interrupts
359 * 0x08 - Flag to allow IUCV control interrupts
361 parm = iucv_param[cpu];
362 memset(parm, 0, sizeof(union iucv_param));
363 parm->set_mask.ipmask = 0xf8;
364 iucv_call_b2f0(IUCV_SETMASK, parm);
366 /* Set indication that iucv interrupts are allowed for this cpu. */
367 cpu_set(cpu, iucv_irq_cpumask);
371 * iucv_block_cpu
372 * @data: unused
374 * Block iucv interrupts on this cpu.
376 static void iucv_block_cpu(void *data)
378 int cpu = smp_processor_id();
379 union iucv_param *parm;
381 /* Disable all iucv interrupts. */
382 parm = iucv_param[cpu];
383 memset(parm, 0, sizeof(union iucv_param));
384 iucv_call_b2f0(IUCV_SETMASK, parm);
386 /* Clear indication that iucv interrupts are allowed for this cpu. */
387 cpu_clear(cpu, iucv_irq_cpumask);
391 * iucv_declare_cpu
392 * @data: unused
394 * Declare a interrupt buffer on this cpu.
396 static void iucv_declare_cpu(void *data)
398 int cpu = smp_processor_id();
399 union iucv_param *parm;
400 int rc;
402 if (cpu_isset(cpu, iucv_buffer_cpumask))
403 return;
405 /* Declare interrupt buffer. */
406 parm = iucv_param[cpu];
407 memset(parm, 0, sizeof(union iucv_param));
408 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
409 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
410 if (rc) {
411 char *err = "Unknown";
412 switch (rc) {
413 case 0x03:
414 err = "Directory error";
415 break;
416 case 0x0a:
417 err = "Invalid length";
418 break;
419 case 0x13:
420 err = "Buffer already exists";
421 break;
422 case 0x3e:
423 err = "Buffer overlap";
424 break;
425 case 0x5c:
426 err = "Paging or storage error";
427 break;
429 pr_warning("Defining an interrupt buffer on CPU %i"
430 " failed with 0x%02x (%s)\n", cpu, rc, err);
431 return;
434 /* Set indication that an iucv buffer exists for this cpu. */
435 cpu_set(cpu, iucv_buffer_cpumask);
437 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
438 /* Enable iucv interrupts on this cpu. */
439 iucv_allow_cpu(NULL);
440 else
441 /* Disable iucv interrupts on this cpu. */
442 iucv_block_cpu(NULL);
446 * iucv_retrieve_cpu
447 * @data: unused
449 * Retrieve interrupt buffer on this cpu.
451 static void iucv_retrieve_cpu(void *data)
453 int cpu = smp_processor_id();
454 union iucv_param *parm;
456 if (!cpu_isset(cpu, iucv_buffer_cpumask))
457 return;
459 /* Block iucv interrupts. */
460 iucv_block_cpu(NULL);
462 /* Retrieve interrupt buffer. */
463 parm = iucv_param[cpu];
464 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
466 /* Clear indication that an iucv buffer exists for this cpu. */
467 cpu_clear(cpu, iucv_buffer_cpumask);
471 * iucv_setmask_smp
473 * Allow iucv interrupts on all cpus.
475 static void iucv_setmask_mp(void)
477 int cpu;
479 get_online_cpus();
480 for_each_online_cpu(cpu)
481 /* Enable all cpus with a declared buffer. */
482 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
483 !cpu_isset(cpu, iucv_irq_cpumask))
484 smp_call_function_single(cpu, iucv_allow_cpu,
485 NULL, 1);
486 put_online_cpus();
490 * iucv_setmask_up
492 * Allow iucv interrupts on a single cpu.
494 static void iucv_setmask_up(void)
496 cpumask_t cpumask;
497 int cpu;
499 /* Disable all cpu but the first in cpu_irq_cpumask. */
500 cpumask = iucv_irq_cpumask;
501 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
502 for_each_cpu_mask_nr(cpu, cpumask)
503 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
507 * iucv_enable
509 * This function makes iucv ready for use. It allocates the pathid
510 * table, declares an iucv interrupt buffer and enables the iucv
511 * interrupts. Called when the first user has registered an iucv
512 * handler.
514 static int iucv_enable(void)
516 size_t alloc_size;
517 int cpu, rc;
519 get_online_cpus();
520 rc = -ENOMEM;
521 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
522 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
523 if (!iucv_path_table)
524 goto out;
525 /* Declare per cpu buffers. */
526 rc = -EIO;
527 for_each_online_cpu(cpu)
528 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
529 if (cpus_empty(iucv_buffer_cpumask))
530 /* No cpu could declare an iucv buffer. */
531 goto out;
532 put_online_cpus();
533 return 0;
534 out:
535 kfree(iucv_path_table);
536 iucv_path_table = NULL;
537 put_online_cpus();
538 return rc;
542 * iucv_disable
544 * This function shuts down iucv. It disables iucv interrupts, retrieves
545 * the iucv interrupt buffer and frees the pathid table. Called after the
546 * last user unregister its iucv handler.
548 static void iucv_disable(void)
550 get_online_cpus();
551 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
552 kfree(iucv_path_table);
553 iucv_path_table = NULL;
554 put_online_cpus();
557 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
558 unsigned long action, void *hcpu)
560 cpumask_t cpumask;
561 long cpu = (long) hcpu;
563 switch (action) {
564 case CPU_UP_PREPARE:
565 case CPU_UP_PREPARE_FROZEN:
566 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
567 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
568 if (!iucv_irq_data[cpu])
569 return NOTIFY_BAD;
570 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
571 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
572 if (!iucv_param[cpu]) {
573 kfree(iucv_irq_data[cpu]);
574 iucv_irq_data[cpu] = NULL;
575 return NOTIFY_BAD;
577 break;
578 case CPU_UP_CANCELED:
579 case CPU_UP_CANCELED_FROZEN:
580 case CPU_DEAD:
581 case CPU_DEAD_FROZEN:
582 kfree(iucv_param[cpu]);
583 iucv_param[cpu] = NULL;
584 kfree(iucv_irq_data[cpu]);
585 iucv_irq_data[cpu] = NULL;
586 break;
587 case CPU_ONLINE:
588 case CPU_ONLINE_FROZEN:
589 case CPU_DOWN_FAILED:
590 case CPU_DOWN_FAILED_FROZEN:
591 if (!iucv_path_table)
592 break;
593 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
594 break;
595 case CPU_DOWN_PREPARE:
596 case CPU_DOWN_PREPARE_FROZEN:
597 if (!iucv_path_table)
598 break;
599 cpumask = iucv_buffer_cpumask;
600 cpu_clear(cpu, cpumask);
601 if (cpus_empty(cpumask))
602 /* Can't offline last IUCV enabled cpu. */
603 return NOTIFY_BAD;
604 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
605 if (cpus_empty(iucv_irq_cpumask))
606 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
607 iucv_allow_cpu, NULL, 1);
608 break;
610 return NOTIFY_OK;
613 static struct notifier_block __refdata iucv_cpu_notifier = {
614 .notifier_call = iucv_cpu_notify,
618 * iucv_sever_pathid
619 * @pathid: path identification number.
620 * @userdata: 16-bytes of user data.
622 * Sever an iucv path to free up the pathid. Used internally.
624 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
626 union iucv_param *parm;
628 parm = iucv_param[smp_processor_id()];
629 memset(parm, 0, sizeof(union iucv_param));
630 if (userdata)
631 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
632 parm->ctrl.ippathid = pathid;
633 return iucv_call_b2f0(IUCV_SEVER, parm);
637 * __iucv_cleanup_queue
638 * @dummy: unused dummy argument
640 * Nop function called via smp_call_function to force work items from
641 * pending external iucv interrupts to the work queue.
643 static void __iucv_cleanup_queue(void *dummy)
648 * iucv_cleanup_queue
650 * Function called after a path has been severed to find all remaining
651 * work items for the now stale pathid. The caller needs to hold the
652 * iucv_table_lock.
654 static void iucv_cleanup_queue(void)
656 struct iucv_irq_list *p, *n;
659 * When a path is severed, the pathid can be reused immediatly
660 * on a iucv connect or a connection pending interrupt. Remove
661 * all entries from the task queue that refer to a stale pathid
662 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
663 * or deliver the connection pending interrupt. To get all the
664 * pending interrupts force them to the work queue by calling
665 * an empty function on all cpus.
667 smp_call_function(__iucv_cleanup_queue, NULL, 1);
668 spin_lock_irq(&iucv_queue_lock);
669 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
670 /* Remove stale work items from the task queue. */
671 if (iucv_path_table[p->data.ippathid] == NULL) {
672 list_del(&p->list);
673 kfree(p);
676 spin_unlock_irq(&iucv_queue_lock);
680 * iucv_register:
681 * @handler: address of iucv handler structure
682 * @smp: != 0 indicates that the handler can deal with out of order messages
684 * Registers a driver with IUCV.
686 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
687 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
689 int iucv_register(struct iucv_handler *handler, int smp)
691 int rc;
693 if (!iucv_available)
694 return -ENOSYS;
695 mutex_lock(&iucv_register_mutex);
696 if (!smp)
697 iucv_nonsmp_handler++;
698 if (list_empty(&iucv_handler_list)) {
699 rc = iucv_enable();
700 if (rc)
701 goto out_mutex;
702 } else if (!smp && iucv_nonsmp_handler == 1)
703 iucv_setmask_up();
704 INIT_LIST_HEAD(&handler->paths);
706 spin_lock_bh(&iucv_table_lock);
707 list_add_tail(&handler->list, &iucv_handler_list);
708 spin_unlock_bh(&iucv_table_lock);
709 rc = 0;
710 out_mutex:
711 mutex_unlock(&iucv_register_mutex);
712 return rc;
714 EXPORT_SYMBOL(iucv_register);
717 * iucv_unregister
718 * @handler: address of iucv handler structure
719 * @smp: != 0 indicates that the handler can deal with out of order messages
721 * Unregister driver from IUCV.
723 void iucv_unregister(struct iucv_handler *handler, int smp)
725 struct iucv_path *p, *n;
727 mutex_lock(&iucv_register_mutex);
728 spin_lock_bh(&iucv_table_lock);
729 /* Remove handler from the iucv_handler_list. */
730 list_del_init(&handler->list);
731 /* Sever all pathids still refering to the handler. */
732 list_for_each_entry_safe(p, n, &handler->paths, list) {
733 iucv_sever_pathid(p->pathid, NULL);
734 iucv_path_table[p->pathid] = NULL;
735 list_del(&p->list);
736 iucv_path_free(p);
738 spin_unlock_bh(&iucv_table_lock);
739 if (!smp)
740 iucv_nonsmp_handler--;
741 if (list_empty(&iucv_handler_list))
742 iucv_disable();
743 else if (!smp && iucv_nonsmp_handler == 0)
744 iucv_setmask_mp();
745 mutex_unlock(&iucv_register_mutex);
747 EXPORT_SYMBOL(iucv_unregister);
750 * iucv_path_accept
751 * @path: address of iucv path structure
752 * @handler: address of iucv handler structure
753 * @userdata: 16 bytes of data reflected to the communication partner
754 * @private: private data passed to interrupt handlers for this path
756 * This function is issued after the user received a connection pending
757 * external interrupt and now wishes to complete the IUCV communication path.
759 * Returns the result of the CP IUCV call.
761 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
762 u8 userdata[16], void *private)
764 union iucv_param *parm;
765 int rc;
767 local_bh_disable();
768 /* Prepare parameter block. */
769 parm = iucv_param[smp_processor_id()];
770 memset(parm, 0, sizeof(union iucv_param));
771 parm->ctrl.ippathid = path->pathid;
772 parm->ctrl.ipmsglim = path->msglim;
773 if (userdata)
774 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
775 parm->ctrl.ipflags1 = path->flags;
777 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
778 if (!rc) {
779 path->private = private;
780 path->msglim = parm->ctrl.ipmsglim;
781 path->flags = parm->ctrl.ipflags1;
783 local_bh_enable();
784 return rc;
786 EXPORT_SYMBOL(iucv_path_accept);
789 * iucv_path_connect
790 * @path: address of iucv path structure
791 * @handler: address of iucv handler structure
792 * @userid: 8-byte user identification
793 * @system: 8-byte target system identification
794 * @userdata: 16 bytes of data reflected to the communication partner
795 * @private: private data passed to interrupt handlers for this path
797 * This function establishes an IUCV path. Although the connect may complete
798 * successfully, you are not able to use the path until you receive an IUCV
799 * Connection Complete external interrupt.
801 * Returns the result of the CP IUCV call.
803 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
804 u8 userid[8], u8 system[8], u8 userdata[16],
805 void *private)
807 union iucv_param *parm;
808 int rc;
810 spin_lock_bh(&iucv_table_lock);
811 iucv_cleanup_queue();
812 parm = iucv_param[smp_processor_id()];
813 memset(parm, 0, sizeof(union iucv_param));
814 parm->ctrl.ipmsglim = path->msglim;
815 parm->ctrl.ipflags1 = path->flags;
816 if (userid) {
817 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
818 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
819 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
821 if (system) {
822 memcpy(parm->ctrl.iptarget, system,
823 sizeof(parm->ctrl.iptarget));
824 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
825 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
827 if (userdata)
828 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
830 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
831 if (!rc) {
832 if (parm->ctrl.ippathid < iucv_max_pathid) {
833 path->pathid = parm->ctrl.ippathid;
834 path->msglim = parm->ctrl.ipmsglim;
835 path->flags = parm->ctrl.ipflags1;
836 path->handler = handler;
837 path->private = private;
838 list_add_tail(&path->list, &handler->paths);
839 iucv_path_table[path->pathid] = path;
840 } else {
841 iucv_sever_pathid(parm->ctrl.ippathid,
842 iucv_error_pathid);
843 rc = -EIO;
846 spin_unlock_bh(&iucv_table_lock);
847 return rc;
849 EXPORT_SYMBOL(iucv_path_connect);
852 * iucv_path_quiesce:
853 * @path: address of iucv path structure
854 * @userdata: 16 bytes of data reflected to the communication partner
856 * This function temporarily suspends incoming messages on an IUCV path.
857 * You can later reactivate the path by invoking the iucv_resume function.
859 * Returns the result from the CP IUCV call.
861 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
863 union iucv_param *parm;
864 int rc;
866 local_bh_disable();
867 parm = iucv_param[smp_processor_id()];
868 memset(parm, 0, sizeof(union iucv_param));
869 if (userdata)
870 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
871 parm->ctrl.ippathid = path->pathid;
872 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
873 local_bh_enable();
874 return rc;
876 EXPORT_SYMBOL(iucv_path_quiesce);
879 * iucv_path_resume:
880 * @path: address of iucv path structure
881 * @userdata: 16 bytes of data reflected to the communication partner
883 * This function resumes incoming messages on an IUCV path that has
884 * been stopped with iucv_path_quiesce.
886 * Returns the result from the CP IUCV call.
888 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
890 union iucv_param *parm;
891 int rc;
893 local_bh_disable();
894 parm = iucv_param[smp_processor_id()];
895 memset(parm, 0, sizeof(union iucv_param));
896 if (userdata)
897 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
898 parm->ctrl.ippathid = path->pathid;
899 rc = iucv_call_b2f0(IUCV_RESUME, parm);
900 local_bh_enable();
901 return rc;
905 * iucv_path_sever
906 * @path: address of iucv path structure
907 * @userdata: 16 bytes of data reflected to the communication partner
909 * This function terminates an IUCV path.
911 * Returns the result from the CP IUCV call.
913 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
915 int rc;
917 preempt_disable();
918 if (iucv_active_cpu != smp_processor_id())
919 spin_lock_bh(&iucv_table_lock);
920 rc = iucv_sever_pathid(path->pathid, userdata);
921 if (!rc) {
922 iucv_path_table[path->pathid] = NULL;
923 list_del_init(&path->list);
925 if (iucv_active_cpu != smp_processor_id())
926 spin_unlock_bh(&iucv_table_lock);
927 preempt_enable();
928 return rc;
930 EXPORT_SYMBOL(iucv_path_sever);
933 * iucv_message_purge
934 * @path: address of iucv path structure
935 * @msg: address of iucv msg structure
936 * @srccls: source class of message
938 * Cancels a message you have sent.
940 * Returns the result from the CP IUCV call.
942 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
943 u32 srccls)
945 union iucv_param *parm;
946 int rc;
948 local_bh_disable();
949 parm = iucv_param[smp_processor_id()];
950 memset(parm, 0, sizeof(union iucv_param));
951 parm->purge.ippathid = path->pathid;
952 parm->purge.ipmsgid = msg->id;
953 parm->purge.ipsrccls = srccls;
954 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
955 rc = iucv_call_b2f0(IUCV_PURGE, parm);
956 if (!rc) {
957 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
958 msg->tag = parm->purge.ipmsgtag;
960 local_bh_enable();
961 return rc;
963 EXPORT_SYMBOL(iucv_message_purge);
966 * iucv_message_receive_iprmdata
967 * @path: address of iucv path structure
968 * @msg: address of iucv msg structure
969 * @flags: how the message is received (IUCV_IPBUFLST)
970 * @buffer: address of data buffer or address of struct iucv_array
971 * @size: length of data buffer
972 * @residual:
974 * Internal function used by iucv_message_receive and __iucv_message_receive
975 * to receive RMDATA data stored in struct iucv_message.
977 static int iucv_message_receive_iprmdata(struct iucv_path *path,
978 struct iucv_message *msg,
979 u8 flags, void *buffer,
980 size_t size, size_t *residual)
982 struct iucv_array *array;
983 u8 *rmmsg;
984 size_t copy;
987 * Message is 8 bytes long and has been stored to the
988 * message descriptor itself.
990 if (residual)
991 *residual = abs(size - 8);
992 rmmsg = msg->rmmsg;
993 if (flags & IUCV_IPBUFLST) {
994 /* Copy to struct iucv_array. */
995 size = (size < 8) ? size : 8;
996 for (array = buffer; size > 0; array++) {
997 copy = min_t(size_t, size, array->length);
998 memcpy((u8 *)(addr_t) array->address,
999 rmmsg, copy);
1000 rmmsg += copy;
1001 size -= copy;
1003 } else {
1004 /* Copy to direct buffer. */
1005 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1007 return 0;
1011 * __iucv_message_receive
1012 * @path: address of iucv path structure
1013 * @msg: address of iucv msg structure
1014 * @flags: how the message is received (IUCV_IPBUFLST)
1015 * @buffer: address of data buffer or address of struct iucv_array
1016 * @size: length of data buffer
1017 * @residual:
1019 * This function receives messages that are being sent to you over
1020 * established paths. This function will deal with RMDATA messages
1021 * embedded in struct iucv_message as well.
1023 * Locking: no locking
1025 * Returns the result from the CP IUCV call.
1027 int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1028 u8 flags, void *buffer, size_t size, size_t *residual)
1030 union iucv_param *parm;
1031 int rc;
1033 if (msg->flags & IUCV_IPRMDATA)
1034 return iucv_message_receive_iprmdata(path, msg, flags,
1035 buffer, size, residual);
1036 parm = iucv_param[smp_processor_id()];
1037 memset(parm, 0, sizeof(union iucv_param));
1038 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1039 parm->db.ipbfln1f = (u32) size;
1040 parm->db.ipmsgid = msg->id;
1041 parm->db.ippathid = path->pathid;
1042 parm->db.iptrgcls = msg->class;
1043 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1044 IUCV_IPFGMID | IUCV_IPTRGCLS);
1045 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1046 if (!rc || rc == 5) {
1047 msg->flags = parm->db.ipflags1;
1048 if (residual)
1049 *residual = parm->db.ipbfln1f;
1051 return rc;
1053 EXPORT_SYMBOL(__iucv_message_receive);
1056 * iucv_message_receive
1057 * @path: address of iucv path structure
1058 * @msg: address of iucv msg structure
1059 * @flags: how the message is received (IUCV_IPBUFLST)
1060 * @buffer: address of data buffer or address of struct iucv_array
1061 * @size: length of data buffer
1062 * @residual:
1064 * This function receives messages that are being sent to you over
1065 * established paths. This function will deal with RMDATA messages
1066 * embedded in struct iucv_message as well.
1068 * Locking: local_bh_enable/local_bh_disable
1070 * Returns the result from the CP IUCV call.
1072 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1073 u8 flags, void *buffer, size_t size, size_t *residual)
1075 int rc;
1077 if (msg->flags & IUCV_IPRMDATA)
1078 return iucv_message_receive_iprmdata(path, msg, flags,
1079 buffer, size, residual);
1080 local_bh_disable();
1081 rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
1082 local_bh_enable();
1083 return rc;
1085 EXPORT_SYMBOL(iucv_message_receive);
1088 * iucv_message_reject
1089 * @path: address of iucv path structure
1090 * @msg: address of iucv msg structure
1092 * The reject function refuses a specified message. Between the time you
1093 * are notified of a message and the time that you complete the message,
1094 * the message may be rejected.
1096 * Returns the result from the CP IUCV call.
1098 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1100 union iucv_param *parm;
1101 int rc;
1103 local_bh_disable();
1104 parm = iucv_param[smp_processor_id()];
1105 memset(parm, 0, sizeof(union iucv_param));
1106 parm->db.ippathid = path->pathid;
1107 parm->db.ipmsgid = msg->id;
1108 parm->db.iptrgcls = msg->class;
1109 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1110 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1111 local_bh_enable();
1112 return rc;
1114 EXPORT_SYMBOL(iucv_message_reject);
1117 * iucv_message_reply
1118 * @path: address of iucv path structure
1119 * @msg: address of iucv msg structure
1120 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1121 * @reply: address of reply data buffer or address of struct iucv_array
1122 * @size: length of reply data buffer
1124 * This function responds to the two-way messages that you receive. You
1125 * must identify completely the message to which you wish to reply. ie,
1126 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1127 * the parameter list.
1129 * Returns the result from the CP IUCV call.
1131 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1132 u8 flags, void *reply, size_t size)
1134 union iucv_param *parm;
1135 int rc;
1137 local_bh_disable();
1138 parm = iucv_param[smp_processor_id()];
1139 memset(parm, 0, sizeof(union iucv_param));
1140 if (flags & IUCV_IPRMDATA) {
1141 parm->dpl.ippathid = path->pathid;
1142 parm->dpl.ipflags1 = flags;
1143 parm->dpl.ipmsgid = msg->id;
1144 parm->dpl.iptrgcls = msg->class;
1145 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1146 } else {
1147 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1148 parm->db.ipbfln1f = (u32) size;
1149 parm->db.ippathid = path->pathid;
1150 parm->db.ipflags1 = flags;
1151 parm->db.ipmsgid = msg->id;
1152 parm->db.iptrgcls = msg->class;
1154 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1155 local_bh_enable();
1156 return rc;
1158 EXPORT_SYMBOL(iucv_message_reply);
1161 * __iucv_message_send
1162 * @path: address of iucv path structure
1163 * @msg: address of iucv msg structure
1164 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1165 * @srccls: source class of message
1166 * @buffer: address of send buffer or address of struct iucv_array
1167 * @size: length of send buffer
1169 * This function transmits data to another application. Data to be
1170 * transmitted is in a buffer and this is a one-way message and the
1171 * receiver will not reply to the message.
1173 * Locking: no locking
1175 * Returns the result from the CP IUCV call.
1177 int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1178 u8 flags, u32 srccls, void *buffer, size_t size)
1180 union iucv_param *parm;
1181 int rc;
1183 parm = iucv_param[smp_processor_id()];
1184 memset(parm, 0, sizeof(union iucv_param));
1185 if (flags & IUCV_IPRMDATA) {
1186 /* Message of 8 bytes can be placed into the parameter list. */
1187 parm->dpl.ippathid = path->pathid;
1188 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1189 parm->dpl.iptrgcls = msg->class;
1190 parm->dpl.ipsrccls = srccls;
1191 parm->dpl.ipmsgtag = msg->tag;
1192 memcpy(parm->dpl.iprmmsg, buffer, 8);
1193 } else {
1194 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1195 parm->db.ipbfln1f = (u32) size;
1196 parm->db.ippathid = path->pathid;
1197 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1198 parm->db.iptrgcls = msg->class;
1199 parm->db.ipsrccls = srccls;
1200 parm->db.ipmsgtag = msg->tag;
1202 rc = iucv_call_b2f0(IUCV_SEND, parm);
1203 if (!rc)
1204 msg->id = parm->db.ipmsgid;
1205 return rc;
1207 EXPORT_SYMBOL(__iucv_message_send);
1210 * iucv_message_send
1211 * @path: address of iucv path structure
1212 * @msg: address of iucv msg structure
1213 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1214 * @srccls: source class of message
1215 * @buffer: address of send buffer or address of struct iucv_array
1216 * @size: length of send buffer
1218 * This function transmits data to another application. Data to be
1219 * transmitted is in a buffer and this is a one-way message and the
1220 * receiver will not reply to the message.
1222 * Locking: local_bh_enable/local_bh_disable
1224 * Returns the result from the CP IUCV call.
1226 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1227 u8 flags, u32 srccls, void *buffer, size_t size)
1229 int rc;
1231 local_bh_disable();
1232 rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
1233 local_bh_enable();
1234 return rc;
1236 EXPORT_SYMBOL(iucv_message_send);
1239 * iucv_message_send2way
1240 * @path: address of iucv path structure
1241 * @msg: address of iucv msg structure
1242 * @flags: how the message is sent and the reply is received
1243 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1244 * @srccls: source class of message
1245 * @buffer: address of send buffer or address of struct iucv_array
1246 * @size: length of send buffer
1247 * @ansbuf: address of answer buffer or address of struct iucv_array
1248 * @asize: size of reply buffer
1250 * This function transmits data to another application. Data to be
1251 * transmitted is in a buffer. The receiver of the send is expected to
1252 * reply to the message and a buffer is provided into which IUCV moves
1253 * the reply to this message.
1255 * Returns the result from the CP IUCV call.
1257 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1258 u8 flags, u32 srccls, void *buffer, size_t size,
1259 void *answer, size_t asize, size_t *residual)
1261 union iucv_param *parm;
1262 int rc;
1264 local_bh_disable();
1265 parm = iucv_param[smp_processor_id()];
1266 memset(parm, 0, sizeof(union iucv_param));
1267 if (flags & IUCV_IPRMDATA) {
1268 parm->dpl.ippathid = path->pathid;
1269 parm->dpl.ipflags1 = path->flags; /* priority message */
1270 parm->dpl.iptrgcls = msg->class;
1271 parm->dpl.ipsrccls = srccls;
1272 parm->dpl.ipmsgtag = msg->tag;
1273 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1274 parm->dpl.ipbfln2f = (u32) asize;
1275 memcpy(parm->dpl.iprmmsg, buffer, 8);
1276 } else {
1277 parm->db.ippathid = path->pathid;
1278 parm->db.ipflags1 = path->flags; /* priority message */
1279 parm->db.iptrgcls = msg->class;
1280 parm->db.ipsrccls = srccls;
1281 parm->db.ipmsgtag = msg->tag;
1282 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1283 parm->db.ipbfln1f = (u32) size;
1284 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1285 parm->db.ipbfln2f = (u32) asize;
1287 rc = iucv_call_b2f0(IUCV_SEND, parm);
1288 if (!rc)
1289 msg->id = parm->db.ipmsgid;
1290 local_bh_enable();
1291 return rc;
1293 EXPORT_SYMBOL(iucv_message_send2way);
1296 * iucv_path_pending
1297 * @data: Pointer to external interrupt buffer
1299 * Process connection pending work item. Called from tasklet while holding
1300 * iucv_table_lock.
1302 struct iucv_path_pending {
1303 u16 ippathid;
1304 u8 ipflags1;
1305 u8 iptype;
1306 u16 ipmsglim;
1307 u16 res1;
1308 u8 ipvmid[8];
1309 u8 ipuser[16];
1310 u32 res3;
1311 u8 ippollfg;
1312 u8 res4[3];
1313 } __attribute__ ((packed));
1315 static void iucv_path_pending(struct iucv_irq_data *data)
1317 struct iucv_path_pending *ipp = (void *) data;
1318 struct iucv_handler *handler;
1319 struct iucv_path *path;
1320 char *error;
1322 BUG_ON(iucv_path_table[ipp->ippathid]);
1323 /* New pathid, handler found. Create a new path struct. */
1324 error = iucv_error_no_memory;
1325 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1326 if (!path)
1327 goto out_sever;
1328 path->pathid = ipp->ippathid;
1329 iucv_path_table[path->pathid] = path;
1330 EBCASC(ipp->ipvmid, 8);
1332 /* Call registered handler until one is found that wants the path. */
1333 list_for_each_entry(handler, &iucv_handler_list, list) {
1334 if (!handler->path_pending)
1335 continue;
1337 * Add path to handler to allow a call to iucv_path_sever
1338 * inside the path_pending function. If the handler returns
1339 * an error remove the path from the handler again.
1341 list_add(&path->list, &handler->paths);
1342 path->handler = handler;
1343 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1344 return;
1345 list_del(&path->list);
1346 path->handler = NULL;
1348 /* No handler wanted the path. */
1349 iucv_path_table[path->pathid] = NULL;
1350 iucv_path_free(path);
1351 error = iucv_error_no_listener;
1352 out_sever:
1353 iucv_sever_pathid(ipp->ippathid, error);
1357 * iucv_path_complete
1358 * @data: Pointer to external interrupt buffer
1360 * Process connection complete work item. Called from tasklet while holding
1361 * iucv_table_lock.
1363 struct iucv_path_complete {
1364 u16 ippathid;
1365 u8 ipflags1;
1366 u8 iptype;
1367 u16 ipmsglim;
1368 u16 res1;
1369 u8 res2[8];
1370 u8 ipuser[16];
1371 u32 res3;
1372 u8 ippollfg;
1373 u8 res4[3];
1374 } __attribute__ ((packed));
1376 static void iucv_path_complete(struct iucv_irq_data *data)
1378 struct iucv_path_complete *ipc = (void *) data;
1379 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1381 if (path && path->handler && path->handler->path_complete)
1382 path->handler->path_complete(path, ipc->ipuser);
1386 * iucv_path_severed
1387 * @data: Pointer to external interrupt buffer
1389 * Process connection severed work item. Called from tasklet while holding
1390 * iucv_table_lock.
1392 struct iucv_path_severed {
1393 u16 ippathid;
1394 u8 res1;
1395 u8 iptype;
1396 u32 res2;
1397 u8 res3[8];
1398 u8 ipuser[16];
1399 u32 res4;
1400 u8 ippollfg;
1401 u8 res5[3];
1402 } __attribute__ ((packed));
1404 static void iucv_path_severed(struct iucv_irq_data *data)
1406 struct iucv_path_severed *ips = (void *) data;
1407 struct iucv_path *path = iucv_path_table[ips->ippathid];
1409 if (!path || !path->handler) /* Already severed */
1410 return;
1411 if (path->handler->path_severed)
1412 path->handler->path_severed(path, ips->ipuser);
1413 else {
1414 iucv_sever_pathid(path->pathid, NULL);
1415 iucv_path_table[path->pathid] = NULL;
1416 list_del_init(&path->list);
1417 iucv_path_free(path);
1422 * iucv_path_quiesced
1423 * @data: Pointer to external interrupt buffer
1425 * Process connection quiesced work item. Called from tasklet while holding
1426 * iucv_table_lock.
1428 struct iucv_path_quiesced {
1429 u16 ippathid;
1430 u8 res1;
1431 u8 iptype;
1432 u32 res2;
1433 u8 res3[8];
1434 u8 ipuser[16];
1435 u32 res4;
1436 u8 ippollfg;
1437 u8 res5[3];
1438 } __attribute__ ((packed));
1440 static void iucv_path_quiesced(struct iucv_irq_data *data)
1442 struct iucv_path_quiesced *ipq = (void *) data;
1443 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1445 if (path && path->handler && path->handler->path_quiesced)
1446 path->handler->path_quiesced(path, ipq->ipuser);
1450 * iucv_path_resumed
1451 * @data: Pointer to external interrupt buffer
1453 * Process connection resumed work item. Called from tasklet while holding
1454 * iucv_table_lock.
1456 struct iucv_path_resumed {
1457 u16 ippathid;
1458 u8 res1;
1459 u8 iptype;
1460 u32 res2;
1461 u8 res3[8];
1462 u8 ipuser[16];
1463 u32 res4;
1464 u8 ippollfg;
1465 u8 res5[3];
1466 } __attribute__ ((packed));
1468 static void iucv_path_resumed(struct iucv_irq_data *data)
1470 struct iucv_path_resumed *ipr = (void *) data;
1471 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1473 if (path && path->handler && path->handler->path_resumed)
1474 path->handler->path_resumed(path, ipr->ipuser);
1478 * iucv_message_complete
1479 * @data: Pointer to external interrupt buffer
1481 * Process message complete work item. Called from tasklet while holding
1482 * iucv_table_lock.
1484 struct iucv_message_complete {
1485 u16 ippathid;
1486 u8 ipflags1;
1487 u8 iptype;
1488 u32 ipmsgid;
1489 u32 ipaudit;
1490 u8 iprmmsg[8];
1491 u32 ipsrccls;
1492 u32 ipmsgtag;
1493 u32 res;
1494 u32 ipbfln2f;
1495 u8 ippollfg;
1496 u8 res2[3];
1497 } __attribute__ ((packed));
1499 static void iucv_message_complete(struct iucv_irq_data *data)
1501 struct iucv_message_complete *imc = (void *) data;
1502 struct iucv_path *path = iucv_path_table[imc->ippathid];
1503 struct iucv_message msg;
1505 if (path && path->handler && path->handler->message_complete) {
1506 msg.flags = imc->ipflags1;
1507 msg.id = imc->ipmsgid;
1508 msg.audit = imc->ipaudit;
1509 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1510 msg.class = imc->ipsrccls;
1511 msg.tag = imc->ipmsgtag;
1512 msg.length = imc->ipbfln2f;
1513 path->handler->message_complete(path, &msg);
1518 * iucv_message_pending
1519 * @data: Pointer to external interrupt buffer
1521 * Process message pending work item. Called from tasklet while holding
1522 * iucv_table_lock.
1524 struct iucv_message_pending {
1525 u16 ippathid;
1526 u8 ipflags1;
1527 u8 iptype;
1528 u32 ipmsgid;
1529 u32 iptrgcls;
1530 union {
1531 u32 iprmmsg1_u32;
1532 u8 iprmmsg1[4];
1533 } ln1msg1;
1534 union {
1535 u32 ipbfln1f;
1536 u8 iprmmsg2[4];
1537 } ln1msg2;
1538 u32 res1[3];
1539 u32 ipbfln2f;
1540 u8 ippollfg;
1541 u8 res2[3];
1542 } __attribute__ ((packed));
1544 static void iucv_message_pending(struct iucv_irq_data *data)
1546 struct iucv_message_pending *imp = (void *) data;
1547 struct iucv_path *path = iucv_path_table[imp->ippathid];
1548 struct iucv_message msg;
1550 if (path && path->handler && path->handler->message_pending) {
1551 msg.flags = imp->ipflags1;
1552 msg.id = imp->ipmsgid;
1553 msg.class = imp->iptrgcls;
1554 if (imp->ipflags1 & IUCV_IPRMDATA) {
1555 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1556 msg.length = 8;
1557 } else
1558 msg.length = imp->ln1msg2.ipbfln1f;
1559 msg.reply_size = imp->ipbfln2f;
1560 path->handler->message_pending(path, &msg);
1565 * iucv_tasklet_fn:
1567 * This tasklet loops over the queue of irq buffers created by
1568 * iucv_external_interrupt, calls the appropriate action handler
1569 * and then frees the buffer.
1571 static void iucv_tasklet_fn(unsigned long ignored)
1573 typedef void iucv_irq_fn(struct iucv_irq_data *);
1574 static iucv_irq_fn *irq_fn[] = {
1575 [0x02] = iucv_path_complete,
1576 [0x03] = iucv_path_severed,
1577 [0x04] = iucv_path_quiesced,
1578 [0x05] = iucv_path_resumed,
1579 [0x06] = iucv_message_complete,
1580 [0x07] = iucv_message_complete,
1581 [0x08] = iucv_message_pending,
1582 [0x09] = iucv_message_pending,
1584 LIST_HEAD(task_queue);
1585 struct iucv_irq_list *p, *n;
1587 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1588 if (!spin_trylock(&iucv_table_lock)) {
1589 tasklet_schedule(&iucv_tasklet);
1590 return;
1592 iucv_active_cpu = smp_processor_id();
1594 spin_lock_irq(&iucv_queue_lock);
1595 list_splice_init(&iucv_task_queue, &task_queue);
1596 spin_unlock_irq(&iucv_queue_lock);
1598 list_for_each_entry_safe(p, n, &task_queue, list) {
1599 list_del_init(&p->list);
1600 irq_fn[p->data.iptype](&p->data);
1601 kfree(p);
1604 iucv_active_cpu = -1;
1605 spin_unlock(&iucv_table_lock);
1609 * iucv_work_fn:
1611 * This work function loops over the queue of path pending irq blocks
1612 * created by iucv_external_interrupt, calls the appropriate action
1613 * handler and then frees the buffer.
1615 static void iucv_work_fn(struct work_struct *work)
1617 typedef void iucv_irq_fn(struct iucv_irq_data *);
1618 LIST_HEAD(work_queue);
1619 struct iucv_irq_list *p, *n;
1621 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1622 spin_lock_bh(&iucv_table_lock);
1623 iucv_active_cpu = smp_processor_id();
1625 spin_lock_irq(&iucv_queue_lock);
1626 list_splice_init(&iucv_work_queue, &work_queue);
1627 spin_unlock_irq(&iucv_queue_lock);
1629 iucv_cleanup_queue();
1630 list_for_each_entry_safe(p, n, &work_queue, list) {
1631 list_del_init(&p->list);
1632 iucv_path_pending(&p->data);
1633 kfree(p);
1636 iucv_active_cpu = -1;
1637 spin_unlock_bh(&iucv_table_lock);
1641 * iucv_external_interrupt
1642 * @code: irq code
1644 * Handles external interrupts coming in from CP.
1645 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1647 static void iucv_external_interrupt(u16 code)
1649 struct iucv_irq_data *p;
1650 struct iucv_irq_list *work;
1652 p = iucv_irq_data[smp_processor_id()];
1653 if (p->ippathid >= iucv_max_pathid) {
1654 WARN_ON(p->ippathid >= iucv_max_pathid);
1655 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1656 return;
1658 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
1659 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1660 if (!work) {
1661 pr_warning("iucv_external_interrupt: out of memory\n");
1662 return;
1664 memcpy(&work->data, p, sizeof(work->data));
1665 spin_lock(&iucv_queue_lock);
1666 if (p->iptype == 0x01) {
1667 /* Path pending interrupt. */
1668 list_add_tail(&work->list, &iucv_work_queue);
1669 schedule_work(&iucv_work);
1670 } else {
1671 /* The other interrupts. */
1672 list_add_tail(&work->list, &iucv_task_queue);
1673 tasklet_schedule(&iucv_tasklet);
1675 spin_unlock(&iucv_queue_lock);
1679 * iucv_init
1681 * Allocates and initializes various data structures.
1683 static int __init iucv_init(void)
1685 int rc;
1686 int cpu;
1688 if (!MACHINE_IS_VM) {
1689 rc = -EPROTONOSUPPORT;
1690 goto out;
1692 rc = iucv_query_maxconn();
1693 if (rc)
1694 goto out;
1695 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
1696 if (rc)
1697 goto out;
1698 iucv_root = root_device_register("iucv");
1699 if (IS_ERR(iucv_root)) {
1700 rc = PTR_ERR(iucv_root);
1701 goto out_int;
1704 for_each_online_cpu(cpu) {
1705 /* Note: GFP_DMA used to get memory below 2G */
1706 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1707 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1708 if (!iucv_irq_data[cpu]) {
1709 rc = -ENOMEM;
1710 goto out_free;
1713 /* Allocate parameter blocks. */
1714 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1715 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1716 if (!iucv_param[cpu]) {
1717 rc = -ENOMEM;
1718 goto out_free;
1721 rc = register_hotcpu_notifier(&iucv_cpu_notifier);
1722 if (rc)
1723 goto out_free;
1724 ASCEBC(iucv_error_no_listener, 16);
1725 ASCEBC(iucv_error_no_memory, 16);
1726 ASCEBC(iucv_error_pathid, 16);
1727 iucv_available = 1;
1728 rc = bus_register(&iucv_bus);
1729 if (rc)
1730 goto out_cpu;
1731 return 0;
1733 out_cpu:
1734 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1735 out_free:
1736 for_each_possible_cpu(cpu) {
1737 kfree(iucv_param[cpu]);
1738 iucv_param[cpu] = NULL;
1739 kfree(iucv_irq_data[cpu]);
1740 iucv_irq_data[cpu] = NULL;
1742 root_device_unregister(iucv_root);
1743 out_int:
1744 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1745 out:
1746 return rc;
1750 * iucv_exit
1752 * Frees everything allocated from iucv_init.
1754 static void __exit iucv_exit(void)
1756 struct iucv_irq_list *p, *n;
1757 int cpu;
1759 spin_lock_irq(&iucv_queue_lock);
1760 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1761 kfree(p);
1762 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1763 kfree(p);
1764 spin_unlock_irq(&iucv_queue_lock);
1765 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1766 for_each_possible_cpu(cpu) {
1767 kfree(iucv_param[cpu]);
1768 iucv_param[cpu] = NULL;
1769 kfree(iucv_irq_data[cpu]);
1770 iucv_irq_data[cpu] = NULL;
1772 root_device_unregister(iucv_root);
1773 bus_unregister(&iucv_bus);
1774 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1777 subsys_initcall(iucv_init);
1778 module_exit(iucv_exit);
1780 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1781 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1782 MODULE_LICENSE("GPL");