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

📄 atarilance.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* 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_flags(flags);	cli();	/* Mask to ring buffer boundary. */	entry = lp->cur_tx & TX_RING_MOD_MASK;	head  = &(MEM->tx_head[entry]);	/* Caution: the write order is important here, set the "ownership" bits	 * last.	 */	/* The old LANCE chips doesn't automatically pad buffers to min. size. */	len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;	/* PAM-Card has a bug: Can only send packets with even number of bytes! */	if (lp->cardtype == PAM_CARD && (len & 1))		++len;	head->length = -len;	head->misc = 0;	lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len );	head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP;	dev_kfree_skb( skb );	lp->cur_tx++;	lp->stats.tx_bytes += skb->len;	while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) {		lp->cur_tx -= TX_RING_SIZE;		lp->dirty_tx -= TX_RING_SIZE;	}	/* Trigger an immediate send poll. */	DREG = CSR0_INEA | CSR0_TDMD;	dev->trans_start = jiffies;	lp->lock = 0;	if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) ==		TMD1_OWN_HOST)		dev->tbusy = 0;	else		lp->tx_full = 1;	restore_flags(flags);	return 0;}/* The LANCE interrupt handler. */static void lance_interrupt( int irq, void *dev_id, struct pt_regs *fp){	struct device *dev = dev_id;	struct lance_private *lp;	struct lance_ioreg	 *IO;	int csr0, boguscnt = 10;	if (dev == NULL) {		DPRINTK( 1, ( "lance_interrupt(): interrupt for unknown device.\n" ));		return;	}	lp = (struct lance_private *)dev->priv;	IO = lp->iobase;	AREG = CSR0;	if (dev->interrupt)		DPRINTK( 2, ( "%s: Re-entering the interrupt handler.\n", dev->name ));	dev->interrupt = 1;	while( ((csr0 = DREG) & (CSR0_ERR | CSR0_TINT | CSR0_RINT)) &&		   --boguscnt >= 0) {		/* Acknowledge all of the current interrupt sources ASAP. */		DREG = csr0 & ~(CSR0_INIT | CSR0_STRT | CSR0_STOP |									CSR0_TDMD | CSR0_INEA);		DPRINTK( 2, ( "%s: interrupt  csr0=%04x new csr=%04x.\n",					  dev->name, csr0, DREG ));		if (csr0 & CSR0_RINT)			/* Rx interrupt */			lance_rx( dev );		if (csr0 & CSR0_TINT) {			/* Tx-done interrupt */			int dirty_tx = lp->dirty_tx;			while( dirty_tx < lp->cur_tx) {				int entry = dirty_tx & TX_RING_MOD_MASK;				int status = MEM->tx_head[entry].flag;				if (status & TMD1_OWN_CHIP)					break;			/* It still hasn't been Txed */				MEM->tx_head[entry].flag = 0;				if (status & TMD1_ERR) {					/* There was an major error, log it. */					int err_status = MEM->tx_head[entry].misc;					lp->stats.tx_errors++;					if (err_status & TMD3_RTRY) lp->stats.tx_aborted_errors++;					if (err_status & TMD3_LCAR) lp->stats.tx_carrier_errors++;					if (err_status & TMD3_LCOL) lp->stats.tx_window_errors++;					if (err_status & TMD3_UFLO) {						/* Ackk!  On FIFO errors the Tx unit is turned off! */						lp->stats.tx_fifo_errors++;						/* Remove this verbosity later! */						DPRINTK( 1, ( "%s: Tx FIFO error! Status %04x\n",									  dev->name, csr0 ));						/* Restart the chip. */						DREG = CSR0_STRT;					}				} else {					if (status & (TMD1_MORE | TMD1_ONE | TMD1_DEF))						lp->stats.collisions++;					lp->stats.tx_packets++;				}				dirty_tx++;			}#ifndef final_version			if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {				DPRINTK( 0, ( "out-of-sync dirty pointer,"							  " %d vs. %d, full=%d.\n",							  dirty_tx, lp->cur_tx, lp->tx_full ));				dirty_tx += TX_RING_SIZE;			}#endif			if (lp->tx_full && dev->tbusy				&& dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {				/* The ring is no longer full, clear tbusy. */				lp->tx_full = 0;				dev->tbusy = 0;				mark_bh( NET_BH );			}			lp->dirty_tx = dirty_tx;		}		/* 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. */			DREG = CSR0_STRT;		}	}    /* Clear any other interrupt, and set interrupt enable. */	DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR |		   CSR0_IDON | CSR0_INEA;	DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n",				  dev->name, DREG ));	dev->interrupt = 0;	return;}static int lance_rx( struct device *dev ){	struct lance_private *lp = (struct lance_private *)dev->priv;	int entry = lp->cur_rx & RX_RING_MOD_MASK;	int i;	DPRINTK( 2, ( "%s: rx int, flag=%04x\n", dev->name,				  MEM->rx_head[entry].flag ));	/* 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;			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 ));					for( i = 0; i < RX_RING_SIZE; i++ )						if (MEM->rx_head[(entry+i) & RX_RING_MOD_MASK].flag &							RMD1_OWN_CHIP)							break;					if (i > RX_RING_SIZE - 2) {						lp->stats.rx_dropped++;						head->flag |= RMD1_OWN_CHIP;						lp->cur_rx++;					}					break;				}				if (lance_debug >= 3) {					u_char *data = PKTBUF_ADDR(head), *p;					printk( "%s: RX pkt type 0x%04x from ", dev->name,							((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\n",						   data[15], data[16], data[17], data[18],						   data[19], data[20], data[21], data[22],						   pkt_len );				}				skb->dev = dev;				skb_reserve( skb, 2 );	/* 16 byte align */				skb_put( skb, pkt_len );	/* Make room */				lp->memcpy_f( skb->data, PKTBUF_ADDR(head), pkt_len );				skb->protocol = eth_type_trans( skb, dev );				netif_rx( skb );				lp->stats.rx_packets++;				lp->stats.rx_bytes += skb->len;			}		}		head->flag |= RMD1_OWN_CHIP;		entry = (++lp->cur_rx) & RX_RING_MOD_MASK;	}	lp->cur_rx &= 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 device *dev ){	struct lance_private *lp = (struct lance_private *)dev->priv;	struct lance_ioreg	 *IO = lp->iobase;	dev->start = 0;	dev->tbusy = 1;	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 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. */static void set_multicast_list( struct device *dev ){	struct lance_private *lp = (struct lance_private *)dev->priv;	struct lance_ioreg	 *IO = lp->iobase;	if (!dev->start)		/* 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 | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);	/* Resume normal operation and reset AREG to CSR0 */	REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;}/* This is needed for old RieblCards and possible for new RieblCards */static int lance_set_mac_address( struct device *dev, void *addr ){	struct lance_private *lp = (struct lance_private *)dev->priv;	struct sockaddr *saddr = addr;	int i;	if (lp->cardtype != OLD_RIEBL && lp->cardtype != NEW_RIEBL)		return( -EOPNOTSUPP );	if (dev->start) {		/* Only possible while card isn't started */		DPRINTK( 1, ( "%s: hwaddr can be set only while card isn't open.\n",					  dev->name ));		return( -EIO );	}	memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len );	for( i = 0; i < 6; i++ )		MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */	lp->memcpy_f( RIEBL_HWADDR_ADDR, dev->dev_addr, 6 );	/* set also the magic for future sessions */	*RIEBL_MAGIC_ADDR = RIEBL_MAGIC;	return( 0 );}#ifdef MODULEstatic char devicename[9] = { 0, };static struct device atarilance_dev ={	devicename,	/* filled in by register_netdev() */	0, 0, 0, 0,	/* memory */	0, 0,		/* base, irq */	0, 0, 0, NULL, atarilance_probe,};int init_module(void){	int err;	if ((err = register_netdev( &atarilance_dev ))) {		if (err == -EIO)  {			printk( "No Atari Lance board found. Module not loaded.\n");		}		return( err );	}	return( 0 );}void cleanup_module(void){	unregister_netdev( &atarilance_dev );}#endif /* MODULE *//* * Local variables: *  c-indent-level: 4 *  tab-width: 4 * End: */

⌨️ 快捷键说明

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