ibm_emac_tah.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * drivers/net/ibm_emac/ibm_emac_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 <linux/config.h>
  17. #include <asm/io.h>
  18. #include "ibm_emac_core.h"
  19. static int __init tah_init(struct ocp_device *ocpdev)
  20. {
  21. struct tah_regs *p;
  22. if (ocp_get_drvdata(ocpdev)) {
  23. printk(KERN_ERR "tah%d: already in use!\n", ocpdev->def->index);
  24. return -EBUSY;
  25. }
  26. /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
  27. p = (struct tah_regs *)ioremap(ocpdev->def->paddr, sizeof(*p));
  28. if (!p) {
  29. printk(KERN_ERR "tah%d: could not ioremap device registers!\n",
  30. ocpdev->def->index);
  31. return -ENOMEM;
  32. }
  33. ocp_set_drvdata(ocpdev, p);
  34. __tah_reset(ocpdev);
  35. return 0;
  36. }
  37. int __init tah_attach(void *emac)
  38. {
  39. struct ocp_enet_private *dev = emac;
  40. struct ocp_func_emac_data *emacdata = dev->def->additions;
  41. /* Check if we need to attach to a TAH */
  42. if (emacdata->tah_idx >= 0) {
  43. dev->tah_dev = ocp_find_device(OCP_ANY_ID, OCP_FUNC_TAH,
  44. emacdata->tah_idx);
  45. if (!dev->tah_dev) {
  46. printk(KERN_ERR "emac%d: unknown tah%d!\n",
  47. dev->def->index, emacdata->tah_idx);
  48. return -ENODEV;
  49. }
  50. if (tah_init(dev->tah_dev)) {
  51. printk(KERN_ERR
  52. "emac%d: tah%d initialization failed!\n",
  53. dev->def->index, emacdata->tah_idx);
  54. return -ENODEV;
  55. }
  56. }
  57. return 0;
  58. }
  59. void __exit __tah_fini(struct ocp_device *ocpdev)
  60. {
  61. struct tah_regs *p = ocp_get_drvdata(ocpdev);
  62. BUG_ON(!p);
  63. ocp_set_drvdata(ocpdev, NULL);
  64. iounmap((void *)p);
  65. }
  66. void __tah_reset(struct ocp_device *ocpdev)
  67. {
  68. struct tah_regs *p = ocp_get_drvdata(ocpdev);
  69. int n;
  70. /* Reset TAH */
  71. out_be32(&p->mr, TAH_MR_SR);
  72. n = 100;
  73. while ((in_be32(&p->mr) & TAH_MR_SR) && n)
  74. --n;
  75. if (unlikely(!n))
  76. printk(KERN_ERR "tah%d: reset timeout\n", ocpdev->def->index);
  77. /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */
  78. out_be32(&p->mr,
  79. TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
  80. TAH_MR_DIG);
  81. }
  82. int __tah_get_regs_len(struct ocp_device *ocpdev)
  83. {
  84. return sizeof(struct emac_ethtool_regs_subhdr) +
  85. sizeof(struct tah_regs);
  86. }
  87. void *tah_dump_regs(struct ocp_device *ocpdev, void *buf)
  88. {
  89. struct tah_regs *dev = ocp_get_drvdata(ocpdev);
  90. struct emac_ethtool_regs_subhdr *hdr = buf;
  91. struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
  92. hdr->version = 0;
  93. hdr->index = ocpdev->def->index;
  94. memcpy_fromio(regs, dev, sizeof(struct tah_regs));
  95. return regs + 1;
  96. }