Skip navigation

Monthly Archives: July 2006

Topic:

This document talks about working of a ethernet card device driver in a bird’s eyeview. This is aimed at people who are interested in understanding what is happening inside the driver. If a system administrator understands this document, he/she can understand the scope of command line (ifconfig) and device driver, so that he/she need not to break his/her head with command line for something which can only be done with kernel device driver. This document can make an developer to understand the existing network device driver to some extent. This document may motivate others to start learning kernel stuff.

Assumption:

(a) You know that we talk here about kernel 2.4.X (not latest 2.6.X series kernel)

(b) You know that this network device driver is a a modularized kernel module. It is assumed that it is not linked into the kernel.

(c) The audience should have some basic “C” language and linux system administration skills.

Courtesy:

I have learned about network device driver from the famous book (my favourite too!) Linux Device Drivers – 2nd Edition by Alessandro Rubini & Jonathan Corbet from O’reilly publication. This book has helped me in preparing this document. Thanks to Authors! This book is available under GPL license for download and hard copy of book is available in all leading book stores at reasonable cost.

Feedback:

Your feedback is valuable since I too a newbie to kernel level stuff. This is my attempt to share my understanding with others, so that jointly we can fine tune this document, which can become a starting point for any network device driver programmer. You are welcome to mail me your suggestion to my mail id of “karuppuswamy” which is hosted in gmail dot com.

Enough with header….! Now let us kick start the exciting world of linux system internal of network device drivers. The following is the basic sequence and flow of code in a network driver. It does not talk in depth specific to hardware, but what ever explained here is common to all network device drivers.

1. Detecting Hardware Device:

Once a network driver is loaded into the kernel, the driver probes for the hardware device it supports (I/O ports and IRQ line). The device found are to be registered with kernel.

2. Registration with kernel:

Usually linux drivers register itself with kernel, once it is loaded. During the registration process it asks for its unique major/minor number. There will be a corresponding file in /dev directory with major/minor number allocated for that device (e.g.: /dev/hda – hard disk partition). But when a network driver is loaded into kernel, it does not ask for major/minor number as other drivers do. There is no “everything is a file” concept for network device (it means there is NO /dev/eth0 like file, similar to /dev/hda hard disk partition). Instead, the network driver inserts a data structure (struct net_device) for each newly detected interface into a global list of network devices. This structure describes the characteristics of the found device.

3. Filling up of net_device structure:

Kernel takes care of some ethernet defaults through a function (ether_setup()), which fills several fields in the net_devie structure. Device specific fields are filled by this device driver.

4. Opening (“open” method) the device:

(a) It requests and gets allocated its memory region and IRQs.

(b) The hardware address (“MAC address” popularly known as) is copied from real hardware to net_device structure.

(c) Transmit Queue of this device is started (“netif_start_queue”) to accept packets for transmission.

Note: Before the network device is used, it must be opened by the kernel in response to “ifconfig / ifup” command. With this command an IP address is assigned to the device and device is made up (ON). Assigning IP address is happening at OSI layer 3 (Network layer – IP), so this device driver (OSI layer 2 – MAC) has nothing to do with that. But to make this device up, IFF_UP flag of net_device structure is set. Kernel calls open method of this device to do the same.

5. Transmission of Packet (“hard_start_xmit” method):

(a) Whenever the kernel needs to transmit a data packet, it calls the “hard_start_xmit” method to put the data on an outgoing queue.

(b) Kernel put the data (packet) in the form of a structure called “socket buffer structure” (struct sk_buff).

(c) Device driver does not modify this data and it does some sanity checks only. Then it transmits the data by calling highly hardware dependent routines of the device.

Note1: The “hard_start_xmit” function is protected from concurrent calls by a spinlock (xmit_lock).

Note2: The hardware interface (ethernet card) has limited memory for outgoing packets. When this memory is exhausted, the driver will tell the kernel (“netif_stop_queue”) not to start any more transmissions until the hardware is ready to accept new data. Once the driver has stopped its queue, it must arrange to restart the queue at some point in the future, when it is again able to accept packets for transmission. To do so, it should call “netif_wake_queue” method.

Note3: If the current system time exceeds the device’s “trans_start” time (which is set while a packet is transmitted) by atleast the timeout period, the networking layer will eventually call the driver’s “tx_timeout” method. That method’s job is to clear up the problem and to ensure the proper completion of any transmissions that were already in progress.

6. Receiption of Packet:

(a) When a packet is arrived at hardware, it trigges the corresponding interrupt. The interrupt handling routine of driver is called.

(b) This routine receives a pointer to the data and its length (packet), which are already available in memory. Its responsibility is to send the packet to the upper layers of networking code.

7. Closing/Releasing/Stopping (“stop” method) the device:

(a) It releases allocated memory and IRQs.

(b) Trasmit Queue of this device is stopped (“netif_stop_queue”) from accepting packets for transmission.

Note: This method is called when we issue “ifdown <dev>” command.

8. Changes in Link state:

The networking subsystem needs to know when network links go up or down, and it provides a few functions that the driver may use to convey that information. “netif_carrier_off”, “netif_carrier_on” and “netif_carrier_ok” are such functions.

Conclusion:

I had a nice experience of going through “snull” network interface explained in the LDD3 book. Wish you all the best kernel hack hours!

 

A few weeks back, after analysing various internet resources I came to conclusion that AMD 64 X2 Processors performs better than Intel Dual Core D Series Processors. But suddenly things have changed upright down. Intel has pre-released Core Duo Processors. They seem to be outperforms AMD 64 X2 in wide aspects and good margin. This is not only technically but also monetarily. But it is expected that AMD will also go for price cut by this month end. Here are the summary of benchmark testing by http://www.anandtech.com.

1. Though Core Duo does not have integrated memory controllers, memory latency is very less.
2. One of the major advantage of AMD has been met by the Core Duo processors; it is power consumption. Intel’s power consumption is competetive to AMD in this Core Duo series
3. In application performance area also Core Duo rules with large margin.
4. Surprisingly Intel wins in gaming applications too!!!!

Moral: Don’t upgrade your system with any Dual Core Processors (Intel Pentium D / AMD 64 X2) available in the market now. This month end will see a lot of price cute from both Intel and AMD. For around Rs.10,000/- we will decent hight power processors, fitting to our budget.

Reference: Anand’s comparison

Oh, God! Thanks a lot for making me learn more on Linux!
Oh, Ubuntu! Thanks a lot for giving me a stable complete system!
oh, My Wife! Thanks for caring me to work over night!
Oh, My child! Thanks for motivating me with your flash smile!

It is a lot of pain and patience to install Ubuntu 6.06 Dapper Drake LTS on my legacy (to some extent) machine. My machine is of PIII/192MB/20GB/Intel-D815-Chipset. The real problem of installing Dapper on this machine is due to low RAM. I was able to run Live Cd of SimplyMepis 3.4.1.rc1 in excellent speed and able to install during live cd session without any issues. But Ubuntu’s installation was not so easy. I had discussed with Ubuntu forums on compatibility of this machine with Ubuntu. Many Ubuntians had warned me and wished best of luck. Yes, it is true. I had a lot of patience to install Ubuntu. But after installation, it is -breezy- -breezy- -breezy- that is what I can say. Everything (yes, ***every hardware***) worked out of box with nice configuration. To my surprise, all applications are flying like jet. I don’t find any difference between working on PIV/512MB system and this legacy system. You might have read so many reviews about Ubuntu desktop system, so I need not to tell you more on that. But I want to summarize some of the important precautions/steps/consideration while installing Ubuntu 6.06 on any legacy system with lower RAM.

Upto Ubuntu 5.10, we did not have such installation problem on legacy machine. But since Ubuntu 6.06 (Dapper Drake) has become Live CD (**complete** live cd), it is not cope up with the lower RAM. Here are tips to install Ubuntu 6.06 Desktop successfully on a low end RAM system. What I am suggesting here are more safer to install and increase the chance of successful installation.

1. Boot your machine with Live CD either with option-1 (Start or Install Ubuntu) or option-2 (generice video driver mode). Ensure that you are getting desktop after a few minutes.

2. Don’t click Install icon on desktop. This installation tool is a great one, but not yet stable. This tool in turn call GParted for disk partitioning while installtion, which is also not stable. Don’t run GParted which is available on System->Administration menu also. In my three installation of Ubuntu 6.06, I have faced problem of crashing of GParted consistently. Let us utilize fdisk for partitioning work.

3. Press Ctrl+Alt+F1 to go to console. You will have already live cd user logged in shell prompt.

4. Try to allocate a full hard disk for Ubuntu installation. This technic is to avoid calling GParted in installation wizard. (Console work: You no need to do anything on console)

5. If you want to partition the hard disk for other OS also: Make sure that you have a large free space (not partitioned) available for Ubuntu installation (min 2GB). For example if you want to allocate 10GB for Ubuntu, create a 10GB free space by deleting the existing partition. No other free space size on this hard disk should be more than this 10GB of free space. This technic is to avoid calling GParted in installation wizard. (Console work example: $ sudo fdisk /dev/hda)

6. This is very important. Since live CD creates a root file system on RAM, the installation wizard has no enough RAM to run. This is the most common reason for installation hang. To avoid this we can create a temporary swap partition of atleast 256MB (512MB is fine). (Console work example:
(a) Create swap partition: $ sudo fdisk /dev/hda
(b) Make swap file system (hda5 is swap file system in this example): $ sudo mkswap /dev/hda5
(c) Add swap to the running system: $ sudo swapon /dev/hda5
(d) Make sure that swap is live: $ sudo swapon -s

7. Press Ctrl+Alt+F7 to go to desktop. Don’t run any other program in desktop (please cool, wait! don’t listen music while running installation). Double-click install icon on desktop to run Installation wizard. Now it should not take more than 20 to 30 minutes for entire installation.

8. Ubuntu will create / and swap partition automatically. If you want seperate /home partition, you can add it any time after installation.

Bottomline: 1. Avoid running GParted (use fdisk). 2. Make swap file system available for running live system.

Top moral: Linux makes you to customize your installation according to your hardware configuration. It does not warrant any strict configuration. It is all about choices and freedom.

I have got a used Intel PIII machine for my home, thanks to my guru ManiVS and Mr.Mukunthan. Though it is bit old configuration, I don’t feel so, when I loaded Mepis 3.4.1 and Gentoo 2005 Linux on that. I don’t feel any difference between working on PIV with 512MB RAM and this PIII with 192MB RAM. Linux is really mighty to run on old machines. That too KDE does not seem to be bloated. Here is the configuration:

Intel PIII 800MHz

Intel Motherboard – 815EEA based on 815 Chipset

20GB HDD + (10GB of mine)

SDRAM 128+64 = 192MB

Built-in Video 82815 Chip

Built-in Audio Ensonique 1371

2 USB Ports external

LG 14″ Color Monitor – supports upto 1024×768 60Hz

I bought the above configuration for Rs. 3000/-. Apart from this I bought Samsung Keyboard, Intex Optic Mouse, Intex Speaker and Mic for Rs.700/-.

I am going to install Ubuntu Dapper 6.06 on this machine. I dont’ have internet @ home. I have prepared Extra packages CD, from Ubuntu repositories when I was using Ubuntu Dapper in my work at T & B. This CD will make my job easy to install all the packages which are not available in Ubuntu Installation CD.