SlideShare a Scribd company logo
1 of 15
© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Drivers
2© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
Understanding Network Subsystem
Network Drivers: A different category
Writing Network Drivers
3© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Subsystem
(Network) Protocol Stack
Typically, the TCP/IP Stack
Interfaces with the User Space through network interfaces, instead
of device files
Unlike other drivers, does not provide any /sys or /dev entries
Interface Examples: eth0, wlan1, …
Resides in the <kernel_source>/net folder
Network Interface Card (NIC) Drivers
Driver for the Physical Network Cards
Provides uniform hardware independent interface for the network
protocol layer to access the card
Typically, resides in the <kernel_source>/drivers/net folder
4© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Related Data Structures
Writing a NIC or Network Driver involves
Interacting with the underlying Card over its I/O Bus
Providing the standard APIs to the Protocol Stack
This needs three kind of Data Structures
Core of Protocol Stack
struct sk_buff
NIC & Protocol Stack Interface
struct net_device
NIC I/O bus, e.g. PCI, USB, …
I/O bus specific data structure
5© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
struct sk_buff
Network Packet Descriptor
Header: <linux/skbuff.h>
Driver relevant Fields
head – points to the start of the packet
tail – points to the end of the packet
data – points to the start of the pkt payload
end – points to the end of the packet payload
len – amount of data that the packet contains
6© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Socket Buffer APIs
Header: <linux/skbuff.h>
SK Buffer Storage
struct sk_buff *dev_alloc_skb(len);
dev_kfree_skb(skb);
SK Buffer Operations
void skb_reserve(struct sk_buff *, int len);
struct sk_buff *skb_clone(struct sk_buff *, gfp_t);
unsigned char *skb_put(struct sk_buff *, int len);
7© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Big Picture
(with a PCI NIC)
Network
Stack
sk_buff
net_device
eth0
system calls
ifconfig ping tcpdump ...
PCI Driver
handler
Tx
dpv
Network
Vertical
PCI
Horizontal
NIC Driver
PCI Core
PCI Ctrl Drv
PCI Host Ctrl
DMA
Ctrl
System RAM
Tx
Buf
Rx
Buf
PHY
NIC
PCI
Cfg
Space
Reg
Space
sk_buff...
CPU
User
Space
Kernel
Space
Hardware
Space
poll
Soft IRQ
TxDesc
RxDesc
8© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
struct net_device
Header: <linux/netdevice.h>
Driver relevant Operation Fields
Activation: open, stop, ioctl
Data Transfer: start_xmit, poll (NAPI: new API)
WatchDog: tx_timeout, int watchdog_timeo
Statistics: get_stats, get_wireless_stats
Typically uses struct net_device_stats, populated earlier
Configuration: struct *ethtool_ops, change_mtu
Structure defined in Header: <linux/ethtool.h>
Bus Specific: mem_start, mem_end
Latest kernels have all the operations moved under
struct net_dev_ops
And typically, a prefix ndo_ added and some name changes
9© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Net Device Registration
Header: <linux/netdevice.h>
Net Device Storage
struct net_device *alloc_etherdev(sizeof_priv);
struct net_device *alloc_ieee80211dev(sizeof_priv);
struct net_device *alloc_irdadev(sizeof_priv);
struct net_device *alloc_netdev(sizeof_priv, name, setup_fn);
void free_netdev(struct net_device *);
Registering the Net Device
int register_netdev(struct net_device *);
void unregister_netdev(struct net_device *);
10© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Device Open & Close
A typical Network Device Open
Allocates ring buffers and associated sk_buffs
Initializes the Device
Gets the MAC, … from device EEPROM
Requests firmware download, if needed
int request_firmware(fw, name, device);
Register the interrupt handler(s)
A typical Network Device Close
Would do the reverse in chronology reverse order
11© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Packet Receive Interrupt Handler
A typical receive interrupt handler
Minimally handles the packet received
Sanity checks
Puts back equal number of sk_buffs for re-use
Passes the associated sk_buffs (& ring buffers) to the
protocol layer by the NET_RX_SOFTIRQ
On higher load, switch to poll mode, if supported,
which then passes the associated sk_buffs (& ring
buffers) to the protocol layer by the
NET_RX_SOFTIRQ
12© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Flow Control related APIs
For interaction with the protocol layer
Header: <linux/netdevice.h>
APIs
void netif_start_queue(struct net_device *);
void netif_stop_queue(struct net_device *);
void netif_wake_queue(struct net_device *);
int netif_queue_stopped(struct net_device *);
13© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Driver Examples
Driver: snull
Browse & Discuss
Driver for Realtek NIC 8136
Browse & Hack
14© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
Linux Network Subsystem
How are Network Drivers different?
Writing Network Drivers
Key Data Structures & their APIs
sk_buff & net_device
Network Device Registration
Network Device Operations
Interrupt Handling for Packets received
Flow Control related APIs
15© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

More Related Content

What's hot

netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
Kernel TLV
 
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
Analysis of Open-Source Drivers for IEEE 802.11 WLANsAnalysis of Open-Source Drivers for IEEE 802.11 WLANs
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
Danh Nguyen
 

What's hot (20)

Tutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi Subsystem
Tutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi SubsystemTutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi Subsystem
Tutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi Subsystem
 
Pcie drivers basics
Pcie drivers basicsPcie drivers basics
Pcie drivers basics
 
Programming Embedded linux
Programming Embedded linuxProgramming Embedded linux
Programming Embedded linux
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
Analysis of Open-Source Drivers for IEEE 802.11 WLANsAnalysis of Open-Source Drivers for IEEE 802.11 WLANs
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Linux installation and booting process
Linux installation and booting processLinux installation and booting process
Linux installation and booting process
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network Interfaces
 
Linux dma engine
Linux dma engineLinux dma engine
Linux dma engine
 
Linux Networking Explained
Linux Networking ExplainedLinux Networking Explained
Linux Networking Explained
 

Viewers also liked

Viewers also liked (20)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
Serial Drivers
Serial DriversSerial Drivers
Serial Drivers
 
Interrupts
InterruptsInterrupts
Interrupts
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
I2C Drivers
I2C DriversI2C Drivers
I2C Drivers
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Embedded C
Embedded CEmbedded C
Embedded C
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
References
ReferencesReferences
References
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 
Low-level Accesses
Low-level AccessesLow-level Accesses
Low-level Accesses
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 

Similar to Network Drivers

Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
chiportal
 
26.1.7 lab snort and firewall rules
26.1.7 lab   snort and firewall rules26.1.7 lab   snort and firewall rules
26.1.7 lab snort and firewall rules
Freddy Buenaño
 
05 module managing your network enviornment
05  module managing your network enviornment05  module managing your network enviornment
05 module managing your network enviornment
Asif
 

Similar to Network Drivers (20)

Ccna Imp Guide
Ccna Imp GuideCcna Imp Guide
Ccna Imp Guide
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Better Network Management Through Network Programmability
Better Network Management Through Network ProgrammabilityBetter Network Management Through Network Programmability
Better Network Management Through Network Programmability
 
Advanced RAC troubleshooting: Network
Advanced RAC troubleshooting: NetworkAdvanced RAC troubleshooting: Network
Advanced RAC troubleshooting: Network
 
26.1.7 lab snort and firewall rules
26.1.7 lab   snort and firewall rules26.1.7 lab   snort and firewall rules
26.1.7 lab snort and firewall rules
 
Code Red Security
Code Red SecurityCode Red Security
Code Red Security
 
[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet Processing
 
05 module managing your network enviornment
05  module managing your network enviornment05  module managing your network enviornment
05 module managing your network enviornment
 
Sockets and Socket-Buffer
Sockets and Socket-BufferSockets and Socket-Buffer
Sockets and Socket-Buffer
 
BeagleBone Black Booting Process
BeagleBone Black Booting ProcessBeagleBone Black Booting Process
BeagleBone Black Booting Process
 
Cisco Live! :: Introduction to IOS XR for Enterprises and Service Providers
Cisco Live! :: Introduction to IOS XR for Enterprises and Service ProvidersCisco Live! :: Introduction to IOS XR for Enterprises and Service Providers
Cisco Live! :: Introduction to IOS XR for Enterprises and Service Providers
 
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
 
Q2.12: Power Management Across OSs
Q2.12: Power Management Across OSsQ2.12: Power Management Across OSs
Q2.12: Power Management Across OSs
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SPKrzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
 
The Cell Processor
The Cell ProcessorThe Cell Processor
The Cell Processor
 
Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
 

More from Anil Kumar Pugalia (20)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Processes
ProcessesProcesses
Processes
 
System Calls
System CallsSystem Calls
System Calls
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Power of vi
Power of viPower of vi
Power of vi
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
System Calls
System CallsSystem Calls
System Calls
 
Timers
TimersTimers
Timers
 
Threads
ThreadsThreads
Threads
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Processes
ProcessesProcesses
Processes
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 

Network Drivers

  • 1. © 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Drivers
  • 2. 2© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? Understanding Network Subsystem Network Drivers: A different category Writing Network Drivers
  • 3. 3© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Subsystem (Network) Protocol Stack Typically, the TCP/IP Stack Interfaces with the User Space through network interfaces, instead of device files Unlike other drivers, does not provide any /sys or /dev entries Interface Examples: eth0, wlan1, … Resides in the <kernel_source>/net folder Network Interface Card (NIC) Drivers Driver for the Physical Network Cards Provides uniform hardware independent interface for the network protocol layer to access the card Typically, resides in the <kernel_source>/drivers/net folder
  • 4. 4© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Related Data Structures Writing a NIC or Network Driver involves Interacting with the underlying Card over its I/O Bus Providing the standard APIs to the Protocol Stack This needs three kind of Data Structures Core of Protocol Stack struct sk_buff NIC & Protocol Stack Interface struct net_device NIC I/O bus, e.g. PCI, USB, … I/O bus specific data structure
  • 5. 5© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. struct sk_buff Network Packet Descriptor Header: <linux/skbuff.h> Driver relevant Fields head – points to the start of the packet tail – points to the end of the packet data – points to the start of the pkt payload end – points to the end of the packet payload len – amount of data that the packet contains
  • 6. 6© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Socket Buffer APIs Header: <linux/skbuff.h> SK Buffer Storage struct sk_buff *dev_alloc_skb(len); dev_kfree_skb(skb); SK Buffer Operations void skb_reserve(struct sk_buff *, int len); struct sk_buff *skb_clone(struct sk_buff *, gfp_t); unsigned char *skb_put(struct sk_buff *, int len);
  • 7. 7© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Big Picture (with a PCI NIC) Network Stack sk_buff net_device eth0 system calls ifconfig ping tcpdump ... PCI Driver handler Tx dpv Network Vertical PCI Horizontal NIC Driver PCI Core PCI Ctrl Drv PCI Host Ctrl DMA Ctrl System RAM Tx Buf Rx Buf PHY NIC PCI Cfg Space Reg Space sk_buff... CPU User Space Kernel Space Hardware Space poll Soft IRQ TxDesc RxDesc
  • 8. 8© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. struct net_device Header: <linux/netdevice.h> Driver relevant Operation Fields Activation: open, stop, ioctl Data Transfer: start_xmit, poll (NAPI: new API) WatchDog: tx_timeout, int watchdog_timeo Statistics: get_stats, get_wireless_stats Typically uses struct net_device_stats, populated earlier Configuration: struct *ethtool_ops, change_mtu Structure defined in Header: <linux/ethtool.h> Bus Specific: mem_start, mem_end Latest kernels have all the operations moved under struct net_dev_ops And typically, a prefix ndo_ added and some name changes
  • 9. 9© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Net Device Registration Header: <linux/netdevice.h> Net Device Storage struct net_device *alloc_etherdev(sizeof_priv); struct net_device *alloc_ieee80211dev(sizeof_priv); struct net_device *alloc_irdadev(sizeof_priv); struct net_device *alloc_netdev(sizeof_priv, name, setup_fn); void free_netdev(struct net_device *); Registering the Net Device int register_netdev(struct net_device *); void unregister_netdev(struct net_device *);
  • 10. 10© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Device Open & Close A typical Network Device Open Allocates ring buffers and associated sk_buffs Initializes the Device Gets the MAC, … from device EEPROM Requests firmware download, if needed int request_firmware(fw, name, device); Register the interrupt handler(s) A typical Network Device Close Would do the reverse in chronology reverse order
  • 11. 11© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Packet Receive Interrupt Handler A typical receive interrupt handler Minimally handles the packet received Sanity checks Puts back equal number of sk_buffs for re-use Passes the associated sk_buffs (& ring buffers) to the protocol layer by the NET_RX_SOFTIRQ On higher load, switch to poll mode, if supported, which then passes the associated sk_buffs (& ring buffers) to the protocol layer by the NET_RX_SOFTIRQ
  • 12. 12© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Flow Control related APIs For interaction with the protocol layer Header: <linux/netdevice.h> APIs void netif_start_queue(struct net_device *); void netif_stop_queue(struct net_device *); void netif_wake_queue(struct net_device *); int netif_queue_stopped(struct net_device *);
  • 13. 13© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Driver Examples Driver: snull Browse & Discuss Driver for Realtek NIC 8136 Browse & Hack
  • 14. 14© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? Linux Network Subsystem How are Network Drivers different? Writing Network Drivers Key Data Structures & their APIs sk_buff & net_device Network Device Registration Network Device Operations Interrupt Handling for Packets received Flow Control related APIs
  • 15. 15© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?