Rev 5522 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5522 | Rev 9158 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. 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 | ;; R6040 driver for KolibriOS ;; |
6 | ;; R6040 driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; based on R6040.c from linux ;; |
8 | ;; based on R6040.c from linux ;; |
Line 13... | Line 13... | ||
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; Version 2, June 1991 ;; |
14 | ;; Version 2, June 1991 ;; |
15 | ;; ;; |
15 | ;; ;; |
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line -... | Line 17... | ||
- | 17 | ||
- | 18 | ; TODO: test for RX-overrun |
|
17 | 19 | ||
18 | format PE DLL native |
20 | format PE DLL native |
Line 19... | Line 21... | ||
19 | entry START |
21 | entry START |
20 | 22 | ||
Line 29... | Line 31... | ||
29 | 31 | ||
Line 30... | Line 32... | ||
30 | W_MAX_TIMEOUT = 0x0FFF ; max time out delay time |
32 | W_MAX_TIMEOUT = 0x0FFF ; max time out delay time |
Line 31... | Line 33... | ||
31 | 33 | ||
32 | TX_TIMEOUT = 6000 ; Time before concluding the transmitter is hung, in ms |
34 | TX_TIMEOUT = 6000 ; Time before concluding the transmitter is hung, in ms |
Line 33... | Line 35... | ||
33 | 35 | ||
Line 34... | Line 36... | ||
34 | TX_RING_SIZE = 4 ; RING sizes must be a power of 2 |
36 | TX_RING_SIZE = 16 ; RING sizes must be a power of 2 |
Line 377... | Line 379... | ||
377 | ;; Actual Hardware dependent code starts here ;; |
379 | ;; Actual Hardware dependent code starts here ;; |
378 | ;; ;; |
380 | ;; ;; |
379 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
381 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
Line 380... | Line -... | ||
380 | - | ||
381 | - | ||
382 | ;mdio_read: |
- | |
383 | ; stdcall phy_read, [ebx + device.io_addr], [ebx + device.phy_addr], ecx |
- | |
384 | - | ||
385 | ; ret |
- | |
386 | - | ||
387 | ;mdio_write: |
- | |
388 | ; stdcall phy_write, [ebx + device.io_addr], [ebx + device.phy_addr], ecx, eax |
- | |
389 | - | ||
390 | ; ret |
- | |
391 | 382 | ||
392 | 383 | ||
393 | align 4 |
384 | align 4 |
394 | unload: |
385 | unload: |
395 | ; TODO: (in this particular order) |
386 | ; TODO: (in this particular order) |
Line 600... | Line 591... | ||
600 | out dx, ax |
591 | out dx, ax |
Line 601... | Line 592... | ||
601 | 592 | ||
602 | ;Enable RX |
593 | ;Enable RX |
603 | mov ax, [ebx + device.mcr0] |
594 | mov ax, [ebx + device.mcr0] |
604 | or ax, MCR0_RCVEN |
595 | or ax, MCR0_RCVEN |
605 | set_io [ebx + device.io_addr], 0 |
596 | set_io [ebx + device.io_addr], MCR0 |
Line 606... | Line 597... | ||
606 | out dx, ax |
597 | out dx, ax |
607 | 598 | ||
608 | ;Let TX poll the descriptors |
599 | ;Let TX poll the descriptors |
Line 736... | Line 727... | ||
736 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
727 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
737 | ;; ;; |
728 | ;; ;; |
738 | ;; Transmit ;; |
729 | ;; Transmit ;; |
739 | ;; ;; |
730 | ;; ;; |
740 | ;; In: pointer to device structure in ebx ;; |
731 | ;; In: pointer to device structure in ebx ;; |
- | 732 | ;; Out: eax = 0 on success ;; |
|
741 | ;; ;; |
733 | ;; ;; |
742 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
734 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
743 | 735 | align 16 |
|
744 | proc transmit stdcall bufferptr |
736 | proc transmit stdcall bufferptr |
Line 745... | Line 737... | ||
745 | 737 | ||
746 | pushf |
- | |
Line 747... | Line 738... | ||
747 | cli |
738 | spin_lock_irqsave |
748 | 739 | ||
749 | mov esi, [bufferptr] |
740 | mov esi, [bufferptr] |
750 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length] |
741 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length] |
751 | lea eax, [esi + NET_BUFF.data] |
742 | lea eax, [esi + NET_BUFF.data] |
752 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
743 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
753 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
744 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
Line 754... | Line 745... | ||
754 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
745 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
755 | [eax+13]:2,[eax+12]:2 |
746 | [eax+13]:2,[eax+12]:2 |
756 | 747 | ||
757 | cmp [esi + NET_BUFF.length], 1514 |
748 | cmp [esi + NET_BUFF.length], 1514 |
Line 758... | Line 749... | ||
758 | ja .fail |
749 | ja .error |
759 | cmp [esi + NET_BUFF.length], 60 |
750 | cmp [esi + NET_BUFF.length], 60 |
760 | jb .fail |
751 | jb .error |
761 | 752 | ||
Line 762... | Line 753... | ||
762 | movzx edi, [ebx + device.cur_tx] |
753 | movzx edi, [ebx + device.cur_tx] |
Line 763... | Line 754... | ||
763 | shl edi, 5 |
754 | shl edi, 5 |
764 | add edi, ebx |
755 | add edi, ebx |
765 | add edi, device.tx_ring |
- | |
766 | - | ||
767 | DEBUGF 1,"TX buffer status: 0x%x\n", [edi + x_head.status]:4 |
- | |
Line 768... | Line 756... | ||
768 | 756 | add edi, device.tx_ring |
|
769 | test [edi + x_head.status], DSC_OWNER_MAC ; check if buffer is available |
757 | |
770 | jnz .wait_to_send |
758 | DEBUGF 1,"TX buffer status: 0x%x\n", [edi + x_head.status]:4 |
771 | 759 | ||
Line 794... | Line 782... | ||
794 | inc [ebx + device.packets_tx] |
782 | inc [ebx + device.packets_tx] |
795 | mov eax, [esi + NET_BUFF.length] |
783 | mov eax, [esi + NET_BUFF.length] |
796 | add dword[ebx + device.bytes_tx], eax |
784 | add dword[ebx + device.bytes_tx], eax |
797 | adc dword[ebx + device.bytes_tx + 4], 0 |
785 | adc dword[ebx + device.bytes_tx + 4], 0 |
Line 798... | Line 786... | ||
798 | 786 | ||
799 | popf |
787 | spin_unlock_irqrestore |
800 | xor eax, eax |
788 | xor eax, eax |
Line 801... | Line 789... | ||
801 | ret |
789 | ret |
802 | 790 | ||
803 | .wait_to_send: |
- | |
804 | DEBUGF 1,"Waiting for TX buffer\n" |
791 | .error: |
805 | invoke GetTimerTicks ; returns in eax |
- | |
806 | lea edx, [eax + 100] |
792 | DEBUGF 2, "TX packet error\n" |
807 | .l2: |
- | |
808 | mov esi, [bufferptr] |
- | |
809 | test [edi + x_head.status], DSC_OWNER_MAC |
- | |
810 | jz .do_send |
- | |
811 | popf |
- | |
812 | mov esi, 10 |
- | |
813 | invoke Sleep |
- | |
814 | invoke GetTimerTicks |
- | |
815 | pushf |
- | |
816 | cli |
- | |
Line 817... | Line 793... | ||
817 | cmp edx, eax |
793 | inc [ebx + device.packets_tx_err] |
- | 794 | invoke NetFree, [bufferptr] |
|
- | 795 | ||
- | 796 | spin_unlock_irqrestore |
|
818 | jb .l2 |
797 | or eax, -1 |
819 | 798 | ret |
|
- | 799 | ||
820 | DEBUGF 2,"Send timeout\n" |
800 | .overrun: |
- | 801 | DEBUGF 2, "TX overrun\n" |
|
821 | .fail: |
802 | inc [ebx + device.packets_tx_ovr] |
822 | DEBUGF 2,"Send failed\n" |
803 | invoke NetFree, [bufferptr] |
823 | invoke NetFree, [bufferptr] |
804 | |
Line 824... | Line 805... | ||
824 | popf |
805 | spin_unlock_irqrestore |
Line 832... | Line 813... | ||
832 | ;;;;;;;;;;;;;;;;;;;;;;; |
813 | ;;;;;;;;;;;;;;;;;;;;;;; |
833 | ;; ;; |
814 | ;; ;; |
834 | ;; Interrupt handler ;; |
815 | ;; Interrupt handler ;; |
835 | ;; ;; |
816 | ;; ;; |
836 | ;;;;;;;;;;;;;;;;;;;;;;; |
817 | ;;;;;;;;;;;;;;;;;;;;;;; |
837 | - | ||
838 | align 4 |
818 | align 16 |
839 | int_handler: |
819 | int_handler: |
Line 840... | Line 820... | ||
840 | 820 | ||
Line -... | Line 821... | ||
- | 821 | push ebx esi edi |
|
841 | push ebx esi edi |
822 | |
Line 842... | Line -... | ||
842 | - | ||
843 | DEBUGF 1,"int\n" |
- | |
844 | - | ||
845 | ; Find pointer of device wich made IRQ occur |
- | |
846 | - | ||
847 | mov ecx, [devices] |
823 | mov ebx, [esp+4*4] |
848 | test ecx, ecx |
- | |
849 | jz .nothing |
- | |
Line 850... | Line 824... | ||
850 | mov esi, device_list |
824 | DEBUGF 1,"INT for 0x%x\n", ebx |
851 | .nextdevice: |
825 | |
852 | mov ebx, [esi] |
826 | ; TODO? if we are paranoid, we can check that the value from ebx is present in the current device_list |
853 | - | ||
854 | set_io [ebx + device.io_addr], 0 |
827 | |
855 | set_io [ebx + device.io_addr], MISR |
828 | set_io [ebx + device.io_addr], 0 |
856 | in ax, dx |
- | |
857 | out dx, ax ; send it back to ACK |
- | |
858 | test ax, ax |
- | |
859 | jnz .got_it |
- | |
860 | .continue: |
- | |
861 | add esi, 4 |
- | |
862 | dec ecx |
- | |
863 | jnz .nextdevice |
- | |
864 | .nothing: |
- | |
865 | pop edi esi ebx |
- | |
866 | xor eax, eax |
- | |
867 | - | ||
868 | ret ; If no device was found, abort |
- | |
Line -... | Line 829... | ||
- | 829 | set_io [ebx + device.io_addr], MISR |
|
869 | 830 | in ax, dx |
|
Line 870... | Line 831... | ||
870 | ; At this point, test for all possible reasons, and handle accordingly |
831 | test ax, ax |
Line 871... | Line 832... | ||
871 | 832 | jz .nothing |
|
872 | .got_it: |
833 | |
Line 932... | Line 893... | ||
932 | inc [ebx + device.cur_rx] |
893 | inc [ebx + device.cur_rx] |
933 | and [ebx + device.cur_rx], RX_RING_SIZE - 1 |
894 | and [ebx + device.cur_rx], RX_RING_SIZE - 1 |
Line 934... | Line 895... | ||
934 | 895 | ||
935 | ; At last, send packet to kernel |
896 | ; At last, send packet to kernel |
936 | jmp [EthInput] |
- | |
937 | - | ||
938 | 897 | jmp [EthInput] |
|
- | 898 | .no_RX: |
|
939 | .no_RX: |
899 | |
940 | test word[esp], TX_FINISH |
900 | test word[esp], TX_FINISH |
941 | jz .no_TX |
- | |
942 | 901 | jz .no_TX |
|
943 | .loop_tx: |
902 | .loop_tx: |
944 | movzx edi, [ebx + device.last_tx] |
903 | movzx edi, [ebx + device.last_tx] |
945 | shl edi, 5 |
904 | shl edi, 5 |
Line 959... | Line 918... | ||
959 | 918 | ||
960 | inc [ebx + device.last_tx] |
919 | inc [ebx + device.last_tx] |
Line 961... | Line 920... | ||
961 | and [ebx + device.last_tx], TX_RING_SIZE - 1 |
920 | and [ebx + device.last_tx], TX_RING_SIZE - 1 |
962 | - | ||
963 | jmp .loop_tx |
921 | |
- | 922 | jmp .loop_tx |
|
964 | 923 | .no_TX: |
|
965 | .no_TX: |
924 | |
Line 966... | Line 925... | ||
966 | test word[esp], RX_NO_DESC |
925 | test word[esp], RX_NO_DESC |
967 | jz .no_rxdesc |
- | |
968 | 926 | jz .no_rxdesc |
|
- | 927 | ||
969 | DEBUGF 2, "No more RX descriptors!\n" |
928 | DEBUGF 2, "No more RX descriptors!\n" |
970 | 929 | .no_rxdesc: |
|
Line 971... | Line 930... | ||
971 | .no_rxdesc: |
930 | |
972 | test word[esp], RX_FIFO_FULL |
- | |
973 | jz .no_rxfifo |
931 | test word[esp], RX_FIFO_FULL |
- | 932 | jz .no_rxfifo |
|
974 | 933 | ||
975 | DEBUGF 2, "RX FIFO full!\n" |
934 | DEBUGF 2, "RX FIFO full!\n" |
Line 976... | Line 935... | ||
976 | 935 | .no_rxfifo: |
|
977 | .no_rxfifo: |
- | |
978 | test word[esp], RX_EARLY |
936 | |
- | 937 | test word[esp], RX_EARLY |
|
979 | jz .no_rxearly |
938 | jz .no_rxearly |
980 | 939 | ||
Line 981... | Line 940... | ||
981 | DEBUGF 2, "RX early\n" |
940 | DEBUGF 2, "RX early\n" |
982 | - | ||
983 | .no_rxearly: |
941 | .no_rxearly: |
- | 942 | ||
984 | test word[esp], TX_EARLY |
943 | test word[esp], TX_EARLY |
985 | jz .no_txearly |
944 | jz .no_txearly |
Line 986... | Line 945... | ||
986 | 945 | ||
987 | DEBUGF 2, "TX early\n" |
- | |
988 | 946 | DEBUGF 2, "TX early\n" |
|
- | 947 | .no_txearly: |
|
989 | .no_txearly: |
948 | |
990 | test word[esp], EVENT_OVRFL |
949 | test word[esp], EVENT_OVRFL |
Line 991... | Line 950... | ||
991 | jz .no_ovrfl |
950 | jz .no_ovrfl |
992 | - | ||
993 | DEBUGF 2, "Event counter overflow!\n" |
951 | |
- | 952 | DEBUGF 2, "Event counter overflow!\n" |
|
994 | 953 | .no_ovrfl: |
|
Line 995... | Line 954... | ||
995 | .no_ovrfl: |
954 | |
- | 955 | test word[esp], LINK_CHANGED |
|
- | 956 | jz .no_link |
|
- | 957 | ||
- | 958 | DEBUGF 2, "Link changed\n" |
|
- | 959 | .no_link: |
|
- | 960 | ||
- | 961 | pop ax |
|
- | 962 | ||
Line 996... | Line 963... | ||
996 | test word[esp], LINK_CHANGED |
963 | pop edi esi ebx |