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

📄 cs8900网卡移植.txt

📁 难得的CS8900A的驱动
💻 TXT
📖 第 1 页 / 共 3 页
字号:
 
2007-6-7 linux2.6.14 cs8900网卡移植成功。cs8900, cs8900a
	开发板:成都博睿科技 MC2410.(三星的 s3c2410芯片, 网卡芯片cs8900a)
	cs8900.h, cs8900.c 这两个文件我在网上搜索很久都没有结果。最后在一个帖子里面别人贴出来了,所以我把代码copy下来自己建立cs8900.h cs8900.c 
两个文件自己整理。由于是帖子copy的里面的数千个多余的"+",只好用utraledit逐个替换,还得注意不能把本来的“+”弄没了。其中在.c文件中
开始处添加(已经添加上)
//add by zsyddl
#define CONFIG_ARCH_SMDK2410 
//add end;
	1、按照别人的说法,将两个文件放到 driver/net/arm下面。
	2、在makefile结尾添加 obj-$(CONFIG_CS8900)		+= cs8900.o
	3、在该目录下的kconfig文件中开始或者其他合适的地方 添加
 config CS8900
	tristate "CS8900 support"
	depends on NET_ETHERNET && ARM 
	以便让 上面的makefile语句有效,才能将信新的文件编译。
	4、修改 cs8900.h文件
#include <linux/config.h> 
#include <asm-arm/arch-s3c2410/regs-mem.h>

#define SMDK2410_ETH_IO 0xe0000000 //这个是网卡的物理地址映射到linux系统下的虚拟地址的起始地址。该数字在我的开发板是linux2.4的,内核中是该地址为0xd0000000,但是该地址//在linux2.6内核不正确,不能正确映射,于是修改为此。
#define SMDK2410_ETH_IRQ IRQ_EINT8
//这个是网卡使用的中断吧。我按照linux2.4的数字修改为该值,网上的原本代码是 IRQ_EINT9

	5、修改 arch/arm/mach-s3c2410/mach-smdk2410.c,大概是 112行。这个是告诉内核对地址进行映射,把网卡的物理地址映射到虚拟地址。因为linux系统中都是采用虚拟地址访问。
static struct map_desc smdk2410_iodesc[] __initdata = {
  /* nothing here yet */
	//add by zsyddl
	//虚拟地址    ,物理地址,   占用空间大小。
	{0xe0000000, 0x11000000, SZ_1M, MT_DEVICE},
	//add end
};
	其中的物理地址是根据我的开发版的2.4内核的设定得来。这个根据不同的开发板 数值有所不同。
	6、配置内核,选中driver->networking->ethernet (10 or 100Mbit)-> CS8900 support for s3c2410.以使cs8900配置生效。
	7、保存编译
	8、启动新的内核。在命令行设置:
	> ifconfig eth0 192.168.0.15
	再次使用
	>ifconfig
	应该得到如下信息。如果没有则不正确。还有就是看启动信息中eth0相关的字样有无异常。如果不正常,建议修改:0x11000000数值,IRQ_EINT8,这个需要根据开发板的网卡芯片连接而定。
	>ping 192.168.0.186 //正常
# ping 192.168.0.186
PING 192.168.0.186 (192.168.0.186): 56 data bytes
64 bytes from 192.168.0.186: icmp_seq=0 ttl=64 time=2.8 ms
64 bytes from 192.168.0.186: icmp_seq=1 ttl=64 time=0.6 ms

--- 192.168.0.186 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.6/1.7/2.8 ms

	总结:linux下面的移植都是很痛苦的事情。就这个网卡的移植我也花了3天的时间,也许是我太笨。。。呵呵。其中找到源代码就花掉了90%的时间。所以这次把代码打包放上,希望能给大家一点帮助。
	怕找不到放置的地方,下面把代码贴上。
///cs8900.h文件
#ifndef CS8900_H 
#define CS8900_H 
 
/* 
 * linux/drivers/net/cs8900.h 
 * 
 * Author: Abraham van der Merwe <abraham at 2d3d.co.za> 
 * 
 * A Cirrus Logic CS8900A driver for Linux 
 * based on the cs89x0 driver written by Russell Nelson, 
 * Donald Becker, and others. 
 * 
 * This source code is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * version 2 as published by the Free Software Foundation. 
 */ 
 //add by zsyddl
#include <linux/config.h> 
#include <asm-arm/arch-s3c2410/regs-mem.h>

#define SMDK2410_ETH_IO 0xe0000000 
#define SMDK2410_ETH_IRQ IRQ_EINT8
//
/* 
 * Ports 
 */ 
 
#define PP_Address 0x0a /* PacketPage Pointer Port (Section 4.10.10) */ 
#define PP_Data 0x0c /* PacketPage Data Port (Section 4.10.10) */ 
 
/* 
 * Registers 
 */ 
 
#define PP_ProductID 0x0000 /* Section 4.3.1 Product Identification Code */ 
#define PP_MemBase 0x002c /* Section 4.9.2 Memory Base Address Register */ 
#define PP_IntNum 0x0022 /* Section 3.2.3 Interrupt Number */ 
#define PP_EEPROMCommand 0x0040 /* Section 4.3.11 EEPROM Command */ 
#define PP_EEPROMData 0x0042 /* Section 4.3.12 EEPROM Data */ 
#define PP_RxCFG 0x0102 /* Section 4.4.6 Receiver Configuration */ 
#define PP_RxCTL 0x0104 /* Section 4.4.8 Receiver Control */ 
#define PP_TxCFG 0x0106 /* Section 4.4.9 Transmit Configuration */ 
#define PP_BufCFG 0x010a /* Section 4.4.12 Buffer Configuration */ 
#define PP_LineCTL 0x0112 /* Section 4.4.16 Line Control */ 
#define PP_SelfCTL 0x0114 /* Section 4.4.18 Self Control */ 
#define PP_BusCTL 0x0116 /* Section 4.4.20 Bus Control */ 
#define PP_TestCTL 0x0118 /* Section 4.4.22 Test Control */ 
#define PP_ISQ 0x0120 /* Section 4.4.5 Interrupt Status Queue */ 
#define PP_TxEvent 0x0128 /* Section 4.4.10 Transmitter Event */ 
#define PP_BufEvent 0x012c /* Section 4.4.13 Buffer Event */ 
#define PP_RxMISS 0x0130 /* Section 4.4.14 Receiver Miss Counter */ 
#define PP_TxCOL 0x0132 /* Section 4.4.15 Transmit Collision Counter */ 
#define PP_SelfST 0x0136 /* Section 4.4.19 Self Status */ 
#define PP_BusST 0x0138 /* Section 4.4.21 Bus Status */ 
#define PP_TxCMD 0x0144 /* Section 4.4.11 Transmit Command */ 
#define PP_TxLength 0x0146 /* Section 4.5.2 Transmit Length */ 
#define PP_IA 0x0158 /* Section 4.6.2 Individual Address (IEEE Address) */ 
#define PP_RxStatus 0x0400 /* Section 4.7.1 Receive Status */ 
#define PP_RxLength 0x0402 /* Section 4.7.1 Receive Length (in bytes) */ 
#define PP_RxFrame 0x0404 /* Section 4.7.2 Receive Frame Location */ 
#define PP_TxFrame 0x0a00 /* Section 4.7.2 Transmit Frame Location */ 
 
/* 
 * Values 
 */ 
 
/* PP_IntNum */ 
#define INTRQ0 0x0000 
#define INTRQ1 0x0001 
#define INTRQ2 0x0002 
#define INTRQ3 0x0003 
 
/* PP_ProductID */ 
#define EISA_REG_CODE 0x630e 
#define REVISION(x) (((x) & 0x1f00) >> 8) 
#define VERSION(x) ((x) & ~0x1f00) 
 
#define CS8900A 0x0000 
#define REV_B 7 
#define REV_C 8 
#define REV_D 9 
 
/* PP_RxCFG */ 
#define Skip_1 0x0040 
#define StreamE 0x0080 
#define RxOKiE 0x0100 
#define RxDMAonly 0x0200 
#define AutoRxDMAE 0x0400 
#define BufferCRC 0x0800 
#define CRCerroriE 0x1000 
#define RuntiE 0x2000 
#define ExtradataiE 0x4000 
 
/* PP_RxCTL */ 
#define IAHashA 0x0040 
#define PromiscuousA 0x0080 
#define RxOKA 0x0100 
#define MulticastA 0x0200 
#define IndividualA 0x0400 
#define BroadcastA 0x0800 
#define CRCerrorA 0x1000 
#define RuntA 0x2000 
#define ExtradataA 0x4000 
 
/* PP_TxCFG */ 
#define Loss_of_CRSiE 0x0040 
#define SQErroriE 0x0080 
#define TxOKiE 0x0100 
#define Out_of_windowiE 0x0200 
#define JabberiE 0x0400 
#define AnycolliE 0x0800 
#define T16colliE 0x8000 
 
/* PP_BufCFG */ 
#define SWint_X 0x0040 
#define RxDMAiE 0x0080 
#define Rdy4TxiE 0x0100 
#define TxUnderruniE 0x0200 
#define RxMissiE 0x0400 
#define Rx128iE 0x0800 
#define TxColOvfiE 0x1000 
#define MissOvfloiE 0x2000 
#define RxDestiE 0x8000 
 
/* PP_LineCTL */ 
#define SerRxON 0x0040 
#define SerTxON 0x0080 
#define AUIonly 0x0100 
#define AutoAUI_10BT 0x0200 
#define ModBackoffE 0x0800 
#define PolarityDis 0x1000 
#define L2_partDefDis 0x2000 
#define LoRxSquelch 0x4000 
 
/* PP_SelfCTL */ 
#define RESET 0x0040 
#define SWSuspend 0x0100 
#define HWSleepE 0x0200 
#define HWStandbyE 0x0400 
#define HC0E 0x1000 
#define HC1E 0x2000 
#define HCB0 0x4000 
#define HCB1 0x8000 
 
/* PP_BusCTL */ 
#define ResetRxDMA 0x0040 
#define DMAextend 0x0100 
#define UseSA 0x0200 
#define MemoryE 0x0400 
#define DMABurst 0x0800 
#define IOCHRDYE 0x1000 
#define RxDMAsize 0x2000 
#define EnableRQ 0x8000 
 
/* PP_TestCTL */ 
#define DisableLT 0x0080 
#define ENDECloop 0x0200 
#define AUIloop 0x0400 
#define DisableBackoff 0x0800 
#define FDX 0x4000 
 
/* PP_ISQ */ 
#define RegNum(x) ((x) & 0x3f) 
#define RegContent(x) ((x) & ~0x3d) 
 
#define RxEvent 0x0004 
#define TxEvent 0x0008 
#define BufEvent 0x000c 
#define RxMISS 0x0010 
#define TxCOL 0x0012 
 
/* PP_RxStatus */ 
#define IAHash 0x0040 
#define Dribblebits 0x0080 
#define RxOK 0x0100 
#define Hashed 0x0200 
#define IndividualAdr 0x0400 
#define Broadcast 0x0800 
#define CRCerror 0x1000 
#define Runt 0x2000 
#define Extradata 0x4000 
 
#define HashTableIndex(x) ((x) >> 0xa) 
 
/* PP_TxCMD */ 
#define After5 0 
#define After381 1 
#define After1021 2 
#define AfterAll 3 
#define TxStart(x) ((x) << 6) 
 
#define Force 0x0100 
#define Onecoll 0x0200 
#define InhibitCRC 0x1000 
#define TxPadDis 0x2000 
 
/* PP_BusST */ 
#define TxBidErr 0x0080 
#define Rdy4TxNOW 0x0100 
 
/* PP_TxEvent */ 
#define Loss_of_CRS 0x0040 
#define SQEerror 0x0080 
#define TxOK 0x0100 
#define Out_of_window 0x0200 
#define Jabber 0x0400 
#define T16coll 0x8000 
 
#define TX_collisions(x) (((x) >> 0xb) & ~0x8000) 
 
/* PP_BufEvent */ 
#define SWint 0x0040 
#define RxDMAFrame 0x0080 
#define Rdy4Tx 0x0100 
#define TxUnderrun 0x0200 
#define RxMiss 0x0400 
#define Rx128 0x0800 
#define RxDest 0x8000 
 
/* PP_RxMISS */ 
#define MissCount(x) ((x) >> 6) 
 
/* PP_TxCOL */ 
#define ColCount(x) ((x) >> 6) 
 
/* PP_SelfST */ 
#define T3VActive 0x0040 
#define INITD 0x0080 
#define SIBUSY 0x0100 
#define EEPROMpresent 0x0200 
#define EEPROMOK 0x0400 
#define ELpresent 0x0800 
#define EEsize 0x1000 
 
/* PP_EEPROMCommand */ 
#define EEWriteEnable 0x00F0 
#define EEWriteDisable 0x0000 
#define EEWriteRegister 0x0100 
#define EEReadRegister 0x0200 
#define EEEraseRegister 0x0300 
#define ELSEL 0x0400 
 
#endif /* #ifndef CS8900_H */ 
/////////////////////////////////////////
//////cs8900.c
/*
 * Author: Abraham van der Merwe <abraham at 2d3d.co.za> 
 * 
 * A Cirrus Logic CS8900A driver for Linux 
 * based on the cs89x0 driver written by Russell Nelson, 
 * Donald Becker, and others. 
 * 
 * This source code is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * version 2 as published by the Free Software Foundation. 
 * 
 * History: 
 * 22-May-2002 Initial version (Abraham vd Merwe) 
 * 30-May-2002 Added char device support for eeprom (Frank Becker) 
 * 24-Jan-2004 Fixups for 2.6 (Frank Becker) 
 * 15-July-2004 Modified for SMDK2410 (Roc Wu pwu at jadechip.com) 
 */ 
 
#define VERSION_STRING "Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)" 
//add by zsyddl
#define CONFIG_ARCH_SMDK2410 1 
//add end;
/* 
 * At the moment the driver does not support memory mode operation. 
 * It is trivial to implement this, but not worth the effort. 
 */ 
 
/* 
 * TODO: 
 * 
 * 1. Sort out ethernet checksum 
 * 2. If !ready in send_start(), queue buffer and send it in interrupt 
handler 
 * when we receive a BufEvent with Rdy4Tx, send it again. dangerous! 
 * 3. how do we prevent interrupt handler destroying integrity of get_stats()
? 
 * 4. Change reset code to check status. 
 * 5. Implement set_mac_address and remove fake mac address 
 * 7. Link status detection stuff 
 * 8. Write utility to write EEPROM, do self testing, etc. 
 * 9. Implement DMA routines (I need a board w/ DMA support for that) 
 * 10. Power management 
 * 11. Add support for multiple ethernet chips 
 */ 
 
// added BSt 
#include <linux/config.h> 
 
#include <linux/kernel.h> 
#include <linux/module.h> 
#include <linux/types.h> 
#include <linux/version.h> 
#include <linux/errno.h> 
#include <linux/init.h> 
#include <linux/delay.h> 
#include <linux/ioport.h> 
#include <asm/irq.h> 
#include <asm/hardware.h> 
#include <asm/io.h> 
#include <asm/uaccess.h> 
#include <linux/netdevice.h> 
#include <linux/etherdevice.h> 
#include <linux/skbuff.h> 
 
// Added BSt 
#include <asm/mach-types.h> 
 
#ifdef CONFIG_SA1100_CERF 
#include "asm/arch/cerf.h" 
#endif 
 
#ifdef CONFIG_ARCH_SMDK2410 
//#include "asm/arch/smdk2410.h" 
#endif 
 
#include "cs8900.h" 
 
//#define FULL_DUPLEX 
//#define DEBUG 
 
typedef struct { 
	struct net_device_stats stats; 
	u16 txlen; 
	int char_devnum; 
 
	spinlock_t lock; 
} cs8900_t; 
 
int cs8900_probe (struct net_device *dev); 
// static struct net_device cs8900_dev = 
// { 
// 	init: cs8900_probe 
// }; 
//  
static struct net_device cs8900_dev;

 
/* 
 * There seems to be no way to determine the exact size of the eeprom, 
 * so we use the largest size. 
 * FIXME: Verify it's safe to read/write past the end of a 64/128 
 * byte eeprom. 
 * 
 * Possible eeprom sizes: 
 * Cx46 - 64 bytes 
 * Cx56 - 128 bytes 
 * Cx66 - 256 bytes 
 */ 
#define MAX_EEPROM_SIZE 256 
 
static int cs8900_eeprom_fopen(struct inode *inode, struct file *file); 
static int cs8900_eeprom_frelease(struct inode *inode, struct file *file); 
static loff_t cs8900_eeprom_fllseek(struct file * file,loff_t offset, int 
		flags); 
static ssize_t cs8900_eeprom_fread(struct file *file, char *buf, size_t count
		, loff_t *f_pos); 
static ssize_t cs8900_eeprom_fwrite(struct file *file, const char *buf, 
				    size_t count, loff_t *f_pos); 
static struct file_operations cs8900_eeprom_fops = { 
	owner: THIS_MODULE, 
	open: cs8900_eeprom_fopen, 
	release: cs8900_eeprom_frelease, 
	llseek: cs8900_eeprom_fllseek, 
	read: cs8900_eeprom_fread, 
	write: cs8900_eeprom_fwrite, 
}; 
 
static u16 cs8900_eeprom_cache[MAX_EEPROM_SIZE/2]; 

⌨️ 快捷键说明

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