Subversion Repositories Kolibri OS

Rev

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

Rev 1514 Rev 1519
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2010. 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
;; Realtek 8139 driver for KolibriOS                               ;;
6
;;  Realtek 8139 driver for KolibriOS                              ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
8
;;  based on RTL8139.asm driver for menuetos                       ;;
-
 
9
;;  and realtek8139.asm for SolarOS by Eugen Brasoveanu            ;;
9
;;                                                                 ;;
10
;;                                                                 ;;
10
;;     0.1 - x march 2009                                          ;;
-
 
11
;;     0.2 - 8 november 2009                                       ;;
11
;;    Written by hidnplayr@kolibrios.org                           ;;
12
;;                                                                 ;;
12
;;                                                                 ;;
13
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;          GNU GENERAL PUBLIC LICENSE                             ;;
14
;;             Version 2, June 1991                                ;;
14
;;             Version 2, June 1991                                ;;
15
;;                                                                 ;;
15
;;                                                                 ;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 17... Line -...
17
 
-
 
18
 
17
 
Line 19... Line 18...
19
format MS COFF
18
format MS COFF
-
 
19
 
-
 
20
	API_VERSION		equ 0x01000100
-
 
21
	DRIVER_VERSION		equ 5
Line 20... Line 22...
20
 
22
 
21
	API_VERSION		equ 0x01000100
23
	MAX_DEVICES		equ 16
22
 
24
 
Line 23... Line 25...
23
	DEBUG			equ 1
25
	DEBUG			equ 1
24
	__DEBUG__		equ 1
26
	__DEBUG__		equ 1
25
	__DEBUG_LEVEL__ 	equ 2
27
	__DEBUG_LEVEL__ 	equ 2
26
 
28
 
Line 27... Line -...
27
include 'proc32.inc'
-
 
28
include 'imports.inc'
-
 
29
include 'fdo.inc'
-
 
30
include 'netdrv.inc'
-
 
31
 
29
include 'proc32.inc'
32
OS_BASE 	equ 0
30
include 'imports.inc'
33
new_app_base	equ 0x60400000
31
include 'fdo.inc'
Line 34... Line -...
34
PROC_BASE	equ OS_BASE+0x0080000
-
 
35
 
-
 
36
public START
-
 
37
public service_proc
-
 
38
public version
-
 
39
 
-
 
40
 
-
 
41
virtual at ebx
-
 
42
 
-
 
43
      device:
-
 
44
 
-
 
45
      ETH_DEVICE
-
 
46
 
-
 
47
      .rx_buffer	dd ?
-
 
48
      .tx_buffer	dd ?
-
 
49
      .rx_data_offset	dd ?
-
 
50
      .io_addr		dd ?
-
 
51
      .curr_tx_desc	db ?
-
 
52
      .pci_bus		db ?
-
 
53
      .pci_dev		db ?
-
 
54
      .irq_line 	db ?
-
 
55
      .hw_ver_id	db ?
-
 
56
 
-
 
57
      .size = $ - device
-
 
58
 
-
 
59
end virtual
-
 
60
 
-
 
61
 
-
 
62
; RTL8139 specific defines
-
 
63
 
-
 
64
	MAX_RTL8139		equ 16	 ; Max number of devices this driver may handle
-
 
65
	TX_TIMEOUT		equ 30	 ; 300 milliseconds timeout
-
 
66
 
32
include 'netdrv.inc'
67
	PCI_REG_CMD		equ 0x04 ; command register
33
 
68
	PCI_BIT_PIO		equ 0	 ; bit0: io space control
34
public START
69
	PCI_BIT_MMIO		equ 1	 ; bit1: memory space control
35
public service_proc
70
	PCI_BIT_MASTER		equ 2	 ; bit2: device acts as a PCI master
36
public version
Line 167... Line 133...
167
				    (1 shl BIT_AR) or \ 		; Accept Runt packets (smaller then 64 bytes)
133
				    (1 shl BIT_AR) or \ 		; Accept Runt packets (smaller then 64 bytes)
168
				    (1 shl BIT_AM)			; Accept multicast packets
134
				    (1 shl BIT_AM)			; Accept multicast packets
Line 169... Line 135...
169
 
135
 
170
	RX_BUFFER_SIZE		equ (8192 shl RBLEN);+16
136
	RX_BUFFER_SIZE		equ (8192 shl RBLEN);+16
-
 
137
	MAX_ETH_FRAME_SIZE	equ 1516 ; exactly 1514 wthout CRC
171
	MAX_ETH_FRAME_SIZE	equ 1516 ; exactly 1514 wthout CRC
138
 
172
	NUM_TX_DESC		equ 4
-
 
Line 173... Line 139...
173
	TX_BUF_SIZE		equ 4096 ; size of one tx buffer (set to 4kb because of KolibriOS's page size)
139
	NUM_TX_DESC		equ 4
174
 
140
 
175
	EE_93C46_REG_ETH_ID	equ 7 ; MAC offset
141
	EE_93C46_REG_ETH_ID	equ 7 ; MAC offset
176
	EE_93C46_READ_CMD	equ (6 shl 6) ; 110b + 6bit address
142
	EE_93C46_READ_CMD	equ (6 shl 6) ; 110b + 6bit address
Line 226... Line 192...
226
	TSR_OWC 		equ 1 SHL 29
192
	TSR_OWC 		equ 1 SHL 29
227
	TSR_TABT		equ 1 SHL 30
193
	TSR_TABT		equ 1 SHL 30
228
	TSR_CRS 		equ 1 SHL 31
194
	TSR_CRS 		equ 1 SHL 31
Line -... Line 195...
-
 
195
 
-
 
196
 
-
 
197
virtual at ebx
-
 
198
 
-
 
199
	device:
-
 
200
 
-
 
201
	ETH_DEVICE
-
 
202
 
-
 
203
	.rx_buffer	dd ?
-
 
204
	.tx_buffer	dd ?
-
 
205
	.rx_data_offset dd ?
-
 
206
	.io_addr	dd ?
-
 
207
	.curr_tx_desc	db ?
-
 
208
	.last_tx_desc	db ?
-
 
209
	.pci_bus	db ?
-
 
210
	.pci_dev	db ?
-
 
211
	.irq_line	db ?
-
 
212
	.hw_ver_id	db ?
-
 
213
 
-
 
214
	.TX_DESC	rd NUM_TX_DESC
-
 
215
 
-
 
216
	.size = $ - device
-
 
217
 
-
 
218
end virtual
Line 229... Line 219...
229
 
219
 
Line 230... Line 220...
230
 
220
 
231
 
221
 
Line 296... Line 286...
296
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
286
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
297
	jne	.fail					; other types arent supported for this card yet
287
	jne	.fail					; other types arent supported for this card yet
Line 298... Line 288...
298
 
288
 
Line 299... Line 289...
299
; check if the device is already listed
289
; check if the device is already listed
300
 
290
 
301
	mov	esi, RTL8139_LIST
291
	mov	esi, device_list
302
	mov	ecx, [RTL8139_DEV]
292
	mov	ecx, [devices]
Line 303... Line 293...
303
	test	ecx, ecx
293
	test	ecx, ecx
304
	jz	.firstdevice
294
	jz	.firstdevice
Line 313... Line 303...
313
	loop	.nextdevice
303
	loop	.nextdevice
Line 314... Line 304...
314
 
304
 
315
 
305
 
316
; This device doesnt have its own eth_device structure yet, lets create one
306
; This device doesnt have its own eth_device structure yet, lets create one
317
  .firstdevice:
307
  .firstdevice:
Line 318... Line 308...
318
	cmp	[RTL8139_DEV], MAX_RTL8139		; First check if the driver can handle one more card
308
	cmp	[devices], MAX_DEVICES			; First check if the driver can handle one more card
319
	jge	.fail
309
	jge	.fail
320
 
310
 
Line 353... Line 343...
353
	DEBUGF	2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
343
	DEBUGF	2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
354
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
344
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
Line 355... Line 345...
355
 
345
 
356
 
346
 
Line 357... Line 347...
357
	allocate_and_clear [device.rx_buffer], (RX_BUFFER_SIZE+MAX_ETH_FRAME_SIZE), .err
347
	allocate_and_clear [device.rx_buffer], (RX_BUFFER_SIZE+MAX_ETH_FRAME_SIZE), .err
Line 358... Line 348...
358
	allocate_and_clear [device.tx_buffer], (TX_BUF_SIZE*NUM_TX_DESC), .err
348
   ;;     allocate_and_clear [device.tx_buffer], (TX_BUF_SIZE*NUM_TX_DESC), .err
359
 
349
 
360
; Ok, the eth_device structure is ready, let's probe the device
350
; Ok, the eth_device structure is ready, let's probe the device
Line 361... Line 351...
361
 
351
 
362
	call	probe							; this function will output in eax
352
	call	probe							; this function will output in eax
363
	test	eax, eax
353
	test	eax, eax
364
	jnz	.err							; If an error occured, exit
-
 
Line 365... Line 354...
365
 
354
	jnz	.err							; If an error occured, exit
366
	mov	eax, [RTL8139_DEV]					; Add the device structure to our device list
355
 
Line 367... Line 356...
367
	mov	[RTL8139_LIST+4*eax], ebx				; (IRQ handler uses this list to find device)
356
	mov	eax, [devices]						; Add the device structure to our device list
Line 391... Line 380...
391
  .destroy:
380
  .destroy:
392
	; todo: reset device into virgin state
381
	; todo: reset device into virgin state
Line 393... Line 382...
393
 
382
 
394
  .err:
383
  .err:
395
	stdcall KernelFree, dword [device.rx_buffer]
384
	stdcall KernelFree, dword [device.rx_buffer]
396
	stdcall KernelFree, dword [device.tx_buffer]
385
     ;;   stdcall KernelFree, dword [device.tx_buffer]
Line 397... Line 386...
397
	stdcall KernelFree, ebx
386
	stdcall KernelFree, ebx
398
 
387
 
Line 611... Line 600...
611
 
600
 
Line 612... Line 601...
612
; init RX/TX pointers
601
; init RX/TX pointers
613
 
602
 
-
 
603
	mov	[device.rx_data_offset], eax
Line 614... Line 604...
614
	mov	[device.rx_data_offset], eax
604
	mov	[device.curr_tx_desc], al
Line 615... Line 605...
615
	mov	[device.curr_tx_desc], al
605
	mov	[device.last_tx_desc], al
616
 
606
 
Line 623... Line 613...
623
; clear missing packet counter
613
; clear missing packet counter
Line 624... Line 614...
624
 
614
 
625
	set_io	REG_MPC
615
	set_io	REG_MPC
Line 626... Line -...
626
	out	dx , eax
-
 
627
 
-
 
628
; Set up the 4 Txbuffer descriptors
-
 
629
 
-
 
630
	set_io	REG_TSAD0
-
 
631
	mov	eax, [device.tx_buffer]
-
 
632
	mov	ecx, 4
-
 
633
  .loop:
-
 
634
	push	eax
-
 
635
	call	GetPgAddr
-
 
636
	DEBUGF	1,"Desc: %x ", eax
-
 
637
	out	dx , eax
-
 
638
	add	dx , 4
-
 
639
	pop	eax
-
 
640
	add	eax, TX_BUF_SIZE
-
 
641
	loop	.loop
616
	out	dx , eax
Line 642... Line 617...
642
 
617
 
643
; set RxBuffer address, init RX buffer offset
618
; set RxBuffer address, init RX buffer offset
644
 
619
 
Line 656... Line 631...
656
 
631
 
Line 657... Line 632...
657
; Read MAC address
632
; Read MAC address
Line -... Line 633...
-
 
633
 
-
 
634
	call	read_mac
-
 
635
 
658
 
636
; Set the mtu, kernel will be able to send now
Line 659... Line 637...
659
	call	read_mac
637
	mov	[device.mtu], 1514
660
 
638
 
Line 673... Line 651...
673
;; In: buffer pointer in [esp+4]           ;;
651
;; In: buffer pointer in [esp+4]           ;;
674
;;     size of buffer in [esp+8]           ;;
652
;;     size of buffer in [esp+8]           ;;
675
;;     pointer to device structure in ebx  ;;
653
;;     pointer to device structure in ebx  ;;
676
;;                                         ;;
654
;;                                         ;;
677
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
655
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
678
 
-
 
679
align 4
656
align 4
680
transmit:
657
transmit:
681
	DEBUGF	1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
658
	DEBUGF	1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
682
	mov	eax, [esp+4]
659
	mov	eax, [esp+4]
683
	DEBUGF	1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
660
	DEBUGF	1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
684
	[eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
661
	[eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
685
	[eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
662
	[eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
686
	[eax+13]:2,[eax+12]:2
663
	[eax+13]:2,[eax+12]:2
Line 687... Line 664...
687
 
664
 
688
	cmp	dword [esp+8], MAX_ETH_FRAME_SIZE
665
	cmp	dword [esp+8], MAX_ETH_FRAME_SIZE
689
	jg	.finish 			; packet is too long
666
	jg	.fail
690
	cmp	dword [esp+8], 60
667
	cmp	dword [esp+8], 60
Line 691... Line 668...
691
	jl	.finish 			; packet is too short
668
	jl	.fail
692
 
669
 
693
; check descriptor
670
; check if we own the discriptor
694
	DEBUGF	1,"Checking descriptor, "
671
	set_io	0
695
	movzx	ecx, [device.curr_tx_desc]
672
	movzx	ecx, [device.curr_tx_desc]
696
	mov	edx, [device.io_addr]
673
	shl	ecx, 2
697
	lea	edx, [edx+ecx*4+REG_TSD0]
-
 
698
	in	ax, dx
-
 
699
	test	ax, 0x1fff ; or no size given
-
 
700
	jz	.send_packet
674
	lea	edx, [edx+ecx+REG_TSD0]
701
	and	ax, (1 shl BIT_TOK) or (1 shl BIT_OWN)
675
	in	ax, dx
702
	cmp	ax, (1 shl BIT_TOK) or (1 shl BIT_OWN)
-
 
703
	jz	.send_packet
-
 
704
; wait for timeout
-
 
705
	DEBUGF	1,"Waiting for timeout, "
-
 
706
 
-
 
707
	push	edx ebx 			 ; TODO : rtl8139 internal timer should be used instead
-
 
Line 708... Line -...
708
	stdcall Sleep, TX_TIMEOUT		 ; ? What registers does this destroy ?
-
 
709
	pop	ebx edx
-
 
710
 
-
 
711
	in	ax, dx
-
 
712
	and	ax, (1 shl BIT_TOK) or (1 shl BIT_OWN)
-
 
713
	cmp	ax, (1 shl BIT_TOK) or (1 shl BIT_OWN)
-
 
714
	jz	.send_packet			 ; if chip hung, reset it
-
 
715
	push	dx
676
	test	ax, (1 shl BIT_OWN)
716
	call	reset				 ; reset the card
677
	jz	.wait_to_send
717
	pop	dx
-
 
718
.send_packet:
678
 
719
	DEBUGF	1,"Sending packet, "
-
 
720
 
-
 
721
	push	edx
-
 
722
	movzx	eax, [device.curr_tx_desc]   ; calculate the current tx_buffer address
679
  .send_packet:
723
	mov	edx, TX_BUF_SIZE ;MAX_ETH_FRAME_SIZE          ;
-
 
724
	mul	edx				 ;
-
 
725
	mov	edi, [device.tx_buffer]      ;
-
 
726
	add	edi, eax			 ; Store it in edi
-
 
727
	pop	edx
680
; Set the buffer address
728
 
681
	set_io	0
729
	mov	esi, [esp+4]			 ; Copy data to that address
682
	lea	edx, [edx+ecx+REG_TSAD0]
730
	mov	ecx, [esp+8]			 ;
-
 
731
	shr	ecx, 2				 ;
683
	mov	eax, [esp+4]
732
	rep	movsd				 ;
-
 
Line -... Line 684...
-
 
684
	mov	[device.TX_DESC+ecx], eax
-
 
685
	GetRealAddr
733
	mov	ecx, [esp+8]			 ;
686
	out	dx, eax
734
	and	ecx, 3				 ;
687
 
-
 
688
; And the size of the buffer
-
 
689
	set_io	0
Line -... Line 690...
-
 
690
	lea	edx, [edx+ecx+REG_TSD0]
-
 
691
	mov	eax, [esp+8]
735
	rep	movsb				 ;
692
;        or      eax, (ERTXTH shl BIT_ERTXTH)    ; Early threshold
736
 
693
	out	dx , eax
Line 737... Line -...
737
	inc	[device.packets_tx]	     ;
-
 
738
	mov	eax, [esp+8]			 ; Get packet size in eax
694
 
739
 
-
 
740
	add	dword [device.bytes_tx], eax
-
 
741
	adc	dword [device.bytes_tx + 4], 0
695
; Update stats
742
 
696
	inc	[device.packets_tx]
Line 743... Line 697...
743
;        or      eax, (ERTXTH shl BIT_ERTXTH)     ; Set descriptor size and the early tx treshold into the correct Transmission status register (TSD0, TSD1, TSD2 or TSD3)
697
	add	dword [device.bytes_tx], eax
-
 
698
	adc	dword [device.bytes_tx + 4], 0
-
 
699
 
-
 
700
; get next descriptor
-
 
701
	inc	[device.curr_tx_desc]
-
 
702
	and	[device.curr_tx_desc], 3
-
 
703
 
-
 
704
	DEBUGF	1,"Packet Sent! "
-
 
705
	xor	eax, eax
-
 
706
	ret	8
-
 
707
 
-
 
708
  .wait_to_send:
-
 
709
 
-
 
710
	DEBUGF	1,"Waiting for timeout\n"
-
 
711
 
-
 
712
	mov	esi, 30
-
 
713
	stdcall Sleep
-
 
714
 
-
 
715
	in	ax, dx
-
 
716
	test	ax, (1 shl BIT_OWN)
-
 
717
	jnz	.send_packet
744
	out	dx , eax			 ;
718
 
745
 
719
	pusha
-
 
720
	call	reset				 ; if chip hung, reset it
746
; get next descriptor 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...
721
	popa
Line 747... Line 722...
747
	inc	[device.curr_tx_desc]
722
 
748
	and	[device.curr_tx_desc], 3
723
	jmp	.send_packet
749
 
724
 
750
	DEBUGF	1," - Packet Sent! "
725
  .fail:
751
.finish:
726
	DEBUGF	1,"failed!\n"
752
	DEBUGF	1," - Done!\n"
-
 
753
	ret
727
	or	eax, -1
754
 
728
	ret	8
Line 755... Line 729...
755
 
729
 
Line 756... Line 730...
756
 
730
 
Line 757... Line 731...
757
 
731
 
758
 
732
 
759
;;;;;;;;;;;;;;;;;;;;;;;
733
 
760
;;                   ;;
734
;;;;;;;;;;;;;;;;;;;;;;;
761
;; Interrupt handler ;;
735
;;                   ;;
762
;;                   ;;
736
;; Interrupt handler ;;
Line 797... Line 771...
797
 
771
 
Line 798... Line 772...
798
; Lets found out why the irq occured then..
772
; Lets found out why the irq occured then..
799
 
773
 
800
;----------------------------------------------------
-
 
801
; Received packet ok?
774
;----------------------------------------------------
802
 
775
; Received packet ok?
803
	test	ax, ISR_ROK
776
	test	ax, ISR_ROK
Line 804... Line 777...
804
	jz	@f
777
	jz	@f
Line 834... Line 807...
834
	stdcall KernelAlloc, ecx		    ; Allocate a buffer to put packet into
807
	stdcall KernelAlloc, ecx		    ; Allocate a buffer to put packet into
835
	pop	ecx
808
	pop	ecx
836
	test	eax, eax			    ; Test if we allocated succesfully
809
	test	eax, eax			    ; Test if we allocated succesfully
837
	jz	.abort
810
	jz	.abort
Line 838... Line -...
838
 
-
 
839
 
811
 
Line 840... Line 812...
840
	mov	edi, eax			    ; Where we will copy too
812
	mov	edi, eax			    ; Where we will copy too
841
 
813
 
Line 912... Line 884...
912
  .finish:
884
  .finish:
913
	pop	ax
885
	pop	ax
Line 914... Line 886...
914
 
886
 
915
;----------------------------------------------------
887
;----------------------------------------------------
916
; Transmit error ?
-
 
917
 
888
; Transmit error ?
918
  @@:
889
  @@:
919
	test	ax, ISR_TER
890
	test	ax, ISR_TER
Line 920... Line 891...
920
	jz	@f
891
	jz	@f
921
 
892
 
922
	push	ax
-
 
923
	cmp	[device.curr_tx_desc], 4
-
 
924
	jz	.notxd
-
 
925
 
-
 
926
	set_io	0
-
 
927
	movzx	ecx, [device.curr_tx_desc]
-
 
928
	lea	edx, [edx+ecx*4+REG_TSD0]
-
 
929
	in	eax, dx
-
 
930
 
-
 
931
  .notxd:
-
 
932
	test	eax, TSR_TUN
-
 
933
	jz	.nobun
-
 
934
	DEBUGF	2, "TX: FIFO Buffer underrun!\n"
-
 
935
 
-
 
936
  .nobun:
-
 
937
	test	eax, TSR_OWC
-
 
938
	jz	.noowc
-
 
939
	DEBUGF	2, "TX: OWC!\n"
-
 
940
 
-
 
941
  .noowc:
-
 
942
	test	eax, TSR_TABT
-
 
943
	jz	.notabt
-
 
944
	DEBUGF	2, "TX: TABT!\n"
-
 
945
 
-
 
946
  .notabt:
-
 
947
	test	eax, TSR_CRS
-
 
948
	jz	.nocsl
-
 
949
	DEBUGF	2, "TX: Carrier Sense Lost!\n"
-
 
950
 
-
 
951
  .nocsl:
893
;        push    ax
952
;                test    eax, TSR_OWN or TSR_TOK
-
 
953
;                jz      .nofd
894
;        cmp     [device.curr_tx_desc], 4
-
 
895
;        jz      .notxd
-
 
896
;
-
 
897
;        set_io  0
-
 
898
;        movzx   ecx, [device.curr_tx_desc]
-
 
899
;        lea     edx, [edx+ecx*4+REG_TSD0]
-
 
900
;        in      eax, dx
-
 
901
;
954
;                DEBUGF  1, "TX: Transmit OK (desc: %u)\n", ecx
902
;  .notxd:
-
 
903
;        test    eax, TSR_TUN
-
 
904
;        jz      .nobun
955
;
905
;        DEBUGF  2, "TX: FIFO Buffer underrun!\n"
-
 
906
;
-
 
907
;  .nobun:
-
 
908
;        test    eax, TSR_OWC
-
 
909
;        jz      .noowc
-
 
910
;        DEBUGF  2, "TX: OWC!\n"
-
 
911
;
-
 
912
;  .noowc:
-
 
913
;        test    eax, TSR_TABT
-
 
914
;        jz      .notabt
-
 
915
;        DEBUGF  2, "TX: TABT!\n"
-
 
916
;
-
 
917
;  .notabt:
-
 
918
;        test    eax, TSR_CRS
-
 
919
;        jz      .nocsl
-
 
920
;        DEBUGF  2, "TX: Carrier Sense Lost!\n"
-
 
921
;
Line 956... Line 922...
956
;               .nofd:
922
;  .nocsl:
957
	pop	ax
923
;        pop     ax
958
 
-
 
959
;----------------------------------------------------
924
 
960
; Transmit ok ?
925
;----------------------------------------------------
961
 
926
; Transmit ok ?
Line -... Line 927...
-
 
927
  @@:
-
 
928
	test	ax, ISR_TOK
-
 
929
	jz	@f
-
 
930
 
-
 
931
	push	ax
-
 
932
	mov	si, 4
-
 
933
  .txdesloop:
-
 
934
	movzx	ecx, [device.last_tx_desc]
-
 
935
	shl	ecx, 2
-
 
936
 
-
 
937
	set_io	0
-
 
938
	set_io	REG_TSD0
-
 
939
	add	edx, ecx
-
 
940
	in	eax, dx
-
 
941
 
962
  @@:
942
	test	eax, TSR_TOK
-
 
943
	jz	.notthisone
-
 
944
	mov	eax, TSR_OWN
-
 
945
	out	dx , eax
-
 
946
	DEBUGF	1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8
-
 
947
	stdcall KernelFree, [device.TX_DESC+ecx]
-
 
948
  .notthisone:
-
 
949
 
-
 
950
	inc	[device.last_tx_desc]
-
 
951
	and	[device.last_tx_desc], 3
-
 
952
 
-
 
953
	dec	si
Line 963... Line 954...
963
	test	ax, ISR_TOK
954
	jnz	.txdesloop
964
	jz	@f
955
 
965
 
-
 
966
	DEBUGF	1, "TX: Transmit OK (desc: %u)\n", [device.curr_tx_desc]:1
956
  .done:
967
 
957
	pop	ax
968
;----------------------------------------------------
958
 
Line 969... Line 959...
969
; Rx buffer overflow ?
959
;----------------------------------------------------
970
 
960
; Rx buffer overflow ?
Line 971... Line 961...
971
  @@:
961
  @@:
972
	test	ax, ISR_RXOVW
962
	test	ax, ISR_RXOVW
973
	jz	@f
963
	jz	@f
974
 
964
 
975
	push	ax
965
	push	ax
Line 976... Line 966...
976
	DEBUGF	2,"RX-buffer overflow!\n"
966
	DEBUGF	2,"RX-buffer overflow!\n"
977
 
967
 
978
	mov	edx, [device.io_addr]
-
 
979
	add	edx, REG_ISR
-
 
980
	mov	ax , ISR_FIFOOVW or ISR_RXOVW
968
	set_io	0
981
	out	dx , ax
969
	set_io	REG_ISR
982
	pop	ax
970
	mov	ax , ISR_FIFOOVW or ISR_RXOVW
Line 983... Line 971...
983
 
971
	out	dx , ax
Line 984... Line 972...
984
;----------------------------------------------------
972
	pop	ax
985
; Packet underrun? ?
973
 
986
 
-
 
987
 
974
;----------------------------------------------------
988
  @@:
975
; Packet underrun?
989
	test	ax, ISR_PUN
976
  @@:
Line 990... Line 977...
990
	jz	@f
977
	test	ax, ISR_PUN
991
 
978
	jz	@f
Line 992... Line 979...
992
	DEBUGF	2,"Packet underrun!\n"
979
 
993
 
980
	DEBUGF	2,"Packet underrun!\n"
994
;----------------------------------------------------
981
 
995
; Receive FIFO overflow ?
982
;----------------------------------------------------
996
 
983
; Receive FIFO overflow ?
Line 997... Line 984...
997
  @@:
984
  @@:
998
	test	ax, ISR_FIFOOVW
985
	test	ax, ISR_FIFOOVW
999
	jz	@f
-
 
1000
 
986
	jz	@f
1001
	push	ax
987
 
1002
	DEBUGF	2,"RX fifo overflox!\n"
988
	push	ax
Line 1003... Line 989...
1003
 
989
	DEBUGF	2,"RX fifo overflow!\n"
1004
	mov	edx, [device.io_addr]
990
 
Line 1005... Line -...
1005
	add	edx, REG_ISR
-
 
1006
	mov	ax , ISR_FIFOOVW or ISR_RXOVW
-
 
1007
	out	dx , ax
991
	set_io	0
1008
	pop	ax
-
 
1009
 
-
 
1010
;----------------------------------------------------
992
	set_io	REG_ISR
Line 1211... Line 1193...
1211
	ret
1193
	ret
Line 1212... Line 1194...
1212
 
1194
 
Line -... Line 1195...
-
 
1195
 
1213
 
1196
; End of code
Line 1214... Line 1197...
1214
; End of code
1197
 
1215
 
1198
section '.data' data readable writable align 16 ; place all uninitialized data place here
1216
align 4 					; Place all initialised data here
1199
align 4 					; Place all initialised data here
Line 1217... Line 1200...
1217
 
1200
 
1218
RTL8139_DEV   dd 0
1201
devices 	dd 0
1219
version       dd (5 shl 16) or (API_VERSION and 0xFFFF)
1202
version 	dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
Line 1227... Line 1210...
1227
device_6      db 'Realtek 8139D',0
1210
device_6	db 'Realtek 8139D',0
1228
device_7      db 'Realtek 8139CP',0
1211
device_7	db 'Realtek 8139CP',0
1229
device_8      db 'Realtek 8101',0
1212
device_8	db 'Realtek 8101',0
1230
device_unknown db 'Unknown RTL8139 clone', 0
1213
device_unknown	db 'Unknown RTL8139 clone', 0
Line -... Line 1214...
-
 
1214
 
1231
 
1215
crosslist:
1232
crosslist     dd device_1
1216
	dd device_1
1233
	      dd device_2
1217
	dd device_2
1234
	      dd device_3
1218
	dd device_3
1235
	      dd device_4
1219
	dd device_4
1236
	      dd device_5
1220
	dd device_5
1237
	      dd device_6
1221
	dd device_6
1238
	      dd device_7
1222
	dd device_7
1239
	      dd device_8
1223
	dd device_8
Line 1240... Line 1224...
1240
	      dd device_unknown
1224
	dd device_unknown
-
 
1225
 
1241
 
1226
hw_ver_array:			 ; This array is used by the probe routine to find out wich version of the RTL8139 we are working with
1242
hw_ver_array  db VER_RTL8139			; This array is used by the probe routine to find out wich version of the RTL8139 we are working with
1227
	db VER_RTL8139
1243
	      db VER_RTL8139A
1228
	db VER_RTL8139A
1244
	      db VER_RTL8139B
1229
	db VER_RTL8139B
1245
	      db VER_RTL8139C
1230
	db VER_RTL8139C
Line 1251... Line 1236...
1251
 
1236
 
Line 1252... Line 1237...
1252
HW_VER_ARRAY_SIZE = $-hw_ver_array
1237
HW_VER_ARRAY_SIZE = $-hw_ver_array
Line 1253... Line -...
1253
 
-
 
1254
include_debug_strings				; All data wich FDO uses will be included here
-
 
1255
 
1238