tah.c 3.8 KB

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