1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/module.h>
34#include <linux/moduleparam.h>
35#include <linux/spinlock.h>
36#include <linux/kernel.h>
37#include <linux/slab.h>
38#include <linux/init.h>
39#include <linux/interrupt.h>
40#include <linux/list.h>
41#include <linux/errno.h>
42#include <linux/err.h>
43#include <linux/device.h>
44#include <linux/cpu.h>
45#include <net/iucv/iucv.h>
46#include <asm/atomic.h>
47#include <asm/ebcdic.h>
48#include <asm/io.h>
49#include <asm/s390_ext.h>
50#include <asm/s390_rdev.h>
51#include <asm/smp.h>
52
53
54
55
56
57
58
59
60
61
62
63
64#define IUCV_IPSRCCLS 0x01
65#define IUCV_IPTRGCLS 0x01
66#define IUCV_IPFGPID 0x02
67#define IUCV_IPFGMID 0x04
68#define IUCV_IPNORPY 0x10
69#define IUCV_IPALL 0x80
70
71static int iucv_bus_match(struct device *dev, struct device_driver *drv)
72{
73 return 0;
74}
75
76struct bus_type iucv_bus = {
77 .name = "iucv",
78 .match = iucv_bus_match,
79};
80EXPORT_SYMBOL(iucv_bus);
81
82struct device *iucv_root;
83EXPORT_SYMBOL(iucv_root);
84
85static int iucv_available;
86
87
88struct iucv_irq_data {
89 u16 ippathid;
90 u8 ipflags1;
91 u8 iptype;
92 u32 res2[8];
93};
94
95struct iucv_irq_list {
96 struct list_head list;
97 struct iucv_irq_data data;
98};
99
100static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
101static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
102static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
103
104
105
106
107
108static LIST_HEAD(iucv_task_queue);
109
110
111
112
113static void iucv_tasklet_fn(unsigned long);
114static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
115
116
117
118
119
120static LIST_HEAD(iucv_work_queue);
121
122
123
124
125static void iucv_work_fn(struct work_struct *work);
126static DECLARE_WORK(iucv_work, iucv_work_fn);
127
128
129
130
131static DEFINE_SPINLOCK(iucv_queue_lock);
132
133enum iucv_command_codes {
134 IUCV_QUERY = 0,
135 IUCV_RETRIEVE_BUFFER = 2,
136 IUCV_SEND = 4,
137 IUCV_RECEIVE = 5,
138 IUCV_REPLY = 6,
139 IUCV_REJECT = 8,
140 IUCV_PURGE = 9,
141 IUCV_ACCEPT = 10,
142 IUCV_CONNECT = 11,
143 IUCV_DECLARE_BUFFER = 12,
144 IUCV_QUIESCE = 13,
145 IUCV_RESUME = 14,
146 IUCV_SEVER = 15,
147 IUCV_SETMASK = 16,
148};
149
150
151
152
153
154static char iucv_error_no_listener[16] = "NO LISTENER";
155static char iucv_error_no_memory[16] = "NO MEMORY";
156static char iucv_error_pathid[16] = "INVALID PATHID";
157
158
159
160
161static LIST_HEAD(iucv_handler_list);
162
163
164
165
166static struct iucv_path **iucv_path_table;
167static unsigned long iucv_max_pathid;
168
169
170
171
172static DEFINE_SPINLOCK(iucv_table_lock);
173
174
175
176
177
178static int iucv_active_cpu = -1;
179
180
181
182
183static DEFINE_MUTEX(iucv_register_mutex);
184
185
186
187
188static int iucv_nonsmp_handler;
189
190
191
192
193
194struct iucv_cmd_control {
195 u16 ippathid;
196 u8 ipflags1;
197 u8 iprcode;
198 u16 ipmsglim;
199 u16 res1;
200 u8 ipvmid[8];
201 u8 ipuser[16];
202 u8 iptarget[8];
203} __attribute__ ((packed,aligned(8)));
204
205
206
207
208
209struct iucv_cmd_dpl {
210 u16 ippathid;
211 u8 ipflags1;
212 u8 iprcode;
213 u32 ipmsgid;
214 u32 iptrgcls;
215 u8 iprmmsg[8];
216 u32 ipsrccls;
217 u32 ipmsgtag;
218 u32 ipbfadr2;
219 u32 ipbfln2f;
220 u32 res;
221} __attribute__ ((packed,aligned(8)));
222
223
224
225
226
227
228struct iucv_cmd_db {
229 u16 ippathid;
230 u8 ipflags1;
231 u8 iprcode;
232 u32 ipmsgid;
233 u32 iptrgcls;
234 u32 ipbfadr1;
235 u32 ipbfln1f;
236 u32 ipsrccls;
237 u32 ipmsgtag;
238 u32 ipbfadr2;
239 u32 ipbfln2f;
240 u32 res;
241} __attribute__ ((packed,aligned(8)));
242
243
244
245
246struct iucv_cmd_purge {
247 u16 ippathid;
248 u8 ipflags1;
249 u8 iprcode;
250 u32 ipmsgid;
251 u8 ipaudit[3];
252 u8 res1[5];
253 u32 res2;
254 u32 ipsrccls;
255 u32 ipmsgtag;
256 u32 res3[3];
257} __attribute__ ((packed,aligned(8)));
258
259
260
261
262struct iucv_cmd_set_mask {
263 u8 ipmask;
264 u8 res1[2];
265 u8 iprcode;
266 u32 res2[9];
267} __attribute__ ((packed,aligned(8)));
268
269union iucv_param {
270 struct iucv_cmd_control ctrl;
271 struct iucv_cmd_dpl dpl;
272 struct iucv_cmd_db db;
273 struct iucv_cmd_purge purge;
274 struct iucv_cmd_set_mask set_mask;
275};
276
277
278
279
280static union iucv_param *iucv_param[NR_CPUS];
281
282
283
284
285
286
287
288
289
290
291static inline int iucv_call_b2f0(int command, union iucv_param *parm)
292{
293 register unsigned long reg0 asm ("0");
294 register unsigned long reg1 asm ("1");
295 int ccode;
296
297 reg0 = command;
298 reg1 = virt_to_phys(parm);
299 asm volatile(
300 " .long 0xb2f01000\n"
301 " ipm %0\n"
302 " srl %0,28\n"
303 : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
304 : "m" (*parm) : "cc");
305 return (ccode == 1) ? parm->ctrl.iprcode : ccode;
306}
307
308
309
310
311
312
313
314
315
316static int iucv_query_maxconn(void)
317{
318 register unsigned long reg0 asm ("0");
319 register unsigned long reg1 asm ("1");
320 void *param;
321 int ccode;
322
323 param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
324 if (!param)
325 return -ENOMEM;
326 reg0 = IUCV_QUERY;
327 reg1 = (unsigned long) param;
328 asm volatile (
329 " .long 0xb2f01000\n"
330 " ipm %0\n"
331 " srl %0,28\n"
332 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
333 if (ccode == 0)
334 iucv_max_pathid = reg0;
335 kfree(param);
336 return ccode ? -EPERM : 0;
337}
338
339
340
341
342
343
344
345static void iucv_allow_cpu(void *data)
346{
347 int cpu = smp_processor_id();
348 union iucv_param *parm;
349
350
351
352
353
354
355
356
357
358
359 parm = iucv_param[cpu];
360 memset(parm, 0, sizeof(union iucv_param));
361 parm->set_mask.ipmask = 0xf8;
362 iucv_call_b2f0(IUCV_SETMASK, parm);
363
364
365 cpu_set(cpu, iucv_irq_cpumask);
366}
367
368
369
370
371
372
373
374static void iucv_block_cpu(void *data)
375{
376 int cpu = smp_processor_id();
377 union iucv_param *parm;
378
379
380 parm = iucv_param[cpu];
381 memset(parm, 0, sizeof(union iucv_param));
382 iucv_call_b2f0(IUCV_SETMASK, parm);
383
384
385 cpu_clear(cpu, iucv_irq_cpumask);
386}
387
388
389
390
391
392
393
394static void iucv_declare_cpu(void *data)
395{
396 int cpu = smp_processor_id();
397 union iucv_param *parm;
398 int rc;
399
400 if (cpu_isset(cpu, iucv_buffer_cpumask))
401 return;
402
403
404 parm = iucv_param[cpu];
405 memset(parm, 0, sizeof(union iucv_param));
406 parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
407 rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
408 if (rc) {
409 char *err = "Unknown";
410 switch (rc) {
411 case 0x03:
412 err = "Directory error";
413 break;
414 case 0x0a:
415 err = "Invalid length";
416 break;
417 case 0x13:
418 err = "Buffer already exists";
419 break;
420 case 0x3e:
421 err = "Buffer overlap";
422 break;
423 case 0x5c:
424 err = "Paging or storage error";
425 break;
426 }
427 printk(KERN_WARNING "iucv_register: iucv_declare_buffer "
428 "on cpu %i returned error 0x%02x (%s)\n", cpu, rc, err);
429 return;
430 }
431
432
433 cpu_set(cpu, iucv_buffer_cpumask);
434
435 if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
436
437 iucv_allow_cpu(NULL);
438 else
439
440 iucv_block_cpu(NULL);
441}
442
443
444
445
446
447
448
449static void iucv_retrieve_cpu(void *data)
450{
451 int cpu = smp_processor_id();
452 union iucv_param *parm;
453
454 if (!cpu_isset(cpu, iucv_buffer_cpumask))
455 return;
456
457
458 iucv_block_cpu(NULL);
459
460
461 parm = iucv_param[cpu];
462 iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
463
464
465 cpu_clear(cpu, iucv_buffer_cpumask);
466}
467
468
469
470
471
472
473static void iucv_setmask_mp(void)
474{
475 int cpu;
476
477 get_online_cpus();
478 for_each_online_cpu(cpu)
479
480 if (cpu_isset(cpu, iucv_buffer_cpumask) &&
481 !cpu_isset(cpu, iucv_irq_cpumask))
482 smp_call_function_single(cpu, iucv_allow_cpu,
483 NULL, 1);
484 put_online_cpus();
485}
486
487
488
489
490
491
492static void iucv_setmask_up(void)
493{
494 cpumask_t cpumask;
495 int cpu;
496
497
498 cpumask = iucv_irq_cpumask;
499 cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
500 for_each_cpu_mask_nr(cpu, cpumask)
501 smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
502}
503
504
505
506
507
508
509
510
511
512static int iucv_enable(void)
513{
514 size_t alloc_size;
515 int cpu, rc;
516
517 rc = -ENOMEM;
518 alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
519 iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
520 if (!iucv_path_table)
521 goto out;
522
523 rc = -EIO;
524 get_online_cpus();
525 for_each_online_cpu(cpu)
526 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
527 if (cpus_empty(iucv_buffer_cpumask))
528
529 goto out_path;
530 put_online_cpus();
531 return 0;
532
533out_path:
534 put_online_cpus();
535 kfree(iucv_path_table);
536out:
537 return rc;
538}
539
540
541
542
543
544
545
546
547static void iucv_disable(void)
548{
549 get_online_cpus();
550 on_each_cpu(iucv_retrieve_cpu, NULL, 1);
551 put_online_cpus();
552 kfree(iucv_path_table);
553}
554
555static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
556 unsigned long action, void *hcpu)
557{
558 cpumask_t cpumask;
559 long cpu = (long) hcpu;
560
561 switch (action) {
562 case CPU_UP_PREPARE:
563 case CPU_UP_PREPARE_FROZEN:
564 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
565 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
566 if (!iucv_irq_data[cpu])
567 return NOTIFY_BAD;
568 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
569 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
570 if (!iucv_param[cpu]) {
571 kfree(iucv_irq_data[cpu]);
572 iucv_irq_data[cpu] = NULL;
573 return NOTIFY_BAD;
574 }
575 break;
576 case CPU_UP_CANCELED:
577 case CPU_UP_CANCELED_FROZEN:
578 case CPU_DEAD:
579 case CPU_DEAD_FROZEN:
580 kfree(iucv_param[cpu]);
581 iucv_param[cpu] = NULL;
582 kfree(iucv_irq_data[cpu]);
583 iucv_irq_data[cpu] = NULL;
584 break;
585 case CPU_ONLINE:
586 case CPU_ONLINE_FROZEN:
587 case CPU_DOWN_FAILED:
588 case CPU_DOWN_FAILED_FROZEN:
589 smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
590 break;
591 case CPU_DOWN_PREPARE:
592 case CPU_DOWN_PREPARE_FROZEN:
593 cpumask = iucv_buffer_cpumask;
594 cpu_clear(cpu, cpumask);
595 if (cpus_empty(cpumask))
596
597 return NOTIFY_BAD;
598 smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
599 if (cpus_empty(iucv_irq_cpumask))
600 smp_call_function_single(first_cpu(iucv_buffer_cpumask),
601 iucv_allow_cpu, NULL, 1);
602 break;
603 }
604 return NOTIFY_OK;
605}
606
607static struct notifier_block __refdata iucv_cpu_notifier = {
608 .notifier_call = iucv_cpu_notify,
609};
610
611
612
613
614
615
616
617
618static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
619{
620 union iucv_param *parm;
621
622 parm = iucv_param[smp_processor_id()];
623 memset(parm, 0, sizeof(union iucv_param));
624 if (userdata)
625 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
626 parm->ctrl.ippathid = pathid;
627 return iucv_call_b2f0(IUCV_SEVER, parm);
628}
629
630
631
632
633
634
635
636
637static void __iucv_cleanup_queue(void *dummy)
638{
639}
640
641
642
643
644
645
646
647
648static void iucv_cleanup_queue(void)
649{
650 struct iucv_irq_list *p, *n;
651
652
653
654
655
656
657
658
659
660
661 smp_call_function(__iucv_cleanup_queue, NULL, 1);
662 spin_lock_irq(&iucv_queue_lock);
663 list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
664
665 if (iucv_path_table[p->data.ippathid] == NULL) {
666 list_del(&p->list);
667 kfree(p);
668 }
669 }
670 spin_unlock_irq(&iucv_queue_lock);
671}
672
673
674
675
676
677
678
679
680
681
682
683int iucv_register(struct iucv_handler *handler, int smp)
684{
685 int rc;
686
687 if (!iucv_available)
688 return -ENOSYS;
689 mutex_lock(&iucv_register_mutex);
690 if (!smp)
691 iucv_nonsmp_handler++;
692 if (list_empty(&iucv_handler_list)) {
693 rc = iucv_enable();
694 if (rc)
695 goto out_mutex;
696 } else if (!smp && iucv_nonsmp_handler == 1)
697 iucv_setmask_up();
698 INIT_LIST_HEAD(&handler->paths);
699
700 spin_lock_bh(&iucv_table_lock);
701 list_add_tail(&handler->list, &iucv_handler_list);
702 spin_unlock_bh(&iucv_table_lock);
703 rc = 0;
704out_mutex:
705 mutex_unlock(&iucv_register_mutex);
706 return rc;
707}
708EXPORT_SYMBOL(iucv_register);
709
710
711
712
713
714
715
716
717void iucv_unregister(struct iucv_handler *handler, int smp)
718{
719 struct iucv_path *p, *n;
720
721 mutex_lock(&iucv_register_mutex);
722 spin_lock_bh(&iucv_table_lock);
723
724 list_del_init(&handler->list);
725
726 list_for_each_entry_safe(p, n, &handler->paths, list) {
727 iucv_sever_pathid(p->pathid, NULL);
728 iucv_path_table[p->pathid] = NULL;
729 list_del(&p->list);
730 iucv_path_free(p);
731 }
732 spin_unlock_bh(&iucv_table_lock);
733 if (!smp)
734 iucv_nonsmp_handler--;
735 if (list_empty(&iucv_handler_list))
736 iucv_disable();
737 else if (!smp && iucv_nonsmp_handler == 0)
738 iucv_setmask_mp();
739 mutex_unlock(&iucv_register_mutex);
740}
741EXPORT_SYMBOL(iucv_unregister);
742
743
744
745
746
747
748
749
750
751
752
753
754
755int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
756 u8 userdata[16], void *private)
757{
758 union iucv_param *parm;
759 int rc;
760
761 local_bh_disable();
762
763 parm = iucv_param[smp_processor_id()];
764 memset(parm, 0, sizeof(union iucv_param));
765 parm->ctrl.ippathid = path->pathid;
766 parm->ctrl.ipmsglim = path->msglim;
767 if (userdata)
768 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
769 parm->ctrl.ipflags1 = path->flags;
770
771 rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
772 if (!rc) {
773 path->private = private;
774 path->msglim = parm->ctrl.ipmsglim;
775 path->flags = parm->ctrl.ipflags1;
776 }
777 local_bh_enable();
778 return rc;
779}
780EXPORT_SYMBOL(iucv_path_accept);
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
798 u8 userid[8], u8 system[8], u8 userdata[16],
799 void *private)
800{
801 union iucv_param *parm;
802 int rc;
803
804 spin_lock_bh(&iucv_table_lock);
805 iucv_cleanup_queue();
806 parm = iucv_param[smp_processor_id()];
807 memset(parm, 0, sizeof(union iucv_param));
808 parm->ctrl.ipmsglim = path->msglim;
809 parm->ctrl.ipflags1 = path->flags;
810 if (userid) {
811 memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
812 ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
813 EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
814 }
815 if (system) {
816 memcpy(parm->ctrl.iptarget, system,
817 sizeof(parm->ctrl.iptarget));
818 ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
819 EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
820 }
821 if (userdata)
822 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
823
824 rc = iucv_call_b2f0(IUCV_CONNECT, parm);
825 if (!rc) {
826 if (parm->ctrl.ippathid < iucv_max_pathid) {
827 path->pathid = parm->ctrl.ippathid;
828 path->msglim = parm->ctrl.ipmsglim;
829 path->flags = parm->ctrl.ipflags1;
830 path->handler = handler;
831 path->private = private;
832 list_add_tail(&path->list, &handler->paths);
833 iucv_path_table[path->pathid] = path;
834 } else {
835 iucv_sever_pathid(parm->ctrl.ippathid,
836 iucv_error_pathid);
837 rc = -EIO;
838 }
839 }
840 spin_unlock_bh(&iucv_table_lock);
841 return rc;
842}
843EXPORT_SYMBOL(iucv_path_connect);
844
845
846
847
848
849
850
851
852
853
854
855int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
856{
857 union iucv_param *parm;
858 int rc;
859
860 local_bh_disable();
861 parm = iucv_param[smp_processor_id()];
862 memset(parm, 0, sizeof(union iucv_param));
863 if (userdata)
864 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
865 parm->ctrl.ippathid = path->pathid;
866 rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
867 local_bh_enable();
868 return rc;
869}
870EXPORT_SYMBOL(iucv_path_quiesce);
871
872
873
874
875
876
877
878
879
880
881
882int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
883{
884 union iucv_param *parm;
885 int rc;
886
887 local_bh_disable();
888 parm = iucv_param[smp_processor_id()];
889 memset(parm, 0, sizeof(union iucv_param));
890 if (userdata)
891 memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
892 parm->ctrl.ippathid = path->pathid;
893 rc = iucv_call_b2f0(IUCV_RESUME, parm);
894 local_bh_enable();
895 return rc;
896}
897
898
899
900
901
902
903
904
905
906
907int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
908{
909 int rc;
910
911 preempt_disable();
912 if (iucv_active_cpu != smp_processor_id())
913 spin_lock_bh(&iucv_table_lock);
914 rc = iucv_sever_pathid(path->pathid, userdata);
915 if (!rc) {
916 iucv_path_table[path->pathid] = NULL;
917 list_del_init(&path->list);
918 }
919 if (iucv_active_cpu != smp_processor_id())
920 spin_unlock_bh(&iucv_table_lock);
921 preempt_enable();
922 return rc;
923}
924EXPORT_SYMBOL(iucv_path_sever);
925
926
927
928
929
930
931
932
933
934
935
936int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
937 u32 srccls)
938{
939 union iucv_param *parm;
940 int rc;
941
942 local_bh_disable();
943 parm = iucv_param[smp_processor_id()];
944 memset(parm, 0, sizeof(union iucv_param));
945 parm->purge.ippathid = path->pathid;
946 parm->purge.ipmsgid = msg->id;
947 parm->purge.ipsrccls = srccls;
948 parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
949 rc = iucv_call_b2f0(IUCV_PURGE, parm);
950 if (!rc) {
951 msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
952 msg->tag = parm->purge.ipmsgtag;
953 }
954 local_bh_enable();
955 return rc;
956}
957EXPORT_SYMBOL(iucv_message_purge);
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
975 u8 flags, void *buffer, size_t size, size_t *residual)
976{
977 union iucv_param *parm;
978 struct iucv_array *array;
979 u8 *rmmsg;
980 size_t copy;
981 int rc;
982
983 if (msg->flags & IUCV_IPRMDATA) {
984
985
986
987
988 rc = (size < 8) ? 5 : 0;
989 if (residual)
990 *residual = abs(size - 8);
991 rmmsg = msg->rmmsg;
992 if (flags & IUCV_IPBUFLST) {
993
994 size = (size < 8) ? size : 8;
995 for (array = buffer; size > 0; array++) {
996 copy = min_t(size_t, size, array->length);
997 memcpy((u8 *)(addr_t) array->address,
998 rmmsg, copy);
999 rmmsg += copy;
1000 size -= copy;
1001 }
1002 } else {
1003
1004 memcpy(buffer, rmmsg, min_t(size_t, size, 8));
1005 }
1006 return 0;
1007 }
1008
1009 local_bh_disable();
1010 parm = iucv_param[smp_processor_id()];
1011 memset(parm, 0, sizeof(union iucv_param));
1012 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1013 parm->db.ipbfln1f = (u32) size;
1014 parm->db.ipmsgid = msg->id;
1015 parm->db.ippathid = path->pathid;
1016 parm->db.iptrgcls = msg->class;
1017 parm->db.ipflags1 = (flags | IUCV_IPFGPID |
1018 IUCV_IPFGMID | IUCV_IPTRGCLS);
1019 rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
1020 if (!rc || rc == 5) {
1021 msg->flags = parm->db.ipflags1;
1022 if (residual)
1023 *residual = parm->db.ipbfln1f;
1024 }
1025 local_bh_enable();
1026 return rc;
1027}
1028EXPORT_SYMBOL(iucv_message_receive);
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1042{
1043 union iucv_param *parm;
1044 int rc;
1045
1046 local_bh_disable();
1047 parm = iucv_param[smp_processor_id()];
1048 memset(parm, 0, sizeof(union iucv_param));
1049 parm->db.ippathid = path->pathid;
1050 parm->db.ipmsgid = msg->id;
1051 parm->db.iptrgcls = msg->class;
1052 parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
1053 rc = iucv_call_b2f0(IUCV_REJECT, parm);
1054 local_bh_enable();
1055 return rc;
1056}
1057EXPORT_SYMBOL(iucv_message_reject);
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1075 u8 flags, void *reply, size_t size)
1076{
1077 union iucv_param *parm;
1078 int rc;
1079
1080 local_bh_disable();
1081 parm = iucv_param[smp_processor_id()];
1082 memset(parm, 0, sizeof(union iucv_param));
1083 if (flags & IUCV_IPRMDATA) {
1084 parm->dpl.ippathid = path->pathid;
1085 parm->dpl.ipflags1 = flags;
1086 parm->dpl.ipmsgid = msg->id;
1087 parm->dpl.iptrgcls = msg->class;
1088 memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
1089 } else {
1090 parm->db.ipbfadr1 = (u32)(addr_t) reply;
1091 parm->db.ipbfln1f = (u32) size;
1092 parm->db.ippathid = path->pathid;
1093 parm->db.ipflags1 = flags;
1094 parm->db.ipmsgid = msg->id;
1095 parm->db.iptrgcls = msg->class;
1096 }
1097 rc = iucv_call_b2f0(IUCV_REPLY, parm);
1098 local_bh_enable();
1099 return rc;
1100}
1101EXPORT_SYMBOL(iucv_message_reply);
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1119 u8 flags, u32 srccls, void *buffer, size_t size)
1120{
1121 union iucv_param *parm;
1122 int rc;
1123
1124 local_bh_disable();
1125 parm = iucv_param[smp_processor_id()];
1126 memset(parm, 0, sizeof(union iucv_param));
1127 if (flags & IUCV_IPRMDATA) {
1128
1129 parm->dpl.ippathid = path->pathid;
1130 parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
1131 parm->dpl.iptrgcls = msg->class;
1132 parm->dpl.ipsrccls = srccls;
1133 parm->dpl.ipmsgtag = msg->tag;
1134 memcpy(parm->dpl.iprmmsg, buffer, 8);
1135 } else {
1136 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1137 parm->db.ipbfln1f = (u32) size;
1138 parm->db.ippathid = path->pathid;
1139 parm->db.ipflags1 = flags | IUCV_IPNORPY;
1140 parm->db.iptrgcls = msg->class;
1141 parm->db.ipsrccls = srccls;
1142 parm->db.ipmsgtag = msg->tag;
1143 }
1144 rc = iucv_call_b2f0(IUCV_SEND, parm);
1145 if (!rc)
1146 msg->id = parm->db.ipmsgid;
1147 local_bh_enable();
1148 return rc;
1149}
1150EXPORT_SYMBOL(iucv_message_send);
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1172 u8 flags, u32 srccls, void *buffer, size_t size,
1173 void *answer, size_t asize, size_t *residual)
1174{
1175 union iucv_param *parm;
1176 int rc;
1177
1178 local_bh_disable();
1179 parm = iucv_param[smp_processor_id()];
1180 memset(parm, 0, sizeof(union iucv_param));
1181 if (flags & IUCV_IPRMDATA) {
1182 parm->dpl.ippathid = path->pathid;
1183 parm->dpl.ipflags1 = path->flags;
1184 parm->dpl.iptrgcls = msg->class;
1185 parm->dpl.ipsrccls = srccls;
1186 parm->dpl.ipmsgtag = msg->tag;
1187 parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
1188 parm->dpl.ipbfln2f = (u32) asize;
1189 memcpy(parm->dpl.iprmmsg, buffer, 8);
1190 } else {
1191 parm->db.ippathid = path->pathid;
1192 parm->db.ipflags1 = path->flags;
1193 parm->db.iptrgcls = msg->class;
1194 parm->db.ipsrccls = srccls;
1195 parm->db.ipmsgtag = msg->tag;
1196 parm->db.ipbfadr1 = (u32)(addr_t) buffer;
1197 parm->db.ipbfln1f = (u32) size;
1198 parm->db.ipbfadr2 = (u32)(addr_t) answer;
1199 parm->db.ipbfln2f = (u32) asize;
1200 }
1201 rc = iucv_call_b2f0(IUCV_SEND, parm);
1202 if (!rc)
1203 msg->id = parm->db.ipmsgid;
1204 local_bh_enable();
1205 return rc;
1206}
1207EXPORT_SYMBOL(iucv_message_send2way);
1208
1209
1210
1211
1212
1213
1214
1215
1216struct iucv_path_pending {
1217 u16 ippathid;
1218 u8 ipflags1;
1219 u8 iptype;
1220 u16 ipmsglim;
1221 u16 res1;
1222 u8 ipvmid[8];
1223 u8 ipuser[16];
1224 u32 res3;
1225 u8 ippollfg;
1226 u8 res4[3];
1227} __attribute__ ((packed));
1228
1229static void iucv_path_pending(struct iucv_irq_data *data)
1230{
1231 struct iucv_path_pending *ipp = (void *) data;
1232 struct iucv_handler *handler;
1233 struct iucv_path *path;
1234 char *error;
1235
1236 BUG_ON(iucv_path_table[ipp->ippathid]);
1237
1238 error = iucv_error_no_memory;
1239 path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
1240 if (!path)
1241 goto out_sever;
1242 path->pathid = ipp->ippathid;
1243 iucv_path_table[path->pathid] = path;
1244 EBCASC(ipp->ipvmid, 8);
1245
1246
1247 list_for_each_entry(handler, &iucv_handler_list, list) {
1248 if (!handler->path_pending)
1249 continue;
1250
1251
1252
1253
1254
1255 list_add(&path->list, &handler->paths);
1256 path->handler = handler;
1257 if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
1258 return;
1259 list_del(&path->list);
1260 path->handler = NULL;
1261 }
1262
1263 iucv_path_table[path->pathid] = NULL;
1264 iucv_path_free(path);
1265 error = iucv_error_no_listener;
1266out_sever:
1267 iucv_sever_pathid(ipp->ippathid, error);
1268}
1269
1270
1271
1272
1273
1274
1275
1276
1277struct iucv_path_complete {
1278 u16 ippathid;
1279 u8 ipflags1;
1280 u8 iptype;
1281 u16 ipmsglim;
1282 u16 res1;
1283 u8 res2[8];
1284 u8 ipuser[16];
1285 u32 res3;
1286 u8 ippollfg;
1287 u8 res4[3];
1288} __attribute__ ((packed));
1289
1290static void iucv_path_complete(struct iucv_irq_data *data)
1291{
1292 struct iucv_path_complete *ipc = (void *) data;
1293 struct iucv_path *path = iucv_path_table[ipc->ippathid];
1294
1295 if (path && path->handler && path->handler->path_complete)
1296 path->handler->path_complete(path, ipc->ipuser);
1297}
1298
1299
1300
1301
1302
1303
1304
1305
1306struct iucv_path_severed {
1307 u16 ippathid;
1308 u8 res1;
1309 u8 iptype;
1310 u32 res2;
1311 u8 res3[8];
1312 u8 ipuser[16];
1313 u32 res4;
1314 u8 ippollfg;
1315 u8 res5[3];
1316} __attribute__ ((packed));
1317
1318static void iucv_path_severed(struct iucv_irq_data *data)
1319{
1320 struct iucv_path_severed *ips = (void *) data;
1321 struct iucv_path *path = iucv_path_table[ips->ippathid];
1322
1323 if (!path || !path->handler)
1324 return;
1325 if (path->handler->path_severed)
1326 path->handler->path_severed(path, ips->ipuser);
1327 else {
1328 iucv_sever_pathid(path->pathid, NULL);
1329 iucv_path_table[path->pathid] = NULL;
1330 list_del_init(&path->list);
1331 iucv_path_free(path);
1332 }
1333}
1334
1335
1336
1337
1338
1339
1340
1341
1342struct iucv_path_quiesced {
1343 u16 ippathid;
1344 u8 res1;
1345 u8 iptype;
1346 u32 res2;
1347 u8 res3[8];
1348 u8 ipuser[16];
1349 u32 res4;
1350 u8 ippollfg;
1351 u8 res5[3];
1352} __attribute__ ((packed));
1353
1354static void iucv_path_quiesced(struct iucv_irq_data *data)
1355{
1356 struct iucv_path_quiesced *ipq = (void *) data;
1357 struct iucv_path *path = iucv_path_table[ipq->ippathid];
1358
1359 if (path && path->handler && path->handler->path_quiesced)
1360 path->handler->path_quiesced(path, ipq->ipuser);
1361}
1362
1363
1364
1365
1366
1367
1368
1369
1370struct iucv_path_resumed {
1371 u16 ippathid;
1372 u8 res1;
1373 u8 iptype;
1374 u32 res2;
1375 u8 res3[8];
1376 u8 ipuser[16];
1377 u32 res4;
1378 u8 ippollfg;
1379 u8 res5[3];
1380} __attribute__ ((packed));
1381
1382static void iucv_path_resumed(struct iucv_irq_data *data)
1383{
1384 struct iucv_path_resumed *ipr = (void *) data;
1385 struct iucv_path *path = iucv_path_table[ipr->ippathid];
1386
1387 if (path && path->handler && path->handler->path_resumed)
1388 path->handler->path_resumed(path, ipr->ipuser);
1389}
1390
1391
1392
1393
1394
1395
1396
1397
1398struct iucv_message_complete {
1399 u16 ippathid;
1400 u8 ipflags1;
1401 u8 iptype;
1402 u32 ipmsgid;
1403 u32 ipaudit;
1404 u8 iprmmsg[8];
1405 u32 ipsrccls;
1406 u32 ipmsgtag;
1407 u32 res;
1408 u32 ipbfln2f;
1409 u8 ippollfg;
1410 u8 res2[3];
1411} __attribute__ ((packed));
1412
1413static void iucv_message_complete(struct iucv_irq_data *data)
1414{
1415 struct iucv_message_complete *imc = (void *) data;
1416 struct iucv_path *path = iucv_path_table[imc->ippathid];
1417 struct iucv_message msg;
1418
1419 if (path && path->handler && path->handler->message_complete) {
1420 msg.flags = imc->ipflags1;
1421 msg.id = imc->ipmsgid;
1422 msg.audit = imc->ipaudit;
1423 memcpy(msg.rmmsg, imc->iprmmsg, 8);
1424 msg.class = imc->ipsrccls;
1425 msg.tag = imc->ipmsgtag;
1426 msg.length = imc->ipbfln2f;
1427 path->handler->message_complete(path, &msg);
1428 }
1429}
1430
1431
1432
1433
1434
1435
1436
1437
1438struct iucv_message_pending {
1439 u16 ippathid;
1440 u8 ipflags1;
1441 u8 iptype;
1442 u32 ipmsgid;
1443 u32 iptrgcls;
1444 union {
1445 u32 iprmmsg1_u32;
1446 u8 iprmmsg1[4];
1447 } ln1msg1;
1448 union {
1449 u32 ipbfln1f;
1450 u8 iprmmsg2[4];
1451 } ln1msg2;
1452 u32 res1[3];
1453 u32 ipbfln2f;
1454 u8 ippollfg;
1455 u8 res2[3];
1456} __attribute__ ((packed));
1457
1458static void iucv_message_pending(struct iucv_irq_data *data)
1459{
1460 struct iucv_message_pending *imp = (void *) data;
1461 struct iucv_path *path = iucv_path_table[imp->ippathid];
1462 struct iucv_message msg;
1463
1464 if (path && path->handler && path->handler->message_pending) {
1465 msg.flags = imp->ipflags1;
1466 msg.id = imp->ipmsgid;
1467 msg.class = imp->iptrgcls;
1468 if (imp->ipflags1 & IUCV_IPRMDATA) {
1469 memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1470 msg.length = 8;
1471 } else
1472 msg.length = imp->ln1msg2.ipbfln1f;
1473 msg.reply_size = imp->ipbfln2f;
1474 path->handler->message_pending(path, &msg);
1475 }
1476}
1477
1478
1479
1480
1481
1482
1483
1484
1485static void iucv_tasklet_fn(unsigned long ignored)
1486{
1487 typedef void iucv_irq_fn(struct iucv_irq_data *);
1488 static iucv_irq_fn *irq_fn[] = {
1489 [0x02] = iucv_path_complete,
1490 [0x03] = iucv_path_severed,
1491 [0x04] = iucv_path_quiesced,
1492 [0x05] = iucv_path_resumed,
1493 [0x06] = iucv_message_complete,
1494 [0x07] = iucv_message_complete,
1495 [0x08] = iucv_message_pending,
1496 [0x09] = iucv_message_pending,
1497 };
1498 LIST_HEAD(task_queue);
1499 struct iucv_irq_list *p, *n;
1500
1501
1502 if (!spin_trylock(&iucv_table_lock)) {
1503 tasklet_schedule(&iucv_tasklet);
1504 return;
1505 }
1506 iucv_active_cpu = smp_processor_id();
1507
1508 spin_lock_irq(&iucv_queue_lock);
1509 list_splice_init(&iucv_task_queue, &task_queue);
1510 spin_unlock_irq(&iucv_queue_lock);
1511
1512 list_for_each_entry_safe(p, n, &task_queue, list) {
1513 list_del_init(&p->list);
1514 irq_fn[p->data.iptype](&p->data);
1515 kfree(p);
1516 }
1517
1518 iucv_active_cpu = -1;
1519 spin_unlock(&iucv_table_lock);
1520}
1521
1522
1523
1524
1525
1526
1527
1528
1529static void iucv_work_fn(struct work_struct *work)
1530{
1531 typedef void iucv_irq_fn(struct iucv_irq_data *);
1532 LIST_HEAD(work_queue);
1533 struct iucv_irq_list *p, *n;
1534
1535
1536 spin_lock_bh(&iucv_table_lock);
1537 iucv_active_cpu = smp_processor_id();
1538
1539 spin_lock_irq(&iucv_queue_lock);
1540 list_splice_init(&iucv_work_queue, &work_queue);
1541 spin_unlock_irq(&iucv_queue_lock);
1542
1543 iucv_cleanup_queue();
1544 list_for_each_entry_safe(p, n, &work_queue, list) {
1545 list_del_init(&p->list);
1546 iucv_path_pending(&p->data);
1547 kfree(p);
1548 }
1549
1550 iucv_active_cpu = -1;
1551 spin_unlock_bh(&iucv_table_lock);
1552}
1553
1554
1555
1556
1557
1558
1559
1560
1561static void iucv_external_interrupt(u16 code)
1562{
1563 struct iucv_irq_data *p;
1564 struct iucv_irq_list *work;
1565
1566 p = iucv_irq_data[smp_processor_id()];
1567 if (p->ippathid >= iucv_max_pathid) {
1568 WARN_ON(p->ippathid >= iucv_max_pathid);
1569 iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
1570 return;
1571 }
1572 BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
1573 work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
1574 if (!work) {
1575 printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
1576 return;
1577 }
1578 memcpy(&work->data, p, sizeof(work->data));
1579 spin_lock(&iucv_queue_lock);
1580 if (p->iptype == 0x01) {
1581
1582 list_add_tail(&work->list, &iucv_work_queue);
1583 schedule_work(&iucv_work);
1584 } else {
1585
1586 list_add_tail(&work->list, &iucv_task_queue);
1587 tasklet_schedule(&iucv_tasklet);
1588 }
1589 spin_unlock(&iucv_queue_lock);
1590}
1591
1592
1593
1594
1595
1596
1597static int __init iucv_init(void)
1598{
1599 int rc;
1600 int cpu;
1601
1602 if (!MACHINE_IS_VM) {
1603 rc = -EPROTONOSUPPORT;
1604 goto out;
1605 }
1606 rc = iucv_query_maxconn();
1607 if (rc)
1608 goto out;
1609 rc = register_external_interrupt(0x4000, iucv_external_interrupt);
1610 if (rc)
1611 goto out;
1612 iucv_root = s390_root_dev_register("iucv");
1613 if (IS_ERR(iucv_root)) {
1614 rc = PTR_ERR(iucv_root);
1615 goto out_int;
1616 }
1617
1618 for_each_online_cpu(cpu) {
1619
1620 iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
1621 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1622 if (!iucv_irq_data[cpu]) {
1623 rc = -ENOMEM;
1624 goto out_free;
1625 }
1626
1627
1628 iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
1629 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
1630 if (!iucv_param[cpu]) {
1631 rc = -ENOMEM;
1632 goto out_free;
1633 }
1634 }
1635 rc = register_hotcpu_notifier(&iucv_cpu_notifier);
1636 if (rc)
1637 goto out_free;
1638 ASCEBC(iucv_error_no_listener, 16);
1639 ASCEBC(iucv_error_no_memory, 16);
1640 ASCEBC(iucv_error_pathid, 16);
1641 iucv_available = 1;
1642 rc = bus_register(&iucv_bus);
1643 if (rc)
1644 goto out_cpu;
1645 return 0;
1646
1647out_cpu:
1648 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1649out_free:
1650 for_each_possible_cpu(cpu) {
1651 kfree(iucv_param[cpu]);
1652 iucv_param[cpu] = NULL;
1653 kfree(iucv_irq_data[cpu]);
1654 iucv_irq_data[cpu] = NULL;
1655 }
1656 s390_root_dev_unregister(iucv_root);
1657out_int:
1658 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1659out:
1660 return rc;
1661}
1662
1663
1664
1665
1666
1667
1668static void __exit iucv_exit(void)
1669{
1670 struct iucv_irq_list *p, *n;
1671 int cpu;
1672
1673 spin_lock_irq(&iucv_queue_lock);
1674 list_for_each_entry_safe(p, n, &iucv_task_queue, list)
1675 kfree(p);
1676 list_for_each_entry_safe(p, n, &iucv_work_queue, list)
1677 kfree(p);
1678 spin_unlock_irq(&iucv_queue_lock);
1679 unregister_hotcpu_notifier(&iucv_cpu_notifier);
1680 for_each_possible_cpu(cpu) {
1681 kfree(iucv_param[cpu]);
1682 iucv_param[cpu] = NULL;
1683 kfree(iucv_irq_data[cpu]);
1684 iucv_irq_data[cpu] = NULL;
1685 }
1686 s390_root_dev_unregister(iucv_root);
1687 bus_unregister(&iucv_bus);
1688 unregister_external_interrupt(0x4000, iucv_external_interrupt);
1689}
1690
1691subsys_initcall(iucv_init);
1692module_exit(iucv_exit);
1693
1694MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
1695MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
1696MODULE_LICENSE("GPL");
1697