Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6717 → Rev 6716

/drivers/ethernet/i8255x.asm
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; i8255x (Intel eepro 100) driver for KolibriOS ;;
43,28 → 43,14
include '../fdo.inc'
include '../netdrv.inc'
 
; I/O registers
REG_SCB_STATUS = 0
REG_SCB_CMD = 2
REG_SCB_PTR = 4
REG_PORT = 8
REG_EEPROM = 14
REG_MDI_CTRL = 16
; Serial EEPROM
 
; Port commands
PORT_SOFT_RESET = 0x0
PORT_SELF_TEST = 0x1
PORT_SELECTIVE_RESET = 0x2
PORT_DUMP = 0x3
PORT_DUMP_WAKEUP = 0x7
PORT_PTR_MASK = 0xfffffff0
 
; Serial EEPROM
EE_SK = 1 shl 0 ; serial clock
EE_CS = 1 shl 1 ; chip select
EE_DI = 1 shl 2 ; data in
EE_DO = 1 shl 3 ; data out
EE_MASK = EE_SK + EE_CS + EE_DI + EE_DO
 
; opcodes, first bit is start bit and must be 1
EE_READ = 110b
EE_WRITE = 101b
71,6 → 57,7
EE_ERASE = 111b
 
; The SCB accepts the following controls for the Tx and Rx units:
 
CU_START = 0x0010
CU_RESUME = 0x0020
CU_STATSADDR = 0x0040
86,6 → 73,13
INT_MASK = 0x0100
DRVR_INT = 0x0200 ; Driver generated interrupt
 
REG_SCB_STATUS = 0
REG_SCB_CMD = 2
REG_SCB_PTR = 4
REG_PORT = 8
REG_EEPROM = 14
REG_MDI_CTRL = 16
 
PHY_100a = 0x000003E0
PHY_100c = 0x035002A8
PHY_82555_tx = 0x015002A8
324,7 → 318,7
mov [ebx + device.reset], reset
mov [ebx + device.transmit], transmit
mov [ebx + device.unload], unload
mov [ebx + device.name], devicename
mov [ebx + device.name], my_service
 
; save the pci bus and device numbers
 
344,19 → 338,24
invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
mov [ebx + device.irq_line], al
 
DEBUGF 1,"Hooking into device, devfn:%x, bus:%x, irq:%x, addr:%x\n",\
[ebx + device.pci_dev]:2,[ebx + device.pci_bus]:2,[ebx + device.irq_line]:2,[ebx + device.io_addr]:4
DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
[ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:4
 
; 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] ;
pushf
cli ; disable ints untilm initialisation is done
 
call probe ; this function will output in eax
test eax, eax
jnz .err ; If an error occured, exit
 
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] ;
 
popf
 
mov [ebx + device.type], NET_TYPE_ETH
invoke NetRegDev
 
376,6 → 375,7
ret
 
; If an error occured, remove all allocated data and exit (returning -1 in eax)
 
.err:
invoke KernelFree, ebx
 
423,7 → 423,7
 
; Make the device a bus master
invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
or al, PCI_CMD_MASTER or PCI_CMD_PIO
or al, PCI_CMD_MASTER
invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
 
;---------------------------
452,8 → 452,13
 
.found:
 
call ee_get_width
call MAC_read_eeprom
 
;;; TODO: detect phy
 
 
 
;----------
;
; Reset
475,46 → 480,17
 
DEBUGF 1,"Resetting\n"
 
;----------------
; Selective reset
;---------------
; reset the card
 
set_io [ebx + device.io_addr], 0
set_io [ebx + device.io_addr], REG_EEPROM
mov eax, PORT_SELECTIVE_RESET
out dx, eax
 
mov esi, 1
invoke Sleep
 
;-----------
; Soft reset
 
set_io [ebx + device.io_addr], REG_PORT
mov eax, PORT_SOFT_RESET
xor eax, eax ; Software Reset
out dx, eax
 
mov esi, 10
invoke Sleep
invoke Sleep ; Give the card time to warm up.
 
;-------------
; Read PHY IDs
 
mov cx, 1
mov dx, MII_PHYSID1
call mdio_read
DEBUGF 1, "PHY ID1: 0x%x\n", ax
 
mov cx, 1
mov dx, MII_PHYSID2
call mdio_read
DEBUGF 1, "PHY ID2: 0x%x\n", ax
 
;---------------------
; Read MAC from eeprom
 
call ee_get_width
call mac_read_eeprom
 
;---------------------------------
; Tell device where to store stats
 
1015,8 → 991,8
movzx ecx, [ebx + device.ee_bus_width]
add ecx, 3
 
mov ax, 0x4800 + EE_CS
out dx, ax
mov al, EE_CS
out dx, al
call udelay
 
;-----------------------
1023,7 → 999,7
; Write this to the chip
 
.loop:
mov al, EE_CS
mov al, EE_CS + EE_SK
shl esi, 1
jnc @f
or al, EE_DI
1031,7 → 1007,7
out dx, al
call udelay
 
or al, EE_SK
and al, not EE_SK
out dx, al
call udelay
 
1045,14 → 1021,10
 
.loop2:
shl esi, 1
mov al, EE_CS
mov al, EE_CS + EE_SK
out dx, al
call udelay
 
or al, EE_SK
out dx, al
call udelay
 
in al, dx
test al, EE_DO
jz @f
1059,14 → 1031,19
inc esi
@@:
 
mov al, EE_CS
out dx, al
call udelay
 
loop .loop2
 
;-----------------------
; de-activate the eeprom
 
xor al, al
out dx, al
xor ax, ax
out dx, ax
 
 
DEBUGF 1,"0x%x\n", esi:4
ret
 
1092,14 → 1069,14
movzx ecx, [ebx + device.ee_bus_width]
add ecx, 3
 
mov ax, 0x4800 + EE_CS ; enable chip
out dx, ax
mov al, EE_CS ; enable chip
out dx, al
 
;-----------------------
; Write this to the chip
 
.loop:
mov al, EE_CS
mov al, EE_CS + EE_SK
shl esi, 1
jnc @f
or al, EE_DI
1107,7 → 1084,7
out dx, al
call udelay
 
or al, EE_SK
and al, not EE_SK
out dx, al
call udelay
 
1119,7 → 1096,7
mov ecx, 16
 
.loop2:
mov al, EE_CS
mov al, EE_CS + EE_SK
shl di, 1
jnc @f
or al, EE_DI
1127,7 → 1104,7
out dx, al
call udelay
 
or al, EE_SK
and al, not EE_SK
out dx, al
call udelay
 
1150,23 → 1127,23
set_io [ebx + device.io_addr], 0
set_io [ebx + device.io_addr], REG_EEPROM
 
mov ax, 0x4800 + EE_CS ; activate eeprom
out dx, ax
mov al, EE_CS ; activate eeprom
out dx, al
call udelay
 
mov si, EE_READ shl 13
xor ecx, ecx
.loop:
mov al, EE_CS
mov al, EE_CS + EE_SK
shl si, 1
jnc @f
or al, EE_DI
@@:
out dx, ax
out dx, al
call udelay
 
or al, EE_SK
out dx, ax
and al, not EE_SK
out dx, al
call udelay
 
inc ecx
1189,6 → 1166,7
 
.give_up:
DEBUGF 2, "Eeprom not found!\n"
 
xor al, al
out dx, al ; de-activate eeprom
 
1217,8 → 1195,9
DEBUGF 1,"MDIO read\n"
 
shl ecx, 21 ; PHY addr
shl edx, 16 ; PHY reg addr
 
mov eax, ecx
shl edx, 16 ; PHY reg addr
or eax, edx
or eax, 10b shl 26 ; read opcode
 
1234,8 → 1213,6
 
ret
 
 
 
; ax = data
; cx = phy addr
; dx = phy reg addr
1268,9 → 1245,14
 
ret
 
read_mac:
 
ret
 
 
 
align 4
mac_read_eeprom:
MAC_read_eeprom:
 
mov esi, 0
call ee_read
1288,6 → 1270,16
ret
 
 
align 4
MAC_write:
 
;;;;
 
ret
 
 
 
 
; End of code
 
 
1305,6 → 1297,7
 
 
device_id_list:
 
dw 0x1029
dw 0x1030
dw 0x1031