071-v4.10-0002-net-bgmac-drop-struct-bcma_mdio-we-don-t-need-anymor.patch 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  2. Date: Tue, 31 Jan 2017 19:37:55 +0100
  3. Subject: [PATCH] net: bgmac: drop struct bcma_mdio we don't need anymore
  4. MIME-Version: 1.0
  5. Content-Type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 8bit
  7. Adding struct bcma_mdio was a workaround for bcma code not having access
  8. to the struct bgmac used in the core code. Now we don't duplicate this
  9. struct we can just use it internally in bcma code.
  10. This simplifies code & allows access to all bgmac driver details from
  11. all places in bcma code.
  12. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  13. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  14. Signed-off-by: David S. Miller <davem@davemloft.net>
  15. ---
  16. --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
  17. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
  18. @@ -166,7 +166,7 @@ static int bgmac_probe(struct bcma_devic
  19. if (!bgmac_is_bcm4707_family(core) &&
  20. !(ci->id == BCMA_CHIP_ID_BCM53573 && core->core_unit == 1)) {
  21. - mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
  22. + mii_bus = bcma_mdio_mii_register(bgmac);
  23. if (IS_ERR(mii_bus)) {
  24. err = PTR_ERR(mii_bus);
  25. goto err;
  26. --- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  27. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  28. @@ -12,11 +12,6 @@
  29. #include <linux/brcmphy.h>
  30. #include "bgmac.h"
  31. -struct bcma_mdio {
  32. - struct bcma_device *core;
  33. - u8 phyaddr;
  34. -};
  35. -
  36. static bool bcma_mdio_wait_value(struct bcma_device *core, u16 reg, u32 mask,
  37. u32 value, int timeout)
  38. {
  39. @@ -37,7 +32,7 @@ static bool bcma_mdio_wait_value(struct
  40. * PHY ops
  41. **************************************************/
  42. -static u16 bcma_mdio_phy_read(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg)
  43. +static u16 bcma_mdio_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg)
  44. {
  45. struct bcma_device *core;
  46. u16 phy_access_addr;
  47. @@ -56,12 +51,12 @@ static u16 bcma_mdio_phy_read(struct bcm
  48. BUILD_BUG_ON(BGMAC_PC_MCT_SHIFT != BCMA_GMAC_CMN_PC_MCT_SHIFT);
  49. BUILD_BUG_ON(BGMAC_PC_MTE != BCMA_GMAC_CMN_PC_MTE);
  50. - if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  51. - core = bcma_mdio->core->bus->drv_gmac_cmn.core;
  52. + if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  53. + core = bgmac->bcma.core->bus->drv_gmac_cmn.core;
  54. phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  55. phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  56. } else {
  57. - core = bcma_mdio->core;
  58. + core = bgmac->bcma.core;
  59. phy_access_addr = BGMAC_PHY_ACCESS;
  60. phy_ctl_addr = BGMAC_PHY_CNTL;
  61. }
  62. @@ -87,7 +82,7 @@ static u16 bcma_mdio_phy_read(struct bcm
  63. }
  64. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */
  65. -static int bcma_mdio_phy_write(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg,
  66. +static int bcma_mdio_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg,
  67. u16 value)
  68. {
  69. struct bcma_device *core;
  70. @@ -95,12 +90,12 @@ static int bcma_mdio_phy_write(struct bc
  71. u16 phy_ctl_addr;
  72. u32 tmp;
  73. - if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  74. - core = bcma_mdio->core->bus->drv_gmac_cmn.core;
  75. + if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  76. + core = bgmac->bcma.core->bus->drv_gmac_cmn.core;
  77. phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  78. phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  79. } else {
  80. - core = bcma_mdio->core;
  81. + core = bgmac->bcma.core;
  82. phy_access_addr = BGMAC_PHY_ACCESS;
  83. phy_ctl_addr = BGMAC_PHY_CNTL;
  84. }
  85. @@ -110,8 +105,8 @@ static int bcma_mdio_phy_write(struct bc
  86. tmp |= phyaddr;
  87. bcma_write32(core, phy_ctl_addr, tmp);
  88. - bcma_write32(bcma_mdio->core, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
  89. - if (bcma_read32(bcma_mdio->core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
  90. + bcma_write32(bgmac->bcma.core, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
  91. + if (bcma_read32(bgmac->bcma.core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
  92. dev_warn(&core->dev, "Error setting MDIO int\n");
  93. tmp = BGMAC_PA_START;
  94. @@ -132,39 +127,39 @@ static int bcma_mdio_phy_write(struct bc
  95. }
  96. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */
  97. -static void bcma_mdio_phy_init(struct bcma_mdio *bcma_mdio)
  98. +static void bcma_mdio_phy_init(struct bgmac *bgmac)
  99. {
  100. - struct bcma_chipinfo *ci = &bcma_mdio->core->bus->chipinfo;
  101. + struct bcma_chipinfo *ci = &bgmac->bcma.core->bus->chipinfo;
  102. u8 i;
  103. if (ci->id == BCMA_CHIP_ID_BCM5356) {
  104. for (i = 0; i < 5; i++) {
  105. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x008b);
  106. - bcma_mdio_phy_write(bcma_mdio, i, 0x15, 0x0100);
  107. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  108. - bcma_mdio_phy_write(bcma_mdio, i, 0x12, 0x2aaa);
  109. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  110. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x008b);
  111. + bcma_mdio_phy_write(bgmac, i, 0x15, 0x0100);
  112. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
  113. + bcma_mdio_phy_write(bgmac, i, 0x12, 0x2aaa);
  114. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
  115. }
  116. }
  117. if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) ||
  118. (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) ||
  119. (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg != 9)) {
  120. - struct bcma_drv_cc *cc = &bcma_mdio->core->bus->drv_cc;
  121. + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc;
  122. bcma_chipco_chipctl_maskset(cc, 2, ~0xc0000000, 0);
  123. bcma_chipco_chipctl_maskset(cc, 4, ~0x80000000, 0);
  124. for (i = 0; i < 5; i++) {
  125. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  126. - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5284);
  127. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  128. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x0010);
  129. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  130. - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5296);
  131. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x1073);
  132. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9073);
  133. - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x52b6);
  134. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9273);
  135. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  136. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
  137. + bcma_mdio_phy_write(bgmac, i, 0x16, 0x5284);
  138. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
  139. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x0010);
  140. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
  141. + bcma_mdio_phy_write(bgmac, i, 0x16, 0x5296);
  142. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x1073);
  143. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x9073);
  144. + bcma_mdio_phy_write(bgmac, i, 0x16, 0x52b6);
  145. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x9273);
  146. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
  147. }
  148. }
  149. }
  150. @@ -172,17 +167,17 @@ static void bcma_mdio_phy_init(struct bc
  151. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */
  152. static int bcma_mdio_phy_reset(struct mii_bus *bus)
  153. {
  154. - struct bcma_mdio *bcma_mdio = bus->priv;
  155. - u8 phyaddr = bcma_mdio->phyaddr;
  156. + struct bgmac *bgmac = bus->priv;
  157. + u8 phyaddr = bgmac->phyaddr;
  158. - if (bcma_mdio->phyaddr == BGMAC_PHY_NOREGS)
  159. + if (phyaddr == BGMAC_PHY_NOREGS)
  160. return 0;
  161. - bcma_mdio_phy_write(bcma_mdio, phyaddr, MII_BMCR, BMCR_RESET);
  162. + bcma_mdio_phy_write(bgmac, phyaddr, MII_BMCR, BMCR_RESET);
  163. udelay(100);
  164. - if (bcma_mdio_phy_read(bcma_mdio, phyaddr, MII_BMCR) & BMCR_RESET)
  165. - dev_err(&bcma_mdio->core->dev, "PHY reset failed\n");
  166. - bcma_mdio_phy_init(bcma_mdio);
  167. + if (bcma_mdio_phy_read(bgmac, phyaddr, MII_BMCR) & BMCR_RESET)
  168. + dev_err(bgmac->dev, "PHY reset failed\n");
  169. + bcma_mdio_phy_init(bgmac);
  170. return 0;
  171. }
  172. @@ -202,16 +197,12 @@ static int bcma_mdio_mii_write(struct mi
  173. return bcma_mdio_phy_write(bus->priv, mii_id, regnum, value);
  174. }
  175. -struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr)
  176. +struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac)
  177. {
  178. - struct bcma_mdio *bcma_mdio;
  179. + struct bcma_device *core = bgmac->bcma.core;
  180. struct mii_bus *mii_bus;
  181. int err;
  182. - bcma_mdio = kzalloc(sizeof(*bcma_mdio), GFP_KERNEL);
  183. - if (!bcma_mdio)
  184. - return ERR_PTR(-ENOMEM);
  185. -
  186. mii_bus = mdiobus_alloc();
  187. if (!mii_bus) {
  188. err = -ENOMEM;
  189. @@ -221,15 +212,12 @@ struct mii_bus *bcma_mdio_mii_register(s
  190. mii_bus->name = "bcma_mdio mii bus";
  191. sprintf(mii_bus->id, "%s-%d-%d", "bcma_mdio", core->bus->num,
  192. core->core_unit);
  193. - mii_bus->priv = bcma_mdio;
  194. + mii_bus->priv = bgmac;
  195. mii_bus->read = bcma_mdio_mii_read;
  196. mii_bus->write = bcma_mdio_mii_write;
  197. mii_bus->reset = bcma_mdio_phy_reset;
  198. mii_bus->parent = &core->dev;
  199. - mii_bus->phy_mask = ~(1 << phyaddr);
  200. -
  201. - bcma_mdio->core = core;
  202. - bcma_mdio->phyaddr = phyaddr;
  203. + mii_bus->phy_mask = ~(1 << bgmac->phyaddr);
  204. err = mdiobus_register(mii_bus);
  205. if (err) {
  206. @@ -242,23 +230,17 @@ struct mii_bus *bcma_mdio_mii_register(s
  207. err_free_bus:
  208. mdiobus_free(mii_bus);
  209. err:
  210. - kfree(bcma_mdio);
  211. return ERR_PTR(err);
  212. }
  213. EXPORT_SYMBOL_GPL(bcma_mdio_mii_register);
  214. void bcma_mdio_mii_unregister(struct mii_bus *mii_bus)
  215. {
  216. - struct bcma_mdio *bcma_mdio;
  217. -
  218. if (!mii_bus)
  219. return;
  220. - bcma_mdio = mii_bus->priv;
  221. -
  222. mdiobus_unregister(mii_bus);
  223. mdiobus_free(mii_bus);
  224. - kfree(bcma_mdio);
  225. }
  226. EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister);
  227. --- a/drivers/net/ethernet/broadcom/bgmac.h
  228. +++ b/drivers/net/ethernet/broadcom/bgmac.h
  229. @@ -519,7 +519,7 @@ struct bgmac *bgmac_alloc(struct device
  230. int bgmac_enet_probe(struct bgmac *bgmac);
  231. void bgmac_enet_remove(struct bgmac *bgmac);
  232. -struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
  233. +struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac);
  234. void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
  235. static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)