Subversion Repositories Kolibri OS

Rev

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

Rev 9149 Rev 9161
Line 13... Line 13...
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 -... Line 17...
-
 
17
 
-
 
18
; TODO: test for RX-overrun
17
 
19
 
18
format PE DLL native
20
format PE DLL native
Line 19... Line 21...
19
entry START
21
entry START
20
 
22
 
21
        CURRENT_API             = 0x0200
23
        CURRENT_API             = 0x0200
Line -... Line 24...
-
 
24
        COMPATIBLE_API          = 0x0100
-
 
25
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
22
        COMPATIBLE_API          = 0x0100
26
 
Line 23... Line 27...
23
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
27
; configureable area
Line 24... Line 28...
24
 
28
 
Line 33... Line 37...
33
        RXFTH                   = 7     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold
37
        RXFTH                   = 7     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold
Line 34... Line 38...
34
 
38
 
35
        __DEBUG__               = 1
39
        __DEBUG__               = 1
Line -... Line 40...
-
 
40
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
-
 
41
 
36
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
42
; end configureable area
Line 37... Line 43...
37
 
43
 
38
section '.flat' readable writable executable
44
section '.flat' readable writable executable
39
 
45
 
Line 637... Line 643...
637
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
643
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
638
;;                                         ;;
644
;;                                         ;;
639
;; Transmit                                ;;
645
;; Transmit                                ;;
640
;;                                         ;;
646
;;                                         ;;
641
;; In: pointer to device structure in ebx  ;;
647
;; In: pointer to device structure in ebx  ;;
-
 
648
;; Out: eax = 0 on success                 ;;
642
;;                                         ;;
649
;;                                         ;;
643
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
650
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
644
 
651
align 16
645
proc transmit stdcall bufferptr
652
proc transmit stdcall bufferptr
Line 646... Line 653...
646
 
653
 
647
        pushf
-
 
Line 648... Line 654...
648
        cli
654
        spin_lock_irqsave
649
 
655
 
650
        mov     esi, [bufferptr]
656
        mov     esi, [bufferptr]
651
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
657
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
652
        lea     eax, [esi + NET_BUFF.data]
658
        lea     eax, [esi + NET_BUFF.data]
653
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
659
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
654
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
660
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
Line 655... Line 661...
655
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
661
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
656
        [eax+13]:2,[eax+12]:2
662
        [eax+13]:2,[eax+12]:2
657
 
663
 
658
        cmp     [esi + NET_BUFF.length], 1514
664
        cmp     [esi + NET_BUFF.length], 1514
Line 659... Line 665...
659
        ja      .fail
665
        ja      .error
660
        cmp     [esi + NET_BUFF.length], 60
666
        cmp     [esi + NET_BUFF.length], 60
661
        jb      .fail
667
        jb      .error
662
 
668
 
663
; check if we own the current discriptor
669
; check if we own the current discriptor
664
        set_io  [ebx + device.io_addr], 0
670
        set_io  [ebx + device.io_addr], 0
665
        set_io  [ebx + device.io_addr], REG_TSD0
671
        set_io  [ebx + device.io_addr], REG_TSD0
666
        movzx   ecx, [ebx + device.curr_tx_desc]
672
        movzx   ecx, [ebx + device.curr_tx_desc]
667
        shl     ecx, 2
673
        shl     ecx, 2
Line 668... Line -...
668
        add     edx, ecx
-
 
669
        in      eax, dx
674
        add     edx, ecx
670
        test    eax, (1 shl BIT_OWN)
675
        in      eax, dx
671
        jz      .wait_to_send
676
        test    eax, (1 shl BIT_OWN)
672
 
677
        jz      .overrun
673
  .send_packet:
678
 
Line 689... Line 694...
689
        inc     [ebx + device.curr_tx_desc]
694
        inc     [ebx + device.curr_tx_desc]
690
        and     [ebx + device.curr_tx_desc], NUM_TX_DESC-1
695
        and     [ebx + device.curr_tx_desc], NUM_TX_DESC-1
Line 691... Line 696...
691
 
696
 
692
; Update stats
697
; Update stats
693
        inc     [ebx + device.packets_tx]
698
        inc     [ebx + device.packets_tx]
694
        mov     ecx, [esi + NET_BUFF.length]
699
        mov     eax, [esi + NET_BUFF.length]
695
        add     dword [ebx + device.bytes_tx], ecx
700
        add     dword[ebx + device.bytes_tx], eax
Line 696... Line 701...
696
        adc     dword [ebx + device.bytes_tx+4], 0
701
        adc     dword[ebx + device.bytes_tx + 4], 0
697
 
-
 
698
        DEBUGF  1, "Packet Sent!\n"
702
 
699
        popf
703
        spin_unlock_irqrestore
Line 700... Line 704...
700
        xor     eax, eax
704
        xor     eax, eax
701
        ret
705
        ret
702
 
-
 
703
  .wait_to_send:
-
 
704
        DEBUGF  1, "Waiting for timeout\n"
-
 
705
 
-
 
706
        push    edx
-
 
707
        mov     esi, 30
-
 
708
        invoke  Sleep
-
 
709
        pop     edx
706
 
710
 
707
  .error:
711
        in      ax, dx
-
 
712
        test    ax, (1 shl BIT_OWN)
-
 
713
        jnz     .send_packet
-
 
714
 
-
 
Line -... Line 708...
-
 
708
        DEBUGF  2, "TX packet error\n"
715
        pusha
709
        inc     [ebx + device.packets_tx_err]
-
 
710
        invoke  NetFree, [bufferptr]
Line 716... Line 711...
716
        call    reset                            ; if chip hung, reset it
711
 
717
        popa
712
        spin_unlock_irqrestore
-
 
713
        or      eax, -1
718
 
714
        ret
-
 
715
 
719
        jmp     .send_packet
716
  .overrun:
720
 
717
        DEBUGF  2, "TX overrun\n"
721
  .fail:
718
        inc     [ebx + device.packets_tx_ovr]
Line 722... Line 719...
722
        DEBUGF  2, "transmit failed!\n"
719
        invoke  NetFree, [bufferptr]
Line 734... Line 731...
734
;;;;;;;;;;;;;;;;;;;;;;;
731
;;;;;;;;;;;;;;;;;;;;;;;
735
;;                   ;;
732
;;                   ;;
736
;; Interrupt handler ;;
733
;; Interrupt handler ;;
737
;;                   ;;
734
;;                   ;;
738
;;;;;;;;;;;;;;;;;;;;;;;
735
;;;;;;;;;;;;;;;;;;;;;;;
739
 
-
 
740
align 4
736
align 16
741
int_handler:
737
int_handler:
Line 742... Line 738...
742
 
738
 
Line -... Line 739...
-
 
739
        push    ebx esi edi
743
        push    ebx esi edi
740
 
Line 744... Line -...
744
 
-
 
745
        DEBUGF  1, "INT\n"
-
 
746
 
-
 
747
; find pointer of device wich made IRQ occur
-
 
748
        mov     ecx, [devices]
741
        mov     ebx, [esp+4*4]
749
        test    ecx, ecx
-
 
750
        jz      .nothing
-
 
Line 751... Line 742...
751
        mov     esi, device_list
742
        DEBUGF  1,"INT for 0x%x\n", ebx
752
  .nextdevice:
743
 
753
        mov     ebx, [esi]
744
; TODO? if we are paranoid, we can check that the value from ebx is present in the current device_list
754
 
-
 
755
        set_io  [ebx + device.io_addr], 0
745
 
756
        set_io  [ebx + device.io_addr], REG_ISR
746
        set_io  [ebx + device.io_addr], 0
757
        in      ax, dx                          ; Get interrupt status
-
 
758
        out     dx, ax                          ; send it back to ACK
-
 
759
        test    ax, ax
-
 
760
        jnz     .got_it
-
 
761
  .continue:
-
 
762
        add     esi, 4
-
 
763
        dec     ecx
-
 
764
        jnz     .nextdevice
-
 
765
  .nothing:
-
 
766
        pop     edi esi ebx
-
 
767
        xor     eax, eax
-
 
Line -... Line 747...
-
 
747
        set_io  [ebx + device.io_addr], REG_ISR
768
 
748
        in      ax, dx                          ; Get interrupt status
Line 769... Line 749...
769
        ret                                     ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
749
        test    ax, ax
770
 
750
        jz      .nothing
Line 771... Line 751...
771
  .got_it:
751
 
Line 882... Line 862...
882
        mov     ax, RX_CONFIG
862
        mov     ax, RX_CONFIG
883
        out     dx, ax
863
        out     dx, ax
Line 884... Line 864...
884
 
864
 
885
  .finish:
865
  .finish:
-
 
866
        pop     ax
Line 886... Line 867...
886
        pop     ax
867
  @@:
887
 
868
 
888
;----------------------------------------------------
-
 
889
; Transmit ok / Transmit error
869
;----------------------------------------------------
890
  @@:
870
; Transmit ok / Transmit error
Line 891... Line 871...
891
        test    ax, ISR_TOK + ISR_TER
871
        test    ax, ISR_TOK + ISR_TER
Line 942... Line 922...
942
 
922
 
943
  .notthisone:
923
  .notthisone:
944
        sub     ecx, 4
924
        sub     ecx, 4
945
        jae     .txdescloop
925
        jae     .txdescloop
-
 
926
        pop     ax
Line 946... Line 927...
946
        pop     ax
927
  @@:
947
 
928
 
948
;----------------------------------------------------
-
 
949
; Rx buffer overflow ?
929
;----------------------------------------------------
950
  @@:
930
; Rx buffer overflow ?
Line 951... Line 931...
951
        test    ax, ISR_RXOVW
931
        test    ax, ISR_RXOVW
952
        jz      @f
932
        jz      @f
Line 957... Line 937...
957
        set_io  [ebx + device.io_addr], 0
937
        set_io  [ebx + device.io_addr], 0
958
        set_io  [ebx + device.io_addr], REG_ISR
938
        set_io  [ebx + device.io_addr], REG_ISR
959
        mov     ax, ISR_FIFOOVW or ISR_RXOVW or ISR_ROK
939
        mov     ax, ISR_FIFOOVW or ISR_RXOVW or ISR_ROK
960
        out     dx, ax
940
        out     dx, ax
961
        pop     ax
941
        pop     ax
-
 
942
  @@:
Line 962... Line 943...
962
 
943
 
963
;----------------------------------------------------
944
;----------------------------------------------------
964
; Packet underrun?
-
 
965
  @@:
945
; Packet underrun?
966
        test    ax, ISR_PUN
946
        test    ax, ISR_PUN
Line 967... Line 947...
967
        jz      @f
947
        jz      @f
Line 968... Line 948...
968
 
948
 
-
 
949
        DEBUGF  1, "Packet underrun or link changed!\n"
Line 969... Line 950...
969
        DEBUGF  1, "Packet underrun or link changed!\n"
950
 
970
 
951
        call    link
971
        call    link
-
 
972
 
952
  @@:
973
;----------------------------------------------------
953
 
Line 974... Line 954...
974
; Receive FIFO overflow ?
954
;----------------------------------------------------
975
  @@:
955
; Receive FIFO overflow ?
Line 982... Line 962...
982
        set_io  [ebx + device.io_addr], 0
962
        set_io  [ebx + device.io_addr], 0
983
        set_io  [ebx + device.io_addr], REG_ISR
963
        set_io  [ebx + device.io_addr], REG_ISR
984
        mov     ax, ISR_FIFOOVW or ISR_RXOVW or ISR_ROK
964
        mov     ax, ISR_FIFOOVW or ISR_RXOVW or ISR_ROK
985
        out     dx, ax
965
        out     dx, ax
986
        pop     ax
966
        pop     ax
-
 
967
  @@:
Line 987... Line 968...
987
 
968
 
988
;----------------------------------------------------
969
;----------------------------------------------------
989
; cable length changed ?
-
 
990
  @@:
970
; cable length changed ?
991
        test    ax, ISR_LENCHG
971
        test    ax, ISR_LENCHG
Line 992... Line 972...
992
        jz      .fail
972
        jz      @f
Line 993... Line 973...
993
 
973
 
-
 
974
        DEBUGF  2, "Cable length changed!\n"
Line 994... Line -...
994
        DEBUGF  2, "Cable length changed!\n"
-
 
995
 
975
 
996
        call    link
976
        call    link
997
 
977
  @@:
Line 998... Line 978...
998
  .fail:
978
 
Line -... Line 979...
-
 
979
        pop     edi esi ebx
-
 
980
        xor     eax, eax
-
 
981
        inc     eax
-
 
982
 
-
 
983
        ret
Line 999... Line 984...
999
        pop     edi esi ebx
984
 
1000
        xor     eax, eax
985
  .nothing: