1 Index: linux-2.6.30.8/drivers/net/Kconfig
2 ===================================================================
3 --- linux-2.6.30.8.orig/drivers/net/Kconfig 2009-10-19 21:31:30.000000000 +0200
4 +++ linux-2.6.30.8/drivers/net/Kconfig 2009-10-19 21:31:32.000000000 +0200
7 source "drivers/net/arm/Kconfig"
10 + tristate "Infineon IFXMips eth0 driver"
13 + Support for the MII0 inside the IFXMips SOC
16 tristate "ASIX AX88796 NE2000 clone support"
17 depends on ARM || MIPS || SUPERH
18 Index: linux-2.6.30.8/drivers/net/Makefile
19 ===================================================================
20 --- linux-2.6.30.8.orig/drivers/net/Makefile 2009-10-19 21:31:30.000000000 +0200
21 +++ linux-2.6.30.8/drivers/net/Makefile 2009-10-19 21:31:32.000000000 +0200
23 obj-$(CONFIG_MLX4_CORE) += mlx4/
24 obj-$(CONFIG_ENC28J60) += enc28j60.o
25 obj-$(CONFIG_ETHOC) += ethoc.o
26 +obj-$(CONFIG_IFXMIPS_MII0) += ifxmips_mii0.o
28 obj-$(CONFIG_XTENSA_XT2000_SONIC) += xtsonic.o
30 Index: linux-2.6.30.8/drivers/net/ifxmips_mii0.c
31 ===================================================================
32 --- /dev/null 2010-01-25 20:01:36.843225078 +0100
33 +++ linux-2.6.30.10/drivers/net/ifxmips_mii0.c 2010-03-13 19:04:25.000000000 +0100
36 + * This program is free software; you can redistribute it and/or modify
37 + * it under the terms of the GNU General Public License as published by
38 + * the Free Software Foundation; either version 2 of the License, or
39 + * (at your option) any later version.
41 + * This program is distributed in the hope that it will be useful,
42 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 + * GNU General Public License for more details.
46 + * You should have received a copy of the GNU General Public License
47 + * along with this program; if not, write to the Free Software
48 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
50 + * Copyright (C) 2005 Wu Qi Ming <Qi-Ming.Wu@infineon.com>
51 + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
54 +#include <linux/kernel.h>
55 +#include <linux/slab.h>
56 +#include <linux/errno.h>
57 +#include <linux/types.h>
58 +#include <linux/interrupt.h>
59 +#include <linux/uaccess.h>
60 +#include <linux/in.h>
61 +#include <linux/netdevice.h>
62 +#include <linux/etherdevice.h>
63 +#include <linux/phy.h>
64 +#include <linux/ip.h>
65 +#include <linux/tcp.h>
66 +#include <linux/skbuff.h>
67 +#include <linux/mm.h>
68 +#include <linux/platform_device.h>
69 +#include <linux/ethtool.h>
70 +#include <linux/init.h>
71 +#include <linux/delay.h>
73 +#include <asm/checksum.h>
76 +#include <ifxmips_dma.h>
77 +#include <ifxmips_pmu.h>
79 +struct ifxmips_mii_priv {
80 + struct net_device_stats stats;
81 + struct dma_device_info *dma_device;
82 + struct sk_buff *skb;
84 + struct mii_bus *mii_bus;
85 + struct phy_device *phydev;
86 + int oldlink, oldspeed, oldduplex;
89 +static struct net_device *ifxmips_mii0_dev;
90 +static unsigned char mac_addr[MAX_ADDR_LEN];
92 +static int ifxmips_mdiobus_write(struct mii_bus *bus, int phy_addr,
93 + int phy_reg, u16 phy_data)
95 + u32 val = MDIO_ACC_REQUEST |
96 + ((phy_addr & MDIO_ACC_ADDR_MASK) << MDIO_ACC_ADDR_OFFSET) |
97 + ((phy_reg & MDIO_ACC_REG_MASK) << MDIO_ACC_REG_OFFSET) |
100 + while (ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST)
102 + ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC);
107 +static int ifxmips_mdiobus_read(struct mii_bus *bus, int phy_addr, int phy_reg)
109 + u32 val = MDIO_ACC_REQUEST | MDIO_ACC_READ |
110 + ((phy_addr & MDIO_ACC_ADDR_MASK) << MDIO_ACC_ADDR_OFFSET) |
111 + ((phy_reg & MDIO_ACC_REG_MASK) << MDIO_ACC_REG_OFFSET);
113 + while (ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST)
115 + ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC);
116 + while (ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST)
118 + val = ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_VAL_MASK;
122 +int ifxmips_ifxmips_mii_open(struct net_device *dev)
124 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
125 + struct dma_device_info *dma_dev = priv->dma_device;
128 + for (i = 0; i < dma_dev->max_rx_chan_num; i++) {
129 + if ((dma_dev->rx_chan[i])->control == IFXMIPS_DMA_CH_ON)
130 + (dma_dev->rx_chan[i])->open(dma_dev->rx_chan[i]);
132 + netif_start_queue(dev);
136 +int ifxmips_mii_release(struct net_device *dev)
138 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
139 + struct dma_device_info *dma_dev = priv->dma_device;
142 + for (i = 0; i < dma_dev->max_rx_chan_num; i++)
143 + dma_dev->rx_chan[i]->close(dma_dev->rx_chan[i]);
144 + netif_stop_queue(dev);
148 +int ifxmips_mii_hw_receive(struct net_device *dev, struct dma_device_info *dma_dev)
150 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
151 + unsigned char *buf = NULL;
152 + struct sk_buff *skb = NULL;
155 + len = dma_device_read(dma_dev, &buf, (void **)&skb);
157 + if (len >= ETHERNET_PACKET_DMA_BUFFER_SIZE) {
158 + printk(KERN_INFO "ifxmips_mii0: packet too large %d\n", len);
159 + goto ifxmips_mii_hw_receive_err_exit;
165 + printk(KERN_INFO "ifxmips_mii0: cannot restore pointer\n");
166 + goto ifxmips_mii_hw_receive_err_exit;
169 + if (len > (skb->end - skb->tail)) {
170 + printk(KERN_INFO "ifxmips_mii0: BUG, len:%d end:%p tail:%p\n",
171 + (len+4), skb->end, skb->tail);
172 + goto ifxmips_mii_hw_receive_err_exit;
177 + skb->protocol = eth_type_trans(skb, dev);
180 + priv->stats.rx_packets++;
181 + priv->stats.rx_bytes += len;
184 +ifxmips_mii_hw_receive_err_exit:
187 + dev_kfree_skb_any(skb);
188 + priv->stats.rx_errors++;
189 + priv->stats.rx_dropped++;
196 +int ifxmips_mii_hw_tx(char *buf, int len, struct net_device *dev)
199 + struct ifxmips_mii_priv *priv = netdev_priv(dev);
200 + struct dma_device_info *dma_dev = priv->dma_device;
201 + ret = dma_device_write(dma_dev, buf, len, priv->skb);
205 +int ifxmips_mii_tx(struct sk_buff *skb, struct net_device *dev)
209 + struct ifxmips_mii_priv *priv = netdev_priv(dev);
210 + struct dma_device_info *dma_dev = priv->dma_device;
212 + len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
215 + dev->trans_start = jiffies;
216 + /* TODO: we got more than 1 dma channel,
217 + so we should do something intelligent here to select one */
218 + dma_dev->current_tx_chan = 0;
222 + if (ifxmips_mii_hw_tx(data, len, dev) != len) {
223 + dev_kfree_skb_any(skb);
224 + priv->stats.tx_errors++;
225 + priv->stats.tx_dropped++;
227 + priv->stats.tx_packets++;
228 + priv->stats.tx_bytes += len;
234 +void ifxmips_mii_tx_timeout(struct net_device *dev)
237 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
239 + priv->stats.tx_errors++;
240 + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++)
241 + priv->dma_device->tx_chan[i]->disable_irq(priv->dma_device->tx_chan[i]);
242 + netif_wake_queue(dev);
246 +int dma_intr_handler(struct dma_device_info *dma_dev, int status)
252 + ifxmips_mii_hw_receive(ifxmips_mii0_dev, dma_dev);
255 + case TX_BUF_FULL_INT:
256 + printk(KERN_INFO "ifxmips_mii0: tx buffer full\n");
257 + netif_stop_queue(ifxmips_mii0_dev);
258 + for (i = 0; i < dma_dev->max_tx_chan_num; i++) {
259 + if ((dma_dev->tx_chan[i])->control == IFXMIPS_DMA_CH_ON)
260 + dma_dev->tx_chan[i]->enable_irq(dma_dev->tx_chan[i]);
264 + case TRANSMIT_CPT_INT:
265 + for (i = 0; i < dma_dev->max_tx_chan_num; i++)
266 + dma_dev->tx_chan[i]->disable_irq(dma_dev->tx_chan[i]);
268 + netif_wake_queue(ifxmips_mii0_dev);
275 +unsigned char *ifxmips_etop_dma_buffer_alloc(int len, int *byte_offset, void **opt)
277 + unsigned char *buffer = NULL;
278 + struct sk_buff *skb = NULL;
280 + skb = dev_alloc_skb(ETHERNET_PACKET_DMA_BUFFER_SIZE);
284 + buffer = (unsigned char *)(skb->data);
285 + skb_reserve(skb, 2);
286 + *(int *)opt = (int)skb;
292 +void ifxmips_etop_dma_buffer_free(unsigned char *dataptr, void *opt)
294 + struct sk_buff *skb = NULL;
299 + skb = (struct sk_buff *)opt;
300 + dev_kfree_skb_any(skb);
304 +static struct net_device_stats *ifxmips_get_stats(struct net_device *dev)
306 + return &((struct ifxmips_mii_priv *)netdev_priv(dev))->stats;
310 +ifxmips_adjust_link(struct net_device *dev)
312 + struct ifxmips_mii_priv *priv = netdev_priv(dev);
313 + struct phy_device *phydev = priv->phydev;
316 + /* Did anything change? */
317 + if (priv->oldlink != phydev->link ||
318 + priv->oldduplex != phydev->duplex ||
319 + priv->oldspeed != phydev->speed) {
320 + /* Yes, so update status and mark as changed */
322 + priv->oldduplex = phydev->duplex;
323 + priv->oldspeed = phydev->speed;
324 + priv->oldlink = phydev->link;
327 + /* If link status changed, show new status */
329 + phy_print_status(phydev);
332 +static int mii_probe(struct net_device *dev)
334 + struct ifxmips_mii_priv *priv = netdev_priv(dev);
335 + struct phy_device *phydev = NULL;
339 + priv->oldspeed = 0;
340 + priv->oldduplex = -1;
342 + /* find the first (lowest address) PHY on the current MAC's MII bus */
343 + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
344 + if (priv->mii_bus->phy_map[phy_addr]) {
345 + phydev = priv->mii_bus->phy_map[phy_addr];
346 + break; /* break out with first one found */
351 + printk (KERN_ERR "%s: no PHY found\n", dev->name);
355 + /* now we are supposed to have a proper phydev, to attach to... */
357 + BUG_ON(phydev->attached_dev);
359 + phydev = phy_connect(dev, dev_name(&phydev->dev), &ifxmips_adjust_link,
360 + 0, PHY_INTERFACE_MODE_MII);
362 + if (IS_ERR(phydev)) {
363 + printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
364 + return PTR_ERR(phydev);
367 + /* mask with MAC supported features */
368 + phydev->supported &= (SUPPORTED_10baseT_Half
369 + | SUPPORTED_10baseT_Full
370 + | SUPPORTED_100baseT_Half
371 + | SUPPORTED_100baseT_Full
372 + | SUPPORTED_Autoneg
373 + /* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */
377 + phydev->advertising = phydev->supported;
379 + priv->phydev = phydev;
381 + printk(KERN_INFO "%s: attached PHY driver [%s] "
382 + "(mii_bus:phy_addr=%s, irq=%d)\n",
383 + dev->name, phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
389 +static int ifxmips_mii_dev_init(struct net_device *dev)
392 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
394 + dev->open = ifxmips_ifxmips_mii_open;
395 + dev->stop = ifxmips_mii_release;
396 + dev->hard_start_xmit = ifxmips_mii_tx;
397 + dev->get_stats = ifxmips_get_stats;
398 + dev->tx_timeout = ifxmips_mii_tx_timeout;
399 + dev->watchdog_timeo = 10 * HZ;
400 + memset(priv, 0, sizeof(struct ifxmips_mii_priv));
401 + priv->dma_device = dma_device_reserve("PPE");
402 + if (!priv->dma_device) {
406 + priv->dma_device->buffer_alloc = &ifxmips_etop_dma_buffer_alloc;
407 + priv->dma_device->buffer_free = &ifxmips_etop_dma_buffer_free;
408 + priv->dma_device->intr_handler = &dma_intr_handler;
409 + priv->dma_device->max_rx_chan_num = 4;
411 + for (i = 0; i < priv->dma_device->max_rx_chan_num; i++) {
412 + priv->dma_device->rx_chan[i]->packet_size = ETHERNET_PACKET_DMA_BUFFER_SIZE;
413 + priv->dma_device->rx_chan[i]->control = IFXMIPS_DMA_CH_ON;
416 + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++)
418 + priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_ON;
420 + priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_OFF;
422 + dma_device_register(priv->dma_device);
424 + printk(KERN_INFO "%s: using mac=", dev->name);
425 + for (i = 0; i < 6; i++) {
426 + dev->dev_addr[i] = mac_addr[i];
427 + printk("%02X%c", dev->dev_addr[i], (i == 5) ? ('\n') : (':'));
430 + priv->mii_bus = mdiobus_alloc();
431 + if (priv->mii_bus == NULL)
434 + priv->mii_bus->priv = dev;
435 + priv->mii_bus->read = ifxmips_mdiobus_read;
436 + priv->mii_bus->write = ifxmips_mdiobus_write;
437 + priv->mii_bus->name = "ifxmips_mii";
438 + snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%x", 0);
439 + priv->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
440 + for(i = 0; i < PHY_MAX_ADDR; ++i)
441 + priv->mii_bus->irq[i] = PHY_POLL;
443 + mdiobus_register(priv->mii_bus);
445 + return mii_probe(dev);
448 +static void ifxmips_mii_chip_init(int mode)
450 + ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_DMA);
451 + ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_PPE);
453 + if (mode == REV_MII_MODE)
454 + ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_REVERSE, IFXMIPS_PPE32_CFG);
455 + else if (mode == MII_MODE)
456 + ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_NORMAL, IFXMIPS_PPE32_CFG);
457 + ifxmips_w32(PPE32_PLEN_UNDER | PPE32_PLEN_OVER, IFXMIPS_PPE32_IG_PLEN_CTRL);
458 + ifxmips_w32(PPE32_CGEN, IFXMIPS_PPE32_ENET_MAC_CFG);
462 +static int ifxmips_mii_probe(struct platform_device *dev)
465 + unsigned char *mac = (unsigned char *)dev->dev.platform_data;
466 + ifxmips_mii0_dev = alloc_etherdev(sizeof(struct ifxmips_mii_priv));
467 + ifxmips_mii0_dev->init = ifxmips_mii_dev_init;
468 + memcpy(mac_addr, mac, 6);
469 + strcpy(ifxmips_mii0_dev->name, "eth%d");
470 + ifxmips_mii_chip_init(REV_MII_MODE);
471 + result = register_netdev(ifxmips_mii0_dev);
473 + printk(KERN_INFO "ifxmips_mii0: error %i registering device \"%s\"\n", result, ifxmips_mii0_dev->name);
477 + printk(KERN_INFO "ifxmips_mii0: driver loaded!\n");
483 +static int ifxmips_mii_remove(struct platform_device *dev)
485 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(ifxmips_mii0_dev);
487 + printk(KERN_INFO "ifxmips_mii0: ifxmips_mii0 cleanup\n");
489 + dma_device_unregister(priv->dma_device);
490 + dma_device_release(priv->dma_device);
491 + kfree(priv->dma_device);
492 + unregister_netdev(ifxmips_mii0_dev);
496 +static struct platform_driver ifxmips_mii_driver = {
497 + .probe = ifxmips_mii_probe,
498 + .remove = ifxmips_mii_remove,
500 + .name = "ifxmips_mii0",
501 + .owner = THIS_MODULE,
505 +int __init ifxmips_mii_init(void)
507 + int ret = platform_driver_register(&ifxmips_mii_driver);
509 + printk(KERN_INFO "ifxmips_mii0: Error registering platfom driver!");
513 +static void __exit ifxmips_mii_cleanup(void)
515 + platform_driver_unregister(&ifxmips_mii_driver);
518 +module_init(ifxmips_mii_init);
519 +module_exit(ifxmips_mii_cleanup);
521 +MODULE_LICENSE("GPL");
522 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
523 +MODULE_DESCRIPTION("ethernet driver for IFXMIPS boards");