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