2 * IUCV base infrastructure.
4 * Copyright 2001, 2006 IBM Deutschland Entwicklung GmbH, IBM Corporation
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>
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)
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 #include <linux/module.h>
34 #include <linux/moduleparam.h>
36 #include <linux/spinlock.h>
37 #include <linux/kernel.h>
38 #include <linux/slab.h>
39 #include <linux/init.h>
40 #include <linux/interrupt.h>
41 #include <linux/list.h>
42 #include <linux/errno.h>
43 #include <linux/err.h>
44 #include <linux/device.h>
45 #include <linux/cpu.h>
46 #include <net/iucv/iucv.h>
47 #include <asm/atomic.h>
48 #include <asm/ebcdic.h>
50 #include <asm/s390_ext.h>
51 #include <asm/s390_rdev.h>
56 * All flags are defined in the field IPFLAGS1 of each function
57 * and can be found in CP Programming Services.
58 * IPSRCCLS - Indicates you have specified a source class.
59 * IPTRGCLS - Indicates you have specified a target class.
60 * IPFGPID - Indicates you have specified a pathid.
61 * IPFGMID - Indicates you have specified a message ID.
62 * IPNORPY - Indicates a one-way message. No reply expected.
63 * IPALL - Indicates that all paths are affected.
65 #define IUCV_IPSRCCLS 0x01
66 #define IUCV_IPTRGCLS 0x01
67 #define IUCV_IPFGPID 0x02
68 #define IUCV_IPFGMID 0x04
69 #define IUCV_IPNORPY 0x10
70 #define IUCV_IPALL 0x80
72 static int iucv_bus_match (struct device *dev, struct device_driver *drv)
77 struct bus_type iucv_bus = {
79 .match = iucv_bus_match,
82 struct device *iucv_root;
83 static int iucv_available;
85 /* General IUCV interrupt structure */
86 struct iucv_irq_data {
94 struct list_head list;
95 struct iucv_irq_data data;
98 static LIST_HEAD(iucv_work_queue);
99 static DEFINE_SPINLOCK(iucv_work_lock);
101 static struct iucv_irq_data *iucv_irq_data;
102 static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
103 static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
105 static void iucv_tasklet_handler(unsigned long);
106 static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_handler,0);
108 enum iucv_command_codes {
110 IUCV_RETRIEVE_BUFFER = 2,
118 IUCV_DECLARE_BUFFER = 12,
126 * Error messages that are used with the iucv_sever function. They get
127 * converted to EBCDIC.
129 static char iucv_error_no_listener[16] = "NO LISTENER";
130 static char iucv_error_no_memory[16] = "NO MEMORY";
131 static char iucv_error_pathid[16] = "INVALID PATHID";
134 * iucv_handler_list: List of registered handlers.
136 static LIST_HEAD(iucv_handler_list);
139 * iucv_path_table: an array of iucv_path structures.
141 static struct iucv_path **iucv_path_table;
142 static unsigned long iucv_max_pathid;
145 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
147 static DEFINE_SPINLOCK(iucv_table_lock);
150 * iucv_tasklet_cpu: contains the number of the cpu executing the tasklet.
151 * Needed for iucv_path_sever called from tasklet.
153 static int iucv_tasklet_cpu = -1;
156 * Mutex and wait queue for iucv_register/iucv_unregister.
158 static DEFINE_MUTEX(iucv_register_mutex);
161 * Counter for number of non-smp capable handlers.
163 static int iucv_nonsmp_handler;
166 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
167 * iucv_path_quiesce and iucv_path_sever.
169 struct iucv_cmd_control {
178 } __attribute__ ((packed,aligned(8)));
181 * Data in parameter list iucv structure. Used by iucv_message_send,
182 * iucv_message_send2way and iucv_message_reply.
184 struct iucv_cmd_dpl {
196 } __attribute__ ((packed,aligned(8)));
199 * Data in buffer iucv structure. Used by iucv_message_receive,
200 * iucv_message_reject, iucv_message_send, iucv_message_send2way
201 * and iucv_declare_cpu.
216 } __attribute__ ((packed,aligned(8)));
219 * Purge message iucv structure. Used by iucv_message_purge.
221 struct iucv_cmd_purge {
232 } __attribute__ ((packed,aligned(8)));
235 * Set mask iucv structure. Used by iucv_enable_cpu.
237 struct iucv_cmd_set_mask {
242 } __attribute__ ((packed,aligned(8)));
245 struct iucv_cmd_control ctrl;
246 struct iucv_cmd_dpl dpl;
247 struct iucv_cmd_db db;
248 struct iucv_cmd_purge purge;
249 struct iucv_cmd_set_mask set_mask;
253 * Anchor for per-cpu IUCV command parameter block.
255 static union iucv_param *iucv_param;
259 * @code: identifier of IUCV call to CP.
260 * @parm: pointer to a struct iucv_parm block
262 * Calls CP to execute IUCV commands.
264 * Returns the result of the CP IUCV call.
266 static inline int iucv_call_b2f0(int command, union iucv_param *parm)
268 register unsigned long reg0 asm ("0");
269 register unsigned long reg1 asm ("1");
273 reg1 = virt_to_phys(parm);
275 " .long 0xb2f01000\n"
278 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
279 : "m" (*parm) : "cc");
280 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
286 * Determines the maximum number of connections that may be established.
288 * Returns the maximum number of connections or -EPERM is IUCV is not
291 static int iucv_query_maxconn(void)
293 register unsigned long reg0 asm ("0");
294 register unsigned long reg1 asm ("1");
298 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
302 reg1 = (unsigned long) param;
304 " .long 0xb2f01000\n"
307 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
309 iucv_max_pathid = reg0;
311 return ccode ? -EPERM : 0;
318 * Allow iucv interrupts on this cpu.
320 static void iucv_allow_cpu(void *data)
322 int cpu = smp_processor_id();
323 union iucv_param *parm;
326 * Enable all iucv interrupts.
327 * ipmask contains bits for the different interrupts
328 * 0x80 - Flag to allow nonpriority message pending interrupts
329 * 0x40 - Flag to allow priority message pending interrupts
330 * 0x20 - Flag to allow nonpriority message completion interrupts
331 * 0x10 - Flag to allow priority message completion interrupts
332 * 0x08 - Flag to allow IUCV control interrupts
334 parm = percpu_ptr(iucv_param, smp_processor_id());
335 memset(parm, 0, sizeof(union iucv_param));
336 parm->set_mask.ipmask = 0xf8;
337 iucv_call_b2f0(IUCV_SETMASK, parm);
339 /* Set indication that iucv interrupts are allowed for this cpu. */
340 cpu_set(cpu, iucv_irq_cpumask);
347 * Block iucv interrupts on this cpu.
349 static void iucv_block_cpu(void *data)
351 int cpu = smp_processor_id();
352 union iucv_param *parm;
354 /* Disable all iucv interrupts. */
355 parm = percpu_ptr(iucv_param, smp_processor_id());
356 memset(parm, 0, sizeof(union iucv_param));
357 iucv_call_b2f0(IUCV_SETMASK, parm);
359 /* Clear indication that iucv interrupts are allowed for this cpu. */
360 cpu_clear(cpu, iucv_irq_cpumask);
367 * Declare a interupt buffer on this cpu.
369 static void iucv_declare_cpu(void *data)
371 int cpu = smp_processor_id();
372 union iucv_param *parm;
375 if (cpu_isset(cpu, iucv_buffer_cpumask))
378 /* Declare interrupt buffer. */
379 parm = percpu_ptr(iucv_param, cpu);
380 memset(parm, 0, sizeof(union iucv_param));
381 parm->db.ipbfadr1 = virt_to_phys(percpu_ptr(iucv_irq_data, cpu));
382 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
384 char *err = "Unknown";
387 err = "Directory error";
390 err = "Invalid length";
393 err = "Buffer already exists";
396 err = "Buffer overlap";
399 err = "Paging or storage error";
402 printk(KERN_WARNING "iucv_register: iucv_declare_buffer "
403 "on cpu %i returned error 0x%02x (%s)\n", cpu, rc, err);
407 /* Set indication that an iucv buffer exists for this cpu. */
408 cpu_set(cpu, iucv_buffer_cpumask);
410 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
411 /* Enable iucv interrupts on this cpu. */
412 iucv_allow_cpu(NULL);
414 /* Disable iucv interrupts on this cpu. */
415 iucv_block_cpu(NULL);
422 * Retrieve interrupt buffer on this cpu.
424 static void iucv_retrieve_cpu(void *data)
426 int cpu = smp_processor_id();
427 union iucv_param *parm;
429 if (!cpu_isset(cpu, iucv_buffer_cpumask))
432 /* Block iucv interrupts. */
433 iucv_block_cpu(NULL);
435 /* Retrieve interrupt buffer. */
436 parm = percpu_ptr(iucv_param, cpu);
437 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
439 /* Clear indication that an iucv buffer exists for this cpu. */
440 cpu_clear(cpu, iucv_buffer_cpumask);
446 * Allow iucv interrupts on all cpus.
448 static void iucv_setmask_mp(void)
452 for_each_online_cpu(cpu)
453 /* Enable all cpus with a declared buffer. */
454 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
455 !cpu_isset(cpu, iucv_irq_cpumask))
456 smp_call_function_on(iucv_allow_cpu, NULL, 0, 1, cpu);
462 * Allow iucv interrupts on a single cpus.
464 static void iucv_setmask_up(void)
469 /* Disable all cpu but the first in cpu_irq_cpumask. */
470 cpumask = iucv_irq_cpumask;
471 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
472 for_each_cpu_mask(cpu, cpumask)
473 smp_call_function_on(iucv_block_cpu, NULL, 0, 1, cpu);
479 * This function makes iucv ready for use. It allocates the pathid
480 * table, declares an iucv interrupt buffer and enables the iucv
481 * interrupts. Called when the first user has registered an iucv
484 static int iucv_enable(void)
490 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
491 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
492 if (!iucv_path_table)
494 /* Declare per cpu buffers. */
496 for_each_online_cpu(cpu)
497 smp_call_function_on(iucv_declare_cpu, NULL, 0, 1, cpu);
498 if (cpus_empty(iucv_buffer_cpumask))
499 /* No cpu could declare an iucv buffer. */
504 kfree(iucv_path_table);
512 * This function shuts down iucv. It disables iucv interrupts, retrieves
513 * the iucv interrupt buffer and frees the pathid table. Called after the
514 * last user unregister its iucv handler.
516 static void iucv_disable(void)
518 on_each_cpu(iucv_retrieve_cpu, NULL, 0, 1);
519 kfree(iucv_path_table);
522 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
523 unsigned long action, void *hcpu)
526 long cpu = (long) hcpu;
530 if (!percpu_populate(iucv_irq_data,
531 sizeof(struct iucv_irq_data),
532 GFP_KERNEL|GFP_DMA, cpu))
534 if (!percpu_populate(iucv_param, sizeof(union iucv_param),
535 GFP_KERNEL|GFP_DMA, cpu)) {
536 percpu_depopulate(iucv_irq_data, cpu);
540 case CPU_UP_CANCELED:
542 percpu_depopulate(iucv_param, cpu);
543 percpu_depopulate(iucv_irq_data, cpu);
546 case CPU_DOWN_FAILED:
547 smp_call_function_on(iucv_declare_cpu, NULL, 0, 1, cpu);
549 case CPU_DOWN_PREPARE:
550 cpumask = iucv_buffer_cpumask;
551 cpu_clear(cpu, cpumask);
552 if (cpus_empty(cpumask))
553 /* Can't offline last IUCV enabled cpu. */
555 smp_call_function_on(iucv_retrieve_cpu, NULL, 0, 1, cpu);
556 if (cpus_empty(iucv_irq_cpumask))
557 smp_call_function_on(iucv_allow_cpu, NULL, 0, 1,
558 first_cpu(iucv_buffer_cpumask));
564 static struct notifier_block iucv_cpu_notifier = {
565 .notifier_call = iucv_cpu_notify,
570 * @pathid: path identification number.
571 * @userdata: 16-bytes of user data.
573 * Sever an iucv path to free up the pathid. Used internally.
575 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
577 union iucv_param *parm;
579 parm = percpu_ptr(iucv_param, smp_processor_id());
580 memset(parm, 0, sizeof(union iucv_param));
582 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
583 parm->ctrl.ippathid = pathid;
584 return iucv_call_b2f0(IUCV_SEVER, parm);
588 * __iucv_cleanup_pathid
589 * @dummy: unused dummy argument
591 * Nop function called via smp_call_function to force work items from
592 * pending external iucv interrupts to the work queue.
594 static void __iucv_cleanup_pathid(void *dummy)
599 * iucv_cleanup_pathid
600 * @pathid: 16 bit pathid
602 * Function called after a path has been severed to find all remaining
603 * work items for the now stale pathid. The caller needs to hold the
606 static void iucv_cleanup_pathid(u16 pathid)
608 struct iucv_work *p, *n;
611 * Path is severed, the pathid can be reused immediatly on
612 * a iucv connect or a connection pending interrupt.
613 * iucv_path_connect and connection pending interrupt will
614 * wait until the iucv_table_lock is released before the
615 * recycled pathid enters the system.
616 * Force remaining interrupts to the work queue, then
617 * scan the work queue for items of this path.
619 smp_call_function(__iucv_cleanup_pathid, NULL, 0, 1);
620 spin_lock_irq(&iucv_work_lock);
621 list_for_each_entry_safe(p, n, &iucv_work_queue, list) {
622 /* Remove work items for pathid except connection pending */
623 if (p->data.ippathid == pathid && p->data.iptype != 0x01) {
628 spin_unlock_irq(&iucv_work_lock);
633 * @handler: address of iucv handler structure
634 * @smp: != 0 indicates that the handler can deal with out of order messages
636 * Registers a driver with IUCV.
638 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
639 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
641 int iucv_register(struct iucv_handler *handler, int smp)
647 mutex_lock(&iucv_register_mutex);
649 iucv_nonsmp_handler++;
650 if (list_empty(&iucv_handler_list)) {
654 } else if (!smp && iucv_nonsmp_handler == 1)
656 INIT_LIST_HEAD(&handler->paths);
658 spin_lock_irq(&iucv_table_lock);
659 list_add_tail(&handler->list, &iucv_handler_list);
660 spin_unlock_irq(&iucv_table_lock);
663 mutex_unlock(&iucv_register_mutex);
669 * @handler: address of iucv handler structure
670 * @smp: != 0 indicates that the handler can deal with out of order messages
672 * Unregister driver from IUCV.
674 void iucv_unregister(struct iucv_handler *handler, int smp)
676 struct iucv_path *p, *n;
678 mutex_lock(&iucv_register_mutex);
679 spin_lock_bh(&iucv_table_lock);
680 /* Remove handler from the iucv_handler_list. */
681 list_del_init(&handler->list);
682 /* Sever all pathids still refering to the handler. */
683 list_for_each_entry_safe(p, n, &handler->paths, list) {
684 iucv_sever_pathid(p->pathid, NULL);
685 iucv_path_table[p->pathid] = NULL;
687 iucv_cleanup_pathid(p->pathid);
690 spin_unlock_bh(&iucv_table_lock);
692 iucv_nonsmp_handler--;
693 if (list_empty(&iucv_handler_list))
695 else if (!smp && iucv_nonsmp_handler == 0)
697 mutex_unlock(&iucv_register_mutex);
702 * @path: address of iucv path structure
703 * @handler: address of iucv handler structure
704 * @userdata: 16 bytes of data reflected to the communication partner
705 * @private: private data passed to interrupt handlers for this path
707 * This function is issued after the user received a connection pending
708 * external interrupt and now wishes to complete the IUCV communication path.
710 * Returns the result of the CP IUCV call.
712 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
713 u8 userdata[16], void *private)
715 union iucv_param *parm;
719 /* Prepare parameter block. */
720 parm = percpu_ptr(iucv_param, smp_processor_id());
721 memset(parm, 0, sizeof(union iucv_param));
722 parm->ctrl.ippathid = path->pathid;
723 parm->ctrl.ipmsglim = path->msglim;
725 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
726 parm->ctrl.ipflags1 = path->flags;
728 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
730 path->private = private;
731 path->msglim = parm->ctrl.ipmsglim;
732 path->flags = parm->ctrl.ipflags1;
740 * @path: address of iucv path structure
741 * @handler: address of iucv handler structure
742 * @userid: 8-byte user identification
743 * @system: 8-byte target system identification
744 * @userdata: 16 bytes of data reflected to the communication partner
745 * @private: private data passed to interrupt handlers for this path
747 * This function establishes an IUCV path. Although the connect may complete
748 * successfully, you are not able to use the path until you receive an IUCV
749 * Connection Complete external interrupt.
751 * Returns the result of the CP IUCV call.
753 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
754 u8 userid[8], u8 system[8], u8 userdata[16],
757 union iucv_param *parm;
761 if (iucv_tasklet_cpu != smp_processor_id())
762 spin_lock_bh(&iucv_table_lock);
763 parm = percpu_ptr(iucv_param, smp_processor_id());
764 memset(parm, 0, sizeof(union iucv_param));
765 parm->ctrl.ipmsglim = path->msglim;
766 parm->ctrl.ipflags1 = path->flags;
768 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
769 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
770 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
773 memcpy(parm->ctrl.iptarget, system,
774 sizeof(parm->ctrl.iptarget));
775 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
776 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
779 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
781 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
783 if (parm->ctrl.ippathid < iucv_max_pathid) {
784 path->pathid = parm->ctrl.ippathid;
785 path->msglim = parm->ctrl.ipmsglim;
786 path->flags = parm->ctrl.ipflags1;
787 path->handler = handler;
788 path->private = private;
789 list_add_tail(&path->list, &handler->paths);
790 iucv_path_table[path->pathid] = path;
792 iucv_sever_pathid(parm->ctrl.ippathid,
797 if (iucv_tasklet_cpu != smp_processor_id())
798 spin_unlock_bh(&iucv_table_lock);
805 * @path: address of iucv path structure
806 * @userdata: 16 bytes of data reflected to the communication partner
808 * This function temporarily suspends incoming messages on an IUCV path.
809 * You can later reactivate the path by invoking the iucv_resume function.
811 * Returns the result from the CP IUCV call.
813 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
815 union iucv_param *parm;
819 parm = percpu_ptr(iucv_param, smp_processor_id());
820 memset(parm, 0, sizeof(union iucv_param));
822 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
823 parm->ctrl.ippathid = path->pathid;
824 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
831 * @path: address of iucv path structure
832 * @userdata: 16 bytes of data reflected to the communication partner
834 * This function resumes incoming messages on an IUCV path that has
835 * been stopped with iucv_path_quiesce.
837 * Returns the result from the CP IUCV call.
839 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
841 union iucv_param *parm;
845 parm = percpu_ptr(iucv_param, smp_processor_id());
846 memset(parm, 0, sizeof(union iucv_param));
848 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
849 parm->ctrl.ippathid = path->pathid;
850 rc = iucv_call_b2f0(IUCV_RESUME, parm);
857 * @path: address of iucv path structure
858 * @userdata: 16 bytes of data reflected to the communication partner
860 * This function terminates an IUCV path.
862 * Returns the result from the CP IUCV call.
864 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
870 if (iucv_tasklet_cpu != smp_processor_id())
871 spin_lock_bh(&iucv_table_lock);
872 rc = iucv_sever_pathid(path->pathid, userdata);
874 iucv_path_table[path->pathid] = NULL;
875 list_del_init(&path->list);
876 iucv_cleanup_pathid(path->pathid);
878 if (iucv_tasklet_cpu != smp_processor_id())
879 spin_unlock_bh(&iucv_table_lock);
886 * @path: address of iucv path structure
887 * @msg: address of iucv msg structure
888 * @srccls: source class of message
890 * Cancels a message you have sent.
892 * Returns the result from the CP IUCV call.
894 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
897 union iucv_param *parm;
901 parm = percpu_ptr(iucv_param, smp_processor_id());
902 memset(parm, 0, sizeof(union iucv_param));
903 parm->purge.ippathid = path->pathid;
904 parm->purge.ipmsgid = msg->id;
905 parm->purge.ipsrccls = srccls;
906 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
907 rc = iucv_call_b2f0(IUCV_PURGE, parm);
909 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
910 msg->tag = parm->purge.ipmsgtag;
917 * iucv_message_receive
918 * @path: address of iucv path structure
919 * @msg: address of iucv msg structure
920 * @flags: how the message is received (IUCV_IPBUFLST)
921 * @buffer: address of data buffer or address of struct iucv_array
922 * @size: length of data buffer
925 * This function receives messages that are being sent to you over
926 * established paths. This function will deal with RMDATA messages
927 * embedded in struct iucv_message as well.
929 * Returns the result from the CP IUCV call.
931 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
932 u8 flags, void *buffer, size_t size, size_t *residual)
934 union iucv_param *parm;
935 struct iucv_array *array;
940 if (msg->flags & IUCV_IPRMDATA) {
942 * Message is 8 bytes long and has been stored to the
943 * message descriptor itself.
945 rc = (size < 8) ? 5 : 0;
947 *residual = abs(size - 8);
949 if (flags & IUCV_IPBUFLST) {
950 /* Copy to struct iucv_array. */
951 size = (size < 8) ? size : 8;
952 for (array = buffer; size > 0; array++) {
953 copy = min_t(size_t, size, array->length);
954 memcpy((u8 *)(addr_t) array->address,
960 /* Copy to direct buffer. */
961 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
967 parm = percpu_ptr(iucv_param, smp_processor_id());
968 memset(parm, 0, sizeof(union iucv_param));
969 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
970 parm->db.ipbfln1f = (u32) size;
971 parm->db.ipmsgid = msg->id;
972 parm->db.ippathid = path->pathid;
973 parm->db.iptrgcls = msg->class;
974 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
975 IUCV_IPFGMID | IUCV_IPTRGCLS);
976 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
977 if (!rc || rc == 5) {
978 msg->flags = parm->db.ipflags1;
980 *residual = parm->db.ipbfln1f;
987 * iucv_message_reject
988 * @path: address of iucv path structure
989 * @msg: address of iucv msg structure
991 * The reject function refuses a specified message. Between the time you
992 * are notified of a message and the time that you complete the message,
993 * the message may be rejected.
995 * Returns the result from the CP IUCV call.
997 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
999 union iucv_param *parm;
1003 parm = percpu_ptr(iucv_param, smp_processor_id());
1004 memset(parm, 0, sizeof(union iucv_param));
1005 parm->db.ippathid = path->pathid;
1006 parm->db.ipmsgid = msg->id;
1007 parm->db.iptrgcls = msg->class;
1008 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1009 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1015 * iucv_message_reply
1016 * @path: address of iucv path structure
1017 * @msg: address of iucv msg structure
1018 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1019 * @reply: address of reply data buffer or address of struct iucv_array
1020 * @size: length of reply data buffer
1022 * This function responds to the two-way messages that you receive. You
1023 * must identify completely the message to which you wish to reply. ie,
1024 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1025 * the parameter list.
1027 * Returns the result from the CP IUCV call.
1029 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1030 u8 flags, void *reply, size_t size)
1032 union iucv_param *parm;
1036 parm = percpu_ptr(iucv_param, smp_processor_id());
1037 memset(parm, 0, sizeof(union iucv_param));
1038 if (flags & IUCV_IPRMDATA) {
1039 parm->dpl.ippathid = path->pathid;
1040 parm->dpl.ipflags1 = flags;
1041 parm->dpl.ipmsgid = msg->id;
1042 parm->dpl.iptrgcls = msg->class;
1043 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1045 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1046 parm->db.ipbfln1f = (u32) size;
1047 parm->db.ippathid = path->pathid;
1048 parm->db.ipflags1 = flags;
1049 parm->db.ipmsgid = msg->id;
1050 parm->db.iptrgcls = msg->class;
1052 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1059 * @path: address of iucv path structure
1060 * @msg: address of iucv msg structure
1061 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1062 * @srccls: source class of message
1063 * @buffer: address of send buffer or address of struct iucv_array
1064 * @size: length of send buffer
1066 * This function transmits data to another application. Data to be
1067 * transmitted is in a buffer and this is a one-way message and the
1068 * receiver will not reply to the message.
1070 * Returns the result from the CP IUCV call.
1072 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1073 u8 flags, u32 srccls, void *buffer, size_t size)
1075 union iucv_param *parm;
1079 parm = percpu_ptr(iucv_param, smp_processor_id());
1080 memset(parm, 0, sizeof(union iucv_param));
1081 if (flags & IUCV_IPRMDATA) {
1082 /* Message of 8 bytes can be placed into the parameter list. */
1083 parm->dpl.ippathid = path->pathid;
1084 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1085 parm->dpl.iptrgcls = msg->class;
1086 parm->dpl.ipsrccls = srccls;
1087 parm->dpl.ipmsgtag = msg->tag;
1088 memcpy(parm->dpl.iprmmsg, buffer, 8);
1090 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1091 parm->db.ipbfln1f = (u32) size;
1092 parm->db.ippathid = path->pathid;
1093 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1094 parm->db.iptrgcls = msg->class;
1095 parm->db.ipsrccls = srccls;
1096 parm->db.ipmsgtag = msg->tag;
1098 rc = iucv_call_b2f0(IUCV_SEND, parm);
1100 msg->id = parm->db.ipmsgid;
1106 * iucv_message_send2way
1107 * @path: address of iucv path structure
1108 * @msg: address of iucv msg structure
1109 * @flags: how the message is sent and the reply is received
1110 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1111 * @srccls: source class of message
1112 * @buffer: address of send buffer or address of struct iucv_array
1113 * @size: length of send buffer
1114 * @ansbuf: address of answer buffer or address of struct iucv_array
1115 * @asize: size of reply buffer
1117 * This function transmits data to another application. Data to be
1118 * transmitted is in a buffer. The receiver of the send is expected to
1119 * reply to the message and a buffer is provided into which IUCV moves
1120 * the reply to this message.
1122 * Returns the result from the CP IUCV call.
1124 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1125 u8 flags, u32 srccls, void *buffer, size_t size,
1126 void *answer, size_t asize, size_t *residual)
1128 union iucv_param *parm;
1132 parm = percpu_ptr(iucv_param, smp_processor_id());
1133 memset(parm, 0, sizeof(union iucv_param));
1134 if (flags & IUCV_IPRMDATA) {
1135 parm->dpl.ippathid = path->pathid;
1136 parm->dpl.ipflags1 = path->flags; /* priority message */
1137 parm->dpl.iptrgcls = msg->class;
1138 parm->dpl.ipsrccls = srccls;
1139 parm->dpl.ipmsgtag = msg->tag;
1140 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1141 parm->dpl.ipbfln2f = (u32) asize;
1142 memcpy(parm->dpl.iprmmsg, buffer, 8);
1144 parm->db.ippathid = path->pathid;
1145 parm->db.ipflags1 = path->flags; /* priority message */
1146 parm->db.iptrgcls = msg->class;
1147 parm->db.ipsrccls = srccls;
1148 parm->db.ipmsgtag = msg->tag;
1149 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1150 parm->db.ipbfln1f = (u32) size;
1151 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1152 parm->db.ipbfln2f = (u32) asize;
1154 rc = iucv_call_b2f0(IUCV_SEND, parm);
1156 msg->id = parm->db.ipmsgid;
1163 * @data: Pointer to external interrupt buffer
1165 * Process connection pending work item. Called from tasklet while holding
1168 struct iucv_path_pending {
1179 } __attribute__ ((packed));
1181 static void iucv_path_pending(struct iucv_irq_data *data)
1183 struct iucv_path_pending *ipp = (void *) data;
1184 struct iucv_handler *handler;
1185 struct iucv_path *path;
1188 BUG_ON(iucv_path_table[ipp->ippathid]);
1189 /* New pathid, handler found. Create a new path struct. */
1190 error = iucv_error_no_memory;
1191 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1194 path->pathid = ipp->ippathid;
1195 iucv_path_table[path->pathid] = path;
1196 EBCASC(ipp->ipvmid, 8);
1198 /* Call registered handler until one is found that wants the path. */
1199 list_for_each_entry(handler, &iucv_handler_list, list) {
1200 if (!handler->path_pending)
1203 * Add path to handler to allow a call to iucv_path_sever
1204 * inside the path_pending function. If the handler returns
1205 * an error remove the path from the handler again.
1207 list_add(&path->list, &handler->paths);
1208 path->handler = handler;
1209 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1211 list_del(&path->list);
1212 path->handler = NULL;
1214 /* No handler wanted the path. */
1215 iucv_path_table[path->pathid] = NULL;
1216 iucv_path_free(path);
1217 error = iucv_error_no_listener;
1219 iucv_sever_pathid(ipp->ippathid, error);
1223 * iucv_path_complete
1224 * @data: Pointer to external interrupt buffer
1226 * Process connection complete work item. Called from tasklet while holding
1229 struct iucv_path_complete {
1240 } __attribute__ ((packed));
1242 static void iucv_path_complete(struct iucv_irq_data *data)
1244 struct iucv_path_complete *ipc = (void *) data;
1245 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1247 BUG_ON(!path || !path->handler);
1248 if (path->handler->path_complete)
1249 path->handler->path_complete(path, ipc->ipuser);
1254 * @data: Pointer to external interrupt buffer
1256 * Process connection severed work item. Called from tasklet while holding
1259 struct iucv_path_severed {
1269 } __attribute__ ((packed));
1271 static void iucv_path_severed(struct iucv_irq_data *data)
1273 struct iucv_path_severed *ips = (void *) data;
1274 struct iucv_path *path = iucv_path_table[ips->ippathid];
1276 BUG_ON(!path || !path->handler);
1277 if (path->handler->path_severed)
1278 path->handler->path_severed(path, ips->ipuser);
1280 iucv_sever_pathid(path->pathid, NULL);
1281 iucv_path_table[path->pathid] = NULL;
1282 list_del_init(&path->list);
1283 iucv_cleanup_pathid(path->pathid);
1284 iucv_path_free(path);
1289 * iucv_path_quiesced
1290 * @data: Pointer to external interrupt buffer
1292 * Process connection quiesced work item. Called from tasklet while holding
1295 struct iucv_path_quiesced {
1305 } __attribute__ ((packed));
1307 static void iucv_path_quiesced(struct iucv_irq_data *data)
1309 struct iucv_path_quiesced *ipq = (void *) data;
1310 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1312 BUG_ON(!path || !path->handler);
1313 if (path->handler->path_quiesced)
1314 path->handler->path_quiesced(path, ipq->ipuser);
1319 * @data: Pointer to external interrupt buffer
1321 * Process connection resumed work item. Called from tasklet while holding
1324 struct iucv_path_resumed {
1334 } __attribute__ ((packed));
1336 static void iucv_path_resumed(struct iucv_irq_data *data)
1338 struct iucv_path_resumed *ipr = (void *) data;
1339 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1341 BUG_ON(!path || !path->handler);
1342 if (path->handler->path_resumed)
1343 path->handler->path_resumed(path, ipr->ipuser);
1347 * iucv_message_complete
1348 * @data: Pointer to external interrupt buffer
1350 * Process message complete work item. Called from tasklet while holding
1353 struct iucv_message_complete {
1366 } __attribute__ ((packed));
1368 static void iucv_message_complete(struct iucv_irq_data *data)
1370 struct iucv_message_complete *imc = (void *) data;
1371 struct iucv_path *path = iucv_path_table[imc->ippathid];
1372 struct iucv_message msg;
1374 BUG_ON(!path || !path->handler);
1375 if (path->handler->message_complete) {
1376 msg.flags = imc->ipflags1;
1377 msg.id = imc->ipmsgid;
1378 msg.audit = imc->ipaudit;
1379 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1380 msg.class = imc->ipsrccls;
1381 msg.tag = imc->ipmsgtag;
1382 msg.length = imc->ipbfln2f;
1383 path->handler->message_complete(path, &msg);
1388 * iucv_message_pending
1389 * @data: Pointer to external interrupt buffer
1391 * Process message pending work item. Called from tasklet while holding
1394 struct iucv_message_pending {
1412 } __attribute__ ((packed));
1414 static void iucv_message_pending(struct iucv_irq_data *data)
1416 struct iucv_message_pending *imp = (void *) data;
1417 struct iucv_path *path = iucv_path_table[imp->ippathid];
1418 struct iucv_message msg;
1420 BUG_ON(!path || !path->handler);
1421 if (path->handler->message_pending) {
1422 msg.flags = imp->ipflags1;
1423 msg.id = imp->ipmsgid;
1424 msg.class = imp->iptrgcls;
1425 if (imp->ipflags1 & IUCV_IPRMDATA) {
1426 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1429 msg.length = imp->ln1msg2.ipbfln1f;
1430 msg.reply_size = imp->ipbfln2f;
1431 path->handler->message_pending(path, &msg);
1436 * iucv_tasklet_handler:
1438 * This tasklet loops over the queue of irq buffers created by
1439 * iucv_external_interrupt, calls the appropriate action handler
1440 * and then frees the buffer.
1442 static void iucv_tasklet_handler(unsigned long ignored)
1444 typedef void iucv_irq_fn(struct iucv_irq_data *);
1445 static iucv_irq_fn *irq_fn[] = {
1446 [0x01] = iucv_path_pending,
1447 [0x02] = iucv_path_complete,
1448 [0x03] = iucv_path_severed,
1449 [0x04] = iucv_path_quiesced,
1450 [0x05] = iucv_path_resumed,
1451 [0x06] = iucv_message_complete,
1452 [0x07] = iucv_message_complete,
1453 [0x08] = iucv_message_pending,
1454 [0x09] = iucv_message_pending,
1456 struct iucv_work *p;
1458 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1459 spin_lock(&iucv_table_lock);
1460 iucv_tasklet_cpu = smp_processor_id();
1462 spin_lock_irq(&iucv_work_lock);
1463 while (!list_empty(&iucv_work_queue)) {
1464 p = list_entry(iucv_work_queue.next, struct iucv_work, list);
1465 list_del_init(&p->list);
1466 spin_unlock_irq(&iucv_work_lock);
1467 irq_fn[p->data.iptype](&p->data);
1469 spin_lock_irq(&iucv_work_lock);
1471 spin_unlock_irq(&iucv_work_lock);
1473 iucv_tasklet_cpu = -1;
1474 spin_unlock(&iucv_table_lock);
1478 * iucv_external_interrupt
1481 * Handles external interrupts coming in from CP.
1482 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
1484 static void iucv_external_interrupt(u16 code)
1486 struct iucv_irq_data *p;
1487 struct iucv_work *work;
1489 p = percpu_ptr(iucv_irq_data, smp_processor_id());
1490 if (p->ippathid >= iucv_max_pathid) {
1491 printk(KERN_WARNING "iucv_do_int: Got interrupt with "
1492 "pathid %d > max_connections (%ld)\n",
1493 p->ippathid, iucv_max_pathid - 1);
1494 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1497 if (p->iptype < 0x01 || p->iptype > 0x09) {
1498 printk(KERN_ERR "iucv_do_int: unknown iucv interrupt\n");
1501 work = kmalloc(sizeof(struct iucv_work), GFP_ATOMIC);
1503 printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
1506 memcpy(&work->data, p, sizeof(work->data));
1507 spin_lock(&iucv_work_lock);
1508 list_add_tail(&work->list, &iucv_work_queue);
1509 spin_unlock(&iucv_work_lock);
1510 tasklet_schedule(&iucv_tasklet);
1516 * Allocates and initializes various data structures.
1518 static int iucv_init(void)
1522 if (!MACHINE_IS_VM) {
1523 rc = -EPROTONOSUPPORT;
1526 rc = iucv_query_maxconn();
1529 rc = register_external_interrupt (0x4000, iucv_external_interrupt);
1532 rc = bus_register(&iucv_bus);
1535 iucv_root = s390_root_dev_register("iucv");
1536 if (IS_ERR(iucv_root)) {
1537 rc = PTR_ERR(iucv_root);
1540 /* Note: GFP_DMA used used to get memory below 2G */
1541 iucv_irq_data = percpu_alloc(sizeof(struct iucv_irq_data),
1542 GFP_KERNEL|GFP_DMA);
1543 if (!iucv_irq_data) {
1547 /* Allocate parameter blocks. */
1548 iucv_param = percpu_alloc(sizeof(union iucv_param),
1549 GFP_KERNEL|GFP_DMA);
1554 register_hotcpu_notifier(&iucv_cpu_notifier);
1555 ASCEBC(iucv_error_no_listener, 16);
1556 ASCEBC(iucv_error_no_memory, 16);
1557 ASCEBC(iucv_error_pathid, 16);
1562 percpu_free(iucv_irq_data);
1564 s390_root_dev_unregister(iucv_root);
1566 bus_unregister(&iucv_bus);
1568 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1576 * Frees everything allocated from iucv_init.
1578 static void iucv_exit(void)
1580 struct iucv_work *p, *n;
1582 spin_lock_irq(&iucv_work_lock);
1583 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1585 spin_unlock_irq(&iucv_work_lock);
1586 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1587 percpu_free(iucv_param);
1588 percpu_free(iucv_irq_data);
1589 s390_root_dev_unregister(iucv_root);
1590 bus_unregister(&iucv_bus);
1591 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1594 subsys_initcall(iucv_init);
1595 module_exit(iucv_exit);
1598 * Export all public stuff
1600 EXPORT_SYMBOL (iucv_bus);
1601 EXPORT_SYMBOL (iucv_root);
1602 EXPORT_SYMBOL (iucv_register);
1603 EXPORT_SYMBOL (iucv_unregister);
1604 EXPORT_SYMBOL (iucv_path_accept);
1605 EXPORT_SYMBOL (iucv_path_connect);
1606 EXPORT_SYMBOL (iucv_path_quiesce);
1607 EXPORT_SYMBOL (iucv_path_sever);
1608 EXPORT_SYMBOL (iucv_message_purge);
1609 EXPORT_SYMBOL (iucv_message_receive);
1610 EXPORT_SYMBOL (iucv_message_reject);
1611 EXPORT_SYMBOL (iucv_message_reply);
1612 EXPORT_SYMBOL (iucv_message_send);
1613 EXPORT_SYMBOL (iucv_message_send2way);
1615 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1616 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1617 MODULE_LICENSE("GPL");