The hardware ringbuffer
Understanding the RTL-8139 mechanism for packet reception
Implementing a ringbuffer
Start address Buffer length
datum
HEAD TAIL
Buffer storage
datum datum datum
TAIL = where to insert the next datumHEAD = where to remove the next datum
Some ringbuffer details
• When HEAD == TAIL the buffer is empty
• The HEAD and TAIL pointers advance to the end of the buffer, then ‘wrap around’
• Some storage always remains unused
• When sizes of stored data-items are not uniform, then the size of each item must be stored somewhere – probably with the item itself
RealTek’s implementation
data data data
Receive Buffer Start Address Receive Configuration Register
(includes size of the buffer)
CAPRCurrent Addressof Packet to Read (minus 16 bytes)
CBR Current Buffer Register(4-byte aligned)
= packet header (4-bytes)
= packet data (size varies)
Buffer storage
Packet-Header Format
MAR
PAM
BAR
reservedISE
RUNT
LONG
CRC
FAE
ROK
Packet Status (least significant 16 bits)
Packet Length (most significant 16 bits)
LEGEND ROK = Received OK MAR (Multicast Address Received) FAE = Frame Alignment Error PAM (Physical Address Matched) CRC = CRC Error BAR (Broadcast Address Received) LONG = Packet length exceeds 4KB
RUNT = Packet size below 64 bytesISE = Invalid Symbol Error
15 14 13 5 4 3 2 1 0
31 16
Receive Algorithm
• Reset controller (bit #4 in register CR)
• Allocate memory and program RBSTART
• Enable reception (bit #3 in register CR)
• Configure reception (RXCONFIG register)
• Adjust CAPR for size of allocated buffer
• Optionally unmask the receive interrupts
• Await received packet(s) (bit #0 in CR)
Recall ‘RXCONFIG’ layout
32-bit register (offsets 0x44-0x47)
reservedEarly Receive
Thresholdreserved
MultERINT
RxERR
8
Rx FIFOThreshold
Rx BufLength
Max DMABurse Size
WRAP
0
LONG
RUNT
BCAST
MCAST
MAC
ALL
31 28 27 24 23 18 17 16
15 13 12 11 10 8 7 5 4 3 2 1 0
How to configure Rx
• Buffer length is the most crucial parameter– 8KB (=00)with or without ‘wrap’– 16KB (=01)with or without ‘wrap’– 32KB (=10)with or without ‘wrap’– 64KB (=11) (‘wrap’ is automatic)
• Next is which packets to receive:– Broadcast, Multicast and MAC-Address Match– (You do NOT want to receive ALL packets)
What about thresholds?
• The Linux driver offers us guidance– Can use ‘none’ as Early Rx Threshold – Can use ‘none’ as Rx FIFO Threshold– Can use a ‘reserved’ DMA Burst size
• So the Linux driver used: 0x0000E70E
• But you can experiment with other values
In-class exercise #1
• Install our ‘user8139.c’ device-driver, and take note of its buffer’s physical address
• Install our ‘dram.c’ device-driver, and use ‘fileview’ to look at the NIC Receive Buffer
• Then modify ‘nicstudy.cpp’ so that it will enable (and configure) packet-recption
• Use ‘fileview’ to look at received packets
In-class exercise #2
• Now enhance your modified version of the ‘nicstudy’ application so that it will display a succession of received packets (using both hexadecimal and ascii formats), in a manner similar to our ‘rxtester.cpp’ demo
• Be sure you ‘disable’ the packet reception before you remove ‘user8139.ko’ from the kernel – or risk a system ‘crash’ (Why?)
The ‘/etc/ethers’ file
• This file describes the list of associations of Ethernet-addresses with IP-addresses
• It’s a text file, created with a text editor
• Each line describes one correspondence:
xx:xx:xx:xx:xx:xx 138.202.171.30
• But comments start with a #-character
• A sample ‘ethers’ file is on our website
Dynamic Address Resolution
• A standard Internet Protocol service exists which provides a dynamic way for stations to discover the Ethernet address that goes with a given IP-address
• It is called ‘Address Resolution Protocol’
ARP request
A B
C D E
request
Station ‘A’ wants to know the Ethernet Address for station ‘B’So ‘A’ broadcasts an ARP request-packet to all other stations
ARP reply
A B
C D E
reply
Station ‘B’ recognizes that the request is for its Ethernet Address. So ‘B’ replies directly to ‘A’, and other stations ignore the request.
ARP packet-format
ARP packet-data0806Dest’n MAC Source MAC
packet-header
PTYPE=0008HTYPE=0001
OPER=0001/0002PLEN=04HLEN (01)
source hardware address (6 bytes)
source protocol address (4 bytes)
destination hardware address (6 bytes)
destination protocol address (4 bytes)
All zeros for an ARP request
broadcast address forARP request
Top Related