tah.c 3.8 KB

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