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 1970-01-01 00:00:00.000000000 +0000
33 +++ linux-2.6.30.8/drivers/net/ifxmips_mii0.c 2009-10-19 21:41:10.000000000 +0200
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/ip.h>
64 +#include <linux/tcp.h>
65 +#include <linux/skbuff.h>
66 +#include <linux/mm.h>
67 +#include <linux/platform_device.h>
68 +#include <linux/ethtool.h>
69 +#include <linux/init.h>
70 +#include <linux/delay.h>
72 +#include <asm/checksum.h>
75 +#include <ifxmips_dma.h>
76 +#include <ifxmips_pmu.h>
78 +struct ifxmips_mii_priv {
79 + struct net_device_stats stats;
80 + struct dma_device_info *dma_device;
81 + struct sk_buff *skb;
84 +static struct net_device *ifxmips_mii0_dev;
85 +static unsigned char mac_addr[MAX_ADDR_LEN];
87 +void ifxmips_write_mdio(u32 phy_addr, u32 phy_reg, u16 phy_data)
89 + u32 val = MDIO_ACC_REQUEST |
90 + ((phy_addr & MDIO_ACC_ADDR_MASK) << MDIO_ACC_ADDR_OFFSET) |
91 + ((phy_reg & MDIO_ACC_REG_MASK) << MDIO_ACC_REG_OFFSET) |
94 + while (ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST)
96 + ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC);
98 +EXPORT_SYMBOL(ifxmips_write_mdio);
100 +unsigned short ifxmips_read_mdio(u32 phy_addr, u32 phy_reg)
102 + u32 val = MDIO_ACC_REQUEST | MDIO_ACC_READ |
103 + ((phy_addr & MDIO_ACC_ADDR_MASK) << MDIO_ACC_ADDR_OFFSET) |
104 + ((phy_reg & MDIO_ACC_REG_MASK) << MDIO_ACC_REG_OFFSET);
106 + while (ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST)
108 + ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC);
109 + while (ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST)
111 + val = ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_VAL_MASK;
114 +EXPORT_SYMBOL(ifxmips_read_mdio);
116 +int ifxmips_ifxmips_mii_open(struct net_device *dev)
118 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
119 + struct dma_device_info *dma_dev = priv->dma_device;
122 + for (i = 0; i < dma_dev->max_rx_chan_num; i++) {
123 + if ((dma_dev->rx_chan[i])->control == IFXMIPS_DMA_CH_ON)
124 + (dma_dev->rx_chan[i])->open(dma_dev->rx_chan[i]);
126 + netif_start_queue(dev);
130 +int ifxmips_mii_release(struct net_device *dev)
132 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
133 + struct dma_device_info *dma_dev = priv->dma_device;
136 + for (i = 0; i < dma_dev->max_rx_chan_num; i++)
137 + dma_dev->rx_chan[i]->close(dma_dev->rx_chan[i]);
138 + netif_stop_queue(dev);
142 +int ifxmips_mii_hw_receive(struct net_device *dev, struct dma_device_info *dma_dev)
144 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
145 + unsigned char *buf = NULL;
146 + struct sk_buff *skb = NULL;
149 + len = dma_device_read(dma_dev, &buf, (void **)&skb);
151 + if (len >= ETHERNET_PACKET_DMA_BUFFER_SIZE) {
152 + printk(KERN_INFO "ifxmips_mii0: packet too large %d\n", len);
153 + goto ifxmips_mii_hw_receive_err_exit;
159 + printk(KERN_INFO "ifxmips_mii0: cannot restore pointer\n");
160 + goto ifxmips_mii_hw_receive_err_exit;
163 + if (len > (skb->end - skb->tail)) {
164 + printk(KERN_INFO "ifxmips_mii0: BUG, len:%d end:%p tail:%p\n",
165 + (len+4), skb->end, skb->tail);
166 + goto ifxmips_mii_hw_receive_err_exit;
171 + skb->protocol = eth_type_trans(skb, dev);
174 + priv->stats.rx_packets++;
175 + priv->stats.rx_bytes += len;
178 +ifxmips_mii_hw_receive_err_exit:
181 + dev_kfree_skb_any(skb);
182 + priv->stats.rx_errors++;
183 + priv->stats.rx_dropped++;
190 +int ifxmips_mii_hw_tx(char *buf, int len, struct net_device *dev)
193 + struct ifxmips_mii_priv *priv = netdev_priv(dev);
194 + struct dma_device_info *dma_dev = priv->dma_device;
195 + ret = dma_device_write(dma_dev, buf, len, priv->skb);
199 +int ifxmips_mii_tx(struct sk_buff *skb, struct net_device *dev)
203 + struct ifxmips_mii_priv *priv = netdev_priv(dev);
204 + struct dma_device_info *dma_dev = priv->dma_device;
206 + len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
209 + dev->trans_start = jiffies;
210 + /* TODO: we got more than 1 dma channel,
211 + so we should do something intelligent here to select one */
212 + dma_dev->current_tx_chan = 0;
216 + if (ifxmips_mii_hw_tx(data, len, dev) != len) {
217 + dev_kfree_skb_any(skb);
218 + priv->stats.tx_errors++;
219 + priv->stats.tx_dropped++;
221 + priv->stats.tx_packets++;
222 + priv->stats.tx_bytes += len;
228 +void ifxmips_mii_tx_timeout(struct net_device *dev)
231 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
233 + priv->stats.tx_errors++;
234 + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++)
235 + priv->dma_device->tx_chan[i]->disable_irq(priv->dma_device->tx_chan[i]);
236 + netif_wake_queue(dev);
240 +int dma_intr_handler(struct dma_device_info *dma_dev, int status)
246 + ifxmips_mii_hw_receive(ifxmips_mii0_dev, dma_dev);
249 + case TX_BUF_FULL_INT:
250 + printk(KERN_INFO "ifxmips_mii0: tx buffer full\n");
251 + netif_stop_queue(ifxmips_mii0_dev);
252 + for (i = 0; i < dma_dev->max_tx_chan_num; i++) {
253 + if ((dma_dev->tx_chan[i])->control == IFXMIPS_DMA_CH_ON)
254 + dma_dev->tx_chan[i]->enable_irq(dma_dev->tx_chan[i]);
258 + case TRANSMIT_CPT_INT:
259 + for (i = 0; i < dma_dev->max_tx_chan_num; i++)
260 + dma_dev->tx_chan[i]->disable_irq(dma_dev->tx_chan[i]);
262 + netif_wake_queue(ifxmips_mii0_dev);
269 +unsigned char *ifxmips_etop_dma_buffer_alloc(int len, int *byte_offset, void **opt)
271 + unsigned char *buffer = NULL;
272 + struct sk_buff *skb = NULL;
274 + skb = dev_alloc_skb(ETHERNET_PACKET_DMA_BUFFER_SIZE);
278 + buffer = (unsigned char *)(skb->data);
279 + skb_reserve(skb, 2);
280 + *(int *)opt = (int)skb;
286 +void ifxmips_etop_dma_buffer_free(unsigned char *dataptr, void *opt)
288 + struct sk_buff *skb = NULL;
293 + skb = (struct sk_buff *)opt;
294 + dev_kfree_skb_any(skb);
298 +static struct net_device_stats *ifxmips_get_stats(struct net_device *dev)
300 + return &((struct ifxmips_mii_priv *)netdev_priv(dev))->stats;
303 +static int ifxmips_mii_dev_init(struct net_device *dev)
306 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(dev);
308 + printk(KERN_INFO "ifxmips_mii0: %s is up\n", dev->name);
309 + dev->open = ifxmips_ifxmips_mii_open;
310 + dev->stop = ifxmips_mii_release;
311 + dev->hard_start_xmit = ifxmips_mii_tx;
312 + dev->get_stats = ifxmips_get_stats;
313 + dev->tx_timeout = ifxmips_mii_tx_timeout;
314 + dev->watchdog_timeo = 10 * HZ;
315 + memset(priv, 0, sizeof(struct ifxmips_mii_priv));
316 + priv->dma_device = dma_device_reserve("PPE");
317 + if (!priv->dma_device) {
321 + priv->dma_device->buffer_alloc = &ifxmips_etop_dma_buffer_alloc;
322 + priv->dma_device->buffer_free = &ifxmips_etop_dma_buffer_free;
323 + priv->dma_device->intr_handler = &dma_intr_handler;
324 + priv->dma_device->max_rx_chan_num = 4;
326 + for (i = 0; i < priv->dma_device->max_rx_chan_num; i++) {
327 + priv->dma_device->rx_chan[i]->packet_size = ETHERNET_PACKET_DMA_BUFFER_SIZE;
328 + priv->dma_device->rx_chan[i]->control = IFXMIPS_DMA_CH_ON;
331 + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++)
333 + priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_ON;
335 + priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_OFF;
337 + dma_device_register(priv->dma_device);
339 + printk(KERN_INFO "ifxmips_mii0: using mac=");
340 + for (i = 0; i < 6; i++) {
341 + dev->dev_addr[i] = mac_addr[i];
342 + printk("%02X%c", dev->dev_addr[i], (i == 5) ? ('\n') : (':'));
347 +static void ifxmips_mii_chip_init(int mode)
349 + ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_DMA);
350 + ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_PPE);
352 + if (mode == REV_MII_MODE)
353 + ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_REVERSE, IFXMIPS_PPE32_CFG);
354 + else if (mode == MII_MODE)
355 + ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_NORMAL, IFXMIPS_PPE32_CFG);
356 + ifxmips_w32(PPE32_PLEN_UNDER | PPE32_PLEN_OVER, IFXMIPS_PPE32_IG_PLEN_CTRL);
357 + ifxmips_w32(PPE32_CGEN, IFXMIPS_PPE32_ENET_MAC_CFG);
361 +static int ifxmips_mii_probe(struct platform_device *dev)
364 + unsigned char *mac = (unsigned char *)dev->dev.platform_data;
365 + ifxmips_mii0_dev = alloc_etherdev(sizeof(struct ifxmips_mii_priv));
366 + ifxmips_mii0_dev->init = ifxmips_mii_dev_init;
367 + memcpy(mac_addr, mac, 6);
368 + strcpy(ifxmips_mii0_dev->name, "eth%d");
369 + ifxmips_mii_chip_init(REV_MII_MODE);
370 + result = register_netdev(ifxmips_mii0_dev);
372 + printk(KERN_INFO "ifxmips_mii0: error %i registering device \"%s\"\n", result, ifxmips_mii0_dev->name);
376 + printk(KERN_INFO "ifxmips_mii0: driver loaded!\n");
382 +static int ifxmips_mii_remove(struct platform_device *dev)
384 + struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv *)netdev_priv(ifxmips_mii0_dev);
386 + printk(KERN_INFO "ifxmips_mii0: ifxmips_mii0 cleanup\n");
388 + dma_device_unregister(priv->dma_device);
389 + dma_device_release(priv->dma_device);
390 + kfree(priv->dma_device);
391 + unregister_netdev(ifxmips_mii0_dev);
395 +static struct platform_driver ifxmips_mii_driver = {
396 + .probe = ifxmips_mii_probe,
397 + .remove = ifxmips_mii_remove,
399 + .name = "ifxmips_mii0",
400 + .owner = THIS_MODULE,
404 +int __init ifxmips_mii_init(void)
406 + int ret = platform_driver_register(&ifxmips_mii_driver);
408 + printk(KERN_INFO "ifxmips_mii0: Error registering platfom driver!");
412 +static void __exit ifxmips_mii_cleanup(void)
414 + platform_driver_unregister(&ifxmips_mii_driver);
417 +module_init(ifxmips_mii_init);
418 +module_exit(ifxmips_mii_cleanup);
420 +MODULE_LICENSE("GPL");
421 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
422 +MODULE_DESCRIPTION("ethernet driver for IFXMIPS boards");