tah.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * drivers/net/ibm_newemac/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 <asm/io.h>
  22. #include "emac.h"
  23. #include "core.h"
  24. int __devinit tah_attach(struct platform_device *ofdev, int channel)
  25. {
  26. struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
  27. mutex_lock(&dev->lock);
  28. /* Reset has been done at probe() time... nothing else to do for now */
  29. ++dev->users;
  30. mutex_unlock(&dev->lock);
  31. return 0;
  32. }
  33. void tah_detach(struct platform_device *ofdev, int channel)
  34. {
  35. struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
  36. mutex_lock(&dev->lock);
  37. --dev->users;
  38. mutex_unlock(&dev->lock);
  39. }
  40. void tah_reset(struct platform_device *ofdev)
  41. {
  42. struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
  43. struct tah_regs __iomem *p = dev->base;
  44. int n;
  45. /* Reset TAH */
  46. out_be32(&p->mr, TAH_MR_SR);
  47. n = 100;
  48. while ((in_be32(&p->mr) & TAH_MR_SR) && n)
  49. --n;
  50. if (unlikely(!n))
  51. printk(KERN_ERR "%s: reset timeout\n",
  52. ofdev->dev.of_node->full_name);
  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 = dev_get_drvdata(&ofdev->dev);
  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 __devinit 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. printk(KERN_ERR "%s: could not allocate TAH device!\n",
  86. np->full_name);
  87. goto err_gone;
  88. }
  89. mutex_init(&dev->lock);
  90. dev->ofdev = ofdev;
  91. rc = -ENXIO;
  92. if (of_address_to_resource(np, 0, &regs)) {
  93. printk(KERN_ERR "%s: Can't get registers address\n",
  94. np->full_name);
  95. goto err_free;
  96. }
  97. rc = -ENOMEM;
  98. dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
  99. sizeof(struct tah_regs));
  100. if (dev->base == NULL) {
  101. printk(KERN_ERR "%s: Can't map device registers!\n",
  102. np->full_name);
  103. goto err_free;
  104. }
  105. dev_set_drvdata(&ofdev->dev, dev);
  106. /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
  107. tah_reset(ofdev);
  108. printk(KERN_INFO
  109. "TAH %s initialized\n", ofdev->dev.of_node->full_name);
  110. wmb();
  111. return 0;
  112. err_free:
  113. kfree(dev);
  114. err_gone:
  115. return rc;
  116. }
  117. static int __devexit tah_remove(struct platform_device *ofdev)
  118. {
  119. struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
  120. dev_set_drvdata(&ofdev->dev, NULL);
  121. WARN_ON(dev->users != 0);
  122. iounmap(dev->base);
  123. kfree(dev);
  124. return 0;
  125. }
  126. static struct of_device_id tah_match[] =
  127. {
  128. {
  129. .compatible = "ibm,tah",
  130. },
  131. /* For backward compat with old DT */
  132. {
  133. .type = "tah",
  134. },
  135. {},
  136. };
  137. static struct platform_driver tah_driver = {
  138. .driver = {
  139. .name = "emac-tah",
  140. .owner = THIS_MODULE,
  141. .of_match_table = tah_match,
  142. },
  143. .probe = tah_probe,
  144. .remove = tah_remove,
  145. };
  146. int __init tah_init(void)
  147. {
  148. return platform_driver_register(&tah_driver);
  149. }
  150. void tah_exit(void)
  151. {
  152. platform_driver_unregister(&tah_driver);
  153. }