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

📄 fec_mpc52xx.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
}/* * Read MIB counters in order to reset them, * then zero all the stats fields in memory */static void mpc52xx_fec_reset_stats(struct net_device *dev){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	struct mpc52xx_fec __iomem *fec = priv->fec;	out_be32(&fec->mib_control, FEC_MIB_DISABLE);	memset_io(&fec->rmon_t_drop, 0,		   offsetof(struct mpc52xx_fec, reserved10) -		   offsetof(struct mpc52xx_fec, rmon_t_drop));	out_be32(&fec->mib_control, 0);	memset(&dev->stats, 0, sizeof(dev->stats));}/* * Set or clear the multicast filter for this adaptor. */static void mpc52xx_fec_set_multicast_list(struct net_device *dev){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	struct mpc52xx_fec __iomem *fec = priv->fec;	u32 rx_control;	rx_control = in_be32(&fec->r_cntrl);	if (dev->flags & IFF_PROMISC) {		rx_control |= FEC_RCNTRL_PROM;		out_be32(&fec->r_cntrl, rx_control);	} else {		rx_control &= ~FEC_RCNTRL_PROM;		out_be32(&fec->r_cntrl, rx_control);		if (dev->flags & IFF_ALLMULTI) {			out_be32(&fec->gaddr1, 0xffffffff);			out_be32(&fec->gaddr2, 0xffffffff);		} else {			u32 crc;			int i;			struct dev_mc_list *dmi;			u32 gaddr1 = 0x00000000;			u32 gaddr2 = 0x00000000;			dmi = dev->mc_list;			for (i=0; i<dev->mc_count; i++) {				crc = ether_crc_le(6, dmi->dmi_addr) >> 26;				if (crc >= 32)					gaddr1 |= 1 << (crc-32);				else					gaddr2 |= 1 << crc;				dmi = dmi->next;			}			out_be32(&fec->gaddr1, gaddr1);			out_be32(&fec->gaddr2, gaddr2);		}	}}/** * mpc52xx_fec_hw_init * @dev: network device * * Setup various hardware setting, only needed once on start */static void mpc52xx_fec_hw_init(struct net_device *dev){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	struct mpc52xx_fec __iomem *fec = priv->fec;	int i;	/* Whack a reset.  We should wait for this. */	out_be32(&fec->ecntrl, FEC_ECNTRL_RESET);	for (i = 0; i < FEC_RESET_DELAY; ++i) {		if ((in_be32(&fec->ecntrl) & FEC_ECNTRL_RESET) == 0)			break;		udelay(1);	}	if (i == FEC_RESET_DELAY)		dev_err(&dev->dev, "FEC Reset timeout!\n");	/* set pause to 0x20 frames */	out_be32(&fec->op_pause, FEC_OP_PAUSE_OPCODE | 0x20);	/* high service request will be deasserted when there's < 7 bytes in fifo	 * low service request will be deasserted when there's < 4*7 bytes in fifo	 */	out_be32(&fec->rfifo_cntrl, FEC_FIFO_CNTRL_FRAME | FEC_FIFO_CNTRL_LTG_7);	out_be32(&fec->tfifo_cntrl, FEC_FIFO_CNTRL_FRAME | FEC_FIFO_CNTRL_LTG_7);	/* alarm when <= x bytes in FIFO */	out_be32(&fec->rfifo_alarm, 0x0000030c);	out_be32(&fec->tfifo_alarm, 0x00000100);	/* begin transmittion when 256 bytes are in FIFO (or EOF or FIFO full) */	out_be32(&fec->x_wmrk, FEC_FIFO_WMRK_256B);	/* enable crc generation */	out_be32(&fec->xmit_fsm, FEC_XMIT_FSM_APPEND_CRC | FEC_XMIT_FSM_ENABLE_CRC);	out_be32(&fec->iaddr1, 0x00000000);	/* No individual filter */	out_be32(&fec->iaddr2, 0x00000000);	/* No individual filter */	/* set phy speed.	 * this can't be done in phy driver, since it needs to be called	 * before fec stuff (even on resume) */	mpc52xx_fec_phy_hw_init(priv);}/** * mpc52xx_fec_start * @dev: network device * * This function is called to start or restart the FEC during a link * change.  This happens on fifo errors or when switching between half * and full duplex. */static void mpc52xx_fec_start(struct net_device *dev){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	struct mpc52xx_fec __iomem *fec = priv->fec;	u32 rcntrl;	u32 tcntrl;	u32 tmp;	/* clear sticky error bits */	tmp = FEC_FIFO_STATUS_ERR | FEC_FIFO_STATUS_UF | FEC_FIFO_STATUS_OF;	out_be32(&fec->rfifo_status, in_be32(&fec->rfifo_status) & tmp);	out_be32(&fec->tfifo_status, in_be32(&fec->tfifo_status) & tmp);	/* FIFOs will reset on mpc52xx_fec_enable */	out_be32(&fec->reset_cntrl, FEC_RESET_CNTRL_ENABLE_IS_RESET);	/* Set station address. */	mpc52xx_fec_set_paddr(dev, dev->dev_addr);	mpc52xx_fec_set_multicast_list(dev);	/* set max frame len, enable flow control, select mii mode */	rcntrl = FEC_RX_BUFFER_SIZE << 16;	/* max frame length */	rcntrl |= FEC_RCNTRL_FCE;	if (priv->has_phy)		rcntrl |= FEC_RCNTRL_MII_MODE;	if (priv->duplex == DUPLEX_FULL)		tcntrl = FEC_TCNTRL_FDEN;	/* FD enable */	else {		rcntrl |= FEC_RCNTRL_DRT;	/* disable Rx on Tx (HD) */		tcntrl = 0;	}	out_be32(&fec->r_cntrl, rcntrl);	out_be32(&fec->x_cntrl, tcntrl);	/* Clear any outstanding interrupt. */	out_be32(&fec->ievent, 0xffffffff);	/* Enable interrupts we wish to service. */	out_be32(&fec->imask, FEC_IMASK_ENABLE);	/* And last, enable the transmit and receive processing. */	out_be32(&fec->ecntrl, FEC_ECNTRL_ETHER_EN);	out_be32(&fec->r_des_active, 0x01000000);}/** * mpc52xx_fec_stop * @dev: network device * * stop all activity on fec and empty dma buffers */static void mpc52xx_fec_stop(struct net_device *dev){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	struct mpc52xx_fec __iomem *fec = priv->fec;	unsigned long timeout;	/* disable all interrupts */	out_be32(&fec->imask, 0);	/* Disable the rx task. */	bcom_disable(priv->rx_dmatsk);	/* Wait for tx queue to drain, but only if we're in process context */	if (!in_interrupt()) {		timeout = jiffies + msecs_to_jiffies(2000);		while (time_before(jiffies, timeout) &&				!bcom_queue_empty(priv->tx_dmatsk))			msleep(100);		if (time_after_eq(jiffies, timeout))			dev_err(&dev->dev, "queues didn't drain\n");#if 1		if (time_after_eq(jiffies, timeout)) {			dev_err(&dev->dev, "  tx: index: %i, outdex: %i\n",					priv->tx_dmatsk->index,					priv->tx_dmatsk->outdex);			dev_err(&dev->dev, "  rx: index: %i, outdex: %i\n",					priv->rx_dmatsk->index,					priv->rx_dmatsk->outdex);		}#endif	}	bcom_disable(priv->tx_dmatsk);	/* Stop FEC */	out_be32(&fec->ecntrl, in_be32(&fec->ecntrl) & ~FEC_ECNTRL_ETHER_EN);	return;}/* reset fec and bestcomm tasks */static void mpc52xx_fec_reset(struct net_device *dev){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	struct mpc52xx_fec __iomem *fec = priv->fec;	mpc52xx_fec_stop(dev);	out_be32(&fec->rfifo_status, in_be32(&fec->rfifo_status));	out_be32(&fec->reset_cntrl, FEC_RESET_CNTRL_RESET_FIFO);	mpc52xx_fec_free_rx_buffers(dev, priv->rx_dmatsk);	mpc52xx_fec_hw_init(dev);	phy_stop(priv->phydev);	phy_write(priv->phydev, MII_BMCR, BMCR_RESET);	phy_start(priv->phydev);	bcom_fec_rx_reset(priv->rx_dmatsk);	bcom_fec_tx_reset(priv->tx_dmatsk);	mpc52xx_fec_alloc_rx_buffers(dev, priv->rx_dmatsk);	bcom_enable(priv->rx_dmatsk);	bcom_enable(priv->tx_dmatsk);	mpc52xx_fec_start(dev);}/* ethtool interface */static void mpc52xx_fec_get_drvinfo(struct net_device *dev,		struct ethtool_drvinfo *info){	strcpy(info->driver, DRIVER_NAME);}static int mpc52xx_fec_get_settings(struct net_device *dev, struct ethtool_cmd *cmd){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	return phy_ethtool_gset(priv->phydev, cmd);}static int mpc52xx_fec_set_settings(struct net_device *dev, struct ethtool_cmd *cmd){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	return phy_ethtool_sset(priv->phydev, cmd);}static u32 mpc52xx_fec_get_msglevel(struct net_device *dev){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	return priv->msg_enable;}static void mpc52xx_fec_set_msglevel(struct net_device *dev, u32 level){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	priv->msg_enable = level;}static const struct ethtool_ops mpc52xx_fec_ethtool_ops = {	.get_drvinfo = mpc52xx_fec_get_drvinfo,	.get_settings = mpc52xx_fec_get_settings,	.set_settings = mpc52xx_fec_set_settings,	.get_link = ethtool_op_get_link,	.get_msglevel = mpc52xx_fec_get_msglevel,	.set_msglevel = mpc52xx_fec_set_msglevel,};static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd){	struct mpc52xx_fec_priv *priv = netdev_priv(dev);	return mpc52xx_fec_phy_mii_ioctl(priv, if_mii(rq), cmd);}/* ======================================================================== *//* OF Driver                                                                *//* ======================================================================== */static int __devinitmpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match){	int rv;	struct net_device *ndev;	struct mpc52xx_fec_priv *priv = NULL;	struct resource mem;	const phandle *ph;	phys_addr_t rx_fifo;	phys_addr_t tx_fifo;	/* Get the ether ndev & it's private zone */	ndev = alloc_etherdev(sizeof(struct mpc52xx_fec_priv));	if (!ndev)		return -ENOMEM;	priv = netdev_priv(ndev);	/* Reserve FEC control zone */	rv = of_address_to_resource(op->node, 0, &mem);	if (rv) {		printk(KERN_ERR DRIVER_NAME ": "				"Error while parsing device node resource\n" );		return rv;	}	if ((mem.end - mem.start + 1) < sizeof(struct mpc52xx_fec)) {		printk(KERN_ERR DRIVER_NAME			" - invalid resource size (%lx < %x), check mpc52xx_devices.c\n",			(unsigned long)(mem.end - mem.start + 1), sizeof(struct mpc52xx_fec));		return -EINVAL;	}	if (!request_mem_region(mem.start, sizeof(struct mpc52xx_fec), DRIVER_NAME))		return -EBUSY;	/* Init ether ndev with what we have */	ndev->open		= mpc52xx_fec_open;	ndev->stop		= mpc52xx_fec_close;	ndev->hard_start_xmit	= mpc52xx_fec_hard_start_xmit;	ndev->do_ioctl		= mpc52xx_fec_ioctl;	ndev->ethtool_ops	= &mpc52xx_fec_ethtool_ops;	ndev->get_stats		= mpc52xx_fec_get_stats;	ndev->set_mac_address	= mpc52xx_fec_set_mac_address;	ndev->set_multicast_list = mpc52xx_fec_set_multicast_list;	ndev->tx_timeout	= mpc52xx_fec_tx_timeout;	ndev->watchdog_timeo	= FEC_WATCHDOG_TIMEOUT;	ndev->base_addr		= mem.start;	priv->t_irq = priv->r_irq = ndev->irq = NO_IRQ; /* IRQ are free for now */	spin_lock_init(&priv->lock);	/* ioremap the zones */	priv->fec = ioremap(mem.start, sizeof(struct mpc52xx_fec));	if (!priv->fec) {		rv = -ENOMEM;		goto probe_error;	}	/* Bestcomm init */	rx_fifo = ndev->base_addr + offsetof(struct mpc52xx_fec, rfifo_data);	tx_fifo = ndev->base_addr + offsetof(struct mpc52xx_fec, tfifo_data);	priv->rx_dmatsk = bcom_fec_rx_init(FEC_RX_NUM_BD, rx_fifo, FEC_RX_BUFFER_SIZE);	priv->tx_dmatsk = bcom_fec_tx_init(FEC_TX_NUM_BD, tx_fifo);	if (!priv->rx_dmatsk || !priv->tx_dmatsk) {		printk(KERN_ERR DRIVER_NAME ": Can not init SDMA tasks\n" );		rv = -ENOMEM;		goto probe_error;	}	/* Get the IRQ we need one by one */		/* Control */	ndev->irq = irq_of_parse_and_map(op->node, 0);		/* RX */	priv->r_irq = bcom_get_task_irq(priv->rx_dmatsk);		/* TX */	priv->t_irq = bcom_get_task_irq(priv->tx_dmatsk);	/* MAC address init */	if (!is_zero_ether_addr(mpc52xx_fec_mac_addr))		memcpy(ndev->dev_addr, mpc52xx_fec_mac_addr, 6);	else		mpc52xx_fec_get_paddr(ndev, ndev->dev_addr);	priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT);	priv->duplex = DUPLEX_FULL;	/* is the phy present in device tree? */	ph = of_get_property(op->node, "phy-handle", NULL);	if (ph) {		const unsigned int *prop;		struct device_node *phy_dn;		priv->has_phy = 1;		phy_dn = of_find_node_by_phandle(*ph);		prop = of_get_property(phy_dn, "reg", NULL);		priv->phy_addr = *prop;		of_node_put(phy_dn);		/* Phy speed */		priv->phy_speed = ((mpc52xx_find_ipb_freq(op->node) >> 20) / 5) << 1;	} else {		dev_info(&ndev->dev, "can't find \"phy-handle\" in device"				" tree, using 7-wire mode\n");	}	/* Hardware init */	mpc52xx_fec_hw_init(ndev);	mpc52xx_fec_reset_stats(ndev);	SET_NETDEV_DEV(ndev, &op->dev);	/* Register the new network device */	rv = register_netdev(ndev);	if (rv < 0)		goto probe_error;	/* We're done ! */	dev_set_drvdata(&op->dev, ndev);	return 0;	/* Error handling - free everything that might be allocated */probe_error:	irq_dispose_mapping(ndev->irq);	if (priv->rx_dmatsk)		bcom_fec_rx_release(priv->rx_dmatsk);	if (priv->tx_dmatsk)		bcom_fec_tx_release(priv->tx_dmatsk);	if (priv->fec)		iounmap(priv->fec);	release_mem_region(mem.start, sizeof(struct mpc52xx_fec));	free_netdev(ndev);	return rv;}static intmpc52xx_fec_remove(struct of_device *op){	struct net_device *ndev;	struct mpc52xx_fec_priv *priv;	ndev = dev_get_drvdata(&op->dev);	priv = netdev_priv(ndev);	unregister_netdev(ndev);	irq_dispose_mapping(ndev->irq);	bcom_fec_rx_release(priv->rx_dmatsk);	bcom_fec_tx_release(priv->tx_dmatsk);	iounmap(priv->fec);	release_mem_region(ndev->base_addr, sizeof(struct mpc52xx_fec));	free_netdev(ndev);	dev_set_drvdata(&op->dev, NULL);	return 0;}#ifdef CONFIG_PMstatic int mpc52xx_fec_of_suspend(struct of_device *op, pm_message_t state){	struct net_device *dev = dev_get_drvdata(&op->dev);	if (netif_running(dev))		mpc52xx_fec_close(dev);	return 0;}static int mpc52xx_fec_of_resume(struct of_device *op){	struct net_device *dev = dev_get_drvdata(&op->dev);	mpc52xx_fec_hw_init(dev);	mpc52xx_fec_reset_stats(dev);	if (netif_running(dev))		mpc52xx_fec_open(dev);	return 0;}#endifstatic struct of_device_id mpc52xx_fec_match[] = {	{		.type		= "network",		.compatible	= "mpc5200-fec",	},	{ }};MODULE_DEVICE_TABLE(of, mpc52xx_fec_match);static struct of_platform_driver mpc52xx_fec_driver = {	.owner		= THIS_MODULE,	.name		= DRIVER_NAME,	.match_table	= mpc52xx_fec_match,	.probe		= mpc52xx_fec_probe,	.remove		= mpc52xx_fec_remove,#ifdef CONFIG_PM	.suspend	= mpc52xx_fec_of_suspend,	.resume		= mpc52xx_fec_of_resume,#endif};/* ======================================================================== *//* Module                                                                   *//* ======================================================================== */static int __initmpc52xx_fec_init(void){#ifdef CONFIG_FEC_MPC52xx_MDIO	int ret;	ret = of_register_platform_driver(&mpc52xx_fec_mdio_driver);	if (ret) {		printk(KERN_ERR DRIVER_NAME ": failed to register mdio driver\n");		return ret;	}#endif	return of_register_platform_driver(&mpc52xx_fec_driver);}static void __exitmpc52xx_fec_exit(void){	of_unregister_platform_driver(&mpc52xx_fec_driver);#ifdef CONFIG_FEC_MPC52xx_MDIO	of_unregister_platform_driver(&mpc52xx_fec_mdio_driver);#endif}module_init(mpc52xx_fec_init);module_exit(mpc52xx_fec_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("Dale Farnsworth");MODULE_DESCRIPTION("Ethernet driver for the Freescale MPC52xx FEC");

⌨️ 快捷键说明

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