Subversion Repositories Kolibri OS

Rev

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

Rev 1635 Rev 2434
Line 24... Line 24...
24
;;                                                                 ;;
24
;;                                                                 ;;
25
;;  See file COPYING for details                                   ;;
25
;;  See file COPYING for details                                   ;;
26
;;                                                                 ;;
26
;;                                                                 ;;
27
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 28... Line 28...
28
 
28
 
Line 29... Line 29...
29
$Revision: 907 $
29
$Revision: 2434 $
30
 
30
 
31
 
31
 
Line 548... Line 548...
548
	stdcall pci_read_config_dword,[index]
548
        stdcall pci_read_config_dword, [index]
549
	test	eax,PCI_BASE_ADDRESS_SPACE_IO
549
        test    eax, PCI_BASE_ADDRESS_SPACE_IO
550
	jz	@f
550
        jz      @f
551
	and	eax,PCI_BASE_ADDRESS_IO_MASK
551
        and     eax, PCI_BASE_ADDRESS_IO_MASK
552
	jmp	.exit
552
        jmp     .exit
-
 
553
    @@:
553
    @@: push	eax
554
        push    eax
554
	and	eax,PCI_BASE_ADDRESS_MEM_TYPE_MASK
555
        and     eax, PCI_BASE_ADDRESS_MEM_TYPE_MASK
555
	cmp	eax,PCI_BASE_ADDRESS_MEM_TYPE_64
556
        cmp     eax, PCI_BASE_ADDRESS_MEM_TYPE_64
556
	jne	.not64
557
        jne     .not64
557
	mov	eax,[index]
558
        mov     eax, [index]
558
	add	eax,4
559
        add     eax, 4
Line 581... Line 582...
581
	; Soft reset the chip
582
        ; Soft reset the chip
582
	RTL_W8	RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
583
        RTL_W8  RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
Line 583... Line 584...
583
 
584
 
584
	; Check that the chip has finished the reset
585
        ; Check that the chip has finished the reset
-
 
586
        mov     ecx, 1000
585
	mov	ecx,1000
587
    @@:
586
    @@: RTL_R8	RTL8169_REG_ChipCmd
588
        RTL_R8  RTL8169_REG_ChipCmd
587
	test	al,RTL8169_CMD_Reset
589
        test    al, RTL8169_CMD_Reset
588
	jz	@f
590
        jz      @f
589
	stdcall udelay,10
591
        stdcall udelay, 10
590
	loop	@b
592
        loop    @b
591
    @@:
593
    @@:
592
	; identify config method
594
        ; identify config method
593
	RTL_R32 RTL8169_REG_TxConfig
595
        RTL_R32 RTL8169_REG_TxConfig
594
	and	eax,0x7c800000
596
        and     eax, 0x7c800000
595
;        DEBUGF  1,"K : rtl8169_init_board: TxConfig & 0x7c800000 = 0x%x\n",eax
597
;        DEBUGF  1,"K : rtl8169_init_board: TxConfig & 0x7c800000 = 0x%x\n",eax
-
 
598
        mov     esi, mac_info-8
596
	mov	esi,mac_info-8
599
    @@:
597
    @@: add	esi,8
600
        add     esi, 8
598
	mov	ecx,eax
601
        mov     ecx, eax
599
	and	ecx,[esi]
602
        and     ecx, [esi]
600
	cmp	ecx,[esi]
603
        cmp     ecx, [esi]
601
	jne	@b
604
        jne     @b
Line 607... Line 610...
607
	and	al,0x0f
610
        and     al, 0x0f
608
	or	al,al
611
        or      al, al
609
	jnz	@f
612
        jnz     @f
610
	mov	[rtl8169_tpc.pcfg],PCFG_METHOD_1
613
        mov     [rtl8169_tpc.pcfg], PCFG_METHOD_1
611
	jmp	.pconf
614
        jmp     .pconf
-
 
615
    @@:
612
    @@: dec	al
616
        dec     al
613
	jnz	.pconf
617
        jnz     .pconf
614
	mov	[rtl8169_tpc.pcfg],PCFG_METHOD_2
618
        mov     [rtl8169_tpc.pcfg], PCFG_METHOD_2
615
  .pconf:
619
  .pconf:
Line 616... Line 620...
616
 
620
 
617
	; identify chip attached to board
621
        ; identify chip attached to board
618
	mov	ecx,10
622
        mov     ecx, 10
-
 
623
        mov     eax, [rtl8169_tpc.mcfg]
619
	mov	eax,[rtl8169_tpc.mcfg]
624
    @@:
620
    @@: dec	ecx
625
        dec     ecx
621
	js	@f
626
        js      @f
622
	cmp	eax,[rtl_chip_info+ecx*8]
627
        cmp     eax, [rtl_chip_info+ecx*8]
623
	jne	@b
628
        jne     @b
624
	mov	[rtl8169_tpc.chipset],ecx
629
        mov     [rtl8169_tpc.chipset], ecx
Line 659... Line 664...
659
  .not_4:
664
  .not_4:
660
	cmp	[rtl8169_tpc.mcfg],MCFG_METHOD_02
665
        cmp     [rtl8169_tpc.mcfg], MCFG_METHOD_02
661
	je	@f
666
        je      @f
662
	cmp	[rtl8169_tpc.mcfg],MCFG_METHOD_03
667
        cmp     [rtl8169_tpc.mcfg], MCFG_METHOD_03
663
	jne	.not_2_or_3
668
        jne     .not_2_or_3
-
 
669
    @@:
664
    @@: stdcall RTL8169_WRITE_GMII_REG,0x1F,0x0001
670
        stdcall RTL8169_WRITE_GMII_REG, 0x1F, 0x0001
665
	stdcall RTL8169_WRITE_GMII_REG,0x15,0x1000
671
        stdcall RTL8169_WRITE_GMII_REG, 0x15, 0x1000
666
	stdcall RTL8169_WRITE_GMII_REG,0x18,0x65C7
672
        stdcall RTL8169_WRITE_GMII_REG, 0x18, 0x65C7
667
	stdcall RTL8169_WRITE_GMII_REG,0x04,0x0000
673
        stdcall RTL8169_WRITE_GMII_REG, 0x04, 0x0000
668
	stdcall RTL8169_WRITE_GMII_REG,0x03,0x00A1
674
        stdcall RTL8169_WRITE_GMII_REG, 0x03, 0x00A1
669
	stdcall RTL8169_WRITE_GMII_REG,0x02,0x0008
675
        stdcall RTL8169_WRITE_GMII_REG, 0x02, 0x0008
Line 725... Line 731...
725
	RTL_W32 RTL8169_REG_PHYAR,eax
731
        RTL_W32 RTL8169_REG_PHYAR,eax
726
	stdcall udelay,1	;;;1000
732
        stdcall udelay, 1       ;;;1000
Line 727... Line 733...
727
 
733
 
728
	mov	ecx,2000
734
        mov     ecx, 2000
-
 
735
        ; Check if the RTL8169 has completed writing to the specified MII register
729
	; Check if the RTL8169 has completed writing to the specified MII register
736
    @@:
730
    @@: RTL_R32 RTL8169_REG_PHYAR
737
        RTL_R32 RTL8169_REG_PHYAR
731
	test	eax,0x80000000
738
        test    eax, 0x80000000
732
	jz	.exit
739
        jz      .exit
733
	stdcall udelay,1	;;;100
740
        stdcall udelay, 1       ;;;100
734
	loop	@b
741
        loop    @b
Line 747... Line 754...
747
	RTL_W32 RTL8169_REG_PHYAR,eax
754
        RTL_W32 RTL8169_REG_PHYAR,eax
748
	stdcall udelay,1	;;;1000
755
        stdcall udelay, 1       ;;;1000
Line 749... Line 756...
749
 
756
 
750
	mov	ecx,2000
757
        mov     ecx, 2000
-
 
758
        ; Check if the RTL8169 has completed retrieving data from the specified MII register
751
	; Check if the RTL8169 has completed retrieving data from the specified MII register
759
    @@:
752
    @@: RTL_R32 RTL8169_REG_PHYAR
760
        RTL_R32 RTL8169_REG_PHYAR
753
	test	eax,0x80000000
761
        test    eax, 0x80000000
754
	jnz	.exit
762
        jnz     .exit
755
	stdcall udelay,1	;;;100
763
        stdcall udelay, 1       ;;;100
Line 800... Line 808...
800
	rep	stosd
808
        rep stosd
Line 801... Line 809...
801
 
809
 
802
	mov	edi,rtl8169_tpc.Tx_skbuff
810
        mov     edi, rtl8169_tpc.Tx_skbuff
803
	mov	eax,rtl8169_txb
811
        mov     eax, rtl8169_txb
-
 
812
        mov     ecx, NUM_TX_DESC
804
	mov	ecx,NUM_TX_DESC
813
    @@:
805
    @@: stosd
814
        stosd
806
	inc	eax	      ; add eax,RX_BUF_SIZE ???
815
        inc     eax           ; add eax,RX_BUF_SIZE ???
Line 807... Line 816...
807
	loop	@b
816
        loop    @b
808
 
817
 
Line 816... Line 825...
816
;!!!    }
825
;!!!    }
817
	mov	esi,rtl8169_tpc.RxBufferRing
826
        mov     esi, rtl8169_tpc.RxBufferRing
818
	mov	edi,[rtl8169_tpc.RxDescArray]
827
        mov     edi, [rtl8169_tpc.RxDescArray]
819
	mov	eax,rtl8169_rxb
828
        mov     eax, rtl8169_rxb
820
	mov	ecx,NUM_RX_DESC
829
        mov     ecx, NUM_RX_DESC
-
 
830
    @@:
821
    @@: mov	[esi],eax
831
        mov     [esi], eax
822
	mov	[edi+rtl8169_RxDesc.buf_addr],eax
832
        mov     [edi+rtl8169_RxDesc.buf_addr], eax
823
	sub	[edi+rtl8169_RxDesc.buf_addr],OS_BASE				; shurf 28.09.2008
833
        sub     [edi+rtl8169_RxDesc.buf_addr], OS_BASE                          ; shurf 28.09.2008
824
	mov	[edi+rtl8169_RxDesc.status],RTL8169_DSB_OWNbit or RX_BUF_SIZE
834
        mov     [edi+rtl8169_RxDesc.status], RTL8169_DSB_OWNbit or RX_BUF_SIZE
825
	add	esi,4
835
        add     esi, 4
826
	add	edi,sizeof.rtl8169_RxDesc
836
        add     edi, sizeof.rtl8169_RxDesc
Line 838... Line 848...
838
 
848
 
839
	; Soft reset the chip
849
        ; Soft reset the chip
840
	RTL_W8	RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
850
        RTL_W8  RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
841
	; Check that the chip has finished the reset
851
        ; Check that the chip has finished the reset
-
 
852
        mov     ecx, 1000
842
	mov	ecx,1000
853
    @@:
843
    @@: RTL_R8	RTL8169_REG_ChipCmd
854
        RTL_R8  RTL8169_REG_ChipCmd
844
	and	al,RTL8169_CMD_Reset
855
        and     al, RTL8169_CMD_Reset
845
	jz	@f
856
        jz      @f
846
	stdcall udelay,10
857
        stdcall udelay, 10
847
	loop	@b
858
        loop    @b
Line 870... Line 881...
870
	jne	@f
881
        jne     @f
871
	or	ax,1 shl 14
882
        or      ax, 1 shl 14
872
;       DEBUGF  1,"K :   Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n"
883
;       DEBUGF  1,"K :   Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n"
873
	jmp	.set
884
        jmp     .set
874
    @@:;DEBUGF  1,"K :   Set MAC Reg C+CR Offset 0xE0: bit-3\n"
885
    @@:;DEBUGF  1,"K :   Set MAC Reg C+CR Offset 0xE0: bit-3\n"
-
 
886
  .set:
875
  .set: RTL_W16 RTL8169_REG_CPlusCmd,ax
887
        RTL_W16 RTL8169_REG_CPlusCmd,ax
Line 876... Line 888...
876
 
888
 
877
;       RTL_W16 0xE2,0x1517
889
;       RTL_W16 0xE2,0x1517
878
;       RTL_W16 0xE2,0x152a
890
;       RTL_W16 0xE2,0x152a
879
;       RTL_W16 0xE2,0x282a
891
;       RTL_W16 0xE2,0x282a
Line 927... Line 939...
927
	mov	ecx,MAC_ADDR_LEN
939
        mov     ecx, MAC_ADDR_LEN
928
	mov	edx,[rtl8169_tpc.mmio_addr]
940
        mov     edx, [rtl8169_tpc.mmio_addr]
929
	add	edx,RTL8169_REG_MAC0
941
        add     edx, RTL8169_REG_MAC0
930
	xor	ebx,ebx
942
        xor     ebx, ebx
931
	; Get MAC address. FIXME: read EEPROM
943
        ; Get MAC address. FIXME: read EEPROM
-
 
944
    @@:
932
    @@: RTL_R8	dx
945
        RTL_R8  dx
933
	mov	[node_addr+ebx],al
946
        mov     [node_addr+ebx], al
934
	inc	edx
947
        inc     edx
935
	inc	ebx
948
        inc     ebx
936
	loop	@b
949
        loop    @b
Line 967... Line 980...
967
	; Enable auto-negotiation and restart auto-nigotiation
980
        ; Enable auto-negotiation and restart auto-nigotiation
968
	stdcall RTL8169_WRITE_GMII_REG,RTL8169_PHY_CTRL_REG,RTL8169_PHY_Enable_Auto_Nego or RTL8169_PHY_Restart_Auto_Nego
981
        stdcall RTL8169_WRITE_GMII_REG, RTL8169_PHY_CTRL_REG, RTL8169_PHY_Enable_Auto_Nego or RTL8169_PHY_Restart_Auto_Nego
969
	stdcall udelay,100
982
        stdcall udelay, 100
970
	mov	ecx,10000
983
        mov     ecx, 10000
971
	; wait for auto-negotiation process
984
        ; wait for auto-negotiation process
-
 
985
    @@:
972
    @@: dec	ecx
986
        dec     ecx
973
	jz	@f
987
        jz      @f
974
	stdcall RTL8169_READ_GMII_REG,RTL8169_PHY_STAT_REG
988
        stdcall RTL8169_READ_GMII_REG, RTL8169_PHY_STAT_REG
975
	stdcall udelay,100
989
        stdcall udelay, 100
976
	test	eax,RTL8169_PHY_Auto_Neco_Comp
990
        test    eax, RTL8169_PHY_Auto_Neco_Comp
977
	jz	@b
991
        jz      @b
Line 1079... Line 1093...
1079
	push	eax
1093
        push    eax
1080
	add	ecx,ETH_HLEN
1094
        add     ecx, ETH_HLEN
1081
	and	ecx,0x0FFF
1095
        and     ecx, 0x0FFF
1082
	xor	al,al
1096
        xor     al, al
1083
	add	edi,ecx
1097
        add     edi, ecx
-
 
1098
    @@:
1084
    @@: cmp	ecx,ETH_ZLEN
1099
        cmp     ecx, ETH_ZLEN
1085
	jae	@f
1100
        jae     @f
1086
	stosb
1101
        stosb
1087
	inc	ecx
1102
        inc     ecx
1088
	jmp	@b
1103
        jmp     @b
-
 
1104
    @@:
1089
    @@: pop	eax
1105
        pop     eax
Line 1090... Line 1106...
1090
 
1106
 
1091
	mov	ebx,eax
1107
        mov     ebx, eax
1092
	mov	eax,sizeof.rtl8169_TxDesc
1108
        mov     eax, sizeof.rtl8169_TxDesc
1093
	mul	[rtl8169_tpc.cur_tx]
1109
        mul     [rtl8169_tpc.cur_tx]
Line 1098... Line 1114...
1098
 
1114
 
1099
	mov	eax,ecx
1115
        mov     eax, ecx
1100
	cmp	eax,ETH_ZLEN
1116
        cmp     eax, ETH_ZLEN
1101
	jae	@f
1117
        jae     @f
-
 
1118
        mov     eax, ETH_ZLEN
1102
	mov	eax,ETH_ZLEN
1119
    @@:
1103
    @@: or	eax,RTL8169_DSB_OWNbit or RTL8169_DSB_FSbit or RTL8169_DSB_LSbit
1120
        or      eax, RTL8169_DSB_OWNbit or RTL8169_DSB_FSbit or RTL8169_DSB_LSbit
1104
	cmp	[rtl8169_tpc.cur_tx],NUM_TX_DESC - 1
1121
        cmp     [rtl8169_tpc.cur_tx], NUM_TX_DESC - 1
1105
	jne	@f
1122
        jne     @f
-
 
1123
        or      eax, RTL8169_DSB_EORbit
1106
	or	eax,RTL8169_DSB_EORbit
1124
    @@:
Line 1107... Line 1125...
1107
    @@: mov	[ebx + rtl8169_TxDesc.status],eax
1125
        mov     [ebx + rtl8169_TxDesc.status], eax
Line 1108... Line 1126...
1108
 
1126
 
1109
	RTL_W8	RTL8169_REG_TxPoll,0x40     ; set polling bit
1127
        RTL_W8  RTL8169_REG_TxPoll,0x40     ; set polling bit
Line 1110... Line 1128...
1110
 
1128
 
1111
	inc	[rtl8169_tpc.cur_tx]
1129
        inc     [rtl8169_tpc.cur_tx]
1112
	and	[rtl8169_tpc.cur_tx],NUM_TX_DESC - 1
1130
        and     [rtl8169_tpc.cur_tx], NUM_TX_DESC - 1
-
 
1131
 
1113
 
1132
;!!!    to = currticks() + TX_TIMEOUT;
1114
;!!!    to = currticks() + TX_TIMEOUT;
1133
;!!!    while ((tpc->TxDescArray[entry].status & OWNbit) && (currticks() < to));        /* wait */
1115
;!!!    while ((tpc->TxDescArray[entry].status & OWNbit) && (currticks() < to));        /* wait */
1134
        mov     ecx, TX_TIMEOUT / 10
1116
	mov	ecx,TX_TIMEOUT / 10
1135
    @@:
1117
    @@: test	[ebx + rtl8169_TxDesc.status],RTL8169_DSB_OWNbit
1136
        test    [ebx + rtl8169_TxDesc.status], RTL8169_DSB_OWNbit
1118
	jnz	@f
1137
        jnz     @f
Line 1193... Line 1212...
1193
 
1212
 
1194
	mov	eax,RTL8169_DSB_OWNbit or RX_BUF_SIZE
1213
        mov     eax, RTL8169_DSB_OWNbit or RX_BUF_SIZE
1195
	cmp	[rtl8169_tpc.cur_rx],NUM_RX_DESC - 1
1214
        cmp     [rtl8169_tpc.cur_rx], NUM_RX_DESC - 1
1196
	jne	@f
1215
        jne     @f
-
 
1216
        or      eax, RTL8169_DSB_EORbit
1197
	or	eax,RTL8169_DSB_EORbit
1217
    @@:
Line 1198... Line 1218...
1198
    @@: mov	[ebx + rtl8169_RxDesc.status],eax
1218
        mov     [ebx + rtl8169_RxDesc.status], eax
1199
 
1219
 
1200
	mov	[ebx + rtl8169_RxDesc.buf_addr],edx
1220
        mov     [ebx + rtl8169_RxDesc.buf_addr], edx
1201
	sub	[ebx + rtl8169_RxDesc.buf_addr],OS_BASE 				; shurf 28.09.2008
1221
        sub     [ebx + rtl8169_RxDesc.buf_addr], OS_BASE                                ; shurf 28.09.2008