Some cleanup in rtl8169 driver

git-svn-id: svn://kolibrios.org@2916 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-08-09 14:35:51 +00:00
parent 24d344231c
commit 3b724316fb

View File

@ -144,16 +144,16 @@ public version
PHY_Restart_Auto_Nego = 0x0200 PHY_Restart_Auto_Nego = 0x0200
PHY_Enable_Auto_Nego = 0x1000 PHY_Enable_Auto_Nego = 0x1000
; PHY_STAT_REG = 1; ; PHY_STAT_REG = 1
PHY_Auto_Neco_Comp = 0x0020 PHY_Auto_Neco_Comp = 0x0020
; PHY_AUTO_NEGO_REG = 4; ; PHY_AUTO_NEGO_REG = 4
PHY_Cap_10_Half = 0x0020 PHY_Cap_10_Half = 0x0020
PHY_Cap_10_Full = 0x0040 PHY_Cap_10_Full = 0x0040
PHY_Cap_100_Half = 0x0080 PHY_Cap_100_Half = 0x0080
PHY_Cap_100_Full = 0x0100 PHY_Cap_100_Full = 0x0100
; PHY_1000_CTRL_REG = 9; ; PHY_1000_CTRL_REG = 9
PHY_Cap_1000_Full = 0x0200 PHY_Cap_1000_Full = 0x0200
PHY_Cap_1000_Half = 0x0100 PHY_Cap_1000_Half = 0x0100
@ -180,62 +180,53 @@ public version
RX_BUF_SIZE = 1536 ; Rx Buffer size RX_BUF_SIZE = 1536 ; Rx Buffer size
ETH_ALEN = 6
ETH_HLEN = (2 * ETH_ALEN + 2)
ETH_ZLEN = 60 ; 60 + 4bytes auto payload for
; mininmum 64bytes frame length
; MAC address length
MAC_ADDR_LEN = 6
; max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4) ; max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4)
MAX_ETH_FRAME_SIZE = 1536 MAX_ETH_FRAME_SIZE = 1536
TX_FIFO_THRESH = 256 ; In bytes TX_FIFO_THRESH = 256 ; In bytes
RX_FIFO_THRESH = 7 ; 7 means NO threshold, Rx buffer level before first PCI xfer 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 RX_DMA_BURST = 7 ; Maximum PCI burst, '6' is 1024
TX_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 ETTh = 0x3F ; 0x3F means NO threshold
EarlyTxThld = 0x3F ; 0x3F means NO early transmit EarlyTxThld = 0x3F ; 0x3F means NO early transmit
RxPacketMaxSize = 0x0800 ; Maximum size supported is 16K-1 RxPacketMaxSize = 0x0800 ; Maximum size supported is 16K-1
InterFrameGap = 0x03 ; 3 means InterFrameGap = the shortest one InterFrameGap = 0x03 ; 3 means InterFrameGap = the shortest one
HZ = 1000 HZ = 1000
RTL_MIN_IO_SIZE = 0x80 RTL_MIN_IO_SIZE = 0x80
TX_TIMEOUT = (6*HZ) TX_TIMEOUT = (6*HZ)
TIMER_EXPIRE_TIME = 100 TIMER_EXPIRE_TIME = 100
ETH_HDR_LEN = 14 ETH_HDR_LEN = 14
DEFAULT_MTU = 1500 DEFAULT_MTU = 1500
DEFAULT_RX_BUF_LEN = 1536 DEFAULT_RX_BUF_LEN = 1536
;#ifdef JUMBO_FRAME_SUPPORT ;ifdef JUMBO_FRAME_SUPPORT
;#define MAX_JUMBO_FRAME_MTU ( 10000 ) ; MAX_JUMBO_FRAME_MTU = 10000
;#define MAX_RX_SKBDATA_SIZE ( MAX_JUMBO_FRAME_MTU + ETH_HDR_LEN ) ; MAX_RX_SKBDATA_SIZE = (MAX_JUMBO_FRAME_MTU + ETH_HDR_LEN )
;#else ;else
MAX_RX_SKBDATA_SIZE = 1600 MAX_RX_SKBDATA_SIZE = 1600
;#endif //end #ifdef JUMBO_FRAME_SUPPORT ;end if
MCFG_METHOD_01 = 0x01 MCFG_METHOD_01 = 0x01
MCFG_METHOD_02 = 0x02 MCFG_METHOD_02 = 0x02
MCFG_METHOD_03 = 0x03 MCFG_METHOD_03 = 0x03
MCFG_METHOD_04 = 0x04 MCFG_METHOD_04 = 0x04
MCFG_METHOD_05 = 0x05 MCFG_METHOD_05 = 0x05
MCFG_METHOD_11 = 0x0b MCFG_METHOD_11 = 0x0b
MCFG_METHOD_12 = 0x0c MCFG_METHOD_12 = 0x0c
MCFG_METHOD_13 = 0x0d MCFG_METHOD_13 = 0x0d
MCFG_METHOD_14 = 0x0e MCFG_METHOD_14 = 0x0e
MCFG_METHOD_15 = 0x0f MCFG_METHOD_15 = 0x0f
PCFG_METHOD_1 = 0x01 ; PHY Reg 0x03 bit0-3 == 0x0000 PCFG_METHOD_1 = 0x01 ; PHY Reg 0x03 bit0-3 == 0x0000
PCFG_METHOD_2 = 0x02 ; PHY Reg 0x03 bit0-3 == 0x0001 PCFG_METHOD_2 = 0x02 ; PHY Reg 0x03 bit0-3 == 0x0001
PCFG_METHOD_3 = 0x03 ; PHY Reg 0x03 bit0-3 == 0x0002 PCFG_METHOD_3 = 0x03 ; PHY Reg 0x03 bit0-3 == 0x0002
virtual at 0 virtual at 0
tx_desc: tx_desc:
@ -268,6 +259,12 @@ virtual at ebx
.pci_dev db ? .pci_dev db ?
.irq_line db ? .irq_line db ?
rb 256-(($ - device) and 255) ; align 256
.tx_ring rb NUM_TX_DESC * tx_desc.size * 2
rb 256-(($ - device) and 255) ; align 256
.rx_ring rb NUM_RX_DESC * rx_desc.size * 2
tpc: tpc:
.mmio_addr dd ? ; memory map physical address .mmio_addr dd ? ; memory map physical address
.chipset dd ? .chipset dd ?
@ -280,18 +277,12 @@ virtual at ebx
.TxDescArray dd ? ; Index of 256-alignment Tx Descriptor buffer .TxDescArray dd ? ; Index of 256-alignment Tx Descriptor buffer
.RxDescArray dd ? ; Index of 256-alignment Rx Descriptor buffer .RxDescArray dd ? ; Index of 256-alignment Rx Descriptor buffer
rb 256-(($ - device) and 255) ; align 256
tx_ring rb NUM_TX_DESC * tx_desc.size * 2
rb 256-(($ - device) and 255) ; align 256
rx_ring rb NUM_RX_DESC * rx_desc.size * 2
device_size = $ - device device_size = $ - device
end virtual end virtual
intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_TxOK or ISB_RxErr or ISB_RxOK 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 rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E
macro udelay msec { macro udelay msec {
@ -374,7 +365,7 @@ proc START stdcall, state:dword
.entry: .entry:
DEBUGF 2,"Loading rtl8169 driver\n" DEBUGF 2,"Loading %s driver\n", my_service
stdcall RegService, my_service, service_proc stdcall RegService, my_service, service_proc
ret ret
@ -481,14 +472,13 @@ proc service_proc stdcall, ioctl:dword
; Ok, the eth_device structure is ready, let's probe the device ; Ok, the eth_device structure is ready, let's probe the device
; Because initialization fires IRQ, IRQ handler must be aware of this 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 eax, [devices] ; Add the device structure to our device list
mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) mov [device_list + 4*eax], ebx ; (IRQ handler uses this list to find device)
inc [devices] ; inc [devices] ;
call probe ; this function will output in eax call probe ; this function will output in eax
test eax, eax test eax, eax
jnz .err2 ; If an error occured, exit jnz .err2 ; If an error occured, exit
mov [device.type], NET_TYPE_ETH mov [device.type], NET_TYPE_ETH
call NetRegDev call NetRegDev
@ -517,8 +507,6 @@ proc service_proc stdcall, ioctl:dword
.err: .err:
DEBUGF 2,"removing device structure\n" DEBUGF 2,"removing device structure\n"
stdcall KernelFree, ebx stdcall KernelFree, ebx
.fail: .fail:
or eax, -1 or eax, -1
ret ret
@ -586,7 +574,7 @@ init_board:
mov eax, [tpc.mcfg] mov eax, [tpc.mcfg]
@@: dec ecx @@: dec ecx
js @f js @f
cmp eax, [rtl_chip_info+ecx*8] cmp eax, [rtl_chip_info + ecx*8]
jne @b jne @b
mov [tpc.chipset], ecx mov [tpc.chipset], ecx
jmp .match jmp .match
@ -626,9 +614,7 @@ probe:
DEBUGF 1,"probe\n" DEBUGF 1,"probe\n"
call init_board call init_board
call read_mac call read_mac
call PHY_config call PHY_config
; DEBUGF 1,"K : Set MAC Reg C+CR Offset 0x82h = 0x01h\n" ; DEBUGF 1,"K : Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
@ -701,11 +687,11 @@ reset:
DEBUGF 1,"reset\n" DEBUGF 1,"reset\n"
lea eax, [tx_ring] lea eax, [device.tx_ring]
mov [tpc.TxDescArrays], eax mov [tpc.TxDescArrays], eax
mov [tpc.TxDescArray], eax mov [tpc.TxDescArray], eax
lea eax, [rx_ring] lea eax, [device.rx_ring]
mov [tpc.RxDescArrays], eax mov [tpc.RxDescArrays], eax
mov [tpc.RxDescArray], eax mov [tpc.RxDescArray], eax
@ -834,11 +820,11 @@ init_ring:
mov [tpc.cur_rx], eax mov [tpc.cur_rx], eax
mov [tpc.cur_tx], eax mov [tpc.cur_tx], eax
lea edi, [tx_ring] lea edi, [device.tx_ring]
mov ecx, (NUM_TX_DESC * tx_desc.size) / 4 mov ecx, (NUM_TX_DESC * tx_desc.size) / 4
rep stosd rep stosd
lea edi, [rx_ring] lea edi, [device.rx_ring]
mov ecx, (NUM_RX_DESC * rx_desc.size) / 4 mov ecx, (NUM_RX_DESC * rx_desc.size) / 4
rep stosd rep stosd
@ -875,6 +861,7 @@ hw_start:
mov al, CMD_Reset mov al, CMD_Reset
out dx, al out dx, al
DEBUGF 1,"Waiting for chip to reset... "
; Check that the chip has finished the reset ; Check that the chip has finished the reset
mov ecx, 1000 mov ecx, 1000
set_io REG_ChipCmd set_io REG_ChipCmd
@ -884,6 +871,7 @@ hw_start:
udelay 10 udelay 10
loop @b loop @b
@@: @@:
DEBUGF 1,"done!\n"
set_io REG_Cfg9346 set_io REG_Cfg9346
mov al, CFG_9346_Unlock mov al, CFG_9346_Unlock
@ -946,12 +934,12 @@ hw_start:
xor eax, eax xor eax, eax
mov [tpc.cur_rx], eax mov [tpc.cur_rx], eax
lea eax, [tx_ring] lea eax, [device.tx_ring]
GetRealAddr GetRealAddr
set_io REG_TxDescStartAddr set_io REG_TxDescStartAddr
out dx, eax out dx, eax
lea eax, [rx_ring] lea eax, [device.rx_ring]
GetRealAddr GetRealAddr
set_io REG_RxDescStartAddr set_io REG_RxDescStartAddr
out dx, eax out dx, eax
@ -991,7 +979,7 @@ read_mac:
set_io REG_MAC0 set_io REG_MAC0
xor ecx, ecx xor ecx, ecx
lea edi, [device.mac] lea edi, [device.mac]
mov ecx, MAC_ADDR_LEN mov ecx, 6
; Get MAC address. FIXME: read EEPROM ; Get MAC address. FIXME: read EEPROM
@@: in al, dx @@: in al, dx
@ -999,7 +987,8 @@ read_mac:
inc edx inc edx
loop @r loop @r
DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",[device.mac+0]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\
[device.mac+0]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2
ret ret
@ -1040,7 +1029,7 @@ transmit:
mov eax, tx_desc.size mov eax, tx_desc.size
mul [tpc.cur_tx] mul [tpc.cur_tx]
lea esi, [eax + tx_ring] lea esi, [eax + device.tx_ring]
DEBUGF 1,"Using TX desc: %x\n", esi DEBUGF 1,"Using TX desc: %x\n", esi
@ -1080,7 +1069,7 @@ transmit:
; Update stats ; Update stats
inc [device.packets_tx] inc [device.packets_tx]
mov eax, [esp+8] mov eax, [esp + 8]
add dword [device.bytes_tx], eax add dword [device.bytes_tx], eax
adc dword [device.bytes_tx + 4], 0 adc dword [device.bytes_tx + 4], 0
@ -1151,7 +1140,7 @@ int_handler:
DEBUGF 1,"ebx = 0x%x\n", ebx DEBUGF 1,"ebx = 0x%x\n", ebx
mov eax, rx_desc.size mov eax, rx_desc.size
mul [tpc.cur_rx] mul [tpc.cur_rx]
lea esi, [eax + rx_ring] lea esi, [eax + device.rx_ring]
DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status] DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
@ -1219,19 +1208,19 @@ int_handler:
DEBUGF 1,"TX ok!\n" DEBUGF 1,"TX ok!\n"
mov ecx, NUM_TX_DESC mov ecx, NUM_TX_DESC
lea esi, [tx_ring] lea esi, [device.tx_ring]
.txloop: .txloop:
cmp [esi+tx_desc.buf_soft_addr], 0 cmp [esi + tx_desc.buf_soft_addr], 0
jz .maybenext jz .maybenext
test [esi+tx_desc.status], DSB_OWNbit test [esi + tx_desc.status], DSB_OWNbit
jnz .maybenext jnz .maybenext
push ecx push ecx
DEBUGF 1,"Freeing up TX desc: %x\n", esi DEBUGF 1,"Freeing up TX desc: %x\n", esi
stdcall KernelFree, [esi+tx_desc.buf_soft_addr] stdcall KernelFree, [esi + tx_desc.buf_soft_addr]
pop ecx pop ecx
and [esi+tx_desc.buf_soft_addr], 0 and [esi + tx_desc.buf_soft_addr], 0
.maybenext: .maybenext:
add esi, tx_desc.size add esi, tx_desc.size