Subversion Repositories Kolibri OS

Rev

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

Rev 1177 Rev 1178
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;; ne2000 driver for KolibriOS                                     ;;
6
;; RTL8029/ne2000 driver for KolibriOS                             ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
-
 
9
;;     with help from CleverMouse                                  ;;
9
;;                                                                 ;;
10
;;                                                                 ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
12
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
13
;;                                                                 ;;
13
;; current status (september 2009) - INCOMPLETE                    ;;
14
;; current status (september 2009) - UNSTABLE                      ;;
-
 
15
;;                                                                 ;;
-
 
16
;; based on RTL8029.asm driver for menuetos                        ;;
-
 
17
;; and realtek8029.asm for SolarOS by Eugen Brasoveanu             ;;
14
;;                                                                 ;;
18
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 20...
16
 
20
 
Line 296... Line 300...
296
	mov	[ebx+device.pci_bus], cl       ;
300
	mov	[ebx+device.pci_bus], cl       ;
297
	mov	[ebx+device.pci_dev], ch       ;
301
	mov	[ebx+device.pci_dev], ch       ;
Line 298... Line 302...
298
 
302
 
299
	mov	edx, PCI_BASE_ADDRESS_0        ; find the base io address
303
	mov	edx, PCI_BASE_ADDRESS_0        ; find the base io address
300
  .sb_reg_check:
304
  .sb_reg_check:
301
  ;
305
 
302
	movzx	eax, byte [ebx+device.pci_bus] ;
306
	movzx	eax, byte [ebx+device.pci_bus] ;
303
	movzx	ecx, byte [ebx+device.pci_dev] ;
307
	movzx	ecx, byte [ebx+device.pci_dev] ;
304
					       ;
308
					       ;
305
	push	edx ecx
309
	push	edx ecx
Line 413... Line 417...
413
	mov	dword [ebx+device.reset], reset
417
	mov	dword [ebx+device.reset], reset
414
	mov	dword [ebx+device.transmit], transmit
418
	mov	dword [ebx+device.transmit], transmit
415
	mov	dword [ebx+device.get_MAC], read_mac
419
	mov	dword [ebx+device.get_MAC], read_mac
416
	mov	dword [ebx+device.set_MAC], write_mac
420
	mov	dword [ebx+device.set_MAC], write_mac
417
	mov	dword [ebx+device.unload], unload
421
	mov	dword [ebx+device.unload], unload
-
 
422
	mov	dword [ebx+device.name], my_service
Line 418... Line 423...
418
 
423
 
Line 419... Line 424...
419
	ret
424
	ret
420
 
425
 
Line 583... Line 588...
583
	je	reset
588
	je	reset
Line 584... Line 589...
584
 
589
 
585
	mov	eax, [ebp + device.bmem]
590
	mov	eax, [ebp + device.bmem]
Line 586... Line 591...
586
	mov	[ebp + device.rmem], eax
591
	mov	[ebp + device.rmem], eax
587
 
592
 
588
	;-- hack
593
	;-- hack (read mac from eeprom ant write it to hardware's register)
Line 589... Line -...
589
	mov	ebx, ebp
-
 
590
	call	read_mac
594
	mov	ebx, ebp
591
 
595
	call	read_mac
592
 
596
 
593
	push	.hack
597
	push	.hack
594
	sub	esp, 6
598
	sub	esp, 6
595
	mov	edi, esp
599
	mov	edi, esp
596
	lea	esi, [ebp + device.mac]
-
 
597
	movsd
600
	lea	esi, [ebp + device.mac]
598
	movsw
601
	movsd
599
 
602
	movsw
Line 611... Line 614...
611
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
614
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 612... Line 615...
612
 
615
 
613
reset:
616
reset:
Line 614... Line -...
614
	mov	ebp, ebx	;---
-
 
615
 
617
	mov	ebp, ebx	;---
Line 616... Line 618...
616
 
618
 
617
	DEBUGF	2,"Resetting rtl8029\n"
619
	DEBUGF	2,"Resetting device\n"
618
 
620
 
619
; attach int handler
621
; attach int handler
Line 732... Line 734...
732
; clear transmit control register
734
; clear transmit control register
733
	set_io	P0_TCR
735
	set_io	P0_TCR
734
	mov	al, 0		; no loopback
736
	mov	al, 0		; no loopback
735
	out	dx, al
737
	out	dx, al
Line -... Line 738...
-
 
738
 
-
 
739
; clear packet/byte counters
-
 
740
 
-
 
741
	lea	edi, [ebp+device.bytes_tx]
-
 
742
	mov	ecx, 6
-
 
743
	rep	stosd
Line 736... Line 744...
736
 
744
 
737
 
745
 
738
; Indicate that we have successfully reset the card
746
; Indicate that we have successfully reset the card
Line 790... Line 798...
790
	set_io	0
798
	set_io	0
791
	mov	al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA
799
	mov	al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA
792
	out	dx, al
800
	out	dx, al
Line 793... Line 801...
793
 
801
 
-
 
802
	DEBUGF	2," - Packet Sent!\n"
-
 
803
 
-
 
804
	inc	[ebp+device.packets_tx] 	 ;
-
 
805
	mov	eax, [esp+4]			 ; Get packet size in eax
-
 
806
 
-
 
807
	add	dword [ebp + device.bytes_tx], eax
794
	DEBUGF	2," - Packet Sent!\n"
808
	adc	dword [ebp + device.bytes_tx + 4], 0
795
.finish:
809
.finish:
Line 796... Line 810...
796
	mov	ebx, ebp
810
	mov	ebx, ebp
797
 
811
 
Line 816... Line 830...
816
	mov	esi, ne2000_LIST
830
	mov	esi, ne2000_LIST
817
	mov	ecx, [ne2000_DEV]
831
	mov	ecx, [ne2000_DEV]
818
.nextdevice:
832
.nextdevice:
819
	mov	ebp, dword [esi]
833
	mov	ebp, dword [esi]
Line 820... Line 834...
820
 
834
 
821
	set_io	0		; We chould check ISR instead..
835
	set_io	0
822
	set_io	P0_ISR
836
	set_io	P0_ISR
Line 823... Line 837...
823
	in	al, dx
837
	in	al, dx
Line 824... Line 838...
824
 
838
 
825
	DEBUGF	2,"isr %x ",eax:2
839
	DEBUGF	2,"isr %x ",eax:2
Line 826... Line 840...
826
 
840
 
Line 827... Line 841...
827
	test	al, ISR_PRX
841
	test	al, ISR_PRX    ; packet received ok ?
828
	jnz	.rx
842
	jnz	.rx
Line -... Line 843...
-
 
843
 
-
 
844
	add	esi, 4
829
 
845
 
830
	add	esi, 4
846
	loop	.nextdevice
-
 
847
	ret
-
 
848
 
-
 
849
 
Line -... Line 850...
-
 
850
 
-
 
851
; looks like we've found a device wich received a packet..
Line 831... Line 852...
831
 
852
.rx:
Line 832... Line 853...
832
	loop	.nextdevice
853
	stdcall KernelAlloc, ETH_FRAME_LEN  ; size doesnt really matter as packet size is smaller then kernel's page size
833
	ret
854
	test	eax, eax
834
 
855
	jz	.fail_2
835
; looks like we've found it!
856
 
836
.rx:
857
;--------------------------------------
Line -... Line 858...
-
 
858
; allocate memory for temp variables in stack
-
 
859
 
837
 
860
	sub	esp, 14+8
838
 
861
 
Line 839... Line 862...
839
	sub	esp, 14+8			  ; allocate memory for temp variables in stack
862
	eth_type	equ esp
-
 
863
	pkthdr		equ esp + 2
840
 
864
	pktoff		equ esp + 6
841
	eth_type	equ esp
865
	eth_rx_data_ptr equ esp + 8
Line 842... Line 866...
842
	pkthdr		equ esp + 2
866
	eth_tmp_len	equ esp + 12
843
	pktoff		equ esp + 6
867
 
Line 913... Line 937...
913
	mov	ax, [pkthdr + 2]
937
	mov	ax , [pkthdr + 2]
914
	sub	ax, 4
938
	sub	ax , 4
Line 915... Line 939...
915
 
939
 
Line -... Line 940...
-
 
940
	DEBUGF	2,"Received %u bytes\n",eax
-
 
941
 
-
 
942
	add	dword [ebp + device.bytes_rx], eax  ; Update stats
-
 
943
	adc	dword [ebp + device.bytes_rx + 4], 0
916
	DEBUGF	2,"Received %u bytes\n",eax
944
	inc	dword [ebp + device.packets_rx]     ;
917
 
945
 
Line 918... Line 946...
918
	mov	[eth_tmp_len], ax
946
	mov	[eth_tmp_len], ax
919
	mov	dword[size], eax
947
	mov	dword[size], eax
Line 928... Line 956...
928
	test	al, RSTAT_PRX
956
	test	al , RSTAT_PRX
929
	jz	.fail
957
	jz	.fail
Line 930... Line 958...
930
 
958
 
Line -... Line 959...
-
 
959
   ; Right, we can now get the data
931
   ; Right, we can now get the data
960
 
932
 
961
	xor	ebx, ebx
Line 933... Line 962...
933
	mov	bh, [ebp + device.memsize]
962
	mov	bh , [ebp + device.memsize]
934
	sub	bx, [pktoff]
963
	sub	bx , [pktoff]
Line -... Line 964...
-
 
964
 
-
 
965
	cmp	[eth_tmp_len], bx
935
 
966
	jbe	.nsp_005
936
	cmp	[eth_tmp_len], bx
967
 
937
	jbe	.nsp_005
968
	DEBUGF	2,"tadaa!\n"
Line 938... Line 969...
938
 
969
 
939
	mov	al, [ebp + device.flags]
970
	mov	al , [ebp + device.flags]
940
	test	al, FLAG_PIO
971
	test	al , FLAG_PIO
941
	jz	.nsp_006
972
	jz	.nsp_006
942
 
973
 
943
	push	bx
974
	push	ebx
944
	mov	cx, bx
975
	mov	cx , bx
Line 945... Line 976...
945
	mov	bx, [pktoff]
976
	mov	bx , [pktoff+4]
-
 
977
	mov	edi, [eth_rx_data_ptr+4]
946
	mov	edi, [eth_rx_data_ptr]
978
	call	eth_pio_read
Line 947... Line 979...
947
	call	eth_pio_read
979
	pop	ebx
948
	pop	bx
980
	jmp	.nsp_007
949
	jmp	.nsp_007
981
 
Line 973... Line 1005...
973
	mov	edi, [eth_rx_data_ptr]
1005
	mov	edi, [eth_rx_data_ptr]
974
	call	eth_pio_read
1006
	call	eth_pio_read
975
	jmp	.nsp_009
1007
	jmp	.nsp_009
Line 976... Line 1008...
976
 
1008
 
-
 
1009
.nsp_008:
977
.nsp_008:
1010
	DEBUGF	2,"PIO mode not supported by HW!\n"
Line 978... Line 1011...
978
   ; Not implemented, as we are using PIO mode on this card
1011
   ; Not implemented, as we are using PIO mode on this card
979
 
1012
 
980
.nsp_009:
1013
.nsp_009:
Line 988... Line 1021...
988
	set_io	0
1021
	set_io	0
989
	set_io	P0_BOUND
1022
	set_io	P0_BOUND
990
	dec	al
1023
	dec	al
991
	out	dx, al
1024
	out	dx, al
Line -... Line 1025...
-
 
1025
 
992
 
1026
	mov	ebx, ebp
Line 993... Line 1027...
993
	add	esp, 14
1027
	add	esp, 14
994
 
1028
 
Line 995... Line 1029...
995
	mov	ebx, ebp
1029
	mov	ebx, ebp
996
	jmp	EthReceiver	;;;
1030
	jmp	EthReceiver	; send it to the kernel
-
 
1031
 
997
 
1032
.fail:
998
.fail:
1033
	add	esp, 14+8
Line 1009... Line 1044...
1009
;; Write MAC address ;;
1044
;; Write MAC address ;;
1010
;;                   ;;
1045
;;                   ;;
1011
;;;;;;;;;;;;;;;;;;;;;;;
1046
;;;;;;;;;;;;;;;;;;;;;;;
Line 1012... Line 1047...
1012
 
1047
 
1013
align 4
1048
align 4
Line 1014... Line 1049...
1014
write_mac:	; in: mac on stack
1049
write_mac:	; in: mac on stack (6 bytes)
Line 1015... Line 1050...
1015
 
1050
 
Line 1060... Line 1095...
1060
;        in      al, dx
1095
;        in      al, dx
1061
;        stosb
1096
;        stosb
1062
;        inc     dx
1097
;        inc     dx
1063
;        loopw   .loop
1098
;        loopw   .loop
1064
;
1099
;
1065
;        lea     edi, [ebp + device.mac]
-
 
1066
;        DEBUGF  1,"%x-%x-%x-%x-%x-%x\n",[edi+0]:2,[edi+1]:2,[edi+2]:2,[edi+3]:2,[edi+4]:2,[edi+5]:2
-
 
1067
;
-
 
1068
;        set_io  0
1100
;        set_io  0
1069
;        mov     al, CMD_PS0; + CMD_RD2 + CMD_STA  ; set page back to 0
1101
;        mov     al, CMD_PS0; + CMD_RD2 + CMD_STA  ; set page back to 0
1070
;        out     dx, al
1102
;        out     dx, al
Line 1085... Line 1117...
1085
	jz	.8bit
1117
	jz	.8bit
1086
	inc	esi
1118
	inc	esi
1087
  .8bit:
1119
  .8bit:
1088
	loop	.loop
1120
	loop	.loop
Line -... Line 1121...
-
 
1121
 
Line 1089... Line 1122...
1089
 
1122
	DEBUGF	1,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2
Line 1090... Line 1123...
1090
 
1123
 
Line 1259... Line 1292...
1259
;all initialized data place here
1292
;all initialized data place here
1260
align 4
1293
align 4
Line 1261... Line 1294...
1261
 
1294
 
1262
ne2000_DEV	dd 0
1295
ne2000_DEV	dd 0
1263
version 	dd (5 shl 16) or (API_VERSION and 0xFFFF)
1296
version 	dd (5 shl 16) or (API_VERSION and 0xFFFF)
-
 
1297
my_service	db 'RTL8029/ne2000',0  ;max 16 chars include zero
1264
my_service	db 'ne2000',0  ;max 16 chars include zero
1298
 
1265
devicename	db 'Realtek 8029',0
1299
device_1	db 'Realtek 8029',0
1266
		db 'Realtek 8019',0
1300
device_2	db 'Realtek 8019',0
1267
		db 'Realtek 8019AS',0
1301
device_3	db 'Realtek 8019AS',0
1268
		db 'ne2000',0
1302
device_4	db 'ne2000',0
Line 1269... Line 1303...
1269
		db 'DP8390',0
1303
device_5	db 'DP8390',0
1270
 
-
 
Line 1271... Line 1304...
1271
test_data	db 'NE*000 memory',0
1304
 
Line 1272... Line 1305...
1272
;test_buffer     db '             ',0
1305
test_data	db 'NE*000 memory',0
1273
 
-
 
1274
include_debug_strings
-
 
Line 1275... Line -...
1275
 
-
 
1276
section '.data' data readable writable align 16
1306