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

📄 triocs8900.c

📁 arm平台上的uclinux系统全部源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	writereg(dev, PP_BusCTL, 0); /* ints off! */#ifdef CONFIG_TRIO_CS8900	setup_arm_irq(IRQ_EXT0, &irq_cs8900);#else		*(volatile unsigned short *)0xfffff302 |= 0x0080; /* +ve pol irq */        if (request_irq(IRQ_MACHSPEC | 20,                        cs8900_interrupt,                        IRQ_FLG_STD,                        "CrystalLAN_cs8900a", NULL))                panic("Unable to attach cs8900 intr\n");#endif			/* set the Ethernet address */	set_mac_address(dev, dev->dev_addr);	/* Set the LineCTL */	lp->linectl = 0;        /* check to make sure that they have the "right" hardware available */	switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {	case A_CNF_MEDIA_10B_T:		result = lp->adapter_cnf & A_CNF_10B_T;		break;	case A_CNF_MEDIA_AUI:		result = lp->adapter_cnf & A_CNF_AUI;		break;	case A_CNF_MEDIA_10B_2:		result = lp->adapter_cnf & A_CNF_10B_2;		break;        default:		result = lp->adapter_cnf & 		         (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);        }        if (!result) {                printk("%s: EEPROM is configured for unavailable media\n", dev->name);        release_irq:                writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) & ~(SERIAL_TX_ON | SERIAL_RX_ON));                irq2dev_map[dev->irq] = 0;		return -EAGAIN;	}        /* set the hardware to the configured choice */	switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {	case A_CNF_MEDIA_10B_T:                result = detect_tp(dev);                if (!result) printk("%s: 10Base-T (RJ-45) has no cable\n", dev->name);                if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */                        result = A_CNF_MEDIA_10B_T; /* Yes! I don't care if I see a link pulse */		break;	case A_CNF_MEDIA_AUI:	  printk("AUI?  What stinking AUI?\n");		break;	case A_CNF_MEDIA_10B_2:	  printk("10Base2?  What stinking 10Base2?\n");		break;	case A_CNF_MEDIA_AUTO:		writereg(dev, PP_LineCTL, lp->linectl | AUTO_AUI_10BASET);		if (lp->adapter_cnf & A_CNF_10B_T)			if ((result = detect_tp(dev)) != 0)				break;		printk("%s: no media detected\n", dev->name);                goto release_irq;	}	switch(result) {	case 0: printk("%s: no network cable attached to configured media\n", dev->name);                goto release_irq;	case A_CNF_MEDIA_10B_T: printk("%s: using 10Base-T (RJ-45)\n", dev->name);break;	case A_CNF_MEDIA_AUI:   printk("%s: using 10Base-5 (AUI)\n", dev->name);break;	case A_CNF_MEDIA_10B_2: printk("%s: using 10Base-2 (BNC)\n", dev->name);break;	default: printk("%s: unexpected result was %x\n", dev->name, result); goto release_irq;	}	/* Turn on both receive and transmit operations */	writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);	/* Receive only error free packets addressed to this card */	lp->rx_mode = 0;	writereg(dev, PP_RxCTL, DEF_RX_ACCEPT);	lp->curr_rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL;	if (lp->isa_config & STREAM_TRANSFER)		lp->curr_rx_cfg |= RX_STREAM_ENBL;	writereg(dev, PP_RxCFG, lp->curr_rx_cfg);	writereg(dev, PP_TxCFG, TX_LOST_CRS_ENBL | TX_SQE_ERROR_ENBL | TX_OK_ENBL |	       TX_LATE_COL_ENBL | TX_JBR_ENBL | TX_ANY_COL_ENBL | TX_16_COL_ENBL);	writereg(dev, PP_BufCFG, READY_FOR_TX_ENBL | RX_MISS_COUNT_OVRFLOW_ENBL |		 TX_COL_COUNT_OVRFLOW_ENBL | TX_UNDERRUN_ENBL);	/* now that we've got our act together, enable everything */	writereg(dev, PP_BusCTL, ENABLE_IRQ                 );	dev->tbusy = 0;	dev->interrupt = 0;	dev->start = 1;	return 0;}static intnet_send_packet(struct sk_buff *skb, struct device *dev){	if (dev->tbusy) {		/* If we get here, some higher level has decided we are broken.		   There should really be a "kick me" function call instead. */		int tickssofar = jiffies - dev->trans_start;		if (tickssofar < 5)			return 1;		if (net_debug > 0) printk("%s: transmit timed out, %s?\n", dev->name,			   tx_done(dev) ? "IRQ conflict" : "network cable problem");		/* Try to restart the adaptor. */		dev->tbusy=0;		dev->trans_start = jiffies;	}	/* If some higher layer thinks we've missed an tx-done interrupt	   we are passed NULL. Caution: dev_tint() handles the cli()/sti()	   itself. */	if (skb == NULL) {		dev_tint(dev);		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. */	if (set_bit(0, (void*)&dev->tbusy) != 0)		printk("%s: Transmitter access conflict.\n", dev->name);	else {		struct net_local *lp = (struct net_local *)dev->priv;		unsigned long ioaddr = dev->base_addr;		unsigned long flags;		if (net_debug > 3)printk("%s: sent %ld byte packet of type %x\n", dev->name, skb->len, (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);		/* keep the upload from being interrupted, since we                   ask the chip to start transmitting before the                   whole packet has been completely uploaded. */		save_flags(flags);		cli();		/* initiate a transmit sequence */		outw(lp->send_cmd, ioaddr + TX_CMD_PORT);		outw(skb->len, ioaddr + TX_LEN_PORT);		/* Test to see if the chip has allocated memory for the packet */		if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) {			/* Gasp!  It hasn't.  But that shouldn't happen since			   we're waiting for TxOk, so return 1 and requeue this packet. */			restore_flags(flags);			printk("cs8900 did not allocate memory for tx!\n");			return 1;		}		/* Write the contents of the packet */                outsw(ioaddr + TX_FRAME_PORT,skb->data,(skb->len+1) >>1);		restore_flags(flags);		dev->trans_start = jiffies;	}	dev_kfree_skb (skb, FREE_WRITE);	return 0;}/* The typical workload of the driver:   Handle the network interface interrupts. */voidcs8900_interrupt(int irq, void *dev_id, struct pt_regs * regs){        struct device *dev = (struct device *)(irq2dev_map[/* FIXME */0]);	struct net_local *lp;	int ioaddr, status;	dev = irq2dev_map[0];	if (dev == NULL) {		printk ("net_interrupt(): irq %d for unknown device.\n", irq);		return;	}	if (dev->interrupt)		printk("%s: Re-entering the interrupt handler.\n", dev->name);	dev->interrupt = 1;	ioaddr = dev->base_addr;	lp = (struct net_local *)dev->priv;	/* we MUST read all the events out of the ISQ, otherwise we'll never           get interrupted again.  As a consequence, we can't have any limit           on the number of times we loop in the interrupt handler.  The           hardware guarantees that eventually we'll run out of events.  Of           course, if you're on a slow machine, and packets are arriving           faster than you can read them off, you're screwed.  Hasta la           vista, baby!  */	while ((status = readword(dev, ISQ_PORT))) {		if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status);		switch(status & ISQ_EVENT_MASK) {		case ISQ_RECEIVER_EVENT:			/* Got a packet(s). */			net_rx(dev);			break;		case ISQ_TRANSMITTER_EVENT:			lp->stats.tx_packets++;			dev->tbusy = 0;			mark_bh(NET_BH);	/* Inform upper layers. */			if ((status & TX_OK) == 0) lp->stats.tx_errors++;			if (status & TX_LOST_CRS) lp->stats.tx_carrier_errors++;			if (status & TX_SQE_ERROR) lp->stats.tx_heartbeat_errors++;			if (status & TX_LATE_COL) lp->stats.tx_window_errors++;			if (status & TX_16_COL) lp->stats.tx_aborted_errors++;			break;		case ISQ_BUFFER_EVENT:			if (status & READY_FOR_TX) {				/* we tried to transmit a packet earlier,                                   but inexplicably ran out of buffers.                                   That shouldn't happen since we only ever                                   load one packet.  Shrug.  Do the right                                   thing anyway. */				dev->tbusy = 0;				mark_bh(NET_BH);	/* Inform upper layers. */			}			if (status & TX_UNDERRUN) {				if (net_debug > 0) printk("%s: transmit underrun\n", dev->name);                                lp->send_underrun++;                                if (lp->send_underrun > 3) lp->send_cmd = TX_AFTER_ALL;                        }			break;		case ISQ_RX_MISS_EVENT:			lp->stats.rx_missed_errors += (status >>6);			break;		case ISQ_TX_COL_EVENT:			lp->stats.collisions += (status >>6);			break;		}	}	dev->interrupt = 0;	return;}/* We have a good packet(s), get it/them out of the buffers. */static voidnet_rx(struct device *dev){	struct net_local *lp = (struct net_local *)dev->priv;	int ioaddr = dev->base_addr;	struct sk_buff *skb;	int status, length;	status = inw(ioaddr + RX_FRAME_PORT);	length = inw(ioaddr + RX_FRAME_PORT);	if ((status & RX_OK) == 0) {		lp->stats.rx_errors++;		if (status & RX_RUNT) lp->stats.rx_length_errors++;		if (status & RX_EXTRA_DATA) lp->stats.rx_length_errors++;		if (status & RX_CRC_ERROR) if (!(status & (RX_EXTRA_DATA|RX_RUNT)))			/* per str 172 */			lp->stats.rx_crc_errors++;		if (status & RX_DRIBBLE) lp->stats.rx_frame_errors++;		return;	}	/* Malloc up new buffer. */	skb = alloc_skb(length, GFP_ATOMIC);	if (skb == NULL) {		printk("%s: Memory squeeze, dropping packet.\n", dev->name);		lp->stats.rx_dropped++;		return;	}	skb->len = length;	skb->dev = dev;        insw(ioaddr + RX_FRAME_PORT, skb->data, length >> 1);	if (length & 1)		skb->data[length-1] = inw(ioaddr + RX_FRAME_PORT);	if (net_debug > 3)printk("%s: received %d byte packet of type %x\n",                                 dev->name, length,                                 (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);        skb->protocol=eth_type_trans(skb,dev);	netif_rx(skb);	lp->stats.rx_packets++;	return;}/* The inverse routine to net_open(). */static intnet_close(struct device *dev){	/* FIXME:  This needs to put the chip to sleep and turn off the irq */	writereg(dev, PP_RxCFG, 0);	writereg(dev, PP_TxCFG, 0);	writereg(dev, PP_BufCFG, 0);	writereg(dev, PP_BusCTL, 0);	dev->start = 0;#if 0	free_irq(dev->irq, NULL);#endif	irq2dev_map[/* FIXME */ 0] = 0;	/* Update the statistics here. */	return 0;}/* Get the current statistics.	This may be called with the card open or   closed. */static struct enet_statistics *net_get_stats(struct device *dev){	struct net_local *lp = (struct net_local *)dev->priv;	cli();	/* Update the statistics from the device registers. */	lp->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);	lp->stats.collisions += (readreg(dev, PP_TxCol) >> 6);	sti();	return &lp->stats;}static void set_multicast_list(struct device *dev){	struct net_local *lp = (struct net_local *)dev->priv;	if(dev->flags&IFF_PROMISC)	{		lp->rx_mode = RX_ALL_ACCEPT;	}	else if((dev->flags&IFF_ALLMULTI)||dev->mc_list)	{		/* The multicast-accept list is initialized to accept-all, and we		   rely on higher-level filtering for now. */		lp->rx_mode = RX_MULTCAST_ACCEPT;	} 	else		lp->rx_mode = 0;	writereg(dev, PP_RxCTL, DEF_RX_ACCEPT | lp->rx_mode);	/* in promiscuous mode, we accept errored packets, so we have to enable interrupts on them also */	writereg(dev, PP_RxCFG, lp->curr_rx_cfg |	     (lp->rx_mode == RX_ALL_ACCEPT? (RX_CRC_ERROR_ENBL|RX_RUNT_ENBL|RX_EXTRA_DATA_ENBL) : 0));}static intset_mac_address(struct device *dev, void *addr){	int i;	if (dev->start)		return -EBUSY;	printk("%s: Setting MAC address to ", dev->name);	for (i = 0; i < 6; i++)		printk(" %2.2x", dev->dev_addr[i] = ((unsigned char *)addr)[i]);	printk(".\n");	/* set the Ethernet address */	for (i=0; i < ETH_ALEN/2; i++)		writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));	return 0;}/* * Local variables: *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/include -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DMODULE -DCONFIG_MODVERSIONS -c cs89x0.c" *  version-control: t *  kept-new-versions: 5 *  c-indent-level: 8 *  tab-width: 8 * End: */

⌨️ 快捷键说明

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