Docsity

82573L Ethernet Controller: Driver Development and Counter Examples, Slides of Computer Applications

Partial preview of the text

Download 82573L Ethernet Controller: Driver Development and Counter Examples and more Slides Computer Applications in PDF only on Docsity!

More 82573L details

Getting ready to write and test a

character-mode device-driver for our

anchor-LAN’s ethernet controllers

A ‘nic.c’ character driver?

open

read

write

my_fops

ioctl my_ioctl()

my_open()

my_read()

my_write()

my_release()

my_isr()

module_init() module_exit()

release

Initializing the nic’s counters

• The statistical counters all have address-

offsets in the range 0x04000 – 0x04FFF

• You can use a very simple program-loop

to ‘clear’ each of these read-only registers

// Here ‘io’ is the virtual base-address of the nic’s i/o-memory region

int r;

// clear all of the Pro/1000 controller’s statistical counters

for (r = 0x4000; r < 0x4FFF; r += 4) ioread32( io + r );

A few ‘counter’ examples

0x4000 CRCERRS CRC Errors Count

0x400C RXERRC Receive Error Count

0x4014 SCC Single Collision Count

0x4018 ECOL Excessive Collision Count

0x4074 GPRC Good Packets Received

0x4078 BPRC Broadcast Packets Received

0x407C MPRC Multicast Packets Received

0x40D0 TPR Total Packets Received

0x40D4 TPT Total Packets Transmitted

0x40F0 MPTC Multicast Packets Transmitted

0x40F4 BPTC Broadcast Packets Transmitted

Filter registers

• All the modern ethernet controllers have a

built-in ‘filtering’ capability which allows the

NIC to automatically discard any packets

having a destination-address different from

the controller’s own unique MAC address

• But the 82573L offers a more elaborate

filtering mechanism (and can also ‘reject’

packets based on the ‘source’ addresses)

How ‘receive’ works

descriptor

descriptor

descriptor

descriptor

Buffer

Buffer

Buffer

Buffer

List of Buffer-Descriptors

We setup memory-buffers where we want received packets to be placed by the NIC

We also create a list of buffer-descriptors and inform the NIC of its location and size

Then, when ready, we tell the NIC to ‘Go!’ (i.e., start receiving), but to let us know when these receptions have occurred

Random Access Memory

Registers’ Names

Memory-information registers

RDBA(L/H) = Receive-Descriptor Base-Address Low/High (64-bits)

RDLEN = Receive-Descriptor array Length

RDH = Receive-Descriptor Head

RDT = Receive-Descriptor Tail

Receive-engine control registers

RXDCTL = Receive-Descriptor Control Register

RCTL = Receive Control Register

Notification timing registers

RDTR = Receive-interrupt packet Delay Timer

RADV = Receive-interrupt Absolute Delay Value

Rx-Desc Ring-Buffer

Circular buffer (128-bytes minimum)

RDBA

base-address

RDLEN

(in bytes)

RDH (head)

RDT (tail)

= owned by hardware (nic)

= owned by software (cpu)

0x

0x

0x

0x

0x

0x

0x

0x

0x

Legacy Rx-Descriptor Layout

VLAN tag

0x

0x

0x

Packet Checksum

Buffer-Address high (bits 63..32)

Buffer-Address low (bits 31..0)

Packet Length (in bytes)

Errors Status

Buffer-Address = the packet-buffer’s 64-bit address in physical memory

Packet Length = number of bytes in the data-packet that has was received

Packet Checksum = the16-bit one’s-complement of the entire logical packet

Status = shows if descriptor has been used and if it’s last in a logical packet

Errors = valid only when DD and EOP are set in the descriptor’s Status field

Suggested C syntax

typedef struct {

unsigned long long base_addr;

unsigned short pkt_length;

unsigned short checksum;

unsigned char desc_stat;

unsigned char desc_errs;

unsigned short vlan_tag;

} rx_descriptor;

RxDesc Error-field

RXE IPE TCPE

reserved

=0 SE^ CE

RXE = Received-data Error (1=yes, 0=no)

IPE = IPv4-checksum error

TCPE = TCP/UDP checksum error (1=yes, 0=no)

SEQ = Sequence error (1=yes, 0=no)

SE = Symbol Error (1=yes, 0=no)

CE = CRC Error or alignment error (1=yes, 0=no)

SEQ

reserved =

Network Administration

• Some higher-level networking protocols

require the Operating System to setup a

translation between the ‘hostname’ for a

workstation and the hardware-address of

its Network Interface Controller

• One mechanism for doing this is creation

of a specially-named textfile (‘/etc/ethers’)

that provides database for translations

Our ‘seereset.c’ demo

• We created this LKM to demonstrate the

sequence of ‘state-changes’ that three of

our network controller’s registers undergo

in response to initiating a ‘reset’ operation

• The programming technique used here is

one which we think could be useful in lots

of other hardware programming situations

where a vendor’s manual may not answer

all our questions about how devices work

In-class exercise

• Try redirecting the output from this ‘cat’

command to a file, like this:

$ cat /proc/seereset > seereset.out

• Then edit this textfile, adding a comment

to each line which indicates the bit(s) that

experienced a ‘change-of-state’ from the

line that came before it (thereby providing

yourself with a running commentary as to

how the NIC proceeds through a ‘reset’)