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 #ifdef CONFIG_HOTPLUG_CPU
523 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
524 unsigned long action, void *hcpu)
527 long cpu = (long) hcpu;
531 if (!percpu_populate(iucv_irq_data,
532 sizeof(struct iucv_irq_data),
533 GFP_KERNEL|GFP_DMA, cpu))
535 if (!percpu_populate(iucv_param, sizeof(union iucv_param),
536 GFP_KERNEL|GFP_DMA, cpu)) {
537 percpu_depopulate(iucv_irq_data, cpu);
541 case CPU_UP_CANCELED:
543 percpu_depopulate(iucv_param, cpu);
544 percpu_depopulate(iucv_irq_data, cpu);
547 case CPU_DOWN_FAILED:
548 smp_call_function_on(iucv_declare_cpu, NULL, 0, 1, cpu);
550 case CPU_DOWN_PREPARE:
551 cpumask = iucv_buffer_cpumask;
552 cpu_clear(cpu, cpumask);
553 if (cpus_empty(cpumask))
554 /* Can't offline last IUCV enabled cpu. */
556 smp_call_function_on(iucv_retrieve_cpu, NULL, 0, 1, cpu);
557 if (cpus_empty(iucv_irq_cpumask))
558 smp_call_function_on(iucv_allow_cpu, NULL, 0, 1,
559 first_cpu(iucv_buffer_cpumask));
565 static struct notifier_block iucv_cpu_notifier = {
566 .notifier_call = iucv_cpu_notify,
572 * @pathid: path identification number.
573 * @userdata: 16-bytes of user data.
575 * Sever an iucv path to free up the pathid. Used internally.
577 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
579 union iucv_param *parm;
581 parm = percpu_ptr(iucv_param, smp_processor_id());
582 memset(parm, 0, sizeof(union iucv_param));
584 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
585 parm->ctrl.ippathid = pathid;
586 return iucv_call_b2f0(IUCV_SEVER, parm);
590 * __iucv_cleanup_pathid
591 * @dummy: unused dummy argument
593 * Nop function called via smp_call_function to force work items from
594 * pending external iucv interrupts to the work queue.
596 static void __iucv_cleanup_pathid(void *dummy)
601 * iucv_cleanup_pathid
602 * @pathid: 16 bit pathid
604 * Function called after a path has been severed to find all remaining
605 * work items for the now stale pathid. The caller needs to hold the
608 static void iucv_cleanup_pathid(u16 pathid)
610 struct iucv_work *p, *n;
613 * Path is severed, the pathid can be reused immediatly on
614 * a iucv connect or a connection pending interrupt.
615 * iucv_path_connect and connection pending interrupt will
616 * wait until the iucv_table_lock is released before the
617 * recycled pathid enters the system.
618 * Force remaining interrupts to the work queue, then
619 * scan the work queue for items of this path.
621 smp_call_function(__iucv_cleanup_pathid, NULL, 0, 1);
622 spin_lock_irq(&iucv_work_lock);
623 list_for_each_entry_safe(p, n, &iucv_work_queue, list) {
624 /* Remove work items for pathid except connection pending */
625 if (p->data.ippathid == pathid && p->data.iptype != 0x01) {
630 spin_unlock_irq(&iucv_work_lock);
635 * @handler: address of iucv handler structure
636 * @smp: != 0 indicates that the handler can deal with out of order messages
638 * Registers a driver with IUCV.
640 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
641 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
643 int iucv_register(struct iucv_handler *handler, int smp)
649 mutex_lock(&iucv_register_mutex);
651 iucv_nonsmp_handler++;
652 if (list_empty(&iucv_handler_list)) {
656 } else if (!smp && iucv_nonsmp_handler == 1)
658 INIT_LIST_HEAD(&handler->paths);
660 spin_lock_irq(&iucv_table_lock);
661 list_add_tail(&handler->list, &iucv_handler_list);
662 spin_unlock_irq(&iucv_table_lock);
665 mutex_unlock(&iucv_register_mutex);
671 * @handler: address of iucv handler structure
672 * @smp: != 0 indicates that the handler can deal with out of order messages
674 * Unregister driver from IUCV.
676 void iucv_unregister(struct iucv_handler *handler, int smp)
678 struct iucv_path *p, *n;
680 mutex_lock(&iucv_register_mutex);
681 spin_lock_bh(&iucv_table_lock);
682 /* Remove handler from the iucv_handler_list. */
683 list_del_init(&handler->list);
684 /* Sever all pathids still refering to the handler. */
685 list_for_each_entry_safe(p, n, &handler->paths, list) {
686 iucv_sever_pathid(p->pathid, NULL);
687 iucv_path_table[p->pathid] = NULL;
689 iucv_cleanup_pathid(p->pathid);
692 spin_unlock_bh(&iucv_table_lock);
694 iucv_nonsmp_handler--;
695 if (list_empty(&iucv_handler_list))
697 else if (!smp && iucv_nonsmp_handler == 0)
699 mutex_unlock(&iucv_register_mutex);
704 * @path: address of iucv path structure
705 * @handler: address of iucv handler structure
706 * @userdata: 16 bytes of data reflected to the communication partner
707 * @private: private data passed to interrupt handlers for this path
709 * This function is issued after the user received a connection pending
710 * external interrupt and now wishes to complete the IUCV communication path.
712 * Returns the result of the CP IUCV call.
714 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
715 u8 userdata[16], void *private)
717 union iucv_param *parm;
721 /* Prepare parameter block. */
722 parm = percpu_ptr(iucv_param, smp_processor_id());
723 memset(parm, 0, sizeof(union iucv_param));
724 parm->ctrl.ippathid = path->pathid;
725 parm->ctrl.ipmsglim = path->msglim;
727 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
728 parm->ctrl.ipflags1 = path->flags;
730 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
732 path->private = private;
733 path->msglim = parm->ctrl.ipmsglim;
734 path->flags = parm->ctrl.ipflags1;
742 * @path: address of iucv path structure
743 * @handler: address of iucv handler structure
744 * @userid: 8-byte user identification
745 * @system: 8-byte target system identification
746 * @userdata: 16 bytes of data reflected to the communication partner
747 * @private: private data passed to interrupt handlers for this path
749 * This function establishes an IUCV path. Although the connect may complete
750 * successfully, you are not able to use the path until you receive an IUCV
751 * Connection Complete external interrupt.
753 * Returns the result of the CP IUCV call.
755 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
756 u8 userid[8], u8 system[8], u8 userdata[16],
759 union iucv_param *parm;
763 if (iucv_tasklet_cpu != smp_processor_id())
764 spin_lock_bh(&iucv_table_lock);
765 parm = percpu_ptr(iucv_param, smp_processor_id());
766 memset(parm, 0, sizeof(union iucv_param));
767 parm->ctrl.ipmsglim = path->msglim;
768 parm->ctrl.ipflags1 = path->flags;
770 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
771 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
772 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
775 memcpy(parm->ctrl.iptarget, system,
776 sizeof(parm->ctrl.iptarget));
777 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
778 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
781 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
783 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
785 if (parm->ctrl.ippathid < iucv_max_pathid) {
786 path->pathid = parm->ctrl.ippathid;
787 path->msglim = parm->ctrl.ipmsglim;
788 path->flags = parm->ctrl.ipflags1;
789 path->handler = handler;
790 path->private = private;
791 list_add_tail(&path->list, &handler->paths);
792 iucv_path_table[path->pathid] = path;
794 iucv_sever_pathid(parm->ctrl.ippathid,
799 if (iucv_tasklet_cpu != smp_processor_id())
800 spin_unlock_bh(&iucv_table_lock);
807 * @path: address of iucv path structure
808 * @userdata: 16 bytes of data reflected to the communication partner
810 * This function temporarily suspends incoming messages on an IUCV path.
811 * You can later reactivate the path by invoking the iucv_resume function.
813 * Returns the result from the CP IUCV call.
815 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
817 union iucv_param *parm;
821 parm = percpu_ptr(iucv_param, smp_processor_id());
822 memset(parm, 0, sizeof(union iucv_param));
824 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
825 parm->ctrl.ippathid = path->pathid;
826 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
833 * @path: address of iucv path structure
834 * @userdata: 16 bytes of data reflected to the communication partner
836 * This function resumes incoming messages on an IUCV path that has
837 * been stopped with iucv_path_quiesce.
839 * Returns the result from the CP IUCV call.
841 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
843 union iucv_param *parm;
847 parm = percpu_ptr(iucv_param, smp_processor_id());
848 memset(parm, 0, sizeof(union iucv_param));
850 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
851 parm->ctrl.ippathid = path->pathid;
852 rc = iucv_call_b2f0(IUCV_RESUME, parm);
859 * @path: address of iucv path structure
860 * @userdata: 16 bytes of data reflected to the communication partner
862 * This function terminates an IUCV path.
864 * Returns the result from the CP IUCV call.
866 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
872 if (iucv_tasklet_cpu != smp_processor_id())
873 spin_lock_bh(&iucv_table_lock);
874 rc = iucv_sever_pathid(path->pathid, userdata);
876 iucv_path_table[path->pathid] = NULL;
877 list_del_init(&path->list);
878 iucv_cleanup_pathid(path->pathid);
880 if (iucv_tasklet_cpu != smp_processor_id())
881 spin_unlock_bh(&iucv_table_lock);
888 * @path: address of iucv path structure
889 * @msg: address of iucv msg structure
890 * @srccls: source class of message
892 * Cancels a message you have sent.
894 * Returns the result from the CP IUCV call.
896 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
899 union iucv_param *parm;
903 parm = percpu_ptr(iucv_param, smp_processor_id());
904 memset(parm, 0, sizeof(union iucv_param));
905 parm->purge.ippathid = path->pathid;
906 parm->purge.ipmsgid = msg->id;
907 parm->purge.ipsrccls = srccls;
908 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
909 rc = iucv_call_b2f0(IUCV_PURGE, parm);
911 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
912 msg->tag = parm->purge.ipmsgtag;
919 * iucv_message_receive
920 * @path: address of iucv path structure
921 * @msg: address of iucv msg structure
922 * @flags: how the message is received (IUCV_IPBUFLST)
923 * @buffer: address of data buffer or address of struct iucv_array
924 * @size: length of data buffer
927 * This function receives messages that are being sent to you over
928 * established paths. This function will deal with RMDATA messages
929 * embedded in struct iucv_message as well.
931 * Returns the result from the CP IUCV call.
933 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
934 u8 flags, void *buffer, size_t size, size_t *residual)
936 union iucv_param *parm;
937 struct iucv_array *array;
942 if (msg->flags & IUCV_IPRMDATA) {
944 * Message is 8 bytes long and has been stored to the
945 * message descriptor itself.
947 rc = (size < 8) ? 5 : 0;
949 *residual = abs(size - 8);
951 if (flags & IUCV_IPBUFLST) {
952 /* Copy to struct iucv_array. */
953 size = (size < 8) ? size : 8;
954 for (array = buffer; size > 0; array++) {
955 copy = min_t(size_t, size, array->length);
956 memcpy((u8 *)(addr_t) array->address,
962 /* Copy to direct buffer. */
963 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
969 parm = percpu_ptr(iucv_param, smp_processor_id());
970 memset(parm, 0, sizeof(union iucv_param));
971 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
972 parm->db.ipbfln1f = (u32) size;
973 parm->db.ipmsgid = msg->id;
974 parm->db.ippathid = path->pathid;
975 parm->db.iptrgcls = msg->class;
976 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
977 IUCV_IPFGMID | IUCV_IPTRGCLS);
978 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
979 if (!rc || rc == 5) {
980 msg->flags = parm->db.ipflags1;
982 *residual = parm->db.ipbfln1f;
989 * iucv_message_reject
990 * @path: address of iucv path structure
991 * @msg: address of iucv msg structure
993 * The reject function refuses a specified message. Between the time you
994 * are notified of a message and the time that you complete the message,
995 * the message may be rejected.
997 * Returns the result from the CP IUCV call.
999 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1001 union iucv_param *parm;
1005 parm = percpu_ptr(iucv_param, smp_processor_id());
1006 memset(parm, 0, sizeof(union iucv_param));
1007 parm->db.ippathid = path->pathid;
1008 parm->db.ipmsgid = msg->id;
1009 parm->db.iptrgcls = msg->class;
1010 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1011 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1017 * iucv_message_reply
1018 * @path: address of iucv path structure
1019 * @msg: address of iucv msg structure
1020 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1021 * @reply: address of reply data buffer or address of struct iucv_array
1022 * @size: length of reply data buffer
1024 * This function responds to the two-way messages that you receive. You
1025 * must identify completely the message to which you wish to reply. ie,
1026 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1027 * the parameter list.
1029 * Returns the result from the CP IUCV call.
1031 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1032 u8 flags, void *reply, size_t size)
1034 union iucv_param *parm;
1038 parm = percpu_ptr(iucv_param, smp_processor_id());
1039 memset(parm, 0, sizeof(union iucv_param));
1040 if (flags & IUCV_IPRMDATA) {
1041 parm->dpl.ippathid = path->pathid;
1042 parm->dpl.ipflags1 = flags;
1043 parm->dpl.ipmsgid = msg->id;
1044 parm->dpl.iptrgcls = msg->class;
1045 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1047 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1048 parm->db.ipbfln1f = (u32) size;
1049 parm->db.ippathid = path->pathid;
1050 parm->db.ipflags1 = flags;
1051 parm->db.ipmsgid = msg->id;
1052 parm->db.iptrgcls = msg->class;
1054 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1061 * @path: address of iucv path structure
1062 * @msg: address of iucv msg structure
1063 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1064 * @srccls: source class of message
1065 * @buffer: address of send buffer or address of struct iucv_array
1066 * @size: length of send buffer
1068 * This function transmits data to another application. Data to be
1069 * transmitted is in a buffer and this is a one-way message and the
1070 * receiver will not reply to the message.
1072 * Returns the result from the CP IUCV call.
1074 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1075 u8 flags, u32 srccls, void *buffer, size_t size)
1077 union iucv_param *parm;
1081 parm = percpu_ptr(iucv_param, smp_processor_id());
1082 memset(parm, 0, sizeof(union iucv_param));
1083 if (flags & IUCV_IPRMDATA) {
1084 /* Message of 8 bytes can be placed into the parameter list. */
1085 parm->dpl.ippathid = path->pathid;
1086 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1087 parm->dpl.iptrgcls = msg->class;
1088 parm->dpl.ipsrccls = srccls;
1089 parm->dpl.ipmsgtag = msg->tag;
1090 memcpy(parm->dpl.iprmmsg, buffer, 8);
1092 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1093 parm->db.ipbfln1f = (u32) size;
1094 parm->db.ippathid = path->pathid;
1095 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1096 parm->db.iptrgcls = msg->class;
1097 parm->db.ipsrccls = srccls;
1098 parm->db.ipmsgtag = msg->tag;
1100 rc = iucv_call_b2f0(IUCV_SEND, parm);
1102 msg->id = parm->db.ipmsgid;
1108 * iucv_message_send2way
1109 * @path: address of iucv path structure
1110 * @msg: address of iucv msg structure
1111 * @flags: how the message is sent and the reply is received
1112 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1113 * @srccls: source class of message
1114 * @buffer: address of send buffer or address of struct iucv_array
1115 * @size: length of send buffer
1116 * @ansbuf: address of answer buffer or address of struct iucv_array
1117 * @asize: size of reply buffer
1119 * This function transmits data to another application. Data to be
1120 * transmitted is in a buffer. The receiver of the send is expected to
1121 * reply to the message and a buffer is provided into which IUCV moves
1122 * the reply to this message.
1124 * Returns the result from the CP IUCV call.
1126 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1127 u8 flags, u32 srccls, void *buffer, size_t size,
1128 void *answer, size_t asize, size_t *residual)
1130 union iucv_param *parm;
1134 parm = percpu_ptr(iucv_param, smp_processor_id());
1135 memset(parm, 0, sizeof(union iucv_param));
1136 if (flags & IUCV_IPRMDATA) {
1137 parm->dpl.ippathid = path->pathid;
1138 parm->dpl.ipflags1 = path->flags; /* priority message */
1139 parm->dpl.iptrgcls = msg->class;
1140 parm->dpl.ipsrccls = srccls;
1141 parm->dpl.ipmsgtag = msg->tag;
1142 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1143 parm->dpl.ipbfln2f = (u32) asize;
1144 memcpy(parm->dpl.iprmmsg, buffer, 8);
1146 parm->db.ippathid = path->pathid;
1147 parm->db.ipflags1 = path->flags; /* priority message */
1148 parm->db.iptrgcls = msg->class;
1149 parm->db.ipsrccls = srccls;
1150 parm->db.ipmsgtag = msg->tag;
1151 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1152 parm->db.ipbfln1f = (u32) size;
1153 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1154 parm->db.ipbfln2f = (u32) asize;
1156 rc = iucv_call_b2f0(IUCV_SEND, parm);
1158 msg->id = parm->db.ipmsgid;
1165 * @data: Pointer to external interrupt buffer
1167 * Process connection pending work item. Called from tasklet while holding
1170 struct iucv_path_pending {
1181 } __attribute__ ((packed));
1183 static void iucv_path_pending(struct iucv_irq_data *data)
1185 struct iucv_path_pending *ipp = (void *) data;
1186 struct iucv_handler *handler;
1187 struct iucv_path *path;
1190 BUG_ON(iucv_path_table[ipp->ippathid]);
1191 /* New pathid, handler found. Create a new path struct. */
1192 error = iucv_error_no_memory;
1193 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1196 path->pathid = ipp->ippathid;
1197 iucv_path_table[path->pathid] = path;
1198 EBCASC(ipp->ipvmid, 8);
1200 /* Call registered handler until one is found that wants the path. */
1201 list_for_each_entry(handler, &iucv_handler_list, list) {
1202 if (!handler->path_pending)
1205 * Add path to handler to allow a call to iucv_path_sever
1206 * inside the path_pending function. If the handler returns
1207 * an error remove the path from the handler again.
1209 list_add(&path->list, &handler->paths);
1210 path->handler = handler;
1211 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1213 list_del(&path->list);
1214 path->handler = NULL;
1216 /* No handler wanted the path. */
1217 iucv_path_table[path->pathid] = NULL;
1218 iucv_path_free(path);
1219 error = iucv_error_no_listener;
1221 iucv_sever_pathid(ipp->ippathid, error);
1225 * iucv_path_complete
1226 * @data: Pointer to external interrupt buffer
1228 * Process connection complete work item. Called from tasklet while holding
1231 struct iucv_path_complete {
1242 } __attribute__ ((packed));
1244 static void iucv_path_complete(struct iucv_irq_data *data)
1246 struct iucv_path_complete *ipc = (void *) data;
1247 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1249 BUG_ON(!path || !path->handler);
1250 if (path->handler->path_complete)
1251 path->handler->path_complete(path, ipc->ipuser);
1256 * @data: Pointer to external interrupt buffer
1258 * Process connection severed work item. Called from tasklet while holding
1261 struct iucv_path_severed {
1271 } __attribute__ ((packed));
1273 static void iucv_path_severed(struct iucv_irq_data *data)
1275 struct iucv_path_severed *ips = (void *) data;
1276 struct iucv_path *path = iucv_path_table[ips->ippathid];
1278 BUG_ON(!path || !path->handler);
1279 if (path->handler->path_severed)
1280 path->handler->path_severed(path, ips->ipuser);
1282 iucv_sever_pathid(path->pathid, NULL);
1283 iucv_path_table[path->pathid] = NULL;
1284 list_del_init(&path->list);
1285 iucv_cleanup_pathid(path->pathid);
1286 iucv_path_free(path);
1291 * iucv_path_quiesced
1292 * @data: Pointer to external interrupt buffer
1294 * Process connection quiesced work item. Called from tasklet while holding
1297 struct iucv_path_quiesced {
1307 } __attribute__ ((packed));
1309 static void iucv_path_quiesced(struct iucv_irq_data *data)
1311 struct iucv_path_quiesced *ipq = (void *) data;
1312 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1314 BUG_ON(!path || !path->handler);
1315 if (path->handler->path_quiesced)
1316 path->handler->path_quiesced(path, ipq->ipuser);
1321 * @data: Pointer to external interrupt buffer
1323 * Process connection resumed work item. Called from tasklet while holding
1326 struct iucv_path_resumed {
1336 } __attribute__ ((packed));
1338 static void iucv_path_resumed(struct iucv_irq_data *data)
1340 struct iucv_path_resumed *ipr = (void *) data;
1341 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1343 BUG_ON(!path || !path->handler);
1344 if (path->handler->path_resumed)
1345 path->handler->path_resumed(path, ipr->ipuser);
1349 * iucv_message_complete
1350 * @data: Pointer to external interrupt buffer
1352 * Process message complete work item. Called from tasklet while holding
1355 struct iucv_message_complete {
1368 } __attribute__ ((packed));
1370 static void iucv_message_complete(struct iucv_irq_data *data)
1372 struct iucv_message_complete *imc = (void *) data;
1373 struct iucv_path *path = iucv_path_table[imc->ippathid];
1374 struct iucv_message msg;
1376 BUG_ON(!path || !path->handler);
1377 if (path->handler->message_complete) {
1378 msg.flags = imc->ipflags1;
1379 msg.id = imc->ipmsgid;
1380 msg.audit = imc->ipaudit;
1381 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1382 msg.class = imc->ipsrccls;
1383 msg.tag = imc->ipmsgtag;
1384 msg.length = imc->ipbfln2f;
1385 path->handler->message_complete(path, &msg);
1390 * iucv_message_pending
1391 * @data: Pointer to external interrupt buffer
1393 * Process message pending work item. Called from tasklet while holding
1396 struct iucv_message_pending {
1414 } __attribute__ ((packed));
1416 static void iucv_message_pending(struct iucv_irq_data *data)
1418 struct iucv_message_pending *imp = (void *) data;
1419 struct iucv_path *path = iucv_path_table[imp->ippathid];
1420 struct iucv_message msg;
1422 BUG_ON(!path || !path->handler);
1423 if (path->handler->message_pending) {
1424 msg.flags = imp->ipflags1;
1425 msg.id = imp->ipmsgid;
1426 msg.class = imp->iptrgcls;
1427 if (imp->ipflags1 & IUCV_IPRMDATA) {
1428 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1431 msg.length = imp->ln1msg2.ipbfln1f;
1432 msg.reply_size = imp->ipbfln2f;
1433 path->handler->message_pending(path, &msg);
1438 * iucv_tasklet_handler:
1440 * This tasklet loops over the queue of irq buffers created by
1441 * iucv_external_interrupt, calls the appropriate action handler
1442 * and then frees the buffer.
1444 static void iucv_tasklet_handler(unsigned long ignored)
1446 typedef void iucv_irq_fn(struct iucv_irq_data *);
1447 static iucv_irq_fn *irq_fn[] = {
1448 [0x01] = iucv_path_pending,
1449 [0x02] = iucv_path_complete,
1450 [0x03] = iucv_path_severed,
1451 [0x04] = iucv_path_quiesced,
1452 [0x05] = iucv_path_resumed,
1453 [0x06] = iucv_message_complete,
1454 [0x07] = iucv_message_complete,
1455 [0x08] = iucv_message_pending,
1456 [0x09] = iucv_message_pending,
1458 struct iucv_work *p;
1460 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1461 spin_lock(&iucv_table_lock);
1462 iucv_tasklet_cpu = smp_processor_id();
1464 spin_lock_irq(&iucv_work_lock);
1465 while (!list_empty(&iucv_work_queue)) {
1466 p = list_entry(iucv_work_queue.next, struct iucv_work, list);
1467 list_del_init(&p->list);
1468 spin_unlock_irq(&iucv_work_lock);
1469 irq_fn[p->data.iptype](&p->data);
1471 spin_lock_irq(&iucv_work_lock);
1473 spin_unlock_irq(&iucv_work_lock);
1475 iucv_tasklet_cpu = -1;
1476 spin_unlock(&iucv_table_lock);
1480 * iucv_external_interrupt
1483 * Handles external interrupts coming in from CP.
1484 * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
1486 static void iucv_external_interrupt(u16 code)
1488 struct iucv_irq_data *p;
1489 struct iucv_work *work;
1491 p = percpu_ptr(iucv_irq_data, smp_processor_id());
1492 if (p->ippathid >= iucv_max_pathid) {
1493 printk(KERN_WARNING "iucv_do_int: Got interrupt with "
1494 "pathid %d > max_connections (%ld)\n",
1495 p->ippathid, iucv_max_pathid - 1);
1496 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1499 if (p->iptype < 0x01 || p->iptype > 0x09) {
1500 printk(KERN_ERR "iucv_do_int: unknown iucv interrupt\n");
1503 work = kmalloc(sizeof(struct iucv_work), GFP_ATOMIC);
1505 printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
1508 memcpy(&work->data, p, sizeof(work->data));
1509 spin_lock(&iucv_work_lock);
1510 list_add_tail(&work->list, &iucv_work_queue);
1511 spin_unlock(&iucv_work_lock);
1512 tasklet_schedule(&iucv_tasklet);
1518 * Allocates and initializes various data structures.
1520 static int iucv_init(void)
1524 if (!MACHINE_IS_VM) {
1525 rc = -EPROTONOSUPPORT;
1528 rc = iucv_query_maxconn();
1531 rc = register_external_interrupt (0x4000, iucv_external_interrupt);
1534 rc = bus_register(&iucv_bus);
1537 iucv_root = s390_root_dev_register("iucv");
1538 if (IS_ERR(iucv_root)) {
1539 rc = PTR_ERR(iucv_root);
1542 /* Note: GFP_DMA used used to get memory below 2G */
1543 iucv_irq_data = percpu_alloc(sizeof(struct iucv_irq_data),
1544 GFP_KERNEL|GFP_DMA);
1545 if (!iucv_irq_data) {
1549 /* Allocate parameter blocks. */
1550 iucv_param = percpu_alloc(sizeof(union iucv_param),
1551 GFP_KERNEL|GFP_DMA);
1556 register_hotcpu_notifier(&iucv_cpu_notifier);
1557 ASCEBC(iucv_error_no_listener, 16);
1558 ASCEBC(iucv_error_no_memory, 16);
1559 ASCEBC(iucv_error_pathid, 16);
1564 percpu_free(iucv_irq_data);
1566 s390_root_dev_unregister(iucv_root);
1568 bus_unregister(&iucv_bus);
1570 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1578 * Frees everything allocated from iucv_init.
1580 static void iucv_exit(void)
1582 struct iucv_work *p, *n;
1584 spin_lock_irq(&iucv_work_lock);
1585 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1587 spin_unlock_irq(&iucv_work_lock);
1588 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1589 percpu_free(iucv_param);
1590 percpu_free(iucv_irq_data);
1591 s390_root_dev_unregister(iucv_root);
1592 bus_unregister(&iucv_bus);
1593 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1596 subsys_initcall(iucv_init);
1597 module_exit(iucv_exit);
1600 * Export all public stuff
1602 EXPORT_SYMBOL (iucv_bus);
1603 EXPORT_SYMBOL (iucv_root);
1604 EXPORT_SYMBOL (iucv_register);
1605 EXPORT_SYMBOL (iucv_unregister);
1606 EXPORT_SYMBOL (iucv_path_accept);
1607 EXPORT_SYMBOL (iucv_path_connect);
1608 EXPORT_SYMBOL (iucv_path_quiesce);
1609 EXPORT_SYMBOL (iucv_path_sever);
1610 EXPORT_SYMBOL (iucv_message_purge);
1611 EXPORT_SYMBOL (iucv_message_receive);
1612 EXPORT_SYMBOL (iucv_message_reject);
1613 EXPORT_SYMBOL (iucv_message_reply);
1614 EXPORT_SYMBOL (iucv_message_send);
1615 EXPORT_SYMBOL (iucv_message_send2way);
1617 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1618 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1619 MODULE_LICENSE("GPL");