Subversion Repositories Kolibri OS

Rev

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

Rev 5617 Rev 8897
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                  ;;
2
;;                                                                  ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.     ;;
3
;; Copyright (C) KolibriOS team 2004-2021. All rights reserved.     ;;
4
;; Distributed under terms of the GNU General Public License        ;;
4
;; Distributed under terms of the GNU General Public License        ;;
5
;;                                                                  ;;
5
;;                                                                  ;;
6
;;  AMD PCnet driver for KolibriOS                                  ;;
6
;;  AMD PCnet driver for KolibriOS                                  ;;
7
;;                                                                  ;;
7
;;                                                                  ;;
8
;;  By hidnplayr & clevermouse                                      ;;
8
;;  By hidnplayr & clevermouse                                      ;;
Line 19... Line 19...
19
 
19
 
20
        CURRENT_API             = 0x0200
20
        CURRENT_API             = 0x0200
21
        COMPATIBLE_API          = 0x0100
21
        COMPATIBLE_API          = 0x0100
Line 22... Line 22...
22
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
22
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
Line -... Line 23...
-
 
23
 
-
 
24
; configureable area
23
 
25
 
24
        MAX_DEVICES             = 16
26
        MAX_DEVICES             = 16    ; Maximum number of devices this driver may handle
Line 25... Line 27...
25
 
27
 
26
        __DEBUG__               = 1
28
        __DEBUG__               = 1     ; 1 = on, 0 = off
-
 
29
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
-
 
30
 
Line 27... Line 31...
27
        __DEBUG_LEVEL__         = 2             ; 1 = verbose, 2 = errors only
31
        TX_RING_SIZE            = 32    ; Number of packets in send ring buffer
Line 28... Line 32...
28
 
32
        RX_RING_SIZE            = 32    ; Number of packets in receive ring buffer
29
        TX_RING_SIZE            = 4
33
 
30
        RX_RING_SIZE            = 4
34
; end configureable area
31
 
35
 
32
section '.flat' readable writable executable
36
section '.flat' readable writable executable
Line -... Line 37...
-
 
37
 
-
 
38
include '../struct.inc'
-
 
39
include '../macros.inc'
-
 
40
include '../proc32.inc'
-
 
41
include '../fdo.inc'
-
 
42
include '../netdrv.inc'
-
 
43
 
-
 
44
if (bsr TX_RING_SIZE)>(bsf TX_RING_SIZE)
-
 
45
  display 'TX_RING_SIZE must be a power of two'
Line 33... Line 46...
33
 
46
  err
34
include '../struct.inc'
47
end if
35
include '../macros.inc'
48
 
36
include '../proc32.inc'
49
if (bsr RX_RING_SIZE)>(bsf RX_RING_SIZE)
Line 47... Line 60...
47
        PORT_100                = 0x40
60
        PORT_100                = 0x40
48
        PORT_FD                 = 0x80
61
        PORT_FD                 = 0x80
Line 49... Line 62...
49
 
62
 
Line 50... Line -...
50
        DMA_MASK                = 0xffffffff
-
 
51
 
-
 
52
        LOG_TX_BUFFERS          = 2             ; FIXME
-
 
53
        LOG_RX_BUFFERS          = 2
-
 
54
 
63
        DMA_MASK                = 0xffffffff
55
        TX_RING_MOD_MASK        = (TX_RING_SIZE-1)
-
 
56
        TX_RING_LEN_BITS        = (LOG_TX_BUFFERS shl 12)
-
 
57
 
64
 
Line 58... Line 65...
58
        RX_RING_MOD_MASK        = (RX_RING_SIZE-1)
65
        TX_RING_LEN_BITS        = ((bsf TX_RING_SIZE) shl 12)
Line 59... Line 66...
59
        RX_RING_LEN_BITS        = (LOG_RX_BUFFERS shl 4)
66
        RX_RING_LEN_BITS        = ((bsf RX_RING_SIZE) shl 4)
60
 
67
 
Line 279... Line 286...
279
        TXCTL_BUFSZ             = 0x00000FFF
286
        TXCTL_BUFSZ             = 0x00000FFF
Line 280... Line 287...
280
 
287
 
Line 281... Line -...
281
        MAX_PHYS                = 32
-
 
282
 
-
 
283
 
-
 
284
struct  device          ETH_DEVICE
-
 
285
 
288
        MAX_PHYS                = 32
-
 
289
 
-
 
290
 
286
        rb 0x100-($ and 0xff)   ; align 256
291
; Pcnet configuration structure
287
 
292
struct  pcnet_init_block
288
; Pcnet configuration structure
293
 
289
        mode            dw ?
294
        mode            dw ?
290
        tlen_rlen       dw ?
295
        tlen_rlen       dw ?
291
        phys_addr       dp ?
296
        phys_addr       dp ?
292
        reserved        dw ?
297
        reserved        dw ?
-
 
298
        filter          dq ?
-
 
299
        rx_ring_phys    dd ?
-
 
300
        tx_ring_phys    dd ?
293
        filter          dq ?
301
ends
Line 294... Line 302...
294
        rx_ring_phys    dd ?
302
 
-
 
303
 
Line -... Line 304...
-
 
304
struct  device          ETH_DEVICE
295
        tx_ring_phys    dd ?
305
 
Line 296... Line 306...
296
; end of pcnet config struct
306
        rb 0x100-($ and 0xff)   ; align 256
297
 
-
 
298
        rb 0x100-($ and 0xff)   ; align 256
307
        init_block      pcnet_init_block
Line 299... Line 308...
299
 
308
 
300
        rx_ring         rb RX_RING_SIZE * sizeof.descriptor
309
        rb 0x100-($ and 0xff)   ; align 256
301
 
310
        rx_ring         rb RX_RING_SIZE * sizeof.descriptor
-
 
311
 
302
        rb 0x100-($ and 0xff)   ; align 256
312
        rb 0x100-($ and 0xff)   ; align 256
303
 
313
        tx_ring         rb TX_RING_SIZE * sizeof.descriptor
304
        tx_ring         rb TX_RING_SIZE * sizeof.descriptor
314
 
305
 
315
        cur_rx          dd ?
306
        cur_rx          db ?
316
        cur_tx          dd ?
Line 320... Line 330...
320
        pci_bus         dd ?
330
        pci_bus         dd ?
321
        pci_dev         dd ?
331
        pci_dev         dd ?
Line 322... Line 332...
322
 
332
 
Line -... Line 333...
-
 
333
        phy             dw ?
-
 
334
 
323
        phy             dw ?
335
        rb 0x100-($ and 0xff)   ; align 256
324
 
336
 
325
        read_csr        dd ?
337
        read_csr        dd ?
326
        write_csr       dd ?
338
        write_csr       dd ?
327
        read_bcr        dd ?
339
        read_bcr        dd ?
Line 691... Line 703...
691
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
703
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
692
        or      al, PCI_CMD_MASTER
704
        or      al, PCI_CMD_MASTER
693
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
705
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
Line 694... Line 706...
694
 
706
 
695
        mov     [ebx + device.options], PORT_ASEL
707
        mov     [ebx + device.options], PORT_ASEL
696
        mov     [ebx + device.mode], MODE_RXD + MODE_TXD     ; disable receive and transmit
708
        mov     [ebx + device.init_block.mode], MODE_RXD + MODE_TXD     ; disable receive and transmit
Line 697... Line 709...
697
        mov     [ebx + device.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS)
709
        mov     [ebx + device.init_block.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS)
698
 
710
 
Line 699... Line 711...
699
        mov     dword[ebx + device.filter], 0
711
        mov     dword[ebx + device.init_block.filter], 0
700
        mov     dword[ebx + device.filter+4], 0
712
        mov     dword[ebx + device.init_block.filter+4], 0
Line 701... Line 713...
701
 
713
 
Line 801... Line 813...
801
        call    [ebx + device.write_csr]
813
        call    [ebx + device.write_csr]
802
  @@:
814
  @@:
803
        mov     eax, [ebx + device.options]
815
        mov     eax, [ebx + device.options]
804
        and     eax, PORT_PORTSEL
816
        and     eax, PORT_PORTSEL
805
        shl     eax, 7
817
        shl     eax, 7
806
        mov     [ebx + device.mode], ax
818
        mov     [ebx + device.init_block.mode], ax
807
        mov     dword [ebx + device.filter], -1
819
        mov     dword [ebx + device.init_block.filter], -1
808
        mov     dword [ebx + device.filter+4], -1
820
        mov     dword [ebx + device.init_block.filter+4], -1
Line 809... Line 821...
809
 
821
 
Line 858... Line 870...
858
;-----------------------------------------------
870
;-----------------------------------------------
Line 859... Line 871...
859
 
871
 
Line 860... Line 872...
860
        call    read_mac
872
        call    read_mac
861
 
873
 
862
        lea     esi, [ebx + device.mac]
874
        lea     esi, [ebx + device.mac]
863
        lea     edi, [ebx + device.phys_addr]
875
        lea     edi, [ebx + device.init_block.phys_addr]
Line 864... Line 876...
864
        movsd
876
        movsd
865
        movsw
877
        movsw
866
 
878
 
Line 867... Line 879...
867
        call    init_ring
879
        call    init_ring
Line 868... Line 880...
868
        test    eax, eax
880
        test    eax, eax
869
        jnz     .fail
881
        jnz     .fail
870
 
882
 
871
        mov     edx, [ebx + device.io_addr]   ; init ring destroys edx
883
        mov     edx, [ebx + device.io_addr]     ; init ring destroys edx
872
 
884
 
873
        lea     eax, [ebx + device.mode]
885
        lea     eax, [ebx + device.init_block]
874
        invoke  GetPhysAddr
886
        invoke  GetPhysAddr
875
        push    eax
887
        push    eax
876
        and     eax, 0xffff
888
        and     eax, 0xffff
877
        mov     ecx, 1
889
        mov     ecx, CSR_IAB0
Line 878... Line 890...
878
        call    [ebx + device.write_csr]
890
        call    [ebx + device.write_csr]
879
        pop     eax
891
        pop     eax
880
        shr     eax, 16
892
        shr     eax, 16
Line 881... Line 893...
881
        mov     ecx, 2
893
        mov     ecx, CSR_IAB1
882
        call    [ebx + device.write_csr]
894
        call    [ebx + device.write_csr]
883
 
895
 
Line 932... Line 944...
932
        DEBUGF  1,"init ring\n"
944
        DEBUGF  1,"init ring\n"
Line 933... Line 945...
933
 
945
 
934
        lea     edi, [ebx + device.rx_ring]
946
        lea     edi, [ebx + device.rx_ring]
935
        mov     eax, edi
947
        mov     eax, edi
936
        invoke  GetPhysAddr
948
        invoke  GetPhysAddr
937
        mov     [ebx + device.rx_ring_phys], eax
949
        mov     [ebx + device.init_block.rx_ring_phys], eax
938
        mov     ecx, RX_RING_SIZE
950
        mov     ecx, RX_RING_SIZE
939
  .rx_init:
951
  .rx_init:
940
        push    ecx
952
        push    ecx
941
        invoke  NetAlloc, PKT_BUF_SZ+NET_BUFF.data
953
        invoke  NetAlloc, PKT_BUF_SZ+NET_BUFF.data
Line 945... Line 957...
945
        mov     [edi + descriptor.virtual], eax
957
        mov     [edi + descriptor.virtual], eax
946
        invoke  GetPhysAddr
958
        invoke  GetPhysAddr
947
        add     eax, NET_BUFF.data
959
        add     eax, NET_BUFF.data
948
        mov     [edi + descriptor.base], eax
960
        mov     [edi + descriptor.base], eax
949
        mov     [edi + descriptor.length], - PKT_BUF_SZ
961
        mov     [edi + descriptor.length], - PKT_BUF_SZ
950
        mov     [edi + descriptor.status], RXSTAT_OWN
-
 
951
        mov     dword[edi + descriptor.msg_length], 0    ; also clears misc field
962
        mov     dword[edi + descriptor.msg_length], 0    ; also clears misc field
-
 
963
        mov     [edi + descriptor.status], RXSTAT_OWN
952
        add     edi, sizeof.descriptor
964
        add     edi, sizeof.descriptor
953
        dec     ecx
965
        dec     ecx
954
        jnz     .rx_init
966
        jnz     .rx_init
Line 955... Line 967...
955
 
967
 
956
        lea     edi, [ebx + device.tx_ring]
968
        lea     edi, [ebx + device.tx_ring]
957
        mov     eax, edi
969
        mov     eax, edi
958
        invoke  GetPhysAddr
970
        invoke  GetPhysAddr
959
        mov     [ebx + device.tx_ring_phys], eax
971
        mov     [ebx + device.init_block.tx_ring_phys], eax
960
        mov     ecx, TX_RING_SIZE
972
        mov     ecx, TX_RING_SIZE
961
  .tx_init:
973
  .tx_init:
962
        mov     [edi + descriptor.status], 0
974
        mov     [edi + descriptor.status], 0
963
        add     edi, sizeof.descriptor
975
        add     edi, sizeof.descriptor
964
        dec     ecx
976
        dec     ecx
Line 965... Line 977...
965
        jnz     .tx_init
977
        jnz     .tx_init
Line 966... Line 978...
966
 
978
 
967
        mov     [ebx + device.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS)
979
        mov     [ebx + device.init_block.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS)
968
 
980
 
Line 1008... Line 1020...
1008
        cmp     [esi + NET_BUFF.length], 60
1020
        cmp     [esi + NET_BUFF.length], 60
1009
        jb      .fail
1021
        jb      .fail
Line 1010... Line 1022...
1010
 
1022
 
1011
; check descriptor
1023
; check descriptor
1012
        lea     edi, [ebx + device.tx_ring]
1024
        lea     edi, [ebx + device.tx_ring]
1013
        movzx   ecx, [ebx + device.cur_tx]
1025
        mov     ecx, [ebx + device.cur_tx]
1014
        shl     ecx, 4
1026
        shl     ecx, 4
Line 1015... Line 1027...
1015
        add     edi, ecx
1027
        add     edi, ecx
1016
 
1028
 
Line 1034... Line 1046...
1034
        xor     ecx, ecx                        ; CSR0
1046
        xor     ecx, ecx                        ; CSR0
1035
        call    [ebx + device.read_csr]
1047
        call    [ebx + device.read_csr]
1036
        or      eax, CSR_TX
1048
        or      eax, CSR_TX
1037
        call    [ebx + device.write_csr]
1049
        call    [ebx + device.write_csr]
Line 1038... Line 1050...
1038
 
1050
 
1039
; get next descriptor 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...
1051
; get next descriptor
1040
        inc     [ebx + device.cur_tx]
1052
        inc     [ebx + device.cur_tx]
Line 1041... Line 1053...
1041
        and     [ebx + device.cur_tx], TX_RING_SIZE - 1
1053
        and     [ebx + device.cur_tx], TX_RING_SIZE - 1
1042
 
1054
 
Line 1108... Line 1120...
1108
        jz      .not_receive
1120
        jz      .not_receive
Line 1109... Line 1121...
1109
 
1121
 
1110
        push    ebx
1122
        push    ebx
1111
  .rx_loop:
1123
  .rx_loop:
1112
        pop     ebx
1124
        pop     ebx
1113
        movzx   eax, [ebx + device.cur_rx]
1125
        mov     eax, [ebx + device.cur_rx]
1114
        shl     eax, 4
1126
        shl     eax, 4
1115
        lea     edi, [ebx + device.rx_ring]
1127
        lea     edi, [ebx + device.rx_ring]
Line 1116... Line 1128...
1116
        add     edi, eax                        ; edi now points to current rx ring entry
1128
        add     edi, eax                        ; edi now points to current rx ring entry
Line 1175... Line 1187...
1175
        test    ax, CSR_TINT
1187
        test    ax, CSR_TINT
1176
        jz      .not_transmit
1188
        jz      .not_transmit
Line 1177... Line 1189...
1177
 
1189
 
1178
  .tx_loop:
1190
  .tx_loop:
1179
        lea     edi, [ebx + device.tx_ring]
1191
        lea     edi, [ebx + device.tx_ring]
1180
        movzx   eax, [ebx + device.last_tx]
1192
        mov     eax, [ebx + device.last_tx]
1181
        shl     eax, 4
1193
        shl     eax, 4
Line 1182... Line 1194...
1182
        add     edi, eax
1194
        add     edi, eax
1183
 
1195