Subversion Repositories Kolibri OS

Rev

Rev 1541 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1541 Rev 1556
Line 20... Line 20...
20
	API_VERSION		equ 0x01000100
20
	API_VERSION		equ 0x01000100
21
	DRIVER_VERSION		equ 5
21
	DRIVER_VERSION		equ 5
Line 22... Line 22...
22
 
22
 
Line -... Line 23...
-
 
23
	MAX_DEVICES		equ 16
-
 
24
 
23
	MAX_DEVICES		equ 16
25
	RBLEN			equ 3 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k
24
 
26
 
25
	DEBUG			equ 1
27
	DEBUG			equ 1
Line 26... Line 28...
26
	__DEBUG__		equ 1
28
	__DEBUG__		equ 1
Line 114... Line 116...
114
	BIT_SELECTOR		equ 0 ; binary encoded selector CSMA/CD=00001
116
	BIT_SELECTOR		equ 0 ; binary encoded selector CSMA/CD=00001
Line 115... Line 117...
115
 
117
 
116
	BIT_IFG1		equ 25
118
	BIT_IFG1		equ 25
Line 117... Line -...
117
	BIT_IFG0		equ 24
-
 
118
 
119
	BIT_IFG0		equ 24
119
	RBLEN			equ 2 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k
120
 
120
	TXRR			equ 8 ; total retries = 16+(TXRR*16)
121
	TXRR			equ 8 ; total retries = 16+(TXRR*16)
121
	TX_MXDMA		equ 6 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048
122
	TX_MXDMA		equ 6 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048
122
	ERTXTH			equ 8 ; in unit of 32 bytes e.g:(8*32)=256
123
	ERTXTH			equ 8 ; in unit of 32 bytes e.g:(8*32)=256
Line 133... Line 134...
133
				    (1 shl BIT_AR) or \ 		; Accept Runt packets (smaller then 64 bytes)
134
				    (1 shl BIT_AR) or \ 		; Accept Runt packets (smaller then 64 bytes)
134
				    (1 shl BIT_AM)			; Accept multicast packets
135
				    (1 shl BIT_AM)			; Accept multicast packets
Line 135... Line 136...
135
 
136
 
136
	RX_BUFFER_SIZE		equ (8192 shl RBLEN);+16
137
	RX_BUFFER_SIZE		equ (8192 shl RBLEN);+16
137
	MAX_ETH_FRAME_SIZE	equ 1516 ; exactly 1514 wthout CRC
-
 
138
 
138
	MAX_ETH_FRAME_SIZE	equ 1516 ; exactly 1514 wthout CRC
Line 139... Line 139...
139
	NUM_TX_DESC		equ 4
139
	NUM_TX_DESC		equ 4
140
 
140
 
141
	EE_93C46_REG_ETH_ID	equ 7 ; MAC offset
141
	EE_93C46_REG_ETH_ID	equ 7 ; MAC offset
Line 200... Line 200...
200
 
200
 
Line 201... Line 201...
201
	ETH_DEVICE
201
	ETH_DEVICE
202
 
202
 
-
 
203
	.rx_buffer	dd ?
203
	.rx_buffer	dd ?
204
	.tx_buffer	dd ?
204
	.tx_buffer	dd ?
205
 
-
 
206
	.rx_data_offset dd ?
205
	.rx_data_offset dd ?
207
	.io_addr	dd ?
206
	.io_addr	dd ?
-
 
207
	.curr_tx_desc	db ?
208
 
208
	.last_tx_desc	db ?
209
	.curr_tx_desc	db ?
209
	.pci_bus	db ?
210
	.pci_bus	db ?
210
	.pci_dev	db ?
211
	.pci_dev	db ?
Line 336... Line 337...
336
	find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
337
	find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
Line 337... Line 338...
337
 
338
 
338
	DEBUGF	2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
339
	DEBUGF	2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
Line -... Line 340...
-
 
340
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
Line 339... Line 341...
339
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
341
 
-
 
342
; Allocate the receive buffer
-
 
343
 
340
 
344
	stdcall CreateRingBuffer, dword (RX_BUFFER_SIZE), dword PG_SW
Line 341... Line 345...
341
 
345
	test	eax, eax
Line 342... Line 346...
342
	allocate_and_clear [device.rx_buffer], (RX_BUFFER_SIZE+MAX_ETH_FRAME_SIZE), .err
346
	jz	.err
343
   ;;     allocate_and_clear [device.tx_buffer], (TX_BUF_SIZE*NUM_TX_DESC), .err
347
	mov	[device.rx_buffer], eax
Line 375... Line 379...
375
  .destroy:
379
  .destroy:
376
	; todo: reset device into virgin state
380
	; todo: reset device into virgin state
Line 377... Line 381...
377
 
381
 
378
  .err:
382
  .err:
379
	stdcall KernelFree, dword [device.rx_buffer]
-
 
380
     ;;   stdcall KernelFree, dword [device.tx_buffer]
383
	stdcall KernelFree, dword [device.rx_buffer]
Line 381... Line -...
381
	stdcall KernelFree, ebx
-
 
382
 
384
	stdcall KernelFree, ebx
383
 
385
 
384
  .fail:
386
  .fail:
Line 385... Line 387...
385
	or	eax, -1
387
	or	eax, -1
Line 557... Line 559...
557
 
559
 
558
	mov	al , (1 shl BIT_RE) or (1 shl BIT_TE)
560
	mov	al , (1 shl BIT_RE) or (1 shl BIT_TE)
559
	set_io	REG_COMMAND
561
	set_io	REG_COMMAND
Line 560... Line 562...
560
	out	dx , al
562
	out	dx , al
561
 
563
 
Line 562... Line 564...
562
; 32k Rxbuffer, unlimited dma burst, no wrapping, no rx threshold
564
; Rxbuffer size, unlimited dma burst, no wrapping, no rx threshold
563
; accept broadcast packets, accept physical match packets
565
; accept broadcast packets, accept physical match packets
564
 
566
 
Line 595... Line 597...
595
 
597
 
Line 596... Line 598...
596
; init RX/TX pointers
598
; init RX/TX pointers
597
 
599
 
-
 
600
	mov	[device.rx_data_offset], eax
-
 
601
	mov	[device.curr_tx_desc], al
598
	mov	[device.rx_data_offset], eax
602
 
Line 599... Line 603...
599
	mov	[device.curr_tx_desc], al
603
;        set_io  REG_CAPR
Line 600... Line 604...
600
	mov	[device.last_tx_desc], al
604
;        out     dx , ax
601
 
605
 
Line 611... Line 615...
611
	out	dx , eax
615
	out	dx , eax
Line 612... Line 616...
612
 
616
 
Line 613... Line 617...
613
; set RxBuffer address, init RX buffer offset
617
; set RxBuffer address, init RX buffer offset
-
 
618
 
-
 
619
	mov	eax, [device.rx_buffer]
614
 
620
	mov	dword[eax], 0
615
	mov	eax, [device.rx_buffer]
621
	DEBUGF	2,"RX buffer:%x\n", eax
616
	call	GetPgAddr
622
	GetRealAddr
617
;        set_io  0
623
	DEBUGF	2,"RX buffer:%X\n", eax
Line 618... Line 624...
618
	set_io	REG_RBSTART
624
	set_io	REG_RBSTART
Line 649... Line 655...
649
;;     pointer to device structure in ebx  ;;
655
;;     pointer to device structure in ebx  ;;
650
;;                                         ;;
656
;;                                         ;;
651
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
657
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
652
align 4
658
align 4
653
transmit:
659
transmit:
654
	DEBUGF	1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
660
	DEBUGF	1,"\nTransmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
655
	mov	eax, [esp+4]
661
	mov	eax, [esp+4]
656
	DEBUGF	1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
662
	DEBUGF	1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
657
	[eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
663
	[eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
658
	[eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
664
	[eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
659
	[eax+13]:2,[eax+12]:2
665
	[eax+13]:2,[eax+12]:2
Line 661... Line 667...
661
	cmp	dword [esp+8], MAX_ETH_FRAME_SIZE
667
	cmp	dword [esp+8], MAX_ETH_FRAME_SIZE
662
	jg	.fail
668
	jg	.fail
663
	cmp	dword [esp+8], 60
669
	cmp	dword [esp+8], 60
664
	jl	.fail
670
	jl	.fail
Line 665... Line 671...
665
 
671
 
666
; check if we own the discriptor
672
; check if we own the current discriptor
-
 
673
	set_io	0
667
	set_io	0
674
	set_io	REG_TSD0
668
	movzx	ecx, [device.curr_tx_desc]
675
	movzx	ecx, [device.curr_tx_desc]
669
	shl	ecx, 2
676
	shl	ecx, 2
670
	lea	edx, [edx+ecx+REG_TSD0]
677
	add	edx, ecx
671
	in	ax, dx
678
	in	eax, dx
672
	test	ax, (1 shl BIT_OWN)
679
	test	eax, (1 shl BIT_OWN)
Line 673... Line 680...
673
	jz	.wait_to_send
680
	jz	.wait_to_send
-
 
681
 
-
 
682
  .send_packet:
-
 
683
; get next descriptor
-
 
684
	inc	[device.curr_tx_desc]
-
 
685
	and	[device.curr_tx_desc], NUM_TX_DESC-1
-
 
686
 
-
 
687
; Update stats
-
 
688
	inc	[device.packets_tx]
-
 
689
	mov	eax, [esp+8]
-
 
690
	add	dword [device.bytes_tx], eax
674
 
691
	adc	dword [device.bytes_tx + 4], 0
675
  .send_packet:
692
 
676
; Set the buffer address
-
 
677
	set_io	0
693
; Set the buffer address
678
	lea	edx, [edx+ecx+REG_TSAD0]
694
	set_io	REG_TSAD0
679
	mov	eax, [esp+4]
695
	mov	eax, [esp+4]
680
	mov	[device.TX_DESC+ecx], eax
696
	mov	[device.TX_DESC+ecx], eax
Line 681... Line 697...
681
	GetRealAddr
697
	GetRealAddr
682
	out	dx, eax
698
	out	dx, eax
683
 
-
 
684
; And the size of the buffer
699
 
685
	set_io	0
700
; And the size of the buffer
686
	lea	edx, [edx+ecx+REG_TSD0]
701
	set_io	REG_TSD0
Line 687... Line -...
687
	mov	eax, [esp+8]
-
 
688
;        or      eax, (ERTXTH shl BIT_ERTXTH)    ; Early threshold
-
 
689
	out	dx , eax
-
 
690
 
-
 
691
; Update stats
-
 
692
	inc	[device.packets_tx]
-
 
693
	add	dword [device.bytes_tx], eax
-
 
694
	adc	dword [device.bytes_tx + 4], 0
-
 
695
 
-
 
696
; get next descriptor
702
	mov	eax, [esp+8]
697
	inc	[device.curr_tx_desc]
703
	or	eax, (ERTXTH shl BIT_ERTXTH)	; Early threshold
698
	and	[device.curr_tx_desc], 3
704
	out	dx, eax
Line 699... Line 705...
699
 
705
 
700
	DEBUGF	1,"Packet Sent! "
-
 
701
	xor	eax, eax
706
	DEBUGF	1,"Packet Sent!\n"
Line -... Line 707...
-
 
707
	xor	eax, eax
702
	ret	8
708
	ret	8
703
 
709
 
-
 
710
  .wait_to_send:
Line 704... Line 711...
704
  .wait_to_send:
711
	DEBUGF	1,"Waiting for timeout\n"
705
 
712
 
706
	DEBUGF	1,"Waiting for timeout\n"
713
	push	edx
Line 733... Line 740...
733
;;                   ;;
740
;;                   ;;
734
;;;;;;;;;;;;;;;;;;;;;;;
741
;;;;;;;;;;;;;;;;;;;;;;;
735
align 4
742
align 4
736
int_handler:
743
int_handler:
Line 737... Line 744...
737
 
744
 
Line 738... Line 745...
738
	DEBUGF	1,"IRQ %x\n", eax:2		      ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
745
	DEBUGF	1,"\nIRQ %x\n", eax:2			; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
Line 739... Line 746...
739
 
746
 
740
; find pointer of device wich made IRQ occur
747
; find pointer of device wich made IRQ occur
Line 788... Line 795...
788
	jz	.reset_rx
795
	jz	.reset_rx
Line 789... Line 796...
789
 
796
 
790
; packet is ok, copy it
797
; packet is ok, copy it
Line -... Line 798...
-
 
798
	movzx	ecx, word [eax+2]		    ; packet length
-
 
799
 
791
	movzx	ecx, word [eax+2]		    ; packet length
800
	sub	ecx, 4				    ; don't copy CRC
792
 
801
 
793
; Update stats
802
; Update stats
794
	add	dword [device.bytes_rx], ecx
803
	add	dword [device.bytes_rx], ecx
Line 795... Line -...
795
	adc	dword [device.bytes_rx + 4], 0
-
 
796
	inc	dword [device.packets_rx]
-
 
797
 
804
	adc	dword [device.bytes_rx + 4], 0
Line 798... Line 805...
798
	sub	ecx, 4				    ; don't copy CRC
805
	inc	dword [device.packets_rx]
799
 
806
 
800
	DEBUGF	1,"Received %u bytes\n", ecx
807
	DEBUGF	1,"Received %u bytes\n", ecx
Line 826... Line 833...
826
	rep	movsd
833
	rep	movsd
827
  .nd:
834
  .nd:
Line 828... Line 835...
828
 
835
 
Line 829... Line -...
829
	jmp	EthReceiver			    ; Send it to kernel
-
 
830
 
836
	jmp	EthReceiver			    ; Send it to kernel
831
 
837
 
832
  .abort:
838
  .abort:
833
	pop	eax ebx
839
	pop	eax ebx
834
						    ; update eth_data_start_offset
840
						    ; update eth_data_start_offset
Line 841... Line 847...
841
	jl	.no_wrap
847
	jl	.no_wrap
842
	DEBUGF	2,"Wrapping"
848
	DEBUGF	2,"Wrapping"
843
	sub	eax, RX_BUFFER_SIZE
849
	sub	eax, RX_BUFFER_SIZE
844
  .no_wrap:
850
  .no_wrap:
845
	mov	[device.rx_data_offset], eax
851
	mov	[device.rx_data_offset], eax
846
	DEBUGF	1,"New RX ptr: %d ", eax
852
	DEBUGF	1,"New RX ptr: %d\n", eax
Line 847... Line 853...
847
 
853
 
848
	set_io	0
854
	set_io	0
849
	set_io	REG_CAPR			    ; update 'Current Address of Packet Read register'
855
	set_io	REG_CAPR			    ; update 'Current Address of Packet Read register'
850
	sub	eax, 0x10			    ; value 0x10 is a constant for CAPR
856
	sub	eax, 0x10			    ; value 0x10 is a constant for CAPR
Line 879... Line 885...
879
 
885
 
880
  .finish:
886
  .finish:
Line 881... Line 887...
881
	pop	ax
887
	pop	ax
882
 
888
 
883
;----------------------------------------------------
889
;----------------------------------------------------
884
; Transmit error ?
890
; Transmit ok / Transmit error
885
  @@:
891
  @@:
Line -... Line 892...
-
 
892
	test	ax, ISR_TOK + ISR_TER
-
 
893
	jz	@f
-
 
894
 
-
 
895
	push	ax
-
 
896
	xor	ecx, ecx
-
 
897
  .txdesloop:
-
 
898
	set_io	0
-
 
899
	set_io	REG_TSD0
-
 
900
	add	edx, ecx
-
 
901
	in	eax, dx
-
 
902
 
886
	test	ax, ISR_TER
903
	test	eax, TSR_OWN			; DMA operation completed
-
 
904
	jz	.notthisone
Line 887... Line -...
887
	jz	@f
-
 
888
 
-
 
889
	DEBUGF	1,"Transmit error\n"
-
 
890
 
-
 
891
;        push    ax
-
 
892
;        cmp     [device.curr_tx_desc], 4
-
 
893
;        jz      .notxd
-
 
894
;
-
 
895
;        set_io  0
-
 
896
;        movzx   ecx, [device.curr_tx_desc]
905
 
897
;        lea     edx, [edx+ecx*4+REG_TSD0]
906
	cmp	[device.TX_DESC+ecx], 0
898
;        in      eax, dx
907
	je	.notthisone
899
;
908
 
900
;  .notxd:
909
;  .notxd:
Line 916... Line 925...
916
;        test    eax, TSR_CRS
925
;        test    eax, TSR_CRS
917
;        jz      .nocsl
926
;        jz      .nocsl
918
;        DEBUGF  2, "TX: Carrier Sense Lost!\n"
927
;        DEBUGF  2, "TX: Carrier Sense Lost!\n"
919
;
928
;
920
;  .nocsl:
929
;  .nocsl:
921
;        pop     ax
-
 
922
 
-
 
923
;----------------------------------------------------
-
 
924
; Transmit ok ?
-
 
925
  @@:
-
 
926
	test	ax, ISR_TOK
-
 
927
	jz	@f
-
 
Line 928... Line -...
928
 
-
 
929
	push	ax
-
 
930
	mov	si, 4
-
 
931
  .txdesloop:
-
 
932
	movzx	ecx, [device.last_tx_desc]
-
 
933
	shl	ecx, 2
-
 
934
 
-
 
935
	set_io	0
-
 
936
	set_io	REG_TSD0
-
 
937
	add	edx, ecx
-
 
938
	in	eax, dx
-
 
939
 
-
 
940
	test	eax, TSR_TOK
-
 
941
	jz	.notthisone
-
 
942
	mov	eax, TSR_OWN
-
 
943
	out	dx , eax
930
 
-
 
931
	DEBUGF	1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8
944
	DEBUGF	1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8
932
	push	ecx ebx
945
	stdcall KernelFree, [device.TX_DESC+ecx]
933
	stdcall KernelFree, [device.TX_DESC+ecx]
946
  .notthisone:
-
 
947
 
-
 
948
	inc	[device.last_tx_desc]
934
	pop	ebx ecx
Line -... Line 935...
-
 
935
	mov	[device.TX_DESC+ecx], 0
949
	and	[device.last_tx_desc], 3
936
 
950
 
937
  .notthisone:
951
	dec	si
-
 
952
	jnz	.txdesloop
938
	add	ecx, 4
953
 
939
	cmp	ecx, 16
Line 954... Line 940...
954
  .done:
940
	jl	.txdesloop
955
	pop	ax
941
	pop	ax
956
 
942