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

📄 skge.c

📁 移植到2410开发板上的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************** * * Name:    skge.c * Project:	GEnesis, PCI Gigabit Ethernet Adapter * Version:	$Revision: 1.29.2.6 $ * Date:       	$Date: 2001/05/21 07:59:29 $ * Purpose:	The main driver source module * ******************************************************************************/ /****************************************************************************** * *	(C)Copyright 1998-2001 SysKonnect GmbH. * *	Driver for SysKonnect Gigabit Ethernet Server Adapters: * *	SK-9861 (single link 1000Base-SX, VF45 Volition Plug) *	SK-9862 (dual link   1000Base-SX, VF45 Volition Plug) *	SK-9841 (single link 1000Base-LX) *	SK-9842 (dual link   1000Base-LX) *	SK-9843 (single link 1000Base-SX) *	SK-9844 (dual link   1000Base-SX) *	SK-9821 (single link 1000Base-T) *	SK-9822 (dual link   1000Base-T) * *	Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and  *	SysKonnects GEnesis Solaris driver *	Author: Christoph Goos (cgoos@syskonnect.de) *	        Mirko Lindner (mlindner@syskonnect.de) * *	Address all question to: linux@syskonnect.de * *	The technical manual for the adapters is available from SysKonnect's *	web pages: www.syskonnect.com *	Goto "Support" and search Knowledge Base for "manual". *	 *	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. * *	The information in this file is provided "AS IS" without warranty. * ******************************************************************************//****************************************************************************** * * History: * *	$Log: skge.c,v $ *	Revision 1.29.2.6  2001/05/21 07:59:29  mlindner *	fix: MTU init problems *	 *	Revision 1.29.2.5  2001/05/08 11:25:08  mlindner *	fix: removed VLAN error message *	 *	Revision 1.29.2.4  2001/05/04 13:31:43  gklug *	fix: do not handle eth_copy on bad fragments received. *	 *	Revision 1.29.2.3  2001/04/23 08:06:43  mlindner *	Fix: error handling *	 *	Revision 1.29.2.2  2001/03/15 12:04:54  mlindner *	Fixed memory problem *	 *	Revision 1.29.2.1  2001/03/12 16:41:44  mlindner *	add: procfs function *	add: dual-net function *	add: RLMT networks *	add: extended PNMI features *	 *	Kernel 2.4.x specific: *	Revision 1.xx  2000/09/12 13:31:56  cgoos *	Fixed missign "dev=NULL in skge_probe. *	Added counting for jumbo frames (corrects error statistic). *	Removed VLAN tag check (enables VLAN support). *	 *	Kernel 2.2.x specific: *	Revision 1.29  2000/02/21 13:31:56  cgoos *	Fixed "unused" warning for UltraSPARC change. *	 *	Partially kernel 2.2.x specific: *	Revision 1.28  2000/02/21 10:32:36  cgoos *	Added fixes for UltraSPARC. *	Now printing RlmtMode and PrefPort setting at startup. *	Changed XmitFrame return value. *	Fixed rx checksum calculation for BIG ENDIAN systems. *	Fixed rx jumbo frames counted as ierrors. *	 *	 *	Revision 1.27  1999/11/25 09:06:28  cgoos *	Changed base_addr to unsigned long. *	 *	Revision 1.26  1999/11/22 13:29:16  cgoos *	Changed license header to GPL. *	Changes for inclusion in linux kernel (2.2.13). *	Removed 2.0.x defines. *	Changed SkGeProbe to skge_probe. *	Added checks in SkGeIoctl. *	 *	Revision 1.25  1999/10/07 14:47:52  cgoos *	Changed 984x to 98xx. *	 *	Revision 1.24  1999/09/30 07:21:01  cgoos *	Removed SK_RLMT_SLOW_LOOKAHEAD option. *	Giving spanning tree packets also to OS now. *	 *	Revision 1.23  1999/09/29 07:36:50  cgoos *	Changed assignment for IsBc/IsMc. *	 *	Revision 1.22  1999/09/28 12:57:09  cgoos *	Added CheckQueue also to Single-Port-ISR. *	 *	Revision 1.21  1999/09/28 12:42:41  cgoos *	Changed parameter strings for RlmtMode. *	 *	Revision 1.20  1999/09/28 12:37:57  cgoos *	Added CheckQueue for fast delivery of RLMT frames. *	 *	Revision 1.19  1999/09/16 07:57:25  cgoos *	Copperfield changes. *	 *	Revision 1.18  1999/09/03 13:06:30  cgoos *	Fixed RlmtMode=CheckSeg bug: wrong DEV_KFREE_SKB in RLMT_SEND caused *	double allocated skb's. *	FrameStat in ReceiveIrq was accessed via wrong Rxd. *	Queue size for async. standby Tx queue was zero. *	FillRxLimit of 0 could cause problems with ReQueue, changed to 1. *	Removed debug output of checksum statistic. *	 *	Revision 1.17  1999/08/11 13:55:27  cgoos *	Transmit descriptor polling was not reenabled after SkGePortInit. *	 *	Revision 1.16  1999/07/27 15:17:29  cgoos *	Added some "\n" in output strings (removed while debuging...). *	 *	Revision 1.15  1999/07/23 12:09:30  cgoos *	Performance optimization, rx checksumming, large frame support. *	 *	Revision 1.14  1999/07/14 11:26:27  cgoos *	Removed Link LED settings (now in RLMT). *	Added status output at NET UP. *	Fixed SMP problems with Tx and SWITCH running in parallel. *	Fixed return code problem at RLMT_SEND event. *	 *	Revision 1.13  1999/04/07 10:11:42  cgoos *	Fixed Single Port problems. *	Fixed Multi-Adapter problems. *	Always display startup string. *	 *	Revision 1.12  1999/03/29 12:26:37  cgoos *	Reversed locking to fine granularity. *	Fixed skb double alloc problem (caused by incorrect xmit return code). *	Enhanced function descriptions. *	 *	Revision 1.11  1999/03/15 13:10:51  cgoos *	Changed device identifier in output string to ethX. *	 *	Revision 1.10  1999/03/15 12:12:34  cgoos *	Changed copyright notice. *	 *	Revision 1.9  1999/03/15 12:10:17  cgoos *	Changed locking to one driver lock. *	Added check of SK_AC-size (for consistency with library). *	 *	Revision 1.8  1999/03/08 11:44:02  cgoos *	Fixed missing dev->tbusy in SkGeXmit. *	Changed large frame (jumbo) buffer number. *	Added copying of short frames. *	 *	Revision 1.7  1999/03/04 13:26:57  cgoos *	Fixed spinlock calls for SMP. *	 *	Revision 1.6  1999/03/02 09:53:51  cgoos *	Added descriptor revertion for big endian machines. *	 *	Revision 1.5  1999/03/01 08:50:59  cgoos *	Fixed SkGeChangeMtu. *	Fixed pci config space accesses. *	 *	Revision 1.4  1999/02/18 15:48:44  cgoos *	Corrected some printk's. *	 *	Revision 1.3  1999/02/18 12:45:55  cgoos *	Changed SK_MAX_CARD_PARAM to default 16 *	 *	Revision 1.2  1999/02/18 10:55:32  cgoos *	Removed SkGeDrvTimeStamp function. *	Printing "ethX:" before adapter type at adapter init. *	 * *	10-Feb-1999 cg	Created, based on Linux' acenic.c, 3c59x.c and  *			SysKonnects GEnesis Solaris driver * ******************************************************************************//****************************************************************************** * * Possible compiler options (#define xxx / -Dxxx): * *	debugging can be enable by changing SK_DEBUG_CHKMOD and  *	SK_DEBUG_CHKCAT in makefile (described there). * ******************************************************************************/ /****************************************************************************** * * Description: * *	This is the main module of the Linux GE driver. *	 *	All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h *	are part of SysKonnect's COMMON MODULES for the SK-98xx adapters. *	Those are used for drivers on multiple OS', so some thing may seem *	unnecessary complicated on Linux. Please do not try to 'clean up' *	them without VERY good reasons, because this will make it more *	difficult to keep the Linux driver in synchronisation with the *	other versions. * * Include file hierarchy: * *	<linux/module.h> * *	"h/skdrv1st.h" *		<linux/version.h> *		<linux/types.h> *		<linux/kernel.h> *		<linux/string.h> *		<linux/errno.h> *		<linux/ioport.h> *		<linux/slab.h> *		<linux/interrupt.h> *		<linux/pci.h> *		<asm/byteorder.h> *		<asm/bitops.h> *		<asm/io.h> *		<linux/netdevice.h> *		<linux/etherdevice.h> *		<linux/skbuff.h> *	    those three depending on kernel version used: *		<linux/bios32.h> *		<linux/init.h> *		<asm/uaccess.h> *		<net/checksum.h> * *		"h/skerror.h" *		"h/skdebug.h" *		"h/sktypes.h" *		"h/lm80.h" *		"h/xmac_ii.h" * *      "h/skdrv2nd.h" *		"h/skqueue.h" *		"h/skgehwt.h" *		"h/sktimer.h" *		"h/ski2c.h" *		"h/skgepnmi.h" *		"h/skvpd.h" *		"h/skgehw.h" *		"h/skgeinit.h" *		"h/skaddr.h" *		"h/skgesirq.h" *		"h/skcsum.h" *		"h/skrlmt.h" * ******************************************************************************/#include	"h/skversion.h"#include	<linux/module.h>#include	<linux/init.h>#include 	<linux/proc_fs.h>#include	"h/skdrv1st.h"#include	"h/skdrv2nd.h"/* defines ******************************************************************//* for debuging on x86 only *//* #define BREAKPOINT() asm(" int $3"); *//* use of a transmit complete interrupt */#define USE_TX_COMPLETE/* use interrupt moderation (for tx complete only) */// #define USE_INT_MOD#define INTS_PER_SEC	1000/* * threshold for copying small receive frames * set to 0 to avoid copying, set to 9001 to copy all frames */#define SK_COPY_THRESHOLD	200/* number of adapters that can be configured via command line params */#define SK_MAX_CARD_PARAM	16/* * use those defines for a compile-in version of the driver instead  * of command line parameters */// #define AUTO_NEG_A	{"Sense", }// #define AUTO_NEG_B	{"Sense", }// #define DUP_CAP_A	{"Both", }// #define DUP_CAP_B	{"Both", }// #define FLOW_CTRL_A	{"SymOrRem", }// #define FLOW_CTRL_B	{"SymOrRem", }// #define ROLE_A	{"Auto", }// #define ROLE_B	{"Auto", }// #define PREF_PORT	{"A", }// #define RLMT_MODE	{"CheckLinkState", }#define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)#define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)#define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)/* function prototypes ******************************************************/static void	FreeResources(struct net_device *dev);int		init_module(void);void		cleanup_module(void);static int	SkGeBoardInit(struct net_device *dev, SK_AC *pAC);static SK_BOOL	BoardAllocMem(SK_AC *pAC);static void	BoardFreeMem(SK_AC *pAC);static void	BoardInitMem(SK_AC *pAC);static void	SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**,			int*, SK_BOOL);static void	SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);static void	SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);static int	SkGeOpen(struct net_device *dev);static int	SkGeClose(struct net_device *dev);static int	SkGeXmit(struct sk_buff *skb, struct net_device *dev);static int	SkGeSetMacAddr(struct net_device *dev, void *p);static void	SkGeSetRxMode(struct net_device *dev);static struct net_device_stats *SkGeStats(struct net_device *dev);static int	SkGeIoctl(struct net_device *dev, struct ifreq *rq, int cmd);static void	GetConfiguration(SK_AC*);static void	ProductStr(SK_AC*);static int	XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);static void	FreeTxDescriptors(SK_AC*pAC, TX_PORT*);static void	FillRxRing(SK_AC*, RX_PORT*);static SK_BOOL	FillRxDescriptor(SK_AC*, RX_PORT*);static void	ReceiveIrq(SK_AC*, RX_PORT*);static void	ClearAndStartRx(SK_AC*, int);static void	ClearTxIrq(SK_AC*, int, int);static void	ClearRxRing(SK_AC*, RX_PORT*);static void	ClearTxRing(SK_AC*, TX_PORT*);static void	SetQueueSizes(SK_AC	*pAC);static int	SkGeChangeMtu(struct net_device *dev, int new_mtu);static void	PortReInitBmu(SK_AC*, int);static int	SkGeIocMib(DEV_NET*, unsigned int, int);/*Extern */extern struct proc_dir_entry *pSkRootDir;//extern struct proc_dir_entry Our_Proc_Dir;extern int proc_read(char *buffer, char **buffer_location,	off_t offset, int buffer_length, int *eof, void *data);#ifdef DEBUGstatic void	DumpMsg(struct sk_buff*, char*);static void	DumpData(char*, int);static void	DumpLong(char*, int);#endif/* global variables *********************************************************/static const char *BootString = BOOT_STRING;struct net_device *sk98lin_root_dev = NULL;static int probed __initdata = 0;struct inode_operations SkInodeOps;//static struct file_operations SkFileOps;  /* with open/relase *//* local variables **********************************************************/static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};void proc_fill_inode(struct inode *inode, int fill){	if (fill)		MOD_INC_USE_COUNT;	else		MOD_DEC_USE_COUNT;}/***************************************************************************** * * 	skge_probe - find all SK-98xx adapters * * Description: *	This function scans the PCI bus for SK-98xx adapters. Resources for *	each adapter are allocated and the adapter is brought into Init 1 *	state. * * Returns: *	0, if everything is ok *	!=0, on error */static int __init skge_probe (void){	int 		boards_found = 0;	int			version_disp = 0;	SK_AC		*pAC;	DEV_NET		*pNet = NULL;	struct 		pci_dev	*pdev = NULL;	unsigned long		base_address;	struct net_device *dev = NULL;	struct proc_dir_entry	*pProcFile;	if (probed)		return -ENODEV;	probed++;		/* display driver info */	if (!version_disp)	{		/* set display flag to TRUE so that */		/* we only display this string ONCE */		version_disp = 1;		printk("%s\n", BootString);	}	if (!pci_present())		/* is PCI support present? */		return -ENODEV;        pSkRootDir = create_proc_entry("sk98lin",                S_IFDIR | S_IWUSR | S_IRUGO | S_IXUGO, proc_net); 	pSkRootDir->owner = THIS_MODULE;	while((pdev = pci_find_device(PCI_VENDOR_ID_SYSKONNECT,				      PCI_DEVICE_ID_SYSKONNECT_GE, pdev)) != NULL) {		dev = NULL;		pNet = NULL;		if (pci_enable_device(pdev))			continue;		/* Configure DMA attributes. */		if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff) &&		    pci_set_dma_mask(pdev, (u64) 0xffffffff))				continue;

⌨️ 快捷键说明

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