?? 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 Versions: 1.0 - first release 1.1 - second release 1.2 - 2003-06-10**/#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_if.h"#include "r8180_type.h"#include "r8180_export.h"/****************************************************************** rtl8180 wireless lan driver debugging flag******************************************************************/char wlan_debug = RTL_DDEBUG_OUTINFO;/****************************************************************** (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 //------------------------------------------------------- if( setup != NULL ){ 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 ******************************************************************/#ifdef WDS{ int priv_size; if ( dev == NULL ) // ap context priv_size = sizeof_priv; else priv_size = 0; return rtl_alloc_netdev( priv_size, "wlan%d", ether_setup );}#else return rtl_alloc_netdev( sizeof_priv, "wlan%d", ether_setup );#endif}//==========================================================================================// rtl_register_netdev()// Register the net device//==========================================================================================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//==========================================================================================void rtl_unregister_netdev(struct net_device *dev){ DPRINTK_INFO("%s() in rtl8180_pci_remove(). \n", __FUNCTION__); unregister_netdev(dev);}//------------------------------------------------------// Skb statistic debug//------------------------------------------------------#ifdef ENABLE_RTL_SKB_STATS atomic_t rtl_alloc_skb_cnt; atomic_t rtl_kfree_skb_cnt; atomic_t rtl_netif_rx_skb_cnt;#endif //end #ifdef ENABLE_RTL_SKB_STATS//==========================================================================================// rtl_dev_alloc_skb()// Allocate net device socket buffer.//==========================================================================================struct sk_buff *rtl_dev_alloc_skb(unsigned int length){ struct sk_buff *skb = NULL; skb = dev_alloc_skb( length );#ifdef ENABLE_RTL_SKB_STATS rtl_skb_atomic_inc(&rtl_alloc_skb_cnt);#endif //end #ifdef ENABLE_RTL_SKB_STATS#ifdef ENABLE_RTL_SKB_TAGS_DBG if(skb){ skb_cbinfo_set_rtag(skb,RTL_TAG_FROM_DRV|RTL_TAG_WAITFREE); skb_cbinfo_set_rskb_structp(skb); skb_cbinfo_set_rskb_bufhead(skb); }#endif //end #ifdef ENABLE_RTL_SKB_TAGS_DBG return skb;}//==========================================================================================// rtl_skb_reserve()// Reserve the first $len bytes in net device socket buffer.//==========================================================================================void rtl_skb_reserve(struct sk_buff *skb, unsigned int len){ if ((unsigned int)skb == 0) printk("WLAN-OUT of SKB\n"); else skb_reserve( skb, len );}//==========================================================================================// rtl_kfree_skb()// Free net device socket buffer.//==========================================================================================void rtl_kfree_skb(struct sk_buff *skb){#ifdef ENABLE_RTL_SKB_STATS rtl_skb_atomic_inc(&rtl_kfree_skb_cnt);#endif //end #ifdef ENABLE_RTL_SKB_STATS#ifdef ENABLE_RTL_SKB_TAGS_DBG if( ( (skb_cbinfo_get_rtag(skb)&RTL_TAG_SRC_MASK) != RTL_TAG_FROM_DRV ) && ( (skb_cbinfo_get_rtag(skb)&RTL_TAG_SRC_MASK) != RTL_TAG_FROM_LLC ) ) {#ifdef ENABLE_RTL8180_TEST_MODE#else printk("%s:Unknown skb_cbinfo_get_rtag(skb)=0x%08lx\n", __FUNCTION__, skb_cbinfo_get_rtag(skb));#endif //end #ifdef ENABLE_RTL8180_TEST_MODE } else{// if( (skb_cbinfo_get_rtag(skb)==RTL_TAG_FROM_DRV) ){// printk("%s:skb_cbinfo_get_rtag(skb)=RTL_TAG_FROM_DRV\n", __FUNCTION__);// }// else if( (skb_cbinfo_get_rtag(skb)==RTL_TAG_FROM_LLC) ){// printk("%s:skb_cbinfo_get_rtag(skb)=RTL_TAG_FROM_LLC\n", __FUNCTION__);// } if( !(skb_cbinfo_get_rtag(skb)&RTL_TAG_WAITFREE) ){ printk("%s:Error for free skb, <skb_cbinfo_get_rtag(skb)=0x%08lx>\n", __FUNCTION__, skb_cbinfo_get_rtag(skb)); } skb_cbinfo_set_rtag(skb,~RTL_TAG_WAITFREE); if( skb_cbinfo_get_rskb_structp(skb) != (unsigned long)skb ){ printk("%s:Invalid skb_cbinfo_get_rskb_structp(skb)=0x%08lx, <skb=0x%08lx>\n", __FUNCTION__, (unsigned long)skb_cbinfo_get_rskb_structp(skb), (unsigned long)skb); } if( skb_cbinfo_set_rskb_bufhead(skb) != (unsigned long)skb->head ){ printk("%s:Invalid skb_cbinfo_get_rskb_bufhead(skb)=0x%08lx, <skb->head=0x%08lx>\n", __FUNCTION__, (unsigned long)skb_cbinfo_get_rskb_bufhead(skb), (unsigned long)skb->head); } }#endif //end #ifdef ENABLE_RTL_SKB_TAGS_DBG 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){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -