2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 21:10:22 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; MTD80x driver for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Based on mtd80x.c from the etherboot project ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
format PE DLL native
|
|
|
|
entry START
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
CURRENT_API = 0x0200
|
|
|
|
COMPATIBLE_API = 0x0100
|
|
|
|
API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
MAX_DEVICES = 16
|
|
|
|
|
|
|
|
__DEBUG__ = 1
|
|
|
|
__DEBUG_LEVEL__ = 2
|
|
|
|
|
2014-02-19 16:48:17 +01:00
|
|
|
NUM_TX_DESC = 6
|
|
|
|
NUM_RX_DESC = 12
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01: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
|
|
|
|
|
|
|
; for different PHY
|
|
|
|
|
|
|
|
MysonPHY = 1
|
|
|
|
AhdocPHY = 2
|
|
|
|
SeeqPHY = 3
|
|
|
|
MarvellPHY = 4
|
|
|
|
Myson981 = 5
|
|
|
|
LevelOnePHY = 6
|
|
|
|
OtherPHY = 10
|
|
|
|
|
|
|
|
; Offsets to the Command and Status Registers.
|
|
|
|
|
|
|
|
PAR0 = 0x0 ; physical address 0-3
|
|
|
|
PAR1 = 0x04 ; physical address 4-5
|
|
|
|
MAR0 = 0x08 ; multicast address 0-3
|
|
|
|
MAR1 = 0x0C ; multicast address 4-7
|
|
|
|
FAR0 = 0x10 ; flow-control address 0-3
|
|
|
|
FAR1 = 0x14 ; flow-control address 4-5
|
|
|
|
TCRRCR = 0x18 ; receive & transmit configuration
|
|
|
|
BCR = 0x1C ; bus command
|
|
|
|
TXPDR = 0x20 ; transmit polling demand
|
|
|
|
RXPDR = 0x24 ; receive polling demand
|
|
|
|
RXCWP = 0x28 ; receive current word pointer
|
|
|
|
TXLBA = 0x2C ; transmit list base address
|
|
|
|
RXLBA = 0x30 ; receive list base address
|
|
|
|
ISR = 0x34 ; interrupt status
|
|
|
|
IMR = 0x38 ; interrupt mask
|
|
|
|
FTH = 0x3C ; flow control high/low threshold
|
|
|
|
MANAGEMENT = 0x40 ; bootrom/eeprom and mii management
|
|
|
|
TALLY = 0x44 ; tally counters for crc and mpa
|
|
|
|
TSR = 0x48 ; tally counter for transmit status
|
|
|
|
BMCRSR = 0x4c ; basic mode control and status
|
|
|
|
PHYIDENTIFIER = 0x50 ; phy identifier
|
|
|
|
ANARANLPAR = 0x54 ; auto-negotiation advertisement and link partner ability
|
|
|
|
ANEROCR = 0x58 ; auto-negotiation expansion and pci conf.
|
|
|
|
BPREMRPSR = 0x5c ; bypass & receive error mask and phy status
|
|
|
|
|
|
|
|
; Bits in the interrupt status/enable registers.
|
|
|
|
|
|
|
|
RFCON = 0x00020000 ; receive flow control xon packet
|
|
|
|
RFCOFF = 0x00010000 ; receive flow control xoff packet
|
|
|
|
LSCStatus = 0x00008000 ; link status change
|
|
|
|
ANCStatus = 0x00004000 ; autonegotiation completed
|
|
|
|
FBE = 0x00002000 ; fatal bus error
|
|
|
|
FBEMask = 0x00001800 ; mask bit12-11
|
|
|
|
ParityErr = 0x00000000 ; parity error
|
|
|
|
TargetErr = 0x00001000 ; target abort
|
|
|
|
MasterErr = 0x00000800 ; master error
|
|
|
|
TUNF = 0x00000400 ; transmit underflow
|
|
|
|
ROVF = 0x00000200 ; receive overflow
|
|
|
|
ETI = 0x00000100 ; transmit early int
|
|
|
|
ERI = 0x00000080 ; receive early int
|
|
|
|
CNTOVF = 0x00000040 ; counter overflow
|
|
|
|
RBU = 0x00000020 ; receive buffer unavailable
|
|
|
|
TBU = 0x00000010 ; transmit buffer unavilable
|
|
|
|
TI = 0x00000008 ; transmit interrupt
|
|
|
|
RI = 0x00000004 ; receive interrupt
|
|
|
|
RxErr = 0x00000002 ; receive error
|
|
|
|
|
|
|
|
; Bits in the NetworkConfig register.
|
|
|
|
|
|
|
|
RxModeMask = 0xe0
|
|
|
|
AcceptAllPhys = 0x80 ; promiscuous mode
|
|
|
|
AcceptBroadcast = 0x40 ; accept broadcast
|
|
|
|
AcceptMulticast = 0x20 ; accept mutlicast
|
|
|
|
AcceptRunt = 0x08 ; receive runt pkt
|
|
|
|
ALP = 0x04 ; receive long pkt
|
|
|
|
AcceptErr = 0x02 ; receive error pkt
|
|
|
|
|
|
|
|
AcceptMyPhys = 0x00000000
|
|
|
|
RxEnable = 0x00000001
|
|
|
|
RxFlowCtrl = 0x00002000
|
|
|
|
TxEnable = 0x00040000
|
|
|
|
TxModeFDX = 0x00100000
|
|
|
|
TxThreshold = 0x00e00000
|
|
|
|
|
|
|
|
PS1000 = 0x00010000
|
|
|
|
PS10 = 0x00080000
|
|
|
|
FD = 0x00100000
|
|
|
|
|
|
|
|
|
|
|
|
; Bits in network_desc.status
|
|
|
|
|
|
|
|
RXOWN = 0x80000000 ; own bit
|
|
|
|
FLNGMASK = 0x0fff0000 ; frame length
|
|
|
|
FLNGShift = 16
|
|
|
|
MARSTATUS = 0x00004000 ; multicast address received
|
|
|
|
BARSTATUS = 0x00002000 ; broadcast address received
|
|
|
|
PHYSTATUS = 0x00001000 ; physical address received
|
|
|
|
RXFSD = 0x00000800 ; first descriptor
|
|
|
|
RXLSD = 0x00000400 ; last descriptor
|
|
|
|
ErrorSummary = 0x80 ; error summary
|
|
|
|
RUNT = 0x40 ; runt packet received
|
|
|
|
LONG = 0x20 ; long packet received
|
|
|
|
FAE = 0x10 ; frame align error
|
|
|
|
CRC = 0x08 ; crc error
|
|
|
|
RXER = 0x04 ; receive error
|
|
|
|
|
|
|
|
; rx_desc_control_bits
|
|
|
|
|
|
|
|
RXIC = 0x00800000 ; interrupt control
|
|
|
|
RBSShift = 0
|
|
|
|
|
|
|
|
; tx_desc_status_bits
|
|
|
|
|
|
|
|
TXOWN = 0x80000000 ; own bit
|
|
|
|
JABTO = 0x00004000 ; jabber timeout
|
|
|
|
CSL = 0x00002000 ; carrier sense lost
|
|
|
|
LC = 0x00001000 ; late collision
|
|
|
|
EC = 0x00000800 ; excessive collision
|
|
|
|
UDF = 0x00000400 ; fifo underflow
|
|
|
|
DFR = 0x00000200 ; deferred
|
|
|
|
HF = 0x00000100 ; heartbeat fail
|
|
|
|
NCRMask = 0x000000ff ; collision retry count
|
|
|
|
NCRShift = 0
|
|
|
|
|
|
|
|
; tx_desc_control_bits
|
|
|
|
|
|
|
|
TXIC = 0x80000000 ; interrupt control
|
|
|
|
ETIControl = 0x40000000 ; early transmit interrupt
|
|
|
|
TXLD = 0x20000000 ; last descriptor
|
|
|
|
TXFD = 0x10000000 ; first descriptor
|
|
|
|
CRCEnable = 0x08000000 ; crc control
|
|
|
|
PADEnable = 0x04000000 ; padding control
|
|
|
|
RetryTxLC = 0x02000000 ; retry late collision
|
|
|
|
PKTSMask = 0x3ff800 ; packet size bit21-11
|
|
|
|
PKTSShift = 11
|
|
|
|
TBSMask = 0x000007ff ; transmit buffer bit 10-0
|
|
|
|
TBSShift = 0
|
|
|
|
|
|
|
|
; BootROM/EEPROM/MII Management Register
|
|
|
|
|
|
|
|
MASK_MIIR_MII_READ = 0x00000000
|
|
|
|
MASK_MIIR_MII_WRITE = 0x00000008
|
|
|
|
MASK_MIIR_MII_MDO = 0x00000004
|
|
|
|
MASK_MIIR_MII_MDI = 0x00000002
|
|
|
|
MASK_MIIR_MII_MDC = 0x00000001
|
|
|
|
|
|
|
|
; ST+OP+PHYAD+REGAD+TA
|
|
|
|
|
|
|
|
OP_READ = 0x6000 ; ST:01+OP:10+PHYAD+REGAD+TA:Z0
|
|
|
|
OP_WRITE = 0x5002 ; ST:01+OP:01+PHYAD+REGAD+TA:10
|
|
|
|
|
|
|
|
; -------------------------------------------------------------------------
|
|
|
|
; Constants for Myson PHY
|
|
|
|
; -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MysonPHYID = 0xd0000302
|
|
|
|
MysonPHYID0 = 0x0302
|
|
|
|
StatusRegister = 18
|
|
|
|
SPEED100 = 0x0400 ; bit10
|
|
|
|
FULLMODE = 0x0800 ; bit11
|
|
|
|
|
|
|
|
; -------------------------------------------------------------------------
|
|
|
|
; Constants for Seeq 80225 PHY
|
|
|
|
; -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SeeqPHYID0 = 0x0016
|
|
|
|
MIIRegister18 = 18
|
|
|
|
SPD_DET_100 = 0x80
|
|
|
|
DPLX_DET_FULL = 0x40
|
|
|
|
|
|
|
|
; -------------------------------------------------------------------------
|
|
|
|
; Constants for Ahdoc 101 PHY
|
|
|
|
; -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
AhdocPHYID0 = 0x0022
|
|
|
|
DiagnosticReg = 18
|
|
|
|
DPLX_FULL = 0x0800
|
|
|
|
Speed_100 = 0x0400
|
|
|
|
|
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MarvellPHYID0 = 0x0141
|
|
|
|
LevelOnePHYID0 = 0x0013
|
|
|
|
|
|
|
|
MII1000BaseTControlReg = 9
|
|
|
|
MII1000BaseTStatusReg = 10
|
|
|
|
SpecificReg = 17
|
|
|
|
|
|
|
|
; for 1000BaseT Control Register
|
|
|
|
|
|
|
|
PHYAbletoPerform1000FullDuplex = 0x0200
|
|
|
|
PHYAbletoPerform1000HalfDuplex = 0x0100
|
|
|
|
PHY1000AbilityMask = 0x300
|
|
|
|
|
|
|
|
; for phy specific status register, marvell phy.
|
|
|
|
|
|
|
|
SpeedMask = 0x0c000
|
|
|
|
Speed_1000M = 0x08000
|
|
|
|
Speed_100M = 0x4000
|
|
|
|
Speed_10M = 0
|
|
|
|
Full_Duplex = 0x2000
|
|
|
|
|
|
|
|
; for phy specific status register, levelone phy
|
|
|
|
|
|
|
|
LXT1000_100M = 0x08000
|
|
|
|
LXT1000_1000M = 0x0c000
|
|
|
|
LXT1000_Full = 0x200
|
|
|
|
|
|
|
|
; for PHY
|
|
|
|
|
|
|
|
LinkIsUp = 0x0004
|
|
|
|
LinkIsUp2 = 0x00040000
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
struct descriptor
|
|
|
|
status dd ?
|
|
|
|
control dd ?
|
|
|
|
buffer dd ?
|
|
|
|
next_desc dd ?
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
next_desc_logical dd ?
|
|
|
|
skbuff dd ?
|
|
|
|
reserved1 dd ?
|
|
|
|
reserved2 dd ?
|
|
|
|
ends
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
struct device ETH_DEVICE
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
io_addr dd ?
|
|
|
|
pci_bus dd ?
|
|
|
|
pci_dev dd ?
|
|
|
|
irq_line db ?
|
|
|
|
dev_id dw ?
|
|
|
|
flags dd ?
|
|
|
|
crvalue dd ?
|
|
|
|
bcrvalue dd ?
|
|
|
|
cur_rx dd ?
|
|
|
|
cur_tx dd ?
|
|
|
|
default_port dd ?
|
|
|
|
PHYType dd ?
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; MII transceiver section.
|
2014-02-20 20:35:01 +01:00
|
|
|
mii_cnt dd ? ; MII device addresses.
|
|
|
|
phys db ? ; MII device addresses.
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
; descriptors
|
|
|
|
rb 0x100 - ($ and 0xff) ; align 256
|
|
|
|
tx_desc rb NUM_TX_DESC*sizeof.descriptor
|
|
|
|
rx_desc rb NUM_RX_DESC*sizeof.descriptor
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
ends
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc START ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
proc START c, reason:dword, cmdline:dword
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp [reason], DRV_ENTRY
|
|
|
|
jne .fail
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 1,"Loading driver\n"
|
|
|
|
invoke RegService, my_service, service_proc
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
2014-02-20 20:35:01 +01: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
|
|
|
|
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-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-02-20 20:35:01 +01:00
|
|
|
cmp al, byte[ebx + device.pci_bus]
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp ah, byte[ebx + device.pci_dev]
|
2013-05-28 19:34:26 +02: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-20 20:35:01 +01:00
|
|
|
allocate_and_clear ebx, sizeof.device, .fail
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Fill in the direct call addresses into the struct
|
|
|
|
|
2014-02-20 20:35:01 +01: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-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.pci_bus], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
movzx ecx, byte[eax+2]
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.pci_dev], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Now, it's time to find the base io addres of the PCI device
|
|
|
|
|
2014-02-20 20:35:01 +01: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-02-20 20:35:01 +01: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
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
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]: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-02-20 20:35:01 +01: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-02-20 20:35:01 +01: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-02-20 20:35:01 +01:00
|
|
|
invoke KernelFree, ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
.fail:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
|
|
|
|
;; ;;
|
|
|
|
;; Actual Hardware dependent code starts here ;;
|
|
|
|
;; ;;
|
|
|
|
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
unload:
|
|
|
|
; TODO: (in this particular order)
|
|
|
|
;
|
|
|
|
; - Stop the device
|
|
|
|
|
|
|
|
; /* Disable Tx Rx*/
|
|
|
|
; outl( mtdx.crvalue & (~TxEnable) & (~RxEnable), mtdx.ioaddr + TCRRCR );
|
|
|
|
;
|
|
|
|
; /* Reset the chip to erase previous misconfiguration. */
|
|
|
|
; mtd_reset(nic);
|
|
|
|
|
|
|
|
; - Detach int handler
|
|
|
|
; - Remove device from local list (device_list)
|
|
|
|
; - call unregister function in kernel
|
|
|
|
; - Remove all allocated structures and buffers the card used
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
or eax, -1
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
;-------
|
|
|
|
;
|
|
|
|
; PROBE
|
|
|
|
;
|
|
|
|
;-------
|
|
|
|
align 4
|
|
|
|
probe:
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 1,"Probing\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01: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 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
; Check vendor/device id's
|
2014-03-11 15:29:10 +01:00
|
|
|
invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ax, 0x1516
|
|
|
|
jne .notfound
|
|
|
|
shr eax, 16
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.dev_id], ax
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ax, 0x0800
|
2014-02-20 20:35:01 +01:00
|
|
|
je .mtd800
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ax, 0x0803
|
2014-02-20 20:35:01 +01:00
|
|
|
je .mtd803
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ax, 0x0891
|
2014-02-20 20:35:01 +01:00
|
|
|
je .mtd891
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.notfound:
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 2,"Device not supported!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
dec eax
|
|
|
|
ret
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
.mtd803:
|
|
|
|
mov [ebx + device.name], sz_mtd803
|
2013-05-28 19:34:26 +02:00
|
|
|
DEBUGF 1,"Device has chip xcvr\n"
|
2014-02-20 20:35:01 +01:00
|
|
|
jmp .xcvr_set
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
.mtd800:
|
|
|
|
DEBUGF 1,"Device has mii xcvr\n"
|
|
|
|
mov [ebx + device.name], sz_mtd800
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp .xcvr_set
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
.mtd891:
|
2013-05-28 19:34:26 +02:00
|
|
|
DEBUGF 1,"Device has mii xcvr\n"
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.name], sz_mtd800
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.xcvr_set:
|
|
|
|
call read_mac
|
|
|
|
|
|
|
|
; Reset the chip to erase previous misconfiguration.
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], BCR
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
; find the connected MII xcvrs
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp [ebx + device.dev_id], 0x0803
|
2013-05-28 19:34:26 +02:00
|
|
|
je .is_803
|
|
|
|
|
|
|
|
; int phy, phy_idx = 0;
|
|
|
|
;
|
|
|
|
; for (phy = 1; phy < 32 && phy_idx < 1; phy++) {
|
|
|
|
; int mii_status = mdio_read(nic, phy, 1);
|
|
|
|
;
|
|
|
|
; if (mii_status != 0xffff && mii_status != 0x0000) {
|
|
|
|
; mtdx.phys[phy_idx] = phy;
|
|
|
|
;
|
|
|
|
; DBG ( "%s: MII PHY found at address %d, status "
|
|
|
|
; "0x%4.4x.\n", mtdx.nic_name, phy, mii_status );
|
|
|
|
; /* get phy type */
|
|
|
|
; {
|
|
|
|
; unsigned int data;
|
|
|
|
;
|
|
|
|
; data = mdio_read(nic, mtdx.phys[phy_idx], 2);
|
|
|
|
; if (data equ= SeeqPHYID0)
|
|
|
|
; mtdx.PHYType = SeeqPHY;
|
|
|
|
; else if (data equ= AhdocPHYID0)
|
|
|
|
; mtdx.PHYType = AhdocPHY;
|
|
|
|
; else if (data equ= MarvellPHYID0)
|
|
|
|
; mtdx.PHYType = MarvellPHY;
|
|
|
|
; else if (data equ= MysonPHYID0)
|
|
|
|
; mtdx.PHYType = Myson981;
|
|
|
|
; else if (data equ= LevelOnePHYID0)
|
|
|
|
; mtdx.PHYType = LevelOnePHY;
|
|
|
|
; else
|
|
|
|
; mtdx.PHYType = OtherPHY;
|
|
|
|
; }
|
|
|
|
; phy_idx++;
|
|
|
|
; }
|
|
|
|
; }
|
|
|
|
;
|
|
|
|
; mtdx.mii_cnt = phy_idx;
|
|
|
|
; if (phy_idx equ= 0) {
|
|
|
|
; printf("%s: MII PHY not found -- this device may "
|
|
|
|
; "not operate correctly.\n", mtdx.nic_name);
|
|
|
|
; }
|
|
|
|
|
|
|
|
jmp .no_803
|
|
|
|
|
|
|
|
.is_803:
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.phys], 32
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; get phy type
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], PHYIDENTIFIER
|
2013-05-28 19:34:26 +02:00
|
|
|
in eax, dx
|
|
|
|
|
|
|
|
cmp eax, MysonPHYID
|
|
|
|
jne @f
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.PHYType], MysonPHY
|
|
|
|
DEBUGF 1,"Myson PHY\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp .no_803
|
|
|
|
@@:
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.PHYType], OtherPHY
|
|
|
|
DEBUGF 1,"Other PHY\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
.no_803:
|
|
|
|
|
|
|
|
;-------
|
|
|
|
;
|
|
|
|
; RESET
|
|
|
|
;
|
|
|
|
;-------
|
|
|
|
align 4
|
|
|
|
reset:
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
DEBUGF 1,"Resetting\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
; attach irq handler
|
|
|
|
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-02-20 20:35:01 +01:00
|
|
|
invoke AttachIntHandler, eax, int_handler, ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 2,"Could not attach int handler!\n"
|
2014-02-19 16:48:17 +01:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
|
|
|
|
|
|
|
; Reset the chip to erase previous misconfiguration.
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], BCR
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
call init_ring
|
|
|
|
|
|
|
|
; Initialize other registers.
|
|
|
|
; Configure the PCI bus bursts and FIFO thresholds.
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.bcrvalue], 0x10 ; little-endian, 8 burst length
|
|
|
|
mov [ebx + device.crvalue], 0xa00 ; 128 burst length
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp [ebx + device.dev_id], 0x891
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
2014-02-20 20:35:01 +01:00
|
|
|
or [ebx + device.bcrvalue], 0x200 ; set PROG bit
|
|
|
|
or [ebx + device.crvalue], 0x02000000 ; set enhanced bit
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
2014-02-20 20:35:01 +01:00
|
|
|
or [ebx + device.crvalue], RxEnable + TxThreshold + TxEnable
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
call set_rx_mode
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], BCR
|
|
|
|
mov eax, [ebx + device.bcrvalue]
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], TCRRCR
|
|
|
|
mov eax, [ebx + device.crvalue]
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
call getlinkstatus
|
|
|
|
|
|
|
|
; Restart Rx engine if stopped.
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], RXPDR
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
; Enable interrupts
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], ISR
|
2014-02-19 16:48:17 +01:00
|
|
|
mov eax, FBE or TUNF or CNTOVF or RBU or TI or RI
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], IMR
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
; clear packet/byte counters
|
|
|
|
xor eax, eax
|
2014-02-20 20:35:01 +01:00
|
|
|
lea edi, [ebx + device.bytes_tx]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, 6
|
|
|
|
rep stosd
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.mtu], 1514
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
init_ring:
|
|
|
|
|
|
|
|
DEBUGF 1,"initializing rx and tx ring\n"
|
|
|
|
|
|
|
|
; Initialize all Rx descriptors
|
2014-02-20 20:35:01 +01:00
|
|
|
lea esi, [ebx + device.rx_desc]
|
|
|
|
mov [ebx + device.cur_rx], esi
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, NUM_RX_DESC
|
|
|
|
.rx_desc_loop:
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.status], RXOWN
|
|
|
|
mov [esi + descriptor.control], 1536 shl RBSShift
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
lea eax, [esi + sizeof.descriptor]
|
|
|
|
mov [esi + descriptor.next_desc_logical], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
push ecx esi
|
2014-02-20 20:35:01 +01:00
|
|
|
invoke GetPhysAddr
|
|
|
|
mov [esi + descriptor.next_desc], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
invoke KernelAlloc, 1536
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi
|
|
|
|
push esi
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.skbuff], eax
|
|
|
|
invoke GetPgAddr
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi ecx
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.buffer], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
add esi, sizeof.descriptor
|
2013-05-28 19:34:26 +02:00
|
|
|
loop .rx_desc_loop
|
|
|
|
|
|
|
|
; Mark the last entry as wrapping the ring.
|
2014-02-20 20:35:01 +01:00
|
|
|
lea eax, [ebx + device.rx_desc]
|
|
|
|
mov [esi - sizeof.descriptor + descriptor.next_desc_logical], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
push esi
|
2014-02-20 20:35:01 +01:00
|
|
|
invoke GetPhysAddr
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi - sizeof.descriptor + descriptor.next_desc], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], RXLBA
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
; Initialize all Tx descriptors
|
2014-02-20 20:35:01 +01:00
|
|
|
lea esi, [ebx + device.tx_desc]
|
|
|
|
mov [ebx + device.cur_tx], esi
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, NUM_TX_DESC
|
|
|
|
.tx_desc_loop:
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.status], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
lea eax, [esi + sizeof.descriptor]
|
|
|
|
mov [esi + descriptor.next_desc_logical], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
push ecx esi
|
2014-02-20 20:35:01 +01:00
|
|
|
invoke GetPhysAddr
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi ecx
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.next_desc], eax
|
|
|
|
mov [esi + descriptor.skbuff], 0
|
|
|
|
add esi, sizeof.descriptor
|
2013-05-28 19:34:26 +02:00
|
|
|
loop .tx_desc_loop
|
|
|
|
|
|
|
|
; Mark the last entry as wrapping the ring.
|
2014-02-20 20:35:01 +01:00
|
|
|
lea eax, [ebx + device.tx_desc]
|
|
|
|
mov [esi - sizeof.descriptor + descriptor.next_desc_logical], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
push esi
|
2014-02-20 20:35:01 +01:00
|
|
|
invoke GetPhysAddr
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi - sizeof.descriptor + descriptor.next_desc], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], TXLBA
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
set_rx_mode:
|
|
|
|
|
|
|
|
DEBUGF 1,"Setting RX mode\n"
|
|
|
|
|
|
|
|
; Too many to match, or accept all multicasts.
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], MAR0
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
out dx, eax
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], MAR1
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, eax
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
and [ebx + device.crvalue], not (RxModeMask)
|
|
|
|
or [ebx + device.crvalue], AcceptBroadcast + AcceptMulticast + AcceptMyPhys
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
getlinkstatus:
|
|
|
|
|
|
|
|
DEBUGF 1,"Getting link status\n"
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [ebx + device.state], ETH_LINK_DOWN ; assume link is dead
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp [ebx + device.PHYType], MysonPHY
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .no_myson_phy
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], BMCRSR
|
2013-05-28 19:34:26 +02:00
|
|
|
in eax, dx
|
|
|
|
test eax, LinkIsUp2
|
2014-02-20 20:35:01 +01:00
|
|
|
jnz getlinktype
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.no_myson_phy:
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], BMCRSR
|
|
|
|
in eax, dx
|
|
|
|
test eax, LinkIsUp
|
|
|
|
jnz getlinktype
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
getlinktype:
|
|
|
|
|
|
|
|
DEBUGF 1,"Getting link type\n"
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp [ebx + device.PHYType], MysonPHY
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .no_myson_phy
|
|
|
|
|
|
|
|
DEBUGF 1,"myson PHY\n"
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], TCRRCR
|
2013-05-28 19:34:26 +02:00
|
|
|
in eax, dx
|
|
|
|
test eax, FD
|
2014-02-20 20:35:01 +01:00
|
|
|
jz @f
|
2013-05-28 19:34:26 +02:00
|
|
|
DEBUGF 1,"full duplex\n"
|
2014-02-20 20:35:01 +01:00
|
|
|
or [ebx + device.state], ETH_LINK_FD
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
|
|
|
test eax, PS10
|
2014-02-20 20:35:01 +01:00
|
|
|
jnz @f
|
2013-05-28 19:34:26 +02:00
|
|
|
DEBUGF 1,"100mbit\n"
|
2014-02-20 20:35:01 +01:00
|
|
|
or [ebx + device.state], ETH_LINK_100M
|
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 1,"10mbit\n"
|
|
|
|
or [ebx + device.state], ETH_LINK_10M
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.no_myson_phy:
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 1,"not a myson PHY\n"
|
|
|
|
mov [ebx + device.state], ETH_LINK_UNKNOWN
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; if (mtdx.PHYType equ= SeeqPHY) { /* this PHY is SEEQ 80225 */
|
|
|
|
; unsigned int data;
|
|
|
|
;
|
|
|
|
; data = mdio_read(dev, mtdx.phys[0], MIIRegister18);
|
|
|
|
; if (data & SPD_DET_100)
|
|
|
|
; mtdx.line_speed = 2; /* 100M */
|
|
|
|
; else
|
|
|
|
; mtdx.line_speed = 1; /* 10M */
|
|
|
|
; if (data & DPLX_DET_FULL)
|
|
|
|
; mtdx.duplexmode = 2; /* full duplex mode */
|
|
|
|
; else
|
|
|
|
; mtdx.duplexmode = 1; /* half duplex mode */
|
|
|
|
; } else if (mtdx.PHYType equ= AhdocPHY) {
|
|
|
|
; unsigned int data;
|
|
|
|
;
|
|
|
|
; data = mdio_read(dev, mtdx.phys[0], DiagnosticReg);
|
|
|
|
; if (data & Speed_100)
|
|
|
|
; mtdx.line_speed = 2; /* 100M */
|
|
|
|
; else
|
|
|
|
; mtdx.line_speed = 1; /* 10M */
|
|
|
|
; if (data & DPLX_FULL)
|
|
|
|
; mtdx.duplexmode = 2; /* full duplex mode */
|
|
|
|
; else
|
|
|
|
; mtdx.duplexmode = 1; /* half duplex mode */
|
|
|
|
; }
|
|
|
|
; else if (mtdx.PHYType equ= MarvellPHY) {
|
|
|
|
; unsigned int data;
|
|
|
|
;
|
|
|
|
; data = mdio_read(dev, mtdx.phys[0], SpecificReg);
|
|
|
|
; if (data & Full_Duplex)
|
|
|
|
; mtdx.duplexmode = 2; /* full duplex mode */
|
|
|
|
; else
|
|
|
|
; mtdx.duplexmode = 1; /* half duplex mode */
|
|
|
|
; data &= SpeedMask;
|
|
|
|
; if (data equ= Speed_1000M)
|
|
|
|
; mtdx.line_speed = 3; /* 1000M */
|
|
|
|
; else if (data equ= Speed_100M)
|
|
|
|
; mtdx.line_speed = 2; /* 100M */
|
|
|
|
; else
|
|
|
|
; mtdx.line_speed = 1; /* 10M */
|
|
|
|
; }
|
|
|
|
; else if (mtdx.PHYType equ= Myson981) {
|
|
|
|
; unsigned int data;
|
|
|
|
;
|
|
|
|
; data = mdio_read(dev, mtdx.phys[0], StatusRegister);
|
|
|
|
;
|
|
|
|
; if (data & SPEED100)
|
|
|
|
; mtdx.line_speed = 2;
|
|
|
|
; else
|
|
|
|
; mtdx.line_speed = 1;
|
|
|
|
;
|
|
|
|
; if (data & FULLMODE)
|
|
|
|
; mtdx.duplexmode = 2;
|
|
|
|
; else
|
|
|
|
; mtdx.duplexmode = 1;
|
|
|
|
; }
|
|
|
|
; else if (mtdx.PHYType equ= LevelOnePHY) {
|
|
|
|
; unsigned int data;
|
|
|
|
;
|
|
|
|
; data = mdio_read(dev, mtdx.phys[0], SpecificReg);
|
|
|
|
; if (data & LXT1000_Full)
|
|
|
|
; mtdx.duplexmode = 2; /* full duplex mode */
|
|
|
|
; else
|
|
|
|
; mtdx.duplexmode = 1; /* half duplex mode */
|
|
|
|
; data &= SpeedMask;
|
|
|
|
; if (data equ= LXT1000_1000M)
|
|
|
|
; mtdx.line_speed = 3; /* 1000M */
|
|
|
|
; else if (data equ= LXT1000_100M)
|
|
|
|
; mtdx.line_speed = 2; /* 100M */
|
|
|
|
; else
|
|
|
|
; mtdx.line_speed = 1; /* 10M */
|
|
|
|
; }
|
|
|
|
|
|
|
|
; // chage crvalue
|
|
|
|
; // mtdx.crvalue&equ(~PS10)&(~FD);
|
|
|
|
; mtdx.crvalue &= (~PS10) & (~FD) & (~PS1000);
|
|
|
|
; if (mtdx.line_speed equ= 1)
|
|
|
|
; mtdx.crvalue |= PS10;
|
|
|
|
; else if (mtdx.line_speed equ= 3)
|
|
|
|
; mtdx.crvalue |= PS1000;
|
|
|
|
; if (mtdx.duplexmode equ= 2)
|
|
|
|
; mtdx.crvalue |= FD;
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Transmit ;;
|
|
|
|
;; ;;
|
|
|
|
;; In: buffer pointer in [esp+4] ;;
|
|
|
|
;; size of buffer in [esp+8] ;;
|
|
|
|
;; pointer to device structure in ebx ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
proc transmit stdcall bufferptr, buffersize
|
|
|
|
|
|
|
|
pushf
|
|
|
|
cli
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
|
|
|
|
mov eax, [bufferptr]
|
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
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp [buffersize], 1514
|
2013-05-28 19:34:26 +02:00
|
|
|
ja .fail
|
2014-02-20 20:35:01 +01:00
|
|
|
cmp [buffersize], 60
|
|
|
|
jb .fail
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
mov esi, [ebx + device.cur_tx]
|
2014-02-19 16:48:17 +01:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
test [esi + descriptor.status], TXOWN
|
2014-02-19 16:48:17 +01:00
|
|
|
jnz .fail
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
push [esi + descriptor.next_desc_logical]
|
|
|
|
pop [ebx + device.cur_tx]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
mov eax, [bufferptr]
|
|
|
|
mov [esi + descriptor.skbuff], eax
|
|
|
|
invoke GetPhysAddr
|
|
|
|
mov [esi + descriptor.buffer], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
mov eax, [buffersize]
|
2014-02-19 16:48:17 +01:00
|
|
|
mov ecx, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
shl eax, PKTSShift ; packet size
|
2014-02-19 16:48:17 +01:00
|
|
|
shl ecx, TBSShift
|
|
|
|
or eax, ecx
|
|
|
|
or eax, TXIC + TXLD + TXFD + CRCEnable + PADEnable
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.control], eax
|
|
|
|
mov [esi + descriptor.status], TXOWN
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Update stats
|
2014-02-20 20:35:01 +01:00
|
|
|
inc [ebx + device.packets_tx]
|
|
|
|
mov eax, [buffersize]
|
|
|
|
add dword[ebx + device.bytes_tx], eax
|
|
|
|
adc dword[ebx + device.bytes_tx + 4], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-19 16:48:17 +01:00
|
|
|
; TX Poll
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], TXPDR
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
|
|
|
out dx, eax
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 1,"Transmit OK\n"
|
|
|
|
popf
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
2014-02-20 20:35:01 +01:00
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.fail:
|
2014-02-20 20:35:01 +01:00
|
|
|
DEBUGF 2,"Transmit failed\n"
|
|
|
|
invoke KernelFree, [bufferptr]
|
|
|
|
popf
|
2013-12-08 15:34:08 +01:00
|
|
|
or eax, -1
|
2014-02-20 20:35:01 +01:00
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
read_mac:
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], PAR0
|
|
|
|
lea edi, [ebx + device.mac]
|
2013-05-28 19:34:26 +02:00
|
|
|
insd
|
2014-02-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], PAR1
|
2013-05-28 19:34:26 +02:00
|
|
|
insw
|
|
|
|
DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\
|
2014-02-20 20:35:01 +01: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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Interrupt handler ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
align 4
|
|
|
|
int_handler:
|
|
|
|
|
|
|
|
push ebx esi edi
|
|
|
|
|
2014-02-19 16:48:17 +01:00
|
|
|
DEBUGF 1,"INT\n"
|
2013-05-28 19:34:26 +02: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-20 20:35:01 +01:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], ISR
|
2013-05-28 19:34:26 +02:00
|
|
|
in eax, dx
|
|
|
|
out dx, eax ; send it back to ACK
|
|
|
|
test eax, eax
|
|
|
|
jnz .got_it
|
|
|
|
.continue:
|
|
|
|
add esi, 4
|
|
|
|
dec ecx
|
|
|
|
jnz .nextdevice
|
|
|
|
.nothing:
|
|
|
|
pop edi esi ebx
|
|
|
|
xor eax, eax
|
|
|
|
|
|
|
|
ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
|
|
|
|
|
|
|
|
.got_it:
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
DEBUGF 1,"Device: %x Status: %x\n", ebx, ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
test ax, RI ; receive interrupt
|
|
|
|
jz .no_rx
|
|
|
|
push ax
|
|
|
|
.rx_loop:
|
2014-02-20 20:35:01 +01:00
|
|
|
mov esi, [ebx + device.cur_rx]
|
|
|
|
test [esi + descriptor.status], RXOWN
|
|
|
|
jnz .rx_done
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-19 16:48:17 +01:00
|
|
|
push ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
push .rx_complete
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
mov ecx, [esi + descriptor.status]
|
2013-05-28 19:34:26 +02:00
|
|
|
shr ecx, FLNGShift
|
|
|
|
sub ecx, 4 ; we dont need CRC
|
|
|
|
push ecx
|
2014-02-19 16:48:17 +01:00
|
|
|
DEBUGF 1,"Received %u bytes\n", ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Update stats
|
2014-02-20 20:35:01 +01:00
|
|
|
add dword[ebx + device.bytes_rx], ecx
|
|
|
|
adc dword[ebx + device.bytes_rx + 4], 0
|
|
|
|
inc [ebx + device.packets_rx]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
push [esi + descriptor.skbuff]
|
|
|
|
jmp [Eth_input]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.rx_complete:
|
2014-02-19 16:48:17 +01:00
|
|
|
pop ebx
|
2014-02-20 20:35:01 +01:00
|
|
|
mov esi, [ebx + device.cur_rx]
|
|
|
|
mov [esi + descriptor.control], 1536 shl RBSShift
|
2014-02-19 16:48:17 +01:00
|
|
|
push esi
|
2014-02-20 20:35:01 +01:00
|
|
|
invoke KernelAlloc, 1536
|
2014-02-19 16:48:17 +01:00
|
|
|
pop esi
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.skbuff], eax
|
|
|
|
invoke GetPgAddr
|
|
|
|
mov [esi + descriptor.buffer], eax
|
|
|
|
mov [esi + descriptor.status], RXOWN
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
push [esi + descriptor.next_desc_logical]
|
|
|
|
pop [ebx + device.cur_rx]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
jmp .rx_loop
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
.rx_done:
|
2014-02-19 16:48:17 +01:00
|
|
|
DEBUGF 1,"RX done\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
; Restart Rx engine if stopped.
|
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], RXPDR
|
|
|
|
xor eax, eax
|
|
|
|
out dx, eax
|
|
|
|
|
|
|
|
pop ax
|
2014-02-19 16:48:17 +01:00
|
|
|
.no_rx:
|
2014-02-20 20:35:01 +01:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
test ax, TI ; transmit interrupt
|
|
|
|
jz .no_tx
|
2014-02-19 16:48:17 +01:00
|
|
|
DEBUGF 1,"TX\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
push ax
|
2014-02-20 20:35:01 +01:00
|
|
|
lea esi, [ebx + device.tx_desc]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, NUM_TX_DESC
|
|
|
|
.tx_loop:
|
2014-02-20 20:35:01 +01:00
|
|
|
test [esi + descriptor.status], TXOWN
|
2013-05-28 19:34:26 +02:00
|
|
|
jnz .skip_this_one
|
2014-02-20 20:35:01 +01:00
|
|
|
mov eax, [esi + descriptor.skbuff]
|
2013-05-28 19:34:26 +02:00
|
|
|
test eax, eax
|
|
|
|
je .skip_this_one
|
2014-02-20 20:35:01 +01:00
|
|
|
mov [esi + descriptor.skbuff], 0
|
2014-02-19 16:48:17 +01:00
|
|
|
DEBUGF 1,"freeing buffer: 0x%x\n", eax
|
2014-02-20 20:35:01 +01:00
|
|
|
invoke KernelFree, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
.skip_this_one:
|
2014-02-20 20:35:01 +01:00
|
|
|
mov esi, [esi + descriptor.next_desc_logical]
|
2013-05-28 19:34:26 +02:00
|
|
|
loop .tx_loop
|
|
|
|
pop ax
|
|
|
|
.no_tx:
|
2014-02-20 20:35:01 +01:00
|
|
|
|
|
|
|
test ax, LSCStatus
|
|
|
|
jz .no_link_change
|
|
|
|
push ax
|
|
|
|
call getlinkstatus
|
|
|
|
pop ax
|
|
|
|
.no_link_change:
|
|
|
|
|
2014-02-19 16:48:17 +01:00
|
|
|
; test ax, TBU
|
|
|
|
; jz .no_tbu
|
|
|
|
; DEBUGF 2,"Transmit buffer unavailable!\n"
|
|
|
|
; .no_tbu:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.fail:
|
|
|
|
pop edi esi ebx
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
; End of code
|
|
|
|
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
data fixups
|
|
|
|
end data
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
include '../peimport.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-11-22 18:01:23 +01:00
|
|
|
my_service db 'MTD80X',0 ; max 16 chars include zero
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
sz_mtd800 db "Myson MTD800", 0
|
|
|
|
sz_mtd803 db "Surecom EP-320X", 0
|
|
|
|
sz_mtd891 db "Myson MTD891", 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
include_debug_strings ; All data wich FDO uses will be included here
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-02-20 20:35:01 +01:00
|
|
|
align 4
|
|
|
|
devices dd 0
|
|
|
|
device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|