Subversion Repositories Kolibri OS

Rev

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

Rev 4470 Rev 4606
Line 19... Line 19...
19
;;  See file COPYING for details                                   ;;
19
;;  See file COPYING for details                                   ;;
20
;;                                                                 ;;
20
;;                                                                 ;;
21
;;                                                                 ;;
21
;;                                                                 ;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 23... Line 23...
23
 
23
 
-
 
24
format PE DLL native
Line -... Line 25...
-
 
25
entry START
24
format MS COFF
26
 
25
 
27
	CURRENT_API		= 0x0200
Line 26... Line 28...
26
        API_VERSION             = 0x01000100
28
	COMPATIBLE_API		= 0x0100
Line 27... Line -...
27
        DRIVER_VERSION          = 5
-
 
28
 
29
	API_VERSION		= (COMPATIBLE_API shl 16) + CURRENT_API
29
        MAX_DEVICES             = 16
30
 
Line 30... Line 31...
30
 
31
	MAX_DEVICES		= 16
31
        DEBUG                   = 1
32
 
Line 32... Line 33...
32
        __DEBUG__               = 1
33
	__DEBUG__		= 1
33
        __DEBUG_LEVEL__         = 2
34
	__DEBUG_LEVEL__ 	= 1	; 1 = all, 2 = errors only
Line 34... Line 35...
34
 
35
 
35
        TX_RING_SIZE            = 4
36
	TX_RING_SIZE		= 4
36
        RX_RING_SIZE            = 4
-
 
Line 37... Line 37...
37
 
37
	RX_RING_SIZE		= 4
38
        ; max time out delay time
38
 
39
        W_MAX_TIMEOUT           = 0x0FFF
39
	; max time out delay time
Line 40... Line 40...
40
 
40
	W_MAX_TIMEOUT		= 0x0FFF
41
        ; Size of the in-memory receive ring.
41
 
42
        RX_BUF_LEN_IDX          = 3     ; 0==8K, 1==16K, 2==32K, 3==64K
42
	; Size of the in-memory receive ring.
43
        RX_BUF_LEN              = (8192 shl RX_BUF_LEN_IDX)
43
	RX_BUF_LEN_IDX		= 3	; 0==8K, 1==16K, 2==32K, 3==64K
Line -... Line 44...
-
 
44
 
-
 
45
	; PCI Tuning Parameters
-
 
46
	; Threshold is bytes transferred to chip before transmission starts.
44
 
47
	TX_FIFO_THRESH		= 256	; In bytes, rounded down to 32 byte units.
45
        ; PCI Tuning Parameters
48
 
46
        ;   Threshold is bytes transferred to chip before transmission starts.
-
 
47
        TX_FIFO_THRESH          = 256   ; In bytes, rounded down to 32 byte units.
-
 
48
 
49
	; The following settings are log_2(bytes)-4:  0 == 16 bytes .. 6==1024.
49
        ; The following settings are log_2(bytes)-4:  0 == 16 bytes .. 6==1024.
50
	RX_FIFO_THRESH		= 4	; Rx buffer level before first PCI transfer.
50
        RX_FIFO_THRESH          = 4     ; Rx buffer level before first PCI xfer.
-
 
51
        RX_DMA_BURST            = 4     ; Maximum PCI burst, '4' is 256 bytes
-
 
52
        TX_DMA_BURST            = 4
-
 
53
 
-
 
Line 54... Line 51...
54
 
51
	RX_DMA_BURST		= 4	; Maximum PCI burst, '4' is 256 bytes
55
include '../struct.inc'
52
	TX_DMA_BURST		= 4
56
include '../macros.inc'
53
 
Line 243... Line 240...
243
MIICR_MOUT              = 0x08
240
MIICR_MOUT		= 0x08
244
MIICR_MDO               = 0x04
241
MIICR_MDO		= 0x04
245
MIICR_MDI               = 0x02
242
MIICR_MDI		= 0x02
246
MIICR_MDC               = 0x01
243
MIICR_MDC		= 0x01
247
; Bits in the EECSR register
244
; Bits in the EECSR register
248
EECSR_EEPR              = 0x80    ; eeprom programed status, 73h means programed
245
EECSR_EEPR		= 0x80	  ; eeprom programmed status, 73h means programmed
249
EECSR_EMBP              = 0x40    ; eeprom embeded programming
246
EECSR_EMBP		= 0x40	  ; eeprom embedded programming
250
EECSR_AUTOLD            = 0x20    ; eeprom content reload
247
EECSR_AUTOLD		= 0x20	  ; eeprom content reload
251
EECSR_DPM               = 0x10    ; eeprom direct programming
248
EECSR_DPM		= 0x10	  ; eeprom direct programming
252
EECSR_CS                = 0x08    ; eeprom CS pin
249
EECSR_CS		= 0x08	  ; eeprom CS pin
253
EECSR_SK                = 0x04    ; eeprom SK pin
250
EECSR_SK		= 0x04	  ; eeprom SK pin
254
EECSR_DI                = 0x02    ; eeprom DI pin
251
EECSR_DI		= 0x02	  ; eeprom DI pin
Line 266... Line 263...
266
BCR1_CTFT0              = 0x08
263
BCR1_CTFT0		= 0x08
267
BCR1_POT2               = 0x04
264
BCR1_POT2		= 0x04
268
BCR1_POT1               = 0x02
265
BCR1_POT1		= 0x02
269
BCR1_POT0               = 0x01
266
BCR1_POT0		= 0x01
270
; Bits in the CFGA register
267
; Bits in the CFGA register
271
CFGA_EELOAD             = 0x80    ; enable eeprom embeded and direct programming
268
CFGA_EELOAD		= 0x80	  ; enable eeprom embedded and direct programming
272
CFGA_JUMPER             = 0x40
269
CFGA_JUMPER		= 0x40
273
CFGA_MTGPIO             = 0x08
270
CFGA_MTGPIO		= 0x08
274
CFGA_T10EN              = 0x02
271
CFGA_T10EN		= 0x02
275
CFGA_AUTO               = 0x01
272
CFGA_AUTO		= 0x01
276
; Bits in the CFGB register
273
; Bits in the CFGB register
Line 480... Line 477...
480
        IntrAbnormalSummary     = 0xC260
477
	IntrAbnormalSummary	= 0xC260
481
        IntrTxDescRace          = 0x080000        ; mapped from IntrStatus2
478
	IntrTxDescRace		= 0x080000	  ; mapped from IntrStatus2
482
        IntrTxErrSummary        = 0x082218
479
	IntrTxErrSummary	= 0x082218
Line 483... Line 480...
483
 
480
 
-
 
481
	DEFAULT_INTR		= (IntrRxDone or IntrRxErr or IntrRxEmpty or IntrRxOverflow or IntrRxDropped or IntrRxNoBuf)
Line -... Line 482...
-
 
482
	RX_BUF_LEN		= (8192 shl RX_BUF_LEN_IDX)
-
 
483
 
-
 
484
struct	rx_head
-
 
485
	status		dd ?
-
 
486
	control 	dd ?
Line 484... Line -...
484
DEFAULT_INTR  = (IntrRxDone or IntrRxErr or IntrRxEmpty or IntrRxOverflow or IntrRxDropped or IntrRxNoBuf)
-
 
485
 
-
 
486
 
487
	buff_addr	dd ?	; address
487
virtual at ebx
-
 
488
 
488
	next_desc	dd ?	;
489
        device:
-
 
490
 
-
 
491
        ETH_DEVICE
-
 
492
 
-
 
493
        .io_addr                dd ?
-
 
494
        .pci_dev                dd ?
-
 
495
        .pci_bus                dd ?
-
 
496
        .revision               db ?
-
 
497
        .irq_line               db ?
-
 
498
        .chip_id                dw ?
-
 
499
 
-
 
500
        .cur_rx                 dw ?
-
 
501
        .cur_tx                 dw ?
-
 
502
        .last_tx                dw ?
-
 
503
 
-
 
504
                                rb 0x100-(($ - device) and 0xff)        ;        align 256
-
 
505
        .tx_ring                rb tx_head.sizeof*TX_RING_SIZE
-
 
506
 
-
 
507
                                rb 0x100-(($ - device) and 0xff)        ;        align 256
-
 
508
        .rx_ring                rb rx_head.sizeof*RX_RING_SIZE
-
 
509
 
489
 
Line 510... Line -...
510
        .size                   = $ - device
-
 
511
 
490
	buff_addr_virt	dd ?
512
end virtual
491
			rd 3	; alignment
513
 
492
ends
514
virtual at 0
493
 
515
        rx_head:
494
struct	tx_head
Line 516... Line 495...
516
        .status         dd ?
495
	status		dd ?
517
        .control        dd ?
496
	control 	dd ?
518
        .buff_addr      dd ?    ; address
-
 
519
        .next_desc      dd ?    ;
497
	buff_addr	dd ?	; address
Line -... Line 498...
-
 
498
	next_desc	dd ?	;
Line 520... Line 499...
520
 
499
 
521
        .buff_addr_virt dd ?
500
	buff_addr_virt	dd ?
522
                        rd 3    ; alignment
501
			rd 3	; alignment
523
        .sizeof:
502
ends
524
end virtual
503
 
525
 
504
struct	device		ETH_DEVICE
Line -... Line 505...
-
 
505
 
526
 
506
	io_addr 	dd ?
-
 
507
	pci_dev 	dd ?
-
 
508
	pci_bus 	dd ?
527
virtual at 0
509
	revision	db ?
528
        tx_head:
510
	irq_line	db ?
529
        .status         dd ?
-
 
Line -... Line 511...
-
 
511
	chip_id 	dw ?
-
 
512
 
Line -... Line 513...
-
 
513
	cur_rx		dw ?
Line 530... Line -...
530
        .control        dd ?
-
 
Line 531... Line 514...
531
        .buff_addr      dd ?    ; address
514
	cur_tx		dw ?
532
        .next_desc      dd ?    ;
515
	last_tx 	dw ?
533
 
516
 
534
        .buff_addr_virt dd ?
517
	rb 0x100 - ($ and 0xff) ; align 256
535
                        rd 3    ; alignment
518
	tx_ring 	rb sizeof.tx_head*TX_RING_SIZE
536
        .sizeof:
519
 
Line 537... Line -...
537
end virtual
-
 
538
 
520
	rb 0x100 - ($ and 0xff) ; align 256
Line 539... Line 521...
539
 
521
	rx_ring 	rb sizeof.rx_head*RX_RING_SIZE
540
 
522
 
541
section '.flat' code readable align 16
-
 
542
 
-
 
Line 543... Line 523...
543
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
523
ends
544
;;                        ;;
524
 
545
;; proc START             ;;
525
 
Line 546... Line 526...
546
;;                        ;;
526
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
547
;; (standard driver proc) ;;
-
 
548
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
527
;;                        ;;
549
 
528
;; proc START             ;;
Line 550... Line 529...
550
align 4
529
;;                        ;;
Line 572... Line 551...
572
;; proc SERVICE_PROC      ;;
551
;; proc SERVICE_PROC      ;;
573
;;                        ;;
552
;;                        ;;
574
;; (standard driver proc) ;;
553
;; (standard driver proc) ;;
575
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
554
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 576... Line -...
576
 
-
 
577
align 4
555
 
Line 578... Line 556...
578
proc service_proc stdcall, ioctl:dword
556
proc service_proc stdcall, ioctl:dword
579
 
557
 
Line 601... Line 579...
601
        cmp     [edx + IOCTL.inp_size], 3               ; Data input must be at least 3 bytes
579
	cmp	[edx + IOCTL.inp_size], 3		; Data input must be at least 3 bytes
602
        jb      .fail
580
	jb	.fail
Line 603... Line 581...
603
 
581
 
604
        mov     eax, [edx + IOCTL.input]
582
	mov	eax, [edx + IOCTL.input]
605
        cmp     byte [eax], 1                           ; 1 means device number and bus number (pci) are given
583
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
Line 606... Line 584...
606
        jne     .fail                                   ; other types arent supported for this card yet
584
	jne	.fail					; other types aren't supported for this card yet
Line 607... Line 585...
607
 
585
 
608
; check if the device is already listed
586
; check if the device is already listed
Line 614... Line 592...
614
 
592
 
615
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
593
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
616
        mov     ax, [eax+1]                             ;
594
	mov	ax, [eax+1]				;
617
  .nextdevice:
595
  .nextdevice:
618
        mov     ebx, [esi]
596
	mov	ebx, [esi]
619
        cmp     al, byte[device.pci_bus]
597
	cmp	al, byte[ebx + device.pci_bus]
620
        jne     @f
598
	jne	@f
621
        cmp     ah, byte[device.pci_dev]
599
	cmp	ah, byte[ebx + device.pci_dev]
622
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
600
	je	.find_devicenum 			; Device is already loaded, let's find it's device number
623
       @@:
601
       @@:
624
        add     esi, 4
602
	add	esi, 4
Line 625... Line 603...
625
        loop    .nextdevice
603
	loop	.nextdevice
626
 
604
 
627
 
605
 
628
; This device doesnt have its own eth_device structure yet, lets create one
606
; This device doesn't have its own eth_device structure yet, lets create one
Line 629... Line 607...
629
  .firstdevice:
607
  .firstdevice:
Line 630... Line 608...
630
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
608
	cmp	[devices], MAX_DEVICES			; First check if the driver can handle one more card
Line 631... Line 609...
631
        jae     .fail
609
	jae	.fail
632
 
610
 
633
        allocate_and_clear ebx, device.size, .fail      ; Allocate the buffer for device structure
611
	allocate_and_clear ebx, sizeof.device, .fail	; Allocate the buffer for device structure
634
 
612
 
Line 635... Line 613...
635
; Fill in the direct call addresses into the struct
613
; Fill in the direct call addresses into the struct
Line 636... Line 614...
636
 
614
 
637
        mov     [device.reset], reset
615
	mov	[ebx + device.reset], reset
638
        mov     [device.transmit], transmit
616
	mov	[ebx + device.transmit], transmit
639
        mov     [device.unload], unload
617
	mov	[ebx + device.unload], unload
640
        mov     [device.name], my_service
618
	mov	[ebx + device.name], my_service
Line 641... Line 619...
641
 
619
 
Line -... Line 620...
-
 
620
; save the pci bus and device numbers
642
; save the pci bus and device numbers
621
 
Line 643... Line 622...
643
 
622
	mov	eax, [edx + IOCTL.input]
Line -... Line 623...
-
 
623
	movzx	ecx, byte[eax+1]
644
        mov     eax, [edx + IOCTL.input]
624
	mov	[ebx + device.pci_bus], ecx
Line 645... Line 625...
645
        movzx   ecx, byte[eax+1]
625
	movzx	ecx, byte[eax+2]
646
        mov     [device.pci_bus], ecx
626
	mov	[ebx + device.pci_dev], ecx
Line 647... Line 627...
647
        movzx   ecx, byte[eax+2]
627
 
648
        mov     [device.pci_dev], ecx
628
; Now, it's time to find the base io address of the PCI device
649
 
629
 
650
; Now, it's time to find the base io addres of the PCI device
630
	stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
Line 651... Line 631...
651
 
631
	mov	[ebx + device.io_addr], eax
652
        PCI_find_io
632
 
653
 
633
; We've found the io address, find IRQ now
Line 654... Line 634...
654
; We've found the io address, find IRQ now
634
 
655
 
635
	invoke	PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
Line 656... Line 636...
656
        PCI_find_irq
636
	mov	[ebx + device.irq_line], al
657
 
637
 
Line 658... Line 638...
658
        DEBUGF  1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
638
	DEBUGF	1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
Line 659... Line 639...
659
        [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
639
	[ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:4
Line 660... Line 640...
660
 
640
 
661
; Ok, the eth_device structure is ready, let's probe the device
641
; Ok, the eth_device structure is ready, let's probe the device
662
        call    probe                                                   ; this function will output in eax
642
	call	probe							; this function will output in eax
663
        test    eax, eax
643
	test	eax, eax
664
        jnz     .err                                                    ; If an error occured, exit
644
	jnz	.err							; If an error occurred, exit
665
 
645
 
666
        mov     eax, [devices]                                          ; Add the device structure to our device list
646
	mov	eax, [devices]						; Add the device structure to our device list
Line 667... Line 647...
667
        mov     [device_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
647
	mov	[device_list+4*eax], ebx				; (IRQ handler uses this list to find device)
Line 668... Line 648...
668
        inc     [devices]                                               ;
648
	inc	[devices]						;
669
 
649
 
Line 670... Line 650...
670
        mov     [device.type], NET_TYPE_ETH
650
	mov	[ebx + device.type], NET_TYPE_ETH
671
        call    NetRegDev
651
	invoke	NetRegDev
Line 672... Line 652...
672
 
652
 
673
        cmp     eax, -1
653
	cmp	eax, -1
674
        je      .destroy
654
	je	.destroy
Line 706... Line 686...
706
;;        Actual Hardware dependent code starts here                      ;;
686
;;        Actual Hardware dependent code starts here                      ;;
707
;;                                                                        ;;
687
;;                                                                        ;;
708
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
688
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
Line -... Line 689...
-
 
689
 
-
 
690
 
-
 
691
;-------
709
 
692
;
-
 
693
; PROBE
710
 
694
;
Line 711... Line -...
711
 
-
 
712
probe:
695
;-------
-
 
696
probe:
Line 713... Line 697...
713
 
697
 
-
 
698
	DEBUGF	1, "Probing\n"
714
        mov     eax, [device.io_addr]
699
 
-
 
700
 
Line 715... Line 701...
715
        DEBUGF  1, "Probing card at 0x%x\n", eax
701
; Make the device a bus master
716
 
702
	invoke	PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
717
; make the card a bus master
703
	or	al, PCI_CMD_MASTER
Line 718... Line 704...
718
        PCI_make_bus_master
704
	invoke	PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
719
 
705
 
720
; get device id
706
; get device id
721
        stdcall PciRead16, [device.pci_bus], [device.pci_dev], PCI_DEVICE_ID
707
	invoke	PciRead16, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.device_id
722
        mov     [device.chip_id], ax
708
	mov	[ebx + device.chip_id], ax
723
 
709
 
724
        mov     esi, chiplist
710
	mov	esi, chiplist
725
  .loop:
711
  .loop:
726
        cmp     word[esi+2], ax
712
	cmp	word[esi+2], ax
727
        je      .got_it
713
	je	.got_it
728
        add     esi, 8
714
	add	esi, 8
729
        cmp     esi, chiplist + 6*8
715
	cmp	esi, chiplist + 6*8
730
        jbe     .loop
716
	jbe	.loop
731
        DEBUGF  2, "Unknown chip: 0x%x, continueing anyway\n", ax
717
	DEBUGF	2, "Unknown chip: 0x%x, continuing anyway\n", ax
Line 732... Line 718...
732
        jmp     .done
718
	jmp	.done
-
 
719
  .got_it:
733
  .got_it:
720
	mov	eax, dword[esi+4]
Line 734... Line 721...
734
        mov     eax, dword[esi+4]
721
	mov	[ebx + device.name], eax
735
        mov     [device.name], eax
722
	DEBUGF	1, "Chip type = %s\n", eax
Line 736... Line 723...
736
        DEBUGF  1, "Chip type = %s\n", eax
723
  .done:
737
  .done:
724
 
738
 
725
; get revision id.
Line 739... Line 726...
739
; get revision id.
726
	invoke	PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.revision_id
740
        PCI_find_rev
727
	mov	[ebx + device.revision], al
Line 741... Line 728...
741
 
728
 
742
        movzx   eax, [device.revision]
729
	movzx	eax, [ebx + device.revision]
743
        DEBUGF  1, "Card revision = 0x%x\n", eax
730
	DEBUGF	1, "Card revision = 0x%x\n", eax
744
 
731
 
745
; D-Link provided reset code (with comment additions)
732
; D-Link provided reset code (with comment additions)
746
        cmp     al, 0x40
733
	cmp	al, 0x40
Line 747... Line 734...
747
        jb      .below_x40
734
	jb	.below_x40
748
 
735
 
749
        mov     ax, [device.chip_id]
736
	mov	ax, [ebx + device.chip_id]
750
        DEBUGF  1, "Enabling Sticky Bit Workaround for Chip_id: 0x%x\n", ax
737
	DEBUGF	1, "Enabling Sticky Bit Workaround for Chip_id: 0x%x\n", ax
751
 
738
 
Line 752... Line 739...
752
        ; clear sticky bit before reset & read ethernet address
739
	; clear sticky bit before reset & read ethernet address
753
        set_io  0
740
	set_io	[ebx + device.io_addr], 0
754
        set_io  bySTICKHW
741
	set_io	[ebx + device.io_addr], bySTICKHW
Line 755... Line 742...
755
        in      al, dx
742
	in	al, dx
756
        and     al, 0xFC
743
	and	al, 0xFC
757
        out     dx, al
744
	out	dx, al
Line 758... Line 745...
758
 
745
 
Line 759... Line 746...
759
        ; (bits written are cleared?)
746
	; (bits written are cleared?)
760
        ; disable force PME-enable
747
	; disable force PME-enable
761
        set_io  byWOLcgClr
748
	set_io	[ebx + device.io_addr], byWOLcgClr
762
        mov     al, 0x80
749
	mov	al, 0x80
763
        out     dx, al
750
	out	dx, al
Line 764... Line 751...
764
 
751
 
765
        ; disable power-event config bit
752
	; disable power-event config bit
766
        mov     al, 0xFF
753
	mov	al, 0xFF
767
        out     dx, al
754
	out	dx, al
768
 
755
 
769
        ; clear power status (undocumented in vt6102 docs?)
756
	; clear power status (undocumented in vt6102 docs?)
Line 770... Line 757...
770
        set_io  byPwrcsrClr
757
	set_io	[ebx + device.io_addr], byPwrcsrClr
771
        out     dx, al
758
	out	dx, al
772
 
759
 
Line 794... Line 781...
794
        loop    .poll_again
781
	loop	.poll_again
795
        DEBUGF  1, "Soft reset timeout!\n"
782
	DEBUGF	1, "Soft reset timeout!\n"
796
   @@:
783
   @@:
Line 797... Line 784...
797
 
784
 
798
; issue AUTOLoad in EECSR to reload eeprom
785
; issue AUTOLoad in EECSR to reload eeprom
799
        set_io  byEECSR
786
	set_io	[ebx + device.io_addr], byEECSR
800
        mov     al, 0x20
787
	mov	al, 0x20
Line 801... Line 788...
801
        out     dx, al
788
	out	dx, al
802
 
789
 
803
; if vt3065 delay after reset
790
; if vt3065 delay after reset
Line 804... Line 791...
804
        cmp     [device.revision], 0x40
791
	cmp	[ebx + device.revision], 0x40
805
        jb      .not_vt3065
792
	jb	.not_vt3065
806
 
793
 
Line 807... Line 794...
807
        ; delay 8ms to let MAC stable
794
	; delay 10ms to let MAC stable
808
        mov     esi, 8 ; 8ms
795
	mov	esi, 1 ; 10ms
809
        call    Sleep
796
	invoke	Sleep
Line 810... Line 797...
810
 
797
 
811
        ; for 3065D, EEPROM reloaded will cause bit 0 in MAC_REG_CFGA
798
	; for 3065D, EEPROM reloaded will cause bit 0 in MAC_REG_CFGA
812
        ; turned on.  it makes MAC receive magic packet
799
	; turned on.  it makes MAC receive magic packet
813
        ; automatically. So, we turn it off. (D-Link)
800
	; automatically. So, we turn it off. (D-Link)
Line 814... Line 801...
814
 
801
 
815
        set_io  byCFGA
802
	set_io	[ebx + device.io_addr], byCFGA
816
        in      al, dx
803
	in	al, dx
817
        and     al, 0xFE
804
	and	al, 0xFE
818
        out     dx, al
805
	out	dx, al
Line 819... Line 806...
819
 
806
 
820
        ; turn on bit2 in PCI configuration register 0x53 , only for 3065
807
	; turn on bit2 in PCI configuration register 0x53 , only for 3065
821
        stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REG_MODE3
808
	invoke	PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_REG_MODE3
822
        or      al,  MODE3_MIION
809
	or	al, MODE3_MIION
823
        stdcall PciWrite8, [device.pci_bus], [device.pci_dev], PCI_REG_MODE3, eax
810
	invoke	PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_REG_MODE3, eax
824
  .not_vt3065:
811
  .not_vt3065:
Line 825... Line 812...
825
 
812
 
Line 841... Line 828...
841
 
828
 
Line 842... Line 829...
842
        DEBUGF  1, "Analyzing Media type, this may take several seconds"
829
	DEBUGF	1, "Analyzing Media type, this may take several seconds"
843
 
830
 
844
        mov     ecx, 5
-
 
845
     .read_again:
831
	mov	ecx, 5
846
        DEBUGF  1, "."
832
     .read_again:
Line 847... Line 833...
847
        mov     esi, 1
833
	mov	esi, 1
848
        call    Sleep
834
	invoke	Sleep
849
 
835
 
850
        stdcall ReadMII, 1
836
	stdcall ReadMII, 1
851
        test    eax, 0x0020
837
	test	eax, 0x0020
852
        jnz     .read_done
838
	jnz	.read_done
853
        loop    .read_again
839
	loop	.read_again
Line 854... Line 840...
854
        DEBUGF  1, "timeout!\n"
840
	DEBUGF	1, "timeout!\n"
Line 855... Line 841...
855
     .read_done:
841
     .read_done:
856
        DEBUGF  1, " OK\n"
842
	DEBUGF	1, "OK\n"
857
 
843
 
858
if DEBUG
844
if 0
859
 
845
 
Line 860... Line 846...
860
        set_io  0
846
	set_io	[ebx + device.io_addr], 0
Line 873... Line 859...
873
        DEBUGF  1, "link 0x%x\n", ax
859
	DEBUGF	1, "link 0x%x\n", ax
Line 874... Line 860...
874
 
860
 
Line 875... Line 861...
875
end if
861
end if
876
 
862
 
877
; query MII to know LineSpeed, duplex mode
863
; query MII to know LineSpeed, duplex mode
878
        set_io  0
864
	set_io	[ebx + device.io_addr], 0
879
        set_io  MIIStatus
865
	set_io	[ebx + device.io_addr], MIIStatus
880
        in      al, dx
866
	in	al, dx
881
        test    al, MIISR_SPEED
867
	test	al, MIISR_SPEED
882
        jz      .100mbps
868
	jz	.100mbps
Line 891... Line 877...
891
 
877
 
892
        test    eax, 1
878
	test	eax, 1
Line 893... Line 879...
893
        jz      .halfduplex
879
	jz	.halfduplex
894
 
880
 
895
        DEBUGF  1, "Fullduplex\n"
881
	DEBUGF	1, "Fullduplex\n"
896
        set_io  0
882
	set_io	[ebx + device.io_addr], 0
897
        set_io  byCR0
883
	set_io	[ebx + device.io_addr], byCR0
898
        mov     ax, CR_FDX
884
	mov	ax, CR_FDX
Line 899... Line 885...
899
        out     dx, ax
885
	out	dx, ax
900
        jmp     @f
886
	jmp	@f
901
 
887
 
Line 902... Line 888...
902
    .halfduplex:
888
    .halfduplex:
903
        DEBUGF  1, "Halfduplex\n"
889
	DEBUGF	1, "Halfduplex\n"
904
    @@:
890
    @@:
905
 
891
 
906
; set MII 10 FULL ON, only apply in vt3043
892
; set MII 10 FULL ON, only apply in vt3043
Line 907... Line 893...
907
        cmp     [device.chip_id], 0x3043
893
	cmp	[ebx + device.chip_id], 0x3043
908
        jne     @f
894
	jne	@f
909
        stdcall WriteMII, 0x17, 1 shl 1, 1
895
	stdcall WriteMII, 0x17, 1 shl 1, 1
910
    @@:
896
    @@:
911
 
897
 
912
; turn on MII link change
898
; turn on MII link change
913
        set_io  0
899
	set_io	[ebx + device.io_addr], 0
Line 914... Line 900...
914
        set_io  byMIICR
900
	set_io	[ebx + device.io_addr], byMIICR
Line 915... Line 901...
915
        in      al, dx
901
	in	al, dx
916
        and     al, 0x7F
902
	and	al, 0x7F
917
        out     dx, al
903
	out	dx, al
Line 918... Line 904...
918
        push    eax
904
	push	eax
Line 919... Line 905...
919
 
905
 
920
        call    MIIDelay
906
	call	MIIDelay
921
 
907
 
922
        set_io  byMIIAD
908
	set_io	[ebx + device.io_addr], byMIIAD
Line 923... Line 909...
923
        mov     al, 0x41
909
	mov	al, 0x41
924
        out     dx, al
910
	out	dx, al
925
 
911
 
Line 937... Line 923...
937
reset:
923
reset:
Line 938... Line 924...
938
 
924
 
Line 939... Line 925...
939
        DEBUGF  1, "reset\n"
925
	DEBUGF	1, "reset\n"
940
 
-
 
941
; attach int handler
926
 
942
 
927
; attach int handler
943
        movzx   eax, [device.irq_line]
928
	movzx	eax, [ebx + device.irq_line]
944
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
929
	DEBUGF	1,"Attaching int handler to irq %x\n", eax:1
945
        stdcall AttachIntHandler, eax, int_handler, dword 0
930
	invoke	AttachIntHandler, eax, int_handler, ebx
946
        test    eax, eax
931
	test	eax, eax
947
        jnz     @f
932
	jnz	@f
948
        DEBUGF  2,"\nCould not attach int handler!\n"
933
	DEBUGF	2,"Could not attach int handler!\n"
949
;        or      eax, -1
934
	or	eax, -1
Line 950... Line 935...
950
;        ret
935
	ret
951
       @@:
936
       @@:
952
 
937
 
953
; Soft reset the chip.
938
; Soft reset the chip.
954
        set_io  0
939
	set_io	[ebx + device.io_addr], 0
Line 955... Line 940...
955
        set_io  byCR0
940
	set_io	[ebx + device.io_addr], byCR0
Line 956... Line 941...
956
        mov     ax, CR_SFRST
941
	mov	ax, CR_SFRST
957
        out     dx, ax
942
	out	dx, ax
Line 958... Line 943...
958
 
943
 
959
        call    MIIDelay
944
	call	MIIDelay
Line 960... Line 945...
960
 
945
 
961
; Initialize rings
946
; Initialize rings
962
        call    init_ring
947
	call	init_ring
963
 
948
 
964
; Setup Multicast
949
; Set Multicast
Line 965... Line 950...
965
        call    set_rx_mode
950
	call	set_rx_mode
966
 
951
 
967
; set TCR RCR threshold to store and forward
952
; set TCR RCR threshold to store and forward
Line 968... Line 953...
968
        set_io  0
953
	set_io	[ebx + device.io_addr], 0
969
        set_io  byBCR0
954
	set_io	[ebx + device.io_addr], byBCR0
970
        mov     al, 0x3E
955
	mov	al, 0x3E
Line 971... Line 956...
971
        out     dx, al
956
	out	dx, al
972
 
957
 
973
        set_io  byBCR1
958
	set_io	[ebx + device.io_addr], byBCR1
Line 974... Line 959...
974
        mov     al, 0x38
959
	mov	al, 0x38
Line 975... Line 960...
975
        out     dx, al
960
	out	dx, al
976
 
961
 
977
        set_io  byRCR
962
	set_io	[ebx + device.io_addr], byRCR
Line 978... Line 963...
978
        mov     al, 0x2C
963
	mov	al, 0x2C
979
        out     dx, al
964
	out	dx, al
980
 
965
 
981
        set_io  byTCR
966
	set_io	[ebx + device.io_addr], byTCR
Line 982... Line 967...
982
        mov     al, 0x60
967
	mov	al, 0x60
983
        out     dx, al
968
	out	dx, al
984
 
969
 
985
; Set Fulldupex
970
; Set Fulldupex
Line 986... Line 971...
986
 
971
 
987
        call    QueryAuto
972
	call	QueryAuto
988
        test    eax, eax        ; full duplex?
973
	test	eax, eax	; full duplex?
989
        jz      @f
974
	jz	@f
990
 
975
 
Line 991... Line 976...
991
        set_io  0
976
	set_io	[ebx + device.io_addr], 0
Line 992... Line 977...
992
        set_io  byCFGD
977
	set_io	[ebx + device.io_addr], byCFGD
993
        mov     al, CFGD_CFDX
978
	mov	al, CFGD_CFDX
994
        out     dx, al
979
	out	dx, al
995
 
980
 
996
        set_io  byCR0
981
	set_io	[ebx + device.io_addr], byCR0
Line 997... Line 982...
997
        mov     ax, CR_FDX
982
	mov	ax, CR_FDX
998
        out     dx, ax
983
	out	dx, ax
Line 999... Line 984...
999
    @@:
984
    @@:
1000
 
985
 
Line 1001... Line 986...
1001
; ENABLE interrupts
986
; ENABLE interrupts
1002
        set_io  0
987
	set_io	[ebx + device.io_addr], 0
1003
        set_io  byIMR0
988
	set_io	[ebx + device.io_addr], byIMR0
Line 1030... Line 1015...
1030
        call    reset
1015
	call	reset
1031
        push    eax edx
1016
	push	eax edx
1032
        DEBUGF  1, "rhine disable\n"
1017
	DEBUGF	1, "rhine disable\n"
Line 1033... Line 1018...
1033
 
1018
 
1034
        ; Switch to loopback mode to avoid hardware races.
1019
	; Switch to loopback mode to avoid hardware races.
1035
        set_io  0
1020
	set_io	[ebx + device.io_addr], 0
1036
        set_io  byTCR
1021
	set_io	[ebx + device.io_addr], byTCR
1037
        mov     al, 0x61
1022
	mov	al, 0x61
Line 1038... Line 1023...
1038
        out     dx, al
1023
	out	dx, al
1039
 
1024
 
1040
        ; Stop the chip's Tx and Rx processes.
1025
	; Stop the chip's Tx and Rx processes.
1041
        set_io  byCR0
1026
	set_io	[ebx + device.io_addr], byCR0
1042
        mov     ax, CR_STOP
1027
	mov	ax, CR_STOP
Line 1043... Line 1028...
1043
        out     dx, ax
1028
	out	dx, ax
Line 1051... Line 1036...
1051
align 4
1036
align 4
1052
reload_eeprom:
1037
reload_eeprom:
Line 1053... Line 1038...
1053
 
1038
 
Line 1054... Line 1039...
1054
        DEBUGF  1, "Reload eeprom\n"
1039
	DEBUGF	1, "Reload eeprom\n"
1055
 
1040
 
1056
        set_io  0
1041
	set_io	[ebx + device.io_addr], 0
1057
        set_io  byEECSR
1042
	set_io	[ebx + device.io_addr], byEECSR
1058
        mov     al, 0x20
1043
	mov	al, 0x20
1059
        out     dx, al
1044
	out	dx, al
1060
        ; Typically 2 cycles to reload.
1045
	; Typically 2 cycles to reload.
1061
        mov     ecx, 150
1046
	mov	ecx, 150
1062
  .reload:
1047
  .reload:
1063
        in      al, dx
1048
	in	al, dx
1064
        test    al, 0x20
1049
	test	al, 0x20
1065
        jz      @f
1050
	jz	@f
1066
        loop    .reload
1051
	loop	.reload
Line 1067... Line 1052...
1067
        DEBUGF  1, "Reload timeout!\n"
1052
	DEBUGF	2, "Reload eeprom: timeout!\n"
Line -... Line 1053...
-
 
1053
  @@:
-
 
1054
 
1068
  @@:
1055
	ret
1069
 
1056
 
1070
        ret
1057
 
Line 1071... Line 1058...
1071
 
1058
 
Line 1072... Line 1059...
1072
; Initialize the Rx and Tx rings, along with various 'dev' bits.
1059
; Initialize the Rx and Tx rings, along with various 'dev' bits.
1073
align 4
1060
align 4
1074
init_ring:
1061
init_ring:
1075
 
1062
 
1076
        DEBUGF  1, "Init ring\n"
1063
	DEBUGF	1, "Init ring\n"
1077
 
1064
 
1078
        lea     edi, [device.rx_ring]
1065
	lea	edi, [ebx + device.rx_ring]
1079
        mov     eax, edi
1066
	mov	eax, edi
1080
        GetRealAddr
1067
	invoke	GetPhysAddr
1081
        mov     esi, eax
1068
	mov	esi, eax
1082
        push    esi
1069
	push	esi
1083
        mov     ecx, RX_RING_SIZE
1070
	mov	ecx, RX_RING_SIZE
1084
   .rx_init:
1071
   .rx_init:
1085
        add     esi, rx_head.sizeof
1072
	add	esi, sizeof.rx_head
1086
        mov     [edi + rx_head.status], RX_SBITS_OWN_BIT
1073
	mov	[edi + rx_head.status], RX_SBITS_OWN_BIT
1087
        mov     [edi + rx_head.control], PKT_BUF_SZ
1074
	mov	[edi + rx_head.control], PKT_BUF_SZ
1088
        push    ecx
1075
	push	ecx
1089
        stdcall KernelAlloc, PKT_BUF_SZ
1076
	invoke	KernelAlloc, PKT_BUF_SZ
1090
        pop     ecx
1077
	pop	ecx
1091
        mov     [edi + rx_head.buff_addr_virt], eax
1078
	mov	[edi + rx_head.buff_addr_virt], eax
1092
        GetRealAddr
1079
	invoke	GetPhysAddr
Line 1093... Line 1080...
1093
        mov     [edi + rx_head.buff_addr], eax                        ; buffer ptr
1080
	mov	[edi + rx_head.buff_addr], eax			      ; buffer ptr
1094
        mov     [edi + rx_head.next_desc], esi                        ; next head
1081
	mov	[edi + rx_head.next_desc], esi			      ; next head
1095
        add     edi, rx_head.sizeof
1082
	add	edi, sizeof.rx_head
1096
        dec     ecx
1083
	dec	ecx
1097
        jnz     .rx_init
1084
	jnz	.rx_init
1098
        pop     [edi - rx_head.sizeof + rx_head.next_desc]            ; Mark the last entry as wrapping the ring.
1085
	pop	[edi - sizeof.rx_head + rx_head.next_desc]	      ; Mark the last entry as wrapping the ring.
1099
 
1086
 
1100
 
1087
 
1101
        lea     edi, [device.tx_ring]
1088
	lea	edi, [ebx + device.tx_ring]
1102
        mov     eax, edi
1089
	mov	eax, edi
1103
        GetRealAddr
1090
	invoke	GetPhysAddr
1104
        mov     esi, eax
1091
	mov	esi, eax
1105
        push    esi
1092
	push	esi
1106
        mov     ecx, TX_RING_SIZE
1093
	mov	ecx, TX_RING_SIZE
1107
   .tx_init:
1094
   .tx_init:
1108
        add     esi, tx_head.sizeof
1095
	add	esi, sizeof.tx_head
1109
        mov     [edi + tx_head.status], 0
1096
	mov	[edi + tx_head.status], 0
Line 1110... Line 1097...
1110
        mov     [edi + tx_head.control], 0x00E08000
1097
	mov	[edi + tx_head.control], 0x00E08000
1111
        mov     [edi + tx_head.buff_addr], 0
1098
	mov	[edi + tx_head.buff_addr], 0
1112
        mov     [edi + tx_head.next_desc], esi
1099
	mov	[edi + tx_head.next_desc], esi
1113
        mov     [edi + tx_head.buff_addr_virt], 0
1100
	mov	[edi + tx_head.buff_addr_virt], 0
1114
        add     edi, tx_head.sizeof
1101
	add	edi, sizeof.tx_head
1115
        dec     ecx
1102
	dec	ecx
Line 1116... Line 1103...
1116
        jnz     .tx_init
1103
	jnz	.tx_init
1117
        pop     [edi - tx_head.sizeof + tx_head.next_desc]              ; Mark the last entry as wrapping the ring.
1104
	pop	[edi - sizeof.tx_head + tx_head.next_desc]		; Mark the last entry as wrapping the ring.
1118
 
1105
 
1119
; write Descriptors to MAC
1106
; write Descriptors to MAC
Line 1120... Line 1107...
1120
        lea     eax, [device.rx_ring]
1107
	lea	eax, [ebx + device.rx_ring]
1121
        GetRealAddr
1108
	invoke	GetPhysAddr
1122
        set_io  0
1109
	set_io	[ebx + device.io_addr], 0
1123
        set_io  dwCurrentRxDescAddr
1110
	set_io	[ebx + device.io_addr], dwCurrentRxDescAddr
Line 1124... Line 1111...
1124
        out     dx, eax
1111
	out	dx, eax
Line 1125... Line 1112...
1125
 
1112
 
Line 1167... Line 1154...
1167
 
1154
 
Line 1168... Line 1155...
1168
;        DEBUGF  1, "ReadMII Index=%x\n", [byMIIIndex]
1155
;        DEBUGF  1, "ReadMII Index=%x\n", [byMIIIndex]
Line 1169... Line 1156...
1169
 
1156
 
1170
        push    esi ebx ecx edx
1157
	push	esi ebx ecx edx
1171
 
1158
 
1172
        set_io  0
1159
	set_io	[ebx + device.io_addr], 0
Line 1173... Line 1160...
1173
        set_io  byMIIAD
1160
	set_io	[ebx + device.io_addr], byMIIAD
1174
        in      al, dx
1161
	in	al, dx
1175
        mov     bl, al
1162
	mov	bl, al
1176
 
1163
 
1177
        set_io  byMIICR
1164
	set_io	[ebx + device.io_addr], byMIICR
Line 1178... Line 1165...
1178
        in      al, dx
1165
	in	al, dx
Line 1179... Line 1166...
1179
        mov     bh, al
1166
	mov	bh, al
1180
        and     al, 0x7F
1167
	and	al, 0x7F
1181
        out     dx, al
1168
	out	dx, al
Line 1182... Line 1169...
1182
 
1169
 
Line 1183... Line 1170...
1183
        call    MIIDelay
1170
	call	MIIDelay
1184
 
1171
 
1185
        mov     al, byte [byMIIIndex]
1172
	mov	al, byte [byMIIIndex]
1186
        set_io  byMIIAD
1173
	set_io	[ebx + device.io_addr], byMIIAD
Line 1187... Line 1174...
1187
        out     dx, al
1174
	out	dx, al
Line 1198... Line 1185...
1198
        in      al, dx
1185
	in	al, dx
1199
        test    al, 0x40
1186
	test	al, 0x40
1200
        jz      @f
1187
	jz	@f
Line 1201... Line 1188...
1201
 
1188
 
1202
        mov     esi, 10
1189
	mov	esi, 10
1203
        call    Sleep
1190
	invoke	Sleep
1204
        dec     ecx
1191
	dec	ecx
1205
        jnz     .read_again
1192
	jnz	.read_again
1206
        DEBUGF  1, "\nReadMII timeout!\n"
1193
	DEBUGF	2, "ReadMII: timeout!\n"
Line 1207... Line 1194...
1207
  @@:
1194
  @@:
Line 1208... Line 1195...
1208
 
1195
 
1209
        call    MIIDelay
1196
	call	MIIDelay
Line 1210... Line 1197...
1210
 
1197
 
1211
        set_io  byMIIAD
1198
	set_io	[ebx + device.io_addr], byMIIAD
1212
        in      ax, dx
1199
	in	ax, dx
1213
 
1200
 
Line 1214... Line 1201...
1214
        push    eax
1201
	push	eax
1215
        mov     ax, bx
1202
	mov	ax, bx
1216
        set_io  byMIIAD
1203
	set_io	[ebx + device.io_addr], byMIIAD
Line 1217... Line 1204...
1217
        out     dx, al
1204
	out	dx, al
Line 1218... Line 1205...
1218
 
1205
 
1219
        shr     ax, 8
1206
	shr	ax, 8
1220
        set_io  byMIICR
1207
	set_io	[ebx + device.io_addr], byMIICR
Line 1221... Line 1208...
1221
        out     dx, al
1208
	out	dx, al
1222
 
1209
 
1223
        call    MIIDelay
1210
	call	MIIDelay
Line -... Line 1211...
-
 
1211
 
-
 
1212
	pop	eax
1224
 
1213
	and	eax, 0xFFFF
Line 1225... Line 1214...
1225
        pop     eax
1214
	rol	ax, 8
Line 1226... Line 1215...
1226
        and     eax, 0xFFFF
1215
 
Line 1227... Line 1216...
1227
        rol     ax, 8           ;;;;; I dont know how or why but it seems needed...
1216
	pop	edx ecx ebx esi
1228
 
1217
	ret
1229
        pop     edx ecx ebx esi
1218
endp
1230
        ret
1219
 
Line 1231... Line 1220...
1231
endp
1220
 
1232
 
1221
 
1233
proc    WriteMII stdcall, byMIISetByte:dword, byMIISetBit:dword, byMIIOP:dword
1222
proc	WriteMII stdcall, byMIISetByte:dword, byMIISetBit:dword, byMIIOP:dword
1234
 
1223
 
1235
;        DEBUGF  1, "WriteMII SetByte=%x SetBit=%x OP=%x\n", [byMIISetByte], [byMIISetBit], [byMIIOP]
1224
;        DEBUGF  1, "WriteMII SetByte=%x SetBit=%x OP=%x\n", [byMIISetByte], [byMIISetBit], [byMIIOP]
Line 1236... Line 1225...
1236
 
1225
 
Line 1237... Line 1226...
1237
        push    ebx eax ecx edx
1226
	push	ebx eax ecx edx
1238
 
1227
 
1239
        set_io  0
1228
	set_io	[ebx + device.io_addr], 0
Line 1240... Line 1229...
1240
        set_io  byMIIAD
1229
	set_io	[ebx + device.io_addr], byMIIAD
Line 1241... Line 1230...
1241
        in      al, dx
1230
	in	al, dx
1242
        mov     bl, al
1231
	mov	bl, al
1243
 
1232
 
1244
        set_io  byMIICR
1233
	set_io	[ebx + device.io_addr], byMIICR
Line 1245... Line 1234...
1245
        in      al, dx
1234
	in	al, dx
Line 1265... Line 1254...
1265
        in      al, dx
1254
	in	al, dx
1266
        test    al, 0x40
1255
	test	al, 0x40
1267
        jz      .done
1256
	jz	.done
Line 1268... Line 1257...
1268
 
1257
 
1269
        mov     esi, 10
1258
	mov	esi, 10
1270
        call    Sleep
1259
	invoke	Sleep
1271
        dec     ecx
1260
	dec	ecx
1272
        jnz     .read_again0
1261
	jnz	.read_again0
1273
        DEBUGF  1, "WriteMII timeout 1\n"
1262
	DEBUGF	2, "WriteMII: timeout (1)\n"
Line 1274... Line 1263...
1274
  .done:
1263
  .done:
Line 1275... Line 1264...
1275
 
1264
 
1276
        call    MIIDelay
1265
	call	MIIDelay
Line 1277... Line 1266...
1277
 
1266
 
1278
        set_io  wMIIDATA
1267
	set_io	[ebx + device.io_addr], wMIIDATA
Line 1279... Line 1268...
1279
        in      ax, dx
1268
	in	ax, dx
1280
 
1269
 
1281
        mov     ecx, [byMIISetBit]
1270
	mov	ecx, [byMIISetBit]
1282
        rol     cx, 8                   ;;;;;;;;;;;;;;;;; CHECKME
1271
	rol	cx, 8
1283
 
1272
 
1284
        cmp     byte [byMIIOP], 0
1273
	cmp	byte [byMIIOP], 0
1285
        jne     @f
1274
	jne	@f
1286
        not     ecx
1275
	not	ecx
Line 1287... Line 1276...
1287
        and     ax, cx
1276
	and	ax, cx
1288
        jmp     .end_mascarad
1277
	jmp	.end_mascarad
Line 1289... Line 1278...
1289
     @@:
1278
     @@:
Line 1290... Line 1279...
1290
        or      ax, cx
1279
	or	ax, cx
1291
     .end_mascarad:
1280
     .end_mascarad:
1292
 
1281
 
1293
        set_io  wMIIDATA
1282
	set_io	[ebx + device.io_addr], wMIIDATA
Line 1294... Line 1283...
1294
        out     dx, ax
1283
	out	dx, ax
Line 1305... Line 1294...
1305
        in      al, dx
1294
	in	al, dx
1306
        test    al, 0x20
1295
	test	al, 0x20
1307
        jz      @f
1296
	jz	@f
Line 1308... Line 1297...
1308
 
1297
 
1309
        mov     esi, 10
1298
	mov	esi, 10
1310
        call    Sleep
1299
	invoke	Sleep
1311
        dec     ecx
1300
	dec	ecx
1312
        jnz     .read_again1
1301
	jnz	.read_again1
1313
        DEBUGF  1, "WriteMII timeout 2\n"
1302
	DEBUGF	2, "WriteMII timeout (2)\n"
Line 1314... Line 1303...
1314
    @@:
1303
    @@:
Line 1315... Line 1304...
1315
 
1304
 
1316
        call    MIIDelay
1305
	call	MIIDelay
1317
 
1306
 
1318
        mov     ax, bx
1307
	mov	ax, bx
Line 1319... Line 1308...
1319
        and     al, 0x7F
1308
	and	al, 0x7F
1320
        set_io  byMIIAD
1309
	set_io	[ebx + device.io_addr], byMIIAD
1321
        out     dx, al
1310
	out	dx, al
Line 1322... Line 1311...
1322
 
1311
 
Line 1323... Line 1312...
1323
        shr     ax, 8
1312
	shr	ax, 8
Line 1350... Line 1339...
1350
 
1339
 
Line 1351... Line 1340...
1351
        DEBUGF  1, "Set RX mode\n"
1340
	DEBUGF	1, "Set RX mode\n"
1352
 
1341
 
1353
        ; ! IFF_PROMISC
1342
	; ! IFF_PROMISC
1354
        mov     eax, 0xffffffff
1343
	mov	eax, 0xffffffff
1355
        set_io  0
1344
	set_io	[ebx + device.io_addr], 0
Line 1356... Line 1345...
1356
        set_io  byMAR0
1345
	set_io	[ebx + device.io_addr], byMAR0
1357
        out     dx, eax
1346
	out	dx, eax
Line 1358... Line 1347...
1358
 
1347
 
1359
        set_io  byMAR4
1348
	set_io	[ebx + device.io_addr], byMAR4
1360
        out     dx, eax
1349
	out	dx, eax
Line 1361... Line 1350...
1361
 
1350
 
Line 1370... Line 1359...
1370
 
1359
 
1371
 
1360
 
1372
; Beware of PCI posted writes
1361
; Beware of PCI posted writes
1373
macro IOSYNC
1362
macro IOSYNC
1374
{
1363
{
1375
        set_io  StationAddr
1364
	set_io	[ebx + device.io_addr], StationAddr
Line 1376... Line 1365...
1376
        in      al, dx
1365
	in	al, dx
1377
}
1366
}
Line 1378... Line 1367...
1378
 
1367
 
1379
 
1368
 
1380
 
1369
 
1381
align 4
1370
align 4
1382
read_mac:
1371
read_mac:
1383
 
1372
 
1384
        lea     edi, [device.mac]
1373
	lea	edi, [ebx + device.mac]
1385
        set_io  0
1374
	set_io	[ebx + device.io_addr], 0
1386
        set_io  byPAR0
1375
	set_io	[ebx + device.io_addr], byPAR0
1387
        mov     ecx, 6
1376
	mov	ecx, 6
Line 1388... Line 1377...
1388
  .next:
1377
  .next:
1389
        in      al, dx
1378
	in	al, dx
Line 1390... Line 1379...
1390
        stosb
1379
	stosb
Line 1407... Line 1396...
1407
;;     size of buffer in [esp+8]           ;;
1396
;;     size of buffer in [esp+8]           ;;
1408
;;     pointer to device structure in ebx  ;;
1397
;;     pointer to device structure in ebx  ;;
1409
;;                                         ;;
1398
;;                                         ;;
1410
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1399
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1411
align 4
1400
align 4
-
 
1401
proc transmit stdcall bufferptr, buffersize
-
 
1402
 
1412
transmit:
1403
	pushf
-
 
1404
	cli
-
 
1405
 
1413
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
1406
	DEBUGF	1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
1414
        mov     eax, [esp+4]
1407
	mov	eax, [bufferptr]
1415
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1408
	DEBUGF	1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1416
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1409
	[eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1417
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1410
	[eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1418
        [eax+13]:2,[eax+12]:2
1411
	[eax+13]:2,[eax+12]:2
Line 1419... Line 1412...
1419
 
1412
 
1420
        cmp     dword [esp+8], 1514
1413
	cmp	[buffersize], 1514
1421
        ja      .fail
1414
	ja	.fail
1422
        cmp     dword [esp+8], 60
1415
	cmp	[buffersize], 60
Line 1423... Line 1416...
1423
        jb      .fail
1416
	jb	.fail
1424
 
1417
 
1425
        movzx   eax, [device.cur_tx]
1418
	movzx	eax, [ebx + device.cur_tx]
1426
        mov     ecx, tx_head.sizeof
1419
	mov	ecx, sizeof.tx_head
1427
        mul     ecx
1420
	mul	ecx
Line 1428... Line 1421...
1428
        lea     edi, [device.tx_ring]
1421
	lea	edi, [ebx + device.tx_ring]
1429
        add     edi, eax
1422
	add	edi, eax
Line 1430... Line 1423...
1430
 
1423
 
1431
        cmp     [edi + tx_head.buff_addr_virt], 0
1424
	cmp	[edi + tx_head.buff_addr_virt], 0
1432
        jne     .fail
1425
	jne	.fail
1433
 
1426
 
1434
        mov     eax, [esp+4]
1427
	mov	eax, [bufferptr]
1435
        mov     [edi + tx_head.buff_addr_virt], eax
1428
	mov	[edi + tx_head.buff_addr_virt], eax
1436
        GetRealAddr
1429
	invoke	GetPhysAddr
1437
        mov     [edi + tx_head.buff_addr], eax
1430
	mov	[edi + tx_head.buff_addr], eax
1438
        mov     ecx, [esp+8]
1431
	mov	ecx, [buffersize]
Line 1439... Line 1432...
1439
        and     ecx, TX_CBITS_TX_BUF_SIZE
1432
	and	ecx, TX_CBITS_TX_BUF_SIZE
1440
        or      ecx,  0x00E08000
1433
	or	ecx,  0x00E08000
1441
        mov     [edi + tx_head.control], ecx
1434
	mov	[edi + tx_head.control], ecx
1442
        or      [edi + tx_head.status], TX_SBITS_OWN_BIT
1435
	or	[edi + tx_head.status], TX_SBITS_OWN_BIT
1443
 
1436
 
Line 1444... Line 1437...
1444
        set_io  0
1437
	set_io	[ebx + device.io_addr], 0
1445
        set_io  byCR1
1438
	set_io	[ebx + device.io_addr], byCR1
Line 1446... Line 1439...
1446
        in      al, dx
1439
	in	al, dx
Line 1447... Line 1440...
1447
        or      al, CR1_TDMD1
1440
	or	al, CR1_TDMD1
1448
        out     dx, al
1441
	out	dx, al
1449
 
1442
 
1450
        inc     [device.cur_tx]
1443
	inc	[ebx + device.cur_tx]
1451
        and     [device.cur_tx], TX_RING_SIZE-1
1444
	and	[ebx + device.cur_tx], TX_RING_SIZE-1
Line 1452... Line 1445...
1452
 
1445
 
-
 
1446
	;outw(IMRShadow,byIMR0); ;
1453
        ;outw(IMRShadow,byIMR0); ;
1447
 
-
 
1448
; Update stats
Line 1454... Line 1449...
1454
 
1449
	inc	[ebx + device.packets_tx]
1455
; Update stats
1450
	mov	ecx, [buffersize]
1456
        inc     [device.packets_tx]
1451
	add	dword [ebx + device.bytes_tx], ecx
1457
        mov     ecx, [esp+8]    ;;;;;
-
 
-
 
1452
	adc	dword [ebx + device.bytes_tx + 4], 0
1458
        add     dword [device.bytes_tx], ecx
1453
 
1459
        adc     dword [device.bytes_tx + 4], 0
-
 
1460
 
-
 
1461
        xor     eax, eax        ; Transmit succesfull
-
 
1462
        ret     8
1454
	DEBUGF	1,"Transmit OK\n"
Line -... Line 1455...
-
 
1455
	popf
Line 1463... Line 1456...
1463
 
1456
	xor	eax, eax
1464
  .fail:
1457
	ret
Line 1485... Line 1478...
1485
 
1478
 
Line 1486... Line 1479...
1486
        push    ebx esi edi
1479
	push	ebx esi edi
Line 1487... Line 1480...
1487
 
1480
 
Line 1488... Line 1481...
1488
        DEBUGF  1,"INT\n"
1481
	DEBUGF	1,"INT\n"
1489
 
1482
 
1490
; Find pointer of device wich made IRQ occur
1483
; Find pointer of device which made IRQ occur
1491
 
1484
 
1492
        mov     ecx, [devices]
1485
	mov	ecx, [devices]
1493
        test    ecx, ecx
1486
	test	ecx, ecx
Line 1494... Line 1487...
1494
        jz      .nothing
1487
	jz	.nothing
1495
        mov     esi, device_list
1488
	mov	esi, device_list
1496
  .nextdevice:
1489
  .nextdevice:
1497
        mov     ebx, [esi]
1490
	mov	ebx, [esi]
1498
 
1491
 
1499
        set_io  0
1492
	set_io	[ebx + device.io_addr], 0
1500
        set_io  IntrStatus
1493
	set_io	[ebx + device.io_addr], IntrStatus
Line 1525... Line 1518...
1525
 
1518
 
1526
        push    ebx
1519
	push	ebx
1527
  .more_RX:
1520
  .more_RX:
Line 1528... Line 1521...
1528
        pop     ebx
1521
	pop	ebx
Line 1529... Line 1522...
1529
 
1522
 
1530
; Get the current descripter pointer
1523
; Get the current descriptor pointer
1531
 
1524
 
1532
        movzx   eax, [device.cur_rx]
1525
	movzx	eax, [ebx + device.cur_rx]
1533
        mov     ecx, rx_head.sizeof
1526
	mov	ecx, sizeof.rx_head
Line 1534... Line 1527...
1534
        mul     ecx
1527
	mul	ecx
Line 1535... Line 1528...
1535
        lea     edi, [device.rx_ring]
1528
	lea	edi, [ebx + device.rx_ring]
Line 1551... Line 1544...
1551
        shr     ecx, 16
1544
	shr	ecx, 16
1552
        sub     ecx, 4  ; We dont want CRC
1545
	sub	ecx, 4	; We dont want CRC
Line 1553... Line 1546...
1553
 
1546
 
Line 1554... Line 1547...
1554
; Update stats
1547
; Update stats
1555
 
1548
 
1556
        add     dword [device.bytes_rx], ecx
1549
	add	dword [ebx + device.bytes_rx], ecx
Line 1557... Line 1550...
1557
        adc     dword [device.bytes_rx + 4], 0
1550
	adc	dword [ebx + device.bytes_rx + 4], 0
Line 1558... Line 1551...
1558
        inc     [device.packets_rx]
1551
	inc	[ebx + device.packets_rx]
1559
 
1552
 
Line 1566... Line 1559...
1566
        push    [edi + rx_head.buff_addr_virt]
1559
	push	[edi + rx_head.buff_addr_virt]
Line 1567... Line 1560...
1567
 
1560
 
Line 1568... Line 1561...
1568
; reset the RX descriptor
1561
; reset the RX descriptor
1569
 
1562
 
1570
        push    edi
1563
	push	edi
1571
        stdcall KernelAlloc, PKT_BUF_SZ
1564
	invoke	KernelAlloc, PKT_BUF_SZ
1572
        pop     edi
1565
	pop	edi
1573
        mov     [edi + rx_head.buff_addr_virt], eax
1566
	mov	[edi + rx_head.buff_addr_virt], eax
1574
        GetRealAddr
1567
	invoke	GetPhysAddr
Line 1575... Line 1568...
1575
        mov     [edi + rx_head.buff_addr], eax
1568
	mov	[edi + rx_head.buff_addr], eax
Line 1576... Line 1569...
1576
        mov     [edi + rx_head.status], RX_SBITS_OWN_BIT
1569
	mov	[edi + rx_head.status], RX_SBITS_OWN_BIT
1577
 
1570
 
Line 1578... Line 1571...
1578
; Use next descriptor next time
1571
; Use next descriptor next time
Line 1579... Line 1572...
1579
 
1572
 
Line 1580... Line 1573...
1580
        inc     [device.cur_rx]
1573
	inc	[ebx + device.cur_rx]
1581
        and     [device.cur_rx], RX_RING_SIZE - 1
1574
	and	[ebx + device.cur_rx], RX_RING_SIZE - 1
Line 1582... Line 1575...
1582
 
1575
 
Line 1583... Line 1576...
1583
; At last, send packet to kernel
1576
; At last, send packet to kernel
1584
 
1577
 
Line 1585... Line 1578...
1585
        jmp     Eth_input
1578
	jmp	[Eth_input]
1586
 
1579
 
1587
  .not_bit_own:
1580
  .not_bit_own:
1588
  .not_RX:
1581
  .not_RX:
1589
 
1582
 
1590
        pop     ax
1583
	pop	ax
Line 1591... Line 1584...
1591
 
1584
 
1592
        test    ax, IntrTxDone
1585
	test	ax, IntrTxDone
Line 1607... Line 1600...
1607
 
1600
 
Line 1608... Line 1601...
1608
        DEBUGF  1,"Freeing buffer 0x%x\n", [edi + tx_head.buff_addr_virt]
1601
	DEBUGF	1,"Freeing buffer 0x%x\n", [edi + tx_head.buff_addr_virt]
1609
 
1602
 
1610
        push    [edi + tx_head.buff_addr_virt]
1603
	push	[edi + tx_head.buff_addr_virt]
Line 1611... Line 1604...
1611
        mov     [edi + tx_head.buff_addr_virt], 0
1604
	mov	[edi + tx_head.buff_addr_virt], 0
1612
        call    KernelFree
1605
	invoke	KernelFree
Line 1613... Line 1606...
1613
 
1606
 
Line 1614... Line 1607...
1614
        inc     [device.last_tx]
1607
	inc	[ebx + device.last_tx]
Line 1615... Line 1608...
1615
        and     [device.last_tx], TX_RING_SIZE - 1
1608
	and	[ebx + device.last_tx], TX_RING_SIZE - 1
1616
 
1609
 
1617
        jmp     .loop_tx
1610
	jmp	.loop_tx
1618
 
1611
 
1619
  .not_TX:
1612
  .not_TX:
1620
 
1613
 
1621
        ; On Rhine-II, Bit 3 indicates Tx descriptor write-back race.
1614
	; On Rhine-II, Bit 3 indicates Tx descriptor write-back race.
1622
if 0
1615
if 0
1623
        cmp     [device.chip_id], 0x3065 ;if (tp->chip_id == 0x3065)
1616
	cmp	[ebx + device.chip_id], 0x3065 ;if (tp->chip_id == 0x3065)
1624
        jne     @f
1617
	jne	@f
1625
        push    ax
1618
	push	ax
1626
        xor     eax, eax
1619
	xor	eax, eax
Line 1635... Line 1628...
1635
 
1628
 
1636
        ; Acknowledge all of the current interrupt sources ASAP.
1629
	; Acknowledge all of the current interrupt sources ASAP.
1637
        xor     ecx, ecx
1630
	xor	ecx, ecx
1638
        test    eax, IntrTxDescRace
1631
	test	eax, IntrTxDescRace
1639
        jz      @f
1632
	jz	@f
1640
        set_io  0
1633
	set_io	[ebx + device.io_addr], 0
1641
        set_io  IntrStatus2
1634
	set_io	[ebx + device.io_addr], IntrStatus2
1642
        push    ax
1635
	push	ax
1643
        mov     al, 0x08
1636
	mov	al, 0x08
1644
        out     dx, al
1637
	out	dx, al
1645
        pop     ax
1638
	pop	ax
1646
    @@:
1639
    @@:
1647
        set_io  0
1640
	set_io	[ebx + device.io_addr], 0
1648
        set_io  IntrStatus
1641
	set_io	[ebx + device.io_addr], IntrStatus
1649
        out     dx, ax
1642
	out	dx, ax
Line 1650... Line 1643...
1650
        IOSYNC
1643
	IOSYNC
Line 1661... Line 1654...
1661
 
1654
 
Line 1662... Line 1655...
1662
 
1655
 
-
 
1656
 
-
 
1657
; End of code
1663
 
1658
 
Line 1664... Line -...
1664
; End of code
-
 
1665
 
-
 
1666
section '.data' data readable writable align 16 ; place all uninitialized data here
1659
data fixups
Line 1667... Line 1660...
1667
align 4                                         ; Place all initialised data here
1660
end data
1668
 
1661
 
1669
devices         dd 0
1662
include '../peimport.inc'
1670
version         dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
1663
 
1671
my_service      db 'RHINE',0                    ; max 16 chars including zero
1664
my_service	db 'RHINE',0			; max 16 chars including zero
1672
 
1665
 
1673
chiplist:
1666
chiplist:
1674
                dd 0x30431106, rhine_3043;, RHINE_IOTYPE, RHINE_I_IOSIZE, CanHaveMII or ReqTxAlign or HasV1TxStat
1667
		dd 0x30431106, rhine_3043;, RHINE_IOTYPE, RHINE_I_IOSIZE, CanHaveMII or ReqTxAlign or HasV1TxStat
1675
                dd 0x61001106, rhine_6100;, RHINE_IOTYPE, RHINE_I_IOSIZE, CanHaveMII or ReqTxAlign or HasV1TxStat
1668
		dd 0x61001106, rhine_6100;, RHINE_IOTYPE, RHINE_I_IOSIZE, CanHaveMII or ReqTxAlign or HasV1TxStat
Line 1676... Line 1669...
1676
                dd 0x30651106, rhine_6102;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL
1669
		dd 0x30651106, rhine_6102;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL
1677
                dd 0x31061106, rhine_6105;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL
1670
		dd 0x31061106, rhine_6105;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL
1678
                ; Duplicate entry, with 'M' features enabled.
1671
; Duplicate entry, with 'M' features enabled.
1679
                dd 0x31061106, rhine_6105;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL or HasIPChecksum or HasVLAN
1672
;                dd 0x31061106, rhine_6105;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL or HasIPChecksum or HasVLAN
1680
                dd 0x30531106, rhine_3053;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL
1673
		dd 0x30531106, rhine_3053;, RHINE_IOTYPE, RHINEII_IOSIZE, CanHaveMII or HasWOL
Line 1681... Line 1674...
1681
                dd 0
1674
		dd 0
Line -... Line 1675...
-
 
1675
 
-
 
1676
rhine_3043	db "VIA VT3043 Rhine", 0
1682
 
1677
rhine_6100	db "VIA VT86C100A Rhine", 0