sni_82596.c 4.6 KB

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