Brief Analysis of CS8900 NIC Driver (2)

Source: Internet
Author: User

Cs8900_probe function itself is not difficult, but you must understand the important functions of probe function. Because you are likely to write a probe function for your device.

First, let's look at a line that is easy to understand.Code:
Printk (version_string "/N ");
Obviously, the information displayed during kernel startup is printed out in this sentence.

Dev_addr in net_device is the MAC address of the NIC. You should provide:

# If defined (config_arch_smdk2410)
Dev-> dev_addr [0] = 0x00;
Dev-> dev_addr [1] = 0x00;
Dev-> dev_addr [2] = 0x3e;
Dev-> dev_addr [3] = 0x26;
Dev-> dev_addr [4] = 0x0a;
Dev-> dev_addr [5] = 0x00;
# Endif

Use similar code to provide network chips
Dev-> if_port = if_port_10baset; (multiple interfaces supported)
Dev-> priv = (void *) & priv; (private data structure of the device)

Oh, I 'd like to say that if_port_10baset is defined in include/Linux/netdevice. H. You can use this enumeration type to learn more interface information:

Enum {
If_port_unknown = 0,
If_port_10base2,
If_port_10baset,
If_port_aui,
If_port_100baset,
If_port_100basetx,
If_port_100basefx
};

The following code is critical for porting. Vsmdk2410_eth_io is the virtual address of the network card, and irq_eint9 is the hardware interruption. The two values and the other addresses (physical addresses of NICS) must be defined in the header file and correctly defined.

# If defined (config_arch_smdk2410)
Dev-> base_addr = vsmdk2410_eth_io + 0x300;
Dev-> IRQ = irq_eint9;
# Endif/* # If defined (config_arch_smdk2410 )*/

Next, allocate the I/O port resources. The functions used are check_mem_region and request_mem_region. The theory in LDD is combined with the practice here. I believe you will soon master this API in driver programming.

The following code implements hardware read/write. The functions used are cs8900_read and cs8900_write. Although this pair of read/write functions can be explained in a short time, to avoid distracting your attention to the cs8900_probe function, I will leave it in the next section and say, Don't worry :)
Oh, I almost forgot. The kernel spin lock (spin_lock_init) is used here, but the spin lock mechanism is beyond the scope of this article. Now you only need to know that the spin lock is used for concurrency control and how to dynamically initialize the spin lock. If you want to learn more, please learn the APIS related to spin locks on your own. They are:

Spinlock_t spin; // defines the spin lock.
Spin_lock (Lock); // get the spin lock
Spin_trylock (Lock); // try to obtain the spin lock
Spin_unlock (Lock); // release the spin lock

In a word, the cs8900_probe function continues to initialize the device and applies for various resources.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.