1,6 → 1,6 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;; R6040 driver for KolibriOS ;; |
66,9 → 66,17 |
;************************************************************************** |
; RDC R6040 Register Definitions |
;************************************************************************** |
|
MCR0 = 0x00 ;Control register 0 |
MCR0_RCVEN = 0x0002 ; Receive enable |
MCR0_PROMISC = 0x0020 ; Promiscuous mode |
MCR0_HASH_EN = 0x0100 ; Enable multicast hash table function |
MCR0_XMTEN = 0x1000 ; Transmission enable |
MCR0_FD = 0x8000 ; Full/Half Duplex mode |
|
MCR1 = 0x01 ;Control register 1 |
MAC_RST = 0x0001 ;Reset the MAC |
|
MBCR = 0x08 ;Bus control |
MT_ICR = 0x0C ;TX interrupt control |
MR_ICR = 0x10 ;RX interrupt control |
76,15 → 84,18 |
MR_BSR = 0x18 ;RX buffer size |
MR_DCR = 0x1A ;RX descriptor control |
MLSR = 0x1C ;Last status |
|
MMDIO = 0x20 ;MDIO control register |
MDIO_WRITE = 0x4000 ;MDIO write |
MDIO_READ = 0x2000 ;MDIO read |
MMRD = 0x24 ;MDIO read data register |
MMWD = 0x28 ;MDIO write data register |
|
MTD_SA0 = 0x2C ;TX descriptor start address 0 |
MTD_SA1 = 0x30 ;TX descriptor start address 1 |
MRD_SA0 = 0x34 ;RX descriptor start address 0 |
MRD_SA1 = 0x38 ;RX descriptor start address 1 |
|
MISR = 0x3C ;Status register |
MIER = 0x40 ;INT enable register |
MSK_INT = 0x0000 ;Mask off interrupts |
96,6 → 107,7 |
TX_EARLY = 0x0080 ;TX early |
EVENT_OVRFL = 0x0100 ;Event counter overflow |
LINK_CHANGED = 0x0200 ;PHY link changed |
|
ME_CISR = 0x44 ;Event counter INT status |
ME_CIER = 0x48 ;Event counter INT enable |
MR_CNT = 0x50 ;Successfully received packet counter |
224,7 → 236,7 |
|
.entry: |
|
DEBUGF 2,"Loading %s driver\n", my_service |
DEBUGF 2,"Loading driver\n" |
stdcall RegService, my_service, service_proc |
ret |
|
415,7 → 427,7 |
|
align 4 |
probe: |
DEBUGF 2,"Probing R6040 device\n" |
DEBUGF 1,"Probing R6040 device\n" |
|
PCI_make_bus_master |
|
438,11 → 450,11 |
or eax, dword [device.mac] |
test eax, eax |
jnz @f |
DEBUGF 2, "ERROR: MAC address not initialized!\n" |
DEBUGF 2, "MAC address not initialized!\n" |
|
@@: |
; Init RDC private data |
mov [device.mcr0], 0x1002 |
mov [device.mcr0], MCR0_XMTEN or MCR0_RCVEN |
;mov [private.phy_addr], 1 ; Asper: Only one network card is supported now. |
mov [device.switch_sig], 0 |
|
463,7 → 475,7 |
call init_rxbufs |
|
; Read the PHY ID |
mov [device.phy_mode], 0x8000 |
mov [device.phy_mode], MCR0_FD |
stdcall phy_read, 0, 2 |
mov [device.switch_sig], ax |
cmp ax, ICPLUS_PHY_ID |
513,7 → 525,7 |
align 4 |
reset: |
|
DEBUGF 2,"Resetting R6040\n" |
DEBUGF 1,"Resetting R6040\n" |
|
; Mask off Interrupt |
xor ax, ax |
525,11 → 537,11 |
; attach int handler |
|
movzx eax, [device.irq_line] |
DEBUGF 2,"Attaching int handler to irq %x\n", eax:1 |
DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
stdcall AttachIntHandler, eax, int_handler, dword 0 |
test eax, eax |
jnz @f |
DEBUGF 2,"\nCould not attach int handler!\n" |
DEBUGF 2,"Could not attach int handler!\n" |
; or eax, -1 |
; ret |
@@: |
600,9 → 612,9 |
set_io MIER |
out dx, ax |
|
;Enable TX and RX |
;Enable RX |
mov ax, [device.mcr0] |
or ax, 0x0002 |
or ax, MCR0_RCVEN |
set_io 0 |
out dx, ax |
|
670,9 → 682,9 |
.next_desc: |
mov [esi + x_head.ndesc], edx |
|
push esi ecx |
push esi ecx edx |
stdcall KernelAlloc, MAX_BUF_SIZE |
pop ecx esi |
pop edx ecx esi |
|
mov [esi + x_head.skb_ptr], eax |
GetRealAddr |
686,7 → 698,6 |
jnz .next_desc |
|
; complete the ring by linking the last to the first |
|
lea eax, [device.rx_ring] |
GetRealAddr |
mov [device.rx_ring + x_head.sizeof*(RX_RING_SIZE - 1) + x_head.ndesc], eax |
751,9 → 762,9 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
align 4 |
transmit: |
DEBUGF 2,"\nTransmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] |
DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] |
mov eax, [esp+4] |
DEBUGF 2,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
[eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
[eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
[eax+13]:2,[eax+12]:2 |
768,15 → 779,14 |
add edi, ebx |
add edi, device.tx_ring - ebx |
|
DEBUGF 2,"TX buffer status: 0x%x\n", [edi + x_head.status]:4 |
DEBUGF 1,"TX buffer status: 0x%x\n", [edi + x_head.status]:4 |
|
test [edi + x_head.status], DSC_OWNER_MAC ; check if buffer is available |
jnz .wait_to_send |
|
.do_send: |
DEBUGF 1,"Sending now\n" |
|
DEBUGF 2,"Sending now\n" |
|
mov eax, [esp+4] |
mov [edi + x_head.skb_ptr], eax |
GetRealAddr |
805,7 → 815,7 |
|
.wait_to_send: |
|
DEBUGF 2,"Waiting for TX buffer\n" |
DEBUGF 1,"Waiting for TX buffer\n" |
|
call GetTimerTicks ; returns in eax |
lea edx, [eax + 100] |
818,11 → 828,11 |
cmp edx, eax |
jb .l2 |
|
DEBUGF 1,"Send timeout\n" |
DEBUGF 2,"Send timeout\n" |
xor eax, eax |
dec eax |
.fail: |
DEBUGF 1,"Send failed\n" |
DEBUGF 2,"Send failed\n" |
stdcall KernelFree, [esp+4] |
or eax, -1 |
ret 8 |
842,7 → 852,7 |
|
push ebx esi edi |
|
DEBUGF 1,"\n%s int\n", my_service |
DEBUGF 1,"int\n" |
|
; Find pointer of device wich made IRQ occur |
|
874,7 → 884,7 |
|
.got_it: |
|
DEBUGF 1,"Device: %x Status: %x ", ebx, ax |
DEBUGF 1,"Device: %x Status: %x\n", ebx, ax |
|
push ax |
|
886,24 → 896,21 |
pop ebx |
|
; Find the current RX descriptor |
|
movzx edx, [device.cur_rx] |
shl edx, 5 |
lea edx, [device.rx_ring + edx] |
|
; Check the descriptor status |
|
mov cx, [edx + x_head.status] |
test cx, DSC_OWNER_MAC |
jnz .no_RX |
|
DEBUGF 2,"packet status=0x%x\n", cx |
DEBUGF 1,"packet status=0x%x\n", cx |
|
test cx, DSC_RX_ERR ; Global error status set |
jnz .no_RX |
|
; Packet successfully received |
|
movzx ecx, [edx + x_head.len] |
and ecx, 0xFFF |
sub ecx, 4 ; Do not count the CRC |
914,7 → 921,6 |
inc dword [device.packets_rx] |
|
; Push packet size and pointer, kernel will need it.. |
|
push ebx |
push .more_RX |
|
921,10 → 927,9 |
push ecx |
push [edx + x_head.skb_ptr] |
|
DEBUGF 2,"packet ptr=0x%x\n", [edx + x_head.skb_ptr] |
DEBUGF 1,"packet ptr=0x%x\n", [edx + x_head.skb_ptr] |
|
; reset the RX descriptor |
|
push edx |
stdcall KernelAlloc, MAX_BUF_SIZE |
pop edx |
934,12 → 939,10 |
mov [edx + x_head.status], DSC_OWNER_MAC |
|
; Use next descriptor next time |
|
inc [device.cur_rx] |
and [device.cur_rx], RX_RING_SIZE - 1 |
|
; At last, send packet to kernel |
|
jmp Eth_input |
|
|
959,7 → 962,7 |
cmp [edi + x_head.skb_ptr], 0 |
je .no_TX |
|
DEBUGF 2,"Freeing buffer 0x%x\n", [edi + x_head.skb_ptr] |
DEBUGF 1,"Freeing buffer 0x%x\n", [edi + x_head.skb_ptr] |
|
push [edi + x_head.skb_ptr] |
mov [edi + x_head.skb_ptr], 0 |
971,6 → 974,42 |
jmp .loop_tx |
|
.no_TX: |
test word[esp], RX_NO_DESC |
jz .no_rxdesc |
|
DEBUGF 2, "No more RX descriptors!\n" |
|
.no_rxdesc: |
test word[esp], RX_FIFO_FULL |
jz .no_rxfifo |
|
DEBUGF 2, "RX FIFO full!\n" |
|
.no_rxfifo: |
test word[esp], RX_EARLY |
jz .no_rxearly |
|
DEBUGF 1, "RX early\n" |
|
.no_rxearly: |
test word[esp], TX_EARLY |
jz .no_txearly |
|
DEBUGF 1, "TX early\n" |
|
.no_txearly: |
test word[esp], EVENT_OVRFL |
jz .no_ovrfl |
|
DEBUGF 2, "Event counter overflow!\n" |
|
.no_ovrfl: |
test word[esp], LINK_CHANGED |
jz .no_link |
|
DEBUGF 1, "Link changed\n" |
|
.no_link: |
pop ax |
|
pop edi esi ebx |
983,7 → 1022,7 |
align 4 |
init_mac_regs: |
|
DEBUGF 2,"initializing MAC regs\n" |
DEBUGF 1,"initializing MAC regs\n" |
|
; MAC operation register |
mov ax, 1 |
1012,7 → 1051,7 |
align 4 |
proc phy_read stdcall, phy_addr:dword, reg:dword |
|
DEBUGF 2,"PHY read, addr=0x%x reg=0x%x\n", [phy_addr]:8, [reg]:8 |
DEBUGF 1,"PHY read, addr=0x%x reg=0x%x\n", [phy_addr]:8, [reg]:8 |
|
mov eax, [phy_addr] |
shl eax, 8 |
1036,7 → 1075,7 |
in ax, dx |
and eax, 0xFFFF |
|
DEBUGF 2,"PHY read, val=0x%x\n", eax:4 |
DEBUGF 1,"PHY read, val=0x%x\n", eax:4 |
|
ret |
|
1050,7 → 1089,7 |
align 4 |
proc phy_write stdcall, phy_addr:dword, reg:dword, val:dword |
|
DEBUGF 2,"PHY write, addr=0x%x reg=0x%x val=0x%x\n", [phy_addr]:8, [reg]:8, [val]:8 |
DEBUGF 1,"PHY write, addr=0x%x reg=0x%x val=0x%x\n", [phy_addr]:8, [reg]:8, [val]:8 |
|
mov eax, [val] |
set_io 0 |
1076,7 → 1115,7 |
jnz .write |
@@: |
|
DEBUGF 2,"PHY write ok\n" |
DEBUGF 1,"PHY write ok\n" |
|
ret |
endp |
1086,7 → 1125,7 |
align 4 |
read_mac: |
|
DEBUGF 2,"Reading MAC: " |
DEBUGF 1,"Reading MAC: " |
|
mov cx, 3 |
lea edi, [device.mac] |
1100,7 → 1139,7 |
dec cx |
jnz .mac |
|
DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2, [edi-5]:2, [edi-4]:2, [edi-3]:2, [edi-2]:2, [edi-1]:2 |
DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2, [edi-5]:2, [edi-4]:2, [edi-3]:2, [edi-2]:2, [edi-1]:2 |
|
ret |
|