tah.c 4.1 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 of_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 of_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 of_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 accomodates 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 of_device *ofdev)
  59. {
  60. return sizeof(struct emac_ethtool_regs_subhdr) +
  61. sizeof(struct tah_regs);
  62. }
  63. void *tah_dump_regs(struct of_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 of_device *ofdev,
  77. const struct of_device_id *match)
  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. printk(KERN_ERR "%s: could not allocate TAH device!\n",
  87. np->full_name);
  88. goto err_gone;
  89. }
  90. mutex_init(&dev->lock);
  91. dev->ofdev = ofdev;
  92. rc = -ENXIO;
  93. if (of_address_to_resource(np, 0, &regs)) {
  94. printk(KERN_ERR "%s: Can't get registers address\n",
  95. np->full_name);
  96. goto err_free;
  97. }
  98. rc = -ENOMEM;
  99. dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
  100. sizeof(struct tah_regs));
  101. if (dev->base == NULL) {
  102. printk(KERN_ERR "%s: Can't map device registers!\n",
  103. np->full_name);
  104. goto err_free;
  105. }
  106. dev_set_drvdata(&ofdev->dev, dev);
  107. /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
  108. tah_reset(ofdev);
  109. printk(KERN_INFO
  110. "TAH %s initialized\n", ofdev->dev.of_node->full_name);
  111. wmb();
  112. return 0;
  113. err_free:
  114. kfree(dev);
  115. err_gone:
  116. return rc;
  117. }
  118. static int __devexit tah_remove(struct of_device *ofdev)
  119. {
  120. struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
  121. dev_set_drvdata(&ofdev->dev, NULL);
  122. WARN_ON(dev->users != 0);
  123. iounmap(dev->base);
  124. kfree(dev);
  125. return 0;
  126. }
  127. static struct of_device_id tah_match[] =
  128. {
  129. {
  130. .compatible = "ibm,tah",
  131. },
  132. /* For backward compat with old DT */
  133. {
  134. .type = "tah",
  135. },
  136. {},
  137. };
  138. static struct of_platform_driver tah_driver = {
  139. .driver = {
  140. .name = "emac-tah",
  141. .owner = THIS_MODULE,
  142. .of_match_table = tah_match,
  143. },
  144. .probe = tah_probe,
  145. .remove = tah_remove,
  146. };
  147. int __init tah_init(void)
  148. {
  149. return of_register_platform_driver(&tah_driver);
  150. }
  151. void tah_exit(void)
  152. {
  153. of_unregister_platform_driver(&tah_driver);
  154. }