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

📄 8253xnet.c

📁 这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自测试~但就算用来做参考资料也是非常好的
💻 C
📖 第 1 页 / 共 2 页
字号:
	memset(statsp, 0, sizeof(struct net_device_stats));		statsp->rx_packets +=		((SAB_PORT*)dev->priv)->Counters.receivepacket;	statsp->tx_packets +=		((SAB_PORT*)dev->priv)->Counters.transmitpacket;	statsp->tx_dropped += 		((SAB_PORT*)dev->priv)->Counters.tx_drops;	statsp->rx_dropped += 		((SAB_PORT*)dev->priv)->Counters.rx_drops;}struct net_device_stats *sab8253xn_stats(struct net_device *dev){	SAB_PORT *priv = (SAB_PORT*) dev->priv;		Sab8253xCollectStats(dev);	return &priv->stats;}/* minimal ioctls -- more to be added later */int sab8253xn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd){		SAB_PORT *priv = (SAB_PORT*) dev->priv;		switch(cmd)	{	case SAB8253XCLEARCOUNTERS:		memset(&priv->Counters, 0, sizeof(struct counters));		break;			default:		break;	}	return 0;}#if 0static int sab8253x_block_til_readyN(SAB_PORT *port){	DECLARE_WAITQUEUE(wait, current);	int retval;	int do_clocal = 0;	unsigned long	flags;		/*	 * If the device is in the middle of being closed, then block	 * until it's done, and then try again.	 */	if (port->flags & FLAG8253X_CLOSING)	{		if (port->flags & FLAG8253X_CLOSING)		{			interruptible_sleep_on(&port->close_wait);		}#ifdef SERIAL_DO_RESTART		if (port->flags & FLAG8253X_HUP_NOTIFY)		{			return -EAGAIN;		}		else		{			return -ERESTARTSYS;		}#else		return -EAGAIN;#endif	}		/*	 * this is not a callout device	 */		/* suppose callout active */	if (port->flags & FLAG8253X_CALLOUT_ACTIVE) 	{		if (port->normal_termios.c_cflag & CLOCAL)		{			do_clocal = 1;		}	} 		/*	 * Block waiting for the carrier detect and the line to become	 * free (i.e., not in use by the callout).  While we are in	 * this loop, port->count is dropped by one, so that	 * sab8253x_close() knows when to free things.  We restore it upon	 * exit, either normal or abnormal.	 */	retval = 0;	add_wait_queue(&port->open_wait, &wait);	port->blocked_open++;	while (1) 	{		save_flags(flags); cli();		if (!(port->flags & FLAG8253X_CALLOUT_ACTIVE))		{			RAISE(port,dtr);			RAISE(port,rts);	/* maybe not correct for sync */			/*			 * ??? Why changing the mode here? 			 *  port->regs->rw.mode |= SAB82532_MODE_FRTS;			 *  port->regs->rw.mode &= ~(SAB82532_MODE_RTS);			 */		}		restore_flags(flags);		current->state = TASK_INTERRUPTIBLE;		if (!(port->flags & FLAG8253X_INITIALIZED)) 		{#ifdef SERIAL_DO_RESTART			if (port->flags & FLAG8253X_HUP_NOTIFY)			{				retval = -EAGAIN;			}			else			{				retval = -ERESTARTSYS;				}#else			retval = -EAGAIN;#endif			break;		}		if (!(port->flags & FLAG8253X_CALLOUT_ACTIVE) &&		    !(port->flags & FLAG8253X_CLOSING) &&		    (do_clocal || ISON(port,dcd))) 		{			break;		}#ifdef DEBUG_OPEN		printk("block_til_readyN:2 flags = 0x%x\n",port->flags);#endif		if (signal_pending(current)) 		{			retval = -ERESTARTSYS;			break;		}		schedule();	}	current->state = TASK_RUNNING;	remove_wait_queue(&port->open_wait, &wait);	port->blocked_open--;	if (retval)	{		return retval;	}	port->flags |= FLAG8253X_NORMAL_ACTIVE; /* is this a good flag? */	return 0;}#endifint sab8253x_startupN(struct sab_port *port){	unsigned long flags;	int retval = 0;		save_flags(flags); cli();		if (port->flags & FLAG8253X_INITIALIZED) 	{		goto errout;	}		if (!port->regs) 	{		retval = -ENODEV;		goto errout;	}	/*	 * Initialize the Hardware	 */	sab8253x_init_lineS(port);	/* nothing in this function					 * refers to tty structure */		/* Activate RTS */	RAISE(port,rts);	/* Activate DTR */	RAISE(port,dtr);	/*	 * Initialize the modem signals values	 */	port->dcd.val=ISON(port,dcd);	port->cts.val=ISON(port,cts);	port->dsr.val=ISON(port,dsr);	/*	 * Finally, enable interrupts	 */		port->interrupt_mask0 = SAB82532_IMR0_RFS | SAB82532_IMR0_PCE |		SAB82532_IMR0_PLLA | SAB82532_IMR0_RSC | SAB82532_IMR0_CDSC;	/*((port->ccontrol.ccr2 & SAB82532_CCR2_TOE) ? SAB82532_IMR0_CDSC : 0); */		WRITEB(port,imr0,port->interrupt_mask0);	port->interrupt_mask1 = SAB82532_IMR1_EOP | SAB82532_IMR1_XMR |		SAB82532_IMR1_TIN | SAB82532_IMR1_XPR;	WRITEB(port, imr1, port->interrupt_mask1);	port->all_sent = 1;			/*	 * and set the speed of the serial port	 */	sab8253x_change_speedN(port);		port->flags |= FLAG8253X_INITIALIZED; /* bad name for indicating to other functionalities status */	port->receive_chars = sab8253x_receive_charsN;	port->transmit_chars = sab8253x_transmit_charsS;	port->check_status = sab8253x_check_statusN;	port->receive_test = (SAB82532_ISR0_RME | SAB82532_ISR0_RFO | SAB82532_ISR0_RPF);	port->transmit_test = (SAB82532_ISR1_ALLS | SAB82532_ISR1_RDO | SAB82532_ISR1_XPR |			       SAB82532_ISR1_XDU | SAB82532_ISR1_CSC);	port->check_status_test = (SAB82532_ISR1_CSC);		/*((port->ccontrol.ccr2 & SAB82532_CCR2_TOE) ? 0 : SAB82532_ISR0_CDSC));*/		restore_flags(flags);	return 0;	 errout:	restore_flags(flags);	return retval;}int sab8253xn_open(struct net_device *dev){	unsigned int retval;	SAB_PORT *priv = (SAB_PORT*) dev->priv;		if(priv->function != FUNCTION_NR)	{		return -ENODEV;		/* only allowed if there are no restrictions on the port */	}			if(priv->flags & FLAG8253X_CLOSING) /* try again after the TTY close finishes */	{	#ifdef SERIAL_DO_RESTART		return ((priv->flags & FLAG8253X_HUP_NOTIFY) ?			-EAGAIN : -ERESTARTSYS); /* The ifconfig UP will just fail */#else		return -EAGAIN;#endif	}		/*	 * Maybe start up serial port -- may already be running a TTY	 */	if(priv->flags & FLAG8253X_NORMAL_ACTIVE) /* probably should be a test open at all */	{		return -EBUSY;	/* can't reopen in NET */	}		if(Sab8253xSetUpLists(priv))	{		return -ENODEV;	}		if(Sab8253xInitDescriptors2(priv, sab8253xn_listsize, sab8253xn_rbufsize))	{		Sab8253xCleanUpTransceiveN(priv);		return -ENODEV;	}	netif_carrier_off(dev);		priv->open_type = OPEN_SYNC_NET;	priv->tty = 0;		retval = sab8253x_startupN(priv);	if (retval)	{		Sab8253xCleanUpTransceiveN(priv);		return retval;			}		priv->flags |= FLAG8253X_NETWORK; /* flag the call out driver that it has to reinitialize the port */	priv->tx_full = 0;#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)	dev->start = 1;	dev->tbusy = 0;#else	netif_start_queue(dev);#endif	priv->flags |= FLAG8253X_NORMAL_ACTIVE; /* is this a good flag? */	MOD_INC_USE_COUNT;	return 0;			/* success */}/* stop the PPC, free all skbuffers */int sab8253xn_release(struct net_device *dev)	/* stop */{	SAB_PORT *priv = (SAB_PORT*) dev->priv;	unsigned long flags;		printk(KERN_ALERT "sab8253xn: network interface going down.\n");	save_flags(flags); cli();	#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)	dev->start = 0;	dev->tbusy = 1;#else	netif_stop_queue (dev);#endif		sab8253x_shutdownN(priv);	Sab8253xCleanUpTransceiveN(priv);	netif_carrier_off(dev);	priv->flags &= ~FLAG8253X_NETWORK; 	priv->flags &= ~(FLAG8253X_NORMAL_ACTIVE|/*FLAG8253X_CALLOUT_ACTIVE|*/			 FLAG8253X_CLOSING);	priv->open_type = OPEN_NOT;	MOD_DEC_USE_COUNT;	restore_flags(flags);	return 0;}SAB_PORT *current_sab_port = NULL;int sab8253xn_init(struct net_device *dev){		SAB_PORT *priv;		printk(KERN_ALERT "sab8253xn: initializing SAB8253X network driver instance.\n");		priv = current_sab_port;	dev->priv = priv;		if(dev->priv == NULL)	{		printk(KERN_ALERT "sab8253xn: could not find active port!\n");		return -ENOMEM;	}	priv->dev = dev;		ether_setup(dev);		dev->irq = priv->irq;	dev->hard_start_xmit = sab8253xn_write2;	dev->do_ioctl = sab8253xn_ioctl;	dev->open = sab8253xn_open;	dev->stop = sab8253xn_release;	dev->get_stats = sab8253xn_stats;	dev->base_addr = (unsigned) priv->regs;	/* should I do a request region here */	priv->next_dev = Sab8253xRoot;	Sab8253xRoot = dev;	return 0;}

⌨️ 快捷键说明

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