ibm_emac_phy.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * ibm_emac_phy.h
  3. *
  4. *
  5. * Benjamin Herrenschmidt <benh@kernel.crashing.org>
  6. * February 2003
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  16. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  19. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, write to the Free Software Foundation, Inc.,
  26. * 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. *
  29. * This file basically duplicates sungem_phy.{c,h} with different PHYs
  30. * supported. I'm looking into merging that in a single mii layer more
  31. * flexible than mii.c
  32. */
  33. #ifndef _IBM_EMAC_PHY_H_
  34. #define _IBM_EMAC_PHY_H_
  35. /*
  36. * PHY mode settings
  37. * Used for multi-mode capable PHYs
  38. */
  39. #define PHY_MODE_NA 0
  40. #define PHY_MODE_MII 1
  41. #define PHY_MODE_RMII 2
  42. #define PHY_MODE_SMII 3
  43. #define PHY_MODE_RGMII 4
  44. #define PHY_MODE_TBI 5
  45. #define PHY_MODE_GMII 6
  46. #define PHY_MODE_RTBI 7
  47. #define PHY_MODE_SGMII 8
  48. /*
  49. * PHY specific registers/values
  50. */
  51. /* CIS8201 */
  52. #define MII_CIS8201_EPCR 0x17
  53. #define EPCR_MODE_MASK 0x3000
  54. #define EPCR_GMII_MODE 0x0000
  55. #define EPCR_RGMII_MODE 0x1000
  56. #define EPCR_TBI_MODE 0x2000
  57. #define EPCR_RTBI_MODE 0x3000
  58. struct mii_phy;
  59. /* Operations supported by any kind of PHY */
  60. struct mii_phy_ops {
  61. int (*init) (struct mii_phy * phy);
  62. int (*suspend) (struct mii_phy * phy, int wol_options);
  63. int (*setup_aneg) (struct mii_phy * phy, u32 advertise);
  64. int (*setup_forced) (struct mii_phy * phy, int speed, int fd);
  65. int (*poll_link) (struct mii_phy * phy);
  66. int (*read_link) (struct mii_phy * phy);
  67. };
  68. /* Structure used to statically define an mii/gii based PHY */
  69. struct mii_phy_def {
  70. u32 phy_id; /* Concatenated ID1 << 16 | ID2 */
  71. u32 phy_id_mask; /* Significant bits */
  72. u32 features; /* Ethtool SUPPORTED_* defines */
  73. int magic_aneg; /* Autoneg does all speed test for us */
  74. const char *name;
  75. const struct mii_phy_ops *ops;
  76. };
  77. /* An instance of a PHY, partially borrowed from mii_if_info */
  78. struct mii_phy {
  79. struct mii_phy_def *def;
  80. int advertising;
  81. int mii_id;
  82. /* 1: autoneg enabled, 0: disabled */
  83. int autoneg;
  84. /* forced speed & duplex (no autoneg)
  85. * partner speed & duplex & pause (autoneg)
  86. */
  87. int speed;
  88. int duplex;
  89. int pause;
  90. /* PHY mode - if needed */
  91. int mode;
  92. /* Provided by host chip */
  93. struct net_device *dev;
  94. int (*mdio_read) (struct net_device * dev, int mii_id, int reg);
  95. void (*mdio_write) (struct net_device * dev, int mii_id, int reg,
  96. int val);
  97. };
  98. /* Pass in a struct mii_phy with dev, mdio_read and mdio_write
  99. * filled, the remaining fields will be filled on return
  100. */
  101. extern int mii_phy_probe(struct mii_phy *phy, int mii_id);
  102. static inline int __phy_read(struct mii_phy *phy, int id, int reg)
  103. {
  104. return phy->mdio_read(phy->dev, id, reg);
  105. }
  106. static inline void __phy_write(struct mii_phy *phy, int id, int reg, int val)
  107. {
  108. phy->mdio_write(phy->dev, id, reg, val);
  109. }
  110. static inline int phy_read(struct mii_phy *phy, int reg)
  111. {
  112. return phy->mdio_read(phy->dev, phy->mii_id, reg);
  113. }
  114. static inline void phy_write(struct mii_phy *phy, int reg, int val)
  115. {
  116. phy->mdio_write(phy->dev, phy->mii_id, reg, val);
  117. }
  118. #endif /* _IBM_EMAC_PHY_H_ */