Go to the documentation of this file.
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);
Queue< NetworkQueue::Packet *, NetworkQueue::MaxPackets > m_transmitPending
List of pointers to packets pending transmission.
Memory::Range m_receiveDescRange
Memory range for receive descriptors.
virtual bool insertAt(const Size position, T *item)
Inserts the given item at the given position.
Result
Enumeration of generic kernel API result codes.
virtual FileSystem::Result transmit(NetworkQueue::Packet *pkt)
Add a network packet to the transmit queue.
@ TransmitCtl0
< Interrupt Enable
#define WARNING(msg)
Output a warning message.
Result initialize()
Perform initialization.
void dsb()
Data Synchronisation Barrier.
@ TransmitStatus
< MAC Address Low
Size m_maximumPacketSize
Maximum size of each packet.
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
Network Device abstract class.
void write(u32 reg, u32 data)
write to memory mapped I/O register
#define PAGESIZE
ARM uses 4K pages.
static const Size MaxPackets
Maximum number of packets available.
@ BasicCtl1
< Basic Control 0
Result enable(const Clock clock)
Enable a clock.
@ ReceiveStatus
< Transmit Current Buffer
Transmit/receive frame descriptor.
static const Address MemoryAddress
Physical memory address of the device memory mapped registers.
@ TransmitDescList
< Transmit Flow Control
unsigned long Address
A memory address.
void release(Packet *packet)
Put unused packet back.
@ TransmitCtl1
< Transmit Control 0
virtual FileSystem::Result process(const NetworkQueue::Packet *packet, const Size offset=0)
Process a received network packet.
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
Size m_transmitIndex
Current transmit packet index.
Size m_receiveIndex
Current receive packet index.
@ ReceiveCtl0
< Transmit Descriptor List Address
Packet * get()
Get unused packet.
Sun8iEmac(const u32 inode, NetworkServer &server)
Constructor.
@ MiiData
< Management Interface Command
Memory::Range m_transmitDescRange
Memory range for transmit descriptors.
void printRx()
Print diagnostic information about the receive queue (RX)
FileSystem::Result receive()
Receive packets.
#define DEBUG(msg)
Output a debug message to standard output.
void printTx()
Print diagnostic information about the transmit queue (TX)
Ethernet network address.
Index< FrameDescriptor, NetworkQueue::MaxPackets > m_transmitDesc
List of pointers to transmit descriptors.
@ IntEnable
< Interrupt Status
bool miiBusyWait() const
Wait until the PHY comes out of busy state.
Address phys
Physical address.
virtual FileSystem::Result interrupt(const Size vector)
Called when an interrupt has been triggered for this device.
@ MiiRegAdv
< Identifier Low
FileSystem::Result resetPhy()
Reset the PHY connected to the MAC controller.
SunxiClockControl m_ccu
Clock Control Unit.
@ TransmitCurDesc
< Transmit DMA Status
unsigned short u16
Unsigned 16-bit number.
@ ReceiveDescList
< Receive Control 1
@ ReceiveCurDesc
< Receive DMA Status
unsigned int u32
Unsigned 32-bit number.
unsigned int Size
Any sane size indicator cannot go negative.
u32 miiRead(const u8 phyAddr, const u8 regAddr)
Read a Media-Independent-Interface (MII) register on the PHY.
SunxiSystemControl m_syscon
System Control Unit.
@ MiiRegIdLow
< Identifier High
virtual FileSystem::Result initialize()
Initialize the device.
u32 read(u32 reg) const
read from memory mapped I/O register
static const Size MaximumResetPoll
Maximum number of polling reset iterations.
@ AddrLow
< MAC Address High
FileSystem::Result configPhy()
Configure the PHY connected to the MAC controller.
virtual FileSystem::Result status(FileSystem::FileStat &st)
Retrieve file statistics.
Arch::IO m_io
Memory mapped registers.
Result deassert(const Reset reset)
De-assert a reset signal.
virtual FileSystem::Result startDMA()
Start DMA processing.
static const u8 PhyMdioAddress
Fixed address of the PHY on the MDIO bus.
Result setupEmac(const uint phyAddr)
Setup EMAC mode.
Queue< NetworkQueue::Packet *, NetworkQueue::MaxPackets > m_transmitPackets
List of pointers to packets that the driver has submitted for transmission.
virtual Size count() const
Returns the number of items in the Queue.
#define assert(exp)
Insert program diagnostics.
#define ERROR(msg)
Output an error message.
virtual FileSystem::Result getAddress(Ethernet::Address *address)
Read ethernet address.
Result
Result code for filesystem Actions.
unsigned char u8
Unsigned 8-bit number.
@ AddrHigh
< Management Interface Data
static const Size InterruptNumber
Interrupt number for this device on a sun8i family SoC.
Result initialize()
Perform initialization.
Index< NetworkQueue::Packet, NetworkQueue::MaxPackets > m_receivePackets
List of pointers to receive packets.
T & pop()
Remove item from the tail of the Queue.
static const Size MaximumMiiPoll
Maximum number of polling reads for MII-busy flag.
@ IntStatus
< Basic Control 1
void set(Address addr, u32 data)
Set bits in memory mapped register.
Address virt
Virtual address.
bool push(const T &item)
Add item to the head of the Queue.
@ ReceiveCtl1
< Receive Control 0
Represents a network packet.
FileSystem::Result resetReceive()
Reset receive control functions.
Size size
Size in number of bytes.
Access access
Page access flags.
virtual FileSystem::Result initialize()
Initialize the device.
FileSystem::Result reset()
Reset the controller.
Index< FrameDescriptor, NetworkQueue::MaxPackets > m_receiveDesc
List of pointers to receive descriptors.
void miiWrite(const u8 phyAddr, const u8 regAddr, const u32 data)
Write a Media-Independent-Interface (MII) register on the PHY.
virtual ~Sun8iEmac()
Destructor.
FileSystem::Result resetTransmit()
Reset transmit control functions.
@ MiiCmd
< Receive Hash Table 1
virtual FileSystem::Result setAddress(const Ethernet::Address *address)
Set ethernet address.