22#pragma clang optimize off
23#pragma GCC push_options
24#pragma GCC optimize ("O0")
47 ERROR(
"failed to initialize Clock Control Unit: result = " << (
int) ccuResult);
55 ERROR(
"failed to initialize System Control: result = " << (
int) sysResult);
65 ERROR(
"failed to map hardware registers: result = " << (
int) mapResult);
79 ERROR(
"failed to allocate receive descriptors: result = " << (
int) vmResult);
92 ERROR(
"failed to allocate transmit descriptors: result = " << (
int) vmResult);
100 ERROR(
"hardware reset failed: result = " << (
int) resetResult);
108 ERROR(
"failed to initialize NetworkDevice: result = " << (
int) result);
116 ERROR(
"failed to enable interrupt: result = " << (
int) irqResult);
128 DEBUG(
"address = " << *address);
135 DEBUG(
"address = " << *address);
158 DEBUG(
"m_receiveDesc[" << i <<
"]: status = " << (
void *)d->
status <<
159 ", bufsize = " << d->
bufsize <<
", bufaddr = " << (
void *) d->
bufaddr <<
160 ", next = " << (
void *) d->
next)
185 DEBUG(
"vector = " << vector <<
" status = " << (
void *)
status);
197 DEBUG(
"releasing tx:pkt = " << (
void *) pkt);
206 ERROR(
"failed to receive packets");
220 ERROR(
"transmit queue full");
251 ERROR(
"failed to lookup packet physical address: result = " << (
int) vmResult);
259 ERROR(
"failed to clean data cache at " << (
void *) range.
virt <<
260 ": result = " << (
int) ccResult);
274 " tx:size = " << pkt->
size <<
" tx:payload = " << *pkt);
311 ERROR(
"last flag not set: skipping packet");
327 ERROR(
"failed to invalidate cache lines for packet: result = " << (
int) result);
334 pkt->
size = bytes -
sizeof(
u32);
364 ERROR(
"PHY is busy");
386 DEBUG(
"phyAddr = " << phyAddr <<
" regAddr = " << regAddr <<
" data = " << (
void *) data);
394 DEBUG(
"phyAddr = " << phyAddr <<
" regAddr = " << regAddr <<
" data = " << (
void *) data);
413 ERROR(
"failed to enable TX clock: result = " << (
int) ccuResult);
421 ERROR(
"failed to de-assert TX clock reset: result = " << (
int) ccuResult);
429 ERROR(
"failed to enable Ephy clock: result = " << (
int) ccuResult);
437 ERROR(
"failed to de-assert Ephy clock reset: result = " << (
int) ccuResult);
447 if (idLow != 0x1400 || idHigh != 0x44)
449 WARNING(
"unrecognized PHY identification: high = " << (
void *) idHigh <<
450 " low = " << (
void *) idLow);
452 DEBUG(
"idHigh = " << (
void *)idHigh <<
" idLow " << (
void *)idLow);
470 ERROR(
"failed to reset PHY: reset bit is high: reg = " << (
void *) reg);
507 WARNING(
"timeout waiting for auto negociation/link: status = " << (
void *) val);
511 DEBUG(
"status = " << (
void *) val);
537 ERROR(
"failed to lookup physical address of packet: result = " << (
int) result);
608 ERROR(
"failed to read MAC address: result = " << (
int) macRead);
612 DEBUG(
"savedMac = " << mac);
618 ERROR(
"failed to reset PHY: result = " << (
int) result);
626 ERROR(
"failed to reset PHY: result = " << (
int) result);
645 ERROR(
"basic hardware reset failed");
653 ERROR(
"failed to write MAC address: result = " << (
int) macWrite);
667 ERROR(
"failed to reset receive control: result = " << (
int) rxResult);
674 ERROR(
"failed to reset transmit control: result = " << (
int) txResult);
681 val &= ~BasicCtl0SpeedMask;
#define dsb(type)
Data Memory Barrier.
Result
Enumeration of generic kernel API result codes.
void set(Address addr, u32 data)
Set bits in memory mapped register.
void write(u32 reg, u32 data)
write to memory mapped I/O register
u32 read(u32 reg) const
read from memory mapped I/O register
virtual FileSystem::Result status(FileSystem::FileStat &st)
Retrieve file statistics.
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
virtual bool insertAt(const Size position, T *item)
Inserts the given item at the given position.
Network Device abstract class.
Size m_maximumPacketSize
Maximum size of each packet.
virtual FileSystem::Result process(const NetworkQueue::Packet *packet, const Size offset=0)
Process a received network packet.
virtual FileSystem::Result initialize()
Initialize the device.
Packet * get()
Get unused packet.
void release(Packet *packet)
Put unused packet back.
static const Size MaxPackets
Maximum number of packets available.
T & pop()
Remove item from the tail of the Queue.
virtual Size count() const
Returns the number of items in the Queue.
bool push(const T &item)
Add item to the head of the Queue.
static const u8 PhyMdioAddress
Fixed address of the PHY on the MDIO bus.
static const Size MaximumMiiPoll
Maximum number of polling reads for MII-busy flag.
Index< NetworkQueue::Packet, NetworkQueue::MaxPackets > m_receivePackets
List of pointers to receive packets.
Queue< NetworkQueue::Packet *, NetworkQueue::MaxPackets > m_transmitPending
List of pointers to packets pending transmission.
FileSystem::Result reset()
Reset the controller.
Index< FrameDescriptor, NetworkQueue::MaxPackets > m_receiveDesc
List of pointers to receive descriptors.
virtual FileSystem::Result startDMA()
Start DMA processing.
virtual FileSystem::Result interrupt(const Size vector)
Called when an interrupt has been triggered for this device.
virtual FileSystem::Result getAddress(Ethernet::Address *address)
Read ethernet address.
virtual FileSystem::Result setAddress(const Ethernet::Address *address)
Set ethernet address.
u32 miiRead(const u8 phyAddr, const u8 regAddr)
Read a Media-Independent-Interface (MII) register on the PHY.
Sun8iEmac(const u32 inode, NetworkServer &server)
Constructor.
@ MiiData
< Management Interface Command
@ ReceiveStatus
< Transmit Current Buffer
@ ReceiveCtl1
< Receive Control 0
@ BasicCtl1
< Basic Control 0
@ TransmitCurDesc
< Transmit DMA Status
@ TransmitCtl1
< Transmit Control 0
@ IntEnable
< Interrupt Status
@ AddrHigh
< Management Interface Data
@ AddrLow
< MAC Address High
@ IntStatus
< Basic Control 1
@ ReceiveDescList
< Receive Control 1
@ TransmitStatus
< MAC Address Low
@ ReceiveCtl0
< Transmit Descriptor List Address
@ TransmitCtl0
< Interrupt Enable
@ ReceiveCurDesc
< Receive DMA Status
@ TransmitDescList
< Transmit Flow Control
@ MiiCmd
< Receive Hash Table 1
Index< FrameDescriptor, NetworkQueue::MaxPackets > m_transmitDesc
List of pointers to transmit descriptors.
@ MiiRegAdv
< Identifier Low
@ MiiRegIdLow
< Identifier High
FileSystem::Result receive()
Receive packets.
static const Size MaximumResetPoll
Maximum number of polling reset iterations.
Size m_transmitIndex
Current transmit packet index.
bool miiBusyWait() const
Wait until the PHY comes out of busy state.
virtual FileSystem::Result initialize()
Initialize the device.
void printRx()
Print diagnostic information about the receive queue (RX)
Queue< NetworkQueue::Packet *, NetworkQueue::MaxPackets > m_transmitPackets
List of pointers to packets that the driver has submitted for transmission.
void printTx()
Print diagnostic information about the transmit queue (TX)
Memory::Range m_receiveDescRange
Memory range for receive descriptors.
void miiWrite(const u8 phyAddr, const u8 regAddr, const u32 data)
Write a Media-Independent-Interface (MII) register on the PHY.
FileSystem::Result configPhy()
Configure the PHY connected to the MAC controller.
SunxiSystemControl m_syscon
System Control Unit.
FileSystem::Result resetTransmit()
Reset transmit control functions.
FileSystem::Result resetPhy()
Reset the PHY connected to the MAC controller.
Arch::IO m_io
Memory mapped registers.
virtual FileSystem::Result transmit(NetworkQueue::Packet *pkt)
Add a network packet to the transmit queue.
static const Address MemoryAddress
Physical memory address of the device memory mapped registers.
FileSystem::Result resetReceive()
Reset receive control functions.
SunxiClockControl m_ccu
Clock Control Unit.
virtual ~Sun8iEmac()
Destructor.
Size m_receiveIndex
Current receive packet index.
static const Size InterruptNumber
Interrupt number for this device on a sun8i family SoC.
Memory::Range m_transmitDescRange
Memory range for transmit descriptors.
Result deassert(const Reset reset)
De-assert a reset signal.
Result initialize()
Perform initialization.
Result enable(const Clock clock)
Enable a clock.
Result setupEmac(const uint phyAddr)
Setup EMAC mode.
Result initialize()
Perform initialization.
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
#define PAGESIZE
ARM uses 4K pages.
#define assert(exp)
Insert program diagnostics.
unsigned int u32
Unsigned 32-bit number.
unsigned long Address
A memory address.
#define ERROR(msg)
Output an error message.
#define WARNING(msg)
Output a warning message.
unsigned short u16
Unsigned 16-bit number.
unsigned int Size
Any sane size indicator cannot go negative.
#define ALIGN(n)
Aligns a symbol at the given boundary.
#define DEBUG(msg)
Output a debug message to standard output.
unsigned char u8
Unsigned 8-bit number.
Result
Result code for filesystem Actions.
Ethernet network address.
Size size
Size in number of bytes.
Address phys
Physical address.
Address virt
Virtual address.
Access access
Page access flags.
Represents a network packet.
Transmit/receive frame descriptor.