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