📄 r8180_if.c
字号:
/* r8180_if.c: Part of Linux wireless lan driver for RTL8180. *//* Written 2002-2003 by ShuChen. This software may be used and distributed according to the terms of the GNU General Public License (GPL), incorporated herein by reference. Drivers based on or derived from this code fall under the GPL and must retain the authorship, copyright and license notice. This file is not a complete program and may only be used when the entire operating system is licensed under the GPL. The original author may be reached as shuchen@realtek.com.tw*/#include <linux/module.h>#include <linux/kernel.h>#include <linux/config.h>#include <linux/init.h>#include <linux/ioport.h>#include <linux/sched.h>#include <linux/types.h>#include <linux/slab.h>#include <linux/netdevice.h>#include <linux/pci.h>#include <linux/etherdevice.h>#include <linux/delay.h>#include <linux/rtnetlink.h> //for rtnl_lock()#include <linux/wireless.h>#include <linux/timer.h>#include <linux/proc_fs.h> // Necessary because we use the proc fs#include <linux/circ_buf.h>#include <asm/uaccess.h> //for copy_from_user#include <asm/io.h>#include "r8180_type.h"#include "r8180_pci_init.h"#include "r8180_export.h"/****************************************************************** (1)Allocate net_device and rtl8180 private area. (2)Initialize net_device******************************************************************/static struct net_device *rtl_alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)){ struct net_device *dev; int alloc_size; //------------------------------------------------------- // ensure 32-byte alignment of the private area //------------------------------------------------------- alloc_size = sizeof (*dev) + sizeof_priv + 31; //------------------------------------------------------- // Memory-Allocate for *dev, privete_data //------------------------------------------------------- dev = (struct net_device *) kmalloc (alloc_size, GFP_KERNEL); if (dev == NULL) { printk(KERN_ERR "alloc_dev: Unable to allocate device memory.\n"); return NULL; } memset(dev, 0, alloc_size); //------------------------------------------------------- // ensure 32-byte alignment of the private area //------------------------------------------------------- if (sizeof_priv){ dev->priv = (void *) (((long)(dev + 1) + 31) & ~31); } //------------------------------------------------------- // Setup net_device //------------------------------------------------------- setup(dev); //------------------------------------------------------- // Setup net_device name //------------------------------------------------------- strcpy(dev->name, mask); return dev;}//end of static struct net_device *rtl8180_init_netdev()//==========================================================================================// rtl_alloc_wlandev()// based on alloc_etherdev() - Allocates and sets up an ethernet device.// @sizeof_priv: Size of additional driver-private structure to be allocated for this ethernet device// Fill in the fields of the device structure with ethernet-generic values.// Basically does everything except registering the device.// Constructs a new net device, complete with a private data area of// size @sizeof_priv. A 32-byte (not bit) alignment is enforced for// this private data area.//==========================================================================================struct net_device *rtl_alloc_wlandev(struct net_device *dev, int sizeof_priv){ DPRINTK_INFO("%s() in rtl8180_pci_probe(). \n", __FUNCTION__); /****************************************************************** (1)Allocate net_device and rtl8180 private area. (2)Initialize net_device ******************************************************************/ return rtl_alloc_netdev( sizeof_priv, "wlan%d", ether_setup );}//==========================================================================================// rtl_register_netdev()// Register the net device once everything initializes.//==========================================================================================int rtl_register_netdev(struct net_device *dev){ DPRINTK_INFO("%s() in rtl8180_pci_probe() once everything initializes. (after request_irq)\n", __FUNCTION__); return register_netdev(dev);}//==========================================================================================// rtl_unregister_netdev()// Unregister the net device once everything initializes.//==========================================================================================void rtl_unregister_netdev(struct net_device *dev){ DPRINTK_INFO("%s() in rtl8180_pci_remove(). \n", __FUNCTION__); unregister_netdev(dev);}/************************************************************************************************************************************/struct sk_buff *rtl_dev_alloc_skb(unsigned int length){ return dev_alloc_skb( length );}/************************************************************************************************************************************/void rtl_skb_reserve(struct sk_buff *skb, unsigned int len){ skb_reserve( skb, len );}/************************************************************************************************************************************/void rtl_kfree_skb(struct sk_buff *skb){ dev_kfree_skb_irq(skb); //dev_kfree_skb(skb);}int rtl_malloc_cnt = 0;/************************************************************************************************************************************/unsigned char *rtl_malloc(int size, int flags){ unsigned char *buf; rtl_malloc_cnt ++; buf = kmalloc( (size_t)size, flags); return buf;}/************************************************************************************************************************************/void rtl_free( unsigned char *buf){ rtl_malloc_cnt --; kfree ( (void *)buf );}/************************************************************************************************************************************/int rtl_netif_running(struct net_device *dev){ return netif_running(dev);}/************************************************************************************************************************************/int rtl_netif_queue_stopped(struct net_device *dev){ return netif_queue_stopped(dev);}/************************************************************************************************************************************/void rtl_netif_wake_queue(struct net_device *dev){ netif_wake_queue(dev);}/************************************************************************************************************************************/void rtl_netif_start_queue(struct net_device *dev){#if( LINUX_VERSION_CODE < 0x020338) dev->tbusy = 0; dev->start = 1;#else netif_start_queue(dev);#endif //end #if( LINUX_VERSION_CODE < 0x020343)}/************************************************************************************************************************************/void rtl_netif_stop_queue(struct net_device *dev){#if( LINUX_VERSION_CODE < 0x020338) dev->tbusy = 1; dev->start = 0;#else netif_stop_queue(dev);#endif //end #if( LINUX_VERSION_CODE < 0x020343)}/****************************************************************** Indicate received frame.******************************************************************/void rtl_indicate_rx_frame(struct net_device *dev, struct sk_buff *rx_skb, int frame_len){ int ret; rx_skb->dev = dev; skb_put ( rx_skb, frame_len ); //rx_skb->tail = rx_skb->data + frame_len; rx_skb->protocol = eth_type_trans ( rx_skb, dev ); ret = netif_rx (rx_skb);// switch(ret)// {// case NET_RX_SUCCESS: printk("%s: NETIF_RX_SUCCESS\n", dev->name); break;// case NET_RX_CN_LOW: printk("%s: NETIF_RX_CN_LOW\n", dev->name); break;// case NET_RX_CN_MOD: printk("%s: NETIF_CN_MOD\n", dev->name); break;// case NET_RX_CN_HIGH: printk("%s: NETIF_CN_HIGH\n", dev->name); break;// case NET_RX_DROP: printk("%s: NETIF_RX_DROP\n", dev->name); break;// default: printk("%s: netif_rx():Unknown\n", dev->name); break;// }}//end of void Indicate_to_bridge(WLAN_CTX *wCtx, struct sk_buff *rx_skb){//===========================================================================// Move to r8180_type.h//===========================================================================unsigned long GetCurTime(void){ //return current time return jiffies;}int jiftime(char *s, long mark){ s += 8; *s-- = '\0'; *s-- = mark % 10 + '0'; mark /= 10; *s-- = mark % 10 + '0'; mark /= 10; *s-- = '.'; *s-- = mark % 10 + '0'; mark /= 10; *s-- = mark % 6 + '0'; mark /= 6; *s-- = ':'; *s-- = mark % 10 + '0'; mark /= 10; *s-- = mark % 10 + '0'; return(8);}//===========================================================================// Move to r8180_if.h//===========================================================================int timer_cnt = 0;//---------------------------------------------------------------int rtl_request_timer( timer_t *timer, unsigned long timer_expires, void *timer_func, void *timer_data ){ init_timer(timer); timer->expires = (unsigned long)(jiffies + timer_expires);// timer->expires = (unsigned long)(jiffies + timer_expires*HZ); timer->data = (unsigned long)timer_data; timer->function = timer_func; add_timer(timer); timer_cnt++; MLME_DPRINTK_INFO("request_timer at 0x%08lx, timer_cnt=%d\n", (unsigned long)timer, timer_cnt); return 0;}//===========================================================================// Move to r8180_if.h//===========================================================================void rtl_delete_timer( timer_t *del_timer_t ){ del_timer(del_timer_t); timer_cnt--; MLME_DPRINTK_INFO("delete_timer at 0x%08lx, timer_cnt=%d\n", (unsigned long)del_timer_t, timer_cnt);}//===========================================================================// Move to r8180_if.h//===========================================================================int rtl_check_timer( timer_t *timer ){ if( (timer->list.next == NULL) && (timer->list.prev == NULL) ){ return 1; } return 0;}/************************************************************************************************************************************/int rtl8180_open(struct net_device *dev){ return __rtl8180_open(dev);}/************************************************************************************************************************************/int rtl8180_close(struct net_device *dev){ return __rtl8180_close(dev);}/*---------------------------------------------------------------- rtl8180_xmit Net_device hard_start_xmit callback function. Arguments: skb - socket buffer pointer dev - net device pointer Returns: None----------------------------------------------------------------*/int rtl8180_xmit(struct sk_buff *skb, struct net_device *dev){ return __rtl8180_xmit(skb,dev);}/************************************************************************************************************************************/struct net_device_stats *rtl8180_get_stats(struct net_device *dev){ return __rtl8180_get_stats(dev);}/************************************************************************************************************************************/int rtl8180_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd){ return __rtl8180_ioctl(dev, ifr, cmd);}/************************************************************************************************************************************/void rtl8180_interrupt(int irq, void *dev_id, struct pt_regs *regs){ __rtl8180_interrupt(irq, dev_id, regs);}//-------------------------------------------------------------------------// Wireless Lan MAC initialization// Initialize SW, HW//-------------------------------------------------------------------------void rtl8180_init( struct net_device *dev ){ //----------------------------------------------------------------------------- // Allocate memory . //----------------------------------------------------------------------------- __rtl8180_alloc_mem( dev ); //----------------------------------------------------------------------------- // SW Initialization //----------------------------------------------------------------------------- __rtl8180_init_default_config( dev ); __rtl8180_sw_init( dev ); //----------------------------------------------------------------------------- // Add proc file system //----------------------------------------------------------------------------- __rtl8180_init_proc(dev); //----------------------------------------------------------------------------- // HW Initialization //----------------------------------------------------------------------------- __rtl8180_hw_init( dev );}//-------------------------------------------------------------------------// Wireless Lan MAC initialization//-------------------------------------------------------------------------void rtl8180_remove( struct net_device *dev ){ //----------------------------------------------------------------------------- // Free memory . //----------------------------------------------------------------------------- __rtl8180_free_mem( dev ); //----------------------------------------------------------------------------- // HW removal //----------------------------------------------------------------------------- __rtl8180_hw_remove( dev ); //----------------------------------------------------------------------------- // Remove proc file system //----------------------------------------------------------------------------- __rtl8180_remove_proc(dev); //----------------------------------------------------------------------------- // SW removal //----------------------------------------------------------------------------- __rtl8180_sw_remove( dev );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -