Analysis of S3C2440 driver-dm9000 NIC Driver (2)

Source: Internet
Author: User

After explaining the framework of the dm9000 NIC Driver in the first blog in this series, we should analyze this "giant thing" for beginners by module. This article first explains the. Driver and. Remove branches. What? I don't know what the two things are? Please first look at the younger brother this series of first blog (http://blog.csdn.net/jarvis_xian/archive/2011/06/10/6537446.aspx ).

 

Before introducing the two branches, we 'd better follow the steps of the analysis driver. First, find the "entry" and "exit" to be able to break in and out!

Static int _ init <br/> dm9000_init (void) <br/>{< br/> printk (kern_info "% s Ethernet driver, V % s/n", cardname, drv_version); </P> <p> return platform_driver_register (& dm9000_driver ); <br/>}</P> <p> static void _ exit <br/> dm9000_cleanup (void) <br/>{< br/> platform_driver_unregister (& dm9000_driver ); <br/>}</P> <p> module_init (dm9000_init); <br/> module_exit (dm9000_cleanup );

 

We can see that dm9000 is a platform virtual bus driver. Its platform_driver is the function parameter dm9000_driver.

Dm9000_driver:

Static struct platform_driver dm9000_driver ={< br/>. driver ={< br/>. name = "dm9000", <br/>. owner = this_module, <br/>. PM = & dm9000_drv_pm_ops, <br/>}, <br/>. probe = dm9000_probe, <br/>. remove = _ devexit_p (dm9000_drv_remove), <br/> };

Here is the three branches we mentioned above:. Driver. probe. Remove, where. Probe is left for the next blog post for detailed analysis. This article first discusses. Driver and. Remove. We can see that the most important part in the. driver structure should be the member. pm. The code for assigning the value dm9000_drv_pm_ops is as follows:

Static const struct dev_pm_ops dm9000_drv_pm_ops ={< br/>. Suspend = dm9000_drv_suspend, <br/>. Resume = dm9000_drv_resume, <br/> };

 

The following two functions are provided: dm9000_drv_suspend and dm9000_drv_resume:

 

1. dm9000_drv_suspend:

Static int dm9000_drv_suspend (struct device * Dev) <br/>{< br/> struct platform_device * pdev = to_platform_device (Dev ); <br/> struct net_device * ndev = platform_get_drvdata (pdev); <br/> board_info_t * dB; </P> <p> If (ndev) {<br/> DB = netdev_priv (ndev); <br/> DB-> in_suspend = 1; </P> <p> If (! Netif_running (ndev) <br/> return 0; </P> <p> netif_device_detach (ndev ); </P> <p>/* Only Shutdown if not using Wol */<br/> If (! DB-> wake_state) <br/> dm9000_shutdown (ndev); <br/>}< br/> return 0; <br/>}< br/>

This function is used to suspend the NIC interface. The core action is netif_device_detach (ndev );

Void netif_device_detach (struct net_device * Dev) <br/>{< br/> If (test_and_clear_bit (_ link_state_present, & Dev-> state) & <br/> netif_running (Dev) {<br/> netif_tx_stop_all_queues (Dev); <br/>}< br/>}

As the name suggests, the netif_device_detach function deletes devices temporarily. The function first checks whether the device is in the connection and running status (indispensable), and then runs the netif_tx_stop_all_queues function. Deleting a device actually stops all work queues of the device, not physically deleting the device.

 

2. dm9000_drv_resume

Static int dm9000_drv_resume (struct device * Dev) <br/>{< br/> struct platform_device * pdev = to_platform_device (Dev ); <br/> struct net_device * ndev = platform_get_drvdata (pdev); <br/> board_info_t * DB = netdev_priv (ndev); </P> <p> If (ndev) {<br/> If (netif_running (ndev )) {<br/>/* reset if we were not in wake mode to ensure if <br/> * the device was powered off it is in a known state */<br/> if (! DB-> wake_state) {<br/> dm9000_reset (db); <br/> dm9000_init_dm9000 (ndev ); <br/>}</P> <p> netif_device_attach (ndev); <br/>}</P> <p> DB-> in_suspend = 0; <br/>}< br/> return 0; <br/>}< br/>

Function to restore the interface, mainly look at netif_device_attach (ndev );
Void netif_device_attach (struct net_device * Dev) <br/>{< br/> If (! Test_and_set_bit (_ link_state_present, & Dev-> state) & <br/> netif_running (Dev) {<br/> netif_tx_wake_all_queues (Dev ); <br/>__ netdev_watchdog_up (Dev); <br/>}< br/>}

Corresponds to the netif_device_detach function. This function is used to actually wake up the work queue and wake up the network interface's watchdog.

 

3. dm9000_drv_remove

Static int _ devexit dm9000_drv_remove (struct platform_device * pdev) <br/>{< br/> struct net_device * ndev = platform_get_drvdata (pdev ); </P> <p> platform_set_drvdata (pdev, null); </P> <p> unregister_netdev (ndev ); // release the registered Network Interface <br/> dm9000_release_board (pdev, netdev_priv (ndev); // release the resource <br/> free_netdev (ndev ); // release struct </P> <p> dev_dbg (& pdev-> Dev, "released and freed device/N"); <br/> return 0; <br/>}

Similar to the previous remove function, they politely return the resources they occupy to the kernel. Imagine if each module is not so polite, if a system runs for a long time and the system resources are always exhausted, then the only thing that waits for us will crash. Therefore, courtesy not only "survive" in our daily lives, but also shows this excellent character in Linux systems!

 

The content of this article is relatively simple. when the power is warm-up, the following blog posts will analyze the series of. Probe functions and their operations. Please wait ~

 

 

 

Link to this series of courses

Dm9000 NIC Driver (1) http://blog.csdn.net/jarvis_xian/archive/2011/06/10/6537446.aspx
Dm9000 NIC Driver (2) http://blog.csdn.net/jarvis_xian/archive/2011/06/12/6539931.aspx
Dm9000 NIC Driver (3) http://blog.csdn.net/jarvis_xian/archive/2011/06/13/6542411.aspx
Dm9000 NIC Driver (4) http://blog.csdn.net/jarvis_xian/archive/2011/06/15/6545109.aspx
Dm9000 NIC Driver (5) http://blog.csdn.net/jarvis_xian/archive/2011/06/15/6547203.aspx

 

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.