A network driver ‘framework’ We construct a ‘skeleton’ module showing just the essential pieces of a Linux network device driver.

Slides:



Advertisements
Similar presentations
Tutorial 3 - Linux Interrupt Handling -
Advertisements

Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
The ATA/IDE Interface Can we write a character-mode device driver for the hard disk?
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
Creating a device-file node An introduction to some privileged Linux system-calls (needed for an upcoming programming exercise)
Exceptions and Interrupts
1 Homework Reading –Review previous material on “interrupts” Machine Projects –MP4 Due today –Starting on MP5 (Due at start of Class 28) Labs –Continue.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Message Signaled Interrupts
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
EET 450 Chapter 2 – How hardware and Software Work Together.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
Handling a UART interrupt A look at some recent changes in the Linux kernel’s programming interface for device-interrupts.
A “real” network driver? We want to construct a Linux network device-driver that is able to send and receive packets.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
The ‘net_device’ structure A look at the main kernel-object concerned with a Linux system’s network interface controller.
OS Spring’03 Introduction Operating Systems Spring 2003.
Our ‘nic.c’ module We create a ‘character-mode’ device-driver for the 82573L NIC to use in future experiments.
Adjusting out device-driver Here we complete the job of modifying our ‘nicf.c’ Linux driver to support ‘raw’ packet-transfers.
What’s needed to transmit? A look at the minimum steps required for programming our anchor nic’s to send packets.
Common network diagnostic and configuration utilities A ‘toolkit’ for network users and managers when ‘troubleshooting’ is needed on your network.
Advanced Programmable Interrupt Controllers Multiprocessor-systems require enhanced circuitry for signaling of external interrupt-requests.
Dr. Kimberly E. Newman Hybrid Embedded wk3 Fall 2009.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Intel 945 Motherboard architecture GMCH ICH7 (8254,8259,8237) Interrupt & io-apic IDT, GDT Multiprocessor.
Operating System Program 5 I/O System DMA Device Driver.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Input Systems (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Xen I/O Overview. Xen is a popular open-source x86 virtual machine monitor – full-virtualization – para-virtualization para-virtualization as a more efficient.
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Date: File:PRO1_12E.1 SIMATIC S7 Siemens AG All rights reserved. Information and Training Center Knowledge for Automation Troubleshooting.
Microprocessors 1 MCS-51 Interrupts.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
6-1 Infineon 167 Interrupts The C167CS provides 56 separate interrupt sources that may be assigned to 16 priority levels. The C167CS uses a vectored interrupt.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Lecture 7 Interrupt ,Trap and System Call
Interrupts and Exceptions 國立中正大學 資訊工程研究所 羅習五 老師. Interrupt & Exceptions Interrupts – maskable & nonmaskable interrupt Exceptions – Processor-detected.
Introduction to Operating Systems Concepts
Homework Reading Machine Projects
Linux Kernel Development - Robert Love
Interrupts and signals
Microprocessor Systems Design I
Homework Reading Machine Projects Labs
Operating Systems Lecture 3.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
COMP3221: Microprocessors and Embedded Systems
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

A network driver ‘framework’ We construct a ‘skeleton’ module showing just the essential pieces of a Linux network device driver

Overview hardware device driver module Linux operating system Kernel networking subsystem application program standard runtime libraries user space kernel space

Source-code layout #include … typedef struct { /* driver’s private data */ } MY_DRIVERDATA; char modname[ ] = “netframe”; struct net_device *netdev; netframe.c my_initmy_exit The mandatory module- administration functions my_open() my_stop() my_hard_start_xmit() my_isr() my_get_info() The network driver’s “payload” functions

module_init() This function will execute when the driver is installed in the kernel (‘/sbin/insmod’) Its role is to allocate and partially initialize a ‘struct net_device’ object for our network interface controller (i.e., hardware device), then “register” that object with the kernel For ethernet NICs there exists a kernel helper-function that drivers can utilize

The ‘key’ statements… typedefstruct { /* the driver’s private data */ } MY_DRIVERDATA; struct net_device *netdev; static int __init my_init( void ) { netdev = alloc_etherdev( sizeof( MY_DRIVERDATA ) ); if ( !netdev ) return –ENOMEM; netdev->open= my_open; netdev->stop= my_stop; netdev->hard_start_xmit = my_hard_start_xmit; returnregister_netdev( netdev ); }

module_exit() This function will execute when the driver is removed from the kernel (‘/sbin/rmmod’) Its role is to “unregister” the ‘net_device’ structure and free the memory that was allocated during the module’s initialization

The ‘key’ statements… struct net_device *netdev; static void __exit my_exit( void ) { unregister_netdev( netdev ); free_netdev( netdev ); }

open() The kernel will call this function when the system administrator “configures” the NIC (e.g., with the ‘/sbin/ifconfig’ command) to assign an IP-address to the interface and and bring it UP Thus the role of ‘open()’ would be to reset the hardware to a known working state and initiate packet-queueing by the kernel

The ‘key’ statements… int my_open( struct net_device *dev ) { /* initialize any remaining ‘private’ data */ /* prepare the hardware for operation */ /* install an Interrupt Service Routine */ /* enable the NIC to generate interrupts */ netif_start_queue( netdev ); return0; //SUCCESS }

stop() The kernel will call this function when the NIC is brought DOWN (i.e., to turn off its transmission and reception of packets) This could occur because of a command (such as ‘/sbin/ifconfig’) executed by the System Administrator, or because a user is removing the driver-module from the kernel (with the ‘/sbin/rmmod’ command)

The ‘key’ statements… int my_stop( struct net_device *dev ) { netif_stop_queue( netdev ); /* kill any previously scheduled ‘tasklets’ (or other deferred work) */ /* turn off the NIC’s transmit and receive engines */ /* disable the NIC’s ability to generate interrupts */ /* delete the NIC’s Interrupt Service Routine */ return0; //SUCCESS }

hard_start_xmit() The kernel will call this function whenever it has data that it wants the NIC to transmit The kernel will supply the address for a socket-buffer (‘struct sk_buff’) that holds the packet-data that is to be transmitted So this function’s duties are: to initiate transmission, update relevant statistics, and then release that ‘sk_buff’ structure

The ‘key’ statements… int my_hard_start_xmit( struct sk_buff *skb, struct net_device *dev ) { /* code goes here to initiate transmission by the hardware */ dev->trans_start= jiffies; dev->stats.tx_packets += 1; dev->stats.tx_bytes += skb->len; dev_kfree_skb( skb ); return0; //SUCCESS }

What about reception? The NIC hardware receives data-packets asynchronously – not at a time of its own choosing – and we don’t want our system to be ‘stalled’ doing ‘busy-waiting’ Thus an interrupt handler is normally used to detect and arrange for received packets to be validated and dispatched to upper layers in the kernel’s network subsystem

Simulating an interrupt Our network device-driver ‘framework’ was only designed for demonstration purposes; it does not work with any actual hardware But we can use a ‘software interrupt’ that will trigger the execution of our ISR To implement this scheme, we’ll need to employ an otherwise unused IRQ-number, along with its associated ‘Interrupt-ID’

Advanced Programmable Interrupt Controller Multi-CORE CPU CPU 0 CPU 1 I/O APIC LOCAL APIC LOCAL APIC ●●●●●● IRQ0 IRQ1 IRQ2 IRQ3 IRQ23 The I/O APIC component is programmable – its 24 inputs can be assigned to interrupt ID-numbers in the range 0x20..0xFF (lower numbers are reserved by Intel for the CPU’s exception-vectors) The I/O-APIC’s 24 Redirection Table registers determine these assignments

The I/O APIC in our classroom machines supports 24 Interrupt-Request input-lines Its 24 programmable registers determine how interrupt-signals get routed to CPUs Two-dozen IRQs Redirection-table

Redirection Table Entry reserved interrupt vector ID L/PL/P STATUSSTATUS H/LH/L RIRRRIRR E/LE/L MASKMASK extended destination destination delivery mode 000 = Fixed 001 = Lowest Priority 010 = SMI 011 = (reserved) 100 = NMI 101 = INIT 110 = (reserved) 111 = ExtINT Trigger-Mode (1=Edge-triggered, 0=Level-triggered) Remote IRR (for Level-Triggered only) 0 = Reset when EOI received from Local-APIC 1 = Set when Local-APICs accept Level-Interrupt sent by IO-APIC Interrupt Input-pin Polarity (1=Active-High, 0=Active-Low) Destination-Mode (1=Logical, 0=Physical) Delivery-Status (1=Pending, 0=Idle)

Our ‘ioapic.c’ module Last semester we created a module that will show us which IRQ-numbers are not currently being used by our system, and the Interrupt-IDs those IRQ-signals were assigned to by Linux during ‘startup’ Timeout for an in-class demonstration

my_isr() We created a “dummy” Interrupt Service Routine for our ‘netframe.c’ demo-module #define IRQ4// temporarily unused (normally for serial-UART #define intID0x49// our I/O-APIC has assigned this ID to to IRQ 4 irqreturn_t my_isr( int irq, void *my_netdev_addr ) { struct net_device *dev = (struct net_device *)my_netdev_addr; MY_DRIVERDATA*priv = dev->priv; // we do processing of the received packet in our “bottom half” tasklet_schedule( &priv->my_rxtasklet ); returnIRQ_HANDLED; }

Installing and removing an ISR if ( request_irq( IRQ, my_isr, IRQF_SHARED, dev->name, dev ) < 0 ) return –EBUSY; IRQ’s signal-number entry-point for interrupt-handler option-flagsname for display ISR data-argument free_irq( IRQ, dev ); This statement would go in the driver’s ‘open()’ function… …and this statement would go in the driver’s ‘stop()’ function Here ‘dev’ is the address of the interface’s ‘struct net_device’ object

Processing a received packet When the NIC notifies our driver that it has received a new ethernet-packet, our driver must allocate a socket-buffer structure for the received data, initialize the ‘sk_buff’ with that data and supporting parameters, then pass that socket-buffer upward to the kernel’s network subsystem for delivery to the appropriate application-program that is listening for it

The ‘key’ statements… void my_rxhandler( unsigned long data ) { struct net_device*dev = (struct net_device *)data; struct sk_buff*skb; intrxbytes = 60;// just an artificial value here skb = dev_alloc_skb( rxbytes + 2 ); skb->dev = dev; skb->protocol = eth_type_trans( skb, dev ); skb->ip_summed = CHECKSUM_NONE; dev->stats.rx_packets += 1; dev->stats.rx_bytes += rxbytes; netif_rx( skb ); }

Triggering the interrupt… We allow a user to trigger execution of our interrupt-handler (for testing purposes), by reading from a pseudo-file that our driver creates during module-initialization, whose ‘get_info()’ function includes execution of a software-interrupt instruction: ‘int $0x49’ This inline assembly language instruction is produced via the GNU ‘asm’ construct

Using the ‘asm-construct’ #define intID0x49 asm(“ int %0 “ : : “i” (intID) ); assembly language opcode parameter indicator parameter type (“i” = immediate data) parameter-value (symbolic) statement keyword This example shows how a symbolic constant’s value, defined in the high-level C programming language using a ‘#define’ preprocessor directive, is able to be referenced by an “inline” assembly language statement within a C code-module

Testing our ‘framework’ You can download, compile, and install our ‘netframe.c’ network driver module It doesn’t do anything with real hardware, but it does illustrate essential interactions of a network device driver with the Linux operating system’s networking subsystem

In-class exercise #1 Use the ‘/sbin/ifconfig’ command to assign an IP-address to the ‘struct net_device’ object that our framework-module creates You can discover the interface’s name by using our earlier ‘netdevs.c’ module You should use a ‘private’ IP-address EXAMPLE (for station ‘hrn23501’): $ sudo /sbin/ifconfig eth up

In-class exercise #2 Use ‘ifconfig’ to confirm the IP-address, the IRQ, and the interface’s status: $ /sbin/ifconfig eth1 Use ‘ifconfig’ to examine the interface’s statistics (packets transmitted/received)

In-class exercise #3 Use the ‘cat’ command to simulate an interrupt from your device’s interface Verify that your interrupt-handler did get executed, by looking at the statistics, and by displaying the output of a pseudo-file Linux creates (named ‘/proc/interrupts’) $ cat /proc/interrupts

In-class exercise #4 Try removing the ‘netframe.ko’ module (with the ‘/sbin/rmmod’ command), then use the ‘dmesg’ command to see your system’s log-file messages