Subversion Repositories Kolibri OS

Rev

Rev 1519 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1519 Rev 1521
Line 355... Line 355...
355
	.ver_id 		  db ?
355
	.ver_id 		  db ?
356
	.full_bus_master	  db ?
356
	.full_bus_master	  db ?
357
	.has_hwcksm		  db ?
357
	.has_hwcksm		  db ?
358
	.preamble		  db ?
358
	.preamble		  db ?
359
	.dn_list_ptr_cleared	  db ?
359
	.dn_list_ptr_cleared	  db ?
360
	.self_directed_packet	  rb 20
-
 
Line 361... Line 360...
361
 
360
 
Line 362... Line 361...
362
	.size = $ - device
361
	.size = $ - device
Line 471... Line 470...
471
	mov	ecx, [BOOMERANG_DEVICES]
470
	mov	ecx, [BOOMERANG_DEVICES]
472
	add	ecx, [VORTEX_DEVICES]
471
	add	ecx, [VORTEX_DEVICES]
473
	cmp	ecx, MAX_DEVICES			; First check if the driver can handle one more card
472
	cmp	ecx, MAX_DEVICES			; First check if the driver can handle one more card
474
	jge	.fail
473
	jge	.fail
Line 475... Line -...
475
 
-
 
476
	push	edx
474
 
477
	stdcall KernelAlloc, dword device.size		; Allocate the buffer for eth_device structure
-
 
478
	pop	edx
-
 
479
	test	eax, eax
-
 
480
	jz	.fail
-
 
Line 481... Line 475...
481
	mov	ebx, eax				; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
475
	allocate_and_clear ebx, device.size, .fail	; Allocate the buffer for device structure
Line 482... Line 476...
482
 
476
 
483
; Fill in the direct call addresses into the struct
477
; Fill in the direct call addresses into the struct
Line 514... Line 508...
514
 
508
 
515
	movzx	ecx, [device.ver_id]
509
	movzx	ecx, [device.ver_id]
516
	test	word [hw_versions+2+ecx*4], IS_VORTEX
510
	test	word [hw_versions+2+ecx*4], IS_VORTEX
Line 517... Line -...
517
	jz	.not_vortex
-
 
518
 
511
	jz	.not_vortex
519
 
512
 
520
	mov	eax, [VORTEX_DEVICES]					       ; Add the device structure to our device list
513
	mov	eax, [VORTEX_DEVICES]					; Add the device structure to our device list
Line 521... Line 514...
521
	mov	[VORTEX_LIST+4*eax], ebx				; (IRQ handler uses this list to find device)
514
	mov	[VORTEX_LIST+4*eax], ebx				; (IRQ handler uses this list to find device)
522
	inc	[VORTEX_DEVICES]					       ;
-
 
523
 
515
	inc	[VORTEX_DEVICES]					;
524
  .register:
516
 
Line 525... Line 517...
525
 
517
  .register:
526
	mov	[device.type], NET_TYPE_ETH
518
	mov	[device.type], NET_TYPE_ETH
Line 527... Line 519...
527
	call	NetRegDev
519
	call	NetRegDev
528
 
-
 
529
	cmp	eax, -1
520
 
Line 530... Line 521...
530
	je	.destroy
521
	cmp	eax, -1
531
 
-
 
532
	call	start
522
	je	.destroy
533
 
523
 
534
	ret
524
	call	start_device
Line 535... Line 525...
535
 
525
	ret
Line 536... Line 526...
536
  .not_vortex:
526
 
Line 537... Line 527...
537
 
527
  .not_vortex:
538
	mov	eax, [BOOMERANG_DEVICES]					  ; Add the device structure to our device list
528
	mov	eax, [BOOMERANG_DEVICES]					  ; Add the device structure to our device list
Line 739... Line 729...
739
	mov	ax, 1
729
	mov	ax, 1
740
	out	dx, ax			      ; enable card
730
	out	dx, ax			      ; enable card
Line 741... Line 731...
741
 
731
 
Line 742... Line 732...
742
	call	write_mac
732
	call	write_mac
743
 
733
 
Line 744... Line 734...
744
	call	rx_reset
734
 
745
	call	tx_reset
735
;<<<<<<<<<<<<<<
746
 
736
 
Line 766... Line 756...
766
	out	dx, ax
756
	out	dx, ax
Line 767... Line 757...
767
 
757
 
768
	call	set_rx_mode
758
	call	set_rx_mode
Line -... Line 759...
-
 
759
	call	set_active_port
-
 
760
 
-
 
761
;>>>>>>>>>>
-
 
762
 
-
 
763
	call	create_rx_ring
-
 
764
	call	rx_reset
-
 
765
	call	tx_reset
-
 
766
 
769
	call	set_active_port
767
;>>>>>>>>>>>>>>>>>>
770
 
768
 
771
	set_io	0
769
	set_io	0
772
	set_io	REG_COMMAND
770
	set_io	REG_COMMAND
Line 801... Line 799...
801
 
799
 
802
 
800
 
-
 
801
 
Line 803... Line 802...
803
 
802
 
804
 
803
align 4
805
align 4
804
start_device:
806
start:
805
	DEBUGF	1,"Starting the device\n"
Line 820... Line 819...
820
 
819
 
821
; wait for linkDetect
820
; wait for linkDetect
822
	set_io	REG_MEDIA_STATUS
821
	set_io	REG_MEDIA_STATUS
823
	mov	ecx, 20 ; wait for max 2s
822
	mov	ecx, 20 ; wait for max 2s
824
.link_detect_loop:
823
  .link_detect_loop:
825
	mov	esi, 10
824
	mov	esi, 100
826
	stdcall Sleep ; 100 ms
825
	call	Sleep ; 100 ms
827
	in	ax, dx
826
	in	ax, dx
828
	test	ah, 1000b ; linkDetect
827
	test	ah, 1000b ; linkDetect
829
	jnz	@f
828
	jnz	@f
-
 
829
	loop	.link_detect_loop
830
	loop	.link_detect_loop
830
	DEBUGF	1,"Link detect timed-out!\n"
Line 831... Line 831...
831
@@:
831
       @@:
832
 
832
 
833
; print link type
833
; print link type
834
	xor	eax, eax
834
	xor	eax, eax
835
	bsr	ax, word [device.mode]
835
	bsr	ax, word [device.mode]
836
	jz	@f
836
	jz	@f
-
 
837
	sub	ax, 4
837
	sub	ax, 4
838
       @@:
838
@@:
839
 
Line -... Line 840...
-
 
840
	mov	esi, [link_str+eax*4]
Line 839... Line -...
839
	mov	esi, [link_str+eax*4]
-
 
840
	DEBUGF 1,"Established Link type: %s\n", esi
841
	DEBUGF	1,"Established Link type: %s\n", esi
841
 
842
 
842
 
843
; enable interrupts
Line 843... Line 844...
843
	set_io	0
844
 
Line 852... Line 853...
852
	out	dx, ax
853
	out	dx, ax
Line 853... Line 854...
853
 
854
 
854
	mov	ax, SetIntrEnb + S_5_INTS
855
	mov	ax, SetIntrEnb + S_5_INTS
Line 855... Line -...
855
	out	dx, ax
-
 
856
 
-
 
857
	set_io	0
-
 
858
	set_io	REG_COMMAND
-
 
859
	mov	ax, SELECT_REGISTER_WINDOW + 1
-
 
860
 
856
	out	dx, ax
Line 868... Line 864...
868
 
864
 
869
 
865
 
Line -... Line 866...
-
 
866
align 4
-
 
867
set_rx_mode:
870
align 4
868
 
871
set_rx_mode:
869
	DEBUGF	1,"Setting RX mode\n"
Line 872... Line 870...
872
 
870
 
873
	set_io	0
871
	set_io	0
874
	set_io	REG_COMMAND
872
	set_io	REG_COMMAND
875
 
873
 
876
	if	defined PROMISCIOUS
874
if	defined PROMISCIOUS
877
	mov	ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast + RxProm
875
	mov	ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast + RxProm
878
	else if  defined ALLMULTI
876
else if  defined ALLMULTI
879
	mov	ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast
-
 
880
	else
877
	mov	ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast
Line 881... Line 878...
881
	mov	ax, SetRxFilter + RxStation + RxBroadcast
878
else
Line 903... Line 900...
903
;***************************************************************************1
900
;***************************************************************************1
Line 904... Line 901...
904
 
901
 
905
align 4
902
align 4
Line 906... Line 903...
906
global_reset:
903
global_reset:
Line 907... Line 904...
907
 
904
 
908
	DEBUGF 1,"Global reset: "
905
	DEBUGF 1,"Global reset..\n"
909
 
906
 
910
; GlobalReset
907
; GlobalReset
Line 916... Line 913...
916
; wait for GlobalReset to complete
913
; wait for GlobalReset to complete
917
	mov	ecx, 64000
914
	mov	ecx, 64000
918
.loop:
915
  .loop:
919
	in	ax , dx
916
	in	ax , dx
920
	test	ah , 10000b ; check CmdInProgress
917
	test	ah , 10000b ; check CmdInProgress
921
;        jz      .finish
-
 
922
	loopz	.loop
918
	loopz	.loop
923
;.finish:
919
 
924
;        DEBUGF 1,"Waiting for nic to boot..\n"
920
	DEBUGF 1,"Waiting for nic to boot..\n"
925
; wait for 2 seconds for NIC to boot
921
; wait for 2 seconds for NIC to boot
926
	mov	esi, 200
922
	mov	esi, 2000
927
	stdcall Sleep ; 2 seconds
923
	call	Sleep ; 2 seconds
Line 928... Line 924...
928
 
924
 
Line 929... Line 925...
929
	DEBUGF 1,"Ok!\n"
925
	DEBUGF 1,"Ok!\n"
Line 988... Line 984...
988
; wait for RxReset to complete
984
; wait for RxReset to complete
989
	mov	ecx, 200000
985
	mov	ecx, 200000
990
  .loop:
986
  .loop:
991
	in	ax, dx
987
	in	ax, dx
992
	test	ah, 10000b ; check CmdInProgress
988
	test	ah, 10000b ; check CmdInProgress
-
 
989
	jz	.done
993
	dec	ecx
990
	dec	ecx
994
	jnz	.loop
991
	jnz	.loop
-
 
992
  .done:
-
 
993
 
-
 
994
	lea	eax, [device.upd_buffer]
-
 
995
	mov	[device.curr_upd], eax
-
 
996
	GetRealAddr
-
 
997
	set_io	0
-
 
998
	set_io	REG_UP_LIST_PTR
-
 
999
	out	dx, eax
-
 
1000
 
-
 
1001
  .rx_enable:
-
 
1002
	ret
Line -... Line 1003...
-
 
1003
 
-
 
1004
 
-
 
1005
align 4
995
 
1006
create_rx_ring:
996
; create upd ring
1007
; create upd ring
997
	lea	eax, [device.upd_buffer]
1008
	lea	eax, [device.upd_buffer]
998
	GetRealAddr
1009
	GetRealAddr
Line 1022... Line 1033...
1022
	add	esi, upd.size
1033
	add	esi, upd.size
1023
	add	edi, upd.size
1034
	add	edi, upd.size
1024
	dec	ecx
1035
	dec	ecx
1025
	jnz	.upd_loop
1036
	jnz	.upd_loop
Line 1026... Line -...
1026
 
-
 
1027
	lea	eax, [device.upd_buffer]
-
 
1028
	mov	[device.curr_upd], eax
-
 
1029
	GetRealAddr
-
 
1030
	set_io	0
-
 
1031
	set_io	REG_UP_LIST_PTR
-
 
1032
	out	dx, eax
-
 
1033
 
-
 
1034
  .rx_enable:
1037
 
Line 1035... Line -...
1035
	ret
-
 
1036
 
1038
	ret
1037
 
1039
 
1038
 
1040
 
1039
 
1041
 
1040
;---------------------------------------------------------------------------
1042
;---------------------------------------------------------------------------
Line 1056... Line 1058...
1056
try_link_detect:
1058
try_link_detect:
Line 1057... Line 1059...
1057
 
1059
 
Line 1058... Line 1060...
1058
	DEBUGF 1,"trying to detect link\n"
1060
	DEBUGF	1,"trying to detect link\n"
-
 
1061
 
-
 
1062
; create self-directed packet
-
 
1063
	stdcall KernelAlloc, 20 ; create a buffer for the self-directed packet
-
 
1064
	test	eax, eax
-
 
1065
	jz	.fail
-
 
1066
 
-
 
1067
	pushd	20		; Packet parameters for device.transmit
-
 
1068
	push	eax		;
-
 
1069
 
1059
 
1070
	mov	edi, eax
1060
; create self-directed packet
-
 
1061
	lea	esi, [device.mac]
1071
 
1062
	lea	edi, [device.self_directed_packet]
1072
	lea	esi, [device.mac]
1063
	movsw
1073
	movsw
1064
	movsd
1074
	movsd
1065
	sub	esi, 6
1075
	sub	esi, 6
1066
	movsw
1076
	movsw
1067
	movsd
1077
	movsd
Line 1068... Line 1078...
1068
	mov	ax , 0x0608
1078
	mov	ax , 0x0608
1069
	stosw
-
 
1070
 
-
 
1071
; download self-directed packet
-
 
1072
	push	20
1079
	stosw
Line 1073... Line 1080...
1073
	lea	eax, [device.self_directed_packet]
1080
 
1074
	push	eax
1081
; download self-directed packet
1075
	call	[device.transmit]
1082
	call	[device.transmit]
Line 1096... Line 1103...
1096
	jnz	.link_detected
1103
	jnz	.link_detected
1097
	xor	al, al
1104
	xor	al, al
1098
	jmp	.finish
1105
	jmp	.finish
Line 1099... Line 1106...
1099
 
1106
 
-
 
1107
  .link_detected:
1100
.link_detected:
1108
	DEBUGF	1,"link detected!\n"
Line 1101... Line 1109...
1101
	setb	al
1109
	setb	al
1102
 
1110
 
1103
.finish:
1111
  .finish:
1104
	test	al, al
1112
	test	al, al
1105
	jz	@f
1113
	jz	@f
1106
	or	byte [device.mode+1], 100b
1114
	or	byte [device.mode+1], 100b
Line -... Line 1115...
-
 
1115
       @@:
-
 
1116
	ret
-
 
1117
 
Line 1107... Line 1118...
1107
@@:
1118
  .fail:
1108
	ret
1119
	ret
1109
 
1120
 
1110
 
1121
 
1111
 
1122
 
1112
;***************************************************************************
1123
;***************************************************************************
1113
;   Function
1124
;   Function
1114
;      try_phy
1125
;      try_phy
1115
;   Description
1126
;   Description
1116
;      try_phy checks the auto-negotiation function
1127
;      try_phy checks the auto-negotiation function
1117
;      in the PHY at PHY index. It can also be extended to
1128
;      in the PHY at PHY index. It can also be extended to
1118
;      include link detection for non-IEEE 802.3u
1129
;      include link detection for non-IEEE 802.3u
1119
;      auto-negotiation devices, for instance the BCM5000.
1130
;      auto-negotiation devices, for instance the BCM5000.              ; TODO: BCM5000
Line 1129... Line 1140...
1129
;***************************************************************************
1140
;***************************************************************************
Line 1130... Line 1141...
1130
 
1141
 
1131
align 4
1142
align 4
Line 1132... Line 1143...
1132
try_phy:
1143
try_phy:
-
 
1144
 
Line 1133... Line 1145...
1133
 
1145
	DEBUGF 1,"PHY=%u\n", ah
1134
	DEBUGF 1,"trying phy\n"
1146
	DEBUGF 1,"Detecting if device is auto-negotiation capable\n"
1135
 
1147
 
1136
	mov	al, REG_MII_BMCR
1148
	mov	al, REG_MII_BMCR
1137
	push	eax
1149
	push	eax
1138
	call	mdio_read	; returns with window #4
1150
	call	mdio_read	; returns with window #4
1139
	or	ah , 0x80	; software reset
1151
	or	ah , 0x80	; software reset
Line 1140... Line 1152...
1140
	mov	esi, eax
1152
	mov	esi, eax
1141
	mov	eax, dword [esp]
1153
	mov	eax, dword [esp]
1142
	call	mdio_write	; returns with window #4
1154
	call	mdio_write	; returns with window #4
1143
 
1155
 
1144
; wait for reset to complete
1156
; wait for reset to complete
1145
	mov	esi, 200
1157
	mov	esi, 2000
1146
	stdcall Sleep	   ; 2s
1158
	stdcall Sleep	   ; 2s
1147
	mov	eax, [esp]
1159
	mov	eax, [esp]
Line 1148... Line 1160...
1148
	call	mdio_read	; returns with window #4
1160
	call	mdio_read	; returns with window #4
1149
	test	ah , 0x80
1161
	test	ah , 0x80
1150
	jnz	.fail_finish
1162
	jnz	.fail1
1151
	mov	eax, [esp]
1163
	mov	eax, [esp]
1152
 
1164
 
1153
; wait for a while after reset
1165
; wait for a while after reset
1154
	mov	esi, 2
1166
	mov	esi, 20
1155
	stdcall Sleep	   ; 20ms
1167
	stdcall Sleep	   ; 20ms
Line 1156... Line 1168...
1156
	mov	eax, [esp]
1168
	mov	eax, [esp]
1157
	mov	al , REG_MII_BMSR
1169
	mov	al , REG_MII_BMSR
1158
	call	mdio_read	; returns with window #4
1170
	call	mdio_read	 ; returns with window #4
-
 
1171
	test	al , 1		 ; extended capability supported?
-
 
1172
	jz	.fail2
Line 1159... Line 1173...
1159
	test	al , 1		 ; extended capability supported?
1173
 
1160
	jz	.no_ext_cap
1174
; auto-neg capable?
1161
 
1175
	test	al , 1000b
Line -... Line 1176...
-
 
1176
	jz	.fail2		 ; not auto-negotiation capable
-
 
1177
 
1162
; auto-neg capable?
1178
	DEBUGF	1,"Device is auto-negotiation capable\n"
1163
	test	al , 1000b
1179
 
1164
	jz	.fail_finish	; not auto-negotiation capable
1180
; auto-neg complete?
1165
 
1181
	test	al , 100000b
1166
; auto-neg complete?
1182
	jnz	.auto_neg_ok
Line 1180... Line 1196...
1180
	call	mdio_read	; returns with window #4
1196
	call	mdio_read	; returns with window #4
1181
	mov	esi, eax
1197
	mov	esi, eax
1182
	or	bh , 10010b	; restart auto-negotiation
1198
	or	bh , 10010b	; restart auto-negotiation
1183
	mov	eax, [esp]
1199
	mov	eax, [esp]
1184
	call	mdio_write	; returns with window #4
1200
	call	mdio_write	; returns with window #4
1185
	mov	esi, 400
1201
	mov	esi, 4000
1186
	stdcall Sleep  ; 4 seconds
1202
	stdcall Sleep  ; 4 seconds
1187
	mov	eax, [esp]
1203
	mov	eax, [esp]
1188
	mov	al , REG_MII_BMSR
1204
	mov	al , REG_MII_BMSR
1189
	call	mdio_read ; returns with window #4
1205
	call	mdio_read ; returns with window #4
1190
	test	al , 100000b ; auto-neg complete?
1206
	test	al , 100000b ; auto-neg complete?
1191
	jnz	.auto_neg_ok
1207
	jnz	.auto_neg_ok
1192
	jmp	.fail_finish
1208
	jmp	.fail3
1193
.auto_neg_ok:
1209
  .auto_neg_ok:
Line -... Line 1210...
-
 
1210
 
-
 
1211
	DEBUGF	1,"Auto-negotiation complete\n"
1194
 
1212
 
1195
; compare advertisement and link partner ability registers
1213
; compare advertisement and link partner ability registers
1196
	mov	eax, [esp]
1214
	mov	eax, [esp]
1197
	mov	al , REG_MII_ANAR
1215
	mov	al , REG_MII_ANAR
1198
	call	mdio_read	; returns with window #4
1216
	call	mdio_read	; returns with window #4
Line 1219... Line 1237...
1219
	pop	esi
1237
	pop	esi
1220
	test	esi, 1010b shl 5; check for full-duplex
1238
	test	esi, 1010b shl 5; check for full-duplex
1221
	jz	.half_duplex
1239
	jz	.half_duplex
1222
	or	ax , 0x120	; set full duplex and flow control
1240
	or	ax , 0x120	; set full duplex and flow control
1223
.half_duplex:
1241
  .half_duplex:
-
 
1242
	DEBUGF 1,"Using half-duplex\n"
1224
	out	dx , ax
1243
	out	dx , ax
1225
	mov	al , 1
1244
	mov	al , 1
1226
	ret
1245
	ret
1227
.no_ext_cap:
-
 
Line -... Line 1246...
-
 
1246
 
-
 
1247
 
1228
 
1248
  .fail1:
-
 
1249
	DEBUGF	1,"reset failed!\n"
-
 
1250
	pop	eax
-
 
1251
	xor	al, al
-
 
1252
	ret
-
 
1253
 
-
 
1254
  .fail2:
-
 
1255
	DEBUGF	1,"This device is not auto-negotiation capable!\n"
-
 
1256
	pop	eax
-
 
1257
	xor	al, al
-
 
1258
	ret
1229
; not yet implemented BCM5000
1259
 
-
 
1260
  .fail3:
1230
.fail_finish:
1261
	DEBUGF	1,"auto-negotiation reset failed!\n"
1231
	pop	eax
1262
	pop	eax
1232
	xor	al, al
1263
	xor	al, al
Line 1253... Line 1284...
1253
;***************************************************************************
1284
;***************************************************************************
Line 1254... Line 1285...
1254
 
1285
 
1255
align 4
1286
align 4
Line 1256... Line 1287...
1256
try_mii:
1287
try_mii:
Line 1257... Line 1288...
1257
 
1288
 
1258
	DEBUGF 1,"trying mii\n"
1289
	DEBUGF	1,"trying to find MII PHY\n"
1259
 
1290
 
1260
; switch to register window 3
1291
; switch to register window 3
Line 1265... Line 1296...
1265
	set_io	REG_INTERNAL_CONFIG
1296
	set_io	REG_INTERNAL_CONFIG
1266
	in	eax, dx
1297
	in	eax, dx
1267
	and	eax, (1111b shl 20)
1298
	and	eax, (1111b shl 20)
1268
	cmp	eax, (1000b shl 20) ; is auto-negotiation set?
1299
	cmp	eax, (1000b shl 20) ; is auto-negotiation set?
1269
	jne	.mii_device
1300
	jne	.mii_device
-
 
1301
 
1270
; auto-negotiation is set
1302
	DEBUGF	1,"auto-negotiation is set\n"
1271
; switch to register window 4
1303
; switch to register window 4
1272
	set_io	REG_COMMAND
1304
	set_io	REG_COMMAND
1273
	mov	ax , SELECT_REGISTER_WINDOW+4
1305
	mov	ax , SELECT_REGISTER_WINDOW+4
1274
	out	dx , ax
1306
	out	dx , ax
-
 
1307
 
1275
; PHY==24 is the on-chip auto-negotiation logic
1308
; PHY==24 is the on-chip auto-negotiation logic
1276
; it supports only 10base-T and 100base-TX
1309
; it supports only 10base-T and 100base-TX
1277
	mov	ah , 24
1310
	mov	ah , 24
1278
	call	try_phy
1311
	call	try_phy
1279
	test	al , al
1312
	test	al , al
1280
	jz	.fail_finish
1313
	jz	.fail_finish
-
 
1314
 
1281
	mov	cl , 24
1315
	mov	cl , 24
1282
	jmp	.check_preamble
1316
	jmp	.check_preamble
-
 
1317
 
1283
.mii_device:
1318
  .mii_device:
1284
	cmp	eax, (0110b shl 20)
1319
	cmp	eax, (0110b shl 20)
1285
	jne	.fail_finish
1320
	jne	.fail_finish
-
 
1321
 
1286
	set_io	0
1322
	set_io	0
1287
	set_io	REG_COMMAND
1323
	set_io	REG_COMMAND
1288
	mov	ax , SELECT_REGISTER_WINDOW+4
1324
	mov	ax , SELECT_REGISTER_WINDOW+4
1289
	out	dx , ax
1325
	out	dx , ax
-
 
1326
 
1290
	set_io	REG_PHYSICAL_MGMT
1327
	set_io	REG_PHYSICAL_MGMT
1291
	in	ax , dx
1328
	in	ax , dx
1292
	and	al , (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_DATA)
1329
	and	al , (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_DATA)
1293
	cmp	al , (1 shl BIT_MGMT_DATA)
1330
	cmp	al , (1 shl BIT_MGMT_DATA)
1294
	je	.search_for_phy
1331
	je	.search_for_phy
-
 
1332
 
1295
	xor	al , al
1333
	xor	al , al
1296
	ret
1334
	ret
-
 
1335
 
1297
.search_for_phy:
1336
  .search_for_phy:
1298
; search for PHY
1337
; search for PHY
1299
	mov	cx , 31
1338
	mov	cx , 31
1300
.search_phy_loop:
1339
  .search_phy_loop:
-
 
1340
	DEBUGF	1,"Searching the PHY\n"
1301
	cmp	cx , 24
1341
	cmp	cx , 24
1302
	je	.next_phy
1342
	je	.next_phy
1303
	mov	ah , cl ; ah = phy
1343
	mov	ah , cl ; ah = phy
1304
	mov	al , REG_MII_BMCR ; al = Basic Mode Status Register
1344
	mov	al , REG_MII_BMCR ; al = Basic Mode Status Register
1305
	push	cx
1345
	push	cx
Line 1315... Line 1355...
1315
	pop	cx
1355
	pop	cx
1316
	test	al , al
1356
	test	al , al
1317
	jnz	.check_preamble
1357
	jnz	.check_preamble
1318
.next_phy:
1358
  .next_phy:
1319
	loopw	.search_phy_loop
1359
	loopw	.search_phy_loop
-
 
1360
 
1320
.fail_finish:
1361
  .fail_finish:
1321
	xor	al, al
1362
	xor	al, al
1322
	ret
1363
	ret
-
 
1364
 
1323
; epilog
1365
; epilog
1324
.check_preamble:
1366
  .check_preamble:
-
 
1367
	DEBUGF	1,"Using PHY: %u\nChecking PreAmble\n", cl
1325
	push	eax ; eax contains the return value of try_phy
1368
	push	eax ; eax contains the return value of try_phy
1326
; check hard coded preamble forcing
1369
; check hard coded preamble forcing
1327
	movzx	eax, [device.ver_id]
1370
	movzx	eax, [device.ver_id]
1328
	test	word [eax*4+hw_versions+2], EXTRA_PREAMBLE
1371
	test	word [eax*4+hw_versions+2], EXTRA_PREAMBLE
1329
	setnz	[device.preamble] ; force preamble
1372
	setnz	[device.preamble] ; force preamble
1330
	jnz	.finish
1373
	jnz	.finish
-
 
1374
 
1331
; check mii for preamble suppression
1375
; check mii for preamble suppression
1332
	mov	ah, cl
1376
	mov	ah, cl
1333
	mov	al, REG_MII_BMSR
1377
	mov	al, REG_MII_BMSR
1334
	call	mdio_read
1378
	call	mdio_read
1335
	test	al, 1000000b ; preamble suppression?
1379
	test	al, 1000000b ; preamble suppression?
1336
	setz	[device.preamble] ; no
1380
	setz	[device.preamble] ; no
-
 
1381
 
1337
.finish:
1382
  .finish:
1338
	pop	eax
1383
	pop	eax
1339
	ret
1384
	ret
Line 1382... Line 1427...
1382
 
1427
 
1383
; issue RxEnable and TxEnable
1428
; issue RxEnable and TxEnable
1384
	call	rx_reset
1429
	call	rx_reset
Line 1385... Line 1430...
1385
	call	tx_reset
1430
	call	tx_reset
-
 
1431
 
-
 
1432
; create self-directed packet
-
 
1433
	stdcall KernelAlloc, 20 ; create a buffer for the self-directed packet
-
 
1434
	test	eax, eax
-
 
1435
	jz	.fail
-
 
1436
 
-
 
1437
	pushd	20		; Packet parameters for device.transmit
-
 
1438
	push	eax		;
1386
 
1439
 
1387
; download a self-directed test packet
-
 
1388
	lea	esi, [device.mac]
1440
	mov	edi, eax
1389
	lea	edi, [device.self_directed_packet]
1441
	lea	esi, [device.mac]
1390
	movsw
1442
	movsw
1391
	movsd
1443
	movsd
1392
	sub	esi, 6
1444
	sub	esi, 6
1393
	movsw
1445
	movsw
1394
	movsd
1446
	movsd
Line 1395... Line -...
1395
	mov	ax , 0x0608
-
 
1396
	stosw
1447
	mov	ax , 0x0608
1397
 
-
 
1398
	push	20
1448
	stosw
Line 1399... Line 1449...
1399
	lea	eax, [device.self_directed_packet]
1449
 
1400
	push	eax
1450
; download self-directed packet
1401
	call	[device.transmit]
1451
	call	[device.transmit]
Line 1402... Line 1452...
1402
 
1452
 
1403
; wait for 2s
1453
; wait for 2s
1404
	mov	esi, 200
1454
	mov	esi, 2000
1405
	stdcall Sleep	 ; 2s
1455
	call	Sleep
Line 1418... Line 1468...
1418
; clear fullDuplexEnable in MacControl register
1468
; clear fullDuplexEnable in MacControl register
1419
	set_io	REG_MAC_CONTROL
1469
	set_io	REG_MAC_CONTROL
1420
	in	ax , dx
1470
	in	ax , dx
1421
	and	ax , not 0x120
1471
	and	ax , not 0x120
1422
	out	dx , ax
1472
	out	dx , ax
-
 
1473
  .fail:
1423
	xor	eax, eax
1474
	xor	eax, eax
Line 1424... Line 1475...
1424
 
1475
 
1425
.finish:
1476
  .finish:
Line 1466... Line 1517...
1466
	jz	.complete_loopback
1517
	jz	.complete_loopback
1467
; enable 100BASE-2 DC-DC converter
1518
; enable 100BASE-2 DC-DC converter
1468
	mov	ax, (10b shl 11) ; EnableDcConverter
1519
	mov	ax, (10b shl 11) ; EnableDcConverter
1469
	out	dx, ax
1520
	out	dx, ax
1470
.complete_loopback:
1521
  .complete_loopback:
-
 
1522
 
1471
	mov	cx, 2 ; give a port 3 chances to complete a loopback
1523
	mov	cx, 2 ; give a port 3 chances to complete a loopback
1472
.next_try:
1524
  .next_try:
1473
	push	ecx
1525
	push	ecx
1474
	call	test_packet
1526
	call	test_packet
1475
	pop	ecx
1527
	pop	ecx
1476
	test	eax, eax
1528
	test	eax, eax
1477
	loopzw	.next_try
1529
	loopzw	.next_try
-
 
1530
 
1478
.finish:
1531
  .finish:
1479
	xchg	eax, [esp]
1532
	xchg	eax, [esp]
1480
	test	al, al
1533
	test	al, al
1481
	jz	.aui_finish
1534
	jz	.aui_finish
-
 
1535
 
1482
; issue DisableDcConverter command
1536
; issue DisableDcConverter command
1483
	set_io	0
1537
	set_io	0
1484
	set_io	REG_COMMAND
1538
	set_io	REG_COMMAND
1485
	mov	ax, (10111b shl 11)
1539
	mov	ax, (10111b shl 11)
1486
	out	dx, ax
1540
	out	dx, ax
Line 1507... Line 1561...
1507
;***************************************************************************
1561
;***************************************************************************
Line 1508... Line 1562...
1508
 
1562
 
1509
align 4
1563
align 4
Line 1510... Line 1564...
1510
set_active_port:
1564
set_active_port:
Line 1511... Line 1565...
1511
 
1565
 
1512
	DEBUGF 1,"Setting active port: "
1566
	DEBUGF 1,"Trying to find the active port\n"
1513
 
1567
 
1514
; switch to register window 3
1568
; switch to register window 3
1515
	set_io	0
1569
	set_io	0
-
 
1570
	set_io	REG_COMMAND
1516
	set_io	REG_COMMAND
1571
	mov	ax, SELECT_REGISTER_WINDOW + 3
1517
	mov	ax, SELECT_REGISTER_WINDOW+3
1572
	out	dx, ax
1518
	out	dx, ax
1573
 
1519
	set_io	REG_INTERNAL_CONFIG
1574
	set_io	REG_INTERNAL_CONFIG
Line 1536... Line 1591...
1536
	call	try_mii
1591
	call	try_mii
1537
	test	al, al
1592
	test	al, al
1538
	jz	.mii_device
1593
	jz	.mii_device
1539
	DEBUGF 1,"Using auto negotiation\n"
1594
	DEBUGF 1,"Using auto negotiation\n"
1540
	ret
1595
	ret
1541
.mii_device:
-
 
Line -... Line 1596...
-
 
1596
 
1542
 
1597
  .mii_device:
1543
; switch to register window 3
1598
; switch to register window 3
1544
	set_io	0
-
 
1545
	set_io	REG_COMMAND
-
 
1546
	mov	ax, SELECT_REGISTER_WINDOW+3
-
 
1547
	out	dx, ax
-
 
1548
 
1599
	set_io	0
1549
; check for off-chip mii device
1600
; check for off-chip mii device
1550
	set_io	REG_MEDIA_OPTIONS
1601
	set_io	REG_MEDIA_OPTIONS
1551
	in	ax, dx
1602
	in	ax, dx
1552
	test	al, 1000000b ; check miiDevice
1603
	test	al, 1000000b ; check miiDevice
Line 1559... Line 1610...
1559
	call	try_mii
1610
	call	try_mii
1560
	test	al, al
1611
	test	al, al
1561
	jz	.base_fx
1612
	jz	.base_fx
1562
	DEBUGF 1,"Using off-chip mii device\n"
1613
	DEBUGF 1,"Using off-chip mii device\n"
1563
	ret
1614
	ret
1564
.base_fx:
-
 
Line -... Line 1615...
-
 
1615
 
1565
 
1616
  .base_fx:
1566
; switch to register window 3
1617
; switch to register window 3
1567
	set_io	0
-
 
1568
	set_io	REG_COMMAND
-
 
1569
	mov	ax, SELECT_REGISTER_WINDOW+3
-
 
1570
	out	dx, ax
1618
	set_io	0
1571
; check for 100BASE-FX
1619
; check for 100BASE-FX
1572
	set_io	REG_MEDIA_OPTIONS
1620
	set_io	REG_MEDIA_OPTIONS
1573
	in	ax, dx ; read media option register
1621
	in	ax, dx ; read media option register
1574
	test	al, 100b ; check 100BASE-FX
1622
	test	al, 100b ; check 100BASE-FX
Line 1581... Line 1629...
1581
	call	try_link_detect
1629
	call	try_link_detect
1582
	test	al, al
1630
	test	al, al
1583
	jz	.aui_enable
1631
	jz	.aui_enable
1584
	DEBUGF 1,"Using 100Base-FX\n"
1632
	DEBUGF 1,"Using 100Base-FX\n"
1585
	ret
1633
	ret
1586
.aui_enable:
-
 
Line -... Line 1634...
-
 
1634
 
1587
 
1635
  .aui_enable:
1588
; switch to register window 3
1636
; switch to register window 3
1589
	set_io	0
-
 
1590
	set_io	REG_COMMAND
-
 
1591
	mov	ax, SELECT_REGISTER_WINDOW+3
-
 
1592
	out	dx, ax
1637
	set_io	0
1593
; check for 10Mbps AUI connector
1638
; check for 10Mbps AUI connector
1594
	set_io	REG_MEDIA_OPTIONS
1639
	set_io	REG_MEDIA_OPTIONS
1595
	in	ax, dx ; read media option register
1640
	in	ax, dx ; read media option register
1596
	test	al, 100000b ; check 10Mbps AUI connector
1641
	test	al, 100000b ; check 10Mbps AUI connector
Line 1604... Line 1649...
1604
	call	try_loopback
1649
	call	try_loopback
1605
	test	al, al
1650
	test	al, al
1606
	jz	.coax_available
1651
	jz	.coax_available
1607
	DEBUGF 1,"Using 10Mbps aui\n"
1652
	DEBUGF 1,"Using 10Mbps aui\n"
1608
	ret
1653
	ret
1609
.coax_available:
-
 
Line -... Line 1654...
-
 
1654
 
1610
 
1655
  .coax_available:
1611
; switch to register window 3
1656
; switch to register window 3
1612
	set_io	0
-
 
1613
	set_io	REG_COMMAND
-
 
1614
	mov	ax, SELECT_REGISTER_WINDOW+3
-
 
1615
	out	dx, ax
1657
	set_io	0
1616
; check for coaxial 10BASE-2 port
1658
; check for coaxial 10BASE-2 port
1617
	set_io	REG_MEDIA_OPTIONS
1659
	set_io	REG_MEDIA_OPTIONS
1618
	in	ax, dx ; read media option register
1660
	in	ax, dx ; read media option register
1619
	test	al, 10000b ; check 10BASE-2
1661
	test	al, 10000b ; check 10BASE-2
-
 
1662
	jz	.set_first_available_media
1620
	jz	.set_first_available_media
1663
 
1621
	set_io	REG_INTERNAL_CONFIG
1664
	set_io	REG_INTERNAL_CONFIG
1622
	in	eax, dx
1665
	in	eax, dx
1623
	and	eax, not (1111b shl 20)
1666
	and	eax, not (1111b shl 20)
1624
	or	eax, (0011b shl 20) ; set 10BASE-2
1667
	or	eax, (0011b shl 20) ; set 10BASE-2
Line 1627... Line 1670...
1627
	call	try_loopback
1670
	call	try_loopback
1628
	test	al, al
1671
	test	al, al
1629
	jz	.set_first_available_media
1672
	jz	.set_first_available_media
1630
	DEBUGF 1,"Using 10BASE-2 port\n"
1673
	DEBUGF 1,"Using 10BASE-2 port\n"
1631
	ret
1674
	ret
1632
.set_first_available_media:
-
 
Line -... Line 1675...
-
 
1675
 
-
 
1676
  .set_first_available_media:
Line 1633... Line 1677...
1633
 
1677
	DEBUGF	1,"Using the first available media\n"
1634
 
1678
 
1635
;***************************************************************************
1679
;***************************************************************************
1636
;   Function
1680
;   Function
1637
;      set_available_media
1681
;      set_available_media
1638
;   Description
1682
;   Description
1639
;      sets the first available media
1683
;      sets the first available media
1640
;   Parameters
1684
;   Parameters
1641
;      ebp - io_addr
1685
;      ebx - ptr to device struct
1642
;   Return value
1686
;   Return value
1643
;      al - 0
1687
;      al - 0
1644
;      al - 1
1688
;      al - 1
Line 1648... Line 1692...
1648
;***************************************************************************
1692
;***************************************************************************
Line 1649... Line 1693...
1649
 
1693
 
1650
align 4
1694
align 4
Line 1651... Line 1695...
1651
set_available_media:
1695
set_available_media:
1652
 
-
 
1653
	DEBUGF 1,"Using the first available media\n"
1696
 
1654
 
1697
	DEBUGF	1,"Setting the available media\n"
1655
; switch to register window 3
1698
; switch to register window 3
1656
	set_io	0
1699
	set_io	0
1657
	set_io	REG_COMMAND
1700
	set_io	REG_COMMAND
1658
	mov	ax, SELECT_REGISTER_WINDOW+3
-
 
1659
	out	dx, ax
-
 
1660
	set_io	REG_INTERNAL_CONFIG
1701
	mov	ax, SELECT_REGISTER_WINDOW+3
1661
	in	eax, dx
1702
	out	dx, ax
1662
	push	eax
1703
 
-
 
1704
	set_io	REG_MEDIA_OPTIONS
1663
	set_io	REG_MEDIA_OPTIONS
1705
	in	ax, dx
-
 
1706
	DEBUGF	1,"available media:%x\n", al
-
 
1707
	mov	cl, al
-
 
1708
 
-
 
1709
	set_io	REG_INTERNAL_CONFIG
-
 
1710
	in	eax, dx
-
 
1711
	and	eax, not (1111b shl 20) ; these bits hold the 'transceiver select' value
1664
	in	ax, dx
1712
 
1665
	test	al, 10b
-
 
1666
	jz	@f
1713
	test	cl, 10b 	; baseTXAvailable
1667
; baseTXAvailable
1714
	jz	@f
1668
	pop	eax
1715
 
1669
	and	eax, not (1111b shl 20)
1716
	DEBUGF	1,"base TX is available\n"
1670
	or	eax, (100b shl 20)
1717
	or	eax, (100b shl 20)
1671
if defined FORCE_FD
1718
if defined FORCE_FD
1672
	mov	word [device.mode], (1 shl 8)
1719
	mov	word [device.mode], (1 shl 8)
1673
else
1720
else
1674
	mov	word [device.mode], (1 shl 7)
1721
	mov	word [device.mode], (1 shl 7)
1675
end if
1722
end if
-
 
1723
	jmp	.set_media
1676
	jmp	.set_media
1724
       @@:
1677
@@:
1725
 
1678
	test	al, 100b
-
 
1679
	jz	@f
-
 
1680
; baseFXAvailable
-
 
1681
	pop	eax
-
 
Line -... Line 1726...
-
 
1726
	test	cl, 100b	; baseFXAvailable
-
 
1727
	jz	@f
1682
	and	eax, not (1111b shl 20)
1728
 
1683
	or	eax, (101b shl 20)
-
 
1684
 
1729
	DEBUGF	1,"base FX is available\n"
1685
	mov	word [device.mode], (1 shl 10)
1730
	or	eax, (101b shl 20)
-
 
1731
	mov	word [device.mode], (1 shl 10)
1686
 
1732
	jmp	.set_media
1687
	jmp	.set_media
1733
       @@:
1688
@@:
-
 
1689
	test	al, 1000000b
-
 
1690
	jz	@f
-
 
1691
; miiDevice
-
 
Line -... Line 1734...
-
 
1734
 
-
 
1735
	test	cl, 1000000b	; miiDevice
1692
	pop	eax
1736
	jz	@f
1693
	and	eax, not (1111b shl 20)
-
 
1694
	or	eax, (0110b shl 20)
1737
 
1695
 
1738
	DEBUGF	1,"mii-device is available\n"
-
 
1739
	or	eax, (0110b shl 20)
1696
	mov	word [device.mode], (1 shl 13)
1740
	mov	word [device.mode], (1 shl 13)
1697
 
1741
	jmp	.set_media
-
 
1742
       @@:
-
 
1743
 
1698
	jmp	.set_media
1744
	test	cl, 1000b	; 10bTAvailable
1699
@@:
-
 
1700
	test	al, 1000b
-
 
1701
	jz	@f
-
 
1702
.set_default:
1745
	jz	@f
1703
; 10bTAvailable
1746
 
1704
	pop	eax
1747
	DEBUGF	1,"10base-T is available\n"
1705
	and	eax, not (1111b shl 20)
1748
  .set_default:
1706
if FORCE_FD
1749
if FORCE_FD
1707
	mov	word [device.mode], (1 shl 6)
1750
	mov	word [device.mode], (1 shl 6)
1708
else
1751
else
-
 
1752
	mov	word [device.mode], (1 shl 5)
1709
	mov	word [device.mode], (1 shl 5)
1753
end if
1710
end if ; FORCE_FD
1754
	jmp	.set_media
-
 
1755
       @@:
1711
	jmp	.set_media
1756
 
-
 
1757
	test	cl, 10000b	; coaxAvailable
1712
@@:
1758
	jz	@f
1713
	test	al, 10000b
1759
 
1714
	jz	@f
1760
	DEBUGF	1,"coax is available\n"
1715
; coaxAvailable
1761
	push	eax
1716
	set_io	REG_COMMAND
-
 
1717
	mov	ax, (10b shl 11) ; EnableDcConverter
-
 
Line -... Line 1762...
-
 
1762
	set_io	REG_COMMAND
1718
	out	dx, ax
1763
	mov	ax, (10b shl 11) ; EnableDcConverter
1719
	pop	eax
-
 
1720
	and	eax, not (1111b shl 20)
1764
	out	dx, ax
1721
	or	eax, (11b shl 20)
1765
	pop	eax
-
 
1766
 
1722
 
1767
	or	eax, (11b shl 20)
1723
	mov	word [device.mode], (1 shl 12)
1768
	mov	word [device.mode], (1 shl 12)
1724
 
-
 
1725
	jmp	.set_media
-
 
1726
@@:
-
 
1727
	test	al, 10000b
-
 
Line -... Line 1769...
-
 
1769
	jmp	.set_media
-
 
1770
       @@:
1728
	jz	.set_default
1771
 
Line 1729... Line 1772...
1729
; auiAvailable
1772
	test	cl, 10000b	; auiAvailable
-
 
1773
	jz	.set_default
1730
	pop	eax
1774
 
1731
	and	eax, not (1111b shl 20)
1775
	DEBUGF	1,"AUI is available\n"
-
 
1776
	or	eax, (1 shl 20)
1732
	or	eax, (1 shl 20)
1777
	mov	word [device.mode], (1 shl 11)
1733
 
1778
 
1734
	mov	word [device.mode], (1 shl 11)
1779
  .set_media:
1735
 
1780
	set_io	0
1736
.set_media:
1781
	set_io	REG_INTERNAL_CONFIG
1737
	set_io	REG_INTERNAL_CONFIG
1782
	out	dx, eax
1738
	out	dx, eax
1783
 
1739
if FORCE_FD
-
 
Line -... Line 1784...
-
 
1784
if FORCE_FD
1740
; set fullDuplexEnable in MacControl register
1785
	DEBUGF	1,"Forcing full duplex\n"
Line 1741... Line 1786...
1741
	set_io	REG_MAC_CONTROL
1786
	set_io	REG_MAC_CONTROL
Line 1769... Line 1814...
1769
	stdcall PciRead32, ecx, edx, PCI_REG_STATUS
1814
	stdcall PciRead32, ecx, edx, PCI_REG_STATUS
Line 1770... Line 1815...
1770
 
1815
 
1771
	test	al, 10000b	; is there "new capabilities" linked list?
1816
	test	al, 10000b	; is there "new capabilities" linked list?
Line 1772... Line -...
1772
	jz	.device_awake
-
 
1773
 
-
 
1774
	DEBUGF 1,"1 "
1817
	jz	.device_awake
1775
 
1818
 
1776
; search for power management register
1819
; search for power management register
1777
	stdcall PciRead16, ecx, edx, PCI_REG_CAP_PTR
1820
	stdcall PciRead16, ecx, edx, PCI_REG_CAP_PTR
Line 1778... Line -...
1778
	cmp	al, 0x3f
-
 
1779
	jbe	.device_awake
-
 
1780
 
1821
	cmp	al, 0x3f
1781
	DEBUGF 1,"2 "
1822
	jbe	.device_awake
1782
 
1823
 
1783
; traverse the list
1824
; traverse the list
Line 1795... Line 1836...
1795
	jmp	.device_awake
1836
	jmp	.device_awake
Line 1796... Line 1837...
1796
 
1837
 
1797
; waku up the device if necessary
1838
; waku up the device if necessary
Line 1798... Line -...
1798
.set_pm_state:
-
 
1799
 
-
 
1800
	DEBUGF 1,"3 "
1839
  .set_pm_state:
1801
 
1840
 
1802
	add	esi, PCI_REG_PM_CTRL
1841
	add	esi, PCI_REG_PM_CTRL
1803
	stdcall PciRead32, ecx, edx, esi
1842
	stdcall PciRead32, ecx, edx, esi
1804
	test	al, 3
1843
	test	al, 3
1805
	jz	.device_awake
1844
	jz	.device_awake
1806
	and	al, not 11b ; set state to D0
-
 
Line -... Line 1845...
-
 
1845
	and	al, not 11b ; set state to D0
1807
	stdcall PciWrite32, ecx, edx, esi, eax
1846
	stdcall PciWrite32, ecx, edx, esi, eax
Line 1808... Line 1847...
1808
.device_awake:
1847
 
Line 1893... Line 1932...
1893
;       pop     eax
1932
;       pop     eax
1894
;       or      ax, 01b shl 6
1933
;       or      ax, 01b shl 6
1895
;       out     dx, ax
1934
;       out     dx, ax
1896
;.finish:
1935
;.finish:
1897
;       ret
1936
;       ret
-
 
1937
 
-
 
1938
 
1898
;***************************************************************************
1939
;***************************************************************************
1899
;   Function
1940
;   Function
1900
;      read_eeprom
1941
;      read_eeprom
1901
;   Description
1942
;   Description
1902
;      reads eeprom
1943
;      reads eeprom
Line 1904... Line 1945...
1904
;       ax - register to be read (only the first 63 words can be read)
1945
;       ax - register to be read (only the first 63 words can be read)
1905
;      ebx = driver structure
1946
;      ebx = driver structure
1906
;   Return value:
1947
;   Return value:
1907
;      ax - word read
1948
;      ax - word read
1908
;   Destroyed registers
1949
;   Destroyed registers
1909
;      ax, ebx, edx, ebp
1950
;      ax, ebx, edx
1910
;
1951
;
1911
;***************************************************************************
1952
;***************************************************************************
Line 1912... Line 1953...
1912
 
1953
 
1913
align 4
1954
align 4
Line 1914... Line 1955...
1914
read_eeprom:
1955
read_eeprom:
Line 1915... Line 1956...
1915
 
1956
 
1916
	DEBUGF 1,"Reading from eeprom:\n"
1957
	DEBUGF 1,"Reading from eeprom.. "
1917
 
1958
 
1918
	push	eax
1959
	push	eax
Line 2009... Line 2050...
2009
;***************************************************************************
2050
;***************************************************************************
Line 2010... Line 2051...
2010
 
2051
 
2011
align 4
2052
align 4
Line 2012... Line 2053...
2012
mdio_read:
2053
mdio_read:
Line 2013... Line 2054...
2013
 
2054
 
2014
	DEBUGF 1,"reading MII registers\n"
2055
	DEBUGF 1,"Reading MII registers\n"
2015
 
2056
 
2016
	push	eax
2057
	push	eax
Line 2097... Line 2138...
2097
	or	eax, 10b ; transition bits
2138
	or	eax, 10b ; transition bits
2098
	shl	eax, 16
2139
	shl	eax, 16
2099
	mov	ax, si
2140
	mov	ax, si
2100
	mov	esi, eax
2141
	mov	esi, eax
2101
	mov	ecx, 31
2142
	mov	ecx, 31
-
 
2143
 
2102
.cmd_loop:
2144
  .cmd_loop:
2103
	mov	ax, (1 shl BIT_MGMT_DIR) ; write mii
2145
	mov	ax, (1 shl BIT_MGMT_DIR) ; write mii
2104
	bt	esi, ecx
2146
	bt	esi, ecx
2105
	jnc	.zero_bit
2147
	jnc	@f
2106
	or	al, (1 shl BIT_MGMT_DATA)
2148
	or	al, (1 shl BIT_MGMT_DATA)
2107
.zero_bit:
2149
       @@:
2108
	out	dx, ax
2150
	out	dx, ax
2109
	push	eax
2151
	push	eax
2110
	in	ax, dx ; delay
2152
	in	ax, dx ; delay
2111
	pop	eax
2153
	pop	eax
2112
	or	al, (1 shl BIT_MGMT_CLK) ; write
2154
	or	al, (1 shl BIT_MGMT_CLK) ; write
Line 2137... Line 2179...
2137
 
2179
 
2138
; clear TxStatus queue
2180
; clear TxStatus queue
2139
	set_io	0
2181
	set_io	0
2140
	set_io	REG_TX_STATUS
2182
	set_io	REG_TX_STATUS
-
 
2183
	mov	ecx, 31 ; max number of queue entries
2141
	mov	ecx, 31 ; max number of queue entries
2184
 
2142
.tx_status_loop:
2185
  .tx_status_loop:
2143
	in	al, dx
2186
	in	al, dx
2144
	test	al, al
2187
	test	al, al
2145
	jz	.finish ; no error
2188
	jz	.finish ; no error
Line 2148... Line 2191...
2148
.no_error_found:
2191
  .no_error_found:
2149
; clear current TxStatus entry which advances the next one
2192
; clear current TxStatus entry which advances the next one
2150
	xor	al, al
2193
	xor	al, al
2151
	out	dx, al
2194
	out	dx, al
2152
	loop	.tx_status_loop
2195
	loop	.tx_status_loop
-
 
2196
 
2153
.finish:
2197
  .finish:
Line 2154... Line 2198...
2154
 
2198
 
Line 2355... Line 2399...
2355
 
2399
 
2356
 
2400
 
Line 2357... Line -...
2357
;---------------------------------
-
 
2358
; Write MAC
2401
;---------------------------------
2359
 
2402
; Write MAC
Line 2360... Line 2403...
2360
 
2403
 
Line 2361... Line 2404...
2361
align 4
2404
align 4
2362
write_mac:   ; Tested - ok
2405
write_mac:
Line 2379... Line 2422...
2379
	outsw
2422
	outsw
2380
	inc	dx
2423
	inc	dx
2381
	inc	dx
2424
	inc	dx
2382
	outsw
2425
	outsw
Line -... Line 2426...
-
 
2426
 
2383
 
2427
 
2384
;----------------------------
2428
;----------------------------
Line 2385... Line -...
2385
; Read MAC
-
 
2386
 
2429
; Read MAC
2387
 
2430
 
2388
align 4
-
 
2389
read_mac:    ; Tested - ok
-
 
Line 2390... Line 2431...
2390
 
2431
align 4
2391
 
2432
read_mac:
Line 2392... Line 2433...
2392
 
2433
 
Line 2414... Line 2455...
2414
 
2455
 
2415
 
2456
 
Line 2416... Line -...
2416
;------------------------------------
-
 
2417
; Read MAC from eeprom
2457
;------------------------------------
2418
 
2458
; Read MAC from eeprom
Line 2419... Line 2459...
2419
 
2459
 
Line 2429... Line 2469...
2429
	push	ecx
2469
	push	ecx
2430
	call	read_eeprom
2470
	call	read_eeprom
2431
	pop	ecx
2471
	pop	ecx
2432
	xchg	ah, al ; htons
2472
	xchg	ah, al ; htons
2433
	mov	word [device.mac+ecx*2-2], ax
2473
	mov	word [device.mac+ecx*2-2], ax
2434
 
-
 
2435
	loop	.mac_loop
2474
	loop	.mac_loop
Line 2436... Line 2475...
2436
 
2475
 
Line 2437... Line 2476...
2437
	DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2
2476
	DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2
Line 2552... Line 2591...
2552
	out	dx, ax
2591
	out	dx, ax
Line 2553... Line 2592...
2553
 
2592
 
2554
; check for master operation in progress
2593
; check for master operation in progress
2555
	set_io	REG_MASTER_STATUS   ; TODO: use timeout and reset after timeout expired
2594
	set_io	REG_MASTER_STATUS   ; TODO: use timeout and reset after timeout expired
2556
  .dma_loop:
-
 
2557
	xor	esi, esi
-
 
2558
	stdcall Sleep
2595
  .dma_loop:
2559
	in	ax, dx
2596
	in	ax, dx
2560
	test	ah, 0x80
2597
	test	ah, 0x80
Line 2561... Line 2598...
2561
	jnz	.dma_loop
2598
	jnz	.dma_loop