DOC PREVIEW
USF CS 686 - A network driver ‘framework’

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

A network driver framework We construct a skeleton module showing just the essential pieces of a Linux network device driver Overview user space standard runtime libraries kernel space Linux operating system Kernel networking subsystem application program device driver module hardware Source code layout netframe c include linux module h include linux etherdevice h typedef struct driver s private data MY DRIVERDATA char modname netframe struct net device netdev my open my stop The network driver s payload functions my hard start xmit my isr my get info The mandatory moduleadministration functions my init my exit 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 typedef struct 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 netdev stop netdev hard start xmit return my open my stop my hard start xmit register 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 return 0 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 return 0 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 return 0 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 LOCAL APIC CPU 1 LOCAL APIC I O 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 Two dozen IRQs The I O APIC in our classroom machines supports 24 Interrupt Request input lines Redirection table Its 24 programmable registers determine how interrupt signals get routed to CPUs Redirection Table Entry 63 56 55 destination 48 32 extended destination 31 reserved 16 15 14 13 12 11 10 reserved M A S K 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 Delivery Status 1 Pending 0 Idle E L R I R R H L S T A T U S L P 9 8 delivery mode 7 0 interrupt vector ID 000 Fixed 001 Lowest Priority 010 SMI 011 reserved 100 NMI 101 INIT 110 reserved 111 ExtINT Destination Mode 1 Logical 0 Physical 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 IRQ define intID 4 0x49 temporarily unused normally for serial UART 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 return IRQ HANDLED Installing and removing an ISR entry point for interrupt handler option flags IRQ s signal number name for display ISR data argument if request irq IRQ my isr IRQF SHARED dev name dev 0 return EBUSY This statement would go in the driver s open function and this statement would go in the driver s stop function free irq IRQ dev 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


View Full Document

USF CS 686 - A network driver ‘framework’

Documents in this Course
Load more
Download A network driver ‘framework’
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view A network driver ‘framework’ and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view A network driver ‘framework’ and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?