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 287... Line 287...
287
        RxStation               = 1
287
        RxStation               = 1
288
        RxMulticast             = 2
288
        RxMulticast             = 2
289
        RxBroadcast             = 4
289
        RxBroadcast             = 4
290
        RxProm                  = 8
290
        RxProm                  = 8
Line 291... Line -...
291
 
-
 
292
; RX/TX buffers sizes
291
 
293
        MAX_ETH_PKT_SIZE        = 1536          ; max packet size
-
 
Line 294... Line 292...
294
        MAX_ETH_FRAME_SIZE      = 1520          ; size of ethernet frame + bytes alignment
292
        MAX_ETH_FRAME_SIZE      = 1514
Line 295... Line 293...
295
 
293
 
Line 804... Line 802...
804
        out     dx, ax
802
        out     dx, ax
Line 805... Line 803...
805
 
803
 
Line 806... Line 804...
806
        call    set_active_port
804
        call    set_active_port
-
 
805
 
-
 
806
        call    create_rx_ring
-
 
807
        test    eax, eax
807
 
808
        jnz     .err
808
        call    create_rx_ring
809
 
Line 809... Line 810...
809
        call    rx_reset
810
        call    rx_reset
810
        call    tx_reset
811
        call    tx_reset
Line 811... Line 812...
811
 
812
 
812
        xor     eax, eax
813
        xor     eax, eax
813
; clear packet/byte counters
814
; clear packet/byte counters
Line 814... Line -...
814
 
-
 
-
 
815
 
815
        lea     edi, [ebx + device.bytes_tx]
816
        lea     edi, [ebx + device.bytes_tx]
Line 816... Line 817...
816
        mov     ecx, 6
817
        mov     ecx, 6
-
 
818
        rep     stosd
-
 
819
 
817
        rep     stosd
820
        xor     eax, eax
Line 818... Line 821...
818
 
821
        ret
819
 
822
 
820
        ret
823
  .err:
Line 900... Line 903...
900
; Set the mtu, kernel will be able to send now
903
; Set the mtu, kernel will be able to send now
901
        mov     [ebx + device.mtu], 1514
904
        mov     [ebx + device.mtu], 1514
Line 902... Line 905...
902
 
905
 
903
; Set link state to unknown
906
; Set link state to unknown
-
 
907
        mov     [ebx + device.state], ETH_LINK_UNKNOWN
Line 904... Line 908...
904
        mov     [ebx + device.state], ETH_LINK_UNKNOWN  
908
        xor     eax, eax
Line 995... Line 999...
995
        mov     ecx, NUM_RX_DESC
999
        mov     ecx, NUM_RX_DESC
996
  .loop:
1000
  .loop:
997
        mov     [edx + rx_desc.next_ptr], edi
1001
        mov     [edx + rx_desc.next_ptr], edi
Line 998... Line 1002...
998
 
1002
 
999
        push    ecx edx
1003
        push    ecx edx
1000
        invoke  KernelAlloc, MAX_ETH_FRAME_SIZE
1004
        invoke  NetAlloc, MAX_ETH_FRAME_SIZE+NET_BUFF.data
-
 
1005
        pop     edx ecx
-
 
1006
        test    eax, eax
1001
        pop     edx ecx
1007
        jz      .out_of_mem
1002
        mov     [esi + rx_desc.realaddr], eax
1008
        mov     [esi + rx_desc.realaddr], eax
-
 
1009
        invoke  GetPhysAddr
1003
        invoke  GetPgAddr
1010
        add     eax, NET_BUFF.data
1004
        mov     [esi + rx_desc.frag_addr], eax
1011
        mov     [esi + rx_desc.frag_addr], eax
1005
        and     [esi + rx_desc.pkt_status], 0
1012
        and     [esi + rx_desc.pkt_status], 0
Line 1006... Line 1013...
1006
        mov     [esi + rx_desc.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31)
1013
        mov     [esi + rx_desc.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31)
Line 1012... Line 1019...
1012
        add     esi, sizeof.rx_desc
1019
        add     esi, sizeof.rx_desc
1013
        add     edi, sizeof.rx_desc
1020
        add     edi, sizeof.rx_desc
1014
        dec     ecx
1021
        dec     ecx
1015
        jnz     .loop
1022
        jnz     .loop
Line -... Line 1023...
-
 
1023
 
-
 
1024
        xor     eax, eax
-
 
1025
        ret
-
 
1026
 
-
 
1027
  .out_of_mem:
1016
 
1028
        or      eax, -1
Line 1017... Line 1029...
1017
        ret
1029
        ret
Line 1037... Line 1049...
1037
try_link_detect:
1049
try_link_detect:
Line 1038... Line 1050...
1038
 
1050
 
Line 1039... Line 1051...
1039
        DEBUGF  1,"Trying to detect link\n"
1051
        DEBUGF  1,"Trying to detect link\n"
1040
 
1052
 
1041
; create self-directed packet
1053
; create self-directed packet
1042
        invoke  KernelAlloc, 20 ; create a buffer for the self-directed packet
1054
        invoke  NetAlloc, 20+NET_BUFF.data     ; create a buffer for the self-directed packet
Line 1043... Line -...
1043
        test    eax, eax
-
 
1044
        jz      .fail
1055
        test    eax, eax
1045
 
-
 
1046
        pushd   20              ; Packet parameters for device.transmit
1056
        jz      .fail
Line -... Line 1057...
-
 
1057
 
1047
        push    eax             ;
1058
        push    eax
1048
 
1059
        mov     [eax + NET_BUFF.length], 20
1049
        mov     edi, eax
1060
 
1050
 
1061
        lea     edi, [eax + NET_BUFF.data]
1051
        lea     esi, [ebx + device.mac]
1062
        lea     esi, [ebx + device.mac]
Line 1090... Line 1101...
1090
  .finish:
1101
  .finish:
1091
        test    al, al
1102
        test    al, al
1092
        jz      @f
1103
        jz      @f
1093
        or      byte [ebx + device.internal_link+1], 100b
1104
        or      byte [ebx + device.internal_link+1], 100b
1094
       @@:
1105
       @@:
-
 
1106
        xor     eax, eax
1095
        ret
1107
        ret
Line 1096... Line 1108...
1096
 
1108
 
1097
  .fail:
1109
  .fail:
-
 
1110
        DEBUGF  1,"No link detected!\n"
1098
        DEBUGF  1,"No link detected!\n"
1111
        or      eax, -1
Line 1099... Line 1112...
1099
        ret
1112
        ret
Line 1133... Line 1146...
1133
        mov     eax, [esp]
1146
        mov     eax, [esp]
1134
        call    mdio_write      ; returns with window #4
1147
        call    mdio_write      ; returns with window #4
Line 1135... Line 1148...
1135
 
1148
 
1136
; wait for reset to complete
1149
; wait for reset to complete
1137
        mov     esi, 2000
1150
        mov     esi, 2000
1138
        invoke  Sleep      ; 2s
1151
        invoke  Sleep           ; 2s FIXME
1139
        mov     eax, [esp]
1152
        mov     eax, [esp]
1140
        call    mdio_read       ; returns with window #4
1153
        call    mdio_read       ; returns with window #4
1141
        test    ah, 0x80
1154
        test    ah, 0x80
1142
        jnz     .fail1
1155
        jnz     .fail1
Line 1405... Line 1418...
1405
; issue RxEnable and TxEnable
1418
; issue RxEnable and TxEnable
1406
        call    rx_reset
1419
        call    rx_reset
1407
        call    tx_reset
1420
        call    tx_reset
Line 1408... Line 1421...
1408
 
1421
 
1409
; create self-directed packet
1422
; create self-directed packet
1410
        invoke  KernelAlloc, 20 ; create a buffer for the self-directed packet
1423
        invoke  NetAlloc, 20 + NET_BUFF.data   ; create a buffer for the self-directed packet
1411
        test    eax, eax
1424
        test    eax, eax
Line -... Line 1425...
-
 
1425
        jz      .fail
1412
        jz      .fail
1426
 
1413
 
1427
        push    eax
Line 1414... Line 1428...
1414
        pushd   20              ; Packet parameters for device.transmit
1428
        mov     [eax + NET_BUFF.length], 20
1415
        push    eax             ;
1429
;        mov     [eax + NET_BUFF.device], ebx
1416
 
1430
 
1417
        mov     edi, eax
1431
        lea     edi, [eax + NET_BUFF.data]
1418
        lea     esi, [ebx + device.mac]
1432
        lea     esi, [ebx + device.mac]
1419
        movsw
1433
        movsw
Line 1426... Line 1440...
1426
 
1440
 
1427
; download self-directed packet
1441
; download self-directed packet
Line 1428... Line 1442...
1428
        call    [ebx + device.transmit]
1442
        call    [ebx + device.transmit]
1429
 
1443
 
1430
; wait for 2s
1444
; wait for 2s
Line 1431... Line 1445...
1431
        mov     esi, 2000
1445
        mov     esi, 2000       ; FIXME
1432
        invoke  Sleep
1446
        invoke  Sleep
1433
 
1447
 
Line 2122... Line 2136...
2122
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2136
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2123
;;                                         ;;
2137
;;                                         ;;
2124
;; Transmit (vortex)                       ;;
2138
;; Transmit (vortex)                       ;;
2125
;;                                         ;;
2139
;;                                         ;;
2126
;; In: buffer pointer in [esp+4]           ;;
2140
;; In: buffer pointer in [esp+4]           ;;
2127
;;     size of buffer in [esp+8]           ;;
-
 
2128
;;     pointer to device structure in ebx  ;;
2141
;;     pointer to device structure in ebx  ;;
2129
;;                                         ;;
2142
;;                                         ;;
2130
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 2131... Line 2144...
2131
 
2144
 
Line 2132... Line 2145...
2132
proc vortex_transmit stdcall bufferptr, buffersize
2145
proc vortex_transmit stdcall bufferptr
2133
 
2146
 
Line -... Line 2147...
-
 
2147
        pushf
2134
        pushf
2148
        cli
2135
        cli
2149
 
2136
 
2150
        mov     esi, [bufferptr]
2137
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
2151
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
2138
        mov     eax, [bufferptr]
2152
        lea     eax, [esi + NET_BUFF.data]
2139
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
2153
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
Line 2140... Line 2154...
2140
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
2154
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
2141
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
2155
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
2142
        [eax+13]:2,[eax+12]:2
2156
        [eax+13]:2,[eax+12]:2
2143
 
2157
 
Line 2144... Line 2158...
2144
        cmp     [buffersize], 1514
2158
        cmp     [esi + NET_BUFF.length], 1514
Line 2145... Line 2159...
2145
        ja      .fail
2159
        ja      .fail
2146
        cmp     [buffersize], 60
2160
        cmp     [esi + NET_BUFF.length], 60
2147
        jb      .fail
2161
        jb      .fail
2148
 
2162
 
2149
        call    check_tx_status
2163
        call    check_tx_status
-
 
2164
 
2150
 
2165
; switch to register window 7
2151
; switch to register window 7
2166
        set_io  [ebx + device.io_addr], 0
2152
        set_io  [ebx + device.io_addr], 0
2167
        set_io  [ebx + device.io_addr], REG_COMMAND
2153
        set_io  [ebx + device.io_addr], REG_COMMAND
2168
        mov     ax, SELECT_REGISTER_WINDOW+7
2154
        mov     ax, SELECT_REGISTER_WINDOW+7
2169
        out     dx, ax
-
 
2170
 
2155
        out     dx, ax
2171
; check for master operation in progress
2156
; check for master operation in progress
2172
        set_io  [ebx + device.io_addr], REG_MASTER_STATUS
2157
        set_io  [ebx + device.io_addr], REG_MASTER_STATUS
2173
        in      ax, dx
-
 
2174
        test    ah, 0x80
2158
        in      ax, dx
2175
        jnz     .fail ; no DMA for sending
2159
        test    ah, 0x80
2176
 
-
 
2177
; program frame address to be sent
2160
        jnz     .fail ; no DMA for sending
2178
        set_io  [ebx + device.io_addr], REG_MASTER_ADDRESS
2161
; program frame address to be sent
2179
        mov     eax, esi
2162
        set_io  [ebx + device.io_addr], REG_MASTER_ADDRESS
2180
        add     eax, [eax + NET_BUFF.offset]
2163
        mov     eax, [bufferptr]
2181
        invoke  GetPhysAddr
-
 
2182
        out     dx, eax
2164
        invoke  GetPhysAddr
2183
 
2165
        out     dx, eax
2184
; program frame length
2166
; program frame length
2185
        set_io  [ebx + device.io_addr], REG_MASTER_LEN
2167
        set_io  [ebx + device.io_addr], REG_MASTER_LEN
2186
        mov     eax, [esi + NET_BUFF.length]
2168
        mov     eax, [buffersize]
2187
        out     dx, ax
Line 2176... Line 2195...
2176
        xor     eax, eax
2195
        xor     eax, eax
2177
        ret
2196
        ret
Line 2178... Line 2197...
2178
 
2197
 
2179
  .fail:
2198
  .fail:
2180
        DEBUGF  2,"Send failed\n"
2199
        DEBUGF  2,"Send failed\n"
2181
        invoke  KernelFree, [bufferptr]
2200
        invoke  NetFree, [bufferptr]
2182
        popf
2201
        popf
2183
        or      eax, -1
2202
        or      eax, -1
Line 2184... Line 2203...
2184
        ret
2203
        ret
Line 2188... Line 2207...
2188
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2207
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2189
;;                                         ;;
2208
;;                                         ;;
2190
;; Transmit (boomerang)                    ;;
2209
;; Transmit (boomerang)                    ;;
2191
;;                                         ;;
2210
;;                                         ;;
2192
;; In: buffer pointer in [esp+4]           ;;
2211
;; In: buffer pointer in [esp+4]           ;;
2193
;;     size of buffer in [esp+8]           ;;
-
 
2194
;;     pointer to device structure in ebx  ;;
2212
;;     pointer to device structure in ebx  ;;
2195
;;                                         ;;
2213
;;                                         ;;
2196
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2214
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 2197... Line 2215...
2197
 
2215
 
Line 2198... Line 2216...
2198
proc boomerang_transmit stdcall bufferptr, buffersize
2216
proc boomerang_transmit stdcall bufferptr
2199
 
2217
 
Line -... Line 2218...
-
 
2218
        pushf
2200
        pushf
2219
        cli
2201
        cli
2220
 
2202
 
2221
        mov     esi, [bufferptr]
2203
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
2222
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
2204
        mov     eax, [bufferptr]
2223
        lea     eax, [esi + NET_BUFF.data]
2205
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
2224
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
Line 2206... Line 2225...
2206
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
2225
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
2207
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
2226
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
2208
        [eax+13]:2,[eax+12]:2
2227
        [eax+13]:2,[eax+12]:2
2209
 
2228
 
Line 2210... Line 2229...
2210
        cmp     [buffersize], 1514
2229
        cmp     [esi + NET_BUFF.length], 1514
Line 2211... Line 2230...
2211
        ja      .fail
2230
        ja      .fail
2212
        cmp     [buffersize], 60
2231
        cmp     [esi + NET_BUFF.length], 60
2213
        jb      .fail
2232
        jb      .fail
2214
 
2233
 
2215
        call    check_tx_status                         ; Reset TX engine if needed
2234
        call    check_tx_status                         ; Reset TX engine if needed
2216
 
2235
 
2217
; calculate descriptor address
2236
; calculate descriptor address
2218
        mov     esi, [ebx + device.curr_tx]
2237
        mov     edi, [ebx + device.curr_tx]
2219
        DEBUGF  1,"Previous TX desc: %x\n", esi
2238
        DEBUGF  1,"Previous TX desc: %x\n", edi
2220
        add     esi, sizeof.tx_desc
2239
        add     edi, sizeof.tx_desc
Line 2221... Line 2240...
2221
        lea     ecx, [ebx + device.tx_desc_buffer + (NUM_TX_DESC)*sizeof.tx_desc]
2240
        lea     ecx, [ebx + device.tx_desc_buffer + (NUM_TX_DESC)*sizeof.tx_desc]
2222
        cmp     esi, ecx
2241
        cmp     edi, ecx
Line 2237... Line 2256...
2237
;        cmp     eax, esi
2256
;        cmp     eax, esi
2238
;        jz      .finish
2257
;        jz      .finish
Line 2239... Line 2258...
2239
 
2258
 
2240
; update statistics
2259
; update statistics
2241
        inc     [ebx + device.packets_tx]
2260
        inc     [ebx + device.packets_tx]
2242
        mov     ecx, [buffersize]
2261
        mov     ecx, [esi + NET_BUFF.length]
2243
        add     dword [ebx + device.bytes_tx], ecx
2262
        add     dword [ebx + device.bytes_tx], ecx
Line 2244... Line 2263...
2244
        adc     dword [ebx + device.bytes_tx + 4], 0
2263
        adc     dword [ebx + device.bytes_tx + 4], 0
2245
 
2264
 
2246
; program DPD
2265
; program DPD
2247
        and     [esi + tx_desc.next_ptr], 0
2266
        and     [edi + tx_desc.next_ptr], 0
-
 
2267
        mov     eax, [bufferptr]
2248
        mov     eax, [bufferptr]
2268
        mov     [edi + tx_desc.realaddr], eax
2249
        mov     [esi + tx_desc.realaddr], eax
2269
        add     eax, [eax + NET_BUFF.offset]
2250
        invoke  GetPhysAddr
2270
        invoke  GetPhysAddr
2251
        mov     [esi + tx_desc.frag_addr], eax
2271
        mov     [edi + tx_desc.frag_addr], eax
2252
        mov     ecx, [buffersize]
2272
;;;        mov     ecx, [buffersize]
Line 2253... Line 2273...
2253
        or      ecx, 0x80000000         ; last fragment flag
2273
        or      ecx, 0x80000000         ; last fragment flag
2254
        mov     [esi + tx_desc.frag_len], ecx
2274
        mov     [edi + tx_desc.frag_len], ecx
2255
 
2275
 
2256
        mov     ecx, [buffersize]       ; packet size
2276
;;;        mov     ecx, [buffersize]       ; packet size
2257
        or      ecx, 0x80008000         ; set OWN bit + transmission complete notification flag
2277
        or      ecx, 0x80008000         ; set OWN bit + transmission complete notification flag
2258
;        test    byte [ebx + device.has_hwcksm], 0xff
2278
;        test    byte [ebx + device.has_hwcksm], 0xff
2259
;        jz      @f
2279
;        jz      @f
2260
;        or      ecx, (1 shl 26)         ; set AddTcpChecksum
2280
;        or      ecx, (1 shl 26)         ; set AddTcpChecksum
Line 2261... Line 2281...
2261
;@@:
2281
;@@:
2262
        mov     [esi + tx_desc.frame_start_hdr], ecx
2282
        mov     [edi + tx_desc.frame_start_hdr], ecx
2263
        DEBUGF  1,"TX desc: lin=%x phys=%x len=%x start hdr=%x\n", [esi+tx_desc.realaddr]:8, [esi+tx_desc.frag_addr]:8, [esi+tx_desc.frag_len]:8, [esi+tx_desc.frame_start_hdr]:8
2283
        DEBUGF  1,"TX desc: lin=%x phys=%x len=%x start hdr=%x\n", [edi+tx_desc.realaddr]:8, [edi+tx_desc.frag_addr]:8, [edi+tx_desc.frag_len]:8, [edi+tx_desc.frame_start_hdr]:8
2264
 
2284
 
2265
; calculate physical address of tx descriptor
2285
; calculate physical address of tx descriptor
Line 2266... Line 2286...
2266
        mov     eax, esi
2286
        mov     eax, edi
Line 2316... Line 2336...
2316
        set_io  [ebx + device.io_addr], REG_COMMAND
2336
        set_io  [ebx + device.io_addr], REG_COMMAND
2317
        mov     ax, ((110b shl 11)+3)
2337
        mov     ax, ((110b shl 11)+3)
2318
        out     dx, ax
2338
        out     dx, ax
Line 2319... Line 2339...
2319
 
2339
 
2320
  .finish:
2340
  .finish:
2321
        mov     [ebx + device.curr_tx], esi
2341
        mov     [ebx + device.curr_tx], edi
2322
        popf
2342
        popf
2323
        xor     eax, eax
2343
        xor     eax, eax
Line 2324... Line 2344...
2324
        ret
2344
        ret
2325
 
2345
 
2326
  .fail:
2346
  .fail:
2327
        DEBUGF  2,"Send failed\n"
2347
        DEBUGF  2,"Send failed\n"
2328
        invoke  KernelFree, [bufferptr]
2348
        invoke  NetFree, [bufferptr]
2329
        popf
2349
        popf
Line 2330... Line 2350...
2330
        or      eax, -1
2350
        or      eax, -1
Line 2491... Line 2511...
2491
        out     dx, ax
2511
        out     dx, ax
2492
        jmp     .rx_status_loop
2512
        jmp     .rx_status_loop
Line 2493... Line 2513...
2493
 
2513
 
2494
  .check_length:
2514
  .check_length:
2495
        and     eax, 0x1fff
2515
        and     eax, 0x1fff
2496
        cmp     eax, MAX_ETH_PKT_SIZE
2516
        cmp     eax, MAX_ETH_FRAME_SIZE
Line 2497... Line 2517...
2497
        ja      .discard_frame ; frame is too long discard it
2517
        ja      .discard_frame ; frame is too long discard it
2498
 
2518
 
2499
  .check_dma:
2519
  .check_dma:
Line 2511... Line 2531...
2511
        jnz     .finish
2531
        jnz     .finish
Line 2512... Line 2532...
2512
 
2532
 
2513
  .read_frame:
2533
  .read_frame:
2514
; program buffer address to read in
2534
; program buffer address to read in
2515
        push    ecx
2535
        push    ecx
2516
        invoke  KernelAlloc, MAX_ETH_FRAME_SIZE
2536
        invoke  NetAlloc, MAX_ETH_FRAME_SIZE + NET_BUFF.data
2517
        pop     ecx
2537
        pop     ecx
2518
        test    eax, eax
2538
        test    eax, eax
Line 2519... Line 2539...
2519
        jz      .finish
2539
        jz      .finish
2520
 
-
 
2521
        push    .discard_frame
2540
 
-
 
2541
        push    .discard_frame
-
 
2542
        push    eax
-
 
2543
        mov     [eax + NET_BUFF.length], ecx
2522
        push    ecx
2544
        mov     [eax + NET_BUFF.device], ebx
-
 
2545
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
2523
        push    eax
2546
        invoke  GetPhysAddr
2524
;        zero_to_dma eax
2547
        add     eax, NET_BUFF.data
Line 2525... Line 2548...
2525
        set_io  [ebx + device.io_addr], REG_MASTER_ADDRESS
2548
        set_io  [ebx + device.io_addr], REG_MASTER_ADDRESS
2526
        out     dx, eax
2549
        out     dx, eax
Line 2541... Line 2564...
2541
        in      ax, dx
2564
        in      ax, dx
2542
        test    ah, 0x80
2565
        test    ah, 0x80
2543
        jnz     .dma_loop
2566
        jnz     .dma_loop
Line 2544... Line 2567...
2544
 
2567
 
2545
; registrate the received packet to kernel
2568
; registrate the received packet to kernel
Line 2546... Line 2569...
2546
        jmp     Eth_input
2569
        jmp     [EthInput]
2547
 
2570
 
2548
; discard the top frame received
2571
; discard the top frame received
2549
  .discard_frame:
2572
  .discard_frame:
Line 2676... Line 2699...
2676
;  .copy_packet:
2699
;  .copy_packet:
Line 2677... Line 2700...
2677
 
2700
 
Line 2678... Line 2701...
2678
        DEBUGF  1, "Received %u bytes in buffer %x\n", ecx, [esi + rx_desc.realaddr]:8
2701
        DEBUGF  1, "Received %u bytes in buffer %x\n", ecx, [esi + rx_desc.realaddr]:8
-
 
2702
 
2679
 
2703
        push    dword .loop ;.finish
-
 
2704
        mov     eax, [esi + rx_desc.realaddr]
2680
        push    dword .loop ;.finish
2705
        push    eax
-
 
2706
        mov     [eax + NET_BUFF.length], ecx
Line 2681... Line 2707...
2681
        push    ecx
2707
        mov     [eax + NET_BUFF.device], ebx
2682
        push    [esi + rx_desc.realaddr]
2708
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
2683
 
2709
 
2684
; update statistics
2710
; update statistics
Line 2685... Line 2711...
2685
        inc     [ebx + device.packets_rx]
2711
        inc     [ebx + device.packets_rx]
2686
        add     dword [ebx + device.bytes_rx], ecx
2712
        add     dword [ebx + device.bytes_rx], ecx
2687
        adc     dword [ebx + device.bytes_rx + 4], 0
2713
        adc     dword [ebx + device.bytes_rx + 4], 0
2688
 
2714
 
-
 
2715
; update rx descriptor (Alloc new buffer for next packet)
2689
; update rx descriptor (Alloc new buffer for next packet)
2716
        invoke  NetAlloc, MAX_ETH_FRAME_SIZE + NET_BUFF.data
2690
        invoke  KernelAlloc, MAX_ETH_FRAME_SIZE
2717
        mov     [esi + rx_desc.realaddr], eax
2691
        mov     [esi + rx_desc.realaddr], eax
2718
        invoke  GetPhysAddr
Line 2692... Line 2719...
2692
        invoke  GetPhysAddr
2719
        add     eax, NET_BUFF.data
Line 2702... Line 2729...
2702
        lea     esi, [ebx + device.rx_desc_buffer]
2729
        lea     esi, [ebx + device.rx_desc_buffer]
2703
       @@:
2730
       @@:
2704
        mov     [ebx + device.curr_rx], esi
2731
        mov     [ebx + device.curr_rx], esi
2705
        DEBUGF  1, "Next RX desc: %x\n", esi
2732
        DEBUGF  1, "Next RX desc: %x\n", esi
Line 2706... Line 2733...
2706
 
2733
 
2707
        jmp     [Eth_input]
2734
        jmp     [EthInput]
Line 2708... Line 2735...
2708
  .loop:
2735
  .loop:
2709
 
2736
 
Line 2740... Line 2767...
2740
        test    [esi+tx_desc.frame_start_hdr], 1 shl 31
2767
        test    [esi+tx_desc.frame_start_hdr], 1 shl 31
2741
        jz      .maybenext
2768
        jz      .maybenext
Line 2742... Line 2769...
2742
 
2769
 
2743
        and     [esi+tx_desc.frame_start_hdr], 0
2770
        and     [esi+tx_desc.frame_start_hdr], 0
2744
        push    ecx
2771
        push    ecx
2745
        invoke  KernelFree, [esi+tx_desc.realaddr]
2772
        invoke  NetFree, [esi+tx_desc.realaddr]
Line 2746... Line 2773...
2746
        pop     ecx
2773
        pop     ecx
2747
 
2774
 
2748
  .maybenext:
2775
  .maybenext: