Ethernet
Ethernet is a wired protocol for connecting many devices in a network such that they can transfer data between each other. It defines both the physical layers (10BASE-T, 100BASE-TX ...) as well the data format of an Ethernet packet & frame.
Ethernet packet & frame
There are two major formats of ethernet packets: the regular variant which supports MTUs (Maximum Transmission Unit) of up to 1500 bytes and "jumbo frames", which support MTUs of up to 9000 bytes. The latter are only supported for gigabit links and higher.
Note: each byte is transmitted starting from its LSb to its MSb.
Ethernet packet
Every Ethernet packet starts with a preamble.
This preamble is a repeated pattern of 01010101
bits (hex: 0x55
).
This pattern is used to synchronize the clock as well as signal to the receiver a frame is about to be transmitted.
The preamble consists of 7 bytes.
Immediately followed after the preamble is the SFD (Start Frame Delimiter).
This byte has the value 01110101
(0xd5
) and indicates the start of the Ethernet Frame.
After the Ethernet Frame there is an IPG (InterPacket Gap) of 12 bytes during which no data is sent whatsoever.
Preamble | SFD | Ethernet frame | IPG |
---|---|---|---|
0x55, 7 times | 0xd5 | ... | 12 bytes of nothing |
Ethernet frame
An Ethernet frame is at least 64 bytes long.
Each frame ends with a FCS (Frame Check Sequence) which is a CRC32 of all preceding frame data.
Destination MAC address | Source MAC address | EtherType | Payload | FCS |
---|---|---|---|---|
6 bytes | 6 bytes | 2 bytes | At least 46 bytes | 4 bytes |
The "EtherType" 0x8100
indicate a 802.1Q tag is present, in which case the format is as follows:
Destination MAC address | Source MAC address | 802.1Q tag | EtherType | Payload | FCS |
---|---|---|---|---|---|
6 bytes | 6 bytes | 4 bytes | 2 bytes | At least 42 bytes | 4 bytes |
The "real" EtherType is located right after the tag.
TPID | TCI |
---|---|
0x8100 | ... |
Interfaces
There are various types of interfaces to interact with Ethernet controllers.
Media Independent Interface (MII)
The MII is the most common type of interface. Several variants exists for higher speeds or lower pin count.
Standard
The standard MII interfaces supports 10BASE-T and 100BASE-TX.
Pin(s) | Description |
---|---|
TX_CLK | Transmission clock. Must be used when sending data. |
TXD[0:3] | 4 bits of data to transmit if TX_EN is high. |
TX_EN | When high, transmit data. |
TX_ER | When high, force a transmission error. |
RX_CLK | Receive clock. Must be used when receiving data. |
RXD[0:3] | 4 bits of received data when RX_DV is high. |
RX_DV | Whether data is currently being received. |
RX_ER | Whether an error occured during reception. |
CRS | Carrier sense. TODO |
COL | Collision detect. TODO |
MDIO | |
MDC |
When receiving or sending data, the high nibble (4 bits) is sent first, then the low nibble.
It is possible some bytes of the preamble may be missing on reception. This may happen if the controller detects the signal late.