123-phy-generate-swphy-registers-on-the-fly.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. From e0f33a88243329da1aa5a90fe10ab25c9fb0a091 Mon Sep 17 00:00:00 2001
  2. From: Russell King <rmk+kernel@arm.linux.org.uk>
  3. Date: Sun, 20 Sep 2015 11:28:39 +0100
  4. Subject: [PATCH 712/744] phy: generate swphy registers on the fly
  5. Generate software phy registers as and when requested, rather than
  6. duplicating the state in fixed_phy. This allows us to eliminate
  7. the duplicate storage of of the same data, which is only different
  8. in format.
  9. As fixed_phy_update_regs() no longer updates register state, rename
  10. it to fixed_phy_update().
  11. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  12. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  13. ---
  14. drivers/net/phy/fixed_phy.c | 31 +++++-------------------------
  15. drivers/net/phy/swphy.c | 47 ++++++++++++++++++++++++++++++++-------------
  16. drivers/net/phy/swphy.h | 2 +-
  17. 3 files changed, 40 insertions(+), 40 deletions(-)
  18. --- a/drivers/net/phy/fixed_phy.c
  19. +++ b/drivers/net/phy/fixed_phy.c
  20. @@ -26,8 +26,6 @@
  21. #include "swphy.h"
  22. -#define MII_REGS_NUM 29
  23. -
  24. struct fixed_mdio_bus {
  25. int irqs[PHY_MAX_ADDR];
  26. struct mii_bus *mii_bus;
  27. @@ -36,7 +34,6 @@ struct fixed_mdio_bus {
  28. struct fixed_phy {
  29. int addr;
  30. - u16 regs[MII_REGS_NUM];
  31. struct phy_device *phydev;
  32. struct fixed_phy_status status;
  33. int (*link_update)(struct net_device *, struct fixed_phy_status *);
  34. @@ -49,12 +46,10 @@ static struct fixed_mdio_bus platform_fm
  35. .phys = LIST_HEAD_INIT(platform_fmb.phys),
  36. };
  37. -static void fixed_phy_update_regs(struct fixed_phy *fp)
  38. +static void fixed_phy_update(struct fixed_phy *fp)
  39. {
  40. if (gpio_is_valid(fp->link_gpio))
  41. fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
  42. -
  43. - swphy_update_regs(fp->regs, &fp->status);
  44. }
  45. static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
  46. @@ -62,29 +57,15 @@ static int fixed_mdio_read(struct mii_bu
  47. struct fixed_mdio_bus *fmb = bus->priv;
  48. struct fixed_phy *fp;
  49. - if (reg_num >= MII_REGS_NUM)
  50. - return -1;
  51. -
  52. - /* We do not support emulating Clause 45 over Clause 22 register reads
  53. - * return an error instead of bogus data.
  54. - */
  55. - switch (reg_num) {
  56. - case MII_MMD_CTRL:
  57. - case MII_MMD_DATA:
  58. - return -1;
  59. - default:
  60. - break;
  61. - }
  62. -
  63. list_for_each_entry(fp, &fmb->phys, node) {
  64. if (fp->addr == phy_addr) {
  65. /* Issue callback if user registered it. */
  66. if (fp->link_update) {
  67. fp->link_update(fp->phydev->attached_dev,
  68. &fp->status);
  69. - fixed_phy_update_regs(fp);
  70. + fixed_phy_update(fp);
  71. }
  72. - return fp->regs[reg_num];
  73. + return swphy_read_reg(reg_num, &fp->status);
  74. }
  75. }
  76. @@ -144,7 +125,7 @@ int fixed_phy_update_state(struct phy_de
  77. _UPD(pause);
  78. _UPD(asym_pause);
  79. #undef _UPD
  80. - fixed_phy_update_regs(fp);
  81. + fixed_phy_update(fp);
  82. return 0;
  83. }
  84. }
  85. @@ -169,8 +150,6 @@ int fixed_phy_add(unsigned int irq, int
  86. if (!fp)
  87. return -ENOMEM;
  88. - memset(fp->regs, 0xFF, sizeof(fp->regs[0]) * MII_REGS_NUM);
  89. -
  90. fmb->irqs[phy_addr] = irq;
  91. fp->addr = phy_addr;
  92. @@ -184,7 +163,7 @@ int fixed_phy_add(unsigned int irq, int
  93. goto err_regs;
  94. }
  95. - fixed_phy_update_regs(fp);
  96. + fixed_phy_update(fp);
  97. list_add_tail(&fp->node, &fmb->phys);
  98. --- a/drivers/net/phy/swphy.c
  99. +++ b/drivers/net/phy/swphy.c
  100. @@ -20,6 +20,8 @@
  101. #include "swphy.h"
  102. +#define MII_REGS_NUM 29
  103. +
  104. struct swmii_regs {
  105. u16 bmcr;
  106. u16 bmsr;
  107. @@ -110,14 +112,13 @@ int swphy_validate_state(const struct fi
  108. EXPORT_SYMBOL_GPL(swphy_validate_state);
  109. /**
  110. - * swphy_update_regs - update MII register array with fixed phy state
  111. - * @regs: array of 32 registers to update
  112. + * swphy_read_reg - return a MII register from the fixed phy state
  113. + * @reg: MII register
  114. * @state: fixed phy status
  115. *
  116. - * Update the array of MII registers with the fixed phy link, speed,
  117. - * duplex and pause mode settings.
  118. + * Return the MII @reg register generated from the fixed phy state @state.
  119. */
  120. -void swphy_update_regs(u16 *regs, const struct fixed_phy_status *state)
  121. +int swphy_read_reg(int reg, const struct fixed_phy_status *state)
  122. {
  123. int speed_index, duplex_index;
  124. u16 bmsr = BMSR_ANEGCAPABLE;
  125. @@ -125,9 +126,12 @@ void swphy_update_regs(u16 *regs, const
  126. u16 lpagb = 0;
  127. u16 lpa = 0;
  128. + if (reg > MII_REGS_NUM)
  129. + return -1;
  130. +
  131. speed_index = swphy_decode_speed(state->speed);
  132. if (WARN_ON(speed_index < 0))
  133. - return;
  134. + return 0;
  135. duplex_index = state->duplex ? SWMII_DUPLEX_FULL : SWMII_DUPLEX_HALF;
  136. @@ -147,12 +151,29 @@ void swphy_update_regs(u16 *regs, const
  137. lpa |= LPA_PAUSE_ASYM;
  138. }
  139. - regs[MII_PHYSID1] = 0;
  140. - regs[MII_PHYSID2] = 0;
  141. + switch (reg) {
  142. + case MII_BMCR:
  143. + return bmcr;
  144. + case MII_BMSR:
  145. + return bmsr;
  146. + case MII_PHYSID1:
  147. + case MII_PHYSID2:
  148. + return 0;
  149. + case MII_LPA:
  150. + return lpa;
  151. + case MII_STAT1000:
  152. + return lpagb;
  153. +
  154. + /*
  155. + * We do not support emulating Clause 45 over Clause 22 register
  156. + * reads. Return an error instead of bogus data.
  157. + */
  158. + case MII_MMD_CTRL:
  159. + case MII_MMD_DATA:
  160. + return -1;
  161. - regs[MII_BMSR] = bmsr;
  162. - regs[MII_BMCR] = bmcr;
  163. - regs[MII_LPA] = lpa;
  164. - regs[MII_STAT1000] = lpagb;
  165. + default:
  166. + return 0xffff;
  167. + }
  168. }
  169. -EXPORT_SYMBOL_GPL(swphy_update_regs);
  170. +EXPORT_SYMBOL_GPL(swphy_read_reg);
  171. --- a/drivers/net/phy/swphy.h
  172. +++ b/drivers/net/phy/swphy.h
  173. @@ -4,6 +4,6 @@
  174. struct fixed_phy_status;
  175. int swphy_validate_state(const struct fixed_phy_status *state);
  176. -void swphy_update_regs(u16 *regs, const struct fixed_phy_status *state);
  177. +int swphy_read_reg(int reg, const struct fixed_phy_status *state);
  178. #endif