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

📄 lan91c96.c

📁 u-boot-1.1.6 for mini2440开发板。 支持网络下载
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (packet_no & LAN91C96_ARR_FAILED) {		/* or isn't there?  BAD CHIP! */		printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);		return 0;	}	/* we have a packet address, so tell the card to use it */	SMC_outb (packet_no, LAN91C96_PNR);	/* point to the beginning of the packet */	SMC_outw (LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);	PRINTK3 ("%s: Trying to xmit packet of length %x\n",			 SMC_DEV_NAME, length);#if SMC_DEBUG > 2	printf ("Transmitting Packet\n");	print_packet (buf, length);#endif	/* send the packet length ( +6 for status, length and ctl byte )	   and the status word ( set to zeros ) */#ifdef USE_32_BIT	SMC_outl ((length + 6) << 16, LAN91C96_DATA_HIGH);#else	SMC_outw (0, LAN91C96_DATA_HIGH);	/* send the packet length ( +6 for status words, length, and ctl */	SMC_outw ((length + 6), LAN91C96_DATA_HIGH);#endif /* USE_32_BIT */	/* send the actual data	 * I _think_ it's faster to send the longs first, and then	 * mop up by sending the last word.  It depends heavily	 * on alignment, at least on the 486.  Maybe it would be	 * a good idea to check which is optimal?  But that could take	 * almost as much time as is saved?	 */#ifdef USE_32_BIT	SMC_outsl (LAN91C96_DATA_HIGH, buf, length >> 2);	if (length & 0x2)		SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))),				  LAN91C96_DATA_HIGH);#else	SMC_outsw (LAN91C96_DATA_HIGH, buf, (length) >> 1);#endif /* USE_32_BIT */	/* Send the last byte, if there is one.   */	if ((length & 1) == 0) {		SMC_outw (0, LAN91C96_DATA_HIGH);	} else {		SMC_outw (buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH);	}	/* and let the chipset deal with it */	SMC_outw (LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU);	/* poll for TX INT */	if (poll4int (LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) {		/* sending failed */		PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);		/* release packet */		SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);		/* wait for MMU getting ready (low) */		while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {			udelay (10);		}		PRINTK2 ("MMU ready\n");		return 0;	} else {		/* ack. int */		SMC_outw (LAN91C96_IST_TX_INT, LAN91C96_INT_STATS);		PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, length);		/* release packet */		SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);		/* wait for MMU getting ready (low) */		while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {			udelay (10);		}		PRINTK2 ("MMU ready\n");	}	return length;}/*------------------------------------------------------------------------- * smc_destructor( struct net_device * dev ) *   Input parameters: *	dev, pointer to the device structure * *   Output: *	None. *-------------------------------------------------------------------------- */void smc_destructor (){	PRINTK2 (CARDNAME ":smc_destructor\n");}/* * Open and Initialize the board * * Set up everything, reset the card, etc .. * */static int smc_open (bd_t *bd){	int i, err;			/* used to set hw ethernet address */	PRINTK2 ("%s:smc_open\n", SMC_DEV_NAME);	/* reset the hardware */	smc_reset ();	smc_enable ();	SMC_SELECT_BANK (1);	err = smc_get_ethaddr (bd);	/* set smc_mac_addr, and sync it with u-boot globals */	if (err < 0) {		memset (bd->bi_enetaddr, 0, 6); /* hack to make error stick! upper code will abort if not set */		return (-1);	/* upper code ignores this, but NOT bi_enetaddr */	}#ifdef USE_32_BIT	for (i = 0; i < 6; i += 2) {		word address;		address = smc_mac_addr[i + 1] << 8;		address |= smc_mac_addr[i];		SMC_outw (address, LAN91C96_IA0 + i);	}#else	for (i = 0; i < 6; i++)		SMC_outb (smc_mac_addr[i], LAN91C96_IA0 + i);#endif	return 0;}/*------------------------------------------------------------- * * smc_rcv -  receive a packet from the card * * There is ( at least ) a packet waiting to be read from * chip-memory. * * o Read the status * o If an error, record it * o otherwise, read in the packet *------------------------------------------------------------- */static int smc_rcv (){	int packet_number;	word status;	word packet_length;	int is_error = 0;#ifdef USE_32_BIT	dword stat_len;#endif	SMC_SELECT_BANK (2);	packet_number = SMC_inw (LAN91C96_FIFO);	if (packet_number & LAN91C96_FIFO_RXEMPTY) {		return 0;	}	PRINTK3 ("%s:smc_rcv\n", SMC_DEV_NAME);	/*  start reading from the start of the packet */	SMC_outw (LAN91C96_PTR_READ | LAN91C96_PTR_RCV |			  LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);	/* First two words are status and packet_length */#ifdef USE_32_BIT	stat_len = SMC_inl (LAN91C96_DATA_HIGH);	status = stat_len & 0xffff;	packet_length = stat_len >> 16;#else	status = SMC_inw (LAN91C96_DATA_HIGH);	packet_length = SMC_inw (LAN91C96_DATA_HIGH);#endif	packet_length &= 0x07ff;	/* mask off top bits */	PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length);	if (!(status & FRAME_FILTER)) {		/* Adjust for having already read the first two words */		packet_length -= 4;		/*4; */		/* set odd length for bug in LAN91C111, */		/* which never sets RS_ODDFRAME */		/* TODO ? */#ifdef USE_32_BIT		PRINTK3 (" Reading %d dwords (and %d bytes) \n",			 packet_length >> 2, packet_length & 3);		/* QUESTION:  Like in the TX routine, do I want		   to send the DWORDs or the bytes first, or some		   mixture.  A mixture might improve already slow PIO		   performance  */		SMC_insl (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 2);		/* read the left over bytes */		if (packet_length & 3) {			int i;			byte *tail = (byte *) (NetRxPackets[0] + (packet_length & ~3));			dword leftover = SMC_inl (LAN91C96_DATA_HIGH);			for (i = 0; i < (packet_length & 3); i++)				*tail++ = (byte) (leftover >> (8 * i)) & 0xff;		}#else		PRINTK3 (" Reading %d words and %d byte(s) \n",				 (packet_length >> 1), packet_length & 1);		SMC_insw (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 1);#endif /* USE_32_BIT */#if	SMC_DEBUG > 2		printf ("Receiving Packet\n");		print_packet (NetRxPackets[0], packet_length);#endif	} else {		/* error ... */		/* TODO ? */		is_error = 1;	}	while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)		udelay (1);		/* Wait until not busy */	/*  error or good, tell the card to get rid of this packet */	SMC_outw (LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU);	while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)		udelay (1);		/* Wait until not busy */	if (!is_error) {		/* Pass the packet up to the protocol layers. */		NetReceive (NetRxPackets[0], packet_length);		return packet_length;	} else {		return 0;	}}/*---------------------------------------------------- * smc_close * * this makes the board clean up everything that it can * and not talk to the outside world.   Caused by * an 'ifconfig ethX down' * -----------------------------------------------------*/static int smc_close (){	PRINTK2 ("%s:smc_close\n", SMC_DEV_NAME);	/* clear everything */	smc_shutdown ();	return 0;}#if SMC_DEBUG > 2static void print_packet (byte * buf, int length){#if 0	int i;	int remainder;	int lines;	printf ("Packet of length %d \n", length);	lines = length / 16;	remainder = length % 16;	for (i = 0; i < lines; i++) {		int cur;		for (cur = 0; cur < 8; cur++) {			byte a, b;			a = *(buf++);			b = *(buf++);			printf ("%02x%02x ", a, b);		}		printf ("\n");	}	for (i = 0; i < remainder / 2; i++) {		byte a, b;		a = *(buf++);		b = *(buf++);		printf ("%02x%02x ", a, b);	}	printf ("\n");#endif /* 0 */}#endif /* SMC_DEBUG > 2 */int eth_init (bd_t * bd){	return (smc_open(bd));}void eth_halt (){	smc_close ();}int eth_rx (){	return smc_rcv ();}int eth_send (volatile void *packet, int length){	return smc_send_packet (packet, length);}#if 0/*------------------------------------------------------------------------- * smc_hw_init() * *   Function: *      Reset and enable the device, check if the I/O space location *      is correct * *   Input parameters: *      None * *   Output: *	0 --> success *	1 --> error *-------------------------------------------------------------------------- */static int smc_hw_init (){	unsigned short status_test;	/* The attribute register of the LAN91C96 is located at address	   0x0e000000 on the lubbock platform */	volatile unsigned *attaddr = (unsigned *) (0x0e000000);	/* first reset, then enable the device. Sequence is critical */	attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_SRESET;	udelay (100);	attaddr[LAN91C96_ECOR] &= ~LAN91C96_ECOR_SRESET;	attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_ENABLE;	/* force 16-bit mode */	attaddr[LAN91C96_ECSR] &= ~LAN91C96_ECSR_IOIS8;	udelay (100);	/* check if the I/O address is correct, the upper byte of the	   bank select register should read 0x33 */	status_test = SMC_inw (LAN91C96_BANK_SELECT);	if ((status_test & 0xFF00) != 0x3300) {		printf ("Failed to initialize ethernetchip\n");		return 1;	}	return 0;}#endif /* 0 */#endif /* COMMANDS & CFG_NET *//* smc_get_ethaddr (bd_t * bd) * * This checks both the environment and the ROM for an ethernet address. If * found, the environment takes precedence. */int smc_get_ethaddr (bd_t * bd){	int env_size = 0;	int rom_valid = 0;	int env_present = 0;	int reg = 0;	char *s = NULL;	char *e = NULL;	char *v_mac, es[] = "11:22:33:44:55:66";	char s_env_mac[64];	uchar v_env_mac[6];	uchar v_rom_mac[6];	env_size = getenv_r ("ethaddr", s_env_mac, sizeof (s_env_mac));	if (env_size != sizeof(es)) {	/* Ignore if env is bad or not set */		printf ("\n*** Warning: ethaddr is not set properly, ignoring!!\n");	} else {		env_present = 1;		s = s_env_mac;		for (reg = 0; reg < 6; ++reg) { /* turn string into mac value */			v_env_mac[reg] = s ? simple_strtoul (s, &e, 16) : 0;			if (s)				s = (*e) ? e + 1 : e;		}	}	rom_valid = get_rom_mac (v_rom_mac);	/* get ROM mac value if any */	if (!env_present) {	/* if NO env */		if (rom_valid) {	/* but ROM is valid */			v_mac = (char *)v_rom_mac;			sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X",				 v_mac[0], v_mac[1], v_mac[2], v_mac[3],				 v_mac[4], v_mac[5]);			setenv ("ethaddr", s_env_mac);		} else {	/* no env, bad ROM */			printf ("\n*** ERROR: ethaddr is NOT set !!\n");			return (-1);		}	} else {		/* good env, don't care ROM */		v_mac = (char *)v_env_mac;	/* always use a good env over a ROM */	}	if (env_present && rom_valid) { /* if both env and ROM are good */		if (memcmp (v_env_mac, v_rom_mac, 6) != 0) {			printf ("\nWarning: MAC addresses don't match:\n");			printf ("\tHW MAC address:  "				"%02X:%02X:%02X:%02X:%02X:%02X\n",				v_rom_mac[0], v_rom_mac[1],				v_rom_mac[2], v_rom_mac[3],				v_rom_mac[4], v_rom_mac[5] );			printf ("\t\"ethaddr\" value: "				"%02X:%02X:%02X:%02X:%02X:%02X\n",				v_env_mac[0], v_env_mac[1],				v_env_mac[2], v_env_mac[3],				v_env_mac[4], v_env_mac[5]) ;			debug ("### Set MAC addr from environment\n");		}	}	memcpy (bd->bi_enetaddr, v_mac, 6);	/* update global address to match env (allows env changing) */	smc_set_mac_addr ((unsigned char *)v_mac); /* use old function to update smc default */	PRINTK("Using MAC Address %02X:%02X:%02X:%02X:%02X:%02X\n", v_mac[0], v_mac[1],		v_mac[2], v_mac[3], v_mac[4], v_mac[5]);	return (0);}/* * get_rom_mac() * Note, this has omly been tested for the OMAP730 P2. */int get_rom_mac (unsigned char *v_rom_mac){#ifdef HARDCODE_MAC	/* used for testing or to supress run time warnings */	char hw_mac_addr[] = { 0x02, 0x80, 0xad, 0x20, 0x31, 0xb8 };	memcpy (v_rom_mac, hw_mac_addr, 6);	return (1);#else	int i;	SMC_SELECT_BANK (1);	for (i=0; i<6; i++)	{		v_rom_mac[i] = SMC_inb (LAN91C96_IA0 + i);	}	return (1);#endif}#endif /* CONFIG_DRIVER_LAN91C96 */

⌨️ 快捷键说明

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