Subversion Repositories Kolibri OS

Rev

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

Rev 6948 Rev 9232
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2017. 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
;; i8255x (Intel eepro 100) driver for KolibriOS                   ;;
6
;; i8255x (Intel eepro 100) driver for KolibriOS                   ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
Line 25... Line 25...
25
 
25
 
26
        CURRENT_API             = 0x0200
26
        CURRENT_API             = 0x0200
27
        COMPATIBLE_API          = 0x0100
27
        COMPATIBLE_API          = 0x0100
Line 28... Line 28...
28
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
28
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
Line 29... Line 29...
29
 
29
 
Line 30... Line 30...
30
        MAX_DEVICES             = 16
30
; configureable area
-
 
31
 
-
 
32
        MAX_DEVICES             = 16            ; Maximum number of devices this driver may handle
31
 
33
 
32
        TX_RING_SIZE            = 16
34
        TX_RING_SIZE            = 16            ; Number of packets in send ring buffer
Line -... Line 35...
-
 
35
        RX_RING_SIZE            = 1             ; Number of packets in receive ring buffer
-
 
36
 
33
 
37
        __DEBUG__               = 1             ; 1 = on, 0 = off
Line 34... Line 38...
34
        DEBUG                   = 1
38
        __DEBUG_LEVEL__         = 2             ; 1 = verbose, 2 = errors only
35
        __DEBUG__               = 1
39
 
36
        __DEBUG_LEVEL__         = 2             ; 1 = verbose, 2 = errors only
40
; end configureable area
37
 
41
 
38
section '.flat' readable writable executable
42
section '.flat' readable writable executable
Line -... Line 43...
-
 
43
 
-
 
44
include '../proc32.inc'
-
 
45
include '../struct.inc'
-
 
46
include '../macros.inc'
-
 
47
include '../fdo.inc'
-
 
48
include '../netdrv.inc'
-
 
49
 
-
 
50
if (bsr TX_RING_SIZE)>(bsf TX_RING_SIZE)
-
 
51
  display 'TX_RING_SIZE must be a power of two'
-
 
52
  err
39
 
53
end if
40
include '../proc32.inc'
54
 
41
include '../struct.inc'
55
if (RX_RING_SIZE)<>(1)
42
include '../macros.inc'
56
  display 'RX_RING_SIZE must be 1'
43
include '../fdo.inc'
57
  err
Line 62... Line 76...
62
; Serial EEPROM
76
; Serial EEPROM
63
EE_SK                   = 1 shl 0       ; serial clock
77
EE_SK                   = 1 shl 0       ; serial clock
64
EE_CS                   = 1 shl 1       ; chip select
78
EE_CS                   = 1 shl 1       ; chip select
65
EE_DI                   = 1 shl 2       ; data in
79
EE_DI                   = 1 shl 2       ; data in
66
EE_DO                   = 1 shl 3       ; data out
80
EE_DO                   = 1 shl 3       ; data out
67
EE_MASK                 = EE_SK + EE_CS + EE_DI + EE_DO
81
EE_MASK                 = EE_SK or EE_CS or EE_DI or EE_DO
68
; opcodes, first bit is start bit and must be 1
82
; opcodes, first bit is start bit and must be 1
69
EE_READ                 = 110b
83
EE_READ                 = 110b
70
EE_WRITE                = 101b
84
EE_WRITE                = 101b
71
EE_ERASE                = 111b
85
EE_ERASE                = 111b
Line 579... Line 593...
579
        call    cmd_wait
593
        call    cmd_wait
Line 580... Line 594...
580
 
594
 
581
;-------------------------
595
;-------------------------
Line 582... Line 596...
582
; Individual address setup
596
; Individual address setup
583
 
597
 
584
        mov     [ebx + device.confcmd.command], TXFD_CMD_IA + TXFD_CMD_SUSPEND
598
        mov     [ebx + device.confcmd.command], TXFD_CMD_IA or TXFD_CMD_SUSPEND
585
        mov     [ebx + device.confcmd.status], 0
599
        mov     [ebx + device.confcmd.status], 0
586
        lea     eax, [ebx + device.tx_ring]
600
        lea     eax, [ebx + device.tx_ring]
587
        invoke  GetPhysAddr
601
        invoke  GetPhysAddr
Line 602... Line 616...
602
        call    cmd_wait
616
        call    cmd_wait
Line 603... Line 617...
603
 
617
 
604
;-------------
618
;-------------
Line 605... Line 619...
605
; Configure CU
619
; Configure CU
606
 
620
 
607
        mov     [ebx + device.confcmd.command], TXFD_CMD_CFG + TXFD_CMD_SUSPEND
621
        mov     [ebx + device.confcmd.command], TXFD_CMD_CFG or TXFD_CMD_SUSPEND
608
        mov     [ebx + device.confcmd.status], 0
622
        mov     [ebx + device.confcmd.status], 0
609
        lea     eax, [ebx + device.confcmd.status]
623
        lea     eax, [ebx + device.confcmd.status]
Line 702... Line 716...
702
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
716
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
703
;;                                         ;;
717
;;                                         ;;
704
;; Transmit                                ;;
718
;; Transmit                                ;;
705
;;                                         ;;
719
;;                                         ;;
706
;; In: pointer to device structure in ebx  ;;
720
;; In: pointer to device structure in ebx  ;;
-
 
721
;; Out: eax = 0 on success                 ;;
707
;;                                         ;;
722
;;                                         ;;
708
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
723
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
709
 
724
align 16
710
proc transmit stdcall bufferptr
725
proc transmit stdcall bufferptr
Line 711... Line 726...
711
 
726
 
712
        pushf
-
 
Line 713... Line 727...
713
        cli
727
        spin_lock_irqsave
714
 
728
 
715
        mov     esi, [bufferptr]
729
        mov     esi, [bufferptr]
716
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
730
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
717
        lea     eax, [esi + NET_BUFF.data]
731
        lea     eax, [esi + NET_BUFF.data]
718
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
732
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
719
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
733
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
Line 720... Line 734...
720
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
734
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
721
        [eax+13]:2,[eax+12]:2
735
        [eax+13]:2,[eax+12]:2
722
 
736
 
723
        cmp     [esi + NET_BUFF.length], 1514
737
        cmp     [esi + NET_BUFF.length], 1514
Line 724... Line 738...
724
        ja      .fail
738
        ja      .error
725
        cmp     [esi + NET_BUFF.length], 60
739
        cmp     [esi + NET_BUFF.length], 60
726
        jb      .fail
740
        jb      .error
727
 
741
 
728
        ; Get current TX descriptor
742
        ; Get current TX descriptor
Line 729... Line 743...
729
        mov     edi, [ebx + device.cur_tx]
743
        mov     edi, [ebx + device.cur_tx]
730
        mov     eax, sizeof.txfd
744
        mov     eax, sizeof.txfd
731
        mul     edi
745
        mul     edi
Line 732... Line 746...
732
        lea     edi, [ebx + device.tx_ring + eax]
746
        lea     edi, [ebx + device.tx_ring + eax]
733
 
747
 
734
        ; Check if current descriptor is free or still in use
748
        ; Check if current descriptor is free or still in use
735
        cmp     [edi + txfd.status], 0
749
        cmp     [edi + txfd.status], 0
Line 736... Line 750...
736
        jne     .fail
750
        jne     .overrun
737
 
751
 
738
        ; Fill in status and command values
752
        ; Fill in status and command values
Line 766... Line 780...
766
        ; Update stats
780
        ; Update stats
767
        inc     [ebx + device.packets_tx]
781
        inc     [ebx + device.packets_tx]
768
        add     dword[ebx + device.bytes_tx], ecx
782
        add     dword[ebx + device.bytes_tx], ecx
769
        adc     dword[ebx + device.bytes_tx + 4], 0
783
        adc     dword[ebx + device.bytes_tx + 4], 0
Line 770... Line -...
770
 
-
 
771
        ; Wait for command to complete
-
 
772
        call    cmd_wait
-
 
773
 
784
 
774
        inc     [ebx + device.cur_tx]
785
        inc     [ebx + device.cur_tx]
Line 775... Line 786...
775
        and     [ebx + device.cur_tx], TX_RING_SIZE - 1
786
        and     [ebx + device.cur_tx], TX_RING_SIZE - 1
776
 
787
 
-
 
788
        ; Wait for command to complete
-
 
789
        call    cmd_wait
777
        DEBUGF  1,"Transmit OK\n"
790
 
778
        popf
791
        spin_unlock_irqrestore
Line 779... Line 792...
779
        xor     eax, eax
792
        xor     eax, eax
780
        ret
793
        ret
-
 
794
 
-
 
795
  .error:
-
 
796
        DEBUGF  2, "TX packet error\n"
-
 
797
        inc     [ebx + device.packets_tx_err]
-
 
798
        invoke  NetFree, [bufferptr]
-
 
799
 
-
 
800
        spin_unlock_irqrestore
-
 
801
        or      eax, -1
-
 
802
        ret
-
 
803
 
781
 
804
  .overrun:
-
 
805
        DEBUGF  2, "TX overrun\n"
782
  .fail:
806
        inc     [ebx + device.packets_tx_ovr]
783
        DEBUGF  2,"Transmit failed!\n"
807
        invoke  NetFree, [bufferptr]
784
        invoke  NetFree, [bufferptr]
808
 
Line 785... Line 809...
785
        popf
809
        spin_unlock_irqrestore
Line 792... Line 816...
792
;;;;;;;;;;;;;;;;;;;;;;;
816
;;;;;;;;;;;;;;;;;;;;;;;
793
;;                   ;;
817
;;                   ;;
794
;; Interrupt handler ;;
818
;; Interrupt handler ;;
795
;;                   ;;
819
;;                   ;;
796
;;;;;;;;;;;;;;;;;;;;;;;
820
;;;;;;;;;;;;;;;;;;;;;;;
797
 
-
 
798
align 4
821
align 16
799
int_handler:
822
int_handler:
Line 800... Line 823...
800
 
823
 
Line 801... Line 824...
801
        push    ebx esi edi
824
        push    ebx esi edi
802
 
-
 
803
        DEBUGF  1,"INT\n"
825
 
Line 804... Line -...
804
 
-
 
805
; find pointer of device wich made IRQ occur
-
 
806
 
-
 
807
        mov     ecx, [devices]
826
        mov     ebx, [esp+4*4]
808
        test    ecx, ecx
-
 
809
        jz      .nothing
-
 
Line 810... Line 827...
810
        mov     esi, device_list
827
        DEBUGF  1,"INT for 0x%x\n", ebx
811
  .nextdevice:
828
 
812
        mov     ebx, [esi]
829
; TODO? if we are paranoid, we can check that the value from ebx is present in the current device_list
813
 
-
 
814
;        set_io  [ebx + device.io_addr], 0      ; REG_SCB_STATUS = 0
830
 
815
        set_io  [ebx + device.io_addr], REG_SCB_STATUS
831
;        set_io  [ebx + device.io_addr], 0      ; REG_SCB_STATUS = 0
816
        in      ax, dx
-
 
817
        out     dx, ax                          ; send it back to ACK
-
 
818
        test    ax, ax
-
 
819
        jnz     .got_it
-
 
820
  .continue:
-
 
821
        add     esi, 4
-
 
822
        dec     ecx
-
 
823
        jnz     .nextdevice
-
 
824
  .nothing:
832
        set_io  [ebx + device.io_addr], REG_SCB_STATUS
825
        pop     edi esi ebx
-
 
826
        xor     eax, eax
-
 
Line 827... Line 833...
827
 
833
        in      ax, dx
Line 828... Line 834...
828
        ret                                         ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
834
        test    ax, ax
829
 
835
        jz      .nothing
Line 830... Line 836...
830
  .got_it:
836
        out     dx, ax                          ; send it back to ACK
Line 956... Line 962...
956
  .tx_done:
962
  .tx_done:
957
        pop     eax
963
        pop     eax
958
  .no_tx:
964
  .no_tx:
Line 959... Line 965...
959
 
965
 
960
        test    ax, RU_STATUS_NO_RESOURCES
966
        test    ax, RU_STATUS_NO_RESOURCES
Line 961... Line 967...
961
        jne     .fail
967
        jz      .not_out_of_resources
Line 962... Line 968...
962
 
968
 
963
        DEBUGF  2, "Out of resources!\n"
969
        DEBUGF  2, "Out of resources!\n"
964
 
970
 
965
  .fail:
971
  .not_out_of_resources:
Line 966... Line 972...
966
        pop     edi esi ebx
972
        pop     edi esi ebx
Line -... Line 973...
-
 
973
        xor     eax, eax
-
 
974
        inc     eax
-
 
975
 
Line -... Line 976...
-
 
976
        ret
Line 967... Line 977...
967
        xor     eax, eax
977
 
968
        inc     eax
978
  .nothing:
Line 981... Line 991...
981
 
991
 
Line 982... Line -...
982
        ret
-
 
983
 
-
 
984
 
-
 
985
 
992
        ret
986
 
993
 
Line 987... Line 994...
987
 
994