cphy.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*****************************************************************************
  2. * *
  3. * File: cphy.h *
  4. * $Revision: 1.7 $ *
  5. * $Date: 2005/06/21 18:29:47 $ *
  6. * Description: *
  7. * part of the Chelsio 10Gb Ethernet Driver. *
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License, version 2, as *
  11. * published by the Free Software Foundation. *
  12. * *
  13. * You should have received a copy of the GNU General Public License along *
  14. * with this program; if not, write to the Free Software Foundation, Inc., *
  15. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  16. * *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * http://www.chelsio.com *
  22. * *
  23. * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
  24. * All rights reserved. *
  25. * *
  26. * Maintainers: maintainers@chelsio.com *
  27. * *
  28. * Authors: Dimitrios Michailidis <dm@chelsio.com> *
  29. * Tina Yang <tainay@chelsio.com> *
  30. * Felix Marti <felix@chelsio.com> *
  31. * Scott Bardone <sbardone@chelsio.com> *
  32. * Kurt Ottaway <kottaway@chelsio.com> *
  33. * Frank DiMambro <frank@chelsio.com> *
  34. * *
  35. * History: *
  36. * *
  37. ****************************************************************************/
  38. #ifndef _CXGB_CPHY_H_
  39. #define _CXGB_CPHY_H_
  40. #include "common.h"
  41. struct mdio_ops {
  42. void (*init)(adapter_t *adapter, const struct board_info *bi);
  43. int (*read)(adapter_t *adapter, int phy_addr, int mmd_addr,
  44. int reg_addr, unsigned int *val);
  45. int (*write)(adapter_t *adapter, int phy_addr, int mmd_addr,
  46. int reg_addr, unsigned int val);
  47. };
  48. /* PHY interrupt types */
  49. enum {
  50. cphy_cause_link_change = 0x1,
  51. cphy_cause_error = 0x2
  52. };
  53. struct cphy;
  54. /* PHY operations */
  55. struct cphy_ops {
  56. void (*destroy)(struct cphy *);
  57. int (*reset)(struct cphy *, int wait);
  58. int (*interrupt_enable)(struct cphy *);
  59. int (*interrupt_disable)(struct cphy *);
  60. int (*interrupt_clear)(struct cphy *);
  61. int (*interrupt_handler)(struct cphy *);
  62. int (*autoneg_enable)(struct cphy *);
  63. int (*autoneg_disable)(struct cphy *);
  64. int (*autoneg_restart)(struct cphy *);
  65. int (*advertise)(struct cphy *phy, unsigned int advertise_map);
  66. int (*set_loopback)(struct cphy *, int on);
  67. int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex);
  68. int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed,
  69. int *duplex, int *fc);
  70. };
  71. /* A PHY instance */
  72. struct cphy {
  73. int addr; /* PHY address */
  74. adapter_t *adapter; /* associated adapter */
  75. struct cphy_ops *ops; /* PHY operations */
  76. int (*mdio_read)(adapter_t *adapter, int phy_addr, int mmd_addr,
  77. int reg_addr, unsigned int *val);
  78. int (*mdio_write)(adapter_t *adapter, int phy_addr, int mmd_addr,
  79. int reg_addr, unsigned int val);
  80. struct cphy_instance *instance;
  81. };
  82. /* Convenience MDIO read/write wrappers */
  83. static inline int mdio_read(struct cphy *cphy, int mmd, int reg,
  84. unsigned int *valp)
  85. {
  86. return cphy->mdio_read(cphy->adapter, cphy->addr, mmd, reg, valp);
  87. }
  88. static inline int mdio_write(struct cphy *cphy, int mmd, int reg,
  89. unsigned int val)
  90. {
  91. return cphy->mdio_write(cphy->adapter, cphy->addr, mmd, reg, val);
  92. }
  93. static inline int simple_mdio_read(struct cphy *cphy, int reg,
  94. unsigned int *valp)
  95. {
  96. return mdio_read(cphy, 0, reg, valp);
  97. }
  98. static inline int simple_mdio_write(struct cphy *cphy, int reg,
  99. unsigned int val)
  100. {
  101. return mdio_write(cphy, 0, reg, val);
  102. }
  103. /* Convenience initializer */
  104. static inline void cphy_init(struct cphy *phy, adapter_t *adapter,
  105. int phy_addr, struct cphy_ops *phy_ops,
  106. struct mdio_ops *mdio_ops)
  107. {
  108. phy->adapter = adapter;
  109. phy->addr = phy_addr;
  110. phy->ops = phy_ops;
  111. if (mdio_ops) {
  112. phy->mdio_read = mdio_ops->read;
  113. phy->mdio_write = mdio_ops->write;
  114. }
  115. }
  116. /* Operations of the PHY-instance factory */
  117. struct gphy {
  118. /* Construct a PHY instance with the given PHY address */
  119. struct cphy *(*create)(adapter_t *adapter, int phy_addr,
  120. struct mdio_ops *mdio_ops);
  121. /*
  122. * Reset the PHY chip. This resets the whole PHY chip, not individual
  123. * ports.
  124. */
  125. int (*reset)(adapter_t *adapter);
  126. };
  127. extern struct gphy t1_mv88x201x_ops;
  128. extern struct gphy t1_dummy_phy_ops;
  129. #endif /* _CXGB_CPHY_H_ */