Subversion Repositories Kolibri OS

Rev

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

Rev 5494 Rev 5498
Line 247... Line 247...
247
        irq_line        db ?
247
        irq_line        db ?
248
                        rb 3 ; align 4
248
                        rb 3 ; align 4
249
        mmio_addr       dd ? ; memory map physical address
249
        mmio_addr       dd ? ; memory map physical address
250
        pcfg            dd ?
250
        pcfg            dd ?
251
        mcfg            dd ?
251
        mcfg            dd ?
-
 
252
 
252
        cur_rx          dd ? ; Index into the Rx descriptor buffer of next Rx pkt
253
        cur_rx          dd ? ; Index into the Rx descriptor buffer of next Rx pkt
253
        cur_tx          dd ? ; Index into the Tx descriptor buffer of next Rx pkt
254
        cur_tx          dd ? ; Index into the Tx descriptor buffer of next Rx pkt
254
        TxDescArrays    dd ? ; Index of Tx Descriptor buffer
-
 
255
        RxDescArrays    dd ? ; Index of Rx Descriptor buffer
255
        last_tx         dd ?
256
        TxDescArray     dd ? ; Index of 256-alignment Tx Descriptor buffer
-
 
257
        RxDescArray     dd ? ; Index of 256-alignment Rx Descriptor buffer
-
 
258
        mac_version     dd ?
256
        mac_version     dd ?
Line 259... Line 257...
259
 
257
 
260
        rb 0x100-($ and 0xff)   ; align 256
258
        rb 0x100-($ and 0xff)   ; align 256
Line 661... Line 659...
661
align 4
659
align 4
662
reset:
660
reset:
Line 663... Line 661...
663
 
661
 
Line 664... Line -...
664
        DEBUGF  1,"resetting\n"
-
 
665
 
-
 
666
        lea     eax, [ebx + device.tx_ring]
-
 
667
        mov     [ebx + device.TxDescArrays], eax
-
 
668
        mov     [ebx + device.TxDescArray], eax
-
 
669
 
-
 
670
        lea     eax, [ebx + device.rx_ring]
-
 
671
        mov     [ebx + device.RxDescArrays], eax
-
 
672
        mov     [ebx + device.RxDescArray], eax
662
        DEBUGF  1,"resetting\n"
673
 
663
 
Line 674... Line 664...
674
        call    init_ring
664
        call    init_ring
Line 680... Line 670...
680
        lea     edi, [ebx + device.bytes_tx]
670
        lea     edi, [ebx + device.bytes_tx]
681
        mov     ecx, 6
671
        mov     ecx, 6
682
        rep     stosd
672
        rep     stosd
Line 683... Line 673...
683
 
673
 
684
        mov     [ebx + device.mtu], 1500
-
 
685
 
674
        mov     [ebx + device.mtu], 1500
686
; Set link state to unknown
-
 
Line 687... Line 675...
687
        mov     [ebx + device.state], ETH_LINK_UNKNOWN
675
        call    detect_link
688
 
676
 
689
        DEBUGF  2,"init OK!\n"
677
        DEBUGF  2,"init OK!\n"
Line 796... Line 784...
796
        DEBUGF  1,"init_ring\n"
784
        DEBUGF  1,"init_ring\n"
Line 797... Line 785...
797
 
785
 
798
        xor     eax, eax
786
        xor     eax, eax
799
        mov     [ebx + device.cur_rx], eax
787
        mov     [ebx + device.cur_rx], eax
-
 
788
        mov     [ebx + device.cur_tx], eax
Line 800... Line 789...
800
        mov     [ebx + device.cur_tx], eax
789
        mov     [ebx + device.last_tx], eax
801
 
790
 
802
        lea     edi, [ebx + device.tx_ring]
791
        lea     edi, [ebx + device.tx_ring]
Line 803... Line 792...
803
        mov     ecx, (NUM_TX_DESC * sizeof.tx_desc) / 4
792
        mov     ecx, (NUM_TX_DESC * sizeof.tx_desc) / 4 * 2
804
        rep     stosd
793
        rep     stosd
805
 
794
 
Line 806... Line 795...
806
        lea     edi, [ebx + device.rx_ring]
795
        lea     edi, [ebx + device.rx_ring]
807
        mov     ecx, (NUM_RX_DESC * sizeof.rx_desc) / 4
796
        mov     ecx, (NUM_RX_DESC * sizeof.rx_desc) / 4
808
        rep     stosd
797
        rep     stosd
809
 
798
 
810
        mov     edi, [ebx + device.RxDescArray]
799
        lea     edi, [ebx + device.rx_ring]
811
        mov     ecx, NUM_RX_DESC
800
        mov     ecx, NUM_RX_DESC
812
  .loop:
801
  .loop:
813
        push    ecx
802
        push    ecx
814
        invoke  KernelAlloc, RX_BUF_SIZE
803
        invoke  KernelAlloc, RX_BUF_SIZE
815
        mov     dword [edi + rx_desc.buf_soft_addr], eax
804
        mov     dword [edi + rx_desc.buf_soft_addr], eax
816
        invoke  GetPgAddr
805
        invoke  GetPhysAddr
817
        mov     dword [edi + rx_desc.buf_addr], eax
806
        mov     dword [edi + rx_desc.buf_addr], eax
Line 971... Line 960...
971
        xor     ecx, ecx
960
        xor     ecx, ecx
972
        lea     edi, [ebx + device.mac]
961
        lea     edi, [ebx + device.mac]
973
        mov     ecx, 6
962
        mov     ecx, 6
Line 974... Line 963...
974
 
963
 
-
 
964
        ; Get MAC address. FIXME: read EEPROM
975
        ; Get MAC address. FIXME: read EEPROM
965
    @@:
976
    @@: in      al, dx
966
        in      al, dx
977
        stosb
967
        stosb
978
        inc     edx
968
        inc     edx
Line 979... Line 969...
979
        loop    @r
969
        loop    @r
Line 1024... Line 1014...
1024
        mul     [ebx + device.cur_tx]
1014
        mul     [ebx + device.cur_tx]
1025
        lea     esi, [ebx + device.tx_ring + eax]
1015
        lea     esi, [ebx + device.tx_ring + eax]
Line 1026... Line 1016...
1026
 
1016
 
Line -... Line 1017...
-
 
1017
        DEBUGF  1,"Using TX desc: %x\n", esi
-
 
1018
 
-
 
1019
;----------------------------------
-
 
1020
; Check if the descriptor is in use
-
 
1021
 
-
 
1022
        test    [esi + tx_desc.status], DSB_OWNbit
1027
        DEBUGF  1,"Using TX desc: %x\n", esi
1023
        jnz     .desc
1028
 
1024
 
Line 1029... Line 1025...
1029
;---------------------------
1025
;---------------------------
1030
; Program the packet pointer
1026
; Program the packet pointer
Line 1036... Line 1032...
1036
 
1032
 
1037
;------------------------
1033
;------------------------
Line 1038... Line 1034...
1038
; Program the packet size
1034
; Program the packet size
-
 
1035
 
1039
 
1036
        mov     eax, [buffersize]
1040
        mov     eax, [buffersize]
1037
    @@:
1041
    @@: or      eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit
1038
        or      eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit
1042
        cmp     [ebx + device.cur_tx], NUM_TX_DESC - 1
1039
        cmp     [ebx + device.cur_tx], NUM_TX_DESC - 1
-
 
1040
        jne     @f
1043
        jne     @f
1041
        or      eax, DSB_EORbit
Line 1044... Line 1042...
1044
        or      eax, DSB_EORbit
1042
    @@:
1045
    @@: mov     [esi + tx_desc.status], eax
1043
        mov     [esi + tx_desc.status], eax
Line 1046... Line 1044...
1046
 
1044
 
Line 1068... Line 1066...
1068
 
1066
 
1069
        popf
1067
        popf
1070
        xor     eax, eax
1068
        xor     eax, eax
Line -... Line 1069...
-
 
1069
        ret
-
 
1070
 
1071
        ret
1071
  .desc:
1072
 
1072
        DEBUGF  2,"Descriptor is still in use!\n"
1073
  .fail:
1073
  .fail:
1074
        DEBUGF  2,"Transmit failed\n"
1074
        DEBUGF  2,"Transmit failed\n"
1075
        invoke  KernelFree, [bufferptr]
1075
        invoke  KernelFree, [bufferptr]
1076
        popf
1076
        popf
Line 1077... Line 1077...
1077
        or      eax, -1
1077
        or      eax, -1
Line 1078... Line -...
1078
        ret
-
 
1079
 
-
 
Line 1080... Line 1078...
1080
endp
1078
        ret
1081
 
1079
 
1082
 
1080
endp
1083
;;;DSB_OWNbit
1081
 
Line 1106... Line 1104...
1106
        mov     ebx, [esi]
1104
        mov     ebx, [esi]
Line 1107... Line 1105...
1107
 
1105
 
1108
        set_io  [ebx + device.io_addr], 0
1106
        set_io  [ebx + device.io_addr], 0
1109
        set_io  [ebx + device.io_addr], REG_IntrStatus
1107
        set_io  [ebx + device.io_addr], REG_IntrStatus
-
 
1108
        in      ax, dx
-
 
1109
        out     dx, ax                                  ; ACK all interrupts
-
 
1110
        cmp     ax, 0xffff                              ; if so, hardware is no longer present
1110
        in      ax, dx
1111
        je      .nothing
1111
        test    ax, ax
1112
        test    ax, ax
1112
        jnz     .got_it
1113
        jnz     .got_it
1113
  .continue:
1114
  .continue:
1114
        add     esi, 4
1115
        add     esi, 4
Line 1119... Line 1120...
1119
        xor     eax, eax
1120
        xor     eax, eax
Line 1120... Line 1121...
1120
 
1121
 
Line 1121... Line 1122...
1121
        ret                                             ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
1122
        ret                                             ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
1122
 
-
 
1123
  .got_it:
1123
 
Line 1124... Line -...
1124
 
-
 
1125
        DEBUGF  1,"Device: %x Status: %x\n", ebx, ax
-
 
1126
 
-
 
1127
        cmp     ax, 0xFFFF      ; if so, hardware is no longer present
1124
  .got_it:
1128
        je      .fail
1125
        DEBUGF  1,"Device: %x Status: %x\n", ebx, ax
1129
 
-
 
1130
;--------
1126
 
1131
; Receive
1127
;--------
Line 1132... Line 1128...
1132
 
1128
; Receive
1133
        test    ax, ISB_RxOK
1129
        test    ax, ISB_RxOK
Line 1143... Line 1139...
1143
        lea     esi, [ebx + device.rx_ring + eax]
1139
        lea     esi, [ebx + device.rx_ring + eax]
Line 1144... Line 1140...
1144
 
1140
 
1145
        DEBUGF  1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
1141
        DEBUGF  1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
1146
        mov     eax, [esi + rx_desc.status]
1142
        mov     eax, [esi + rx_desc.status]
1147
        test    eax, DSB_OWNbit ;;;
1143
        test    eax, DSB_OWNbit ;;;
Line 1148... Line 1144...
1148
        jnz     .rx_return
1144
        jnz     .no_own
Line 1149... Line 1145...
1149
 
1145
 
1150
        DEBUGF  1,"cur_rx = %u\n", [ebx + device.cur_rx]
1146
        DEBUGF  1,"cur_rx = %u\n", [ebx + device.cur_rx]
Line 1157... Line 1153...
1157
        and     eax, 0x00001FFF
1153
        and     eax, 0x00001FFF
1158
        add     eax, -4                         ; we dont need CRC
1154
        add     eax, -4                         ; we dont need CRC
1159
        push    eax
1155
        push    eax
1160
        DEBUGF  1,"data length = %u\n", ax
1156
        DEBUGF  1,"data length = %u\n", ax
Line 1161... Line -...
1161
 
-
 
1162
;-------------
1157
 
Line 1163... Line 1158...
1163
; Update stats
1158
        ; Update stats
1164
 
1159
 
1165
        add     dword [ebx + device.bytes_rx], eax
1160
        add     dword [ebx + device.bytes_rx], eax
Line 1166... Line 1161...
1166
        adc     dword [ebx + device.bytes_rx + 4], 0
1161
        adc     dword [ebx + device.bytes_rx + 4], 0
Line 1167... Line -...
1167
        inc     [ebx + device.packets_rx]
-
 
1168
 
1162
        inc     [ebx + device.packets_rx]
Line 1169... Line 1163...
1169
        pushd   [esi + rx_desc.buf_soft_addr]
1163
 
1170
 
1164
        pushd   [esi + rx_desc.buf_soft_addr]
1171
;----------------------
1165
 
1172
; Allocate a new buffer
1166
        ; Allocate a new buffer
Line 1173... Line -...
1173
 
-
 
1174
        invoke  KernelAlloc, RX_BUF_SIZE
1167
 
Line 1175... Line 1168...
1175
        mov     [esi + rx_desc.buf_soft_addr], eax
1168
        invoke  KernelAlloc, RX_BUF_SIZE
1176
        invoke  GetPhysAddr
1169
        mov     [esi + rx_desc.buf_soft_addr], eax
1177
        mov     dword [esi + rx_desc.buf_addr], eax
1170
        invoke  GetPhysAddr
1178
 
1171
        mov     dword [esi + rx_desc.buf_addr], eax
1179
;---------------
1172
 
1180
; re set OWN bit
1173
        ; reset OWN bit
Line 1181... Line -...
1181
 
-
 
1182
        mov     eax, DSB_OWNbit or RX_BUF_SIZE
1174
 
Line 1183... Line 1175...
1183
        cmp     [ebx + device.cur_rx], NUM_RX_DESC - 1
1175
        mov     eax, DSB_OWNbit or RX_BUF_SIZE
1184
        jne     @f
1176
        cmp     [ebx + device.cur_rx], NUM_RX_DESC - 1
Line 1185... Line 1177...
1185
        or      eax, DSB_EORbit
1177
        jne     @f
1186
    @@:
1178
        or      eax, DSB_EORbit
-
 
1179
    @@:
1187
        mov     [esi + rx_desc.status], eax
1180
        mov     [esi + rx_desc.status], eax
1188
 
1181
 
1189
;--------------
1182
        ; Update rx ptr
Line 1190... Line 1183...
1190
; Update rx ptr
1183
 
1191
 
1184
        inc     [ebx + device.cur_rx]
Line 1192... Line 1185...
1192
        inc     [ebx + device.cur_rx]
1185
        and     [ebx + device.cur_rx], NUM_RX_DESC - 1
1193
        and     [ebx + device.cur_rx], NUM_RX_DESC - 1
1186
 
1194
 
-
 
Line 1195... Line 1187...
1195
        jmp     [Eth_input]
1187
        jmp     [Eth_input]
1196
  .rx_return:
-
 
1197
 
-
 
1198
        pop     ax
-
 
1199
  .no_rx:
1188
  .rx_return:
-
 
1189
        DEBUGF  1,"RX error!\n"
-
 
1190
  .no_own:
-
 
1191
        pop     ax
-
 
1192
  .no_rx:
1200
 
1193
 
1201
;---------
1194
;-----------------
Line 1202... Line 1195...
1202
; Transmit
1195
; Transmit cleanup
1203
 
1196
 
Line 1204... Line -...
1204
        test    ax, ISB_TxOK
-
 
1205
        jz      .no_tx
1197
        test    ax, ISB_TxOK or ISB_TxErr or ISB_TxDescUnavail
1206
        push    ax
1198
        jz      .no_tx
1207
 
1199
 
-
 
1200
        DEBUGF  1,"TX done!\n"
1208
        DEBUGF  1,"TX ok!\n"
1201
  .txloop:
-
 
1202
        mov     esi, [ebx + device.last_tx]
-
 
1203
        imul    esi, sizeof.tx_desc
Line 1209... Line -...
1209
 
-
 
1210
        mov     ecx, NUM_TX_DESC
1204
        lea     esi, [ebx + device.tx_ring + esi]
1211
        lea     esi, [ebx + device.tx_ring]
1205
 
1212
  .txloop:
1206
        cmp     dword [esi + tx_desc.buf_soft_addr], 0
1213
        cmp     dword [esi + tx_desc.buf_soft_addr], 0
-
 
1214
        jz      .maybenext
-
 
1215
 
1207
        je      .no_tx
Line 1216... Line -...
1216
        test    [esi + tx_desc.status], DSB_OWNbit
-
 
1217
        jnz     .maybenext
1208
 
1218
 
-
 
1219
        push    ecx
1209
        test    [esi + tx_desc.status], DSB_OWNbit
1220
        DEBUGF  1,"Freeing up TX desc: %x\n", esi
1210
        jnz     .no_tx
1221
        invoke  KernelFree, [esi + tx_desc.buf_soft_addr]
1211
 
-
 
1212
        DEBUGF  1,"Freeing up TX desc: 0x%x\n", esi
Line 1222... Line -...
1222
        pop     ecx
-
 
1223
        and     dword [esi + tx_desc.buf_soft_addr], 0
1213
        DEBUGF  1,"buff: 0x%x\n", [esi + tx_desc.buf_soft_addr]
1224
 
1214
        push    eax
1225
  .maybenext:
1215
        push    dword [esi + tx_desc.buf_soft_addr]
Line 1226... Line 1216...
1226
        add     esi, sizeof.tx_desc
1216
        and     dword [esi + tx_desc.buf_soft_addr], 0
Line -... Line 1217...
-
 
1217
        invoke  KernelFree
-
 
1218
        pop     eax
-
 
1219
 
-
 
1220
        inc     [ebx + device.last_tx]
-
 
1221
        and     [ebx + device.last_tx], NUM_TX_DESC-1
-
 
1222
        jmp     .txloop
-
 
1223
  .no_tx:
-
 
1224
 
-
 
1225
        test    ax, ISB_LinkChg
-
 
1226
        jz      .no_linkchange
-
 
1227
        DEBUGF  2, "Link change detected\n"
-
 
1228
        call    detect_link
-
 
1229
  .no_linkchange:
-
 
1230
 
-
 
1231
        pop     edi esi ebx
-
 
1232
        xor     eax, eax
-
 
1233
        inc     eax
-
 
1234
 
-
 
1235
        ret
-
 
1236
 
-
 
1237
 
-
 
1238
 
-
 
1239
align 4
-
 
1240
detect_link:
-
 
1241
 
-
 
1242
        set_io  [ebx + device.io_addr], 0
-
 
1243
 
-
 
1244
;        set_io  [ebx + device.io_addr], REG_TBICSR
-
 
1245
;        in      eax, dx
-
 
1246
;        test    eax, TBI_LinkOK
-
 
1247
;        jz      .down
-
 
1248
 
-
 
1249
;        mov     [ebx + device.state], ETH_LINK_UNKNOWN
-
 
1250
;        invoke  NetLinkChanged
-
 
1251
;        ret
-
 
1252
 
-
 
1253
        set_io  [ebx + device.io_addr], REG_PHYstatus
-
 
1254
        in      al, dx
-
 
1255
        test    al, PHYS_LinkStatus
-
 
1256
        jz      .down
-
 
1257
        DEBUGF  2, "Link is up, phystatus=0x%x\n", al
-
 
1258
        xor     ecx, ecx
-
 
1259
        test    al, PHYS_10bps
-
 
1260
        jz      @f
-
 
1261
        or      cl, ETH_LINK_10M
-
 
1262
  @@:
-
 
1263
        test    al, PHYS_100bps
-
 
1264
        jz      @f
1227
        dec     ecx
1265
        or      cl, ETH_LINK_100M
Line 1228... Line 1266...
1228
        jnz     .txloop
1266
  @@:
1229
 
1267
        test    al, PHYS_1000bpsF