2013-05-28 21:34:26 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 23:10:22 +03:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2013-05-28 21:34:26 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; R6040 driver for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; based on R6040.c from linux ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by Asper (asper.85@mail.ru) ;;
|
|
|
|
;; and hidnplayr (hidnplayr@gmail.com) ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
format PE DLL native
|
|
|
|
entry START
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
CURRENT_API = 0x0200
|
|
|
|
COMPATIBLE_API = 0x0100
|
|
|
|
API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
MAX_DEVICES = 16
|
|
|
|
|
|
|
|
__DEBUG__ = 1
|
|
|
|
__DEBUG_LEVEL__ = 2
|
|
|
|
|
|
|
|
W_MAX_TIMEOUT = 0x0FFF ; max time out delay time
|
|
|
|
|
|
|
|
TX_TIMEOUT = 6000 ; Time before concluding the transmitter is hung, in ms
|
|
|
|
|
|
|
|
TX_RING_SIZE = 4 ; RING sizes must be a power of 2
|
|
|
|
RX_RING_SIZE = 4
|
|
|
|
|
|
|
|
RX_BUF_LEN_IDX = 3 ; 0==8K, 1==16K, 2==32K, 3==64K
|
|
|
|
|
|
|
|
; Threshold is bytes transferred to chip before transmission starts.
|
|
|
|
|
|
|
|
TX_FIFO_THRESH = 256 ; In bytes, rounded down to 32 byte units.
|
|
|
|
|
|
|
|
; The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024.
|
|
|
|
|
|
|
|
RX_FIFO_THRESH = 4 ; Rx buffer level before first PCI xfer.
|
|
|
|
RX_DMA_BURST = 4 ; Maximum PCI burst, '4' is 256 bytes
|
|
|
|
TX_DMA_BURST = 4
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
section '.flat' readable writable executable
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
include '../proc32.inc'
|
2014-01-17 16:51:32 +04:00
|
|
|
include '../struct.inc'
|
|
|
|
include '../macros.inc'
|
2013-05-28 21:34:26 +04:00
|
|
|
include '../fdo.inc'
|
2014-08-31 18:09:14 +04:00
|
|
|
include '../netdrv.inc'
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Operational parameters that usually are not changed.
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
PHY1_ADDR = 1 ; For MAC1
|
|
|
|
PHY2_ADDR = 3 ; For MAC2
|
|
|
|
PHY_MODE = 0x3100 ; PHY CHIP Register 0
|
|
|
|
PHY_CAP = 0x01E1 ; PHY CHIP Register 4
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
;**************************************************************************
|
|
|
|
; RDC R6040 Register Definitions
|
|
|
|
;**************************************************************************
|
2014-01-11 00:33:38 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
MTPR = 0x14 ; TX poll command register
|
|
|
|
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
|
|
|
|
RX_FINISH = 0x0001 ; RX finished
|
|
|
|
RX_NO_DESC = 0x0002 ; No RX descriptor available
|
|
|
|
RX_FIFO_FULL = 0x0004 ; RX FIFO full
|
|
|
|
RX_EARLY = 0x0008 ; RX early
|
|
|
|
TX_FINISH = 0x0010 ; TX finished
|
|
|
|
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
|
|
|
|
ME_CNT0 = 0x52 ; Event counter 0
|
|
|
|
ME_CNT1 = 0x54 ; Event counter 1
|
|
|
|
ME_CNT2 = 0x56 ; Event counter 2
|
|
|
|
ME_CNT3 = 0x58 ; Event counter 3
|
|
|
|
MT_CNT = 0x5A ; Successfully transmit packet counter
|
|
|
|
ME_CNT4 = 0x5C ; Event counter 4
|
|
|
|
MP_CNT = 0x5E ; Pause frame counter register
|
|
|
|
MAR0 = 0x60 ; Hash table 0
|
|
|
|
MAR1 = 0x62 ; Hash table 1
|
|
|
|
MAR2 = 0x64 ; Hash table 2
|
|
|
|
MAR3 = 0x66 ; Hash table 3
|
|
|
|
MID_0L = 0x68 ; Multicast address MID0 Low
|
|
|
|
MID_0M = 0x6A ; Multicast address MID0 Medium
|
|
|
|
MID_0H = 0x6C ; Multicast address MID0 High
|
|
|
|
MID_1L = 0x70 ; MID1 Low
|
|
|
|
MID_1M = 0x72 ; MID1 Medium
|
|
|
|
MID_1H = 0x74 ; MID1 High
|
|
|
|
MID_2L = 0x78 ; MID2 Low
|
|
|
|
MID_2M = 0x7A ; MID2 Medium
|
|
|
|
MID_2H = 0x7C ; MID2 High
|
|
|
|
MID_3L = 0x80 ; MID3 Low
|
|
|
|
MID_3M = 0x82 ; MID3 Medium
|
|
|
|
MID_3H = 0x84 ; MID3 High
|
|
|
|
PHY_CC = 0x88 ; PHY status change configuration register
|
|
|
|
PHY_ST = 0x8A ; PHY status register
|
|
|
|
MAC_SM = 0xAC ; MAC status machine
|
|
|
|
MAC_ID = 0xBE ; Identifier register
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
MAX_BUF_SIZE = 1514
|
2014-01-11 00:33:38 +04:00
|
|
|
|
|
|
|
MBCR_DEFAULT = 0x012A ; MAC Bus Control Register
|
|
|
|
MCAST_MAX = 3 ; Max number multicast addresses to filter
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
;Descriptor status
|
2014-01-11 00:33:38 +04:00
|
|
|
DSC_OWNER_MAC = 0x8000 ; MAC is the owner of this descriptor
|
|
|
|
DSC_RX_OK = 0x4000 ; RX was successfull
|
|
|
|
DSC_RX_ERR = 0x0800 ; RX PHY error
|
|
|
|
DSC_RX_ERR_DRI = 0x0400 ; RX dribble packet
|
|
|
|
DSC_RX_ERR_BUF = 0x0200 ; RX length exceeds buffer size
|
|
|
|
DSC_RX_ERR_LONG = 0x0100 ; RX length > maximum packet length
|
|
|
|
DSC_RX_ERR_RUNT = 0x0080 ; RX packet length < 64 byte
|
|
|
|
DSC_RX_ERR_CRC = 0x0040 ; RX CRC error
|
|
|
|
DSC_RX_BCAST = 0x0020 ; RX broadcast (no error)
|
|
|
|
DSC_RX_MCAST = 0x0010 ; RX multicast (no error)
|
|
|
|
DSC_RX_MCH_HIT = 0x0008 ; RX multicast hit in hash table (no error)
|
|
|
|
DSC_RX_MIDH_HIT = 0x0004 ; RX MID table hit (no error)
|
|
|
|
DSC_RX_IDX_MID_MASK = 3 ; RX mask for the index of matched MIDx
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
;PHY settings
|
|
|
|
ICPLUS_PHY_ID = 0x0243
|
|
|
|
|
|
|
|
RX_INTS = RX_FIFO_FULL or RX_NO_DESC or RX_FINISH
|
|
|
|
TX_INTS = TX_FINISH
|
|
|
|
INT_MASK = RX_INTS or TX_INTS
|
|
|
|
|
|
|
|
RX_BUF_LEN equ (8192 << RX_BUF_LEN_IDX) ; Size of the in-memory receive ring.
|
|
|
|
|
|
|
|
IO_SIZE = 256 ; RDC MAC I/O Size
|
|
|
|
MAX_MAC = 2 ; MAX RDC MAC
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
struct x_head
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
status dw ? ;0-1
|
|
|
|
len dw ? ;2-3
|
|
|
|
buf dd ? ;4-7
|
|
|
|
ndesc dd ? ;8-B
|
|
|
|
rev1 dd ? ;C-F
|
|
|
|
vbufp dd ? ;10-13
|
|
|
|
vndescp dd ? ;14-17
|
|
|
|
skb_ptr dd ? ;18-1B
|
|
|
|
rev2 dd ? ;1C-1F
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
ends
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
struct device ETH_DEVICE
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
io_addr dd ?
|
|
|
|
pci_bus dd ?
|
|
|
|
pci_dev dd ?
|
|
|
|
irq_line db ?
|
|
|
|
rb 3 ; align 4
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
cur_rx dw ?
|
|
|
|
cur_tx dw ?
|
|
|
|
last_tx dw ?
|
|
|
|
phy_addr dd ?
|
|
|
|
phy_mode dw ?
|
|
|
|
mcr0 dw ?
|
|
|
|
mcr1 dw ?
|
|
|
|
switch_sig dw ?
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
rb 0x100 - ($ and 0xff) ; align 256
|
|
|
|
tx_ring rb ((TX_RING_SIZE*sizeof.x_head+32) and 0xfffffff0)
|
|
|
|
rx_ring rb ((RX_RING_SIZE*sizeof.x_head+32) and 0xfffffff0)
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
ends
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc START ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
proc START c, reason:dword, cmdline:dword
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
cmp [reason], DRV_ENTRY
|
|
|
|
jne .fail
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-07-18 13:43:53 +04:00
|
|
|
DEBUGF 2,"Loading driver\n"
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke RegService, my_service, service_proc
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
2014-02-26 15:40:04 +04:00
|
|
|
xor eax, eax
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc SERVICE_PROC ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
|
|
|
|
|
|
|
mov edx, [ioctl]
|
2014-01-17 19:07:07 +04:00
|
|
|
mov eax, [edx + IOCTL.io_code]
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
|
|
|
|
cmp eax, 0 ;SRV_GETVERSION
|
|
|
|
jne @F
|
|
|
|
|
2014-01-17 19:07:07 +04:00
|
|
|
cmp [edx + IOCTL.out_size], 4
|
2013-05-28 21:34:26 +04:00
|
|
|
jb .fail
|
2014-01-17 19:07:07 +04:00
|
|
|
mov eax, [edx + IOCTL.output]
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [eax], dword API_VERSION
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
@@:
|
|
|
|
cmp eax, 1 ;SRV_HOOK
|
|
|
|
jne .fail
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes
|
2013-05-28 21:34:26 +04:00
|
|
|
jb .fail
|
|
|
|
|
2014-01-17 19:07:07 +04:00
|
|
|
mov eax, [edx + IOCTL.input]
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given
|
|
|
|
jne .fail ; other types arent supported for this card yet
|
|
|
|
|
|
|
|
; check if the device is already listed
|
|
|
|
|
|
|
|
mov esi, device_list
|
|
|
|
mov ecx, [devices]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .firstdevice
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers
|
2013-05-28 21:34:26 +04:00
|
|
|
mov ax , [eax+1] ;
|
|
|
|
.nextdevice:
|
|
|
|
mov ebx, [esi]
|
2014-02-26 15:40:04 +04:00
|
|
|
cmp al, byte[ebx + device.pci_bus]
|
2013-05-28 21:34:26 +04:00
|
|
|
jne @f
|
2014-02-26 15:40:04 +04:00
|
|
|
cmp ah, byte[ebx + device.pci_dev]
|
2013-05-28 21:34:26 +04:00
|
|
|
je .find_devicenum ; Device is already loaded, let's find it's device number
|
|
|
|
@@:
|
|
|
|
add esi, 4
|
|
|
|
loop .nextdevice
|
|
|
|
|
|
|
|
|
|
|
|
; This device doesnt have its own eth_device structure yet, lets create one
|
|
|
|
.firstdevice:
|
|
|
|
cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card
|
|
|
|
jae .fail
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
allocate_and_clear ebx, sizeof.device, .fail ; Allocate the buffer for device structure
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Fill in the direct call addresses into the struct
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.reset], reset
|
|
|
|
mov [ebx + device.transmit], transmit
|
|
|
|
mov [ebx + device.unload], unload
|
|
|
|
mov [ebx + device.name], my_service
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; save the pci bus and device numbers
|
|
|
|
|
2014-01-17 19:07:07 +04:00
|
|
|
mov eax, [edx + IOCTL.input]
|
2013-05-28 21:34:26 +04:00
|
|
|
movzx ecx, byte[eax+1]
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.pci_bus], ecx
|
2013-05-28 21:34:26 +04:00
|
|
|
movzx ecx, byte[eax+2]
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.pci_dev], ecx
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Now, it's time to find the base io addres of the PCI device
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
|
|
|
|
mov [ebx + device.io_addr], eax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; We've found the io address, find IRQ now
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
|
|
|
|
mov [ebx + device.irq_line], al
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
|
2014-02-26 15:40:04 +04:00
|
|
|
[ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:8
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Ok, the eth_device structure is ready, let's probe the device
|
|
|
|
|
|
|
|
mov eax, [devices] ; Add the device structure to our device list
|
|
|
|
mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device)
|
|
|
|
inc [devices] ;
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
call probe ; this function will output in eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .err2
|
|
|
|
|
2014-07-18 13:43:53 +04:00
|
|
|
DEBUGF 2,"Initialised OK\n"
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.type], NET_TYPE_ETH
|
|
|
|
invoke NetRegDev
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
cmp eax, -1
|
|
|
|
je .destroy
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
; If the device was already loaded, find the device number and return it in eax
|
|
|
|
|
|
|
|
.find_devicenum:
|
2014-02-26 15:40:04 +04:00
|
|
|
DEBUGF 2,"Trying to find device number of already registered device\n"
|
|
|
|
invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx
|
2013-05-28 21:34:26 +04:00
|
|
|
; into a device number in edi
|
|
|
|
mov eax, edi ; Application wants it in eax instead
|
2014-02-26 15:40:04 +04:00
|
|
|
DEBUGF 2,"Kernel says: %u\n", eax
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
; If an error occured, remove all allocated data and exit (returning -1 in eax)
|
|
|
|
|
|
|
|
.destroy:
|
|
|
|
; todo: reset device into virgin state
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
.err2:
|
|
|
|
dec [devices]
|
2013-05-28 21:34:26 +04:00
|
|
|
.err:
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke KernelFree, ebx
|
2013-05-28 21:34:26 +04:00
|
|
|
.fail:
|
2014-02-26 15:40:04 +04:00
|
|
|
DEBUGF 2, "Failed to load\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
|
|
|
|
;; ;;
|
|
|
|
;; Actual Hardware dependent code starts here ;;
|
|
|
|
;; ;;
|
|
|
|
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
|
|
|
|
|
|
|
|
|
2014-01-14 18:14:31 +04:00
|
|
|
;mdio_read:
|
2014-02-26 15:40:04 +04:00
|
|
|
; stdcall phy_read, [ebx + device.io_addr], [ebx + device.phy_addr], ecx
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-01-14 18:14:31 +04:00
|
|
|
; ret
|
|
|
|
|
|
|
|
;mdio_write:
|
2014-02-26 15:40:04 +04:00
|
|
|
; stdcall phy_write, [ebx + device.io_addr], [ebx + device.phy_addr], ecx, eax
|
2014-01-14 18:14:31 +04:00
|
|
|
|
|
|
|
; ret
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
unload:
|
|
|
|
; TODO: (in this particular order)
|
|
|
|
;
|
|
|
|
; - Stop the device
|
|
|
|
; - Detach int handler
|
2015-03-18 00:50:29 +03:00
|
|
|
; - Remove device from local list (device_list)
|
2013-05-28 21:34:26 +04:00
|
|
|
; - call unregister function in kernel
|
|
|
|
; - Remove all allocated structures and buffers the card used
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
2014-01-14 18:14:31 +04:00
|
|
|
;; probe: enables the device (if it really is R6040)
|
2013-05-28 21:34:26 +04:00
|
|
|
;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
align 4
|
|
|
|
probe:
|
2014-02-26 15:40:04 +04:00
|
|
|
DEBUGF 1,"Probing\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
; Make the device a bus master
|
|
|
|
invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
|
|
|
|
or al, PCI_CMD_MASTER
|
|
|
|
invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; If PHY status change register is still set to zero
|
|
|
|
; it means the bootloader didn't initialize it
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], PHY_CC
|
2013-05-28 21:34:26 +04:00
|
|
|
in ax, dx
|
|
|
|
test ax, ax
|
|
|
|
jnz @f
|
|
|
|
mov ax, 0x9F07
|
|
|
|
out dx, ax
|
2015-03-18 00:50:29 +03:00
|
|
|
@@:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
call read_mac
|
|
|
|
|
|
|
|
; Some bootloaders/BIOSes do not initialize MAC address, warn about that
|
|
|
|
and eax, 0xFF
|
2014-02-26 15:40:04 +04:00
|
|
|
or eax, dword [ebx + device.mac]
|
2013-05-28 21:34:26 +04:00
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 2, "MAC address not initialized!\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
@@:
|
2013-05-28 21:34:26 +04:00
|
|
|
; Init RDC private data
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.mcr0], MCR0_XMTEN or MCR0_RCVEN
|
|
|
|
mov [ebx + device.phy_addr], PHY1_ADDR
|
|
|
|
mov [ebx + device.switch_sig], 0
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Check the vendor ID on the PHY, if 0xFFFF assume none attached
|
2014-02-26 15:40:04 +04:00
|
|
|
stdcall phy_read, [ebx + device.phy_addr], 2
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp ax, 0xFFFF
|
|
|
|
jne @f
|
2014-01-14 18:14:31 +04:00
|
|
|
DEBUGF 2, "Failed to detect an attached PHY!\n"
|
2015-03-18 00:50:29 +03:00
|
|
|
.err:
|
2013-05-28 21:34:26 +04:00
|
|
|
mov eax, -1
|
|
|
|
ret
|
2015-03-18 00:50:29 +03:00
|
|
|
@@:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Set MAC address
|
|
|
|
call init_mac_regs
|
|
|
|
|
|
|
|
; Initialize and alloc RX/TX buffers
|
|
|
|
call init_txbufs
|
|
|
|
call init_rxbufs
|
2015-03-18 00:50:29 +03:00
|
|
|
test eax, eax
|
|
|
|
jnz .err
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Read the PHY ID
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.phy_mode], MCR0_FD
|
2013-05-28 21:34:26 +04:00
|
|
|
stdcall phy_read, 0, 2
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.switch_sig], ax
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp ax, ICPLUS_PHY_ID
|
|
|
|
jne @f
|
|
|
|
stdcall phy_write, 29, 31, 0x175C ; Enable registers
|
|
|
|
jmp .phy_readen
|
2015-03-18 00:50:29 +03:00
|
|
|
@@:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; PHY Mode Check
|
2014-02-26 15:40:04 +04:00
|
|
|
stdcall phy_write, [ebx + device.phy_addr], 4, PHY_CAP
|
|
|
|
stdcall phy_write, [ebx + device.phy_addr], 0, PHY_MODE
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
if PHY_MODE = 0x3100
|
|
|
|
call phy_mode_chk
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.phy_mode], ax
|
2013-05-28 21:34:26 +04:00
|
|
|
jmp .phy_readen
|
|
|
|
end if
|
|
|
|
|
|
|
|
if not (PHY_MODE and 0x0100)
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.phy_mode], 0
|
2013-05-28 21:34:26 +04:00
|
|
|
end if
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
.phy_readen:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Set duplex mode
|
2014-02-26 15:40:04 +04:00
|
|
|
mov ax, [ebx + device.phy_mode]
|
|
|
|
or [ebx + device.mcr0], ax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; improve performance (by RDC guys)
|
|
|
|
stdcall phy_read, 30, 17
|
|
|
|
or ax, 0x4000
|
|
|
|
stdcall phy_write, 30, 17, eax
|
|
|
|
|
|
|
|
stdcall phy_read, 30, 17
|
|
|
|
and ax, not 0x2000
|
|
|
|
stdcall phy_write, 30, 17, eax
|
|
|
|
|
|
|
|
stdcall phy_write, 0, 19, 0x0000
|
|
|
|
stdcall phy_write, 0, 30, 0x01F0
|
|
|
|
|
|
|
|
; Initialize all Mac registers
|
|
|
|
call init_mac_regs
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
reset:
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
DEBUGF 1,"Resetting\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Mask off Interrupt
|
|
|
|
xor ax, ax
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MIER
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
; attach int handler
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
movzx eax, [ebx + device.irq_line]
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"Attaching int handler to irq %x\n", eax:1
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke AttachIntHandler, eax, int_handler, ebx
|
2013-05-28 21:34:26 +04:00
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 2,"Could not attach int handler!\n"
|
2014-02-26 15:40:04 +04:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2015-03-18 00:50:29 +03:00
|
|
|
@@:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
;Reset RDC MAC
|
|
|
|
mov eax, MAC_RST
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MCR1
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
mov ecx, 2048 ;limit
|
|
|
|
.read:
|
|
|
|
in ax, dx
|
|
|
|
test ax, 0x1
|
|
|
|
jnz @f
|
|
|
|
dec ecx
|
|
|
|
test ecx, ecx
|
|
|
|
jnz .read
|
|
|
|
@@:
|
|
|
|
;Reset internal state machine
|
|
|
|
mov ax, 2
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MAC_SM
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
xor ax, ax
|
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
mov esi, 5
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke Sleep
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
;MAC Bus Control Register
|
|
|
|
mov ax, MBCR_DEFAULT
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MBCR
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Buffer Size Register
|
|
|
|
mov ax, MAX_BUF_SIZE
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MR_BSR
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Write TX ring start address
|
2014-02-26 15:40:04 +04:00
|
|
|
lea eax, [ebx + device.tx_ring]
|
|
|
|
invoke GetPhysAddr
|
|
|
|
set_io [ebx + device.io_addr], MTD_SA0
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
shr eax, 16
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MTD_SA1
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Write RX ring start address
|
2014-02-26 15:40:04 +04:00
|
|
|
lea eax, [ebx + device.rx_ring]
|
|
|
|
invoke GetPhysAddr
|
|
|
|
set_io [ebx + device.io_addr], MRD_SA0
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
shr eax, 16
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MRD_SA1
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Set interrupt waiting time and packet numbers
|
|
|
|
xor ax, ax
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MT_ICR
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Enable interrupts
|
|
|
|
mov ax, INT_MASK
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MIER
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
;Enable RX
|
2014-02-26 15:40:04 +04:00
|
|
|
mov ax, [ebx + device.mcr0]
|
2014-01-11 00:33:38 +04:00
|
|
|
or ax, MCR0_RCVEN
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Let TX poll the descriptors
|
2014-02-26 15:40:04 +04:00
|
|
|
;we may got called by tx_timeout which has left some unset tx buffers
|
2013-05-28 21:34:26 +04:00
|
|
|
xor ax, ax
|
|
|
|
inc ax
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MTPR
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
; Set the mtu, kernel will be able to send now
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.mtu], 1514
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Set link state to unknown
|
2014-02-26 15:40:04 +04:00
|
|
|
mov [ebx + device.state], ETH_LINK_UNKNOWN
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
DEBUGF 1,"Reset ok\n"
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
init_txbufs:
|
|
|
|
|
|
|
|
DEBUGF 1,"Init TxBufs\n"
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
lea esi, [ebx + device.tx_ring]
|
|
|
|
lea eax, [ebx + device.tx_ring + sizeof.x_head]
|
|
|
|
invoke GetPhysAddr
|
2013-05-28 21:34:26 +04:00
|
|
|
mov ecx, TX_RING_SIZE
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
.next_desc:
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [esi + x_head.ndesc], eax
|
|
|
|
mov [esi + x_head.skb_ptr], 0
|
|
|
|
mov [esi + x_head.status], DSC_OWNER_MAC
|
2014-02-26 15:40:04 +04:00
|
|
|
add eax, sizeof.x_head
|
|
|
|
add esi, sizeof.x_head
|
2013-05-28 21:34:26 +04:00
|
|
|
dec ecx
|
|
|
|
jnz .next_desc
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
lea eax, [ebx + device.tx_ring]
|
|
|
|
invoke GetPhysAddr
|
|
|
|
mov dword[ebx + device.tx_ring + sizeof.x_head*(TX_RING_SIZE-1) + x_head.ndesc], eax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
init_rxbufs:
|
|
|
|
|
|
|
|
DEBUGF 1,"Init RxBufs\n"
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
lea esi, [ebx + device.rx_ring]
|
|
|
|
lea eax, [ebx + device.rx_ring + sizeof.x_head]
|
|
|
|
invoke GetPhysAddr
|
2013-05-28 21:34:26 +04:00
|
|
|
mov edx, eax
|
|
|
|
mov ecx, RX_RING_SIZE
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
.next_desc:
|
2014-01-11 00:33:38 +04:00
|
|
|
mov [esi + x_head.ndesc], edx
|
|
|
|
push esi ecx edx
|
2015-03-18 00:50:29 +03:00
|
|
|
invoke NetAlloc, MAX_BUF_SIZE+NET_BUFF.data
|
2014-01-11 00:33:38 +04:00
|
|
|
pop edx ecx esi
|
2015-03-18 00:50:29 +03:00
|
|
|
test eax, eax
|
|
|
|
jz .out_of_mem
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [esi + x_head.skb_ptr], eax
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke GetPhysAddr
|
2015-03-18 00:50:29 +03:00
|
|
|
add eax, NET_BUFF.data
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [esi + x_head.buf], eax
|
|
|
|
mov [esi + x_head.status], DSC_OWNER_MAC
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
add edx, sizeof.x_head
|
|
|
|
add esi, sizeof.x_head
|
2013-05-28 21:34:26 +04:00
|
|
|
dec ecx
|
|
|
|
jnz .next_desc
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
; complete the ring by linking the last to the first
|
2014-02-26 15:40:04 +04:00
|
|
|
lea eax, [ebx + device.rx_ring]
|
|
|
|
invoke GetPhysAddr
|
|
|
|
mov dword[ebx + device.rx_ring + sizeof.x_head*(RX_RING_SIZE-1) + x_head.ndesc], eax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.out_of_mem:
|
|
|
|
or eax, -1
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
phy_mode_chk:
|
|
|
|
|
|
|
|
DEBUGF 1,"Checking PHY mode\n"
|
|
|
|
|
|
|
|
; PHY Link Status Check
|
2014-02-26 15:40:04 +04:00
|
|
|
stdcall phy_read, [ebx + device.phy_addr], MII_BMSR
|
2014-01-14 18:14:31 +04:00
|
|
|
test ax, BMSR_LSTATUS
|
2013-05-28 21:34:26 +04:00
|
|
|
jz .ret_0x8000
|
|
|
|
|
|
|
|
; PHY Chip Auto-Negotiation Status
|
2014-01-14 18:14:31 +04:00
|
|
|
test ax, BMSR_ANEGCOMPLETE
|
2013-05-28 21:34:26 +04:00
|
|
|
jnz .auto_nego
|
|
|
|
|
|
|
|
; Force Mode
|
2014-02-26 15:40:04 +04:00
|
|
|
stdcall phy_read, [ebx + device.phy_addr], MII_BMCR
|
2014-01-14 18:14:31 +04:00
|
|
|
test ax, BMCR_FULLDPLX
|
2013-05-28 21:34:26 +04:00
|
|
|
jnz .ret_0x8000
|
|
|
|
|
|
|
|
.auto_nego:
|
|
|
|
; Auto Negotiation Mode
|
2014-02-26 15:40:04 +04:00
|
|
|
stdcall phy_read, [ebx + device.phy_addr], MII_LPA
|
2014-01-14 18:14:31 +04:00
|
|
|
mov cx, ax
|
2014-02-26 15:40:04 +04:00
|
|
|
stdcall phy_read, [ebx + device.phy_addr], MII_ADVERTISE
|
2014-01-14 18:14:31 +04:00
|
|
|
and ax, cx
|
|
|
|
test ax, ADVERTISE_10FULL + ADVERTISE_100FULL
|
2013-05-28 21:34:26 +04:00
|
|
|
jnz .ret_0x8000
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.ret_0x8000:
|
|
|
|
mov eax, 0x8000
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Transmit ;;
|
|
|
|
;; ;;
|
2014-02-26 15:40:04 +04:00
|
|
|
;; In: pointer to device structure in ebx ;;
|
2013-05-28 21:34:26 +04:00
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2014-02-26 15:40:04 +04:00
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
proc transmit stdcall bufferptr
|
2014-02-26 15:40:04 +04:00
|
|
|
|
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
mov esi, [bufferptr]
|
|
|
|
DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
|
|
|
|
lea eax, [esi + NET_BUFF.data]
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
|
2013-05-28 21:34:26 +04:00
|
|
|
[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
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
cmp [esi + NET_BUFF.length], 1514
|
2013-05-28 21:34:26 +04:00
|
|
|
ja .fail
|
2015-03-18 00:50:29 +03:00
|
|
|
cmp [esi + NET_BUFF.length], 60
|
2013-05-28 21:34:26 +04:00
|
|
|
jb .fail
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
movzx edi, [ebx + device.cur_tx]
|
2013-05-28 21:34:26 +04:00
|
|
|
shl edi, 5
|
|
|
|
add edi, ebx
|
2014-02-26 15:40:04 +04:00
|
|
|
add edi, device.tx_ring
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"TX buffer status: 0x%x\n", [edi + x_head.status]:4
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
test [edi + x_head.status], DSC_OWNER_MAC ; check if buffer is available
|
|
|
|
jnz .wait_to_send
|
|
|
|
|
|
|
|
.do_send:
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"Sending now\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
mov [edi + x_head.skb_ptr], esi
|
|
|
|
mov eax, esi
|
|
|
|
add eax, [eax + NET_BUFF.offset]
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke GetPhysAddr
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [edi + x_head.buf], eax
|
2015-03-18 00:50:29 +03:00
|
|
|
mov ecx, [esi + NET_BUFF.length]
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [edi + x_head.len], cx
|
|
|
|
mov [edi + x_head.status], DSC_OWNER_MAC
|
|
|
|
|
|
|
|
; Trigger the MAC to check the TX descriptor
|
|
|
|
mov ax, 0x01
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MTPR
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
inc [ebx + device.cur_tx]
|
|
|
|
and [ebx + device.cur_tx], TX_RING_SIZE - 1
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Update stats
|
2014-02-26 15:40:04 +04:00
|
|
|
inc [ebx + device.packets_tx]
|
2015-03-18 00:50:29 +03:00
|
|
|
mov eax, [esi + NET_BUFF.length]
|
2014-02-26 15:40:04 +04:00
|
|
|
add dword[ebx + device.bytes_tx], eax
|
|
|
|
adc dword[ebx + device.bytes_tx + 4], 0
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
popf
|
2014-09-15 15:28:35 +04:00
|
|
|
xor eax, eax
|
2014-02-26 15:40:04 +04:00
|
|
|
ret
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
.wait_to_send:
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"Waiting for TX buffer\n"
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke GetTimerTicks ; returns in eax
|
2013-05-28 21:34:26 +04:00
|
|
|
lea edx, [eax + 100]
|
2015-03-18 00:50:29 +03:00
|
|
|
.l2:
|
|
|
|
mov esi, [bufferptr]
|
2013-05-28 21:34:26 +04:00
|
|
|
test [edi + x_head.status], DSC_OWNER_MAC
|
|
|
|
jz .do_send
|
2015-03-18 00:50:29 +03:00
|
|
|
popf
|
2013-05-28 21:34:26 +04:00
|
|
|
mov esi, 10
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke Sleep
|
|
|
|
invoke GetTimerTicks
|
2015-03-18 00:50:29 +03:00
|
|
|
pushf
|
|
|
|
cli
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp edx, eax
|
|
|
|
jb .l2
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 2,"Send timeout\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
.fail:
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 2,"Send failed\n"
|
2015-03-18 00:50:29 +03:00
|
|
|
invoke NetFree, [bufferptr]
|
2014-02-26 15:40:04 +04:00
|
|
|
popf
|
2013-12-08 18:34:08 +04:00
|
|
|
or eax, -1
|
2014-02-26 15:40:04 +04:00
|
|
|
ret
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
endp
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Interrupt handler ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
align 4
|
|
|
|
int_handler:
|
|
|
|
|
|
|
|
push ebx esi edi
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"int\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Find pointer of device wich made IRQ occur
|
|
|
|
|
|
|
|
mov ecx, [devices]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .nothing
|
|
|
|
mov esi, device_list
|
|
|
|
.nextdevice:
|
|
|
|
mov ebx, [esi]
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MISR
|
2013-05-28 21:34:26 +04:00
|
|
|
in ax, dx
|
|
|
|
out dx, ax ; send it back to ACK
|
|
|
|
test ax, ax
|
|
|
|
jnz .got_it
|
|
|
|
.continue:
|
|
|
|
add esi, 4
|
|
|
|
dec ecx
|
|
|
|
jnz .nextdevice
|
|
|
|
.nothing:
|
|
|
|
pop edi esi ebx
|
|
|
|
xor eax, eax
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
ret ; If no device was found, abort
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; At this point, test for all possible reasons, and handle accordingly
|
|
|
|
|
|
|
|
.got_it:
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"Device: %x Status: %x\n", ebx, ax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
push ax
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
test word[esp], RX_FINISH
|
2013-05-28 21:34:26 +04:00
|
|
|
jz .no_RX
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
.more_RX:
|
|
|
|
pop ebx
|
|
|
|
|
|
|
|
; Find the current RX descriptor
|
2014-02-26 15:40:04 +04:00
|
|
|
movzx edx, [ebx + device.cur_rx]
|
2013-05-28 21:34:26 +04:00
|
|
|
shl edx, 5
|
2014-02-26 15:40:04 +04:00
|
|
|
lea edx, [ebx + device.rx_ring + edx]
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; Check the descriptor status
|
|
|
|
mov cx, [edx + x_head.status]
|
|
|
|
test cx, DSC_OWNER_MAC
|
|
|
|
jnz .no_RX
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"packet status=0x%x\n", cx
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
DEBUGF 1,"packet ptr=0x%x size=%u\n", [edx + x_head.skb_ptr], ecx
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
; Update stats
|
2014-02-26 15:40:04 +04:00
|
|
|
add dword[ebx + device.bytes_rx], ecx
|
|
|
|
adc dword[ebx + device.bytes_rx + 4], 0
|
|
|
|
inc dword[ebx + device.packets_rx]
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
push ebx
|
2015-03-18 00:50:29 +03:00
|
|
|
; Push packet ptr and return addr for Eth_input
|
2013-05-28 21:34:26 +04:00
|
|
|
push .more_RX
|
2015-03-18 00:50:29 +03:00
|
|
|
mov eax, [edx + x_head.skb_ptr]
|
|
|
|
push eax
|
|
|
|
mov [eax + NET_BUFF.length], ecx
|
|
|
|
mov [eax + NET_BUFF.device], ebx
|
|
|
|
mov [eax + NET_BUFF.offset], NET_BUFF.data
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
; reset the RX descriptor (alloc new buffer)
|
2013-05-28 21:34:26 +04:00
|
|
|
push edx
|
2015-03-18 00:50:29 +03:00
|
|
|
invoke NetAlloc, MAX_BUF_SIZE+NET_BUFF.data
|
2013-05-28 21:34:26 +04:00
|
|
|
pop edx
|
|
|
|
mov [edx + x_head.skb_ptr], eax
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke GetPhysAddr
|
2015-03-18 00:50:29 +03:00
|
|
|
add eax, NET_BUFF.data
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [edx + x_head.buf], eax
|
|
|
|
mov [edx + x_head.status], DSC_OWNER_MAC
|
|
|
|
|
|
|
|
; Use next descriptor next time
|
2014-02-26 15:40:04 +04:00
|
|
|
inc [ebx + device.cur_rx]
|
|
|
|
and [ebx + device.cur_rx], RX_RING_SIZE - 1
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; At last, send packet to kernel
|
2015-03-18 00:50:29 +03:00
|
|
|
jmp [EthInput]
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
.no_RX:
|
2014-01-11 00:33:38 +04:00
|
|
|
test word[esp], TX_FINISH
|
2013-05-28 21:34:26 +04:00
|
|
|
jz .no_TX
|
|
|
|
|
2015-03-18 00:50:29 +03:00
|
|
|
.loop_tx:
|
2014-02-26 15:40:04 +04:00
|
|
|
movzx edi, [ebx + device.last_tx]
|
2013-05-28 21:34:26 +04:00
|
|
|
shl edi, 5
|
2014-02-26 15:40:04 +04:00
|
|
|
lea edi, [ebx + device.tx_ring + edi]
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
test [edi + x_head.status], DSC_OWNER_MAC
|
|
|
|
jnz .no_TX
|
|
|
|
|
|
|
|
cmp [edi + x_head.skb_ptr], 0
|
|
|
|
je .no_TX
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"Freeing buffer 0x%x\n", [edi + x_head.skb_ptr]
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
push [edi + x_head.skb_ptr]
|
|
|
|
mov [edi + x_head.skb_ptr], 0
|
2015-03-18 00:50:29 +03:00
|
|
|
invoke NetFree
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
inc [ebx + device.last_tx]
|
|
|
|
and [ebx + device.last_tx], TX_RING_SIZE - 1
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
jmp .loop_tx
|
|
|
|
|
|
|
|
.no_TX:
|
2014-01-11 00:33:38 +04:00
|
|
|
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
|
|
|
|
|
2014-01-14 18:14:31 +04:00
|
|
|
DEBUGF 2, "RX early\n"
|
2014-01-11 00:33:38 +04:00
|
|
|
|
|
|
|
.no_rxearly:
|
|
|
|
test word[esp], TX_EARLY
|
|
|
|
jz .no_txearly
|
|
|
|
|
2014-01-14 18:14:31 +04:00
|
|
|
DEBUGF 2, "TX early\n"
|
2014-01-11 00:33:38 +04:00
|
|
|
|
|
|
|
.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
|
|
|
|
|
2014-01-14 18:14:31 +04:00
|
|
|
DEBUGF 2, "Link changed\n"
|
2014-01-11 00:33:38 +04:00
|
|
|
|
|
|
|
.no_link:
|
2013-05-28 21:34:26 +04:00
|
|
|
pop ax
|
|
|
|
|
|
|
|
pop edi esi ebx
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
init_mac_regs:
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"initializing MAC regs\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
; MAC operation register
|
|
|
|
mov ax, 1
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MCR1
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
; Reset MAC
|
|
|
|
mov ax, 2
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MAC_SM
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
; Reset internal state machine
|
|
|
|
xor ax, ax
|
|
|
|
out dx, ax
|
|
|
|
mov esi, 5
|
2014-02-26 15:40:04 +04:00
|
|
|
invoke Sleep
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
call read_mac
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Read a word data from PHY Chip
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc phy_read stdcall, phy_addr:dword, reg:dword
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"PHY read, addr=0x%x reg=0x%x\n", [phy_addr]:8, [reg]:8
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
mov eax, [phy_addr]
|
|
|
|
shl eax, 8
|
|
|
|
add eax, [reg]
|
|
|
|
add eax, MDIO_READ
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MMDIO
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Wait for the read bit to be cleared.
|
|
|
|
mov ecx, 2048 ;limit
|
|
|
|
.read:
|
|
|
|
in ax, dx
|
|
|
|
test ax, MDIO_READ
|
|
|
|
jz @f
|
|
|
|
dec ecx
|
|
|
|
jnz .read
|
|
|
|
@@:
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MMRD
|
2013-05-28 21:34:26 +04:00
|
|
|
in ax, dx
|
|
|
|
and eax, 0xFFFF
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"PHY read, val=0x%x\n", eax:4
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Write a word data to PHY Chip
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc phy_write stdcall, phy_addr:dword, reg:dword, val:dword
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
DEBUGF 1,"PHY write, addr=0x%x reg=0x%x val=0x%x\n", \
|
|
|
|
[phy_addr]:8, [reg]:8, [val]:8
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
mov eax, [val]
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MMWD
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Write the command to the MDIO bus
|
|
|
|
mov eax, [phy_addr]
|
|
|
|
shl eax, 8
|
|
|
|
add eax, [reg]
|
|
|
|
add eax, MDIO_WRITE
|
2014-02-26 15:40:04 +04:00
|
|
|
set_io [ebx + device.io_addr], MMDIO
|
2013-05-28 21:34:26 +04:00
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
;Wait for the write bit to be cleared.
|
|
|
|
mov ecx, 2048 ;limit
|
|
|
|
.write:
|
|
|
|
in ax, dx
|
|
|
|
test ax, MDIO_WRITE
|
|
|
|
jz @f
|
|
|
|
dec ecx
|
|
|
|
jnz .write
|
|
|
|
@@:
|
|
|
|
|
2014-01-11 00:33:38 +04:00
|
|
|
DEBUGF 1,"PHY write ok\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
read_mac:
|
|
|
|
|
2014-01-14 18:14:31 +04:00
|
|
|
DEBUGF 1,"Reading MAC:\n"
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
mov cx, 3
|
2014-02-26 15:40:04 +04:00
|
|
|
lea edi, [ebx + device.mac]
|
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MID_0L
|
2015-03-18 00:50:29 +03:00
|
|
|
.loop:
|
2013-05-28 21:34:26 +04:00
|
|
|
in ax, dx
|
|
|
|
stosw
|
|
|
|
inc dx
|
|
|
|
inc dx
|
|
|
|
dec cx
|
2015-03-18 00:50:29 +03:00
|
|
|
jnz .loop
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
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
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; End of code
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
data fixups
|
|
|
|
end data
|
|
|
|
|
|
|
|
include '../peimport.inc'
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
my_service db 'R6040',0 ; max 16 chars include zero
|
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
include_debug_strings
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2014-02-26 15:40:04 +04:00
|
|
|
align 4
|
|
|
|
devices dd 0
|
2013-05-28 21:34:26 +04:00
|
|
|
device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling
|
|
|
|
|