tah.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * drivers/net/ethernet/ibm/emac/tah.c
  4. *
  5. * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
  6. *
  7. * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  8. * <[email protected]>
  9. *
  10. * Based on the arch/ppc version of the driver:
  11. *
  12. * Copyright 2004 MontaVista Software, Inc.
  13. * Matt Porter <[email protected]>
  14. *
  15. * Copyright (c) 2005 Eugene Surovegin <[email protected]>
  16. */
  17. #include <linux/of_address.h>
  18. #include <asm/io.h>
  19. #include "emac.h"
  20. #include "core.h"
  21. int tah_attach(struct platform_device *ofdev, int channel)
  22. {
  23. struct tah_instance *dev = platform_get_drvdata(ofdev);
  24. mutex_lock(&dev->lock);
  25. /* Reset has been done at probe() time... nothing else to do for now */
  26. ++dev->users;
  27. mutex_unlock(&dev->lock);
  28. return 0;
  29. }
  30. void tah_detach(struct platform_device *ofdev, int channel)
  31. {
  32. struct tah_instance *dev = platform_get_drvdata(ofdev);
  33. mutex_lock(&dev->lock);
  34. --dev->users;
  35. mutex_unlock(&dev->lock);
  36. }
  37. void tah_reset(struct platform_device *ofdev)
  38. {
  39. struct tah_instance *dev = platform_get_drvdata(ofdev);
  40. struct tah_regs __iomem *p = dev->base;
  41. int n;
  42. /* Reset TAH */
  43. out_be32(&p->mr, TAH_MR_SR);
  44. n = 100;
  45. while ((in_be32(&p->mr) & TAH_MR_SR) && n)
  46. --n;
  47. if (unlikely(!n))
  48. printk(KERN_ERR "%pOF: reset timeout\n", ofdev->dev.of_node);
  49. /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
  50. out_be32(&p->mr,
  51. TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
  52. TAH_MR_DIG);
  53. }
  54. int tah_get_regs_len(struct platform_device *ofdev)
  55. {
  56. return sizeof(struct emac_ethtool_regs_subhdr) +
  57. sizeof(struct tah_regs);
  58. }
  59. void *tah_dump_regs(struct platform_device *ofdev, void *buf)
  60. {
  61. struct tah_instance *dev = platform_get_drvdata(ofdev);
  62. struct emac_ethtool_regs_subhdr *hdr = buf;
  63. struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
  64. hdr->version = 0;
  65. hdr->index = 0; /* for now, are there chips with more than one
  66. * zmii ? if yes, then we'll add a cell_index
  67. * like we do for emac
  68. */
  69. memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
  70. return regs + 1;
  71. }
  72. static int tah_probe(struct platform_device *ofdev)
  73. {
  74. struct device_node *np = ofdev->dev.of_node;
  75. struct tah_instance *dev;
  76. struct resource regs;
  77. int rc;
  78. rc = -ENOMEM;
  79. dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
  80. if (dev == NULL)
  81. goto err_gone;
  82. mutex_init(&dev->lock);
  83. dev->ofdev = ofdev;
  84. rc = -ENXIO;
  85. if (of_address_to_resource(np, 0, &regs)) {
  86. printk(KERN_ERR "%pOF: Can't get registers address\n", np);
  87. goto err_free;
  88. }
  89. rc = -ENOMEM;
  90. dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
  91. sizeof(struct tah_regs));
  92. if (dev->base == NULL) {
  93. printk(KERN_ERR "%pOF: Can't map device registers!\n", np);
  94. goto err_free;
  95. }
  96. platform_set_drvdata(ofdev, dev);
  97. /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
  98. tah_reset(ofdev);
  99. printk(KERN_INFO "TAH %pOF initialized\n", ofdev->dev.of_node);
  100. wmb();
  101. return 0;
  102. err_free:
  103. kfree(dev);
  104. err_gone:
  105. return rc;
  106. }
  107. static int tah_remove(struct platform_device *ofdev)
  108. {
  109. struct tah_instance *dev = platform_get_drvdata(ofdev);
  110. WARN_ON(dev->users != 0);
  111. iounmap(dev->base);
  112. kfree(dev);
  113. return 0;
  114. }
  115. static const struct of_device_id tah_match[] =
  116. {
  117. {
  118. .compatible = "ibm,tah",
  119. },
  120. /* For backward compat with old DT */
  121. {
  122. .type = "tah",
  123. },
  124. {},
  125. };
  126. static struct platform_driver tah_driver = {
  127. .driver = {
  128. .name = "emac-tah",
  129. .of_match_table = tah_match,
  130. },
  131. .probe = tah_probe,
  132. .remove = tah_remove,
  133. };
  134. int __init tah_init(void)
  135. {
  136. return platform_driver_register(&tah_driver);
  137. }
  138. void tah_exit(void)
  139. {
  140. platform_driver_unregister(&tah_driver);
  141. }