⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r8180_core.c

📁 rtl8180网卡在linux下的驱动程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*   This is part of rtl8180 OpenSource driver - v 0.21   Copyright (C) Andrea Merello 2004-2005  <andreamrl@tiscali.it>    Released under the terms of GPL (General Public Licence)      Parts of this driver are based on the GPL part of the official    Realtek driver.      Parts of this driver are based on the rtl8180 driver skeleton    from Patric Schenke & Andres Salomon.   Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.   bo    Parts of BB/RF code are derived from David Young rtl8180 netbsd driver.      RSSI calc function from 'The Deuce'      Some ideas borrowed from the 8139too.c driver included in linux kernel.      We (I?) want to thanks the Authors of those projecs and also the    Ndiswrapper's project Authors.*/#ifndef CONFIG_FORCE_HARD_FLOATdouble __floatsidf (int i) { return i; }unsigned int __fixunsdfsi (double d) { return d; }double __adddf3(double a, double b) { return a+b; }double __addsf3(float a, float b) { return a+b; }double __subdf3(double a, double b) { return a-b; }double __extendsfdf2(float a) {return a;}#endif/*#define DEBUG_RX_SKB#define DEBUG_TX_FRAG#define DEBUG_RX_FRAG#define DEBUG_TX_FILLDESC#define DEBUG_TX#define DEBUG_IRQ#define DEBUG_RX_VERBOSE#define DEBUG_RX#define DEBUG_RXALLOC#define DUMMY_RX#define DEBUG_EPROM#define DEBUG_REGISTERS#define DEBUG_RING#define DEBUG_IRQ_TASKLET#define DEBUG_TX_ALLOC#define DEBUG_TX_DESC*///#define CONFIG_RTL8180_IO_MAP#include "r8180_hw.h"#include "r8180.h"#include "r8180_sa2400.h"  /* PHILIPS Radio frontend */#include "r8180_max2820.h" /* MAXIM Radio frontend */#include "r8180_gct.h"     /* GCT Radio frontend */#include "r8180_93cx6.h"   /* Card EEPROM */#include "r8180_wx.h"#ifdef CONFIG_RTL8180_PM#include "r8180_pm.h"#endif#ifndef PCI_VENDOR_ID_BELKIN	#define PCI_VENDOR_ID_BELKIN 0x1799#endif#ifndef PCI_VENDOR_ID_DLINK	#define PCI_VENDOR_ID_DLINK 0x1186#endif	static struct pci_device_id rtl8180_pci_id_tbl[] __devinitdata = {        {                .vendor = PCI_VENDOR_ID_REALTEK,                .device = 0x8180,                .subvendor = PCI_ANY_ID,                .subdevice = PCI_ANY_ID,                .driver_data = 0,        },        {                .vendor = PCI_VENDOR_ID_BELKIN,                .device = 0x6001,                .subvendor = PCI_ANY_ID,                .subdevice = PCI_ANY_ID,                .driver_data = 1,        },        {       /* Belkin F5D6020 v3 */	        .vendor = PCI_VENDOR_ID_BELKIN,                .device = 0x6020,                .subvendor = PCI_ANY_ID,                .subdevice = PCI_ANY_ID,                .driver_data = 2,        },        {       /* D-Link DWL-610 */                .vendor = PCI_VENDOR_ID_DLINK,                .device = 0x3300,                .subvendor = PCI_ANY_ID,                .subdevice = PCI_ANY_ID,                .driver_data = 3,        },        {                .vendor = 0,                .device = 0,                .subvendor = 0,                .subdevice = 0,                .driver_data = 0,        }};static char* ifname = "wlan%d";static int hwseqnum = 0;static int hwwep = 0;static int channels = 0x3fff;MODULE_LICENSE("GPL");MODULE_DEVICE_TABLE(pci, rtl8180_pci_id_tbl);MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 WiFi cards");MODULE_PARM(ifname,"s");MODULE_PARM_DESC(devname," Net interface name, wlan%d=default");MODULE_PARM(hwseqnum,"i");MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");MODULE_PARM(hwwep,"i");MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");MODULE_PARM(channels,"i");MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");static int __devinit rtl8180_pci_probe(struct pci_dev *pdev, 				       const struct pci_device_id *id);static void __devexit rtl8180_pci_remove(struct pci_dev *pdev);static struct pci_driver rtl8180_pci_driver = {	.name		= RTL8180_MODULE_NAME,	          /* Driver name   */	.id_table	= rtl8180_pci_id_tbl,	          /* PCI_ID table  */	.probe		= rtl8180_pci_probe,	          /* probe fn      */	.remove		= __devexit_p(rtl8180_pci_remove),/* remove fn     */#ifdef CONFIG_RTL8180_PM	.suspend	= rtl8180_suspend,	          /* PM suspend fn */	.resume		= rtl8180_resume,                 /* PM resume fn  */#else	.suspend	= NULL,			          /* PM suspend fn */	.resume      	= NULL,			          /* PM resume fn  */#endif};#ifdef CONFIG_RTL8180_IO_MAPu8 read_nic_byte(struct net_device *dev, int x) {        return 0xff&inb(dev->base_addr +x);}u32 read_nic_dword(struct net_device *dev, int x) {        return inl(dev->base_addr +x);}u16 read_nic_word(struct net_device *dev, int x) {        return inw(dev->base_addr +x);}void write_nic_byte(struct net_device *dev, int x,u8 y){        outb(y&0xff,dev->base_addr +x);}void write_nic_word(struct net_device *dev, int x,u16 y){        outw(y,dev->base_addr +x);}void write_nic_dword(struct net_device *dev, int x,u32 y){        outl(y,dev->base_addr +x);}#else /* RTL_IO_MAP */u8 read_nic_byte(struct net_device *dev, int x) {        return 0xff&readb((u8*)dev->mem_start +x);}u32 read_nic_dword(struct net_device *dev, int x) {        return readl((u8*)dev->mem_start +x);}u16 read_nic_word(struct net_device *dev, int x) {        return readw((u8*)dev->mem_start +x);}void write_nic_byte(struct net_device *dev, int x,u8 y){        writeb(y,(u8*)dev->mem_start +x);}void write_nic_dword(struct net_device *dev, int x,u32 y){        writel(y,(u8*)dev->mem_start +x);}void write_nic_word(struct net_device *dev, int x,u16 y) {        writew(y,(u8*)dev->mem_start +x);}#endif /* RTL_IO_MAP */irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs);void set_nic_rxring(struct net_device *dev);void set_nic_txring(struct net_device *dev);static struct net_device_stats *rtl8180_stats(struct net_device *dev);void rtl8180_commit(struct net_device *dev);/****************************************************************************   -----------------------------PROCFS STUFF-------------------------*****************************************************************************/static struct proc_dir_entry *rtl8180_proc = NULL;static int proc_get_registers(char *page, char **start,			  off_t offset, int count,			  int *eof, void *data){	struct net_device *dev = data;//	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;		int len = 0;	int i,n;				int max=0xff;		/* This dump the current register page */	for(n=0;n<=max;)	{		//printk( "\nD: %2x> ", n);		len += snprintf(page + len, count - len,			"\nD:  %2x > ",n);		for(i=0;i<16 && n<=max;i++,n++)		len += snprintf(page + len, count - len,			"%2x ",read_nic_byte(dev,n));		//	printk("%2x ",read_nic_byte(dev,n));	}	len += snprintf(page + len, count - len,"\n");			*eof = 1;	return len;}static int proc_get_stats_hw(char *page, char **start,			  off_t offset, int count,			  int *eof, void *data){	struct net_device *dev = data;	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;		int len = 0;		len += snprintf(page + len, count - len,		"NIC int: %lu\n"		"Total int: %lu\n",		priv->stats.ints,		priv->stats.shints);				*eof = 1;	return len;}static int proc_get_stats_rx(char *page, char **start,			  off_t offset, int count,			  int *eof, void *data){	struct net_device *dev = data;	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;		int len = 0;		len += snprintf(page + len, count - len,		"RX descriptor not available: %lu\n"		"RX incomplete (missing last descriptor): %lu\n"		"RX not data: %lu\n"		"RX descriptor pointer reset: %lu\n"		"RX descriptor pointer lost: %lu\n"		"RX pointer workaround: %lu\n"		"RX error int: %lu\n"		"RX fifo overflow: %lu\n"		"RX int: %lu\n"		"RX packet: %lu\n"		"RX bytes: %lu\n"		"RX DMA fail: %lu\n",		priv->stats.rxrdu,		priv->stats.rxnolast,		priv->stats.rxnodata,		priv->stats.rxreset,		priv->stats.rxnopointer,		priv->stats.rxwrkaround,		priv->stats.rxerr,		priv->stats.rxoverflow,		priv->stats.rxint,		priv->ieee80211->stats.rx_packets,		priv->ieee80211->stats.rx_bytes,		priv->stats.rxdmafail);		*eof = 1;	return len;}static int proc_get_stats_ieee(char *page, char **start,			  off_t offset, int count,			  int *eof, void *data){	struct net_device *dev = data;	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;		int len = 0;		len += snprintf(page + len, count - len,		"TXed association requests: %u\n"		"TXed authentication requests: %u\n"		"RXed successful association response: %u\n"		"RXed failed association response: %u\n"		"RXed successful authentication response: %u\n"		"RXed failed authentication response: %u\n"		"Association requests without response: %u\n"		"Authentication requests without response: %u\n"		"TX probe response: %u\n"		"RX probe request: %u\n"		"TX probe request: %lu\n"		"RX authentication requests: %lu\n"					"RX association requests: %lu\n"		"Reassociations: %lu\n",		priv->ieee80211->ieee_stats.tx_ass,		priv->ieee80211->ieee_stats.tx_aut,		priv->ieee80211->ieee_stats.rx_ass_ok,		priv->ieee80211->ieee_stats.rx_ass_err,		priv->ieee80211->ieee_stats.rx_aut_ok,		priv->ieee80211->ieee_stats.rx_aut_err,		priv->ieee80211->ieee_stats.ass_noresp,		priv->ieee80211->ieee_stats.aut_noresp,		priv->ieee80211->ieee_stats.tx_probe,		priv->ieee80211->ieee_stats.rx_probe,		priv->ieee80211->ieee_stats.tx_probe_rq,		priv->ieee80211->ieee_stats.rx_auth_rq,		priv->ieee80211->ieee_stats.rx_assoc_rq,		priv->ieee80211->ieee_stats.reassoc);	*eof = 1;	return len;}	static int proc_get_stats_ap(char *page, char **start,			  off_t offset, int count,			  int *eof, void *data){	struct net_device *dev = data;	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;	struct mac_htable_t *list;	int i;	int len = 0;		if(priv->ieee80211->iw_mode != IW_MODE_MASTER){		len += snprintf(page + len, count - len,		"Card is not acting as AP...\n"		);	}else{		len += snprintf(page + len, count - len,		"List of associated STA:\n"		);				for(i=0;i<MAC_HTABLE_ENTRY;i++)			for (list = priv->ieee80211->assoc_htable[i]; list!=NULL; list = list->next){				len += snprintf(page + len, count - len, 					MACSTR"\n",MAC2STR(list->adr)); 			} 			}	*eof = 1;	return len;}static int proc_get_stats_tx(char *page, char **start,			  off_t offset, int count,			  int *eof, void *data){	struct net_device *dev = data;	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;		int len = 0;		len += snprintf(page + len, count - len,		"TX normal priority ok int: %lu\n"		"TX normal priority error int: %lu\n"		"TX high priority ok int: %lu\n"		"TX high priority failed error int: %lu\n"		"TX low priority ok int: %lu\n"		"TX low priority failed error int: %lu\n"		"TX bytes: %lu\n"		"TX packets: %lu\n"		"TX queue resume: %lu\n"		"TX queue stopped?: %d\n"		"TX fifo overflow: %lu\n"		"SW TX stop: %lu\n"		"SW TX wake: %lu\n"		"TX beacon: %lu\n"		"TX beacon aborted: %lu\n",		priv->stats.txnpokint,		priv->stats.txnperr,		priv->stats.txhpokint,		priv->stats.txhperr,		priv->stats.txlpokint,		priv->stats.txlperr,		priv->ieee80211->stats.tx_bytes,		priv->ieee80211->stats.tx_packets,		priv->stats.txresumed,		netif_queue_stopped(dev),		priv->stats.txoverflow,		priv->ieee80211->ieee_stats.swtxstop,		priv->ieee80211->ieee_stats.swtxawake,		priv->stats.txbeacon,		priv->stats.txbeaconerr);				*eof = 1;	return len;}		static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev){       struct r8180_priv *priv = dev->priv;       return &priv->wstats;}void rtl8180_proc_module_init(void){		DMESG("Initializing proc filesystem");	rtl8180_proc=create_proc_entry(RTL8180_MODULE_NAME, S_IFDIR, proc_net);}void rtl8180_proc_module_remove(void){	remove_proc_entry(RTL8180_MODULE_NAME, proc_net);}void rtl8180_proc_remove_one(struct net_device *dev){	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;	if (priv->dir_dev) {		remove_proc_entry("stats-hw", priv->dir_dev);		remove_proc_entry("stats-tx", priv->dir_dev);		remove_proc_entry("stats-rx", priv->dir_dev);		remove_proc_entry("stats-ieee", priv->dir_dev);		remove_proc_entry("stats-ap", priv->dir_dev);		remove_proc_entry("registers", priv->dir_dev);		remove_proc_entry(dev->name, rtl8180_proc);		priv->dir_dev = NULL;	}}void rtl8180_proc_init_one(struct net_device *dev){	struct proc_dir_entry *e;	struct r8180_priv *priv = (struct r8180_priv *)dev->priv;	priv->dir_dev = create_proc_entry(dev->name, 					  S_IFDIR | S_IRUGO | S_IXUGO, 					  rtl8180_proc);	if (!priv->dir_dev) {		DMESG("EE: Unable to initialize /proc/net/rtl8180/%s\n",		      dev->name);		return;	}		e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,				   priv->dir_dev, proc_get_stats_hw, dev);				   	if (!e) {		DMESG("Unable to initialize "		      "/proc/net/rtl8180/%s/stats-hw\n",		      dev->name);	}		e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,				   priv->dir_dev, proc_get_stats_rx, dev);				   	if (!e) {		DMESG("Unable to initialize "		      "/proc/net/rtl8180/%s/stats-rx\n",		      dev->name);	}			e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,				   priv->dir_dev, proc_get_stats_tx, dev);				   	if (!e) {		DMESG("Unable to initialize "		      "/proc/net/rtl8180/%s/stats-tx\n",		      dev->name);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -