sni_82596.c 4.7 KB

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