1/* 2 * sni_82596.c -- driver for intel 82596 ethernet controller, as 3 * used in older SNI RM machines 4 */ 5 6#include <linux/module.h> 7#include <linux/kernel.h> 8#include <linux/string.h> 9#include <linux/errno.h> 10#include <linux/ioport.h> 11#include <linux/interrupt.h> 12#include <linux/delay.h> 13#include <linux/netdevice.h> 14#include <linux/etherdevice.h> 15#include <linux/skbuff.h> 16#include <linux/init.h> 17#include <linux/types.h> 18#include <linux/bitops.h> 19#include <linux/platform_device.h> 20#include <linux/io.h> 21#include <linux/irq.h> 22 23#define SNI_82596_DRIVER_VERSION "SNI RM 82596 driver - Revision: 0.01" 24 25static const char sni_82596_string[] = "snirm_82596"; 26 27#define DMA_ALLOC dma_alloc_coherent 28#define DMA_FREE dma_free_coherent 29#define DMA_WBACK(priv, addr, len) do { } while (0) 30#define DMA_INV(priv, addr, len) do { } while (0) 31#define DMA_WBACK_INV(priv, addr, len) do { } while (0) 32 33#define SYSBUS 0x00004400 34 35/* big endian CPU, 82596 little endian */ 36#define SWAP32(x) cpu_to_le32((u32)(x)) 37#define SWAP16(x) cpu_to_le16((u16)(x)) 38 39#define OPT_MPU_16BIT 0x01 40 41#include "lib82596.c" 42 43MODULE_AUTHOR("Thomas Bogendoerfer"); 44MODULE_DESCRIPTION("i82596 driver"); 45MODULE_LICENSE("GPL"); 46MODULE_ALIAS("platform:snirm_82596"); 47module_param(i596_debug, int, 0); 48MODULE_PARM_DESC(i596_debug, "82596 debug mask"); 49 50static inline void ca(struct net_device *dev) 51{ 52 struct i596_private *lp = netdev_priv(dev); 53 54 writel(0, lp->ca); 55} 56 57 58static void mpu_port(struct net_device *dev, int c, dma_addr_t x) 59{ 60 struct i596_private *lp = netdev_priv(dev); 61 62 u32 v = (u32) (c) | (u32) (x); 63 64 if (lp->options & OPT_MPU_16BIT) { 65 writew(v & 0xffff, lp->mpu_port); 66 wmb(); /* order writes to MPU port */ 67 udelay(1); 68 writew(v >> 16, lp->mpu_port); 69 } else { 70 writel(v, lp->mpu_port); 71 wmb(); /* order writes to MPU port */ 72 udelay(1); 73 writel(v, lp->mpu_port); 74 } 75} 76 77 78static int __devinit sni_82596_probe(struct platform_device *dev) 79{ 80 struct net_device *netdevice; 81 struct i596_private *lp; 82 struct resource *res, *ca, *idprom, *options; 83 int retval = -ENOMEM; 84 void __iomem *mpu_addr; 85 void __iomem *ca_addr; 86 u8 __iomem *eth_addr; 87 88 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 89 ca = platform_get_resource(dev, IORESOURCE_MEM, 1); 90 options = platform_get_resource(dev, 0, 0); 91 idprom = platform_get_resource(dev, IORESOURCE_MEM, 2); 92 if (!res || !ca || !options || !idprom) 93 return -ENODEV; 94 mpu_addr = ioremap_nocache(res->start, 4); 95 if (!mpu_addr) 96 return -ENOMEM; 97 ca_addr = ioremap_nocache(ca->start, 4); 98 if (!ca_addr) 99 goto probe_failed_free_mpu; 100 101 printk(KERN_INFO "Found i82596 at 0x%x\n", res->start); 102 103 netdevice = alloc_etherdev(sizeof(struct i596_private)); 104 if (!netdevice) 105 goto probe_failed_free_ca; 106 107 SET_NETDEV_DEV(netdevice, &dev->dev); 108 platform_set_drvdata (dev, netdevice); 109 110 netdevice->base_addr = res->start; 111 netdevice->irq = platform_get_irq(dev, 0); 112 113 eth_addr = ioremap_nocache(idprom->start, 0x10); 114 if (!eth_addr) 115 goto probe_failed; 116 117 /* someone seems to like messed up stuff */ 118 netdevice->dev_addr[0] = readb(eth_addr + 0x0b); 119 netdevice->dev_addr[1] = readb(eth_addr + 0x0a); 120 netdevice->dev_addr[2] = readb(eth_addr + 0x09); 121 netdevice->dev_addr[3] = readb(eth_addr + 0x08); 122 netdevice->dev_addr[4] = readb(eth_addr + 0x07); 123 netdevice->dev_addr[5] = readb(eth_addr + 0x06); 124 iounmap(eth_addr); 125 126 if (!netdevice->irq) { 127 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n", 128 __FILE__, netdevice->base_addr); 129 goto probe_failed; 130 } 131 132 lp = netdev_priv(netdevice); 133 lp->options = options->flags & IORESOURCE_BITS; 134 lp->ca = ca_addr; 135 lp->mpu_port = mpu_addr; 136 137 retval = i82596_probe(netdevice); 138 if (retval == 0) 139 return 0; 140 141probe_failed: 142 free_netdev(netdevice); 143probe_failed_free_ca: 144 iounmap(ca_addr); 145probe_failed_free_mpu: 146 iounmap(mpu_addr); 147 return retval; 148} 149 150static int __devexit sni_82596_driver_remove(struct platform_device *pdev) 151{ 152 struct net_device *dev = platform_get_drvdata(pdev); 153 struct i596_private *lp = netdev_priv(dev); 154 155 unregister_netdev(dev); 156 DMA_FREE(dev->dev.parent, sizeof(struct i596_private), 157 lp->dma, lp->dma_addr); 158 iounmap(lp->ca); 159 iounmap(lp->mpu_port); 160 free_netdev (dev); 161 return 0; 162} 163 164static struct platform_driver sni_82596_driver = { 165 .probe = sni_82596_probe, 166 .remove = __devexit_p(sni_82596_driver_remove), 167 .driver = { 168 .name = sni_82596_string, 169 .owner = THIS_MODULE, 170 }, 171}; 172 173static int __devinit sni_82596_init(void) 174{ 175 printk(KERN_INFO SNI_82596_DRIVER_VERSION "\n"); 176 return platform_driver_register(&sni_82596_driver); 177} 178 179 180static void __exit sni_82596_exit(void) 181{ 182 platform_driver_unregister(&sni_82596_driver); 183} 184 185module_init(sni_82596_init); 186module_exit(sni_82596_exit); 187