sni_82596.c 4.6 KB

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