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

📄 sun3lance.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 2 页
字号:
	struct lance_private *lp = (struct lance_private *)dev->priv;	int entry, len;	struct lance_tx_head *head;	unsigned long flags;	/* Transmitter timeout, serious problems. */	if (netif_queue_stopped(dev)) {		int tickssofar = jiffies - dev->trans_start;		if (tickssofar < 20)			return( 1 );		DPRINTK( 1, ( "%s: transmit timed out, status %04x, resetting.\n",					  dev->name, DREG ));		DREG = CSR0_STOP;		/*		 * Always set BSWP after a STOP as STOP puts it back into		 * little endian mode.		 */		REGA(CSR3) = CSR3_BSWP;		lp->stats.tx_errors++;		if(lance_debug >= 2) {			int i;			printk("Ring data: old_tx %d new_tx %d%s new_rx %d\n",			       lp->old_tx, lp->new_tx,			       lp->tx_full ? " (full)" : "",			       lp->new_rx );			for( i = 0 ; i < RX_RING_SIZE; i++ )				printk( "rx #%d: base=%04x blen=%04x mlen=%04x\n",					i, MEM->rx_head[i].base,					-MEM->rx_head[i].buf_length,					MEM->rx_head[i].msg_length);			for( i = 0 ; i < TX_RING_SIZE; i++ )				printk("tx #%d: base=%04x len=%04x misc=%04x\n",				       i, MEM->tx_head[i].base,				       -MEM->tx_head[i].length,				       MEM->tx_head[i].misc );		}		lance_init_ring(dev);		REGA( CSR0 ) = CSR0_INEA | CSR0_INIT | CSR0_STRT;				netif_start_queue(dev);		dev->trans_start = jiffies;				return 0;	}		/* Block a timer-based transmit from overlapping.  This could better be	   done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */	/* Block a timer-based transmit from overlapping with us by	   stopping the queue for a bit... */     	netif_stop_queue(dev);	if (test_and_set_bit( 0, (void*)&lp->lock ) != 0) {		printk( "%s: tx queue lock!.\n", dev->name);		/* don't clear dev->tbusy flag. */		return 1;	}	AREG = CSR0;//	DPRINTK( 2, ( "%s: lance_start_xmit() called, csr0 %4.4x.\n",//				  dev->name, DREG ));		/* Fill in a Tx ring entry */#if 0	if (lance_debug >= 3) {		u_char *p;		int i;		printk( "%s: TX pkt %d type 0x%04x from ", dev->name,			lp->new_tx, ((u_short *)skb->data)[6]);		for( p = &((u_char *)skb->data)[6], i = 0; i < 6; i++ )			printk("%02x%s", *p++, i != 5 ? ":" : "" );		printk(" to ");		for( p = (u_char *)skb->data, i = 0; i < 6; i++ )			printk("%02x%s", *p++, i != 5 ? ":" : "" );		printk(" data at 0x%08x len %d\n", (int)skb->data,		       (int)skb->len );	}#endif		/* We're not prepared for the int until the last flags are set/reset.	 * And the int may happen already after setting the OWN_CHIP... */	save_and_cli(flags);	/* Mask to ring buffer boundary. */	entry = lp->new_tx;	head  = &(MEM->tx_head[entry]);	/* Caution: the write order is important here, set the "ownership" bits	 * last.	 */	/* the sun3's lance needs it's buffer padded to the minimum	   size */	len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;//	head->length = -len;	head->length = (-len) | 0xf000;	head->misc = 0;	memcpy( PKTBUF_ADDR(head), (void *)skb->data, skb->len );	head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP;	lp->new_tx = (lp->new_tx + 1) & TX_RING_MOD_MASK;	lp->stats.tx_bytes += skb->len;	/* Trigger an immediate send poll. */	REGA(CSR0) = CSR0_INEA | CSR0_TDMD;	dev->trans_start = jiffies;	dev_kfree_skb( skb );	lp->lock = 0;	if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) ==	    TMD1_OWN_HOST) 		netif_start_queue(dev);	restore_flags(flags);	return 0;}/* The LANCE interrupt handler. */static void lance_interrupt( int irq, void *dev_id, struct pt_regs *fp){	struct net_device *dev = dev_id;	struct lance_private *lp = dev->priv;	int csr0;	static int in_interrupt;	if (dev == NULL) {		DPRINTK( 1, ( "lance_interrupt(): invalid dev_id\n" ));		return;	}	if (in_interrupt)		DPRINTK( 2, ( "%s: Re-entering the interrupt handler.\n", dev->name ));	in_interrupt = 1; still_more:	AREG = CSR0;	csr0 = DREG;	/* ack interrupts */	DREG = csr0 & (CSR0_TINT | CSR0_RINT);	/* clear errors */	if(csr0 & CSR0_ERR)		DREG = CSR0_BABL | CSR0_MERR | CSR0_CERR | CSR0_MISS;	DPRINTK( 2, ( "%s: interrupt  csr0=%04x new csr=%04x.\n",		      dev->name, csr0, DREG ));	if (csr0 & CSR0_TINT) {			/* Tx-done interrupt */		int old_tx = lp->old_tx;//		if(lance_debug >= 3) {//			int i;//			//			printk("%s: tx int\n", dev->name);//			//			for(i = 0; i < TX_RING_SIZE; i++)//				printk("ring %d flag=%04x\n", i,//				       MEM->tx_head[i].flag);//		}				while( old_tx != lp->new_tx) {			struct lance_tx_head *head = &(MEM->tx_head[old_tx]); 						DPRINTK(3, ("on tx_ring %d\n", old_tx));			if (head->flag & TMD1_OWN_CHIP)				break; /* It still hasn't been Txed */							if (head->flag & TMD1_ERR) {				int status = head->misc;				lp->stats.tx_errors++;				if (status & TMD3_RTRY) lp->stats.tx_aborted_errors++;				if (status & TMD3_LCAR) lp->stats.tx_carrier_errors++;				if (status & TMD3_LCOL) lp->stats.tx_window_errors++;				if (status & (TMD3_UFLO | TMD3_BUFF)) {					lp->stats.tx_fifo_errors++;					printk("%s: Tx FIFO error\n",					       dev->name); 					REGA(CSR0) = CSR0_STOP;					REGA(CSR3) = CSR3_BSWP;					lance_init_ring(dev);					REGA(CSR0) = CSR0_STRT | CSR0_INEA;					return;				}			} else if(head->flag & (TMD1_ENP | TMD1_STP)) {								head->flag &= ~(TMD1_ENP | TMD1_STP);				if(head->flag & (TMD1_ONE | TMD1_MORE))					lp->stats.collisions++;								lp->stats.tx_packets++;				DPRINTK(3, ("cleared tx ring %d\n", old_tx));			}			old_tx = (old_tx +1) & TX_RING_MOD_MASK;		}		lp->old_tx = old_tx;	}	if (netif_queue_stopped(dev)) {		/* The ring is no longer full, clear tbusy. */		netif_start_queue(dev);		netif_wake_queue(dev);	}	if (csr0 & CSR0_RINT)			/* Rx interrupt */		lance_rx( dev );		/* Log misc errors. */	if (csr0 & CSR0_BABL) lp->stats.tx_errors++; /* Tx babble. */	if (csr0 & CSR0_MISS) lp->stats.rx_errors++; /* Missed a Rx frame. */	if (csr0 & CSR0_MERR) {		DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), "			      "status %04x.\n", dev->name, csr0 ));		/* Restart the chip. */		REGA(CSR0) = CSR0_STOP;		REGA(CSR3) = CSR3_BSWP;		lance_init_ring(dev);		REGA(CSR0) = CSR0_STRT | CSR0_INEA;	}    /* Clear any other interrupt, and set interrupt enable. *///	DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR |//		   CSR0_IDON | CSR0_INEA;	REGA(CSR0) = CSR0_INEA;	if(DREG & (CSR0_RINT | CSR0_TINT)) {	     DPRINTK(2, ("restarting interrupt, csr0=%#04x\n", DREG));	     goto still_more;	}	DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n",				  dev->name, DREG ));	in_interrupt = 0;	return;}/* get packet, toss into skbuff */static int lance_rx( struct net_device *dev ){	struct lance_private *lp = (struct lance_private *)dev->priv;	int entry = lp->new_rx;	/* If we own the next entry, it's a new packet. Send it up. */	while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) {		struct lance_rx_head *head = &(MEM->rx_head[entry]);		int status = head->flag;				if (status != (RMD1_ENP|RMD1_STP)) {  /* There was an error. */			/* There is a tricky error noted by John Murphy,			   <murf@perftech.com> to Russ Nelson: Even with 			   full-sized buffers it's possible for a jabber packet to use two			   buffers, with only the last correctly noting the error. */			if (status & RMD1_ENP)	/* Only count a general error at the */				lp->stats.rx_errors++; /* end of a packet.*/			if (status & RMD1_FRAM) lp->stats.rx_frame_errors++;			if (status & RMD1_OFLO) lp->stats.rx_over_errors++;			if (status & RMD1_CRC) lp->stats.rx_crc_errors++;			if (status & RMD1_BUFF) lp->stats.rx_fifo_errors++;			head->flag &= (RMD1_ENP|RMD1_STP);		} else {			/* Malloc up new buffer, compatible with net-3. *///			short pkt_len = head->msg_length;// & 0xfff;			short pkt_len = (head->msg_length & 0xfff) - 4;			struct sk_buff *skb;			if (pkt_len < 60) {				printk( "%s: Runt packet!\n", dev->name );				lp->stats.rx_errors++;			}			else {				skb = dev_alloc_skb( pkt_len+2 );				if (skb == NULL) {					DPRINTK( 1, ( "%s: Memory squeeze, deferring packet.\n",						      dev->name ));										lp->stats.rx_dropped++;					head->msg_length = 0;					head->flag |= RMD1_OWN_CHIP;					lp->new_rx = (lp->new_rx+1) &					     RX_RING_MOD_MASK;				}#if 0				if (lance_debug >= 3) {					u_char *data = PKTBUF_ADDR(head), *p;					printk( "%s: RX pkt %d type 0x%04x from ", dev->name, entry, ((u_short *)data)[6]);					for( p = &data[6], i = 0; i < 6; i++ )						printk("%02x%s", *p++, i != 5 ? ":" : "" );					printk(" to ");					for( p = data, i = 0; i < 6; i++ )						printk("%02x%s", *p++, i != 5 ? ":" : "" );					printk(" data %02x %02x %02x %02x %02x %02x %02x %02x "					       "len %d at %08x\n",					       data[15], data[16], data[17], data[18],					       data[19], data[20], data[21], data[22],					       pkt_len, data);				}#endif				if (lance_debug >= 3) {					u_char *data = PKTBUF_ADDR(head);					printk( "%s: RX pkt %d type 0x%04x len %d\n ", dev->name, entry, ((u_short *)data)[6], pkt_len);				}								skb->dev = dev;				skb_reserve( skb, 2 );	/* 16 byte align */				skb_put( skb, pkt_len );	/* Make room *///			        memcpy( skb->data, PKTBUF_ADDR(head), pkt_len );				eth_copy_and_sum(skb,						 PKTBUF_ADDR(head),						 pkt_len, 0);				skb->protocol = eth_type_trans( skb, dev );				netif_rx( skb );				dev->last_rx = jiffies;				lp->stats.rx_packets++;				lp->stats.rx_bytes += pkt_len;			}		}//		head->buf_length = -PKT_BUF_SZ | 0xf000;		head->msg_length = 0;		head->flag = RMD1_OWN_CHIP;		entry = lp->new_rx = (lp->new_rx +1) & RX_RING_MOD_MASK;	}	/* From lance.c (Donald Becker): */	/* We should check that at least two ring entries are free.	   If not, we should free one and mark stats->rx_dropped++. */	return 0;}static int lance_close( struct net_device *dev ){	struct lance_private *lp = (struct lance_private *)dev->priv;	netif_stop_queue(dev);	AREG = CSR0;	DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n",				  dev->name, DREG ));	/* We stop the LANCE here -- it occasionally polls	   memory if we don't. */	DREG = CSR0_STOP;	MOD_DEC_USE_COUNT;	return 0;}static struct net_device_stats *lance_get_stats( struct net_device *dev ){	struct lance_private *lp = (struct lance_private *)dev->priv;	return &lp->stats;}/* Set or clear the multicast filter for this adaptor.   num_addrs == -1		Promiscuous mode, receive all packets   num_addrs == 0		Normal mode, clear multicast list   num_addrs > 0		Multicast mode, receive normal and MC packets, and do						best-effort filtering. *//* completely untested on a sun3 */static void set_multicast_list( struct net_device *dev ){	struct lance_private *lp = (struct lance_private *)dev->priv;	if(netif_queue_stopped(dev))		/* Only possible if board is already started */		return;	/* We take the simple way out and always enable promiscuous mode. */	DREG = CSR0_STOP; /* Temporarily stop the lance. */	if (dev->flags & IFF_PROMISC) {		/* Log any net taps. */		DPRINTK( 1, ( "%s: Promiscuous mode enabled.\n", dev->name ));		REGA( CSR15 ) = 0x8000; /* Set promiscuous mode */	} else {		short multicast_table[4];		int num_addrs = dev->mc_count;		int i;		/* We don't use the multicast table, but rely on upper-layer		 * filtering. */		memset( multicast_table, (num_addrs == 0) ? 0 : -1,				sizeof(multicast_table) );		for( i = 0; i < 4; i++ )			REGA( CSR8+i ) = multicast_table[i];		REGA( CSR15 ) = 0; /* Unset promiscuous mode */	}	/*	 * Always set BSWP after a STOP as STOP puts it back into	 * little endian mode.	 */	REGA( CSR3 ) = CSR3_BSWP;	/* Resume normal operation and reset AREG to CSR0 */	REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;}#ifdef MODULEstatic char devicename[9];static struct net_device sun3lance_dev ={	devicename,	/* filled in by register_netdev() */	0, 0, 0, 0,	/* memory */	0, 0,		/* base, irq */	0, 0, 0, NULL, sun3lance_probe,};int init_module(void){	int err;	if ((err = register_netdev( &sun3lance_dev ))) {		if (err == -EIO)  {			printk( "SUN3 Lance not detected.  Module not loaded.\n");		}		return( err );	}	return( 0 );}void cleanup_module(void){	unregister_netdev( &sun3lance_dev );}#endif /* MODULE */

⌨️ 快捷键说明

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