2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-05-30 01:50:06 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; RTL8169 driver for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright 2007 mike.dld, ;;
|
|
|
|
;; mike.dld@gmail.com ;;
|
|
|
|
;; ;;
|
2016-02-01 19:21:55 +01:00
|
|
|
;; Port to the new network stack by hidnplayr ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; ;;
|
|
|
|
;; References: ;;
|
2016-02-01 21:32:42 +01:00
|
|
|
;; r8169.c - linux driver ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
format PE DLL native
|
|
|
|
entry START
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
CURRENT_API = 0x0200
|
|
|
|
COMPATIBLE_API = 0x0100
|
|
|
|
API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-07-04 19:43:16 +02:00
|
|
|
; configureable area
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-07-04 19:43:16 +02:00
|
|
|
MAX_DEVICES = 16 ; Maximum number of devices this driver may handle
|
|
|
|
|
|
|
|
__DEBUG__ = 1 ; 1 = on, 0 = off
|
2014-08-21 23:10:40 +02:00
|
|
|
__DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-07-04 19:43:16 +02:00
|
|
|
NUM_TX_DESC = 32 ; Number of packets in send ring buffer
|
|
|
|
NUM_RX_DESC = 32 ; Number of packets in receive ring buffer
|
|
|
|
|
|
|
|
; end configureable area
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
section '.flat' readable writable executable
|
|
|
|
|
|
|
|
include '../proc32.inc'
|
2014-01-17 13:51:32 +01:00
|
|
|
include '../struct.inc'
|
|
|
|
include '../macros.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
include '../fdo.inc'
|
2014-08-31 16:09:14 +02:00
|
|
|
include '../netdrv.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-07-04 19:43:16 +02:00
|
|
|
if (bsr NUM_TX_DESC)>(bsf NUM_TX_DESC)
|
|
|
|
display 'NUM_TX_DESC must be a power of two'
|
|
|
|
err
|
|
|
|
end if
|
|
|
|
|
|
|
|
if (bsr NUM_RX_DESC)>(bsf NUM_RX_DESC)
|
|
|
|
display 'NUM_RX_DESC must be a power of two'
|
|
|
|
err
|
|
|
|
end if
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
REG_MAC0 = 0x0 ; Ethernet hardware address
|
|
|
|
REG_MAR0 = 0x8 ; Multicast filter
|
|
|
|
REG_TxDescStartAddr = 0x20
|
|
|
|
REG_TxHDescStartAddr = 0x28
|
|
|
|
REG_FLASH = 0x30
|
|
|
|
REG_ERSR = 0x36
|
|
|
|
REG_ChipCmd = 0x37
|
|
|
|
REG_TxPoll = 0x38
|
|
|
|
REG_IntrMask = 0x3C
|
|
|
|
REG_IntrStatus = 0x3E
|
|
|
|
REG_TxConfig = 0x40
|
|
|
|
REG_RxConfig = 0x44
|
|
|
|
REG_RxMissed = 0x4C
|
|
|
|
REG_Cfg9346 = 0x50
|
|
|
|
REG_Config0 = 0x51
|
|
|
|
REG_Config1 = 0x52
|
|
|
|
REG_Config2 = 0x53
|
|
|
|
REG_Config3 = 0x54
|
|
|
|
REG_Config4 = 0x55
|
|
|
|
REG_Config5 = 0x56
|
|
|
|
REG_MultiIntr = 0x5C
|
|
|
|
REG_PHYAR = 0x60
|
|
|
|
REG_TBICSR = 0x64
|
|
|
|
REG_TBI_ANAR = 0x68
|
|
|
|
REG_TBI_LPAR = 0x6A
|
|
|
|
REG_PHYstatus = 0x6C
|
|
|
|
REG_RxMaxSize = 0xDA
|
|
|
|
REG_CPlusCmd = 0xE0
|
|
|
|
REG_RxDescStartAddr = 0xE4
|
|
|
|
REG_ETThReg = 0xEC
|
|
|
|
REG_FuncEvent = 0xF0
|
|
|
|
REG_FuncEventMask = 0xF4
|
|
|
|
REG_FuncPresetState = 0xF8
|
|
|
|
REG_FuncForceEvent = 0xFC
|
|
|
|
|
|
|
|
; InterruptStatusBits
|
|
|
|
ISB_SYSErr = 0x8000
|
|
|
|
ISB_PCSTimeout = 0x4000
|
|
|
|
ISB_SWInt = 0x0100
|
|
|
|
ISB_TxDescUnavail = 0x80
|
|
|
|
ISB_RxFIFOOver = 0x40
|
|
|
|
ISB_LinkChg = 0x20
|
|
|
|
ISB_RxOverflow = 0x10
|
|
|
|
ISB_TxErr = 0x08
|
|
|
|
ISB_TxOK = 0x04
|
|
|
|
ISB_RxErr = 0x02
|
|
|
|
ISB_RxOK = 0x01
|
|
|
|
|
|
|
|
; RxStatusDesc
|
2021-07-04 19:43:16 +02:00
|
|
|
SD_RxBOVF = (1 shl 24)
|
|
|
|
SD_RxFOVF = (1 shl 23)
|
|
|
|
SD_RxRWT = (1 shl 22)
|
|
|
|
SD_RxRES = (1 shl 21)
|
|
|
|
SD_RxRUNT = (1 shl 20)
|
|
|
|
SD_RxCRC = (1 shl 19)
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; ChipCmdBits
|
|
|
|
CMD_Reset = 0x10
|
|
|
|
CMD_RxEnb = 0x08
|
|
|
|
CMD_TxEnb = 0x04
|
|
|
|
CMD_RxBufEmpty = 0x01
|
|
|
|
|
|
|
|
; Cfg9346Bits
|
|
|
|
CFG_9346_Lock = 0x00
|
|
|
|
CFG_9346_Unlock = 0xC0
|
|
|
|
|
|
|
|
; rx_mode_bits
|
|
|
|
RXM_AcceptErr = 0x20
|
|
|
|
RXM_AcceptRunt = 0x10
|
|
|
|
RXM_AcceptBroadcast = 0x08
|
|
|
|
RXM_AcceptMulticast = 0x04
|
|
|
|
RXM_AcceptMyPhys = 0x02
|
|
|
|
RXM_AcceptAllPhys = 0x01
|
|
|
|
|
|
|
|
; RxConfigBits
|
|
|
|
RXC_FIFOShift = 13
|
|
|
|
RXC_DMAShift = 8
|
|
|
|
|
|
|
|
; TxConfigBits
|
|
|
|
TXC_InterFrameGapShift = 24
|
|
|
|
TXC_DMAShift = 8 ; DMA burst value (0-7) is shift this many bits
|
|
|
|
|
|
|
|
; PHYstatus
|
|
|
|
PHYS_TBI_Enable = 0x80
|
|
|
|
PHYS_TxFlowCtrl = 0x40
|
|
|
|
PHYS_RxFlowCtrl = 0x20
|
|
|
|
PHYS_1000bpsF = 0x10
|
|
|
|
PHYS_100bps = 0x08
|
|
|
|
PHYS_10bps = 0x04
|
|
|
|
PHYS_LinkStatus = 0x02
|
|
|
|
PHYS_FullDup = 0x01
|
|
|
|
|
|
|
|
; GIGABIT_PHY_registers
|
|
|
|
PHY_CTRL_REG = 0
|
|
|
|
PHY_STAT_REG = 1
|
|
|
|
PHY_AUTO_NEGO_REG = 4
|
|
|
|
PHY_1000_CTRL_REG = 9
|
|
|
|
|
|
|
|
; GIGABIT_PHY_REG_BIT
|
|
|
|
PHY_Restart_Auto_Nego = 0x0200
|
|
|
|
PHY_Enable_Auto_Nego = 0x1000
|
|
|
|
|
|
|
|
; PHY_STAT_REG = 1
|
|
|
|
PHY_Auto_Neco_Comp = 0x0020
|
|
|
|
|
|
|
|
; PHY_AUTO_NEGO_REG = 4
|
|
|
|
PHY_Cap_10_Half = 0x0020
|
|
|
|
PHY_Cap_10_Full = 0x0040
|
|
|
|
PHY_Cap_100_Half = 0x0080
|
|
|
|
PHY_Cap_100_Full = 0x0100
|
|
|
|
|
|
|
|
; PHY_1000_CTRL_REG = 9
|
|
|
|
PHY_Cap_1000_Full = 0x0200
|
|
|
|
PHY_Cap_1000_Half = 0x0100
|
|
|
|
|
|
|
|
PHY_Cap_PAUSE = 0x0400
|
|
|
|
PHY_Cap_ASYM_PAUSE = 0x0800
|
|
|
|
|
|
|
|
PHY_Cap_Null = 0x0
|
|
|
|
|
|
|
|
; _MediaType
|
|
|
|
MT_10_Half = 0x01
|
|
|
|
MT_10_Full = 0x02
|
|
|
|
MT_100_Half = 0x04
|
|
|
|
MT_100_Full = 0x08
|
|
|
|
MT_1000_Full = 0x10
|
|
|
|
|
|
|
|
; _TBICSRBit
|
2015-06-02 00:06:51 +02:00
|
|
|
TBI_RESET = 0x80000000
|
|
|
|
TBI_LOOPBACK = 0x40000000
|
|
|
|
TBI_NW_ENABLE = 0x20000000
|
|
|
|
TBI_NW_RESTART = 0x10000000
|
|
|
|
TBI_LINK_OK = 0x02000000
|
|
|
|
TBI_NW_COMPLETE = 0x01000000
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; _DescStatusBit
|
|
|
|
DSB_OWNbit = 0x80000000
|
|
|
|
DSB_EORbit = 0x40000000
|
|
|
|
DSB_FSbit = 0x20000000
|
|
|
|
DSB_LSbit = 0x10000000
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
RX_BUF_SIZE = 1514 ; Rx Buffer size
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4)
|
2015-03-17 22:50:29 +01:00
|
|
|
MAX_ETH_FRAME_SIZE = 1514
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
TX_FIFO_THRESH = 256 ; In bytes
|
|
|
|
|
|
|
|
RX_FIFO_THRESH = 7 ; 7 means NO threshold, Rx buffer level before first PCI xfer
|
|
|
|
RX_DMA_BURST = 7 ; Maximum PCI burst, '6' is 1024
|
|
|
|
TX_DMA_BURST = 7 ; Maximum PCI burst, '6' is 1024
|
|
|
|
ETTh = 0x3F ; 0x3F means NO threshold
|
|
|
|
|
|
|
|
EarlyTxThld = 0x3F ; 0x3F means NO early transmit
|
|
|
|
RxPacketMaxSize = 0x0800 ; Maximum size supported is 16K-1
|
|
|
|
InterFrameGap = 0x03 ; 3 means InterFrameGap = the shortest one
|
|
|
|
|
|
|
|
HZ = 1000
|
|
|
|
|
|
|
|
RTL_MIN_IO_SIZE = 0x80
|
|
|
|
TX_TIMEOUT = (6*HZ)
|
|
|
|
|
|
|
|
TIMER_EXPIRE_TIME = 100
|
|
|
|
|
|
|
|
ETH_HDR_LEN = 14
|
|
|
|
DEFAULT_MTU = 1500
|
2015-03-17 22:50:29 +01:00
|
|
|
DEFAULT_RX_BUF_LEN = 1514
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
;ifdef JUMBO_FRAME_SUPPORT
|
|
|
|
; MAX_JUMBO_FRAME_MTU = 10000
|
|
|
|
; MAX_RX_SKBDATA_SIZE = (MAX_JUMBO_FRAME_MTU + ETH_HDR_LEN )
|
|
|
|
;else
|
|
|
|
MAX_RX_SKBDATA_SIZE = 1600
|
|
|
|
;end if
|
|
|
|
|
|
|
|
MCFG_METHOD_01 = 0x01
|
|
|
|
MCFG_METHOD_02 = 0x02
|
|
|
|
MCFG_METHOD_03 = 0x03
|
|
|
|
MCFG_METHOD_04 = 0x04
|
|
|
|
MCFG_METHOD_05 = 0x05
|
|
|
|
MCFG_METHOD_11 = 0x0b
|
|
|
|
MCFG_METHOD_12 = 0x0c
|
|
|
|
MCFG_METHOD_13 = 0x0d
|
|
|
|
MCFG_METHOD_14 = 0x0e
|
|
|
|
MCFG_METHOD_15 = 0x0f
|
|
|
|
|
|
|
|
PCFG_METHOD_1 = 0x01 ; PHY Reg 0x03 bit0-3 == 0x0000
|
|
|
|
PCFG_METHOD_2 = 0x02 ; PHY Reg 0x03 bit0-3 == 0x0001
|
|
|
|
PCFG_METHOD_3 = 0x03 ; PHY Reg 0x03 bit0-3 == 0x0002
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
struct tx_desc
|
|
|
|
status dd ?
|
|
|
|
vlan_tag dd ?
|
|
|
|
buf_addr dq ?
|
|
|
|
ends
|
|
|
|
tx_desc.buf_soft_addr = NUM_TX_DESC*sizeof.tx_desc
|
|
|
|
|
|
|
|
struct rx_desc
|
|
|
|
status dd ?
|
|
|
|
vlan_tag dd ?
|
|
|
|
buf_addr dq ?
|
|
|
|
ends
|
|
|
|
rx_desc.buf_soft_addr = NUM_RX_DESC*sizeof.rx_desc
|
|
|
|
|
|
|
|
struct device ETH_DEVICE
|
|
|
|
|
|
|
|
io_addr dd ?
|
|
|
|
pci_bus dd ?
|
|
|
|
pci_dev dd ?
|
|
|
|
irq_line db ?
|
|
|
|
rb 3 ; align 4
|
|
|
|
pcfg dd ?
|
|
|
|
mcfg dd ?
|
2015-03-05 21:04:52 +01:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
cur_rx dd ? ; Index into the Rx descriptor buffer of next Rx pkt
|
|
|
|
cur_tx dd ? ; Index into the Tx descriptor buffer of next Rx pkt
|
2015-03-05 21:04:52 +01:00
|
|
|
last_tx dd ?
|
2015-03-03 14:31:19 +01:00
|
|
|
mac_version dd ?
|
2014-08-21 23:10:40 +02:00
|
|
|
|
|
|
|
rb 0x100-($ and 0xff) ; align 256
|
|
|
|
tx_ring rb NUM_TX_DESC * sizeof.tx_desc * 2
|
|
|
|
|
|
|
|
rb 0x100-($ and 0xff) ; align 256
|
|
|
|
rx_ring rb NUM_RX_DESC * sizeof.rx_desc * 2
|
|
|
|
|
|
|
|
ends
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_TxOK or ISB_RxErr or ISB_RxOK
|
|
|
|
rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E
|
|
|
|
|
|
|
|
|
|
|
|
macro udelay msec {
|
|
|
|
|
2014-04-08 21:42:47 +02:00
|
|
|
push esi ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, msec
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke Sleep
|
2014-04-08 21:42:47 +02:00
|
|
|
pop ecx esi
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
macro WRITE_GMII_REG RegAddr, value {
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_PHYAR
|
2013-05-28 19:34:26 +02:00
|
|
|
if value eq ax
|
|
|
|
and eax, 0x0000ffff
|
|
|
|
or eax, 0x80000000 + (RegAddr shl 16)
|
|
|
|
else
|
|
|
|
mov eax, 0x80000000 + (RegAddr shl 16) + value
|
|
|
|
end if
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
call PHY_WAIT_WRITE
|
|
|
|
}
|
|
|
|
|
|
|
|
macro READ_GMII_REG RegAddr {
|
|
|
|
|
|
|
|
local .error, .done
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_PHYAR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov eax, RegAddr shl 16
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
call PHY_WAIT_READ
|
|
|
|
jz .error
|
|
|
|
|
|
|
|
in eax, dx
|
|
|
|
and eax, 0xFFFF
|
|
|
|
jmp .done
|
|
|
|
|
|
|
|
.error:
|
|
|
|
or eax, -1
|
|
|
|
.done:
|
|
|
|
}
|
|
|
|
|
|
|
|
align 4
|
|
|
|
PHY_WAIT_READ: ; io addr must already be set to REG_PHYAR
|
|
|
|
|
|
|
|
udelay 1 ;;;1000
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
mov ecx, 2000
|
|
|
|
; Check if the RTL8169 has completed writing/reading to the specified MII register
|
|
|
|
@@:
|
|
|
|
in eax, dx
|
|
|
|
test eax, 0x80000000
|
|
|
|
jnz .exit
|
|
|
|
udelay 1 ;;;100
|
|
|
|
loop @b
|
|
|
|
.exit:
|
|
|
|
pop ecx
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
PHY_WAIT_WRITE: ; io addr must already be set to REG_PHYAR
|
|
|
|
|
|
|
|
udelay 1 ;;;1000
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
mov ecx, 2000
|
|
|
|
; Check if the RTL8169 has completed writing/reading to the specified MII register
|
|
|
|
@@:
|
|
|
|
in eax, dx
|
|
|
|
test eax, 0x80000000
|
|
|
|
jz .exit
|
|
|
|
udelay 1 ;;;100
|
|
|
|
loop @b
|
|
|
|
.exit:
|
|
|
|
pop ecx
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc START ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
proc START c, reason:dword, cmdline:dword
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [reason], DRV_ENTRY
|
|
|
|
jne .fail
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
DEBUGF 2,"Loading driver\n"
|
|
|
|
invoke RegService, my_service, service_proc
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
2014-08-21 23:10:40 +02:00
|
|
|
xor eax, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc SERVICE_PROC ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
|
|
|
|
|
|
|
mov edx, [ioctl]
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.io_code]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
|
|
|
|
cmp eax, 0 ;SRV_GETVERSION
|
|
|
|
jne @F
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
cmp [edx + IOCTL.out_size], 4
|
2013-05-28 19:34:26 +02:00
|
|
|
jb .fail
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.output]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov [eax], dword API_VERSION
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
@@:
|
|
|
|
cmp eax, 1 ;SRV_HOOK
|
|
|
|
jne .fail
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes
|
2013-05-28 19:34:26 +02:00
|
|
|
jb .fail
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.input]
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given
|
2024-05-30 01:50:06 +02:00
|
|
|
jne .fail ; other types aren't supported for this card yet
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; check if the device is already listed
|
|
|
|
|
|
|
|
mov esi, device_list
|
|
|
|
mov ecx, [devices]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .firstdevice
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers
|
|
|
|
mov ax, [eax+1] ;
|
2013-05-28 19:34:26 +02:00
|
|
|
.nextdevice:
|
|
|
|
mov ebx, [esi]
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp al, byte[ebx + device.pci_bus]
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp ah, byte[ebx + device.pci_dev]
|
2024-05-30 01:50:06 +02:00
|
|
|
je .find_devicenum ; Device is already loaded, let's find its device number
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
|
|
|
add esi, 4
|
|
|
|
loop .nextdevice
|
|
|
|
|
|
|
|
|
2024-05-30 01:50:06 +02:00
|
|
|
; This device doesn't have its own eth_device structure yet, let's create one
|
2013-05-28 19:34:26 +02:00
|
|
|
.firstdevice:
|
|
|
|
cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card
|
|
|
|
jae .fail
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
allocate_and_clear ebx, sizeof.device, .fail ; Allocate memory to put the device structure in
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Fill in the direct call addresses into the struct
|
|
|
|
|
2014-08-21 23:10:40 +02: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 19:34:26 +02:00
|
|
|
|
|
|
|
; save the pci bus and device numbers
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.input]
|
2013-05-28 19:34:26 +02:00
|
|
|
movzx ecx, byte[eax+1]
|
2014-08-21 23:10:40 +02:00
|
|
|
mov [ebx + device.pci_bus], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
movzx ecx, byte[eax+2]
|
2014-08-21 23:10:40 +02:00
|
|
|
mov [ebx + device.pci_dev], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2024-05-30 01:50:06 +02:00
|
|
|
; Now, it's time to find the base io address of the PCI device
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
|
|
|
|
mov [ebx + device.io_addr], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; We've found the io address, find IRQ now
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
|
|
|
|
mov [ebx + device.irq_line], al
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
|
2014-08-21 23:10:40 +02:00
|
|
|
[ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:8
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Ok, the eth_device structure is ready, let's probe the device
|
|
|
|
; Because initialization fires IRQ, IRQ handler must be aware of this 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] ;
|
|
|
|
|
|
|
|
call probe ; this function will output in eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .err2 ; If an error occured, exit
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
mov [ebx + device.type], NET_TYPE_ETH
|
|
|
|
invoke NetRegDev
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp eax, -1
|
|
|
|
je .destroy
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
; If the device was already loaded, find the device number and return it in eax
|
|
|
|
|
|
|
|
.find_devicenum:
|
|
|
|
DEBUGF 2,"Trying to find device number of already registered device\n"
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
; into a device number in edi
|
|
|
|
mov eax, edi ; Application wants it in eax instead
|
|
|
|
DEBUGF 2,"Kernel says: %u\n", eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
; If an error occured, remove all allocated data and exit (returning -1 in eax)
|
|
|
|
|
|
|
|
.destroy:
|
|
|
|
; todo: reset device into virgin state
|
|
|
|
|
|
|
|
.err2:
|
|
|
|
dec [devices]
|
|
|
|
.err:
|
|
|
|
DEBUGF 2,"removing device structure\n"
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke KernelFree, ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
.fail:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
unload:
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
init_board:
|
|
|
|
|
|
|
|
DEBUGF 1,"init_board\n"
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
; Make the device a bus master
|
|
|
|
invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
|
2018-07-01 12:56:44 +02:00
|
|
|
or al, PCI_CMD_MASTER or PCI_CMD_PIO
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Soft reset the chip
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], REG_ChipCmd
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_Reset
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; Check that the chip has finished the reset
|
|
|
|
mov ecx, 1000
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_ChipCmd
|
2015-03-03 14:31:19 +01:00
|
|
|
@@:
|
|
|
|
in al, dx
|
2013-05-28 19:34:26 +02:00
|
|
|
test al, CMD_Reset
|
|
|
|
jz @f
|
|
|
|
udelay 10
|
|
|
|
loop @b
|
2018-07-01 12:56:44 +02:00
|
|
|
DEBUGF 2,"chip reset timeout\n"
|
|
|
|
or eax, -1
|
|
|
|
ret
|
2015-03-03 14:31:19 +01:00
|
|
|
@@:
|
|
|
|
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_TxConfig
|
2013-05-28 19:34:26 +02:00
|
|
|
in eax, dx
|
2015-03-03 14:31:19 +01:00
|
|
|
mov esi, MAC_VERSION_LIST
|
|
|
|
@@:
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, eax
|
2015-03-03 14:31:19 +01:00
|
|
|
and ecx, dword[esi]
|
|
|
|
cmp ecx, dword[esi+4]
|
|
|
|
je @f
|
|
|
|
add esi, 4*4
|
|
|
|
jmp @r
|
|
|
|
@@:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2016-02-01 19:21:55 +01:00
|
|
|
mov ecx, [esi+8]
|
|
|
|
mov [ebx + device.mac_version], ecx
|
|
|
|
mov ecx, [esi+12]
|
|
|
|
mov [ebx + device.name], ecx
|
|
|
|
DEBUGF 2, "Detected chip: %s\n", ecx
|
|
|
|
cmp dword[esi], 0
|
|
|
|
jne @f
|
2018-07-01 12:56:44 +02:00
|
|
|
DEBUGF 1, "TxConfig = 0x%x\n", eax
|
2016-02-01 19:21:55 +01:00
|
|
|
@@:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
; Function
|
|
|
|
; probe
|
|
|
|
; Description
|
|
|
|
; Searches for an ethernet card, enables it and clears the rx buffer
|
|
|
|
; If a card was found, it enables the ethernet -> TCPIP link
|
|
|
|
; Destroyed registers
|
|
|
|
; eax, ebx, ecx, edx
|
|
|
|
;
|
|
|
|
;***************************************************************************
|
|
|
|
align 4
|
|
|
|
probe:
|
|
|
|
|
|
|
|
DEBUGF 1,"probe\n"
|
|
|
|
|
|
|
|
call init_board
|
|
|
|
call read_mac
|
|
|
|
call PHY_config
|
|
|
|
|
2013-12-08 15:34:08 +01:00
|
|
|
DEBUGF 1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], 0x82
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 0x01
|
|
|
|
out dx, al
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.mcfg], MCFG_METHOD_03
|
2013-05-28 19:34:26 +02:00
|
|
|
jae @f
|
2013-12-08 15:34:08 +01:00
|
|
|
DEBUGF 1,"Set PCI Latency=0x40\n"
|
2014-08-21 23:10:40 +02:00
|
|
|
; Adjust PCI latency to be at least 64
|
|
|
|
invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency
|
|
|
|
cmp al, 64
|
|
|
|
jae @f
|
|
|
|
mov al, 64
|
|
|
|
invoke PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax
|
|
|
|
@@:
|
|
|
|
cmp [ebx + device.mcfg], MCFG_METHOD_02
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
2013-12-08 15:34:08 +01:00
|
|
|
DEBUGF 1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], 0x82
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 0x01
|
|
|
|
out dx, al
|
2013-12-08 15:34:08 +01:00
|
|
|
DEBUGF 1,"Set PHY Reg 0x0bh = 0x00h\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
WRITE_GMII_REG 0x0b, 0x0000 ; w 0x0b 15 0 0
|
|
|
|
@@:
|
|
|
|
; if TBI is not enabled
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], REG_PHYstatus
|
2013-05-28 19:34:26 +02:00
|
|
|
in al, dx
|
|
|
|
test al, PHYS_TBI_Enable
|
|
|
|
jz .tbi_dis
|
|
|
|
READ_GMII_REG PHY_AUTO_NEGO_REG
|
|
|
|
|
|
|
|
; enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged
|
|
|
|
and eax, 0x0C1F
|
|
|
|
or eax, PHY_Cap_10_Half or PHY_Cap_10_Full or PHY_Cap_100_Half or PHY_Cap_100_Full
|
|
|
|
WRITE_GMII_REG PHY_AUTO_NEGO_REG, ax
|
|
|
|
|
|
|
|
; enable 1000 Full Mode
|
|
|
|
WRITE_GMII_REG PHY_1000_CTRL_REG, PHY_Cap_1000_Full or PHY_Cap_1000_Half ; rtl8168
|
|
|
|
|
|
|
|
; Enable auto-negotiation and restart auto-nigotiation
|
|
|
|
WRITE_GMII_REG PHY_CTRL_REG, PHY_Enable_Auto_Nego or PHY_Restart_Auto_Nego
|
|
|
|
|
2014-04-08 21:42:47 +02:00
|
|
|
udelay 1 ; 100
|
|
|
|
mov ecx, 200 ; 10000
|
|
|
|
DEBUGF 1, "Waiting for auto-negotiation to complete\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
; wait for auto-negotiation process
|
|
|
|
@@: dec ecx
|
|
|
|
jz @f
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
READ_GMII_REG PHY_STAT_REG
|
2014-04-08 21:42:47 +02:00
|
|
|
udelay 1 ; 100
|
2013-05-28 19:34:26 +02:00
|
|
|
test eax, PHY_Auto_Neco_Comp
|
|
|
|
jz @b
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_PHYstatus
|
2013-05-28 19:34:26 +02:00
|
|
|
in al, dx
|
|
|
|
jmp @f
|
|
|
|
.tbi_dis:
|
2014-04-08 21:42:47 +02:00
|
|
|
udelay 1 ; 100
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
2014-04-08 21:42:47 +02:00
|
|
|
DEBUGF 1, "auto-negotiation complete\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
; Function
|
|
|
|
; rt8169_reset
|
|
|
|
; Description
|
|
|
|
; Place the chip (ie, the ethernet card) into a virgin state
|
|
|
|
; Destroyed registers
|
|
|
|
; eax, ebx, ecx, edx
|
|
|
|
;
|
|
|
|
;***************************************************************************
|
|
|
|
align 4
|
|
|
|
reset:
|
|
|
|
|
2014-04-08 21:42:47 +02:00
|
|
|
DEBUGF 1,"resetting\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
call init_ring
|
2015-03-17 22:50:29 +01:00
|
|
|
test eax, eax
|
|
|
|
jnz .err
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
call hw_start
|
|
|
|
|
|
|
|
; clear packet/byte counters
|
|
|
|
|
|
|
|
xor eax, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
lea edi, [ebx + device.bytes_tx]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, 6
|
|
|
|
rep stosd
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
mov [ebx + device.mtu], 1500
|
2015-03-05 21:04:52 +01:00
|
|
|
call detect_link
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-04-08 21:42:47 +02:00
|
|
|
DEBUGF 2,"init OK!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
.err:
|
2018-07-01 12:56:44 +02:00
|
|
|
DEBUGF 2,"reset failed!\n"
|
2015-03-17 22:50:29 +01:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
PHY_config:
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
DEBUGF 1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n", [ebx + device.mcfg], [ebx + device.pcfg]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.mcfg], MCFG_METHOD_04
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .not_4
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
; WRITE_GMII_REG 0x1F, 0x0001
|
|
|
|
; WRITE_GMII_REG 0x1b, 0x841e
|
|
|
|
; WRITE_GMII_REG 0x0e, 0x7bfb
|
|
|
|
; WRITE_GMII_REG 0x09, 0x273a
|
|
|
|
WRITE_GMII_REG 0x1F, 0x0002
|
|
|
|
WRITE_GMII_REG 0x01, 0x90D0
|
|
|
|
WRITE_GMII_REG 0x1F, 0x0000
|
|
|
|
jmp .exit
|
|
|
|
.not_4:
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.mcfg], MCFG_METHOD_02
|
2013-05-28 19:34:26 +02:00
|
|
|
je @f
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.mcfg], MCFG_METHOD_03
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .not_2_or_3
|
|
|
|
@@:
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
WRITE_GMII_REG 0x1F, 0x0001
|
|
|
|
WRITE_GMII_REG 0x15, 0x1000
|
|
|
|
WRITE_GMII_REG 0x18, 0x65C7
|
|
|
|
WRITE_GMII_REG 0x04, 0x0000
|
|
|
|
WRITE_GMII_REG 0x03, 0x00A1
|
|
|
|
WRITE_GMII_REG 0x02, 0x0008
|
|
|
|
WRITE_GMII_REG 0x01, 0x1020
|
|
|
|
WRITE_GMII_REG 0x00, 0x1000
|
|
|
|
WRITE_GMII_REG 0x04, 0x0800
|
|
|
|
WRITE_GMII_REG 0x04, 0x0000
|
|
|
|
WRITE_GMII_REG 0x04, 0x7000
|
|
|
|
WRITE_GMII_REG 0x03, 0xFF41
|
|
|
|
WRITE_GMII_REG 0x02, 0xDE60
|
|
|
|
WRITE_GMII_REG 0x01, 0x0140
|
|
|
|
WRITE_GMII_REG 0x00, 0x0077
|
|
|
|
WRITE_GMII_REG 0x04, 0x7800
|
|
|
|
WRITE_GMII_REG 0x04, 0x7000
|
|
|
|
WRITE_GMII_REG 0x04, 0xA000
|
|
|
|
WRITE_GMII_REG 0x03, 0xDF01
|
|
|
|
WRITE_GMII_REG 0x02, 0xDF20
|
|
|
|
WRITE_GMII_REG 0x01, 0xFF95
|
|
|
|
WRITE_GMII_REG 0x00, 0xFA00
|
|
|
|
WRITE_GMII_REG 0x04, 0xA800
|
|
|
|
WRITE_GMII_REG 0x04, 0xA000
|
|
|
|
WRITE_GMII_REG 0x04, 0xB000
|
|
|
|
WRITE_GMII_REG 0x03, 0xFF41
|
|
|
|
WRITE_GMII_REG 0x02, 0xDE20
|
|
|
|
WRITE_GMII_REG 0x01, 0x0140
|
|
|
|
WRITE_GMII_REG 0x00, 0x00BB
|
|
|
|
WRITE_GMII_REG 0x04, 0xB800
|
|
|
|
WRITE_GMII_REG 0x04, 0xB000
|
|
|
|
WRITE_GMII_REG 0x04, 0xF000
|
|
|
|
WRITE_GMII_REG 0x03, 0xDF01
|
|
|
|
WRITE_GMII_REG 0x02, 0xDF20
|
|
|
|
WRITE_GMII_REG 0x01, 0xFF95
|
|
|
|
WRITE_GMII_REG 0x00, 0xBF00
|
|
|
|
WRITE_GMII_REG 0x04, 0xF800
|
|
|
|
WRITE_GMII_REG 0x04, 0xF000
|
|
|
|
WRITE_GMII_REG 0x04, 0x0000
|
|
|
|
WRITE_GMII_REG 0x1F, 0x0000
|
|
|
|
WRITE_GMII_REG 0x0B, 0x0000
|
|
|
|
jmp .exit
|
|
|
|
.not_2_or_3:
|
2014-08-21 23:10:40 +02:00
|
|
|
DEBUGF 1,"mcfg=%d, discard hw PHY config\n", [ebx + device.mcfg]
|
2013-05-28 19:34:26 +02:00
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
set_rx_mode:
|
|
|
|
|
|
|
|
DEBUGF 1,"set_rx_mode\n"
|
|
|
|
|
|
|
|
; IFF_ALLMULTI
|
|
|
|
; Too many to filter perfectly -- accept all multicasts
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], REG_RxConfig
|
2013-05-28 19:34:26 +02:00
|
|
|
in eax, dx
|
2015-03-03 14:31:19 +01:00
|
|
|
and eax, 0xff7e1880
|
2013-05-28 19:34:26 +02:00
|
|
|
or eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys)
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
; Multicast hash filter
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_MAR0 + 0
|
2013-05-28 19:34:26 +02:00
|
|
|
or eax, -1
|
|
|
|
out dx, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_MAR0 + 4
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
init_ring:
|
|
|
|
|
|
|
|
DEBUGF 1,"init_ring\n"
|
|
|
|
|
|
|
|
xor eax, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
mov [ebx + device.cur_rx], eax
|
|
|
|
mov [ebx + device.cur_tx], eax
|
2015-03-05 21:04:52 +01:00
|
|
|
mov [ebx + device.last_tx], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
lea edi, [ebx + device.tx_ring]
|
2015-03-05 21:04:52 +01:00
|
|
|
mov ecx, (NUM_TX_DESC * sizeof.tx_desc) / 4 * 2
|
2013-05-28 19:34:26 +02:00
|
|
|
rep stosd
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
lea edi, [ebx + device.rx_ring]
|
|
|
|
mov ecx, (NUM_RX_DESC * sizeof.rx_desc) / 4
|
2013-05-28 19:34:26 +02:00
|
|
|
rep stosd
|
|
|
|
|
2015-03-05 21:04:52 +01:00
|
|
|
lea edi, [ebx + device.rx_ring]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, NUM_RX_DESC
|
|
|
|
.loop:
|
|
|
|
push ecx
|
2015-03-17 22:50:29 +01:00
|
|
|
invoke NetAlloc, RX_BUF_SIZE+NET_BUFF.data
|
|
|
|
test eax, eax
|
|
|
|
jz .err
|
2014-08-21 23:10:40 +02:00
|
|
|
mov dword [edi + rx_desc.buf_soft_addr], eax
|
2015-03-05 21:04:52 +01:00
|
|
|
invoke GetPhysAddr
|
2015-03-17 22:50:29 +01:00
|
|
|
add eax, NET_BUFF.data
|
2013-05-28 19:34:26 +02:00
|
|
|
mov dword [edi + rx_desc.buf_addr], eax
|
|
|
|
mov [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE
|
2014-08-21 23:10:40 +02:00
|
|
|
add edi, sizeof.rx_desc
|
2013-05-28 19:34:26 +02:00
|
|
|
pop ecx
|
2014-08-21 23:10:40 +02:00
|
|
|
dec ecx
|
|
|
|
jnz .loop
|
|
|
|
or [edi - sizeof.rx_desc + rx_desc.status], DSB_EORbit
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
xor eax, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
.err:
|
|
|
|
pop eax
|
|
|
|
or eax, -1
|
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
hw_start:
|
|
|
|
|
|
|
|
DEBUGF 1,"hw_start\n"
|
|
|
|
|
|
|
|
; attach int handler
|
2014-08-21 23:10:40 +02:00
|
|
|
movzx eax, [ebx + device.irq_line]
|
2013-05-28 19:34:26 +02:00
|
|
|
DEBUGF 1,"Attaching int handler to irq %x\n", eax:1
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke AttachIntHandler, eax, int_handler, ebx
|
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
|
|
|
DEBUGF 2,"Could not attach int handler!\n"
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
@@:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Soft reset the chip
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], REG_ChipCmd
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_Reset
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
DEBUGF 1,"Waiting for chip to reset... "
|
|
|
|
; Check that the chip has finished the reset
|
|
|
|
mov ecx, 1000
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_ChipCmd
|
2013-05-28 19:34:26 +02:00
|
|
|
@@: in al, dx
|
|
|
|
test al, CMD_Reset
|
|
|
|
jz @f
|
|
|
|
udelay 10
|
|
|
|
loop @b
|
|
|
|
@@:
|
|
|
|
DEBUGF 1,"done!\n"
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_Cfg9346
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CFG_9346_Unlock
|
|
|
|
out dx, al
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_ChipCmd
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_TxEnb or CMD_RxEnb
|
|
|
|
out dx, al
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_ETThReg
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, ETTh
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; For gigabit rtl8169
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_RxMaxSize
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ax, RxPacketMaxSize
|
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
; Set Rx Config register
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_RxConfig
|
2013-05-28 19:34:26 +02:00
|
|
|
in ax, dx
|
2015-03-03 14:31:19 +01:00
|
|
|
and eax, 0xff7e1880
|
2013-05-28 19:34:26 +02:00
|
|
|
or eax, rx_config
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
; Set DMA burst size and Interframe Gap Time
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_TxConfig
|
2013-05-28 19:34:26 +02:00
|
|
|
mov eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift)
|
|
|
|
out dx, eax
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_CPlusCmd
|
2013-05-28 19:34:26 +02:00
|
|
|
in ax, dx
|
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
in ax, dx
|
|
|
|
or ax, 1 shl 3
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.mcfg], MCFG_METHOD_02
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.mcfg], MCFG_METHOD_03
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
|
|
|
or ax,1 shl 14
|
|
|
|
DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n"
|
|
|
|
jmp .set
|
|
|
|
@@:
|
|
|
|
DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n"
|
|
|
|
.set:
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_CPlusCmd
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, ax
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0xE2
|
2013-05-28 19:34:26 +02:00
|
|
|
; mov ax, 0x1517
|
|
|
|
; out dx, ax
|
|
|
|
; mov ax, 0x152a
|
|
|
|
; out dx, ax
|
|
|
|
; mov ax, 0x282a
|
|
|
|
; out dx, ax
|
|
|
|
xor ax, ax
|
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
xor eax, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
mov [ebx + device.cur_rx], eax
|
|
|
|
lea eax, [ebx + device.tx_ring]
|
|
|
|
invoke GetPhysAddr
|
|
|
|
set_io [ebx + device.io_addr], REG_TxDescStartAddr
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_TxDescStartAddr + 4
|
2013-11-27 12:09:26 +01:00
|
|
|
xor eax, eax
|
|
|
|
out dx, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
lea eax, [ebx + device.rx_ring]
|
|
|
|
invoke GetPhysAddr
|
|
|
|
set_io [ebx + device.io_addr], REG_RxDescStartAddr
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
2013-11-27 12:09:26 +01:00
|
|
|
xor eax, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_RxDescStartAddr + 4
|
2013-11-27 12:09:26 +01:00
|
|
|
out dx, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_Cfg9346
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CFG_9346_Lock
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
udelay 10
|
|
|
|
|
|
|
|
xor eax, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_RxMissed
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
call set_rx_mode
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
; no early-rx interrupts
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_MultiIntr
|
2013-05-28 19:34:26 +02:00
|
|
|
in ax, dx
|
|
|
|
and ax, 0xF000
|
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
; set interrupt mask
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], REG_IntrMask
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ax, intr_mask
|
|
|
|
out dx, ax
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
read_mac:
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], REG_MAC0
|
2013-05-28 19:34:26 +02:00
|
|
|
xor ecx, ecx
|
2014-08-21 23:10:40 +02:00
|
|
|
lea edi, [ebx + device.mac]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, 6
|
|
|
|
|
|
|
|
; Get MAC address. FIXME: read EEPROM
|
2015-03-05 21:04:52 +01:00
|
|
|
@@:
|
|
|
|
in al, dx
|
2013-05-28 19:34:26 +02:00
|
|
|
stosb
|
|
|
|
inc edx
|
|
|
|
loop @r
|
|
|
|
|
|
|
|
DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\
|
2014-08-21 23:10:40 +02:00
|
|
|
[ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,[ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
write_mac:
|
|
|
|
|
|
|
|
ret 6
|
|
|
|
|
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
; Function
|
|
|
|
; transmit
|
|
|
|
; Description
|
|
|
|
; Transmits a packet of data via the ethernet card
|
|
|
|
;
|
2021-08-22 22:57:59 +02:00
|
|
|
; In: pointer to device structure in ebx
|
|
|
|
; Out: eax = 0 on success
|
2013-05-28 19:34:26 +02:00
|
|
|
;
|
|
|
|
;***************************************************************************
|
2021-08-22 22:57:59 +02:00
|
|
|
align 16
|
2015-03-17 22:50:29 +01:00
|
|
|
proc transmit stdcall bufferptr
|
2014-08-21 23:10:40 +02:00
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
spin_lock_irqsave
|
2014-08-21 23:10:40 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
mov esi, [bufferptr]
|
|
|
|
DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
|
|
|
|
lea eax, [esi + NET_BUFF.data]
|
2013-05-28 19:34:26 +02:00
|
|
|
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
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
cmp [esi + NET_BUFF.length], 1514
|
2021-07-04 19:43:16 +02:00
|
|
|
ja .error
|
2015-03-17 22:50:29 +01:00
|
|
|
cmp [esi + NET_BUFF.length], 60
|
2021-07-04 19:43:16 +02:00
|
|
|
jb .error
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;----------------------------------
|
|
|
|
; Find currentTX descriptor address
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
mov eax, sizeof.tx_desc
|
|
|
|
mul [ebx + device.cur_tx]
|
|
|
|
lea esi, [ebx + device.tx_ring + eax]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
DEBUGF 1,"Using TX desc: %x\n", esi
|
|
|
|
|
2015-03-05 21:04:52 +01:00
|
|
|
;----------------------------------
|
|
|
|
; Check if the descriptor is in use
|
|
|
|
|
|
|
|
test [esi + tx_desc.status], DSB_OWNbit
|
2021-07-04 19:43:16 +02:00
|
|
|
jnz .overrun
|
2015-03-05 21:04:52 +01:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
;---------------------------
|
|
|
|
; Program the packet pointer
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
mov eax, [bufferptr]
|
2015-03-17 22:50:29 +01:00
|
|
|
mov ecx, [eax + NET_BUFF.length]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov [esi + tx_desc.buf_soft_addr], eax
|
2015-03-17 22:50:29 +01:00
|
|
|
add eax, [eax + NET_BUFF.offset]
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke GetPhysAddr
|
2013-05-28 19:34:26 +02:00
|
|
|
mov dword [esi + tx_desc.buf_addr], eax
|
|
|
|
|
|
|
|
;------------------------
|
|
|
|
; Program the packet size
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
mov eax, ecx
|
2015-03-05 21:04:52 +01:00
|
|
|
or eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.cur_tx], NUM_TX_DESC - 1
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
|
|
|
or eax, DSB_EORbit
|
2015-03-05 21:04:52 +01:00
|
|
|
@@:
|
|
|
|
mov [esi + tx_desc.status], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;-----------------------------------------
|
|
|
|
; Set the polling bit (start transmission)
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], REG_TxPoll
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 0x40 ; set polling bit
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
;-----------------------
|
|
|
|
; Update TX descriptor
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
inc [ebx + device.cur_tx]
|
|
|
|
and [ebx + device.cur_tx], NUM_TX_DESC - 1
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;-------------
|
|
|
|
; Update stats
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
inc [ebx + device.packets_tx]
|
2015-03-17 22:50:29 +01:00
|
|
|
add dword [ebx + device.bytes_tx], ecx
|
2014-08-21 23:10:40 +02:00
|
|
|
adc dword [ebx + device.bytes_tx + 4], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
spin_unlock_irqrestore
|
2014-09-15 13:23:03 +02:00
|
|
|
xor eax, eax
|
2014-08-21 23:10:40 +02:00
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-07-04 19:43:16 +02:00
|
|
|
.error:
|
|
|
|
DEBUGF 2, "TX packet error\n"
|
|
|
|
inc [ebx + device.packets_tx_err]
|
2015-03-17 22:50:29 +01:00
|
|
|
invoke NetFree, [bufferptr]
|
2021-07-04 19:43:16 +02:00
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
spin_unlock_irqrestore
|
2021-07-04 19:43:16 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
.overrun:
|
|
|
|
DEBUGF 2, "TX overrun\n"
|
|
|
|
inc [ebx + device.packets_tx_ovr]
|
|
|
|
invoke NetFree, [bufferptr]
|
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
spin_unlock_irqrestore
|
2013-12-08 15:34:08 +01:00
|
|
|
or eax, -1
|
2014-08-21 23:10:40 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Interrupt handler ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
2021-08-22 22:57:59 +02:00
|
|
|
align 16
|
2013-05-28 19:34:26 +02:00
|
|
|
int_handler:
|
|
|
|
|
|
|
|
push ebx esi edi
|
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
mov ebx, [esp+4*4]
|
|
|
|
DEBUGF 1,"INT for 0x%x\n", ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
; TODO? if we are paranoid, we can check that the value from ebx is present in the current device_list
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], REG_IntrStatus
|
2013-05-28 19:34:26 +02:00
|
|
|
in ax, dx
|
|
|
|
test ax, ax
|
2021-08-22 22:57:59 +02:00
|
|
|
jz .nothing
|
|
|
|
cmp ax, 0xffff ; if so, hardware is no longer present
|
|
|
|
je .nothing ;
|
|
|
|
test ax, ax
|
|
|
|
jz .nothing
|
|
|
|
out dx, ax ; ACK all interrupts
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
DEBUGF 1,"Status: %x\n", ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;--------
|
|
|
|
; Receive
|
|
|
|
test ax, ISB_RxOK
|
|
|
|
jz .no_rx
|
|
|
|
|
|
|
|
push ax
|
|
|
|
push ebx
|
|
|
|
|
2015-06-02 00:06:51 +02:00
|
|
|
.rx_loop:
|
2013-05-28 19:34:26 +02:00
|
|
|
pop ebx
|
2014-08-21 23:10:40 +02:00
|
|
|
mov eax, sizeof.rx_desc
|
|
|
|
mul [ebx + device.cur_rx]
|
|
|
|
lea esi, [ebx + device.rx_ring + eax]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
|
2015-03-17 22:50:29 +01:00
|
|
|
mov ecx, [esi + rx_desc.status]
|
2015-06-02 00:06:51 +02:00
|
|
|
test ecx, DSB_OWNbit
|
2021-07-04 19:43:16 +02:00
|
|
|
jnz .rx_done
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
DEBUGF 1,"cur_rx = %u\n", [ebx + device.cur_rx]
|
2021-07-04 19:43:16 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
test ecx, SD_RxRES
|
2021-07-04 19:43:16 +02:00
|
|
|
jnz .rx_error
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
push ebx
|
2015-06-02 00:06:51 +02:00
|
|
|
push .rx_loop
|
2015-03-17 22:50:29 +01:00
|
|
|
and ecx, 0x00001FFF
|
2024-05-30 01:50:06 +02:00
|
|
|
add ecx, -4 ; we don't need CRC
|
2015-03-17 22:50:29 +01:00
|
|
|
DEBUGF 1,"data length = %u\n", ecx
|
|
|
|
mov eax, [esi + rx_desc.buf_soft_addr]
|
2013-05-28 19:34:26 +02:00
|
|
|
push eax
|
2015-03-17 22:50:29 +01:00
|
|
|
mov [eax + NET_BUFF.length], ecx
|
|
|
|
mov [eax + NET_BUFF.device], ebx
|
|
|
|
mov [eax + NET_BUFF.offset], NET_BUFF.data
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
;-------------
|
|
|
|
; Update stats
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2016-08-16 18:15:03 +02:00
|
|
|
add dword [ebx + device.bytes_rx], ecx
|
2014-08-21 23:10:40 +02:00
|
|
|
adc dword [ebx + device.bytes_rx + 4], 0
|
|
|
|
inc [ebx + device.packets_rx]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
;----------------------
|
|
|
|
; Allocate a new buffer
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-06-02 00:06:51 +02:00
|
|
|
mov [esi + rx_desc.status], 0
|
2015-03-17 22:50:29 +01:00
|
|
|
invoke NetAlloc, RX_BUF_SIZE+NET_BUFF.data
|
2015-06-02 00:06:51 +02:00
|
|
|
test eax, eax
|
2021-07-04 19:43:16 +02:00
|
|
|
jz .rx_overrun
|
2013-05-28 19:34:26 +02:00
|
|
|
mov [esi + rx_desc.buf_soft_addr], eax
|
2014-08-21 23:10:40 +02:00
|
|
|
invoke GetPhysAddr
|
2015-03-17 22:50:29 +01:00
|
|
|
add eax, NET_BUFF.data
|
2013-05-28 19:34:26 +02:00
|
|
|
mov dword [esi + rx_desc.buf_addr], eax
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
;---------------
|
|
|
|
; re set OWN bit
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
mov eax, DSB_OWNbit or RX_BUF_SIZE
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp [ebx + device.cur_rx], NUM_RX_DESC - 1
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
|
|
|
or eax, DSB_EORbit
|
2014-08-21 23:10:40 +02:00
|
|
|
@@:
|
|
|
|
mov [esi + rx_desc.status], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
;--------------
|
|
|
|
; Update rx ptr
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
inc [ebx + device.cur_rx]
|
|
|
|
and [ebx + device.cur_rx], NUM_RX_DESC - 1
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
jmp [EthInput]
|
|
|
|
|
2021-07-04 19:43:16 +02:00
|
|
|
.rx_overrun:
|
|
|
|
DEBUGF 2,"RX FIFO overrun\n"
|
|
|
|
inc [ebx + device.packets_rx_ovr]
|
|
|
|
jmp .rx_next
|
|
|
|
|
|
|
|
.rx_error:
|
|
|
|
inc [ebx + device.packets_rx_err]
|
|
|
|
test ecx, SD_RxRWT or SD_RxRUNT
|
|
|
|
jz @f
|
|
|
|
DEBUGF 2,"RX length error"
|
|
|
|
@@:
|
|
|
|
test ecx, SD_RxCRC
|
|
|
|
jz @f
|
|
|
|
DEBUGF 2,"RX CRC error"
|
|
|
|
@@:
|
|
|
|
test ecx, SD_RxFOVF
|
|
|
|
jz @f
|
|
|
|
DEBUGF 2,"RX FIFO error"
|
|
|
|
@@:
|
|
|
|
|
|
|
|
.rx_next:
|
2015-06-02 00:06:51 +02:00
|
|
|
mov eax, DSB_OWNbit or RX_BUF_SIZE
|
|
|
|
cmp [ebx + device.cur_rx], NUM_RX_DESC - 1
|
|
|
|
jne @f
|
|
|
|
or eax, DSB_EORbit
|
|
|
|
@@:
|
|
|
|
mov [esi + rx_desc.status], eax
|
|
|
|
push ebx
|
|
|
|
jmp .rx_loop
|
|
|
|
|
2021-07-04 19:43:16 +02:00
|
|
|
.rx_done:
|
2013-05-28 19:34:26 +02:00
|
|
|
pop ax
|
|
|
|
.no_rx:
|
|
|
|
|
2015-03-05 21:04:52 +01:00
|
|
|
;-----------------
|
|
|
|
; Transmit cleanup
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-05 21:04:52 +01:00
|
|
|
test ax, ISB_TxOK or ISB_TxErr or ISB_TxDescUnavail
|
2013-05-28 19:34:26 +02:00
|
|
|
jz .no_tx
|
2015-03-17 22:50:29 +01:00
|
|
|
push ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-05 21:04:52 +01:00
|
|
|
DEBUGF 1,"TX done!\n"
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
mov ecx, NUM_TX_DESC
|
|
|
|
lea esi, [ebx + device.tx_ring]
|
|
|
|
.txloop:
|
2014-08-21 23:10:40 +02:00
|
|
|
cmp dword [esi + tx_desc.buf_soft_addr], 0
|
2015-03-17 22:50:29 +01:00
|
|
|
jz .maybenext
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
test [esi + tx_desc.status], DSB_OWNbit
|
2015-03-17 22:50:29 +01:00
|
|
|
jnz .maybenext
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
push ecx
|
|
|
|
DEBUGF 1,"Freeing up TX desc: %x\n", esi
|
|
|
|
invoke NetFree, [esi + tx_desc.buf_soft_addr]
|
|
|
|
pop ecx
|
2014-08-21 23:10:40 +02:00
|
|
|
and dword [esi + tx_desc.buf_soft_addr], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
.maybenext:
|
|
|
|
add esi, sizeof.tx_desc
|
|
|
|
dec ecx
|
|
|
|
jnz .txloop
|
|
|
|
|
|
|
|
pop ax
|
2013-05-28 19:34:26 +02:00
|
|
|
.no_tx:
|
|
|
|
|
2015-03-05 21:04:52 +01:00
|
|
|
test ax, ISB_LinkChg
|
|
|
|
jz .no_linkchange
|
|
|
|
DEBUGF 2, "Link change detected\n"
|
|
|
|
call detect_link
|
|
|
|
.no_linkchange:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
pop edi esi ebx
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2021-08-22 22:57:59 +02:00
|
|
|
.nothing:
|
|
|
|
pop edi esi ebx
|
|
|
|
xor eax, eax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
2015-03-05 21:04:52 +01:00
|
|
|
align 4
|
|
|
|
detect_link:
|
|
|
|
|
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
|
|
|
|
; set_io [ebx + device.io_addr], REG_TBICSR
|
|
|
|
; in eax, dx
|
|
|
|
; test eax, TBI_LinkOK
|
|
|
|
; jz .down
|
|
|
|
|
|
|
|
; mov [ebx + device.state], ETH_LINK_UNKNOWN
|
|
|
|
; invoke NetLinkChanged
|
|
|
|
; ret
|
|
|
|
|
|
|
|
set_io [ebx + device.io_addr], REG_PHYstatus
|
|
|
|
in al, dx
|
|
|
|
test al, PHYS_LinkStatus
|
|
|
|
jz .down
|
|
|
|
DEBUGF 2, "Link is up, phystatus=0x%x\n", al
|
|
|
|
xor ecx, ecx
|
|
|
|
test al, PHYS_10bps
|
|
|
|
jz @f
|
2021-08-22 23:14:54 +02:00
|
|
|
or cl, ETH_LINK_SPEED_10M
|
2015-03-05 21:04:52 +01:00
|
|
|
@@:
|
|
|
|
test al, PHYS_100bps
|
|
|
|
jz @f
|
2021-08-22 23:14:54 +02:00
|
|
|
or cl, ETH_LINK_SPEED_100M
|
2015-03-05 21:04:52 +01:00
|
|
|
@@:
|
|
|
|
test al, PHYS_1000bpsF
|
|
|
|
jz @f
|
2021-08-22 23:14:54 +02:00
|
|
|
or cl, ETH_LINK_SPEED_1G ;or ETH_LINK_FULL_DUPLEX
|
2015-03-05 21:04:52 +01:00
|
|
|
@@:
|
|
|
|
test al, PHYS_FullDup
|
|
|
|
jz @f
|
2021-08-22 23:14:54 +02:00
|
|
|
or cl, ETH_LINK_FULL_DUPLEX
|
2015-03-05 21:04:52 +01:00
|
|
|
@@:
|
|
|
|
mov [ebx + device.state], ecx
|
|
|
|
invoke NetLinkChanged
|
|
|
|
ret
|
|
|
|
|
|
|
|
.down:
|
|
|
|
DEBUGF 2, "Link is down\n"
|
|
|
|
mov [ebx + device.state], ETH_LINK_DOWN
|
|
|
|
invoke NetLinkChanged
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
; End of code
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
data fixups
|
|
|
|
end data
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
include '../peimport.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
my_service db 'RTL8169',0 ; max 16 chars include zero
|
|
|
|
|
|
|
|
include_debug_strings ; All data wich FDO uses will be included here
|
|
|
|
|
2015-03-03 14:31:19 +01:00
|
|
|
MAC_VERSION_LIST:
|
|
|
|
|
2018-07-01 12:56:44 +02:00
|
|
|
; 8168E+ family
|
|
|
|
dd 0x7cf00000, 0x50200000, 51, sz_rtl8168ep
|
|
|
|
dd 0x7cf00000, 0x50100000, 50, sz_rtl8168ep
|
|
|
|
dd 0x7cf00000, 0x50000000, 49, sz_rtl8168ep
|
|
|
|
|
|
|
|
; 8168H family
|
|
|
|
dd 0x7cf00000, 0x54100000, 46, sz_rtl8168h
|
|
|
|
dd 0x7cf00000, 0x54000000, 45, sz_rtl8168h
|
|
|
|
|
|
|
|
; 8168G family
|
|
|
|
dd 0x7cf00000, 0x5c800000, 44, sz_rtl8411
|
|
|
|
dd 0x7cf00000, 0x50900000, 42, sz_rtl8168g
|
|
|
|
dd 0x7cf00000, 0x4c100000, 41, sz_rtl8168g
|
|
|
|
dd 0x7cf00000, 0x4c000000, 40, sz_rtl8168g
|
|
|
|
|
|
|
|
; 8168F family
|
|
|
|
dd 0x7c800000, 0x48800000, 38, sz_rtl8411
|
|
|
|
dd 0x7cf00000, 0x48100000, 36, sz_rtl8168f
|
|
|
|
dd 0x7cf00000, 0x48000000, 35, sz_rtl8168f
|
|
|
|
|
|
|
|
; 8168E family
|
|
|
|
dd 0x7c800000, 0x2c800000, 34, sz_rtl8168evl
|
|
|
|
dd 0x7cf00000, 0x2c200000, 33, sz_rtl8168e
|
|
|
|
dd 0x7cf00000, 0x2c100000, 32, sz_rtl8168e
|
|
|
|
dd 0x7c800000, 0x2c000000, 33, sz_rtl8168e
|
|
|
|
|
|
|
|
; 8168D family
|
|
|
|
dd 0x7cf00000, 0x28300000, 26, sz_rtl8168d
|
|
|
|
dd 0x7cf00000, 0x28100000, 25, sz_rtl8168d
|
|
|
|
dd 0x7c800000, 0x28000000, 26, sz_rtl8168d
|
|
|
|
|
|
|
|
; 8168D+ family
|
|
|
|
dd 0x7cf00000, 0x28800000, 27, sz_rtl8168dp
|
|
|
|
dd 0x7cf00000, 0x28a00000, 28, sz_rtl8168dp
|
|
|
|
|
|
|
|
; 8168C family
|
|
|
|
dd 0x7cf00000, 0x3cb00000, 24, sz_rtl8168p
|
|
|
|
dd 0x7cf00000, 0x3c900000, 23, sz_rtl8168p
|
|
|
|
dd 0x7cf00000, 0x3c800000, 18, sz_rtl8168p
|
|
|
|
dd 0x7c800000, 0x3c800000, 24, sz_rtl8168p
|
|
|
|
dd 0x7cf00000, 0x3c000000, 19, sz_rtl8168c
|
|
|
|
dd 0x7cf00000, 0x3c200000, 20, sz_rtl8168c
|
|
|
|
dd 0x7cf00000, 0x3c300000, 21, sz_rtl8168c
|
|
|
|
dd 0x7cf00000, 0x3c400000, 22, sz_rtl8168c
|
|
|
|
dd 0x7c800000, 0x3c000000, 22, sz_rtl8168c
|
|
|
|
|
|
|
|
; 8168B family
|
|
|
|
dd 0x7cf00000, 0x38000000, 12, sz_rtl8168b
|
|
|
|
dd 0x7cf00000, 0x38500000, 17, sz_rtl8101e
|
|
|
|
dd 0x7c800000, 0x38000000, 17, sz_rtl8101e
|
|
|
|
dd 0x7c800000, 0x30000000, 11, sz_rtl8168b
|
|
|
|
|
|
|
|
; 8101 family
|
|
|
|
dd 0x7cf00000, 0x44900000, 39, sz_rtl8106e
|
|
|
|
dd 0x7c800000, 0x44800000, 39, sz_rtl8106e
|
|
|
|
dd 0x7c800000, 0x44000000, 37, sz_rtl8402
|
|
|
|
dd 0x7cf00000, 0x40b00000, 30, sz_rtl8105e
|
|
|
|
dd 0x7cf00000, 0x40a00000, 30, sz_rtl8105e
|
|
|
|
dd 0x7cf00000, 0x40900000, 29, sz_rtl8105e
|
|
|
|
dd 0x7c800000, 0x40800000, 30, sz_rtl8105e
|
|
|
|
dd 0x7cf00000, 0x34a00000, 09, sz_rtl8102e
|
|
|
|
dd 0x7cf00000, 0x24a00000, 09, sz_rtl8102e
|
|
|
|
dd 0x7cf00000, 0x34900000, 08, sz_rtl8102e
|
|
|
|
dd 0x7cf00000, 0x24900000, 08, sz_rtl8102e
|
|
|
|
dd 0x7cf00000, 0x34800000, 07, sz_rtl8102e
|
|
|
|
dd 0x7cf00000, 0x24800000, 07, sz_rtl8102e
|
|
|
|
dd 0x7cf00000, 0x34000000, 13, sz_rtl8101e
|
|
|
|
dd 0x7cf00000, 0x34300000, 10, sz_rtl8101e
|
|
|
|
dd 0x7cf00000, 0x34200000, 16, sz_rtl8168b
|
|
|
|
dd 0x7c800000, 0x34800000, 09, sz_rtl8102e
|
|
|
|
dd 0x7c800000, 0x24800000, 09, sz_rtl8102e
|
|
|
|
dd 0x7c800000, 0x34000000, 16, sz_rtl8168b
|
|
|
|
dd 0xfc800000, 0x38800000, 15, sz_rtl8100e
|
|
|
|
dd 0xfc800000, 0x30800000, 14, sz_rtl8100e
|
|
|
|
|
|
|
|
; 8110 family
|
|
|
|
dd 0xfc800000, 0x98000000, 06, sz_rtl8169sc
|
|
|
|
dd 0xfc800000, 0x18000000, 05, sz_rtl8169sc
|
|
|
|
dd 0xfc800000, 0x10000000, 04, sz_rtl8169sb
|
|
|
|
dd 0xfc800000, 0x04000000, 03, sz_rtl8110s
|
|
|
|
dd 0xfc800000, 0x00800000, 02, sz_rtl8169s
|
|
|
|
dd 0xfc800000, 0x00000000, 01, sz_rtl8169
|
2015-03-03 14:31:19 +01:00
|
|
|
|
|
|
|
; Catch-all
|
2018-07-01 12:56:44 +02:00
|
|
|
dd 0x00000000, 0x00000000, 0, sz_unknown
|
|
|
|
|
|
|
|
sz_rtl8169 db "Realtek 8169",0
|
|
|
|
sz_rtl8169s db "Realtek 8169s",0
|
|
|
|
sz_rtl8110s db "Realtek 8110s",0
|
|
|
|
sz_rtl8169sb db "Realtek 8169sb/8110sb",0
|
|
|
|
sz_rtl8169sc db "Realtek 8169sc/8110sc",0
|
|
|
|
sz_rtl8102e db "Realtek 8102e",0
|
|
|
|
sz_rtl8101e db "Realtek 8101e",0
|
|
|
|
sz_rtl8168b db "Realtek 8168b/8111b",0
|
|
|
|
sz_rtl8100e db "Realtek 8100e",0
|
|
|
|
sz_rtl8168p db "Realtek 8168c+/8111c+",0
|
|
|
|
sz_rtl8168c db "Realtek 8168c/8111c",0
|
|
|
|
sz_rtl8168d db "Realtek 8168d/8111d",0
|
|
|
|
sz_rtl8168dp db "Realtek 8168d+/8111d+",0
|
|
|
|
sz_rtl8105e db "Realtek 8105e",0
|
|
|
|
sz_rtl8168e db "Realtek 8168e/8111e",0
|
|
|
|
sz_rtl8168evl db "Realtek 8168evl/8111evl",0
|
|
|
|
sz_rtl8168f db "Realtek 8168f/8111f",0
|
|
|
|
sz_rtl8402 db "Realtek 8402",0
|
|
|
|
sz_rtl8411 db "Realtek 8411",0
|
|
|
|
sz_rtl8106e db "Realtek 8106e",0
|
|
|
|
sz_rtl8168ep db "Realtek 8168e+",0
|
|
|
|
sz_rtl8168g db "Realtek 8168g/8111g",0
|
|
|
|
sz_rtl8168h db "Realtek 8168h/8111h",0
|
|
|
|
sz_unknown db "unknown RTL8169 rev",0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-08-21 23:10:40 +02:00
|
|
|
align 4
|
|
|
|
devices dd 0
|
2013-05-28 19:34:26 +02:00
|
|
|
device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling
|
|
|
|
|
|
|
|
|