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 {
93 struct iucv_irq_list {
94 struct list_head list;
95 struct iucv_irq_data data;
98 static struct iucv_irq_data *iucv_irq_data;
99 static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
100 static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
103 * Queue of interrupt buffers lock for delivery via the tasklet
104 * (fast but can't call smp_call_function).
106 static LIST_HEAD(iucv_task_queue);
109 * The tasklet for fast delivery of iucv interrupts.
111 static void iucv_tasklet_fn(unsigned long);
112 static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
115 * Queue of interrupt buffers for delivery via a work queue
116 * (slower but can call smp_call_function).
118 static LIST_HEAD(iucv_work_queue);
121 * The work element to deliver path pending interrupts.
123 static void iucv_work_fn(struct work_struct *work);
124 static DECLARE_WORK(iucv_work, iucv_work_fn);
127 * Spinlock protecting task and work queue.
129 static DEFINE_SPINLOCK(iucv_queue_lock);
131 enum iucv_command_codes {
133 IUCV_RETRIEVE_BUFFER = 2,
141 IUCV_DECLARE_BUFFER = 12,
149 * Error messages that are used with the iucv_sever function. They get
150 * converted to EBCDIC.
152 static char iucv_error_no_listener[16] = "NO LISTENER";
153 static char iucv_error_no_memory[16] = "NO MEMORY";
154 static char iucv_error_pathid[16] = "INVALID PATHID";
157 * iucv_handler_list: List of registered handlers.
159 static LIST_HEAD(iucv_handler_list);
162 * iucv_path_table: an array of iucv_path structures.
164 static struct iucv_path **iucv_path_table;
165 static unsigned long iucv_max_pathid;
168 * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
170 static DEFINE_SPINLOCK(iucv_table_lock);
173 * iucv_active_cpu: contains the number of the cpu executing the tasklet
174 * or the work handler. Needed for iucv_path_sever called from tasklet.
176 static int iucv_active_cpu = -1;
179 * Mutex and wait queue for iucv_register/iucv_unregister.
181 static DEFINE_MUTEX(iucv_register_mutex);
184 * Counter for number of non-smp capable handlers.
186 static int iucv_nonsmp_handler;
189 * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
190 * iucv_path_quiesce and iucv_path_sever.
192 struct iucv_cmd_control {
201 } __attribute__ ((packed,aligned(8)));
204 * Data in parameter list iucv structure. Used by iucv_message_send,
205 * iucv_message_send2way and iucv_message_reply.
207 struct iucv_cmd_dpl {
219 } __attribute__ ((packed,aligned(8)));
222 * Data in buffer iucv structure. Used by iucv_message_receive,
223 * iucv_message_reject, iucv_message_send, iucv_message_send2way
224 * and iucv_declare_cpu.
239 } __attribute__ ((packed,aligned(8)));
242 * Purge message iucv structure. Used by iucv_message_purge.
244 struct iucv_cmd_purge {
255 } __attribute__ ((packed,aligned(8)));
258 * Set mask iucv structure. Used by iucv_enable_cpu.
260 struct iucv_cmd_set_mask {
265 } __attribute__ ((packed,aligned(8)));
268 struct iucv_cmd_control ctrl;
269 struct iucv_cmd_dpl dpl;
270 struct iucv_cmd_db db;
271 struct iucv_cmd_purge purge;
272 struct iucv_cmd_set_mask set_mask;
276 * Anchor for per-cpu IUCV command parameter block.
278 static union iucv_param *iucv_param;
282 * @code: identifier of IUCV call to CP.
283 * @parm: pointer to a struct iucv_parm block
285 * Calls CP to execute IUCV commands.
287 * Returns the result of the CP IUCV call.
289 static inline int iucv_call_b2f0(int command, union iucv_param *parm)
291 register unsigned long reg0 asm ("0");
292 register unsigned long reg1 asm ("1");
296 reg1 = virt_to_phys(parm);
298 " .long 0xb2f01000\n"
301 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
302 : "m" (*parm) : "cc");
303 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
309 * Determines the maximum number of connections that may be established.
311 * Returns the maximum number of connections or -EPERM is IUCV is not
314 static int iucv_query_maxconn(void)
316 register unsigned long reg0 asm ("0");
317 register unsigned long reg1 asm ("1");
321 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
325 reg1 = (unsigned long) param;
327 " .long 0xb2f01000\n"
330 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
332 iucv_max_pathid = reg0;
334 return ccode ? -EPERM : 0;
341 * Allow iucv interrupts on this cpu.
343 static void iucv_allow_cpu(void *data)
345 int cpu = smp_processor_id();
346 union iucv_param *parm;
349 * Enable all iucv interrupts.
350 * ipmask contains bits for the different interrupts
351 * 0x80 - Flag to allow nonpriority message pending interrupts
352 * 0x40 - Flag to allow priority message pending interrupts
353 * 0x20 - Flag to allow nonpriority message completion interrupts
354 * 0x10 - Flag to allow priority message completion interrupts
355 * 0x08 - Flag to allow IUCV control interrupts
357 parm = percpu_ptr(iucv_param, smp_processor_id());
358 memset(parm, 0, sizeof(union iucv_param));
359 parm->set_mask.ipmask = 0xf8;
360 iucv_call_b2f0(IUCV_SETMASK, parm);
362 /* Set indication that iucv interrupts are allowed for this cpu. */
363 cpu_set(cpu, iucv_irq_cpumask);
370 * Block iucv interrupts on this cpu.
372 static void iucv_block_cpu(void *data)
374 int cpu = smp_processor_id();
375 union iucv_param *parm;
377 /* Disable all iucv interrupts. */
378 parm = percpu_ptr(iucv_param, smp_processor_id());
379 memset(parm, 0, sizeof(union iucv_param));
380 iucv_call_b2f0(IUCV_SETMASK, parm);
382 /* Clear indication that iucv interrupts are allowed for this cpu. */
383 cpu_clear(cpu, iucv_irq_cpumask);
390 * Declare a interupt buffer on this cpu.
392 static void iucv_declare_cpu(void *data)
394 int cpu = smp_processor_id();
395 union iucv_param *parm;
398 if (cpu_isset(cpu, iucv_buffer_cpumask))
401 /* Declare interrupt buffer. */
402 parm = percpu_ptr(iucv_param, cpu);
403 memset(parm, 0, sizeof(union iucv_param));
404 parm->db.ipbfadr1 = virt_to_phys(percpu_ptr(iucv_irq_data, cpu));
405 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
407 char *err = "Unknown";
410 err = "Directory error";
413 err = "Invalid length";
416 err = "Buffer already exists";
419 err = "Buffer overlap";
422 err = "Paging or storage error";
425 printk(KERN_WARNING "iucv_register: iucv_declare_buffer "
426 "on cpu %i returned error 0x%02x (%s)\n", cpu, rc, err);
430 /* Set indication that an iucv buffer exists for this cpu. */
431 cpu_set(cpu, iucv_buffer_cpumask);
433 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
434 /* Enable iucv interrupts on this cpu. */
435 iucv_allow_cpu(NULL);
437 /* Disable iucv interrupts on this cpu. */
438 iucv_block_cpu(NULL);
445 * Retrieve interrupt buffer on this cpu.
447 static void iucv_retrieve_cpu(void *data)
449 int cpu = smp_processor_id();
450 union iucv_param *parm;
452 if (!cpu_isset(cpu, iucv_buffer_cpumask))
455 /* Block iucv interrupts. */
456 iucv_block_cpu(NULL);
458 /* Retrieve interrupt buffer. */
459 parm = percpu_ptr(iucv_param, cpu);
460 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
462 /* Clear indication that an iucv buffer exists for this cpu. */
463 cpu_clear(cpu, iucv_buffer_cpumask);
469 * Allow iucv interrupts on all cpus.
471 static void iucv_setmask_mp(void)
476 for_each_online_cpu(cpu)
477 /* Enable all cpus with a declared buffer. */
478 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
479 !cpu_isset(cpu, iucv_irq_cpumask))
480 smp_call_function_on(iucv_allow_cpu, NULL, 0, 1, cpu);
487 * Allow iucv interrupts on a single cpu.
489 static void iucv_setmask_up(void)
494 /* Disable all cpu but the first in cpu_irq_cpumask. */
495 cpumask = iucv_irq_cpumask;
496 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
497 for_each_cpu_mask(cpu, cpumask)
498 smp_call_function_on(iucv_block_cpu, NULL, 0, 1, cpu);
504 * This function makes iucv ready for use. It allocates the pathid
505 * table, declares an iucv interrupt buffer and enables the iucv
506 * interrupts. Called when the first user has registered an iucv
509 static int iucv_enable(void)
515 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
516 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
517 if (!iucv_path_table)
519 /* Declare per cpu buffers. */
522 for_each_online_cpu(cpu)
523 smp_call_function_on(iucv_declare_cpu, NULL, 0, 1, cpu);
525 if (cpus_empty(iucv_buffer_cpumask))
526 /* No cpu could declare an iucv buffer. */
531 kfree(iucv_path_table);
539 * This function shuts down iucv. It disables iucv interrupts, retrieves
540 * the iucv interrupt buffer and frees the pathid table. Called after the
541 * last user unregister its iucv handler.
543 static void iucv_disable(void)
545 on_each_cpu(iucv_retrieve_cpu, NULL, 0, 1);
546 kfree(iucv_path_table);
549 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
550 unsigned long action, void *hcpu)
553 long cpu = (long) hcpu;
557 if (!percpu_populate(iucv_irq_data,
558 sizeof(struct iucv_irq_data),
559 GFP_KERNEL|GFP_DMA, cpu))
561 if (!percpu_populate(iucv_param, sizeof(union iucv_param),
562 GFP_KERNEL|GFP_DMA, cpu)) {
563 percpu_depopulate(iucv_irq_data, cpu);
567 case CPU_UP_CANCELED:
569 percpu_depopulate(iucv_param, cpu);
570 percpu_depopulate(iucv_irq_data, cpu);
573 case CPU_DOWN_FAILED:
574 smp_call_function_on(iucv_declare_cpu, NULL, 0, 1, cpu);
576 case CPU_DOWN_PREPARE:
577 cpumask = iucv_buffer_cpumask;
578 cpu_clear(cpu, cpumask);
579 if (cpus_empty(cpumask))
580 /* Can't offline last IUCV enabled cpu. */
582 smp_call_function_on(iucv_retrieve_cpu, NULL, 0, 1, cpu);
583 if (cpus_empty(iucv_irq_cpumask))
584 smp_call_function_on(iucv_allow_cpu, NULL, 0, 1,
585 first_cpu(iucv_buffer_cpumask));
591 static struct notifier_block iucv_cpu_notifier = {
592 .notifier_call = iucv_cpu_notify,
597 * @pathid: path identification number.
598 * @userdata: 16-bytes of user data.
600 * Sever an iucv path to free up the pathid. Used internally.
602 static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
604 union iucv_param *parm;
606 parm = percpu_ptr(iucv_param, smp_processor_id());
607 memset(parm, 0, sizeof(union iucv_param));
609 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
610 parm->ctrl.ippathid = pathid;
611 return iucv_call_b2f0(IUCV_SEVER, parm);
616 * __iucv_cleanup_queue
617 * @dummy: unused dummy argument
619 * Nop function called via smp_call_function to force work items from
620 * pending external iucv interrupts to the work queue.
622 static void __iucv_cleanup_queue(void *dummy)
630 * Function called after a path has been severed to find all remaining
631 * work items for the now stale pathid. The caller needs to hold the
634 static void iucv_cleanup_queue(void)
636 struct iucv_irq_list *p, *n;
639 * When a path is severed, the pathid can be reused immediatly
640 * on a iucv connect or a connection pending interrupt. Remove
641 * all entries from the task queue that refer to a stale pathid
642 * (iucv_path_table[ix] == NULL). Only then do the iucv connect
643 * or deliver the connection pending interrupt. To get all the
644 * pending interrupts force them to the work queue by calling
645 * an empty function on all cpus.
647 smp_call_function(__iucv_cleanup_queue, NULL, 0, 1);
648 spin_lock_irq(&iucv_queue_lock);
649 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
650 /* Remove stale work items from the task queue. */
651 if (iucv_path_table[p->data.ippathid] == NULL) {
656 spin_unlock_irq(&iucv_queue_lock);
661 * @handler: address of iucv handler structure
662 * @smp: != 0 indicates that the handler can deal with out of order messages
664 * Registers a driver with IUCV.
666 * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
667 * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
669 int iucv_register(struct iucv_handler *handler, int smp)
675 mutex_lock(&iucv_register_mutex);
677 iucv_nonsmp_handler++;
678 if (list_empty(&iucv_handler_list)) {
682 } else if (!smp && iucv_nonsmp_handler == 1)
684 INIT_LIST_HEAD(&handler->paths);
686 spin_lock_irq(&iucv_table_lock);
687 list_add_tail(&handler->list, &iucv_handler_list);
688 spin_unlock_irq(&iucv_table_lock);
691 mutex_unlock(&iucv_register_mutex);
697 * @handler: address of iucv handler structure
698 * @smp: != 0 indicates that the handler can deal with out of order messages
700 * Unregister driver from IUCV.
702 void iucv_unregister(struct iucv_handler *handler, int smp)
704 struct iucv_path *p, *n;
706 mutex_lock(&iucv_register_mutex);
707 spin_lock_bh(&iucv_table_lock);
708 /* Remove handler from the iucv_handler_list. */
709 list_del_init(&handler->list);
710 /* Sever all pathids still refering to the handler. */
711 list_for_each_entry_safe(p, n, &handler->paths, list) {
712 iucv_sever_pathid(p->pathid, NULL);
713 iucv_path_table[p->pathid] = NULL;
717 spin_unlock_bh(&iucv_table_lock);
719 iucv_nonsmp_handler--;
720 if (list_empty(&iucv_handler_list))
722 else if (!smp && iucv_nonsmp_handler == 0)
724 mutex_unlock(&iucv_register_mutex);
729 * @path: address of iucv path structure
730 * @handler: address of iucv handler structure
731 * @userdata: 16 bytes of data reflected to the communication partner
732 * @private: private data passed to interrupt handlers for this path
734 * This function is issued after the user received a connection pending
735 * external interrupt and now wishes to complete the IUCV communication path.
737 * Returns the result of the CP IUCV call.
739 int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
740 u8 userdata[16], void *private)
742 union iucv_param *parm;
746 /* Prepare parameter block. */
747 parm = percpu_ptr(iucv_param, smp_processor_id());
748 memset(parm, 0, sizeof(union iucv_param));
749 parm->ctrl.ippathid = path->pathid;
750 parm->ctrl.ipmsglim = path->msglim;
752 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
753 parm->ctrl.ipflags1 = path->flags;
755 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
757 path->private = private;
758 path->msglim = parm->ctrl.ipmsglim;
759 path->flags = parm->ctrl.ipflags1;
767 * @path: address of iucv path structure
768 * @handler: address of iucv handler structure
769 * @userid: 8-byte user identification
770 * @system: 8-byte target system identification
771 * @userdata: 16 bytes of data reflected to the communication partner
772 * @private: private data passed to interrupt handlers for this path
774 * This function establishes an IUCV path. Although the connect may complete
775 * successfully, you are not able to use the path until you receive an IUCV
776 * Connection Complete external interrupt.
778 * Returns the result of the CP IUCV call.
780 int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
781 u8 userid[8], u8 system[8], u8 userdata[16],
784 union iucv_param *parm;
788 spin_lock_bh(&iucv_table_lock);
789 iucv_cleanup_queue();
790 parm = percpu_ptr(iucv_param, smp_processor_id());
791 memset(parm, 0, sizeof(union iucv_param));
792 parm->ctrl.ipmsglim = path->msglim;
793 parm->ctrl.ipflags1 = path->flags;
795 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
796 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
797 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
800 memcpy(parm->ctrl.iptarget, system,
801 sizeof(parm->ctrl.iptarget));
802 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
803 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
806 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
808 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
810 if (parm->ctrl.ippathid < iucv_max_pathid) {
811 path->pathid = parm->ctrl.ippathid;
812 path->msglim = parm->ctrl.ipmsglim;
813 path->flags = parm->ctrl.ipflags1;
814 path->handler = handler;
815 path->private = private;
816 list_add_tail(&path->list, &handler->paths);
817 iucv_path_table[path->pathid] = path;
819 iucv_sever_pathid(parm->ctrl.ippathid,
824 spin_unlock_bh(&iucv_table_lock);
830 * @path: address of iucv path structure
831 * @userdata: 16 bytes of data reflected to the communication partner
833 * This function temporarily suspends incoming messages on an IUCV path.
834 * You can later reactivate the path by invoking the iucv_resume function.
836 * Returns the result from the CP IUCV call.
838 int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
840 union iucv_param *parm;
844 parm = percpu_ptr(iucv_param, smp_processor_id());
845 memset(parm, 0, sizeof(union iucv_param));
847 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
848 parm->ctrl.ippathid = path->pathid;
849 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
856 * @path: address of iucv path structure
857 * @userdata: 16 bytes of data reflected to the communication partner
859 * This function resumes incoming messages on an IUCV path that has
860 * been stopped with iucv_path_quiesce.
862 * Returns the result from the CP IUCV call.
864 int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
866 union iucv_param *parm;
870 parm = percpu_ptr(iucv_param, smp_processor_id());
871 memset(parm, 0, sizeof(union iucv_param));
873 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
874 parm->ctrl.ippathid = path->pathid;
875 rc = iucv_call_b2f0(IUCV_RESUME, parm);
882 * @path: address of iucv path structure
883 * @userdata: 16 bytes of data reflected to the communication partner
885 * This function terminates an IUCV path.
887 * Returns the result from the CP IUCV call.
889 int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
895 if (iucv_active_cpu != smp_processor_id())
896 spin_lock_bh(&iucv_table_lock);
897 rc = iucv_sever_pathid(path->pathid, userdata);
899 iucv_path_table[path->pathid] = NULL;
900 list_del_init(&path->list);
902 if (iucv_active_cpu != smp_processor_id())
903 spin_unlock_bh(&iucv_table_lock);
910 * @path: address of iucv path structure
911 * @msg: address of iucv msg structure
912 * @srccls: source class of message
914 * Cancels a message you have sent.
916 * Returns the result from the CP IUCV call.
918 int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
921 union iucv_param *parm;
925 parm = percpu_ptr(iucv_param, smp_processor_id());
926 memset(parm, 0, sizeof(union iucv_param));
927 parm->purge.ippathid = path->pathid;
928 parm->purge.ipmsgid = msg->id;
929 parm->purge.ipsrccls = srccls;
930 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
931 rc = iucv_call_b2f0(IUCV_PURGE, parm);
933 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
934 msg->tag = parm->purge.ipmsgtag;
941 * iucv_message_receive
942 * @path: address of iucv path structure
943 * @msg: address of iucv msg structure
944 * @flags: how the message is received (IUCV_IPBUFLST)
945 * @buffer: address of data buffer or address of struct iucv_array
946 * @size: length of data buffer
949 * This function receives messages that are being sent to you over
950 * established paths. This function will deal with RMDATA messages
951 * embedded in struct iucv_message as well.
953 * Returns the result from the CP IUCV call.
955 int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
956 u8 flags, void *buffer, size_t size, size_t *residual)
958 union iucv_param *parm;
959 struct iucv_array *array;
964 if (msg->flags & IUCV_IPRMDATA) {
966 * Message is 8 bytes long and has been stored to the
967 * message descriptor itself.
969 rc = (size < 8) ? 5 : 0;
971 *residual = abs(size - 8);
973 if (flags & IUCV_IPBUFLST) {
974 /* Copy to struct iucv_array. */
975 size = (size < 8) ? size : 8;
976 for (array = buffer; size > 0; array++) {
977 copy = min_t(size_t, size, array->length);
978 memcpy((u8 *)(addr_t) array->address,
984 /* Copy to direct buffer. */
985 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
991 parm = percpu_ptr(iucv_param, smp_processor_id());
992 memset(parm, 0, sizeof(union iucv_param));
993 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
994 parm->db.ipbfln1f = (u32) size;
995 parm->db.ipmsgid = msg->id;
996 parm->db.ippathid = path->pathid;
997 parm->db.iptrgcls = msg->class;
998 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
999 IUCV_IPFGMID | IUCV_IPTRGCLS);
1000 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1001 if (!rc || rc == 5) {
1002 msg->flags = parm->db.ipflags1;
1004 *residual = parm->db.ipbfln1f;
1011 * iucv_message_reject
1012 * @path: address of iucv path structure
1013 * @msg: address of iucv msg structure
1015 * The reject function refuses a specified message. Between the time you
1016 * are notified of a message and the time that you complete the message,
1017 * the message may be rejected.
1019 * Returns the result from the CP IUCV call.
1021 int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1023 union iucv_param *parm;
1027 parm = percpu_ptr(iucv_param, smp_processor_id());
1028 memset(parm, 0, sizeof(union iucv_param));
1029 parm->db.ippathid = path->pathid;
1030 parm->db.ipmsgid = msg->id;
1031 parm->db.iptrgcls = msg->class;
1032 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1033 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1039 * iucv_message_reply
1040 * @path: address of iucv path structure
1041 * @msg: address of iucv msg structure
1042 * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1043 * @reply: address of reply data buffer or address of struct iucv_array
1044 * @size: length of reply data buffer
1046 * This function responds to the two-way messages that you receive. You
1047 * must identify completely the message to which you wish to reply. ie,
1048 * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
1049 * the parameter list.
1051 * Returns the result from the CP IUCV call.
1053 int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1054 u8 flags, void *reply, size_t size)
1056 union iucv_param *parm;
1060 parm = percpu_ptr(iucv_param, smp_processor_id());
1061 memset(parm, 0, sizeof(union iucv_param));
1062 if (flags & IUCV_IPRMDATA) {
1063 parm->dpl.ippathid = path->pathid;
1064 parm->dpl.ipflags1 = flags;
1065 parm->dpl.ipmsgid = msg->id;
1066 parm->dpl.iptrgcls = msg->class;
1067 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1069 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1070 parm->db.ipbfln1f = (u32) size;
1071 parm->db.ippathid = path->pathid;
1072 parm->db.ipflags1 = flags;
1073 parm->db.ipmsgid = msg->id;
1074 parm->db.iptrgcls = msg->class;
1076 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1083 * @path: address of iucv path structure
1084 * @msg: address of iucv msg structure
1085 * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
1086 * @srccls: source class of message
1087 * @buffer: address of send buffer or address of struct iucv_array
1088 * @size: length of send buffer
1090 * This function transmits data to another application. Data to be
1091 * transmitted is in a buffer and this is a one-way message and the
1092 * receiver will not reply to the message.
1094 * Returns the result from the CP IUCV call.
1096 int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1097 u8 flags, u32 srccls, void *buffer, size_t size)
1099 union iucv_param *parm;
1103 parm = percpu_ptr(iucv_param, smp_processor_id());
1104 memset(parm, 0, sizeof(union iucv_param));
1105 if (flags & IUCV_IPRMDATA) {
1106 /* Message of 8 bytes can be placed into the parameter list. */
1107 parm->dpl.ippathid = path->pathid;
1108 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1109 parm->dpl.iptrgcls = msg->class;
1110 parm->dpl.ipsrccls = srccls;
1111 parm->dpl.ipmsgtag = msg->tag;
1112 memcpy(parm->dpl.iprmmsg, buffer, 8);
1114 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1115 parm->db.ipbfln1f = (u32) size;
1116 parm->db.ippathid = path->pathid;
1117 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1118 parm->db.iptrgcls = msg->class;
1119 parm->db.ipsrccls = srccls;
1120 parm->db.ipmsgtag = msg->tag;
1122 rc = iucv_call_b2f0(IUCV_SEND, parm);
1124 msg->id = parm->db.ipmsgid;
1130 * iucv_message_send2way
1131 * @path: address of iucv path structure
1132 * @msg: address of iucv msg structure
1133 * @flags: how the message is sent and the reply is received
1134 * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
1135 * @srccls: source class of message
1136 * @buffer: address of send buffer or address of struct iucv_array
1137 * @size: length of send buffer
1138 * @ansbuf: address of answer buffer or address of struct iucv_array
1139 * @asize: size of reply buffer
1141 * This function transmits data to another application. Data to be
1142 * transmitted is in a buffer. The receiver of the send is expected to
1143 * reply to the message and a buffer is provided into which IUCV moves
1144 * the reply to this message.
1146 * Returns the result from the CP IUCV call.
1148 int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1149 u8 flags, u32 srccls, void *buffer, size_t size,
1150 void *answer, size_t asize, size_t *residual)
1152 union iucv_param *parm;
1156 parm = percpu_ptr(iucv_param, smp_processor_id());
1157 memset(parm, 0, sizeof(union iucv_param));
1158 if (flags & IUCV_IPRMDATA) {
1159 parm->dpl.ippathid = path->pathid;
1160 parm->dpl.ipflags1 = path->flags; /* priority message */
1161 parm->dpl.iptrgcls = msg->class;
1162 parm->dpl.ipsrccls = srccls;
1163 parm->dpl.ipmsgtag = msg->tag;
1164 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1165 parm->dpl.ipbfln2f = (u32) asize;
1166 memcpy(parm->dpl.iprmmsg, buffer, 8);
1168 parm->db.ippathid = path->pathid;
1169 parm->db.ipflags1 = path->flags; /* priority message */
1170 parm->db.iptrgcls = msg->class;
1171 parm->db.ipsrccls = srccls;
1172 parm->db.ipmsgtag = msg->tag;
1173 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1174 parm->db.ipbfln1f = (u32) size;
1175 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1176 parm->db.ipbfln2f = (u32) asize;
1178 rc = iucv_call_b2f0(IUCV_SEND, parm);
1180 msg->id = parm->db.ipmsgid;
1187 * @data: Pointer to external interrupt buffer
1189 * Process connection pending work item. Called from tasklet while holding
1192 struct iucv_path_pending {
1203 } __attribute__ ((packed));
1205 static void iucv_path_pending(struct iucv_irq_data *data)
1207 struct iucv_path_pending *ipp = (void *) data;
1208 struct iucv_handler *handler;
1209 struct iucv_path *path;
1212 BUG_ON(iucv_path_table[ipp->ippathid]);
1213 /* New pathid, handler found. Create a new path struct. */
1214 error = iucv_error_no_memory;
1215 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1218 path->pathid = ipp->ippathid;
1219 iucv_path_table[path->pathid] = path;
1220 EBCASC(ipp->ipvmid, 8);
1222 /* Call registered handler until one is found that wants the path. */
1223 list_for_each_entry(handler, &iucv_handler_list, list) {
1224 if (!handler->path_pending)
1227 * Add path to handler to allow a call to iucv_path_sever
1228 * inside the path_pending function. If the handler returns
1229 * an error remove the path from the handler again.
1231 list_add(&path->list, &handler->paths);
1232 path->handler = handler;
1233 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1235 list_del(&path->list);
1236 path->handler = NULL;
1238 /* No handler wanted the path. */
1239 iucv_path_table[path->pathid] = NULL;
1240 iucv_path_free(path);
1241 error = iucv_error_no_listener;
1243 iucv_sever_pathid(ipp->ippathid, error);
1247 * iucv_path_complete
1248 * @data: Pointer to external interrupt buffer
1250 * Process connection complete work item. Called from tasklet while holding
1253 struct iucv_path_complete {
1264 } __attribute__ ((packed));
1266 static void iucv_path_complete(struct iucv_irq_data *data)
1268 struct iucv_path_complete *ipc = (void *) data;
1269 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1271 if (path && path->handler && path->handler->path_complete)
1272 path->handler->path_complete(path, ipc->ipuser);
1277 * @data: Pointer to external interrupt buffer
1279 * Process connection severed work item. Called from tasklet while holding
1282 struct iucv_path_severed {
1292 } __attribute__ ((packed));
1294 static void iucv_path_severed(struct iucv_irq_data *data)
1296 struct iucv_path_severed *ips = (void *) data;
1297 struct iucv_path *path = iucv_path_table[ips->ippathid];
1299 if (!path || !path->handler) /* Already severed */
1301 if (path->handler->path_severed)
1302 path->handler->path_severed(path, ips->ipuser);
1304 iucv_sever_pathid(path->pathid, NULL);
1305 iucv_path_table[path->pathid] = NULL;
1306 list_del_init(&path->list);
1307 iucv_path_free(path);
1312 * iucv_path_quiesced
1313 * @data: Pointer to external interrupt buffer
1315 * Process connection quiesced work item. Called from tasklet while holding
1318 struct iucv_path_quiesced {
1328 } __attribute__ ((packed));
1330 static void iucv_path_quiesced(struct iucv_irq_data *data)
1332 struct iucv_path_quiesced *ipq = (void *) data;
1333 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1335 if (path && path->handler && path->handler->path_quiesced)
1336 path->handler->path_quiesced(path, ipq->ipuser);
1341 * @data: Pointer to external interrupt buffer
1343 * Process connection resumed work item. Called from tasklet while holding
1346 struct iucv_path_resumed {
1356 } __attribute__ ((packed));
1358 static void iucv_path_resumed(struct iucv_irq_data *data)
1360 struct iucv_path_resumed *ipr = (void *) data;
1361 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1363 if (path && path->handler && path->handler->path_resumed)
1364 path->handler->path_resumed(path, ipr->ipuser);
1368 * iucv_message_complete
1369 * @data: Pointer to external interrupt buffer
1371 * Process message complete work item. Called from tasklet while holding
1374 struct iucv_message_complete {
1387 } __attribute__ ((packed));
1389 static void iucv_message_complete(struct iucv_irq_data *data)
1391 struct iucv_message_complete *imc = (void *) data;
1392 struct iucv_path *path = iucv_path_table[imc->ippathid];
1393 struct iucv_message msg;
1395 if (path && path->handler && path->handler->message_complete) {
1396 msg.flags = imc->ipflags1;
1397 msg.id = imc->ipmsgid;
1398 msg.audit = imc->ipaudit;
1399 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1400 msg.class = imc->ipsrccls;
1401 msg.tag = imc->ipmsgtag;
1402 msg.length = imc->ipbfln2f;
1403 path->handler->message_complete(path, &msg);
1408 * iucv_message_pending
1409 * @data: Pointer to external interrupt buffer
1411 * Process message pending work item. Called from tasklet while holding
1414 struct iucv_message_pending {
1432 } __attribute__ ((packed));
1434 static void iucv_message_pending(struct iucv_irq_data *data)
1436 struct iucv_message_pending *imp = (void *) data;
1437 struct iucv_path *path = iucv_path_table[imp->ippathid];
1438 struct iucv_message msg;
1440 if (path && path->handler && path->handler->message_pending) {
1441 msg.flags = imp->ipflags1;
1442 msg.id = imp->ipmsgid;
1443 msg.class = imp->iptrgcls;
1444 if (imp->ipflags1 & IUCV_IPRMDATA) {
1445 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1448 msg.length = imp->ln1msg2.ipbfln1f;
1449 msg.reply_size = imp->ipbfln2f;
1450 path->handler->message_pending(path, &msg);
1457 * This tasklet loops over the queue of irq buffers created by
1458 * iucv_external_interrupt, calls the appropriate action handler
1459 * and then frees the buffer.
1461 static void iucv_tasklet_fn(unsigned long ignored)
1463 typedef void iucv_irq_fn(struct iucv_irq_data *);
1464 static iucv_irq_fn *irq_fn[] = {
1465 [0x02] = iucv_path_complete,
1466 [0x03] = iucv_path_severed,
1467 [0x04] = iucv_path_quiesced,
1468 [0x05] = iucv_path_resumed,
1469 [0x06] = iucv_message_complete,
1470 [0x07] = iucv_message_complete,
1471 [0x08] = iucv_message_pending,
1472 [0x09] = iucv_message_pending,
1474 struct list_head task_queue = LIST_HEAD_INIT(task_queue);
1475 struct iucv_irq_list *p, *n;
1477 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1478 spin_lock(&iucv_table_lock);
1479 iucv_active_cpu = smp_processor_id();
1481 spin_lock_irq(&iucv_queue_lock);
1482 list_splice_init(&iucv_task_queue, &task_queue);
1483 spin_unlock_irq(&iucv_queue_lock);
1485 list_for_each_entry_safe(p, n, &task_queue, list) {
1486 list_del_init(&p->list);
1487 irq_fn[p->data.iptype](&p->data);
1491 iucv_active_cpu = -1;
1492 spin_unlock(&iucv_table_lock);
1498 * This work function loops over the queue of path pending irq blocks
1499 * created by iucv_external_interrupt, calls the appropriate action
1500 * handler and then frees the buffer.
1502 static void iucv_work_fn(struct work_struct *work)
1504 typedef void iucv_irq_fn(struct iucv_irq_data *);
1505 struct list_head work_queue = LIST_HEAD_INIT(work_queue);
1506 struct iucv_irq_list *p, *n;
1508 /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
1509 spin_lock_bh(&iucv_table_lock);
1510 iucv_active_cpu = smp_processor_id();
1512 spin_lock_irq(&iucv_queue_lock);
1513 list_splice_init(&iucv_work_queue, &work_queue);
1514 spin_unlock_irq(&iucv_queue_lock);
1516 iucv_cleanup_queue();
1517 list_for_each_entry_safe(p, n, &work_queue, list) {
1518 list_del_init(&p->list);
1519 iucv_path_pending(&p->data);
1523 iucv_active_cpu = -1;
1524 spin_unlock_bh(&iucv_table_lock);
1528 * iucv_external_interrupt
1531 * Handles external interrupts coming in from CP.
1532 * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
1534 static void iucv_external_interrupt(u16 code)
1536 struct iucv_irq_data *p;
1537 struct iucv_irq_list *work;
1539 p = percpu_ptr(iucv_irq_data, smp_processor_id());
1540 if (p->ippathid >= iucv_max_pathid) {
1541 printk(KERN_WARNING "iucv_do_int: Got interrupt with "
1542 "pathid %d > max_connections (%ld)\n",
1543 p->ippathid, iucv_max_pathid - 1);
1544 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1547 if (p->iptype < 0x01 || p->iptype > 0x09) {
1548 printk(KERN_ERR "iucv_do_int: unknown iucv interrupt\n");
1551 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1553 printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
1556 memcpy(&work->data, p, sizeof(work->data));
1557 spin_lock(&iucv_queue_lock);
1558 if (p->iptype == 0x01) {
1559 /* Path pending interrupt. */
1560 list_add_tail(&work->list, &iucv_work_queue);
1561 schedule_work(&iucv_work);
1563 /* The other interrupts. */
1564 list_add_tail(&work->list, &iucv_task_queue);
1565 tasklet_schedule(&iucv_tasklet);
1567 spin_unlock(&iucv_queue_lock);
1573 * Allocates and initializes various data structures.
1575 static int iucv_init(void)
1579 if (!MACHINE_IS_VM) {
1580 rc = -EPROTONOSUPPORT;
1583 rc = iucv_query_maxconn();
1586 rc = register_external_interrupt (0x4000, iucv_external_interrupt);
1589 rc = bus_register(&iucv_bus);
1592 iucv_root = s390_root_dev_register("iucv");
1593 if (IS_ERR(iucv_root)) {
1594 rc = PTR_ERR(iucv_root);
1597 /* Note: GFP_DMA used used to get memory below 2G */
1598 iucv_irq_data = percpu_alloc(sizeof(struct iucv_irq_data),
1599 GFP_KERNEL|GFP_DMA);
1600 if (!iucv_irq_data) {
1604 /* Allocate parameter blocks. */
1605 iucv_param = percpu_alloc(sizeof(union iucv_param),
1606 GFP_KERNEL|GFP_DMA);
1611 register_hotcpu_notifier(&iucv_cpu_notifier);
1612 ASCEBC(iucv_error_no_listener, 16);
1613 ASCEBC(iucv_error_no_memory, 16);
1614 ASCEBC(iucv_error_pathid, 16);
1619 percpu_free(iucv_irq_data);
1621 s390_root_dev_unregister(iucv_root);
1623 bus_unregister(&iucv_bus);
1625 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1633 * Frees everything allocated from iucv_init.
1635 static void iucv_exit(void)
1637 struct iucv_irq_list *p, *n;
1639 spin_lock_irq(&iucv_queue_lock);
1640 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1642 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1644 spin_unlock_irq(&iucv_queue_lock);
1645 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1646 percpu_free(iucv_param);
1647 percpu_free(iucv_irq_data);
1648 s390_root_dev_unregister(iucv_root);
1649 bus_unregister(&iucv_bus);
1650 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1653 subsys_initcall(iucv_init);
1654 module_exit(iucv_exit);
1657 * Export all public stuff
1659 EXPORT_SYMBOL (iucv_bus);
1660 EXPORT_SYMBOL (iucv_root);
1661 EXPORT_SYMBOL (iucv_register);
1662 EXPORT_SYMBOL (iucv_unregister);
1663 EXPORT_SYMBOL (iucv_path_accept);
1664 EXPORT_SYMBOL (iucv_path_connect);
1665 EXPORT_SYMBOL (iucv_path_quiesce);
1666 EXPORT_SYMBOL (iucv_path_sever);
1667 EXPORT_SYMBOL (iucv_message_purge);
1668 EXPORT_SYMBOL (iucv_message_receive);
1669 EXPORT_SYMBOL (iucv_message_reject);
1670 EXPORT_SYMBOL (iucv_message_reply);
1671 EXPORT_SYMBOL (iucv_message_send);
1672 EXPORT_SYMBOL (iucv_message_send2way);
1674 MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1675 MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1676 MODULE_LICENSE("GPL");