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

📄 r8168.h

📁 RT8111/R8168 PCI Express 的linux驱动程序
💻 H
📖 第 1 页 / 共 3 页
字号:
/*################################################################################# # Copyright(c) Realtek Semiconductor Corp. All rights reserved.# # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version.# # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for # more details.# # You should have received a copy of the GNU General Public License along with# this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA  02111-1307, USA.# # The full GNU General Public License is included in this distribution in the# file called LICENSE.# ################################################################################*/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)#define CHECKSUM_PARTIAL CHECKSUM_HW#endif#ifndef IRQ_HANDLED#define irqreturn_t void#define IRQ_HANDLED#define IRQ_NONE#endif#ifndef HAVE_FREE_NETDEV#define free_netdev(x)	kfree(x)#endif#ifndef SET_NETDEV_DEV#define SET_NETDEV_DEV(net, pdev)#endif#ifndef SET_MODULE_OWNER#define SET_MODULE_OWNER(dev)#endif#ifndef SA_SHIRQ#define SA_SHIRQ IRQF_SHARED#endif//Due to the hardware design of RTL8111B, the low 32 bit address of receive//buffer must be 8-byte alignment.#undef NET_IP_ALIGN#define NET_IP_ALIGN 8#define CONFIG_R8168_NAPI 1#ifdef CONFIG_R8168_NAPI#define NAPI_SUFFIX	"-NAPI"#else#define NAPI_SUFFIX	""#endif#define RTL8168_VERSION "8.009.00" NAPI_SUFFIX#define MODULENAME "r8168"#define PFX MODULENAME ": "#ifdef RTL8168_DEBUG#define assert(expr) \        if(!(expr)) {					\	        printk( "Assertion failed! %s,%s,%s,line=%d\n",	\        	#expr,__FILE__,__FUNCTION__,__LINE__);		\        }#define dprintk(fmt, args...)	do { printk(PFX fmt, ## args); } while (0)#else#define assert(expr) do {} while (0)#define dprintk(fmt, args...)	do {} while (0)#endif /* RTL8168_DEBUG */#define R8168_MSG_DEFAULT \	(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)#define TX_BUFFS_AVAIL(tp) \	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)#ifdef CONFIG_R8168_NAPI#define rtl8168_rx_skb			netif_receive_skb#define rtl8168_rx_hwaccel_skb		vlan_hwaccel_receive_skb#define rtl8168_rx_quota(count, quota)	min(count, quota)#else#define rtl8168_rx_skb			netif_rx#define rtl8168_rx_hwaccel_skb		vlan_hwaccel_rx#define rtl8168_rx_quota(count, quota)	count#endif/* MAC address length */#ifndef MAC_ADDR_LEN#define MAC_ADDR_LEN	6#endif#ifndef MAC_PROTOCOL_LEN#define MAC_PROTOCOL_LEN	2#endif#define Reserved2_data	7#define RX_DMA_BURST	7	/* Maximum PCI burst, '6' is 1024 */#define TX_DMA_BURST_unlimited	7#define TX_DMA_BURST_1024	6#define TX_DMA_BURST_512	5#define TX_DMA_BURST_256	4#define TX_DMA_BURST_128	3#define TX_DMA_BURST_64		2#define TX_DMA_BURST_32		1#define TX_DMA_BURST_16		0#define Reserved1_data 	0x3F#define RxPacketMaxSize	0x3FE8	/* 16K - 1 - ETH_HLEN - VLAN - CRC... */#define Jumbo_Frame_2k	(2 * 1024)#define Jumbo_Frame_3k	(3 * 1024)#define Jumbo_Frame_4k	(4 * 1024)#define Jumbo_Frame_5k	(5 * 1024)#define Jumbo_Frame_6k	(6 * 1024)#define Jumbo_Frame_7k	(7 * 1024)#define Jumbo_Frame_8k	(8 * 1024)#define Jumbo_Frame_9k	(9 * 1024)#define InterFrameGap	0x03	/* 3 means InterFrameGap = the shortest one */#define R8168_REGS_SIZE		256#define R8168_NAPI_WEIGHT	64//#define RX_BUF_SIZE	1536	/* Rx Buffer size */#define RX_BUF_SIZE	0x05F3	/* 0x05F3 = 1523 Rx Buffer size */#define R8168_TX_RING_BYTES	(NUM_TX_DESC * sizeof(struct TxDesc))#define R8168_RX_RING_BYTES	(NUM_RX_DESC * sizeof(struct RxDesc))#define RTL8168_TX_TIMEOUT	(6*HZ)#define RTL8168_PHY_TIMEOUT	(10*HZ)#define RTL8168_ESD_TIMEOUT	(2*HZ)#define NUM_TX_DESC	1024	/* Number of Tx descriptor registers */#define NUM_RX_DESC	1024	/* Number of Rx descriptor registers */#define NODE_ADDRESS_SIZE 6/* write/read MMIO register */#define RTL_W8(reg, val8)	writeb ((val8), ioaddr + (reg))#define RTL_W16(reg, val16)	writew ((val16), ioaddr + (reg))#define RTL_W32(reg, val32)	writel ((val32), ioaddr + (reg))#define RTL_R8(reg)		readb (ioaddr + (reg))#define RTL_R16(reg)		readw (ioaddr + (reg))#define RTL_R32(reg)		((unsigned long) readl (ioaddr + (reg)))#ifndef	DMA_64BIT_MASK#define DMA_64BIT_MASK	0xffffffffffffffffULL#endif#ifndef	DMA_32BIT_MASK#define DMA_32BIT_MASK	0x00000000ffffffffULL#endif#ifndef	NETDEV_TX_OK#define NETDEV_TX_OK 0		/* driver took care of packet */#endif#ifndef	NETDEV_TX_BUSY#define NETDEV_TX_BUSY 1	/* driver tx path was busy*/#endif#ifndef	NETDEV_TX_LOCKED#define NETDEV_TX_LOCKED -1	/* driver tx lock was already taken */#endif#ifndef	ADVERTISED_Pause#define ADVERTISED_Pause	(1 << 13)#endif#ifndef	ADVERTISED_Asym_Pause#define ADVERTISED_Asym_Pause	(1 << 14)#endif#ifndef	ADVERTISE_PAUSE_CAP#define ADVERTISE_PAUSE_CAP	0x400#endif#ifndef	ADVERTISE_PAUSE_ASYM#define ADVERTISE_PAUSE_ASYM	0x800#endif#ifndef	MII_CTRL1000#define MII_CTRL1000		0x09#endif#ifndef	ADVERTISE_1000FULL#define ADVERTISE_1000FULL	0x200#endif#ifndef	ADVERTISE_1000HALF#define ADVERTISE_1000HALF	0x100#endif/*****************************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)	#define	RTLDEV	tp#else	#define	RTLDEV	dev#endif	//LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)/*****************************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)	typedef struct net_device *napi_ptr;	typedef int *napi_budget;	#define napi dev	#define RTL_NAPI_CONFIG(ndev, priv, function, weig)	ndev->poll=function;	\								ndev->weight=weig;	#define RTL_NAPI_QUOTA(budget, ndev)			min(*budget, ndev->quota)	#define RTL_GET_PRIV(stuct_ptr, priv_struct)		netdev_priv(stuct_ptr)	#define RTL_GET_NETDEV(priv_ptr)				#define RTL_RX_QUOTA(ndev, budget)			ndev->quota	#define RTL_NAPI_QUOTA_UPDATE(ndev, work_done, budget)	*budget -= work_done;	\								ndev->quota -= work_done;	#define RTL_NETIF_RX_COMPLETE(dev, napi)		netif_rx_complete(dev)	#define RTL_NETIF_RX_SCHEDULE_PREP(dev, napi)		netif_rx_schedule_prep(dev)	#define __RTL_NETIF_RX_SCHEDULE(dev, napi)		__netif_rx_schedule(dev)	#define RTL_NAPI_RETURN_VALUE				work_done >= work_to_do	#define RTL_NAPI_ENABLE(dev, napi)			netif_poll_enable(dev)	#define RTL_NAPI_DISABLE(dev, napi)			netif_poll_disable(dev)#else	typedef struct napi_struct *napi_ptr;	typedef int napi_budget;	#define RTL_NAPI_CONFIG(ndev, priv, function, weight)	netif_napi_add(ndev, &priv->napi, function, weight)	#define RTL_NAPI_QUOTA(budget, ndev)			min(budget, budget)	#define RTL_GET_PRIV(stuct_ptr, priv_struct)		container_of(stuct_ptr, priv_struct, stuct_ptr)	#define RTL_GET_NETDEV(priv_ptr)			struct net_device *dev = priv_ptr->dev;	#define RTL_RX_QUOTA(ndev, budget)			budget	#define RTL_NAPI_QUOTA_UPDATE(ndev, work_done, budget)	#define RTL_NETIF_RX_COMPLETE(dev, napi)		netif_rx_complete(dev, napi)	#define RTL_NETIF_RX_SCHEDULE_PREP(dev, napi)		netif_rx_schedule_prep(dev, napi)	#define __RTL_NETIF_RX_SCHEDULE(dev, napi)		__netif_rx_schedule(dev, napi)	#define RTL_NAPI_RETURN_VALUE work_done	#define RTL_NAPI_ENABLE(dev, napi)			napi_enable(napi)	#define RTL_NAPI_DISABLE(dev, napi)			napi_disable(napi)#endif	//LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)/*****************************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)#ifdef __CHECKER__#define __iomem	__attribute__((noderef, address_space(2)))extern void __chk_io_ptr(void __iomem *);#define __bitwise __attribute__((bitwise))#else#define __iomem#define __chk_io_ptr(x) (void)0#define __bitwise#endif#endif	//LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)/*****************************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8)#ifdef __CHECKER__#define __force	__attribute__((force))#else#define __force#endif#endif	//LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8)#ifndef module_param#define module_param(v,t,p) MODULE_PARM(v, "i");#endif#ifndef PCI_DEVICE#define PCI_DEVICE(vend,dev) \	.vendor = (vend), .device = (dev), \	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID#endif/*****************************************************************************//* 2.5.28 => 2.4.23 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,28) )static inline void _kc_synchronize_irq(void){	synchronize_irq();}#undef synchronize_irq#define synchronize_irq(X) _kc_synchronize_irq()#include <linux/tqueue.h>#define work_struct tq_struct#undef INIT_WORK#define INIT_WORK(a,b,c) INIT_TQUEUE(a,(void (*)(void *))b,c)#undef container_of#define container_of list_entry#define schedule_work schedule_task#define flush_scheduled_work flush_scheduled_tasks#endif /* 2.5.28 => 2.4.17 *//*****************************************************************************//* 2.6.4 => 2.6.0 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )#define MODULE_VERSION(_version) MODULE_INFO(version, _version)#endif /* 2.6.4 => 2.6.0 *//*****************************************************************************//* 2.6.0 => 2.5.28 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )#define MODULE_INFO(version, _version)#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT#define CONFIG_E1000_DISABLE_PACKET_SPLIT 1#endif#define pci_set_consistent_dma_mask(dev,mask) 1#undef dev_put#define dev_put(dev) __dev_put(dev)#ifndef skb_fill_page_desc#define skb_fill_page_desc _kc_skb_fill_page_descextern void _kc_skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size);#endif#ifndef pci_dma_mapping_error#define pci_dma_mapping_error _kc_pci_dma_mapping_errorstatic inline int _kc_pci_dma_mapping_error(dma_addr_t dma_addr){	return dma_addr == 0;}#endif#undef ALIGN#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))#endif /* 2.6.0 => 2.5.28 *//*****************************************************************************//* 2.4.22 => 2.4.17 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )#define pci_name(x)	((x)->slot_name)#endif /* 2.4.22 => 2.4.17 *//*****************************************************************************//* 2.6.5 => 2.6.0 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) )#define pci_dma_sync_single_for_cpu	pci_dma_sync_single#define pci_dma_sync_single_for_device	pci_dma_sync_single_for_cpu#endif /* 2.6.5 => 2.6.0 *//*****************************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)/* * initialize a work-struct's func and data pointers: */#define PREPARE_WORK(_work, _func, _data)			\	do {							\		(_work)->func = _func;				\		(_work)->data = _data;				\	} while (0)#endif/*****************************************************************************//* 2.6.4 => 2.6.0 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,25) || \    ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \      LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) )#define ETHTOOL_OPS_COMPAT

⌨️ 快捷键说明

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