lasi_82596.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,608 行 · 第 1/3 页

C
1,608
字号
	struct tx_cmd *tx_cmd;	struct i596_tbd *tbd;	short length = skb->len;	dev->trans_start = jiffies;	DEB(DEB_STARTTX, printk("%s: i596_start_xmit(%x,%p) called\n", dev->name,				skb->len, skb->data));	if (length < ETH_ZLEN) {		skb = skb_padto(skb, ETH_ZLEN);		if (skb == NULL)			return 0;		length = ETH_ZLEN;	}		netif_stop_queue(dev);	tx_cmd = lp->tx_cmds + lp->next_tx_cmd;	tbd = lp->tbds + lp->next_tx_cmd;	if (tx_cmd->cmd.command) {		DEB(DEB_ERRORS, printk("%s: xmit ring full, dropping packet.\n",				dev->name));		lp->stats.tx_dropped++;		dev_kfree_skb(skb);	} else {		if (++lp->next_tx_cmd == TX_RING_SIZE)			lp->next_tx_cmd = 0;		tx_cmd->tbd = WSWAPtbd(virt_to_dma(lp,tbd));		tbd->next = I596_NULL;		tx_cmd->cmd.command = CMD_FLEX | CmdTx;		tx_cmd->skb = skb;		tx_cmd->pad = 0;		tx_cmd->size = 0;		tbd->pad = 0;		tbd->size = EOF | length;		tx_cmd->dma_addr = dma_map_single(lp->dev, skb->data, skb->len,				DMA_TO_DEVICE);		tbd->data = WSWAPchar(tx_cmd->dma_addr);		DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));		CHECK_WBACK_INV(tx_cmd, sizeof(struct tx_cmd));		CHECK_WBACK_INV(tbd, sizeof(struct i596_tbd));		i596_add_cmd(dev, &tx_cmd->cmd);		lp->stats.tx_packets++;		lp->stats.tx_bytes += length;	}	netif_start_queue(dev);	return 0;}static void print_eth(unsigned char *add, char *str){	int i;	printk("i596 0x%p, ", add);	for (i = 0; i < 6; i++)		printk(" %02X", add[i + 6]);	printk(" -->");	for (i = 0; i < 6; i++)		printk(" %02X", add[i]);	printk(" %02X%02X, %s\n", add[12], add[13], str);}#define LAN_PROM_ADDR	0xF0810000static int __devinit i82596_probe(struct net_device *dev,				  struct device *gen_dev){	int i;	struct i596_private *lp;	char eth_addr[6];	dma_addr_t dma_addr;	/* This lot is ensure things have been cache line aligned. */	if (sizeof(struct i596_rfd) != 32) {	    printk("82596: sizeof(struct i596_rfd) = %d\n",			    (int)sizeof(struct i596_rfd));	    return -ENODEV;	}	if ((sizeof(struct i596_rbd) % 32) != 0) {	    printk("82596: sizeof(struct i596_rbd) = %d\n",			    (int)sizeof(struct i596_rbd));	    return -ENODEV;	}	if ((sizeof(struct tx_cmd) % 32) != 0) {	    printk("82596: sizeof(struct tx_cmd) = %d\n",			    (int)sizeof(struct tx_cmd));	    return -ENODEV;	}	if (sizeof(struct i596_tbd) != 32) {	    printk("82596: sizeof(struct i596_tbd) = %d\n",			    (int)sizeof(struct i596_tbd));	    return -ENODEV;	}#ifndef __LP64__	if (sizeof(struct i596_private) > 4096) {	    printk("82596: sizeof(struct i596_private) = %d\n",			    (int)sizeof(struct i596_private));	    return -ENODEV;	}#endif	if (!dev->base_addr || !dev->irq)		return -ENODEV;	if (pdc_lan_station_id(eth_addr, dev->base_addr)) {		for (i=0; i < 6; i++) {			eth_addr[i] = gsc_readb(LAN_PROM_ADDR + i);		}		printk(KERN_INFO "%s: MAC of HP700 LAN read from EEPROM\n", __FILE__);	}	dev->mem_start = (unsigned long) dma_alloc_noncoherent(gen_dev, 		sizeof(struct i596_private), &dma_addr, GFP_KERNEL);	if (!dev->mem_start) {		printk(KERN_ERR "%s: Couldn't get shared memory\n", __FILE__);		return -ENOMEM;	}	for (i = 0; i < 6; i++)		dev->dev_addr[i] = eth_addr[i];	/* The 82596-specific entries in the device structure. */	dev->open = i596_open;	dev->stop = i596_close;	dev->hard_start_xmit = i596_start_xmit;	dev->get_stats = i596_get_stats;	dev->set_multicast_list = set_multicast_list;	dev->tx_timeout = i596_tx_timeout;	dev->watchdog_timeo = TX_TIMEOUT;	dev->priv = (void *)(dev->mem_start);	lp = dev->priv;	memset(lp, 0, sizeof(struct i596_private));	lp->scb.command = 0;	lp->scb.cmd = I596_NULL;	lp->scb.rfd = I596_NULL;	lp->lock = SPIN_LOCK_UNLOCKED;	lp->dma_addr = dma_addr;	lp->dev = gen_dev;	CHECK_WBACK_INV(dev->mem_start, sizeof(struct i596_private));	i = register_netdev(dev);	if (i) {		lp = dev->priv;		dma_free_noncoherent(lp->dev, sizeof(struct i596_private), 				    (void *)dev->mem_start, lp->dma_addr);		return i;	};	DEB(DEB_PROBE, printk(KERN_INFO "%s: 82596 at %#3lx,", dev->name, dev->base_addr));	for (i = 0; i < 6; i++)		DEB(DEB_PROBE, printk(" %2.2X", dev->dev_addr[i]));	DEB(DEB_PROBE, printk(" IRQ %d.\n", dev->irq));	DEB(DEB_INIT, printk(KERN_INFO "%s: lp at 0x%p (%d bytes), lp->scb at 0x%p\n",		dev->name, lp, (int)sizeof(struct i596_private), &lp->scb));	return 0;}static irqreturn_t i596_interrupt(int irq, void *dev_id, struct pt_regs *regs){	struct net_device *dev = dev_id;	struct i596_private *lp;	unsigned short status, ack_cmd = 0;	if (dev == NULL) {		printk("%s: irq %d for unknown device.\n", __FUNCTION__, irq);		return IRQ_NONE;	}	lp = dev->priv;	spin_lock (&lp->lock);	wait_cmd(dev, lp, 100, "i596 interrupt, timeout");	status = lp->scb.status;	DEB(DEB_INTS, printk("%s: i596 interrupt, IRQ %d, status %4.4x.\n",			dev->name, irq, status));	ack_cmd = status & 0xf000;	if (!ack_cmd) {		DEB(DEB_ERRORS, printk("%s: interrupt with no events\n", dev->name));		spin_unlock (&lp->lock);		return IRQ_NONE;	}	if ((status & 0x8000) || (status & 0x2000)) {		struct i596_cmd *ptr;		if ((status & 0x8000))			DEB(DEB_INTS, printk("%s: i596 interrupt completed command.\n", dev->name));		if ((status & 0x2000))			DEB(DEB_INTS, printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700));		while (lp->cmd_head != NULL) {			CHECK_INV(lp->cmd_head, sizeof(struct i596_cmd));			if (!(lp->cmd_head->status & STAT_C))				break;			ptr = lp->cmd_head;			DEB(DEB_STATUS, printk("cmd_head->status = %04x, ->command = %04x\n",				       lp->cmd_head->status, lp->cmd_head->command));			lp->cmd_head = ptr->v_next;			lp->cmd_backlog--;			switch ((ptr->command) & 0x7) {			case CmdTx:			    {				struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;				struct sk_buff *skb = tx_cmd->skb;				if ((ptr->status) & STAT_OK) {					DEB(DEB_TXADDR, print_eth(skb->data, "tx-done"));				} else {					lp->stats.tx_errors++;					if ((ptr->status) & 0x0020)						lp->stats.collisions++;					if (!((ptr->status) & 0x0040))						lp->stats.tx_heartbeat_errors++;					if ((ptr->status) & 0x0400)						lp->stats.tx_carrier_errors++;					if ((ptr->status) & 0x0800)						lp->stats.collisions++;					if ((ptr->status) & 0x1000)						lp->stats.tx_aborted_errors++;				}				dma_unmap_single(lp->dev, tx_cmd->dma_addr, skb->len, DMA_TO_DEVICE);				dev_kfree_skb_irq(skb);				tx_cmd->cmd.command = 0; /* Mark free */				break;			    }			case CmdTDR:			    {				unsigned short status = ((struct tdr_cmd *)ptr)->status;				if (status & 0x8000) {					DEB(DEB_ANY, printk("%s: link ok.\n", dev->name));				} else {					if (status & 0x4000)						printk("%s: Transceiver problem.\n", dev->name);					if (status & 0x2000)						printk("%s: Termination problem.\n", dev->name);					if (status & 0x1000)						printk("%s: Short circuit.\n", dev->name);					DEB(DEB_TDR, printk("%s: Time %d.\n", dev->name, status & 0x07ff));				}				break;			    }			case CmdConfigure:				/* Zap command so set_multicast_list() knows it is free */				ptr->command = 0;				break;			}			ptr->v_next = NULL;		        ptr->b_next = I596_NULL;			CHECK_WBACK(ptr, sizeof(struct i596_cmd));			lp->last_cmd = jiffies;		}		/* This mess is arranging that only the last of any outstanding		 * commands has the interrupt bit set.  Should probably really		 * only add to the cmd queue when the CU is stopped.		 */		ptr = lp->cmd_head;		while ((ptr != NULL) && (ptr != lp->cmd_tail)) {			struct i596_cmd *prev = ptr;			ptr->command &= 0x1fff;			ptr = ptr->v_next;			CHECK_WBACK_INV(prev, sizeof(struct i596_cmd));		}		if ((lp->cmd_head != NULL))			ack_cmd |= CUC_START;		lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&lp->cmd_head->status));		CHECK_WBACK_INV(&lp->scb, sizeof(struct i596_scb));	}	if ((status & 0x1000) || (status & 0x4000)) {		if ((status & 0x4000))			DEB(DEB_INTS, printk("%s: i596 interrupt received a frame.\n", dev->name));		i596_rx(dev);		/* Only RX_START if stopped - RGH 07-07-96 */		if (status & 0x1000) {			if (netif_running(dev)) {				DEB(DEB_ERRORS, printk("%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status));				ack_cmd |= RX_START;				lp->stats.rx_errors++;				lp->stats.rx_fifo_errors++;				rebuild_rx_bufs(dev);			}		}	}	wait_cmd(dev, lp, 100, "i596 interrupt, timeout");	lp->scb.command = ack_cmd;	CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));	/* DANGER: I suspect that some kind of interrupt	 acknowledgement aside from acking the 82596 might be needed 	 here...  but it's running acceptably without */	CA(dev);	wait_cmd(dev, lp, 100, "i596 interrupt, exit timeout");	DEB(DEB_INTS, printk("%s: exiting interrupt.\n", dev->name));	spin_unlock (&lp->lock);	return IRQ_HANDLED;}static int i596_close(struct net_device *dev){	struct i596_private *lp = dev->priv;	unsigned long flags;	netif_stop_queue(dev);	DEB(DEB_INIT, printk("%s: Shutting down ethercard, status was %4.4x.\n",		       dev->name, lp->scb.status));	spin_lock_irqsave(&lp->lock, flags);	wait_cmd(dev, lp, 100, "close1 timed out");	lp->scb.command = CUC_ABORT | RX_ABORT;	CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));	CA(dev);	wait_cmd(dev, lp, 100, "close2 timed out");	spin_unlock_irqrestore(&lp->lock, flags);	DEB(DEB_STRUCT,i596_display_data(dev));	i596_cleanup_cmd(dev,lp);	disable_irq(dev->irq);	free_irq(dev->irq, dev);	remove_rx_bufs(dev);	return 0;}static struct net_device_stats * i596_get_stats(struct net_device *dev){	struct i596_private *lp = dev->priv;	return &lp->stats;}/* *    Set or clear the multicast filter for this adaptor. */static void set_multicast_list(struct net_device *dev){	struct i596_private *lp = dev->priv;	int config = 0, cnt;	DEB(DEB_MULTI, printk("%s: set multicast list, %d entries, promisc %s, allmulti %s\n",		dev->name, dev->mc_count, dev->flags & IFF_PROMISC ? "ON" : "OFF",		dev->flags & IFF_ALLMULTI ? "ON" : "OFF"));	if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) {		lp->cf_cmd.i596_config[8] |= 0x01;		config = 1;	}	if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) {		lp->cf_cmd.i596_config[8] &= ~0x01;		config = 1;	}	if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) {		lp->cf_cmd.i596_config[11] &= ~0x20;		config = 1;	}	if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) {		lp->cf_cmd.i596_config[11] |= 0x20;		config = 1;	}	if (config) {		if (lp->cf_cmd.cmd.command)			printk("%s: config change request already queued\n",			       dev->name);		else {			lp->cf_cmd.cmd.command = CmdConfigure;			CHECK_WBACK_INV(&lp->cf_cmd, sizeof(struct cf_cmd));			i596_add_cmd(dev, &lp->cf_cmd.cmd);		}	}	cnt = dev->mc_count;	if (cnt > MAX_MC_CNT)	{		cnt = MAX_MC_CNT;		printk("%s: Only %d multicast addresses supported",			dev->name, cnt);	}		if (dev->mc_count > 0) {		struct dev_mc_list *dmi;		unsigned char *cp;		struct mc_cmd *cmd;		cmd = &lp->mc_cmd;		cmd->cmd.command = CmdMulticastList;		cmd->mc_cnt = dev->mc_count * 6;		cp = cmd->mc_addrs;		for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) {			memcpy(cp, dmi->dmi_addr, 6);			if (i596_debug > 1)				DEB(DEB_MULTI, printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n",						dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]));		}		CHECK_WBACK_INV(&lp->mc_cmd, sizeof(struct mc_cmd));		i596_add_cmd(dev, &cmd->cmd);	}}MODULE_PARM(debug, "i");MODULE_PARM_DESC(debug, "lasi_82596 debug mask");static int debug = -1;static int num_drivers;static struct net_device *netdevs[MAX_DRIVERS];static int __devinitlan_init_chip(struct parisc_device *dev){	struct	net_device *netdevice;	int	retval;	if (num_drivers >= MAX_DRIVERS) {		/* max count of possible i82596 drivers reached */		return -ENOMEM;	}	if (num_drivers == 0)		printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n");		if (!dev->irq) {		printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",			__FILE__, dev->hpa);		return -ENODEV;	}	printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n", dev->hpa, dev->irq);	netdevice = alloc_etherdev(0);	if (!netdevice)		return -ENOMEM;	netdevice->base_addr = dev->hpa;	netdevice->irq = dev->irq;	retval = i82596_probe(netdevice, &dev->dev);	if (retval) {		free_netdev(netdevice);		return -ENODEV;	}	if (dev->id.sversion == 0x72) {		((struct i596_private *)netdevice->priv)->options = OPT_SWAP_PORT;	}	netdevs[num_drivers++] = netdevice;	return retval;}static struct parisc_device_id lan_tbl[] = {	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a },	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 },	{ 0, }};MODULE_DEVICE_TABLE(parisc, lan_tbl);static struct parisc_driver lan_driver = {	.name		= "Apricot",	.id_table	= lan_tbl,	.probe		= lan_init_chip,};static int __devinit lasi_82596_init(void){	if (debug >= 0)		i596_debug = debug;	return register_parisc_driver(&lan_driver);}module_init(lasi_82596_init);static void __exit lasi_82596_exit(void){	int i;	for (i=0; i<MAX_DRIVERS; i++) {		struct i596_private *lp;		struct net_device *netdevice;				netdevice = netdevs[i];		if (!netdevice) 			continue;				unregister_netdev(netdevice);		lp = netdevice->priv;		dma_free_noncoherent(lp->dev, sizeof(struct i596_private), 				       (void *)netdevice->mem_start, lp->dma_addr);		free_netdev(netdevice);	}	num_drivers = 0;	unregister_parisc_driver(&lan_driver);}module_exit(lasi_82596_exit);

⌨️ 快捷键说明

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