forked from SDL-Hercules-390/hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.c
3592 lines (3074 loc) · 126 KB
/
channel.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
/* CHANNEL.C (c) Copyright Roger Bowler, 1999-2006 */
/* ESA/390 Channel Emulator */
/*-------------------------------------------------------------------*/
/* This module contains the channel subsystem functions for the */
/* Hercules S/370 and ESA/390 emulator. */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Additional credits: */
/* Measurement block support by Jan Jaeger */
/* Fix program check on NOP due to addressing - Jan Jaeger */
/* Fix program check on TIC as first ccw on RSCH - Jan Jaeger */
/* Fix PCI intermediate status flags - Jan Jaeger */
/* z/Architecture support - (c) Copyright Jan Jaeger, 1999-2006 */
/* 64-bit IDAW support - Roger Bowler v209 @IWZ*/
/* Incorrect-length-indication-suppression - Jan Jaeger */
/* Read backward support contributed by Hackules 13jun2002 */
/* Read backward fixes contributed by Jay Jaeger 16sep2003 */
/* MIDAW support - Roger Bowler 03aug2005 @MW*/
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
#include "hercules.h"
#include "devtype.h"
#include "opcode.h"
#if defined(OPTION_FISHIO)
#include "w32chan.h"
#endif // defined(OPTION_FISHIO)
void call_execute_ccw_chain(int arch_mode, void* pDevBlk);
#ifdef OPTION_IODELAY_KLUDGE
#define IODELAY(_dev) \
do { \
if (sysblk.iodelay > 0 && (_dev)->devchar[10] == 0x20) \
usleep(sysblk.iodelay); \
} while (0)
#else
#define IODELAY(_dev)
#endif
#undef CHADDRCHK
#if defined(FEATURE_ADDRESS_LIMIT_CHECKING)
#define CHADDRCHK(_addr,_dev) \
( ((_addr) > (_dev)->mainlim) \
|| ((dev->orb.flag5 & ORB5_A) \
&& ((((_dev)->pmcw.flag5 & PMCW5_LM_LOW) \
&& ((_addr) < sysblk.addrlimval)) \
|| (((_dev)->pmcw.flag5 & PMCW5_LM_HIGH) \
&& ((_addr) >= sysblk.addrlimval)) ) ))
#else /*!defined(FEATURE_ADDRESS_LIMIT_CHECKING)*/
#define CHADDRCHK(_addr,_dev) \
((_addr) > (_dev)->mainlim)
#endif /*!defined(FEATURE_ADDRESS_LIMIT_CHECKING)*/
#if !defined(_CHANNEL_C)
#define _CHANNEL_C
/*-------------------------------------------------------------------*/
/* FORMAT I/O BUFFER DATA */
/*-------------------------------------------------------------------*/
static void format_iobuf_data (RADR addr, BYTE *area, DEVBLK *dev) /*@IWZ*/
{
BYTE *a; /* -> Byte in main storage */
int i, j; /* Array subscripts */
BYTE c; /* Character work area */
area[0] = '\0';
if (addr <= dev->mainlim - 16)
{
a = dev->mainstor + addr;
j = sprintf ((char *)area,
"=>%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X"
" %2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X ",
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]);
for (i = 0; i < 16; i++)
{
c = guest_to_host(*a++);
if (!isprint(c)) c = '.';
area[j++] = c;
}
area[j] = '\0';
}
} /* end function format_iobuf_data */
/*-------------------------------------------------------------------*/
/* DISPLAY CHANNEL COMMAND WORD AND DATA */
/*-------------------------------------------------------------------*/
static void display_ccw (DEVBLK *dev, BYTE ccw[], U32 addr)
{
BYTE area[64]; /* Data display area */
format_iobuf_data (addr, area, dev);
logmsg (_("HHCCP048I %4.4X:CCW=%2.2X%2.2X%2.2X%2.2X "
"%2.2X%2.2X%2.2X%2.2X%s\n"),
dev->devnum,
ccw[0], ccw[1], ccw[2], ccw[3],
ccw[4], ccw[5], ccw[6], ccw[7], area);
} /* end function display_ccw */
/*-------------------------------------------------------------------*/
/* DISPLAY CHANNEL STATUS WORD */
/*-------------------------------------------------------------------*/
static void display_csw (DEVBLK *dev, BYTE csw[])
{
logmsg (_("HHCCP049I %4.4X:Stat=%2.2X%2.2X Count=%2.2X%2.2X "
"CCW=%2.2X%2.2X%2.2X\n"),
dev->devnum,
csw[4], csw[5], csw[6], csw[7],
csw[1], csw[2], csw[3]);
} /* end function display_csw */
/*-------------------------------------------------------------------*/
/* DISPLAY SUBCHANNEL STATUS WORD */
/*-------------------------------------------------------------------*/
static void display_scsw (DEVBLK *dev, SCSW scsw)
{
logmsg (_("HHCCP050I %4.4X:SCSW=%2.2X%2.2X%2.2X%2.2X "
"Stat=%2.2X%2.2X Count=%2.2X%2.2X "
"CCW=%2.2X%2.2X%2.2X%2.2X\n"),
dev->devnum,
scsw.flag0, scsw.flag1, scsw.flag2, scsw.flag3,
scsw.unitstat, scsw.chanstat,
scsw.count[0], scsw.count[1],
scsw.ccwaddr[0], scsw.ccwaddr[1],
scsw.ccwaddr[2], scsw.ccwaddr[3]);
} /* end function display_scsw */
/*-------------------------------------------------------------------*/
/* STORE CHANNEL ID */
/*-------------------------------------------------------------------*/
int stchan_id (REGS *regs, U16 chan)
{
U32 chanid; /* Channel identifier word */
int devcount = 0; /* #of devices on channel */
DEVBLK *dev; /* -> Device control block */
PSA_3XX *psa; /* -> Prefixed storage area */
/* Find a device on specified channel */
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
{
/* Skip the device if not on specified channel */
if ((dev->devnum & 0xFF00) != chan
|| (dev->pmcw.flag5 & PMCW5_V) == 0
#if defined(FEATURE_CHANNEL_SWITCHING)
|| regs->chanset != dev->chanset
#endif /*defined(FEATURE_CHANNEL_SWITCHING)*/
)
continue;
/* Found device on the channel */
devcount++;
break;
} /* end for(dev) */
/* Exit with condition code 3 if no devices on channel */
if (devcount == 0)
return 3;
/* Construct the channel id word */
chanid = CHANNEL_BMX;
/* Store the channel id word at PSA+X'A8' */
psa = (PSA_3XX*)(regs->mainstor + regs->PX);
STORE_FW(psa->chanid, chanid);
/* Exit with condition code 0 indicating channel id stored */
return 0;
} /* end function stchan_id */
/*-------------------------------------------------------------------*/
/* TEST CHANNEL */
/*-------------------------------------------------------------------*/
int testch (REGS *regs, U16 chan)
{
DEVBLK *dev; /* -> Device control block */
int devcount = 0; /* Number of devices found */
int cc = 0; /* Returned condition code */
/* Scan devices on the channel */
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
{
/* Skip the device if not on specified channel */
if ((dev->devnum & 0xFF00) != chan
|| (dev->pmcw.flag5 & PMCW5_V) == 0
#if defined(FEATURE_CHANNEL_SWITCHING)
|| regs->chanset != dev->chanset
#endif /*defined(FEATURE_CHANNEL_SWITCHING)*/
)
continue;
/* Increment device count on this channel */
devcount++;
/* Test for pending interrupt */
if (IOPENDING(dev))
{
cc = 1;
break;
}
}
/* Set condition code 3 if no devices found on the channel */
if (devcount == 0)
cc = 3;
return cc;
} /* end function testch */
/*-------------------------------------------------------------------*/
/* TEST I/O */
/*-------------------------------------------------------------------*/
int testio (REGS *regs, DEVBLK *dev, BYTE ibyte)
{
int cc; /* Condition code */
PSA_3XX *psa; /* -> Prefixed storage area */
/* ISW20030812 - Added 1 line */
IOINT *ioint=NULL;
/* ISW20030812 - END */
UNREFERENCED(ibyte);
if (dev->ccwtrace || dev->ccwstep)
logmsg (_("HHCCP051I %4.4X: Test I/O\n"), dev->devnum);
obtain_lock (&dev->lock);
/* Test device status and set condition code */
if ((dev->busy && dev->ioactive == DEV_SYS_LOCAL)
|| dev->startpending)
{
/* Set condition code 2 if device is busy */
cc = 2;
}
else
{
if (IOPENDING(dev))
{
/* Set condition code 1 if interrupt pending */
cc = 1;
/* Store the channel status word at PSA+X'40' */
psa = (PSA_3XX*)(regs->mainstor + regs->PX);
if (dev->pcipending)
{
memcpy (psa->csw, dev->pcicsw, 8);
dev->pcipending = 0;
/* ISW20030812 - Added 1 line */
ioint=&dev->pciioint;
/* ISW20030812 - END */
}
else
{
if(dev->pending)
{
memcpy (psa->csw, dev->csw, 8);
dev->pending = 0;
ioint=&dev->ioint;
}
else
{
memcpy (psa->csw, dev->attncsw, 8);
dev->attnpending = 0;
ioint=&dev->attnioint;
}
}
/* Signal console thread to redrive select */
if (dev->console)
{
SIGNAL_CONSOLE_THREAD();
}
if (dev->ccwtrace || dev->ccwstep)
display_csw (dev, psa->csw);
}
else
{
/* Set condition code 1 if device is LCS CTC */
if ( dev->ctctype == CTC_LCS )
{
cc = 1;
dev->csw[4] = 0;
dev->csw[5] = 0;
psa = (PSA_3XX*)(regs->mainstor + regs->PX);
memcpy (psa->csw, dev->csw, 8);
if (dev->ccwtrace)
{
logmsg(_("HHCCP052I TIO modification executed CC=1\n"));
display_csw (dev, dev->csw);
}
}
else
/* Set condition code 0 if device is available */
cc = 0;
}
}
release_lock (&dev->lock);
/* ISW20030812 - Added 6 lines */
if(ioint)
{
obtain_lock (&sysblk.intlock);
DEQUEUE_IO_INTERRUPT(ioint);
release_lock (&sysblk.intlock);
}
/* ISW20030812 - END */
/* Return the condition code */
return cc;
} /* end function testio */
/*-------------------------------------------------------------------*/
/* HALT I/O */
/*-------------------------------------------------------------------*/
int haltio (REGS *regs, DEVBLK *dev, BYTE ibyte)
{
int cc; /* Condition code */
PSA_3XX *psa; /* -> Prefixed storage area */
int pending = 0; /* New interrupt pending */
UNREFERENCED(ibyte);
if (dev->ccwtrace || dev->ccwstep)
logmsg (_("HHCCP053I %4.4X: Halt I/O\n"), dev->devnum);
obtain_lock (&dev->lock);
/* Test device status and set condition code */
if (dev->busy)
{
/* Invoke the provided halt_device routine @ISW */
/* if it has been provided by the handler @ISW */
/* code at init @ISW */
if(dev->halt_device!=NULL) /* @ISW */
{ /* @ISW */
dev->halt_device(dev); /* @ISW */
cc=0; /* @ISW */
} /* @ISW */
else
{
/* Set condition code 2 if device is busy */
cc = 2;
/* Tell channel and device to halt */
dev->scsw.flag2 |= SCSW2_FC_HALT;
/* Clear pending interrupts */
dev->pending = dev->pcipending = dev->attnpending = 0;
}
}
else if (!IOPENDING(dev) && dev->ctctype != CTC_LCS)
{
/* Set condition code 1 */
cc = 1;
/* Store the channel status word at PSA+X'40' */
psa = (PSA_3XX*)(regs->mainstor + regs->PX);
memcpy (psa->csw, dev->csw, 8);
/* Set pending interrupt */
dev->pending = pending = 1;
if (dev->ccwtrace || dev->ccwstep)
display_csw (dev, dev->csw);
}
else
{
/* Set cc 1 if interrupt is not pending and LCS CTC */
if ( dev->ctctype == CTC_LCS )
{
cc = 1;
dev->csw[4] = 0;
dev->csw[5] = 0;
psa = (PSA_3XX*)(regs->mainstor + regs->PX);
memcpy (psa->csw, dev->csw, 8);
if (dev->ccwtrace)
{
logmsg(_("HHCCP054I HIO modification executed CC=1\n"));
display_csw (dev, dev->csw);
}
}
else
/* Set condition code 0 if interrupt is pending */
cc = 0;
}
/* For 3270 device, clear any pending input */
if (dev->devtype == 0x3270)
{
dev->readpending = 0;
dev->rlen3270 = 0;
}
/* Signal console thread to redrive select */
if (dev->console)
{
SIGNAL_CONSOLE_THREAD();
}
release_lock (&dev->lock);
if (pending)
{
obtain_lock (&sysblk.intlock);
QUEUE_IO_INTERRUPT (&dev->ioint);
release_lock (&sysblk.intlock);
}
/* Return the condition code */
return cc;
} /* end function haltio */
/*-------------------------------------------------------------------*/
/* CANCEL SUBCHANNEL */
/*-------------------------------------------------------------------*/
/* Input */
/* regs -> CPU register context */
/* dev -> Device control block */
/* Return value */
/* The return value is the condition code for the XSCH */
/* 0=start function cancelled (not yet implemented) */
/* 1=status pending (no action taken) */
/* 2=function not applicable */
/*-------------------------------------------------------------------*/
int cancel_subchan (REGS *regs, DEVBLK *dev)
{
int cc; /* Condition code */
UNREFERENCED(regs);
obtain_lock (&dev->lock);
#if defined(_FEATURE_IO_ASSIST)
if(SIE_MODE(regs)
&& (regs->siebk->zone != dev->pmcw.zone
|| !(dev->pmcw.flag27 & PMCW27_I)))
{
release_lock (&dev->lock);
longjmp(regs->progjmp,SIE_INTERCEPT_INST);
}
#endif
/* Check pending status */
if ((dev->pciscsw.flag3 & SCSW3_SC_PEND)
|| (dev->scsw.flag3 & SCSW3_SC_PEND)
|| (dev->attnscsw.flag3 & SCSW3_SC_PEND))
cc = 1;
else
{
cc = 2;
#if !defined(OPTION_FISHIO)
obtain_lock(&sysblk.ioqlock);
if(sysblk.ioq != NULL)
{
DEVBLK *tmp;
/* special case for head of queue */
if(sysblk.ioq == dev)
{
/* Remove device from the i/o queue */
sysblk.ioq = dev->nextioq;
cc = 0;
}
else
{
/* Search for device on i/o queue */
for(tmp = sysblk.ioq; tmp->nextioq != NULL && tmp->nextioq != dev; tmp = tmp->nextioq);
/* Remove from queue if found */
if(tmp->nextioq == dev)
{
tmp->nextioq = tmp->nextioq->nextioq;
cc = 0;
}
}
/* Reset the device */
if(!cc)
{
/* Terminate suspended channel program */
if (dev->scsw.flag3 & SCSW3_AC_SUSP)
{
dev->suspended = 0;
signal_condition (&dev->resumecond);
}
/* Reset the scsw */
dev->scsw.flag2 &= ~(SCSW2_AC_RESUM | SCSW2_FC_START | SCSW2_AC_START);
dev->scsw.flag3 &= ~(SCSW3_AC_SUSP);
}
}
release_lock(&sysblk.ioqlock);
#endif /*!defined(OPTION_FISHIO)*/
}
release_lock (&dev->lock);
/* Return the condition code */
return cc;
} /* end function cancel_subchan */
/*-------------------------------------------------------------------*/
/* TEST SUBCHANNEL */
/*-------------------------------------------------------------------*/
/* Input */
/* regs -> CPU register context */
/* dev -> Device control block */
/* Output */
/* irb -> Interruption response block */
/* Return value */
/* The return value is the condition code for the TSCH */
/* instruction: 0=status was pending and is now cleared, */
/* 1=no status was pending. The IRB is updated in both cases. */
/*-------------------------------------------------------------------*/
int test_subchan (REGS *regs, DEVBLK *dev, IRB *irb)
{
int cc; /* Condition code */
#if defined(_FEATURE_IO_ASSIST)
UNREFERENCED(regs);
#endif
obtain_lock (&dev->lock);
#if defined(_FEATURE_IO_ASSIST)
if(SIE_MODE(regs)
&& (regs->siebk->zone != dev->pmcw.zone
|| !(dev->pmcw.flag27 & PMCW27_I)))
{
release_lock (&dev->lock);
longjmp(regs->progjmp,SIE_INTERCEPT_INST);
}
#endif
/* Return PCI SCSW if PCI status is pending */
if (dev->pciscsw.flag3 & SCSW3_SC_PEND)
{
#if defined(_FEATURE_IO_ASSIST)
/* For I/O assisted devices we must intercept if type B
status is present on the subchannel */
if(SIE_MODE(regs)
&& ( (regs->siebk->tschds & dev->pciscsw.unitstat)
|| (regs->siebk->tschsc & dev->pciscsw.chanstat) ) )
{
dev->pmcw.flag27 &= ~PMCW27_I;
release_lock (&dev->lock);
longjmp(regs->progjmp,SIE_INTERCEPT_IOINST);
}
#endif
/* Display the subchannel status word */
if (dev->ccwtrace || dev->ccwstep)
display_scsw (dev, dev->pciscsw);
/* Copy the PCI SCSW to the IRB */
irb->scsw = dev->pciscsw;
/* Clear the ESW and ECW in the IRB */
memset (&irb->esw, 0, sizeof(ESW));
irb->esw.lpum = 0x80;
memset (irb->ecw, 0, sizeof(irb->ecw));
/* Clear the pending PCI status */
dev->pciscsw.flag2 &= ~(SCSW2_FC | SCSW2_AC);
dev->pciscsw.flag3 &= ~(SCSW3_SC);
dev->pcipending = 0;
/* Return condition code 0 to indicate status was pending */
release_lock (&dev->lock);
/* ISW20030812 - Added 3 lines */
obtain_lock(&sysblk.intlock);
DEQUEUE_IO_INTERRUPT(&dev->pciioint);
release_lock(&sysblk.intlock);
/* ISW20030812 - END */
return 0;
} /* end if(pcipending) */
/* Copy the subchannel status word to the IRB */
irb->scsw = dev->scsw;
/* Copy the extended status word to the IRB */
irb->esw = dev->esw;
/* Copy the extended control word to the IRB */
memcpy (irb->ecw, dev->ecw, sizeof(irb->ecw));
/* Test device status and set condition code */
if (dev->scsw.flag3 & SCSW3_SC_PEND)
{
#if defined(_FEATURE_IO_ASSIST)
/* For I/O assisted devices we must intercept if type B
status is present on the subchannel */
if(SIE_MODE(regs)
&& ( (regs->siebk->tschds & dev->scsw.unitstat)
|| (regs->siebk->tschsc & dev->scsw.chanstat) ) )
{
dev->pmcw.flag27 &= ~PMCW27_I;
release_lock (&dev->lock);
longjmp(regs->progjmp,SIE_INTERCEPT_IOINST);
}
#endif
/* Set condition code 0 for status pending */
cc = 0;
/* Display the subchannel status word */
if (dev->ccwtrace || dev->ccwstep)
display_scsw (dev, dev->scsw);
/* [14.3.13] If status is anything other than intermediate with
pending then clear the function control, activity control,
status control, and path not-operational bits in the SCSW */
if ((dev->scsw.flag3 & SCSW3_SC)
!= (SCSW3_SC_INTER | SCSW3_SC_PEND))
{
dev->scsw.flag2 &= ~(SCSW2_FC | SCSW2_AC);
dev->scsw.flag3 &= ~(SCSW3_AC_SUSP);
dev->scsw.flag1 &= ~(SCSW1_N);
}
else
{
/* [14.3.13] Clear the function control bits if function
code is halt and the channel program is suspended */
if ((dev->scsw.flag2 & SCSW2_FC_HALT)
&& (dev->scsw.flag3 & SCSW3_AC_SUSP))
dev->scsw.flag2 &= ~(SCSW2_FC);
/* [14.3.13] Clear the activity control bits if function
code is start+halt and channel program is suspended */
if ((dev->scsw.flag2 & (SCSW2_FC_START | SCSW2_FC_HALT))
== (SCSW2_FC_START | SCSW2_FC_HALT)
&& (dev->scsw.flag3 & SCSW3_AC_SUSP))
{
dev->scsw.flag2 &= ~(SCSW2_AC);
dev->scsw.flag3 &= ~(SCSW3_AC_SUSP);
dev->scsw.flag1 &= ~(SCSW1_N);
}
/* [14.3.13] Clear the resume pending bit if function code
is start without halt and channel program suspended */
if ((dev->scsw.flag2 & (SCSW2_FC_START | SCSW2_FC_HALT))
== SCSW2_FC_START
&& (dev->scsw.flag3 & SCSW3_AC_SUSP))
{
dev->scsw.flag2 &= ~(SCSW2_AC_RESUM);
dev->scsw.flag1 &= ~(SCSW1_N);
}
} /* end if(INTER+PEND) */
/* Clear the status bits in the SCSW */
dev->scsw.flag3 &= ~(SCSW3_SC);
}
else
{
/* Test device status and set condition code */
if (dev->attnscsw.flag3 & SCSW3_SC_PEND)
{
#if defined(_FEATURE_IO_ASSIST)
/* For I/O assisted devices we must intercept if type B
status is present on the subchannel */
if(SIE_MODE(regs)
&& ( (regs->siebk->tschds & dev->attnscsw.unitstat)
|| (regs->siebk->tschsc & dev->attnscsw.chanstat) ) )
{
dev->pmcw.flag27 &= ~PMCW27_I;
release_lock (&dev->lock);
longjmp(regs->progjmp,SIE_INTERCEPT_IOINST);
}
#endif
/* Set condition code 0 for status pending */
cc = 0;
/* Display the subchannel status word */
if (dev->ccwtrace || dev->ccwstep)
display_scsw (dev, dev->attnscsw);
/* Copy the ATTN SCSW to the IRB */
irb->scsw = dev->attnscsw;
/* Clear the ESW and ECW in the IRB */
memset (&irb->esw, 0, sizeof(ESW));
irb->esw.lpum = 0x80;
memset (irb->ecw, 0, sizeof(irb->ecw));
/* Clear the pending ATTN status */
dev->attnscsw.flag2 &= ~(SCSW2_FC | SCSW2_AC);
dev->attnscsw.flag3 &= ~(SCSW3_SC);
dev->attnpending = 0;
/* Signal console thread to redrive select */
/* Return condition code 0 to indicate status was pending */
release_lock (&dev->lock);
/* ISW20030812 - Added 3 lines */
obtain_lock(&sysblk.intlock);
DEQUEUE_IO_INTERRUPT(&dev->attnioint);
release_lock(&sysblk.intlock);
/* ISW20030812 - END */
if (dev->console)
{
SIGNAL_CONSOLE_THREAD();
}
return 0;
}
/* Set condition code 1 if status not pending */
else
{
cc = 1;
}
}
/* Clear any pending interrupt */
dev->pending = 0;
release_lock (&dev->lock);
/* ISW20030812 - Added 3 lines */
obtain_lock(&sysblk.intlock);
DEQUEUE_IO_INTERRUPT(&dev->ioint);
release_lock(&sysblk.intlock);
/* ISW20030812 - END */
/* Signal console thread to redrive select */
if (dev->console)
{
SIGNAL_CONSOLE_THREAD();
}
/* Return the condition code */
return cc;
} /* end function test_subchan */
/*-------------------------------------------------------------------*/
/* CLEAR SUBCHANNEL */
/*-------------------------------------------------------------------*/
/* Input */
/* regs -> CPU register context */
/* dev -> Device control block */
/*-------------------------------------------------------------------*/
void clear_subchan (REGS *regs, DEVBLK *dev)
{
int pending = 0;
UNREFERENCED(regs);
if (dev->ccwtrace || dev->ccwstep)
logmsg (_("HHCCP055I %4.4X: Clear subchannel\n"), dev->devnum);
obtain_lock (&dev->lock);
#if defined(_FEATURE_IO_ASSIST)
if(SIE_MODE(regs)
&& (regs->siebk->zone != dev->pmcw.zone
|| !(dev->pmcw.flag27 & PMCW27_I)))
{
release_lock (&dev->lock);
longjmp(regs->progjmp,SIE_INTERCEPT_INST);
}
#endif
/* If the device is busy then signal the device to clear */
if ((dev->busy && dev->ioactive == DEV_SYS_LOCAL)
|| dev->startpending)
{
/* Set clear pending condition */
dev->scsw.flag2 |= SCSW2_FC_CLEAR | SCSW2_AC_CLEAR;
/* Signal the subchannel to resume if it is suspended */
if (dev->scsw.flag3 & SCSW3_AC_SUSP)
{
dev->scsw.flag2 |= SCSW2_AC_RESUM;
signal_condition (&dev->resumecond);
}
#if !defined(NO_SIGABEND_HANDLER)
else
{
if( dev->ctctype )
signal_thread(dev->tid, SIGUSR2);
}
#endif /*!defined(NO_SIGABEND_HANDLER)*/
}
else
{
/* [15.3.2] Perform clear function subchannel modification */
dev->pmcw.pom = 0xFF;
dev->pmcw.lpum = 0x00;
dev->pmcw.pnom = 0x00;
/* [15.3.3] Perform clear function signaling and completion */
dev->scsw.flag0 = 0;
dev->scsw.flag1 = 0;
dev->scsw.flag2 &= ~(SCSW2_FC | SCSW2_AC);
dev->scsw.flag2 |= SCSW2_FC_CLEAR;
dev->scsw.flag3 &= ~(SCSW3_AC | SCSW3_SC);
dev->scsw.flag3 |= SCSW3_SC_PEND;
store_fw (dev->scsw.ccwaddr, 0);
dev->scsw.chanstat = 0;
dev->scsw.unitstat = 0;
store_hw (dev->scsw.count, 0);
dev->pcipending = 0;
dev->pending = 1;
pending = 1;
/* For 3270 device, clear any pending input */
if (dev->devtype == 0x3270)
{
dev->readpending = 0;
dev->rlen3270 = 0;
}
/* Signal console thread to redrive select */
if (dev->console)
{
SIGNAL_CONSOLE_THREAD();
}
}
release_lock (&dev->lock);
/* Queue any pending i/o interrupt */
if (pending)
{
obtain_lock (&sysblk.intlock);
QUEUE_IO_INTERRUPT (&dev->ioint);
release_lock (&sysblk.intlock);
}
} /* end function clear_subchan */
/*-------------------------------------------------------------------*/
/* HALT SUBCHANNEL */
/*-------------------------------------------------------------------*/
/* Input */
/* regs -> CPU register context */
/* dev -> Device control block */
/* Return value */
/* The return value is the condition code for the HSCH */
/* instruction: 0=Halt initiated, 1=Non-intermediate status */
/* pending, 2=Busy */
/*-------------------------------------------------------------------*/
int halt_subchan (REGS *regs, DEVBLK *dev)
{
int pending = 0;
UNREFERENCED(regs);
if (dev->ccwtrace || dev->ccwstep)
logmsg (_("HHCCP056I %4.4X: Halt subchannel\n"), dev->devnum);
obtain_lock (&dev->lock);
#if defined(_FEATURE_IO_ASSIST)
if(SIE_MODE(regs)
&& (regs->siebk->zone != dev->pmcw.zone
|| !(dev->pmcw.flag27 & PMCW27_I)))
{
release_lock (&dev->lock);
longjmp(regs->progjmp,SIE_INTERCEPT_INST);
}
#endif
/* Set condition code 1 if subchannel is status pending alone or
is status pending with alert, primary, or secondary status */
if ((dev->scsw.flag3 & SCSW3_SC) == SCSW3_SC_PEND
|| ((dev->scsw.flag3 & SCSW3_SC_PEND)
&& (dev->scsw.flag3 &
(SCSW3_SC_ALERT | SCSW3_SC_PRI | SCSW3_SC_SEC))))
{
if (dev->ccwtrace || dev->ccwstep)
logmsg (_("HHCCP057I %4.4X: Halt subchannel: cc=1\n"), dev->devnum);
release_lock (&dev->lock);
return 1;
}
/* Set condition code 2 if the halt function or the clear
function is already in progress at the subchannel */
if (dev->scsw.flag2 & (SCSW2_AC_HALT | SCSW2_AC_CLEAR))
{
if (dev->ccwtrace || dev->ccwstep)
logmsg (_("HHCCP058I %4.4X: Halt subchannel: cc=2\n"), dev->devnum);
release_lock (&dev->lock);
return 2;
}
/* If the device is busy then signal subchannel to halt */
if ((dev->busy && dev->ioactive == DEV_SYS_LOCAL)
|| dev->startpending)
{
/* Set halt pending condition and reset pending condition */
dev->scsw.flag2 |= (SCSW2_FC_HALT | SCSW2_AC_HALT);
dev->scsw.flag3 &= ~SCSW3_SC_PEND;
/* Clear any pending interrupt */
dev->pending = dev->pcipending = dev->attnpending = 0;
/* Signal the subchannel to resume if it is suspended */
if (dev->scsw.flag3 & SCSW3_AC_SUSP)
{
dev->scsw.flag2 |= SCSW2_AC_RESUM;
signal_condition (&dev->resumecond);
}
#if !defined(OPTION_FISHIO)
/* Remove the device from the ioq if startpending */
obtain_lock(&sysblk.ioqlock);
if(dev->startpending)
{
if(sysblk.ioq == dev)
sysblk.ioq = dev->nextioq;
else
{
DEVBLK *tmp;
for(tmp = sysblk.ioq; tmp->nextioq != NULL && tmp->nextioq != dev; tmp = tmp->nextioq);
if(tmp->nextioq == dev)
tmp->nextioq = tmp->nextioq->nextioq;
}
}
dev->startpending = 0;
release_lock(&sysblk.ioqlock);
#endif /*!defined(OPTION_FISHIO)*/
/* Invoke the provided halt_device routine @ISW */
/* if it has been provided by the handler @ISW */
/* code at init @ISW */
if(dev->halt_device!=NULL) /* @ISW */
{ /* @ISW */
dev->halt_device(dev); /* @ISW */
} /* @ISW */
#if !defined(NO_SIGABEND_HANDLER)
else
{
if( dev->ctctype && dev->tid)
signal_thread(dev->tid, SIGUSR2);
}
#endif /*!defined(NO_SIGABEND_HANDLER)*/
}
else
{
/* [15.4.2] Perform halt function signaling and completion */
dev->scsw.flag2 |= SCSW2_FC_HALT;
dev->scsw.flag3 |= SCSW3_SC_PEND;
dev->pcipending = 0;
dev->pending = 1;
pending = 1;
/* For 3270 device, clear any pending input */
if (dev->devtype == 0x3270)
{
dev->readpending = 0;
dev->rlen3270 = 0;
}
/* Signal console thread to redrive select */
if (dev->console)
{
SIGNAL_CONSOLE_THREAD();
}
}
release_lock (&dev->lock);
/* Queue any pending i/o interrupt */
if (pending)
{
obtain_lock (&sysblk.intlock);
QUEUE_IO_INTERRUPT (&dev->ioint);
release_lock (&sysblk.intlock);
}
if (dev->ccwtrace || dev->ccwstep)
logmsg (_("HHCCP059I %4.4X: Halt subchannel: cc=0\n"), dev->devnum);
/* Return condition code zero */
return 0;
} /* end function halt_subchan */
/*-------------------------------------------------------------------*/
/* RESUME SUBCHANNEL */
/*-------------------------------------------------------------------*/
/* Input */
/* regs -> CPU register context */
/* dev -> Device control block */