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

📄 dev_net_cs8900a.c

📁 cs8900网卡驱动for linux 在arm处理器上的
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	dev_net_cs8900a.c - skyeye Cirrus Logic CS8900A ethernet controllor simulation	Copyright (C) 2003 - 2005 Skyeye Develop Group        for help please send mail to <skyeye-developer@lists.gro.clinux.org>		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  *//* * 03/19/2007	replaced the codes based on sigaction with portable function. * 			Anthony Lee <don.anthony.lee@gmail.com> * 06/04/2005   initial verion for cs8900a *                      walimis <wlm@student.dlut.edu.cn> */#include "armdefs.h"#include "skyeye_device.h"#include "dev_net_cs8900a.h"#include "portable/gettimeofday.h"static struct device_default_value cs8900a_net_def[] = {	/* name         base        size   interrupt array */	{"at91", 0xfffa0000, 0x20, {16, 0, 0, 0}},	{"s3c2410x", 0x19000300, 0x20, {9, 0, 0, 0}},	{NULL},};#define MAX_DEVICE_NUM 10static struct device_desc *cs8900a_devs[MAX_DEVICE_NUM];static struct timeval eth_timeout[MAX_DEVICE_NUM];static void net_cs8900a_reset (struct device_desc *dev);static int eth_timeout_flags[MAX_DEVICE_NUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};#define TIMEVAL_ADD_USEC(tv, usec)					\	do {								\		tv.tv_sec += ((tv.tv_usec + usec) / (1000000UL));	\		tv.tv_usec = ((tv.tv_usec + usec) % (1000000UL));	\	} while (0)#define TIMEVAL_CMP(tv1, tv2)						\	(memcmp(&tv1, &tv2, sizeof(struct timeval)) == 0 ?		\	 0 : (								\		tv1.tv_sec < tv2.tv_sec ? -1 : (			\		(tv1.tv_sec == tv2.tv_sec && tv1.tv_usec < tv2.tv_usec) ? -1 : 1        \	)))static void set_time(int index, int packets){	eth_timeout_flags[index] = 0;	if (packets <= 0) return;	if (gettimeofday(&eth_timeout[index], NULL) != 0) return;#if 0	TIMEVAL_ADD_USEC(eth_timeout[index], (unsigned int)packets * 100UL);#else	/* 	 * NOTE by Stano:	 * 	In 10 ms - no reason to wait 1 second for a big packet	 *	 * NOTE by Lee:	 * 	Though the timeout just for generating interrupt,	 *	but please increase the timeout microseconds to decrease	 *	the loading of CPU when connecting to an external network.	 */	TIMEVAL_ADD_USEC(eth_timeout[index], 10000UL);#endif	eth_timeout_flags[index] = 1;}voidnet_cs8900a_set_update_intr (struct device_desc *dev){	struct device_interrupt *intr = &dev->intr;	struct machine_config *mc = (struct machine_config *) dev->mach;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	mc->mach_set_intr (intr->interrupts[INT_CS8900A]);	mc->mach_update_intr (mc);}static void send_interrupt(int index){	struct device_desc *dev;	if ((dev = cs8900a_devs[index]) != NULL) {		struct net_device *net_dev = (struct net_device *) dev->dev;		struct machine_config *mc = (struct machine_config *) dev->mach;		struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;		if ((io->need_update)) {			/* only update once. */			net_cs8900a_set_update_intr (dev);			io->need_update = 0;			set_time (index, 0);		}	}}static void check_timeout(int index){	struct timeval tv;	if (!eth_timeout_flags[index]) return;	if (gettimeofday(&tv, NULL) != 0) return;	if (TIMEVAL_CMP(tv, eth_timeout[index]) < 1) return;	send_interrupt(index);	eth_timeout_flags[index] = 0;}/* ISQ read*/static voidisq_read (struct device_desc *dev, u16 * data){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	io->ctrl_st[CtrlStNum (PP_ISQ)] = 0x0;	if (io->ctrl_st[CtrlStNum (PP_RxEvent)] & 0xffc0) {		io->ctrl_st[CtrlStNum (PP_ISQ)] =			io->ctrl_st[CtrlStNum (PP_RxEvent)];//		io->ctrl_st[CtrlStNum (PP_RxEvent)] &= 0x3f;	}	else if (io->ctrl_st[CtrlStNum (PP_TxEvent)] & 0xffc0) {		io->ctrl_st[CtrlStNum (PP_ISQ)] =			io->ctrl_st[CtrlStNum (PP_TxEvent)];		io->ctrl_st[CtrlStNum (PP_TxEvent)] &= 0x3f;	}	*data = io->ctrl_st[CtrlStNum (PP_ISQ)];}static voidframe_write (struct device_desc *dev, u16 data){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	io->tx_frame[io->tx_tail] = data;	io->tx_tail++;	if ((io->tx_tail * 2) >= io->tx_length) {		cs8900a_output (dev, (u8 *) io->tx_frame, (io->tx_tail * 2));		io->tx_tail = 0;	}}static voidframe_read (struct device_desc *dev, u16 * data){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	if (io->rx_tail > io->rx_head) {		io->rx_head = io->rx_tail = 0;		return;	}	*data = io->rx_frame[io->rx_tail];	if (io->rx_tail==io->rx_head) {		io->ctrl_st[CtrlStNum (PP_RxEvent)] &= ~0x100;	}	io->rx_tail++;}static voideeprom_reset (struct device_desc *dev){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	u8 offset, checksum = 0, *buf;	u16 eeprom_val[17] = { 0xa120,		0x2020, 0x0300, 0x0003, 0x0001,		0x502c, 0xe000, 0x000f, 0x0, 0xd, 0xc000, 0xf,		0x2158, 0x0010, 0x0, 0x0,		0x2800	};	/* set eeprom mac address */	eeprom_val[13] = net_dev->macaddr[0] | (net_dev->macaddr[1] << 8);	eeprom_val[14] = net_dev->macaddr[2] | (net_dev->macaddr[3] << 8);	eeprom_val[15] = net_dev->macaddr[4] | (net_dev->macaddr[5] << 8);	/* re-compute checksum. */	buf = (u8 *) eeprom_val;	for (offset = 0; offset < (sizeof (eeprom_val) - 2); offset++)		checksum += buf[offset];	eeprom_val[16] = ((u8) (0x100 - checksum)) << 8;	/* fill eeprom. */	memcpy (io->eeprom, eeprom_val, sizeof (eeprom_val));	/* others */	io->eeprom_writable = 0;	io->ctrl_st[CtrlStNum (PP_SelfST)] |= EEPROMpresent | EEPROMOK;	memcpy (io->ieee_addr, net_dev->macaddr, 6);}static voidctrl_status_write (struct device_desc *dev, u16 data){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	io->ctrl_st[CtrlStNum (io->pp_address)] = data; 	if (io->pp_address==PP_SelfCTL) 	{ 		if (data&RESET) 			net_cs8900a_reset(dev);	 	}	//printf("%s: addr %x, data %x\n", __FUNCTION__, io->pp_address, data);}static voidctrl_status_read (struct device_desc *dev, u16 * data){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	*data = io->ctrl_st[CtrlStNum (io->pp_address)];	//printf("%s: addr %x, data %x\n", __FUNCTION__, io->pp_address, *data);}/* FIXME: now it doesn't support erase-all/write-all commands */static voideeprom_write (struct device_desc *dev, u16 data){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	if ((io->eeprom_cmd & EEWriteRegister) && io->eeprom_writable == 1) {		io->eeprom[io->eeprom_cmd & 0xff] = io->eeprom_data;	}	else if ((io->eeprom_cmd & EEEraseRegister)		 && io->eeprom_writable == 1) {		io->eeprom[io->eeprom_cmd & 0xff] = 0xffff;	}	else {		if (io->eeprom_cmd & EEWriteEnable) {			io->eeprom_writable = 1;		}		else if (io->eeprom_cmd & EEWriteDis) {			io->eeprom_writable = 0;		}	}}static voideeprom_read (struct device_desc *dev, u16 * data){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	if (!(io->eeprom_cmd & EEReadRegister))		return;	*data = io->eeprom[io->eeprom_cmd & 0xff];}static voidnet_cs8900a_fini (struct device_desc *dev){	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	free (dev->dev);	free (io);}static voidnet_cs8900a_reset (struct device_desc *dev){	struct net_device *net_dev = (struct net_device *) dev->dev;	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;	int i;	/* set ProductID: rev_d */	io->product_id[0] = EISA_REG_CODE;	io->product_id[1] = CS8900A | (REV_D << 8);	/* see section 4.10.5 */	io->pp_address |= 0x3000;

⌨️ 快捷键说明

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