Subversion Repositories Kolibri OS

Rev

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

Rev 8896 Rev 9017
Line 19... Line 19...
19
;;          GNU GENERAL PUBLIC LICENSE                             ;;
19
;;          GNU GENERAL PUBLIC LICENSE                             ;;
20
;;             Version 2, June 1991                                ;;
20
;;             Version 2, June 1991                                ;;
21
;;                                                                 ;;
21
;;                                                                 ;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 23... Line 23...
23
 
23
 
Line 24... Line 24...
24
$Revision: 8896 $
24
$Revision: 9017 $
25
 
25
 
26
uglobal
26
uglobal
27
        net_10ms        dd ?
27
        net_10ms        dd ?
Line 28... Line 28...
28
        net_tmr_count   dw ?
28
        net_tmr_count   dw ?
29
endg
29
endg
-
 
30
 
Line 30... Line 31...
30
 
31
DEBUG_NETWORK_ERROR     = 1
31
DEBUG_NETWORK_ERROR     = 1
32
DEBUG_NETWORK_VERBOSE   = 0
32
DEBUG_NETWORK_VERBOSE   = 0
33
NETWORK_SANITY_CHECKS   = 1
33
 
34
 
Line 260... Line 261...
260
align 4
261
align 4
Line 261... Line 262...
261
 
262
 
262
        net_device_count        dd ?
263
        net_device_count        dd ?
Line 263... Line 264...
263
        net_device_list         rd NET_DEVICES_MAX
264
        net_device_list         rd NET_DEVICES_MAX
264
 
265
 
-
 
266
        net_buffs_free          rd NET_BUFFERS  ; list of pointers to actual net buffs
-
 
267
        .current                dd ?            ; pointer to current element in net_buffs_free list
-
 
268
 
-
 
269
if defined NETWORK_SANITY_CHECKS
-
 
270
        net_buffs_low           dd ?            ; actual net buff mem region start
Line 265... Line 271...
265
        net_buffs_free          rd NET_BUFFERS
271
        net_buffs_high          dd ?            ; actual net buff mem region stop
Line 266... Line 272...
266
        .current                dd ?
272
end if
Line 282... Line 288...
282
; allocate network buffers
288
; allocate network buffers
283
        stdcall kernel_alloc, NET_BUFFER_SIZE*NET_BUFFERS
289
        stdcall kernel_alloc, NET_BUFFER_SIZE*NET_BUFFERS
284
        test    eax, eax
290
        test    eax, eax
285
        jz      .fail
291
        jz      .fail
Line -... Line 292...
-
 
292
 
-
 
293
if defined NETWORK_SANITY_CHECKS
-
 
294
        mov     [net_buffs_low], eax
-
 
295
end if
286
 
296
 
287
        mov     edi, net_buffs_free
297
        mov     edi, net_buffs_free
288
        mov     ecx, NET_BUFFERS
298
        mov     ecx, NET_BUFFERS
289
        cld
299
        cld
290
  .loop:
300
  .loop:
291
        stosd
301
        stosd
292
        add     eax, NET_BUFFER_SIZE
302
        add     eax, NET_BUFFER_SIZE
293
        dec     ecx
303
        dec     ecx
Line -... Line 304...
-
 
304
        jnz     .loop
-
 
305
 
-
 
306
if defined NETWORK_SANITY_CHECKS
-
 
307
        sub     eax, NET_BUFFER_SIZE
-
 
308
        mov     [net_buffs_high], eax
294
        jnz     .loop
309
end if
295
 
310
 
Line 296... Line 311...
296
        mov     eax, net_buffs_free
311
        mov     eax, net_buffs_free
297
        stosd
312
        stosd
Line 392... Line 407...
392
        mov     eax, [eax]
407
        mov     eax, [eax]
393
        add     [net_buffs_free.current], 4
408
        add     [net_buffs_free.current], 4
Line 394... Line 409...
394
 
409
 
Line -... Line 410...
-
 
410
        spin_unlock_irqrestore
-
 
411
 
-
 
412
if defined NETWORK_SANITY_CHECKS
-
 
413
        cmp     eax, [net_buffs_low]
-
 
414
        cmp     eax, [net_buffs_low]
-
 
415
        jb      .assert_mbuff
-
 
416
        cmp     eax, [net_buffs_high]
-
 
417
        ja      .assert_mbuff
-
 
418
        test    eax, 0x7ff
-
 
419
        jnz     .assert_mbuff
395
        spin_unlock_irqrestore
420
end if
396
 
421
 
Line 397... Line 422...
397
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net_buff_alloc: 0x%x\n", eax
422
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net_buff_alloc: 0x%x\n", eax
398
        ret
423
        ret
Line 406... Line 431...
406
 
431
 
407
  .too_large:
432
  .too_large:
408
        xor     eax, eax
433
        xor     eax, eax
409
        DEBUGF  DEBUG_NETWORK_ERROR, "net_buff_alloc: too large!\n"
434
        DEBUGF  DEBUG_NETWORK_ERROR, "net_buff_alloc: too large!\n"
-
 
435
        ret
-
 
436
 
-
 
437
if defined NETWORK_SANITY_CHECKS
-
 
438
  .assert_mbuff:
-
 
439
        DEBUGF  DEBUG_NETWORK_ERROR, "net_buff_alloc: invalid buffer 0x%x\n", eax
-
 
440
        DEBUGF  DEBUG_NETWORK_ERROR, "net_buff_alloc: caller=0x%x\n", [esp+4]
-
 
441
        xor     eax, eax
-
 
442
        ret
-
 
443
end if
410
        ret
444
 
Line 411... Line 445...
411
endp
445
endp
412
 
446
 
Line 413... Line 447...
413
 
447
 
Line -... Line 448...
-
 
448
align 4
-
 
449
proc net_buff_free stdcall, buffer
-
 
450
 
-
 
451
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net_buff_free: 0x%x\n", [buffer]
-
 
452
 
-
 
453
if defined NETWORK_SANITY_CHECKS
-
 
454
        mov     eax, [buffer]
-
 
455
        cmp     eax, [net_buffs_low]
-
 
456
        jb      .assert_mbuff
-
 
457
        cmp     eax, [net_buffs_high]
414
align 4
458
        ja      .assert_mbuff
Line 415... Line 459...
415
proc net_buff_free stdcall, buffer
459
        test    eax, 0x7ff
416
 
460
        jnz     .assert_mbuff
417
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net_buff_free: 0x%x\n", [buffer]
461
end if
418
 
462
 
Line 419... Line 463...
419
        spin_lock_irqsave
463
        spin_lock_irqsave
Line 420... Line 464...
420
 
464
 
-
 
465
        sub     [net_buffs_free.current], 4             ; move pointer backwards
-
 
466
        mov     eax, [net_buffs_free.current]           ; place free'd buffer pointer on the list
-
 
467
        push    [buffer]
-
 
468
        pop     dword[eax]
-
 
469
 
-
 
470
        spin_unlock_irqrestore
-
 
471
 
-
 
472
        ret
-
 
473
 
421
        sub     [net_buffs_free.current], 4             ; move pointer backwards
474
if defined NETWORK_SANITY_CHECKS
Line 422... Line 475...
422
        mov     eax, [net_buffs_free.current]           ; place free'd buffer pointer on the list
475
  .assert_mbuff:
423
        push    [buffer]
476
        DEBUGF  DEBUG_NETWORK_ERROR, "net_buff_free: invalid buffer 0x%x\n", eax
Line 758... Line 811...
758
        dd      .packets_tx             ; 6
811
        dd      .packets_tx             ;  6
759
        dd      .packets_rx             ; 7
812
        dd      .packets_rx             ;  7
760
        dd      .bytes_tx               ; 8
813
        dd      .bytes_tx               ;  8
761
        dd      .bytes_rx               ; 9
814
        dd      .bytes_rx               ;  9
762
        dd      .state                  ; 10
815
        dd      .state                  ; 10
-
 
816
        dd      .packets_tx_err         ; 11
-
 
817
        dd      .packets_tx_drop        ; 12
-
 
818
        dd      .packets_tx_ovr         ; 13
-
 
819
        dd      .packets_rx_err         ; 14
-
 
820
        dd      .packets_rx_drop        ; 15
-
 
821
        dd      .packets_rx_ovr         ; 16
-
 
822
 
763
  .number = ($ - .table) / 4 - 1
823
  .number = ($ - .table) / 4 - 1
Line 764... Line 824...
764
 
824
 
765
  .get_type:
825
  .get_type:
766
        mov     eax, [eax + NET_DEVICE.device_type]
826
        mov     eax, [eax + NET_DEVICE.device_type]
767
        mov     [esp+32], eax
827
        mov     [esp+32], eax
Line 768... Line 828...
768
        ret
828
        ret
769
 
829
 
770
  .get_dev_name:
-
 
771
; { Patch by Coldy, sanity check
830
  .get_dev_name:
772
        mov     ebx, eax ; eax will used for is_region_userspace return 
831
        mov     ebx, eax
773
        stdcall is_region_userspace, ecx, 64
832
        stdcall is_region_userspace, ecx, 64
774
        jz      .bad_buffer      
-
 
775
        mov     esi, [ebx + NET_DEVICE.name] ;mov     esi, [eax + NET_DEVICE.name]
833
        jz      .bad_buffer      
Line 776... Line 834...
776
; } End patch by Coldy, sanity check
834
        mov     esi, [ebx + NET_DEVICE.name]
777
        mov     edi, ecx
835
        mov     edi, ecx
Line 826... Line 884...
826
        mov     [esp+20], ebx
884
        mov     [esp+20], ebx
827
        mov     eax, dword[eax + NET_DEVICE.bytes_rx]
885
        mov     eax, dword[eax + NET_DEVICE.bytes_rx]
828
        mov     [esp+32], eax
886
        mov     [esp+32], eax
829
        ret
887
        ret
Line -... Line 888...
-
 
888
 
-
 
889
  .packets_tx_err:
-
 
890
        mov     eax, [eax + NET_DEVICE.packets_tx_err]
-
 
891
        mov     [esp+32], eax
-
 
892
        ret
-
 
893
 
-
 
894
  .packets_tx_drop:
-
 
895
        mov     eax, [eax + NET_DEVICE.packets_tx_drop]
-
 
896
        mov     [esp+32], eax
-
 
897
        ret
-
 
898
 
-
 
899
  .packets_tx_ovr:
-
 
900
        mov     eax, [eax + NET_DEVICE.packets_tx_ovr]
-
 
901
        mov     [esp+32], eax
-
 
902
        ret
-
 
903
 
-
 
904
  .packets_rx_err:
-
 
905
        mov     eax, [eax + NET_DEVICE.packets_rx_err]
-
 
906
        mov     [esp+32], eax
-
 
907
        ret
-
 
908
 
-
 
909
  .packets_rx_drop:
-
 
910
        mov     eax, [eax + NET_DEVICE.packets_rx_drop]
-
 
911
        mov     [esp+32], eax
-
 
912
        ret
-
 
913
 
-
 
914
  .packets_rx_ovr:
-
 
915
        mov     eax, [eax + NET_DEVICE.packets_rx_ovr]
-
 
916
        mov     [esp+32], eax
-
 
917
        ret
830
 
918
 
831
  .state:
919
  .state:
832
        mov     eax, [eax + NET_DEVICE.link_state]
920
        mov     eax, [eax + NET_DEVICE.link_state]
833
        mov     [esp+32], eax
921
        mov     [esp+32], eax