ibm_emac_tah.c 2.8 KB

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