Subversion Repositories Kolibri OS

Rev

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

Rev 5363 Rev 5522
Line 135... Line 135...
135
PHY_CC          = 0x88                  ; PHY status change configuration register
135
PHY_CC          = 0x88                  ; PHY status change configuration register
136
PHY_ST          = 0x8A                  ; PHY status register
136
PHY_ST          = 0x8A                  ; PHY status register
137
MAC_SM          = 0xAC                  ; MAC status machine
137
MAC_SM          = 0xAC                  ; MAC status machine
138
MAC_ID          = 0xBE                  ; Identifier register
138
MAC_ID          = 0xBE                  ; Identifier register
Line 139... Line 139...
139
 
139
 
Line 140... Line 140...
140
MAX_BUF_SIZE    = 0x600                 ; 1536
140
MAX_BUF_SIZE    = 1514
141
 
141
 
Line 142... Line 142...
142
MBCR_DEFAULT    = 0x012A                ; MAC Bus Control Register
142
MBCR_DEFAULT    = 0x012A                ; MAC Bus Control Register
Line 394... Line 394...
394
unload:
394
unload:
395
        ; TODO: (in this particular order)
395
        ; TODO: (in this particular order)
396
        ;
396
        ;
397
        ; - Stop the device
397
        ; - Stop the device
398
        ; - Detach int handler
398
        ; - Detach int handler
399
        ; - Remove device from local list (RTL8139_LIST)
399
        ; - Remove device from local list (device_list)
400
        ; - call unregister function in kernel
400
        ; - call unregister function in kernel
401
        ; - Remove all allocated structures and buffers the card used
401
        ; - Remove all allocated structures and buffers the card used
Line 402... Line 402...
402
 
402
 
403
        or      eax,-1
-
 
404
 
403
        or      eax, -1
Line 405... Line 404...
405
ret
404
        ret
406
 
405
 
Line 450... Line 449...
450
        ; Check the vendor ID on the PHY, if 0xFFFF assume none attached
449
        ; Check the vendor ID on the PHY, if 0xFFFF assume none attached
451
        stdcall phy_read, [ebx + device.phy_addr], 2
450
        stdcall phy_read, [ebx + device.phy_addr], 2
452
        cmp     ax, 0xFFFF
451
        cmp     ax, 0xFFFF
453
        jne     @f
452
        jne     @f
454
        DEBUGF  2, "Failed to detect an attached PHY!\n"
453
        DEBUGF  2, "Failed to detect an attached PHY!\n"
-
 
454
  .err:
455
        mov     eax, -1
455
        mov     eax, -1
456
        ret
456
        ret
457
     @@:
457
  @@:
Line 458... Line 458...
458
 
458
 
459
        ; Set MAC address
459
        ; Set MAC address
Line 460... Line 460...
460
        call    init_mac_regs
460
        call    init_mac_regs
461
 
461
 
462
        ; Initialize and alloc RX/TX buffers
462
        ; Initialize and alloc RX/TX buffers
-
 
463
        call    init_txbufs
-
 
464
        call    init_rxbufs
Line 463... Line 465...
463
        call    init_txbufs
465
        test    eax, eax
464
        call    init_rxbufs
466
        jnz     .err
465
 
467
 
466
        ; Read the PHY ID
468
        ; Read the PHY ID
Line 660... Line 662...
660
        mov     edx, eax
662
        mov     edx, eax
661
        mov     ecx, RX_RING_SIZE
663
        mov     ecx, RX_RING_SIZE
Line 662... Line 664...
662
 
664
 
663
    .next_desc:
665
  .next_desc:
664
        mov     [esi + x_head.ndesc], edx
-
 
665
 
666
        mov     [esi + x_head.ndesc], edx
666
        push    esi ecx edx
667
        push    esi ecx edx
667
        invoke  KernelAlloc, MAX_BUF_SIZE
668
        invoke  NetAlloc, MAX_BUF_SIZE+NET_BUFF.data
668
        pop     edx ecx esi
-
 
-
 
669
        pop     edx ecx esi
-
 
670
        test    eax, eax
669
 
671
        jz      .out_of_mem
670
        mov     [esi + x_head.skb_ptr], eax
672
        mov     [esi + x_head.skb_ptr], eax
-
 
673
        invoke  GetPhysAddr
671
        invoke  GetPhysAddr
674
        add     eax, NET_BUFF.data
672
        mov     [esi + x_head.buf], eax
675
        mov     [esi + x_head.buf], eax
Line 673... Line 676...
673
        mov     [esi + x_head.status], DSC_OWNER_MAC
676
        mov     [esi + x_head.status], DSC_OWNER_MAC
674
 
677
 
675
        add     edx, sizeof.x_head
-
 
676
        add     esi, sizeof.x_head
678
        add     edx, sizeof.x_head
677
 
679
        add     esi, sizeof.x_head
Line 678... Line 680...
678
        dec     ecx
680
        dec     ecx
679
        jnz     .next_desc
681
        jnz     .next_desc
680
 
682
 
681
; complete the ring by linking the last to the first
683
; complete the ring by linking the last to the first
Line -... Line 684...
-
 
684
        lea     eax, [ebx + device.rx_ring]
-
 
685
        invoke  GetPhysAddr
-
 
686
        mov     dword[ebx + device.rx_ring + sizeof.x_head*(RX_RING_SIZE-1) + x_head.ndesc], eax
-
 
687
 
-
 
688
        xor     eax, eax
682
        lea     eax, [ebx + device.rx_ring]
689
        ret
Line 683... Line 690...
683
        invoke  GetPhysAddr
690
 
Line 732... Line 739...
732
;;                                         ;;
739
;;                                         ;;
733
;; In: pointer to device structure in ebx  ;;
740
;; In: pointer to device structure in ebx  ;;
734
;;                                         ;;
741
;;                                         ;;
735
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
742
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 736... Line 743...
736
 
743
 
Line 737... Line 744...
737
proc transmit stdcall bufferptr, buffersize
744
proc transmit stdcall bufferptr
738
 
745
 
Line -... Line 746...
-
 
746
        pushf
739
        pushf
747
        cli
740
        cli
748
 
741
 
749
        mov     esi, [bufferptr]
742
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
750
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
743
        mov     eax, [bufferptr]
751
        lea     eax, [esi + NET_BUFF.data]
744
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
752
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
Line 745... Line 753...
745
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
753
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
746
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
754
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
747
        [eax+13]:2,[eax+12]:2
755
        [eax+13]:2,[eax+12]:2
748
 
756
 
Line 749... Line 757...
749
        cmp     [buffersize], 1514
757
        cmp     [esi + NET_BUFF.length], 1514
750
        ja      .fail
758
        ja      .fail
751
        cmp     [buffersize], 60
759
        cmp     [esi + NET_BUFF.length], 60
Line 762... Line 770...
762
        jnz     .wait_to_send
770
        jnz     .wait_to_send
Line 763... Line 771...
763
 
771
 
764
  .do_send:
772
  .do_send:
Line -... Line 773...
-
 
773
        DEBUGF  1,"Sending now\n"
765
        DEBUGF  1,"Sending now\n"
774
 
766
 
775
        mov     [edi + x_head.skb_ptr], esi
767
        mov     eax, [bufferptr]
776
        mov     eax, esi
768
        mov     [edi + x_head.skb_ptr], eax
777
        add     eax, [eax + NET_BUFF.offset]
769
        invoke  GetPhysAddr
778
        invoke  GetPhysAddr
770
        mov     [edi + x_head.buf], eax
779
        mov     [edi + x_head.buf], eax
771
        mov     ecx, [buffersize]
780
        mov     ecx, [esi + NET_BUFF.length]
Line 772... Line 781...
772
        mov     [edi + x_head.len], cx
781
        mov     [edi + x_head.len], cx
773
        mov     [edi + x_head.status], DSC_OWNER_MAC
782
        mov     [edi + x_head.status], DSC_OWNER_MAC
Line 781... Line 790...
781
        inc     [ebx + device.cur_tx]
790
        inc     [ebx + device.cur_tx]
782
        and     [ebx + device.cur_tx], TX_RING_SIZE - 1
791
        and     [ebx + device.cur_tx], TX_RING_SIZE - 1
Line 783... Line 792...
783
 
792
 
784
; Update stats
793
; Update stats
785
        inc     [ebx + device.packets_tx]
794
        inc     [ebx + device.packets_tx]
786
        mov     eax, [buffersize]
795
        mov     eax, [esi + NET_BUFF.length]
787
        add     dword[ebx + device.bytes_tx], eax
796
        add     dword[ebx + device.bytes_tx], eax
Line 788... Line 797...
788
        adc     dword[ebx + device.bytes_tx + 4], 0
797
        adc     dword[ebx + device.bytes_tx + 4], 0
789
 
798
 
790
        popf
799
        popf
Line 791... Line 800...
791
        xor     eax, eax
800
        xor     eax, eax
792
        ret
801
        ret
793
 
-
 
794
  .wait_to_send:
802
 
795
        DEBUGF  1,"Waiting for TX buffer\n"
803
  .wait_to_send:
796
 
804
        DEBUGF  1,"Waiting for TX buffer\n"
-
 
805
        invoke  GetTimerTicks           ; returns in eax
797
        invoke  GetTimerTicks           ; returns in eax
806
        lea     edx, [eax + 100]
798
        lea     edx, [eax + 100]
807
  .l2:
-
 
808
        mov     esi, [bufferptr]
799
     .l2:
809
        test    [edi + x_head.status], DSC_OWNER_MAC
800
        test    [edi + x_head.status], DSC_OWNER_MAC
810
        jz      .do_send
801
        jz      .do_send
811
        popf
-
 
812
        mov     esi, 10
-
 
813
        invoke  Sleep
802
        mov     esi, 10
814
        invoke  GetTimerTicks
803
        invoke  Sleep
815
        pushf
Line 804... Line 816...
804
        invoke  GetTimerTicks
816
        cli
805
        cmp     edx, eax
817
        cmp     edx, eax
806
        jb      .l2
818
        jb      .l2
807
 
819
 
808
        DEBUGF  2,"Send timeout\n"
820
        DEBUGF  2,"Send timeout\n"
809
  .fail:
821
  .fail:
810
        DEBUGF  2,"Send failed\n"
822
        DEBUGF  2,"Send failed\n"
Line 811... Line 823...
811
        invoke  KernelFree, [bufferptr]
823
        invoke  NetFree, [bufferptr]
Line 888... Line 900...
888
        ; Packet successfully received
900
        ; Packet successfully received
889
        movzx   ecx, [edx + x_head.len]
901
        movzx   ecx, [edx + x_head.len]
890
        and     ecx, 0xFFF
902
        and     ecx, 0xFFF
891
        sub     ecx, 4                  ; Do not count the CRC
903
        sub     ecx, 4                  ; Do not count the CRC
Line -... Line 904...
-
 
904
 
-
 
905
        DEBUGF  1,"packet ptr=0x%x size=%u\n", [edx + x_head.skb_ptr], ecx
892
 
906
 
893
        ; Update stats
907
        ; Update stats
894
        add     dword[ebx + device.bytes_rx], ecx
908
        add     dword[ebx + device.bytes_rx], ecx
895
        adc     dword[ebx + device.bytes_rx + 4], 0
909
        adc     dword[ebx + device.bytes_rx + 4], 0
Line 896... Line -...
896
        inc     dword[ebx + device.packets_rx]
-
 
897
 
910
        inc     dword[ebx + device.packets_rx]
-
 
911
 
898
        ; Push packet size and pointer, kernel will need it..
912
        push    ebx
-
 
913
        ; Push packet ptr and return addr for Eth_input
-
 
914
        push    .more_RX
-
 
915
        mov     eax, [edx + x_head.skb_ptr]
-
 
916
        push    eax
-
 
917
        mov     [eax + NET_BUFF.length], ecx
Line 899... Line -...
899
        push    ebx
-
 
900
        push    .more_RX
-
 
901
 
-
 
902
        push    ecx
-
 
903
        push    [edx + x_head.skb_ptr]
-
 
904
 
918
        mov     [eax + NET_BUFF.device], ebx
905
        DEBUGF  1,"packet ptr=0x%x\n", [edx + x_head.skb_ptr]
919
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
906
 
920
 
907
        ; reset the RX descriptor
921
        ; reset the RX descriptor (alloc new buffer)
908
        push    edx
922
        push    edx
909
        invoke  KernelAlloc, MAX_BUF_SIZE
923
        invoke  NetAlloc, MAX_BUF_SIZE+NET_BUFF.data
-
 
924
        pop     edx
910
        pop     edx
925
        mov     [edx + x_head.skb_ptr], eax
911
        mov     [edx + x_head.skb_ptr], eax
926
        invoke  GetPhysAddr
Line 912... Line 927...
912
        invoke  GetPhysAddr
927
        add     eax, NET_BUFF.data
913
        mov     [edx + x_head.buf], eax
928
        mov     [edx + x_head.buf], eax
914
        mov     [edx + x_head.status], DSC_OWNER_MAC
929
        mov     [edx + x_head.status], DSC_OWNER_MAC
Line 915... Line 930...
915
 
930
 
916
        ; Use next descriptor next time
931
        ; Use next descriptor next time
Line 917... Line 932...
917
        inc     [ebx + device.cur_rx]
932
        inc     [ebx + device.cur_rx]
918
        and     [ebx + device.cur_rx], RX_RING_SIZE - 1
-
 
919
 
933
        and     [ebx + device.cur_rx], RX_RING_SIZE - 1
920
        ; At last, send packet to kernel
934
 
Line 921... Line 935...
921
        jmp     [Eth_input]
935
        ; At last, send packet to kernel
922
 
936
        jmp     [EthInput]
Line 939... Line 953...
939
 
953
 
Line 940... Line 954...
940
        DEBUGF  1,"Freeing buffer 0x%x\n", [edi + x_head.skb_ptr]
954
        DEBUGF  1,"Freeing buffer 0x%x\n", [edi + x_head.skb_ptr]
941
 
955
 
942
        push    [edi + x_head.skb_ptr]
956
        push    [edi + x_head.skb_ptr]
Line 943... Line 957...
943
        mov     [edi + x_head.skb_ptr], 0
957
        mov     [edi + x_head.skb_ptr], 0
944
        invoke  KernelFree
958
        invoke  NetFree
Line 945... Line 959...
945
 
959
 
Line 1104... Line 1118...
1104
 
1118
 
1105
        mov     cx, 3
1119
        mov     cx, 3
1106
        lea     edi, [ebx + device.mac]
1120
        lea     edi, [ebx + device.mac]
1107
        set_io  [ebx + device.io_addr], 0
1121
        set_io  [ebx + device.io_addr], 0
1108
        set_io  [ebx + device.io_addr], MID_0L
1122
        set_io  [ebx + device.io_addr], MID_0L
1109
     .mac:
1123
  .loop:
1110
        in      ax, dx
1124
        in      ax, dx
1111
        stosw
1125
        stosw
1112
        inc     dx
1126
        inc     dx
1113
        inc     dx
1127
        inc     dx
1114
        dec     cx
1128
        dec     cx
Line 1115... Line 1129...
1115
        jnz     .mac
1129
        jnz     .loop
1116
 
1130
 
Line 1117... Line 1131...
1117
        DEBUGF  1,"%x-%x-%x-%x-%x-%x\n",\
1131
        DEBUGF  1,"%x-%x-%x-%x-%x-%x\n",\