-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathqeth.c
executable file
·6665 lines (5715 loc) · 256 KB
/
qeth.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* QETH.C (c) Copyright Jan Jaeger, 1999-2012 */
/* OSA Express */
/* */
/* This module contains device handling functions for the */
/* OSA Express emulated card */
/* */
/* This implementation is based on the S/390 Linux implementation */
/* */
/* Device module hdtqeth */
/* */
/* hercules.cnf: */
/* 0A00-0A02 QETH <optional parameters> */
/* Default parm: iface /dev/net/tun */
/* Optional parms: ifname <name of interface> */
/* hwaddr <MAC address> */
/* ipaddr <IPv4 address and prefix length> */
/* netmask <IPv4 netmask> */
/* ipaddr6 <IPv6 address and prefix length> */
/* mtu <MTU> */
/* chpid <channel path id> */
/* debug */
/* */
/* When using a bridged configuration no parameters are required */
/* on the QETH device statement. The tap device will in that case */
/* need to be bridged to another virtual or real ethernet adapter. */
/* e.g. */
/* 0A00.3 QETH */
/* The tap device will need to be bridged e.g. */
/* brctl addif <bridge> tap0 */
/* */
/* When using a routed configuration the tap device needs to have */
/* an IP address assigned in the same subnet as the guests virtual */
/* eth adapter. */
/* e.g. */
/* 0A00.3 QETH ipaddr 192.168.10.1 */
/* where the guest can then use any other IP address in the */
/* 192.168.10 range */
/* */
/* */
/* zLinux defines which three devices addresses are used for what */
/* purpose depending on on the distribution. */
/* Debian, in a file named, for example, config-ccw-0.0.0800, in the */
/* /etc/sysconfig/hardware directory, has the CCWGROUP_CHANS */
/* statement. An example CCWGROUP_CHANS statement is:- */
/* CCWGROUP_CHANS=(0.0.0800 0.0.0801 0.0.0802) */
/* Similarly, Fedora, in a file named, for example, */
/* ifcfg-enccw0.0.0800, in the /etc/sysconfig/network-scripts */
/* directory, has the SUBCHANNELS statement. An example SUBCHANNELS */
/* statement is:- */
/* SUBCHANNELS="0.0.0800,0.0.0801,0.0.0802" */
/* With the example SUBCHANNELS statement the first device address, */
/* i.e. 800, would be used for the read device, the second device */
/* address, i.e. 801, would be used for the write device, and the */
/* third device address, i.e. 802, would be used for the data */
/* device. However, if the SUBCHANNELS statement were specified as:- */
/* SUBCHANNELS="0.0.0802,0.0.0800,0.0.0801" */
/* then device address 802 would be used for the read device, device */
/* address 800 would be used for the write device, and device */
/* address 801 would be used for the data device. */
/* (It's not clear whether the group of device addresses even needs */
/* to be consecutive?) */
/* */
/* z/VM defines which devices addresses are used for what purpose in */
/* the 'DEVICE and LINK Statements for OSD Devices' (see 'z/VM: */
/* TCP/IP Planning and Customization'). A single device address */
/* specifies the first of three consecutive virtual device numbers */
/* to be grouped for the OSA-Express Adapter. TCP/IP uses the first */
/* device address for the data device, the second device address for */
/* the read device, and the third device address for the write */
/* device. */
/* */
/* z/OS defines which devices addresses are used for what purpose in */
/* a VTAM 'Transport resource list major node' (a TRLE, see 'z/OS */
/* Communication Server: SNA Reource Definition Guide'). One read */
/* device address, one write device address, and up to 238 data */
/* device addresses must be specified. The read device address must */
/* be an even number, and the write device address must be an odd */
/* number that is one greater than the read device address. Each */
/* TCP/IP in the same logical partition instance that starts an */
/* OSA-Express in QDIO mode is assigned one of the data device */
/* addresses by VTAM. Each TCP/IP in the same logical partition */
/* instance that starts an OSA-Express network traffic analyzer */
/* (OSAENTA) trace is also assigned one of the DATAPATH channels by */
/* VTAM. A sufficient number of data device addresses must be coded */
/* for the number of concurrent instances that will be using an */
/* OSA-Express port. For example, if you wanted three instances of */
/* TCP/IP in the same logical partition, you could code the DATAPATH */
/* operand in the TRLE as follows: */
/* DATAPATH=(402,403,404), or DATAPATH=(402-404). */
/* */
/* The OSA-Express Implementation Guide says:- */
/* - Any OSD, OSX, or OSM CHPID (QDIO mode) requires at least three */
/* devices for each TCP/IP stack: read, write, and data path. For */
/* z/OS, only the first TCP/IP stack requires three devices. Any */
/* additional TCP/IP stack requires only one device (data path). If */
/* you define both IPv4 and IPv6 with INTERFACE statements, z/OS */
/* will use two data devices, one for each protocol. */
/* - If you plan to use the OSA-Express Network Traffic Analyzer, */
/* you need one more data device, which is used to transmit the */
/* captured trace data to TCP/IP. */
/* - Any OSE CHPID requires two devices (read and write) for each */
/* TCP/IP. SNA requires one device. */
/* */
/* */
/* Note: QETH.C uses many TUNTAP functions to control and manipulate */
/* the settings of the TUN or TAP interface. */
/* */
/* Many of the TUNTAP functions used by QETH.C on *nix, i.e. */
/* TUNTAP_SetFlags, TUNTAP_SetMACAddr, TUNTAP_SetIPAddr, */
/* TUNTAP_SetIPAddr6, TUNTAP_SetDestAddr, TUNTAP_SetNetMask and */
/* TUNTAP_SetMTU, return a return code that is actually the return */
/* code from function IFC_IOCtl. The return code from IFC_IOCtl */
/* will normally be zero, indicating that the interface manipulation */
/* request was successfully sent to hercifc. So, in general on *nix, */
/* the TUNTAP function return codes do not indicate whether the */
/* interface has been manipulated successfully or not, they simply */
/* indicate that the manipulation request should be issued at some */
/* point in the near future. Beware. */
/* */
#include "hstdinc.h"
DISABLE_GCC_WARNING( "-Wunused-function" )
#include "hercules.h"
#include "devtype.h"
#include "chsc.h"
#include "mpc.h"
#include "tuntap.h"
#include "resolve.h"
#include "ctcadpt.h"
#include "hercifc.h"
#include "qeth.h"
/*-------------------------------------------------------------------*/
/* QETH Debugging */
/*-------------------------------------------------------------------*/
#define ENABLE_QETH_DEBUG 1 // 1:enable, 0:disable, #undef:default
#define QETH_PTT_TRACING // #define to enable PTT debug tracing
#define QETH_DUMP_DATA // #undef to suppress i/o buffers dump
/*-------------------------------------------------------------------*/
/* QETH Debugging */
/*-------------------------------------------------------------------*/
/* (enable debugging if needed/requested) */
#if (!defined(ENABLE_QETH_DEBUG) && defined(DEBUG)) || \
( defined(ENABLE_QETH_DEBUG) && ENABLE_QETH_DEBUG)
#define QETH_DEBUG
#endif
/* (activate debugging if debugging is enabled) */
#if defined(QETH_DEBUG)
#define ENABLE_TRACING_STMTS 1 // (Fish: DEBUGGING)
#include "dbgtrace.h" // (Fish: DEBUGGING)
#define NO_QETH_OPTIMIZE // (Fish: DEBUGGING) (MSVC only)
#define QETH_PTT_TRACING // (Fish: DEBUG speed/debugging)
#endif
/* (disable optimizations if debugging) */
#if defined( _MSVC_ ) && defined( NO_QETH_OPTIMIZE )
#pragma optimize( "", off ) // disable optimizations for reliable breakpoints
#endif
/* (QETH speed/performance/debugging) */
#if defined( QETH_PTT_TRACING )
#define PTT_QETH_TRACE( _string, _tr1, _tr2, _tr3) \
PTT(PTT_CL_INF, _string, _tr1, _tr2, _tr3)
#else
#define PTT_QETH_TRACE(...) // (do nothing)
#endif
/* DBGTRC statements controlled by dev stmt "debug" option */
static void DBGTRC( DEVBLK* dev, char* fmt, ... )
{
DEVGRP *devgrp = dev->group;
if (devgrp)
{
OSA_GRP* grp = devgrp->grp_data;
if (grp && grp->debugmask)
{
char buf[256];
va_list vargs;
va_start( vargs, fmt );
#if defined( _MSVC_ )
_vsnprintf_s( buf, sizeof(buf), _TRUNCATE, fmt, vargs );
#else
vsnprintf( buf, sizeof(buf), fmt, vargs );
#endif
// HHC03991 "%1d:%04X %s: %s"
WRMSG( HHC03991, "D", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname,
buf );
va_end( vargs );
}
}
}
/* (trace I/O data buffers if debugging) */
#if defined( QETH_DUMP_DATA )
#define MPC_DUMP_DATA(_str,_adr,_len,_dir) \
net_data_trace( dev, _adr, _len, _dir, 'D', _str, 0 );
#else
#define MPC_DUMP_DATA(...) // (do nothing)
#endif // QETH_DUMP_DATA
/* DBGUPD statements controlled by "debugupdown" option */
static void DBGUPD( DEVBLK* dev, int what, void* adr, int len, BYTE dir, char* fmt, ... )
{
DEVGRP *devgrp = dev->group;
if (devgrp)
{
OSA_GRP* grp = devgrp->grp_data;
if (grp && (grp->debugmask & DBGQETHUPDOWN))
{
char buf[256];
va_list vargs;
va_start( vargs, fmt );
#if defined( _MSVC_ )
_vsnprintf_s( buf, sizeof(buf), _TRUNCATE, fmt, vargs );
#else
vsnprintf( buf, sizeof(buf), fmt, vargs );
#endif
// HHC03991 "%1d:%04X %s: %s"
WRMSG( HHC03991, "D", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname,
buf );
va_end( vargs );
if (what == 3) {
mpc_display_osa_iear( dev, adr, dir, len );
} else if (what == 2) {
mpc_display_osa_iea( dev, adr, dir, len );
} else if (what == 1) {
mpc_display_osa_th_etc( dev, adr, dir, 0 );
} else {
mpc_display_stuff( dev, "", adr, len, dir );
}
}
}
}
/*-------------------------------------------------------------------*/
/* Hercules Dynamic Loader (HDL) */
/*-------------------------------------------------------------------*/
#if defined( OPTION_DYNAMIC_LOAD )
#if defined( WIN32 ) && !defined( _MSVC_ ) && !defined( HDL_USE_LIBTOOL )
SYSBLK *psysblk;
#define sysblk (*psysblk)
#endif
#endif /*defined( OPTION_DYNAMIC_LOAD )*/
/*-------------------------------------------------------------------*/
/* Helper functions, entirely internal to qeth.c */
/*-------------------------------------------------------------------*/
static OSA_BHR* process_cm_enable( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_cm_setup( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_cm_takedown( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_cm_disable( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static int process_ulp_enable_extract( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_ulp_enable( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_ulp_setup( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_dm_act( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_ulp_takedown( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* process_ulp_disable( DEVBLK*, MPC_TH*, MPC_RRH*, MPC_PUK* );
static OSA_BHR* alloc_buffer( DEVBLK*, int );
static void add_buffer_to_chain( OSA_BAN*, OSA_BHR* );
static OSA_BHR* remove_buffer_from_chain( OSA_BAN* );
static void remove_and_free_any_buffers_on_chain( OSA_BAN* );
static void signal_idx_event( OSA_GRP* );
static void InitMACAddr( DEVBLK* dev, OSA_GRP* grp );
static void InitMTU ( DEVBLK* dev, OSA_GRP* grp );
static int netmask2prefix( char* ttnetmask, char** ttpfxlen );
static int prefix2netmask( char* ttpfxlen, char** ttnetmask );
static U32 makepfxmask4( char* ttpfxlen );
static void makepfxmask6( char* ttpfxlen6, BYTE* pfxmask6 );
static void qeth_init_queues(DEVBLK *dev);
static void qeth_init_queue(DEVBLK *dev, int output);
#if defined(ENABLE_IPV6)
static void process_l3_icmpv6_packet(DEVBLK*, OSA_GRP*, IP6FRM*);
static void calculate_icmpv6_checksum(IP6FRM*, BYTE*, int);
#endif /*defined(ENABLE_IPV6)*/
/*-------------------------------------------------------------------*/
/* Configuration Data Constants */
/*-------------------------------------------------------------------*/
static const NED osa_device_ned[] = {OSA_DEVICE_NED};
static const NED osa_ctlunit_ned[] = {OSA_CTLUNIT_NED};
static const NED osa_token_ned[] = {OSA_TOKEN_NED};
static const NEQ osa_general_neq[] = {OSA_GENERAL_NEQ};
static NED configuration_data[4]; // (initialized by HDL_DEPENDENCY_SECTION)
static const ND osa_nd[] = {OSA_ND};
static const NQ osa_nq[] = {OSA_NQ};
static ND node_data[2]; // (initialized by HDL_DEPENDENCY_SECTION)
#define SII_SIZE sizeof(U32)
static const BYTE sense_id_bytes[] =
{
0xFF, /* Always 0xFF */
OSA_SNSID_1731_01, /* Control Unit type/model */
OSA_SNSID_1732_01, /* I/O Device type/model */
0x00, /* Always 0x00 */
OSA_RCD_CIW, /* Read Config. Data CIW */
OSA_SII_CIW, /* Set Interface Id. CIW */
OSA_RNI_CIW, /* Read Node Identifier CIW */
OSA_EQ_CIW, /* Establish Queues CIW */
OSA_AQ_CIW /* Activate Queues CIW */
};
static BYTE qeth_immed_commands [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0, /* 00 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, /* 10 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 20 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 30 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 40 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 50 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 60 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 70 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 80 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 90 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* A0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* B0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* C0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* D0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* E0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* F0 */
};
/*-------------------------------------------------------------------*/
/* Internal socket pipe signals used to request something */
/*-------------------------------------------------------------------*/
#define QDSIG_RESET 0 /* Used to reset signal flag */
#define QDSIG_HALT 1 /* Halt Device signalling */
#define QDSIG_SYNC 2 /* SIGA Synchronize */
#define QDSIG_READ 3 /* SIGA Initiate Input */
#define QDSIG_RDMULT 4 /* SIGA Initiate Input Multiple */
#define QDSIG_WRIT 5 /* SIGA Initiate Output */
#define QDSIG_WRMULT 6 /* SIGA Initiate Output Multiple */
#define QDSIG_WAKEUP 7 /* Wakeup signalling */
static const char* qsig2str( BYTE sig ) {
static const char* sigstr[] = {
/*0*/ "QDSIG_RESET",
/*1*/ "QDSIG_HALT",
/*2*/ "QDSIG_SYNC",
/*3*/ "QDSIG_READ",
/*4*/ "QDSIG_RDMULT",
/*5*/ "QDSIG_WRIT",
/*6*/ "QDSIG_WRMULT",
/*7*/ "QDSIG_WAKEUP",
}; static char buf[16];
if (sig < _countof( sigstr ))
return sigstr[ sig ];
MSGBUF(buf,"QDSIG_0x%02X",sig);
return buf;
}
/*-------------------------------------------------------------------*/
/* The following is the original macro comment - kept for historical */
/* value */
/*-------------------------------------------------------------------*/
/* STORCHK macro: check storage access & update ref & change bits. */
/* Returns 0 if successful or CSW_PROGC or CSW_PROTC if error. */
/* Storage key ref & change bits are only updated if successful. */
/*-------------------------------------------------------------------*/
/* Make the macro unto an inline function - same perf, less arcane @ISW */
/* NOTE : This should probably go into qdio.h */
static inline int qeth_storage_access_check(U64 addr, size_t len,int key,int acc, DEVBLK *dev)
{
if(addr+len>dev->mainlim)
{
DBGTRC(dev,"Address %llx above main storage\n",addr);
return CSW_PROGC; /* Outside storage */
}
if(dev->orb.flag5 & ORB5_A) /* Address limit checking enabled ?*/
{
if(dev->pmcw.flag5 & PMCW5_LM_LOW) /* Low address defined ? */
{
if(addr<sysblk.addrlimval)
{
DBGTRC(dev,"Address %llx below limit of %llx\n",addr,sysblk.addrlimval);
return CSW_PROGC;
}
}
if(dev->pmcw.flag5 & PMCW5_LM_HIGH) /* High address defined ? */
{
if((addr+len)>sysblk.addrlimval)
{
DBGTRC(dev,"Address %llx above limit of %llx\n",addr+len,sysblk.addrlimval);
return CSW_PROGC;
}
}
}
/* key 0 always right */
if(key==0) return 0;
/* This may not be described anywhere - and could be wrong */
/* But apparently z/VM TC/IP expects Key 14 to allow access to all */
/* including storage frames with key 0.... */
/* and apparently z/OS TCP/IP expects Key 6 to allow access to all */
/* including storage frames with key 0.... */
if((key & 0Xf0)==0xe0) return 0; /* Special case for key 14 ? */
if((key & 0Xf0)==0x60) return 0; /* Special case for key 6 ? */
/* Key match check if keys match we're good */
if((STORAGE_KEY(addr,dev) & STORKEY_KEY) == key) return 0;
/* Ok for fetch when key mismatches */
if(!((STORAGE_KEY(addr,dev)) & STORKEY_FETCH) && acc==STORKEY_FETCH) return 0;
/* Ok for write or fetch when write allowed even on key mismatch */
if(((STORAGE_KEY(addr,dev)) & STORKEY_CHANGE)) return 0;
DBGTRC(dev,"Key mismatch protection exception : requested key : %x, storage key : %x access type %x\n",key,STORAGE_KEY(addr,dev),acc);
return CSW_PROTC;
}
/* The following function updates the storage key on access */
static inline int qeth_storage_access_check_and_update(U64 addr, size_t len,int key,int acc, DEVBLK *dev)
{
int rc;
rc=qeth_storage_access_check(addr,len,key,acc,dev);
if(rc==0)
{
/* Update the REF/CHANGE flag in the storage key */
STORAGE_KEY(addr,dev)|=(acc & (STORKEY_FETCH | STORKEY_CHANGE));
}
return rc;
}
/* Macro wrapper */
#define STORCHK(_addr,_len,_key,_acc,_dev) qeth_storage_access_check_and_update(_addr,_len,_key,_acc,_dev)
#if defined(_FEATURE_QDIO_THININT)
/*-------------------------------------------------------------------*/
/* Set Adapter Local Summary Indicator bits */
/*-------------------------------------------------------------------*/
static inline void set_alsi(DEVBLK *dev, BYTE bits)
{
if(dev->qdio.alsi)
{
BYTE *alsi = dev->mainstor + dev->qdio.alsi;
obtain_lock(&sysblk.mainlock);
*alsi |= bits;
STORAGE_KEY(dev->qdio.alsi, dev) |= (STORKEY_REF|STORKEY_CHANGE);
release_lock(&sysblk.mainlock);
}
}
#define SET_ALSI(_dev,_bits) set_alsi((_dev),(_bits))
#if 0
dead code and also over in zfcp.c
/*-------------------------------------------------------------------*/
/* Clear Adapter Local Summary Indicator bits */
/*-------------------------------------------------------------------*/
static inline void clr_alsi(DEVBLK *dev, BYTE bits)
{
if(dev->qdio.alsi)
{
BYTE *alsi = dev->mainstor + dev->qdio.alsi;
obtain_lock(&sysblk.mainlock);
*alsi &= bits;
STORAGE_KEY(dev->qdio.alsi, dev) |= (STORKEY_REF|STORKEY_CHANGE);
release_lock(&sysblk.mainlock);
}
}
#endif
#define CLR_ALSI(_dev,_bits) clr_alsi((_dev),(_bits))
/*-------------------------------------------------------------------*/
/* Set Device State Change Indicator bits */
/*-------------------------------------------------------------------*/
static inline void set_dsci(DEVBLK *dev, BYTE bits)
{
if(dev->qdio.dsci)
{
BYTE *dsci = dev->mainstor + dev->qdio.dsci;
BYTE *alsi = dev->mainstor + dev->qdio.alsi;
obtain_lock(&sysblk.mainlock);
*dsci |= bits;
STORAGE_KEY(dev->qdio.dsci, dev) |= (STORKEY_REF|STORKEY_CHANGE);
*alsi |= bits;
STORAGE_KEY(dev->qdio.alsi, dev) |= (STORKEY_REF|STORKEY_CHANGE);
release_lock(&sysblk.mainlock);
}
}
#define SET_DSCI(_dev,_bits) set_dsci((_dev),(_bits))
#if 0
dead code and also over in zfcp.c
/*-------------------------------------------------------------------*/
/* Clear Device State Change Indicator bits */
/*-------------------------------------------------------------------*/
static inline void clr_dsci(DEVBLK *dev, BYTE bits)
{
if(dev->qdio.dsci)
{
BYTE *dsci = dev->mainstor + dev->qdio.dsci;
obtain_lock(&sysblk.mainlock);
*dsci &= bits;
STORAGE_KEY(dev->qdio.dsci, dev) |= (STORKEY_REF|STORKEY_CHANGE);
release_lock(&sysblk.mainlock);
}
}
#endif
#define CLR_DSCI(_dev,_bits) clr_dsci((_dev),(_bits))
#else /*!defined(_FEATURE_QDIO_THININT)*/
#define SET_ALSI(_dev,_bits) /* (do nothing) */
#define CLR_ALSI(_dev,_bits) /* (do nothing) */
#define SET_DSCI(_dev,_bits) /* (do nothing) */
#define CLR_DSCI(_dev,_bits) /* (do nothing) */
#endif /*defined(_FEATURE_QDIO_THININT)*/
/*-------------------------------------------------------------------*/
/* Register local MAC address */
/*-------------------------------------------------------------------*/
/* The returned values are:- */
/* -1 The table is full */
/* 0 The MAC address was added to the table */
/* 1 The MAC address was already in the table */
static int register_mac(OSA_GRP *grp, DEVBLK* dev, BYTE *mac, int type)
{
int i;
char charmac[24];
/* Check whether the MAC address is already registered. */
for (i = 0; i < OSA_MAXMAC; i++)
{
if (grp->mac[i].type &&
memcmp(grp->mac[i].addr, mac, IFHWADDRLEN) == 0)
{
return 1;
}
}
/* Register the previously unknown MAC address. */
for (i = 0; i < OSA_MAXMAC; i++)
{
if (!grp->mac[i].type)
{
memcpy(grp->mac[i].addr, mac, IFHWADDRLEN);
grp->mac[i].type = type;
snprintf( charmac, sizeof(charmac),
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
// HHC03801 "%1d:%04X %s: %s: Register guest MAC address %s"
WRMSG(HHC03801, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charmac );
return 0;
}
}
/* Oh dear, the MAC address table is full. */
snprintf( charmac, sizeof(charmac),
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
// HHC03802 "%1d:%04X %s: %s: Cannot register guest MAC address %s"
WRMSG(HHC03802, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charmac );
return -1;
}
/*-------------------------------------------------------------------*/
/* Unregister local MAC address */
/*-------------------------------------------------------------------*/
/* The returned values are:- */
/* 0 The MAC address was removed from the table */
/* 1 The MAC address was not in the table */
static int unregister_mac(OSA_GRP *grp, DEVBLK* dev, BYTE *mac, int type)
{
int i;
char charmac[24];
UNREFERENCED(type);
/* Check whether the MAC address is registered. */
for (i = 0; i < OSA_MAXMAC; i++)
{
if (grp->mac[i].type &&
memcmp(grp->mac[i].addr, mac, IFHWADDRLEN) == 0)
{
grp->mac[i].type = MAC_TYPE_NONE;
memset(grp->mac[i].addr, 0, IFHWADDRLEN);
snprintf( charmac, sizeof(charmac),
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
// HHC03803 "%1d:%04X %s: %s: Unregistered guest MAC address %s"
WRMSG(HHC03803, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charmac );
return 0;
}
}
/* Oh dear, the MAC address wasn't registered. */
snprintf( charmac, sizeof(charmac),
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
// HHC03804 "%1d:%04X %s: %s: Cannot unregister guest MAC address %s"
WRMSG(HHC03804, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charmac );
return 1;
}
/*-------------------------------------------------------------------*/
/* Unregister all local MAC address */
/*-------------------------------------------------------------------*/
/* The returned value is:- */
/* 0 All MAC addresses were removed from the table */
static int unregister_all_mac(OSA_GRP *grp)
{
int i;
for(i = 0; i < OSA_MAXMAC; i++)
{
grp->mac[i].type = MAC_TYPE_NONE;
memset(grp->mac[i].addr, 0, IFHWADDRLEN);
}
return MAC_TYPE_NONE;
}
/*-------------------------------------------------------------------*/
/* Validate MAC address and return MAC type */
/* In promiscuous mode, all frames are accepted */
/* a Broadcast frame is always valid (unless we do not seek broadcast*/
/* frames */
/*-------------------------------------------------------------------*/
static int validate_mac(BYTE *mac, int type, OSA_GRP *grp)
{
int i; /* Utility variable */
/* Always accept broadcast frames */
/* Search for all FFs */
for(i=0;i<IFHWADDRLEN;i++)
{
if(mac[i]!=0xff) break;
}
/* If we reached end of MAC address, all FF then it is a broadcast */
/* Return it is a broadcast unless broadcast isn't sought for */
/* unless the interface is in promiscuous mode */
if(i==(IFHWADDRLEN)) return (MAC_TYPE_BRDCST & type) | grp->promisc;
/* Find a matching MAC (Unicast or Multicast) */
for(i = 0; i < OSA_MAXMAC; i++)
{
/* Find a type matching the search mask with a matching MAC addr */
if((grp->mac[i].type & type) && !memcmp(grp->mac[i].addr,mac,IFHWADDRLEN))
return grp->mac[i].type | grp->promisc;
}
/* Not match found - but accept it if the interface is in promiscuous mode */
/* Otherwise, ignore the frame */
return grp->promisc;
}
/*-------------------------------------------------------------------*/
/* Register local IPv4 address */
/*-------------------------------------------------------------------*/
/* The returned values are:- */
/* -1 The table is full */
/* 0 The IPv4 address was added to the table */
/* 1 The IPv4 address was already in the table */
static int register_ipv4(OSA_GRP* grp, DEVBLK* dev, BYTE *ipaddr4)
{
int i;
char charip4[48];
/* Check whether the IPv4 address is already registered. */
for (i = 0; i < OSA_MAXIPV4; i++)
{
if (grp->ipaddr4[i].type == IPV4_TYPE_INUSE &&
memcmp(grp->ipaddr4[i].addr, ipaddr4, 4) == 0)
{
return 1;
}
}
/* Register the previously unknown IPv4 address. */
for (i = 0; i < OSA_MAXIPV4; i++)
{
if (grp->ipaddr4[i].type == IPV4_TYPE_NONE)
{
memcpy(grp->ipaddr4[i].addr, ipaddr4, 4);
grp->ipaddr4[i].type = IPV4_TYPE_INUSE;
hinet_ntop( AF_INET, ipaddr4, charip4, sizeof(charip4) );
// HHC03805 "%1d:%04X %s: %s: Register guest IP address %s"
WRMSG(HHC03805, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip4 );
return 0;
}
}
/* Oh dear, the table of IPv4 addresses is full. */
hinet_ntop( AF_INET, ipaddr4, charip4, sizeof(charip4) );
// HHC03806 "%1d:%04X %s: %s: Cannot register guest IP address %s"
WRMSG(HHC03806, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip4 );
return -1;
}
/*-------------------------------------------------------------------*/
/* Unregister local IPv4 address */
/*-------------------------------------------------------------------*/
/* The returned values are:- */
/* 0 The IPv4 address was removed from the table */
/* 1 The IPv4 address was not in the table */
static int unregister_ipv4(OSA_GRP* grp, DEVBLK* dev, BYTE *ipaddr4)
{
int i;
char charip4[48];
/* Check whether the IPv4 address is registered. */
for (i = 0; i < OSA_MAXIPV4; i++)
{
if (grp->ipaddr4[i].type == IPV4_TYPE_INUSE &&
memcmp(grp->ipaddr4[i].addr, ipaddr4, 4) == 0)
{
grp->ipaddr4[i].type = IPV4_TYPE_NONE;
memset(grp->ipaddr4[i].addr, 0, 4);
hinet_ntop( AF_INET, ipaddr4, charip4, sizeof(charip4) );
// HHC03807 "%1d:%04X %s: s: Unregister guest IP address %s"
WRMSG(HHC03807, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip4 );
return 0;
}
}
/* Oh dear, the IPv4 address wasn't registered. */
hinet_ntop( AF_INET, ipaddr4, charip4, sizeof(charip4) );
// HHC03808 "%1d:%04X %s: %s: Cannot unregister guest IP address %s"
WRMSG(HHC03808, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip4 );
return 1;
}
/*-------------------------------------------------------------------*/
/* Unregister all local IPv4 addresses */
/*-------------------------------------------------------------------*/
/* The returned value is:- */
/* 0 All IPv4 addresses were removed from the table */
static int unregister_all_ipv4(OSA_GRP* grp)
{
int i;
for (i = 0; i < OSA_MAXIPV4; i++)
{
grp->ipaddr4[i].type = IPV4_TYPE_NONE;
memset(grp->ipaddr4[i].addr, 0, 4);
}
return 0;
}
/*-------------------------------------------------------------------*/
/* Register local IPv6 address */
/*-------------------------------------------------------------------*/
/* The returned values are:- */
/* -1 The table is full */
/* 0 The IPv6 address was added to the table */
/* 1 The IPv6 address was already in the table */
static int register_ipv6(OSA_GRP* grp, DEVBLK* dev, BYTE *ipaddr6)
{
int i;
char charip6[48];
/* Check whether the IPv6 address is already registered. */
for (i = 0; i < OSA_MAXIPV6; i++)
{
if (grp->ipaddr6[i].type == IPV6_TYPE_INUSE &&
memcmp(grp->ipaddr6[i].addr, ipaddr6, 16) == 0)
{
return 1;
}
}
/* Register the previously unknown IPv6 address. */
for (i = 0; i < OSA_MAXIPV6; i++)
{
if (grp->ipaddr6[i].type == IPV6_TYPE_NONE)
{
memcpy(grp->ipaddr6[i].addr, ipaddr6, 16);
grp->ipaddr6[i].type = IPV6_TYPE_INUSE;
hinet_ntop( AF_INET6, ipaddr6, charip6, sizeof(charip6) );
// HHC03805 "%1d:%04X %s: %s: Register guest IP address %s"
WRMSG(HHC03805, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip6 );
return 0;
}
}
/* Oh dear, the IPv6 address table is full. */
hinet_ntop( AF_INET6, ipaddr6, charip6, sizeof(charip6) );
// HHC03806 "%1d:%04X %s: %s: Cannot register guest IP address %s"
WRMSG(HHC03806, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip6 );
return -1;
}
/*-------------------------------------------------------------------*/
/* Unregister local IPv6 address */
/*-------------------------------------------------------------------*/
/* The returned values are:- */
/* 0 The IPv6 address was removed from the table */
/* 1 The IPv6 address was not in the table */
static int unregister_ipv6(OSA_GRP* grp, DEVBLK* dev, BYTE *ipaddr6)
{
int i;
char charip6[48];
/* Check whether the IPv6 address is registered. */
for (i = 0; i < OSA_MAXIPV6; i++)
{
if (grp->ipaddr6[i].type == IPV6_TYPE_INUSE &&
memcmp(grp->ipaddr6[i].addr, ipaddr6, 16) == 0)
{
grp->ipaddr6[i].type = IPV6_TYPE_NONE;
memset(grp->ipaddr6[i].addr, 0, 16);
hinet_ntop( AF_INET6, ipaddr6, charip6, sizeof(charip6) );
// HHC03807 "%1d:%04X %s: %s: Unregistered guest IP address %s"
WRMSG(HHC03807, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip6 );
return 0;
}
}
/* Oh dear, the IPv6 address wasn't registered. */
hinet_ntop( AF_INET6, ipaddr6, charip6, sizeof(charip6) );
// HHC03808 "%1d:%04X %s: %s: Cannot unregister guest IP address %s"
WRMSG(HHC03808, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->typname, grp->ttifname,
charip6 );
return 1;
}
/*-------------------------------------------------------------------*/
/* Unregister all local IPv6 addresses */
/*-------------------------------------------------------------------*/
/* The returned value is:- */
/* 0 All IPv6 addresses were removed from the table */
static int unregister_all_ipv6(OSA_GRP* grp)
{
int i;
for (i = 0; i < OSA_MAXIPV6; i++)
{
grp->ipaddr6[i].type = IPV6_TYPE_NONE;
memset(grp->ipaddr6[i].addr, 0, 16);
}
return 0;
}
/*-------------------------------------------------------------------*/
/* QETH pipe read/write/select... */
/*-------------------------------------------------------------------*/
#define QETH_TEMP_PIPE_ERROR( errnum ) ( errnum == HSO_EINTR || \
errnum == HSO_EAGAIN || \
errnum == HSO_EALREADY || \
errnum == HSO_EWOULDBLOCK )
static int qeth_select (int nfds, fd_set* rdset, struct timeval* tv)
{
int rc, errnum;
PTT_QETH_TRACE( "b4 select", 0,0,0 );
for (;;)
{
/* Do the select */
rc = select( nfds, rdset, NULL, NULL, tv );
/* Get error code */
errnum = HSO_errno;
/* Return if successful */
if (rc >= 0)
break;
/* Return if non-temporary error */
if (!QETH_TEMP_PIPE_ERROR( errnum ))
break;
/* Otherwise pause before retrying */
sched_yield();
}
if (rc <= 0)
errno = errnum;
PTT_QETH_TRACE( "af select", 0,0,0 );
return rc;
}
static int qeth_read_pipe (int fd, BYTE *sig)
{
int rc, errnum;
PTT_QETH_TRACE( "b4 rdpipe", 0,0,*sig );
for (;;) {
rc = read_pipe( fd, sig, 1 );
if (rc > 0)
break;
errnum = HSO_errno;
if (!QETH_TEMP_PIPE_ERROR( errnum ))
break;
sched_yield();
}
if (rc <= 0)
errno = errnum;
PTT_QETH_TRACE( "af rdpipe", 0,0,*sig );
return rc;
}
static int qeth_write_pipe (int fd, BYTE *sig)
{
int rc, errnum;
PTT_QETH_TRACE( "b4 wrpipe", 0,0,*sig );
for (;;) {
rc = write_pipe( fd, sig, 1 );
if (rc > 0)
break;
errnum = HSO_errno;
if (!QETH_TEMP_PIPE_ERROR( errnum ))
break;
sched_yield();
}
if (rc <= 0)
errno = errnum;
PTT_QETH_TRACE( "af wrpipe", 0,0,*sig );
return rc;
}
/*-------------------------------------------------------------------*/
/* Issue generic error message with return code and strerror msg. */
/* Returns the same errnum value that was passed. */
/*-------------------------------------------------------------------*/
static int qeth_errnum_msg(DEVBLK *dev, OSA_GRP *grp,
int errnum, char* msgcode, char* errmsg )
{
char strerr[256] = {0};
char msgbuf[256] = {0};
if (errnum >= 0)
strlcpy( strerr, strerror( errnum ), sizeof( strerr ));
else
strlcpy( strerr, "An unidentified error has occurred", sizeof( strerr ));
/* "function() failed, rc=99 (0x00000063): an error occurred" */
MSGBUF( msgbuf, "%s, rc=%d (0x%08X): %s",
errmsg, errnum, errnum, strerr);
// HHC03996 "%1d:%04X %s: %s: %s"
if (str_caseless_eq("E",msgcode))
WRMSG( HHC03996, "E", SSID_TO_LCSS(dev->ssid), dev->devnum,
"QETH", grp->ttifname, msgbuf);
else if (str_caseless_eq("W",msgcode))
WRMSG( HHC03996, "W", SSID_TO_LCSS(dev->ssid), dev->devnum,
"QETH", grp->ttifname, msgbuf);
else /* "I" information presumed */
WRMSG( HHC03996, "I", SSID_TO_LCSS(dev->ssid), dev->devnum,
"QETH", grp->ttifname, msgbuf);
return errnum;
}
/*-------------------------------------------------------------------*/
/* Report what values we are using */
/*-------------------------------------------------------------------*/
static void qeth_report_using( DEVBLK *dev, OSA_GRP *grp )
{
char not[8];
strlcpy( not, grp->enabled ? "" : "not ", sizeof( not ));
// HHC03997 "%1d:%04X %s: Interface %s %susing %s %s"
WRMSG( HHC03997, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, "QETH",
grp->ttifname, not, "MAC address", grp->tthwaddr );
if (grp->l3 && grp->ttipaddr)
{
WRMSG( HHC03997, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, "QETH",
grp->ttifname, not, "IP address", grp->ttipaddr );
if(grp->ttnetmask)
{
WRMSG( HHC03997, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, "QETH",
grp->ttifname, not, "subnet mask", grp->ttnetmask );
}
}
if (grp->l3 && grp->ttipaddr6)
{
WRMSG( HHC03997, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, "QETH",
grp->ttifname, not, "IP address", grp->ttipaddr6 );
if(grp->ttpfxlen6)
{
WRMSG( HHC03997, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, "QETH",
grp->ttifname, not, "prefix length", grp->ttpfxlen6 );
}
}
if (grp->ttmtu)