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

📄 e100lpslavenet.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 2 页
字号:
	 */#ifdef ETHDEBUG        printk("Starting slave network transmit queue\n");#endif	netif_start_queue(dev);	return 0;}static void e100_reset_tranceiver(void){  /* To do: Reboot and setup slave Etrax */}/* Called by upper layers if they decide it took too long to complete * sending a packet - we need to reset and stuff. */static voide100_tx_timeout(struct net_device *dev){	struct net_local *np = (struct net_local *)dev->priv;	printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,	       tx_done(dev) ? "IRQ problem" : "network cable problem");		/* remember we got an error */		np->stats.tx_errors++; 		/* reset the TX DMA in case it has hung on something */		RESET_DMA(4);	WAIT_DMA(4);		/* Reset the tranceiver. */		e100_reset_tranceiver();		/* and get rid of the packet that never got an interrupt */		dev_kfree_skb(tx_skb);	tx_skb = 0;		/* tell the upper layers we're ok again */		netif_wake_queue(dev);}/* This will only be invoked if the driver is _not_ in XOFF state. * What this means is that we need not check it, and that this * invariant will hold if we make sure that the netif_*_queue() * calls are done at the proper times. */static inte100_send_packet(struct sk_buff *skb, struct net_device *dev){	struct net_local *np = (struct net_local *)dev->priv;	int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;	unsigned char *buf = skb->data;	#ifdef ETHDEBUG        unsigned char *temp_data_ptr = buf;        int i;        	printk("Sending a packet of length %d:\n", length);	/* dump the first bytes in the packet */	for(i = 0; i < 8; i++) {		printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i * 8,		       temp_data_ptr[0],temp_data_ptr[1],temp_data_ptr[2],                       temp_data_ptr[3],temp_data_ptr[4],temp_data_ptr[5],                       temp_data_ptr[6],temp_data_ptr[7]);		temp_data_ptr += 8;	}#endif	spin_lock_irq(&np->lock);  /* protect from tx_interrupt */	tx_skb = skb; /* remember it so we can free it in the tx irq handler later */	dev->trans_start = jiffies;		e100_hardware_send_packet(HOST_CMD_SENDPACK, buf, length);	/* this simple TX driver has only one send-descriptor so we're full	 * directly. If this had a send-ring instead, we would only do this if	 * the ring got full.	 */	netif_stop_queue(dev);        	spin_unlock_irq(&np->lock);	return 0;}/* * The typical workload of the driver: *   Handle the network interface interrupts. */static voide100rx_interrupt(int irq, void *dev_id, struct pt_regs * regs){	struct net_device *dev = (struct net_device *)dev_id;	unsigned long irqbits = *R_IRQ_MASK2_RD;        	if(irqbits & IO_STATE(R_IRQ_MASK2_RD, dma3_eop, active)) {		/* acknowledge the eop interrupt */		*R_DMA_CH3_CLR_INTR = IO_STATE(R_DMA_CH3_CLR_INTR, clr_eop, do);		/* check if one or more complete packets were indeed received */		while(*R_DMA_CH3_FIRST != virt_to_phys(myNextRxDesc)) {			/* Take out the buffer and give it to the OS, then			 * allocate a new buffer to put a packet in.			 */			e100_rx(dev);			((struct net_local *)dev->priv)->stats.rx_packets++;			/* restart/continue on the channel, for safety */			*R_DMA_CH3_CMD = IO_STATE(R_DMA_CH3_CMD, cmd, restart);			/* clear dma channel 3 eop/descr irq bits */			*R_DMA_CH3_CLR_INTR =				IO_STATE(R_DMA_CH3_CLR_INTR, clr_eop, do) |				IO_STATE(R_DMA_CH3_CLR_INTR, clr_descr, do);						/* now, we might have gotten another packet			   so we have to loop back and check if so */		}	}}/* the transmit dma channel interrupt * * this is supposed to free the skbuff which was pending during transmission, * and inform the kernel that we can send one more buffer */static voide100tx_interrupt(int irq, void *dev_id, struct pt_regs * regs){	struct net_device *dev = (struct net_device *)dev_id;	unsigned long irqbits = *R_IRQ_MASK2_RD;	struct net_local *np = (struct net_local *)dev->priv;#ifdef ETHDEBUG        printk("We got tx interrupt\n");#endif	/* check for a dma4_eop interrupt */	if(irqbits & IO_STATE(R_IRQ_MASK2_RD, dma4_descr, active)) {		/* This protects us from concurrent execution of		 * our dev->hard_start_xmit function above.		 */		spin_lock(&np->lock);				/* acknowledge the eop interrupt */                		*R_DMA_CH4_CLR_INTR = IO_STATE(R_DMA_CH4_CLR_INTR, clr_descr, do);                /* skip *R_DMA_CH4_FIRST == 0 test since we use d_wait... */		if(tx_skb) {			np->stats.tx_bytes += tx_skb->len;			np->stats.tx_packets++;			/* dma is ready with the transmission of the data in tx_skb, so now we can release the skb memory */			dev_kfree_skb_irq(tx_skb);			tx_skb = 0;			netif_wake_queue(dev);		} else {			printk(KERN_WARNING "%s: tx weird interrupt\n",                               cardname);		}		spin_unlock(&np->lock);	}}static voidecp_interrupt(int irq, void *dev_id, struct pt_regs * regs){	struct net_device *dev = (struct net_device *)dev_id;	struct net_local *lp = (struct net_local *)dev->priv;	unsigned long temp, irqbits = *R_IRQ_MASK0_RD;        /* check for ecp irq */	if(irqbits & IO_MASK(R_IRQ_MASK0_RD, par0_ecp_cmd)) { 		/* acknowledge by reading the bit */		temp = *R_PAR0_STATUS_DATA;		/* force an EOP on the incoming channel, so we'll get an rx interrupt */		*R_SET_EOP = IO_STATE(R_SET_EOP, ch3_eop, set);	}}/* We have a good packet(s), get it/them out of the buffers. */static voide100_rx(struct net_device *dev){	struct sk_buff *skb;	int length=0;	int i;	struct net_local *np = (struct net_local *)dev->priv;	struct etrax_dma_descr *mySaveRxDesc = myNextRxDesc;	unsigned char *skb_data_ptr;	/* If the packet is broken down in many small packages then merge	 * count how much space we will need to alloc with skb_alloc() for	 * it to fit.	 */	while (!(myNextRxDesc->status & d_eop)) {		length += myNextRxDesc->sw_len; /* use sw_len for the first descs */		myNextRxDesc->status = 0;		myNextRxDesc = phys_to_virt(myNextRxDesc->next);	}	length += myNextRxDesc->hw_len; /* use hw_len for the last descr */#ifdef ETHDEBUG	printk("Got a packet of length %d:\n", length);	/* dump the first bytes in the packet */	skb_data_ptr = (unsigned char *)phys_to_virt(mySaveRxDesc->buf);	for(i = 0; i < 8; i++) {		printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i * 8,		       skb_data_ptr[0],skb_data_ptr[1],skb_data_ptr[2],skb_data_ptr[3],		       skb_data_ptr[4],skb_data_ptr[5],skb_data_ptr[6],skb_data_ptr[7]);		skb_data_ptr += 8;	}#endif	skb = dev_alloc_skb(length - ETHER_HEAD_LEN);	if (!skb) {		np->stats.rx_errors++;		printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n",		       dev->name);		return;	}	skb_put(skb, length - ETHER_HEAD_LEN);        /* allocate room for the packet body */	skb_data_ptr = skb_push(skb, ETHER_HEAD_LEN); /* allocate room for the header */#ifdef ETHDEBUG	printk("head = 0x%x, data = 0x%x, tail = 0x%x, end = 0x%x\n",	       skb->head, skb->data, skb->tail, skb->end);	printk("copying packet to 0x%x.\n", skb_data_ptr);#endif	/* this loop can be made using max two memcpy's if optimized */	while(mySaveRxDesc != myNextRxDesc) {		memcpy(skb_data_ptr, phys_to_virt(mySaveRxDesc->buf),		       mySaveRxDesc->sw_len);		skb_data_ptr += mySaveRxDesc->sw_len;		mySaveRxDesc = phys_to_virt(mySaveRxDesc->next);	}	memcpy(skb_data_ptr, phys_to_virt(mySaveRxDesc->buf),	       mySaveRxDesc->hw_len);	skb->dev = dev;	skb->protocol = eth_type_trans(skb, dev);	/* Send the packet to the upper layers */	netif_rx(skb);	/* Prepare for next packet */	myNextRxDesc->status = 0;	myPrevRxDesc = myNextRxDesc;	myNextRxDesc = phys_to_virt(myNextRxDesc->next);	myPrevRxDesc->ctrl |= d_eol;	myLastRxDesc->ctrl &= ~d_eol;	myLastRxDesc = myPrevRxDesc;	return;}/* The inverse routine to net_open(). */static inte100_close(struct net_device *dev){	struct net_local *np = (struct net_local *)dev->priv;	printk("Closing %s.\n", dev->name);	netif_stop_queue(dev);	*R_IRQ_MASK0_CLR = IO_STATE(R_IRQ_MASK0_CLR, par0_ecp_cmd, clr);	*R_IRQ_MASK2_CLR =		IO_STATE(R_IRQ_MASK2_CLR, dma3_eop, clr) |		IO_STATE(R_IRQ_MASK2_CLR, dma4_descr, clr);		/* Stop the receiver and the transmitter */	RESET_DMA(3);	RESET_DMA(4);	/* Flush the Tx and disable Rx here. */	free_irq(DMA3_RX_IRQ_NBR, (void *)dev);	free_irq(DMA4_TX_IRQ_NBR, (void *)dev);	free_irq(PAR0_ECP_IRQ_NBR, (void *)dev);	free_dma(PAR1_TX_DMA_NBR);	free_dma(PAR0_RX_DMA_NBR);	/* Update the statistics here. */	update_rx_stats(&np->stats);	update_tx_stats(&np->stats);	return 0;}static voidupdate_rx_stats(struct net_device_stats *es){	unsigned long r = *R_REC_COUNTERS;	/* update stats relevant to reception errors */	es->rx_fifo_errors += r >> 24;            /* fifo overrun */	es->rx_crc_errors += r & 0xff;            /* crc error */	es->rx_frame_errors += (r >> 8) & 0xff;   /* alignment error */	es->rx_length_errors += (r >> 16) & 0xff; /* oversized frames */}static voidupdate_tx_stats(struct net_device_stats *es){	unsigned long r = *R_TR_COUNTERS;	/* update stats relevant to transmission errors */	es->collisions += (r & 0xff) + ((r >> 8) & 0xff); /* single_col + multiple_col */	es->tx_errors += (r >> 24) & 0xff; /* deferred transmit frames */}/* * Get the current statistics. * This may be called with the card open or closed. */static struct net_device_stats *e100_get_stats(struct net_device *dev){	struct net_local *lp = (struct net_local *)dev->priv;	update_rx_stats(&lp->stats);	update_tx_stats(&lp->stats);	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 voidset_multicast_list(struct net_device *dev){  /* To do */}voide100_hardware_send_packet(unsigned long hostcmd, char *buf, int length){  static char bogus_ecp[] = { 42, 42 };  int i;  #ifdef ETHDEBUG	printk("e100 send pack, buf 0x%x len %d\n", buf, length);#endif                host_command = hostcmd;	/* Configure the tx dma descriptor. Desc 0 is already configured.*/        TxDescList[1].sw_len = length;	/* bug workaround - etrax100 needs d_wait on the descriptor _before_	 * a descriptor containing an ECP command	 */	TxDescList[1].ctrl = d_wait;	TxDescList[1].buf = virt_to_phys(buf);	TxDescList[1].next = virt_to_phys(&TxDescList[2]);        /* append the ecp dummy descriptor - its only purpose is to 	 * make the receiver generate an irq due to the ecp command	 * so the receiver knows where packets end	 */	TxDescList[2].sw_len = 1;	TxDescList[2].ctrl = d_ecp | d_eol | d_int;	TxDescList[2].buf = virt_to_phys(bogus_ecp);        	/* setup the dma channel and start it */        *R_DMA_CH4_FIRST = virt_to_phys(TxDescList);	*R_DMA_CH4_CMD = IO_STATE(R_DMA_CH4_CMD, cmd, start);        #ifdef ETHDEBUG                  printk("done\n");#endif}/* send a chunk of code to the slave chip to boot it. */static voidboot_slave(unsigned char *code){  int i;#ifdef ETHDEBUG	printk("  booting slave ETRAX...\n");#endif        *R_PORT_PB_DATA = 0x7F; /* Reset slave */        udelay(15); /* Time enough to reset WAN tranciever */        *R_PORT_PB_DATA = 0xFF; /* Reset slave */	/* configure the tx dma data descriptor */	TxDescList[1].sw_len = ETRAX_PAR_BOOT_LENGTH;	TxDescList[1].ctrl = d_eol | d_int;                                                       	TxDescList[1].buf = virt_to_phys(code);	TxDescList[1].next = 0;                /* setup the dma channel and start it */ 	*R_DMA_CH4_FIRST = virt_to_phys(&TxDescList[1]);	*R_DMA_CH4_CMD = IO_STATE(R_DMA_CH4_CMD, cmd, start);	/* wait for completion */	while(!(*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma4_descr)));	/* ack the irq */	*R_DMA_CH4_CLR_INTR = IO_STATE(R_DMA_CH4_CLR_INTR, clr_descr, do);#if 0        /* manual transfer of boot code - requires dma turned off */        for (i=0; i<ETRAX_PAR_BOOT_LENGTH; i++)        {          printk("  sending byte: %u value: %x\n",i,code[i]);          while (((*R_PAR1_STATUS)&0x02) == 0); /* Wait while tr_rdy is busy*/          *R_PAR1_CTRL_DATA = code[i];        }#endif#ifdef ETHDEBUG	printk("  done\n");#endif}#ifdef ETHDEBUG/* debug code to check the current status of PAR1 */static voiddump_parport_status(void){  unsigned long temp;    printk("Parport1 status:\n");    temp = (*R_PAR1_STATUS)&0xE000;  temp = temp >> 13;  printk("Reg mode: %u (ecp_fwd(5), ecp_rev(6))\n", temp);    temp = (*R_PAR1_STATUS)&0x1000;  temp = temp >> 12;  printk("Reg perr: %u (ecp_rev(0))\n", temp);    temp = (*R_PAR1_STATUS)&0x0800;  temp = temp >> 11;  printk("Reg ack: %u (inactive (1), active (0))\n", temp);    temp = (*R_PAR1_STATUS)&0x0400;  temp = temp >> 10;  printk("Reg busy: %u (inactive (0), active (1))\n", temp);    temp = (*R_PAR1_STATUS)&0x0200;  temp = temp >> 9;  printk("Reg fault: %u (inactive (1), active (0))\n", temp);    temp = (*R_PAR1_STATUS)&0x0100;  temp = temp >> 8;  printk("Reg sel: %u (inactive (0), active (1), xflag(1))\n", temp);  temp = (*R_PAR1_STATUS)&0x02;  temp = temp >> 1;  printk("Reg tr_rdy: %u (busy (0), ready (1))\n", temp);}#endif /* ETHDEBUG */static struct net_device dev_etrax_slave_ethernet;static intetrax_init_module(void){	struct net_device *d = &dev_etrax_slave_ethernet;	d->init = etrax_ethernet_lpslave_init;	if(register_netdev(d) == 0)		return 0;	else		return -ENODEV;}module_init(etrax_init_module);

⌨️ 快捷键说明

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