Subversion Repositories Kolibri OS

Rev

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

Rev 5363 Rev 5522
Line 33... Line 33...
33
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
33
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
Line 34... Line 34...
34
 
34
 
Line 35... Line 35...
35
        MAX_DEVICES             = 16
35
        MAX_DEVICES             = 16
36
 
36
 
Line 37... Line 37...
37
        RBLEN                   = 0     ; Receive buffer size: 0=4K 1=8k 2=16k 3=32k 4=64k
37
        RBLEN                   = 0     ; Receive buffer size: 0=4K 1=8k 2=16k 3=32k 4=64k
38
                                        ; FIXME: option 1 and 2 will not allocate buffer correctly causing data loss!
38
                                        ; FIXME: option 1 and 2 may allocate a non contiguous buffer causing data loss!
39
 
39
 
Line 1369... Line 1369...
1369
 
1369
 
1370
align 4
1370
align 4
Line 1371... Line 1371...
1371
init_ring:
1371
init_ring:
1372
 
1372
 
Line 1373... Line 1373...
1373
        DEBUGF  1,"init rings\n"
1373
        DEBUGF  1,"init rings\n"
1374
        push    eax esi ecx
1374
        push    esi ecx
Line 1375... Line 1375...
1375
 
1375
 
Line 1390... Line 1390...
1390
 
1390
 
1391
        mov     ecx, RX_RING
1391
        mov     ecx, RX_RING
1392
        lea     esi, [ebx + device.rx_ring]
1392
        lea     esi, [ebx + device.rx_ring]
1393
  .rx_loop:
1393
  .rx_loop:
1394
        push    ecx esi
1394
        push    ecx esi
1395
        invoke  KernelAlloc, 4096 shl RBLEN             ; push/pop esi not needed, but just in case...
1395
        invoke  NetAlloc, (4096 shl RBLEN) + NET_BUFF.data             ; push/pop esi not needed, but just in case...
-
 
1396
        pop     esi
-
 
1397
        test    eax, eax
1396
        pop     esi
1398
        jz      .out_of_mem
1397
        mov     [esi + RX_RING*sizeof.RxDesc], eax
1399
        mov     [esi + RX_RING*sizeof.RxDesc], eax
-
 
1400
        invoke  GetPhysAddr
1398
        invoke  GetPhysAddr
1401
        add     eax, NET_BUFF.data
1399
        mov     [esi + RxDesc.PacketBuffer], eax
1402
        mov     [esi + RxDesc.PacketBuffer], eax
1400
        mov     [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL)
1403
        mov     [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL)
1401
        add     esi, sizeof.RxDesc
1404
        add     esi, sizeof.RxDesc
1402
        pop     ecx
1405
        pop     ecx
1403
        dec     ecx
1406
        dec     ecx
Line 1404... Line 1407...
1404
        jnz     .rx_loop
1407
        jnz     .rx_loop
Line -... Line 1408...
-
 
1408
        
-
 
1409
        pop     ecx esi
-
 
1410
 
-
 
1411
        xor     eax, eax
-
 
1412
        ret
-
 
1413
 
1405
        
1414
  .out_of_mem:
Line 1779... Line 1788...
1779
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1788
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1780
;;                                         ;;
1789
;;                                         ;;
1781
;; Transmit                                ;;
1790
;; Transmit                                ;;
1782
;;                                         ;;
1791
;;                                         ;;
1783
;; In: buffer pointer in [esp+4]           ;;
1792
;; In: buffer pointer in [esp+4]           ;;
1784
;;     size of buffer in [esp+8]           ;;
-
 
1785
;;     pointer to device structure in ebx  ;;
1793
;;     pointer to device structure in ebx  ;;
1786
;;                                         ;;
1794
;;                                         ;;
1787
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1795
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 1788... Line 1796...
1788
 
1796
 
Line 1789... Line 1797...
1789
proc transmit stdcall bufferptr, buffersize
1797
proc transmit stdcall bufferptr
1790
 
1798
 
Line -... Line 1799...
-
 
1799
        pushf
1791
        pushf
1800
        cli
1792
        cli
1801
 
1793
 
1802
        mov     esi, [bufferptr]
1794
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
1803
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
1795
        mov     eax, [bufferptr]
1804
        lea     eax, [esi + NET_BUFF.data]
1796
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1805
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
Line 1797... Line 1806...
1797
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1806
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1798
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1807
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1799
        [eax+13]:2,[eax+12]:2
1808
        [eax+13]:2,[eax+12]:2
1800
 
1809
 
Line 1801... Line 1810...
1801
        cmp     [buffersize], 1514
1810
        cmp     [esi + NET_BUFF.length], 1514
1802
        ja      .fail
1811
        ja      .fail
1803
        cmp     [buffersize], 60
1812
        cmp     [esi + NET_BUFF.length], 60
1804
        jb      .fail
1813
        jb      .fail
Line 1805... Line 1814...
1805
 
1814
 
1806
; get the descriptor address
1815
; get the descriptor address
-
 
1816
        mov     eax, [ebx + device.cur_tx]
1807
        mov     eax, [ebx + device.cur_tx]
1817
        shl     eax, 3                                  ; TX descriptor is 8 bytes.
1808
        shl     eax, 3                                  ; TX descriptor is 8 bytes.
1818
        lea     edi, [ebx + device.tx_ring + eax]
Line 1809... Line 1819...
1809
        lea     esi, [ebx + device.tx_ring + eax]
1819
 
1810
 
1820
        mov     eax, [bufferptr]
1811
        mov     eax, [bufferptr]
1821
        mov     [edi + TX_RING*sizeof.TxDesc], eax
Line 1812... Line 1822...
1812
        mov     [esi + TX_RING*sizeof.TxDesc], eax
1822
        add     eax, [eax + NET_BUFF.offset]
1813
        invoke  GetPhysAddr                             ; Does not change esi/ebx :)
1823
        invoke  GetPhysAddr                             ; Does not change esi/ebx :)
1814
        mov     [esi + TxDesc.PacketBuffer], eax
1824
        mov     [edi + TxDesc.PacketBuffer], eax
1815
 
1825
 
Line 1827... Line 1837...
1827
        inc     [ebx + device.cur_tx]
1837
        inc     [ebx + device.cur_tx]
1828
        and     [ebx + device.cur_tx], (TX_RING-1)
1838
        and     [ebx + device.cur_tx], (TX_RING-1)
Line 1829... Line 1839...
1829
 
1839
 
1830
; Update stats
1840
; Update stats
1831
        inc     [ebx + device.packets_tx]
-
 
1832
        mov     eax, [buffersize]
1841
        inc     [ebx + device.packets_tx]
1833
        add     dword[ebx + device.bytes_tx], eax
1842
        add     dword[ebx + device.bytes_tx], ecx
Line 1834... Line 1843...
1834
        adc     dword[ebx + device.bytes_tx + 4], 0
1843
        adc     dword[ebx + device.bytes_tx + 4], 0
1835
 
1844
 
1836
        popf
1845
        popf
Line 1837... Line 1846...
1837
        xor     eax, eax
1846
        xor     eax, eax
1838
        ret
1847
        ret
1839
 
1848
 
1840
  .fail:
1849
  .fail:
1841
        DEBUGF  2,"Send failed\n"
1850
        DEBUGF  2,"Send failed\n"
1842
        invoke  KernelFree, [bufferptr]
1851
        invoke  NetFree, [bufferptr]
Line 1843... Line 1852...
1843
        popf
1852
        popf
Line 1894... Line 1903...
1894
        pop     ebx
1903
        pop     ebx
1895
        mov     eax, [ebx + device.cur_rx]
1904
        mov     eax, [ebx + device.cur_rx]
1896
        mov     cx, sizeof.RxDesc
1905
        mov     cx, sizeof.RxDesc
1897
        mul     cx
1906
        mul     cx
1898
        lea     esi, [ebx + device.rx_ring + eax]
1907
        lea     esi, [ebx + device.rx_ring + eax]
1899
        mov     eax, [esi + RxDesc.FlagLen]
1908
        mov     ecx, [esi + RxDesc.FlagLen]
Line 1900... Line 1909...
1900
 
1909
 
1901
        test    eax, NV_RX_AVAIL        ; still owned by hardware
1910
        test    ecx, NV_RX_AVAIL        ; still owned by hardware
Line 1902... Line 1911...
1902
        jnz     .no_rx
1911
        jnz     .no_rx
1903
 
1912
 
1904
        cmp     [ebx + device.desc_ver], DESC_VER_1
1913
        cmp     [ebx + device.desc_ver], DESC_VER_1
1905
        jne     @f
1914
        jne     @f
1906
        test    eax, NV_RX_DESCRIPTORVALID
1915
        test    ecx, NV_RX_DESCRIPTORVALID
1907
        jz      .no_rx
1916
        jz      .no_rx
1908
        jmp     .next
1917
        jmp     .next
1909
  @@:
1918
  @@:
Line 1910... Line 1919...
1910
        test    eax, NV_RX2_DESCRIPTORVALID
1919
        test    ecx, NV_RX2_DESCRIPTORVALID
1911
        jz      .no_rx
1920
        jz      .no_rx
1912
 
1921
 
1913
  .next:
1922
  .next:
1914
        cmp     dword[ebx + device.desc_ver], DESC_VER_1
1923
        cmp     dword[ebx + device.desc_ver], DESC_VER_1
1915
        jne     @f
1924
        jne     @f
1916
        and     eax, LEN_MASK_V1
1925
        and     ecx, LEN_MASK_V1
Line 1917... Line 1926...
1917
        jmp     .next2
1926
        jmp     .next2
1918
   @@:
1927
   @@:
Line 1919... Line 1928...
1919
        and     eax, LEN_MASK_V2
1928
        and     ecx, LEN_MASK_V2
1920
 
1929
 
1921
  .next2:
1930
  .next2:
1922
        DEBUGF  1,"Received %u bytes\n", eax
1931
        DEBUGF  1,"Received %u bytes\n", ecx
Line 1923... Line 1932...
1923
 
1932
 
1924
        ; Update stats
1933
        ; Update stats
1925
        add     dword[ebx + device.bytes_rx], eax
1934
        add     dword[ebx + device.bytes_rx], ecx
Line -... Line 1935...
-
 
1935
        adc     dword[ebx + device.bytes_rx + 4], 0
1926
        adc     dword[ebx + device.bytes_rx + 4], 0
1936
        inc     dword[ebx + device.packets_rx]
-
 
1937
 
1927
        inc     dword[ebx + device.packets_rx]
1938
        ; Prepare to give packet to kernel
-
 
1939
        push    ebx
1928
 
1940
        push    .more_rx
Line 1929... Line 1941...
1929
        ; Prepare to give packet to kernel
1941
 
1930
        push    ebx
1942
        mov     eax, [esi + RX_RING*sizeof.RxDesc]
1931
        push    .more_rx
1943
        push    eax
1932
 
1944
        mov     [eax + NET_BUFF.device], ebx
-
 
1945
        mov     [eax + NET_BUFF.length], ecx
1933
        push    eax
1946
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
1934
        push    dword[esi + RX_RING*sizeof.RxDesc]
1947
        DEBUGF  1,"packet ptr=0x%x\n", [esi + RX_RING*sizeof.RxDesc]
Line 1935... Line 1948...
1935
        DEBUGF  1,"packet ptr=0x%x\n", [esi + RX_RING*sizeof.RxDesc]
1948
 
1936
 
1949
        ; Allocate new buffer for this descriptor
1937
        ; Allocate new buffer for this descriptor
1950
        invoke  NetAlloc, (4096 shl RBLEN) + NET_BUFF.data
Line 1938... Line 1951...
1938
        invoke  KernelAlloc, 4096 shl RBLEN
1951
        mov     [esi + RX_RING*sizeof.RxDesc], eax
Line 1939... Line 1952...
1939
        mov     [esi + RX_RING*sizeof.RxDesc], eax
1952
        invoke  GetPhysAddr
1940
        invoke  GetPhysAddr
1953
        add     eax, NET_BUFF.data
1941
        mov     [esi + RxDesc.PacketBuffer], eax
1954
        mov     [esi + RxDesc.PacketBuffer], eax
Line 1997... Line 2010...
1997
        je      .no_tx
2010
        je      .no_tx
Line 1998... Line 2011...
1998
 
2011
 
1999
        DEBUGF  1,"Freeing buffer 0x%x\n", [esi + TX_RING*sizeof.TxDesc]:8
2012
        DEBUGF  1,"Freeing buffer 0x%x\n", [esi + TX_RING*sizeof.TxDesc]:8
2000
        push    dword[esi + TX_RING*sizeof.TxDesc]
2013
        push    dword[esi + TX_RING*sizeof.TxDesc]
2001
        mov     dword[esi + TX_RING*sizeof.TxDesc], 0
2014
        mov     dword[esi + TX_RING*sizeof.TxDesc], 0
Line 2002... Line 2015...
2002
        invoke  KernelFree
2015
        invoke  NetFree
2003
 
2016
 
Line 2004... Line 2017...
2004
        inc     [ebx + device.last_tx]
2017
        inc     [ebx + device.last_tx]