Subversion Repositories Kolibri OS

Rev

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

Rev 5363 Rev 5522
Line 16... Line 16...
16
;; Intel's programming manual for i8255x:                          ;;
16
;; Intel's programming manual for i8255x:                          ;;
17
;; http://www.intel.com/design/network/manuals/8255x_opensdm.htm   ;;
17
;; http://www.intel.com/design/network/manuals/8255x_opensdm.htm   ;;
18
;;                                                                 ;;
18
;;                                                                 ;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 20... Line -...
20
 
-
 
21
; TODO: use separate descriptors in memory instead of placing them in front of packets!
-
 
Line 22... Line 20...
22
 
20
 
23
 
21
 
Line 24... Line 22...
24
format PE DLL native
22
format PE DLL native
Line 76... Line 74...
76
CmdConfigure    = 0x0002
74
CmdConfigure    = 0x0002
77
CmdTx           = 0x0004
75
CmdTx           = 0x0004
78
CmdTxFlex       = 0x0008
76
CmdTxFlex       = 0x0008
79
Cmdsuspend      = 0x4000
77
Cmdsuspend      = 0x4000
Line -... Line 78...
-
 
78
 
-
 
79
CmdRxFlex       = 0x0008
80
 
80
 
81
reg_scb_status  = 0
81
reg_scb_status  = 0
82
reg_scb_cmd     = 2
82
reg_scb_cmd     = 2
83
reg_scb_ptr     = 4
83
reg_scb_ptr     = 4
84
reg_port        = 8
84
reg_port        = 8
Line 485... Line 485...
485
 
485
 
486
;-----------------------------
486
;-----------------------------
Line 487... Line 487...
487
; Create RX and TX descriptors
487
; Create RX and TX descriptors
-
 
488
 
-
 
489
        call    create_ring
Line 488... Line 490...
488
 
490
        test    eax, eax
Line 489... Line 491...
489
        call    create_ring
491
        jz      .error
490
 
492
 
491
; RX start
493
; RX start
492
 
494
 
-
 
495
        set_io  [ebx + device.io_addr], 0
493
        set_io  [ebx + device.io_addr], 0
496
        set_io  [ebx + device.io_addr], reg_scb_ptr
Line 494... Line 497...
494
        set_io  [ebx + device.io_addr], reg_scb_ptr
497
        mov     eax, [ebx + device.rx_desc]
495
        mov     eax, [ebx + device.rx_desc]
498
        invoke  GetPhysAddr
496
        invoke  GetPhysAddr
499
        add     eax, NET_BUFF.data
Line 578... Line 581...
578
        mov     [ebx + device.state], ETH_LINK_UNKNOWN
581
        mov     [ebx + device.state], ETH_LINK_UNKNOWN
Line 579... Line 582...
579
 
582
 
580
        xor     eax, eax        ; indicate that we have successfully reset the card
583
        xor     eax, eax        ; indicate that we have successfully reset the card
Line -... Line 584...
-
 
584
        ret
-
 
585
 
-
 
586
  .error:
-
 
587
        or      eax, -1
Line 581... Line 588...
581
        ret
588
        ret
582
 
589
 
Line 583... Line 590...
583
 
590
 
Line 584... Line 591...
584
align 4
591
align 4
585
create_ring:
592
create_ring:
Line 586... Line 593...
586
 
593
 
-
 
594
        DEBUGF  1,"Creating ring\n"
-
 
595
 
587
        DEBUGF  1,"Creating ring\n"
596
;---------------------
588
 
597
; build rxfd structure
589
;---------------------
598
 
-
 
599
        invoke  NetAlloc, 2000
590
; build rxfd structure
600
        test    eax, eax
591
 
601
        jz      .out_of_mem
592
        invoke  KernelAlloc, 2000
602
        mov     [ebx + device.rx_desc], eax
593
        mov     [ebx + device.rx_desc], eax
603
        mov     esi, eax
594
        mov     esi, eax
604
        invoke  GetPhysAddr
Line 595... Line 605...
595
        invoke  GetPhysAddr
605
        add     eax, NET_BUFF.data
596
        mov     [esi + rxfd.status], 0x0000
606
        mov     [esi + sizeof.NET_BUFF + rxfd.status], 0x0000
Line 597... Line 607...
597
        mov     [esi + rxfd.command], 0x0000
607
        mov     [esi + sizeof.NET_BUFF + rxfd.command], 0x0000
Line 608... Line 618...
608
        mov     [ebx + device.txfd.count], 0x01208000
618
        mov     [ebx + device.txfd.count], 0x01208000
609
        lea     eax, [ebx + device.txfd.buf_addr0]
619
        lea     eax, [ebx + device.txfd.buf_addr0]
610
        invoke  GetPhysAddr
620
        invoke  GetPhysAddr
611
        mov     [ebx + device.txfd.desc_addr], eax
621
        mov     [ebx + device.txfd.desc_addr], eax
Line -... Line 622...
-
 
622
 
-
 
623
  .out_of_mem:
612
 
624
 
Line 613... Line 625...
613
        ret
625
        ret
Line 620... Line 632...
620
;;                                         ;;
632
;;                                         ;;
621
;; In: pointer to device structure in ebx  ;;
633
;; In: pointer to device structure in ebx  ;;
622
;;                                         ;;
634
;;                                         ;;
623
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
635
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 624... Line 636...
624
 
636
 
Line 625... Line 637...
625
proc transmit stdcall bufferptr, buffersize
637
proc transmit stdcall bufferptr
626
 
638
 
Line -... Line 639...
-
 
639
        pushf
627
        pushf
640
        cli
628
        cli
641
 
629
 
642
        mov     esi, [bufferptr]
630
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
643
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
631
        mov     eax, [bufferptr]
644
        lea     eax, [esi + NET_BUFF.data]
632
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
645
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
Line 633... Line 646...
633
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
646
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
634
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
647
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
635
        [eax+13]:2,[eax+12]:2
648
        [eax+13]:2,[eax+12]:2
636
 
649
 
Line 637... Line 650...
637
        cmp     [buffersize], 1514
650
        cmp     [esi + NET_BUFF.length], 1514
638
        ja      .fail
651
        ja      .fail
-
 
652
        cmp     [esi + NET_BUFF.length], 60
639
        cmp     [buffersize], 60
653
        jb      .fail
-
 
654
 
640
        jb      .fail
655
        ;;; TODO: check if current descriptor is in use
641
 
656
        ; fill in buffer address and size
642
        ;;; TODO: check if current descriptor is in use
657
        mov     eax, [bufferptr]
-
 
658
        mov     [ebx + device.last_tx_buffer], eax
643
        ; fill in buffer address and size
659
        add     eax, [eax + NET_BUFF.offset]
Line 644... Line 660...
644
        mov     [ebx + device.last_tx_buffer], eax
660
        invoke  GetPhysAddr
645
        invoke  GetPhysAddr
661
        mov     [ebx + device.txfd.buf_addr0], eax
646
        mov     [ebx + device.txfd.buf_addr0], eax
662
        mov     ecx, [bufferptr]
Line 647... Line 663...
647
        mov     ecx, [buffersize]
663
        mov     ecx, [ecx + NET_BUFF.length]
648
        mov     [ebx + device.txfd.buf_size0], ecx
664
        mov     [ebx + device.txfd.buf_size0], ecx
649
 
665
 
Line 664... Line 680...
664
        out     dx, ax
680
        out     dx, ax
665
        call    cmd_wait
681
        call    cmd_wait
Line 666... Line 682...
666
 
682
 
667
; Update stats
683
; Update stats
668
        inc     [ebx + device.packets_tx]
-
 
669
        mov     ecx, [buffersize]
684
        inc     [ebx + device.packets_tx]
670
        add     dword[ebx + device.bytes_tx], ecx
685
        add     dword[ebx + device.bytes_tx], ecx
Line 671... Line 686...
671
        adc     dword[ebx + device.bytes_tx + 4], 0
686
        adc     dword[ebx + device.bytes_tx + 4], 0
672
 
687
 
673
        DEBUGF  1,"Transmit OK\n"
688
        DEBUGF  1,"Transmit OK\n"
674
        popf
689
        popf
Line 675... Line 690...
675
        xor     eax, eax
690
        xor     eax, eax
676
        ret
691
        ret
677
 
692
 
678
  .fail:
693
  .fail:
679
        invoke  KernelFree, [bufferptr]
694
        invoke  NetFree, [bufferptr]
Line 680... Line 695...
680
        popf
695
        popf
Line 736... Line 751...
736
        push    ebx
751
        push    ebx
737
  .rx_loop:
752
  .rx_loop:
738
        pop     ebx
753
        pop     ebx
Line 739... Line 754...
739
 
754
 
740
        mov     esi, [ebx + device.rx_desc]
755
        mov     esi, [ebx + device.rx_desc]
741
        cmp     [esi + rxfd.status], 0        ; we could also check bits C and OK (bit 15 and 13)
756
        cmp     [esi + sizeof.NET_BUFF + rxfd.status], 0        ; we could also check bits C and OK (bit 15 and 13)
Line 742... Line 757...
742
        je      .nodata
757
        je      .nodata
Line 743... Line 758...
743
 
758
 
744
        DEBUGF  1,"rxfd status=0x%x\n", [esi + rxfd.status]:4
759
        DEBUGF  1,"rxfd status=0x%x\n", [esi + sizeof.NET_BUFF + rxfd.status]:4
Line 745... Line 760...
745
 
760
 
746
        movzx   ecx, [esi + rxfd.count]
761
        movzx   ecx, [esi + sizeof.NET_BUFF + rxfd.count]
747
        and     ecx, 0x3fff
-
 
748
 
-
 
749
        push    ebx
762
        and     ecx, 0x3fff
-
 
763
 
-
 
764
        push    ebx
-
 
765
        push    .rx_loop
Line 750... Line 766...
750
        push    .rx_loop
766
        push    esi
751
        push    ecx
767
        mov     [esi + NET_BUFF.length], ecx
752
        add     esi, rxfd.packet
768
        mov     [esi + NET_BUFF.device], ebx
753
        push    esi
769
        mov     [esi + NET_BUFF.offset], NET_BUFF.data + rxfd.packet
Line 754... Line 770...
754
 
770
 
Line 755... Line 771...
755
; Update stats
771
; Update stats
756
        add     dword [ebx + device.bytes_rx], ecx
772
        add     dword [ebx + device.bytes_rx], ecx
757
        adc     dword [ebx + device.bytes_rx + 4], 0
773
        adc     dword [ebx + device.bytes_rx + 4], 0
758
        inc     dword [ebx + device.packets_rx]
774
        inc     dword [ebx + device.packets_rx]
-
 
775
 
759
 
776
; allocate new descriptor
760
; allocate new descriptor
777
 
761
 
778
        invoke  NetAlloc, 2000
762
        invoke  KernelAlloc, 2000
779
        mov     [ebx + device.rx_desc], eax
763
        mov     [ebx + device.rx_desc], eax
780
        mov     esi, eax
Line 764... Line 781...
764
        mov     esi, eax
781
        invoke  GetPhysAddr
Line 765... Line 782...
765
        invoke  GetPhysAddr
782
        add     eax, NET_BUFF.data
766
        mov     [esi + rxfd.status], 0x0000
783
        mov     [esi + sizeof.NET_BUFF + rxfd.status], 0x0000
Line 781... Line 798...
781
        mov     ax, RX_START
798
        mov     ax, RX_START
782
        out     dx, ax
799
        out     dx, ax
783
        call    cmd_wait
800
        call    cmd_wait
Line 784... Line 801...
784
 
801
 
785
; And give packet to kernel
802
; And give packet to kernel
Line 786... Line 803...
786
        jmp     [Eth_input]
803
        jmp     [EthInput]
787
 
804
 
788
  .nodata:
805
  .nodata: