Realtek DPDK PMD

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

Writing a PMD for DPDK —


Part 1
Nayan Gadre
Dec 16, 2019 · 5 min read

As mentioned in the previous post, in this series about DPDK, I have


shared how to prototype L2/L3 applications using DPDK library
without any dependency on Hardware (Physical/Emulated).

In this post, I share how to write a PMD (Poll Mode Driver) for
DPDK, off-course, it will not cover all the enhancements and

1 of 8 24/09/20, 12:52 am
Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

features present in industry grade drivers, which you can explore in


the existing PMDs in the DPDK source. Advanced features include,
queueing algorithms for QoS, Offloading features for Protocol
offloading, Protocol Parallelisation features.

Here, we see how to write a PMD for a Network Interface Card,


most commonly found on your Desktop/Laptop, Realtek 8136. I’ll
point out the steps for compilation, file/directory changes, and will
share the link for the source at the end of the series.

1. What is a PMD (Poll Mode Driver):


If you have gone through DPDK in general, the processing of IOs
and Network packets, is being pushed to userspace. Whenever a
device needs application to work dedicatedly towards
processing IO or Network packets, you need to bypass the kernel
storage/networking stack and directly access the hardware. The
reasons to skip kernel is to avoid multiple copies of data before
its processed, as well as, avoid multiple copies in the other
direction as well.

2. How to access hardware directly in User space:


The linux kernel has features (kernel modules) to work with
hardware directly. The Userspace-IO is a kernel module that
exposes device registers to userspace applications through files.
The user-space application then simply needs to open the binary
files and access specific offsets of the device registers.

3. How DPDK uses PMDs:


DPDK has build options to compile your driver as a shared
library or compile everything as a single combined library.
These options can be set/unset through the “.config”
configuration file present in the build directory. Like the Linux
kernel, DPDK provides software bus enumeration and device

2 of 8 24/09/20, 12:52 am
Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

registration facility which your driver should use to register


itself to the bus. All the bus enumeration and device registration
happens either before your main() gets called, or through
library provided function later called for init.

4. Testpmd to test your driver:


DPDK provides a testpmd application to test your driver.
However, its not straightforward to integrate your driver with
the application since, there are no generic function pointers
provided to work with the driver functions, hence you
separately compile your driver as a library and then compile the
testpmd alongwith the driver library to use the driver. You also
need to write multiple #ifdefs and #if defined MACROs for
your Vendor specific driver to call functions directly to setup the
device.

5. How to write the basic framework:


All DPDK compatible PMD drivers are present under the
drivers/net hierarchy, so we will have to add a directory for our
vendor specific driver here: drivers/net/realtek. We need to
add the configuration options to COMPILE source under our
driver directory in build/.config, CONFIG_…
In the driver directory, the Makefile should export headers
which contain all functions that our testpmd would call, and
finally in the testpmd make a provision to include our driver
library before compiling.
DPDK framework provides following list of function pointers for
any PMD to implement.

3 of 8 24/09/20, 12:52 am
Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

List of functions to implement a full driver

But before we implement all or some of these functions (as we will


do so in the next series of posts), we must complete the probe and
device init procedure.

And before that little description about the device for which we are
writing the PMD for:

4 of 8 24/09/20, 12:52 am
Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

Here the lspci -v output shows my Realtek Ethernet Adapter


information. The moment you load “modprobe uio_pci_generic;
insmod igb_uio.ko” and call the “dpdk_devbind.py” script for this
PCI BDF 07:00.0, the UIO framework would have filled structures
like uio_info and igb_uio would have filled its own set of structures
to represent this device with its Register Locations. Keep the
RTL8101L datasheet handy to view the list of Ethernet Adapter
registers required to be configured.

We attach our eth_dev_ops to dpdk provided eth_dev structure


dev_ops handle. Also the 2 functions required to Transmit and
Receive packets are also assigned to the DPDK provided handles

5 of 8 24/09/20, 12:52 am
Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

“realtek_recv_pkts” and “realtek_xmit_pkts”. We store the


Register Space Base address from BAR2 into our device specific
private structure struct realtek_eth_hw.

The remaining functions to reset the hardware and then init the
hardware are mentioned below:

6 of 8 24/09/20, 12:52 am
Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

Apparently, all the existing kernel driver’s functions need to be


borrowed and incorporated into your PMD. The specifications on
how to configure the registers can be found in the datasheet. For
eg: disable and clear the interrupts has a peculiar way of doing it,
we set value 0x0000, then read from the same register and write
into the register the value we just read.

So till now, our PHY, and Interrupts have been initialized as per the
working in-kernel driver routines. In the next few posts, we shall
Linux Networking Dpdk Device Drivers Kernel
see how to setup the Network Packet Descriptor rings and then
finally write the TX and RX functions. Stay tuned …

Discover Medium Make Medium yours Become a member


Reference:
Welcome to a place where Follow all the topics you care Get unlimited access to the
1. Anil
words Pugalias,
matter. sysplayabout,
On Medium, workshop
and we’ll on writing
deliver the Netowrk
best storiesDrivers
on MediumI —

7 of 8 24/09/20, 12:52 am
Writing a PMD for DPDK — Part 1. As mentione... https://medium.com/powerof2/writing-a-pmd-for...

smart voices and original best stories for you to your and support writers while
attended some years back. (https://sysplay.in/).
ideas take center stage - homepage and inbox. Explore you’re at it. Just $5/month.
2. Existing PMDs from the DPDK source.
with no ads in sight. Watch Upgrade

About Help Legal

8 of 8 24/09/20, 12:52 am

You might also like