tah.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 "%s: reset timeout\n",
  53. ofdev->dev.of_node->full_name);
  54. /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
  55. out_be32(&p->mr,
  56. TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
  57. TAH_MR_DIG);
  58. }
  59. int tah_get_regs_len(struct platform_device *ofdev)
  60. {
  61. return sizeof(struct emac_ethtool_regs_subhdr) +
  62. sizeof(struct tah_regs);
  63. }
  64. void *tah_dump_regs(struct platform_device *ofdev, void *buf)
  65. {
  66. struct tah_instance *dev = platform_get_drvdata(ofdev);
  67. struct emac_ethtool_regs_subhdr *hdr = buf;
  68. struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
  69. hdr->version = 0;
  70. hdr->index = 0; /* for now, are there chips with more than one
  71. * zmii ? if yes, then we'll add a cell_index
  72. * like we do for emac
  73. */
  74. memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
  75. return regs + 1;
  76. }
  77. static int tah_probe(struct platform_device *ofdev)
  78. {
  79. struct device_node *np = ofdev->dev.of_node;
  80. struct tah_instance *dev;
  81. struct resource regs;
  82. int rc;
  83. rc = -ENOMEM;
  84. dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
  85. if (dev == NULL)
  86. goto err_gone;
  87. mutex_init(&dev->lock);
  88. dev->ofdev = ofdev;
  89. rc = -ENXIO;
  90. if (of_address_to_resource(np, 0, &regs)) {
  91. printk(KERN_ERR "%s: Can't get registers address\n",
  92. np->full_name);
  93. goto err_free;
  94. }
  95. rc = -ENOMEM;
  96. dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
  97. sizeof(struct tah_regs));
  98. if (dev->base == NULL) {
  99. printk(KERN_ERR "%s: Can't map device registers!\n",
  100. np->full_name);
  101. goto err_free;
  102. }
  103. platform_set_drvdata(ofdev, dev);
  104. /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
  105. tah_reset(ofdev);
  106. printk(KERN_INFO
  107. "TAH %s initialized\n", ofdev->dev.of_node->full_name);
  108. wmb();
  109. return 0;
  110. err_free:
  111. kfree(dev);
  112. err_gone:
  113. return rc;
  114. }
  115. static int tah_remove(struct platform_device *ofdev)
  116. {
  117. struct tah_instance *dev = platform_get_drvdata(ofdev);
  118. WARN_ON(dev->users != 0);
  119. iounmap(dev->base);
  120. kfree(dev);
  121. return 0;
  122. }
  123. static const struct of_device_id tah_match[] =
  124. {
  125. {
  126. .compatible = "ibm,tah",
  127. },
  128. /* For backward compat with old DT */
  129. {
  130. .type = "tah",
  131. },
  132. {},
  133. };
  134. static struct platform_driver tah_driver = {
  135. .driver = {
  136. .name = "emac-tah",
  137. .of_match_table = tah_match,
  138. },
  139. .probe = tah_probe,
  140. .remove = tah_remove,
  141. };
  142. int __init tah_init(void)
  143. {
  144. return platform_driver_register(&tah_driver);
  145. }
  146. void tah_exit(void)
  147. {
  148. platform_driver_unregister(&tah_driver);
  149. }