-
Notifications
You must be signed in to change notification settings - Fork 0
/
hydradev.asm
3123 lines (2582 loc) · 60 KB
/
hydradev.asm
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
;+asm
;add module "hash.o"
;do
;*
;;;;copy hydradev devs:networks/hydra.device
;
; hydradev.a -- sanaII device driver for Hydra Systems ethernet card
;
; Timo Rossi, 1992-1994
;
;
; notes:
; - all assembler symbol names in sana2.i are in UPPER case
; - WireError is ULONG
; - The C-include file devices/sana2.h (revision 1.10)
; has an error in the Sana2DeviceStats structure definition
; - SoftMisses-field is missing
; (SoftMisses has been replaced by an unused field in newer includes)
;
; - packet types <= 1500 are ieee802.3 length fields
;
; (Disable/Enable should probably be replaced with routines that only
; disable/enable the PORTS/ExtLevel2 interrupt)
;
;
; 1.9 -- 1992-11-27
; - added buffer overflow check (untested)
; - trying to fix Abort_All
; 1.10 - 1992-11-29
; - added S2_GETSPECIALSTATS
; 1.11 - fixed AbortIO()
; - added S2_ONEVENT and event handling
; - fixed expunge
; 1.14 - added type tracking
; 1.15 - added promiscuous mode
; 1.16 - small changes (event handling)
;
; 1.17 - now 'Packets Received' global stat is incremented also for dropped
; packets.
;
; 1.18 - IEEE802.3 send sets packet length field correctly
; - added collision count special stat (not sure if it works...)
; (also added tally counter interrupt, but the counter values
; are not used for anything yet...)
;
; 1.19 - CIA accesses between NIC accesses to keep the time between
; chip selects long enough.
;
; 1.20 - NIC access delays done with a macro
;
; 1.22 - FIFO treshold lowered from 8+2 to 4+2 words by jm
; 1.23 - Copyright message changed.
;
; 1.24 - fixed RAM test routine (still not perfect... no shadow checking)
;
; 1.25 - fixed dev_Open to work with non-zero units (not tested...)
; - also fixed IOS2_DATALENGTH setting with received raw packets
;
; 1.26 - Now interrupt server is added in S2_CONFIGINTERFACE.
; (previously there was a possibility that interrupt server
; could be left in free memory...)
;
; 1.27 - Modified card memory check routine. Now should be more reliable.
;
; 1.28 - testing... more NIC_Delays and memory copy as words
;
; 1.29 - fixed queued transmit. changed copy routines to copy longwords again.
; 1.30ß-- 940216 (JM)
; - now always sets RAM size to 16K (didn't help)
;
; 1.31 -- 940217 (JM)
; - RAM size check finally, definately fixed by JM (was using a 16-bit
; signed index which caused the test to fail with a 64Kb buffer)
; - Board RAM now properly accessed in interrupt routine (bug located
; by TR)
;
; 1.32 -- 940217 (JM)
; - Two bugs fixed (was using 16-bit signed arithmetic, changed to 32-bit)
;
; 1.33 -- 940217 (JM)
; - Yet another bug fix (was using a signed branch in a bad place :-)
;
; 1.34 -- skipped (JM version which saves register when calling the
; callback routines)
;
; 1.35 -- trying to add PacketFilter support...
; 1.36 -- trying to add multiple read queues
; 1.37 -- fixed device name (???)
;
; 1.38 -- added Disable()/Enable() in CookieList handling
; in Open() and Close() routines.
; Fixed a bug in find_rec_ioreq_loop, it jumped to orphan_packet,
; where it should jump to find_rec_ioreq_cookie_next...
;
; 1.39 -- fixed multiple read queues to work the way they should...
;
; 1.40 -- fixed promiscuous mode flag bit check in close routine
; fixed collision statistics (but still not sure if it really works)
;
; 1.41 -- fixed interrupt name
; (really strange that it didn't get fixed earlier...)
;
; 1.42 -- fixed orphan packet/normal packet handling interaction
;
; 1.43 -- trying to debug problems with Enlan-DFS ...
; (and found a bug in Enlan...)
;
; 1.44 -- now uses Enqueue to queue iorequests (uses priority)
;
; 1.45 -- now clears global/special stats in S2_ONLINE
;
;
; if DEBUG is defined, the device writes a lot of debugging
; info to the serial port (with RawPutChar())
;
;
;DEBUG set 1
;;;
nolist
include 'exec/types.i'
include 'exec/resident.i'
include 'exec/interrupts.i'
include 'exec/devices.i'
include 'exec/io.i'
include 'exec/errors.i'
include 'exec/memory.i'
include 'exec/initializers.i'
include 'devices/timer.i'
include 'utility/tagitem.i'
include 'utility/hooks.i'
include 'libraries/configvars.i'
include 'hardware/intbits.i'
include 'hardware/cia.i'
include 'include/offsets.i'
include 'devices/sana2.i'
include 'devices/sana2specialstats.i'
list
include 'include/hydraboard.i'
include 'include/hydradev.i'
include 'include/macros.i'
;
Ciaa equ $bfe001
;
;
; Delay between NIC (Network Interface Controller) accesses. Done by
; accessing a CIA chip.
;
NIC_Delay macro
tst.b Ciaa+ciapra
tst.b Ciaa+ciapra
endm
;
; bit numbers for S2EVENT_xxx
;
bitnum S2EVENTB_ERROR,S2EVENT_ERROR
bitnum S2EVENTB_TX,S2EVENT_TX
bitnum S2EVENTB_RX,S2EVENT_RX
bitnum S2EVENTB_ONLINE,S2EVENT_ONLINE
bitnum S2EVENTB_OFFLINE,S2EVENT_OFFLINE
bitnum S2EVENTB_BUFF,S2EVENT_BUFF
bitnum S2EVENTB_HARDWARE,S2EVENT_HARDWARE
bitnum S2EVENTB_SOFTWARE,S2EVENT_SOFTWARE
;
xref multicast_hash ;exported from hash.a
DEV_VERSION equ 1
DEV_REVISION equ 45
;
; start of the first hunk of the device file
; if someone tries to run this from CLI/Shell, return an error
;
dev_SafeExit moveq #-1,d0
rts
dev_romtag dc.w RTC_MATCHWORD ;rt_MatchWord
dc.l dev_romtag ;rt_MatchTag
dc.l dev_endskip ;rt_EndSkip
dc.b RTF_AUTOINIT ;rt_Flags
dc.b DEV_VERSION ;rt_Version
dc.b NT_DEVICE ;rt_Type
dc.b 0 ;rt_Pri
dc.l dev_name
dc.l dev_idstring
dc.l dev_init
dev_name dc.b 'hydra.device',0
dc.b '$VER: '
dev_idstring dc.b 'hydradev '
StrNumber DEV_VERSION
dc.b '.'
StrNumber DEV_REVISION
dc.b ' (25.06.95)',CR,LF,0
copyright_msg dc.b 'Copyright © 1992-1995 by JMP-Electronics / Bits & Chips, Finland',CR,LF,0
expansion_name dc.b 'expansion.library',0
intuition_name dc.b 'intuition.library',0
ds.w 0 ;word align
;
; because the RTF_AUTOINIT flag in the RomTag structure was set
; RT_INIT points to this table of parameters for MakeLibrary()
;
dev_init dc.l dev_DataSize
dc.l dev_FuncInit
dc.l dev_StructInit
dc.l dev_InitRoutine
devfunc macro
dc.w \1-dev_FuncInit
endm
;
; device function init
;
dev_FuncInit dc.w -1
; standard library routines
devfunc dev_Open
devfunc dev_Close
devfunc dev_Expunge
devfunc dev_Reserved
; standard device routines
devfunc dev_BeginIO
devfunc dev_AbortIO
dc.w -1
;
; device structure init
;
dev_StructInit INITBYTE LN_TYPE,NT_DEVICE
INITLONG LN_NAME,dev_name
INITLONG LIB_IDSTRING,dev_idstring
INITBYTE LIB_FLAGS,LIBF_CHANGED!LIBF_SUMUSED
INITLONG LIB_VERSION,(DEV_VERSION<<16)+DEV_REVISION
dc.l 0
;
; Device initialization routine
;
; Entry:
; d0 - device base
; a6 - execbase
;
; Return:
; d0 - device base if successfull, zero if not
;
dev_InitRoutine move.l a4,-(sp)
ifd DEBUG
DMSG <'Device init entry (device = $%lx)',LF>
endc
move.l d0,a4 ;get device base in a4
move.l a0,dev_SegList(a4) ;save seglist for expunge
move.l a6,dev_SysBase(a4)
lea expansion_name(pc),a1
moveq #0,d0
lib OpenLibrary
move.l d0,dev_ExpansionBase(a4)
beq.b initfail1
lea intuition_name(pc),a1
moveq #0,d0
lib OpenLibrary
move.l d0,dev_IntuitionBase(a4)
beq.b initfail2
move.l a4,d0
move.l (sp)+,a4
rts
initfail2 move.l dev_ExpansionBase(a4),a1
lib CloseLibrary
initfail1
ifd DEBUG
DMSG <'Device init fail',LF>
endc
move.l (sp)+,a4
dev_Reserved moveq #0,d0
rts
;
; Device open routine
;
; Entry:
; a6 - device base
; a1 - io request
; d0 - unit number
; d1 - flags
;
; Return:
; d0 - zero if successfull, error code if failure
;
dev_Open movem.l d2/d3/a2/a3,-(sp)
ifd DEBUG
DMSG <'Device open entry (unit = %ld, flags = $%lx)',LF>
endc
move.l d1,d3
move.l a1,a2
moveq #NUM_UNITS,d2
cmp.l d2,d0
bcc open_fail
move.l d0,d2
lsl.l #2,d2
move.l dev_UnitTable(a6,d2.l),d0
bne.b unit_ok
move.l d2,d0
lsr.l #2,d0
bsr Initialize_Unit
tst.l d0
beq open_fail
move.l d0,dev_UnitTable(a6,d2.l)
unit_ok move.l d0,a3
tst.w UNIT_OPENCNT(a3)
beq.b excl_ok1
btst #SANA2OPB_MINE,d3
bne excl_open_fail
excl_ok1 btst #UNITB_EXCLUSIVE,UNIT_FLAGS(a3)
bne excl_open_fail
btst #SANA2OPB_MINE,d3
beq.b excl_ok2
bset #UNITB_EXCLUSIVE,UNIT_FLAGS(a3)
excl_ok2 move.l IOS2_BUFFERMANAGEMENT(a2),a1
bsr InitBuffManagement
move.l d0,IOS2_BUFFERMANAGEMENT(a2)
beq open_fail
move.l a6,-(sp)
move.l dev_SysBase(a6),a6
move.l d0,a1
;
; Add magic cookie to the cookie list
; Remember to Disable() when accessing the cookie list
;
lib Disable
lea du_CookieList(a3),a0
lib AddHead
lib Enable
move.l (sp)+,a6
btst #SANA2OPB_PROM,d3
beq.b open_ok1
;
; open in promiscuous mode
; use cookie_Flags so we remember to decrement PromCount in close
;
addq.w #1,du_PromCount(a3)
move.l IOS2_BUFFERMANAGEMENT(a2),a0
bset #BFMB_PROM,cookie_Flags(a0)
move.l du_BoardAddr1(a3),a0
move.b #RCRF_PRO!RCRF_AB!RCRF_AM,NIC_RCR(a0)
ifd DEBUG
DMSG <'Enabled promiscuous mode',LF>
endc
open_ok1 move.l a3,IO_UNIT(a2)
addq.w #1,UNIT_OPENCNT(a3)
addq.w #1,LIB_OPENCNT(a6)
and.b #~LIBF_DELEXP,LIB_FLAGS(a6)
ifd DEBUG
DMSG <'Open successfull',LF>
endc
moveq #0,d0
open_exit movem.l (sp)+,d2/d3/a2/a3
rts
open_fail moveq #IOERR_OPENFAIL,d0
open_err moveq #-1,d1
move.l d1,IO_DEVICE(a2)
move.l d1,IO_UNIT(a2)
move.b d0,IO_ERROR(a2)
ifd DEBUG
DMSG <'Device open failed, error %ld',LF>
endc
bra.b open_exit
excl_open_fail moveq #IOERR_UNITBUSY,d0
bra.b open_err
;
; Device close routine
;
; Entry:
; a6 - device base
; a1 - io request
;
; Return:
; d0 - seglist if device no longer in use, else zero
;
dev_Close movem.l a2/a3,-(sp)
ifd DEBUG
DMSG <'Device close entry',LF>
endc
move.l a1,a2
move.l IO_UNIT(a2),a3
bclr #UNITB_EXCLUSIVE,UNIT_FLAGS(a3)
moveq #-1,d0
move.l d0,IO_DEVICE(a2)
move.l d0,IO_UNIT(a2)
move.l a6,-(sp)
move.l dev_SysBase(a6),a6
;
; Remove magic cookie from the cookie list
; Remember to Disable() when accessing the cookie list
;
lib Disable
move.l IOS2_BUFFERMANAGEMENT(a2),a1
lib Remove
lib Enable
move.l IOS2_BUFFERMANAGEMENT(a2),a1
move.b cookie_Flags(a1),-(sp)
moveq #cookie_Sizeof,d0
lib FreeMem
move.b (sp)+,d0
move.l (sp)+,a6
subq.w #1,UNIT_OPENCNT(a3)
btst #BFMB_PROM,d0
beq.b close_1
subq.w #1,du_PromCount(a3)
bne.b close_1
; disable promiscuous mode
move.l du_BoardAddr1(a3),a0
move.b #RCRF_AB!RCRF_AM,NIC_RCR(a0)
ifd DEBUG
DMSG <'Disabled promiscuous mode',LF>
endc
close_1 moveq #0,d0
subq.w #1,LIB_OPENCNT(a6)
bne.b close_end
btst #LIBB_DELEXP,LIB_FLAGS(a6)
beq.b close_end
bsr.b dev_Expunge
close_end movem.l (sp)+,a2/a3
rts
;
; Device expunge routine
;
; Entry:
; a6 - device base
;
; Return:
; d0 - seglist if device no longer in use, else zero
;
dev_Expunge tst.w LIB_OPENCNT(a6)
beq.b do_expunge
or.b #LIBF_DELEXP,LIB_FLAGS(a6) ;delayed expunge
moveq #0,d0
rts
;
; really expunge the device
;
do_expunge movem.l d2/d3/a4/a6,-(sp)
ifd DEBUG
DMSG <'do_expunge entry',LF>
endc
moveq #NUM_UNITS-1,d3
unit_expunge_loop
move.l d3,d2
lsl.l #2,d2
move.l dev_UnitTable(a6,d2.l),d0
beq.b unit_expunge_next
move.l d0,a1
bsr Expunge_Unit
clr.l dev_UnitTable(a6,d2.l)
unit_expunge_next
dbf d3,unit_expunge_loop
move.l a6,a4
move.l dev_SysBase(a4),a6
move.l dev_ExpansionBase(a4),a1
lib CloseLibrary
move.l dev_IntuitionBase(a4),a1
lib CloseLibrary
move.l dev_SegList(a4),d2
move.l a4,a1
lib Remove
move.l a4,a1
moveq #0,d0
moveq #0,d1
move.w LIB_NEGSIZE(a4),d0
move.w LIB_POSSIZE(a4),d1
sub.l d0,a1
add.l d1,d0
lib FreeMem
move.l d2,d0
movem.l (sp)+,d2/d3/a4/a6
rts
;
; Initialize buffer management magic cookie
;
; Entry:
; a1 - buffer management taglist
;
; This does not use the 2.0+ utility.library taglist functions,
; and it should also work on the 1.3 operating system.
;
InitBuffManagement
movem.l a2/a3,-(sp)
move.l a1,a2
ifd DEBUG
move.l a1,d0
DMSG <'InitBuffManagement entry, taglist = $%lx',LF>
endc
moveq #cookie_Sizeof,d0
move.l #MEMF_PUBLIC!MEMF_CLEAR,d1
lib Exec,AllocMem
tst.l d0
beq initbuffm_exit
move.l d0,a3
ifd DEBUG
DMSG <'Allocated magic cookie at $%lx',LF>
endc
lea DummyCopy(pc),a0
move.l a0,cookie_CopyToBuff(a3)
move.l a0,cookie_CopyFromBuff(a3)
move.l a2,d0
beq.b initbuffm_ok
buffm_tag_loop move.l (a2)+,d0
beq.b initbuffm_ok ;TAG_DONE == 0
cmp.l #S2_COPYTOBUFF,d0
bne.b 1$
move.l (a2)+,cookie_CopyToBuff(a3)
bra.b buffm_tag_loop
1$ cmp.l #S2_COPYFROMBUFF,d0
bne.b 2$
move.l (a2)+,cookie_CopyFromBuff(a3)
bra.b buffm_tag_loop
2$ cmp.l #S2_PACKETFILTER,d0
bne.b 21$
move.l (a2)+,cookie_PacketFilter(a3)
bra.b buffm_tag_loop
21$ subq.l #TAG_IGNORE,d0
bne.b 3$
55$ addq.l #4,a2
bra.b buffm_tag_loop
3$ subq.l #TAG_MORE-TAG_IGNORE,d0
bne.b 4$
move.l (a2),a2
bra.b buffm_tag_loop
4$ subq.l #TAG_SKIP-TAG_MORE,d0
bne.b 55$
addq.l #8,a2
bra.b 55$
initbuffm_ok
ifd DEBUG
move.l cookie_CopyFromBuff(a3),d0
move.l cookie_CopyToBuff(a3),d1
DMSG <'CopyFromBuff = $%lx, CopyToBuff = $%lx',LF>
move.l cookie_PacketFilter(a3),d0
DMSG <'PacketFilter hook = $%lx',LF>
endc
lea cookie_RxQueue(a3),a0
NEWLIST a0
move.l a3,d0
initbuffm_exit movem.l (sp)+,a2/a3
rts
;
; Dummy copy routine for buffer management
;
DummyCopy moveq #1,d0 ; success
rts
;
; Initialize an unit
;
; Entry:
; d0 - unit number
; a6 - device base
;
; Return:
; d0 - pointer to unit structure or zero if failed
;
; Note: Unit number is zero for first Hydra board, one for second etc.
; Initialize_Unit will fail if the board already has
; the CONFIGME bit cleared
;
Initialize_Unit movem.l d2/d3/a2/a3,-(sp)
ifd DEBUG
DMSG <'Initialize unit entry, number = %ld',LF>
endif
move.l d0,d2
move.l d0,d3
suba.l a0,a0
find_board_loop
move.l #HYDRA_MANUF_NUM,d0
move.l #HYDRA_PROD_NUM,d1
lib Expansion,FindConfigDev
tst.l d0
beq init_unit_exit
tst.l d3
beq.b found_board
subq.l #1,d3
move.l d0,a0
bra.b find_board_loop
found_board move.l d0,a2
bclr #CDB_CONFIGME,cd_Flags(a2)
beq init_unit_exit ; board already configured
ifd DEBUG
DMSG <'Found Hydra ethernet board, configdev = $%lx',LF>
endc
;
; find out the amount of RAM memory on the ethernet card
;
ifd DEBUG
move.l cd_BoardAddr(a2),d0
DMSG <'Looking for card RAM at $%lx',LF>
endc
moveq #0,d3
move.l cd_BoardAddr(a2),a0
move.l #$5555,d0
move.l #$aaaa,d1
ram_size_loop move.w d0,0(a0,d3.l) ; .l's added by JM 940217
move.w d1,2(a0,d3.l)
NIC_Delay
NIC_Delay
cmp.w 0(a0,d3.l),d0
bne.b ram_end
cmp.w 2(a0,d3.l),d1
bne.b ram_end
add.w #$100,d3
cmp.w #$ff00,d3
bcs.b ram_size_loop
ram_end
ifd DEBUG
move.l d3,d0
add.l a0,d0
DMSG <'Receive buffer end (end of card RAM) = $%lx',LF>
endc
tst.w d3
beq ram_error
lsr.w #8,d3
move.l #du_Sizeof,d0
move.l #MEMF_PUBLIC!MEMF_CLEAR,d1
lib Exec,AllocMem
tst.l d0
beq init_unit_alloc_fail
move.l d0,a3
lea dev_name(pc),a0
move.l a0,LN_NAME(a3)
move.b #PA_IGNORE,MP_FLAGS(a3) ;the MsgPort in unit is not used
move.l a6,du_DevicePtr(a3)
move.l d2,du_UnitNum(a3)
move.l a2,du_ConfigDev(a3)
move.l cd_BoardAddr(a2),a0
move.l a0,du_BoardAddr(a3)
add.l #$8000,a0
move.l a0,du_BoardAddr1(a3)
moveq #-1,d0
move.l d0,du_CurrentAddr(a3)
move.w d0,du_CurrentAddr+4(a3)
;
; select page 0 & disable & clear NIC interrupts before adding interrupt server
;
move.b #CRF_NODMA!CRF_STOP,NIC_CR(a0)
NIC_Delay
move.b #0,NIC_IMR(a0) ; disable interrupts
NIC_Delay
move.b #$ff,NIC_ISR(a0) ; clear interrupts
NIC_Delay
;
; read default ethernet address from board PROM
;
lea HYDRA_DEFADDR(a0),a0
lea du_DefaultAddr(a3),a1
moveq #EADDR_BYTES-1,d0
get_def_addr_loop
move.b (a0),(a1)+
addq.l #2,a0
dbf d0,get_def_addr_loop
; (interrupt server is added in S2_CONFIGINTERFACE)
;
; initialize transmit page start/receive buffer start/end page variables
;
clr.b du_TPStart(a3)
move.b #8,du_PStart(a3)
move.b d3,du_PStop(a3)
;
; initialize unit transmit/receive queues
;
lea du_TxQueue(a3),a0
NEWLIST a0
lea du_CookieList(a3),a0
NEWLIST a0
lea du_RxOrphanQueue(a3),a0
NEWLIST a0
lea du_EventList(a3),a0
NEWLIST a0
lea du_MultiCastList(a3),a0
NEWLIST a0
lea du_TypeTrackList(a3),a0
NEWLIST a0
init_unit_ok move.l a3,d0
init_unit_exit
ifd DEBUG
DMSG <'Initialize_Unit return = $%lx',LF>
endc
movem.l (sp)+,d2/d3/a2/a3
rts
ram_error
ifd DEBUG
DMSG <'Board RAM test failed',LF>
endc
init_unit_alloc_fail
bset #CDB_CONFIGME,cd_Flags(a2)
moveq #0,d0
bra.b init_unit_exit
;
; Unit expunge routine
;
; Entry:
; a1 - pointer to unit structure
;
; Return:
; nothing
;
Expunge_Unit movem.l d2/a2/a3/a6,-(sp)
move.l dev_SysBase(a6),a6
ifd DEBUG
move.l a1,d0
move.l du_UnitNum(a1),d1
DMSG <'Expunge_Unit called, unit = $%lx (#%ld)',LF>
endc
move.l a1,a3
move.l du_BoardAddr1(a3),a0
move.b #CRF_NODMA!CRF_STOP,NIC_CR(a0) ; reset & select page 0
NIC_Delay
move.b #0,NIC_IMR(a0) ; disable all interrupts
NIC_Delay
move.b #$ff,NIC_ISR(a0) ; clear all interrupts
btst #UNITB_ONLINE,UNIT_FLAGS(a3)
beq.b exp_unit_1
lea du_NIC_Intr(a3),a1
moveq #INTB_PORTS,d0
lib RemIntServer
exp_unit_1
;
; free all multicast addresses that are in use when the unit is expunged
;
move.l du_MultiCastList(a3),a2
exp_mca_loop move.l (a2),d2
beq.b exp_mca_done
move.l a2,a1
move.l #mca_Sizeof,d0
lib FreeMem
move.l d2,a2
bra.b exp_mca_loop
exp_mca_done
;
; free all type tracking nodes that are still here
;
move.l du_TypeTrackList(a3),a2
exp_tt_loop move.l (a2),d2
beq.b exp_tt_done
move.l a2,a1
move.l #ttn_Sizeof,d0
lib FreeMem
move.l d2,a2
bra.b exp_tt_loop
exp_tt_done
;
; and free the unit structure itself
;
move.l a3,a1
move.l du_ConfigDev(a3),a3
move.l #du_Sizeof,d0
lib FreeMem
;
; allow re-configuration of the board
;
bset #CDB_CONFIGME,cd_Flags(a3)
movem.l (sp)+,d2/a2/a3/a6
rts
;
; BeginIO routine
;
; A1 - pointer to IORequest
; A6 - pointer to device
;
dev_BeginIO movem.l a2/a3,-(sp)
move.l a1,a2
move.b #NT_MESSAGE,LN_TYPE(a2) ;LN_TYPE != NT_REPLYMSG
clr.b IO_ERROR(a2)
move.l IO_UNIT(a2),a3
ifd DEBUG
move.l a1,d0
moveq #0,d1
move.w IO_COMMAND(a1),d1
DMSG <'BeginIO, request = $%lx, command = $%lx',LF>
endc
move.w IO_COMMAND(a2),d0
cmp.w #S2_END,d0
bcc.b invalid_cmd
add.w d0,d0 ; d0 *= 2
lea dev_CmdTable(pc),a0
move.l a0,a1
add.w d0,a1
add.w (a1),a0
jsr (a0)
beginio_exit movem.l (sp)+,a2/a3
rts
invalid_cmd moveq #IOERR_NOCMD,d0
moveq #0,d1
IOError move.b d0,IO_ERROR(a2)
move.b d1,IOS2_WIREERROR+3(a2)
;
; a2 - iorequest, a3 - unit, a6 - device
;
TermIO
ifd DEBUG
movem.l d2/d3,-(sp)
move.l a2,d0
moveq #0,d1
move.w IO_COMMAND(a2),d1
moveq #0,d2
move.b IO_ERROR(a2),d2
moveq #0,d3
move.b IO_FLAGS(a2),d3
DMSG <'TermIO, req = $%lx, cmd = $%lx, err = $%lx, flags = %lx',LF>
movem.l (sp)+,d2/d3
endc
move.l a2,a1
btst #SANA2IOB_QUICK,IO_FLAGS(a1)
bne.b termio_exit
lib Exec,ReplyMsg
termio_exit rts
;
; AbortIO routine
; a1 - pointer to IORequest
;
dev_AbortIO movem.l d2/a2/a3,-(sp)
moveq #IOERR_NOCMD,d2
move.l a1,a2
ifd DEBUG
move.l a1,d0
DMSG <'AbortIO, request = $%lx',LF>
endc
move.w IO_COMMAND(a2),d0
cmp.w #S2_ONEVENT,d0
beq.b abort_onevent
cmp.w #CMD_WRITE,d0
beq.b abort_write
cmp.w #S2_MULTICAST,d0
beq.b abort_write
cmp.w #S2_BROADCAST,d0
beq.b abort_write
cmp.w #CMD_READ,d0
beq.b abort_read
cmp.w #S2_READORPHAN,d0
bne.b AbortIO_End
abort_onevent
abort_read
abort_write bclr #IOB_QUEUED,IO_FLAGS(a2)
beq.b AbortIO_End
move.l a2,a1
lib Exec,Remove
ifd DEBUG
DMSG <'Unlinked request',LF>
endc
moveq #IOERR_ABORTED,d0
moveq #0,d1